Skip to main content

Class: DbConnection

A connection to a DriftDB room.

Constructors

constructor

new DbConnection(params?)

Parameters

NameType
params?DbConnectionParams

Defined in

js-pkg/packages/driftdb/src/index.ts:45

Properties

WebSocket

WebSocket: Object

Call signature

new WebSocket(url, protocols?): WebSocket

Parameters
NameType
urlstring | URL
protocols?string | string[]
Returns

WebSocket

Type declaration

NameType
CLOSEDnumber
CLOSINGnumber
CONNECTINGnumber
OPENnumber
prototypeWebSocket

Defined in

js-pkg/packages/driftdb/src/index.ts:43


activeLatencyTest

activeLatencyTest: null | LatencyTest = null

Defined in

js-pkg/packages/driftdb/src/index.ts:40


cbor

cbor: boolean = false

Defined in

js-pkg/packages/driftdb/src/index.ts:41


closed

closed: boolean = false

Defined in

js-pkg/packages/driftdb/src/index.ts:42


connection

connection: null | WebSocket = null

Defined in

js-pkg/packages/driftdb/src/index.ts:31


dbUrl

dbUrl: null | string = null

Defined in

js-pkg/packages/driftdb/src/index.ts:38


messageListener

messageListener: EventListener<MessageFromDb>

Defined in

js-pkg/packages/driftdb/src/index.ts:34


queue

queue: MessageToDb[] = []

Defined in

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


reconnectLoopHandle

reconnectLoopHandle: null | Timeout = null

Defined in

js-pkg/packages/driftdb/src/index.ts:39


sizeSubscriptions

sizeSubscriptions: SubscriptionManager<number>

Defined in

js-pkg/packages/driftdb/src/index.ts:36


status

status: ConnectionStatus

Defined in

js-pkg/packages/driftdb/src/index.ts:32


statusListener

statusListener: EventListener<ConnectionStatus>

Defined in

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


subscriptions

subscriptions: SubscriptionManager<SequenceValue>

Defined in

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

Methods

connect

connect(dbUrl, cbor?): Promise<void>

Connect to a DriftDB room.

Parameters

NameTypeDefault valueDescription
dbUrlstringundefinedThe URL of the DriftDB room to connect to.
cborbooleanfalseWhether to use CBOR encoding for messages.

Returns

Promise<void>

A promise that resolves when the connection is established.

Defined in

js-pkg/packages/driftdb/src/index.ts:67


debugUrl

Private debugUrl(): null | string

Get the URL of the DriftDB UI for this connection.

Returns

null | string

The URL of the DriftDB UI, or null if the connection is not open.

Defined in

js-pkg/packages/driftdb/src/index.ts:188


disconnect

disconnect(): void

Close the connection to the DriftDB room.

Returns

void

Defined in

js-pkg/packages/driftdb/src/index.ts:198


send

send(message): void

Send a message to the DriftDB server.

Parameters

NameTypeDescription
messageMessageToDbThe message to send.

Returns

void

Defined in

js-pkg/packages/driftdb/src/index.ts:221


setStatus

Private setStatus(connected): void

Parameters

NameType
connectedboolean

Returns

void

Defined in

js-pkg/packages/driftdb/src/index.ts:211


subscribe

subscribe(key, listener, sizeCallback?, subscribeOptions?): void

Subscribe to a key in the DriftDB room.

Parameters

NameTypeDescription
keystringThe key to subscribe to.
listener(event: SequenceValue) => voidA callback that will be called whenever a new value is pushed to the key.
sizeCallback?(size: number) => voidAn optional callback that will be called whenever the size of the server's retained stream changes.
subscribeOptions?SubscribeOptions-

Returns

void

Defined in

js-pkg/packages/driftdb/src/index.ts:247


testLatency

testLatency(): null | Promise<number>

Test the connection latency by sending a ping to the server.

Returns

null | Promise<number>

A promise that resolves to the latency in milliseconds, or null if the connection is not open.

Defined in

js-pkg/packages/driftdb/src/index.ts:170


unsubscribe

unsubscribe(subject, listener, sizeCallback?): void

Unsubscribe from a key in the DriftDB room.

Parameters

NameTypeDescription
subjectstring-
listener(event: SequenceValue) => voidThe callback that was passed to subscribe.
sizeCallback?(size: number) => voidThe callback that was passed to subscribe.

Returns

void

Defined in

js-pkg/packages/driftdb/src/index.ts:269