fix(websocket): error when leaving realtime-note

When a user left a realtime-note, the awareness tried to send events even after the socket was closed, resulting in the app crashing.
This fix adds the check that the socket is still open before sending any messages.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2022-08-27 18:29:51 +02:00 committed by Tilman Vatteroth
parent 26d9bf4dde
commit 1938b6eefe

View file

@ -51,7 +51,7 @@ export class WebsocketConnection extends WebsocketTransporter {
private bindYDocEvents(doc: Doc): void { private bindYDocEvents(doc: Doc): void {
doc.on('destroy', () => this.disconnect()) doc.on('destroy', () => this.disconnect())
doc.on('update', (update: Uint8Array, origin: unknown) => { doc.on('update', (update: Uint8Array, origin: unknown) => {
if (origin !== this && this.isSynced()) { if (origin !== this && this.isSynced() && this.isWebSocketOpen()) {
this.send(encodeDocumentUpdateMessage(update)) this.send(encodeDocumentUpdateMessage(update))
} }
}) })