1

we are using peer js webrtc for video call. Everything is working fine just the problem is i am not able to switch camera during call. I have done some work where i can switch camera in local during call but its doesnt effect on remote area.

here is my code

$('select').on('change', function (e) {
    navigator.mediaDevices.enumerateDevices().then(function (devices) {
     
        var valueSelected = $("#myselect option:selected").val();
        alert(valueSelected);
        //var myselect = 0;

        if (valueSelected == "0") {
            var cameras = [];
            devices.forEach(function (device) {
                'videoinput' === device.kind && cameras.push(device.deviceId);
            });
            var constraints = { video: { deviceId: { exact: cameras[0] } } };

            navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
             

              
                    window.localStream = stream;
                
                myapp.setMyVideo(window.localStream)
              
                //if (callback)
                //    callback();
            }, function (err) {
                console.log("The following error occurred: " + err.name);
                alert('Unable to call ' + err.name)
            });
        }
        else {
            var cameras = [];
            devices.forEach(function (device) {
                'videoinput' === device.kind && cameras.push(device.deviceId);
            });
            var constraints = { video: { deviceId: { exact: cameras[1] } } };

            navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
              

            
                    window.localStream = stream;
               

                myapp.setMyVideo(window.localStream)
                //if (callback)
                //    callback();
            }, function (err) {
                console.log("The following error occurred: " + err.name);
                alert('Unable to call ' + err.name)
            });
        }
        //var myselect = $("#myselect option:selected").val();

       
    });
});

1 Answer 1

1

The recommended way to change stream when a peer-to-peer connection is established is to use replaceTrack function that does not require ICE renegotiation: RTCRtpSender.replaceTrack

The documentation says:

Among the use cases for replaceTrack() is the common need to switch between the rear- and front-facing cameras on a phone. With replaceTrack(), you can simply have a track object for each camera and switch between the two as needed. See the example...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.