node-red-contrib-hikvision-ultimate
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -5,2 +5,7 @@ # node-red-contrib-hikvision-ultimate | ||
<p> | ||
<b>Version 0.0.25 GA VERSION WITH STABLE BEHAVOUR</b> December 2020<br/> | ||
- Fine tuning some msg handlers.<br/> | ||
- Debug mode avaiable. Just type banana after the server ip, for example 192.168.1.5banana<br/> | ||
</p> | ||
<p> | ||
<b>Version 0.0.24 GA VERSION WITH STABLE BEHAVOUR</b> December 2020<br/> | ||
@@ -7,0 +12,0 @@ - Better handling of malformed alert messages.<br/> |
@@ -13,3 +13,4 @@ | ||
var node = this | ||
node.host = config.host; | ||
node.debug = config.host.indexOf("banana") > -1; | ||
node.host = config.host.replace("banana",""); | ||
node.port = config.port; | ||
@@ -92,4 +93,5 @@ node.protocol = config.protocol || "http"; | ||
result += chunk.toString(); | ||
//console.log("BANANA RESULT: " + result); | ||
//console.log("HEADESR " + JSON.stringify(stream)) | ||
if (node.debug) RED.log.error("BANANA CHUNK: ######################\n" + chunk.toString() + "\n###################### FINE BANANA CHUNK"); | ||
if (node.debug) RED.log.error("BANANA RESULT: \n" + result + "\n###################### FINE BANANA RESULT"); | ||
// if (node.debug) RED.log.error("HEADESR " + JSON.stringify(stream)) | ||
// Gotta --boundary, process the message | ||
@@ -101,5 +103,5 @@ if (result.indexOf("--boundary") > -1) { | ||
aResults.forEach(sRet => { | ||
//if (aResults.length > 1) console.log("SINGOLO RESULT: " + sRet.replace(/\s/g,"-")); | ||
if (node.debug) RED.log.error("SPLITTATO RESULT: ######################\n" + sRet+ "\n###################### FINE SPLITTATO RESULT"); | ||
if (sRet.trim() !== "") { | ||
//console.log("BANANA PROCESSING" + sRet); | ||
if (node.debug) RED.log.error("BANANA PROCESSING" + sRet); | ||
try { | ||
@@ -110,3 +112,2 @@ //sRet = sRet.replace(/--boundary/g, ''); | ||
sRet = sRet.substring(i); | ||
// console.log("BANANA SBANANATO " + sRet); | ||
// By xml2js | ||
@@ -117,5 +118,8 @@ xml2js(sRet, function (err, result) { | ||
} else { | ||
node.nodeClients.forEach(oClient => { | ||
if (result !== undefined) oClient.sendPayload({ topic: oClient.topic || "", payload: result.EventNotificationAlert }); | ||
}); | ||
if (node.debug) RED.log.error("BANANA SBANANATO XML -> JSON " + JSON.stringify(result)); | ||
if (result !== null && result !== undefined && result.hasOwnProperty("EventNotificationAlert")) { | ||
node.nodeClients.forEach(oClient => { | ||
if (result !== undefined) oClient.sendPayload({ topic: oClient.topic || "", payload: result.EventNotificationAlert }); | ||
}); | ||
} | ||
} | ||
@@ -126,9 +130,12 @@ }); | ||
if (i > -1) { | ||
if (node.debug) RED.log.error("BANANA SBANANATO JSON " + sRet); | ||
sRet = sRet.substring(i); | ||
try { | ||
sRet = JSON.parse(sRet); | ||
// console.log("BANANA JSONATO: " + sRet); | ||
node.nodeClients.forEach(oClient => { | ||
oClient.sendPayload({ topic: oClient.topic || "", payload: sRet }); | ||
}) | ||
// if (node.debug) RED.log.error("BANANA JSONATO: " + sRet); | ||
if (sRet !== null && sRet !== undefined) { | ||
node.nodeClients.forEach(oClient => { | ||
oClient.sendPayload({ topic: oClient.topic || "", payload: sRet }); | ||
}) | ||
} | ||
} catch (error) { | ||
@@ -147,3 +154,3 @@ sRet = ""; | ||
} catch (error) { | ||
// console.log("BANANA startAlarmStream decodifica body: " + error); | ||
// if (node.debug) RED.log.error("BANANA startAlarmStream decodifica body: " + error); | ||
RED.log.warn("Hikvision-config: DecodingBody error: " + (error.message || " unknown error")); | ||
@@ -172,3 +179,3 @@ throw (error); | ||
node.setAllClientsStatus({ fill: "red", shape: "ring", text: response.statusText || " unknown response code" }); | ||
// console.log("BANANA Error response " + response.statusText); | ||
// if (node.debug) RED.log.error("BANANA Error response " + response.statusText); | ||
node.errorDescription = "StatusResponse problem " + (response.statusText || " unknown status response code"); | ||
@@ -175,0 +182,0 @@ throw new Error("StatusResponse " + (response.statusText || " unknown response code")); |
@@ -16,5 +16,7 @@ | ||
node.sendPayload = (_msg) => { | ||
if (_msg === null || _msg === undefined) return; | ||
if (_msg.hasOwnProperty("errorDescription")) { node.send([null,_msg]); return; }; // It's a connection error/restore comunication. | ||
if (_msg.payload.hasOwnProperty("eventType") | ||
if (_msg.hasOwnProperty("payload") | ||
&& _msg.payload.hasOwnProperty("eventType") | ||
&& _msg.payload.eventType.toString().toLowerCase() === "videoloss" | ||
@@ -21,0 +23,0 @@ && _msg.payload.eventState.toString().toLowerCase() === "inactive") { |
@@ -20,3 +20,5 @@ | ||
node.sendPayload = (_msg) => { | ||
if (_msg === null || _msg === undefined) return; | ||
if (_msg.hasOwnProperty("errorDescription")) { node.send([null,_msg]); return; }; // It's a connection error/restore comunication. | ||
if (_msg.payload === null || _msg.payload === undefined) return; | ||
@@ -23,0 +25,0 @@ if (node.currentPlate === _msg.payload) { |
@@ -17,2 +17,3 @@ | ||
node.sendPayload = (_msg) => { | ||
if (_msg === null || _msg === undefined) return; | ||
if (_msg.hasOwnProperty("errorDescription")) { node.send([null,_msg]); return; }; // It's a connection error/restore comunication. | ||
@@ -51,3 +52,7 @@ // Radar alarm JSON | ||
//var oRetMsg = RED.util.cloneMessage(_msg); | ||
if (_msg.payload.hasOwnProperty("CIDEvent") && _msg.payload.CIDEvent.type.toString().toLowerCase() === "zonealarm" && _msg.payload.CIDEvent.hasOwnProperty("zone")) { | ||
if (_msg.payload.hasOwnProperty("payload") | ||
&& _msg.payload.hasOwnProperty("CIDEvent") | ||
&& _msg.payload.CIDEvent.type.toString().toLowerCase() === "zonealarm" | ||
&& _msg.payload.CIDEvent.hasOwnProperty("zone")) { | ||
var oRetMsg = {}; // Return message | ||
@@ -54,0 +59,0 @@ oRetMsg.connected = _msg.connected; |
{ | ||
"name": "node-red-contrib-hikvision-ultimate", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"description": "A native set of node for Hikvision Cameras, Alarms, Radars etc.", | ||
@@ -5,0 +5,0 @@ "author": "Supergiovane (https://github.com/Supergiovane)", |
309223
676