node-red-contrib-hik-media-buffer 1.1.119 → 1.1.121

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 +25 -25
  2. package/package.json +1 -2
@@ -62,42 +62,42 @@ module.exports = function(RED) {
62
62
  if (isClosing || !nvrOnline) return;
63
63
  const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
64
64
  try {
65
- // Interroghiamo l'elenco proxy centralizzato dell'NVR
65
+ // Interroghiamo l'endpoint di status centralizzato in JSON, esente da blocchi 403
66
66
  const res = await nvrAuth.request({
67
67
  method: 'GET',
68
- url: `${node.protocol}://${node.host}:${node.port}/ISAPI/ContentMgmt/InputProxy/channels`,
68
+ url: `${node.protocol}://${node.host}:${node.port}/ISAPI/System/Video/inputs/channels/status?format=json`,
69
69
  timeout: 6000,
70
70
  httpsAgent: node.protocol === "https" ? httpsAgent : undefined
71
71
  });
72
72
 
73
- const xml = res.data.toString();
74
- // Estraiamo i singoli blocchi di canali digitali
75
- const channelBlocks = xml.match(/<InputProxyChannel>[\s\S]*?<\/InputProxyChannel>/g) || [];
73
+ // Il manuale specifica la struttura: VideoInputChannelStatusList -> VideoInputChannelStatus
74
+ const statusList = res.data?.VideoInputChannelStatusList?.VideoInputChannelStatus || [];
76
75
 
77
- for (let block of channelBlocks) {
78
- const idMatch = block.match(/<id>(\d+)<\/id>/i);
79
- // Questa regex cerca la parola "true" o "false" dentro il tag online, sia esso <online>, <onLine> o <ONLINE>
80
- const onlineMatch = block.match(/<onLine[^>]*>(true|false)<\/onLine>/i) || block.match(/<online[^>]*>(true|false)<\/online>/i);
76
+ // Se l'array è vuoto, potrebbe essere una struttura leggermente diversa a seconda del firmware
77
+ const channels = Array.isArray(statusList) ? statusList : [statusList];
78
+
79
+ for (let camStatus of channels) {
80
+ if (!camStatus || !camStatus.id) continue;
81
81
 
82
- if (idMatch) {
83
- const ch = idMatch[1];
84
- const isOnline = onlineMatch ? onlineMatch[1].toLowerCase() === "true" : false;
85
-
86
- if (isOnline && statoCamera[ch] === false) {
87
- const nomeOnline = await getCameraNameFromNVR(ch);
88
- node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", nome_cliente: node.name, nome_telecamera: nomeOnline, ip_telecamera: node.host, channel: ch, msg: "Camera ripristinata" } });
89
- statoCamera[ch] = true;
90
- } else if (!isOnline && statoCamera[ch] !== false && statoCamera[ch] !== undefined) {
91
- node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: `Camera ${ch}`, ip_telecamera: node.host, channel: ch, msg: "Camera non raggiungibile" } });
92
- statoCamera[ch] = false;
93
- } else if (statoCamera[ch] === undefined) {
94
- // Configurazione iniziale dello stato al boot
95
- statoCamera[ch] = isOnline;
96
- }
82
+ const ch = camStatus.id;
83
+ // Estrae lo stato: accetta sia il booleano true che la stringa "true"
84
+ const isOnline = camStatus.online === true || camStatus.online === "true";
85
+
86
+ if (isOnline && statoCamera[ch] === false) {
87
+ const nomeOnline = await getCameraNameFromNVR(ch);
88
+ node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", nome_cliente: node.name, nome_telecamera: nomeOnline, ip_telecamera: node.host, channel: ch.toString(), msg: "Camera ripristinata" } });
89
+ statoCamera[ch] = true;
90
+ } else if (!isOnline && statoCamera[ch] !== false && statoCamera[ch] !== undefined) {
91
+ node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: `Camera ${ch}`, ip_telecamera: node.host, channel: ch.toString(), msg: "Camera non raggiungibile" } });
92
+ statoCamera[ch] = false;
93
+ } else if (statoCamera[ch] === undefined) {
94
+ // Inizializzazione al primo avvio
95
+ statoCamera[ch] = isOnline;
97
96
  }
98
97
  }
99
98
  } catch (e) {
100
- node.error(`Errore nel check diagnostico: ${e.message}`);
99
+ // Se la GET fallisce del tutto, significa che l'NVR stesso è offline
100
+ node.error(`Errore nel check diagnostico JSON: ${e.message}`);
101
101
  }
102
102
  updateNodeStatus();
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.119",
3
+ "version": "1.1.121",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",
@@ -22,7 +22,6 @@
22
22
  "dependencies": {
23
23
  "@mhoc/axios-digest-auth": "^0.8.0",
24
24
  "axios": "^1.6.0",
25
- "node-red-contrib-hik-media-buffer": "^1.1.109",
26
25
  "xml2js": "^0.6.2"
27
26
  }
28
27
  }