// // Response: (JSON encoded) // * `apiKey`: an OpenTok API key that owns the session ID // * `sessionId`: an OpenTok session ID to conduct the chat within // * `token`: a token that the creator of the chat (or inviter) can use to connect to the chat // session // // NOTE: This request is designed in a manner that would make it convenient to add user // authentication in the future. The `invitee` field is not currently used but could be used to help // verify that a user who attempts to create a chat is allowed to do so. An alternative design could // be to hand both the `inviterToken` and `inviteeToken` to the inviter, who could then send the // invitee a token over an OpenTok signal. The drawback of that design would be that the server // loses the ability to keep track of the state of a user (such as if they have joined a chat or not). $app->post('/chats', function () use($app, $opentok, $config) { // NOTE: Uses a relayed session. If a routed session is preferred, add that parameter here. $chatSession = $opentok->createSession(); $responseData = array('apiKey' => $config->opentok('key'), 'sessionId' => $chatSession->getSessionId(), 'token' => $chatSession->generateToken()); $app->response->headers->set('Content-Type', 'application/json'); // NOTE: would add a 'Location' header if a new resource URI were to be created $app->response->setBody(json_encode($responseData)); }); // Join a chat // // Request: (query parameter) // * `sessionId`: the OpenTok session ID which corresponds to the chat an invitee is attempting // to enter // // Response: (JSON encoded) // * `apiKey`: an OpenTok API key that owns the session ID // * `sessionId`: an OpenTok session ID to conduct the chat within // * `token`: a token that the user joining (or invitee) a chat can use to connect to the chat
$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); } catch (Exception $e) { echo "<div style='background:white;padding:15px;'>Please ask your administrator to configure this plugin using administration panel.</div>"; exit; } } else { $grp = time(); } sendMessage($_REQUEST['to'], $broadcast_language[2] . " <a href='javascript:void(0);' onclick=\"javascript:jqcc.ccbroadcast.accept('" . $userid . "','" . $grp . "');\">" . $broadcast_language[3] . "</a> " . $broadcast_language[4], 1); sendMessage($_REQUEST['to'], $broadcast_language[5], 2); if (!empty($_REQUEST['callback'])) { header('content-type: application/json; charset=utf-8'); echo $_REQUEST['callback'] . '()'; }
// retrieve user information $result = sendQuery("SELECT * FROM Schedules WHERE Timestamp='{$timestamp}'"); $appointmentInfo = mysqli_fetch_assoc($result); // delete record sendQuery("DELETE FROM Schedules WHERE Timestamp='{$timestamp}'"); sendEmail('TokBox Demo', '*****@*****.**', $appointmentInfo['Name'], $appointmentInfo['Email'], "Cancelled: Your TokBox appointment on " . $appointmentInfo['Timestring'], "Your appointment on " . $appointmentInfo['Timestring'] . ". has been cancelled. We are sorry for the inconvenience, please reschedule on " . getBaseURL() . "/index.php/"); header("Content-Type: application/json"); echo json_encode($appointmentInfo); }); $app->post('/schedule', function () use($app, $con, $opentok) { $name = $app->request->post("name"); $email = $app->request->post("email"); $comment = $app->request->post("comment"); $timestamp = $app->request->post("timestamp"); $daystring = $app->request->post("daystring"); $session = $opentok->createSession(); $sessionId = $session->getSessionId(); $timestring = $app->request->post("timestring"); $query = sprintf("INSERT INTO Schedules (Name, Email, Comment, Timestamp, Daystring, Sessionid, Timestring) VALUES ('%s', '%s', '%s', '%d', '%s', '%s', '%s')", mysqli_real_escape_string($con, $name), mysqli_real_escape_string($con, $email), mysqli_real_escape_string($con, $comment), intval($timestamp), mysqli_real_escape_string($con, $daystring), mysqli_real_escape_string($con, $sessionId), mysqli_real_escape_string($con, $timestring)); sendQuery($query); sendEmail('TokBox Demo', '*****@*****.**', $name, $email, "Your TokBox appointment on " . $timestring, "You are confirmed for your appointment on " . $timestring . ". On the day of your appointment, go here: " . getBaseURL() . "/index.php/chat/" . $sessionId); $app->render('schedule.php'); }); $app->get('/rep', function () use($app) { $app->render('rep.php'); }); $app->get('/chat/:session_id', function ($session_id) use($app, $con, $apiKey, $opentok) { $result = sendQuery("SELECT * FROM Schedules WHERE Sessionid='{$session_id}'"); $appointmentInfo = mysqli_fetch_assoc($result); $token = $opentok->generateToken($session_id); $app->render('chat.php', array('name' => $appointmentInfo['Name'], 'email' => $appointmentInfo['Email'], 'comment' => $appointmentInfo['Comment'], 'apiKey' => $apiKey, 'session_id' => $session_id, 'token' => $token));
function WebRTC_advisor_login() { $current_user = wp_get_current_user(); $user_role = get_user_meta($current_user->ID, 'role', true); if ($user_role == 'advisor') { $myoptions = get_option('tokbox_settings'); $apiKey = $myoptions['tokbox_account_api_key']; $apiSecret = $myoptions['tokbox_secret']; $opentok = new OpenTok($apiKey, $apiSecret); $session = $opentok->createSession(); $sessionId = $session->getSessionId(); add_user_meta($current_user->ID, 'webrtcSessionID', $sessionId, true); } }