|
99 | 99 | var EZUIKitPlayer = function (params) { |
100 | 100 | var _this = this; |
101 | 101 | console.log("params", params); |
102 | | - this.opt = { |
103 | | - id: params.id, |
104 | | - apiDomain: 'https://open.ys7.com/api/lapp/live/talk/url', |
105 | | - filePath: 'https://open.ys7.com/assets/ezuikit_v2.6.4', |
106 | | - accessToken: '', |
107 | | - url: '', |
108 | | - deviceSerial: '', |
109 | | - channelNo: '', |
110 | | - talkLink: '', |
111 | | - rtcUrl: '', |
112 | | - ttsUrl: '', |
113 | | - stream: '', |
114 | | - // 对讲插件依赖 |
115 | | - isReliesReady: false, |
116 | | - template: 'simple', |
117 | | - plugin: [], // 加载插件,talk-对讲 |
118 | | - audio: 1,// 声音id 0-不开启 1-开启 |
119 | | - autoplay: 1, |
120 | | - } |
121 | 102 | if (params.id) { |
122 | | - this.opt.id = params.id; |
| 103 | + EZUIKit.opt.id = params.id; |
123 | 104 | } |
124 | 105 | if (params.accessToken) { |
125 | | - this.opt.accessToken = params.accessToken; |
| 106 | + EZUIKit.opt.accessToken = params.accessToken; |
126 | 107 | } |
127 | 108 | if (typeof params.audio !== 'undefined') { |
128 | | - this.opt.audio = params.audio; |
| 109 | + EZUIKit.opt.audio = params.audio; |
129 | 110 | } |
130 | 111 | if (params.url) { |
131 | | - this.opt.url = params.url; |
132 | | - this.opt.deviceSerial = params.url.split("/")[3]; |
133 | | - this.opt.channelNo = params.url.split("/")[4].split(".")[0]; |
| 112 | + EZUIKit.opt.url = params.url; |
| 113 | + EZUIKit.opt.deviceSerial = params.url.split("/")[3]; |
| 114 | + EZUIKit.opt.channelNo = params.url.split("/")[4].split(".")[0]; |
134 | 115 | } |
135 | 116 | if (typeof params.template !== 'undefined') { |
136 | | - this.opt.template = params.template; |
| 117 | + EZUIKit.opt.template = params.template; |
137 | 118 | } |
138 | 119 | if (params.plugin) { |
139 | | - this.opt.plugin = params.plugin; |
| 120 | + EZUIKit.opt.plugin = params.plugin; |
140 | 121 | } |
141 | 122 | if (typeof params.autoplay !== 'undefined') { |
142 | | - this.opt.autoplay = params.autoplay ? 1 : 0; |
| 123 | + EZUIKit.opt.autoplay = params.autoplay ? 1 : 0; |
143 | 124 | } |
144 | 125 |
|
145 | | - let id = this.opt.id; |
| 126 | + let id = EZUIKit.opt.id; |
146 | 127 | var domElement = document.getElementById(id); |
147 | 128 | // 间隙 |
148 | 129 | domElement.style.fontSize = 0; |
|
151 | 132 | */ |
152 | 133 | var iframe = document.createElement('iframe'); |
153 | 134 | function matchIframeUrl() { |
154 | | - switch (_this.opt.template) { |
| 135 | + switch (EZUIKit.opt.template) { |
155 | 136 | case 'simple': |
156 | | - return domain + "/ezopen/h5/iframe?url=" + _this.opt.url + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
157 | | - // return "https://open.ys7.com/ezopen/h5/iframe?url=" + _this.opt.url + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
| 137 | + return domain + "/ezopen/h5/iframe?url=" + EZUIKit.opt.url + "&autoplay=" + EZUIKit.opt.autoplay + "&audio=" + EZUIKit.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
| 138 | + // return "https://open.ys7.com/ezopen/h5/iframe?url=" + EZUIKit.opt.url + "&autoplay=" + EZUIKit.opt.autoplay + "&audio=" + EZUIKit.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
158 | 139 | case 'standard': |
159 | | - return domain + "/ezopen/h5/iframe?url=" + _this.opt.url + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=1"; |
| 140 | + return domain + "/ezopen/h5/iframe?url=" + EZUIKit.opt.url + "&autoplay=" + EZUIKit.opt.autoplay + "&audio=" + EZUIKit.opt.audio + "&accessToken=" + params.accessToken + "&templete=1"; |
160 | 141 | case 'security': |
161 | | - return domain + "/ezopen/h5/iframe_se?url=" + _this.opt.url + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
| 142 | + return domain + "/ezopen/h5/iframe_se?url=" + EZUIKit.opt.url + "&autoplay=" + EZUIKit.opt.autoplay + "&audio=" + EZUIKit.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
162 | 143 | default: |
163 | | - return domain + "/ezopen/h5/iframe?url=" + _this.opt.url + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
| 144 | + return domain + "/ezopen/h5/iframe?url=" + EZUIKit.opt.url + "&autoplay=" + EZUIKit.opt.autoplay + "&audio=" + EZUIKit.opt.audio + "&accessToken=" + params.accessToken + "&templete=0"; |
164 | 145 | } |
165 | 146 | } |
166 | 147 | iframe.src = matchIframeUrl(); |
|
182 | 163 | iframe.setAttribute("frameborder", 0) |
183 | 164 | console.log("iframe", iframe) |
184 | 165 | domElement.appendChild(iframe) |
185 | | - var jqueryJS = _this.opt.filePath + '/js/jquery.js'; |
| 166 | + var jqueryJS = EZUIKit.opt.filePath + '/js/jquery.js'; |
186 | 167 | var layerJs = 'https://open.ys7.com/assets/layer/layer.js'; |
187 | | - var recoderCSS = _this.opt.filePath + '/npm/css/recoder.css'; |
| 168 | + var recoderCSS = EZUIKit.opt.filePath + '/npm/css/recoder.css'; |
188 | 169 | addCss(recoderCSS, function () { |
189 | 170 |
|
190 | 171 | }) |
|
306 | 287 | hdModule: false, |
307 | 288 | fullScreenModule: false, |
308 | 289 | } |
309 | | - var template = _this.opt.template; |
| 290 | + var template = EZUIKit.opt.template; |
310 | 291 | switch (template) { |
311 | 292 | case 'simple': |
312 | 293 | if (params.footer && params.footer instanceof Array) { |
|
354 | 335 | saveModule: false, |
355 | 336 | zoomModule: false, |
356 | 337 | } |
357 | | - var template = _this.opt.template; |
| 338 | + var template = EZUIKit.opt.template; |
358 | 339 | switch (template) { |
359 | 340 | case 'simple': |
360 | 341 | if (params.header && params.header instanceof Array) { |
|
382 | 363 | } |
383 | 364 | return result; |
384 | 365 | } |
385 | | - if (matchFooterOpt().footerContainer || _this.opt.plugin.indexOf('talk') !== -1) { |
386 | | - var recoderCSS = _this.opt.filePath + '/npm/css/recoder.css'; |
387 | | - var recoderJs = _this.opt.filePath + '/npm/js/recoder.js'; |
388 | | - var recorderJs = _this.opt.filePath + '/recorder.js'; |
| 366 | + if (matchFooterOpt().footerContainer || EZUIKit.opt.plugin.indexOf('talk') !== -1) { |
| 367 | + var recoderCSS = EZUIKit.opt.filePath + '/npm/css/recoder.css'; |
| 368 | + var recoderJs = EZUIKit.opt.filePath + '/npm/js/recoder.js'; |
| 369 | + var recorderJs = EZUIKit.opt.filePath + '/recorder.js'; |
389 | 370 | // addCss() |
390 | 371 | addCss(recoderCSS, function () { |
391 | 372 | addJs(recoderJs, function () { |
392 | 373 | addJs(recorderJs, function () { |
393 | 374 | // 对讲模块 |
394 | | - if (_this.opt.plugin.indexOf('talk') !== -1 || matchFooterOpt().talkModule) { |
| 375 | + if (EZUIKit.opt.plugin.indexOf('talk') !== -1 || matchFooterOpt().talkModule) { |
395 | 376 | function apiSuccess(data) { |
396 | 377 | console.log("data", data); |
397 | 378 | if (data.code == 200) { |
|
402 | 383 | if (rtcTrunk.indexOf("ws") === -1) { |
403 | 384 | rtcTrunk = rtcTrunk.replace("https", "wss").replace("rtcgw", "rtcgw-ws"); |
404 | 385 | } |
405 | | - _this.opt.rtcUrl = rtcTrunk; |
406 | | - _this.opt.ttsUrl = "tts://" + apiResult.ttsUrl; |
407 | | - var talk = "talk://" + _this.opt.deviceSerial + ":0:" + _this.opt.channelNo + ":cas.ys7.com:6500"; |
408 | | - _this.opt.talkLink = _this.opt.ttsUrl + "/" + talk; |
409 | | - _this.opt.stream = apiResult.stream; |
410 | | - console.log("_this.opt", _this.opt) |
| 386 | + EZUIKit.opt.rtcUrl = rtcTrunk; |
| 387 | + EZUIKit.opt.ttsUrl = "tts://" + apiResult.ttsUrl; |
| 388 | + var talk = "talk://" + EZUIKit.opt.deviceSerial + ":0:" + EZUIKit.opt.channelNo + ":cas.ys7.com:6500"; |
| 389 | + EZUIKit.opt.talkLink = EZUIKit.opt.ttsUrl + "/" + talk; |
| 390 | + EZUIKit.opt.stream = apiResult.stream; |
| 391 | + console.log("EZUIKit.opt", EZUIKit.opt) |
411 | 392 | // 加载依赖 |
412 | | - if (!_this.opt.isReliesReady) { |
413 | | - var adapeterJS = _this.opt.filePath + '/npm/js/adapeter.js'; |
414 | | - var janusJS = _this.opt.filePath + '/npm/js/janus.js'; |
415 | | - var ttsJS = _this.opt.filePath + '/npm/js/tts.js'; |
| 393 | + if (!EZUIKit.opt.isReliesReady) { |
| 394 | + var adapeterJS = EZUIKit.opt.filePath + '/npm/js/adapeter.js'; |
| 395 | + var janusJS = EZUIKit.opt.filePath + '/npm/js/janus.js'; |
| 396 | + var ttsJS = EZUIKit.opt.filePath + '/npm/js/tts.js'; |
416 | 397 | console.log("加载jquery.js"); |
417 | 398 | addJs(adapeterJS, function () { |
418 | 399 | console.log("加载adapeter.js"); |
|
421 | 402 | addJs(ttsJS, function () { |
422 | 403 | console.log("加载tts.js"); |
423 | 404 | // 文件加载完毕; |
424 | | - _this.opt.isReliesReady = true; |
| 405 | + EZUIKit.opt.isReliesReady = true; |
425 | 406 | }) |
426 | 407 | }) |
427 | 408 | }) |
|
450 | 431 |
|
451 | 432 | } |
452 | 433 | request( |
453 | | - _this.opt.apiDomain, |
| 434 | + EZUIKit.opt.apiDomain, |
454 | 435 | 'POST', |
455 | 436 | { |
456 | | - accessToken: _this.opt.accessToken, |
457 | | - deviceSerial: _this.opt.deviceSerial, |
458 | | - channelNo: _this.opt.channelNo |
| 437 | + accessToken: EZUIKit.opt.accessToken, |
| 438 | + deviceSerial: EZUIKit.opt.deviceSerial, |
| 439 | + channelNo: EZUIKit.opt.channelNo |
459 | 440 | }, |
460 | 441 | '', |
461 | 442 | apiSuccess, |
|
476 | 457 | // 高清-标清切换 |
477 | 458 | var hdDom = document.createElement('span'); |
478 | 459 | hdDom.setAttribute('id', 'video-hd'); |
479 | | - hdDom.innerHTML = _this.opt.url.indexOf('.hd') === -1 ? '标清' : '高清'; |
| 460 | + hdDom.innerHTML = EZUIKit.opt.url.indexOf('.hd') === -1 ? '标清' : '高清'; |
480 | 461 | hdDom.onclick = function () { |
481 | 462 | // 停止 |
482 | 463 | _this.stop(); |
483 | | - if (_this.opt.url.indexOf('.hd') === -1) { |
484 | | - _this.opt.url = _this.opt.url.replace('.live', '.hd.live'); |
485 | | - hdDom.innerHTML = _this.opt.url.indexOf('.hd') === -1 ? '标清' : '高清'; |
| 464 | + if (EZUIKit.opt.url.indexOf('.hd') === -1) { |
| 465 | + EZUIKit.opt.url = EZUIKit.opt.url.replace('.live', '.hd.live'); |
| 466 | + hdDom.innerHTML = EZUIKit.opt.url.indexOf('.hd') === -1 ? '标清' : '高清'; |
486 | 467 | } else { |
487 | | - _this.opt.url = _this.opt.url.replace('.hd.live', '.live') |
| 468 | + EZUIKit.opt.url = EZUIKit.opt.url.replace('.hd.live', '.live') |
488 | 469 | } |
489 | | - iframe.src = "https://open.ys7.com/ezopen/h5/iframe?url=" + _this.opt.url.replace('.hd.live', '.live') + "&autoplay=1&audio=" + _this.opt.audio + "&accessToken=" + _this.opt.accessToken + "&templete=" + 0; |
| 470 | + iframe.src = "https://open.ys7.com/ezopen/h5/iframe?url=" + EZUIKit.opt.url.replace('.hd.live', '.live') + "&autoplay=1&audio=" + EZUIKit.opt.audio + "&accessToken=" + EZUIKit.opt.accessToken + "&templete=" + 0; |
490 | 471 | } |
491 | 472 | rightContros.appendChild(hdDom); |
492 | 473 | } |
|
519 | 500 | rightContros.appendChild(closeSoundDOM); |
520 | 501 | } |
521 | 502 | // 根据当前音频配置展示 |
522 | | - if (_this.opt.audio == 1) { |
| 503 | + if (EZUIKit.opt.audio == 1) { |
523 | 504 | closeSoundDOM.setAttribute('class', ''); |
524 | 505 | } else { |
525 | 506 | openSoundDOM.setAttribute('class', ''); |
|
686 | 667 | 'https://open.ys7.com/api/lapp/voice/query', |
687 | 668 | 'POST', |
688 | 669 | { |
689 | | - accessToken: _this.opt.accessToken, |
| 670 | + accessToken: EZUIKit.opt.accessToken, |
690 | 671 | pageStart: page, |
691 | 672 | pageSize: EZUIKit.state.pageSize, |
692 | 673 | default: EZUIKit.state.fetchDefaultList ? 'true' : 'false' |
|
742 | 723 | 'https://open.ys7.com/api/lapp/voice/send', |
743 | 724 | 'POST', |
744 | 725 | { |
745 | | - accessToken: _this.opt.accessToken, |
746 | | - deviceSerial: _this.opt.deviceSerial, |
747 | | - channelNo: _this.opt.channelNo, |
| 726 | + accessToken: EZUIKit.opt.accessToken, |
| 727 | + deviceSerial: EZUIKit.opt.deviceSerial, |
| 728 | + channelNo: EZUIKit.opt.channelNo, |
748 | 729 | fileUrl: voiceUrl, |
749 | 730 | }, |
750 | 731 | '', |
|
902 | 883 | countTime('sub', EZUIKit.state.recodeTime + 2); // 延时 |
903 | 884 | var formdata = new FormData(); // form 表单 {key:value} |
904 | 885 | formdata.append("voiceFile", wav_file); // form input type="file" |
905 | | - formdata.append("accessToken", _this.opt.accessToken); |
906 | | - formdata.append("deviceSerial", _this.opt.deviceSerial); |
907 | | - formdata.append("channelNo", _this.opt.channelNo); |
| 886 | + formdata.append("accessToken", EZUIKit.opt.accessToken); |
| 887 | + formdata.append("deviceSerial", EZUIKit.opt.deviceSerial); |
| 888 | + formdata.append("channelNo", EZUIKit.opt.channelNo); |
908 | 889 | // padding = true; |
909 | 890 |
|
910 | 891 | function apiSuccess(data) { |
|
928 | 909 | 'POST', |
929 | 910 | { |
930 | 911 | voiceFile: wav_file, |
931 | | - accessToken: _this.opt.accessToken, |
932 | | - deviceSerial: _this.opt.deviceSerial, |
933 | | - channelNo: _this.opt.channelNo, |
| 912 | + accessToken: EZUIKit.opt.accessToken, |
| 913 | + deviceSerial: EZUIKit.opt.deviceSerial, |
| 914 | + channelNo: EZUIKit.opt.channelNo, |
934 | 915 | }, |
935 | 916 | '', |
936 | 917 | apiSuccess, |
|
1097 | 1078 |
|
1098 | 1079 | // 播放相关API |
1099 | 1080 | EZUIKitPlayer.prototype.play = function () { |
1100 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1081 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1101 | 1082 | var player = document.getElementById(id).contentWindow; |
1102 | 1083 | player.postMessage("play", domain + "/ezopen/h5/iframe") |
1103 | 1084 | } |
1104 | 1085 | EZUIKitPlayer.prototype.stop = function () { |
1105 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1086 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1106 | 1087 | var player = document.getElementById(id).contentWindow; |
1107 | 1088 | player.postMessage("stop", domain + "/ezopen/h5/iframe") |
1108 | 1089 | } |
1109 | 1090 | EZUIKitPlayer.prototype.openSound = function () { |
1110 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1091 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1111 | 1092 | var player = document.getElementById(id).contentWindow; |
1112 | 1093 | player.postMessage("openSound", domain + "/ezopen/h5/iframe"); |
1113 | 1094 | } |
1114 | 1095 | EZUIKitPlayer.prototype.closeSound = function () { |
1115 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1096 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1116 | 1097 | var player = document.getElementById(id).contentWindow; |
1117 | 1098 | player.postMessage("closeSound", domain + "/ezopen/h5/iframe") |
1118 | 1099 | } |
1119 | 1100 | EZUIKitPlayer.prototype.startSave = function () { |
1120 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1101 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1121 | 1102 | var player = document.getElementById(id).contentWindow; |
1122 | 1103 | player.postMessage("startSave", domain + "/ezopen/h5/iframe") |
1123 | 1104 | } |
1124 | 1105 | EZUIKitPlayer.prototype.stopSave = function () { |
1125 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1106 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1126 | 1107 | var player = document.getElementById(id).contentWindow; |
1127 | 1108 | player.postMessage("stopSave", domain + "/ezopen/h5/iframe") |
1128 | 1109 | } |
1129 | 1110 | EZUIKitPlayer.prototype.fullScreen = function () { |
1130 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1111 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1131 | 1112 | var player = document.getElementById(id).contentWindow; |
1132 | 1113 | player.postMessage("fullScreen", domain + "/ezopen/h5/iframe") |
1133 | 1114 | } |
1134 | 1115 | EZUIKitPlayer.prototype.capturePicture = function () { |
1135 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1116 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1136 | 1117 | var player = document.getElementById(id).contentWindow; |
1137 | 1118 | player.postMessage("capturePicture", domain + "/ezopen/h5/iframe") |
1138 | 1119 | } |
1139 | 1120 | EZUIKitPlayer.prototype.enableZoom = function () { |
1140 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1121 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1141 | 1122 | var player = document.getElementById(id).contentWindow; |
1142 | 1123 | player.postMessage("enableZoom", domain + "/ezopen/h5/iframe") |
1143 | 1124 | } |
1144 | 1125 | EZUIKitPlayer.prototype.closeZoom = function () { |
1145 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1126 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1146 | 1127 | var player = document.getElementById(id).contentWindow; |
1147 | 1128 | player.postMessage("closeZoom", domain + "/ezopen/h5/iframe") |
1148 | 1129 | } |
1149 | 1130 | EZUIKitPlayer.prototype.getOSDTime = function () { |
1150 | | - var id = 'EZUIKitPlayer-' + this.opt.id; |
| 1131 | + var id = 'EZUIKitPlayer-' + EZUIKit.opt.id; |
1151 | 1132 | var player = document.getElementById(id).contentWindow; |
1152 | 1133 | player.postMessage("getOSDTime", domain + "/ezopen/h5/iframe") |
1153 | 1134 | } |
|
0 commit comments