chore: add check for connection status before sending

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2023-12-05 09:31:46 +02:00
parent 7af9750ea8
commit 8fbabdc2cb
2 changed files with 6 additions and 1 deletions
@@ -206,6 +206,11 @@ export class SignalsService implements EventSubscriber {
) {
return;
}
if (conn.ws.readyState !== WebSocket.OPEN) {
return;
}
conn.ws.send(jsonMessage);
});
+1 -1
View File
@@ -126,7 +126,7 @@ export class SignalsClient implements SignalsApi {
const { token } = await this.identity.getCredentials();
const url = new URL(apiUrl);
url.protocol = url.protocol === 'http:' ? 'ws' : 'wss';
url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:';
this.ws = new WebSocket(url.toString(), token);
this.ws.onmessage = (data: MessageEvent) => {