1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Don't store streams that are only used once (#2157)

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2022-02-08 11:13:58 +01:00
committed by GitHub
parent 07171a95c4
commit 5d4e3183aa
2 changed files with 16 additions and 6 deletions

View File

@@ -937,7 +937,7 @@ export class MatrixCall extends EventEmitter {
const upgradeVideo = video && !this.hasLocalUserMediaVideoTrack;
logger.debug(`Upgrading call: audio?=${upgradeAudio} video?=${upgradeVideo}`);
const stream = await this.client.getMediaHandler().getUserMediaStream(upgradeAudio, upgradeVideo);
const stream = await this.client.getMediaHandler().getUserMediaStream(upgradeAudio, upgradeVideo, false);
if (upgradeAudio && upgradeVideo) {
if (this.hasLocalUserMediaAudioTrack) return;
if (this.hasLocalUserMediaVideoTrack) return;
@@ -1978,7 +1978,7 @@ export class MatrixCall extends EventEmitter {
}
private stopAllMedia(): void {
logger.debug(`stopAllMedia (stream=${this.localUsermediaStream})`);
logger.debug("Stopping all media for call", this.callId);
for (const feed of this.feeds) {
if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Usermedia) {
@@ -1986,6 +1986,7 @@ export class MatrixCall extends EventEmitter {
} else if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Screenshare) {
this.client.getMediaHandler().stopScreensharingStream(feed.stream);
} else {
logger.debug("Stopping remote stream", feed.stream.id);
for (const track of feed.stream.getTracks()) {
track.stop();
}

View File

@@ -54,9 +54,12 @@ export class MediaHandler {
}
/**
* @param audio should have an audio track
* @param video should have a video track
* @param reusable is allowed to be reused by the MediaHandler
* @returns {MediaStream} based on passed parameters
*/
public async getUserMediaStream(audio: boolean, video: boolean): Promise<MediaStream> {
public async getUserMediaStream(audio: boolean, video: boolean, reusable = true): Promise<MediaStream> {
const shouldRequestAudio = audio && await this.hasAudioDevice();
const shouldRequestVideo = video && await this.hasVideoDevice();
@@ -78,7 +81,9 @@ export class MediaHandler {
stream = await navigator.mediaDevices.getUserMedia(constraints);
}
if (reusable) {
this.userMediaStreams.push(stream);
}
return stream;
}
@@ -101,9 +106,11 @@ export class MediaHandler {
}
/**
* @param desktopCapturerSourceId sourceId for Electron DesktopCapturer
* @param reusable is allowed to be reused by the MediaHandler
* @returns {MediaStream} based on passed parameters
*/
public async getScreensharingStream(desktopCapturerSourceId: string): Promise<MediaStream | null> {
public async getScreensharingStream(desktopCapturerSourceId: string, reusable = true): Promise<MediaStream | null> {
let stream: MediaStream;
if (this.screensharingStreams.length === 0) {
@@ -125,7 +132,9 @@ export class MediaHandler {
stream = matchingStream.clone();
}
if (reusable) {
this.screensharingStreams.push(stream);
}
return stream;
}