* OpenTok PHP Library * http://www.tokbox.com/ * * Copyright (c) 2011, TokBox, Inc. * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ require_once '../OpenTokSDK.php'; // You must have a valid sessionId and an OpenTokSDK object $apiObj = new OpenTokSDK('11421872', '296cebc2fc4104cd348016667ffa2a3909ec636f'); $sessionId = '1_MX4xMTQyMTg3Mn5-MjAxMi0wNi0wOCAwMTowNjo1MC40NTMxMzIrMDA6MDB-MC40OTY0OTM3NjIzMjh'; // After creating a session, call generateToken(). Require parameter: SessionId $token = $apiObj->generateToken($sessionId); // Giving the token a moderator role, expire time 5 days from now, and connectionData to pass to other users in the session $token = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR, time() + 5 * 24 * 60 * 60, "hello world!"); echo $token;
} if (!isset($myapiKey)) { $myapiKey = API_Config::API_KEY; } if (!isset($myapiSecret)) { $myapiSecret = API_Config::API_SECRET; } if (isset($iOS)) { $myapiKey = $iOSapikey; $myapiSecret = $iOSsecret; } if (!isset($sessionId)) { $res = file_get_contents("sessionid.txt") or die("can't read file"); $res = json_decode($res, true); $sessionId = $res['sessionId']; } // Creating an OpenTok Object $apiObj = new OpenTokSDK($myapiKey, $myapiSecret); // Creating Simple Session object, passing IP address to determine closest production server // Passing IP address to determine closest production server // e.g. $session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"] ); $session = $apiObj->createSession(); // Creating example for Simple Session object to enable p2p connections //$session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"], array(SessionPropertyConstants::P2P_PREFERENCE=> "enabled") ); // Getting sessionId from Sessions // Option 1: Call getSessionId() $arr = array(); $arr['apiKey'] = $myapiKey; $arr['sessionId'] = $sessionId; $arr['token'] = $apiObj->generateToken($sessionId, $role, $dt, $participant); echo json_encode($arr);
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ require_once '../OpenTokSDK.php'; // To download, you need a $apiObj = new OpenTokSDK('11421872', '296cebc2fc4104cd348016667ffa2a3909ec636f', TRUE); $sessionId = '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-'; // Make sure token has the moderator role $token = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR); // This archiveId is generated from your javascript library after you record something $archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939'; // Create an archive object $archive = $apiObj->getArchiveManifest($archiveId, $token); $resources = $archive->getResources(); // To get all videos, loop through the resources array $vid = $resources[0]->getId(); // $url contains the file $url = $archive->downloadArchiveURL($vid, $token); echo $url;
require_once './Opentok-PHP-SDK/API_Config.php'; require_once './Opentok-PHP-SDK/OpenTokSDK.php'; if (!isset($publisher)) { $publisher = 'Guest'; } if (!isset($moderator)) { $moderator = 'Host'; } if (!isset($myapiKey)) { $myapiKey = API_Config::API_KEY; } if (!isset($myapiSecret)) { $myapiSecret = API_Config::API_SECRET; } // Creating an OpenTok Object $apiObj = new OpenTokSDK($myapiKey, $myapiSecret); // Creating Simple Session object, passing IP address to determine closest production server // Passing IP address to determine closest production server // e.g. $session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"] ); $session = $apiObj->createSession(); // Creating example for Simple Session object to enable p2p connections //$session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"], array(SessionPropertyConstants::P2P_PREFERENCE=> "enabled") ); // Getting sessionId from SessionsRoleConstants::MODERATOR // Option 1: Call getSessionId() $sessionId = $session->getSessionId(); $arr = array(); $arr['apiKey'] = $myapiKey; $arr['sessionId'] = $sessionId; $arr['token_moderator'] = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR, $dt, moderator); $arr['token_guest'] = $apiObj->generateToken($sessionId, RoleConstants::PUBLISHER, $dt, publisher); echo json_encode($arr);
require_once './Opentok-PHP-SDK/OpenTokSDK.php'; $arr = array(); // Creating an OpenTok Object $apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET); // Creating Simple Session object, passing IP address to determine closest production server // Passing IP address to determine closest production server // e.g. $session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"] ); $session = $apiObj->createSession($_SERVER["REMOTE_ADDR"], array(SessionPropertyConstants::P2P_PREFERENCE => "enabled")); // Creating example for Simple Session object to enable p2p connections //$session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"], array(SessionPropertyConstants::P2P_PREFERENCE=> "enabled") ); // Getting sessionId from Sessions // Option 1: Call getSessionId() $sessionId = $session->getSessionId(); $arr['sessionId'] = $sessionId; $fname = "sessionid.txt"; file_put_contents($fname, json_encode($arr)) or die("can't write file" . $fname); return; // After creating a session, call generateToken(). Require parameter: SessionId //$token = $apiObj->generateToken($sessionId); // Giving the token a moderator role, expire time 5 days from now, and connectionData to pass to other users in the session //$token = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR, time() + (5*24*60*60), "hello world!" ); //$arr['sessionId'] = $sessionId; //$arr['sessionId'] = "2_MX4xNDE5MTIyMn5-VGh1IERlYyAwNiAxNToyMToxOCBQU1QgMjAxMn4wLjE4MzcxMzh-"; //$arr['token'] = $token; $arr['token'] = $apiObj->generateToken($arr['sessionId']); $arr['apiKey'] = API_Config::API_KEY; // for cross-domain ajax calls use the two lnes below //header("content-type: application/json"); //echo $_GET['callback']. '('. json_encode($arr) . ')'; //$arr['token'] = "T1==cGFydG5lcl9pZD0xNDE5MTIyMiZzaWc9M2M0ZDIyMDk2ZjQyMDIzZjAxMTI5ZGUwN2EwMzM0NDA4ZDk0ZTYwNDpzZXNzaW9uX2lkPTJfTVg0eE5ERTVNVEl5TW41LVZHaDFJRVJsWXlBd05pQXhOVG95TVRveE9DQlFVMVFnTWpBeE1uNHdMakU0TXpjeE16aC0mY3JlYXRlX3RpbWU9MTM1NDgzNjA5NCZyb2xlPXB1Ymxpc2hlciZub25jZT0xMzU0ODM2MDk0LjYyMjIwMzQxMjg4NzE="; echo json_encode($arr);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_VERBOSE, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-TB-TOKEN-ATUH: {$token}")); $result = curl_exec($ch); echo $result; //echo curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } assert_options(ASSERT_CALLBACK, 'my_assert_handler'); set_exception_handler('exception_handler'); require_once '../OpenTokSDK.php'; $a = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET); $token = $a->generateToken(); assert('$token'); $token = $a->generateToken("mysession"); assert('$token'); $token = $a->generateToken("mysession", RoleConstants::SUBSCRIBER); assert('$token'); $token = $a->generateToken("mysession", RoleConstants::PUBLISHER); assert('$token'); $token = $a->generateToken("mysession", RoleConstants::MODERATOR); assert('$token'); try { $token = $a->generateToken("mysession", "randomString"); assert(false); } catch (Exception $e) { assert('$e'); }