node-red-contrib-hik-media-buffer 1.1.118 → 1.1.120
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 +20 -9
- package/package.json +1 -2
package/hik-media-buffer.js
CHANGED
|
@@ -57,40 +57,51 @@ module.exports = function(RED) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// --- 2. CONTROLLO STATUS CAMERE AUTOMATICO
|
|
60
|
+
// --- 2. CONTROLLO STATUS CAMERE AUTOMATICO ---
|
|
61
61
|
async function checkCameras() {
|
|
62
62
|
if (isClosing || !nvrOnline) return;
|
|
63
63
|
const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
|
|
64
64
|
try {
|
|
65
|
-
// Interroghiamo l'elenco proxy di tutti i canali digitali (Pag. 58 della documentazione)
|
|
66
65
|
const res = await nvrAuth.request({
|
|
67
66
|
method: 'GET',
|
|
68
67
|
url: `${node.protocol}://${node.host}:${node.port}/ISAPI/ContentMgmt/InputProxy/channels`,
|
|
69
|
-
timeout:
|
|
68
|
+
timeout: 6000,
|
|
70
69
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
71
70
|
});
|
|
72
71
|
|
|
73
72
|
const xml = res.data.toString();
|
|
74
|
-
//
|
|
73
|
+
// Isola ogni blocco <InputProxyChannel>
|
|
75
74
|
const channelBlocks = xml.match(/<InputProxyChannel>[\s\S]*?<\/InputProxyChannel>/g) || [];
|
|
76
75
|
|
|
77
76
|
for (let block of channelBlocks) {
|
|
78
77
|
const idMatch = block.match(/<id>(\d+)<\/id>/i);
|
|
79
|
-
// Standard Hikvision: estraiamo il tag <online> (true/false)
|
|
80
|
-
const onlineMatch = block.match(/<online>([^<]+)<\/online>/i);
|
|
81
78
|
|
|
82
79
|
if (idMatch) {
|
|
83
80
|
const ch = idMatch[1];
|
|
84
|
-
|
|
81
|
+
let isOnline = false;
|
|
82
|
+
|
|
83
|
+
// Cattura il testo tra <online...> e </online> o <onLine...> e </onLine>
|
|
84
|
+
// gestendo la presenza di attributi come opt="true,false" (Specifiche Pag. 156/162)
|
|
85
|
+
const rawOnlineMatch = block.match(/<online[^>]*>([\s\S]*?)<\/online>/i) ||
|
|
86
|
+
block.match(/<onLine[^>]*>([\s\S]*?)<\/onLine>/i);
|
|
87
|
+
|
|
88
|
+
if (rawOnlineMatch && rawOnlineMatch[1]) {
|
|
89
|
+
const val = rawOnlineMatch[1].trim().toLowerCase();
|
|
90
|
+
// Se il testo contiene "true", la telecamera è online
|
|
91
|
+
if (val.includes("true")) {
|
|
92
|
+
isOnline = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
85
95
|
|
|
86
96
|
if (isOnline && statoCamera[ch] === false) {
|
|
87
97
|
const nomeOnline = await getCameraNameFromNVR(ch);
|
|
88
98
|
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", nome_cliente: node.name, nome_telecamera: nomeOnline, ip_telecamera: node.host, channel: ch, msg: "Camera ripristinata" } });
|
|
89
99
|
statoCamera[ch] = true;
|
|
90
|
-
} else if (!isOnline && statoCamera[ch] !== false) {
|
|
100
|
+
} else if (!isOnline && statoCamera[ch] !== false && statoCamera[ch] !== undefined) {
|
|
91
101
|
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: `Camera ${ch}`, ip_telecamera: node.host, channel: ch, msg: "Camera non raggiungibile" } });
|
|
92
102
|
statoCamera[ch] = false;
|
|
93
103
|
} else if (statoCamera[ch] === undefined) {
|
|
104
|
+
// Boot iniziale: salva lo stato rilevato senza inviare messaggi spuri
|
|
94
105
|
statoCamera[ch] = isOnline;
|
|
95
106
|
}
|
|
96
107
|
}
|
|
@@ -112,7 +123,7 @@ module.exports = function(RED) {
|
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
125
|
|
|
115
|
-
const heartbeatInterval = setInterval(checkCameras,
|
|
126
|
+
const heartbeatInterval = setInterval(checkCameras, 15000);
|
|
116
127
|
|
|
117
128
|
// --- 3. DOWNLOAD MEDIA CON DELAY E FORMATO STRINGA CORRETTO ---
|
|
118
129
|
async function downloadMedia(evento, channelID) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-hik-media-buffer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.120",
|
|
4
4
|
"description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@mhoc/axios-digest-auth": "^0.8.0",
|
|
24
24
|
"axios": "^1.6.0",
|
|
25
|
-
"node-red-contrib-hik-media-buffer": "^1.1.109",
|
|
26
25
|
"xml2js": "^0.6.2"
|
|
27
26
|
}
|
|
28
27
|
}
|