function startMqttServer() { if (!window.WebSocket) { $("#connect").html("\

Get a new Web Browser!

\

\ Your browser does not support WebSockets. This example will not work properly.
\ Please use a Web Browser with WebSockets support (WebKit or Google Chrome).\

\ "); } else { console.log(JSON.parse(window.sessionStorage.getItem("userInfo")).UserCode); if (JSON.parse(window.sessionStorage.getItem("userInfo")).UserCode != undefined) { usersUid = JSON.parse(window.sessionStorage.getItem("userInfo")).UserCode OrgId = JSON.parse(window.sessionStorage.getItem("userInfo")).OrgID initmqtt(OrgId, usersUid); } } } function initmqtt(orgId, usersUid) { //var destination = ["044A58B5F3E74B6CBBAD9EC33A339C22/" + usersUid + "/APP/APPROVAL"]; //订阅主题 var destination = ["XJYQ/" + orgId + "/" + usersUid + "/PC/PushMsg"]; //订阅主题 iotpush = CreateIOTPushObject(); //iotpush.clientId = iotpush.guid().replace(/\-/g, ""); iotpush.clientId = iotpush.uuid(16, 16); iotpush.destination = destination; iotpush.setClient(); iotpush.client.onMessageArrived = onMessageArrived; //信息接收 iotpush.setConnect(); } //消息发送 function sendMessage(title, content, usercode) { var jsonstr = "{\"Title\":\"" + title + "\",\"Type\":\"APPROVAL\",\"Content\":\"" + content + "\"}"; var destinationName = "044A58B5F3E74B6CBBAD9EC33A339C22/" + usercode + "/APP/APPROVAL"; //订阅主题 //var destinationName = "044A58B5F3E74B6CBBAD9EC33A339C22/" + shzxfzd + "/APP/APPROVAL"; //订阅主题 iotpush.send(jsonstr, destinationName); } //信息接收 function onMessageArrived(message) { console.log(message.payloadString); var objMsg = JSON.parse(message.payloadString); if (objMsg.Type == "WARN") { setRealWarnList(objMsg.WARNINFO); } else if (objMsg.Type == "INFO") { } else if (objMsg.Type == "Remind") { RemindMsgAlert(objMsg); } } function setRealWarnList(objMsg) { var strHtml = ""; var msg = objMsg; var snbj = $(".ssbj-list." + msg.DEVICE_ID + "." + msg.EVENT_TYPE); var bjno = 0; if (snbj != null && snbj.length > 0) { var text = snbj.find(".bj-number").text(); if (text != "") { bjno = text; } snbj.remove(); } bjno++; strHtml += "
"; strHtml += "
" + bjno + "
"; strHtml += "
" + msg.EVENT_TYPE_NAME + "预警
"; strHtml += "

设备:" + msg.DEVICE_SN + "

" + "

报警原因:" + msg.ALARM_REASONNAME + "

" + "

位置:" + msg.ADDR + "

" + "

时间:" + msg.ALARM_TIME + +"

" + "

描述:" + msg.DESCRIBE + "

" + "
"; strHtml += "
"; $("#divWarnReal").prepend(strHtml); $("#divWarnReal .ssbj-list").dblclick(function () { dvcinfo($(this).attr("dvcid")); }); } //提醒信息 function RemindMsgAlert(objMsg) { var msg = objMsg; var title; if (objMsg.Title.length > 18) { title = objMsg.Title.substring(1, 18) + "........." } else { title = objMsg.Title; } var nodeCount = $("#alertMsg dd").length var strHtml = "
新消息:" + title + "
"; if (nodeCount >= 11) { var lastAVal = $("#lasta").text(); $("#win_ad dd").eq(-2).remove(); $("#win_ad dt").eq(0).after(strHtml); $("#lasta").text(parseInt(lastAVal) + 1); } else { $("#alertMsg").append(strHtml); } $("#win_ad").removeAttr("hidden"); }