Hey OpenTok,
I am Taking a plain html and generating session and token from opentok server side libraries and passing these three values as static content to html.
But Session is connected and sessionConnectedHandler(event) is not firing and showing the message dialog.
The Connection timeout. Make Sure that You have allowed this page in FlashPlayer Global Settings Manager.
Goto:http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
But i have added my file location and started my browser even then same error;
Please get me out of it:
Here is my code,
<html>
<head>
<script src="http://static.opentok.com/v0.91/js/TB.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" language="javascript">
var tokenGen ="T1==cGFydG5lcl9pZD0yMTMwODc0MSZzZGtfdmVyc2lvbj10YmRvdG5ldCZzaWc9ZGJhYTRmYWFkNWM0Y2I5YTQ4YTIzM2JjZjc2YTM3YmIwYTMzMmJjODpjb25uZWN0aW9uX2RhdGE9NTA0JnNlc3Npb25faWQ9Ml9NWDR5TVRNd09EYzBNWDR4TUM0eE1DNHhNQzR6TjM1R2Nta2dUbTkySURBeUlESXpPalV4T2pVNElGQkVWQ0F5TURFeWZqQXVNRGMwTnpRNU1qbC0mY3JlYXRlX3RpbWU9MTM1MTkyNTY2MyZub25jZT0xMDE4OTEmcm9sZT1wdWJsaXNoZXI=";
var apiKey =21308741;
var sessionId = "2_MX4yMTMwODc0MX4xMC4xMC4xMC4zN35GcmkgTm92IDAyIDIzOjUxOjU4IFBEVCAyMDEyfjAuMDc0NzQ5Mjl-";
var VIDEO_WIDTH = 310;
var VIDEO_HEIGHT = 200;
var VIDEO_WIDTH1 = 310;
var VIDEO_HEIGHT1 = 400;
var publisher;
var session;
var subscribers = {};
var txt="";
function StartConference() {
alert("Conf Started");
TB.setLogLevel(TB.DEBUG);
TB.addEventListener("exception", exceptionHandler);
if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
alert("Please upgrade to the latest version of Flash.");
} else {
connect();
}
}
//To start the connecation
function connect() {
alert("connect called");
session = TB.initSession(sessionId); // Initialize session
alert("session intiialized");
// Add event listeners to the session
session.addEventListener('sessionConnected', sessionConnectedHandler);
session.addEventListener('streamCreated', streamCreatedHandler);
session.addEventListener('connectionCreated', connectionCreatedHandler);
session.addEventListener('sessionDisconnected', sessionDisconnectedHandler);
session.addEventListener('connectionDestroyed', connectionDestroyedHandler);
session.addEventListener('streamDestroyed', streamDestroyedHandler);
session.connect(apiKey, tokenGen);
alert("session connected");
}
//To disconnection the session
function leaveConference() {
session.disconnect();
}
//To start publishing our video
function startPublishing() {
if (!publisher) {
alert("publishing my video started");
var parentDiv = document.getElementById('myCamera');
// Create a div for the publisher to replace
var publisherDiv = document.createElement('div');
publisherDiv.setAttribute('id', 'opentok_publisher');
parentDiv.appendChild(publisherDiv);
var publisherProps = { width: VIDEO_WIDTH, height: VIDEO_HEIGHT };
// Pass the replacement div id and properties
publisher = TB.initPublisher(apiKey, publisherDiv.id, publisherProps);
session.publish(publisher);
alert("publishing my video finished");
}
}
//This is Our Video
function sessionConnectedHandler(event) {
alert("fired");
alert(event.streams.length+"My Stream");
startPublishing();
for (var i = 0; i < event.streams.length; i++) {
subscribeToStreams(event.streams[i]);
}
}
//New Arrived Streams
function streamCreatedHandler(event) {
alert(event.streams.length+"Other Streams");
startPublishing();
for (var i = 0; i < event.streams.length; i++) {
subscribeToStreams(event.streams[i]);
}
// Subscribe to any new streams that are created
}
function streamDestroyedHandler(event) {
// This signals that a stream was destroyed. Any Subscribers will automatically be removed.
// This default behaviour can be prevented using event.preventDefault()
}
//
function sessionDisconnectedHandler(event) {
// will automatically be removed. This default behaviour can be prevented using event.preventDefault()
publisher = null;
window.top.location = "Meeting.aspx";
}
function connectionDestroyedHandler(event) {
// This signals that connections were destroyed
}
function connectionCreatedHandler(event) {
// This signals new connections have been created.
}
//Streams of that session
function subscribeToStreams(stream) {
alert(event.streams.length);
if (stream.connection.connectionId == session.connection.connectionId) {
return;
}
var subscriberDiv = document.createElement('div'); // Create a div for the subscriber to replace
subscriberDiv.setAttribute('id', stream.streamId); // Give the replacement div the id of the stream as its id.
document.getElementById("subscribers").appendChild(subscriberDiv);
var subscriberProps = {height: VIDEO_HEIGHT1, width: VIDEO_WIDTH1 };
//subscribers[stream.streamId] =
session.subscribe(stream, subscriberDiv.id, subscriberProps);
}
//Exception Handler
function exceptionHandler(event) {
// Retry session connect
if (event.code === 1006 || event.code === 1008 || event.code === 1014) {
alert('There was an error connecting. Trying again.');
session.connect(apiKey, tokenGen);
}
}
//To Show and Hide the controls..
function show(id) {
document.getElementById(id).style.display = 'block';
}
function hide(id) {
document.getElementById(id).style.display = 'none';
}
</script>
</head>
<body onload="StartConference();">
<div class="span-17half last">
<div class="span-8 last" id="myCamera" style="float: left;border:1px solid #999999;"></div>
<div class="span-8 last" id="subscribers" style="float: left;border:1px solid #999999;margin-left:10px;"></div>
</div>
</body>
</html>