From c739037bc4206c2421440669e8c6f8466b455878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 31 Aug 2020 14:54:52 +0200 Subject: [PATCH] Camera was not properly closed in EnableCameraScene --- front/src/Phaser/Login/EnableCameraScene.ts | 3 ++ front/src/WebRtc/MediaManager.ts | 36 ++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/front/src/Phaser/Login/EnableCameraScene.ts b/front/src/Phaser/Login/EnableCameraScene.ts index 7e631b6b..6fc1cd54 100644 --- a/front/src/Phaser/Login/EnableCameraScene.ts +++ b/front/src/Phaser/Login/EnableCameraScene.ts @@ -266,6 +266,9 @@ export class EnableCameraScene extends Phaser.Scene { this.soundMeter.stop(); window.removeEventListener('resize', this.repositionCallback); + mediaManager.stopCamera(); + mediaManager.stopMicrophone(); + // Do we have a start URL in the address bar? If so, let's redirect to this address const instanceAndMapUrl = this.findMapUrl(); if (instanceAndMapUrl !== null) { diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index a043e51e..ebd2a585 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -127,7 +127,7 @@ export class MediaManager { } } - showGameOverlay(){ + public showGameOverlay(){ const gameOverlay = this.getElementByIdOrFail('game-overlay'); gameOverlay.classList.add('active'); } @@ -148,11 +148,7 @@ export class MediaManager { this.cinemaBtn.classList.add("disabled"); this.constraintsMedia.video = false; this.myCamVideo.srcObject = null; - if (this.localStream) { - this.localStream.getVideoTracks().forEach((MediaStreamTrack: MediaStreamTrack) => { - MediaStreamTrack.stop(); - }); - } + this.stopCamera(); this.getCamera().then((stream) => { this.triggerUpdatedLocalStreamCallbacks(stream); }); @@ -173,11 +169,7 @@ export class MediaManager { this.microphone.style.display = "none"; this.microphoneBtn.classList.add("disabled"); this.constraintsMedia.audio = false; - if(this.localStream) { - this.localStream.getAudioTracks().forEach((MediaStreamTrack: MediaStreamTrack) => { - MediaStreamTrack.stop(); - }); - } + this.stopMicrophone(); this.getCamera().then((stream) => { this.triggerUpdatedLocalStreamCallbacks(stream); }); @@ -287,6 +279,28 @@ export class MediaManager { } } + /** + * Stops the camera from filming + */ + public stopCamera(): void { + if (this.localStream) { + for (const track of this.localStream.getVideoTracks()) { + track.stop(); + } + } + } + + /** + * Stops the microphone from listening + */ + public stopMicrophone(): void { + if (this.localStream) { + for (const track of this.localStream.getAudioTracks()) { + track.stop(); + } + } + } + setCamera(id: string): Promise { let video = this.constraintsMedia.video; if (typeof(video) === 'boolean' || video === undefined) {