This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tok.php
75 lines (63 loc) · 1.74 KB
/
tok.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
include_once "Session.php";
/** Methods for managing creation and handling of sessions/tokens for opentok
connection. Layers between client-side javascript and web services. **/
//The list of active session
$sessionList = array();
// Creating an OpenTok Object
$apiObj = new OpenTokSDK();
/**
Return the list of active sessions.
*/
function getSessionList() {
return $sessionList;
}
/**
Create a new session (a session is like a chat room, with the password to the room being the token)
*/
function generateSessionId() {
$sessionId = $apiObj->createSession( $_SERVER["REMOTE_ADDR"] );
return $sessionId;
}
/**
Generate a token for the given session (a token is the password needed to access a session)
*/
function generateToken($sessionId) {
// Generate a token. 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!" );
return $token;
}
/**
Generate a new Session
*/
function createSession($sessionId, $token, $users) {
//Generate the new Session object
$session = new $Session($sessionId, $token, $users);
//Add it to the list of active sessions
$sessionList[] = $session;
}
/**
Removes a session
*/
function removeSession($sessionId) {
for($i = 0; $i < sizeof($sessions); ++$i) {
if($sessions[i]->$sessionId == $sessionId) {
unset($sessions[i]);
break;
}
}
}
/**
Checks to see if a user is in any active session
*/
function isInSession($userId) {
for($i = 0; $i < sizeof($sessions); ++$i) {
if($sessions[i]->isInSessions($userId)) {
return true;
}
}
return false;
}
?>