示例#1
1
function tokbox()
{
    $current_user = wp_get_current_user();
    $skillid = $_POST['skillid'];
    $myoptions = get_option('tokbox_settings');
    $apiKey = $myoptions['tokbox_account_api_key'];
    $apiSecret = $myoptions['tokbox_secret'];
    //get advisor id
    $skill = get_post($skillid);
    $advisor_id = $skill->post_author;
    $advisor_session_id = get_user_meta($advisor_id, 'webrtcSessionID', true);
    $opentok = new OpenTok($apiKey, $apiSecret);
    // Set some options in a token
    $token = $opentok->generateToken($advisor_session_id, array('role' => 'publisher', 'expireTime' => time() + 7 * 24 * 60 * 60, 'data' => (string) $current_user->ID));
    $return = array('apiKey' => $apiKey, 'sessionId' => $advisor_session_id, 'token' => $token);
    wp_send_json_success($return);
}
示例#2
1
function WebRTC_advisor_generate_token()
{
    $current_user = wp_get_current_user();
    $myoptions = get_option('tokbox_settings');
    $apiKey = $myoptions['tokbox_account_api_key'];
    $apiSecret = $myoptions['tokbox_secret'];
    $advisor_sessionID = get_user_meta($current_user->ID, 'webrtcSessionID', true);
    //echo $advisor_sessionID;die;
    $opentok = new OpenTok($apiKey, $apiSecret);
    $token = $opentok->generateToken($advisor_sessionID, array('role' => 'publisher', 'expireTime' => time() + 7 * 24 * 60 * 60, 'data' => (string) $current_user->ID));
    //echo 'token - '.$token;
    $return = array('token' => $token, 'apiKey' => $apiKey, 'sessionId' => $advisor_sessionID);
    wp_send_json_success($return);
}
示例#3
1
 public function testGeneratesTokenWithData()
 {
     // Arrange
     // This sessionId is a fixture designed by using a known but bogus apiKey and apiSecret
     $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI';
     $bogusApiKey = '12345678';
     $bogusApiSecret = '0123456789abcdef0123456789abcdef0123456789';
     $opentok = new OpenTok($bogusApiKey, $bogusApiSecret);
     // Act
     $userStatus = '{nick:"johnny",status:"hey there fellas!"}';
     $token = $opentok->generateToken($sessionId, array('data' => $userStatus));
     // Assert
     $this->assertInternalType('string', $token);
     $decodedToken = TestHelpers::decodeToken($token);
     $this->assertEquals($sessionId, $decodedToken['session_id']);
     $this->assertEquals($bogusApiKey, $decodedToken['partner_id']);
     $this->assertNotEmpty($decodedToken['nonce']);
     $this->assertNotEmpty($decodedToken['create_time']);
     $this->assertEquals($userStatus, $decodedToken['connection_data']);
     $this->assertNotEmpty($decodedToken['role']);
     // TODO: should all tokens have a default expire time even if it wasn't specified?
     //$this->assertNotEmpty($decodedToken['expire_time']);
     $this->assertNotEmpty($decodedToken['sig']);
     $this->assertEquals(hash_hmac('sha1', $decodedToken['dataString'], $bogusApiSecret), $decodedToken['sig']);
 }
示例#4
0
/* ------------------------------------------------------------------------------------------------
 * Configuration
 * -----------------------------------------------------------------------------------------------*/
$provider = new ArrayProvider('../config');
$config = new Container($provider);
// Environment Selection
$app->configureMode('development', function () use($config) {
    $config->setEnvironment('development');
});
$config->load(array('opentok'), true);
// Constants
define('NAME_MAX_LENGTH', '100');
/* ------------------------------------------------------------------------------------------------
 * OpenTok Initialization
 * -----------------------------------------------------------------------------------------------*/
$opentok = new OpenTok($config->opentok('key'), $config->opentok('secret'));
/* ------------------------------------------------------------------------------------------------
 * Routing
 * -----------------------------------------------------------------------------------------------*/
// Presence configuration
//
// Response: (JSON encoded)
// *  `apiKey`: The presence session API Key
// *  `sessionId`: The presence session ID
$app->get('/presence', function () use($app, $config) {
    $responseData = array('apiKey' => $config->opentok('key'), 'sessionId' => $config->opentok('presenceSession'));
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode($responseData));
});
// User enters
//
示例#5
0
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    return;
}
// end of email setup
function getBaseURL()
{
    $pageURL = 'http';
    $pageURL .= "://" . $_SERVER["SERVER_NAME"];
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= ":" . $_SERVER["SERVER_PORT"];
    }
    return $pageURL;
}
// opentok
$opentok = new OpenTok($apiKey, $apiSecret);
// setup slim framework
$app = new \Slim\Slim(array('templates.path' => './templates'));
// routes
$app->get('/', function () use($app) {
    $app->render('customer.php');
});
// rep get details about an appointment
$app->get('/getinfo/:timestamp', function ($timestamp) use($app, $con) {
    $result = sendQuery("SELECT * FROM Schedules WHERE Timestamp='{$timestamp}'");
    $appointmentInfo = mysqli_fetch_assoc($result);
    header("Content-Type: application/json");
    echo json_encode($appointmentInfo);
});
// get availability of a certain day, used by both rep and customer
$app->get('/availability/:daystring', function ($daystring) use($app, $con) {
示例#6
0
文件: index.php 项目: hughnguy/php
    exit;
}
if (!checkcURL() && $videoPluginType == '2') {
    echo "<div style='background:white;'>Please contact your site administrator to configure this plugin.</div>";
    exit;
}
if ($videoPluginType == '2') {
    if ($opentokApiSecret == '' || $opentokApiKey == '' || !file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'OpenTok' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) {
        echo "<div style='background:white;'>The plugin has not been configured correctly. Please contact the site owner.</div>";
        exit;
    }
    include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'OpenTok' . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
    $apiKey = $opentokApiKey;
    $apiSecret = $opentokApiSecret;
    try {
        $apiObj = new OpenTok($apiKey, $apiSecret);
    } catch (Exception $e) {
        echo "<div style='background:white;padding:15px;'>Please ask your administrator to configure this plugin using administration panel.</div>";
        exit;
    }
}
if ($_REQUEST['action'] == 'request') {
    if ($videoPluginType == '2') {
        $location = time();
        if (!empty($_SERVER['REMOTE_ADDR'])) {
            $location = $_SERVER['REMOTE_ADDR'];
        }
        try {
            $session = $apiObj->createSession(array('location' => $location));
            $grp = $session->getSessionId();
            $avchat_token = $apiObj->generateToken($grp);
示例#7
0
<body style="background-image: url('video_page/img/sky.jpg'); background-size: cover">

    <div id="videos">
        <div id="subscriber"></div>
        <div id="publisher"></div>
    </div>

	<div style="height: 5%"></div>

	<?php 
require "video_page/opentok.phar";
use OpenTok\OpenTok;
//$sessionID = $_POST["sessionID"];
$sessionID = "1_MX40NTQyNzc3Mn5-MTQ0OTM3NDM1MTk4Mn5MVStKL1lkVVBQcHN1L0pDWDMydmxMMjl-UH4";
$opentok = new OpenTok(45427772, "51ce05e8512d7bb676c94be7fe86cd692b32793a");
$token = $opentok->generateToken($sessionID);
$apiKey = 45427772;
$_POST["userType"] = "asker";
?>

	<script type="text/javascript">
		var apiKey,
			sessionId,
			token,
			session;

		$(document).ready(function() {
			$.get(SAMPLE_SERVER_BASE_URL + '/session', function(res) {
				apiKey = <?php 
echo $apiKey;
示例#8
0
 * -----------------------------------------------------------------------------------------------*/
$app = new Slim(array('log.enabled' => true, 'templates.path' => '../templates'));
/* ------------------------------------------------------------------------------------------------
 * Configuration
 * -----------------------------------------------------------------------------------------------*/
$provider = new ArrayProvider('../config');
$config = new Container($provider);
// Environment Selection
$app->configureMode('development', function () use($config) {
    $config->setEnvironment('development');
});
$config->load(array('opentok', 'redis'), true);
/* ------------------------------------------------------------------------------------------------
 * OpenTok Initialization
 * -----------------------------------------------------------------------------------------------*/
$opentok = new OpenTok($config->opentok('key'), $config->opentok('secret'));
/* ------------------------------------------------------------------------------------------------
 * Redis Initialization
 * -----------------------------------------------------------------------------------------------*/
$redis = new \Predis\Client($config->redis(), array('prefix' => $config->redis('prefix')));
define('PREFIX_HELP_SESSION_KEY', 'helpsession:');
define('HELP_QUEUE_KEY', 'helpqueue');
/* ------------------------------------------------------------------------------------------------
 * Routing
 * -----------------------------------------------------------------------------------------------*/
// Customer landing page
$app->get('/', function () use($app) {
    $app->render('customer.php');
});
// Representative landing page
$app->get('/agente', function () use($app) {
示例#9
0
mysqli_select_db($con, $dbname);
$sql = "CREATE TABLE IF NOT EXISTS `Rooms` (\n  `Name` CHAR(255),\n  `Sessionid` CHAR(255),\n  `User2` CHAR(255),\n  `User1` CHAR(255))";
if (!mysqli_query($con, $sql)) {
    echo "Error creating table: " . mysqli_error($con);
}
function getBaseURL()
{
    $pageURL = 'http';
    $pageURL .= "://" . $_SERVER["SERVER_NAME"];
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= ":" . $_SERVER["SERVER_PORT"];
    }
    return $pageURL;
}
// opentok
$opentok = new OpenTok($apiKey, $apiSecret);
// setup slim framework
$app = new \Slim\Slim(array('templates.path' => './templates'));
// variables
$date = new DateTime();
// routes
$app->get('/', function () use($app) {
    $app->render('createRoom.php');
});
$app->post('/:sessionId', function ($sessionId) use($app, $con, $date) {
    $userType = $app->request->post("userType");
    echo $userType;
    $currentTime = $date->getTimestamp();
    if ($userType == "User1") {
        $sql = "UPDATE ROOMS SET User1='{$currentTime}' WHERE Sessionid='{$sessionId}'";
    } else {
示例#10
0
 * -----------------------------------------------------------------------------------------------*/
$app = new Slim(array('log.enabled' => true, 'templates.path' => '../templates'));
/* ------------------------------------------------------------------------------------------------
 * Configuration
 * -----------------------------------------------------------------------------------------------*/
$provider = new ArrayProvider('../config');
$config = new Container($provider);
// Environment Selection
$app->configureMode('development', function () use($config) {
    $config->setEnvironment('development');
});
$config->load(array('opentok', 'mysql'), true);
/* ------------------------------------------------------------------------------------------------
 * OpenTok Initialization
 * -----------------------------------------------------------------------------------------------*/
$opentok = new OpenTok($config->opentok('key'), $config->opentok('secret'));
/* ------------------------------------------------------------------------------------------------
 * Setup MySQL
 * -----------------------------------------------------------------------------------------------*/
// mysql - replace user/pw and database name
// Set env vars in /Applications/MAMP/Library/bin/envvars if you are using MAMP
// MYSQL env: export CLEARDB_DATABASE_URL="mysql://root:root@localhost/adserverkit
// MYSQL formate: username:pw@url/database
$mysql_url = parse_url(getenv("CLEARDB_DATABASE_URL") ?: $config->mysql('mysql_url'));
$dbname = substr($mysql_url['path'], 1);
$host = $mysql_url['host'];
if ($mysql_url['port']) {
    $host = $host . ':' . $mysql_url['port'];
}
$con = mysqli_connect($host, $mysql_url['user'], $mysql_url['pass']);
// Check connection
示例#11
0
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.opentok.com/session/create");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-TB-PARTNER-AUTH: {$key}:{$secret}"));
curl_setopt($ch, CURLOPT_POST, 1);
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
// parse response
$p = xml_parser_create();
xml_parse_into_struct($p, $output, $vals, $index);
xml_parser_free($p);
$creds = array();
foreach ($vals as $entry) {
    if ($entry["tag"] == "SESSION_ID") {
        $creds['sessionId'] = $entry['value'];
    }
}
// return empty on failure
if (!isset($creds['sessionId'])) {
    $creds['sessionId'] = 0;
    $creds['token'] = 0;
} else {
    // create token
    $openTok = new OpenTok($key, $secret);
    $creds['token'] = $openTok->generateToken($creds['sessionId']);
}
echo json_encode($creds);
?>