- Code: Select all
Archived Post
Hi everyone.I was working with the php sdk last night and unfortuately could not run the code on thr server.code below:<?php/*!* OpenTok PHP Library* http://www.tokbox.com/** Copyright 2010, TokBox, Inc.**/
<?php require_once 'SDK/API_Config.php'; require_once 'SDK/OpenTokSDK.php'; require_once 'SDK/SessionPropertyConstants.php';
$apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);
$session = $apiObj->create_session($_SERVER["REMOTE_ADDR"]; array(SessionPropertyConstants::MULTIPLEXER_NUMOUTPUTSTREAMS=>2; SessionPropertyConstants::MULTIPLEXER_SWITCHTYPE=>1; SessionPropertyConstants::MULTIPLEXER_SWITCHTIMEOUT=>5000)); echo $session->getSessionId();?>?>
<html><head>
<title>chrome</title> <script src="http://static.opentok.com/v0.91/js/TB.min.js"></script><script type="text/javascript" src="/scripts/application.js"></script><script type="text/javascript">
var apiKey = "2248802";var sessionId = '<?php print $sessionId; ?>';var token = '<?php print $apiObj->generate_token($sessionId); ?>';
var session;
TB.addEventListener('exception', exceptionHandler); session = TB.initSession(sessionId);
//Video chat event listeners session.addEventListener('sessionConnected', sessionConnectedHandler); session.addEventListener('streamCreated', streamCreatedHandler); session.addEventListener('streamDestroyed', streamDestroyedHandler);
session.connect(apiKey, token);
</script>
</head><body>
</body></html>1. when i run it on my browser this is what i get:create_session($_SERVER["REMOTE_ADDR"]; array(SessionPropertyConstants::MULTIPLEXER_NUMOUTPUTSTREAMS=>2; SessionPropertyConstants::MULTIPLEXER_SWITCHTYPE=>1; SessionPropertyConstants::MULTIPLEXER_SWITCHTIMEOUT=>5000)); echo $session->getSessionId(); ?> ?>2.I did create a foder named SDK and placed the following components/files inside:
/OpenTokSDK.php'; SessionPropertyConstants.phpSessionPropertyConstants.phpIm new with php, could someone help me?the aplication.js script is below:// Place your application-specific JavaScript functions and classes here// This file is automatically included by javascript_include_tag :defaults
var videos = 1;
var publisher; var publisherObj;
var subscribers = {}; var subscriberObj = {};
var MAX_WIDTH_VIDEO = 264; var MAX_HEIGHT_VIDEO = 198;
var MIN_WIDTH_VIDEO = 200; var MIN_HEIGHT_VIDEO = 150; var MAX_WIDTH_BOX = 800; var MAX_HEIGHT_BOX = 600;
var CURRENT_WIDTH = MAX_WIDTH_VIDEO; var CURRENT_HEIGHT = MAX_HEIGHT_VIDEO; function sessionConnectedHandler(event) { publish(); for (var i = 0; i < event.streams.length; i++) { addStream(event.streams[i]); } }
function streamCreatedHandler(event) { for (var i = 0; i < event.streams.length; i++) { addStream(event.streams[i]); } }
function streamDestroyedHandler(event) { videos--; layoutManager(); }
function exceptionHandler(event) { alert("Exception msg:" + event.message + "title: " + event.title + " code: " + event.code); }
//-------------------------------------- // HELPER METHODS //-------------------------------------- function addStream(stream) { // Check if this is the stream that I am publishing. If not // we choose to subscribe to the stream. if (stream.connection.connectionId == session.connection.connectionId) { return; }
var div = document.createElement('div'); // Create a replacement div for the subscriber var divId = stream.streamId; // Give the replacement div the id of the stream as its id div.setAttribute('id', divId); document.getElementById("videobox").appendChild(div); subscriberObj[stream.streamId] = div; subscribers[stream.streamId] = session.subscribe(stream, divId, {"width": CURRENT_WIDTH, "height": CURRENT_HEIGHT});
videos++; layoutManager(); }
function publish() { if (!publisher) { var parentDiv = document.getElementById("videobox"); publisherObj = document.createElement('div'); // Create a replacement div for the publisher publisherObj.setAttribute('id', 'opentok_publisher'); parentDiv.appendChild(publisherObj); publisher = session.publish('opentok_publisher', {"width": CURRENT_WIDTH, "height": CURRENT_HEIGHT}); } } function layoutManager() { var estBoxWidth = MAX_WIDTH_BOX / videos; var width = Math.min(MAX_WIDTH_VIDEO, Math.max(MIN_WIDTH_VIDEO, estBoxWidth)); var height = 3*width/4; publisherObj.height = height; publisherObj.width = width; for(var subscriberDiv in subscriberObj) { subscriberDiv.height = height; subscriberDiv.width = width; } CURRENT_HEIGHT = height; CURRENT_WIDTH = width; }