node-red-contrib-hik-media-buffer 1.1.12 → 1.1.13

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 +21 -18
  2. package/package.json +1 -1
@@ -48,36 +48,39 @@ module.exports = function(RED) {
48
48
  });
49
49
 
50
50
  try {
51
- console.log(`\n--- INIZIO RISPOSTA XML DA ${cam.ip} ---`);
52
-
51
+ // Interroghiamo il CANALE specifico (es. /channels/2)
53
52
  const res = await camAuth.request({
54
53
  method: 'GET',
55
- url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/deviceInfo`,
54
+ url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/Video/inputs/channels/${cam.channel}`,
56
55
  timeout: 5000,
57
56
  httpsAgent: node.protocol === "https" ? httpsAgent : undefined
58
57
  });
59
58
 
60
- // Stampiamo TUTTO l'XML ricevuto
61
- const xmlCompleto = res.data.toString();
62
- console.log(xmlCompleto);
63
- console.log(`--- FINE RISPOSTA XML ---\n`);
64
-
65
- // Proviamo a estrarre il nome (cambieremo la regex dopo aver visto il log)
66
- const match = xmlCompleto.match(/<deviceName>([^<]+)<\/deviceName>/i);
59
+ const data = res.data.toString();
60
+
61
+ // In questo XML il tag è solitamente <name>
62
+ const match = data.match(/<name>([^<]+)<\/name>/i);
67
63
 
68
- if (match) {
69
- return match[1];
64
+ if (match && match[1]) {
65
+ return match[1].trim(); // Restituirà "Ufficio"
70
66
  } else {
71
- return `Tag_Non_Trovato_${cam.ip}`;
67
+ return `Canale_${cam.channel}`;
72
68
  }
73
69
 
74
70
  } catch (e) {
75
- console.log(`[ERRORE] Chiamata fallita a ${cam.ip}: ${e.message}`);
76
- if (e.response) {
77
- // Se la camera risponde con un errore (es. 401 Unauthorized) lo vediamo qui
78
- console.log(`[ERRORE] Dati tecnici:`, e.response.data.toString());
71
+ // Se l'URL sopra fallisce (alcuni modelli vecchi), proviamo questo URL alternativo
72
+ try {
73
+ const resAlt = await camAuth.request({
74
+ method: 'GET',
75
+ url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/ContentMgmt/InputProxy/channels/${cam.channel}`,
76
+ timeout: 3000
77
+ });
78
+ const dataAlt = resAlt.data.toString();
79
+ const matchAlt = dataAlt.match(/<name>([^<]+)<\/name>/i);
80
+ return matchAlt ? matchAlt[1].trim() : `Cam_${cam.channel}`;
81
+ } catch (err) {
82
+ return `Camera_${cam.ip}`;
79
83
  }
80
- return `Errore_Connessione_${cam.ip}`;
81
84
  }
82
85
  }
83
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-hik-media-buffer",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Ottiene buffer video e immagine da camere Hikvision via ISAPI",
5
5
  "keywords": [
6
6
  "node-red",