UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 2.75 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import{watch as s}from"../../../../../core/reactiveUtils.js";import{property as n,subclass as a}from"../../../../../core/accessorSupport/decorators.js";const i=2500;let r=class extends t{constructor(e){super(),this._connection=e,this._enabledEventTypes=new Set,this._updateInfo={websocket:0,client:0},this._lastTime=performance.now(),this._queuedCommands=[],this.addHandles([s(()=>this._strategy?.connectionStatus??"disconnected",e=>{this._layerView.setProperty({propertyName:"pipelineConnectionStatus",value:e})},{initial:!0}),s(()=>this._strategy?.errorString||null,e=>this._layerView.setProperty({propertyName:"pipelineErrorString",value:e}),{initial:!0})])}destroy(){this._strategy=null,this.removeAllHandles()}get _layerView(){return this._connection.layerView}set strategy(e){null==this._strategy&&this._resetUpdateInfo(performance.now());const t="event-handles";this.removeHandles(t),null!=e&&(this.addHandles([e.events.on("data-received",e=>this._onFeature(e)),e.events.on("message-received",e=>this._onWebSocketMessage(e)),e.events.on("features-updated",e=>this._onUpdate(e)),e.events.on("tick",()=>this._onTick())],t),this._queuedCommands.forEach(t=>t(e)),this._queuedCommands=[]),this._strategy=e}updateCustomParameters(e){null!=e&&this._callOrEnqueue(t=>t.updateCustomParameters(e))}sendMessageToSocket(e){this._callOrEnqueue(t=>t.sendMessageToSocket(e))}sendMessageToClient(e){this._callOrEnqueue(t=>t.sendMessageToClient(e))}enableEvent(e,t){t?this._enabledEventTypes.add(e):this._enabledEventTypes.delete(e)}disconnect(){this._strategy?.disconnect()}connect(){this._strategy?.connect()}clear(){this._strategy?.clear()}_onWebSocketMessage(e){this._enabledEventTypes.has("message-received")&&this._layerView.emitEvent({name:"message-received",event:e})}_onFeature(e){this._updateInfo.websocket++,this._enabledEventTypes.has("data-received")&&this._layerView.emitEvent({name:"data-received",event:{attributes:e.attributes,centroid:e.centroid,geometry:e.geometry}})}_onUpdate(e){this._updateInfo.client+=e}_onTick(){const e=performance.now(),t=e-this._lastTime;if(t>i){const s=Math.round(this._updateInfo.client/(t/1e3)),n=Math.round(this._updateInfo.websocket/(t/1e3));this._resetUpdateInfo(e),this._layerView.emitEvent({name:"update-rate",event:{client:s,websocket:n}})}}_resetUpdateInfo(e){this._lastTime=e,this._updateInfo.client=0,this._updateInfo.websocket=0}_callOrEnqueue(e){null!=this._strategy?e(this._strategy):this._queuedCommands.push(e)}};e([n()],r.prototype,"_strategy",void 0),r=e([a("esri.views.2d.layers.features.sources.StreamMessenger")],r);export{r as StreamMessenger};