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

Fix connectivity regressions #2780

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Changes from 1 commit
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
34 changes: 23 additions & 11 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,15 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
// 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) {
// Actually, we don't do this since firefox doesn't implement setStreams() yet, so the only way
// we can group the tracks into streams is to use addTrack(). It remains here to hopefully be
// resurrected once Firefox sort themselves out.
/*if (purpose == SDPStreamMetadataPurpose.Usermedia) {
dbkr marked this conversation as resolved.
Show resolved Hide resolved
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);

Expand Down Expand Up @@ -700,10 +703,14 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
purpose,
}));

/*
Another commented block for retrieving existing transceivers: re-enable once we can use
dbkr marked this conversation as resolved.
Show resolved Hide resolved
addTransceiver (see the many other comments).
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);

Expand Down Expand Up @@ -773,16 +780,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 +1327,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