Skip to content

Commit

Permalink
Fix bug with ine-way audio after a transfer (#2193)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dbkr authored Feb 23, 2022
1 parent 55dda84 commit 2128f67
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,11 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
private pushNewLocalFeed(stream: MediaStream, purpose: SDPStreamMetadataPurpose, addToPeerConnection = true): void {
const userId = this.client.getUserId();

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

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

try {
const stream = await this.client.getMediaHandler().getUserMediaStream(audio, video);

// make sure all the tracks are enabled (same as pushNewLocalFeed -
// we probably ought to just have one code path for adding streams)
setTracksEnabled(stream.getAudioTracks(), true);
setTracksEnabled(stream.getVideoTracks(), true);

const callFeed = new CallFeed({
client: this.client,
roomId: this.roomId,
Expand Down

0 comments on commit 2128f67

Please sign in to comment.