Moving to async/await
This commit is contained in:
parent
7e2bf38562
commit
c322de4412
@ -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.localStream = stream;
|
||||||
this.myCamVideo.srcObject = this.localStream;
|
this.myCamVideo.srcObject = this.localStream;
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
|
||||||
//TODO resize remote cam
|
//TODO resize remote cam
|
||||||
/*console.log(this.localStream.getTracks());
|
/*console.log(this.localStream.getTracks());
|
||||||
let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video");
|
let videoMediaStreamTrack = this.localStream.getTracks().find((media : MediaStreamTrack) => media.kind === "video");
|
||||||
let {width, height} = videoMediaStreamTrack.getSettings();
|
let {width, height} = videoMediaStreamTrack.getSettings();
|
||||||
console.info(`${width}x${height}`); // 6*/
|
console.info(`${width}x${height}`); // 6*/
|
||||||
|
} catch (err) {
|
||||||
return stream;
|
|
||||||
}).catch((err) => {
|
|
||||||
console.info("error get media ", this.constraintsMedia.video, this.constraintsMedia.audio, err);
|
console.info("error get media ", this.constraintsMedia.video, this.constraintsMedia.audio, err);
|
||||||
this.localStream = null;
|
this.localStream = null;
|
||||||
throw err;
|
throw err;
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
promise = Promise.reject<MediaStream>(e);
|
|
||||||
}
|
}
|
||||||
return promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCamera(id: string): Promise<MediaStream> {
|
setCamera(id: string): Promise<MediaStream> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user