Permalink
Browse files

new archive

  • Loading branch information...
1 parent 1582794 commit d9e956632e1beb155162f7a95723fc60ccb8a1af Song Zheng committed Jun 7, 2012
Showing with 100 additions and 26 deletions.
  1. +2 −2 API_Config.php
  2. +32 −2 OpenTokArchive.php
  3. +3 −3 OpenTokSDK.php
  4. +6 −5 sample/createSession.php
  5. +43 −0 sample/downloadArchive.php
  6. +14 −14 test/TestOpenTokSDK.php
View
4 API_Config.php
@@ -32,8 +32,8 @@ class API_Config {
// Replace this value with your TokBox API Partner Secret
const API_SECRET = "8f5cde4ade6b11ea22cfd73ea345c64b4e423d29";
- const API_SERVER = "http://staging.tokbox.com/hl";
- //const API_SERVER = "https://api.opentok.com/hl";
+ //const API_SERVER = "http://staging.tokbox.com/hl";
+ const API_SERVER = "https://api.opentok.com/hl";
}
?>
View
34 OpenTokArchive.php
@@ -43,8 +43,38 @@ public function getTimeline() {
/*************/
////Public FNs/
/*************/
- public function downloadArchiveURL($videoId) {
- return API_Config::API_SERVER . '/archive/url/'.$this->archiveId.'/'.$videoId;
+ public function downloadArchiveURL($videoId, $token) {
+ $url = API_Config::API_SERVER . '/archive/url/' .$this->archiveId.'/'.$videoId;
+ $authString = "X-TB-TOKEN-AUTH: ".$token;
+
+ if(function_exists("curl_init")) {
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array($authString));
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+ $res = curl_exec($ch);
+ if(curl_errno($ch)) {
+ throw new RequestException('Request error: ' . curl_error($ch));
+ }
+
+ curl_close($ch);
+ }
+ else {
+ if (function_exists("file_get_contents")) {
+ $context_source = array ('http' => array ( 'method' => 'GET', 'header'=> Array($authString) ) );
+ $context = stream_context_create($context_source);
+ $res = @file_get_contents( $url ,false, $context);
+ }
+ else{
+ throw new RequestException("Your PHP installion neither supports the file_get_contents method nor cURL. Please enable one of these functions so that you can make API calls.");
+ }
+ }
+
+ return $res;
}
/*************/
View
6 OpenTokSDK.php
@@ -58,7 +58,7 @@ public function __construct($api_key, $api_secret) {
* $role - One of the constants defined in RoleConstants. Default is publisher, look in the documentation to learn more about roles.
* $expire_time - Optional timestamp to change when the token expires. See documentation on token for details.
*/
- public function generate_token($session_id='', $role='', $expire_time=NULL, $connection_data='') {
+ public function generateToken($session_id='', $role='', $expire_time=NULL, $connection_data='') {
$create_time = time();
$nonce = microtime(true) . mt_rand();
@@ -97,7 +97,7 @@ public function generate_token($session_id='', $role='', $expire_time=NULL, $con
* $location - IP address to geolocate the call around.
* $properties - Optional array, keys are defined in SessionPropertyConstants
*/
- public function create_session($location='', $properties=array()) {
+ public function createSession($location='', $properties=array()) {
$properties["location"] = $location;
$properties["api_key"] = $this->api_key;
@@ -126,7 +126,7 @@ public function create_session($location='', $properties=array()) {
return new OpenTokSession($sessionId, null);
}
- public function get_archive_manifest($archiveId, $token) {
+ public function getArchiveManifest($archiveId, $token) {
$auth = array('type' => 'token', 'token' => $token);
$archiveManifestResult = $this->_do_request("/archive/getmanifest/$archiveId", array(), $auth);
View
11 sample/createSession.php
@@ -27,12 +27,13 @@
require_once '../API_Config.php';
require_once '../OpenTokSDK.php';
-$apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);
+$apiObj = new OpenTokSDK('11421872', '296cebc2fc4104cd348016667ffa2a3909ec636f');
-$session = $apiObj->create_session($_SERVER["REMOTE_ADDR"]);
+$session = $apiObj->createSession();
+$sessionId = $session->getSessionId();
+$token = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR);
-echo $session->getSessionId();
-echo "<br/>";
-echo $apiObj->generate_token();
+echo $sessionId;
+echo $token;
?>
View
43 sample/downloadArchive.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+* 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 '../API_Config.php';
+require_once '../OpenTokSDK.php';
+
+$apiObj = new OpenTokSDK('11421872', '296cebc2fc4104cd348016667ffa2a3909ec636f');
+
+$archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939';
+$sessionId = '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-';
+$token = $apiObj->generateToken($sessionId, RoleConstants::MODERATOR);
+
+$archive = $apiObj->getArchiveManifest($archiveId, $token);
+$resources = $archive->getResources();
+
+$vid = $resources[0]->getId();
+$url = $archive->downloadArchiveURL($vid, $token);
+echo $url;
+
+?>
View
28 test/TestOpenTokSDK.php
@@ -66,54 +66,54 @@ function validate_token($token) {
require_once '../OpenTokSDK.php';
$a = new OpenTokSDK(API_Config::API_KEY,API_Config::API_SECRET);
-$token = $a->generate_token();
+$token = $a->generateToken();
assert('$token');
-$token = $a->generate_token("mysession");
+$token = $a->generateToken("mysession");
assert('$token');
-$token = $a->generate_token("mysession", RoleConstants::SUBSCRIBER);
+$token = $a->generateToken("mysession", RoleConstants::SUBSCRIBER);
assert('$token');
-$token = $a->generate_token("mysession", RoleConstants::PUBLISHER);
+$token = $a->generateToken("mysession", RoleConstants::PUBLISHER);
assert('$token');
-$token = $a->generate_token("mysession", RoleConstants::MODERATOR);
+$token = $a->generateToken("mysession", RoleConstants::MODERATOR);
assert('$token');
try {
- $token = $a->generate_token("mysession", "randomString");
+ $token = $a->generateToken("mysession", "randomString");
assert(false);
} catch (Exception $e) {
assert('$e');
}
try {
- $token = $a->generate_token("mysession", RoleConstants::MODERATOR, gmmktime() - 100000);
+ $token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() - 100000);
assert(false);
} catch (Exception $e) {
assert('$e');
}
-$token = $a->generate_token("mysession", RoleConstants::MODERATOR, gmmktime() + 100000);
+$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() + 100000);
assert('$token');
-$token = $a->generate_token("mysession", RoleConstants::MODERATOR, gmmktime());
+$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime());
assert('$token');
try {
- $token = $a->generate_token("mysession", RoleConstants::MODERATOR, gmmktime() + 1000000);
+ $token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() + 1000000);
assert(false);
} catch (Exception $e) {
assert('$e');
}
-$sessionId = $a->create_session("127.0.0.1")->getSessionId();
+$sessionId = $a->createSession("127.0.0.1")->getSessionId();
assert('$sessionId');
-$sessionId = $a->create_session("8.8.8.8")->getSessionId();
+$sessionId = $a->createSession("8.8.8.8")->getSessionId();
assert('$sessionId');
-$sessionId = $a->create_session()->getSessionId();
+$sessionId = $a->createSession()->getSessionId();
assert('$sessionId');
-$sessionId = $a->create_session('127.0.0.1', array("p2p.preference" => "enabled"))->getSessionId();
+$sessionId = $a->createSession('127.0.0.1', array("p2p.preference" => "enabled"))->getSessionId();
assert('$sessionId');
// try {

0 comments on commit d9e9566

Please sign in to comment.