Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Resolve join promise after API channel ready" #190

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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