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

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 +29 -26
  2. package/package.json +1 -1
@@ -62,42 +62,45 @@ 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'endpoint di status centralizzato in JSON, esente da blocchi 403
65
+ // Chiamata all'endpoint specifico di status dei canali proxy (Pag. 322)
66
66
  const res = await nvrAuth.request({
67
67
  method: 'GET',
68
- url: `${node.protocol}://${node.host}:${node.port}/ISAPI/System/Video/inputs/channels/status?format=json`,
69
- timeout: 6000,
68
+ url: `${node.protocol}://${node.host}:${node.port}/ISAPI/ContentMgmt/InputProxy/channels/status`,
69
+ timeout: 8000,
70
70
  httpsAgent: node.protocol === "https" ? httpsAgent : undefined
71
71
  });
72
72
 
73
- // Il manuale specifica la struttura: VideoInputChannelStatusList -> VideoInputChannelStatus
74
- const statusList = res.data?.VideoInputChannelStatusList?.VideoInputChannelStatus || [];
73
+ const xml = res.data.toString();
74
+ // Separiamo i singoli blocchi <InputProxyChannelStatus>
75
+ const channelBlocks = xml.match(/<InputProxyChannelStatus>[\s\S]*?<\/InputProxyChannelStatus>/g) || [];
75
76
 
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
-
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";
77
+ for (let block of channelBlocks) {
78
+ const idMatch = block.match(/<id>([\s\S]*?)<\/id>/i);
79
+ const onlineMatch = block.match(/<online>[ \t]*(true|false)[ \t]*<\/online>/i);
80
+ const nameMatch = block.match(/<channelName>([^<]+)<\/channelName>/i);
85
81
 
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;
82
+ if (idMatch) {
83
+ const ch = idMatch[1].trim();
84
+ // Estraiamo lo stato online nativo (true/false)
85
+ const isOnline = onlineMatch ? onlineMatch[1].trim().toLowerCase() === "true" : false;
86
+ // Estraiamo il nome reale configurato nell'NVR (se vuoto o "--", usiamo un fallback)
87
+ let nomeCameraReal = nameMatch ? nameMatch[1].trim() : `Camera ${ch}`;
88
+ if (nomeCameraReal === "--") nomeCameraReal = `Camera ${ch}`;
89
+
90
+ if (isOnline && statoCamera[ch] === false) {
91
+ node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", nome_cliente: node.name, nome_telecamera: nomeCameraReal, ip_telecamera: node.host, channel: ch, msg: "Camera ripristinata" } });
92
+ statoCamera[ch] = true;
93
+ } else if (!isOnline && statoCamera[ch] === true) {
94
+ node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: nomeCameraReal, ip_telecamera: node.host, channel: ch, msg: "Camera non raggiungibile" } });
95
+ statoCamera[ch] = false;
96
+ } else if (statoCamera[ch] === undefined) {
97
+ // Primo avvio: memorizza lo stato specchio dell'NVR
98
+ statoCamera[ch] = isOnline;
99
+ }
96
100
  }
97
101
  }
98
102
  } catch (e) {
99
- // Se la GET fallisce del tutto, significa che l'NVR stesso è offline
100
- node.error(`Errore nel check diagnostico JSON: ${e.message}`);
103
+ node.error(`Errore nel check diagnostico InputProxy: ${e.message}`);
101
104
  }
102
105
  updateNodeStatus();
103
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.121",
3
+ "version": "1.1.122",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",