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

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 +32 -29
  2. package/package.json +1 -1
@@ -37,7 +37,7 @@ module.exports = function(RED) {
37
37
  }
38
38
 
39
39
  // --- 1. PRENDE IL NOME REALE DELLA TELECAMERA DAL DIGITAL PROXY ---
40
- async function getCameraNameFromNVR(channelID) {
40
+ async function getCameraName(channelID) {
41
41
  const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
42
42
  try {
43
43
  // In accordo con la pag. 58 della documentazione, interroghiamo l'InputProxy del canale digitale
@@ -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 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);
85
80
 
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;
81
+ if (idMatch) {
82
+ const ch = idMatch[1].trim();
83
+ // Estraiamo lo stato online nativo (true/false)
84
+ const isOnline = onlineMatch ? onlineMatch[1].trim().toLowerCase() === "true" : false;
85
+
86
+ if (isOnline && statoCamera[ch] === false) {
87
+ // 🌟 RECUPERO REALE DEL NOME: Usiamo getCameraName per avere il nome corretto OSD ("ufficio")
88
+ const nomeOnline = await getCameraName(ch);
89
+
90
+ 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" } });
91
+ statoCamera[ch] = true;
92
+ } else if (!isOnline && statoCamera[ch] === true) {
93
+ // Per l'offline usiamo un fallback sul canale, dato che la cam non risponderebbe a getCameraName
94
+ 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" } });
95
+ statoCamera[ch] = false;
96
+ } else if (statoCamera[ch] === undefined) {
97
+ // Memorizzazione iniziale dello stato al boot
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
  }
@@ -123,14 +126,14 @@ module.exports = function(RED) {
123
126
  lastTriggerTime[channelID] = nowTime;
124
127
 
125
128
  node.status({fill:"yellow", shape:"dot", text:`Attesa scrittura NVR (6s)...`});
126
- await new Promise(resolve => setTimeout(resolve, 6000));
129
+ await new Promise(resolve => setTimeout(resolve, 8000));
127
130
 
128
131
  const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
129
132
  const referenceTime = new Date();
130
133
  const timestamp = Math.floor(referenceTime.getTime() / 1000);
131
134
 
132
135
  const videoTrackID = (parseInt(channelID) * 100) + 1;
133
- const nomeCamera = await getCameraNameFromNVR(channelID);
136
+ const nomeCamera = await getCameraName(channelID);
134
137
  node.status({fill:"yellow", shape:"dot", text:`Download Cam ${channelID}...`});
135
138
 
136
139
  const inizioFinestra = new Date(referenceTime.getTime() - (2 * 60 * 1000));
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.123",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",