I’ve tested the following code and it works perfectly on every device i’ve used except one Huawei android device. When the camera changes to one of the back ones it throws an error in the console saying the device is already in use, but it’s not in use! I’m literally using the front camera on the website and switching it to the back, nothing else is using the device.
I have 2 questions:
-
What would be causing it to say the device is in use when it isn’t, and how do we get around this?
-
The little snippet of code below, OVSession.publish is a promise, yet if i attach a catch() to it it doesn’t catch the promise rejection, instead it just puts an error in the console which isn’t helpful! This is using openvidu browser 2.20.0
this.OVSession.publish(this.OVPublisher).then(()=>{
console.log("NEW PUBLISHER DONE")
})
FULL CODE BELOW OF CAMERA SWITCHING
this.OV.getDevices().then((devices)=> {
console.log("DEVICES",devices)
let videoDevices = []
if(this.OVCurrentCamera === 'front'){
videoDevices = devices.filter(device => device.kind === 'videoinput' && device.label !== 'Snap Camera' && device.label.toLowerCase().indexOf('back') !== -1);
}else{
videoDevices = devices.filter(device => device.kind === 'videoinput' && device.label !== 'Snap Camera' && device.label.toLowerCase().indexOf('front') !== -1);
}
if(!videoDevices || videoDevices.length === 0){
console.log("NO VIDEO DEVICES FOUND",videoDevices)
videoDevices = devices.filter(device => device.kind === 'videoinput' && device.label !== 'Snap Camera');
}
if(videoDevices && videoDevices.length > 0){
console.log("FOUND VIDEO DEVICES",videoDevices)
// get new device id
// if we already on front the back device is the last one in the list otherwise the first
let newDeviceId = this.OVCurrentCamera === 'front' ? videoDevices[videoDevices.length - 1].deviceId : videoDevices[0].deviceId;
console.log("NEW DEVICE ID",newDeviceId)
let newPublisher = this.OV.initPublisher("publisher-video",{
videoSource: newDeviceId,
publishAudio: !this.muted,
publishVideo: this.camOn,
frameRate: 24,
mirror: this.OVCurrentCamera === 'back' // mirror the video if we are switching FROM back - at this point it will be back
});
this.OVSession.unpublish(this.OVPublisher).then(() => {
console.log("OLD PUBLISHER IS GONE")
this.OVPublisher = newPublisher;
this.OVCurrentCamera = this.OVCurrentCamera === 'front' ? 'back' : 'front';
this.OVSession.publish(this.OVPublisher).then(()=>{
console.log("NEW PUBLISHER DONE")
})
}).catch(() => {
this.toast.error('Failed to switch camera, try again!');
this.OVCurrentCamera = this.OVCurrentCamera === 'front' ? 'back' : 'front';
})
}else{
this.toast.error('Could Not Load Your Cameras');
}
})