node-red-contrib-hik-media-buffer 1.1.121 → 1.1.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hik-media-buffer.js +29 -26
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -62,42 +62,45 @@ module.exports = function(RED) {
|
|
|
62
62
|
if (isClosing || !nvrOnline) return;
|
|
63
63
|
const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
|
|
64
64
|
try {
|
|
65
|
-
//
|
|
65
|
+
// Chiamata all'endpoint specifico di status dei canali proxy (Pag. 322)
|
|
66
66
|
const res = await nvrAuth.request({
|
|
67
67
|
method: 'GET',
|
|
68
|
-
url: `${node.protocol}://${node.host}:${node.port}/ISAPI/
|
|
69
|
-
timeout:
|
|
68
|
+
url: `${node.protocol}://${node.host}:${node.port}/ISAPI/ContentMgmt/InputProxy/channels/status`,
|
|
69
|
+
timeout: 8000,
|
|
70
70
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const xml = res.data.toString();
|
|
74
|
+
// Separiamo i singoli blocchi <InputProxyChannelStatus>
|
|
75
|
+
const channelBlocks = xml.match(/<InputProxyChannelStatus>[\s\S]*?<\/InputProxyChannelStatus>/g) || [];
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!camStatus || !camStatus.id) continue;
|
|
81
|
-
|
|
82
|
-
const ch = camStatus.id;
|
|
83
|
-
// Estrae lo stato: accetta sia il booleano true che la stringa "true"
|
|
84
|
-
const isOnline = camStatus.online === true || camStatus.online === "true";
|
|
77
|
+
for (let block of channelBlocks) {
|
|
78
|
+
const idMatch = block.match(/<id>([\s\S]*?)<\/id>/i);
|
|
79
|
+
const onlineMatch = block.match(/<online>[ \t]*(true|false)[ \t]*<\/online>/i);
|
|
80
|
+
const nameMatch = block.match(/<channelName>([^<]+)<\/channelName>/i);
|
|
85
81
|
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
if (idMatch) {
|
|
83
|
+
const ch = idMatch[1].trim();
|
|
84
|
+
// Estraiamo lo stato online nativo (true/false)
|
|
85
|
+
const isOnline = onlineMatch ? onlineMatch[1].trim().toLowerCase() === "true" : false;
|
|
86
|
+
// Estraiamo il nome reale configurato nell'NVR (se vuoto o "--", usiamo un fallback)
|
|
87
|
+
let nomeCameraReal = nameMatch ? nameMatch[1].trim() : `Camera ${ch}`;
|
|
88
|
+
if (nomeCameraReal === "--") nomeCameraReal = `Camera ${ch}`;
|
|
89
|
+
|
|
90
|
+
if (isOnline && statoCamera[ch] === false) {
|
|
91
|
+
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", nome_cliente: node.name, nome_telecamera: nomeCameraReal, ip_telecamera: node.host, channel: ch, msg: "Camera ripristinata" } });
|
|
92
|
+
statoCamera[ch] = true;
|
|
93
|
+
} else if (!isOnline && statoCamera[ch] === true) {
|
|
94
|
+
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: nomeCameraReal, ip_telecamera: node.host, channel: ch, msg: "Camera non raggiungibile" } });
|
|
95
|
+
statoCamera[ch] = false;
|
|
96
|
+
} else if (statoCamera[ch] === undefined) {
|
|
97
|
+
// Primo avvio: memorizza lo stato specchio dell'NVR
|
|
98
|
+
statoCamera[ch] = isOnline;
|
|
99
|
+
}
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
} catch (e) {
|
|
99
|
-
|
|
100
|
-
node.error(`Errore nel check diagnostico JSON: ${e.message}`);
|
|
103
|
+
node.error(`Errore nel check diagnostico InputProxy: ${e.message}`);
|
|
101
104
|
}
|
|
102
105
|
updateNodeStatus();
|
|
103
106
|
}
|