fixed a game crash on firefox on http
authorkharhamel <oognic@gmail.com>
Wed, 13 May 2020 14:56:22 +0000 (16:56 +0200)
committerkharhamel <oognic@gmail.com>
Wed, 13 May 2020 14:56:22 +0000 (16:56 +0200)
front/src/WebRtc/MediaManager.ts

index 5ebbc0c7402a9e43ba95c855a677f915fa50f6fd..1dabf2c6263925dcfef90aa9016a581bfb70b684 100644 (file)
@@ -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;
     }
 
     /**