ezuikit-js 8.0.11 → 8.0.12-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,343 +1,343 @@
1
- // We make use of this 'server' variable to provide the address of the
2
- // REST Janus API. By default, in this example we assume that Janus is
3
- // co-located with the web server hosting the HTML pages but listening
4
- // on a different port (8088, the default for HTTP in Janus), which is
5
- // why we make use of the 'window.location.hostname' base address. Since
6
- // Janus can also do HTTPS, and considering we don't really want to make
7
- // use of HTTP for Janus if your demos are served on HTTPS, we also rely
8
- // on the 'window.location.protocol' prefix to build the variable, in
9
- // particular to also change the port used to contact Janus (8088 for
10
- // HTTP and 8089 for HTTPS, if enabled).
11
- // In case you place Janus behind an Apache frontend (as we did on the
12
- // online demos at http://janus.conf.meetecho.com) you can just use a
13
- // relative path for the variable, e.g.:
14
- //
15
- // var server = "/janus";
16
- //
17
- // which will take care of this on its own.
18
- //
19
- //
20
- // If you want to use the WebSockets frontend to Janus, instead, you'll
21
- // have to pass a different kind of address, e.g.:
22
- //
23
- // var server = "ws://" + window.location.hostname + ":8188";
24
- //
25
- // Of course this assumes that support for WebSockets has been built in
26
- // when compiling the server. WebSockets support has not been tested
27
- // as much as the REST API, so handle with care!
28
- //
29
- //
30
- // If you have multiple options available, and want to let the library
31
- // autodetect the best way to contact your server (or pool of servers),
32
- // you can also pass an array of servers, e.g., to provide alternative
33
- // means of access (e.g., try WebSockets first and, if that fails, fall
34
- // back to plain HTTP) or just have failover servers:
35
- //
36
- // var server = [
37
- // "ws://" + window.location.hostname + ":8188",
38
- // "/janus"
39
- // ];
40
- //
41
- // This will tell the library to try connecting to each of the servers
42
- // in the presented order. The first working server will be used for
43
- // the whole session.
44
- //
45
- var server = null;
46
- if(window.location.protocol === 'http:')
47
- //server = "http://" + window.location.hostname + ":9020/janus";
48
- // yujianbo
49
- server = "https://" + "10.80.21.211" + ":9022/janus";
50
- else
51
- //server = "https://" + window.location.hostname + ":9022/janus";
52
- // -yujianbo
53
- server = "https://" + "10.80.21.211" + ":9022/janus";
54
-
55
- var janus = null;
56
- var tts = null;
57
- var opaqueId = "tts-"+Janus.randomString(12);
58
-
59
- var spinner = null;
60
-
61
- // Initialize the library (all console debuggers enabled)
62
- Janus.init({debug: "all", callback: function() {
63
- window.stopTalk = function (){
64
- janus.destroy();
65
- }
66
- // debugger;
67
- window.startTalk = function() {
68
- // Make sure the browser supports WebRTC
69
- if(!Janus.isWebrtcSupported()) {
70
- bootbox.alert("No WebRTC support... ");
71
- return;
72
- }
73
-
74
- // if($('#tts_url').val().length == 0){
75
- // bootbox.alert("Please input tts url... ");
76
- // return;
77
- // }
78
-
79
- // $(this).attr('disabled', true).unbind('click');
80
-
81
- // Create session
82
- janus = new Janus(
83
- {
84
- server: window.EZUIKit.opt.rtcUrl,
85
- // No "iceServers" is provided, meaning janus.js will use a default STUN server
86
- // Here are some examples of how an iceServers field may look like to support TURN
87
- // iceServers: [{urls: "turn:yourturnserver.com:3478", username: "janususer", credential: "januspwd"}],
88
- // iceServers: [{urls: "turn:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}],
89
- // iceServers: [{urls: "turns:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}],
90
- // Should the Janus API require authentication, you can specify either the API secret or user token here too
91
- // token: "mytoken",
92
- // or
93
- // apisecret: "serversecret",
94
- success: function() {
95
- // Attach to tts plugin
96
- janus.attach(
97
- {
98
- plugin: "rtcgw.plugin.tts",
99
- opaqueId: opaqueId,
100
- success: function(pluginHandle) {
101
- // $('#details').remove();
102
- tts = pluginHandle;
103
- Janus.log("Plugin attached! (" + tts.getPlugin() + ", id=" + tts.getId() + ")");
104
- // Negotiate WebRTC
105
- //var url = "tts://61.130.6.23:8664/talk://D13781761:0:1:cas.ys7.com:6500?97fbd2a75fa94b7682c994d3d1fac8ca:ut.5porslgu79e9r7ca48z32k8abgl3rp58-77bhb6i7xr-1kmumtg-jkhy7pvfr:0:3"
106
-
107
-
108
- //var url = "tts://10.86.15.209:8664/talk://D13781761:0:1:cas.ys7.com:6500?32db2578ba7c4a84be22ecc0bcd0f8db:ut.5lqpkhim5m7cdk2y5w60g7hm9vd7i3v0-3d2pwhxe2t-11wx2ge-sh4yazbll:0:3"
109
- //var url = "tts://10.86.15.209:8664/talk://D13781761:0:1:cas.ys7.com:6500"
110
- //test12.ys.com
111
- //var url = "tts://10.86.15.209:8664/talk://D08197169:0:1:cas.ys7.com:6500"
112
- //test10.ys.com
113
- //var url = "tts://10.86.29.210:8664/talk://D08197169:0:1:cas.ys7.com:6500"
114
- var url = window.EZUIKit.opt.talkLink;
115
- console.log("ttsUlr",url);
116
- var body = { "request": "start", "url": url, "codec": "opus", "dir": "sendrecv", "audio_debug": 1};
117
- //tts.send({"message": body});
118
- Janus.debug("Trying a createOffer too (audio/video sendrecv)");
119
- tts.createOffer(
120
- {
121
- // No media provided: by default, it's sendrecv for audio and video
122
- media: { audio: true, video: false, data: false }, // Audio only
123
- // If you want to test simulcasting (Chrome and Firefox only), then
124
- // pass a ?simulcast=true when opening this demo page: it will turn
125
- // the following 'simulcast' property to pass to janus.js to true
126
- simulcast: false,
127
- simulcast2: false,
128
- success: function(jsep) {
129
- Janus.debug("Got SDP!");
130
- Janus.debug(jsep);
131
- tts.send({"message": body, "jsep": jsep});
132
- if(typeof window.EZUIKit.handleTalkSuccess !== 'undefined'){
133
- window.EZUIKit.handleTalkSuccess();
134
- }
135
- },
136
- error: function(error) {
137
- Janus.error("WebRTC error:", error);
138
- // bootbox.alert("WebRTC error... " + JSON.stringify(error));
139
- if(typeof window.EZUIKit.handleTalkError !== 'undefined'){
140
- window.EZUIKit.handleTalkError(error);
141
- }
142
- }
143
- });
144
- // $('#start').removeAttr('disabled').html("Stop")
145
- // .click(function() {
146
- // $(this).attr('disabled', true);
147
- // janus.destroy();
148
- // });
149
- },
150
- error: function(error) {
151
- console.error(" -- Error attaching plugin...", error);
152
- bootbox.alert("Error attaching plugin... " + error);
153
- if(window.EZUIKit.handleTalkError !== 'undefined'){
154
- window.EZUIKit.handleTalkError(error);
155
- }
156
- },
157
- consentDialog: function(on) {
158
- Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
159
- if(on) {
160
- // Darken screen and show hint
161
- // $.blockUI({
162
- // message: '<div><img src="up_arrow.png"/></div>',
163
- // css: {
164
- // border: 'none',
165
- // padding: '15px',
166
- // backgroundColor: 'transparent',
167
- // color: '#aaa',
168
- // top: '10px',
169
- // left: (navigator.mozGetUserMedia ? '-100px' : '300px')
170
- // } });
171
- } else {
172
- // Restore screen
173
- // $.unblockUI();
174
- }
175
- },
176
- iceState: function(state) {
177
- Janus.log("ICE state changed to " + state);
178
- },
179
- mediaState: function(medium, on) {
180
- Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
181
- },
182
- webrtcState: function(on) {
183
- Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
184
- // $("#audioleft").parent().unblock();
185
- },
186
- slowLink: function(uplink, lost) {
187
- Janus.warn("Janus reports problems " + (uplink ? "sending" : "receiving") +
188
- " packets on this PeerConnection (" + lost + " lost packets)");
189
- },
190
- onmessage: function(msg, jsep) {
191
- Janus.debug(" ::: Got a message :::");
192
- Janus.debug(msg);
193
- if(jsep !== undefined && jsep !== null) {
194
- Janus.debug("Handling SDP as well...");
195
- Janus.debug(jsep);
196
- tts.handleRemoteJsep({jsep: jsep});
197
- }
198
- var result = msg["result"];
199
- if(result !== null && result !== undefined) {
200
- if(result === "done") {
201
- // The plugin closed
202
- bootbox.alert("The TTS Test is over");
203
- if(spinner !== null && spinner !== undefined)
204
- spinner.stop();
205
- spinner = null;
206
- // $('#myaudio').remove();
207
- //$('#waitingvideo').remove();
208
- // $('#peeraudio').remove();
209
- return;
210
- }
211
-
212
- if(result === "msg"){
213
- if(typeof window.EZUIKit.handleTalkMessage !== 'undefined'){
214
- window.EZUIKit.handleTalkMessage(msg);
215
- }
216
- }
217
- // Any loss?
218
- var status = result["status"];
219
- if(status === "slow_link") {
220
- //~ var bitrate = result["bitrate"];
221
- //~ toastr.warning("The bitrate has been cut to " + (bitrate/1000) + "kbps", "Packet loss?", {timeOut: 2000});
222
- toastr.warning("Janus apparently missed many packets we sent, maybe we should reduce the bitrate", "Packet loss?", {timeOut: 2000});
223
- }
224
- }
225
- },
226
- onlocalstream: function(stream) {
227
- Janus.debug(" ::: Got a local stream :::");
228
- Janus.debug(stream);
229
-
230
- // if($('#myaudio').length === 0) {
231
- // $('#audios').removeClass('hide').show();
232
- // $('#audioleft').append('<audio id="myaudio" autoplay controls muted>Your browser does not support audio tag</audio>');
233
- // }
234
- Janus.attachMediaStream(document.getElementById("myaudio"), stream);
235
- //$("#myaudio").get(0).muted = "muted";
236
- if(tts.webrtcStuff.pc.iceConnectionState !== "completed" &&
237
- tts.webrtcStuff.pc.iceConnectionState !== "connected") {
238
- // $("#audioleft").parent().block({
239
- // message: '<b>Publishing...</b>',
240
- // css: {
241
- // border: 'none',
242
- // backgroundColor: 'transparent',
243
- // color: 'white'
244
- // }
245
- // });
246
- // No remote video yet
247
- //$('#audioright').append('<video class="rounded centered" id="waitingvideo" width=320 height=240 />');
248
- if(spinner == null) {
249
- var target = document.getElementById('audioright');
250
- //spinner = new Spinner({top:100}).spin(target);
251
- } else {
252
- spinner.spin();
253
- }
254
- }
255
- var audioTracks = stream.getAudioTracks();
256
- if(audioTracks === null || audioTracks === undefined || audioTracks.length === 0) {
257
- // $('#myaudio').hide();
258
- } else {
259
- // $('#myaudio').removeClass('hide').show();
260
- // document.getElementById('myaudio').play();
261
- }
262
- },
263
- onremotestream: function(stream) {
264
- Janus.debug(" ::: Got a remote stream :::");
265
- Janus.debug(stream);
266
- // if($('#peeraudio').length === 0) {
267
- // $('#audios').removeClass('hide').show();
268
- // // $('#audioright').append('<audio id="peeraudio" autoplay controls>Your browser does not support audio tag</audio>');
269
- // // Show the video, hide the spinner and show the resolution when we get a playing event
270
- // var audio = $('<audio id="peeraudio" autoplay controls playsinline preload="preload" loop="true"></audio>');
271
- // audio = audio.get(0);
272
- // audio.setAttribute("id", 'peeraudio');
273
- // audio.setAttribute("preload","preload");
274
- // // 自动播放解决苹果不兼容autoplay属性
275
- // audio.setAttribute("loop",true);
276
- // $('#audioright').append(audio);
277
- // $("#peeraudio").bind("playing", function () {
278
- // //$('#waitingvideo').remove();
279
- // $('#peeraudio').removeClass('hide').show();
280
- // if(spinner !== null && spinner !== undefined)
281
- // spinner.stop();
282
- // spinner = null;
283
- // });
284
- // }
285
- Janus.attachMediaStream(document.getElementById("peeraudio"), stream);
286
- var audioTracks = stream.getAudioTracks();
287
- if(audioTracks === null || audioTracks === undefined || audioTracks.length === 0) {
288
- // $('#peeraudio').hide();
289
- } else {
290
- // $('#peeraudio').removeClass('hide').show();
291
- document.getElementById('peeraudio').play();
292
- }
293
- },
294
- ondataopen: function(data) {
295
- Janus.log("The DataChannel is available!");
296
- },
297
- ondata: function(data) {
298
- Janus.debug("We got data from the DataChannel! " + data);
299
- },
300
- oncleanup: function() {
301
- Janus.log(" ::: Got a cleanup notification :::");
302
- if(spinner !== null && spinner !== undefined)
303
- spinner.stop();
304
- spinner = null;
305
- // $('#myaudio').remove();
306
- // //$('#waitingvideo').remove();
307
- // $("#audioleft").parent().unblock();
308
- // $('#peeraudio').remove();
309
- }
310
- });
311
- },
312
- error: function(error) {
313
- Janus.error(error);
314
- if(window.EZUIKit.handleTalkError !== 'undefined'){
315
- window.EZUIKit.handleTalkError(error);
316
- }
317
- },
318
- destroyed: function() {
319
- // window.location.reload();
320
- }
321
- });
322
- }
323
-
324
- }});
325
-
326
- function checkEnter(event) {
327
- var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
328
- if(theCode == 13) {
329
- sendData();
330
- return false;
331
- } else {
332
- return true;
333
- }
334
- }
335
-
336
- // Helper to parse query string
337
- function getQueryStringValue(name) {
338
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
339
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
340
- results = regex.exec(location.search);
341
- return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
342
- }
343
-
1
+ // We make use of this 'server' variable to provide the address of the
2
+ // REST Janus API. By default, in this example we assume that Janus is
3
+ // co-located with the web server hosting the HTML pages but listening
4
+ // on a different port (8088, the default for HTTP in Janus), which is
5
+ // why we make use of the 'window.location.hostname' base address. Since
6
+ // Janus can also do HTTPS, and considering we don't really want to make
7
+ // use of HTTP for Janus if your demos are served on HTTPS, we also rely
8
+ // on the 'window.location.protocol' prefix to build the variable, in
9
+ // particular to also change the port used to contact Janus (8088 for
10
+ // HTTP and 8089 for HTTPS, if enabled).
11
+ // In case you place Janus behind an Apache frontend (as we did on the
12
+ // online demos at http://janus.conf.meetecho.com) you can just use a
13
+ // relative path for the variable, e.g.:
14
+ //
15
+ // var server = "/janus";
16
+ //
17
+ // which will take care of this on its own.
18
+ //
19
+ //
20
+ // If you want to use the WebSockets frontend to Janus, instead, you'll
21
+ // have to pass a different kind of address, e.g.:
22
+ //
23
+ // var server = "ws://" + window.location.hostname + ":8188";
24
+ //
25
+ // Of course this assumes that support for WebSockets has been built in
26
+ // when compiling the server. WebSockets support has not been tested
27
+ // as much as the REST API, so handle with care!
28
+ //
29
+ //
30
+ // If you have multiple options available, and want to let the library
31
+ // autodetect the best way to contact your server (or pool of servers),
32
+ // you can also pass an array of servers, e.g., to provide alternative
33
+ // means of access (e.g., try WebSockets first and, if that fails, fall
34
+ // back to plain HTTP) or just have failover servers:
35
+ //
36
+ // var server = [
37
+ // "ws://" + window.location.hostname + ":8188",
38
+ // "/janus"
39
+ // ];
40
+ //
41
+ // This will tell the library to try connecting to each of the servers
42
+ // in the presented order. The first working server will be used for
43
+ // the whole session.
44
+ //
45
+ var server = null;
46
+ if(window.location.protocol === 'http:')
47
+ //server = "http://" + window.location.hostname + ":9020/janus";
48
+ // yujianbo
49
+ server = "https://" + "10.80.21.211" + ":9022/janus";
50
+ else
51
+ //server = "https://" + window.location.hostname + ":9022/janus";
52
+ // -yujianbo
53
+ server = "https://" + "10.80.21.211" + ":9022/janus";
54
+
55
+ var janus = null;
56
+ var tts = null;
57
+ var opaqueId = "tts-"+Janus.randomString(12);
58
+
59
+ var spinner = null;
60
+
61
+ // Initialize the library (all console debuggers enabled)
62
+ Janus.init({debug: "all", callback: function() {
63
+ window.stopTalk = function (){
64
+ janus.destroy();
65
+ }
66
+ // debugger;
67
+ window.startTalk = function() {
68
+ // Make sure the browser supports WebRTC
69
+ if(!Janus.isWebrtcSupported()) {
70
+ bootbox.alert("No WebRTC support... ");
71
+ return;
72
+ }
73
+
74
+ // if($('#tts_url').val().length == 0){
75
+ // bootbox.alert("Please input tts url... ");
76
+ // return;
77
+ // }
78
+
79
+ // $(this).attr('disabled', true).unbind('click');
80
+
81
+ // Create session
82
+ janus = new Janus(
83
+ {
84
+ server: window.EZUIKit.opt.rtcUrl,
85
+ // No "iceServers" is provided, meaning janus.js will use a default STUN server
86
+ // Here are some examples of how an iceServers field may look like to support TURN
87
+ // iceServers: [{urls: "turn:yourturnserver.com:3478", username: "janususer", credential: "januspwd"}],
88
+ // iceServers: [{urls: "turn:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}],
89
+ // iceServers: [{urls: "turns:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}],
90
+ // Should the Janus API require authentication, you can specify either the API secret or user token here too
91
+ // token: "mytoken",
92
+ // or
93
+ // apisecret: "serversecret",
94
+ success: function() {
95
+ // Attach to tts plugin
96
+ janus.attach(
97
+ {
98
+ plugin: "rtcgw.plugin.tts",
99
+ opaqueId: opaqueId,
100
+ success: function(pluginHandle) {
101
+ // $('#details').remove();
102
+ tts = pluginHandle;
103
+ Janus.log("Plugin attached! (" + tts.getPlugin() + ", id=" + tts.getId() + ")");
104
+ // Negotiate WebRTC
105
+ //var url = "tts://61.130.6.23:8664/talk://D13781761:0:1:cas.ys7.com:6500?97fbd2a75fa94b7682c994d3d1fac8ca:ut.5porslgu79e9r7ca48z32k8abgl3rp58-77bhb6i7xr-1kmumtg-jkhy7pvfr:0:3"
106
+
107
+
108
+ //var url = "tts://10.86.15.209:8664/talk://D13781761:0:1:cas.ys7.com:6500?32db2578ba7c4a84be22ecc0bcd0f8db:ut.5lqpkhim5m7cdk2y5w60g7hm9vd7i3v0-3d2pwhxe2t-11wx2ge-sh4yazbll:0:3"
109
+ //var url = "tts://10.86.15.209:8664/talk://D13781761:0:1:cas.ys7.com:6500"
110
+ //test12.ys.com
111
+ //var url = "tts://10.86.15.209:8664/talk://D08197169:0:1:cas.ys7.com:6500"
112
+ //test10.ys.com
113
+ //var url = "tts://10.86.29.210:8664/talk://D08197169:0:1:cas.ys7.com:6500"
114
+ var url = window.EZUIKit.opt.talkLink;
115
+ console.log("ttsUlr",url);
116
+ var body = { "request": "start", "url": url, "codec": "opus", "dir": "sendrecv", "audio_debug": 1};
117
+ //tts.send({"message": body});
118
+ Janus.debug("Trying a createOffer too (audio/video sendrecv)");
119
+ tts.createOffer(
120
+ {
121
+ // No media provided: by default, it's sendrecv for audio and video
122
+ media: { audio: true, video: false, data: false }, // Audio only
123
+ // If you want to test simulcasting (Chrome and Firefox only), then
124
+ // pass a ?simulcast=true when opening this demo page: it will turn
125
+ // the following 'simulcast' property to pass to janus.js to true
126
+ simulcast: false,
127
+ simulcast2: false,
128
+ success: function(jsep) {
129
+ Janus.debug("Got SDP!");
130
+ Janus.debug(jsep);
131
+ tts.send({"message": body, "jsep": jsep});
132
+ if(typeof window.EZUIKit.handleTalkSuccess !== 'undefined'){
133
+ window.EZUIKit.handleTalkSuccess();
134
+ }
135
+ },
136
+ error: function(error) {
137
+ Janus.error("WebRTC error:", error);
138
+ // bootbox.alert("WebRTC error... " + JSON.stringify(error));
139
+ if(typeof window.EZUIKit.handleTalkError !== 'undefined'){
140
+ window.EZUIKit.handleTalkError(error);
141
+ }
142
+ }
143
+ });
144
+ // $('#start').removeAttr('disabled').html("Stop")
145
+ // .click(function() {
146
+ // $(this).attr('disabled', true);
147
+ // janus.destroy();
148
+ // });
149
+ },
150
+ error: function(error) {
151
+ console.error(" -- Error attaching plugin...", error);
152
+ bootbox.alert("Error attaching plugin... " + error);
153
+ if(window.EZUIKit.handleTalkError !== 'undefined'){
154
+ window.EZUIKit.handleTalkError(error);
155
+ }
156
+ },
157
+ consentDialog: function(on) {
158
+ Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
159
+ if(on) {
160
+ // Darken screen and show hint
161
+ // $.blockUI({
162
+ // message: '<div><img src="up_arrow.png"/></div>',
163
+ // css: {
164
+ // border: 'none',
165
+ // padding: '15px',
166
+ // backgroundColor: 'transparent',
167
+ // color: '#aaa',
168
+ // top: '10px',
169
+ // left: (navigator.mozGetUserMedia ? '-100px' : '300px')
170
+ // } });
171
+ } else {
172
+ // Restore screen
173
+ // $.unblockUI();
174
+ }
175
+ },
176
+ iceState: function(state) {
177
+ Janus.log("ICE state changed to " + state);
178
+ },
179
+ mediaState: function(medium, on) {
180
+ Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
181
+ },
182
+ webrtcState: function(on) {
183
+ Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
184
+ // $("#audioleft").parent().unblock();
185
+ },
186
+ slowLink: function(uplink, lost) {
187
+ Janus.warn("Janus reports problems " + (uplink ? "sending" : "receiving") +
188
+ " packets on this PeerConnection (" + lost + " lost packets)");
189
+ },
190
+ onmessage: function(msg, jsep) {
191
+ Janus.debug(" ::: Got a message :::");
192
+ Janus.debug(msg);
193
+ if(jsep !== undefined && jsep !== null) {
194
+ Janus.debug("Handling SDP as well...");
195
+ Janus.debug(jsep);
196
+ tts.handleRemoteJsep({jsep: jsep});
197
+ }
198
+ var result = msg["result"];
199
+ if(result !== null && result !== undefined) {
200
+ if(result === "done") {
201
+ // The plugin closed
202
+ bootbox.alert("The TTS Test is over");
203
+ if(spinner !== null && spinner !== undefined)
204
+ spinner.stop();
205
+ spinner = null;
206
+ // $('#myaudio').remove();
207
+ //$('#waitingvideo').remove();
208
+ // $('#peeraudio').remove();
209
+ return;
210
+ }
211
+
212
+ if(result === "msg"){
213
+ if(typeof window.EZUIKit.handleTalkMessage !== 'undefined'){
214
+ window.EZUIKit.handleTalkMessage(msg);
215
+ }
216
+ }
217
+ // Any loss?
218
+ var status = result["status"];
219
+ if(status === "slow_link") {
220
+ //~ var bitrate = result["bitrate"];
221
+ //~ toastr.warning("The bitrate has been cut to " + (bitrate/1000) + "kbps", "Packet loss?", {timeOut: 2000});
222
+ toastr.warning("Janus apparently missed many packets we sent, maybe we should reduce the bitrate", "Packet loss?", {timeOut: 2000});
223
+ }
224
+ }
225
+ },
226
+ onlocalstream: function(stream) {
227
+ Janus.debug(" ::: Got a local stream :::");
228
+ Janus.debug(stream);
229
+
230
+ // if($('#myaudio').length === 0) {
231
+ // $('#audios').removeClass('hide').show();
232
+ // $('#audioleft').append('<audio id="myaudio" autoplay controls muted>Your browser does not support audio tag</audio>');
233
+ // }
234
+ Janus.attachMediaStream(document.getElementById("myaudio"), stream);
235
+ //$("#myaudio").get(0).muted = "muted";
236
+ if(tts.webrtcStuff.pc.iceConnectionState !== "completed" &&
237
+ tts.webrtcStuff.pc.iceConnectionState !== "connected") {
238
+ // $("#audioleft").parent().block({
239
+ // message: '<b>Publishing...</b>',
240
+ // css: {
241
+ // border: 'none',
242
+ // backgroundColor: 'transparent',
243
+ // color: 'white'
244
+ // }
245
+ // });
246
+ // No remote video yet
247
+ //$('#audioright').append('<video class="rounded centered" id="waitingvideo" width=320 height=240 />');
248
+ if(spinner == null) {
249
+ var target = document.getElementById('audioright');
250
+ //spinner = new Spinner({top:100}).spin(target);
251
+ } else {
252
+ spinner.spin();
253
+ }
254
+ }
255
+ var audioTracks = stream.getAudioTracks();
256
+ if(audioTracks === null || audioTracks === undefined || audioTracks.length === 0) {
257
+ // $('#myaudio').hide();
258
+ } else {
259
+ // $('#myaudio').removeClass('hide').show();
260
+ // document.getElementById('myaudio').play();
261
+ }
262
+ },
263
+ onremotestream: function(stream) {
264
+ Janus.debug(" ::: Got a remote stream :::");
265
+ Janus.debug(stream);
266
+ // if($('#peeraudio').length === 0) {
267
+ // $('#audios').removeClass('hide').show();
268
+ // // $('#audioright').append('<audio id="peeraudio" autoplay controls>Your browser does not support audio tag</audio>');
269
+ // // Show the video, hide the spinner and show the resolution when we get a playing event
270
+ // var audio = $('<audio id="peeraudio" autoplay controls playsinline preload="preload" loop="true"></audio>');
271
+ // audio = audio.get(0);
272
+ // audio.setAttribute("id", 'peeraudio');
273
+ // audio.setAttribute("preload","preload");
274
+ // // 自动播放解决苹果不兼容autoplay属性
275
+ // audio.setAttribute("loop",true);
276
+ // $('#audioright').append(audio);
277
+ // $("#peeraudio").bind("playing", function () {
278
+ // //$('#waitingvideo').remove();
279
+ // $('#peeraudio').removeClass('hide').show();
280
+ // if(spinner !== null && spinner !== undefined)
281
+ // spinner.stop();
282
+ // spinner = null;
283
+ // });
284
+ // }
285
+ Janus.attachMediaStream(document.getElementById("peeraudio"), stream);
286
+ var audioTracks = stream.getAudioTracks();
287
+ if(audioTracks === null || audioTracks === undefined || audioTracks.length === 0) {
288
+ // $('#peeraudio').hide();
289
+ } else {
290
+ // $('#peeraudio').removeClass('hide').show();
291
+ document.getElementById('peeraudio').play();
292
+ }
293
+ },
294
+ ondataopen: function(data) {
295
+ Janus.log("The DataChannel is available!");
296
+ },
297
+ ondata: function(data) {
298
+ Janus.debug("We got data from the DataChannel! " + data);
299
+ },
300
+ oncleanup: function() {
301
+ Janus.log(" ::: Got a cleanup notification :::");
302
+ if(spinner !== null && spinner !== undefined)
303
+ spinner.stop();
304
+ spinner = null;
305
+ // $('#myaudio').remove();
306
+ // //$('#waitingvideo').remove();
307
+ // $("#audioleft").parent().unblock();
308
+ // $('#peeraudio').remove();
309
+ }
310
+ });
311
+ },
312
+ error: function(error) {
313
+ Janus.error(error);
314
+ if(window.EZUIKit.handleTalkError !== 'undefined'){
315
+ window.EZUIKit.handleTalkError(error);
316
+ }
317
+ },
318
+ destroyed: function() {
319
+ // window.location.reload();
320
+ }
321
+ });
322
+ }
323
+
324
+ }});
325
+
326
+ function checkEnter(event) {
327
+ var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
328
+ if(theCode == 13) {
329
+ sendData();
330
+ return false;
331
+ } else {
332
+ return true;
333
+ }
334
+ }
335
+
336
+ // Helper to parse query string
337
+ function getQueryStringValue(name) {
338
+ name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
339
+ var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
340
+ results = regex.exec(location.search);
341
+ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
342
+ }
343
+