Class: Subscription

stream~Subscription(client, dispatcher)

new Subscription(client, dispatcher)

A stream subscription which dispatches events received to the registered listener functions. This class must be constructed via Client#stream method.

Parameters:
Name Type Description
client StreamClient

Internal stream client interface.

dispatcher EventDispatcher

Internal event dispatcher interface.

Source:

Methods

close()

Stops the current subscription and closes the underlying network connection.

Source:

on(event, callback) → {module:stream~Subscription}

Subscribes to an event type.

Parameters:
Name Type Description
event string

The event's type.

callback module:stream~Subscription~eventCalllback

A callback function.

Source:
Returns:

This instance.

Type
module:stream~Subscription

start() → {module:stream~Subscription}

Initiates the underlying subscription network calls.

Source:
Returns:

This instance.

Type
module:stream~Subscription

Type Definitions

eventCalllback(data, event)

The callback to be executed when an new event occurs.

Parameters:
Name Type Description
data any

The event's data field.

event object

The event's entire object.

Source:

Events

error

An error event is fired both for client and server errors that may occur as a result of a subscription.

Type:
  • object
Properties:
Name Type Attributes Default Description
type string 'error'

The event type.

txn number <nullable>

The event's transaction timestamp.

event Error

The underlying error.

Source:

history_rewrite

A history rewrite event occurs upon any modifications to the history of the subscribed document.

Type:
  • object
Properties:
Name Type Default Description
type string 'history_rewrite'

The event type.

txn number

The event's transaction timestamp.

event object

The event's data.

Source:

snapshot

A snapshot event. A snapshot event is fired once the document stream helper finishes loading the subscribed document's snapshot data. See Client#stream for more details on the document stream helper.

Type:
  • object
Properties:
Name Type Default Description
type string 'snapshot'

The event type.

txn number

The event's transaction timestamp.

event object

The event's data.

Source:

start

Stream's start event. A stream subscription always begins with a start event. Upcoming events are guaranteed to have transaction timestamps equal to or greater than the stream's start timestamp.

Type:
  • object
Properties:
Name Type Default Description
type string 'start'

The event type.

txn number

The event's transaction timestamp.

event module:number

The stream start timestamp.

Source:

version

A version event occurs upon any modifications to the current state of the subscribed document.

Type:
  • object
Properties:
Name Type Default Description
type string 'version'

The event type.

txn number

The event's transaction timestamp.

event object

The event's data.

Source: