diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index 50f4bf15..cdee2ae8 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -125,35 +125,33 @@ export class MediaManager { } //get camera - getCamera(): Promise { - let promise = null; - + async getCamera(): Promise { if (navigator.mediaDevices === undefined) { - return Promise.reject(new Error('Unable to access your camera or microphone. Your browser is too old (or you are running a development version of WorkAdventure on Firefox)')); + if (window.location.protocol === 'http:') { + throw new Error('Unable to access your camera or microphone. You need to use a HTTPS connection.'); + } else { + throw new Error('Unable to access your camera or microphone. Your browser is too old.'); + } } try { - promise = navigator.mediaDevices.getUserMedia(this.constraintsMedia) - .then((stream: MediaStream) => { - this.localStream = stream; - this.myCamVideo.srcObject = this.localStream; + let stream = await navigator.mediaDevices.getUserMedia(this.constraintsMedia); - //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*/ + this.localStream = stream; + this.myCamVideo.srcObject = this.localStream; - return stream; - }).catch((err) => { - console.info("error get media ", this.constraintsMedia.video, this.constraintsMedia.audio, err); - this.localStream = null; - throw err; - }); - } catch (e) { - promise = Promise.reject(e); + return stream; + + //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*/ + } catch (err) { + console.info("error get media ", this.constraintsMedia.video, this.constraintsMedia.audio, err); + this.localStream = null; + throw err; } - return promise; } setCamera(id: string): Promise {