node-red-contrib-hik-media-buffer 1.1.37 → 1.1.39
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 +48 -4
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -27,7 +27,6 @@ module.exports = function(RED) {
|
|
|
27
27
|
let statoCamera = {};
|
|
28
28
|
|
|
29
29
|
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
30
|
-
const EventList = ["FieldDetection", "LineDetection"];
|
|
31
30
|
|
|
32
31
|
// CARTELLA TEMPORANEA
|
|
33
32
|
const baseStorage = path.join(os.tmpdir(), "hik_temp_media");
|
|
@@ -242,12 +241,57 @@ module.exports = function(RED) {
|
|
|
242
241
|
updateNodeStatus();
|
|
243
242
|
response.data.on('data', (chunk) => {
|
|
244
243
|
const data = chunk.toString().toLowerCase();
|
|
244
|
+
|
|
245
245
|
if (data.includes("active")) {
|
|
246
246
|
const chMatch = data.match(/<channelid>(\d+)<\/channelid>/i);
|
|
247
247
|
if (chMatch) {
|
|
248
|
-
let
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
let channelID = chMatch[1];
|
|
249
|
+
|
|
250
|
+
// 1. ESTRAZIONE DIRETTA E DINAMICA DELL'EVENTO
|
|
251
|
+
// Prende il testo dentro <eventType>...</eventType>
|
|
252
|
+
let ev = data.match(/<eventtype>([^<]+)<\/eventtype>/i)?.[1] || "unknown";
|
|
253
|
+
ev = ev.trim();
|
|
254
|
+
|
|
255
|
+
// 2. IL TUO CONTROLLO LOGICO PERFETTO
|
|
256
|
+
// Se è un heartbeat o se non è stato estratto nulla, blocca tutto qui!
|
|
257
|
+
if (ev === "unknown" || ev === "heartbeat") {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
let targetIP = node.host;
|
|
262
|
+
let forzaTermico = false;
|
|
263
|
+
|
|
264
|
+
// Cerchiamo nell'elenco la telecamera inserita come canale 2 (la termica)
|
|
265
|
+
const camTermica = node.cameras.find(c => c.channel == "2");
|
|
266
|
+
|
|
267
|
+
// 3. SWITCH DINAMICO INTELLIGENTE PER I FILE
|
|
268
|
+
if (camTermica && node.host === camTermica.ip) {
|
|
269
|
+
// Se parliamo con la CAM diretta
|
|
270
|
+
targetIP = node.host;
|
|
271
|
+
forzaTermico = true; // Tracce 201/203
|
|
272
|
+
channelID = "1"; // La cam ha solo il canale 1 nativo
|
|
273
|
+
} else {
|
|
274
|
+
// Se parliamo con l'NVR
|
|
275
|
+
const camTrovata = node.cameras.find(c => c.channel == channelID);
|
|
276
|
+
if (camTrovata) {
|
|
277
|
+
targetIP = camTrovata.ip;
|
|
278
|
+
}
|
|
279
|
+
if (channelID === "2") {
|
|
280
|
+
forzaTermico = true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Filtro Anti-Rimbalzo (Debounce) per evitare raffiche di richieste
|
|
285
|
+
const adesso = Date.now();
|
|
286
|
+
if (!ultimoAllarmeTempo[targetIP]) ultimoAllarmeTempo[targetIP] = 0;
|
|
287
|
+
if (adesso - ultimoAllarmeTempo[targetIP] < 10000) return;
|
|
288
|
+
ultimoAllarmeTempo[targetIP] = adesso;
|
|
289
|
+
|
|
290
|
+
// Aspetta 2 secondi per dare tempo alla telecamera di scrivere l'immagine
|
|
291
|
+
setTimeout(() => {
|
|
292
|
+
// Passiamo direttamente "ev" (es. fielddetection) estratto dall'XML
|
|
293
|
+
downloadMedia(ev, targetIP, channelID, forzaTermico);
|
|
294
|
+
}, 2000);
|
|
251
295
|
}
|
|
252
296
|
}
|
|
253
297
|
});
|