Skip to content

Commit

Permalink
fix: prevent message over closed WS
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx authored and xstelea committed Oct 9, 2023
1 parent bac745a commit ba5d149
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/connector/signaling/signaling-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,14 @@ export const SignalingClient = (input: {
const sendMessage$ = of(stringify(encryptedMessage)).pipe(
tap((result) =>
result.map((data) => {
logger?.trace(
`🛰💬⬆️ sending: ${message.method} (${encryptedMessage.requestId})`,
)
return ws.send(data)
const incorrectStates: number[] = [ws.CLOSED, ws.CLOSING]
if (!incorrectStates.includes(ws.readyState)) {
logger?.trace(
`🛰💬⬆️ sending: ${message.method} (${encryptedMessage.requestId})`,
)

return ws.send(data)
}
}),
),
filter(() => false),
Expand Down

0 comments on commit ba5d149

Please sign in to comment.