Moving to async/await

This commit is contained in:
David Négrier 2020-06-25 10:43:27 +02:00
parent 7e2bf38562
commit c322de4412
1 changed files with 20 additions and 22 deletions

View File

@ -125,35 +125,33 @@ export class MediaManager {
} }
//get camera //get camera
getCamera(): Promise<MediaStream> { async getCamera(): Promise<MediaStream> {
let promise = null;
if (navigator.mediaDevices === undefined) { if (navigator.mediaDevices === undefined) {
return Promise.reject<MediaStream>(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 { try {
promise = navigator.mediaDevices.getUserMedia(this.constraintsMedia) let stream = await navigator.mediaDevices.getUserMedia(this.constraintsMedia);
.then((stream: MediaStream) => {
this.localStream = stream;
this.myCamVideo.srcObject = this.localStream;
//TODO resize remote cam this.localStream = stream;
/*console.log(this.localStream.getTracks()); this.myCamVideo.srcObject = this.localStream;
let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video");
let {width, height} = videoMediaStreamTrack.getSettings();
console.info(`${width}x${height}`); // 6*/
return stream; return stream;
}).catch((err) => {
console.info("error get media ", this.constraintsMedia.video, this.constraintsMedia.audio, err); //TODO resize remote cam
this.localStream = null; /*console.log(this.localStream.getTracks());
throw err; let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video");
}); let {width, height} = videoMediaStreamTrack.getSettings();
} catch (e) { console.info(`${width}x${height}`); // 6*/
promise = Promise.reject<MediaStream>(e); } 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<MediaStream> { setCamera(id: string): Promise<MediaStream> {