diff --git a/app/products/calls/connection.ts b/app/products/calls/connection.ts index 4ec440a54..912784a9c 100644 --- a/app/products/calls/connection.ts +++ b/app/products/calls/connection.ts @@ -44,7 +44,7 @@ export async function newClient(channelID: string, iceServers: ICEServersConfigs console.log('Unable to get media device:', err); // eslint-disable-line no-console } - const ws = new WebSocketClient(Client4.getWebSocketUrl()); + const ws = new WebSocketClient(Client4.getWebSocketUrl(), Client4.getToken()); const disconnect = () => { if (!isClosed) { diff --git a/app/products/calls/websocket.ts b/app/products/calls/websocket.ts index 286a99957..16dd293a1 100644 --- a/app/products/calls/websocket.ts +++ b/app/products/calls/websocket.ts @@ -7,13 +7,14 @@ import {encode} from '@msgpack/msgpack/dist'; export default class WebSocketClient extends EventEmitter { private ws: WebSocket | null; - private seqNo = 0; + private seqNo = 1; private connID = ''; private eventPrefix = `custom_${Calls.PluginId}`; - constructor(connURL: string) { + constructor(connURL: string, authToken: string) { super(); - this.ws = new WebSocket(connURL); + + this.ws = new WebSocket(connURL, [], {headers: {authorization: `Bearer ${authToken}`}}); this.ws.onerror = (err) => { this.emit('error', err); @@ -73,6 +74,7 @@ export default class WebSocketClient extends EventEmitter { seq: this.seqNo++, data, }; + if (this.ws && this.ws.readyState === WebSocket.OPEN) { if (binary) { this.ws.send(encode(msg)); @@ -87,7 +89,7 @@ export default class WebSocketClient extends EventEmitter { this.ws.close(); this.ws = null; } - this.seqNo = 0; + this.seqNo = 1; this.connID = ''; this.emit('close'); }