Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface SocketOptions

Hierarchy

  • SocketOptions

Index

Properties

Optional autoReconnect

autoReconnect: undefined | false | true

Determines if the socket should automatically re-connect with the upstream service upon an abnormal disconnection.

The re-connection happens after the given SocketOptions.reconnectDelayInMs has elapsed.

default

true

Optional id

id: undefined | string

An id to assign to this socket instance. This is used through the debug package to display a different debug tag when provided (i.e. dfuse:socket:<id>).

default

undefined

Optional keepAlive

keepAlive: undefined | false | true

Whether ping messages should be send automatically at regular interval by the Socket instance. The actual interval used can be defined by providing the SocketOptions.keepAliveIntervalInMs option.

default

true

Optional keepAliveIntervalInMs

keepAliveIntervalInMs: undefined | number

The interval of time at which ping messages are automatically sent to the remote endpoint. This is time that elapsed between two consecutives ping messages.

As no effect if SocketOptions.keepAlive is sets to false.

default

30s (See DEFAULT_KEEP_ALIVE_INTERVAL_IN_MS)

Optional onClose

onClose: undefined | ((event: any) => void)

A callback that can be provided to be notified when the Socket receives a close event. The close event is always emitted even when an error has occurred, it will however always come after the error event.

The callback will be invoked with the actual event as defined by the WebSocket instance used.

Important Note

The actual event object you will receive is different wheter you use the Browser WebSocket instance (CloseEvent) or depending on the Node.js library you use (If you use ws package, then it's CloseEvent)

default

() => {} (noop)

Optional onError

onError: undefined | ((event: any) => void)

A callback that can be provided to be notified when the Socket receives an error event. The error event is always emitted only where an error occurred with the connection. It is not emitted on a normal and expected disconnection with the server (when closing the underlying socket for example).

The callback will be invoked with the actual event as defined by the WebSocket instance used.

Important Note

The actual event object you will receive is different wheter you use the Browser WebSocket instance (ErrorEvent) or depending on the Node.js library you use (If you use ws package, then it's ErrorEvent)

default

() => {} (noop)

Optional onReconnect

onReconnect: undefined | (() => void)

A callback that can be provided to be notified when the Socket just performed a re-connection. This will be called after a successful re-connection. When the callback is invoked, the connection with the server has actually resumed and stream can be restarted or other actions can be taken.

This is a post re-connection callback.

default

() => {} (noop)

Optional reconnectDelayInMs

reconnectDelayInMs: undefined | number

The delay after the abnormal closure of the connection before trying a re-connection. As no effect if SocketOptions.autoReconnect is sets to false.

default

2.5s (See DEFAULT_RECONNECT_DELAY_IN_MS)

Optional webSocketFactory

webSocketFactory: WebSocketFactory

A factory method used to create the WebSocket instance that should be used by the Socket instance.

Inferrence

When not provided (default), the factory to use is actually inferred based on the runtime environment.

If a window.WebSocket variable exists, which should be the case on a Browser environment, the factory used will call new window.WebSocket(...) to instantiate the WebSocket instance.

If a global.WebSocket variable exists, which can be the case upon a global.WebSocket = ... call at the bootstrap phase in a Node.js environment, the factory used will call new global.WebSocket(...) to instantiate the WebSocket instance.

Finally, if no WebSocket instance could be determined, a DfuseError is thrown with a message explaining the situtation and a link to the documentation on how to solve the problem.

default

undefined (Inferred based on environment, see Inferrence note above)

Optional webSocketProtocols

webSocketProtocols: string | string[]

The set of webSocket protocols we want to send when performing the connection handshake. For example, GraphQL subscription over WebSocket uses "graphql-ws" protocol while standard WebSocket connection can pass undefined as the value.

default

undefined

Generated using TypeDoc