var accTok = JSON.parse(localStorage.getItem("_yz_TT")).ysyTok;
var _playSn = null;
var _Player = null;
var timeId = null;
var deList = [],shipSn = null;
var allData = [],snData = [];
window.addEventListener('message',(data)=>{
$(".topBox .iconfont").removeClass("icon-zhankai").addClass("icon-zhedie");
closeVid();
_playSn = null;
InitAjax();
})
$(document).ready(function(){
deList = JSON.parse(localStorage.getItem("deList"));
InitAjax();
timeId = setInterval("InitAjax()",60*1000);
});
var nvrStatus = {};
function InitAjax(){
shipSn = localStorage.getItem("shipSn");
let _lis = deList[shipSn];
if(_lis != "" && _lis != undefined && _lis != null){
infoAjax(_lis.split(","),function sdff(res){
nvrStatus = res;
SBAjax(_lis.split(","),function asd(_data){
allData = _data;
setBody();
},0)
},0)
}else{
allData = [];
setBody();
}
}
function setBody(){
let _str = "",newLi = [];
let _lis = deList[shipSn];
if(allData.length){
let _Li = allData;
for(var i=0;i<_Li.length;i++){
if(_lis.indexOf(_Li[i].deviceSerial) != -1&&_Li[i].channelName.indexOf("@") == -1){
_str += `
${_Li[i].channelName.split("_")[0]}`;
newLi.push(_Li[i]);
if(_playSn != null){
if((_playSn.deviceSerial == _Li[i].deviceSerial)&&(_playSn.channelNo == _Li[i].channelNo)){
_playSn = _Li[i];
}
}
}
}
snData = newLi;
if(newLi.length){
if(_playSn == null){
_playSn = newLi[0];
$(".curTxt").text(_playSn.channelName);
}
}else{
_str=`暂无设备列表`;
_playSn = null;
$(".curTxt").text("无设备");
}
}else{
_str=`暂无设备列表`;
_playSn = null;
$(".curTxt").text("无设备");
}
$("#SBli").html(_str);
if(newLi.length){
$(`#SBli li[data-id='${_playSn.deviceSerial+"_"+_playSn.channelNo}']`).addClass("act");
}else{
$("#SBli li").eq(0).addClass("act");
}
}
function playEzopen(){
if(_Player != null){
_Player.stop();
}
if(_playSn == null){
return;
}
if(_playSn.status == 0&&nvrStatus[_playSn.deviceSerial] != 1){
ShowLoading("该设备离线中!",1);
return;
}
let _wid = $("#videoBox").width();
let _hei = $("#videoBox").height();
let _str = ``
$("#videoBox").html(_str);
let _src = "ezopen://open.ys7.com/"+_playSn.deviceSerial+"/"+_playSn.channelNo+".hd.live";
_Player = new EZUIKit.EZUIPlayer({
id: 'playWind_0',
autoplay: true,
url: _src,
accessToken: accTok,
width:_wid,
height:_hei,
audio:1,
decoderPath: staticUrl,
handleError: handleError,
handleSuccess: handleSuccess,
});
}
// 静音、不静音
$(document).on("click",".li_box .pauseVoice",function(){
if($(this).hasClass("icon-shengyin-kai")){
_Player.closeSound();
$(this).removeClass("icon-shengyin-kai").addClass("icon-shengyin-guan");
}else{
_Player.openSound();
$(this).removeClass("icon-shengyin-guan").addClass("icon-shengyin-kai");
}
})
$(document).on("click",".SBmask li",function(){
let _sn = $(this).data("id").split("_");
let _ind = snData.findIndex((item,ind) => { return (item.deviceSerial == _sn[0]&&item.channelNo == _sn[1]) })
if(_ind != -1){
_playSn = snData[_ind];
if(_playSn.status == 1&&nvrStatus[_playSn.deviceSerial] == 1){
playEzopen();
$(this).addClass("act").siblings().removeClass("act");
$(".curTxt").text($(this).text());
$(".SBmask").css("display","none");
}else{
ShowLoading("该设备离线中!",1);
}
}
})
function showMadel(_who){
$("."+_who).css("display","flex");
}
function hideMadel(_who){
$("."+_who).css("display","none");
}
function closeVid(){
if(_Player != null){
_Player.stop();
_Player = null;
$("#videoBox").html('');
}
}
$(document).on("click","#videoBox .noBg",function(){
playEzopen();
})
$(".tabli").on("click","",function(){
top.location.href='./AlertPh.html?key='+$(this).data("key");
})
$(".topBox").on("click",".iconfont",function(){
if($(".topBox .iconfont").hasClass("icon-zhankai")){
window.parent.changeShow("-150px");
$(".topBox .iconfont").removeClass("icon-zhankai").addClass("icon-zhedie");
}else{
window.parent.changeShow("0px");
$(".topBox .iconfont").removeClass("icon-zhedie").addClass("icon-zhankai");
}
})