Add possibility to guess as a player
All checks were successful
Deploy Feature / deploy-feature (push) Successful in 25s
All checks were successful
Deploy Feature / deploy-feature (push) Successful in 25s
This commit is contained in:
@@ -162,26 +162,46 @@ server.on('upgrade', (req, socket, head) => {
|
||||
)
|
||||
|
||||
ws.on('message', (buffer) => {
|
||||
let parsed: { type?: string; state?: SessionState } | null = null
|
||||
let parsed: { type?: string; state?: SessionState; teamId?: string } | null = null
|
||||
try {
|
||||
parsed = JSON.parse(buffer.toString()) as { type?: string; state?: SessionState }
|
||||
parsed = JSON.parse(buffer.toString()) as {
|
||||
type?: string
|
||||
state?: SessionState
|
||||
teamId?: string
|
||||
}
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!parsed || parsed.type !== 'state:update' || !parsed.state) return
|
||||
const targetSession = ensureSession(gameId)
|
||||
targetSession.state = parsed.state
|
||||
targetSession.updatedAt = Date.now()
|
||||
if (!parsed) return
|
||||
|
||||
broadcast(
|
||||
gameId,
|
||||
{
|
||||
type: 'state:update',
|
||||
if (parsed.type === 'state:update' && parsed.state) {
|
||||
const targetSession = ensureSession(gameId)
|
||||
targetSession.state = parsed.state
|
||||
targetSession.updatedAt = Date.now()
|
||||
|
||||
broadcast(
|
||||
gameId,
|
||||
state: targetSession.state
|
||||
},
|
||||
ws
|
||||
)
|
||||
{
|
||||
type: 'state:update',
|
||||
gameId,
|
||||
state: targetSession.state
|
||||
},
|
||||
ws
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (parsed.type === 'guess:request' && parsed.teamId) {
|
||||
broadcast(
|
||||
gameId,
|
||||
{
|
||||
type: 'guess:request',
|
||||
gameId,
|
||||
teamId: parsed.teamId
|
||||
},
|
||||
ws
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
ws.on('close', () => {
|
||||
|
||||
Reference in New Issue
Block a user