Browser-Phone icon indicating copy to clipboard operation
Browser-Phone copied to clipboard

camera

Open prathibhacdac opened this issue 2 years ago • 1 comments

camera changed from back cam to front. But there is no change in the remote video. It still shows the back cam.

prathibhacdac avatar Feb 15 '23 04:02 prathibhacdac

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.

InnovateAsterisk avatar Feb 15 '23 07:02 InnovateAsterisk

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.

prathibhacdac avatar Mar 19 '24 09:03 prathibhacdac

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);
});

prathibhacdac avatar Mar 19 '24 11:03 prathibhacdac