InnovateAsterisk / Browser-Phone

A fully featured browser based WebRTC SIP phone for Asterisk
https://www.innovateasterisk.com
GNU Affero General Public License v3.0
499 stars 245 forks source link

camera #438

Closed prathibhacdac closed 6 months ago

prathibhacdac commented 1 year ago

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

InnovateAsterisk commented 1 year ago

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.

prathibhacdac commented 6 months ago

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 commented 6 months ago

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