function Playervideo() {
    this.esayloaderWorker = null;
    this.logger = new Logger("Playervideo");
    this.connection = this.connection.bind(this);
    this.intervaleasy;
    this.parampos;
    this.parampos1;
    this.parampos2;
    this.videoType;
    this.opentype = false; //区分当前是否是开流操作
    this.paramsdata; //参数对象
    this.osdWhois;
    this.uniqueId;
    this.assistCommand;
    this.createobj = {};
    this.initDownloaderWorker();
}

/**
 * websoket线程
 */

Playervideo.prototype.initDownloaderWorker = function () {
    var self = this;
    this.esayloaderWorker = new Worker("js/EasyVideo/downloadereasy.js");
    this.esayloaderWorker.onmessage = function (evt) { //监听downloadereasy发过来的消息
        var objData = evt.data;
        switch (objData.t) {
            case kcreateDevRsp:
                self.onmessageWS(objData.i); //创建设备createDev Websocket响应的数据
                break;
            case kcrdevliveRsp:
                self.onmessageWS1(objData.i); //初始化实时流live Websocket响应的数据
                break;
            case kcrdevrecordRsp:
                self.onmessageWS3(objData.i); //开始录像或者停止录像 Websocket响应的数据
                break;
            case kcrdevsnapshotRsp:
                self.onmessageWS4(objData.i); //抓图
                break;
            case kdevSetcloseRsp:
                self.onmessageWS7(objData.i); //关闭实时流
                break;
            case kserverPushRsp:
                self.onmessageWS10(objData.i); //初始化实时流live Websocket响应的数据
                break;
            case kdevreconstructionRsp:
                self.onmessageWS11(objData.i); //reconcreatedev---createDev 切换模块创建实时流 Websocket响应的数据
                break;
            case kdevreconsglobalCtrlRsp:
                self.onmessageWS12(objData.i);
                break;
        }
    };
};


//没唤起之前一直尝试连接
Playervideo.prototype.connection = function () {
    this.createdev();
};

/**
 * 创建设备
 */
Playervideo.prototype.createdev = function () {
    var arr = [];
    for (var i = 0; i < config.deviceInfo.VideoInputChannels; i++) {
        arr.push(2);
    }
    if (this.esayloaderWorker) {
        var obj = {};
        obj.Fountion = "createDev";
        obj.Auth = {};
        obj.Auth.usr = config.user;
        obj.Auth.address = location.hostname;
        obj.Auth.pwd = config.password;
        obj.Device = {};
        obj.Device.MAC = config.MacAddress;
        obj.Device.resShowBitrate = $.i18n.prop("i18n-showbitrate");
        obj.Device.resMainStream = $.i18n.prop("i18n-miancodestream");
        obj.Device.resSubStream = $.i18n.prop("i18n-codestream1");
        obj.Device.resThirdStream = $.i18n.prop("i18n-codestream2");
        if (window.deviceType == "IPC") {
            obj.Device.totalChannel = 1;
            obj.Device.stream = [parseInt(config.deviceCap[0].StreamCount, 10)];
        } else {
            //obj.Device.totalChannel = 36;
            obj.Device.totalChannel = config.deviceInfo.VideoInputChannels - 0;
            obj.Device.stream = arr;
        }
        obj.Device.mediaPort = parseInt(config.Network.mediaPort, 10);
        obj.Device.cmdPort = parseInt(config.Network.commandPort, 10);
        this.esayloaderWorker.postMessage({ //主线程像web work发送消息
            t: kcreateDevReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};

/**
 *
 * 切换模块重复创建
 */
Playervideo.prototype.reconcreatedev = function (param, param1, param2, param3, Dzwl, paramdata, opentype) {
    this.paramsdata = paramdata;
    this.videoType = Dzwl;
    this.createobj = param;
    this.parampos = param1;
    this.parampos1 = param2;
    this.parampos2 = param3;
    if (opentype) {
        this.opentype = opentype;
    }
    var arr = [];
    for (var i = 0; i < config.deviceInfo.VideoInputChannels; i++) {
        arr.push(2);
    }
    if (this.esayloaderWorker) {
        var obj = {};
        obj.Fountion = "createDev";
        obj.Auth = {};
        obj.Auth.usr = config.user;
        obj.Auth.address = config.easyvideodaaress;
        obj.Auth.pwd = config.password;
        obj.Device = {};
        obj.Device.MAC = config.MacAddress;
        obj.Device.resShowBitrate = $.i18n.prop("i18n-showbitrate");
        obj.Device.resMainStream = $.i18n.prop("i18n-miancodestream");
        obj.Device.resSubStream = $.i18n.prop("i18n-codestream1");
        obj.Device.resThirdStream = $.i18n.prop("i18n-codestream2");
        if (config.deviceInfo.DeviceName == "IPC" && config.isSupportMultiChannel != true) { //需要判断是否多目设备
            obj.Device.totalChannel = 1;
            obj.Device.stream = [parseInt(config.deviceCap[0].StreamCount, 10)];
            obj.Device.multilens = false;
        } else {
            obj.Device.totalChannel = config.deviceInfo.VideoInputChannels - 0;
            obj.Device.stream = arr;
            obj.Device.multilens = true;
        }
        obj.Device.mediaPort = parseInt(config.Network.mediaPort, 10);
        obj.Device.cmdPort = parseInt(config.Network.commandPort, 10);
        this.esayloaderWorker.postMessage({
            t: kdevreconstructionReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};


/**
 * 实时流预览
 * @param obj
 */

Playervideo.prototype.live = function (obj, dzwl, paramdata, opentype, osdWho) {
    // if (dzwl) {
    if (opentype) {
        this.opentype = opentype;
    } else {
        this.opentype = false;
    }
    this.videoType = dzwl;
    // }
    if (osdWho) {
        this.osdWhois = osdWho;
    }
    if (paramdata) {
        this.paramsdata = paramdata;
    }
    if (this.esayloaderWorker) {
        this.esayloaderWorker.postMessage({
            t: kcrdevliveReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};

/**
 * 抓图
 * @param obj
 */

Playervideo.prototype.snapshot = function (obj) {
    if (this.esayloaderWorker) {
        this.esayloaderWorker.postMessage({
            t: kcrdevsnapshotReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};

Playervideo.prototype.global = function (obj, uniqueId, assistCommand) {
    if(obj.global.type===3||obj.global.type===1||obj.global.type===4){
        this.uniqueId = uniqueId;
        this.assistCommand = assistCommand;
    }
    if (this.esayloaderWorker) {
        this.esayloaderWorker.postMessage({
            t: kdevreconsglobalCtrlReq,
            url: config.url,
            msg: obj,
            type: ""
        });
           if(obj.global.type===6){
               clearInterval(config.waveInfoTime);
               return
           }
            // 清除之前可能存在的定时器
           clearInterval(config.waveInfoTime);
           config.waveInfoTime = setInterval(function () {
               getwaveInfo();
           }, 1000*10);
    }
};


/**
 * 录像 (开始录像与停止录像)
 * @param obj
 */
Playervideo.prototype.record = function (obj) {
    if (this.esayloaderWorker) {
        this.esayloaderWorker.postMessage({
            t: kcrdevrecordReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};
/**
 * 销毁设备
 */
Playervideo.prototype.destroy = function () {
    if (this.esayloaderWorker) {
        var obj = {};
        obj.Fountion = "destroy";
        obj.DestroyObject = {};
        obj.DestroyObject.Device = {};
        obj.DestroyObject.type = 1; //销毁的设备参数。仅当type 的值为 1 时此值有效
        obj.DestroyObject.Device.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
        this.esayloaderWorker.postMessage({
            t: kdevCloseReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};

/**
 *实时流切换菜单隐藏所有窗口 切换播放模式时候 关闭预览的流
 */
Playervideo.prototype.close = function (param) {
    if (this.esayloaderWorker) {
        var obj = {};
        obj.Fountion = "live";
        obj.LiveCtrl = {};
        obj.LiveCtrl.Preview = {};
        obj.LiveCtrl.type = 1;
        obj.LiveCtrl.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
        obj.LiveCtrl.channel = 0;
        obj.LiveCtrl.Preview.open = false; //关闭实时流

        this.esayloaderWorker.postMessage({
            t: kdevSetcloseReq,
            url: config.url,
            msg: obj,
            type: ""
        });
    }
};


//设备是否创建成功的响应

Playervideo.prototype.onmessageWS = function (data) {
    //未登录到预览界面全使用window.deviceType获取设备类型
    if (data.code == 200) {
        clearInterval(this.intervaleasy);
        sessionStorage.setItem("connectionfail", "2");
        // config.cgiTimeout=data.data.cgiTimeout;暂时注释掉，，等插件支持
        if (data.data.uniqueId) { //创建设备成功
            sessionStorage.setItem("isWakeupeasyvideo", "true");
            sessionStorage.setItem("uniqueId", data.data.uniqueId);
            var dpiRadio = data.data.dpiRadio / 100;
            sessionStorage.setItem("dpiRadio", dpiRadio);
            if (window.location.pathname == "/index.html") {
                $("#WebPlayer").removeClass("active");
                $("#EasyVideo").click().addClass("active");
                $("#selfadaptation").click();
                $("#playstyle span").text(document.getElementById("EasyVideo").innerText);
                $("#playstyledropdown").toggle();
                $("#playstyledropright").toggle();
                $("#codestreamcustomize").show();
                $("#playcz").show();
                $("#playCanvas").hide();
                $("#axdiv").show();
                if (sessionStorage.getItem("playstyle") == "WebPlayer") { //上一次的播放方案是WebPlayer
                    if (sessionStorage.getItem("stream") == "miancodestream") {
                        self.player.stop("main");
                    } else if (sessionStorage.getItem("stream") == "codestream1") {
                        self.player.stop("sub1");
                    } else {
                        self.player.stop("sub2");
                    }
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    $("#axdiv").empty();
                    clearInterval(config.gs_interval);
                }
                if (sessionStorage.getItem("isWakeupeasyvideo") == "true") {
                    sessionStorage.setItem("playstyle", "EasyVideo");
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "cerate", false);
                }
            }
            if (window.location.pathname == "/") {
                window.location.href = "index.html";
            }
        } else {
            sessionStorage.setItem("isWakeupeasyvideo", "false");
            if (sessionStorage.getItem("connectionfail") != "1") {
                window.location.href = "index.html";
            }
        }
    } else if (data.code == 9999) {
        sessionStorage.setItem("isWakeupeasyvideo", "false");
        if (window.deviceType == "IPC") {
            if (window.location.pathname == "/") {
                window.location.href = "index.html";
            }
            if (sessionStorage.getItem("connectionfail") != "1" && window.location.pathname != "/") {
                var eleLink = document.createElement("a");
                eleLink.style.display = "none";
                eleLink.href = "xrsapp://127.0.0.1";
                document.body.appendChild(eleLink);
                eleLink.click();
                sessionStorage.setItem("connectionfail", "1");
            }
        } else {
            if (window.location.pathname == "/" || window.location.pathname == "login.html") {
                $("#myModal").modal("show");
                sessionStorage.setItem("connectionfail", "2");
            }
            if (sessionStorage.getItem("connectionfail") != "1") { //唤起;
                var eleLink = document.createElement("a");
                eleLink.style.display = "none";
                eleLink.href = "xrsapp://127.0.0.1";
                document.body.appendChild(eleLink);
                eleLink.click();
                sessionStorage.setItem("connectionfail", "1"); //简单成功
            }
        }


    } else if (data.code == 1018) { //资源已满
        bootoast({
            message: $.i18n.prop("i18n-resources"),
            type: "danger",
            position: "bottom-center",
            timeout: true,
            animationDuration: 3000,
            dismissable: true
        });
    } else { //创建设备失败
        sessionStorage.setItem("isWakeupeasyvideo", "false");
        clearInterval(this.intervaleasy);
        sessionStorage.setItem("connectionfail", "2");
        if (window.location.pathname == "/") {
            if (window.deviceType == "IPC") {
                window.location.href = "index.html";
            } else {
                $("#myModal").modal("show");
            }
        }
    }

};

//实时流控制句柄保存，，历史流控制句柄保存，，事件进度处理等

Playervideo.prototype.onmessageWS1 = function (data) {
    if (data.code == 200) {
        if (this.opentype) { //表示这个是开流的返回结果
            if (window.location.hash == "#nvr/pages/image/osd.html" && config.devicelose != true) {
                CHOSDGetSel(config.chnelNum + 1);
            }
            if (window.location.hash == "#ipc/pages/image/osd.html") {
                console.log("开流成功了调用获取配置,osd");
                getOSD();
            } else if (window.location.hash == "#ipc/pages/image/privacySettings.html") {
                console.log("开流成功了调用获取配置,隐私遮盖");
                getPrivacyZone();
            } else if (window.location.hash == "#ipc/pages/events/motionDetection.html") {
                console.log("开流成功了调用获取配置,移动侦测");
                getRegionCfg();
            } else if (window.location.hash == "#ipc/pages/events/humanFormDetection.html") {
                console.log("开流成功了调用获取配置,人形侦测");
                getpeopleRegionCfg();
            } else if (window.location.hash == "#ipc/pages/events/Facerecognition.html") {
                console.log("开流成功了调用获取配置,人脸抓拍");
                getfacetime(this.paramsdata.a, this.paramsdata.b);
            } else if (window.location.hash == "#ipc/pages/events/fireDetect.html") {
                console.log("开流成功了调用获取配置,火焰检测");
                getFireconfig(this.paramsdata.a, this.paramsdata.b);
            } else if (window.location.hash == "#ipc/pages/events/electricScooter.html") {
                getEBikeconfig(this.paramsdata.a, this.paramsdata.b);
            } else if (window.location.hash == "#ipc/pages/events/gasTankDetection.html") {
                getGasconfig(this.paramsdata.a, this.paramsdata.b);
            } else if (window.location.hash == "#ipc/pages/events/licenseplate.html") {
                if (config.checkWEB == 1) {
                    console.log("开流成功了调用获取配置,车牌抓拍");
                    getaCarinfomation(this.paramsdata.a, this.paramsdata.b);
                } else if (config.checkWEB == 3) {
                    console.log("开流成功了调用获取配置,车位设置");
                    getParkSpaceConfig();
                }
            } else if (window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") != -1) {
                if (this.videoType == 1) { //电子围栏
                    getElectronicfenceConfig(this.paramsdata);
                } else if (this.videoType == 6) { //越界侦测
                    if (config.isTraffic) {
                        getpassengerTra(this.paramsdata.a, this.paramsdata.b);
                    } else {
                        getcrossdetect(this.paramsdata);
                    }
                } else if (this.videoType == 7) { //离岗侦测
                    getoffDutyDetec(this.paramsdata);
                } else if (this.videoType == 8) { //客流统计
                    getpassengerFlow(this.paramsdata.a, this.paramsdata.b);
                }
            }
        }
        if (window.location.hash == "#remoteplayback.html") {
            if (m_bIsPlaying && config.timebarSave == null) {
                config.timebarSave = setInterval(function () {
                    if (sessionStorage.getItem("playstyle") == "ActiveX") {
                        PlaybackGetPos(numberOfScreens);
                    } else {
                        serchVideoCounts(numberOfScreens);
                        config.SaveCavans.MovePosinVideo(new Date(data.data.nowPos).getTime(), config.RemoteplayPosin);
                    }
                }, 1000);
            }
            if (!m_bIsPlaying && config.timebarSave) config.timebarSave = null;
        }


        if (config.liveStatus == true && config.deviceInfo.DeviceName != "IPC") {
            preWindowfollowing(false);
            config.liveStatus = false;
        }
        if (config.liveStatus == true && config.deviceInfo.DeviceName != "IPC") {
            preWindowfollowing(false);
            config.liveStatus = false;
        }
        //nvrSplitScreen();
        if (config.devicelose) {
            if (window.location.hash == "#preview.html") {
                preWindowfollowing(false);
            }
            if (this.videoType == 2) {
                // osd设置
                if (config.deviceInfo.DeviceName == "IPC") {
                    getOSD();
                } else {
                    CHOSDGetSel(config.chnelNum + 1);
                }
            } else if (this.videoType == 3) {
                // 图像配置不做任何操作
            } else if (this.videoType == 4) {
                // 隐私遮盖
                getPrivacyZone();
            } else if (this.videoType == 5) {
                // 移动侦测
                getRegionCfg();
            } else if (this.videoType == 1) {
                // 电子围栏
                getElectronicfenceConfig(this.paramsdata);
            } else if (this.videoType == 6) {
                if (config.isTraffic) {
                    getpassengerTra(this.paramsdata.a, this.paramsdata.b);
                } else {
                    // 越界侦测
                    getcrossdetect(this.paramsdata);
                }
            } else if (this.videoType == 7) {
                // 离岗侦测
                getoffDutyDetec(this.paramsdata);
            } else if (this.videoType == 8) {
                // 客流统计
                getpassengerFlow(this.paramsdata.a, this.paramsdata.b);
            } else if (this.videoType == 9) {
                // 人脸抓拍
                getfacetime(this.paramsdata.a, this.paramsdata.b);
            } else if (this.videoType == 10) {
                getFacestime(this.paramsdata.a, this.paramsdata.b);
            } else if (this.videoType == 11) {
                // 车牌抓拍
                getaCarinfomation(this.paramsdata.a, this.paramsdata.b);
                // miaoyue车位设置
                getParkSpaceConfig();
            } else if (this.videoType == 12) {
                //人形检测
                getpeopleRegionCfg();
            } else if (this.videoType == 13) {
                //火焰检测
                getFireconfig(this.paramsdata.a, this.paramsdata.b);
            }
        }
        localStorage.setItem("reawaken", "0000");
        if (data.data.taskId) { //下载
            var self = this;
            localStorage.setItem("taskId", data.data.taskId);
            config.doloadInterval = setInterval(function () {
                self.querypercentfun(data.data.taskId);
            }, 1000);
        } else if (data.data.percent) { //下载进度
            if (parseInt(data.data.percent / 100) == 100) { //达到100停止进度查询
                config.isdown = 3;
                clearInterval(config.doloadInterval);
                $("#nowdoloadBtn").text($.i18n.prop("i18n-Downloadsuccess"));
                $("#nowdoloadBtn").prop("disabled", false);
            } else { //未达到100进行进度渲染
                $("#nowdoloadBtn").text($.i18n.prop("i18n-Downloading") + data.data.percent / 100 + "%");
            }
        } else if (data.data.settings) {
            if (data.data.settings.electricFence) {
                getEletricValue(data.data.settings); //电子围栏
            } else if (data.data.settings.crossBorder) {
                if (config.isTraffic) {
                    gettratricValue(data.data.settings); // 车流统计
                } else if (config.deviceAiCap[0].PassengerFlowsupportV2 == "true" && config.isSupportV2 === false) {
                    getflowtricValue(data.data.settings); //客流统计
                } else {
                    getdeatricValue(data.data.settings); //越界侦测
                }
            } else if (data.data.settings.offDuty) {
                getofftricValue(data.data.settings); //离岗侦测
            } else if (data.data.settings.passenger) {
                getflowtricValue(data.data.settings); //客流统计
            } else if (data.data.settings.faceSnapshot) {
                if (window.location.hash == "#ipc/pages/events/licenseplate.html") {
                    if (config.IsSuportScend == "true") {
                        config.IsSuportScendArr.push(data.data.settings);
                        if (config.IsSuportScendArr.length == 2) {
                            setEasyCartronic(config.IsSuportScendArr);
                            config.IsSuportScendArr = [];
                        } else {
                            PolygonConfigBlack(8, config.isSuportScendNum, 1);
                        }
                    } else {
                        if (config.checkWEB == 1) {
                            setEasyCartronic(data.data.settings); //车牌抓拍
                        } else if (config.checkWEB == 3) {
                            setEasyParkSpaceConfig(data.data.settings); // miaoyue车位设置
                        }
                    }
                } else if (window.location.hash == "#ipc/pages/events/fireDetect.html") {
                    getfiretricValue(data.data.settings); //火焰检测
                } else if (window.location.hash == "#ipc/pages/events/electricScooter.html") {
                    getelectricValue(data.data.settings); //电动车
                } else if (window.location.hash == "#ipc/pages/events/gasTankDetection.html") {
                    getGasValue(data.data.settings); //电动车
                } else {
                    getfacetricValue(data.data.settings); //人脸抓拍
                }
            } else if (data.data.settings.motion) {
                if (window.location.hash == "#ipc/pages/events/humanFormDetection.html") {
                    getRegionlistout(data.data.settings); //人形检测
                } else {
                    getmottricValue(data.data.settings); //移动侦测
                }
            } else if (data.data.settings.OSD) {
                if (window.location.hash == "#preview.html"){ //预览页面
                    if (data.data.settings.OSD.base64 != undefined) {
                        if (this.osdWhois == 1) {
                            keepditowpre(data.data.settings); //获取点阵信息2
                            this.osdWhois = null;
                        } else {
                            keepditpre(data.data.settings); //获取点阵信息
                        }
                    }
                    // else {
                    //     getOSDtricValuepre(data.data.settings); //osd
                    // }
                }else{
                    if (data.data.settings.OSD.base64 != undefined) {
                        if (this.osdWhois == 1) {
                            keepditow(data.data.settings); //获取点阵信息2
                            this.osdWhois = null;
                        } else {
                            keepdit(data.data.settings); //获取点阵信息
                        }
                    } else {
                        getOSDtricValue(data.data.settings); //osd
                    }
                }
            } else {
                getprivacyValue(data.data.settings); //获取隐私配置
            }
        }
        config.devicelose = false;
    } else if (data.code == 1016) { //找不到设备
        config.devicelose = true;
        localStorage.setItem("reawaken", "0000");
    } else if (data.code == 9999) { //websocket出错或者连接被关闭手动返回9999
        config.devicelose = false;
        localStorage.setItem("reawaken", "9999");
        //sessionStorage.setItem('isWakeupeasyvideo',"false" );
        var ua = navigator.userAgent.toLocaleLowerCase();
        if (config.playMode.indexOf("WebPlayer") !== -1) {
            if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null || ua.match(/metasr/) != null || ua.match(/ubrowser/) != null) {
                $("#MJPEG").click();
            } else {
                // if(sessionStorage.getItem("playstyle") == "EasyVideo")return;
                var stream=null;
                if (sessionStorage.getItem('stream') !== null||sessionStorage.getItem('stream')!="null") {
                    stream=sessionStorage.getItem('stream');
                }
                closeWebPlayer();
                $("#WebPlayer").click();
               if(stream){ sessionStorage.setItem('stream', stream)}
            }
        } else if (config.playMode.indexOf("MJPEG") !== -1) {
            $("#MJPEG").click();
        } else {
            $("#downloadeasyplay").show();
            $("#downlodeasyvideo").show();
            $("#playcz").hide();
        }

    } else {
        config.devicelose = false;
        easyerrortranslation(data.code); //easyvideo返回码翻译
    }
};


Playervideo.prototype.onmessageWS7 = function (data) {
    if (data.code == 200) { //实时流关闭成功，立即隐藏
        if (this.esayloaderWorker) {
            var obj = {};
            obj.Fountion = "live";
            obj.LiveCtrl = {};
            obj.LiveCtrl.ShowDock = {};
            obj.LiveCtrl.type = 9;
            obj.LiveCtrl.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
            obj.LiveCtrl.channel = 0;
            obj.LiveCtrl.settings = false;
            obj.LiveCtrl.ShowDock.showMode = 4;
            this.live(obj);
        }

    } else if (data.code == 9999) {
        //sessionStorage.setItem('isWakeupeasyvideo',"false" );
        localStorage.setItem("reawaken", "9999");
        var ua = navigator.userAgent.toLocaleLowerCase();
        if (config.playMode.indexOf("WebPlayer") !== -1) {
            if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null || ua.match(/metasr/) != null || ua.match(/ubrowser/) != null) {
                $("#MJPEG").click();
            } else {
                console.log("3333");
                $("#WebPlayer").click();
            }
        } else if (config.playMode.indexOf("MJPEG") !== -1) {
            $("#MJPEG").click();
        } else {
            $("#downloadeasyplay").show();
            $("#downlodeasyvideo").show();
            $("#playcz").hide();
        }

    } else {
        easyerrortranslation(data.code);
    }
};

//事件推送
Playervideo.prototype.onmessageWS10 = function (data) {
    console.log(data);
    if (data.code == 200) {
        if (config.deviceInfo.DeviceName == "IPC") {
            if (data.data.PushDetail.StreamSwitch != undefined) {
                if (data.data.PushDetail.StreamSwitch.stream == 1) { //主码流
                    $("#miancodestream").click();
                } else if (data.data.PushDetail.StreamSwitch.stream == 2) { //第一码流
                    $("#codestream1").click();
                } else if (data.data.PushDetail.StreamSwitch.stream == 3) { //第二码流
                    $("#codestream2").click();
                }
            } else if (data.data.PushDetail.Bitrate != undefined) {
                if (data.data.PushDetail.Bitrate.enable) { //需要码率
                    var self = this;
                    if (data.data.PushDetail.Bitrate.stream == 1) {
                        config.Bitratetime = setInterval(function () {
                            self.Bitratetimefun(1);
                        }, 1000);
                    } else if (data.data.PushDetail.Bitrate.stream == 2) {
                        config.Bitratetime = setInterval(function () {
                            self.Bitratetimefun(2);
                        }, 1000);
                    } else if (data.data.PushDetail.Bitrate.stream == 3) {
                        config.Bitratetime = setInterval(function () {
                            self.Bitratetimefun(3);
                        }, 1000);
                    }
                } else { //不需要码流
                    clearInterval(config.Bitratetime);
                }
            } else if (data.data.PushDetail.HttpDownload != undefined) { //抓图和录像
                if (data.data.PushDetail.HttpDownload.type == 1) { //视频
                    bootoast({
                        message: $.i18n.prop("i18n-videosuccess"),
                        type: "success",
                        position: "bottom-center",
                        timeout: true,
                        animationDuration: 3000,
                        dismissable: true
                    });
                    if (navigator.userAgent.indexOf("Firefox") !== -1) {
                        window.open(data.data.PushDetail.HttpDownload.url, "new", "menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
                    } else {
                        location.href = data.data.PushDetail.HttpDownload.url;
                    }

                } else if (data.data.PushDetail.HttpDownload.type == 2) { //抓图
                    // 显示 toast 提示消息
                    bootoast({
                        message: $.i18n.prop("i18n-Capturepicturesuccess"),
                        type: "success",
                        position: "bottom-center",
                        timeout: true,
                        animationDuration: 3000,
                        dismissable: true
                    });
                    if (navigator.userAgent.indexOf("Firefox") !== -1) {
                        window.open(data.data.PushDetail.HttpDownload.url, "new", "menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
                    } else {
                        location.href = data.data.PushDetail.HttpDownload.url;
                    }

                }
            }else if(data.data.PushDetail){ //3D定位
                var d3= data.data.PushDetail._3dPos;
                var record={};
                if(d3.operator!==0){
                    var pos=d3.pos;
                    var left=pos[0].x;
                    var top=pos[0].y;
                    var right=pos[1].x;
                    var bottom=pos[1].y;
                    var centerX = (left +right) / 2;
                    var centerY = (top + bottom) / 2;
                     record = {
                        type: d3.operator,
                        topLeft: {
                            x:left ,
                            y: top
                        },
                        topRight: {
                            x: right,
                            y: top
                        },
                        bottomLeft: {
                            x: left,
                            y: bottom
                        },
                        bottomRight: {
                            x: right,
                            y: bottom
                        },
                        centerPoint: {
                            x: centerX,
                            y: centerY
                        }
                    }
                }else{
                    var center=d3.pos[0];
                    record = {
                        type: d3.operator,
                        topLeft: {
                            x: center.x,
                            y: center.y
                        },
                        topRight: {
                            x: center.x,
                            y: center.y
                        },
                        bottomLeft: {
                            x: center.x,
                            y: center.y
                        },
                        bottomRight: {
                            x: center.x,
                            y: center.y
                        },
                        centerPoint: {
                            x: center.x,
                            y: center.y
                        }
                    }
                }
                console.log(record);
                set3dPos(record);
            }
        } else if (config.deviceInfo.DeviceName == "NVR") {
            if (data.data.PushDetail != undefined) {
                config.thoroughfare = data.data.PushDetail.channel;
                if (window.location.hash == "#preview.html") {
                    // 处理声音状态
                    var picts = document.getElementById("soundopen");
                    if (config.nums_push_list.indexOf(config.thoroughfare) != -1) {
                        picts.setAttribute("src", "img/preview/soundopen.png");
                    } else {
                        picts.setAttribute("src", "img/preview/soundclose.png");
                    }
                    // 处理视频比例
                    if (config.bine_push_list.indexOf(config.thoroughfare) != -1) {
                        $("#pictureScale span").text(document.getElementById("originalScale").innerText);
                        document.getElementById("originalScale").classList.remove("active");
                    } else {
                        $("#pictureScale span").text(document.getElementById("selfadaptation").innerText);
                        document.getElementById("selfadaptation").classList.remove("active");
                    }
                    // 点击对应通道获取对应通道的通用参数,只有在打开右边栏的时候才点击就去获取避免频繁获取
                    if (document.getElementById("slideleftId").style.display == "none") {
                        $("#codestreamselect").select2("val", "1");
                        getPTZCfg();
                        getCapabilityV2();
                        getMainstream();
                        getOSD();
                        getTimeinfo();
                    }
                }
            }
            if (data.data.PushDetail.StreamSwitch != undefined) {
                config.thoroughfare = data.data.PushDetail.channel;
            } else if (data.data.PushDetail.HttpDownload != undefined) { //NVR的抓图和录像1视频 2图像
                if (data.data.PushDetail.HttpDownload.type == 1) { //视频
                    bootoast({
                        message: $.i18n.prop("i18n-videosuccess"),
                        type: "success",
                        position: "bottom-center",
                        timeout: true,
                        animationDuration: 3000,
                        dismissable: true
                    });
                    if (navigator.userAgent.indexOf("Firefox") !== -1) {
                        window.open(data.data.PushDetail.HttpDownload.url, "new", "menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
                    } else {
                        location.href = data.data.PushDetail.HttpDownload.url;
                    }
                } else if (data.data.PushDetail.HttpDownload.type == 2) { //抓图
                    bootoast({
                        message: $.i18n.prop("i18n-Capturepicturesuccess"),
                        type: "success",
                        position: "bottom-center",
                        timeout: true,
                        animationDuration: 3000,
                        dismissable: true
                    });
                    if (navigator.userAgent.indexOf("Firefox") !== -1) {
                        window.open(data.data.PushDetail.HttpDownload.url, "new", "menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
                    } else {
                        location.href = data.data.PushDetail.HttpDownload.url;
                    }
                }
            } else if (data.data.PushDetail.Bitrate != undefined) {
                if (data.data.PushDetail.Bitrate.enable) { //需要码率
                    var self = this;
                    if (!config.thoroughfareList.includes(data.data.PushDetail.channel)) {
                        config.thoroughfareList.push(data.data.PushDetail.channel);
                        var intervalId = setInterval(function () {
                            self.Bitratetimefun(data.data.PushDetail.Bitrate.stream, data.data.PushDetail.channel);
                        }, 1000);
                        config.BitratetimeList.push(intervalId);
                    }
                } else { //不需要码流
                    var channel = data.data.PushDetail.channel;
                    var index = config.thoroughfareList.indexOf(channel);
                    if (index !== -1) {
                        clearInterval(config.BitratetimeList[index]);
                        config.BitratetimeList.splice(index, 1);
                        config.thoroughfareList.splice(index, 1);
                    }
                }
            }
        }
    } else if (data.code == 9999) {
        //sessionStorage.setItem('isWakeupeasyvideo',"false" );
        localStorage.setItem("reawaken", "9999");
        var ua = navigator.userAgent.toLocaleLowerCase();
        if (config.playMode.indexOf("WebPlayer") !== -1) {
            if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null || ua.match(/metasr/) != null || ua.match(/ubrowser/) != null) {
                $("#MJPEG").click();
            } else {
                console.log("444");
                $("#WebPlayer").click();
            }
        } else if (config.playMode.indexOf("MJPEG") !== -1) {
            $("#MJPEG").click();
        } else {
            $("#downloadeasyplay").show();
            $("#downlodeasyvideo").show();
            $("#playcz").hide();
        }
    } else {
        easyerrortranslation(data.code);
    }
};


//码率定时器方法
Playervideo.prototype.Bitratetimefun = function (param, isNvrnums) {
    // getBitrate();
    config.bitrate = getBitrate(parseInt(isNvrnums) + 1);
    var obj = {};
    obj.Fountion = "live";
    obj.LiveCtrl = {};
    obj.LiveCtrl.Bitrate = {};
    obj.LiveCtrl.type = 8;
    obj.LiveCtrl.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
    if (isNvrnums) {
        obj.LiveCtrl.channel = isNvrnums;
    } else {
        obj.LiveCtrl.channel = 0;
    }
    if (param == 1) {
        obj.LiveCtrl.Bitrate.kbpsMain = parseInt(config.bitrate.MainBitrate, 10);
    } else if (param == 2) {
        obj.LiveCtrl.Bitrate.kbpsSub = parseInt(config.bitrate.FirstBitrate, 10);
    } else if (param == 3) {
        obj.LiveCtrl.Bitrate.kbpsThird = parseInt(config.bitrate.SecondBitrate, 10);
    }
    this.live(obj);
};


//下载进度定时器
Playervideo.prototype.querypercentfun = function (param) {
    var obj = {};
    obj.Fountion = "download";
    obj.DownloadParam = {};
    obj.DownloadParam.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
    obj.DownloadParam.path = 9;
    obj.DownloadParam.operate = 2;
    obj.DownloadParam.Query = {};
    obj.DownloadParam.Query.taskId = param;
    this.live(obj);
};


//录像保存地址提示

Playervideo.prototype.onmessageWS3 = function (data) {
    if (data.code == 200) {

    } else if (data.code == 9999) {
        //sessionStorage.setItem('isWakeupeasyvideo',"false" );
        localStorage.setItem("reawaken", "9999");
        var ua = navigator.userAgent.toLocaleLowerCase();
        if (config.playMode.indexOf("WebPlayer") !== -1) {
            if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null || ua.match(/metasr/) != null || ua.match(/ubrowser/) != null) {
                $("#MJPEG").click();
            } else {
                console.log("555");
                $("#WebPlayer").click();
            }
        } else if (config.playMode.indexOf("MJPEG") !== -1) {
            $("#MJPEG").click();
        } else {
            if (config.deviceInfo.DeviceName == "IPC") {
                $("#downloadeasyplay").show();
                $("#downlodeasyvideo").show();
                $("#playcz").hide();
            } else {
                //NVR不能去切，必须清除再开，而且对于火狐浏览器有特殊情况，此为备用方案，暂时保留代码
                if (navigator.userAgent.indexOf("Firefox") !== -1) {
                    // huifuPreview();
                }
            }
        }
    } else {
        easyerrortranslation(data.code);
    }
};


//截图保存地址提示

Playervideo.prototype.onmessageWS4 = function (data) {
    if (data.code == 200) {

    } else if (data.code == 9999) {
        //sessionStorage.setItem('isWakeupeasyvideo',"false" );
        localStorage.setItem("reawaken", "9999");
        var ua = navigator.userAgent.toLocaleLowerCase();
        if (config.playMode.indexOf("WebPlayer") !== -1) {
            if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null || ua.match(/metasr/) != null || ua.match(/ubrowser/) != null) {
                $("#MJPEG").click();
            } else {
                console.log("1111");
                $("#WebPlayer").click();
            }
        } else if (config.playMode.indexOf("MJPEG") !== -1) {
            $("#MJPEG").click();
        } else {
            if (config.deviceInfo.DeviceName == "IPC") {
                $("#downloadeasyplay").show();
                $("#downlodeasyvideo").show();
                $("#playcz").hide();
            } else {
                //NVR不能去切，必须清除再开，而且对于火狐浏览器有特殊情况,此为备用方案，暂时保留代码
                if (navigator.userAgent.indexOf("Firefox") !== -1) {
                    if (window.location.hash == "#remoteplayback.html") {
                        // refsh(); //回放抓图之后处理
                    } else {
                        // huifuPreview(); //预览抓图之后处理
                    }
                }
            }
        }
    } else {
        easyerrortranslation(data.code);
    }
};


//设备是否创建成功的响应

Playervideo.prototype.onmessageWS11 = function (data) {
    if (data.code == 200) {
        if (data.data.uniqueId) { //创建设备成功
            sessionStorage.setItem("uniqueId", data.data.uniqueId);
            var dpiRadio = data.data.dpiRadio / 100;
            sessionStorage.setItem("dpiRadio", dpiRadio);
            if (this.createobj.LiveCtrl) {
                this.createobj.LiveCtrl.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
            } else if (this.createobj.PlaybackCtrl) {
                this.createobj.PlaybackCtrl.uniqueId = parseInt(sessionStorage.getItem("uniqueId"), 10);
            }
            if (this.videoType == 2) {
                this.live(this.createobj, this.videoType);
            } else {
                this.live(this.createobj, this.videoType, "", this.opentype);
            }
            if (this.parampos == "osd" || this.videoType == 2) {
                if (config.deviceInfo.DeviceName == "IPC") {
                    getOSD();
                } else {
                    CHOSDGetSel(1);
                }
            } else if (this.parampos == "faceCap") { //人脸抓拍
                console.log("wobeichufal");
                getfacetime(this.parampos1, this.parampos2);
            } else if (this.parampos == "privay") { //隐私遮盖
                getPrivacyZone();
            } else if (this.parampos == "faceShot") { //人脸检测
                getFacestime(this.parampos1, this.parampos2);
            } else if (this.parampos == "motion") { //移动侦测
                getRegionCfg();
            } else if (this.parampos == "carCap") { //车牌抓拍
                getaCarinfomation(this.parampos1, this.parampos2);
            } else if (this.parampos == "human") { //人形检测
                getpeopleRegionCfg();
            } else if (this.parampos == "fire") { //火焰检测
                getFireconfig(this.parampos1, this.parampos2);
            } else if (this.parampos == "electricCar") { //电动车
                getEBikeconfig(this.parampos1, this.parampos2);
            } else if (this.parampos == "gasTankDetect") { //电动车
                getGasconfig(this.parampos1, this.parampos2);
            } else {
                if (this.parampos != "") {
                    gotimepos(this.parampos);
                }
            }
        } else {
            bootoast({
                message: $.i18n.prop("i18n-createeasyfail"),
                type: "danger",
                position: "bottom-center",
                timeout: true,
                animationDuration: 3000,
                dismissable: true
            });
        }
    } else if (data.code == 10000) { //我连接出错了
        $("#axdiv").hide();
        $("#downlodeasyvideo").hide();
    } else {
        easyerrortranslation(data.code);
    }

};

function textPlay(base64Data) {
    // 解码 Base64 数据
    var binaryData = atob(base64Data);
    // 创建 Uint8Array 存储二进制数据
    var arrayBuffer = new ArrayBuffer(binaryData.length);
    var uint8Array = new Uint8Array(arrayBuffer);
    for (var i = 0; i < binaryData.length; i++) {
        uint8Array[i] = binaryData.charCodeAt(i);
    }
    // 创建 Blob 对象
    var blob = new Blob([arrayBuffer], {type: "audio/mpeg"});
    // 生成对象 URL
    var audioPath = URL.createObjectURL(blob);
    console.log(audioPath);
    // 创建隐藏的 audio 元素
    var audio = document.createElement("audio");
    audio.style.display = "none";
    audio.src = audioPath;
    audio.autoplay = true;
    audio.onended = function () {
        // 音频播放结束后移除 audio 元素
        document.body.removeChild(audio);
        // $.MaskUtil.unmask();
        $.optionBootoast($.i18n.prop("i18n-voice-stend"), "success");
    };
    document.body.appendChild(audio);
}

function textUpload(base64Data, assistCommand) {
    // 解码 Base64 数据
    var binaryData = atob(base64Data);
    // 创建 Uint8Array 存储二进制数据
    var arrayBuffer = new ArrayBuffer(binaryData.length);
    var uint8Array = new Uint8Array(arrayBuffer);
    for (var i = 0; i < binaryData.length; i++) {
        uint8Array[i] = binaryData.charCodeAt(i);
    }
    // 获取二进制文件的大小（字节）
    var fileSizeInBytes = arrayBuffer.byteLength;

    if (fileSizeInBytes > config.maxTotal) {
        $.MaskUtil.unmask();
        return $.optionBootoast($.i18n.prop("i18n-voice-textMax"), "danger");
    }
    var url;
    if (sessionStorage.getItem("xystyle") == "p2p") {
        url = config.baseUrl + "/mixinPut?url=" + "/System/DeviceCustomFunction" + "&id=" + config.p2pId;
    } else {
        url = config.baseUrl + "/System/DeviceCustomFunction";
    }
    var xhr = new XMLHttpRequest();

    xhr.open("PUT", url, true);
    xhr.setRequestHeader("Content-Type", "text/plain; charset=iso-8859-1");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status >= 200) {
                if (sessionStorage.getItem("xystyle") == "p2p") {
                    if (xhr && xhr.responseText) {
                        var responseData = JSON.parse(xhr.responseText);
                        if (responseData[0].error == 0) {
                            var xmlDoc = xmlStr2XmlObj(Base64.decode(responseData[0].attach.response));
                            var statusCode = $(xmlDoc).find("statusCode").text();
                            if (0 == statusCode) {
                                $.optionBootoast($.i18n.prop("i18n-upload-success"), "success");
                            } else {
                                $.optionBootoast($.i18n.prop("i18n-upload-fail"), "danger");
                            }
                        } else {
                            $.optionBootoast($.i18n.prop("i18n-upload-fail"), "danger");
                        }
                    } else {
                        $.optionBootoast($.i18n.prop("i18n-upload-fail"), "danger");
                    }
                } else {
                    var xmlDoc = new DOMParser().parseFromString(xhr.responseText, "text/xml");
                    var statusCode = $(xmlDoc).find("statusCode").text();
                    if (statusCode == 0) {
                        $.optionBootoast($.i18n.prop("i18n-upload-success"), "success");
                    } else {
                        $.optionBootoast($.i18n.prop("i18n-upload-fail"), "danger");
                    }
                }
            } else {
                $.optionBootoast($.i18n.prop("i18n-upload-fail"), "danger");
            }
            $.MaskUtil.unmask();
            $("#" + this.uniqueId + "saveUploadVideo").attr("disabled", false);
        }
    };
    // 构建自定义协议头部
    var header = "Main-Command:\"1\"\r\n" +
        "Assist-Command:\"" + assistCommand + "\"\r\n" +
        "Payload-Length:\"" + fileSizeInBytes + "\"\r\n" +
        "Content:\r\n\r\n";
    //
    // var encoder = new TextEncoder("iso-8859-1"); // 避免 UTF-8 编码干扰
    // var headerBytes = encoder.encode(header);
    var headerBytes = encodeToISO88591(header);

    // 拼接 header + 文件，生成完整请求体
    var blob = new Blob([headerBytes, arrayBuffer], {type: "application/octet-stream"});

    xhr.send(blob);

}


Playervideo.prototype.onmessageWS12 = function (data) {
    console.log("----------");
    console.log("data.data.audio");
    if (data.data && data.data.audio) {
        destoryWaveInfo();
    }
    if (data.code == 200) {
        if (data.data && data.data.audio) {
            if (config.voiceFileResultType === 2) {
                $("#" + this.uniqueId + "listenVideo").attr("disabled", false);
                $.MaskUtil.unmask();
                textPlay(data.data.audio);   //试听播放
            } else if (config.voiceFileResultType === 1) { //上传
                $("#" + this.uniqueId + "UploadVideo").attr("disabled", false);
                textUpload(data.data.audio, this.assistCommand); //上传
            } else if (config.voiceFileResultType === 3) {
                $("#" + this.uniqueId + "UploadVideo").attr("disabled", false);
                textUpload(data.data.audio, this.assistCommand); //上传
            }
        }
    } else {
        $("#" + this.uniqueId + "UploadVideo").attr("disabled", false);
        $("#" + this.uniqueId + "listenVideo").attr("disabled", false);
        $.MaskUtil.unmask();
        easyerrortranslation(data.code);
    }
};

