JavaScript Library for the Real-Time State API

This JavaScript library is provided to facilitate use of the socket-based real-time state API in a browser (see Protocol of the Real-Time State API). It simplifies interactions with the API in the following ways:

  • Direct interaction with the WebSocket API is not necessary.
  • The connection, authentication, and table registration steps are handled for you using the credentials, appliance information, and table names you provide.
  • The server's JSON messages are buffered and decoded automatically.
  • Model changes are provided as JavaScript objects instead of JSON strings.
  • Several methods of subscribing to model changes are provided to help filter, transfer, and store the data more easily.

Browser Requirements

This API will only work in browsers that support binary WebSockets.

Usage

To use this JavaScript library, your HTML page must reference the state.js file located on your Bomgar Appliance.

A script tag would look something like the example below, where "support.example.com" is your appliance's hostname:

  • <script src="https://support.example.com/api/state.js"></script>

This script tag must be included in your HTML page before any of your own code that uses the API.

Note: Examples in this document use a simple script tag and the API’s global bomgarState() function. However, state.js also contains a universal module definition (UMD) wrapper that allows it to be used with various JavaScript module systems such as Browserify or RequireJS.