-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.html
353 lines (300 loc) · 10.5 KB
/
index.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<!--
Cyber Mega Phone 2K
Copyright (C) 2017 Digium, Inc.
This program is free software, distributed under the terms of the
MIT License. See the LICENSE file at the top of the source tree.
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Cyber Mega Phone 2K</title>
<link rel="stylesheet" type="text/css" href="cyber_mega_phone.css">
<script src="lib/sdp-interop-sl-1.4.0.js"></script>
<script src="lib/jssip-3.0.13.js"></script>
<script src="utils.js"></script>
<script src="cyber_mega_phone.js"></script>
<script type="text/javascript">
let phone;
window.onload = function() {
document.getElementById("accountId").placeholder = "video";
document.getElementById("accountName").value = "";
document.getElementById("accountPassword").placeholder = "video";
document.getElementById("accountHost").placeholder = "localhost";
document.getElementById("accountRegister").checked = true;
document.getElementById("extension").placeholder = "video-conference";
document.getElementById("connect").value = "Connect";
document.getElementById("connect").disabled = false;
document.getElementById("call").value = "Call";
document.getElementById("call").disabled = true;
function findMediaView(parent, stream) {
let nodes = parent.childNodes;
for (let i = 0; i < nodes.length; ++i) {
if (nodes[i].id == stream.id) {
return nodes[i];
}
}
return null;
}
function createMediaControls(video) {
let controls = document.createElement("div");
controls.className = "media-controls";
// If only -webkit-media-controls were fully supported across browsers
let audioTracks = video.srcObject.getAudioTracks();
if (audioTracks.length > 0) {
let muteAudio = document.createElement("input");
muteAudio.type = "button";
muteAudio.value = "mute audio";
muteAudio.className = "audio-btn";
muteAudio.setAttribute("state", "unmute");
muteAudio.onclick = function() {
let state = this.getAttribute("state");
this.setAttribute("state", state == "mute" ? "unmute" : "mute");
this.value = state + " audio";
mute(video.srcObject, {audio: this.getAttribute("state") == "mute"});
};
controls.appendChild(muteAudio);
}
let videoTracks = video.srcObject.getVideoTracks();
if (videoTracks.length > 0) {
let muteVideo = document.createElement("input");
muteVideo.type = "button";
muteVideo.value = "mute video";
muteVideo.className = "video-btn";
muteVideo.setAttribute("state", "unmute");
muteVideo.onclick = function() {
let state = this.getAttribute("state");
this.setAttribute("state", state == "mute" ? "unmute" : "mute");
this.value = state + " video";
mute(video.srcObject, {video: this.getAttribute("state") == "mute"});
};
controls.appendChild(muteVideo);
if (video.srcObject.local == false) {
let fullScreen = document.createElement("input");
fullScreen.type = "button";
fullScreen.value = "fullscreen";
fullScreen.className = "fullScreen-btn";
fullScreen.onclick = function() {
this.fullScreen.request();
};
fullScreen.fullScreen = new FullScreen(video);
controls.appendChild(fullScreen);
}
}
return controls;
}
function createMediaView(stream) {
let mediaView = document.createElement("div");
mediaView.className = "media-view";
mediaView.id = stream.id; // Makes it easy to find later
let videoView = document.createElement("div");
let videoOverlay = document.createElement("div");
videoOverlay.classname = "media-overlay";
if (stream.local == false) {
let audioTracks = stream.getAudioTracks();
let videoTracks = stream.getVideoTracks();
let videoText = document.createTextNode("No Media Available");
if (audioTracks.length > 0) {
videoText = document.createTextNode("Audio Only");
} else if (videoTracks.length > 0) {
videoText = document.createTextNode("Waiting For Video");
}
videoOverlay.appendChild(videoText);
function checkForVideo() {
if (video.videoWidth < 10 || video.videoHeight < 10) {
videoView.style.display = 'none';
return;
}
videoOverlay.removeChild(videoText);
videoText = document.createTextNode("Remote Video");
videoOverlay.appendChild(videoText);
videoView.style.display = 'inline';
}
setInterval(checkForVideo, 1000);
} else {
let videoText = document.createTextNode("Local Video");
videoOverlay.appendChild(videoText);
}
mediaView.appendChild(videoOverlay);
let video = document.createElement("video");
video.autoplay = true;
video.srcObject = stream;
video.onloadedmetadata = function() {
let tracks = stream.getVideoTracks();
for (let i = 0; i < tracks.length; ++i) {
tracks[i].enabled = true;
}
};
// Video elements connected to local streams will by default
// echo both the video and the audio back to ourselves. Since
// we don't want to hear ourselves we mute it, which mutes only
// the audio portion.
if (stream.local == true) {
video.muted = true;
} else {
// We hide the video view until we receive video
videoView.style.display = 'none';
}
videoView.appendChild(video);
mediaView.appendChild(videoView);
mediaView.appendChild(createMediaControls(video));
return mediaView;
}
function removeMediaView(parent, stream) {
let node = findMediaView(parent, stream);
if (node) {
parent.removeChild(node);
}
}
function getValue(id) {
let obj = document.getElementById(id);
return obj.value ? obj.value : obj.placeholder;
}
document.getElementById("connect").addEventListener("click", function() {
if (document.getElementById("connect").value == "Disconnect") {
document.getElementById("call").value = "Call";
document.getElementById("call").disabled = true;
document.getElementById("connect").value = "Disconnecting";
document.getElementById("connect").disabled = true;
phone.disconnect();
return;
}
phone = new CyberMegaPhone(getValue("accountId"),
getValue("accountName"),
getValue("accountPassword"),
getValue("accountHost"),
document.getElementById("accountRegister").checked);
phone.handle("connected", function () {
if (document.getElementById("accountRegister").checked &&
document.getElementById("connect").value != "Disconnect") {
document.getElementById("connect").value = "Registering";
} else {
document.getElementById("connect").value = "Disconnect";
document.getElementById("connect").disabled = false;
document.getElementById("call").disabled = false;
}
});
phone.handle("disconnected", function () {
document.getElementById("connect").value = "Connect";
document.getElementById("connect").disabled = false;
document.getElementById("call").value = "Call";
document.getElementById("call").disabled = true;
});
phone.handle("registered", function () {
document.getElementById("connect").value = "Disconnect";
document.getElementById("connect").disabled = false;
document.getElementById("call").disabled = false;
});
phone.handle("registrationFailed", function () {
phone.disconnect();
});
phone.handle("incoming", function (reason) {
document.getElementById("call").value = "Answer";
});
phone.handle("failed", function (reason) {
document.getElementById("call").value = "Call";
document.getElementById("call").disabled = false;
});
phone.handle("ended", function (reason) {
document.getElementById("call").value = "Call";
document.getElementById("call").disabled = document.getElementById("connect").value == "Connect";
});
phone.handle("streamAdded", function (stream) {
document.getElementById("media-views").appendChild(createMediaView(stream));
document.getElementById("call").value = "Hangup";
document.getElementById("call").disabled = false;
});
phone.handle("streamRemoved", function (stream) {
removeMediaView(document.getElementById("media-views"), stream);
});
phone.connect();
document.getElementById("connect").disabled = true;
document.getElementById("connect").value = "Connecting";
});
document.getElementById("call").addEventListener("click", function() {
let node = document.getElementById("call");
if (node.value == "Call") {
phone.call(getValue("extension"));
node.disabled = true;
node.value = "Ringing";
} else if (node.value == "Answer") {
node.disabled = true;
node.value = "Hangup";
} else {
node.value = "Call";
phone.terminate();
}
});
}; // window.onload
window.onunload = function() {
if (phone) {
phone.disconnect();
}
}; // window.onunload
</script>
</head>
<body>
<header>
<p><marquee behavior="alternate">Welcome to Cyber Mega Phone 2K Ultimate Dynamic Edition</marquee></p>
</header>
<div class="connection">
<input type="button" id="account" class="account" value="Account" onclick="accountShow()" />
<input type="button" id="connect" class="connect" value="Connect" />
<input type="button" id="call" class="call" value="Call" />
</div>
<div id="account-modal" class="account-modal">
<div class="account-content">
<span class="account-close" onclick="accountClose()">×</span>
<label>ID:</label>
<input type="text" id="accountId"/><br>
<label>Authorization Name:</label>
<input type="text" id="accountName"/><br>
<label>Authorization password:</label>
<input type="text" id="accountPassword" /><br>
<label>Host IP/Name:</label>
<input type="text" id="accountHost" /><br>
<label>Register:</label>
<label class="switch">
<input type="checkbox" id="accountRegister" checked="true"/>
<div class="slider"></div>
</label>
<label>Extension:</label>
<input type="text" id="extension"/>
</div>
</div>
<div id="calling"></div>
<div id="media-views" class="media-views"></div>
<div class="footer">© 2017 Digium, Inc.</div>
<script>
FullScreen.prototype.request = function() {
if (this.is()) {
return;
}
if (this._obj.requestFullscreen) {
this._obj.requestFullscreen();
} else if (this._obj.mozRequestFullScreen) {
this._obj.mozRequestFullScreen();
} else if (this._obj.webkitRequestFullScreen) {
this._obj.webkitRequestFullScreen();
} else if (this._obj.msRequestFullscreen) {
this._obj.msRequestFullscreen();
}
this.setData(true);
};
function accountShow() {
let modal = document.getElementById("account-modal");
modal.style.display = "block";
}
function accountClose() {
let modal = document.getElementById("account-modal");
modal.style.display = "none";
}
window.onclick = function(event) {
let modal = document.getElementById("account-modal");
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>