Websocket
To start sending requests from your environment, choose a language.
Basic usage#
The imported BigStateWsDeliveryClient class (or BigStateClient, according to usage) allows you to create a client with a base URL.:
import { BigStateWsDeliveryClient } from 'bigstate.client.javascript';export const client = new BigStateWsDeliveryClient({baseUrl: 'https://',reconnectTime: 5000, // by defaultmaxReconnectCount: 11, // by defaultapiKey: 'YOUR_API_KEY',// or: token: 'YOUR_TOKEN'});
Configuration#
Below is a list of the allowed properties.
- baseUrl - required - string - this is the root URL to which the client will automatically add the paths of all its HTTP requests. This is the "entry point" to API.
- maxReconnectCount - optional - number - Maximum number of reconnection attempts if the WebSocket connection is lost.
- reconnectTime - optional - number - Delay in milliseconds before attempting to reconnect to the WebSocket delivery.
- apiKey - optional - string - the API key used to authenticate requests. It is transmitted to the client if access to service is based on static keys. If an apiKey is specified, the token field is usually not required. How get an ApiKey?
- token - optional - string - the access window that is used to authorize requests. If a token is specified, the apiKey field can be omitted.
How do subscribe?#
Message - object that contains metadata and the actual value of the update. Each field provides additional context about the received state.
import { BigStateWsDeliveryClient } from 'bigstate.client.javascript';const deliveryIds = ['all'];export const client = new BigStateWsDeliveryClient({baseUrl: 'https://',reconnectTime: 5000, // by defaultmaxReconnectCount: 11, // by defaultapiKey: 'YOUR_API_KEY'// or: token: 'YOUR_TOKEN'});const callback = (message) => {console.log(message)}client.subscribeStateUpdate(deliveryIds, callback);
Message included:
- sid - string - The identifier of the subject whose state was updated.
- rec - string - The timestamp (ISO string) indicating when the update was received by the delivery service.
- value - any - The actual state payload. Contains the data published by the subject.
- error - string - Error payload, if the update represents an error instead of a regular state.