node-red-contrib-hik-media-buffer 1.1.9 → 1.1.11
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 +31 -3
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -40,6 +40,31 @@ 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
|
+
const camAuth = new AxiosDigestAuth({
|
|
46
|
+
username: node.user,
|
|
47
|
+
password: node.camPass
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// Chiediamo le info generali del dispositivo (valido per TUTTE le Hikvision)
|
|
52
|
+
const res = await camAuth.request({
|
|
53
|
+
method: 'GET',
|
|
54
|
+
url: `${node.protocol}://${cam.ip}:${node.port}/ISAPI/System/deviceInfo`,
|
|
55
|
+
timeout: 5000
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const data = res.data.toString();
|
|
59
|
+
// Nelle info dispositivo il nome è dentro <deviceName>
|
|
60
|
+
const match = data.match(/<deviceName>([^<]+)<\/deviceName>/i);
|
|
61
|
+
|
|
62
|
+
return match ? match[1] : `Cam_${cam.ip}`;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return `Camera_${cam.ip}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
43
68
|
async function checkCameras() {
|
|
44
69
|
if (isClosing) return;
|
|
45
70
|
for (let cam of node.cameras) {
|
|
@@ -52,14 +77,16 @@ module.exports = function(RED) {
|
|
|
52
77
|
httpsAgent: node.protocol === "https" ? httpsAgent : undefined
|
|
53
78
|
});
|
|
54
79
|
if (statoCamera[cam.ip] === false) {
|
|
55
|
-
|
|
80
|
+
const nomeOnline = await getCameraName(cam);
|
|
81
|
+
node.send({ payload: { status: "online", nomeCliente: node.name, nome_telecamera: nomeOnline, ip: cam.ip, channel: cam.channel, msg: "Camera ripristinata" } });
|
|
56
82
|
statoCamera[cam.ip] = true;
|
|
57
83
|
} else if (statoCamera[cam.ip] === undefined) {
|
|
58
84
|
statoCamera[cam.ip] = true;
|
|
59
85
|
}
|
|
60
86
|
} catch (e) {
|
|
61
87
|
if (statoCamera[cam.ip] !== false) {
|
|
62
|
-
|
|
88
|
+
const nomeOffline = await getCameraName(cam);
|
|
89
|
+
node.send({ payload: { status: "offline", nomeCliente: node.name, nome_telecamera: nomeOffline, ip: cam.ip, channel: cam.channel, msg: "Camera non raggiungibile" } });
|
|
63
90
|
statoCamera[cam.ip] = false;
|
|
64
91
|
}
|
|
65
92
|
}
|
|
@@ -82,6 +109,7 @@ module.exports = function(RED) {
|
|
|
82
109
|
|
|
83
110
|
async function downloadMedia(evento, channelID) {
|
|
84
111
|
const camera = node.cameras.find(c => c.channel == channelID);
|
|
112
|
+
const nomeCamera = await getCameraName(camera);
|
|
85
113
|
if (!camera) return;
|
|
86
114
|
|
|
87
115
|
const nowTime = Date.now();
|
|
@@ -98,7 +126,7 @@ module.exports = function(RED) {
|
|
|
98
126
|
await new Promise(resolve => setTimeout(resolve, 6000));
|
|
99
127
|
|
|
100
128
|
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 };
|
|
129
|
+
let output = { ip: camera.ip, nomeCliente: node.name, nome_telecamera: nomeCamera, channel: channelID, event: evento, videoPath: null, imageBuffer: null, imagePath: null };
|
|
102
130
|
|
|
103
131
|
try {
|
|
104
132
|
const tracks = [{ id: "201" }, { id: "203" }];
|