Skip to main content

Class: PresenceListener<T>

A class that listens for presence messages and broadcasts the client's own presence messages.

Type parameters

Name
T

Constructors

constructor

new PresenceListener<T>(options)

Type parameters

Name
T

Parameters

NameTypeDescription
optionsObject-
options.callback?(presence: Record<string, WrappedPresenceMessage<T>>) => voidCallback to call when the presence of any peer changes.
options.clientIdstringClient ID.
options.dbDbConnectionConnection to the DriftDB room.
options.initialStateTInitial state of the client's own presence.
options.key?stringKey to listen for presence messages on (defaults to __presence).
options.maxPresenceInterval?numberMaximum interval between presence updates (defaults to 1 second).
options.minPresenceInterval?numberMinimum interval between presence updates (defaults to 20 ms).

Defined in

js-pkg/packages/driftdb/src/presence.ts:37

Properties

callback

Private callback: (presence: Record<string, WrappedPresenceMessage<T>>) => void

Type declaration

▸ (presence): void

Parameters
NameType
presenceRecord<string, WrappedPresenceMessage<T>>
Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:23


clientId

Private clientId: string

Defined in

js-pkg/packages/driftdb/src/presence.ts:21


db

Private db: DbConnection

Defined in

js-pkg/packages/driftdb/src/presence.ts:22


interval

Private interval: null | Timer = null

Defined in

js-pkg/packages/driftdb/src/presence.ts:25


key

Private key: string

Defined in

js-pkg/packages/driftdb/src/presence.ts:20


lastUpdate

Private lastUpdate: number = 0

Defined in

js-pkg/packages/driftdb/src/presence.ts:30


maxPresenceInterval

Private maxPresenceInterval: number

Defined in

js-pkg/packages/driftdb/src/presence.ts:27


minPresenceInterval

Private minPresenceInterval: number

Defined in

js-pkg/packages/driftdb/src/presence.ts:26


nextUpdate

Private nextUpdate: number

Defined in

js-pkg/packages/driftdb/src/presence.ts:33


presence

Private presence: Record<string, WrappedPresenceMessage<T>> = {}

Defined in

js-pkg/packages/driftdb/src/presence.ts:24


state

Private state: T

Defined in

js-pkg/packages/driftdb/src/presence.ts:19


updateHandle

Private updateHandle: null | Timeout = null

Defined in

js-pkg/packages/driftdb/src/presence.ts:35

Methods

destroy

destroy(): void

Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:88


onMessage

Private onMessage(event): void

Parameters

NameType
eventSequenceValue

Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:100


subscribe

subscribe(): void

Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:73


update

Private update(): void

Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:118


updateState

updateState(value): void

Update the client's own presence state.

This is debounced locally, so if it is called multiple times in a short period of time, only the last call will be sent.

Parameters

NameType
valueT

Returns

void

Defined in

js-pkg/packages/driftdb/src/presence.ts:139