node-red-contrib-hik-media-buffer 1.1.114 → 1.1.116

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 +19 -19
  2. package/package.json +1 -1
@@ -35,27 +35,28 @@ module.exports = function(RED) {
35
35
 
36
36
  function toHikDate(d) { return d.toISOString().split('.')[0] + "Z"; }
37
37
 
38
- // --- PRENDE IL NOME DELLA TELECAMERA DALL'NVR ---
38
+ // --- PRENDE IL NOME REALE DELLA TELECAMERA DALL'NVR ---
39
39
  async function getCameraNameFromNVR(channelID) {
40
40
  const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
41
41
  try {
42
42
  const res = await nvrAuth.request({
43
43
  method: 'GET',
44
- url: `${node.protocol}://${node.host}:${node.port}/ISAPI/System/Video/inputs/channels/${channelID}/overlays/channelNameOverlay`,
44
+ url: `${node.protocol}://${node.host}:${node.port}/ISAPI/System/Video/inputs/channels/${channelID}`,
45
45
  timeout: 5000,
46
46
  httpsAgent: node.protocol === "https" ? httpsAgent : undefined
47
47
  });
48
48
 
49
49
  const data = res.data.toString();
50
- const match = data.match(/<name>([^<]+)<\/name>/i);
50
+ // Cerchiamo il tag channelName che contiene il nome impostato sull'NVR
51
+ const match = data.match(/<channelName>([^<]+)<\/channelName>/i);
51
52
  if (match && match[1]) return match[1].trim();
52
- return `Canale_${channelID}`;
53
+ return `Canale ${channelID}`;
53
54
  } catch (e) {
54
- return `Camera_${channelID}`;
55
+ return `Canale ${channelID}`;
55
56
  }
56
57
  }
57
58
 
58
- // --- CONTROLLO STATUS CAMERE INTERROGANDO DIRETTAMENTE L'NVR ---
59
+ // --- CONTROLLO STATUS CAMERE (ONLINE/OFFLINE) INTERROGANDO L'NVR ---
59
60
  async function checkCameras() {
60
61
  if (isClosing || !nvrOnline) return;
61
62
  const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
@@ -72,25 +73,29 @@ module.exports = function(RED) {
72
73
 
73
74
  for (let block of channelBlocks) {
74
75
  const idMatch = block.match(/<id>(\d+)<\/id>/i);
75
- const statusMatch = block.match(/<resVerType>([^<]+)<\/resVerType>/i);
76
+ // Hikvision usa il tag <online> true/false per lo stato della telecamera IP accoppiata
77
+ const onlineMatch = block.match(/<online>([^<]+)<\/online>/i) || block.match(/<onLine>([^<]+)<\/onLine>/i);
76
78
 
77
79
  if (idMatch) {
78
80
  const ch = idMatch[1];
79
- const isOnline = statusMatch ? statusMatch[1].toLowerCase() === "online" : true;
81
+ // Se il tag dice true è online, altrimenti se dice false (o manca) è offline
82
+ const isOnline = onlineMatch ? onlineMatch[1].trim().toLowerCase() === "true" : true;
80
83
 
81
84
  if (isOnline && statoCamera[ch] === false) {
82
85
  const nomeOnline = await getCameraNameFromNVR(ch);
83
86
  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" } });
84
87
  statoCamera[ch] = true;
85
88
  } else if (!isOnline && statoCamera[ch] !== false) {
86
- 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" } });
89
+ 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" } });
87
90
  statoCamera[ch] = false;
88
91
  } else if (statoCamera[ch] === undefined) {
89
92
  statoCamera[ch] = isOnline;
90
93
  }
91
94
  }
92
95
  }
93
- } catch (e) {}
96
+ } catch (e) {
97
+ node.error(`Errore durante il check delle camere: ${e.message}`);
98
+ }
94
99
  updateNodeStatus();
95
100
  }
96
101
 
@@ -118,13 +123,12 @@ module.exports = function(RED) {
118
123
  const referenceTime = new Date();
119
124
  const timestamp = Math.floor(referenceTime.getTime() / 1000);
120
125
 
121
- // Calcolo dinamico del Track ID per il Video (canale * 100 + 1)
122
126
  const videoTrackID = (parseInt(channelID) * 100) + 1;
123
127
 
128
+ // Recupera il nome reale prima di inviare l'allarme
124
129
  const nomeCamera = await getCameraNameFromNVR(channelID);
125
130
  node.status({fill:"yellow", shape:"dot", text:`Download Cam ${channelID}...`});
126
131
 
127
- // Finestra temporale per la ricerca foto JSON
128
132
  const startSearchStr = referenceTime.toISOString().split('T')[0] + "T00:00:00 01:00";
129
133
  const endSearchStr = referenceTime.toISOString().split('T')[0] + "T23:59:59 01:00";
130
134
 
@@ -144,7 +148,7 @@ module.exports = function(RED) {
144
148
  let fileDaCancellare = [];
145
149
 
146
150
  try {
147
- // 1. SCARICAMENTO IMMAGINE (POST in JSON a eventRecordSearch)
151
+ // 1. SCARICAMENTO IMMAGINE
148
152
  const payloadFoto = {
149
153
  "EventSearchDescription": {
150
154
  "searchID": "C5AFEE35-B1E0-4C01-83F8-47FD77892E4A",
@@ -169,7 +173,6 @@ module.exports = function(RED) {
169
173
  httpsAgent: node.protocol === "https" ? httpsAgent : undefined
170
174
  });
171
175
 
172
- // CORRETTO: Adesso cerca dentro Targets e prende il pictureUrl grezzo come su Postman
173
176
  if (resFotoSearch.data?.EventSearchResult?.Targets?.[0]?.pictureUrl) {
174
177
  const urlFotoGrezzo = resFotoSearch.data.EventSearchResult.Targets[0].pictureUrl;
175
178
 
@@ -186,7 +189,7 @@ module.exports = function(RED) {
186
189
  fileDaCancellare.push(fullImgPath);
187
190
  }
188
191
 
189
- // 2. SCARICAMENTO VIDEO (POST XML a search -> GET XML a download)
192
+ // 2. SCARICAMENTO VIDEO
190
193
  const startVideoSearch = referenceTime.toISOString().split('T')[0] + "T00:00:00Z";
191
194
  const endVideoSearch = referenceTime.toISOString().split('T')[0] + "T23:59:59Z";
192
195
 
@@ -254,7 +257,6 @@ module.exports = function(RED) {
254
257
  });
255
258
  }
256
259
 
257
- // Invio dei media elaborati
258
260
  if (output.foto_base64 || output.video_base64) {
259
261
  node.send({ payload: output });
260
262
 
@@ -262,9 +264,7 @@ module.exports = function(RED) {
262
264
  for (let file of fileDaCancellare) {
263
265
  try {
264
266
  if (fs.existsSync(file)) fs.unlinkSync(file);
265
- } catch (err) {
266
- node.error(`Errore pulizia file temporaneo ${file}: ${err.message}`);
267
- }
267
+ } catch (err) {}
268
268
  }
269
269
  }, 120000);
270
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.114",
3
+ "version": "1.1.116",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",