Skip to content

Commit

Permalink
Fix connectivity regressions (#2780)
Browse files Browse the repository at this point in the history
* Fix connectivity regressions

Switches back to addTrack, digging the transceivers out manually
to re-use, because the only way to group tracks into streams re-using
trasceivers from the offer is to use setStreams which FF doesn't
implement.

* Remove comments
  • Loading branch information
dbkr authored Oct 19, 2022
1 parent c57c897 commit 5a07873
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,17 +647,6 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
videoMuted,
}));

// gather transceivers from the new tracks so that we can use the same ones for tracks that
// we add later. We only do this for user media streams though: screenshare streams just always
// get their own unidirectional transceiver since a bidirectional screen share is pretty rare
// (we *could* re-use an existing recvonly transceiver for this, but it's simpler to just not).
if (purpose == SDPStreamMetadataPurpose.Usermedia) {
for (const track of stream.getTracks()) {
const transceiver = this.peerConn.getTransceivers().find(t => t.receiver.track == track);
this.transceivers.set(getTransceiverKey(purpose, track.kind), transceiver);
}
}

this.emit(CallEvent.FeedsChanged, this.feeds);

logger.info(
Expand Down Expand Up @@ -700,11 +689,6 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
purpose,
}));

for (const track of stream.getTracks()) {
const transceiver = this.peerConn.getTransceivers().find(t => t.receiver.track == track);
this.transceivers.set(getTransceiverKey(purpose, track.kind), transceiver);
}

this.emit(CallEvent.FeedsChanged, this.feeds);

logger.info(`Call ${this.callId} pushed remote stream (id="${stream.id}", active="${stream.active}")`);
Expand Down Expand Up @@ -773,16 +757,23 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
// Matrix event.
const transceiver = this.transceivers.get(tKey);

// this is what would allow us to use addTransceiver(), but it's not available
// on Firefox yet. We call it anyway if we have it.
if (transceiver.sender.setStreams) transceiver.sender.setStreams(callFeed.stream);

transceiver.sender.replaceTrack(track);
// set the direction to indicate we're going to start sending again
// (this will trigger the re-negotiation)
transceiver.direction = transceiver.direction === "inactive" ? "sendonly" : "sendrecv";
} else {
// create a new one: pass the track in and everything happens automatically
this.transceivers.set(tKey, this.peerConn.addTransceiver(track, {
streams: [callFeed.stream],
direction: callFeed.purpose === SDPStreamMetadataPurpose.Usermedia ? "sendrecv" : "sendonly",
}));
// create a new one. We need to use addTrack rather addTransceiver for this because firefox
// doesn't yet implement RTCRTPSender.setStreams()
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1510802) so we'd have no way to group the
// two tracks together into a stream.
const newSender = this.peerConn.addTrack(track, callFeed.stream);

// now go & fish for the new transceiver
this.transceivers.set(tKey, this.peerConn.getTransceivers().find(t => t.sender === newSender));
}
}
}
Expand Down Expand Up @@ -1313,10 +1304,8 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
`) to peer connection`,
);

this.transceivers.set(tKey, this.peerConn.addTransceiver(track, {
streams: [this.localUsermediaStream],
direction: "sendrecv",
}));
const newSender = this.peerConn.addTrack(track, this.localUsermediaStream);
this.transceivers.set(tKey, this.peerConn.getTransceivers().find(t => t.sender === newSender));
}
}
}
Expand Down

0 comments on commit 5a07873

Please sign in to comment.