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.
Files changed (2) hide show
  1. package/hik-media-buffer.js +33 -13
  2. package/package.json +1 -1
@@ -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
- let currentEventList = EventListNVR;
251
-
252
- // --- IL TUO CONTROLLO LOGICO ---
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
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
- currentEventList = EventListCAM;
258
-
268
+ if (camTermica && node.host === camTermica.ip && channelID === "1") {
269
+ channelID = "2";
259
270
  }
260
- let ev = "Unknown";
261
- for (let e of currentEventList) { if (data.includes(e.toLowerCase())) { ev = e; break; } }
262
- downloadMedia(ev, channelID);
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.38",
3
+ "version": "1.1.40",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",