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
getCamera(): Promise<MediaStream> {
let promise = null;
async getCamera(): Promise<MediaStream> {
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 {
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<MediaStream>(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<MediaStream> {