Skip to content
import StreamConnection from "@arcgis/core/layers/support/StreamConnection.js";
Inheritance:
StreamConnectionAccessor
Since
ArcGIS Maps SDK for JavaScript 4.25

A web socket connection to a stream service. The connection to the stream service can be established by calling StreamLayer's connect() method.

See also
Example
// get layer's connection configurations
const parameters = layer.createConnectionParameters();
// set the spatial reference of the service geometries
parameters.spatialReference = new SpatialReference({
wkid: 2154
});
const connection = await layer.connect(parameters);
// listen to date-received event once the connection is established
// create a graphic from the JSON object returned and add them to view
connection.on("data-received", (feature) => {
const graphic = Graphic.fromJSON(feature);
graphic.symbol = myPointSymbol;
view.graphics.push(graphic);
});
// close the connection when it is not needed anymore
connection.destroy();

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
PropertyTypeClass
connectionError
readonly
connectionStatus
readonly
declaredClass
readonly inherited

connectionError

readonly Property
Type
EsriError | null | undefined

The error that explains an unsuccessful attempt to connect to the stream service or an unexpected disconnection from the stream service.

connectionStatus

readonly Property
Type
StreamConnectionStatus

The status of the Web Socket connection with the stream service. This property can be watched to see if the connection is lost unexpectedly.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

Methods

MethodSignatureClass
destroy(): void
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle

destroy

Method
Signature
destroy (): void

Destroys the existing connection instance to the stream service.

Returns
void

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

hasEventListener

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});

Events

data-received

Event
data-received: CustomEvent<Feature>

Fires when the stream connection receives data. The event object contains the message properties received from the stream service.

bubbles composed cancelable

Type definitions

FeatureMessage

Type definition

A message to add Features to a StreamLayer on the client by calling its sendMessageToClient() method. An array of JSON Features that can be added to a StreamLayer on the client by calling its sendMessageToClient() method. Each feature is an esri Feature JSON object as defined in the Feature object specification.

type

Property
Type
"features"

The type of message being sent to the client.

features

Property
Type
Feature[]

An array of JSON Features to add to a StreamLayer on the client.

DeleteMessage

Type definition

A message to delete features from a StreamLayer on the client by calling its sendMessageToClient() method.

type

Property
Type
"delete"

The type of message being sent to the client.

trackIds

Property
Type
number[]

An array of track IDs identifying the features to delete from a StreamLayer on the client.

objectIds

Property
Type
ObjectId[]

An array of object IDs identifying the features to delete from a StreamLayer on the client.

ClearMessage

Type definition

A message to clear all features from a StreamLayer on the client by calling its sendMessageToClient() method.

type

Property
Type
"clear"

The type of message being sent to the client.

Message

Type definition

The message to send to a StreamLayer on the client by calling its sendMessageToClient() method.