@trillboards/edge-sdk 0.2.273 → 0.2.276

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.
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ const fs=require('node:fs'),crypto=require('node:crypto');
3
+ const hash=bytes=>crypto.createHash('sha256').update(bytes).digest('hex');
4
+ /**
5
+ * floor_object_left_v2's trail (edge-sdk src/FloorObjects.ts): this camera's own frames from sinceMs (the floor
6
+ * memory's last look, whose own frame comes first while the archive still holds it) up to the look under review, at
7
+ * least pitchMs apart, oldest first, at most maxFrames (a longer gap widens the pitch to fit). The archive keeps every
8
+ * grab (intervalMs, 0.5 s) for archiveRetentionMs (10 min), linked by previousCaptureId, so a 30 s look gap holds ~60
9
+ * grabs and a 4 s pitch hands the method 8. The walk stops at the first record the archive no longer holds, another
10
+ * camera's, or one out of capture order; a frame whose bytes no longer match its record is left out. Never throws: the
11
+ * trail is evidence for the method, never a reason to fail the look.
12
+ */
13
+ function resolveHeldFrames(archive,current,sinceMs,pitchMs,maxFrames){
14
+ if(!Number.isSafeInteger(sinceMs)||!(sinceMs<current.capturedAt)||!Number.isSafeInteger(pitchMs)||pitchMs<0
15
+ ||!Number.isSafeInteger(maxFrames)||maxFrames<1)return [];
16
+ const chain=[];
17
+ try{
18
+ let id=current.previousCaptureId,lastAt=current.capturedAt,walked=0;
19
+ while(id&&walked++<4096){
20
+ const r=archive.records.get(id);
21
+ if(!r||r.cameraId!==current.cameraId||!(r.capturedAt<lastAt)||r.capturedAt<sinceMs)break;
22
+ chain.push(r);lastAt=r.capturedAt;id=r.previousCaptureId;
23
+ }
24
+ }catch{return [];}
25
+ chain.reverse();
26
+ if(!chain.length)return [];
27
+ const pitch=Math.max(pitchMs,Math.ceil((current.capturedAt-chain[0].capturedAt)/maxFrames));
28
+ const out=[];
29
+ for(const r of chain){
30
+ if(out.length&&r.capturedAt-out[out.length-1].capturedAtMs<pitch)continue;
31
+ let jpeg;
32
+ try{jpeg=fs.readFileSync(archive.image(r));}catch{continue;}
33
+ if(jpeg.length!==r.imageBytes||hash(jpeg)!==r.imageSha256)continue;
34
+ out.push({capturedAtMs:r.capturedAt,jpeg});
35
+ if(out.length>=maxFrames)break;
36
+ }
37
+ return out;
38
+ }
39
+ module.exports={resolveHeldFrames};