class Jetstream

extends EventEmitter<JetstreamEvents<ResolvedCollections>>

The Jetstream client.

Constructor

constructor(options?)

Parameters

options?: JetstreamOptions<WantedCollections>

Properties

ws?: ReconnectingWebSocket

WebSocket connection to the server.

url: URL

The full connection URL.

cursor?: number

The current cursor.

Methods

start()

Opens a WebSocket connection to the server.

close()

Closes the WebSocket connection.

onCreate(collection, listener)

Listen for records created in a specific collection.

Parameters

collection: T

The name of the collection to listen for.

listener: (event: CommitCreateEvent<T>) => void

A callback function that receives the commit event.

onUpdate(collection, listener)

Listen for records updated in a specific collection.

Parameters

collection: T

The name of the collection to listen for.

listener: (event: CommitUpdateEvent<T>) => void

A callback function that receives the commit event.

onDelete(collection, listener)

Listen for records deleted in a specific collection.

Parameters

collection: T

The name of the collection to listen for.

listener: (event: CommitDeleteEvent<T>) => void

A callback function that receives the commit event.

updateOptions(payload)

Send a message to update options for the duration of this connection.

Parameters

payload: Pick<JetstreamOptions<Collection>, "maxMessageSizeBytes" | "wantedCollections" | "wantedDids">
Overload 1/7

on(event, listener)

Emitted when the connection is opened.

Parameters

event: "open"
listener: () => void

Returns

this

on(event, listener)

Emitted when the connection is closed.

Parameters

event: "close"
listener: () => void

Returns

this

on(event, listener)

Emitted when any commit is received.

Parameters

event: "commit"
listener: (event: CommitEvent<ResolvedCollections>) => void

Returns

this

on(event, listener)

Emitted when an account is updated.

Parameters

event: "account"
listener: (event: AccountEvent) => void

Returns

this

on(event, listener)

Emitted when an identity event is received.

Parameters

event: "identity"
listener: (event: IdentityEvent) => void

Returns

this

on(event, listener)

Emitted when a network error occurs.

Parameters

event: "error"
listener: (error: Error cursor?: number) => void

A callback function that receives the error and the last known cursor.

Returns

this

on(collection, listener)

Listen for all commits related to a specific collection.

Parameters

collection: T

The name of the collection.

listener: (event: CommitEvent<T>) => void

A callback function that receives the commit event.

Returns

this