UNPKG

ps-tcplayer

Version:

Tencent Cloud Player component with Vue2/Vue3 compatibility

1,309 lines 90.1 kB
import { h, isVue2 } from "vue-demi"; import { version } from "vue-demi"; function loadResource(sources, cb) { let arr = [...sources]; if (!arr.length) { cb && cb(); console.log("resouce loaded"); return false; } let item = arr.shift(); if (!item) { loadResource(arr, cb); return false; } const isJsFile = /\.js(\?.*)?$/.test(item); const isCssFile = /\.css(\?.*)?$/.test(item); if (isJsFile) { getJS(item, () => { loadResource(arr, cb); }); } else if (isCssFile) { getCss(item, () => { loadResource(arr, cb); }); } else { console.warn("no suport resource:", item); loadResource(arr, cb); } } function getJS(url, callback) { if (document.querySelector(`script[src="${url}"]`)) { console.log(url, ":has youle"); callback && callback(); return false; } var script = document.createElement("script"), fn = callback || function() { }; script.type = "text/javascript"; if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; fn(); } else { script.onreadystatechange = null; fn(); } console.log(script.readyState); }; } else { script.onload = function() { fn(); }; script.onerror = function(err) { fn(); console.log(err); }; } script.src = url; document.querySelector("body").appendChild(script); } function getCss(url, callback) { if (document.querySelector(`link[href="${url}"]`)) { console.log(url, ":has youle"); callback && callback(); return false; } var css = document.createElement("link"), fn = callback || function() { }; css.rel = "stylesheet"; if (css.readyState) { css.onreadystatechange = function() { if (css.readyState == "loaded" || css.readyState == "complete") { css.onreadystatechange = null; fn(); } else { css.onreadystatechange = null; fn(); } console.log(css.readyState); }; } else { css.onload = function() { fn(); }; css.onerror = function(err) { fn(); console.log(err); }; } css.href = url; document.querySelector("head").appendChild(css); } function parseDom(html2) { let ele = document.createElement("div"); ele.innerHTML = html2.trim(); return ele.childNodes[0]; } function afterinsert(newElement, targetElement) { const parent = targetElement.parentNode; if (parent.lastChild === targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } const STORAGE_KEYS = { VOLUME: "cto_ali_player_vol", RATE: "cto_video_Rate" }; const localStore = { get(key, defaultVal) { try { const val = localStorage.getItem(key); return val !== null ? JSON.parse(val) : defaultVal; } catch (e) { console.error("\u83B7\u53D6\u672C\u5730\u5B58\u50A8\u5931\u8D25:", e); return defaultVal; } }, set(key, val) { try { localStorage.setItem(key, JSON.stringify(val)); } catch (e) { console.error("\u8BBE\u7F6E\u672C\u5730\u5B58\u50A8\u5931\u8D25:", e); } } }; const playerNextHtml = `<div class="player-olympic-player-next"><div class="player-olympic-player-next-tip">\u4E0B\u4E00\u8282</div></div>`; const index$9 = ""; const nextIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA4ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDowOGJiODA5NC0xNDBlLTQ3NmUtOThjMS05YjkyNzUzZGUxZjUiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NUE3MzdENzIzMDcwMTFFQkJBNDA4NUREMTk1NTZBMzEiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NUE3MzdENzEzMDcwMTFFQkJBNDA4NUREMTk1NTZBMzEiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5M2YyNmFjOC0zOWVjLTQ5MjctOTI1MC01OGYyODJhOThiZGEiIHN0UmVmOmRvY3VtZW50SUQ9ImFkb2JlOmRvY2lkOnBob3Rvc2hvcDowZDlmMzQwYS03OGRhLTExN2UtODljNS05ZTJkOWEyMjNlMmYiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz68KeUaAAACVklEQVR42uyaPUgcQRiG9y5yFiYgKAGRsxKJXAySIv5U2kq0EyXptFbDFQqxEESbkEIDwUIUO0OMlYiFhYJKfgoREgVRmxBUVEgEBQXj+g474Co7K+ze7ex57wsP3N3CcDzMfDvf7EZM0zQYdaJUQEEUREEUREEUREEUxFAQBVEQBVEQBVEQBTEUlLWCHoERcAzEWfIO6AYPvA4YScGZdAGoAwdgWf4xXfkMmh1+7wd9nkYUgnxQA/6a1/kGXvgc0ytxU51dr+P6XWIfQb7texX4CsZAYcCzJ+5yrUhXDXqmGLMNbIEOkJPJ9dTvoG7FT8ysD2BV1ijexRSpAAtg8o5lkPW3+VawAd6CGAU55yEYBOuggYLUKQWzYEZ+piBFXoJfYADkUZBzckGvrE8tFKROCfgk73gJClJH7JnWwNCtXToF2SJ2311gU+7KoxTknMeyr1sBTylInWqwBIopyL23e0VB7olRkDrn4AsFOec3aJR3NQqy5Uw2t+VgXtd+I6wRjWwSbOvekIUtQkgnmGOrcTMnhnWYlgiLnDDNIHEcKx7w/Qljz6MzP+VyWgxrIdS1xP5JMc/DLEfHDLoEE6AHHGXCBixIQd/lrPmRSb1NEEvsELSD2kyTk25BF2AYlIFxubzSvXxDJ0jVG4nCWwneyIIcRNy2CHu6BCVll21vKsUT1HrDejgYdEM7rbg26nXQVLxA9QQ0GdYLVFPgVGPJEG+YvQOv5ed9wzr8fw/+6xJ0r8OXOCmIgiiIgiiIgiiIghgKoiAKoiAKoiAKoiDGlisBBgBcQ0BsCEYJ1AAAAABJRU5ErkJggg=="; class PlayerNextComponent { constructor(player, clickHandle) { this.player = player; this.clickHandle = clickHandle; this.$html = parseDom(playerNextHtml); } createEl(el) { if (this.clickHandle) { this.$html.onclick = () => { console.log("this.clickHandle", this.clickHandle); if (typeof this.clickHandle == "function") { this.clickHandle(); } else if (typeof this.clickHandle == "string") { window.location.href = this.clickHandle; } }; this.$html.style.backgroundImage = `url(${nextIcon})`; const beforeNode = el.querySelector(".vjs-play-control"); afterinsert(this.$html, beforeNode); } } dispose() { this.$html.parentNode.removeChild(this.$html); } } const playPrevHtml = `<div class="player-olympic-player-prev"><div class="player-olympic-player-prev-tip">\u4E0A\u4E00\u8282</div></div>`; const index$8 = ""; const prevIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA4RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDplNmVjNDgwYi02N2JjLWMwNDYtYmI4NS01MTM1YjIyYzlkZGMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NUE3MzdENkUzMDcwMTFFQkJBNDA4NUREMTk1NTZBMzEiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NUE3MzdENkQzMDcwMTFFQkJBNDA4NUREMTk1NTZBMzEiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKFdpbmRvd3MpIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6YmZiYTcwMTAtN2VkYi00MjQ4LTllNDgtZTY1YzEzNWE0ZTJjIiBzdFJlZjpkb2N1bWVudElEPSJhZG9iZTpkb2NpZDpwaG90b3Nob3A6NTcyMDAwOGItNzhkYS0xMTdlLTg5YzUtOWUyZDlhMjIzZTJmIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+87YrpwAAAk9JREFUeNrsmj9IG1EAhy/a6qAUhyKCqEtFigq2g7SaQVdBh4JU2qXorDiEaksRHErBqf4Bh9COugiCQRwcDLiEughSsBpBRCSIolgRlTTp73FvCOWehrty7134ffAtAR/nl3vv7l0ulM1mLaImxEAMxEAMxEAMxEAMxECEgRiIgRiIgRiIgRiIMFDeFHn8+2L4Hu5BUToFZ+EjnkE243DM4fNF+Ern/wXDsBLG4anrkUQgDx5l1dR5HNutrTCRcxxnsM3teF4P5i7CPod5DL/BPw7HsuF23KICWCYewEG4C/sV6+ozL4MHmQ44BZvzuJhouYrpogbOwbU84ng+PYNECYzAD7Dcr/kbFLrgJHwSpBtFPxBBYnDZ7zimn0FiCo3KKVWq8xJpIq/hBKw14R7CJBrhjLx8F8Rm9X9RAb/CTZPimHAGiS/oHfwiN5ZG3qbroglG4QvT9zE6qIbrcmoZja416G0Q4ugM9DAot++6Ai3AGwZS8wt2wwMGUrMKn8LP8JqBnLmCnyz7mU6MgdQkYY9lP9JIMpCaFbkf+wgvGciZW7n1EOvTPAOpOYRvYCfcYiA1cfgcDsFzBnImDadhPfwOMwzkzAkcgC9hgoHU/IDtMtYxAzmTkdOtwbJ/DkqbGCh1z1XID8TCPQxb5ILuxI6uQFHF5+L9oH2fz6if8pag759NsHhqMOJ2UK8vUImXAiLyG6yCvy37N3Px1tmFxulXBnst+zn3EtzWFajgYSAGYiAGYiAGYiAGYiDCQAzEQAzEQAzEQAxEcvgrwADvsYR/Evmv3QAAAABJRU5ErkJggg=="; class PlayPrevComponent { constructor(player, clickHandle) { this.player = player; this.clickHandle = clickHandle; this.$html = parseDom(playPrevHtml); } createEl(el) { if (this.clickHandle) { this.$html.onclick = () => { if (typeof this.clickHandle == "function") { this.clickHandle(); } else if (typeof this.clickHandle == "string") { window.location.href = this.clickHandle; } }; this.$html.style.backgroundImage = `url(${prevIcon})`; const beforeNode = el.querySelector(".vjs-play-control"); afterinsert(this.$html, beforeNode); } } dispose() { this.$html.parentNode.removeChild(this.$html); } } const memoryPlayHtml = `<div class="memory-play-wrap"></div>`; const index$7 = ""; class MemoryPlayComponent { constructor(player, autoPlay = false, getTime, saveTimeFunction, htime) { this.html = parseDom(memoryPlayHtml); this.player = player; this.autoPlay = autoPlay; this.getTime = getTime || this._getTime; this.saveTimeFunction = saveTimeFunction || this._saveTime; this.hasMemoryDisplay = false; this.htime = htime || 0; this.memoryKey = "tcplayer_memory_"; } createEl(el) { el.appendChild(this.html); } ready() { try { const player = this.player; let that = this; let playerOptions = player.options_ || {}; let memoryVideo = ""; if (playerOptions.fileID) { memoryVideo = playerOptions.fileID; } else if (playerOptions.src) { memoryVideo = playerOptions.src.replace(/\?.*$/, ""); } this.memoryKey = "tcplayer_memory_" + memoryVideo; let memoryTime = 0; if (this.htime > 0) { memoryTime = this.htime; } else { memoryTime = this.getTime(this.memoryKey) ? parseInt(this.getTime(this.memoryKey)) : 0; } this.hasMemoryDisplay = false; var memoryVideoTime_cto, memoryVideoTime, lasttime, seektime; memoryVideoTime = this.getVideoTime(memoryTime); memoryVideoTime_cto = this.getVideoTime(this.htime); if (!this.hasMemoryDisplay && memoryTime > 0) { this.hasMemoryDisplay = true; let duration = 0; try { duration = player.duration() || 0; } catch (e) { console.error("\u83B7\u53D6\u89C6\u9891\u65F6\u957F\u5931\u8D25:", e); } if (memoryTime <= parseInt(duration) - 2) { var memoryDomString = ""; seektime = 0; lasttime = memoryVideoTime; if (this.autoPlay) { memoryDomString = `<div class="memory-play"><span>\u60A8\u4E0A\u6B21\u5B66\u4E60\u5230${lasttime}\u5DF2\u81EA\u52A8\u4E3A\u60A8\u7EED\u64AD</span><span class="play-jump">\u4ECE\u5934\u64AD\u653E</span><i class="iconfont icon-close"></i></div>`; player.currentTime(memoryTime); } else { memoryDomString = `<div class="memory-play"><span>\u60A8\u4E0A\u6B21\u5B66\u4E60\u5230${lasttime}</span><span class="play-jump">\u7EE7\u7EED\u64AD\u653E</span><i class="iconfont icon-close"></i></div>`; } if (player.paused()) { if (this.autoPlay) { } } this.html.innerHTML = memoryDomString; let timeoutMemory = setTimeout(() => { this.html.innerHTML = ""; }, 5e3); var closebtn = this.html.querySelector(".icon-close"); if (!!closebtn) { closebtn.onclick = () => { this.html.innerHTML = ""; clearTimeout(timeoutMemory); }; } var jumpbtn = this.html.querySelector(".play-jump"); if (!!jumpbtn) { jumpbtn.onclick = () => { if (this.autoPlay) { player.currentTime(0); } else { player.currentTime(memoryTime); } if (player.paused() && this.autoPlay) { try { player.play().catch((err) => { console.warn("\u70B9\u51FB\u540E\u64AD\u653E\u88AB\u963B\u6B62\uFF0C\u8FD9\u79CD\u60C5\u51B5\u5F88\u5C11\u89C1:", err); }); } catch (err) { console.warn("\u64AD\u653E\u5C1D\u8BD5\u5931\u8D25:", err); } } this.html.innerHTML = ""; clearTimeout(timeoutMemory); }; } } } setTimeout(() => { if (!this.hasMemoryDisplay && memoryTime > 0) { this.processMemoryPlayPrompt(memoryTime); } }, 500); this.setupTimeSaving(); } catch (err) { console.error(err); } } error() { this.setMemory(); } dispose() { this.setMemory(); if (this.visibilityHandler) { document.removeEventListener("visibilitychange", this.visibilityHandler); } if (this.unloadHandler) { window.removeEventListener("beforeunload", this.unloadHandler); } if (this.progressInterval) { clearInterval(this.progressInterval); } } processMemoryPlayPrompt(memoryTime) { const player = this.player; this.hasMemoryDisplay = true; let duration = 0; try { duration = player.duration() || 0; } catch (e) { console.error("\u83B7\u53D6\u89C6\u9891\u65F6\u957F\u5931\u8D25:", e); } if (memoryTime <= parseInt(duration) - 2) { const formattedTime = this.getVideoTime(memoryTime); let memoryDomString = ""; if (this.autoPlay) { memoryDomString = `<div class="memory-play"><span>\u60A8\u4E0A\u6B21\u5B66\u4E60\u5230${formattedTime}\u5DF2\u81EA\u52A8\u4E3A\u60A8\u7EED\u64AD</span><span class="play-jump">\u4ECE\u5934\u64AD\u653E</span><i class="iconfont icon-close"></i></div>`; player.currentTime(memoryTime); } else { memoryDomString = `<div class="memory-play"><span>\u60A8\u4E0A\u6B21\u5B66\u4E60\u5230${formattedTime}</span><span class="play-jump">\u7EE7\u7EED\u64AD\u653E</span><i class="iconfont icon-close"></i></div>`; } this.html.innerHTML = memoryDomString; let timeoutMemory = setTimeout(() => { this.html.innerHTML = ""; }, 5e3); const closeBtn = this.html.querySelector(".icon-close"); if (closeBtn) { closeBtn.onclick = () => { this.html.innerHTML = ""; clearTimeout(timeoutMemory); }; } const jumpBtn = this.html.querySelector(".play-jump"); if (jumpBtn) { jumpBtn.onclick = () => { if (this.autoPlay) { player.currentTime(0); } else { player.currentTime(memoryTime); } if (player.paused()) { try { player.play().catch((err) => { console.warn("\u70B9\u51FB\u540E\u64AD\u653E\u88AB\u963B\u6B62:", err); }); } catch (err) { console.warn("\u64AD\u653E\u5C1D\u8BD5\u5931\u8D25:", err); } } this.html.innerHTML = ""; clearTimeout(timeoutMemory); }; } } } setupTimeSaving() { const player = this.player; let that = this; document.removeEventListener("visibilitychange", this.visibilityHandler); this.visibilityHandler = function() { if (document.visibilityState === "hidden" && player.currentTime() > 0) { that.saveTimeFunction(that.memoryKey, player.currentTime()); } }; document.addEventListener("visibilitychange", this.visibilityHandler); window.removeEventListener("beforeunload", this.unloadHandler); this.unloadHandler = function() { if (player.currentTime() > 0) { that.saveTimeFunction(that.memoryKey, player.currentTime()); } }; window.addEventListener("beforeunload", this.unloadHandler); this.progressInterval = setInterval(() => { if (!player.paused() && player.currentTime() > 0) { that.saveTimeFunction(that.memoryKey, player.currentTime()); } }, 3e4); } setMemory() { const player = this.player; try { if (!player || typeof player.currentTime !== "function") { return; } const currentTime = player.currentTime(); if (currentTime > 0) { this.saveTimeFunction(this.memoryKey, currentTime); } } catch (err) { console.error("\u4FDD\u5B58\u8BB0\u5FC6\u65F6\u95F4\u5931\u8D25:", err); } } getVideoTime(duration) { let secondTotal = Math.round(duration); let hour = Math.floor(secondTotal / 3600); let minute = Math.floor((secondTotal - hour * 3600) / 60); let second = secondTotal - hour * 3600 - minute * 60; if (minute < 10) { minute = "0" + minute; } if (second < 10) { second = "0" + second; } return hour === 0 ? minute + ":" + second : hour + ":" + minute + ":" + second; } _getTime(memoryVideo) { return localStorage.getItem(memoryVideo); } _saveTime(memoryVideo, currentTime) { localStorage.setItem(memoryVideo, currentTime); } } const index$6 = ""; const rateHtml = ` <div class="rate-components"> <div class="current-rate">1.0x</div> <ul class="rate-list"> <li data-rate="2.0">2.0x</li> <li data-rate="1.75">1.75x</li> <li data-rate="1.5">1.5x</li> <li data-rate="1.25">1.25x</li> <li data-rate="1.0" class="current">1.0x</li> <li data-rate="0.5">0.5x</li> </ul> </div> `; const index$5 = ""; class RateComponent { constructor(player) { this.html = parseDom(rateHtml); this.player = player; this.hasCreated = false; this.rate = this.getRate(); } createEl(el) { try { if (!el) { console.warn("RateComponent: DOM\u5143\u7D20\u4E0D\u5B58\u5728"); return; } let eleControlbar = el.querySelector(".vjs-control-bar"); if (!eleControlbar) { console.warn("RateComponent: \u65E0\u6CD5\u627E\u5230\u63A7\u5236\u680F\u5143\u7D20\uFF0C\u5C1D\u8BD5\u6DFB\u52A0\u5230\u6839\u5143\u7D20"); el.appendChild(this.html); return; } eleControlbar.appendChild(this.html); } catch (err) { console.error("RateComponent\u521B\u5EFADOM\u5143\u7D20\u5931\u8D25:", err); } } created() { if (this.hasCreated == false) { if (this.rate) { this.player.playbackRate(parseFloat(this.rate)); let li_target_current = this.html.querySelector(`li[class="current"]`); if (li_target_current) { li_target_current.className = ""; } let li_target = this.html.querySelector(`li[data-rate="${this.rate}"]`); if (li_target) { li_target.className = "current"; } } else { this.rate = "1.0"; } let currentRateEle = this.html.querySelector(".current-rate"); currentRateEle.innerText = this.rate + "x"; } this.hasCreated = true; } ready() { let currentRateEle = this.html.querySelector(".current-rate"); let rateListEle = this.html.querySelector(".rate-list"); let timeId = null; let settingRate = document.querySelector(".vcp-rate"); if (settingRate) { settingRate.style.display = "none"; } currentRateEle.onclick = () => { rateListEle.style.display = "block"; }; currentRateEle.onmouseleave = () => { timeId = setTimeout(() => { rateListEle.style.display = "none"; }, 100); }; rateListEle.onmouseenter = () => { clearTimeout(timeId); }; rateListEle.onmouseleave = () => { rateListEle.style.display = "none"; }; rateListEle.onclick = ({ target }) => { let rate = target.dataset.rate; if (rate) { this.player.playbackRate(parseFloat(rate)); if (target.className !== "current") { let currentEle = rateListEle.querySelector(".current"); if (currentEle) { currentEle.className = ""; } target.className = "current"; } rateListEle.style.display = "none"; currentRateEle.innerText = rate + "x"; this.setRate(rate); } }; } setRate(Rate) { localStorage.setItem("cto_video_Rate", Rate); } getRate() { return localStorage.getItem("cto_video_Rate"); } } const index$4 = ""; class BulletScreenComponent { constructor(player, text, style2, bulletPosition = "random") { this.text = text; this.style = style2 || { fontSize: "14px", color: "#fff" }; this.html = parseDom('<div class="bullet-screen paused"></div>'); this.bulletPosition = bulletPosition; this.mintime = 90; this.maxtime = 180; this.animationtime = 10; this.time = 0; this.stoptime = 0; this.start = new Date(); this.player = player; } createEl(el) { this.html.innerText = this.text; el.appendChild(this.html); } ready(e) { const player = this.player; if (player.autoplay() === false) { this.html.style.animationPlayState = "paused"; } Object.keys(this.style).forEach((key) => this.html.style[key] = this.style[key]); var bulletHeight = this.html.offsetHeight; var playerHeight = parseInt(player._el.offsetHeight); var maxHeight = playerHeight - bulletHeight; if (this.bulletPosition === "bottom") { this.html.style.bottom = 0; } else { let top = this.bulletPosition === "top" ? 0 : this.randomTop(maxHeight); this.html.style.top = top; } if (this.bulletPosition === "random") { this.html.addEventListener("animationiteration", () => { this.html.style.top = this.randomTop(maxHeight); }); } this.html.style.webkitAnimationDuration = this.animationtime + "s"; this.start = new Date(); } playing(e) { this.html.style.animationPlayState = "running"; this.start = new Date(); } timeupdate(timeStamp) { const player = this.player; var randomnum = Math.random(); if (this.maxtime - this.mintime > 0) { randomnum = this.mintime + (this.maxtime - this.mintime) * randomnum; } else { randomnum = 0; } let el = player.el(); let componentEl = el.querySelector(".bullet-screen"); this.time = new Date() - this.start + this.stoptime; if (!componentEl) { if (this.time - this.animationtime * 1e3 - randomnum * 1e3 > 0) { el.appendChild(this.html); this.start = new Date(); this.stoptime = 0; } } else if (this.time - this.animationtime * 1e3 > 0) { componentEl.remove(); this.stoptime = 0; } else { if (componentEl.className !== "bullet-screen") { componentEl.className = "bullet-screen"; } let cssStyles = getComputedStyle(componentEl); let display = cssStyles.getPropertyValue("display"); let opacity = cssStyles.getPropertyValue("opacity"); let visibility = cssStyles.getPropertyValue("visibility"); let currentwords = this.text; let modifywords = componentEl.innerText; if (display === "none") { componentEl.style.setProperty("display", "block"); } if (opacity !== "1") { componentEl.style.setProperty("opacity", "1"); } if (visibility === "hidden") { componentEl.style.setProperty("visibility", "visible"); } if (currentwords != modifywords) { componentEl.innerText = currentwords; } } } pause(e) { this.html.style.animationPlayState = "paused"; } randomTop(max) { return Math.floor(Math.random() * max) + "px"; } } const html = { CountdownHtml: `<div class="countdown-wrap"><div class="countdown"></div></div>`, RateHtml: `<div class="player-rate-wrap"><div class="player-rate-tips">\u8FD9\u8282\u8BFE\u7A0B\u60A8\u662F\u5426\u6EE1\u610F\uFF1F</div><div class="player-rate-box"><div class="player-star-wrap"><i class="player-icon player-star" data-id="1"></i><i class="player-icon player-star" data-id="2"></i><i class="player-icon player-star" data-id="3"></i><i class="player-icon player-star" data-id="4"></i><i class="player-icon player-star" data-id="5"></i></div><div class="player-rate-txt">\u8BC4\u5206</div></div></div>` }; const index$3 = ""; class CountdownComponent { constructor(player, open = true, time, type, starOpen) { this.html = parseDom(html.CountdownHtml); this.player = player; this.open = open; this.time = time ? time : 15; this.type = type; this.isClicked = false; this.starOpen = starOpen; this.player.on("timeupdate", () => this.timeupdate()); } createEl(el) { if (this.open) { el.appendChild(this.html); } } timeupdate() { const player = this.player; if (this.type == "star") { var lasttime = player.duration() - player.currentTime(); if (lasttime <= this.time) { this.starOpen(); } } else { if (this.open) { var txtbox = this.html.querySelector(".countdown"); var lasttime = player.duration() - player.currentTime(); if (lasttime <= this.time) { lasttime = lasttime - lasttime % 1 + 1; var countdownString = `<div class="countdown-txt"> <span class="time">${lasttime}s</span>\u540E\u4E3A\u60A8\u64AD\u653E\u4E0B\u4E00\u8282 </div>`; txtbox.innerHTML = countdownString; } else { txtbox.innerHTML = ""; } } } } getVideoTime(duration) { let secondTotal = Math.round(duration); let hour = Math.floor(secondTotal / 3600); let minute = Math.floor((secondTotal - hour * 3600) / 60); let second = secondTotal - hour * 3600 - minute * 60; if (minute < 10) { minute = "0" + minute; } if (second < 10) { second = "0" + second; } return hour === 0 ? minute + ":" + second : hour + ":" + minute + ":" + second; } } const snapshotHtml = ` <div class="prism-snapshot-btn"></div> `; const index$2 = ""; class SnapshotComponent { constructor(player) { this.player = player; this.html = parseDom(snapshotHtml); } createEl(el) { const controlBar = el.querySelector(".vjs-control-bar"); if (controlBar) { const tcpVideoQualitySwitcher = controlBar.querySelector(".vjs-fullscreen-control"); controlBar.insertBefore(this.html, tcpVideoQualitySwitcher.previousSibling); } else { console.warn("\u627E\u4E0D\u5230\u64AD\u653E\u5668\u63A7\u5236\u680F\uFF0C\u5C1D\u8BD5\u6DFB\u52A0\u5230\u6839\u5143\u7D20"); el.appendChild(this.html); } } ready() { this.setupVideoForSnapshot(); this.html.addEventListener("click", () => { this.captureSnapshot(); }); } setupVideoForSnapshot() { const video = this.player.tech_.el_; if (video && !video.crossOrigin) { video.crossOrigin = "anonymous"; video.setAttribute("crossOrigin", "anonymous"); } } captureSnapshot() { const player = this.player; const video = player.tech_.el_; if (!video) { console.error("\u89C6\u9891\u5143\u7D20\u4E0D\u5B58\u5728"); this.showErrorMessage("\u89C6\u9891\u5143\u7D20\u4E0D\u5B58\u5728"); return; } const canvas = document.createElement("canvas"); canvas.width = video.videoWidth || video.clientWidth; canvas.height = video.videoHeight || video.clientHeight; const ctx = canvas.getContext("2d"); try { ctx.drawImage(video, 0, 0, canvas.width, canvas.height); const imageData = canvas.toDataURL("image/png"); const link = document.createElement("a"); link.href = imageData; const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); const title = player.el_.getAttribute("title") || "video"; const filename = `${title}_${timestamp}.png`; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); console.log("\u622A\u56FE\u6210\u529F:", filename); } catch (error) { console.error("\u622A\u56FE\u5931\u8D25:", error); if (error.name === "SecurityError") { this.tryAlternativeSnapshot(video); } else { this.showErrorMessage("\u622A\u56FE\u5931\u8D25\uFF1A" + error.message); } } } tryAlternativeSnapshot(video) { try { const videoSrc = video.src || video.currentSrc; if (videoSrc) { console.log("\u5C1D\u8BD5\u91CD\u65B0\u52A0\u8F7D\u89C6\u9891\u5E76\u8BBE\u7F6E\u8DE8\u57DF\u5C5E\u6027..."); const tempVideo = document.createElement("video"); tempVideo.crossOrigin = "anonymous"; tempVideo.muted = true; tempVideo.style.display = "none"; tempVideo.addEventListener("loadeddata", () => { tempVideo.currentTime = video.currentTime; }); tempVideo.addEventListener("seeked", () => { this.captureFromTempVideo(tempVideo); document.body.removeChild(tempVideo); }); document.body.appendChild(tempVideo); tempVideo.src = videoSrc; tempVideo.load(); } } catch (altError) { console.error("\u66FF\u4EE3\u65B9\u6848\u4E5F\u5931\u8D25\u4E86:", altError); this.showErrorMessage("\u6240\u6709\u622A\u56FE\u65B9\u6848\u90FD\u5931\u8D25\u4E86\uFF0C\u8BF7\u68C0\u67E5\u89C6\u9891\u6E90\u7684 CORS \u914D\u7F6E"); } } captureFromTempVideo(video) { const canvas = document.createElement("canvas"); canvas.width = video.videoWidth; canvas.height = video.videoHeight; const ctx = canvas.getContext("2d"); ctx.drawImage(video, 0, 0, canvas.width, canvas.height); try { const imageData = canvas.toDataURL("image/png"); const link = document.createElement("a"); link.href = imageData; const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); const title = this.player.el_.getAttribute("title") || "video"; const filename = `${title}_${timestamp}.png`; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); } catch (error) { console.error("\u66FF\u4EE3\u65B9\u6848\u622A\u56FE\u5931\u8D25:", error); this.showErrorMessage("\u66FF\u4EE3\u65B9\u6848\u622A\u56FE\u5931\u8D25"); } } showErrorMessage(message) { console.warn("[SnapshotComponent]", message); } } const webFullscreenHtml = ` <div class="prism-web-fullscreen-btn" title="\u7F51\u9875\u5168\u5C4F"></div> `; const index$1 = ""; class WebFullscreenComponent { constructor(player) { this.player = player; this.html = parseDom(webFullscreenHtml); this.isWebFullscreen = false; this.handleToggle = this.handleToggle.bind(this); this.handleKeydown = this.handleKeydown.bind(this); } createEl(el) { const controlBar = el.querySelector(".vjs-control-bar"); if (controlBar) { const fullscreenControl = controlBar.querySelector(".vjs-fullscreen-control"); if (fullscreenControl) { controlBar.insertBefore(this.html, fullscreenControl); } else { controlBar.appendChild(this.html); } } else { console.warn("\u627E\u4E0D\u5230\u64AD\u653E\u5668\u63A7\u5236\u680F\uFF0C\u5C1D\u8BD5\u6DFB\u52A0\u5230\u6839\u5143\u7D20"); el.appendChild(this.html); } } ready() { this.html.addEventListener("click", this.handleToggle); document.addEventListener("keydown", this.handleKeydown); } handleToggle() { if (this.isWebFullscreen) { this.exitWebFullscreen(); } else { this.enterWebFullscreen(); } } enterWebFullscreen() { const playerEl = this.player.el_; if (!playerEl) { console.error("\u64AD\u653E\u5668\u5143\u7D20\u4E0D\u5B58\u5728"); return; } this.originalStyles = { position: playerEl.style.position, top: playerEl.style.top, left: playerEl.style.left, width: playerEl.style.width, height: playerEl.style.height, zIndex: playerEl.style.zIndex, backgroundColor: playerEl.style.backgroundColor }; playerEl.style.position = "fixed"; playerEl.style.top = "0"; playerEl.style.left = "0"; playerEl.style.width = "100vw"; playerEl.style.height = "100vh"; playerEl.style.zIndex = "9999"; playerEl.style.backgroundColor = "#000"; playerEl.classList.add("prism-web-fullscreen"); this.html.classList.add("web-fullscreen"); document.body.style.overflow = "hidden"; this.isWebFullscreen = true; this.player.trigger("webfullscreenchange", { isWebFullscreen: true }); console.log("\u8FDB\u5165\u7F51\u9875\u5168\u5C4F\u6A21\u5F0F"); } exitWebFullscreen() { const playerEl = this.player.el_; if (!playerEl) { console.error("\u64AD\u653E\u5668\u5143\u7D20\u4E0D\u5B58\u5728"); return; } if (this.originalStyles) { Object.keys(this.originalStyles).forEach((key) => { playerEl.style[key] = this.originalStyles[key] || ""; }); } playerEl.classList.remove("prism-web-fullscreen"); this.html.classList.remove("web-fullscreen"); document.body.style.overflow = ""; this.isWebFullscreen = false; this.player.trigger("webfullscreenchange", { isWebFullscreen: false }); console.log("\u9000\u51FA\u7F51\u9875\u5168\u5C4F\u6A21\u5F0F"); } handleKeydown(event) { if (event.key === "Escape" && this.isWebFullscreen) { this.exitWebFullscreen(); event.preventDefault(); } if ((event.ctrlKey || event.metaKey) && event.key === "Enter") { this.handleToggle(); event.preventDefault(); } } destroy() { if (this.isWebFullscreen) { this.exitWebFullscreen(); } if (this.html) { this.html.removeEventListener("click", this.handleToggle); } document.removeEventListener("keydown", this.handleKeydown); this.player = null; this.html = null; } } const wideScreenHtml = ` <div class="prism-wide-screen-btn" title="\u5BBD\u5C4F\u663E\u793A"></div> `; const index = ""; class WideScreenComponent { constructor(player, onWideScreenChange) { this.player = player; this.html = parseDom(wideScreenHtml); this.isWideScreen = false; this.onWideScreenChange = onWideScreenChange; this.handleToggle = this.handleToggle.bind(this); this.handleKeydown = this.handleKeydown.bind(this); } createEl(el) { const controlBar = el.querySelector(".vjs-control-bar"); if (controlBar) { const fullscreenControl = controlBar.querySelector(".vjs-fullscreen-control"); if (fullscreenControl) { controlBar.insertBefore(this.html, fullscreenControl); } else { controlBar.appendChild(this.html); } } else { console.warn("\u627E\u4E0D\u5230\u64AD\u653E\u5668\u63A7\u5236\u680F\uFF0C\u5C1D\u8BD5\u6DFB\u52A0\u5230\u6839\u5143\u7D20"); el.appendChild(this.html); } } ready() { this.html.addEventListener("click", this.handleToggle); document.addEventListener("keydown", this.handleKeydown); } handleToggle() { if (this.isWideScreen) { this.exitWideScreen(); } else { this.enterWideScreen(); } } enterWideScreen() { if (this.isWideScreen) { return; } this.isWideScreen = true; this.html.classList.add("wide-screen"); this.player.trigger("widescreenchange", { isWideScreen: true }); if (this.onWideScreenChange && typeof this.onWideScreenChange === "function") { this.onWideScreenChange(true, this.player); } } exitWideScreen() { if (!this.isWideScreen) { return; } this.isWideScreen = false; this.html.classList.remove("wide-screen"); this.player.trigger("widescreenchange", { isWideScreen: false }); if (this.onWideScreenChange && typeof this.onWideScreenChange === "function") { this.onWideScreenChange(false, this.player); } } handleKeydown(event) { if ((event.ctrlKey || event.metaKey) && event.key === "w") { this.handleToggle(); event.preventDefault(); } } getWideScreenState() { return this.isWideScreen; } setWideScreenState(isWideScreen) { if (isWideScreen && !this.isWideScreen) { this.enterWideScreen(); } else if (!isWideScreen && this.isWideScreen) { this.exitWideScreen(); } } destroy() { if (this.isWideScreen) { this.exitWideScreen(); } if (this.html) { this.html.removeEventListener("click", this.handleToggle); } document.removeEventListener("keydown", this.handleKeydown); this.player = null; this.html = null; this.onWideScreenChange = null; } } function Md5(e) { var n = 8; function t(e2) { return s(r(i(e2), e2.length * n)); } function r(e2, t2) { e2[t2 >> 5] |= 128 << t2 % 32, e2[14 + (t2 + 64 >>> 9 << 4)] = t2; for (var r2 = 1732584193, i2 = -271733879, a = -1732584194, n2 = 271733878, s2 = 0; s2 < e2.length; s2 += 16) { var o2 = r2, l = i2, u = a, d = n2; i2 = p(i2 = p(i2 = p(i2 = p(i2 = f(i2 = f(i2 = f(i2 = f(i2 = h2(i2 = h2(i2 = h2(i2 = h2(i2 = c(i2 = c(i2 = c(i2 = c(i2, a = c(a, n2 = c(n2, r2 = c(r2, i2, a, n2, e2[s2 + 0], 7, -680876936), i2, a, e2[s2 + 1], 12, -389564586), r2, i2, e2[s2 + 2], 17, 606105819), n2, r2, e2[s2 + 3], 22, -1044525330), a = c(a, n2 = c(n2, r2 = c(r2, i2, a, n2, e2[s2 + 4], 7, -176418897), i2, a, e2[s2 + 5], 12, 1200080426), r2, i2, e2[s2 + 6], 17, -1473231341), n2, r2, e2[s2 + 7], 22, -45705983), a = c(a, n2 = c(n2, r2 = c(r2, i2, a, n2, e2[s2 + 8], 7, 1770035416), i2, a, e2[s2 + 9], 12, -1958414417), r2, i2, e2[s2 + 10], 17, -42063), n2, r2, e2[s2 + 11], 22, -1990404162), a = c(a, n2 = c(n2, r2 = c(r2, i2, a, n2, e2[s2 + 12], 7, 1804603682), i2, a, e2[s2 + 13], 12, -40341101), r2, i2, e2[s2 + 14], 17, -1502002290), n2, r2, e2[s2 + 15], 22, 1236535329), a = h2(a, n2 = h2(n2, r2 = h2(r2, i2, a, n2, e2[s2 + 1], 5, -165796510), i2, a, e2[s2 + 6], 9, -1069501632), r2, i2, e2[s2 + 11], 14, 643717713), n2, r2, e2[s2 + 0], 20, -373897302), a = h2(a, n2 = h2(n2, r2 = h2(r2, i2, a, n2, e2[s2 + 5], 5, -701558691), i2, a, e2[s2 + 10], 9, 38016083), r2, i2, e2[s2 + 15], 14, -660478335), n2, r2, e2[s2 + 4], 20, -405537848), a = h2(a, n2 = h2(n2, r2 = h2(r2, i2, a, n2, e2[s2 + 9], 5, 568446438), i2, a, e2[s2 + 14], 9, -1019803690), r2, i2, e2[s2 + 3], 14, -187363961), n2, r2, e2[s2 + 8], 20, 1163531501), a = h2(a, n2 = h2(n2, r2 = h2(r2, i2, a, n2, e2[s2 + 13], 5, -1444681467), i2, a, e2[s2 + 2], 9, -51403784), r2, i2, e2[s2 + 7], 14, 1735328473), n2, r2, e2[s2 + 12], 20, -1926607734), a = f(a, n2 = f(n2, r2 = f(r2, i2, a, n2, e2[s2 + 5], 4, -378558), i2, a, e2[s2 + 8], 11, -2022574463), r2, i2, e2[s2 + 11], 16, 1839030562), n2, r2, e2[s2 + 14], 23, -35309556), a = f(a, n2 = f(n2, r2 = f(r2, i2, a, n2, e2[s2 + 1], 4, -1530992060), i2, a, e2[s2 + 4], 11, 1272893353), r2, i2, e2[s2 + 7], 16, -155497632), n2, r2, e2[s2 + 10], 23, -1094730640), a = f(a, n2 = f(n2, r2 = f(r2, i2, a, n2, e2[s2 + 13], 4, 681279174), i2, a, e2[s2 + 0], 11, -358537222), r2, i2, e2[s2 + 3], 16, -722521979), n2, r2, e2[s2 + 6], 23, 76029189), a = f(a, n2 = f(n2, r2 = f(r2, i2, a, n2, e2[s2 + 9], 4, -640364487), i2, a, e2[s2 + 12], 11, -421815835), r2, i2, e2[s2 + 15], 16, 530742520), n2, r2, e2[s2 + 2], 23, -995338651), a = p(a, n2 = p(n2, r2 = p(r2, i2, a, n2, e2[s2 + 0], 6, -198630844), i2, a, e2[s2 + 7], 10, 1126891415), r2, i2, e2[s2 + 14], 15, -1416354905), n2, r2, e2[s2 + 5], 21, -57434055), a = p(a, n2 = p(n2, r2 = p(r2, i2, a, n2, e2[s2 + 12], 6, 1700485571), i2, a, e2[s2 + 3], 10, -1894986606), r2, i2, e2[s2 + 10], 15, -1051523), n2, r2, e2[s2 + 1], 21, -2054922799), a = p(a, n2 = p(n2, r2 = p(r2, i2, a, n2, e2[s2 + 8], 6, 1873313359), i2, a, e2[s2 + 15], 10, -30611744), r2, i2, e2[s2 + 6], 15, -1560198380), n2, r2, e2[s2 + 13], 21, 1309151649), a = p(a, n2 = p(n2, r2 = p(r2, i2, a, n2, e2[s2 + 4], 6, -145523070), i2, a, e2[s2 + 11], 10, -1120210379), r2, i2, e2[s2 + 2], 15, 718787259), n2, r2, e2[s2 + 9], 21, -343485551), r2 = g(r2, o2), i2 = g(i2, l), a = g(a, u), n2 = g(n2, d); } return Array(r2, i2, a, n2); } function o(e2, t2, r2, i2, a, n2) { return g(function(e3, t3) { return e3 << t3 | e3 >>> 32 - t3; }(g(g(t2, e2), g(i2, n2)), a), r2); } function c(e2, t2, r2, i2, a, n2, s2) { return o(t2 & r2 | ~t2 & i2, e2, t2, a, n2, s2); } function h2(e2, t2, r2, i2, a, n2, s2) { return o(t2 & i2 | r2 & ~i2, e2, t2, a, n2, s2); } function f(e2, t2, r2, i2, a, n2, s2) { return o(t2 ^ r2 ^ i2, e2, t2, a, n2, s2); } function p(e2, t2, r2, i2, a, n2, s2) { return o(r2 ^ (t2 | ~i2), e2, t2, a, n2, s2); } function g(e2, t2) { var r2 = (65535 & e2) + (65535 & t2); return (e2 >> 16) + (t2 >> 16) + (r2 >> 16) << 16 | 65535 & r2; } function i(e2) { for (var t2 = Array(), r2 = (1 << n) - 1, i2 = 0; i2 < e2.length * n; i2 += n) t2[i2 >> 5] |= (e2.charCodeAt(i2 / n) & r2) << i2 % 32; return t2; } function s(e2) { for (var t2 = "0123456789abcdef", r2 = "", i2 = 0; i2 < 4 * e2.length; i2++) r2 += t2.charAt(e2[i2 >> 2] >> i2 % 4 * 8 + 4 & 15) + t2.charAt(e2[i2 >> 2] >> i2 % 4 * 8 & 15); return r2; } return t(e); } const ApiSign = `HRkJaX81cAbXdFjWe4Qg6HXxtCR7bJRr`; const ErrorTypeEnum = { ERROR: "error", CONNECT_BUFFER: "connectBuffer", SEEK_VIDEO_BUFFER: "seekVideoBuffer", VIDEO_BUFFER: "videoBuffer" }; const PlayTypeEnum = { M3U8: 1, VIDEO: 2 }; const LogStatus = { NORMAL: 0, BLOCK_TIME_OVERFLOW: -1, DOWNLINK_TOO_LOW: -2 }; const VIDEO_BLOCK_LIMIT = 1e3; class ErrorReportComponent { constructor(player, params, options) { this.player = player; this.params = params; this.currentTime = 0; this.ali_dt = ""; this.definition = ""; this.errorCode = 0; this.block_time = 0; this.blockStartTime = 0; this.speed = 1; this.errorType = ""; this.is_first = true; this.net_speed = 0; this.bitrate = 0; this.videoResources = []; this.hasOffline = false; this.netTestTimer = null; this.netTestTimeout = 6e4; } created() { console.log("created----==--==-=--=--=--=-"); window.playerEl = this.player; const player = this.player; this.videoResources = player._urls; this.net_speed = 0; this.is_first = true; this.systemEventListen(); this.logger("created videoResources", this.videoResources); } logger(...args) { const isProduction = window.location.host.startsWith("edu.51cto") || false; if (isProduction) { return; } console.log(...args); } getQuality() { let Quality = "\u81EA\u52A8"; try { const targetElement = document.querySelector( ".tcp-video-quality-switcher .vjs-selected .vjs-menu-item-text" ); if (targetElement) { const textContent = targetElement.textContent.trim(); Quality = textContent; } else { console.warn("\u672A\u627E\u5230\u76EE\u6807\u5143\u7D20\uFF0C\u8BF7\u68C0\u67E5\u9009\u62E9\u5668\u6216\u9875\u9762\u72B6\u6001"); Quality = "\u81EA\u52A8"; } } catch (error) { Quality = "\u672A\u77E5"; } this.fp = Quality; } getBitrate() { let bitrate = ""; this.bitrate = bitrate; } async playing() { this.logger("playing:", Date.now()); this.logger("playing-blockStartTime:", this.blockStartTime); this.is_first = false; this.ali_dt = this.player.getDuration(); if (this.blockStartTime > 0) { const blockDuration = Date.now() - this.blockStartTime; this.logger("\u7F13\u51B2\u4E86", `${this.block_time / 1e3}s`); if (blockDuration > VIDEO_BLOCK_LIMIT) { this.block_time = blockDuration; const data = await this.generateRequestParams(); await this.errorRequest(data); } } } ended() { this.errorCode = 0; this.resetBlockState(); } resetBlockState() { this.blockStartTime = 0; this.block_time = 0; this.errorType = ""; } pause() { this.resetBlockState(); } waiting() { const player = this.player; this.logger("\u5F00\u59CB\u7F13\u51B2:", Date.now()); this.logger("\u5F00\u59CB\u7F13\u51B2--seeking:", player._seeking); this.currentTime = player.getCurrentTime(); this.blockStartTime = Date.now(); this.speed = localStorage.getItem("cto_video_Rate") ? localStorage.getItem("cto_video_Rate") : this.speed; if (this.is_first) { this.errorType = ErrorTypeEnum.CONNECT_BUFFER; } else if (player._seeking) { this.errorType = ErrorTypeEnum.SEEK_VIDEO_BUFFER; } else { this.errorType = ErrorTypeEnum.VIDEO_BUFFER; } } timeupdate() { } async error(player, error) { this.logger("error", error); this.errorCode = error.error_code; this.resetBlockState(); this.errorType = ErrorTypeEnum.ERROR; const data = await this.generateRequestParams(); await this.errorRequest(data); } destroyed() { this.errorCode = 0; this.resetBlockState(); } getQuality() { let Quality = "\u81EA\u52A8"; try { const targetElement = document.querySelector( ".tcp-video-quality-switcher .vjs-selected .vjs-menu-item-text" ); if (targetElement) { const textContent = targetElement.textContent.trim(); Quality = textContent; } else { console.warn("\u672A\u627E\u5230\u76EE\u6807\u5143\u7D20\uFF0C\u8BF7\u68C0\u67E5\u9009\u62E9\u5668\u6216\u9875\u9762\u72B6\u6001"); Quality = "\u81EA\u52A8"; } } catch (error) { Quality = "\u672A\u77E5"; } this.definition = Quality; } getDownLink() { if (window.navigator && window.navigator.connection) { return window.navigator.connection.downlink || ""; } } getAccumulation() { if (this.player) { const ReportingComponent2 = this.player.getComponent("ReportingComponent"); this.logger("ReportingComponent", ReportingComponent2); if (ReportingComponent2) { return ReportingComponent2.accumulation; } } } systemEventListen() { window.addEventListener("online", this.onNetworkOnline.bind(this)); window.addEventListener("offline", this.onNetworkOffLine.bind(this)); window.addEventListener("visibleChange", this.onVisibleChange.bind(this)); } onVisibleChange() { this.resetBlockState(); } onNetworkOnline() { this.logger("online"); this.resetBlockState(); } onNetworkOffLine() { this.logger("offline"); this.hasOffline = true; this.resetBlockState(); } startSeek() { this.resetBlockState(); } async generateRequestParams() { const type = this.params.video_id.length === 32 ? PlayTypeEnum.M3U8 : PlayTypeEnum.VIDEO; const pt = this.getAccumulation(); this.getBitrate(); this.getQuality(); var baseData = { video_id: this.params.video_id, user_id: this.params.user_id, uuid: Md5("" + this.params.timestr + this.params.user_id + this.params.random).toString(), type, htime: this.currentTime, dt: this.ali_dt, pt, ref: location.href, sgin: Md5("" + this.params.timestr + ApiSign).toString(), platform: 5, ts_url: this.definition, code: this.errorCode, speed: this.speed, eType: this.errorType, bitrate: this.bitrate, net_speed: 0, downlink: this.getDownLink(), has_offline: this.hasOffline, log_status: LogStatus.NORMAL }; baseData.log_status = this.calcLogStatus(baseData); var data = {}; if ([ErrorTypeEnum.ERROR].includes(this.errorType)) { data = Object.assign(baseData, { time: new Date().getTime() }); } if ([ErrorTypeEnum.CONNECT_BUFFER, ErrorTypeEnum.SEEK_VIDEO_BUFFER, ErrorTypeEnum.VIDEO_BUFFER].includes(this.errorType)) { data = Object.assign(baseData, { time: this.params.timestr, block_time: this.block_time }); } return data; } isParamInvalid(data) { if (![ErrorTypeEnum.ERROR].includes(this.errorType) && data.block_time <= VIDEO_BLOCK_LIMIT) { return true; } if (data.block_time > data.ali_dt) { return true; } if (data.block_time > 10 * 60 * 1e3) { return true; } return false; } async errorRequest(data) { this.logger("\u9519\u8BEF\u4E0A\u62A5", data); const that = this; if (this.isParamInvalid(data)) { return true; } return new Promise((resolve, reject) => { $.ajax({ type: "post", url: `${this.params.error_url}`, data, dataType: "json", async: false, success: function(result) { }, complete: function(res) { that.onReportComplete(); resolve(); } }); }); } onReportComplete() { this.logger("onReportComplete"); this.resetBlockState(); this.errorCode = 0; this.hasOffline = false; } calcLogStatus(baseData) { const blockSecond = baseData.block_time ? baseData.block_time / 1e3 : 0; if (baseData.eType === ErrorTypeEnum.CONNECT_BUFFER) { if (blockSecond > 5 * 60) { return LogStatus.BLOCK_TIME_OVERFLOW; } } else { if (blockSecond > this.ali_dt) { return LogStatus.BLOCK_TIME_OVERFLOW; } if (blockSecond > 5 * 60) { return LogStatus.BLOCK_TIME_OVERFLOW; } } if (baseData.downlink > 0 && baseData.bitrate > 0