@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.07 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../../../../chunks/tslib.es6.js";import t from"../../../../../core/Accessor.js";import{watch as s}from"../../../../../core/reactiveUtils.js";import{property as n}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as r}from"../../../../../core/accessorSupport/decorators/subclass.js";const a=2500;let o=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>a){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()],o.prototype,"_strategy",void 0),o=e([r("esri.views.2d.layers.features.sources.StreamMessenger")],o);export{o as StreamMessenger};