diff --git a/src/signal/json-rpc-impl.ts b/src/signal/json-rpc-impl.ts index 211d1079..53c190f3 100644 --- a/src/signal/json-rpc-impl.ts +++ b/src/signal/json-rpc-impl.ts @@ -10,8 +10,11 @@ class IonSFUJSONRPCSignal implements Signal { onnegotiate?: (jsep: RTCSessionDescriptionInit) => void; ontrickle?: (trickle: Trickle) => void; + private _notifyhandlers: { [ method: string ]: (params: any) => void }; + constructor(uri: string) { this.socket = new WebSocket(uri); + this._notifyhandlers = {}; this.socket.addEventListener('open', () => { if (this._onopen) this._onopen(); @@ -31,10 +34,21 @@ class IonSFUJSONRPCSignal implements Signal { if (this.onnegotiate) this.onnegotiate(resp.params); } else if (resp.method === 'trickle') { if (this.ontrickle) this.ontrickle(resp.params); + } else { + const handler = this._notifyhandlers[resp.method]; + if (handler) { + handler(resp.params); + } } + }); } + + on_notify(method: string, cb: (params: T) => void) { + this._notifyhandlers[method] = cb + } + // JsonRPC2 Call async call(method: string, params: any): Promise { const id = uuidv4();