Extended WebSocket client
BigStateWsDeliveryClientExtended stores the delivery host and credential, opens the socket when you add deliveries, resends delivery.listen after reconnect, and keeps the handler list.
The base BigStateWsDeliveryClient is documented on Connect to WebSocket delivery. React, Angular, and Vue call this extended client for you.
new BigStateWsDeliveryClientExtended(options)- npmnpm install bigstate.client.javascript
- baseUrlstringRequired
Delivery host. The client appends `/v1` automatically.
example: https://ws.delivery.bigstate.dev - apiKeystringOptional
API key used to authenticate the socket. Provide either `apiKey` or `token`.
example: YOUR_RESTRICTED_API_KEY - tokenstringOptional
Session token used to authenticate the socket. Provide either `apiKey` or `token`.
- maxReconnectCountnumberOptional
Maximum reconnect attempts per outage before giving up. Default: `500`.
example: 500 - reconnectTimenumberOptional
Base delay in milliseconds for the rapid reconnect phase. Default: `5000`.
example: 5000 - reconnectLinearStepMsnumberOptional
Step in milliseconds for the long reconnect phase after the rapid window. Default: `300000` (5 minutes).
example: 300000 - debugbooleanOptional
Enable verbose lifecycle logs. Pass `true` for console output, or a function `(message, ...args) => void` for a custom logger.
example: true
The client remembers delivery ids. The first add or set opens the socket and
sends delivery.listen for each id. Later adds send listen only
for the new ids. After a reconnect, listen is sent again for every id still
tracked.
- deliveriesarray[string]Required
Delivery identifiers to append without removing existing ones.
example:["deliveryWsCharts"]
- deliveriesarray[string]Required
Delivery identifiers to listen to.
example:["deliveryWsQuickstart"]
Drops every tracked id and closes the socket. This close does not reconnect.
A handler is (notification) => void. The same function
reference is stored once.
- handlerobjectRequired
Handler to append. Duplicates by reference are ignored.
- handlersarrayRequired
Handlers that receive message, info, and error notifications.
- handlerobjectRequired
Handler reference previously passed to add or set.
Removes every handler. Tracked deliveries stay in place.
Clears deliveries and handlers, then closes the socket. This close does not reconnect.
Returns whether the client currently holds a socket. client.api
is the base BigStateWsDeliveryClient underneath.
- typestringRequired
Notification kind from `NotificationType`.
Values
- NotificationType.Message — `"message"`
- NotificationType.Info — `"info"`
- NotificationType.Error — `"error"`
example: message - dataobjectRequired
Payload shape depends on `type`.
- data.actionnumberOptional
Present on `message`. Object action that triggered the delivery.
Values
- 1 — create
- 2 — update
- 3 — delete
- data.ownerstringOptional
Present on `message`. Owner of the delivered object.
- data.objectstringOptional
Present on `message`. Fully qualified object name.
- data.stateobjectOptional
Present on `message` when included. Snapshot with `at`, `version`, `type`, and `value` or `valueRef`.
- data.messagestringOptional
Present on `info`. Lifecycle description, such as `webSocket opened` or `webSocket closed`.
- data.errorstringOptional
Present on `error`. Error summary.
- data.codeanyOptional
Present on `error`. Optional numeric or string error code.
- data.descriptionstringOptional
Present on `error`. Optional human-readable details.
- data.requestedobjectOptional
Present on `error`. Original subscribe frame that caused the error, when available.
An unintentional close starts reconnect. For the first five minutes the
client retries immediately once, then waits reconnectTime
(default 5000 ms) and doubles that wait up to five minutes. After five
minutes the wait becomes 1×, 2×, 3× reconnectLinearStepMs
(default five minutes).
Reconnect stops after maxReconnectCount attempts (default
500). The client then clears handlers and deliveries and emits an error
notification. disconnect(), clearDeliveries(), and
close code 3001 do not reconnect. A successful open resets the
counters and sends delivery.listen again.
- Listenimport {BigStateWsDeliveryClientExtended,NotificationType,} from 'bigstate.client.javascript';const delivery = new BigStateWsDeliveryClientExtended({baseUrl: 'https://ws.delivery.bigstate.dev',apiKey: 'YOUR_RESTRICTED_API_KEY',});delivery.setDeliveries(['deliveryWsQuickstart']);delivery.setMessageHandlers([(notice) => {if (notice.type !== NotificationType.Message) return;console.log(notice.data.object, notice.data.state);},]);