4

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?

Andrew Niefer
  • 4,279
  • 2
  • 19
  • 22
ronIDX
  • 758
  • 1
  • 5
  • 20

1 Answers1

5

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

ronIDX
  • 758
  • 1
  • 5
  • 20
  • when i stringified the list index there is property included named deviceid – owais Oct 13 '16 at 06:21
  • In my project it's working. Do you solve it or still not working? – ronIDX Oct 13 '16 at 08:24
  • mmm if I'm not wrong the call easyrtc.getVideoSourceList(function(list){....}) is async. So maybe something like could be useful for you: [Link to async function](http://pastebin.com/9ij134Gk) – ronIDX Oct 14 '16 at 15:12
  • Hey if you are using v1.0.17, as stated in changelog of new release [New EasyRTC release](https://easyrtc.com/forum/) you should use "deviceid" instead of "id" for device id. So in my code should be `list[i].deviceid`. In my code I'm using an older versione of EasyRTC, so that's why it works – ronIDX Oct 17 '16 at 08:32
  • Hi, Is your app available in app store yet? I am integrating EasyRTC with ionic as well, and I would like to take a look at it. – ShinyJos Jan 19 '18 at 04:09
  • It's a web app, not a Phonegapp/Apache Cordova. WebRTC must use HTTPS, dunno if you can use it Ionic. – ronIDX Feb 08 '18 at 10:56