@formant/data-sdk 1.39.0 → 1.41.0
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/dist/data-sdk.cjs.js +1 -1
- package/dist/data-sdk.cjs.js.map +1 -1
- package/dist/data-sdk.es.js +149 -135
- package/dist/data-sdk.es.js.map +1 -1
- package/dist/data-sdk.es6.js +149 -135
- package/dist/data-sdk.umd.js +1 -1
- package/dist/types/data-sdk/src/connector/model/IUniverseGridMap.d.ts +1 -1
- package/dist/types/data-sdk/src/model/ILabelingRequestData.d.ts +1 -0
- package/package.json +1 -1
package/dist/data-sdk.cjs.js
CHANGED
|
@@ -99,5 +99,5 @@ Found: ${s.toString().split(`
|
|
|
99
99
|
|
|
100
100
|
gl_FragColor = vec4(y, u, v, 1) * YUV2RGB;
|
|
101
101
|
}
|
|
102
|
-
`,o=[1.16438,0,1.59603,-.87079,1.16438,-.39176,-.81297,.52959,1.16438,2.01723,0,-1.08139,0,0,0,1],s=t.createShader(t.VERTEX_SHADER);if(!s)throw new Error("Failed to create vertex shader");t.shaderSource(s,r),t.compileShader(s);const g=t.createShader(t.FRAGMENT_SHADER);if(!g)throw new Error("Failed to create fragment shader");t.shaderSource(g,n),t.compileShader(g);const l=t.createProgram();if(!l)throw new Error("Failed to create webgl program");t.attachShader(l,s),t.attachShader(l,g),t.linkProgram(l),t.useProgram(l);const u=t.getUniformLocation(l,"YUV2RGB");return t.uniformMatrix4fv(u,!1,o),l}initBuffers(){const{gl:t,program:r}=this,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),t.STATIC_DRAW);const o=t.getAttribLocation(r,"vertexPos");t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0);const s=t.createBuffer();if(!s)throw new Error("Failed to create WebGL buffer");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),t.STATIC_DRAW);const g=t.getAttribLocation(r,"texturePos");return t.enableVertexAttribArray(g),t.vertexAttribPointer(g,2,t.FLOAT,!1,0,0),{texturePosBuffer:s}}initTextures(){const{gl:t,program:r}=this,n=this.initTexture(),o=t.getUniformLocation(r,"yuvSampler");return t.uniform1i(o,0),{textureRef:n}}initTexture(){const{gl:t}=this,r=t.createTexture();if(!r)throw new Error("Failed to initialize texture");return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null),r}}const decoderNotWorkingThreshold=duration$1.second*2.5,warnPerformanceThreshold=duration$1.second/3,noSignalThreshold=duration$1.second*2,maxQueueSize=5,maxDropRatio=30/25,numRetries=5,hardwareIncompatibleErrorCode=1282;class H264BytestreamCanvasDrawer{constructor(t,r,n,o,s){__publicField(this,"_waitingForDecoder",!0),__publicField(this,"_noSignal",!0),__publicField(this,"_lostSignal",!1),__publicField(this,"_overWaitingThreshold",!1),__publicField(this,"_retries",0),__publicField(this,"_webglYUVSupported"),__publicField(this,"lastDecodedFrameTime"),__publicField(this,"lastReceivedFrameTime"),__publicField(this,"lastNoSignalTime",new Date().getTime()),__publicField(this,"moduleStartTime",Date.now()),__publicField(this,"moduleCreateTime",Date.now()),__publicField(this,"timesRestarted",0),__publicField(this,"canvas"),__publicField(this,"decoder"),__publicField(this,"yuvCanvas"),__publicField(this,"webglContext"),__publicField(this,"frameQueue",[]),__publicField(this,"minFrameSize",1/0),__publicField(this,"maxFrameSize",0),__publicField(this,"decoderQueue",[]),__publicField(this,"decoderQueueLocked",!1),__publicField(this,"decodeNextFrameAttempted",!1),__publicField(this,"numFramesDecoded",0),__publicField(this,"numFramesReceived",0),__publicField(this,"hasReceivedKeyframe",!1),__publicField(this,"medianFrameSize",0),__publicField(this,"currentFrameIndex"),__publicField(this,"frameCheckpointMap",new Map),__publicField(this,"lastDrawnFrameTime"),__publicField(this,"minJitter"),__publicField(this,"maxJitter"),__publicField(this,"start",()=>{const{canvas:g}=this;if(!g)return;const l=g.getContext("webgl");this.webglContext=l||void 0,this.lastDecodedFrameTime=void 0,this.lastReceivedFrameTime=void 0,this.hasReceivedKeyframe=!1,this.currentFrameIndex=void 0,!(!this.canvas||!this.webglContext)&&(this.yuvCanvas||(this.yuvCanvas=new YUVCanvas(this.webglContext)),this.moduleStartTime=Date.now())}),__publicField(this,"stop",()=>{var g;(g=this.decoder)==null||g.release(),this.webglContext=void 0,this.decoderQueueLocked=!1}),__publicField(this,"reset",()=>{this.retries=0,this.restart()}),__publicField(this,"notifyWarningTextChanged",()=>{var g;(g=this.onWarningTextChanged)==null||g.call(this,this.getWarningText())}),__publicField(this,"restart",()=>{console.info("Restarting decoder"),console.info("BytestreamPlayer restarting",__spreadProps(__spreadValues({},this.trackInfo),{Restart:this.timesRestarted})),this.frameQueue=[],this.decoderQueue=[],this.stop(),this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),this.start(),this.retries++,this.timesRestarted++}),__publicField(this,"onTrackTick",()=>{if(this.numFramesDecoded===0){if(this.lastDecodedFrameTime===void 0){const p=Date.now();console.info("BytestreamPlayer waiting for video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Waited":p-this.moduleCreateTime}))}return}this.numFramesReceived/this.numFramesDecoded>maxDropRatio&&this.warnPerformanceProblems(),this.numFramesReceived=0,this.numFramesDecoded=0;const l=Array.from(this.frameCheckpointMap.entries()).reduce((p,[v,_])=>{var y;return!this.currentFrameIndex||v>this.currentFrameIndex-60||_==="FrameDrawn"||(p[_]=((y=p[_])!=null?y:0)+1,this.frameCheckpointMap.delete(v)),p},{});Object.keys(l).map(p=>{console.info("BytestreamPlayer Frame Dropped",__spreadProps(__spreadValues({},this.trackInfo),{"Num Dropped":l[p],"Frame State":p}))});const{minJitter:u,maxJitter:c}=this;u&&c&&(console.info("BytestreamPlayer Jitter",__spreadProps(__spreadValues({},this.trackInfo),{minJitter:u,maxJitter:c})),this.minJitter=void 0,this.maxJitter=void 0)}),__publicField(this,"onTick",()=>{var g;const{lastReceivedFrameTime:l,lastDecodedFrameTime:u,moduleStartTime:c,noSignal:p,retries:v}=this,_=new Date().getTime();p&&(this.lastNoSignalTime=_),this.overWaitingThreshold=_-c>noSignalThreshold;const y=_-c>decoderNotWorkingThreshold;if(!u){l&&y&&v<numRetries&&(this.waitingForDecoder=!0,this.restart());return}if(l){const f=_-l,h=_-u;_-this.lastNoSignalTime>noSignalThreshold&&f<warnPerformanceThreshold&&h>warnPerformanceThreshold&&this.warnPerformanceProblems(),f>noSignalThreshold&&(this.lostSignal=!0)}this.overWaitingThreshold&&(this.waitingForDecoder||this.noSignal||this.lostSignal)&&((g=this.onCanvasDrawerWarning)==null||g.call(this,"ShouldDisableControl"))}),__publicField(this,"receiveEncodedFrame",g=>{if(!g)return;const l=g.index;if(l&&this.frameCheckpointMap.set(l,"FrameReceived"),!(!g||!this.canvas||!this.webglContext)){if(this.isKeyframe(g),!this.hasReceivedKeyframe)return console.info("Dropping frame because no keyframe detected"),!1;this.lastReceivedFrameTime===void 0&&console.debug("Received first frame on bytestream player",__spreadValues({},this.trackInfo)),this.checkOrder(g),this.numFramesReceived++,this.lastReceivedFrameTime=Date.now(),this.lostSignal&&this.restart(),this.noSignal=!1,this.lostSignal=!1,this.frameQueue.push(g),l&&this.frameCheckpointMap.set(l,"FrameQueued"),this.frameQueue.length>maxQueueSize&&(this.frameQueue=this.frameQueue.filter(u=>this.isKeyframe(u))),this.frameQueue.length>maxQueueSize&&(this.frameQueue=[],this.decoderQueue=[]),this.decodeNextFrame()}}),__publicField(this,"onDecoderError",g=>{this.frameQueue=[],this.decoderQueue=[],this.hasReceivedKeyframe=!1,console.info("BytestreamPlayer decode error",__spreadProps(__spreadValues({},this.trackInfo),{"Frame Index":g}))}),__publicField(this,"onReceiveDecodedFrame",g=>{var l,u;const{canvas:c,yuvCanvas:p,decoderQueue:v}=this,{timestamp:_,yuv:y,height:f,width:h,index:w}=g;this.frameCheckpointMap.set(w,"FrameDecoded"),this.numFramesDecoded++;const C=Date.now();if(this.lastDecodedFrameTime===void 0&&console.info("BytestreamPlayer started video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Until Video":C-this.moduleCreateTime})),this.lastDecodedFrameTime=C,this.waitingForDecoder=!1,this.decoderQueue=v.filter(E=>C-E<duration$1.second*.5&&E!==_),!v.includes(_)||C-_>duration$1.second||!p||!c||f===0||h===0)return;f!==c.height&&(c.height=f,p.height=f),h!==c.width&&(c.width=h,p.width=h);const L=p.draw(y),T=Date.now();if(this.lastDrawnFrameTime){const E=T-this.lastDrawnFrameTime;this.minJitter=Math.min(E,(l=this.minJitter)!=null?l:Number.MAX_SAFE_INTEGER),this.maxJitter=Math.max(E,(u=this.maxJitter)!=null?u:0)}this.lastDrawnFrameTime=T,this.frameCheckpointMap.set(w,"FrameDrawn"),L===0&&(this.webglYUVSupported=!0),L===hardwareIncompatibleErrorCode&&(this.webglYUVSupported=!1),this.frameQueue.length>0&&this.decodeNextFrame()}),this.workerFactory=t,this.onWebglYUVSupportedChanged=r,this.onWarningTextChanged=n,this.onCanvasDrawerWarning=o,this.trackInfo=s,this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),setInterval(this.onTick,duration$1.millisecond*200),setInterval(this.onTrackTick,duration$1.second*5)}get waitingForDecoder(){return this._waitingForDecoder}set waitingForDecoder(t){this._waitingForDecoder=t,this.notifyWarningTextChanged()}get noSignal(){return this._noSignal}set noSignal(t){this._noSignal=t,this.notifyWarningTextChanged()}get lostSignal(){return this._lostSignal}set lostSignal(t){this._lostSignal=t,this.notifyWarningTextChanged()}get overWaitingThreshold(){return this._overWaitingThreshold}set overWaitingThreshold(t){this._overWaitingThreshold=t,this.notifyWarningTextChanged()}get retries(){return this._retries}set retries(t){this._retries=t,this.notifyWarningTextChanged()}get webglYUVSupported(){return this._webglYUVSupported}set webglYUVSupported(t){var r;this._webglYUVSupported=t,(r=this.onWebglYUVSupportedChanged)==null||r.call(this,t),this.notifyWarningTextChanged()}setCanvas(t){this.canvas=t}getWarningText(){var t;const{waitingForDecoder:r,noSignal:n,overWaitingThreshold:o,lostSignal:s,retries:g,webglYUVSupported:l}=this,u=l===!1,p=r?g===numRetries?"Decoder failed to start":"Starting decoder":void 0,v=u?"Hardware decoding not supported on this device":void 0,_=s?"Lost signal":n?o?"No signal":"Waiting for signal":void 0;return(t=v!=null?v:_)!=null?t:p}decodeNextFrame(){if(this.decoderQueueLocked&&(this.decodeNextFrameAttempted=!0),this.decoderQueueLocked=!0,this.decoderQueue.length>maxQueueSize){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const t=this.frameQueue.shift();if(!t){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const r=Date.now();this.frameCheckpointMap.set(t.index,"FrameSentToDecoder"),this.decoder.post(r,t.frame_data,t.flags,t.index),this.decoderQueue.push(r),this.decoderQueueLocked=!1,this.decodeNextFrameAttempted&&(this.decodeNextFrameAttempted=!1,this.decodeNextFrame())}warnPerformanceProblems(){var t;this.lastDecodedFrameTime&&this.overWaitingThreshold&&!this.lostSignal&&!this.noSignal&&((t=this.onCanvasDrawerWarning)==null||t.call(this,"ShouldDegradeVideo"))}checkOrder(t){if(this.currentFrameIndex!==void 0&&t.index<this.currentFrameIndex){console.info("Out of order frame detected"),console.info("Frame out of order",__spreadValues({},this.trackInfo));return}this.currentFrameIndex=t.index}isKeyframe(t){const{maxFrameSize:r,minFrameSize:n}=this;if(t.flags===3)return this.hasReceivedKeyframe||(this.frameCheckpointMap=new Map),this.hasReceivedKeyframe=!0,!0;const o=t.frame_data.length;return this.maxFrameSize=Math.max(o,r),this.minFrameSize=Math.min(o,n),this.medianFrameSize=(this.maxFrameSize+this.minFrameSize)/2,this.moduleStartTime+duration$1.second*2>Date.now()?!1:o>this.medianFrameSize?(this.hasReceivedKeyframe=!0,!0):!1}}const millisecond=1,second=1e3,minute=60*second,hour=60*minute,day=24*hour,week=7*day,month=30*day,year=365*day,duration={millisecond,second,minute,hour,day,week,month,year};function filterDataByType(e,t){return e.filter(r=>r.type===t)}function filterDataByTime(e,t,r){const n=t.getTime(),o=r.getTime();return e.map(s=>({...s,points:s.points.filter(([g])=>g>=n&&g<o)})).filter(({points:s})=>s.length>0)}function fork(e){}class StoreCache{constructor({capacity:t,timeout:r}={}){de(this,"entries",new Map);de(this,"metadata",new Map);de(this,"capacity");de(this,"timeout");this.capacity=t||1e4,this.timeout=r||duration.minute}get(t,r){const n=this.keyToCacheKey(t),o=this.entries.get(n),s=this.metadata.get(n);return(o===void 0||s&&(s==null?void 0:s.expiration.getTime())<Date.now())&&!(s!=null&&s.generating)&&r&&this.generate(t,r()),o===void 0&&s&&s.lastValue!==void 0?s.lastValue:o}set(t,r){const n=this.keyToCacheKey(t);this.metadata.set(n,{generating:!1,expiration:new Date(Date.now()+this.timeout),lastValue:r}),this.entries.set(n,r),this.metadata.size>this.capacity&&this.deleteOldestEntry()}clear(){this.entries.clear(),[...this.metadata.values()].forEach(t=>t.generating=!1)}clearKey(t){this.metadata.delete(t),this.entries.delete(t)}keyToCacheKey(t){return JSON.stringify(t)}deleteOldestEntry(){if(this.metadata.size<1)return;const[t]=[...this.metadata.entries()].reduce(([r,n],[o,s])=>s.expiration.getTime()<n.expiration.getTime()?[o,s]:[r,n]);this.clearKey(t)}generate(t,r){const n=this.keyToCacheKey(t),o=this.metadata.get(n)||{};this.metadata.set(n,{...o,generating:!0,expiration:new Date(Date.now()+this.timeout)}),setTimeout(()=>{r.then(s=>{const g=this.metadata.get(n);!(g!=null&&g.generating)||this.set(t,s)})},0)}}function roundToNearestSecond(e){return new Date(Math.round(e.getTime()/1e3)*1e3)}class QueryStore{constructor(){de(this,"queryStoreCache",new StoreCache({capacity:1e4,timeout:20*duration.second}));de(this,"liveQueryStoreCache",new StoreCache({capacity:1e4,timeout:1*duration.second}))}moduleQuery(t,r,n,o,s,g=!1){const l={...t,names:[r],types:[n],start:o.toISOString(),end:s.toISOString(),latestOnly:g},u=this.query(l);return u===void 0||u==="too much data"?u:filterDataByType(u,n)}query(t){const r=new Date(t.end)>addSeconds(new Date,-20),n=startOfMinute(new Date(t.start)).toISOString(),o=t.latestOnly?addSeconds(roundToNearestSecond(new Date(t.end)),5).toISOString():addMinutes(roundToNearestMinutes(new Date(t.end)),1).toISOString();let s;return r?s=this.liveQueryCache({...t,start:n,end:o}):s=this.queryCache({...t,start:n,end:o}),!s||s==="too much data"||t.latestOnly?s:filterDataByTime(s,new Date(t.start),new Date(t.end))}queryCache(t){return this.queryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}liveQueryCache(t){return this.liveQueryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}}const debug=new URLSearchParams(window.location.search).get("debug")==="true",PCD_WORKER_POOL_SIZE=5,DATA_FETCH_WORKER_POOL_SIZE=10;class BasicUniverseDataConnector{constructor(){de(this,"pcdWorkerPool",[]);de(this,"dataFetchWorkerPool",[]);de(this,"pcdWorkerPoolOccupancy",[!1,!1,!1,!1,!1]);de(this,"dataFetchWorkerPoolOccupancy",[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1]);de(this,"subscriberSources",new Map);de(this,"subscriberLoaders",new Map);de(this,"subscriberDistributorsLoaders",new Map);de(this,"mapRealtimeConnections",new Map);de(this,"lastQueriedHistoricTime");de(this,"time");de(this,"timeChangeListeners",[]);de(this,"queryStore",new QueryStore);this.time="live";for(let r=0;r<PCD_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/PcdLoaderWorker-eaac0b31.js",self.location));this.pcdWorkerPool.push(n)}for(let r=0;r<DATA_FETCH_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/DataFetchWorker-0a168933.js",self.location));this.dataFetchWorkerPool.push(n)}const t=async()=>{if(Array.from(this.subscriberLoaders.keys()).length>0){const r=[],n=this.generateTelemetryFilter(),o=this.queryStore.query(n);if(!o||o==="too much data")return;o.forEach(u=>{r.push(u.deviceId)});const s=Array.from(new Set(r)),g=[];s.forEach(u=>{const c=this.subscriberLoaders.get(u);c&&c.forEach(p=>{g.push(p(o))})}),(await Promise.all(g)).forEach(u=>{if(u.data){const c=this.subscriberDistributorsLoaders.get(u.deviceId);if(c){const p=c.get(u.sourceId);p&&p.forEach(v=>{v(u.data)})}}})}setTimeout(()=>t(),0)};setTimeout(()=>t(),0)}setTime(t){t!=="live"&&(this.time=t),this.timeChangeListeners.forEach(r=>r(t))}getAvailablePCDWorker(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)if(!this.pcdWorkerPoolOccupancy[t])return this.pcdWorkerPoolOccupancy[t]=!0,this.pcdWorkerPool[t]}getAvailableDataFetchWorker(){for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)if(!this.dataFetchWorkerPoolOccupancy[t])return this.dataFetchWorkerPoolOccupancy[t]=!0,this.dataFetchWorkerPool[t]}releasePCDWorker(t){const r=this.pcdWorkerPool.indexOf(t);this.pcdWorkerPoolOccupancy[r]=!1}releaseDataFetchWorker(t){const r=this.dataFetchWorkerPool.indexOf(t);this.dataFetchWorkerPoolOccupancy[r]=!1}clearWorkerPool(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)this.pcdWorkerPoolOccupancy[t]=!1;for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)this.dataFetchWorkerPoolOccupancy[t]=!1}generateTelemetryFilter(){const t=Array.from(this.subscriberSources.keys()),r=[];return t.forEach(n=>{const o=this.subscriberSources.get(n);o&&Array.from(o==null?void 0:o.values()).forEach(s=>{s.sourceType==="telemetry"&&r.push(s.streamName)})}),{deviceIds:t,names:r,start:subDays(new Date,20).toISOString(),end:new Date().toISOString(),latestOnly:!0}}async sendRtcMessage(t,r){await this.createRealtimeConnection(t);const n=this.mapRealtimeConnections.get(t);n&&n!=="loading"&&n&&n.sendRealtimeMessage(r,{channelLabel:"stream.reliable"})}async createRealtimeConnection(t,r=signaling_pb.SessionType.TELEOP){const n=this.mapRealtimeConnections.get(t);if(n===void 0){this.mapRealtimeConnections.set(t,"loading");const o=t.startsWith("http");console.log("Creating {} realtime connection",o?"peer":"cloud");let s;o?s=new PeerDevice(t):s=await Fleet.getDevice(t),await s.startRealtimeConnection(r),debug&&s.addRealtimeListener((g,l)=>{console.log("received message from peer",g,l)}),this.mapRealtimeConnections.set(t,s)}else n==="loading"&&await new Promise(o=>{const s=setInterval(()=>{const g=this.mapRealtimeConnections.get(t);g&&g!=="loading"&&(clearInterval(s),o())},100)})}addRemovableTelemetrySubscription(t,r,n,o){let s=this.subscriberLoaders.get(t);s||(s=new Map,this.subscriberLoaders.set(t,s)),s.get(r.id)||s.set(r.id,n);let l=this.subscriberDistributorsLoaders.get(t);l||(l=new Map,this.subscriberDistributorsLoaders.set(t,l));const u=l.get(r.id);u?u.push(o):l.set(r.id,[o]);let c=this.subscriberSources.get(t);return c||(c=new Map,this.subscriberSources.set(t,c)),c.set(r.id,r),()=>{const p=this.subscriberLoaders.get(t);p&&p.delete(r.id);const v=this.subscriberDistributorsLoaders.get(t);if(v){const y=v.get(r.id);if(y){const f=y.indexOf(o);f>-1&&y.splice(f,1)}}const _=this.subscriberSources.get(t);_&&_.delete(r.id)}}createH264Drawer(){return new H264BytestreamCanvasDrawer(()=>new Worker("@formant/ui-sdk-realtime-player-core-worker/dist/ui-sdk-realtime-player-core-worker"),()=>{},()=>{})}async sendCommand(t,r,n){const o=this.mapRealtimeConnections.get(t);if(o==="loading"||o===void 0)throw new Error("Device is not ready or doesnt exist");await o.sendCommand(r,n)}async sendRealtimePose(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"pose"},{pose:n},"vision");await this.sendRtcMessage(t,o)}async sendRealtimeBoolean(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"boolean"},{boolean:n});await this.sendRtcMessage(t,o)}async sendRealtimeBitset(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"bitset"},{bitset:{bits:n.keys.map((s,g)=>({key:s,value:n.values[g]}))}});await this.sendRtcMessage(t,o)}async getUrdfs(t){const n=await(await Fleet.getDevice(t)).getConfiguration();return!n.urdfFiles||n.urdfFiles.length===0?[]:[await Fleet.getFileUrl(n.urdfFiles[0])]}async getTelemetryStreams(t){throw new Error("Not implemented")}async getTeleopRosStreams(t){throw new Error("Not implemented")}async getHardwareStreams(t){throw new Error("Not implemented")}addInteraction(t){throw new Error("Method not implemented.")}removeInteraction(t){throw new Error("Method not implemented.")}getInteractions(){throw new Error("Method not implemented.")}addInteractionsChangedListener(t){throw new Error("Method not implemented.")}addInteractionListener(t){throw new Error("Method not implemented.")}getRealtimeButtons(t){throw new Error("Method not implemented.")}async getLatestTransformTrees(t){throw new Error("Not implemented")}async getLatestLocations(){return[{streamName:"spotLocation",location:{latitude:45.4661989,longitude:-122.5782375}}]}async getDeviceContexts(){return[]}async getDeviceContextName(t){throw new Error("Not implemented")}async getTelemetryStreamType(t,r){throw new Error("Not implemented")}async getStatistics(){return{rtcDevices:[]}}subscribeDataSourceStateChange(t,r,n){return()=>{}}async fetchImage(t){const r=new Image;return r.src=t,r.setAttribute("crossOrigin",""),await new Promise(n=>{r.onload=n}),r}}class LiveUniverseData extends BasicUniverseDataConnector{constructor(){super()}subscribeToPath(t,r,n){throw new Error("Method not implemented.")}subscribeToImage(t,r,n){throw new Error("Method not implemented.")}subcribeToVideo(t,r,n){throw new Error("Method not implemented.")}subscribeToBitset(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.bitset){const l=g.payload.bitset,u={keys:[],values:[]};l.bits.forEach(c=>{u.keys.push(c.key),u.values.push(c.value)}),n(u)}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("Telemetry bitset not implemented")}subscribeToOdometry(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.odometry){const l=g.payload.odometry;n({worldToLocal:l.worldToLocal,pose:{translation:{x:l.pose.translation.x,y:l.pose.translation.y,z:l.pose.translation.z},rotation:{x:l.pose.rotation.x,y:l.pose.rotation.y,z:l.pose.rotation.z,w:l.pose.rotation.w}},covariance:[]})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&s.odometry&&(g={worldToLocal:s.odometry.worldToLocal,pose:{translation:{x:s.odometry.pose.translation.x,y:s.odometry.pose.translation.y,z:s.odometry.pose.translation.z},rotation:{x:s.odometry.pose.rotation.x,y:s.odometry.pose.rotation.y,z:s.odometry.pose.rotation.z,w:s.odometry.pose.rotation.w}},covariance:[]}),{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("unexpected")}subscribeToPose(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.pose&&n(g.payload.pose)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("unexpected")}subscribeToNumeric(t,r,n){if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.numeric&&n([[Date.now(),g.payload.numeric.value]])};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToNumericSet(t,r,n){if(r.sourceType==="telemetry"){let o;const s=setInterval(async()=>{o||(o=await Fleet.getDevice(t));const g=new Date,l=new Date(g.getTime()-15*1e3),u=await o.getTelemetry(r.streamName,l,g);if(u.length>0){const c=u[0].points;n(c)}},1e3);return()=>{clearInterval(s)}}return()=>{}}async subscribeToRealtimeMessages(t,r,n){await this.createRealtimeConnection(t,signaling_pb.SessionType.OBSERVE);const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.startListeningToRealtimeDataStream({name:r}),o.addRealtimeListener((s,g)=>{g.header.stream.streamName===r&&n(s,g)}))}async unsubscribeToRealtimeMessages(t,r,n){const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.stopListeningToRealtimeDataStream({name:r}),o.removeRealtimeListener(n))}subscribeToJson(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="json"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.json())),{deviceId:t,sourceId:r.id,data:g}},n);if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.jsonString&&n(JSON.parse(g.payload.jsonString.value))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToText(t,r,n){return r.sourceType==="telemetry"?this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="text"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.text())),{deviceId:t,sourceId:r.id,data:g}},n):()=>{}}subscribeToPointCloud(t,r,n){const o=this.getAvailablePCDWorker();if(!o)throw new Error("No available pointcloud worker");if(r.sourceType==="telemetry"&&r.streamType!=="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="point cloud"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g){const{url:u}=g;l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g==null?void 0:g.worldToLocal,pcd:l}}},n);if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="localization"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g&&g.pointClouds){const{url:u}=g.pointClouds[0];l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g&&(g!=null&&g.pointClouds)&&(g!=null&&g.pointClouds[0])?g.pointClouds[0].worldToLocal:void 0,pcd:l}}},n);if(r.sourceType==="realtime"){const s=async(g,l)=>{var u;if(l.payload.pointCloud){const c=Math.random(),p=await new Promise(v=>{o.postMessage({id:c,pointCloud:defined(l.payload.pointCloud).data}),o.onmessage=_=>{_.data.id===c&&v(_.data.pcd)}});n({worldToLocal:(u=l.payload.pointCloud)==null?void 0:u.world_to_local,pcd:p})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,s),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,s)}}return()=>{}}subscribeToGeometry(t,r,n){throw new Error("type error in realtime sdk")}subscribeToJointState(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.jointState&&n(g.payload.jointState)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToGridMap(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.jsonString){const l=JSON.parse(g.payload.jsonString.value);n({width:l.info.width,height:l.info.height,worldToLocal:{translation:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0,w:1}},resolution:l.info.resolution,origin:{translation:l.info.origin.position,rotation:l.info.origin.orientation},data:l.data,canvas:void 0})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}else if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}if(s&&s.map){const l=document.createElement("canvas"),u=await this.fetchImage(s.map.url);l.width=u.width,l.height=u.height;const c=l.getContext("2d");c&&c.drawImage(u,0,0);const p=c==null?void 0:c.getImageData(0,0,u.width,u.height),v=[];if(p)for(let _=0;_<p.data.length;_+=4){const y=p.data[_];v.push(y)}g={width:s.map.width,height:s.map.height,worldToLocal:s.map.worldToLocal,resolution:s.map.resolution,origin:s.map.origin,canvas:l,data:v}}return{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("Not implemented")}subscribeToVideo(t,r,n){const o=this.createH264Drawer(),s=document.createElement("CANVAS");if(s.width=0,s.height=0,o.setCanvas(s),o.start(),r.sourceType==="realtime"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,g)}}if(r.sourceType==="hardware"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rtcStreamName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rtcStreamName,g)}}return()=>{o.stop()}}subscribeToTransformTree(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s;for(let g=0;g<o.length;g+=1){const l=o[g];if(l.deviceId===t&&l.name===r.streamName&&l.type==="transform tree"){const[u,c]=l.points[l.points.length-1];s=c}}return{deviceId:t,sourceId:r.id,data:s}},n);throw new Error("not implemented for this source type "+r.sourceType)}subscribeToLocation(t,r,n){throw new Error("Not implemented")}}const NoData=Symbol("no_data"),LoadingData=Symbol("loading_data"),FailedData=Symbol("failed_data");class TelemetryUniverseData extends BasicUniverseDataConnector{constructor(){super();de(this,"liveIntervalHandle");de(this,"timeFinders",[]);de(this,"videoCache",new StoreCache({capacity:50}));this.timeChangeListeners.push(this.onTimeChange.bind(this)),this.onTimeChange("live")}subscribeToBitset(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToPath(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"localization",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1];let l=g;g.url&&(l=await(await fetch(g.url)).json()),l.path&&o({worldToLocal:l.path.worldToLocal,poses:l.path.poses})})}onTimeChange(r){r==="live"?this.liveIntervalHandle=setInterval(()=>{this.findDataForTime(new Date)},300):(this.liveIntervalHandle&&clearInterval(this.liveIntervalHandle),this.findDataForTime(r))}findDataForTime(r){this.timeFinders.forEach(n=>{n(r)})}addFinder(r,n,o,s,g){const l=u=>{let c;g?c=addYears(u,-1):c=addSeconds(u,-15);let p;g?p=u:p=addSeconds(u,5);let v=this.queryStore.moduleQuery({deviceIds:[n]},o,s,c,p,g);if(v===void 0)r(void 0);else if(v==="too much data")r("too much data");else if(v.length>0){const y=v[0].points;if(y.length>0){const f=y[y.length-1];if(g){let h=f[0],w=f[1];y.forEach(C=>{const L=C[0],T=C[1];Math.abs(L-u.getTime())<Math.abs(h-u.getTime())&&(h=L,w=T)}),r([[h,w]])}else r(y)}else r(void 0)}else r(void 0)};return this.timeFinders.push(l),l}removeFinder(r){this.timeFinders=this.timeFinders.filter(n=>n!==r)}subscribeTelemetry(r,n,o,s){if(n.sourceType!=="telemetry")throw new Error("Invalid source type");const g=this.addFinder(s,r,n.streamName,o,n.latestDataPoint||!1);return()=>{this.removeFinder(g)}}subscribeToPointCloud(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailablePCDWorker();if(!s)throw new Error("No available pointcloud worker");const g=async()=>new Promise(c=>{const p=f=>{_(),y(),c(f)},v={...n,latestDataPoint:!0},_=this.subscribeTelemetry(r,v,"point cloud",async f=>{f!==void 0&&typeof f!="symbol"&&p("pointcloud")}),y=this.subscribeTelemetry(r,v,"localization",async f=>{f!==void 0&&typeof f!="symbol"&&p("localization")})});let l=()=>{},u=()=>{};return g().then(c=>{c==="pointcloud"?l=this.subscribeTelemetry(r,n,"point cloud",async p=>{if(p==="too much data"||p===void 0){o(NoData);return}const v=p[p.length-1][1];if(typeof v=="string")o(JSON.parse(v));else{const{url:_}=v;s.postMessage({url:_}),s.onmessage=y=>{y.data.url===_&&o({worldToLocal:v.worldToLocal,pcd:y.data.pcd})}}}):c==="localization"&&(u=this.subscribeTelemetry(r,n,"localization",async p=>{if(p==="too much data"||p===void 0){o(NoData);return}let v=p[p.length-1][1];if(v.url&&(v=await(await fetch(v.url)).json()),v.pointClouds){const{url:_,worldToLocal:y}=v.pointClouds[0];s.postMessage({url:_}),s.onmessage=f=>{f.data.url===_&&o({worldToLocal:y,pcd:f.data.pcd})}}}))}),()=>{this.releasePCDWorker(s),l(),u()}}subscribeToOdometry(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"localization",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}const l=g[g.length-1][1];let u=l;l.url&&(s.postMessage({url:l.url}),s.onmessage=c=>{u=c.data.response,u.odometry&&o({worldToLocal:u.odometry.worldToLocal,pose:{translation:{x:u.odometry.pose.translation.x,y:u.odometry.pose.translation.y,z:u.odometry.pose.translation.z},rotation:{x:u.odometry.pose.rotation.x,y:u.odometry.pose.rotation.y,z:u.odometry.pose.rotation.z,w:u.odometry.pose.rotation.w}},covariance:[]})})})}subscribeToPose(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToGeometry(r,n,o){if(n.sourceType==="telemetry"){const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"json",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}let l=g[g.length-1][1];l.startsWith("http")&&(s.postMessage({url:l}),s.onmessage=u=>{l=JSON.stringify(u.data.response),o(JSON.parse(l))})})}else throw new Error("Realtime geometry note supported")}subscribeToJointState(r,n,o){return this.subscribeToJson(r,n,o)}subscribeToGridMap(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");return this.subscribeTelemetry(r,n,"localization",async g=>{if(g==="too much data"||g===void 0){o(NoData);return}const l=g[g.length-1][1];let u=l;l.url&&(s.postMessage({url:l.url}),s.onmessage=async c=>{if(u=c.data.response,u.map){const p=document.createElement("canvas"),v=await this.fetchImage(u.map.url);p.width=v.width,p.height=v.height;const _=p.getContext("2d");_&&_.drawImage(v,0,0);const y=_==null?void 0:_.getImageData(0,0,v.width,v.height),f=[];if(y)for(let w=0;w<y.data.length;w+=4){const C=y.data[w];f.push(C)}const h={width:u.map.width,height:u.map.height,worldToLocal:u.map.worldToLocal,resolution:u.map.resolution,origin:u.map.origin,canvas:p,data:f};o(h)}})})}subscribeToVideo(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"video",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1],{url:l}=g,u=this.videoCache.get(l,async()=>new Promise(c=>{const p=document.createElement("video");p.src=l,p.onload=()=>{}}));if(u){const c=document.createElement("canvas");c.width=u.videoWidth,c.height=u.videoHeight;const p=c.getContext("2d");p&&p.drawImage(u,0,0),o(c)}})}subscribeToTransformTree(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"transform tree",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToLocation(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.subscribeToJson(r,n,o),g=this.subscribeTelemetry(r,n,"location",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];o(u)});return()=>{s(),g()}}subscribeToJson(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"json",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}let g=s[s.length-1][1];g.startsWith("http")&&(g=await(await fetch(g)).text()),o(JSON.parse(g))})}subscribeToText(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"text",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToNumeric(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToNumericSet(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric set",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToImage(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"image",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1].url,l=new Image;l.src=g,l.onload=()=>{const u=document.createElement("canvas");u.width=l.width,u.height=l.height;const c=u.getContext("2d");c&&(c.drawImage(l,0,0),o(u))}})}}exports.Account=Account;exports.App=App;exports.AudioPlayer=AudioPlayer;exports.Authentication=Authentication;exports.BasicUniverseDataConnector=BasicUniverseDataConnector;exports.BinaryRequestDataChannel=BinaryRequestDataChannel;exports.CaptureStream=CaptureStream;exports.DataChannel=DataChannel;exports.Device=Device;exports.FailedData=FailedData;exports.Fleet=Fleet;exports.KeyValue=KeyValue;exports.LiveUniverseData=LiveUniverseData;exports.LoadingData=LoadingData;exports.Manipulator=Manipulator;exports.NoData=NoData;exports.PeerDevice=PeerDevice;exports.QueryStore=QueryStore;exports.Role=Role;exports.SessionType=SessionTypeConstants;exports.TelemetryUniverseData=TelemetryUniverseData;exports.TextRequestDataChannel=TextRequestDataChannel;exports.User=User;exports.accessLevels=accessLevels;exports.administrator=administrator;exports.aggregateByDateFunctions=aggregateByDateFunctions;exports.aggregateFunctionMap=aggregateFunctionMap;exports.aggregateFunctions=aggregateFunctions;exports.aggregateLevels=aggregateLevels;exports.annotationTypes=annotationTypes;exports.createRtcStreamMessage=distExports.createRtcStreamMessage;exports.defined=defined$1;exports.definedAndNotNull=definedAndNotNull;exports.eventTypes=eventTypes;exports.formatTimeFrameText=formatTimeFrameText;exports.getAverage=getAverage;exports.getCount=getCount;exports.getMax=getMax;exports.getMin=getMin;exports.getStandardDeviation=getStandardDeviation;exports.getSum=getSum;exports.getVariance=getVariance;exports.healthStatuses=healthStatuses;exports.interventionTypes=interventionTypes;exports.operator=operator;exports.severities=severities;exports.timeout=timeout;exports.vailableAggregationIntervals=vailableAggregationIntervals;exports.videoMimeTypes=videoMimeTypes;exports.viewer=viewer;
|
|
102
|
+
`,o=[1.16438,0,1.59603,-.87079,1.16438,-.39176,-.81297,.52959,1.16438,2.01723,0,-1.08139,0,0,0,1],s=t.createShader(t.VERTEX_SHADER);if(!s)throw new Error("Failed to create vertex shader");t.shaderSource(s,r),t.compileShader(s);const g=t.createShader(t.FRAGMENT_SHADER);if(!g)throw new Error("Failed to create fragment shader");t.shaderSource(g,n),t.compileShader(g);const l=t.createProgram();if(!l)throw new Error("Failed to create webgl program");t.attachShader(l,s),t.attachShader(l,g),t.linkProgram(l),t.useProgram(l);const u=t.getUniformLocation(l,"YUV2RGB");return t.uniformMatrix4fv(u,!1,o),l}initBuffers(){const{gl:t,program:r}=this,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),t.STATIC_DRAW);const o=t.getAttribLocation(r,"vertexPos");t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0);const s=t.createBuffer();if(!s)throw new Error("Failed to create WebGL buffer");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),t.STATIC_DRAW);const g=t.getAttribLocation(r,"texturePos");return t.enableVertexAttribArray(g),t.vertexAttribPointer(g,2,t.FLOAT,!1,0,0),{texturePosBuffer:s}}initTextures(){const{gl:t,program:r}=this,n=this.initTexture(),o=t.getUniformLocation(r,"yuvSampler");return t.uniform1i(o,0),{textureRef:n}}initTexture(){const{gl:t}=this,r=t.createTexture();if(!r)throw new Error("Failed to initialize texture");return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null),r}}const decoderNotWorkingThreshold=duration$1.second*2.5,warnPerformanceThreshold=duration$1.second/3,noSignalThreshold=duration$1.second*2,maxQueueSize=5,maxDropRatio=30/25,numRetries=5,hardwareIncompatibleErrorCode=1282;class H264BytestreamCanvasDrawer{constructor(t,r,n,o,s){__publicField(this,"_waitingForDecoder",!0),__publicField(this,"_noSignal",!0),__publicField(this,"_lostSignal",!1),__publicField(this,"_overWaitingThreshold",!1),__publicField(this,"_retries",0),__publicField(this,"_webglYUVSupported"),__publicField(this,"lastDecodedFrameTime"),__publicField(this,"lastReceivedFrameTime"),__publicField(this,"lastNoSignalTime",new Date().getTime()),__publicField(this,"moduleStartTime",Date.now()),__publicField(this,"moduleCreateTime",Date.now()),__publicField(this,"timesRestarted",0),__publicField(this,"canvas"),__publicField(this,"decoder"),__publicField(this,"yuvCanvas"),__publicField(this,"webglContext"),__publicField(this,"frameQueue",[]),__publicField(this,"minFrameSize",1/0),__publicField(this,"maxFrameSize",0),__publicField(this,"decoderQueue",[]),__publicField(this,"decoderQueueLocked",!1),__publicField(this,"decodeNextFrameAttempted",!1),__publicField(this,"numFramesDecoded",0),__publicField(this,"numFramesReceived",0),__publicField(this,"hasReceivedKeyframe",!1),__publicField(this,"medianFrameSize",0),__publicField(this,"currentFrameIndex"),__publicField(this,"frameCheckpointMap",new Map),__publicField(this,"lastDrawnFrameTime"),__publicField(this,"minJitter"),__publicField(this,"maxJitter"),__publicField(this,"start",()=>{const{canvas:g}=this;if(!g)return;const l=g.getContext("webgl");this.webglContext=l||void 0,this.lastDecodedFrameTime=void 0,this.lastReceivedFrameTime=void 0,this.hasReceivedKeyframe=!1,this.currentFrameIndex=void 0,!(!this.canvas||!this.webglContext)&&(this.yuvCanvas||(this.yuvCanvas=new YUVCanvas(this.webglContext)),this.moduleStartTime=Date.now())}),__publicField(this,"stop",()=>{var g;(g=this.decoder)==null||g.release(),this.webglContext=void 0,this.decoderQueueLocked=!1}),__publicField(this,"reset",()=>{this.retries=0,this.restart()}),__publicField(this,"notifyWarningTextChanged",()=>{var g;(g=this.onWarningTextChanged)==null||g.call(this,this.getWarningText())}),__publicField(this,"restart",()=>{console.info("Restarting decoder"),console.info("BytestreamPlayer restarting",__spreadProps(__spreadValues({},this.trackInfo),{Restart:this.timesRestarted})),this.frameQueue=[],this.decoderQueue=[],this.stop(),this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),this.start(),this.retries++,this.timesRestarted++}),__publicField(this,"onTrackTick",()=>{if(this.numFramesDecoded===0){if(this.lastDecodedFrameTime===void 0){const p=Date.now();console.info("BytestreamPlayer waiting for video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Waited":p-this.moduleCreateTime}))}return}this.numFramesReceived/this.numFramesDecoded>maxDropRatio&&this.warnPerformanceProblems(),this.numFramesReceived=0,this.numFramesDecoded=0;const l=Array.from(this.frameCheckpointMap.entries()).reduce((p,[v,_])=>{var y;return!this.currentFrameIndex||v>this.currentFrameIndex-60||_==="FrameDrawn"||(p[_]=((y=p[_])!=null?y:0)+1,this.frameCheckpointMap.delete(v)),p},{});Object.keys(l).map(p=>{console.info("BytestreamPlayer Frame Dropped",__spreadProps(__spreadValues({},this.trackInfo),{"Num Dropped":l[p],"Frame State":p}))});const{minJitter:u,maxJitter:c}=this;u&&c&&(console.info("BytestreamPlayer Jitter",__spreadProps(__spreadValues({},this.trackInfo),{minJitter:u,maxJitter:c})),this.minJitter=void 0,this.maxJitter=void 0)}),__publicField(this,"onTick",()=>{var g;const{lastReceivedFrameTime:l,lastDecodedFrameTime:u,moduleStartTime:c,noSignal:p,retries:v}=this,_=new Date().getTime();p&&(this.lastNoSignalTime=_),this.overWaitingThreshold=_-c>noSignalThreshold;const y=_-c>decoderNotWorkingThreshold;if(!u){l&&y&&v<numRetries&&(this.waitingForDecoder=!0,this.restart());return}if(l){const f=_-l,h=_-u;_-this.lastNoSignalTime>noSignalThreshold&&f<warnPerformanceThreshold&&h>warnPerformanceThreshold&&this.warnPerformanceProblems(),f>noSignalThreshold&&(this.lostSignal=!0)}this.overWaitingThreshold&&(this.waitingForDecoder||this.noSignal||this.lostSignal)&&((g=this.onCanvasDrawerWarning)==null||g.call(this,"ShouldDisableControl"))}),__publicField(this,"receiveEncodedFrame",g=>{if(!g)return;const l=g.index;if(l&&this.frameCheckpointMap.set(l,"FrameReceived"),!(!g||!this.canvas||!this.webglContext)){if(this.isKeyframe(g),!this.hasReceivedKeyframe)return console.info("Dropping frame because no keyframe detected"),!1;this.lastReceivedFrameTime===void 0&&console.debug("Received first frame on bytestream player",__spreadValues({},this.trackInfo)),this.checkOrder(g),this.numFramesReceived++,this.lastReceivedFrameTime=Date.now(),this.lostSignal&&this.restart(),this.noSignal=!1,this.lostSignal=!1,this.frameQueue.push(g),l&&this.frameCheckpointMap.set(l,"FrameQueued"),this.frameQueue.length>maxQueueSize&&(this.frameQueue=this.frameQueue.filter(u=>this.isKeyframe(u))),this.frameQueue.length>maxQueueSize&&(this.frameQueue=[],this.decoderQueue=[]),this.decodeNextFrame()}}),__publicField(this,"onDecoderError",g=>{this.frameQueue=[],this.decoderQueue=[],this.hasReceivedKeyframe=!1,console.info("BytestreamPlayer decode error",__spreadProps(__spreadValues({},this.trackInfo),{"Frame Index":g}))}),__publicField(this,"onReceiveDecodedFrame",g=>{var l,u;const{canvas:c,yuvCanvas:p,decoderQueue:v}=this,{timestamp:_,yuv:y,height:f,width:h,index:w}=g;this.frameCheckpointMap.set(w,"FrameDecoded"),this.numFramesDecoded++;const C=Date.now();if(this.lastDecodedFrameTime===void 0&&console.info("BytestreamPlayer started video",__spreadProps(__spreadValues({},this.trackInfo),{"Time Until Video":C-this.moduleCreateTime})),this.lastDecodedFrameTime=C,this.waitingForDecoder=!1,this.decoderQueue=v.filter(E=>C-E<duration$1.second*.5&&E!==_),!v.includes(_)||C-_>duration$1.second||!p||!c||f===0||h===0)return;f!==c.height&&(c.height=f,p.height=f),h!==c.width&&(c.width=h,p.width=h);const L=p.draw(y),T=Date.now();if(this.lastDrawnFrameTime){const E=T-this.lastDrawnFrameTime;this.minJitter=Math.min(E,(l=this.minJitter)!=null?l:Number.MAX_SAFE_INTEGER),this.maxJitter=Math.max(E,(u=this.maxJitter)!=null?u:0)}this.lastDrawnFrameTime=T,this.frameCheckpointMap.set(w,"FrameDrawn"),L===0&&(this.webglYUVSupported=!0),L===hardwareIncompatibleErrorCode&&(this.webglYUVSupported=!1),this.frameQueue.length>0&&this.decodeNextFrame()}),this.workerFactory=t,this.onWebglYUVSupportedChanged=r,this.onWarningTextChanged=n,this.onCanvasDrawerWarning=o,this.trackInfo=s,this.decoder=new H264Decoder(this.workerFactory(),this.onReceiveDecodedFrame,this.onDecoderError),setInterval(this.onTick,duration$1.millisecond*200),setInterval(this.onTrackTick,duration$1.second*5)}get waitingForDecoder(){return this._waitingForDecoder}set waitingForDecoder(t){this._waitingForDecoder=t,this.notifyWarningTextChanged()}get noSignal(){return this._noSignal}set noSignal(t){this._noSignal=t,this.notifyWarningTextChanged()}get lostSignal(){return this._lostSignal}set lostSignal(t){this._lostSignal=t,this.notifyWarningTextChanged()}get overWaitingThreshold(){return this._overWaitingThreshold}set overWaitingThreshold(t){this._overWaitingThreshold=t,this.notifyWarningTextChanged()}get retries(){return this._retries}set retries(t){this._retries=t,this.notifyWarningTextChanged()}get webglYUVSupported(){return this._webglYUVSupported}set webglYUVSupported(t){var r;this._webglYUVSupported=t,(r=this.onWebglYUVSupportedChanged)==null||r.call(this,t),this.notifyWarningTextChanged()}setCanvas(t){this.canvas=t}getWarningText(){var t;const{waitingForDecoder:r,noSignal:n,overWaitingThreshold:o,lostSignal:s,retries:g,webglYUVSupported:l}=this,u=l===!1,p=r?g===numRetries?"Decoder failed to start":"Starting decoder":void 0,v=u?"Hardware decoding not supported on this device":void 0,_=s?"Lost signal":n?o?"No signal":"Waiting for signal":void 0;return(t=v!=null?v:_)!=null?t:p}decodeNextFrame(){if(this.decoderQueueLocked&&(this.decodeNextFrameAttempted=!0),this.decoderQueueLocked=!0,this.decoderQueue.length>maxQueueSize){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const t=this.frameQueue.shift();if(!t){this.decoderQueueLocked=!1,this.decodeNextFrameAttempted=!1;return}const r=Date.now();this.frameCheckpointMap.set(t.index,"FrameSentToDecoder"),this.decoder.post(r,t.frame_data,t.flags,t.index),this.decoderQueue.push(r),this.decoderQueueLocked=!1,this.decodeNextFrameAttempted&&(this.decodeNextFrameAttempted=!1,this.decodeNextFrame())}warnPerformanceProblems(){var t;this.lastDecodedFrameTime&&this.overWaitingThreshold&&!this.lostSignal&&!this.noSignal&&((t=this.onCanvasDrawerWarning)==null||t.call(this,"ShouldDegradeVideo"))}checkOrder(t){if(this.currentFrameIndex!==void 0&&t.index<this.currentFrameIndex){console.info("Out of order frame detected"),console.info("Frame out of order",__spreadValues({},this.trackInfo));return}this.currentFrameIndex=t.index}isKeyframe(t){const{maxFrameSize:r,minFrameSize:n}=this;if(t.flags===3)return this.hasReceivedKeyframe||(this.frameCheckpointMap=new Map),this.hasReceivedKeyframe=!0,!0;const o=t.frame_data.length;return this.maxFrameSize=Math.max(o,r),this.minFrameSize=Math.min(o,n),this.medianFrameSize=(this.maxFrameSize+this.minFrameSize)/2,this.moduleStartTime+duration$1.second*2>Date.now()?!1:o>this.medianFrameSize?(this.hasReceivedKeyframe=!0,!0):!1}}const millisecond=1,second=1e3,minute=60*second,hour=60*minute,day=24*hour,week=7*day,month=30*day,year=365*day,duration={millisecond,second,minute,hour,day,week,month,year};function filterDataByType(e,t){return e.filter(r=>r.type===t)}function filterDataByTime(e,t,r){const n=t.getTime(),o=r.getTime();return e.map(s=>({...s,points:s.points.filter(([g])=>g>=n&&g<o)})).filter(({points:s})=>s.length>0)}function fork(e){}class StoreCache{constructor({capacity:t,timeout:r}={}){de(this,"entries",new Map);de(this,"metadata",new Map);de(this,"capacity");de(this,"timeout");this.capacity=t||1e4,this.timeout=r||duration.minute}get(t,r){const n=this.keyToCacheKey(t),o=this.entries.get(n),s=this.metadata.get(n);return(o===void 0||s&&(s==null?void 0:s.expiration.getTime())<Date.now())&&!(s!=null&&s.generating)&&r&&this.generate(t,r()),o===void 0&&s&&s.lastValue!==void 0?s.lastValue:o}set(t,r){const n=this.keyToCacheKey(t);this.metadata.set(n,{generating:!1,expiration:new Date(Date.now()+this.timeout),lastValue:r}),this.entries.set(n,r),this.metadata.size>this.capacity&&this.deleteOldestEntry()}clear(){this.entries.clear(),[...this.metadata.values()].forEach(t=>t.generating=!1)}clearKey(t){this.metadata.delete(t),this.entries.delete(t)}keyToCacheKey(t){return JSON.stringify(t)}deleteOldestEntry(){if(this.metadata.size<1)return;const[t]=[...this.metadata.entries()].reduce(([r,n],[o,s])=>s.expiration.getTime()<n.expiration.getTime()?[o,s]:[r,n]);this.clearKey(t)}generate(t,r){const n=this.keyToCacheKey(t),o=this.metadata.get(n)||{};this.metadata.set(n,{...o,generating:!0,expiration:new Date(Date.now()+this.timeout)}),setTimeout(()=>{r.then(s=>{const g=this.metadata.get(n);!(g!=null&&g.generating)||this.set(t,s)})},0)}}function roundToNearestSecond(e){return new Date(Math.round(e.getTime()/1e3)*1e3)}class QueryStore{constructor(){de(this,"queryStoreCache",new StoreCache({capacity:1e4,timeout:20*duration.second}));de(this,"liveQueryStoreCache",new StoreCache({capacity:1e4,timeout:1*duration.second}))}moduleQuery(t,r,n,o,s,g=!1){const l={...t,names:[r],types:[n],start:o.toISOString(),end:s.toISOString(),latestOnly:g},u=this.query(l);return u===void 0||u==="too much data"?u:filterDataByType(u,n)}query(t){const r=new Date(t.end)>addSeconds(new Date,-20),n=startOfMinute(new Date(t.start)).toISOString(),o=t.latestOnly?addSeconds(roundToNearestSecond(new Date(t.end)),5).toISOString():addMinutes(roundToNearestMinutes(new Date(t.end)),1).toISOString();let s;return r?s=this.liveQueryCache({...t,start:n,end:o}):s=this.queryCache({...t,start:n,end:o}),!s||s==="too much data"||t.latestOnly?s:filterDataByTime(s,new Date(n),new Date(o))}queryCache(t){return this.queryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}liveQueryCache(t){return this.liveQueryStoreCache.get(t,async()=>{try{return await Fleet.queryTelemetry(t)}catch(r){throw r}})}}const debug=new URLSearchParams(window.location.search).get("debug")==="true",PCD_WORKER_POOL_SIZE=5,DATA_FETCH_WORKER_POOL_SIZE=10;class BasicUniverseDataConnector{constructor(){de(this,"pcdWorkerPool",[]);de(this,"dataFetchWorkerPool",[]);de(this,"pcdWorkerPoolOccupancy",[!1,!1,!1,!1,!1]);de(this,"dataFetchWorkerPoolOccupancy",[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1]);de(this,"subscriberSources",new Map);de(this,"subscriberLoaders",new Map);de(this,"subscriberDistributorsLoaders",new Map);de(this,"mapRealtimeConnections",new Map);de(this,"lastQueriedHistoricTime");de(this,"time");de(this,"timeChangeListeners",[]);de(this,"queryStore",new QueryStore);this.time="live";for(let r=0;r<PCD_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/PcdLoaderWorker-eaac0b31.js",self.location));this.pcdWorkerPool.push(n)}for(let r=0;r<DATA_FETCH_WORKER_POOL_SIZE;r++){const n=new Worker(new URL("/assets/DataFetchWorker-0a168933.js",self.location));this.dataFetchWorkerPool.push(n)}const t=async()=>{if(Array.from(this.subscriberLoaders.keys()).length>0){const r=[],n=this.generateTelemetryFilter(),o=this.queryStore.query(n);if(!o||o==="too much data")return;o.forEach(u=>{r.push(u.deviceId)});const s=Array.from(new Set(r)),g=[];s.forEach(u=>{const c=this.subscriberLoaders.get(u);c&&c.forEach(p=>{g.push(p(o))})}),(await Promise.all(g)).forEach(u=>{if(u.data){const c=this.subscriberDistributorsLoaders.get(u.deviceId);if(c){const p=c.get(u.sourceId);p&&p.forEach(v=>{v(u.data)})}}})}setTimeout(()=>t(),0)};setTimeout(()=>t(),0)}setTime(t){t!=="live"&&(this.time=t),this.timeChangeListeners.forEach(r=>r(t))}getAvailablePCDWorker(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)if(!this.pcdWorkerPoolOccupancy[t])return this.pcdWorkerPoolOccupancy[t]=!0,this.pcdWorkerPool[t]}getAvailableDataFetchWorker(){for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)if(!this.dataFetchWorkerPoolOccupancy[t])return this.dataFetchWorkerPoolOccupancy[t]=!0,this.dataFetchWorkerPool[t]}releasePCDWorker(t){const r=this.pcdWorkerPool.indexOf(t);this.pcdWorkerPoolOccupancy[r]=!1}releaseDataFetchWorker(t){const r=this.dataFetchWorkerPool.indexOf(t);this.dataFetchWorkerPoolOccupancy[r]=!1}clearWorkerPool(){for(let t=0;t<PCD_WORKER_POOL_SIZE;t++)this.pcdWorkerPoolOccupancy[t]=!1;for(let t=0;t<DATA_FETCH_WORKER_POOL_SIZE;t++)this.dataFetchWorkerPoolOccupancy[t]=!1}generateTelemetryFilter(){const t=Array.from(this.subscriberSources.keys()),r=[];return t.forEach(n=>{const o=this.subscriberSources.get(n);o&&Array.from(o==null?void 0:o.values()).forEach(s=>{s.sourceType==="telemetry"&&r.push(s.streamName)})}),{deviceIds:t,names:r,start:subDays(new Date,20).toISOString(),end:new Date().toISOString(),latestOnly:!0}}async sendRtcMessage(t,r){await this.createRealtimeConnection(t);const n=this.mapRealtimeConnections.get(t);n&&n!=="loading"&&n&&n.sendRealtimeMessage(r,{channelLabel:"stream.reliable"})}async createRealtimeConnection(t,r=signaling_pb.SessionType.TELEOP){const n=this.mapRealtimeConnections.get(t);if(n===void 0){this.mapRealtimeConnections.set(t,"loading");const o=t.startsWith("http");console.log("Creating {} realtime connection",o?"peer":"cloud");let s;o?s=new PeerDevice(t):s=await Fleet.getDevice(t),await s.startRealtimeConnection(r),debug&&s.addRealtimeListener((g,l)=>{console.log("received message from peer",g,l)}),this.mapRealtimeConnections.set(t,s)}else n==="loading"&&await new Promise(o=>{const s=setInterval(()=>{const g=this.mapRealtimeConnections.get(t);g&&g!=="loading"&&(clearInterval(s),o())},100)})}addRemovableTelemetrySubscription(t,r,n,o){let s=this.subscriberLoaders.get(t);s||(s=new Map,this.subscriberLoaders.set(t,s)),s.get(r.id)||s.set(r.id,n);let l=this.subscriberDistributorsLoaders.get(t);l||(l=new Map,this.subscriberDistributorsLoaders.set(t,l));const u=l.get(r.id);u?u.push(o):l.set(r.id,[o]);let c=this.subscriberSources.get(t);return c||(c=new Map,this.subscriberSources.set(t,c)),c.set(r.id,r),()=>{const p=this.subscriberLoaders.get(t);p&&p.delete(r.id);const v=this.subscriberDistributorsLoaders.get(t);if(v){const y=v.get(r.id);if(y){const f=y.indexOf(o);f>-1&&y.splice(f,1)}}const _=this.subscriberSources.get(t);_&&_.delete(r.id)}}createH264Drawer(){return new H264BytestreamCanvasDrawer(()=>new Worker("@formant/ui-sdk-realtime-player-core-worker/dist/ui-sdk-realtime-player-core-worker"),()=>{},()=>{})}async sendCommand(t,r,n){const o=this.mapRealtimeConnections.get(t);if(o==="loading"||o===void 0)throw new Error("Device is not ready or doesnt exist");await o.sendCommand(r,n)}async sendRealtimePose(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"pose"},{pose:n},"vision");await this.sendRtcMessage(t,o)}async sendRealtimeBoolean(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"boolean"},{boolean:n});await this.sendRtcMessage(t,o)}async sendRealtimeBitset(t,r,n){const o=distExports.createRtcStreamMessage({entityId:t,streamName:r,streamType:"bitset"},{bitset:{bits:n.keys.map((s,g)=>({key:s,value:n.values[g]}))}});await this.sendRtcMessage(t,o)}async getUrdfs(t){const n=await(await Fleet.getDevice(t)).getConfiguration();return!n.urdfFiles||n.urdfFiles.length===0?[]:[await Fleet.getFileUrl(n.urdfFiles[0])]}async getTelemetryStreams(t){throw new Error("Not implemented")}async getTeleopRosStreams(t){throw new Error("Not implemented")}async getHardwareStreams(t){throw new Error("Not implemented")}addInteraction(t){throw new Error("Method not implemented.")}removeInteraction(t){throw new Error("Method not implemented.")}getInteractions(){throw new Error("Method not implemented.")}addInteractionsChangedListener(t){throw new Error("Method not implemented.")}addInteractionListener(t){throw new Error("Method not implemented.")}getRealtimeButtons(t){throw new Error("Method not implemented.")}async getLatestTransformTrees(t){throw new Error("Not implemented")}async getLatestLocations(){return[{streamName:"spotLocation",location:{latitude:45.4661989,longitude:-122.5782375}}]}async getDeviceContexts(){return[]}async getDeviceContextName(t){throw new Error("Not implemented")}async getTelemetryStreamType(t,r){throw new Error("Not implemented")}async getStatistics(){return{rtcDevices:[]}}subscribeDataSourceStateChange(t,r,n){return()=>{}}async fetchImage(t){const r=new Image;return r.src=t,r.setAttribute("crossOrigin",""),await new Promise(n=>{r.onload=n}),r}}class LiveUniverseData extends BasicUniverseDataConnector{constructor(){super()}subscribeToPath(t,r,n){throw new Error("Method not implemented.")}subscribeToImage(t,r,n){throw new Error("Method not implemented.")}subcribeToVideo(t,r,n){throw new Error("Method not implemented.")}subscribeToBitset(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.bitset){const l=g.payload.bitset,u={keys:[],values:[]};l.bits.forEach(c=>{u.keys.push(c.key),u.values.push(c.value)}),n(u)}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("Telemetry bitset not implemented")}subscribeToOdometry(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.odometry){const l=g.payload.odometry;n({worldToLocal:l.worldToLocal,pose:{translation:{x:l.pose.translation.x,y:l.pose.translation.y,z:l.pose.translation.z},rotation:{x:l.pose.rotation.x,y:l.pose.rotation.y,z:l.pose.rotation.z,w:l.pose.rotation.w}},covariance:[]})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&s.odometry&&(g={worldToLocal:s.odometry.worldToLocal,pose:{translation:{x:s.odometry.pose.translation.x,y:s.odometry.pose.translation.y,z:s.odometry.pose.translation.z},rotation:{x:s.odometry.pose.rotation.x,y:s.odometry.pose.rotation.y,z:s.odometry.pose.rotation.z,w:s.odometry.pose.rotation.w}},covariance:[]}),{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("unexpected")}subscribeToPose(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.pose&&n(g.payload.pose)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}throw new Error("unexpected")}subscribeToNumeric(t,r,n){if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.numeric&&n([[Date.now(),g.payload.numeric.value]])};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToNumericSet(t,r,n){if(r.sourceType==="telemetry"){let o;const s=setInterval(async()=>{o||(o=await Fleet.getDevice(t));const g=new Date,l=new Date(g.getTime()-15*1e3),u=await o.getTelemetry(r.streamName,l,g);if(u.length>0){const c=u[0].points;n(c)}},1e3);return()=>{clearInterval(s)}}return()=>{}}async subscribeToRealtimeMessages(t,r,n){await this.createRealtimeConnection(t,signaling_pb.SessionType.OBSERVE);const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.startListeningToRealtimeDataStream({name:r}),o.addRealtimeListener((s,g)=>{g.header.stream.streamName===r&&n(s,g)}))}async unsubscribeToRealtimeMessages(t,r,n){const o=this.mapRealtimeConnections.get(t);o&&o!=="loading"&&(o.stopListeningToRealtimeDataStream({name:r}),o.removeRealtimeListener(n))}subscribeToJson(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="json"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.json())),{deviceId:t,sourceId:r.id,data:g}},n);if(r.sourceType==="realtime"){const o=async(s,g)=>{g.payload.jsonString&&n(JSON.parse(g.payload.jsonString.value))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToText(t,r,n){return r.sourceType==="telemetry"?this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="text"){const[c,p]=u.points[u.points.length-1];s=p}}return s&&(g=await fetch(s).then(l=>l.text())),{deviceId:t,sourceId:r.id,data:g}},n):()=>{}}subscribeToPointCloud(t,r,n){const o=this.getAvailablePCDWorker();if(!o)throw new Error("No available pointcloud worker");if(r.sourceType==="telemetry"&&r.streamType!=="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="point cloud"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g){const{url:u}=g;l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g==null?void 0:g.worldToLocal,pcd:l}}},n);if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async s=>{let g,l;for(let u=0;u<s.length;u+=1){const c=s[u];if(c.deviceId===t&&c.name===r.streamName&&c.type==="localization"){const[p,v]=c.points[c.points.length-1];g=v;break}}if(g&&g.pointClouds){const{url:u}=g.pointClouds[0];l=await new Promise(c=>{o.postMessage({url:u}),o.onmessage=p=>{p.data.url===u&&c(p.data.pcd)}})}return{deviceId:t,sourceId:r.id,data:{worldToLocal:g&&(g!=null&&g.pointClouds)&&(g!=null&&g.pointClouds[0])?g.pointClouds[0].worldToLocal:void 0,pcd:l}}},n);if(r.sourceType==="realtime"){const s=async(g,l)=>{var u;if(l.payload.pointCloud){const c=Math.random(),p=await new Promise(v=>{o.postMessage({id:c,pointCloud:defined(l.payload.pointCloud).data}),o.onmessage=_=>{_.data.id===c&&v(_.data.pcd)}});n({worldToLocal:(u=l.payload.pointCloud)==null?void 0:u.world_to_local,pcd:p})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,s),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,s)}}return()=>{}}subscribeToGeometry(t,r,n){throw new Error("type error in realtime sdk")}subscribeToJointState(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{g.payload.jointState&&n(g.payload.jointState)};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}return()=>{}}subscribeToGridMap(t,r,n){if(r.sourceType==="realtime"){const o=(s,g)=>{if(g.payload.jsonString){const l=JSON.parse(g.payload.jsonString.value);n({width:l.info.width,height:l.info.height,worldToLocal:{translation:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0,w:1}},resolution:l.info.resolution,origin:{translation:l.info.origin.position,rotation:l.info.origin.orientation},data:l.data,alpha:l.data.map(()=>255)})}};return this.subscribeToRealtimeMessages(t,r.rosTopicName,o),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,o)}}else if(r.sourceType==="telemetry"&&r.streamType==="localization")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s,g;for(let l=0;l<o.length;l+=1){const u=o[l];if(u.deviceId===t&&u.name===r.streamName&&u.type==="localization"){const[c,p]=u.points[u.points.length-1];s=p}}if(s&&s.map){const l=document.createElement("canvas"),u=await this.fetchImage(s.map.url);l.width=u.width,l.height=u.height;const c=l.getContext("2d",{willReadFrequently:!0});c&&c.drawImage(u,0,0);const p=c==null?void 0:c.getImageData(0,0,u.width,u.height),v=[],_=[];if(p)for(let y=0;y<p.data.length;y+=4){const f=p.data[y],h=p.data[y+3];v.push(f),_.push(h)}g={width:s.map.width,height:s.map.height,worldToLocal:s.map.worldToLocal,resolution:s.map.resolution,origin:s.map.origin,alpha:_,data:v}}return{deviceId:t,sourceId:r.id,data:g}},n);throw new Error("Not implemented")}subscribeToVideo(t,r,n){const o=this.createH264Drawer(),s=document.createElement("CANVAS");if(s.width=0,s.height=0,o.setCanvas(s),o.start(),r.sourceType==="realtime"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rosTopicName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rosTopicName,g)}}if(r.sourceType==="hardware"){const g=(l,u)=>{u.payload.h264VideoFrame&&(o.receiveEncodedFrame(u.payload.h264VideoFrame),o&&o.canvas&&o.canvas.width>0&&o.canvas.height>0&&n(o.canvas))};return this.subscribeToRealtimeMessages(t,r.rtcStreamName,g),()=>{this.unsubscribeToRealtimeMessages(t,r.rtcStreamName,g)}}return()=>{o.stop()}}subscribeToTransformTree(t,r,n){if(r.sourceType==="telemetry")return this.addRemovableTelemetrySubscription(t,r,async o=>{let s;for(let g=0;g<o.length;g+=1){const l=o[g];if(l.deviceId===t&&l.name===r.streamName&&l.type==="transform tree"){const[u,c]=l.points[l.points.length-1];s=c}}return{deviceId:t,sourceId:r.id,data:s}},n);throw new Error("not implemented for this source type "+r.sourceType)}subscribeToLocation(t,r,n){throw new Error("Not implemented")}}const NoData=Symbol("no_data"),LoadingData=Symbol("loading_data"),FailedData=Symbol("failed_data");class TelemetryUniverseData extends BasicUniverseDataConnector{constructor(){super();de(this,"liveIntervalHandle");de(this,"timeFinders",[]);de(this,"videoCache",new StoreCache({capacity:50}));this.timeChangeListeners.push(this.onTimeChange.bind(this)),this.onTimeChange("live")}subscribeToBitset(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToPath(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"localization",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];let c=u;u.url&&(s.postMessage({url:u.url}),s.onmessage=p=>{c=p.data.response,c.path&&o({worldToLocal:c.path.worldToLocal,poses:c.path.poses})})});return()=>{this.releaseDataFetchWorker(s),g()}}onTimeChange(r){r==="live"?this.liveIntervalHandle=setInterval(()=>{this.findDataForTime(new Date)},300):(this.liveIntervalHandle&&clearInterval(this.liveIntervalHandle),this.findDataForTime(r))}findDataForTime(r){this.timeFinders.forEach(n=>{n(r)})}addFinder(r,n,o,s,g){const l=u=>{let c;g?c=addYears(u,-1):c=addSeconds(u,-15);let p;g?p=u:p=addSeconds(u,5);let v=this.queryStore.moduleQuery({deviceIds:[n]},o,s,c,p,g);if(v===void 0)r(void 0);else if(v==="too much data")r("too much data");else if(v.length>0){const y=v[0].points;if(y.length>0){const f=y[y.length-1];if(g){let h=f[0],w=f[1];y.forEach(C=>{const L=C[0],T=C[1];Math.abs(L-u.getTime())<Math.abs(h-u.getTime())&&(h=L,w=T)}),r([[h,w]])}else r(y)}else r(void 0)}else r(void 0)};return this.timeFinders.push(l),l}removeFinder(r){this.timeFinders=this.timeFinders.filter(n=>n!==r)}subscribeTelemetry(r,n,o,s){if(n.sourceType!=="telemetry")throw new Error("Invalid source type");const g=this.addFinder(s,r,n.streamName,o,n.latestDataPoint||!1);return()=>{this.removeFinder(g)}}subscribeToPointCloud(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailablePCDWorker();if(!s)throw new Error("No available pointcloud worker");const g=this.getAvailableDataFetchWorker();if(!g)throw new Error("No available data fetch worker");let l=()=>{},u=()=>{};return n.streamType==="point cloud"?l=this.subscribeTelemetry(r,n,"point cloud",async c=>{if(c==="too much data"||c===void 0){o(NoData);return}const p=c[c.length-1][1];if(typeof p=="string")o(JSON.parse(p));else{const{url:v}=p;s.postMessage({url:v}),s.onmessage=_=>{_.data.url===v&&o({worldToLocal:p.worldToLocal,pcd:_.data.pcd})}}}):n.streamType==="localization"&&(u=this.subscribeTelemetry(r,n,"localization",async c=>{if(c==="too much data"||c===void 0){o(NoData);return}let p=c[c.length-1][1];p.url&&(g.postMessage({url:p.url}),g.onmessage=v=>{if(p=v.data.response,p.pointClouds){const{url:_,worldToLocal:y}=p.pointClouds[0];s.postMessage({url:_}),s.onmessage=f=>{f.data.url===_&&o({worldToLocal:y,pcd:f.data.pcd})}}})})),()=>{this.releasePCDWorker(s),this.releaseDataFetchWorker(g),l(),u()}}subscribeToOdometry(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"localization",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];let c=u;u.url&&(s.postMessage({url:u.url}),s.onmessage=p=>{c=p.data.response,c.odometry&&o({worldToLocal:c.odometry.worldToLocal,pose:{translation:{x:c.odometry.pose.translation.x,y:c.odometry.pose.translation.y,z:c.odometry.pose.translation.z},rotation:{x:c.odometry.pose.rotation.x,y:c.odometry.pose.rotation.y,z:c.odometry.pose.rotation.z,w:c.odometry.pose.rotation.w}},covariance:[]})})});return()=>{this.releaseDataFetchWorker(s),g()}}subscribeToPose(r,n,o){throw new Error("Method not implemented for telemetry universe connector.")}subscribeToGeometry(r,n,o){if(n.sourceType==="telemetry"){const s=this.getAvailableDataFetchWorker();if(!s)throw new Error("No available data fetch worker");const g=this.subscribeTelemetry(r,n,"json",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}let u=l[l.length-1][1];u.startsWith("http")&&(s.postMessage({url:u}),s.onmessage=c=>{u=JSON.stringify(c.data),o(JSON.parse(u))})});return()=>{this.releaseDataFetchWorker(s),g()}}else throw new Error("Realtime geometry note supported")}subscribeToJointState(r,n,o){return this.subscribeToJson(r,n,o)}subscribeToGridMap(r,n,o){const s={};if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const g=this.getAvailableDataFetchWorker();if(!g)throw new Error("No available data fetch worker");const l=this.subscribeTelemetry(r,n,"localization",async u=>{if(u==="too much data"||u===void 0){o(NoData);return}const c=u[u.length-1][1];if(c.url){if(s[c.url]){o(s[c.url]);return}g.postMessage({url:c.url}),g.onmessage=async p=>{const v=p.data.response.map;if(v){const _=document.createElement("canvas"),y=await this.fetchImage(v.url);_.width=y.width,_.height=y.height;const f=_.getContext("2d",{willReadFrequently:!0});f&&f.drawImage(y,0,0);const h=f==null?void 0:f.getImageData(0,0,y.width,y.height),w=[],C=[];if(h)for(let T=0;T<h.data.length;T+=4){const E=h.data[T],d=h.data[T+3];w.push(E),C.push(d)}const L={width:v.width,height:v.height,worldToLocal:v.worldToLocal,resolution:v.resolution,origin:v.origin,alpha:C,data:w};s[c.url]=JSON.parse(JSON.stringify(L)),o(L)}}}});return()=>{this.releaseDataFetchWorker(g),l()}}subscribeToVideo(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"video",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1],{url:l}=g,u=this.videoCache.get(l,async()=>new Promise(c=>{const p=document.createElement("video");p.src=l,p.onload=()=>{}}));if(u){const c=document.createElement("canvas");c.width=u.videoWidth,c.height=u.videoHeight;const p=c.getContext("2d");p&&p.drawImage(u,0,0),o(c)}})}subscribeToTransformTree(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"transform tree",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToLocation(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");const s=this.subscribeToJson(r,n,o),g=this.subscribeTelemetry(r,n,"location",async l=>{if(l==="too much data"||l===void 0){o(NoData);return}const u=l[l.length-1][1];o(u)});return()=>{s(),g()}}subscribeToJson(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"json",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}let g=s[s.length-1][1];g.startsWith("http")&&(g=await(await fetch(g)).text()),o(JSON.parse(g))})}subscribeToText(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"text",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s[s.length-1][1])})}subscribeToNumeric(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToNumericSet(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"numeric set",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}o(s)})}subscribeToImage(r,n,o){if(n.sourceType!=="telemetry")throw new Error("Telemetry sources only supported");return this.subscribeTelemetry(r,n,"image",async s=>{if(s==="too much data"||s===void 0){o(NoData);return}const g=s[s.length-1][1].url,l=new Image;l.src=g,l.onload=()=>{const u=document.createElement("canvas");u.width=l.width,u.height=l.height;const c=u.getContext("2d");c&&(c.drawImage(l,0,0),o(u))}})}}exports.Account=Account;exports.App=App;exports.AudioPlayer=AudioPlayer;exports.Authentication=Authentication;exports.BasicUniverseDataConnector=BasicUniverseDataConnector;exports.BinaryRequestDataChannel=BinaryRequestDataChannel;exports.CaptureStream=CaptureStream;exports.DataChannel=DataChannel;exports.Device=Device;exports.FailedData=FailedData;exports.Fleet=Fleet;exports.KeyValue=KeyValue;exports.LiveUniverseData=LiveUniverseData;exports.LoadingData=LoadingData;exports.Manipulator=Manipulator;exports.NoData=NoData;exports.PeerDevice=PeerDevice;exports.QueryStore=QueryStore;exports.Role=Role;exports.SessionType=SessionTypeConstants;exports.TelemetryUniverseData=TelemetryUniverseData;exports.TextRequestDataChannel=TextRequestDataChannel;exports.User=User;exports.accessLevels=accessLevels;exports.administrator=administrator;exports.aggregateByDateFunctions=aggregateByDateFunctions;exports.aggregateFunctionMap=aggregateFunctionMap;exports.aggregateFunctions=aggregateFunctions;exports.aggregateLevels=aggregateLevels;exports.annotationTypes=annotationTypes;exports.createRtcStreamMessage=distExports.createRtcStreamMessage;exports.defined=defined$1;exports.definedAndNotNull=definedAndNotNull;exports.eventTypes=eventTypes;exports.formatTimeFrameText=formatTimeFrameText;exports.getAverage=getAverage;exports.getCount=getCount;exports.getMax=getMax;exports.getMin=getMin;exports.getStandardDeviation=getStandardDeviation;exports.getSum=getSum;exports.getVariance=getVariance;exports.healthStatuses=healthStatuses;exports.interventionTypes=interventionTypes;exports.operator=operator;exports.severities=severities;exports.timeout=timeout;exports.vailableAggregationIntervals=vailableAggregationIntervals;exports.videoMimeTypes=videoMimeTypes;exports.viewer=viewer;
|
|
103
103
|
//# sourceMappingURL=data-sdk.cjs.js.map
|