Class: DbConnection
A connection to a DriftDB room.
Constructors
constructor
• new DbConnection(params?)
Parameters
| Name | Type |
|---|---|
params? | DbConnectionParams |
Defined in
js-pkg/packages/driftdb/src/index.ts:45
Properties
WebSocket
• WebSocket: Object
Call signature
• new WebSocket(url, protocols?): WebSocket
Parameters
| Name | Type |
|---|---|
url | string | URL |
protocols? | string | string[] |
Returns
WebSocket
Type declaration
| Name | Type |
|---|---|
CLOSED | number |
CLOSING | number |
CONNECTING | number |
OPEN | number |
prototype | WebSocket |
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
| Name | Type | Default value | Description |
|---|---|---|---|
dbUrl | string | undefined | The URL of the DriftDB room to connect to. |
cbor | boolean | false | Whether 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
| Name | Type | Description |
|---|---|---|
message | MessageToDb | The message to send. |
Returns
void
Defined in
js-pkg/packages/driftdb/src/index.ts:221
setStatus
▸ Private setStatus(connected): void
Parameters
| Name | Type |
|---|---|
connected | boolean |
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
| Name | Type | Description |
|---|---|---|
key | string | The key to subscribe to. |
listener | (event: SequenceValue) => void | A callback that will be called whenever a new value is pushed to the key. |
sizeCallback? | (size: number) => void | An 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
| Name | Type | Description |
|---|---|---|
subject | string | - |
listener | (event: SequenceValue) => void | The callback that was passed to subscribe. |
sizeCallback? | (size: number) => void | The callback that was passed to subscribe. |
Returns
void