forked from MrSwitch/opentok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.html
65 lines (42 loc) · 1.51 KB
/
subscribe.html
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
<!DOCTYPE html>
<script src="http://staging.tokbox.com/v0.91/js/TB.min.js"></script>
<div id="videowall"><div id="publisher"></div></div> <span id="countdown"></span>
<script>
// Settings
var apiKey = '12142792',
token = "devtoken",
sessionID = "1_MX4xMjE0Mjc5Mn4xMjcuMC4wLjF-MjAxMi0wMi0yMyAyMzowNDoxOC44NTE2ODQrMDA6MDB-MC44MzE0ODQwMzIwMjV-";
// define debug level and global exception handler
TB.setLogLevel(TB.DEBUG);
if(!TB.checkSystemRequirements()){
alert('Ironic, new things are supposed to be Flashy');
}
//
// SESSION
// Add our session ID
//
var session = TB.initSession(sessionID);
// Add Callback Handler to the sessionConnedted Event
session.addEventListener("sessionConnected", function (event) {
session.publish('publisher', {name:navigator.userAgent} );
// Subscribe to existing streams
subscribeStream(event.streams);
});
session.addEventListener("streamCreated", function(event){subscribeStream(event.streams);});
session.connect(apiKey, token);
function subscribeStream(streams){
for (i = 0; i < streams.length; i++) {
var stream = streams[i];
if (stream.connection.connectionId != session.connection.connectionId) {
// add dom element
document.getElementById('videowall').appendChild((function(){
var div = document.createElement('div');
div.setAttribute('id', stream.streamId);
return div;
})());
// Add stream
session.subscribe(stream, stream.streamId );
}
}
}
</script>