Search code examples
node.jscamerawebrtceasyrtc

EasyRTC - Change camera source


I'm developing a videochat using EasyRTC framework.

I have built up a small web application using Node.JS as server.

Everything is working fine and I can make video call.

When I'm using it from tablet or smartphone, default camera is front camera.

How can I switch to back camera?


Solution

  • After some search in source code, I’m able to set back camera in this way:

    easyrtc.getVideoSourceList( function(list) {
           var i;
           for( i = 0; i < list.length; i++ ) {
             alert("label=" + list[i].label + ", id= " + list[i].id);
    
             if(list[i].label.indexOf('back') > 0){  // Searching for label containing back (for back camera)
                 easyrtc.setVideoSource(list[i].id);  // Set the id of back camera. Must be called before easyrtc.initMediaSource()
                 easyrtc.initMediaSource(
                       function(){       // success callback
                           var selfVideo = document.getElementById("self");
                           easyrtc.setVideoObjectSrc(selfVideo, easyrtc.getLocalStream());
                           easyrtc.connect("Company_Chat_Line", connectSuccess, connectFailure);
                       },connectFailure
                 );
    
                 break;
             }
           } 
    

    For version v1.0.17 use list[i].deviceid instead of list[i].id