node-red-contrib-hik-media-buffer 1.1.39 → 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 +26 -38
  2. package/package.json +1 -1
@@ -240,57 +240,45 @@ module.exports = function(RED) {
240
240
  if (!nvrOnline) { node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", ip: node.host, msg: "NVR Online", nome_cliente: node.name } }); nvrOnline = true; }
241
241
  updateNodeStatus();
242
242
  response.data.on('data', (chunk) => {
243
+ // Convertiamo in minuscolo per sicurezza nel parsing del testo
243
244
  const data = chunk.toString().toLowerCase();
244
245
 
246
+ // Controlliamo che sia un evento attivo (allarme o heartbeat che sia)
245
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)
246
259
  const chMatch = data.match(/<channelid>(\d+)<\/channelid>/i);
247
260
  if (chMatch) {
248
261
  let channelID = chMatch[1];
249
262
 
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)
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!
265
267
  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
- }
268
+ if (camTermica && node.host === camTermica.ip && channelID === "1") {
269
+ channelID = "2";
282
270
  }
283
271
 
284
- // Filtro Anti-Rimbalzo (Debounce) per evitare raffiche di richieste
272
+ // Filtro Anti-Rimbalzo (Debounce) per evitare rafficate di richieste in un secondo
285
273
  const adesso = Date.now();
286
- if (!ultimoAllarmeTempo[targetIP]) ultimoAllarmeTempo[targetIP] = 0;
287
- if (adesso - ultimoAllarmeTempo[targetIP] < 10000) return;
288
- ultimoAllarmeTempo[targetIP] = adesso;
274
+ if (!ultimoAllarmeTempo[node.host]) ultimoAllarmeTempo[node.host] = 0;
275
+ if (adesso - ultimoAllarmeTempo[node.host] < 10000) return;
276
+ ultimoAllarmeTempo[node.host] = adesso;
289
277
 
290
- // Aspetta 2 secondi per dare tempo alla telecamera di scrivere l'immagine
278
+ // Aspetta 2 secondi per dare tempo alla telecamera di scrivere l'immagine prima di chiedergliela
291
279
  setTimeout(() => {
292
- // Passiamo direttamente "ev" (es. fielddetection) estratto dall'XML
293
- downloadMedia(ev, targetIP, channelID, forzaTermico);
280
+ // Lancia la tua funzione downloadMedia originale che è giusta!
281
+ downloadMedia(ev, channelID);
294
282
  }, 2000);
295
283
  }
296
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.39",
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",