Skip to content

Commit

Permalink
Revert "Resolve join promise after API channel ready (#185)" (#190)
Browse files Browse the repository at this point in the history
This reverts commit 4d1d436.
  • Loading branch information
adwpc committed Apr 18, 2021
1 parent 4d1d436 commit 95a4af8
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,21 @@ export default class Client {
}
};

const apiReady = new Promise<void>((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);
Expand All @@ -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() {
Expand Down

0 comments on commit 95a4af8

Please sign in to comment.