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.
- package/hik-media-buffer.js +32 -29
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -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
|
|
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
|
-
//
|
|
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/
|
|
69
|
-
timeout:
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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 (
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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));
|