Skip to content

Instantly share code, notes, and snippets.

@storytally
Created December 20, 2012 18:36
Show Gist options
  • Save storytally/4347569 to your computer and use it in GitHub Desktop.
Save storytally/4347569 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Loneliness App</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1; maximum-scale=1.0; user-scalable=0;"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<script src="yepnope.1.5.4-min.js"></script>
<script src="OpenTok.js"></script>
<script type="text/javascript">
function connectToOpenTok() {
var apiKey = '21805942';
var sessionId = '1_MX4yMTgwNTk0Mn5-VGh1IERlYyAyMCAxMDoxOTozNyBQU1QgMjAxMn4wLjMwMjI3Nzkyfg';
var token = 'T1==cGFydG5lcl9pZD0yMTgwNTk0MiZzaWc9MTU4ZjA1MjdjZmNlNzMxOTI1MzI0NDRhODc2ZDNmN2UwNjlkOGU1YjpzZXNzaW9uX2lkPTFfTVg0eU1UZ3dOVGswTW41LVZHaDFJRVJsWXlBeU1DQXhNRG94T1Rvek55QlFVMVFnTWpBeE1uNHdMak13TWpJM056a3lmZyZjcmVhdGVfdGltZT0xMzU2MDI3NTc4JmV4cGlyZV90aW1lPTEzNTYxMTM5Nzgmcm9sZT1wdWJsaXNoZXImbm9uY2U9NTA3NjQ=';
TB.setLogLevel(TB.DEBUG);
var session = TB.initSession(sessionId);
session.addEventListener('sessionConnected', sessionConnectedHandler);
session.addEventListener('streamCreated', streamCreatedHandler);
session.connect(apiKey, token);
function sessionConnectedHandler(event) {
console.log("Session connected with event", event)
var publisher = TB.initPublisher(apiKey, 'myPublisherDiv');
session.publish(publisher);
// Subscribe to streams that were in the session when we connected
subscribeToStreams(event.streams);
}
function streamCreatedHandler(event) {
console.log('handler created')
// Subscribe to any new streams that are created
subscribeToStreams(event.streams);
}
function subscribeToStreams(streams) {
console.log('subscribing to '+(streams.length)+' streams')
for (var i = 0; i < streams.length; i++) {
// Make sure we don't subscribe to ourself
if (streams[i].connection.connectionId == session.connection.connectionId) {
return;
}
// Create the div to put the subscriber element in to
var div = document.createElement('div');
div.setAttribute('id', 'stream' + streams[i].streamId);
$('#streamsContainer').append(div);
// Subscribe to the stream
session.subscribe(streams[i], div.id);
}
}
}
connectToOpenTok();
</script>
<script type='text/javascript'>
/*alert("Cordova is defined: "+(typeof Cordova))
yepnope({
test : (typeof Cordova === undefined),
yep : 'OpenTok.js',
nope : 'http://static.opentok.com/v1.1/js/TB.min.js',
callback: connectToStreams
});*/
</script>
<link rel="stylesheet" href="/application.css" type="text/css" charset="utf-8">
<script src="./application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var jQuery = require("jqueryify");
var exports = this;
jQuery(function(){
var App = require("index");
exports.app = new App({el: $("body")});
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment