node-red-contrib-hik-media-buffer 1.1.8 → 1.1.10
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 +22 -4
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -40,6 +40,22 @@ module.exports = function(RED) {
|
|
|
40
40
|
|
|
41
41
|
function toHikDate(d) { return d.toISOString().split('.')[0] + "Z"; }
|
|
42
42
|
|
|
43
|
+
// --- PRENDE IL NOME DELLA TELECAMERA ---
|
|
44
|
+
async function getCameraName(cam) {
|
|
45
|
+
try {
|
|
46
|
+
const res = await hikRequest({
|
|
47
|
+
method: 'GET',
|
|
48
|
+
url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/Video/inputs/channels/${cam.channel}`,
|
|
49
|
+
user: node.user,
|
|
50
|
+
pass: node.camPass
|
|
51
|
+
});
|
|
52
|
+
const match = res.data.match(/<name>([^<]+)<\/name>/);
|
|
53
|
+
return match ? match[1] : `Cam_${cam.channel}`;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return `Camera_${cam.ip}`; // Fallback se la camera è già offline
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
async function checkCameras() {
|
|
44
60
|
if (isClosing) return;
|
|
45
61
|
for (let cam of node.cameras) {
|
|
@@ -52,14 +68,16 @@ module.exports = function(RED) {
|
|
|
52
68
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
53
69
|
});
|
|
54
70
|
if (statoCamera[cam.ip] === false) {
|
|
55
|
-
|
|
71
|
+
const nomeOnline = await getCameraName(cam);
|
|
72
|
+
node.send({ payload: { status: "online", nomeCliente: node.name, nome_telecamera: nomeOnline, ip: cam.ip, channel: cam.channel, msg: "Camera ripristinata" } });
|
|
56
73
|
statoCamera[cam.ip] = true;
|
|
57
74
|
} else if (statoCamera[cam.ip] === undefined) {
|
|
58
75
|
statoCamera[cam.ip] = true;
|
|
59
76
|
}
|
|
60
77
|
} catch (e) {
|
|
61
78
|
if (statoCamera[cam.ip] !== false) {
|
|
62
|
-
|
|
79
|
+
const nomeOffline = await getCameraName(cam);
|
|
80
|
+
node.send({ payload: { status: "offline", nomeCliente: node.name, nome_telecamera: nomeOffline, ip: cam.ip, channel: cam.channel, msg: "Camera non raggiungibile" } });
|
|
63
81
|
statoCamera[cam.ip] = false;
|
|
64
82
|
}
|
|
65
83
|
}
|
|
@@ -82,6 +100,7 @@ module.exports = function(RED) {
|
|
|
82
100
|
|
|
83
101
|
async function downloadMedia(evento, channelID) {
|
|
84
102
|
const camera = node.cameras.find(c => c.channel == channelID);
|
|
103
|
+
const nomeCamera = await getCameraName(camera);
|
|
85
104
|
if (!camera) return;
|
|
86
105
|
|
|
87
106
|
const nowTime = Date.now();
|
|
@@ -98,7 +117,7 @@ module.exports = function(RED) {
|
|
|
98
117
|
await new Promise(resolve => setTimeout(resolve, 6000));
|
|
99
118
|
|
|
100
119
|
const baseUrl = `${node.protocol}://${camera.ip}:${node.port}/ISAPI/ContentMgmt`;
|
|
101
|
-
let output = { ip: camera.ip, nomeCliente: node.name, channel: channelID, event: evento, videoPath: null, imageBuffer: null, imagePath: null };
|
|
120
|
+
let output = { ip: camera.ip, nomeCliente: node.name, nome_telecamera: nomeCamera, channel: channelID, event: evento, videoPath: null, imageBuffer: null, imagePath: null };
|
|
102
121
|
|
|
103
122
|
try {
|
|
104
123
|
const tracks = [{ id: "201" }, { id: "203" }];
|
|
@@ -144,7 +163,6 @@ module.exports = function(RED) {
|
|
|
144
163
|
resolve();
|
|
145
164
|
});
|
|
146
165
|
});
|
|
147
|
-
setTimeout(() => { if (output.videoPath && fs.existsSync(output.videoPath)) fs.unlinkSync(output.videoPath); }, 180000);
|
|
148
166
|
}
|
|
149
167
|
}
|
|
150
168
|
}
|