Skip to content

Commit

Permalink
fix: dont remove datachannel on unpublish
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Oct 27, 2020
1 parent 7b63090 commit 42bdd1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class Client {
}

private async join(sid: string) {
const offer = await this.pc.createOffer({ offerToReceiveVideo: true, offerToReceiveAudio: true });
const offer = await this.pc.createOffer();
await this.pc.setLocalDescription(offer);
const answer = await this.signal.join(sid, offer);

Expand All @@ -74,10 +74,8 @@ export default class Client {
private async negotiate(description: RTCSessionDescriptionInit) {
try {
await this.pc.setRemoteDescription(description); // SRD rolls back as needed
if (description.type === 'offer') {
await this.pc.setLocalDescription();
this.signal.answer(this.pc.localDescription!);
}
await this.pc.setLocalDescription();
this.signal.answer(this.pc.localDescription!);
} catch (err) {
/* tslint:disable-next-line:no-console */
console.error(err);
Expand Down
6 changes: 3 additions & 3 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ export class LocalStream {

unpublish() {
if (this.pc) {
this.pc.getSenders().forEach(async (sender: RTCRtpSender) => {
if (sender.track && this.stream.getTracks().includes(sender.track)) {
this.pc!.removeTrack(sender);
this.pc.getSenders().forEach((s: RTCRtpSender) => {
if (s.track !== undefined) {
this.pc!.removeTrack(s);
}
});
}
Expand Down

0 comments on commit 42bdd1a

Please sign in to comment.