import {Mooc} from "../factory"; import {Hook, Context} from "@App/internal/utils/hook"; import {Application} from "@App/internal/application"; import {randNumber, get, createBtn, protocolPrompt, isPhone} from "@App/internal/utils/utils"; import {CssBtn} from "./utils"; import {CxTaskControlBar, Task} from "@App/mooc/chaoxing/task"; // 优化播放器 export class CxVideoOptimization implements Mooc { protected param: any; public Start(): void { //对播放器进行优化 window.addEventListener("load", () => { Application.App.config.super_mode && isPhone() && ((Application.GlobalContext).Ext.isChaoxing = true); }); this.hook(); document.addEventListener("readystatechange", () => { this.hook(); }); this.Api(); } protected hook() { if (document.readyState != "interactive") { return; } Application.App.log.Debug("hook cx video"); let dataHook = new Hook("decode", (Application.GlobalContext).Ext); let self = this; dataHook.Middleware(function (next: Context, ...args: any) { let ret = next.apply(this, args); if (Application.App.config.super_mode && ret.danmaku == 1) { ret.danmaku = 0; } return ret; }); window.frameElement.setAttribute("fastforward", ""); window.frameElement.setAttribute("switchwindow", ""); let paramHook = new Hook("params2VideoOpt", (Application.GlobalContext).ans.VideoJs.prototype); paramHook.Middleware(function (next: Context, ...args: any) { self.param = args[0]; let ret = next.apply(this, args); ret.plugins.timelineObjects.url = self.param.rootPath + "/richvideo/initdatawithviewer"; let cdn = Application.App.config.video_cdn || localStorage["cdn"] || "公网1"; for (let i = 0; i < ret.playlines.length; i++) { if (ret.playlines[i].label == cdn) { let copy = ret.playlines[i]; (>ret.playlines).splice(i, 1); (>ret.playlines).splice(0, 0, copy); } } localStorage["cdn"] = ret.playlines[0].label; return ret; }); (Application.GlobalContext).Ext.isSogou = false; let errorHook = new Hook("afterRender", (Application.GlobalContext).ans.videojs.ErrorDisplay.prototype); errorHook.Middleware(function (next: Context, ...args: any) { let ret = next.apply(this, args); setTimeout(() => { let nowCdn = this.renderData.selectedIndex; let playlines = this.renderData.playlines; let cdn = Application.App.config.video_cdn || localStorage["cdn"] || "公网1"; for (let i = 0; i < playlines.length; i++) { if (i != nowCdn) { if (cdn == "") { localStorage["cdn"] = playlines[i].label; return this.onSelected(i); } else if (cdn == playlines[i].label) { localStorage["cdn"] = playlines[i].label; return this.onSelected(i); } } } let index = (nowCdn + 1) % playlines.length; localStorage["cdn"] = playlines[index].label; return this.onSelected(index); }, 2000); return ret; }); } /** * 操作方法 */ protected Api() { (Application.GlobalContext).sendTimePack = (time: number, callback: Function) => { if (time == NaN || time == undefined) { time = parseInt(this.param.duration); } let playTime = Math.round(time || (this.param.duration - randNumber(1, 2))); let enc = '[' + this.param.clazzId + '][' + this.param.userid + '][' + this.param.jobid + '][' + this.param.objectId + '][' + (playTime * 1000).toString() + '][d_yHJ!$pdA~5][' + (this.param.duration * 1000).toString() + '][0_' + this.param.duration + ']'; enc = (Application.GlobalContext).md5(enc); get(this.param.reportUrl + '/' + this.param.dtoken + '?clipTime=0_' + this.param.duration + '&otherInfo=' + this.param.otherInfo + '&userid=' + this.param.userid + '&rt=0.9&jobid=' + this.param.jobid + '&duration=' + this.param.duration + '&dtype=Video&objectId=' + this.param.objectId + '&clazzId=' + this.param.clazzId + '&view=pc&playingTime=' + playTime + '&isdrag=4&enc=' + enc, function (data: string) { let isPassed = JSON.parse(data); callback(isPassed.isPassed); }); } } } export class CxVideoControlBar extends CxTaskControlBar { public defaultBtn() { super.defaultBtn(); let pass = CssBtn(createBtn("秒过视频", "秒过视频会被后台检测到", "cx-btn")); let downloadSubtitle = CssBtn(createBtn("下载字幕", "我要下载字幕一同食用")); pass.style.background = "#F57C00"; downloadSubtitle.style.background = "#638EE1"; this.prev.append(pass, this.download(), downloadSubtitle); pass.onclick = () => { if (!protocolPrompt("秒过视频会产生不良记录,是否继续?", "boom_no_prompt")) { return; } (