songz / cordova-plugin-opentok

Cordova Plugin for OpenTok - add webrtc video to your iOS or Android App
Other
162 stars 270 forks source link

change camera position #98

Closed tantaroth closed 10 years ago

tantaroth commented 10 years ago

I am trying to change the camera position from front to back while having a video call, but when I change it the app crashes and both videos freezes. What is the correct way of doing this? Here is my code:

//My data conection with plugin var data = new Object(); data.apiKey = "my_apikey"; data.sessionId = "my_session_id"; data.token = "my_token"; data.sid = "my_session_id";

        // Very simple OpenTok Code for group video chat
       //cameraName:'front' for default is front but i want change with click
        publisher_p = TB.initPublisher(data.apiKey,"myPublisherDiv-P",{cameraName:'front'});

        session_p = TB.initSession( data.apiKey, data.sid );
        session_p.on({
            'streamCreated': function( event ){
                session_p.subscribe( event.stream, "myFriendDiv-P", {subscribeToAudio: true} );
            },
            'streamDestroyed': function( event ) {
                session_p.unpublish();
                session_p.disconnect();
            }
        });
        session_p.connect(data.token, function(){
            session_p.publish( publisher_p );
        });

I know with "cameraName" change the camera to "back" or "front" but i want change the camera with a event of button(javascript or jquery).

cameraName for default init the application with the value content, for example in the code up.

I want change the camera position to click button, for example:

$(document).ready(function(){ $(".buttonChangeCamera").click(function(){ //event to change camera position "back" or "front }); });

silverio commented 10 years ago

Anyone has a sample code to change the camera position, and turn on/off the mic without crashing the app?

darkpgx commented 10 years ago

Hi tantaroth,

So in the click event you can bind the function called setCameraPosition to your publisherDiv. The setCameraPositon function takes in the parameter "front" or "back", which changes the camera position accordingly.

for example, in jQuery:

$(".buttonChangeCamera").click(function(){ publisher.setCameraPosition("front"); //or "back" });

this will change the camera position accordingly.

I hope this solves your problem.

songz commented 10 years ago

Can you put in some crash logs? its weird that it should be crashing. Android does not seem to support setCameraPosition method, filed an issue for it: https://github.com/songz/cordova-plugin-opentok/issues/101

songz commented 10 years ago

@darkpgx 's suggestion for changing front and back camera works, I tested with iOS and Android after trying out #102 . Closing this issue. If you still experiencing crashing @jfsemaan and @tantaroth , please open up a new ticket and describe how to reproduce the crash.

tantaroth commented 10 years ago

@darkpgx, @songz thank you for your help! it worked great!