getCamera() {
let promise = null;
try {
- promise = navigator.mediaDevices.getUserMedia(this.constraintsMedia)
- .then((stream: MediaStream) => {
- this.localStream = stream;
- this.myCamVideo.srcObject = this.localStream;
+ promise = navigator.mediaDevices.enumerateDevices()
+ .then(devices => {
+ let cams = devices.filter(device => device.kind == "videoinput");
+ if (cams.length == 0){
+ this.constraintsMedia.video = false;
+ document.getElementsByClassName("btn-video")[0].style.display = "none";
+ document.getElementById("div-myCamVideo").style.display = "none";
+ }
+ return navigator.mediaDevices.getUserMedia(this.constraintsMedia).then((stream: MediaStream) => {
+ this.localStream = stream;
+ this.myCamVideo.srcObject = this.localStream;
+ return stream;
+ }).catch((err) => {
+ console.info(`error get media {video: ${this.constraintsMedia.video}},{audio: ${this.constraintsMedia.audio}}`,err);
+ this.localStream = null;
+ })
+ })
- //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.info(`error get media {video: ${this.constraintsMedia.video}},{audio: ${this.constraintsMedia.audio}}`,err);
- this.localStream = null;
- });
} catch (e) {
promise = Promise.reject(false);
}