Skip to content

Commit

Permalink
Merge pull request #622 from EdgeApp/william/fix-lobby
Browse files Browse the repository at this point in the history
Fix lobby
  • Loading branch information
swansontec authored Oct 24, 2024
2 parents 8d5cd08 + 620ef27 commit dd126a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/core/login/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export async function requestEdgeLogin(
appId: string,
opts: EdgeAccountOptions = {}
): Promise<EdgePendingEdgeLogin> {
function handleSoftError(error: unknown): void {
out.error = error
update(out)
}

function handleError(error: unknown): void {
// Stop the long-polling:
for (const cleanup of cleanups) cleanup()
Expand Down Expand Up @@ -121,7 +126,7 @@ export async function requestEdgeLogin(
const lobby = await makeLobby(ai, { loginRequest: { appId } })
const cleanups = [
lobby.close,
lobby.on('error', handleError),
lobby.on('error', handleSoftError),
lobby.on('reply', reply => {
handleReply(reply).catch(handleError)
})
Expand Down
7 changes: 6 additions & 1 deletion src/core/login/lobby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ export async function makeLobby(
task.start({ wait: false })

// Create the return object:
return { close: task.stop, lobbyId, on, replies }
return {
close: () => task.stop(),
lobbyId,
on,
replies
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/core/login/login-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ export function loginFetch(
const { apiKey, apiSecret, serverUri } = state.login

const bodyText =
method !== 'GET' && body != null
? JSON.stringify(wasLoginRequestBody(body))
: ''
method === 'GET' || body == null
? undefined
: JSON.stringify(wasLoginRequestBody(body))

// API key:
let authorization = `Token ${apiKey}`
if (apiSecret != null) {
const requestText = `${method}\n/api${path}\n${bodyText}`
const requestText = `${method}\n/api${path}\n${bodyText ?? ''}`
const hash = hmacSha256(utf8.parse(requestText), apiSecret)
authorization = `HMAC ${apiKey} ${base64.stringify(hash)}`
}
Expand Down

0 comments on commit dd126a1

Please sign in to comment.