<commit_before><?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();

function getSessionList() {
	return $sessionList;
}

// Creating an OpenTok Object
$apiObj = new OpenTokSDK();

//Create a new session (a session is like a chat room, with the password to the
//room being the token)
function createSession($users) {
	$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;
}


include_once 'footer.php';
?><commit_msg>added methods<commit_after><?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;
}
?>
{'fraction_non_alphanumeric': 0.12869924294562973, 'fraction_numerical': 0.006194081211286993, 'mean_word_length': 4.464285714285714, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2661766', 'n_tokens_mistral': 922, 'n_tokens_neox': 874, 'n_words': 320}