import { movedevicewebsocketurl } from "../../../public/js/url.js"; import { updateMoveDeviceMarker,addMoveDeviceMarker,moveDeviceMarkerHash } from "../js/marker/moveDeviceMarker.js"; let mdWsFlag = 60; let mdWsTimer = null; let mdWebsocketConnect = null; let deviceHash={}; function moveDeviceWebsocket(){ return new Promise((resolve, reject) => { mdWebsocketConnect = new WebSocket(movedevicewebsocketurl); mdWebsocketConnect.onopen = function (evt) { mdWsFlag = 3; if (mdWsTimer != null) { clearInterval(mdWsTimer); mdWsTimer = null; mdWsFlag=60; } resolve({ "msg":"移动设备websocket连接成功", "code":0, "mdWebsocketConnect":mdWebsocketConnect }) setInterval(()=>{ let messageObj = { "msgcode": 99, "msgname": "hb", "message":"hb" } if(mdWebsocketConnect!=null){ mdWebsocketConnect.send(JSON.stringify(messageObj)); } },5000) }; mdWebsocketConnect.onclose = function (evt) { console.log("移动设备的websocket已经断开onclose"); mdWebsocketConnect.close(); mdevWebsocketReconnection(); }; mdWebsocketConnect.onerror = function (evt) { console.log("移动设备的websocket已经断开onerror") mdWebsocketConnect.close(); mdevWebsocketReconnection(); }; mdWebsocketConnect.onmessage = function (evt) { var data=JSON.parse(evt.data); var msgcode=data["msgcode"]; var message=data["message"]; if(msgcode=="4000"){//设备心跳 websoceketDeviceBear(message); }else if(msgcode=="4001"){//这是普通的事件 //查询设备的事件跟报警 //getDevicePhotoAndSos(); }else if(msgcode=="4002"){//设备在线,离线状态 deviceStatusUpdate(message); }else if(msgcode=="403"){//获取移动设备的设备列表 //这里需要判断一下,如果是重连,就不做任何事情,只需要连接一下 var list=message["list"]; var pagepro=message["pagepro"]; for(var dev=0;dev3){ deviceHash[deviceid]["appVersion"]=infoArr[3]; }else{ deviceHash[deviceid]["appVersion"]="未知"; } }else{ var infoArr=[]; deviceHash[deviceid]["cardNumber"]=""; deviceHash[deviceid]["appVersion"]="未知"; } }else{ var infoArr=[]; deviceHash[deviceid]["cardNumber"]=""; deviceHash[deviceid]["appVersion"]="未知"; } //如果marker在地图上面显示就去更新位置 if(deviceid in moveDeviceMarkerHash){ updateMoveDeviceMarker(deviceHash[deviceid]); } } } } //设备状态改变4002 function deviceStatusUpdate(message){ for(var i=0;i