node-red-contrib-hik-media-buffer 1.1.48 → 1.1.50
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 +11 -8
- package/package.json +1 -1
package/hik-media-buffer.js
CHANGED
|
@@ -78,7 +78,7 @@ module.exports = function(RED) {
|
|
|
78
78
|
while ((matchBlocco = bloccoRegex.exec(xmlData)) !== null) {
|
|
79
79
|
const bloccoContenuto = matchBlocco[1];
|
|
80
80
|
|
|
81
|
-
const idMatch =
|
|
81
|
+
const idMatch = bloccoContenuto.match(/<id>(\d+)<\/id>/i);
|
|
82
82
|
const statusMatch = bloccoContenuto.match(/<status>([^<]+)</i);
|
|
83
83
|
|
|
84
84
|
if (idMatch && statusMatch) {
|
|
@@ -118,7 +118,7 @@ module.exports = function(RED) {
|
|
|
118
118
|
|
|
119
119
|
const heartbeatInterval = setInterval(checkCameras, 30000);
|
|
120
120
|
|
|
121
|
-
// --- DOWNLOAD MULTIMEDIALE
|
|
121
|
+
// --- DOWNLOAD MULTIMEDIALE CON DIFFERENZIAZIONE XML VIDEO/FOTO ---
|
|
122
122
|
async function downloadMedia(evento, channelID) {
|
|
123
123
|
const nowTime = Date.now();
|
|
124
124
|
if (!lastTriggerTime[channelID]) lastTriggerTime[channelID] = 0;
|
|
@@ -130,7 +130,6 @@ module.exports = function(RED) {
|
|
|
130
130
|
const referenceTime = new Date();
|
|
131
131
|
const timestamp = Math.floor(referenceTime.getTime() / 1000);
|
|
132
132
|
|
|
133
|
-
// Finestra temporale basata sulle date ISO
|
|
134
133
|
const startTime = toHikDate(new Date(referenceTime.getTime() - (20 * 1000)));
|
|
135
134
|
const endTime = toHikDate(new Date(referenceTime.getTime() + (20 * 1000)));
|
|
136
135
|
|
|
@@ -140,7 +139,6 @@ module.exports = function(RED) {
|
|
|
140
139
|
await new Promise(resolve => setTimeout(resolve, 6000));
|
|
141
140
|
const baseUrl = `${node.protocol}://${node.host}:${node.port}/ISAPI/ContentMgmt`;
|
|
142
141
|
|
|
143
|
-
// Ricostruiamo l'evento con il case-sensitive corretto per l'NVR (FieldDetection / LineDetection)
|
|
144
142
|
let eventoNVR = "FieldDetection";
|
|
145
143
|
for (let e of EventList) {
|
|
146
144
|
if (evento.toLowerCase() === e.toLowerCase()) {
|
|
@@ -174,8 +172,15 @@ module.exports = function(RED) {
|
|
|
174
172
|
|
|
175
173
|
try {
|
|
176
174
|
for (let t of tracks) {
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
let searchXml = "";
|
|
176
|
+
|
|
177
|
+
if (t.isFoto) {
|
|
178
|
+
// XML CLONATO DALL'ISPEZIONA IMMAGINI: Per cercare le foto (metadata)
|
|
179
|
+
searchXml = `<?xml version="1.0" encoding="utf-8"?><CMSearchDescription><searchID>LAST_EVENT</searchID><trackIDList><trackID>${t.id}</trackID></trackIDList><timeSpanList><timeSpan><startTime>${startTime}</startTime><endTime>${endTime}</endTime></timeSpan></timeSpanList><contentTypeList><contentType>metadata</contentType></contentTypeList><maxResults>30</maxResults><metadataList><metadataDescriptor>recordType.meta.hikvision.com/${eventoNVR}</metadataDescriptor></metadataList></CMSearchDescription>`;
|
|
180
|
+
} else {
|
|
181
|
+
// XML ADATTATO PER I VIDEO: Cambiato il contentType in video per non mandare l'NVR in errore 400
|
|
182
|
+
searchXml = `<?xml version="1.0" encoding="utf-8"?><CMSearchDescription><searchID>LAST_EVENT</searchID><trackIDList><trackID>${t.id}</trackID></trackIDList><timeSpanList><timeSpan><startTime>${startTime}</startTime><endTime>${endTime}</endTime></timeSpan></timeSpanList><contentTypeList><contentType>video</contentType></contentTypeList><maxResults>30</maxResults><metadataList><metadataDescriptor>recordType.meta.hikvision.com/${eventoNVR}</metadataDescriptor></metadataList></CMSearchDescription>`;
|
|
183
|
+
}
|
|
179
184
|
|
|
180
185
|
const resSearch = await camAuth.request({
|
|
181
186
|
method: 'POST', url: `${baseUrl}/search`, data: searchXml, headers: { "Content-Type": "application/xml" }
|
|
@@ -195,13 +200,11 @@ module.exports = function(RED) {
|
|
|
195
200
|
|
|
196
201
|
let buffer = Buffer.from(resDown.data);
|
|
197
202
|
if (t.isFoto) {
|
|
198
|
-
// SALVA FOTO TERMICA NATIVA IN LOCALE
|
|
199
203
|
const fullImgPath = path.join(baseStorage, `img_${timestamp}.jpg`);
|
|
200
204
|
fs.writeFileSync(fullImgPath, buffer);
|
|
201
205
|
output.foto_base64 = fs.readFileSync(fullImgPath, { encoding: 'base64' });
|
|
202
206
|
fileDaCancellare.push(fullImgPath);
|
|
203
207
|
} else {
|
|
204
|
-
// SALVA VIDEO IN LOCALE
|
|
205
208
|
if (buffer.slice(0, 4).toString() === 'IMKH') buffer = buffer.slice(40);
|
|
206
209
|
const rawPath = path.join(baseStorage, `raw_${timestamp}.mp4`);
|
|
207
210
|
const fixedPath = path.join(baseStorage, `hik_v_${channelID}_${timestamp}.mp4`);
|