Add adaptive per-vehicle layouts, full-panel dragging, source controls and automatic preview recovery for RealSense, Insta360 X4 and XGRIDS K1 observation views. Integrate cached Cesium map layers through the private NAS gateway link, retain bounded sensor command receipts, and document validation and operational handoff.
25 lines
1.6 KiB
TypeScript
25 lines
1.6 KiB
TypeScript
import {perform,type Sensor,type SensorTransport} from './contracts';
|
|
|
|
const pending=new Map<string,Promise<unknown>>();
|
|
export const observationSession=(device:Sensor)=>JSON.stringify([device.snapshot.context.execution.node_id,device.id,device.snapshot.context.session_id]);
|
|
/** Share an in-flight start/recovery across lens windows and React remounts. */
|
|
export function observationOperation<T>(device:Sensor,run:()=>Promise<T>):Promise<T>{
|
|
const key=observationSession(device),current=pending.get(key);if(current)return current as Promise<T>;
|
|
const task=Promise.resolve().then(run);pending.set(key,task);
|
|
const clear=()=>{if(pending.get(key)===task)pending.delete(key);};void task.then(clear,clear);return task;
|
|
}
|
|
export async function currentObservationDevice(device:Sensor,transport:SensorTransport):Promise<Sensor>{
|
|
const inventory=await transport.inventory();
|
|
const current=inventory.items.find(item=>item.id===device.id&&observationSession(item)===observationSession(device));
|
|
if(inventory.fresh===false||!current?.online||!current.prepared)throw new Error('Нет свежей связи с камерой.');
|
|
return current;
|
|
}
|
|
export function startCameraObservation(device:Sensor,transport:SensorTransport){
|
|
return observationOperation(device,async()=>{
|
|
const current=await currentObservationDevice(device,transport);
|
|
if(current.playback_id||['streaming','starting','stopping'].includes(current.snapshot.acquisition))return;
|
|
// The sensor owns its published default profiles. Observation never records.
|
|
await perform(transport,current,'start',{record:false});
|
|
});
|
|
}
|