diff --git a/README b/README index f72d33c..8cdc980 100644 --- a/README +++ b/README @@ -6,12 +6,13 @@ * Title: AwesomeSauce URL coming soon * Description: Coming soon * - * Tech: Facebook API, JavaScript, jQuery, MySQL, PHP - * Last Update: March 12th, 2012 + * Tech: Facebook API, JavaScript, jQuery, MySQL, OpenTok API, PHP + * Last Update: March 19th, 2012 ***********************************************************************/ NOTE: *** 3rd PARTY LIBRARIES HAVE BEEN OMITTED FROM THE PUBLIC REPO *** Libraries Omitted: jQuery http://www.jquery.com FBook PHP SDK https://github.com/facebook/facebook-php-sdk + OpenTok http://www.tokbox.com Timepicker http://trentrichardson.com/examples/timepicker/ \ No newline at end of file diff --git a/js/tb.js b/js/tb.js new file mode 100644 index 0000000..936a012 --- /dev/null +++ b/js/tb.js @@ -0,0 +1,160 @@ +/** + * @author Ezra Velazquez + */ + +console.log("hello world"); + +var OpenTok = function() { + var apiKey = 13249262; // OpenTok sample API key. Replace with your own API key. + var sessionId = '153975e9d3ecce1d11baddd2c9d8d3c9d147df18'; // Replace with your session ID. + var token = 'devtoken'; // Should not be hard-coded. + // Add to the page using the OpenTok server-side libraries. + var session; + var publisher; + var subscribers = {}; + + //-------------------------------------- + // LINK CLICK HANDLERS + //-------------------------------------- + function connect() { + console.log(token); + session.connect(apiKey, token); + } + + function disconnect() { + session.disconnect(); + } + + // Called when user wants to start publishing to the session + function startPublishing() { + if (!publisher) { + var parentDiv = document.getElementById("video_feed_instructor"); + var publisherDiv = document.createElement('div'); // Create a div for the publisher to replace + publisherDiv.setAttribute('id', 'opentok_publisher'); + parentDiv.appendChild(publisherDiv); + publisher = session.publish(publisherDiv.id); // Pass the replacement div id to the publish method + } + } + + function stopPublishing() { + if (publisher) { + session.unpublish(publisher); + } + publisher = null; + } + + //-------------------------------------- + // OPENTOK EVENT HANDLERS + //-------------------------------------- + function sessionConnectedHandler(event) { + startPublishing(); + + // Subscribe to all streams currently in the Session + for (var i = 0; i < event.streams.length; i++) { + addStream(event.streams[i]); + } + } + + function streamCreatedHandler(event) { + // Subscribe to the newly created streams + for (var i = 0; i < event.streams.length; i++) { + addStream(event.streams[i]); + } + } + + function streamDestroyedHandler(event) { + // This signals that a stream was destroyed. Any Subscribers will automatically be removed. + // This default behaviour can be prevented using event.preventDefault() + } + + function sessionDisconnectedHandler(event) { + // This signals that the user was disconnected from the Session. Any subscribers and publishers + // will automatically be removed. This default behaviour can be prevented using event.preventDefault() + publisher = null; + } + + function connectionDestroyedHandler(event) { + // This signals that connections were destroyed + } + + function connectionCreatedHandler(event) { + // This signals new connections have been created. + } + + /* + If you un-comment the call to TB.addEventListener("exception", exceptionHandler) above, OpenTok calls the + exceptionHandler() method when exception events occur. You can modify this method to further process exception events. + If you un-comment the call to TB.setLogLevel(), above, OpenTok automatically displays exception event messages. + */ + function exceptionHandler(event) { + alert("Exception: " + event.code + "::" + event.message); + } + + //-------------------------------------- + // HELPER METHODS + //-------------------------------------- + + function addStream(stream) { + + // For testing purposes, it all goes to instructor currently! + //console.log(stream); + connection_data = getConnectionData(stream['connection']); + console.log(connection_data); + $(".instructor_name.classroom_labels").html(connection_data['name']); + + // Check if this is the stream that I am publishing, and if so do not publish. + if (stream.connection.connectionId == session.connection.connectionId) { + return; + } + var subscriberDiv = document.createElement('div'); // Create a div for the subscriber to replace + subscriberDiv.setAttribute('id', stream.streamId); // Give the replacement div the id of the stream as its id. + document.getElementById("subscribers").appendChild(subscriberDiv); + subscribers[stream.streamId] = session.subscribe(stream, subscriberDiv.id); + } + + function show(id) { + document.getElementById(id).style.display = 'block'; + } + + function hide(id) { + document.getElementById(id).style.display = 'none'; + } + + function getConnectionData(connection) { + try { + connectionData = JSON.parse(connection.data); + } catch(error) { + connectionData = eval("(" + connection.data + ")" ); + } + return connectionData; + } + + return { + init : function() { + $.get('../php/server_ajax.php', { + "o" : "classroom" + }, function(data) { + console.log(data); + sessionId = data.session[0]; + token = data.token; + + if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) { + alert("You don't have the minimum requirements to run this application." + + "Please upgrade to the latest version of Flash."); + } else { + session = TB.initSession(sessionId); // Initialize session + + // Add event listeners to the session + session.addEventListener('sessionConnected', sessionConnectedHandler); + session.addEventListener('sessionDisconnected', sessionDisconnectedHandler); + session.addEventListener('connectionCreated', connectionCreatedHandler); + session.addEventListener('connectionDestroyed', connectionDestroyedHandler); + session.addEventListener('streamCreated', streamCreatedHandler); + session.addEventListener('streamDestroyed', streamDestroyedHandler); + + connect(); + } + }); + } + } +}(); diff --git a/php/classroom.php b/php/classroom.php index 24ceaeb..0975408 100644 --- a/php/classroom.php +++ b/php/classroom.php @@ -1,12 +1,21 @@ + + +
Sir George Martin -
+
75%
25%
diff --git a/php/opentok.php b/php/opentok.php new file mode 100644 index 0000000..a91908c --- /dev/null +++ b/php/opentok.php @@ -0,0 +1,27 @@ +create_session($_SERVER["REMOTE_ADDR"]); + + $role = RoleConstants::PUBLISHER; // Or set to the correct role for the user. + // Get username from the FB server? + $metadata = '{"name": "'.$name.'"}'; + $token_user = $apiObj->generate_token($session->getSessionId(), $role, NULL, $metadata); // Replace with the correct session ID + $session_id = $session->getSessionId(); + + $arr = array('session'=>$session_id, 'token'=>$token_user); + return $arr; + } + } +?> \ No newline at end of file diff --git a/php/server_ajax.php b/php/server_ajax.php index 81a1a80..9a1efe6 100644 --- a/php/server_ajax.php +++ b/php/server_ajax.php @@ -1,6 +1,7 @@ startApp(); @@ -25,6 +26,16 @@ //$response = array('test'=>$date); $response =$server->addWorkshop($title, $tech, $description, $date, $fb_id, $name); + break; + case 'classroom': + require('fbook.php'); + // Get fb id from db + $facebook_array = $facebook->api('/1088730508', 'GET'); + $facebook_name = $facebook_array['name']; + + $opentok = new OpenTok(); + $response = $opentok->generate($facebook_name); + break; default: $response = array('status'=>'400','message'=>'command not known');