/**
* 初始化socket
**/
function initSocket(index_host){//端口号
if( !window.WebSocket ){
console.log("浏览器不支持websocket");
return false;
}
webSocket = new WebSocket("ws://"+index_host+"/hsms/socket/server/"+window.localStorage.userName+"/"+window.localStorage.userID); /**
* 联通
**/
webSocket.onopen = function(event){
console.log(event);
};
/**
* 接收后端消息
**/
webSocket.onmessage = function(msg){
var thisdata=JSON.parse(msg.data);
var isMsg=thisdata.code;//code 1单人聊天 2群组聊天 3是隐患派单
if(isMsg==1||isMsg==2){//消息的通知
var thismsgdata=JSON.parse(thisdata.data)//聊天内容
var index_userID=window.localStorage.getItem("userID");
//获取当前窗口的消息内容 如果当前打开的窗口即使聊天的对象就获取消息
if(parseInt(thismsgdata.fromId)==parseInt(index_userID)&&$('#Qcontent_index').css('display')!='none'){
isMsg=isMsg==1?'single':'msg_group';
getPeopleChatHis(thismsgdata.fromId, isMsg);//获取历史聊天记录
$("#golbal_QtalkOmsg").scrollTop($("#golbal_QtalkOmsg")[0].scrollHeight)//设置滚动条位置
}else{
$('#index_correction_title').text("消息通知");
$('#index_correction_content').append("<div class='index_correction_content user_"+thismsgdata.fromId+"'><span class='index_corrections_child' title="+thismsgdata.content+">"+thismsgdata.fromName+':'+thismsgdata.content+"<a href='javascript:void(0)' class='' onclick='index_Qtalkshow(\""+thismsgdata.fromName+"\",\""+thismsgdata.fromId+"\",\""+thisdata.code+"\")'>回复</a></span></div>")
$('#index_correction').show();//显示提示框
}
$("#index_correction_content").scrollTop($("#index_newcorrection").height())
}
else{//隐患的通知
$('#index_correction_title').text('隐患通知');
$('#index_newcorrection').append("<label>"+thisdata.data+"有隐患<a href='javascript:void(0)' onclick='correction_idnexgo()'>需派发整改单</a></label>")
$("#index_newcorrection").scrollTop($("#index_newcorrection").height())
$('#index_correction').show();//显示提示框
} };
};

  

05-07 15:27