I manage to publish but not to connect to that stream from outside...

Ask any questions or talk about OpenTok here!

I manage to publish but not to connect to that stream from outside...

Postby netusco » Mon Feb 14, 2011 5:55 am

Code: Select all
Archived Post


Hi I'm trying to implement OpenTok in cakephp
so far I've managed to send the token and connect then to publish but from
another browser/computer I don't manage to get that publish shown it appears
as if there's noone publishing neither watching...
any ideas?
thanks
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby Thomas Osowski » Mon Feb 14, 2011 10:21 am

Code: Select all
Archived Post


I'd start by looking to see which session the pages are using.  Can

you confirm that both browsers are attempting to connect to the same

session?  Otherwise could you post code that connects and publishes

without your private key.

Thomas

tho...@tokbox.com

On Feb 14 4:55 am netusco <ernestcon...@gmail.com> wrote:

- Hide quoted text -
Was this post helpful? (0)
Thomas Osowski
 

I manage to publish but not to connect to that stream from outside...

Postby netusco » Mon Feb 14, 2011 11:21 am

Code: Select all
Archived Post


Hi Thomas
thanks to help!
I set to true var learn so when I connect with one browser it alerts me
this:
connectionId: 3380a295cf52c607aff5a722f5448d344d17e814
reason:
in the other browser connectionId is different...
when I stream with the first browser alert says:
streamID: 19700348
connectionId: 3380a295cf52c607aff5a722f5448d344d17e814
type: basic
name:
reason:
when streaming with the other browser again connectionId different than
first (same than second browser) and diferent streamID.
Then the code...
I've used the php API to retrieve api_key token...
    <?php
App::import('Lib' 'Opentok.ApiConfig');  //the way cakephp requires
App::import('Lib' 'opentok.OpenTokSdk');
        $apiObj = new OpenTokSDK(API_Config::API_KEY
API_Config::API_SECRET);
        $session_opTok = $apiObj->create_session($_SERVER["REMOTE_ADDR"]);
?>
        var apiKey = <?php echo json_encode(API_Config::API_KEY); ?>;
        var sessionId = '<?php print $session_opTok->getSessionId();
//changed $session to $seesion_opTok as it was breaking cakephp framework
?>';  
        var token = '<?php print $apiObj->generate_token(); ?>';
Then I'm using the sample from the web I think is the full.php one but I've
tried them all...
and the connection happens here:
    <script type="text/javascript">
        // Set debugging level if wanted
         TB.setLogLevel(TB.DEBUG);
        if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
                        alert("Unable to run TokBox OpenTok in this
browser.");
                } else {
                        // Register the exception handler and
                        // create the local session object
                        TB.addEventListener("exception" exceptionHandler);
                        session = TB.initSession(sessionId);
                        // Register all the listeners that route events to
                        // Javascript functions
            session.addEventListener("sessionConnected"
sessionConnectedHandler);
            session.addEventListener("connectionCreated"
connectionCreatedHandler);
            session.addEventListener("connectionDestroyed"
connectionDestroyedHandler);
            session.addEventListener("streamCreated" streamCreatedHandler);
            session.addEventListener("streamDestroyed"
streamDestroyedHandler);
            session.addEventListener("signalReceived" signalHandler);
            // Connect to the session
            session.connect(apiKey token);
        }
    </script>
any ideas?
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby netusco » Mon Feb 14, 2011 11:23 am

Code: Select all
Archived Post


as for publishing it uses this function though I haven't touched yet the
code from the sample...
        // Action functions
        // Called when user wants to start participating in the call
        function startPublishing() {
            // Starts publishing user local camera and mic
            // as a stream into the session
            // Create a div for the publisher to replace
            var parentDiv = document.getElementById("myCamera");
            var stubDiv = document.createElement("div");
            stubDiv.id = "opentok_publisher";
            parentDiv.appendChild(stubDiv);
            publisher = session.publish(stubDiv.id {width: PUBLISHER_WIDTH
height: PUBLISHER_HEIGHT});
            publisher.addEventListener("settingsButtonClick"
showDMDisplayPanel);
            // If there is a display panel open bind it to this publisher
            if (displayPanel)
                displayPanel.publisher = publisher;
            document.getElementById("status").innerHTML = "Trying to join
the call...";
            document.getElementById("action").innerHTML = "&nbsp;";
        }
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby netusco » Mon Feb 14, 2011 3:26 pm

Code: Select all
Archived Post


thanks to an old post I found I had changed the beggining but it still have
the same problem no matching watchers and publishers...
here the code improved though
        App::import('Lib' 'opentok.OpenTokSdk');    
        $apiObj = new OpenTokSDK(API_Config::API_KEY
API_Config::API_SECRET);
        $client = "";
        if (isset($_SERVER["REMOTE_ADDR"]))    {
            $client = $_SERVER["REMOTE_ADDR"];
        } else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))    {
            $client = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"]))    {
            $client = $_SERVER["HTTP_CLIENT_IP"];
        }
        if(isset($_REQUEST['sessionId'])) {
            $sessionId = $_REQUEST['sessionId'];
        } else {
            $session_opTok = $apiObj->create_session($client);
            $sessionId = $session_opTok->getSessionId();
        }
        $token = $apiObj->generate_token();
    ?>
    <script type="text/javascript"
src="http://static.opentok.com/v0.91/js/TB.min.js"></script>
    <script type="text/javascript">
        var apiKey = <?php print json_encode(API_Config::API_KEY); ?>;
        var sessionId = '<?php print $sessionId; ?>';
        var token = '<?php print $token; ?>';
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby Thomas Osowski » Mon Feb 14, 2011 3:45 pm

Code: Select all
Archived Post


The first thing I tried when using our PHP code was to first replace

the basictutorial.html sample with values generated with my

personalized API key and session.  This was done by printing the

sessionID and token from our PHP sample createSession.php.

I then modified the basicTutorial to hard-code (copy/paste) my API key

and sessionId -- keeping the devtoken ensures that the token

permissions isn't the issue for now.  Let me know if you can get the

html tutorial to work with your newly generated sessionId and apiKey

If you can't get the PHP replacement code working could you send the

console log for each browser:

here is part of mine:

[DEBUG] opentok: TB.setLogLevel(4)

[DEBUG] opentok: TB.addEventListener(exception)

[DEBUG] opentok: TB.removeEventListener(exception)

[DEBUG] opentok: TB.addEventListener(exception)

[DEBUG] opentok: TB.checkSystemRequirements()

[DEBUG] opentok:

TB.initSession(2340ee4a8ee543e5a2504250467dd9df3a7ad016)

Thomas

tho...@tokbox.com

On Feb 14 2:26 pm netusco <ernestcon...@gmail.com> wrote:

- Hide quoted text -
Was this post helpful? (0)
Thomas Osowski
 

I manage to publish but not to connect to that stream from outside...

Postby netusco » Mon Feb 14, 2011 6:20 pm

Code: Select all
Archived Post


with the html tutorial using devtoken and staging server I had no problem to
make it work. It actually also works after replacing all vars and shifting
to production mode the problem is as it was that there is no watchers or
publishers recognized in diferent computers/browsers. Each browser
recognizes only one watcher/publisher.
here the full log of for TB object
thanks
ONE BROWSER LOG
ACTIVE"active"BASIC_STREAM"basic"CLOSE_BUTTON_CLICK"closeButtonClick"
CONNECTION_CREATED"connectionCreated"CONNECTION_DESTROYED
"connectionDestroyed"DEBUG4DEVICES_DETECTED"devicesDetected"DEVICES_SELECTE D
"devicesSelected"DEVICE_INACTIVE"deviceInactive"EXCEPTION"exception"
GLOBAL_GROUP"global"GROUP_PROPERTIES_UPDATED"groupPropertiesUpdated"
HAS_REQUIREMENTS1INACTIVE"inactive"INFO3LOG5MULTIPLEXED_STREAM"multiplexed"
MULTIPLEXER_ACTIVITY_BASED_SWITCH1MULTIPLEXER_TIMEOUT_BASED_SWITCH0NONE0
OLD_FLASH_VERSION0SESSION_CONNECTED"sessionConnected"SESSION_DISCONNECTED
"sessionDisconnected"SETTINGS_BUTTON_CLICK"settingsButtonClick"
SIGNAL_RECEIVED"signalReceived"STREAM_CREATED"streamCreated"STREAM_DESTROYE D
"streamDestroyed"UNKNOWN"unknown"WARN2groups
Object {...}
13ddf99c54e784dbec502b37f2719ced4af63a81_global
Object {_listeners=Object groupId="global" ...}
_listeners
Object {}
groupId
"global"
sessionId
"13ddf99c54e784dbec502b37f2719ced4af63a81"
addEventListener
function()
disableEchoSuppression
function()
dispatchEvent
function()
enableEchoSuppression
function()
getGroupProperties
function()
removeEventListener
function()
superClass
function()
sessions
Object {...}
13ddf99c54e784dbec502b37f2719ced4af63a81
Object {_listeners=Object ...}
_listeners
Object {sessionConnected=[1] connectionCreated=[1] ...}
apiKey
??????
connection
Object {...}
connectionId
"6b817d79616d3478e4f9ae465522ede51fc389e2"
publishers
Object {...}
publisher_13ddf99c54e784dbec502b37f2719ced4af63a81_1
Object {...}
_listeners
Object {settingsButtonClick=[1]}
id
"publisher_13ddf99c54e784dbec502b37f2719ced4af63a81_1"
loaded
true
modified
false
properties
Object {width=220 height=165 ...}
cameraSelected
false
connectionId
"6b817d79616d3478e4f9ae465522ede51fc389e2"
height
165
publisherId
"publisher_13ddf99c54e784dbec502b37f2719ced4af63a81_1"
sessionId
"13ddf99c54e784dbec502b37f2719ced4af63a81"
token
"T1==cGFydG5lcl9pZD0yODI5OTEmc2RrX3ZlcnNpb249dGJwaHAtdjAuOTEuMjAxMS0wMi0wNy ZzaWc9ZDViYzNiYjZmZTFhYzNiZTU4Yzg4ZTViYmU0YjEwMGRjZTJjOGU5ODpzZXNzaW9uX2lkP SZjcmVhdGVfdGltZT0xMjk3NzI5NjI3JnBlcm1pc3Npb25zPSZub25jZT0xMjk3NzI5NjI3LjQ1 MTQ2MzE1OTU3"
width
220
replacedDivId
"opentok_publisher"
addEventListener
function()
disableMicrophone
function()
dispatchEvent
function()
enableMicrophone
function()
parentClass
function()
removeEventListener
function()
setCamera
function()
setMicrophone
function()
superClass
function()
sessionId
"13ddf99c54e784dbec502b37f2719ced4af63a81"
subscribers
Object {}
token
"T1==cGFydG5lcl9pZD0yODI5OTEmc2RrX3ZlcnNpb249dGJwaHAtdjAuOTEuMjAxMS0wMi0wNy ZzaWc9ZDViYzNiYjZmZTFhYzNiZTU4Yzg4ZTViYmU0YjEwMGRjZTJjOGU5ODpzZXNzaW9uX2lkP SZjcmVhdGVfdGltZT0xMjk3NzI5NjI3JnBlcm1pc3Npb25zPSZub25jZT0xMjk3NzI5NjI3LjQ1 MTQ2MzE1OTU3"
addEventListener
function()
cleanup
function()
cleanupConnection
function()
connect
function()
disconnect
function()
disconnectComponents
function()
dispatchEvent
function()
forceDisconnect
function()
forceUnpublish
function()
getPublisherForStream
function()
getSubscribersForStream
function()
publish
function()
removeEventListener
function()
signal
function()
subscribe
function()
superClass
function()
unpublish
function()
unsubscribe
function()
addEventListener
function()
checkSystemRequirements
function()
closeButtonClickHandler
function()
connectionCreatedHandler
function()
connectionDestroyedHandler
function()
deviceInactiveHandler
function()
devicesDetectedHandler
function()
devicesSelectedHandler
function()
dispatchEvent
function()
exceptionHandler
function()
groupPropertiesUpdatedHandler
function()
initDeviceManager
function()
initSession
function()
removeEventListener
function()
resizePublisherToShowSecurity
function()
resizePublisherToTarget
function()
sessionConnectedHandler
function()
sessionDisconnectedHandler
function()
setLogLevel
function()
settingsButtonClickHandler
function()
signalHandler
function()
streamCreatedHandler
function()
streamDestroyedHandler
function()
videoComponentLoadedHandler
function()
ERROR
1
RESIZE
"resize"
NEXT BROWSER LOG
ACTIVE"active"
BASIC_STREAM"basic"
CLOSE_BUTTON_CLICK"closeButtonClick"
CONNECTION_CREATED"connectionCreated"
CONNECTION_DESTROYED"connectionDestroyed"
DEBUG4
DEVICES_DETECTED"devicesDetected"
DEVICES_SELECTED"devicesSelected"
DEVICE_INACTIVE"deviceInactive"
ERROR1
EXCEPTION"exception"
GLOBAL_GROUP"global"
GROUP_PROPERTIES_UPDATED"groupPropertiesUpdated"
HAS_REQUIREMENTS1
INACTIVE"inactive"
INFO3
LOG5
MULTIPLEXED_STREAM"multiplexed"
MULTIPLEXER_ACTIVITY_BASED_SWITCH1
MULTIPLEXER_TIMEOUT_BASED_SWITCH0
NONE0
OLD_FLASH_VERSION0
RESIZE"resize"
SESSION_CONNECTED"sessionConnected"
SESSION_DISCONNECTED"sessionDisconnected"
SETTINGS_BUTTON_CLICK"settingsButtonClick"
SIGNAL_RECEIVED"signalReceived"
STREAM_CREATED"streamCreated"
STREAM_DESTROYED"streamDestroyed"
UNKNOWN"unknown"
WARN2
groupsObject { 190fbcc07315ad7c4836785ec0c415bca7f6b049_global={...}}
190fbcc07315ad7c4836785ec0c415bca7f6b049_globalObject { _listeners={...}
groupId="global" sessionId="190fbcc07315ad7c4836785ec0c415bca7f6b049"}
_listenersObject {}
groupId"global"
sessionId"190fbcc07315ad7c4836785ec0c415bca7f6b049"
addEventListenerfunction()
disableEchoSuppressionfunction()
dispatchEventfunction()
enableEchoSuppressionfunction()
getGroupPropertiesfunction()
removeEventListenerfunction()
superClassT()
sessionsObject { 190fbcc07315ad7c4836785ec0c415bca7f6b049={...}}
190fbcc07315ad7c4836785ec0c415bca7f6b049Object { _listeners={...}
sessionId="190fbcc07315ad7c4836785ec0c415bca7f6b049" more...}
_listenersObject { sessionConnected= connectionCreated= more...}
apiKey??????
connectionObject { connectionId="07d333086557507219fc500be6d721a90588174f"}
connectionId"07d333086557507219fc500be6d721a90588174f"
publishersObject {
publisher_190fbcc07315ad7c4836785ec0c415bca7f6b049_1={...}}
publisher_190fbcc07315ad7c4836785ec0c415bca7f6b049_1Object {
id="publisher_190fbcc07315a...6785ec0c415bca7f6b049_1"
replacedDivId="opentok_publisher" more...}
_listenersObject { settingsButtonClick=}
id"publisher_190fbcc07315ad7c4836785ec0c415bca7f6b049_1"
loadedtrue
modifiedfalse
propertiesObject { width=220 height=165 more...}
cameraSelectedfalse
connectionId"07d333086557507219fc500be6d721a90588174f"
height165
publisherId"publisher_190fbcc07315ad7c4836785ec0c415bca7f6b049_1"
sessionId"190fbcc07315ad7c4836785ec0c415bca7f6b049"
token
"T1==cGFydG5lcl9pZD0yODI5OTEmc2RrX3ZlcnNpb249dGJwaHAtdjAuOTEuMjAxMS0wMi0wNy ZzaWc9MTRiZWVlZTZkNDhmZDM5OTk1MDY2ZDVjZDU4MDg5NTg0NjAxNmI4NzpzZXNzaW9uX2lkP SZjcmVhdGVfdGltZT0xMjk3NzMxNzg1JnBlcm1pc3Npb25zPSZub25jZT0xMjk3NzMxNzg1LjE2 NTY4Nzg2OTIz"
width220
replacedDivId"opentok_publisher"
addEventListenerfunction()
disableMicrophonefunction()
dispatchEventfunction()
enableMicrophonefunction()
parentClassT()
removeEventListenerfunction()
setCamerafunction()
setMicrophonefunction()
superClassB(ae ad)
sessionId"190fbcc07315ad7c4836785ec0c415bca7f6b049"
subscribersObject {}
token"T1==cGFydG5lcl9pZD0yODI...zMxNzg1LjE2NTY4Nzg2OTIz"
addEventListenerfunction()
cleanupfunction()
cleanupConnectionfunction()
connectfunction()
disconnectfunction()
disconnectComponentsfunction()
dispatchEventfunction()
forceDisconnectfunction()
forceUnpublishfunction()
getPublisherForStreamfunction()
getSubscribersForStreamfunction()
publishfunction()
removeEventListenerfunction()
signalfunction()
subscribefunction()
superClassT()
unpublishfunction()
unsubscribefunction()
addEventListenerfunction()
checkSystemRequirementsfunction()
closeButtonClickHandlerfunction()
connectionCreatedHandlerfunction()
connectionDestroyedHandlerfunction()
deviceInactiveHandlerfunction()
devicesDetectedHandlerfunction()
devicesSelectedHandlerfunction()
dispatchEventfunction()
exceptionHandlerfunction()
groupPropertiesUpdatedHandlerfunction()
initDeviceManagerfunction()
initSessionfunction()
removeEventListenerfunction()
resizePublisherToShowSecurityfunction()
resizePublisherToTargetfunction()
sessionConnectedHandlerfunction()
sessionDisconnectedHandlerfunction()
setLogLevelfunction()
settingsButtonClickHandlerfunction()
signalHandlerfunction()
streamCreatedHandlerfunction()
streamDestroyedHandlerfunction()
videoComponentLoadedHandlerfunction()
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby Thomas Osowski » Mon Feb 14, 2011 6:48 pm

Code: Select all
Archived Post


Thanks for the variable list for each browser.  You mentioned "I had

no problem to make it work."  Are you saying hard-coding the sessionID

allows you to publish/watch or that it simply publishes?

Looking at the values posted it looks like the web pages are

attempting to connect to different sessions: sessionId =

13ddf99c54e784dbec502b37f2719ced4af63a81 and sessionId =

190fbcc07315ad7c4836785ec0c415bca7f6b049

Sessions should be seen as the chat room where both browsers will need

to connect to.  Hard-coding the sessionId to one of the above values

should allow the application to see both watcher and publisher.  The

following link should provide a better picture of what is actually

happening: http://www.tokbox.com/opentok/build/doc ... itialize...

So that being said the server-side code will need additional logic to

manage creating sessionIds only when they are needed as they can be re-

used and don't expire.

Please let me know whether or not I'm understanding your issue

correctly.

Thomas

tho...@tokbox.com

On Feb 14 5:20 pm netusco <ernestcon...@gmail.com> wrote:

- Hide quoted text -
Was this post helpful? (0)
Thomas Osowski
 

I manage to publish but not to connect to that stream from outside...

Postby netusco » Tue Feb 15, 2011 3:59 am

Code: Select all
Archived Post


thanks Thomas and yes you understand  it correctly.
I didn't get before that sessionID should be the same. That helps me to
understand better my problem.
So now if I copy/paste one id as sessionID static then it works all
watchers and publishers from diferent browsers/computers.
Then I had checked the code that was generating that sessionID...
So here my questions..
why do we need to generate that session ID if it could be hard coded and as
you say it never expires... couldn't it be given as it is the API_key or
secret...?
or there is a need to generate it sometimes...?
In my case the generation of the sessionID works as I generate Ids but they
are not the same for diferent watchers... I've checked the code and actually
I haven't touched a single coma from the one of your server-side
libraries... so to me the problem might be in the answer from the query
sended to opentok server.
I then got a new key and registered again and tried again but with the same
results... (I registered the key with the root ulr of the aplication
www.myapp.com not with the
propper path where there is the videochat  www.myapp.com/videochat/index.php
)  is that correct?
I would really like to know what's happening any clues?
Was this post helpful? (0)
netusco
 

I manage to publish but not to connect to that stream from outside...

Postby Thomas Osowski » Thu Feb 17, 2011 12:17 pm

Code: Select all
Archived Post


It is great to hear that you are now able to generate sessions and
tokens using your own API key.  The next step is to manage creating
sessions and managing connections to them.
Sesssions (identified by their sessionID) provide a virtual meeting room
where multiple users (one connection per browser) connect to.  When
sessions are created they exist on our media server closest to the
address passed in when creating the session.
We'll take the first case where we use only one session (with its
sessionID) -- the hard-coded example. This is what occurs in our
basictutorial on our website and it allows all users to publish and
watch.  If we wanted to restrict access the application would have to
build logic to manage users (connections).  Once a user connects to a
session (with a newly generated token) a sessionConnected event is
fired that contains all currently connected users (connectionIDs). More
info here:
http://www.tokbox.com/opentok/build/doc ... itialize...
Say you have four users A B X and Y joining a single session.  If you
only want (A B) and (X Y) to view each other the application-side
code would need to manage the streams that each user (connection) can
subscribe to.
For example say that all users connect to the session and publish their
streams.  A streamCreated event gets fired to each user (connection).  
Each user will be notified when a stream is available for (A B X and
Y).   If we are user A's browser (connection) we would only handle the
event where the connection id is B.connectionID.  This means we would
ignore the connection ID for A X and Y.  In this case it is then up
to the developer to manage which user (connection) should subscribe to
the desired stream.
http://www.tokbox.com/opentok/build/doc ... blish.html
So with this example the application would need to manage which
connections should connect to each other.  Additionally there is a
limit of 20 broadcasting connections and the session might not be
situated on a server close to the users.
Another scenario is creating new sessions dynamically.  Using the
scenario above we could generate two new session IDs one for users A
and B and another for users X and Y.  Here the user management
(listening for specific connectionIDs) is removed and connections can
subscribe to all streams in the session.
I believe that a mixture of these techniques can fit most use cases.  
Applications you can use permanent sessions for static discussion rooms
and generate new sessions when spawning new 1:1 chats.
With all of this in mind sessions don't need to be created every time a
browser connects to the site.  I know this is a lot of information to
take in so let me know if you need me to clarify part of this.
Thomas
tho...@tokbox.com
On 2/15/2011 2:59 AM netusco wrote:
- Hide quoted text -
Was this post helpful? (0)
Thomas Osowski
 

Next

Return to Discussion and Questions



Who is online

Users browsing this forum: No registered users and 2 guests

cron