node-red-contrib-hik-media-buffer 1.1.22 → 1.1.24
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 +16 -17
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -29,7 +29,7 @@ module.exports = function(RED) {
|
|
|
29
29
|
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
30
30
|
const EventList = ["FieldDetection", "LineDetection"];
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// CARTELLA TEMPORANEA
|
|
33
33
|
const baseStorage = path.join(os.tmpdir(), "hik_temp_media");
|
|
34
34
|
if (!fs.existsSync(baseStorage)) fs.mkdirSync(baseStorage, { recursive: true });
|
|
35
35
|
|
|
@@ -48,7 +48,7 @@ module.exports = function(RED) {
|
|
|
48
48
|
const res = await camAuth.request({
|
|
49
49
|
method: 'GET',
|
|
50
50
|
url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/Video/inputs/channels/${cam.channel}/overlays/channelNameOverlay`,
|
|
51
|
-
timeout:
|
|
51
|
+
timeout: 3000,
|
|
52
52
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -62,7 +62,7 @@ module.exports = function(RED) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
} catch (e) {
|
|
65
|
-
return `Camera_${cam.
|
|
65
|
+
return `Camera_${cam.channel}`;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -75,7 +75,7 @@ module.exports = function(RED) {
|
|
|
75
75
|
await camAuth.request({
|
|
76
76
|
method: 'GET',
|
|
77
77
|
url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/deviceInfo`,
|
|
78
|
-
timeout:
|
|
78
|
+
timeout: 3000,
|
|
79
79
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
80
80
|
});
|
|
81
81
|
if (statoCamera[cam.ip] === false) {
|
|
@@ -87,8 +87,7 @@ module.exports = function(RED) {
|
|
|
87
87
|
}
|
|
88
88
|
} catch (e) {
|
|
89
89
|
if (statoCamera[cam.ip] !== false) {
|
|
90
|
-
|
|
91
|
-
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: nomeOffline, ip_telecamera: cam.ip, channel: cam.channel, msg: "Camera non raggiungibile" } });
|
|
90
|
+
node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", nome_cliente: node.name, nome_telecamera: `Camera_${cam.channel}`, ip_telecamera: cam.ip, channel: cam.channel, msg: "Camera non raggiungibile" } });
|
|
92
91
|
statoCamera[cam.ip] = false;
|
|
93
92
|
}
|
|
94
93
|
}
|
|
@@ -107,7 +106,7 @@ module.exports = function(RED) {
|
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
const heartbeatInterval = setInterval(checkCameras,
|
|
109
|
+
const heartbeatInterval = setInterval(checkCameras, 10000);
|
|
111
110
|
|
|
112
111
|
// --- DOWNLOAD, SALVATAGGIO, CONVERSIONE E RIMOZIONE DOPO 2 MINUTI ---
|
|
113
112
|
async function downloadMedia(evento, channelID) {
|
|
@@ -130,7 +129,7 @@ module.exports = function(RED) {
|
|
|
130
129
|
|
|
131
130
|
const baseUrl = `${node.protocol}://${camera.ip}:${node.port}/ISAPI/ContentMgmt`;
|
|
132
131
|
|
|
133
|
-
//
|
|
132
|
+
// struttura del payload per Python
|
|
134
133
|
let output = {
|
|
135
134
|
tipo_messaggio: "evento",
|
|
136
135
|
nome_cliente: node.name,
|
|
@@ -144,7 +143,7 @@ module.exports = function(RED) {
|
|
|
144
143
|
video_base64: null
|
|
145
144
|
};
|
|
146
145
|
|
|
147
|
-
|
|
146
|
+
|
|
148
147
|
let fileDaCancellare = [];
|
|
149
148
|
|
|
150
149
|
try {
|
|
@@ -170,7 +169,7 @@ module.exports = function(RED) {
|
|
|
170
169
|
|
|
171
170
|
let buffer = Buffer.from(resDown.data);
|
|
172
171
|
if (t.id === "203") {
|
|
173
|
-
//
|
|
172
|
+
// SALVA FOTO IN LOCALE
|
|
174
173
|
const fullImgPath = path.join(baseStorage, `img_${timestamp}.jpg`);
|
|
175
174
|
fs.writeFileSync(fullImgPath, buffer);
|
|
176
175
|
|
|
@@ -180,13 +179,13 @@ module.exports = function(RED) {
|
|
|
180
179
|
// Registriamo il file per la distruzione futura
|
|
181
180
|
fileDaCancellare.push(fullImgPath);
|
|
182
181
|
} else {
|
|
183
|
-
//
|
|
182
|
+
// SALVA VIDEO IN LOCALE-
|
|
184
183
|
if (buffer.slice(0, 4).toString() === 'IMKH') buffer = buffer.slice(40);
|
|
185
184
|
const rawPath = path.join(baseStorage, `raw_${timestamp}.mp4`);
|
|
186
185
|
const fixedPath = path.join(baseStorage, `hik_v_${channelID}_${timestamp}.mp4`);
|
|
187
186
|
fs.writeFileSync(rawPath, buffer);
|
|
188
187
|
|
|
189
|
-
// Eseguiamo ffmpeg localmente
|
|
188
|
+
// Eseguiamo ffmpeg localmente
|
|
190
189
|
await new Promise((resolve) => {
|
|
191
190
|
exec(`ffmpeg -y -i "${rawPath}" -c copy -movflags +faststart "${fixedPath}"`, (err) => {
|
|
192
191
|
if (!err && fs.existsSync(fixedPath)) {
|
|
@@ -207,7 +206,7 @@ module.exports = function(RED) {
|
|
|
207
206
|
if (output.foto_base64 || output.video_base64) {
|
|
208
207
|
node.send({ payload: output });
|
|
209
208
|
|
|
210
|
-
//
|
|
209
|
+
// TIMER A 2 MINUTI PER LA PULIZIA DEL DISCO
|
|
211
210
|
setTimeout(() => {
|
|
212
211
|
for (let file of fileDaCancellare) {
|
|
213
212
|
try {
|
|
@@ -218,7 +217,7 @@ module.exports = function(RED) {
|
|
|
218
217
|
node.error(`Errore durante la pulizia del file temporaneo ${file}: ${err.message}`);
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
|
-
}, 120000);
|
|
220
|
+
}, 120000);
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
} catch (e) {
|
|
@@ -232,7 +231,7 @@ module.exports = function(RED) {
|
|
|
232
231
|
if (isClosing) return;
|
|
233
232
|
const nvrAuth = new AxiosDigestAuth({ username: node.user, password: node.pass });
|
|
234
233
|
const url = `${node.protocol}://${node.host}:${node.port}/ISAPI/Event/notification/alertStream`;
|
|
235
|
-
nvrAuth.request({ method: 'GET', url: url, responseType: 'stream', httpsAgent: node.protocol === "https" ? httpsAgent : undefined })
|
|
234
|
+
nvrAuth.request({ method: 'GET', url: url, responseType: 'stream', timeout:4000, httpsAgent: node.protocol === "https" ? httpsAgent : undefined })
|
|
236
235
|
.then(response => {
|
|
237
236
|
streamRequest = response;
|
|
238
237
|
if (!nvrOnline) { node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "online", ip: node.host, msg: "NVR Online", nome_cliente: node.name } }); nvrOnline = true; }
|
|
@@ -249,14 +248,14 @@ module.exports = function(RED) {
|
|
|
249
248
|
}
|
|
250
249
|
});
|
|
251
250
|
response.data.on('error', () => handleNvrError());
|
|
252
|
-
response.data.on('end', () => !isClosing && setTimeout(startAlertStream,
|
|
251
|
+
response.data.on('end', () => !isClosing && setTimeout(startAlertStream, 1000));
|
|
253
252
|
}).catch(() => handleNvrError());
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
function handleNvrError() {
|
|
257
256
|
if (nvrOnline) { node.send({ payload: { tipo_messaggio: "status", stato_telecamera: "offline", ip: node.host, msg: "NVR Offline", nome_cliente: node.name } }); nvrOnline = false; }
|
|
258
257
|
updateNodeStatus();
|
|
259
|
-
if (!isClosing) setTimeout(startAlertStream,
|
|
258
|
+
if (!isClosing) setTimeout(startAlertStream, 3000);
|
|
260
259
|
}
|
|
261
260
|
|
|
262
261
|
startAlertStream();
|