node-red-contrib-hik-media-buffer 1.1.40 → 1.1.42

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.
@@ -27,6 +27,7 @@ module.exports = function(RED) {
27
27
  let statoCamera = {};
28
28
 
29
29
  const httpsAgent = new https.Agent({ rejectUnauthorized: false });
30
+ const EventList = ["FieldDetection", "LineDetection"];
30
31
 
31
32
  // CARTELLA TEMPORANEA
32
33
  const baseStorage = path.join(os.tmpdir(), "hik_temp_media");
@@ -240,46 +241,13 @@ module.exports = function(RED) {
240
241
  if (!nvrOnline) { node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", ip: node.host, msg: "NVR Online", nome_cliente: node.name } }); nvrOnline = true; }
241
242
  updateNodeStatus();
242
243
  response.data.on('data', (chunk) => {
243
- // Convertiamo in minuscolo per sicurezza nel parsing del testo
244
244
  const data = chunk.toString().toLowerCase();
245
-
246
- // Controlliamo che sia un evento attivo (allarme o heartbeat che sia)
247
245
  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)
259
246
  const chMatch = data.match(/<channelid>(\d+)<\/channelid>/i);
260
247
  if (chMatch) {
261
- let channelID = chMatch[1];
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!
267
- const camTermica = node.cameras.find(c => c.channel == "2");
268
- if (camTermica && node.host === camTermica.ip && channelID === "1") {
269
- channelID = "2";
270
- }
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);
248
+ let ev = "Unknown";
249
+ for (let e of EventList) { if (data.includes(e.toLowerCase())) { ev = e; break; } }
250
+ downloadMedia(ev, chMatch[1]);
283
251
  }
284
252
  }
285
253
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.40",
3
+ "version": "1.1.42",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",