You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.9 KiB
106 lines
3.9 KiB
|
|
function startMqttServer() {
|
|
if (!window.WebSocket) {
|
|
$("#connect").html("\
|
|
<h1>Get a new Web Browser!</h1>\
|
|
<p>\
|
|
Your browser does not support WebSockets. This example will not work properly.<br>\
|
|
Please use a Web Browser with WebSockets support (WebKit or Google Chrome).\
|
|
</p>\
|
|
");
|
|
} 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 += "<div class='ssbj-list " + msg.DEVICE_ID + " " + msg.EVENT_TYPE + "' dvcid='" + msg.DEVICE_ID + "' >";
|
|
strHtml += "<div class='bj-number'>" + bjno + "</div>";
|
|
strHtml += "<div class='ssbj-list-tit'>" + msg.EVENT_TYPE_NAME + "<span style='background: #ab4649;'>预警</span></div>";
|
|
strHtml += "<div class='ssbj-list-con'><p>设备:" + msg.DEVICE_SN + "</p>"
|
|
+ "<p>报警原因:" + msg.ALARM_REASONNAME + "</p>"
|
|
+ "<p>位置:" + msg.ADDR + "</p>"
|
|
+ "<p>时间:" + msg.ALARM_TIME + +"</p>"
|
|
+ "<p>描述:" + msg.DESCRIBE + "</p>"
|
|
+ "</div>";
|
|
strHtml += "</div>";
|
|
$("#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 = "<dd><strong>新消息:<a href='" + objMsg.Url + "'>" + title + "</a></strong></dd>";
|
|
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");
|
|
|
|
}
|
|
|