node-red-contrib-hik-media-buffer 1.1.38 → 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 +43 -11
- 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");
|
|
@@ -243,23 +241,57 @@ module.exports = function(RED) {
|
|
|
243
241
|
updateNodeStatus();
|
|
244
242
|
response.data.on('data', (chunk) => {
|
|
245
243
|
const data = chunk.toString().toLowerCase();
|
|
244
|
+
|
|
246
245
|
if (data.includes("active")) {
|
|
247
246
|
const chMatch = data.match(/<channelid>(\d+)<\/channelid>/i);
|
|
248
247
|
if (chMatch) {
|
|
249
248
|
let channelID = chMatch[1];
|
|
250
|
-
|
|
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;
|
|
251
263
|
|
|
252
|
-
//
|
|
253
|
-
// Se l'host di ascolto coincide con l'IP della telecamera termica (canale 2)
|
|
254
|
-
// e la telecamera restituisce erroneamente canale 1, forziamo il canale a 2
|
|
264
|
+
// Cerchiamo nell'elenco la telecamera inserita come canale 2 (la termica)
|
|
255
265
|
const camTermica = node.cameras.find(c => c.channel == "2");
|
|
266
|
+
|
|
267
|
+
// 3. SWITCH DINAMICO INTELLIGENTE PER I FILE
|
|
256
268
|
if (camTermica && node.host === camTermica.ip) {
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
259
282
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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);
|
|
263
295
|
}
|
|
264
296
|
}
|
|
265
297
|
});
|