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
Name | Type | Description |
---|---|---|
options | Object | - |
options.callback? | (presence : Record <string , WrappedPresenceMessage <T >>) => void | Callback to call when the presence of any peer changes. |
options.clientId | string | Client ID. |
options.db | DbConnection | Connection to the DriftDB room. |
options.initialState | T | Initial state of the client's own presence. |
options.key? | string | Key to listen for presence messages on (defaults to __presence ). |
options.maxPresenceInterval? | number | Maximum interval between presence updates (defaults to 1 second). |
options.minPresenceInterval? | number | Minimum 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
Name | Type |
---|---|
presence | Record <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
Name | Type |
---|---|
event | SequenceValue |
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
Name | Type |
---|---|
value | T |
Returns
void