From 09912cc87ea3edaa8b3a972b3edfcc1848f96adc Mon Sep 17 00:00:00 2001 From: adwpc Date: Sun, 18 Apr 2021 21:50:51 +0800 Subject: [PATCH] Revert "Resolve `join` promise after API channel ready (#185)" This reverts commit 4d1d436b0c4977d93dffee75dee279ae4bf4e81f. --- src/client.ts | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/client.ts b/src/client.ts index 6f3b60d3..39acfb15 100644 --- a/src/client.ts +++ b/src/client.ts @@ -107,24 +107,21 @@ export default class Client { } }; - const apiReady = new Promise((resolve) => { - this.transports![Role.sub].pc.ondatachannel = (ev: RTCDataChannelEvent) => { - if (ev.channel.label === API_CHANNEL) { - this.transports![Role.sub].api = ev.channel; - ev.channel.onmessage = (e) => { - if (this.onspeaker) { - this.onspeaker(JSON.parse(e.data)); - } - }; - resolve(); - return; - } + this.transports[Role.sub].pc.ondatachannel = (ev: RTCDataChannelEvent) => { + if (ev.channel.label === API_CHANNEL) { + this.transports![Role.sub].api = ev.channel; + ev.channel.onmessage = (e) => { + if (this.onspeaker) { + this.onspeaker(JSON.parse(e.data)); + } + }; + return; + } - if (this.ondatachannel) { - this.ondatachannel(ev); - } - }; - }); + if (this.ondatachannel) { + this.ondatachannel(ev); + } + }; const offer = await this.transports[Role.pub].pc.createOffer(); await this.transports[Role.pub].pc.setLocalDescription(offer); @@ -133,8 +130,6 @@ export default class Client { await this.transports[Role.pub].pc.setRemoteDescription(answer); this.transports[Role.pub].candidates.forEach((c) => this.transports![Role.pub].pc.addIceCandidate(c)); this.transports[Role.pub].pc.onnegotiationneeded = this.onNegotiationNeeded.bind(this); - - return apiReady; } leave() {