node-red-contrib-hik-media-buffer 1.1.120 → 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.
- package/hik-media-buffer.js +25 -35
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -62,52 +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'endpoint di status centralizzato in JSON, esente da blocchi 403
|
|
65
66
|
const res = await nvrAuth.request({
|
|
66
67
|
method: 'GET',
|
|
67
|
-
url: `${node.protocol}://${node.host}:${node.port}/ISAPI/
|
|
68
|
+
url: `${node.protocol}://${node.host}:${node.port}/ISAPI/System/Video/inputs/channels/status?format=json`,
|
|
68
69
|
timeout: 6000,
|
|
69
70
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
70
71
|
});
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const channelBlocks = xml.match(/<InputProxyChannel>[\s\S]*?<\/InputProxyChannel>/g) || [];
|
|
73
|
+
// Il manuale specifica la struttura: VideoInputChannelStatusList -> VideoInputChannelStatus
|
|
74
|
+
const statusList = res.data?.VideoInputChannelStatusList?.VideoInputChannelStatus || [];
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (isOnline && statoCamera[ch] === false) {
|
|
97
|
-
const nomeOnline = await getCameraNameFromNVR(ch);
|
|
98
|
-
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" } });
|
|
99
|
-
statoCamera[ch] = true;
|
|
100
|
-
} else if (!isOnline && statoCamera[ch] !== false && statoCamera[ch] !== undefined) {
|
|
101
|
-
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" } });
|
|
102
|
-
statoCamera[ch] = false;
|
|
103
|
-
} else if (statoCamera[ch] === undefined) {
|
|
104
|
-
// Boot iniziale: salva lo stato rilevato senza inviare messaggi spuri
|
|
105
|
-
statoCamera[ch] = isOnline;
|
|
106
|
-
}
|
|
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;
|
|
107
96
|
}
|
|
108
97
|
}
|
|
109
98
|
} catch (e) {
|
|
110
|
-
|
|
99
|
+
// Se la GET fallisce del tutto, significa che l'NVR stesso è offline
|
|
100
|
+
node.error(`Errore nel check diagnostico JSON: ${e.message}`);
|
|
111
101
|
}
|
|
112
102
|
updateNodeStatus();
|
|
113
103
|
}
|