Skip to content

Commit

Permalink
Close all streams when a call ends
Browse files Browse the repository at this point in the history
We didn't close streams in group calls (presumably from back when
we used the same stream for all calls rather than cloning?) but this
left stray screenshare streams in the mediahandler when a participant
left whilst we were screensharing.

Fixes element-hq/element-call#742
  • Loading branch information
dbkr committed Dec 16, 2022
1 parent c973b26 commit 96ee5b1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2475,18 +2475,20 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
}

private stopAllMedia(): void {
logger.debug(
!this.groupCallId
? `Call ${this.callId} stopping all media`
: `Call ${this.callId} stopping all media except local feeds`,
);
logger.debug(`Call ${this.callId} stopping all media`);

for (const feed of this.feeds) {
if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Usermedia && !this.groupCallId) {
// Slightly awkward as local feed need to go via the correct method on
// the mediahandler so they get removed from mediahandler (remote tracks
// don't)
// NB. We clone local streams when passing them to individual calls in a group
// call, so we can (and should) stop the clones once we no longer need them:
// the other clones will continue fine.
if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Usermedia) {
this.client.getMediaHandler().stopUserMediaStream(feed.stream);
} else if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Screenshare && !this.groupCallId) {
} else if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Screenshare) {
this.client.getMediaHandler().stopScreensharingStream(feed.stream);
} else if (!feed.isLocal() || !this.groupCallId) {
} else if (!feed.isLocal()) {
logger.debug("Stopping remote stream", feed.stream.id);
for (const track of feed.stream.getTracks()) {
track.stop();
Expand Down

0 comments on commit 96ee5b1

Please sign in to comment.