|
186 | 186 | /** insertAfter */ |
187 | 187 | function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } |
188 | 188 |
|
| 189 | + |
| 190 | + |
189 | 191 | var EZUIPlayer = function (playParams) { |
190 | 192 | if (!isModernBrowser) { |
191 | 193 | throw new Error('不支持ie8等低版本浏览器'); |
|
404 | 406 | /** 根据播放参数获取真实播放地址 */ |
405 | 407 | this.loadingStart(); |
406 | 408 | playStartTime = new Date().getTime(); |
407 | | - |
408 | | - var getRealUrl = this.getRealUrl(playParams); |
409 | | - // debugger |
410 | | - /**是否自动播放 */ |
411 | | - if (isPromise(getRealUrl)) { |
412 | | - getRealUrl.then(function (data) { |
413 | | - var initDecoder = _this.initDecoder(playParams); |
414 | | - // 初始化播放器 |
415 | | - _this.loadingSet(0, { text: '初始化播放器...' }); |
416 | | - if (isPromise(initDecoder)) { |
417 | | - initDecoder.then(function (data) { |
418 | | - _this.loadingSet(0, { text: '初始化完成' }); |
419 | | - setTimeout(function () { |
420 | | - _this.play(playParams); |
421 | | - }, 1500) |
422 | | - }) |
423 | | - } |
| 409 | + // var getRealUrl = this.getRealUrl(playParams); |
| 410 | + var initDecoder = this.initDecoder(playParams); |
| 411 | + // 初始化播放器 |
| 412 | + _this.loadingSet(0, { text: '初始化播放器...' }); |
| 413 | + if (isPromise(initDecoder)) { |
| 414 | + initDecoder.then(function (data) { |
| 415 | + _this.loadingSet(0, { text: '初始化完成' }); |
| 416 | + // setTimeout(function () { |
| 417 | + // _this.play(playParams); |
| 418 | + // }, 100) |
| 419 | + var getRealUrl = _this.getRealUrl(playParams); |
| 420 | + getRealUrl.then(function (data) { |
| 421 | + _this.play(playParams); |
| 422 | + }) |
424 | 423 | }) |
425 | | - .catch(function (err) { |
426 | | - var initDecoder = _this.initDecoder(playParams); |
427 | | - if (isPromise(initDecoder) && (playParams.autoplay !== false)) { |
428 | | - initDecoder.then(function () { |
429 | | - // _this.play({ handleError: playParams.handleError }); |
430 | | - }) |
431 | | - } |
432 | | - }); |
433 | 424 | } |
| 425 | + // debugger |
| 426 | + /**是否自动播放 */ |
| 427 | + // if (isPromise(getRealUrl)) { |
| 428 | + // getRealUrl.then(function (data) { |
| 429 | + // var initDecoder = _this.initDecoder(playParams); |
| 430 | + // // 初始化播放器 |
| 431 | + // _this.loadingSet(0, { text: '初始化播放器...' }); |
| 432 | + // if (isPromise(initDecoder)) { |
| 433 | + // initDecoder.then(function (data) { |
| 434 | + // _this.loadingSet(0, { text: '初始化完成' }); |
| 435 | + // setTimeout(function () { |
| 436 | + // _this.play(playParams); |
| 437 | + // }, 1500) |
| 438 | + // }) |
| 439 | + // } |
| 440 | + // }) |
| 441 | + // } |
434 | 442 | } else { |
435 | 443 | var domain = "https://open.ys7.com"; |
436 | 444 | var elementID = ''; |
|
768 | 776 | if (!/^ezopen:\/\//.test(ezopenURL)) { // JSDecoder ws协议播放 |
769 | 777 | resolve(ezopenURL); |
770 | 778 | } else { |
771 | | - var getPlayTokenST = new Date().getTime(); |
772 | | - var nodeUrl = apiDomain + "/jssdk/ezopen/getStreamToken?accessToken=" + playParams.accessToken + '&num=10&type=' + (playParams.url.indexOf('live') !== -1 ? 'live' : 'playback'); |
773 | | - var nodeSuccess = function (data) { |
774 | | - if (data.retcode === 0) { |
775 | | - realUrl = realUrl + data.data.params + '&ssn=' + data.data.tokens[0]; |
776 | | - // _this.opt.currentSource = realUrl; |
777 | | - ezuikitDclog({ |
778 | | - systemName: PERFORMANCE_EZUIKIT, |
779 | | - bn: 3, |
780 | | - browser: JSON.stringify(getBrowserInfo()), |
781 | | - duration: new Date().getTime() - getPlayTokenST, |
782 | | - rt: 200, |
783 | | - }) |
784 | | - resolve(realUrl); |
785 | | - } else { |
786 | | - // 将错误信息捕获到用户自定义错误回调中 |
787 | | - if (playParams && playParams.handleError) { |
788 | | - playParams.handleError(data); |
789 | | - } |
790 | | - // 错误信息显示在状态中 |
791 | | - if (data.msg) { |
792 | | - _this.loadingSet(0, { text: data.msg, color: 'red' }); |
793 | | - } |
794 | | - ezuikitDclog({ |
795 | | - systemName: PERFORMANCE_EZUIKIT, |
796 | | - bn: 3, |
797 | | - browser: JSON.stringify(getBrowserInfo()), |
798 | | - duration: new Date().getTime() - getPlayTokenST, |
799 | | - rt: data.retcode, |
800 | | - msg: data.msg, |
801 | | - }) |
802 | | - resolve(JSON.stringify(data)); |
803 | | - throw new Error('获取播放token失败'); |
804 | | - } |
805 | | - } |
806 | | - var nodeError = function (error) { |
807 | | - // 将错误信息捕获到用户自定义错误回调中 |
808 | | - if (playParams && playParams.handleError) { |
809 | | - playParams.handleError(error); |
810 | | - } |
811 | | - ezuikitDclog({ |
812 | | - systemName: PERFORMANCE_EZUIKIT, |
813 | | - bn: 3, |
814 | | - browser: JSON.stringify(getBrowserInfo()), |
815 | | - duration: new Date().getTime() - getPlayTokenST, |
816 | | - rt: 500, |
817 | | - msg: '获取取流token网络错误', |
818 | | - }) |
819 | | - resolve(JSON.stringify(error)) |
820 | | - throw new Error('获取播放token失败', 'error'); |
821 | | - } |
| 779 | + // var getPlayTokenST = new Date().getTime(); |
| 780 | + // var nodeUrl = apiDomain + "/jssdk/ezopen/getStreamToken?accessToken=" + playParams.accessToken + '&num=10&type=' + (playParams.url.indexOf('live') !== -1 ? 'live' : 'playback'); |
| 781 | + // var nodeSuccess = function (data) { |
| 782 | + // if (data.retcode === 0) { |
| 783 | + // realUrl = realUrl + data.data.params + '&ssn=' + data.data.tokens[0]; |
| 784 | + // // _this.opt.currentSource = realUrl; |
| 785 | + // ezuikitDclog({ |
| 786 | + // systemName: PERFORMANCE_EZUIKIT, |
| 787 | + // bn: 3, |
| 788 | + // browser: JSON.stringify(getBrowserInfo()), |
| 789 | + // duration: new Date().getTime() - getPlayTokenST, |
| 790 | + // rt: 200, |
| 791 | + // }) |
| 792 | + // resolve(realUrl); |
| 793 | + // } else { |
| 794 | + // // 将错误信息捕获到用户自定义错误回调中 |
| 795 | + // if (playParams && playParams.handleError) { |
| 796 | + // playParams.handleError(data); |
| 797 | + // } |
| 798 | + // // 错误信息显示在状态中 |
| 799 | + // if (data.msg) { |
| 800 | + // _this.loadingSet(0, { text: data.msg, color: 'red' }); |
| 801 | + // } |
| 802 | + // ezuikitDclog({ |
| 803 | + // systemName: PERFORMANCE_EZUIKIT, |
| 804 | + // bn: 3, |
| 805 | + // browser: JSON.stringify(getBrowserInfo()), |
| 806 | + // duration: new Date().getTime() - getPlayTokenST, |
| 807 | + // rt: data.retcode, |
| 808 | + // msg: data.msg, |
| 809 | + // }) |
| 810 | + // resolve(JSON.stringify(data)); |
| 811 | + // throw new Error('获取播放token失败'); |
| 812 | + // } |
| 813 | + // } |
| 814 | + // var nodeError = function (error) { |
| 815 | + // // 将错误信息捕获到用户自定义错误回调中 |
| 816 | + // if (playParams && playParams.handleError) { |
| 817 | + // playParams.handleError(error); |
| 818 | + // } |
| 819 | + // ezuikitDclog({ |
| 820 | + // systemName: PERFORMANCE_EZUIKIT, |
| 821 | + // bn: 3, |
| 822 | + // browser: JSON.stringify(getBrowserInfo()), |
| 823 | + // duration: new Date().getTime() - getPlayTokenST, |
| 824 | + // rt: 500, |
| 825 | + // msg: '获取取流token网络错误', |
| 826 | + // }) |
| 827 | + // resolve(JSON.stringify(error)) |
| 828 | + // throw new Error('获取播放token失败', 'error'); |
| 829 | + // } |
822 | 830 | // 向API请求真实地址 |
823 | 831 | var apiUrl = apiDomain + "/api/lapp/live/url/ezopen"; |
824 | 832 | var apiSuccess = function (data) { |
825 | 833 | if (data.code == 200 || data.retcode == 0) { |
826 | 834 | realUrl += data.data; |
| 835 | + if(data.ext && data.ext.token){ |
| 836 | + stream = data.ext.token; |
| 837 | + var type= playParams.url.indexOf('live') !== -1 ? 'live' : 'playback'; |
| 838 | + if(type === 'live'){ |
| 839 | + realUrl = realUrl + '&auth=1&biz=4&cln=100' + '&ssn=' + stream; |
| 840 | + }else { |
| 841 | + realUrl = realUrl + '&auth=1&cln=100' + '&ssn=' + stream; |
| 842 | + } |
| 843 | + console.log(realUrl) |
| 844 | + } |
| 845 | + |
827 | 846 | /**参数容错处理 start*/ |
828 | 847 | if (data.data.indexOf('playback') !== -1) { //回放 |
829 | 848 | var wsBegin = getQueryString('begin', data.data) || getQueryString('begin', playParams.url); |
|
874 | 893 | recSliceArr = recSliceArrFun(data.data); |
875 | 894 | var recSliceArrJSON = JSON.stringify(recSliceArr).replace('\\', ''); |
876 | 895 | realUrl += ('&recSlice=' + recSliceArrJSON.replace('\\', '')); |
877 | | - request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 896 | + // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 897 | + resolve(realUrl); |
878 | 898 | } else { |
879 | 899 | _this.log('未找到录像片段', 'error'); |
880 | 900 | _this.loadingSet(0, { text: '获取设备播放地址' }) |
|
949 | 969 |
|
950 | 970 | } |
951 | 971 | _this.opt.sources[0] = realUrl; |
952 | | - request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 972 | + resolve(realUrl); |
| 973 | + // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
953 | 974 | } else { |
954 | 975 | _this.log('未找到录像片段', 'error'); |
955 | 976 | _this.loadingSet(0, { text: '获取设备播放地址' }) |
|
990 | 1011 | request(recSliceUrl, 'POST', recSliceParams, '', recAPISuccess, recAPIError); |
991 | 1012 | } else { |
992 | 1013 | // arlar rec - end |
993 | | - request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 1014 | + // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 1015 | + resolve(realUrl); |
994 | 1016 | } |
995 | 1017 | } |
996 | 1018 |
|
997 | 1019 | } else { |
998 | 1020 | // 预览直接获取回放片段 |
999 | | - request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 1021 | + // request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError); |
| 1022 | + resolve(realUrl); |
1000 | 1023 | } |
1001 | 1024 | getPlayTokenST = new Date().getTime(); |
1002 | 1025 | // 执行一次API服务请求上报 |
|
0 commit comments