node-red-contrib-hik-media-buffer 1.1.38 → 1.1.40
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 +33 -13
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -27,8 +27,6 @@ module.exports = function(RED) {
|
|
|
27
27
|
let statoCamera = {};
|
|
28
28
|
|
|
29
29
|
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
30
|
-
const EventListNVR = ["FieldDetection", "LineDetection"];
|
|
31
|
-
const EventListCAM = ["fielddetection", "linedetection"];
|
|
32
30
|
|
|
33
31
|
// CARTELLA TEMPORANEA
|
|
34
32
|
const baseStorage = path.join(os.tmpdir(), "hik_temp_media");
|
|
@@ -242,24 +240,46 @@ module.exports = function(RED) {
|
|
|
242
240
|
if (!nvrOnline) { node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", ip: node.host, msg: "NVR Online", nome_cliente: node.name } }); nvrOnline = true; }
|
|
243
241
|
updateNodeStatus();
|
|
244
242
|
response.data.on('data', (chunk) => {
|
|
243
|
+
// Convertiamo in minuscolo per sicurezza nel parsing del testo
|
|
245
244
|
const data = chunk.toString().toLowerCase();
|
|
245
|
+
|
|
246
|
+
// Controlliamo che sia un evento attivo (allarme o heartbeat che sia)
|
|
246
247
|
if (data.includes("active")) {
|
|
248
|
+
|
|
249
|
+
// 1. ESTRAZIONE DINAMICA DELL'EVENTO NATIVO (Pagina 32 del manuale)
|
|
250
|
+
let ev = data.match(/<eventtype>([^<]+)<\/eventtype>/i)?.[1] || "unknown";
|
|
251
|
+
ev = ev.trim();
|
|
252
|
+
|
|
253
|
+
// 2. FILTRO FONDAMENTALE: Se è l'heartbeat di test o è vuoto, FERMA TUTTO
|
|
254
|
+
if (ev === "unknown" || ev === "heartbeat") {
|
|
255
|
+
return; // Non entra in downloadMedia e azzera il loop infinito!
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 3. RECUPERO DEL CANALE REALE (Dall'XML della telecamera o NVR)
|
|
247
259
|
const chMatch = data.match(/<channelid>(\d+)<\/channelid>/i);
|
|
248
260
|
if (chMatch) {
|
|
249
261
|
let channelID = chMatch[1];
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
262
|
+
|
|
263
|
+
// Logica universale:
|
|
264
|
+
// Se node.host è l'IP della telecamera singola, per la tua funzione downloadMedia
|
|
265
|
+
// passiamo il canale "2" in modo che il tuo elenco selezioni la riga corretta della termica,
|
|
266
|
+
// ma l'evento "ev" (es. fielddetection) viene passato pulito in minuscolo come vuole la cam!
|
|
255
267
|
const camTermica = node.cameras.find(c => c.channel == "2");
|
|
256
|
-
if (camTermica && node.host === camTermica.ip) {
|
|
257
|
-
|
|
258
|
-
|
|
268
|
+
if (camTermica && node.host === camTermica.ip && channelID === "1") {
|
|
269
|
+
channelID = "2";
|
|
259
270
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
271
|
+
|
|
272
|
+
// Filtro Anti-Rimbalzo (Debounce) per evitare rafficate di richieste in un secondo
|
|
273
|
+
const adesso = Date.now();
|
|
274
|
+
if (!ultimoAllarmeTempo[node.host]) ultimoAllarmeTempo[node.host] = 0;
|
|
275
|
+
if (adesso - ultimoAllarmeTempo[node.host] < 10000) return;
|
|
276
|
+
ultimoAllarmeTempo[node.host] = adesso;
|
|
277
|
+
|
|
278
|
+
// Aspetta 2 secondi per dare tempo alla telecamera di scrivere l'immagine prima di chiedergliela
|
|
279
|
+
setTimeout(() => {
|
|
280
|
+
// Lancia la tua funzione downloadMedia originale che è giusta!
|
|
281
|
+
downloadMedia(ev, channelID);
|
|
282
|
+
}, 2000);
|
|
263
283
|
}
|
|
264
284
|
}
|
|
265
285
|
});
|