Class: Subscription

stream~ Subscription


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.

Methods


close()

Stops the current subscription and closes the underlying network connection.


on(event, callback)

Subscribes to an event type.

Parameters:
Name Type Description
event string

The event's type.

callback module:stream~Subscription~eventCalllback

A callback function.

Returns:

This instance.

Type
module:stream~Subscription

start()

Initiates the underlying subscription network calls.

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.

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 Argument Default Description
type string 'error'

The event type.

txn number <nullable>

The event's transaction timestamp.

event Error

The underlying error.


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.


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.


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.


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.