Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0160dcc

Browse files
committed
[CHG]更新对讲目录,支持回调
1 parent 174d9f6 commit 0160dcc

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

js/talk/tts.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ var opaqueId = "tts-"+Janus.randomString(12);
5858

5959
var spinner = null;
6060

61+
function PrefixCode(code,msg) {
62+
63+
if(parseInt(code,10) > 0){
64+
var PRECODE = 102;
65+
var retcode = '102' + (code/Math.pow(10,5)).toFixed(5).substr(2);
66+
} else if (code == -1) {
67+
retcode = -1;
68+
}else if (typeof code === 'undefined'){
69+
retcode = 0;
70+
}
71+
return {
72+
code : retcode,
73+
data: msg,
74+
}
75+
// function PrefixInteger(num, length) {
76+
// return (num/Math.pow(10,length)).toFixed(length).substr(2);
77+
// }
78+
}
79+
6180
$(document).ready(function() {
6281
// Initialize the library (all console debuggers enabled)
6382
Janus.init({debug: "all", callback: function() {
@@ -129,6 +148,9 @@ $(document).ready(function() {
129148
},
130149
error: function(error) {
131150
Janus.error("WebRTC error:", error);
151+
if (typeof window.EZUITalk.params.onError === 'function') {
152+
window.EZUITalk.params.onError(PrefixCode(-1,error))
153+
}
132154
// bootbox.alert("WebRTC error... " + JSON.stringify(error));
133155
}
134156
});
@@ -141,6 +163,9 @@ $(document).ready(function() {
141163
error: function(error) {
142164
console.error(" -- Error attaching plugin...", error);
143165
bootbox.alert("Error attaching plugin... " + error);
166+
if (typeof window.EZUITalk.params.onError === 'function') {
167+
window.EZUITalk.params.onError(PrefixCode(-1,error))
168+
}
144169
},
145170
consentDialog: function(on) {
146171
Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
@@ -204,6 +229,12 @@ $(document).ready(function() {
204229
toastr.warning("Janus apparently missed many packets we sent, maybe we should reduce the bitrate", "Packet loss?", {timeOut: 2000});
205230
}
206231
}
232+
var events = msg["event"];
233+
if (events !== null && events !== undefined) {
234+
if (typeof window.EZUITalk.params.onMessage === 'function') {
235+
window.EZUITalk.params.onMessage.onMessage(PrefixCode(msg["code"],msg));
236+
}
237+
}
207238
},
208239
onlocalstream: function(stream) {
209240
Janus.debug(" ::: Got a local stream :::");
@@ -283,9 +314,9 @@ $(document).ready(function() {
283314
},
284315
error: function(error) {
285316
Janus.error(error);
286-
bootbox.alert(error, function() {
287-
// window.location.reload();
288-
});
317+
if (typeof window.EZUITalk.params.onError === 'function') {
318+
window.EZUITalk.params.onError(PrefixCode(-1,error))
319+
}
289320
},
290321
destroyed: function() {
291322
// window.location.reload();
@@ -295,12 +326,8 @@ $(document).ready(function() {
295326
window.stopTalk = function (){
296327
janus.destroy();
297328
}
298-
EZUITalkStopTalk = function (){
299-
janus.destroy();
300-
}
301329
// debugger;
302-
window.startTalk = startTalk;
303-
function startTalk() {
330+
window.startTalk = function() {
304331
// Make sure the browser supports WebRTC
305332
if(!Janus.isWebrtcSupported()) {
306333
bootbox.alert("No WebRTC support... ");
@@ -365,10 +392,15 @@ $(document).ready(function() {
365392
Janus.debug("Got SDP!");
366393
Janus.debug(jsep);
367394
tts.send({"message": body, "jsep": jsep});
395+
if (typeof window.EZUITalk.params.onMessage === 'function') {
396+
window.EZUITalk.params.onMessage(PrefixCode(200, 'start talk success!'))
397+
}
368398
},
369399
error: function(error) {
370400
Janus.error("WebRTC error:", error);
371-
// bootbox.alert("WebRTC error... " + JSON.stringify(error));
401+
if (typeof window.EZUITalk.params.onError === 'function') {
402+
window.EZUITalk.params.onError(PrefixCode(-1,error))
403+
}
372404
}
373405
});
374406
// $('#start').removeAttr('disabled').html("Stop")
@@ -380,6 +412,9 @@ $(document).ready(function() {
380412
error: function(error) {
381413
console.error(" -- Error attaching plugin...", error);
382414
bootbox.alert("Error attaching plugin... " + error);
415+
if (typeof window.EZUITalk.params.onError === 'function') {
416+
window.EZUITalk.params.onError(PrefixCode(-1,error))
417+
}
383418
},
384419
consentDialog: function(on) {
385420
Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
@@ -523,9 +558,15 @@ $(document).ready(function() {
523558
error: function(error) {
524559
Janus.error(error);
525560
console.log("error",error)
561+
if (typeof window.EZUITalk.params.onError === 'function') {
562+
window.EZUITalk.params.onError(PrefixCode(-1,error))
563+
}
526564
},
527565
destroyed: function() {
528566
// window.location.reload();
567+
if (typeof window.EZUITalk.params.onMessage === 'function') {
568+
window.EZUITalk.params.onMessage(PrefixCode(400, 'webrtc destroyed'))
569+
}
529570
}
530571
});
531572
}

0 commit comments

Comments
 (0)