function videoTaskPushlet(){
	videoTaskPushlet.isVoice = '';
	videoTaskPushlet.isPopup = '';
}
videoTaskPushlet.init = function(){
	videoTaskPushlet.initConfigInfo();
	videoTaskPushlet.initData();
}
videoTaskPushlet.initConfigInfo = function(){
	$.ajax({
		url : "ywalarmeventinfoAction!getVideoTaskAlarmConfig.do",
		dataType : "JSON",
		type : "POST",
		async : false,
		success : function(res){
			if(res){
				videoTaskPushlet.isVoice = res.isVoice;
				videoTaskPushlet.isPopup = res.isPopup;
			}
		}
	});
}
//pushlet加载
videoTaskPushlet.initData = function (){
	try {
		console.log("***安全帽检测事件pushlet初始化!***");
		PL._init();
		PL.join();
		PL.listen();
		PL.subscribe('/videoTaskAlarmData'); //安全帽检测事
		console.log("***安全帽检测事件pushlet开启!***");
	} catch(e) {
		$.showMsg('Pushlet监听【videoTaskPushlet】初始化失败! ');
		setTimeout("videoTaskPushlet.initData()",10000);
	}
}

videoTaskPushlet.leave = function () {
	try {
		PL.leave();
		console.log('pushlet关闭');
	} catch(e) {
		console.log("Pushlet关闭失败!");
	}
}

//接收数据
function onData(data) {
//	console.log('安全帽检测事件pushlet接收数据 = ',data);
	var event = data.get("p_subject");
	var sid = data.get("p_sid");
	var text = data.get("json");
	if(text==""||text==null||text==undefined){
		return;
	}
	if(event == "/videoTaskAlarmData") {
//		console.log('安全帽检测事件pushlet接收数据1111=== ',text);
		pushStatMsg(eval(text));
		return;
	}
}


//接收安全帽检测事件，并加载至页面告警台
var msgStr = ""
function pushStatMsg(data){
	console.log("----------------------------",data);
	if(data.length){   //如果返回数据大于0
		var li = "";
		
		$("#videoTask").show();
		data.forEach(function(item){
			var alarmGrade = item.alarmGrade==null?'':item.alarmGrade;
			if(alarmGrade<=videoTaskPushlet.isPopup){
				li +='<li >'
					+'<span class="videoTaskMsg">'+item.alarmDeviceName+' 发生 '+item.alarmRuleName+' 告警</span>'
					/*+'<span class="monitorPresetRecovery" >复位</span>'
					+'<span class="monitorPresetCancel" >取消</span>'*/
					+'</li>';
				if(videoTaskPushlet.isVoice=='1'){
					msgStr += item.alarmDeviceName+' 发生 '+item.alarmRuleName+' 告警';
					for(var i=0; i<3; i++){
						setTimeout(function(){
							const utter = new SpeechSynthesisUtterance();
							utter.lang = 'zh-Hant-CN';      
							utter.text = msgStr;      
							window.speechSynthesis.speak(utter);
						},0);
					}
				}
			}
		})
		$("#videoTask .box ul:eq(0)").html(li);
		//语音提醒信息 3 次
//		if(msgStr){
//			var msgStrs = msgStr.split("$");
//			for(var msg in msgStr){
//				
//			}
//		}
		
	}
	
}
//错误重载
function onError(){
	console.log('安全帽告警事件pushlet--onError！');
	setTimeout("alarmPushlet.init()",60000);
}

