Skip to content

Commit 2128f67

Browse files
authored
Fix bug with ine-way audio after a transfer (#2193)
Seems chrome at least will give you a disabled audio track if you already had another user media audio track and disabled it, so make sure our tracks are enabled when we add them. We already did this on one code path but it didn't get moved over when a new code path was added. On the plus side, we now know the reason for the ancient code that had the comment asking what it was for, so update that.
1 parent 55dda84 commit 2128f67

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/webrtc/call.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,11 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
585585
private pushNewLocalFeed(stream: MediaStream, purpose: SDPStreamMetadataPurpose, addToPeerConnection = true): void {
586586
const userId = this.client.getUserId();
587587

588-
// TODO: Find out what is going on here
589-
// why do we enable audio (and only audio) tracks here? -- matthew
588+
// Tracks don't always start off enabled, eg. chrome will give a disabled
589+
// audio track if you ask for user media audio and already had one that
590+
// you'd set to disabled (presumably because it clones them internally).
590591
setTracksEnabled(stream.getAudioTracks(), true);
592+
setTracksEnabled(stream.getVideoTracks(), true);
591593

592594
// We try to replace an existing feed if there already is one with the same purpose
593595
const existingFeed = this.getLocalFeeds().find((feed) => feed.purpose === purpose);
@@ -630,7 +632,8 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
630632
`id="${track.id}", ` +
631633
`kind="${track.kind}", ` +
632634
`streamId="${callFeed.stream.id}", ` +
633-
`streamPurpose="${callFeed.purpose}"` +
635+
`streamPurpose="${callFeed.purpose}", ` +
636+
`enabled=${track.enabled}` +
634637
`) to peer connection`,
635638
);
636639
senderArray.push(this.peerConn.addTrack(track, callFeed.stream));
@@ -2078,6 +2081,12 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
20782081

20792082
try {
20802083
const stream = await this.client.getMediaHandler().getUserMediaStream(audio, video);
2084+
2085+
// make sure all the tracks are enabled (same as pushNewLocalFeed -
2086+
// we probably ought to just have one code path for adding streams)
2087+
setTracksEnabled(stream.getAudioTracks(), true);
2088+
setTracksEnabled(stream.getVideoTracks(), true);
2089+
20812090
const callFeed = new CallFeed({
20822091
client: this.client,
20832092
roomId: this.roomId,

0 commit comments

Comments
 (0)