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

Skip to content

Commit 640712c

Browse files
committed
[CHG]对讲支持事件回调(onMessage),错误回调(onError)
1 parent 28bb07a commit 640712c

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

ezuikit-talk.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@
2020

2121
// Pass this if window is not defined yet
2222
})(typeof window !== "undefined" ? window : this, function (window, noGlobal) {
23-
// 加载js
23+
function PrefixCode(code,msg) {
24+
if(parseInt(code,10) > 0){
25+
var PRECODE = 102;
26+
var retcode = '102' + (code/Math.pow(10,5)).toFixed(5).substr(2);
27+
} else if (code == -1) {
28+
retcode = -1;
29+
}else if (typeof code === 'undefined'){
30+
retcode = 0;
31+
}
32+
return {
33+
code : retcode,
34+
data: msg,
35+
}
36+
// function PrefixInteger(num, length) {
37+
// return (num/Math.pow(10,length)).toFixed(length).substr(2);
38+
// }
39+
}
40+
// 加载js
2441
function addJs(filepath, callback) {
2542
var oJs = document.createElement("script");
2643
oJs.setAttribute("src", filepath);
@@ -48,10 +65,7 @@
4865
http_request.send(data);
4966
};
5067
var EZUITalk = function (params) {
51-
console.log("params",params);
52-
// this.opt = {
53-
// apiDomain: 'https://test12open.ys7.com/api/lapp/live/talk/url'
54-
// }
68+
this.params = params;
5569
this.opt = {
5670
apiDomain: 'https://open.ys7.com/api/lapp/live/talk/url',
5771
filePath: '',
@@ -93,7 +107,7 @@
93107
// 加载依赖
94108
// this.init();
95109
var adapeterJS = _this.opt.filePath + '/adapeter.js';
96-
var janusJS = _this.opt.filePath + '/janus.js';
110+
var janusJS = _this.opt.filePath + '/rtcgw.js';
97111
var ttsJS = _this.opt.filePath + '/tts.js';
98112
console.log("加载jquery.js");
99113
addJs(adapeterJS,function(){
@@ -103,19 +117,31 @@
103117
addJs(ttsJS,function(){
104118
console.log("加载tts.js");
105119
// 文件加载完毕;
106-
120+
if (typeof params.onMessage === 'function') {
121+
params.onMessage({
122+
code : 10200001,
123+
data: "插件加载成功"
124+
});
125+
}
107126
})
108127
})
109128
})
129+
} else {
130+
if (typeof params.onError === 'function') {
131+
params.onError(PrefixCode(data.code,data));
132+
}
110133
}
111134

135+
} else {
136+
if (typeof params.onError === 'function') {
137+
params.onError(PrefixCode(data.code,data));
138+
}
112139
}
113140
}
114141
function apiError(err){
115-
if(params.handleError){
116-
params.handleError(err);
142+
if(params.onError){
143+
params.onError(err);
117144
}
118-
119145
}
120146
request(
121147
this.opt.apiDomain,

0 commit comments

Comments
 (0)