livekit-client
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -28,2 +28,3 @@ import 'webrtc-adapter'; | ||
isConnected: boolean; | ||
useJSON: boolean; | ||
onClose?: (reason: string) => void; | ||
@@ -38,3 +39,3 @@ onAnswer?: (sd: RTCSessionDescriptionInit) => void; | ||
ws?: WebSocket; | ||
constructor(); | ||
constructor(useJSON?: boolean); | ||
reconnect(url: string, token: string): Promise<void>; | ||
@@ -41,0 +42,0 @@ join(url: string, token: string): Promise<JoinResponse>; |
@@ -20,4 +20,5 @@ "use strict"; | ||
class WSSignalClient { | ||
constructor() { | ||
constructor(useJSON = false) { | ||
this.isConnected = false; | ||
this.useJSON = useJSON; | ||
} | ||
@@ -37,2 +38,3 @@ reconnect(url, token) { | ||
const ws = new WebSocket(url); | ||
ws.binaryType = 'arraybuffer'; | ||
ws.onerror = (ev) => { | ||
@@ -57,4 +59,14 @@ if (!this.ws) { | ||
// not considered connected until JoinResponse is received | ||
const json = JSON.parse(ev.data); | ||
const msg = rtc_1.SignalResponse.fromJSON(json); | ||
let msg; | ||
if (typeof ev.data === 'string') { | ||
const json = JSON.parse(ev.data); | ||
msg = rtc_1.SignalResponse.fromJSON(json); | ||
} | ||
else if (ev.data instanceof ArrayBuffer) { | ||
msg = rtc_1.SignalResponse.decode(new Uint8Array(ev.data)); | ||
} | ||
else { | ||
loglevel_1.default.error('could not decode websocket message', typeof ev.data); | ||
return; | ||
} | ||
if (!this.isConnected) { | ||
@@ -134,4 +146,8 @@ // handle join message only | ||
} | ||
const msg = rtc_1.SignalRequest.toJSON(req); | ||
this.ws.send(JSON.stringify(msg)); | ||
if (this.useJSON) { | ||
this.ws.send(JSON.stringify(rtc_1.SignalRequest.toJSON(req))); | ||
} | ||
else { | ||
this.ws.send(rtc_1.SignalRequest.encode(req).finish()); | ||
} | ||
} | ||
@@ -138,0 +154,0 @@ handleSignalResponse(msg) { |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.5.4"; | ||
declare const version = "0.5.5"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
const version = '0.5.4'; | ||
const version = '0.5.5'; | ||
exports.version = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "livekit-client", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "JavaScript/TypeScript client SDK for LiveKit", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
1452604
9309