From e2531343d12a4a41288e69ff1d5075566ac8f6be Mon Sep 17 00:00:00 2001 From: kharhamel Date: Wed, 13 May 2020 16:56:22 +0200 Subject: [PATCH] fixed a game crash on firefox on http --- front/src/WebRtc/MediaManager.ts | 40 ++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index 5ebbc0c..1dabf2c 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -115,23 +115,29 @@ export class MediaManager { //get camera getCamera() { - return this.getCameraPromise = navigator.mediaDevices.getUserMedia(this.constraintsMedia) - .then((stream: MediaStream) => { - this.localStream = stream; - this.myCamVideo.srcObject = this.localStream; - - //TODO resize remote cam - /*console.log(this.localStream.getTracks()); - let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video"); - let {width, height} = videoMediaStreamTrack.getSettings(); - console.info(`${width}x${height}`); // 6*/ - - return stream; - }).catch((err) => { - console.error(err); - this.localStream = null; - throw err; - }); + let promise = null; + try { + promise = navigator.mediaDevices.getUserMedia(this.constraintsMedia) + .then((stream: MediaStream) => { + this.localStream = stream; + this.myCamVideo.srcObject = this.localStream; + + //TODO resize remote cam + /*console.log(this.localStream.getTracks()); + let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video"); + let {width, height} = videoMediaStreamTrack.getSettings(); + console.info(`${width}x${height}`); // 6*/ + + return stream; + }).catch((err) => { + console.error(err); + this.localStream = null; + throw err; + }); + } catch (e) { + promise = Promise.reject(false); + } + return this.getCameraPromise = promise; } /** -- 2.25.1