-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.html
172 lines (145 loc) · 5.69 KB
/
admin.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Cash Cab Admin</title>
<link href="samples.css" type="text/css" rel="stylesheet" >
<script src="http://staging.tokbox.com/v0.91/js/TB.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var apiKey = 1127; // OpenTok sample code key. Replace with your own API key.
var sessionId = '16a69a59e0bcb6aea58bc1735c62fa36782b676e'; // 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 = {};
// Un-comment either of the following to set automatic logging and exception handling.
// See the exceptionHandler() method below.
// TB.setLogLevel(TB.DEBUG);
// TB.addEventListener("exception", exceptionHandler);
if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
alert('Minimum System Requirements not met!');
} 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);
}
//--------------------------------------
// LINK CLICK HANDLERS
//--------------------------------------
function connect() {
session.connect(apiKey, token);
}
function disconnect() {
session.disconnect();
hide('disconnectLink');
hide('publishLink');
hide('unpublishLink');
}
function publish() {
if (!publisher) {
var parentDiv = document.getElementById("myCamera");
var div = document.createElement('div'); // Create a replacement div for the publisher
div.setAttribute('id', 'opentok_publisher');
parentDiv.appendChild(div);
publisher = session.publish('opentok_publisher'); // Pass the replacement div id to the publish method
show('unpublishLink');
hide('publishLink');
}
}
function unpublish() {
if (publisher) {
session.unpublish(publisher);
}
publisher = null;
show('publishLink');
hide('unpublishLink');
}
//--------------------------------------
// OPENTOK EVENT HANDLERS
//--------------------------------------
function sessionConnectedHandler(event) {
// Subscribe to all streams currently in the Session
for (var i = 0; i < event.streams.length; i++) {
addStream(event.streams[i]);
}
show('disconnectLink');
show('publishLink');
hide('connectLink');
}
function streamCreatedHandler(event) {
// Subscribe to these 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;
show('connectLink');
hide('disconnectLink');
hide('publishLink');
hide('unpublishLink');
}
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.setEventLister(), 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) {
// Check if this is the stream that I am publishing. If not
// we choose to subscribe to the stream.
if (stream.connection.connectionId == session.connection.connectionId) {
return;
}
var div = document.createElement('div'); // Create a replacement div for the subscriber
var divId = stream.streamId; // Give the replacement div the id of the stream as its id
div.setAttribute('id', divId);
document.body.appendChild(div);
subscribers[stream.streamId] = session.subscribe(stream, divId);
}
function show(id) {
document.getElementById(id).style.display = 'block';
}
function hide(id) {
document.getElementById(id).style.display = 'none';
}
</script>
</head>
<body>
<div id="tokbox_console"></div>
<div id="links">
<a href="#" onclick="javascript:connect();" id="connectLink">Connect</a>
<a href="#" onclick="javascript:disconnect();" id="disconnectLink">Leave</a>
<a href="#" onclick="javascript:publish()" id="publishLink">Publish</a>
<a href="#" onclick="javascript:unpublish()" id="unpublishLink">Unpublish</a>
</div>
<div id="myCamera" class="publisherContainer"></div>
</body>
<script>
show('connectLink');
</script>
</html>