UNPKG

@scandit/web-datacapture-core

Version:

Scandit Data Capture SDK for the Web

1 lines 2.73 kB
import {a}from'./chunk-LFJUGRQV.js';import {a as a$1}from'./chunk-XR65N6EG.js';var p=class{constructor(){this.cameraPool=new Set;}getOrCreate(a$1){var e;let{position:l,deviceId:n,label:s}=a$1,c=(e=a$1._isBestGuess)!=null?e:false;if(this.cameraPool.size===0)return this.push(a$1);let o=this.allCamerasNoDeviceId(),i=Array.from(this.cameraPool);if(n){let t=i.find(r=>r.deviceId===n);if(t)return t;if(o){let r=i.find(h=>h.position===l);if(r)return r[a].setDeviceId(n),r[a].setLabel(s),r}}if(c){let t=i.find(r=>r._isBestGuess);if(t)return t}if(o&&!n){let t=i.find(r=>r.position===l);if(t)return t}return this.push(a$1)}integrateIncomingVideoDevices(a$2){let l=Array.from(this.cameraPool),n=new Set,s=[...a$2].reverse();for(let o=s.length-1;o>=0;o--){let i=s[o];if(!i.deviceId)continue;let e=l.find(t=>t.deviceId===i.deviceId&&!n.has(t));e&&(e[a].setLabel(i.label),e.position=i.position,n.add(e),s.splice(o,1),this.debugLog("Updated pool camera by deviceId",{deviceId:e.deviceId,label:e.label,position:e.position}));}for(let o=s.length-1;o>=0;o--){let i=s[o],e=l.find(t=>t.position===i.position&&!n.has(t));e&&(e[a].setDeviceId(i.deviceId),e[a].setLabel(i.label),n.add(e),s.splice(o,1),this.debugLog("Updated pool camera by position",{deviceId:e.deviceId,label:e.label,position:e.position}));}if(s.length>0){let o=l.filter(i=>!n.has(i));if(o.length>0){for(let i=0;i<Math.min(s.length,o.length);i++){let e=o[i],t=s[i];e[a].setDeviceId(t.deviceId),e[a].setLabel(t.label),e.position=t.position,n.add(e),this.debugLog("Force updated pool camera",{deviceId:e.deviceId,label:e.label,position:e.position});}s.splice(0,Math.min(s.length,o.length));}for(let i of s)this.cameraPool.add(i),this.debugLog("Added new camera to pool",{deviceId:i.deviceId,label:i.label,position:i.position});}let c=l.filter(o=>!n.has(o));if(c.length>0){a$1.warn("Some cameras were created but could not be mapped to cameras found on the device. This happens when you create more Cameras than it exists. These cameras will not be accessible.");for(let o of c)a$1.warn("Removing non-updated camera:",{deviceId:o.deviceId,label:o.label,position:o.position}),o[a].markAsUnmappedToDeviceCameras(),this.cameraPool.delete(o);}this.debugLog("Camera pool state after reconciliation:"),this.logPool();}allCamerasNoDeviceId(){return Array.from(this.cameraPool).every(a=>a.deviceId==="")}get(){return Array.from(this.cameraPool)}push(a){return this.debugLog("adding camera to pool",JSON.stringify({deviceId:a.deviceId,position:a.position,label:a.label})),this.cameraPool.add(a),a}debugLog(...a){}logPool(){}dumpAsSimpleObjects(){return [...this.cameraPool].map(a=>({deviceId:a.deviceId,label:a.label,position:a.position}))}},v={[a]:{CameraPool:p}};var u=new p;export{v as a,u as b};