Browser-Phone
Browser-Phone copied to clipboard
camera
camera changed from back cam to front. But there is no change in the remote video. It still shows the back cam.
This project is not optimised for mobile devices. It may work, and it may not work. In my testing, I have seen all sorts of issue with this.
On mobile this is referred to as facing mode: https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode but on Desktop, this hint is meaningless.
While changing the front camera to back camera, I get the following error: Error on getUserMedia DOMException: Could not start video source
No one else is using the webcam.
In Windows, switching the camera works fine. Whereas the above error occurs on Android.
Switch camera is now working in android as well.
We need to stop the previous mediaStreamObj before calling getUserMedia again. In switchVideoSource function add
pc.getSenders().forEach(function (RTCRtpSender) {
if(RTCRtpSender.track && RTCRtpSender.track.kind == "video") {
RTCRtpSender.track.stop();
}
});
navigator.mediaDevices.getUserMedia(constraints).then(function(newStream){
var newMediaTrack = newStream.getVideoTracks()[0];
console.log("New Media Track",newMediaTrack);
// var pc = session.sessionDescriptionHandler.peerConnection;
pc.getSenders().forEach(function (RTCRtpSender) {
if(RTCRtpSender.track && RTCRtpSender.track.kind == "video") {
console.log("Switching Video Track : "+ RTCRtpSender.track.label + " to "+ newMediaTrack.label);
//RTCRtpSender.track.stop();
RTCRtpSender.replaceTrack(newMediaTrack);
localStream.addTrack(newMediaTrack);
}
});
}).catch(function(e){
console.error("Error on getUserMedia", e.name, e.message, constraints);
});