ezuikit.js 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. "use strict";
  2. /**
  3. * EZUIKitPlayer for npm
  4. */
  5. (function (global, factory) {
  6. "use strict";
  7. if (typeof module === "object" && typeof module.exports === "object") {
  8. module.exports = global.document ? factory(global, true) : function (w) {
  9. if (!w.document) {
  10. throw new Error("EZUIPlayer requires a window with a document");
  11. }
  12. return factory(w);
  13. };
  14. } else {
  15. factory(global);
  16. } // Pass this if window is not defined yet
  17. })(typeof window !== "undefined" ? window : void 0, function (window, noGlobal) {
  18. // 加载js
  19. function addJs(filepath, callback) {
  20. var headerScript = document.getElementsByTagName('head')[0].getElementsByTagName("script");
  21. var isReady = false;
  22. for (var i = 0; i < headerScript.length; i++) {
  23. if (headerScript[i].getAttribute("src") == filepath) {
  24. isReady = true;
  25. callback();
  26. }
  27. }
  28. if (!isReady) {
  29. var oJs = document.createElement("script");
  30. oJs.setAttribute("src", filepath);
  31. oJs.onload = callback;
  32. document.getElementsByTagName("head")[0].appendChild(oJs);
  33. }
  34. } // 加载css
  35. function addCss(filepath, callback) {
  36. var headerLink = document.getElementsByTagName('head')[0].getElementsByTagName("link");
  37. var isReady = false;
  38. for (var i = 0; i < headerLink.length; i++) {
  39. if (headerLink[i].getAttribute("href") == filepath) {
  40. isReady = true;
  41. callback();
  42. }
  43. }
  44. if (!isReady) {
  45. var oJs = document.createElement('link');
  46. oJs.rel = 'stylesheet';
  47. oJs.type = 'text/css';
  48. oJs.href = filepath;
  49. oJs.onload = callback;
  50. document.getElementsByTagName("head")[0].appendChild(oJs);
  51. }
  52. } // 通用请求方法
  53. function request(url, method, params, header, success, error) {
  54. var _url = url;
  55. var http_request = new XMLHttpRequest();
  56. http_request.onreadystatechange = function () {
  57. if (http_request.readyState == 4) {
  58. if (http_request.status == 200) {
  59. var _data = JSON.parse(http_request.responseText);
  60. success(_data);
  61. }
  62. }
  63. };
  64. http_request.open(method, _url, true); // http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  65. var data = new FormData();
  66. for (var i in params) {
  67. data.append(i, params[i]);
  68. }
  69. http_request.send(data);
  70. }
  71. var requestFullScreen = function (element) {
  72. var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
  73. if (requestMethod) {
  74. requestMethod.call(element);
  75. } else if (typeof window.ActiveXObject !== "undefined") {
  76. var wscript = new ActiveXObject("WScript.Shell");
  77. if (wscript !== null) {
  78. wscript.SendKeys("{F11}");
  79. }
  80. }
  81. }
  82. ; // 全局属性
  83. var EZUIKit = {
  84. EZUIKitPlayer: undefined,
  85. EZUIKitTalk: undefined,
  86. opt: {
  87. apiDomain: 'https://open.ys7.com/api/lapp/live/talk/url',
  88. filePath: 'https://open.ys7.com/assets/ezuikit_v2.6.4',
  89. accessToken: '',
  90. url: '',
  91. deviceSerial: '',
  92. channelNo: '',
  93. id: '',
  94. talkLink: '',
  95. rtcUrl: '',
  96. ttsUrl: '',
  97. stream: '',
  98. // 对讲插件依赖
  99. isReliesReady: false,
  100. template: 'simple',
  101. plugin: [],
  102. // 加载插件,talk-对讲
  103. audio: 1,
  104. // 声音id 0-不开启 1-开启
  105. autoplay: 1,
  106. videoLoading: false,
  107. },
  108. state: {
  109. countTimer: undefined,
  110. // countTime 计时器
  111. recodeTime: 0,
  112. // 录音时间
  113. recodeTimer: undefined,
  114. //录音时长 计时器
  115. recodeTime: 0,
  116. fetchDefaultList: false,
  117. // 是否拉取默认语音-当用户语音为空
  118. page: 0,
  119. // 语音当前页
  120. pageSize: 5
  121. },
  122. handleTalkSuccess: function(){},
  123. handleTalkError: function(){},
  124. };
  125. /**
  126. * 视频播放器-开始
  127. */
  128. var domain = "https://open.ys7.com";
  129. var filePathDomain = domain;
  130. var EZUIKitPlayer = function EZUIKitPlayer(params) {
  131. var _this = this;
  132. this.opt = {
  133. id: params.id,
  134. apiDomain: domain + '/api/lapp/live/talk/url',
  135. filePath: filePathDomain + '/assets/ezuikit_v2.6.4',
  136. decoderVersion: '',
  137. accessToken: '',
  138. url: '',
  139. deviceSerial: '',
  140. channelNo: '',
  141. talkLink: '',
  142. rtcUrl: '',
  143. ttsUrl: '',
  144. stream: '',
  145. // 对讲插件依赖
  146. isReliesReady: false,
  147. template: 'simple',
  148. plugin: [],
  149. // 加载插件,talk-对讲
  150. audio: 1,
  151. // 声音id 0-不开启 1-开启
  152. autoplay: 1,
  153. fullScreenStatus: 0,
  154. bSupporDoubleClickFull: true,
  155. videoLoading: false,
  156. };
  157. this.params = params;
  158. if (params.id) {
  159. this.opt.id = params.id;
  160. }
  161. if (params.accessToken) {
  162. this.opt.accessToken = params.accessToken;
  163. }
  164. if (typeof params.audio !== 'undefined') {
  165. this.opt.audio = params.audio;
  166. }
  167. if (typeof params.decoderVersion !== 'undefined') {
  168. this.opt.decoderVersion = params.decoderVersion;
  169. }
  170. if (typeof params.env !== 'undefined') {
  171. if(typeof params.env.domain !== 'undefined'){
  172. domain = params.env.domain;
  173. this.opt.apiDomain = domain + '/api/lapp/live/talk/url';
  174. }
  175. if(typeof params.env.filePathDomain !== 'undefined'){
  176. filePathDomain = params.env.filePathDomain;
  177. this.opt.filePathDomain = params.env.filePathDomain;
  178. }
  179. }
  180. // if(typeof params.domain !== 'undefined'){
  181. // this.opt.apiDomain = params.domain + '/api/lapp/live/talk/url';
  182. // }
  183. if (params.url) {
  184. this.opt.url = params.url;
  185. this.opt.deviceSerial = params.url.split("/")[3];
  186. this.opt.channelNo = params.url.split("/")[4].split(".")[0];
  187. }
  188. if (typeof params.template !== 'undefined') {
  189. this.opt.template = params.template;
  190. }
  191. if (params.plugin) {
  192. this.opt.plugin = params.plugin;
  193. }
  194. if (typeof params.autoplay !== 'undefined') {
  195. this.opt.autoplay = params.autoplay ? 1 : 0;
  196. }
  197. if (typeof params.bSupporDoubleClickFull !== 'undefined') {
  198. this.opt.bSupporDoubleClickFull = params.bSupporDoubleClickFull;
  199. }
  200. if (typeof params.handleTalkSuccess !== 'undefined') {
  201. window.EZUIKit.handleTalkSuccess = params.handleTalkSuccess;
  202. }
  203. if (typeof params.handleTalkError !== 'undefined') {
  204. window.EZUIKit.handleTalkError = params.handleTalkError;
  205. }
  206. var id = this.opt.id;
  207. var domElement = document.getElementById(id); // 间隙
  208. domElement.style.fontSize = 0;
  209. domElement.style.overflowY = 'auto';
  210. domElement.style.position = 'relative';
  211. /**
  212. * 渲染iframe视频框
  213. */
  214. var iframe = document.createElement('iframe');
  215. function matchIframeUrl() {
  216. switch (_this.opt.template) {
  217. case 'simple':
  218. var iframeUrl = domain + "/ezopen/h5/iframe?bSupporDoubleClickFull=0&url=" + _this.opt.url.replace("?","&") + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0" + "&id=" + id + "&decoderVersion=" + _this.opt.decoderVersion;
  219. var controlsValue = "";
  220. if(typeof params.controls !== 'undefined' && params.controls){
  221. console.log("typeof" ,typeof params.controls)
  222. controlsValue = "play,voice,hd,fullScreen";
  223. if(params.controls.length > 0){
  224. controlsValue = params.controls.join(",");
  225. iframeUrl += ('&controls=' + controlsValue);
  226. }
  227. }
  228. if (params.websocketParams) {
  229. iframeUrl += ('&websocketParams=' + JSON.stringify(params.websocketParams))
  230. }
  231. return iframeUrl;
  232. case 'standard':
  233. return domain + "/ezopen/h5/iframe?bSupporDoubleClickFull=0&url=" + _this.opt.url.replace("?","&") + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=1" + "&id=" + id + "&decoderVersion=" + _this.opt.decoderVersion;
  234. case 'security':
  235. return domain + "/ezopen/h5/iframe_se?bSupporDoubleClickFull=0&url=" + _this.opt.url.replace("?","&") + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0" + "&id=" + id + "&decoderVersion=" + _this.opt.decoderVersion;
  236. case 'theme':
  237. iframeUrl = domain +`/jssdk/theme.html?url=${params.url}&accessToken=${params.accessToken}&id=${id}&isMobile=${params.isMobile}`;
  238. if(typeof params.isMobile !== 'undefined') {
  239. iframeUrl += '&isMobile=' + params.isMobile;
  240. }
  241. if(typeof params.autoplay !== 'undefined') {
  242. iframeUrl += '&autoplay=' + params.autoplay;
  243. }
  244. if(typeof params.domain !== 'undefined') {
  245. if(params.domain == 'https://test12open.ys7.com')
  246. iframeUrl += '&env=' + 'test12';
  247. }
  248. if (typeof params.env !== 'undefined') {
  249. if(typeof params.env.domain !== 'undefined'){
  250. if(params.env.domain == 'https://test12open.ys7.com'){
  251. iframeUrl += '&env=' + 'test12';
  252. }
  253. }
  254. }
  255. if(typeof params.header !== 'undefined') {
  256. iframeUrl += '&header=' + params.header;
  257. }
  258. return iframeUrl;
  259. default:
  260. return domain + "/ezopen/h5/iframe?bSupporDoubleClickFull=0&url=" + _this.opt.url.replace("?","&") + "&autoplay=" + _this.opt.autoplay + "&audio=" + _this.opt.audio + "&accessToken=" + params.accessToken + "&templete=0" + "&id=" + id + "&decoderVersion=" + _this.opt.decoderVersion;
  261. }
  262. }
  263. iframe.src = matchIframeUrl(); // 默认取容器宽高
  264. var iframeHeight = document.getElementById(id).offsetHeight;
  265. var iframeWidth = document.getElementById(id).offsetWidth;
  266. if (params.height) {
  267. iframeHeight = parseInt(params.height);
  268. if(/\%$/.test(params.height)) {
  269. iframeWidth = document.getElementById(id).offsetWidth * (parseInt(params.height) /100);
  270. }
  271. }
  272. if (params.width) {
  273. iframeWidth = parseInt(params.width);
  274. if(/\%$/.test(params.width)) {
  275. iframeWidth = document.getElementById(id).offsetWidth * (parseInt(params.width) /100);
  276. }
  277. }
  278. iframe.width = iframeWidth;
  279. iframe.height = iframeHeight;
  280. iframe.id = 'EZUIKitPlayer-' + id; // 部分iframe属性
  281. iframe.setAttribute("allowfullscreen", true);
  282. iframe.setAttribute("allow", "autoplay");
  283. iframe.setAttribute("frameborder", 0);
  284. domElement.appendChild(iframe);
  285. var jqueryJS = _this.opt.filePath + '/js/jquery.js';
  286. var layerJs = 'https://open.ys7.com/assets/layer/layer.js';
  287. addJs(jqueryJS, function () {
  288. addJs(layerJs, function () {
  289. // });
  290. // });
  291. /**
  292. * 渲染header
  293. */
  294. if (matchHeaderOpt().headerContainer) {
  295. // if (params.header && params.header instanceof Array) {
  296. var headerContainer = document.createElement('div');
  297. headerContainer.setAttribute('class', 'panel-top');
  298. var controsDOM = document.createElement('div');
  299. controsDOM.setAttribute('class', 'contros');
  300. headerContainer.appendChild(controsDOM);
  301. domElement.insertBefore(headerContainer, iframe);
  302. if (matchHeaderOpt().capturePictureModule) {
  303. // 截图
  304. var capturePictureDOM = document.createElement('span');
  305. capturePictureDOM.innerHTML = '<span title="截图">' + '<svg id="capturePicture" title="截图" t="1578882764585" class="icon" viewBox="0 0 1024 1024" version="1.1"' + ' xmlns="http://www.w3.org/2000/svg" p-id="5958" width="24" height="24">' + ' <path' + ' d="M887.296 315.904h-153.6c-51.2 0-68.096-102.4-119.296-102.4H392.704c-34.304 0-51.2 102.4-102.4 102.4h-153.6c-29.696 0-51.2 21.504-51.2 51.2v439.296c0 25.6 21.504 47.104 51.2 47.104h751.104c29.696 0 51.2-21.504 51.2-51.2v-435.2c-0.512-30.208-21.504-51.2-51.712-51.2zM512 768c-115.2 0-204.8-89.6-204.8-200.704s89.6-200.704 204.8-200.704 204.8 89.6 204.8 200.704-93.696 200.704-204.8 200.704z m247.296-354.304c-12.8 0-25.6-12.8-25.6-25.6s12.8-25.6 25.6-25.6 25.6 12.8 25.6 25.6c0 17.408-12.8 25.6-25.6 25.6zM256 264.704c0-8.704-8.704-16.896-16.896-16.896h-51.2c-8.704 0-16.896 8.704-16.896 16.896V281.6H256v-16.896z m256 148.992c-85.504 0-153.6 68.096-153.6 153.6s68.096 153.6 153.6 153.6 153.6-68.096 153.6-153.6-68.096-153.6-153.6-153.6z"' + ' fill="#ffffff" p-id="5959"></path>' + '</svg>' + '</span>';
  306. capturePictureDOM.onclick = function () {
  307. _this.capturePicture();
  308. };
  309. controsDOM.appendChild(capturePictureDOM);
  310. }
  311. console.log("matchHeaderOpt().saveModule", matchHeaderOpt().saveModule);
  312. if (matchHeaderOpt().saveModule) {
  313. var startSaveDOM = document.createElement('span');
  314. startSaveDOM.innerHTML = '<span title="开始录像">' + ' <svg id="startSave" t="1578882716693" class="icon" viewBox="0 0 1024 1024" version="1.1"' + ' xmlns="http://www.w3.org/2000/svg" p-id="3782" width="24" height="24">' + ' <path' + ' d="M915.2 729.6l-128-76.8c-25.6-12.8-44.8-32-44.8-51.2V435.2c0-25.6 19.2-38.4 44.8-51.2l128-76.8c25.6-12.8 44.8 0 44.8 19.2V704c0 32-19.2 38.4-44.8 25.6z m-332.8 89.6H96c-51.2 0-89.6-38.4-89.6-89.6V332.8c0-51.2 38.4-89.6 89.6-89.6h486.4c51.2 0 89.6 38.4 89.6 89.6v396.8c0 51.2-38.4 89.6-89.6 89.6zM192 364.8c-32 6.4-57.6 32-64 64-12.8 57.6 38.4 115.2 96 102.4 32-6.4 57.6-32 64-70.4 12.8-57.6-38.4-108.8-96-96z m0 0"' + ' p-id="3783" fill="#ffffff"></path>' + ' </svg>' + '</span>';
  315. startSaveDOM.onclick = function () {
  316. _this.startSave();
  317. document.getElementById('startSave').setAttribute('class', 'icon hide');
  318. document.getElementById('stopSave').setAttribute('class', 'icon');
  319. };
  320. controsDOM.appendChild(startSaveDOM);
  321. var stopSaveDOM = document.createElement('span');
  322. stopSaveDOM.innerHTML = '<span title="结束录像">' + ' <svg id="stopSave" t="1578882716693" class="icon hide" viewBox="0 0 1024 1024" version="1.1"' + ' xmlns="http://www.w3.org/2000/svg" p-id="3782" width="24" height="24">' + ' <path' + ' d="M915.2 729.6l-128-76.8c-25.6-12.8-44.8-32-44.8-51.2V435.2c0-25.6 19.2-38.4 44.8-51.2l128-76.8c25.6-12.8 44.8 0 44.8 19.2V704c0 32-19.2 38.4-44.8 25.6z m-332.8 89.6H96c-51.2 0-89.6-38.4-89.6-89.6V332.8c0-51.2 38.4-89.6 89.6-89.6h486.4c51.2 0 89.6 38.4 89.6 89.6v396.8c0 51.2-38.4 89.6-89.6 89.6zM192 364.8c-32 6.4-57.6 32-64 64-12.8 57.6 38.4 115.2 96 102.4 32-6.4 57.6-32 64-70.4 12.8-57.6-38.4-108.8-96-96z m0 0"' + ' p-id="3783" fill="red"></path>' + ' </svg>' + ' </span>';
  323. stopSaveDOM.onclick = function () {
  324. _this.stopSave();
  325. document.getElementById('stopSave').setAttribute('class', 'icon hide');
  326. document.getElementById('startSave').setAttribute('class', 'icon');
  327. };
  328. controsDOM.appendChild(stopSaveDOM);
  329. }
  330. if (matchHeaderOpt().zoomModule) {
  331. var enableZoomDOM = document.createElement('span');
  332. enableZoomDOM.innerHTML = '<span title="开启电子放大">' + ' <svg id="enableZoom" t="1578882639834" class="icon" viewBox="0 0 1000 1000" version="1.1"' + ' xmlns="http://www.w3.org/2000/svg" p-id="2227" width="24" height="24">' + ' <path' + ' d="M830.6119 441.1089c0-193.7756-157.0939-350.8641-350.8775-350.8641S128.8559 247.3333 128.8559 441.1089 285.9508 791.972 479.7344 791.972 830.6119 634.8845 830.6119 441.1089zM483.2821 710.4863c-146.7975 0-265.8187-118.9953-265.8187-265.8088S336.4847 178.8697 483.2821 178.8697s265.8197 118.9953 265.8197 265.8078S630.0796 710.4863 483.2821 710.4863zM770.6031 653.5739l-72.6417 75.9485 141.6917 160.1814 82.0737-90.0739L770.6031 653.5739zM527.5849 267.4727h-88.60655762279428v132.90489048425167H306.0690340253259v88.60292721534799h132.90933675248866v132.9038911617923h88.60655762279428V488.9794719180395h132.90933675248866v-88.60292721534799H527.5849284006089V267.4726535408993z"' + ' p-id="2228" fill="#ffffff"></path>' + ' </svg>' + '</span>';
  333. enableZoomDOM.onclick = function () {
  334. _this.enableZoom();
  335. document.getElementById('enableZoom').setAttribute('class', 'icon hide');
  336. document.getElementById('closeZoom').setAttribute('class', 'icon');
  337. };
  338. controsDOM.appendChild(enableZoomDOM);
  339. var closeZoomDOM = document.createElement('span');
  340. closeZoomDOM.innerHTML = '<span title="关闭电子放大">' + ' <svg id="closeZoom" t="1578882639834" class="icon hide" viewBox="0 0 1000 1000" version="1.1"' + ' xmlns="http://www.w3.org/2000/svg" p-id="2227" width="24" height="24">' + ' <path' + ' d="M830.6119 441.1089c0-193.7756-157.0939-350.8641-350.8775-350.8641S128.8559 247.3333 128.8559 441.1089 285.9508 791.972 479.7344 791.972 830.6119 634.8845 830.6119 441.1089zM483.2821 710.4863c-146.7975 0-265.8187-118.9953-265.8187-265.8088S336.4847 178.8697 483.2821 178.8697s265.8197 118.9953 265.8197 265.8078S630.0796 710.4863 483.2821 710.4863zM770.6031 653.5739l-72.6417 75.9485 141.6917 160.1814 82.0737-90.0739L770.6031 653.5739zM527.5849 267.4727h-88.60655762279428v132.90489048425167H306.0690340253259v88.60292721534799h132.90933675248866v132.9038911617923h88.60655762279428V488.9794719180395h132.90933675248866v-88.60292721534799H527.5849284006089V267.4726535408993z"' + ' p-id="2228" fill="red"></path>' + ' </svg>' + '</span>';
  341. closeZoomDOM.onclick = function () {
  342. _this.closeZoom();
  343. document.getElementById('closeZoom').setAttribute('class', 'icon hide');
  344. document.getElementById('enableZoom').setAttribute('class', 'icon');
  345. };
  346. controsDOM.appendChild(closeZoomDOM);
  347. }
  348. }
  349. /**
  350. * 渲染footer
  351. */
  352. /** 根据配置匹配底部渲染 */
  353. function matchFooterOpt() {
  354. var result = {
  355. footerContainer: false,
  356. talkModule: false,
  357. broadcastModule: false,
  358. hdModule: false,
  359. fullScreenModule: false
  360. };
  361. var template = _this.opt.template;
  362. switch (template) {
  363. case 'simple':
  364. if (params.footer && params.footer instanceof Array) {
  365. var footer = params.footer;
  366. result = {
  367. footerContainer: true,
  368. talkModule: footer.indexOf('talk') !== -1,
  369. broadcastModule: footer.indexOf('broadcast') !== -1,
  370. hdModule: footer.indexOf('hd') !== -1,
  371. fullScreenModule: footer.indexOf('fullScreen') !== -1
  372. };
  373. }
  374. break;
  375. case 'standard':
  376. if (params.footer && params.footer instanceof Array) {
  377. var footer = params.footer;
  378. result = {
  379. footerContainer: true,
  380. talkModule: footer.indexOf('talk') !== -1,
  381. broadcastModule: footer.indexOf('broadcast') !== -1,
  382. hdModule: footer.indexOf('hd') !== -1,
  383. fullScreenModule: footer.indexOf('fullScreen') !== -1
  384. };
  385. }
  386. break;
  387. case 'security':
  388. break;
  389. case 'voice':
  390. result = {
  391. footerContainer: true,
  392. talkModule: true,
  393. broadcastModule: true,
  394. hdModule: true,
  395. fullScreenModule: true
  396. };
  397. break;
  398. }
  399. return result;
  400. }
  401. /** 根据配置匹配底部渲染 */
  402. function matchHeaderOpt() {
  403. var result = {
  404. headerContainer: false,
  405. capturePictureModule: false,
  406. saveModule: false,
  407. zoomModule: false
  408. };
  409. var template = _this.opt.template;
  410. switch (template) {
  411. case 'simple':
  412. if (params.header && params.header instanceof Array) {
  413. var header = params.header;
  414. result = {
  415. headerContainer: true,
  416. capturePictureModule: header.indexOf('capturePicture') !== -1,
  417. saveModule: header.indexOf('save') !== -1,
  418. zoomModule: header.indexOf('zoom') !== -1
  419. };
  420. }
  421. break;
  422. case 'standard':
  423. break;
  424. case 'security':
  425. break;
  426. case 'voice':
  427. result = {
  428. headerContainer: true,
  429. capturePictureModule: true,
  430. saveModule: true,
  431. zoomModule: true
  432. };
  433. break;
  434. }
  435. return result;
  436. }
  437. if (matchFooterOpt().footerContainer || _this.opt.plugin.indexOf('talk') !== -1) {
  438. var recoderCSS = _this.opt.filePath + '/npm/css/recoder.css';
  439. var recoderJs = _this.opt.filePath + '/npm/js/recoder.js';
  440. var recorderJs = _this.opt.filePath + '/recorder.js'; // addCss()
  441. addCss(recoderCSS, function () { });
  442. addJs(recoderJs, function () {
  443. addJs(recorderJs, function () { });
  444. }); // 对讲模块
  445. if (_this.opt.plugin.indexOf('talk') !== -1 || matchFooterOpt().talkModule) {
  446. function apiSuccess(data) {
  447. console.log("data", data);
  448. if (data.code == 200) {
  449. var apiResult = data.data;
  450. if (apiResult) {
  451. // 临时将https转换为websocket
  452. var rtcTrunk = apiResult.rtcUrl;
  453. if (rtcTrunk.indexOf("ws") === -1) {
  454. rtcTrunk = rtcTrunk.replace("https", "wss").replace("rtcgw", "rtcgw-ws");
  455. }
  456. _this.opt.rtcUrl = rtcTrunk;
  457. _this.opt.ttsUrl = "tts://" + apiResult.ttsUrl;
  458. var talk = "talk://" + _this.opt.deviceSerial + ":0:" + _this.opt.channelNo + ":cas.ys7.com:6500";
  459. _this.opt.talkLink = _this.opt.ttsUrl + "/" + talk;
  460. _this.opt.stream = apiResult.stream;
  461. console.log("_this.opt", _this.opt); // 加载依赖
  462. if (!_this.opt.isReliesReady) {
  463. var adapeterJS = _this.opt.filePath + '/npm/js/adapeter.js';
  464. var janusJS = _this.opt.filePath + '/npm/js/janus.js';
  465. var ttsJS = _this.opt.filePath + '/npm/js/tts.js';
  466. console.log("加载jquery.js");
  467. addJs(adapeterJS, function () {
  468. console.log("加载adapeter.js");
  469. addJs(janusJS, function () {
  470. console.log("加载janus.js");
  471. addJs(ttsJS, function () {
  472. console.log("加载tts.js"); // 文件加载完毕;
  473. _this.opt.isReliesReady = true;
  474. });
  475. });
  476. });
  477. } // 创建DOM
  478. if (!document.getElementById("audioleft")) {
  479. var audioleft = document.createElement('div');
  480. audioleft.style.display = 'none';
  481. audioleft.id = 'audioleft';
  482. document.body.appendChild(audioleft);
  483. }
  484. if (!document.getElementById("audioright")) {
  485. var audioright = document.createElement('div');
  486. audioright.style.display = 'none';
  487. audioright.id = 'audioright';
  488. document.body.appendChild(audioright);
  489. }
  490. }
  491. }
  492. EZUIKit.opt = _this.opt;
  493. }
  494. function apiError(err) {
  495. if (params.handleError) {
  496. params.handleError(err);
  497. }
  498. }
  499. request(_this.opt.apiDomain, 'POST', {
  500. accessToken: _this.opt.accessToken,
  501. deviceSerial: _this.opt.deviceSerial,
  502. channelNo: _this.opt.channelNo
  503. }, '', apiSuccess, apiError);
  504. }
  505. if (matchFooterOpt().footerContainer) {
  506. // 底部容器
  507. var footerContainer = document.createElement('div');
  508. footerContainer.setAttribute("class", 'audio-controls');
  509. domElement.appendChild(footerContainer);
  510. if (matchFooterOpt().hdModule || matchFooterOpt().fullScreenModule) {
  511. // 底部右侧元素
  512. var rightContros = document.createElement('div');
  513. rightContros.setAttribute('class', 'contros');
  514. footerContainer.appendChild(rightContros);
  515. if (matchFooterOpt().hdModule) {
  516. // 高清-标清切换
  517. var hdDom = document.createElement('span');
  518. hdDom.setAttribute('id', 'video-hd');
  519. hdDom.innerHTML = _this.opt.url.indexOf('.hd') === -1 ? '标清' : '高清';
  520. hdDom.onclick = function () {
  521. // 停止
  522. if(_this.opt.videoLoading){
  523. layer.msg("视频加载中,请稍后");
  524. return false;
  525. }else {
  526. var stopPromise = _this.stop();
  527. _this.opt.videoLoading = true;
  528. stopPromise.then((data)=>{
  529. _this.opt.videoLoading = false;
  530. if (_this.opt.url.indexOf('.hd') === -1) {
  531. _this.opt.url = _this.opt.url.replace('.live', '.hd.live');
  532. hdDom.innerHTML = _this.opt.url.indexOf('.hd') === -1 ? '标清' : '高清';
  533. } else {
  534. _this.opt.url = _this.opt.url.replace('.hd.live', '.live');
  535. hdDom.innerHTML = _this.opt.url.indexOf('.hd') === -1 ? '标清' : '高清';
  536. }
  537. _this.play(_this.opt.url)
  538. })
  539. .catch((error)=>{
  540. console.log("error",error)
  541. })
  542. }
  543. //iframe.src = domain +"/ezopen/h5/iframe?url=" + _this.opt.url.replace('.hd.live', '.live') + "&autoplay=1&audio=" + _this.opt.audio + "&accessToken=" + _this.opt.accessToken + "&templete=" + 0;
  544. };
  545. rightContros.appendChild(hdDom);
  546. }
  547. if (matchFooterOpt().fullScreenModule) {
  548. // 声音控制
  549. var openSoundDOM = document.createElement('span');
  550. openSoundDOM.setAttribute('class', 'hide');
  551. openSoundDOM.setAttribute('id', 'ezuikit-open-sound');
  552. openSoundDOM.setAttribute('title', '打开声音');
  553. openSoundDOM.setAttribute('style', 'vertical-align: top;');
  554. openSoundDOM.innerHTML = '<svg t="1590476263239" class="icon" viewBox="0 0 1178 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2273" width="16" height="16"><path d="M665.6 51.2 665.6 51.2c-10.24-30.72-40.96-51.2-71.68-51.2-5.12 0-15.36 0-20.48 5.12l0 0L358.4 153.6 51.2 209.92l0 0C20.48 220.16 0 250.88 0 281.6 0 286.72 0 291.84 0 307.2l0 0 0 409.6 0 0c0 15.36 0 20.48 0 25.6 0 30.72 20.48 61.44 51.2 71.68l0 0L358.4 870.4l97.28 71.68 107.52 76.8 0 0c5.12 5.12 15.36 5.12 25.6 5.12 40.96 0 76.8-35.84 76.8-76.8 0-10.24 0-10.24 0-25.6l0 0L665.6 51.2zM563.2 870.4l-153.6-102.4-307.2-51.2L102.4 307.2l307.2-51.2 153.6-102.4L563.2 870.4z" p-id="2274" fill="#FF0000"></path><path d="M1049.6 537.6l112.64-112.64c20.48-20.48 20.48-56.32 0-76.8-20.48-20.48-56.32-20.48-76.8 0L972.8 460.8l-112.64-112.64c0 0 0 0 0 0-20.48-20.48-56.32-20.48-76.8 0 0 0 0 0 0 0-20.48 20.48-20.48 56.32 0 76.8l112.64 112.64-112.64 112.64c-20.48 20.48-20.48 56.32 0 76.8 20.48 20.48 56.32 20.48 76.8 0L972.8 614.4l112.64 112.64c20.48 20.48 56.32 20.48 76.8 0s20.48-56.32 0-76.8L1049.6 537.6z" p-id="2275" fill="#FF0000"></path></svg>';
  555. openSoundDOM.onclick = function () {
  556. _this.openSound(0);
  557. openSoundDOM.setAttribute('class', 'hide');
  558. closeSoundDOM.setAttribute('class', '');
  559. }; // 声音控制
  560. var closeSoundDOM = document.createElement('span');
  561. openSoundDOM.setAttribute('id', 'ezuikit-close-sound');
  562. closeSoundDOM.setAttribute('class', 'hide');
  563. closeSoundDOM.setAttribute('title', '关闭声音');
  564. closeSoundDOM.setAttribute('style', 'vertical-align: top;');
  565. closeSoundDOM.innerHTML = '<svg t="1590414410633" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="20545" width="16" height="16"><path d="M840.533333 98.133333c-17.066667-17.066667-42.666667-17.066667-59.733333 0-17.066667 17.066667-17.066667 42.666667 0 59.733334C883.2 256 938.666667 392.533333 938.666667 533.333333c0 140.8-55.466667 277.333333-157.866667 375.466667-17.066667 17.066667-17.066667 42.666667 0 59.733333 8.533333 8.533333 21.333333 12.8 29.866667 12.8 8.533333 0 21.333333-4.266667 29.866666-12.8 115.2-110.933333 183.466667-268.8 183.466667-435.2 0-166.4-68.266667-324.266667-183.466667-435.2zM571.733333 12.8c-17.066667-8.533333-34.133333-4.266667-46.933333 8.533333L281.6 256H42.666667c-25.6 0-42.666667 17.066667-42.666667 42.666667v426.666666c0 25.6 17.066667 42.666667 42.666667 42.666667h238.933333l243.2 234.666667c8.533333 8.533333 17.066667 12.8 29.866667 12.8 4.266667 0 12.8 0 17.066666-4.266667 17.066667-8.533333 25.6-21.333333 25.6-38.4V51.2c0-17.066667-8.533333-34.133333-25.6-38.4zM512 870.4l-183.466667-179.2c-8.533333-4.266667-17.066667-8.533333-29.866666-8.533333H85.333333V341.333333h213.333334c12.8 0 21.333333-4.266667 29.866666-12.8L512 153.6v716.8z" p-id="20546" fill="#ffffff"></path><path d="M759.466667 349.866667c-12.8-21.333333-38.4-25.6-59.733334-8.533334-21.333333 12.8-25.6 38.4-8.533333 59.733334 21.333333 29.866667 34.133333 76.8 34.133333 123.733333 0 46.933333-12.8 93.866667-34.133333 123.733333-12.8 21.333333-8.533333 46.933333 8.533333 59.733334 8.533333 4.266667 17.066667 8.533333 25.6 8.533333 12.8 0 25.6-4.266667 34.133334-17.066667 34.133333-46.933333 51.2-106.666667 51.2-174.933333 0-68.266667-17.066667-128-51.2-174.933333z" p-id="20547" fill="#ffffff"></path></svg>';
  566. closeSoundDOM.onclick = function () {
  567. _this.closeSound(0);
  568. openSoundDOM.setAttribute('class', '');
  569. closeSoundDOM.setAttribute('class', 'hide');
  570. };
  571. rightContros.appendChild(openSoundDOM);
  572. rightContros.appendChild(closeSoundDOM);
  573. } // 根据当前音频配置展示
  574. if (_this.opt.audio == 1) {
  575. closeSoundDOM.setAttribute('class', '');
  576. } else {
  577. openSoundDOM.setAttribute('class', '');
  578. _this.closeSound(0);
  579. }
  580. if (matchFooterOpt().fullScreenModule) {
  581. // 全屏控制
  582. var fullScreenDOM = document.createElement('span');
  583. fullScreenDOM.setAttribute('title', '全屏');
  584. fullScreenDOM.setAttribute('style', 'vertical-align: top;');
  585. fullScreenDOM.innerHTML = '<svg id="fullScreen" t="1578020167938" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5035" width="16" height="16"> <path d="M348.373333 625.706667l-128 128-64 64v-128a33.28 33.28 0 0 0-35.413333-35.413334A33.493333 33.493333 0 0 0 85.333333 689.706667v213.333333A33.706667 33.706667 0 0 0 120.96 938.666667h213.333333a35.626667 35.626667 0 0 0 0-71.04h-128l64-64 128-128a35.2 35.2 0 0 0-49.92-49.92zM206.293333 156.373333h128a33.28 33.28 0 0 0 35.413334-35.413333A33.493333 33.493333 0 0 0 334.293333 85.333333H113.706667c-7.04 0-14.08 7.04-21.333334 14.293334a26.026667 26.026667 0 0 0-7.04 21.333333v213.333333a33.493333 33.493333 0 0 0 35.626667 35.413334 33.28 33.28 0 0 0 35.413333-35.413334v-128l192 192a35.2 35.2 0 0 0 49.92-49.92zM903.04 85.333333h-213.333333a33.493333 33.493333 0 0 0-35.413334 35.626667 33.28 33.28 0 0 0 35.413334 35.413333h128l-64 64-128 128a35.2 35.2 0 0 0 49.92 49.92l128-128 64-64v128a35.626667 35.626667 0 0 0 71.04 0v-213.333333A33.706667 33.706667 0 0 0 903.04 85.333333zM903.04 654.293333a33.28 33.28 0 0 0-35.413333 35.413334v128l-64-64-128-128a35.2 35.2 0 0 0-49.92 49.92l128 128 64 64h-128a35.626667 35.626667 0 0 0 0 71.04h213.333333A33.706667 33.706667 0 0 0 938.666667 903.04v-213.333333a33.493333 33.493333 0 0 0-35.626667-35.413334z" p-id="5036" fill="#ffffff"></path></svg>';
  586. fullScreenDOM.onclick = function () {
  587. _this.fullScreen();
  588. };
  589. rightContros.appendChild(fullScreenDOM);
  590. }
  591. }
  592. if (matchFooterOpt().talkModule) {
  593. // 对讲
  594. var startTalkDOM = document.createElement('div');
  595. var stopTalkDOM = document.createElement('div');
  596. startTalkDOM.setAttribute("class", "ptp-talk off");
  597. startTalkDOM.innerHTML = '<span title="对讲">' + '<svg t="1581930496966" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1641" width="16" height="16">' + ' <path' + ' d="M715.648 647.872c-30.208-22.336-61.568 39.36-100.992 77.44-39.36 38.08-34.112 31.488-123.392-17.088S311.488 540.224 280 491.648C248.448 443.072 265.472 424.704 265.472 424.704s78.72-62.976 97.152-81.344c18.368-18.368 13.12-30.208 13.12-30.208l-128.64-190.144c-23.616-5.184-64.32 5.12-128.576 57.6C54.208 233.088 30.592 353.856 151.296 575.68c120.768 221.824 347.84 330.752 485.568 374.08 137.856 43.328 228.416-61.696 249.408-103.68 21.056-41.984 13.12-85.312 13.12-85.312S745.856 670.208 715.648 647.872z"' + ' p-id="1642" fill="#ffffff"></path>' + ' <path' + ' d="M715.328 64C580.992 64 472.192 172.864 472.192 307.2s108.8 243.2 243.136 243.2 243.2-108.864 243.2-243.2S849.6 64 715.328 64zM715.328 461.056c-84.992 0-153.856-68.864-153.856-153.856s68.864-153.856 153.856-153.856 153.856 68.928 153.856 153.856S800.32 461.056 715.328 461.056z"' + ' p-id="1643" fill="#ffffff"></path>' + ' <path' + ' d="M777.472 277.376c-18.176 0-32.96-14.784-32.96-33.024 0-8.448 3.136-16.064 8.32-21.888-11.52-5.12-24.128-8-37.568-8-51.2 0-92.672 41.472-92.672 92.736s41.472 92.736 92.672 92.736S808.064 358.4 808.064 307.2c0-13.696-3.072-26.688-8.384-38.4C793.728 274.112 786.048 277.376 777.472 277.376zM715.328 340.928c-18.624 0-33.664-15.104-33.664-33.728 0-18.624 15.04-33.728 33.664-33.728 18.688 0 33.728 15.104 33.728 33.728C749.056 325.824 734.016 340.928 715.328 340.928z"' + ' p-id="1644" fill="#ffffff"></path>' + ' </svg>' + ' </span>' + ' <span>开启对讲</span>';
  598. startTalkDOM.onclick = function () {
  599. console.log("EZUIKit.state.countTimer", EZUIKit.state.countTimer);
  600. if (EZUIKit.state.countTimer) {
  601. window.layer.msg("语音设备正忙,请稍后重试");
  602. return false;
  603. }
  604. countTime('add', 0);
  605. console.log("开始对讲,关闭声音");
  606. _this.closeSound(0);
  607. console.log(_this.opt);
  608. _this.startTalk();
  609. this.setAttribute("class", "ptp-talk off hide");
  610. stopTalkDOM.setAttribute("class", "ptp-talk on");
  611. };
  612. stopTalkDOM.setAttribute("class", "ptp-talk on hide");
  613. stopTalkDOM.innerHTML = '<span title="对讲">' + ' <svg t="1581930496966" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1641" width="16" height="16">' + ' <path' + ' d="M715.648 647.872c-30.208-22.336-61.568 39.36-100.992 77.44-39.36 38.08-34.112 31.488-123.392-17.088S311.488 540.224 280 491.648C248.448 443.072 265.472 424.704 265.472 424.704s78.72-62.976 97.152-81.344c18.368-18.368 13.12-30.208 13.12-30.208l-128.64-190.144c-23.616-5.184-64.32 5.12-128.576 57.6C54.208 233.088 30.592 353.856 151.296 575.68c120.768 221.824 347.84 330.752 485.568 374.08 137.856 43.328 228.416-61.696 249.408-103.68 21.056-41.984 13.12-85.312 13.12-85.312S745.856 670.208 715.648 647.872z"' + ' p-id="1642" fill="#ff0000"></path>' + ' <path' + ' d="M715.328 64C580.992 64 472.192 172.864 472.192 307.2s108.8 243.2 243.136 243.2 243.2-108.864 243.2-243.2S849.6 64 715.328 64zM715.328 461.056c-84.992 0-153.856-68.864-153.856-153.856s68.864-153.856 153.856-153.856 153.856 68.928 153.856 153.856S800.32 461.056 715.328 461.056z"' + ' p-id="1643" fill="#ff0000"></path>' + ' <path' + ' d="M777.472 277.376c-18.176 0-32.96-14.784-32.96-33.024 0-8.448 3.136-16.064 8.32-21.888-11.52-5.12-24.128-8-37.568-8-51.2 0-92.672 41.472-92.672 92.736s41.472 92.736 92.672 92.736S808.064 358.4 808.064 307.2c0-13.696-3.072-26.688-8.384-38.4C793.728 274.112 786.048 277.376 777.472 277.376zM715.328 340.928c-18.624 0-33.664-15.104-33.664-33.728 0-18.624 15.04-33.728 33.664-33.728 18.688 0 33.728 15.104 33.728 33.728C749.056 325.824 734.016 340.928 715.328 340.928z"' + ' p-id="1644" fill="#ff0000"></path>' + ' </svg>' + ' </span>' + '<span>关闭对讲</span>';
  614. stopTalkDOM.onclick = function () {
  615. console.log(_this.opt);
  616. _this.stopTalk();
  617. countTime('destory', 0);
  618. _this.openSound(0);
  619. this.setAttribute("class", "ptp-talk on hide");
  620. startTalkDOM.setAttribute("class", "ptp-talk off");
  621. };
  622. footerContainer.appendChild(startTalkDOM);
  623. footerContainer.appendChild(stopTalkDOM);
  624. }
  625. if (matchFooterOpt().broadcastModule) {
  626. var startBroadcastDOM = document.createElement('div');
  627. var stopBroadcastDOM = document.createElement('div');
  628. startBroadcastDOM.setAttribute("class", 'broadcast off');
  629. stopBroadcastDOM.setAttribute("class", "broadcast on hide");
  630. startBroadcastDOM.innerHTML = ' <span title="语音播报">' + ' <svg t="1583561695846" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1126" width="16" height="16">' + ' <path' + ' d="M513.82044445 964.38044445c-8.192 0-15.47377778-2.73066667-21.84533334-8.192 0 0-46.42133333-41.87022222-99.21422222-86.47111112-89.20177778-73.728-117.41866667-88.29155555-123.79022222-90.112H35.04355555c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666666V271.70133333c0-14.56355555 11.83288889-27.30666667 26.39644444-27.30666666H246.21511111c7.28177778-2.73066667 37.31911111-15.47377778 137.44355556-91.02222222 58.25422222-43.69066667 111.04711111-86.47111111 111.04711111-86.47111112 5.46133333-4.55111111 12.74311111-7.28177778 20.02488889-7.28177778 4.55111111 0 10.01244445 0.91022222 14.56355555 3.6408889 10.92266667 5.46133333 18.20444445 17.29422222 18.20444445 30.03733333v837.40444444c0 12.74311111-7.28177778 25.48622222-19.11466667 30.94755556-5.46133333 1.82044445-10.01244445 2.73066667-14.56355555 2.73066667zM270.79111111 724.992c19.11466667 0 48.24177778 8.192 167.48088889 106.496 16.384 13.65333333 33.67822222 28.21688889 51.88266667 43.69066667l5.46133333 4.55111111V139.71911111l-5.46133333 3.64088889c-22.75555555 17.29422222-44.60088889 34.58844445-65.536 50.06222222C293.54666667 291.72622222 264.41955555 299.008 245.30488889 299.008H82.37511111c-20.02488889 0-21.84533333 12.74311111-21.84533333 26.39644445V694.04444445c0 23.66577778 6.37155555 30.03733333 28.21688889 30.03733333h180.224l1.82044444 0.91022222z m520.64711111 162.01955555c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666666 0-11.83288889 8.192-20.02488889 16.384-24.576 112.86755555-67.35644445 182.04444445-191.14666667 182.04444444-324.03911111 0-132.89244445-70.08711111-256.68266667-182.04444444-324.03911111-10.01244445-5.46133333-15.47377778-14.56355555-15.47377778-24.576 0-14.56355555 11.83288889-27.30666667 26.39644445-27.30666667 5.46133333 0 10.01244445 1.82044445 16.384 5.46133333 128.34133333 76.45866667 207.53066667 218.45333333 207.53066666 369.55022222 0 152.00711111-80.09955555 293.09155555-208.44088889 369.55022223-6.37155555 5.46133333-10.92266667 7.28177778-16.384 7.28177777z m-90.112-152.91733333c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666667 0-10.01244445 4.55111111-18.20444445 12.74311111-23.66577777 61.89511111-34.58844445 100.12444445-100.12444445 100.12444444-171.12177778 0-70.08711111-37.31911111-134.71288889-96.48355555-170.21155555-8.192-4.55111111-12.74311111-13.65333333-12.74311111-23.66577778 0-14.56355555 11.83288889-27.30666667 26.39644444-27.30666667 4.55111111 0 11.83288889 2.73066667 15.47377778 4.55111111 74.63822222 44.60088889 121.96977778 127.43111111 121.96977778 215.72266667 0 90.112-48.24177778 173.85244445-125.61066667 218.45333333-1.82044445 0-9.10222222 4.55111111-15.47377778 4.55111111z"' + ' fill="#ffffff" p-id="1127"></path>' + ' </svg>' + '</span>' + '<span>语音播报</span>';
  631. startBroadcastDOM.onclick = function () {
  632. this.setAttribute("class", "broadcast off hide");
  633. stopBroadcastDOM.setAttribute("class", "broadcast on");
  634. };
  635. stopBroadcastDOM.innerHTML = '<div class="pop-hover">' + ' <div class="pop-hover-content">' + ' <div class="vioce-list" id="voice-list">' + ' <ul class="voice-list-ul">' + ' </ul>' + ' <div id="voice-list-end"></div>' + ' </div>' + ' <div id="voice-custom" style="text-align: center;">自定义语音</div>' + ' </div>' + '</div>' + '<span title="语音播报">' + ' <svg t="1583561695846" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1126" width="16" height="16">' + ' <path' + ' d="M513.82044445 964.38044445c-8.192 0-15.47377778-2.73066667-21.84533334-8.192 0 0-46.42133333-41.87022222-99.21422222-86.47111112-89.20177778-73.728-117.41866667-88.29155555-123.79022222-90.112H35.04355555c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666666V271.70133333c0-14.56355555 11.83288889-27.30666667 26.39644444-27.30666666H246.21511111c7.28177778-2.73066667 37.31911111-15.47377778 137.44355556-91.02222222 58.25422222-43.69066667 111.04711111-86.47111111 111.04711111-86.47111112 5.46133333-4.55111111 12.74311111-7.28177778 20.02488889-7.28177778 4.55111111 0 10.01244445 0.91022222 14.56355555 3.6408889 10.92266667 5.46133333 18.20444445 17.29422222 18.20444445 30.03733333v837.40444444c0 12.74311111-7.28177778 25.48622222-19.11466667 30.94755556-5.46133333 1.82044445-10.01244445 2.73066667-14.56355555 2.73066667zM270.79111111 724.992c19.11466667 0 48.24177778 8.192 167.48088889 106.496 16.384 13.65333333 33.67822222 28.21688889 51.88266667 43.69066667l5.46133333 4.55111111V139.71911111l-5.46133333 3.64088889c-22.75555555 17.29422222-44.60088889 34.58844445-65.536 50.06222222C293.54666667 291.72622222 264.41955555 299.008 245.30488889 299.008H82.37511111c-20.02488889 0-21.84533333 12.74311111-21.84533333 26.39644445V694.04444445c0 23.66577778 6.37155555 30.03733333 28.21688889 30.03733333h180.224l1.82044444 0.91022222z m520.64711111 162.01955555c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666666 0-11.83288889 8.192-20.02488889 16.384-24.576 112.86755555-67.35644445 182.04444445-191.14666667 182.04444444-324.03911111 0-132.89244445-70.08711111-256.68266667-182.04444444-324.03911111-10.01244445-5.46133333-15.47377778-14.56355555-15.47377778-24.576 0-14.56355555 11.83288889-27.30666667 26.39644445-27.30666667 5.46133333 0 10.01244445 1.82044445 16.384 5.46133333 128.34133333 76.45866667 207.53066667 218.45333333 207.53066666 369.55022222 0 152.00711111-80.09955555 293.09155555-208.44088889 369.55022223-6.37155555 5.46133333-10.92266667 7.28177778-16.384 7.28177777z m-90.112-152.91733333c-14.56355555 0-26.39644445-11.83288889-26.39644444-27.30666667 0-10.01244445 4.55111111-18.20444445 12.74311111-23.66577777 61.89511111-34.58844445 100.12444445-100.12444445 100.12444444-171.12177778 0-70.08711111-37.31911111-134.71288889-96.48355555-170.21155555-8.192-4.55111111-12.74311111-13.65333333-12.74311111-23.66577778 0-14.56355555 11.83288889-27.30666667 26.39644444-27.30666667 4.55111111 0 11.83288889 2.73066667 15.47377778 4.55111111 74.63822222 44.60088889 121.96977778 127.43111111 121.96977778 215.72266667 0 90.112-48.24177778 173.85244445-125.61066667 218.45333333-1.82044445 0-9.10222222 4.55111111-15.47377778 4.55111111z"' + ' fill="#ff0000" p-id="1127"></path>' + ' </svg>' + '</span>' + '<span>语音播报</span>'; // //自定义语音唤起
  636. // document.getElementById("voice-custom").onclick = function(){
  637. // console.log("显示自定义语音");
  638. // }
  639. stopBroadcastDOM.onclick = function () {
  640. this.setAttribute("class", "broadcast on hide");
  641. startBroadcastDOM.setAttribute("class", "broadcast off");
  642. };
  643. footerContainer.appendChild(startBroadcastDOM);
  644. footerContainer.appendChild(stopBroadcastDOM); // 召唤自定义语言
  645. document.getElementById("voice-custom").onclick = function () {
  646. console.log("显示自定义语音");
  647. startSpeakDOM.setAttribute('class', 'speak off');
  648. }; // 获取语音列表
  649. fetchVoiceList(0);
  650. function fetchVoiceList(page) {
  651. function apiSuccess(data) {
  652. console.log("data", data);
  653. if (data.code == 200) {
  654. randerVoliceList(data.data, 5);
  655. EZUIKit.state.page = data.page.page; // 如果用户语音列表为空
  656. if (page == 0 && data.data.length == 0 && !EZUIKit.state.fetchDefaultList) {
  657. // 获取用户语音为空
  658. EZUIKit.state.fetchDefaultList = true;
  659. fetchVoiceList(0);
  660. }
  661. }
  662. }
  663. function apiError(err) {
  664. console.log("err", err);
  665. }
  666. request( domain + '/api/lapp/voice/query', 'POST', {
  667. accessToken: _this.opt.accessToken,
  668. pageStart: page,
  669. pageSize: EZUIKit.state.pageSize,
  670. default: EZUIKit.state.fetchDefaultList ? 'true' : 'false'
  671. }, '', apiSuccess, apiError);
  672. }
  673. function randerVoliceList(data) {
  674. console.log("renderVoliceList", data);
  675. if (data && data.length > 0) {
  676. for (var i = 0; i < data.length; i++) {
  677. var voiceItem = document.createElement('li');
  678. voiceItem.innerHTML = "<li class='voice-item' id='voice-item-" + i + "' data-time=" + (data[i]["duration"] || 20) + " data-url=" + data[i]["fileUrl"] + ">" + (data[i]["voiceName"].length > 10 ? data[i]["voiceName"].substr(0, 10) + "..." : data[i]["voiceName"]) + "</li>";
  679. document.getElementsByClassName('voice-list-ul')[0].append(voiceItem); // "<li class='voice-item' id='voice-item-" + i + "' data-time=" + (data[i]["duration"] || 20) + " data-url=" + data[i]["fileUrl"] + ">" + (data[i]["voiceName"].length > 10 ? (data[i]["voiceName"].substr(0, 10) + "...") : data[i]["voiceName"]) + "</li>";
  680. // $("#voice-list ul").append("<li class='voice-item' id='voice-item-" + i + "' data-time=" + (data[i]["duration"] || 20) + " data-url=" + data[i]["fileUrl"] + ">" + (data[i]["voiceName"].length > 10 ? (data[i]["voiceName"].substr(0, 10) + "...") : data[i]["voiceName"]) + "</li>");
  681. voiceItem.onclick = function (e) {
  682. console.log("点击元素", e.target, e.target.dataset.url);
  683. var voiceUrl = e.target.dataset.url;
  684. var time = e.target.dataset.time;
  685. playListOfVoice(voiceUrl, time);
  686. };
  687. }
  688. if (data.length === EZUIKit.state.pageSize) {
  689. document.getElementById('voice-list-end').innerHTML = "向下滚动加载更多";
  690. } else {
  691. document.getElementById('voice-list-end').innerHTML = "没有更多数据了";
  692. }
  693. }
  694. }
  695. function playListOfVoice(voiceUrl, time) {
  696. console.log("播放语音", voiceUrl, time); // decoder && decoder.closeSound(0);
  697. function apiSuccess(data) {
  698. console.log("data.data", data.data);
  699. if (data.code == 200) {
  700. // $("#startBroadcast").show();
  701. // $("#stopBroadcast").hide();
  702. countTime('sub', parseInt(time));
  703. } else if (data.code == "10001") {
  704. window.layer.msg("未找到当前语音");
  705. } else {
  706. window.layer.msg(data.msg || '发送失败,请稍后再试');
  707. } // padding = false;
  708. }
  709. function apiError(err) {
  710. console.log("err", err);
  711. }
  712. request( domain + '/api/lapp/voice/send', 'POST', {
  713. accessToken: _this.opt.accessToken,
  714. deviceSerial: _this.opt.deviceSerial,
  715. channelNo: _this.opt.channelNo,
  716. fileUrl: voiceUrl
  717. }, '', apiSuccess, apiError);
  718. } // 自定义语音
  719. // 对讲
  720. var startSpeakDOM = document.createElement('div');
  721. var stopSpeakDOM = document.createElement('div');
  722. startSpeakDOM.setAttribute('class', 'speak off hide');
  723. stopSpeakDOM.setAttribute('class', 'speak on hide');
  724. startSpeakDOM.setAttribute('id', 'startSpeak');
  725. stopSpeakDOM.setAttribute('id', 'stopSpeak');
  726. startSpeakDOM.innerHTML = '<span title="按住说话">' + ' <svg t="1581994757678" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1639" width="16" height="16">' + ' <path' + ' d="M757.059829 393.846154v-52.512821h262.564103v52.512821H757.059829z m-420.102564 481.367521v96.273504h175.042735a8.752137 8.752137 0 0 1 8.752137 8.752137v35.008547a8.752137 8.752137 0 0 1-8.752137 8.752137H109.401709a8.752137 8.752137 0 0 1-8.752136-8.752137v-35.008547a8.752137 8.752137 0 0 1 8.752136-8.752137h175.042735v-96.273504C129.767932 875.213675 4.376068 749.821812 4.376068 595.145299V463.863248a26.25641 26.25641 0 1 1 52.512821 0v113.777778c0 140.174222 113.637744 253.811966 253.811966 253.811965s253.811966-113.637744 253.811966-253.811965V463.863248a26.25641 26.25641 0 1 1 52.51282 0v131.282051c0 154.676513-125.391863 280.068376-280.068376 280.068376z m-26.25641-96.273504c-111.178393 0-201.299145-90.120752-201.299146-201.299145V201.299145C109.401709 90.120752 199.522462 0 310.700855 0s201.299145 90.120752 201.299145 201.299145v376.341881c0 111.178393-90.120752 201.299145-201.299145 201.299145z m691.418803-280.068376H757.059829v-52.512821h245.059829v52.512821z m-17.504273 105.025641H757.059829v-52.512821h227.555556v52.512821z m-17.504274 105.025641H757.059829v-52.512821h210.051282v52.512821z m-8.752137 105.025641H757.059829v-52.512821h201.299145v52.512821z m-17.504273 105.025641H757.059829v-52.512821h183.794872v52.512821z m-26.25641 105.025641H757.059829v-52.512821h157.538462v52.512821z"' + ' p-id="1640" fill="#ffffff"></path>' + ' </svg>' + '</span>' + '<span>按住说话</span>';
  727. stopSpeakDOM.innerHTML = '<span title="按住说话">' + '<svg t="1581994757678" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"' + ' p-id="1639" width="16" height="16">' + ' <path' + ' d="M757.059829 393.846154v-52.512821h262.564103v52.512821H757.059829z m-420.102564 481.367521v96.273504h175.042735a8.752137 8.752137 0 0 1 8.752137 8.752137v35.008547a8.752137 8.752137 0 0 1-8.752137 8.752137H109.401709a8.752137 8.752137 0 0 1-8.752136-8.752137v-35.008547a8.752137 8.752137 0 0 1 8.752136-8.752137h175.042735v-96.273504C129.767932 875.213675 4.376068 749.821812 4.376068 595.145299V463.863248a26.25641 26.25641 0 1 1 52.512821 0v113.777778c0 140.174222 113.637744 253.811966 253.811966 253.811965s253.811966-113.637744 253.811966-253.811965V463.863248a26.25641 26.25641 0 1 1 52.51282 0v131.282051c0 154.676513-125.391863 280.068376-280.068376 280.068376z m-26.25641-96.273504c-111.178393 0-201.299145-90.120752-201.299146-201.299145V201.299145C109.401709 90.120752 199.522462 0 310.700855 0s201.299145 90.120752 201.299145 201.299145v376.341881c0 111.178393-90.120752 201.299145-201.299145 201.299145z m691.418803-280.068376H757.059829v-52.512821h245.059829v52.512821z m-17.504273 105.025641H757.059829v-52.512821h227.555556v52.512821z m-17.504274 105.025641H757.059829v-52.512821h210.051282v52.512821z m-8.752137 105.025641H757.059829v-52.512821h201.299145v52.512821z m-17.504273 105.025641H757.059829v-52.512821h183.794872v52.512821z m-26.25641 105.025641H757.059829v-52.512821h157.538462v52.512821z"' + ' p-id="1640" fill="#ff0000"></path>' + '</svg>' + '</span>' + '<span>松开发送</span>';
  728. footerContainer.appendChild(startSpeakDOM);
  729. footerContainer.appendChild(stopSpeakDOM);
  730. document.getElementById("voice-list").onscroll = function (e) {
  731. var sum = this.scrollHeight;
  732. console.log("sum", sum, this.scrollTop, document.getElementById("voice-list").clientHeight);
  733. if (sum <= this.scrollTop + this.clientHeight) {
  734. console.log("拖动到底,执行加载", EZUIKit.state.page);
  735. fetchVoiceList(++EZUIKit.state.page);
  736. }
  737. }; // $("#voice-list").unbind("scroll").bind("scroll", function (e) {
  738. // // console.log("e",e,this.scrollHeight, $(this).scrollTop() + $(this).height())
  739. // var sum = this.scrollHeight;
  740. // if (sum <= $(this).scrollTop() + $(this).height()) {
  741. // console.log("拖动到底,执行加载", page);
  742. // fetchVoiceList(++page);
  743. // }
  744. // loading = false;
  745. // });
  746. // time-area
  747. var timeAreaDOM = document.createElement('div');
  748. timeAreaDOM.setAttribute('class', 'time-area');
  749. timeAreaDOM.setAttribute('id', 'time-area');
  750. timeAreaDOM.innerHTML = '00:00';
  751. footerContainer.appendChild(timeAreaDOM); // 按住说话
  752. var recorder;
  753. document.getElementById('startSpeak').onmousedown = function () {
  754. if (EZUIKit.state.countTimer) {
  755. window.layer.msg("语音设备正忙,请稍后重试");
  756. return false;
  757. }
  758. console.log("按住说话");
  759. startSpeakDOM.setAttribute('class', 'speak off hide');
  760. stopSpeakDOM.setAttribute('class', 'speak on'); // console.log("startRecording",startRecording);
  761. // startRecording();
  762. voiceInit();
  763. countTime('add', 0);
  764. setTimeout(function () {
  765. EZUIKit.state.recodeTime = 0;
  766. startRecording();
  767. }, 1000);
  768. if (EZUIKit.state.recodeTimer) {
  769. // 先清空计数器
  770. clearInterval(EZUIKit.state.recodeTimer);
  771. }
  772. EZUIKit.state.recodeTimer = setInterval(function () {
  773. if (EZUIKit.state.recodeTime >= 59) {
  774. _this.stopTalk();
  775. countTime('destory', 0);
  776. this.setAttribute("class", "ptp-talk on hide");
  777. startTalkDOM.setAttribute("class", "ptp-talk off");
  778. window.layer.msg("不超过1分钟");
  779. } else {
  780. EZUIKit.state.recodeTime = EZUIKit.state.recodeTime + 1;
  781. }
  782. }, 1000);
  783. /** 录音控制 */
  784. var audio_context;
  785. function startUserMedia(stream) {
  786. var input = audio_context.createMediaStreamSource(stream);
  787. recorder = new window.Recorder(input);
  788. }
  789. function startRecording() {
  790. recorder && recorder.record();
  791. }
  792. function stopRecording() {
  793. recorder && recorder.stop();
  794. recorder.clear();
  795. }
  796. function voiceInit() {
  797. console.log("run init");
  798. try {
  799. // webkit shim
  800. window.AudioContext = window.AudioContext || window.webkitAudioContext;
  801. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
  802. window.URL = window.URL || window.webkitURL;
  803. audio_context = new AudioContext();
  804. console.log('Audio context set up.');
  805. console.log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!'));
  806. } catch (e) {
  807. console.log("err", e);
  808. window.layer.msg('No web audio support in this browser!');
  809. }
  810. navigator.getUserMedia({
  811. audio: true
  812. }, startUserMedia, function (e) {
  813. console.log('No live audio input: ' + e);
  814. });
  815. }
  816. ;
  817. }; // 松开发送
  818. document.getElementById('stopSpeak').onmouseup = function () {
  819. console.log("松开发送");
  820. stopSpeakDOM.setAttribute('class', 'speak on hide');
  821. stopSpeakFun();
  822. function stopSpeakFun() {
  823. countTime('destory', 0);
  824. if (EZUIKit.state.recodeTime < 1) {
  825. window.layer.msg("说话时间过短");
  826. clearInterval(EZUIKit.state.recodeTimer);
  827. return false;
  828. }
  829. clearInterval(EZUIKit.state.recodeTimer);
  830. wavUpload();
  831. }
  832. function wavUpload() {
  833. try {
  834. recorder && recorder.stop(); // createAudioDom();
  835. recorder && recorder.exportWAV(function (wav_file) {
  836. console.log("wav_file", wav_file);
  837. if (wav_file.size < 1000) {
  838. window.layer.msg("录音失败,请重试"); // recodeTime = 0;
  839. EZUIKit.state.recodeTime = 0;
  840. return false;
  841. } // 测试
  842. countTime('sub', EZUIKit.state.recodeTime + 2); // 延时
  843. var formdata = new FormData(); // form 表单 {key:value}
  844. formdata.append("voiceFile", wav_file); // form input type="file"
  845. formdata.append("accessToken", _this.opt.accessToken);
  846. formdata.append("deviceSerial", _this.opt.deviceSerial);
  847. formdata.append("channelNo", _this.opt.channelNo); // padding = true;
  848. function apiSuccess(data) {
  849. console.log("data.data", data.data);
  850. if (data.code == 200) {
  851. // $("#startBroadcast").show();
  852. // $("#stopBroadcast").hide();
  853. countTime('sub', EZUIKit.state.recodeTime + 2);
  854. } else if (data.code == "10001") {
  855. window.layer.msg("未找到当前语音");
  856. } else {
  857. window.layer.msg(data.msg || '发送失败,请稍后再试');
  858. } // padding = false;
  859. }
  860. function apiError(err) {
  861. console.log("err", err);
  862. }
  863. request(domain + '/api/lapp/voice/sendonce', 'POST', {
  864. voiceFile: wav_file,
  865. accessToken: _this.opt.accessToken,
  866. deviceSerial: _this.opt.deviceSerial,
  867. channelNo: _this.opt.channelNo
  868. }, '', apiSuccess, apiError);
  869. });
  870. recorder && recorder.clear();
  871. } catch (err) {
  872. console.log(err);
  873. }
  874. }
  875. };
  876. }
  877. /* 时间计数 */
  878. function countTime(type, start) {
  879. clearInterval(EZUIKit.state.countTimer);
  880. if (type === 'add') {
  881. var i = start;
  882. EZUIKit.state.countTimer = setInterval(function () {
  883. ++i;
  884. document.getElementById("time-area").innerHTML = formatSeconds(i);
  885. }, 1000);
  886. } else if (type === 'sub') {
  887. var i = start;
  888. EZUIKit.state.countTimer = setInterval(function () {
  889. if (i > 0) {
  890. i--;
  891. document.getElementById("time-area").innerHTML = formatSeconds(i);
  892. } else {
  893. clearInterval(EZUIKit.state.countTimer);
  894. EZUIKit.state.countTimer = undefined;
  895. console.log("倒计时结束,开启声音"); // decoder.openSound(0);
  896. }
  897. }, 1000);
  898. } else if (type === 'destory') {
  899. clearInterval(EZUIKit.state.countTimer);
  900. EZUIKit.state.countTimer = undefined;
  901. document.getElementById("time-area").innerHTML = '00:00';
  902. } //将秒数转换为时分秒格式
  903. function formatSeconds(value) {
  904. var theTime = parseInt(value); // 秒
  905. var middle = 0; // 分
  906. var hour = 0; // 小时
  907. var secondV = '00';
  908. var minV = '00';
  909. var hourV = '00';
  910. if (theTime > 59) {
  911. middle = parseInt(theTime / 60);
  912. theTime = parseInt(theTime % 60);
  913. if (middle > 59) {
  914. hour = parseInt(middle / 60);
  915. middle = parseInt(middle % 60);
  916. }
  917. }
  918. secondV = parseInt(theTime) > 9 ? parseInt(theTime) : '0' + parseInt(theTime);
  919. minV = parseInt(middle) > 9 ? parseInt(middle) : '0' + parseInt(middle);
  920. hourV = parseInt(hour) > 9 ? parseInt(hour) : '0' + parseInt(hour);
  921. if (hour > 0) {
  922. return hourV + ':' + minV + ':' + secondV;
  923. } else if (middle > 0) {
  924. return minV + ':' + secondV;
  925. } else {
  926. return '00:' + secondV;
  927. }
  928. }
  929. }
  930. /* 将秒数转换为时分秒格式 */
  931. function formatSeconds(value) {
  932. var theTime = parseInt(value); // 秒
  933. var middle = 0; // 分
  934. var hour = 0; // 小时
  935. var secondV = '00';
  936. var minV = '00';
  937. var hourV = '00';
  938. if (theTime > 59) {
  939. middle = parseInt(theTime / 60);
  940. theTime = parseInt(theTime % 60);
  941. if (middle > 59) {
  942. hour = parseInt(middle / 60);
  943. middle = parseInt(middle % 60);
  944. }
  945. }
  946. secondV = parseInt(theTime) > 9 ? parseInt(theTime) : '0' + parseInt(theTime);
  947. minV = parseInt(middle) > 9 ? parseInt(middle) : '0' + parseInt(middle);
  948. hourV = parseInt(hour) > 9 ? parseInt(hour) : '0' + parseInt(hour);
  949. if (hour > 0) {
  950. return hourV + ':' + minV + ':' + secondV;
  951. } else if (middle > 0) {
  952. return minV + ':' + secondV;
  953. } else {
  954. return '00:' + secondV;
  955. }
  956. }
  957. }
  958. }
  959. })
  960. })
  961. // iframe 传递数据
  962. var _this = this;
  963. window.addEventListener("message", function (event) {
  964. var origin = event.origin;
  965. var id = _this.opt.id;
  966. if (event.data.type) {
  967. switch (event.data.type) {
  968. case 'openSound':
  969. if (id == event.data.id && params.openSoundCallBack) {
  970. params.openSoundCallBack(event.data);
  971. }
  972. break;
  973. case 'closeSound':
  974. if (id == event.data.id && params.closeSoundCallBack) {
  975. params.closeSoundCallBack(event.data);
  976. }
  977. break;
  978. case 'capturePicture':
  979. if (id == event.data.id && params.capturePictureCallBack) {
  980. params.capturePictureCallBack(event.data);
  981. }
  982. break;
  983. case 'startSave':
  984. if (id == event.data.id && params.startSaveCallBack) {
  985. params.startSaveCallBack(event.data);
  986. }
  987. break;
  988. case 'stopSave':
  989. if (id == event.data.id && params.stopSaveCallBack) {
  990. params.stopSaveCallBack(event.data);
  991. }
  992. break;
  993. case 'fullScreen':
  994. if (id == event.data.id && params.fullScreenCallBack) {
  995. params.fullScreenCallBack(event.data);
  996. }
  997. break;
  998. case 'getOSDTime':
  999. if (id == event.data.id && params.getOSDTimeCallBack) {
  1000. params.getOSDTimeCallBack(event.data);
  1001. }
  1002. break;
  1003. case 'handleSuccess':
  1004. if (id == event.data.id && params.handleSuccess) {
  1005. params.handleSuccess(event.data);
  1006. }
  1007. break;
  1008. case 'handleError':
  1009. if (id == event.data.id && params.handleError) {
  1010. params.handleError(event.data);
  1011. }
  1012. break;
  1013. case 'dblclick':
  1014. if (id == event.data.id && _this.opt.bSupporDoubleClickFull) {
  1015. if(_this.opt.fullScreenStatus === 0){
  1016. _this.fullScreen();
  1017. } else {
  1018. _this.cancelFullScreen();
  1019. }
  1020. }
  1021. break;
  1022. case 'startTalk':
  1023. _this.startTalk();
  1024. // params.startTalk();
  1025. _this.closeSound();
  1026. break;
  1027. case 'stopTalk':
  1028. // window.stopTalk()
  1029. // params.stopTalk();
  1030. _this.openSound();
  1031. break;
  1032. case 'clickEventHandle':
  1033. console.log("event.data",event.data);
  1034. if(params.clickEventHandle) {
  1035. params.clickEventHandle(event.data);
  1036. }
  1037. break;
  1038. case 'removeEventHandle':
  1039. if(params.removeEventHandle) {
  1040. params.removeEventHandle(event.data);
  1041. }
  1042. break;
  1043. case 'esc':
  1044. if(params.clickEventHandle) {
  1045. params.clickEventHandle(event.data);
  1046. }
  1047. break;
  1048. }
  1049. }
  1050. });
  1051. // 全屏变化回调
  1052. function fullscreenchange(data) {
  1053. _this.opt.fullScreenStatus = data ? 1 : 0;
  1054. if (params.fullScreenChangeCallBack) {
  1055. params.fullScreenChangeCallBack({data:data,id: _this.opt.id});
  1056. }
  1057. }
  1058. if (typeof document.fullScreen !== "undefined") {
  1059. document.addEventListener("fullscreenchange", function() {
  1060. var e = document.fullscreen || false;
  1061. fullscreenchange(e)
  1062. })
  1063. } else if (typeof document.webkitIsFullScreen !== "undefined") {
  1064. document.addEventListener("webkitfullscreenchange", function() {
  1065. var e = document.webkitIsFullScreen || false;
  1066. fullscreenchange(e)
  1067. })
  1068. } else if (typeof document.mozFullScreen !== "undefined") {
  1069. document.addEventListener("mozfullscreenchange", function() {
  1070. var e = document.mozFullScreen || false;
  1071. fullscreenchange(e)
  1072. })
  1073. }
  1074. }; // 播放相关API
  1075. EZUIKitPlayer.prototype.play = function (data) {
  1076. var id = 'EZUIKitPlayer-' + this.opt.id;
  1077. var player = document.getElementById(id).contentWindow;
  1078. if (typeof data === 'object' && data.url) {
  1079. this.opt.url = data.url;
  1080. }
  1081. if (typeof data === 'object' && data.accessToken) {
  1082. this.opt.accessToken = data.accessToken;
  1083. }
  1084. if (typeof data === 'string') {
  1085. this.opt.url = data;
  1086. }
  1087. player.postMessage({
  1088. action: "play",
  1089. accessToken: this.opt.accessToken,
  1090. url: this.opt.url
  1091. }, domain + "/ezopen/h5/iframe");
  1092. var _this = this;
  1093. this.opt.videoLoading = true;
  1094. var promise = new Promise(function(resolve,reject) {
  1095. window.addEventListener("message", function (event) {
  1096. var playId = _this.opt.id;
  1097. if (playId == event.data.id && event.data.type === 'handleSuccess') {
  1098. setTimeout(()=>{
  1099. _this.opt.videoLoading = false;
  1100. },1000)
  1101. resolve(event.data);
  1102. }
  1103. });
  1104. });
  1105. return promise;
  1106. };
  1107. EZUIKitPlayer.prototype.stop = function () {
  1108. var id = 'EZUIKitPlayer-' + this.opt.id;
  1109. var player = document.getElementById(id).contentWindow;
  1110. player.postMessage("stop", domain + "/ezopen/h5/iframe");
  1111. var _this = this;
  1112. var promise = new Promise(function(resolve,reject) {
  1113. window.addEventListener("message", function (event) {
  1114. var playId = _this.opt.id;
  1115. if (playId == event.data.id && event.data.type === 'stop') {
  1116. resolve(event.data);
  1117. }
  1118. });
  1119. });
  1120. return promise;
  1121. };
  1122. EZUIKitPlayer.prototype.openSound = function () {
  1123. var id = 'EZUIKitPlayer-' + this.opt.id;
  1124. var player = document.getElementById(id).contentWindow;
  1125. player.postMessage("openSound", domain + "/ezopen/h5/iframe");
  1126. var _this = this;
  1127. var promise = new Promise(function(resolve,reject) {
  1128. window.addEventListener("message", function (event) {
  1129. var playId = _this.opt.id;
  1130. if (playId == event.data.id && event.data.type === 'openSound') {
  1131. resolve(event.data);
  1132. }
  1133. });
  1134. });
  1135. return promise;
  1136. };
  1137. EZUIKitPlayer.prototype.closeSound = function () {
  1138. var id = 'EZUIKitPlayer-' + this.opt.id;
  1139. var player = document.getElementById(id).contentWindow;
  1140. player.postMessage("closeSound", domain + "/ezopen/h5/iframe");
  1141. var _this = this;
  1142. var promise = new Promise(function(resolve,reject) {
  1143. window.addEventListener("message", function (event) {
  1144. var playId = _this.opt.id;
  1145. if (playId == event.data.id && event.data.type === 'closeSound') {
  1146. resolve(event.data);
  1147. }
  1148. });
  1149. });
  1150. return promise;
  1151. };
  1152. EZUIKitPlayer.prototype.startSave = function (fileName) {
  1153. var id = 'EZUIKitPlayer-' + this.opt.id;
  1154. var player = document.getElementById(id).contentWindow;
  1155. player.postMessage({
  1156. action: "startSave",
  1157. fileName: fileName || 'default'
  1158. }, domain + "/ezopen/h5/iframe");
  1159. var _this = this;
  1160. var promise = new Promise(function(resolve,reject) {
  1161. window.addEventListener("message", function (event) {
  1162. var playId = _this.opt.id;
  1163. if (playId == event.data.id && event.data.type === 'startSave') {
  1164. resolve(event.data);
  1165. }
  1166. });
  1167. });
  1168. return promise;
  1169. };
  1170. EZUIKitPlayer.prototype.stopSave = function () {
  1171. var id = 'EZUIKitPlayer-' + this.opt.id;
  1172. var player = document.getElementById(id).contentWindow;
  1173. player.postMessage("stopSave", domain + "/ezopen/h5/iframe");
  1174. var _this = this;
  1175. var promise = new Promise(function(resolve,reject) {
  1176. window.addEventListener("message", function (event) {
  1177. var playId = _this.opt.id;
  1178. if (playId == event.data.id && event.data.type === 'stopSave') {
  1179. resolve(event.data);
  1180. }
  1181. });
  1182. });
  1183. return promise;
  1184. };
  1185. EZUIKitPlayer.prototype.fullScreen = function () {
  1186. if(this.opt.fullScreenStatus === 1){
  1187. return false
  1188. }
  1189. var _this = this;
  1190. var id = 'EZUIKitPlayer-' + this.opt.id;
  1191. var player = document.getElementById(id).contentWindow;
  1192. if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  1193. // console.log('移动端全屏');
  1194. var width = document.documentElement.clientWidth;
  1195. var height = document.documentElement.clientHeight;
  1196. // wrapper = document.getElementById("test"),
  1197. var wrapper = document.body;//document.body 属性返回 <body> 元素, document.documentElement 属性返回 <html> 元素。
  1198. wrapper =document.getElementById(id);
  1199. var style = "";
  1200. style += "width:" + height + "px;";// 注意旋转后的宽高切换
  1201. style += "height:" + width + "px;";
  1202. style += "-webkit-transform: rotate(90deg); transform: rotate(90deg);";
  1203. // 注意旋转中点的处理
  1204. style += "-webkit-transform-origin: " + width / 2 + "px " + width / 2 + "px;";
  1205. style += "transform-origin: " + width / 2 + "px " + width / 2 + "px;";
  1206. style += 'position: fixed;top: 0;left: 0;z-index:10';
  1207. wrapper.style.cssText = style;
  1208. // var cancelFullDOM = document.createElement('div');
  1209. // cancelFullDOM.id = id + "cancel-full-screen"
  1210. // var cancelFullDOMStyle="width:30px;height:"+height+"px;z-index:1000;position:fixed;top:0px;right:0px;";
  1211. // cancelFullDOMStyle += "background-image: url(https://resource.ys7cloud.com/group1/M00/00/7E/CtwQE1-01qeAH2wAAAABOliqQ5g167.png);"
  1212. // cancelFullDOMStyle += "background-size: contain;background-repeat:no-repeat;background-color:rgba(0,0,0,0.2)"
  1213. // cancelFullDOM.style = cancelFullDOMStyle;
  1214. // cancelFullDOM.onclick = function(){
  1215. // _this.cancelFullScreen();
  1216. // }
  1217. // document.body.appendChild(cancelFullDOM);
  1218. setTimeout(function () {
  1219. player.postMessage('autoResize', domain + "/ezopen/h5/iframe")
  1220. }, 500)
  1221. } else {
  1222. // console.log('pc端全屏');
  1223. var requestFullScreen = function (element) {
  1224. var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
  1225. if (requestMethod) {
  1226. requestMethod.call(element);
  1227. } else if (typeof window.ActiveXObject !== "undefined") {
  1228. var wscript = new ActiveXObject("WScript.Shell");
  1229. if (wscript !== null) {
  1230. wscript.SendKeys("{F11}");
  1231. }
  1232. }
  1233. }
  1234. requestFullScreen(document.getElementById(id));
  1235. }
  1236. if (this.params.fullScreenCallBack) {
  1237. this.params.fullScreenCallBack(this.opt.id);
  1238. }
  1239. this.opt.fullScreenStatus = 1;
  1240. };
  1241. EZUIKitPlayer.prototype.cancelFullScreen = function () {
  1242. if(this.opt.fullScreenStatus === 0){
  1243. return false
  1244. }
  1245. var id = 'EZUIKitPlayer-' + this.opt.id;
  1246. var player = document.getElementById(id).contentWindow;
  1247. if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  1248. var width = document.getElementById(id).width;
  1249. var height = document.getElementById(id).height;
  1250. // wrapper = document.getElementById("test"),
  1251. var wrapper = document.body;//document.body 属性返回 <body> 元素, document.documentElement 属性返回 <html> 元素。
  1252. wrapper =document.getElementById(id);
  1253. var style = "";
  1254. style += "width:" + width + "px;";
  1255. style += "height:" + height + "px;";
  1256. style += "-webkit-transform: rotate(0); transform: rotate(0);";
  1257. style += "-webkit-transform-origin: 0 0;";
  1258. style += "transform-origin: 0 0;";
  1259. wrapper.style.cssText = style;
  1260. setTimeout(function () {
  1261. player.postMessage("autoResize", domain + "/ezopen/h5/iframe")
  1262. }, 500);
  1263. var cancelFullDOMId = id + "cancel-full-screen";
  1264. var cancelFullDOM = document.getElementById(cancelFullDOMId);
  1265. if(cancelFullDOM){
  1266. document.body.removeChild(cancelFullDOM)
  1267. }
  1268. } else {
  1269. if (document.exitFullscreen) {
  1270. document.exitFullscreen();
  1271. } else if (document.webkitCancelFullScreen) {
  1272. document.webkitCancelFullScreen();
  1273. } else if (document.mozCancelFullScreen) {
  1274. document.mozCancelFullScreen();
  1275. }
  1276. }
  1277. if (this.params.cancelFullScreenCallBack) {
  1278. this.params.cancelFullScreenCallBack(this.opt.id);
  1279. }
  1280. this.opt.fullScreenStatus = 0;
  1281. }
  1282. EZUIKitPlayer.prototype.capturePicture = function (fileName,isUndownload) {
  1283. var id = 'EZUIKitPlayer-' + this.opt.id;
  1284. var player = document.getElementById(id).contentWindow;
  1285. player.postMessage({
  1286. action: "capturePicture",
  1287. fileName: fileName || 'default',
  1288. isUndownload: isUndownload,
  1289. }, domain + "/ezopen/h5/iframe");
  1290. var _this = this;
  1291. var promise = new Promise(function(resolve,reject) {
  1292. window.addEventListener("message", function (event) {
  1293. var playId = _this.opt.id;
  1294. if (playId == event.data.id && event.data.type === 'capturePicture') {
  1295. resolve(event.data);
  1296. }
  1297. });
  1298. });
  1299. return promise;
  1300. };
  1301. EZUIKitPlayer.prototype.enableZoom = function () {
  1302. var id = 'EZUIKitPlayer-' + this.opt.id;
  1303. var player = document.getElementById(id).contentWindow;
  1304. player.postMessage("enableZoom", domain + "/ezopen/h5/iframe");
  1305. };
  1306. EZUIKitPlayer.prototype.closeZoom = function () {
  1307. var id = 'EZUIKitPlayer-' + this.opt.id;
  1308. var player = document.getElementById(id).contentWindow;
  1309. player.postMessage("closeZoom", domain + "/ezopen/h5/iframe");
  1310. };
  1311. EZUIKitPlayer.prototype.getOSDTime = function () {
  1312. var id = 'EZUIKitPlayer-' + this.opt.id;
  1313. var player = document.getElementById(id).contentWindow;
  1314. player.postMessage("getOSDTime", domain + "/ezopen/h5/iframe");
  1315. var _this = this;
  1316. var promise = new Promise(function(resolve,reject) {
  1317. window.addEventListener("message", function (event) {
  1318. var playId = _this.opt.id;
  1319. if (playId == event.data.id && event.data.type === 'getOSDTime') {
  1320. resolve(event.data);
  1321. }
  1322. });
  1323. });
  1324. return promise;
  1325. };
  1326. EZUIKitPlayer.prototype.autoResize = function () {
  1327. var id = 'EZUIKitPlayer-' + this.opt.id;
  1328. var player = document.getElementById(id).contentWindow;
  1329. player.postMessage("autoResize", domain + "/ezopen/h5/iframe")
  1330. };
  1331. EZUIKitPlayer.prototype.reSize = function (width,height) {
  1332. var id = 'EZUIKitPlayer-' + this.opt.id;
  1333. var player = document.getElementById(id).contentWindow;
  1334. var containerDOM = document.getElementById(this.opt.id);
  1335. containerDOM.style.width = width + 'px';
  1336. containerDOM.style.height = height + 'px';
  1337. document.getElementById(this.opt.id).style.width = width + 'px';
  1338. document.getElementById(this.opt.id).style.height = height + 'px';
  1339. var playDOM = document.getElementById(id);
  1340. playDOM.setAttribute("width",width);
  1341. playDOM.setAttribute("height",height);
  1342. playDOM.style.width = width + 'px';
  1343. playDOM.style.height = height + 'px';
  1344. setTimeout(function(){
  1345. player.postMessage({
  1346. action: 'autoResize',
  1347. }, domain + "/ezopen/h5/iframe");
  1348. },500)
  1349. };
  1350. EZUIKitPlayer.prototype.startTalk = function () {
  1351. console.log("执行开始对讲");
  1352. console.log(this.opt);
  1353. var _this = this;
  1354. EZUIKit.opt = this.opt;
  1355. var apiSuccess = function(data) {
  1356. if (data.code == 200) {
  1357. var apiResult = data.data;
  1358. if (apiResult) {
  1359. // 临时将https转换为websocket
  1360. var rtcTrunk = apiResult.rtcUrl;
  1361. if (rtcTrunk.indexOf("ws") === -1) {
  1362. rtcTrunk = rtcTrunk.replace("https", "wss").replace("rtcgw", "rtcgw-ws");
  1363. }
  1364. _this.opt.rtcUrl = rtcTrunk;
  1365. _this.opt.ttsUrl = "tts://" + apiResult.ttsUrl;
  1366. var talk = "talk://" + _this.opt.deviceSerial + ":0:" + _this.opt.channelNo + ":cas.ys7.com:6500";
  1367. _this.opt.talkLink = _this.opt.ttsUrl + "/" + talk;
  1368. _this.opt.stream = apiResult.stream;
  1369. window.startTalk();
  1370. }
  1371. }
  1372. }
  1373. var apiError = function() {
  1374. layer.msg("获取对讲token失败")
  1375. }
  1376. request(_this.opt.apiDomain, 'POST', {
  1377. accessToken: _this.opt.accessToken,
  1378. deviceSerial: _this.opt.deviceSerial,
  1379. channelNo: _this.opt.channelNo
  1380. }, '', apiSuccess, apiError);
  1381. };
  1382. EZUIKitPlayer.prototype.stopTalk = function () {
  1383. console.log("执行结束对讲");
  1384. window.stopTalk();
  1385. };
  1386. EZUIKitPlayer.prototype.edit = function () {
  1387. var id = 'EZUIKitPlayer-' + this.opt.id;
  1388. var player = document.getElementById(id).contentWindow;
  1389. player.postMessage("edit", domain + "/ezopen/h5/iframe");
  1390. };
  1391. EZUIKitPlayer.prototype.btnReRender = function (data) {
  1392. var id = 'EZUIKitPlayer-' + this.opt.id;
  1393. var player = document.getElementById(id).contentWindow;
  1394. player.postMessage({action: "btnReRender",data: data}, domain + "/ezopen/h5/iframe")
  1395. };
  1396. EZUIKitPlayer.prototype.changePlayUrl = function (data) {
  1397. var id = 'EZUIKitPlayer-' + this.opt.id;
  1398. var player = document.getElementById(id).contentWindow;
  1399. player.postMessage({action: "changePlayUrl",data: data}, domain + "/ezopen/h5/iframe");
  1400. };
  1401. EZUIKitPlayer.prototype.fetchThemeData = function () {
  1402. var id = 'EZUIKitPlayer-' + this.opt.id;
  1403. var player = document.getElementById(id).contentWindow;
  1404. player.postMessage({action: "fetchThemeData"}, domain + "/ezopen/h5/iframe")
  1405. };
  1406. EZUIKitPlayer.prototype.setThemeData = function (accessToken, header, footer) {
  1407. var id = 'EZUIKitPlayer-' + this.opt.id;
  1408. var player = document.getElementById(id).contentWindow;
  1409. player.postMessage({action: "setThemeData",data:{accessToken, header, footer}}, domain + "/ezopen/h5/iframe")
  1410. };
  1411. /**
  1412. * 视频播放器-结束
  1413. */
  1414. EZUIKit.EZUIKitPlayer = EZUIKitPlayer;
  1415. window.EZUIKit = EZUIKit;
  1416. if (!noGlobal) {
  1417. window.EZUIKit = EZUIKit;
  1418. }
  1419. return EZUIKit;
  1420. });