LiquidTap Javascript Client
To manage API tokens, refer to: https://app.liquid.com/settings/api-tokens
To learn more about Liquid Api token management, see the help links below: https://help.liquid.com/connect-to-liquid-via-api
Links
Events Authentication Troubleshooting Contributing
Quick Start
Install via npm or yarn:
npm install liquid-tap
yarn add liquid-tap
OR Include the library:
; const tap = ;const public_channel = tap;public_channel;
Events
Event | Payload | Description |
---|---|---|
connected |
{ reconnect: boolean } |
Fires on successful connection. Contains a boolean indicating whether this was an automatic reconnection. |
disconnected |
n/a | Fires on disconnect. |
unavailable |
n/a | Fires when a connection is unavailable for any reason. |
tick_received |
{ event: string, data: any, channel?: string } |
Fires on every websocket event. Contains the entire websocket payload. |
authenticated |
n/a | Fires when the websocket has successfully authenticated |
authentication_failed |
{ message: string, attempts: number } |
Fires when authentication has failed. Contains a message from the server and the number of authentication attempts. |
authentication_aborted |
{ attempts: number } |
Fires when the maximum number of automatic authentication retries is reached. Contains the number of attempts. |
Binding to events
Callbacks
var tap = ;tap;tap;tap;
Promises
var tap = ;tap;tap;tap;
Options
Key | Type | Default | Description |
---|---|---|---|
wsHost |
string |
'tap.liquid.com' |
Tap WS host to connect to. |
wsPort |
number |
433 |
Port to connect to. |
wssPort |
number |
433 |
SSL Port to connect to. |
useTls |
boolean |
true |
Should connect using SSL. |
auth |
AuthType (see below) |
null | Authentication information. See below. |
appId |
string |
'LiquidTapClient' |
Arbitrary name to use in the WS url. |
authenticationTimeout |
number (ms) |
5000 |
Timeout to assume authentication has failed. (Note a auth_failed event is expected) |
authRetryDelay |
number (ms) |
200 |
Time to wait before retrying authentication. |
authRetryMaxAttempts |
number |
3 |
Maximum number of authentication retries. |
Authentication
To subscribe to protected channels, the client must provide a token_id and token_secret which has permission to view those channels. The library will attempt to authenticate three times by default.
Authenticate Sequence
Before Initialization
var tap = auth: tokenId: token_id toeknSecret: token_secret ;// Refer to profile page for user_id: https://app.liquid.com/settings/profilevar protected_channel = tap;protected_channel;
After Initialization
The library allows the LiquidTap client to be created and subscribe to public channels, then when a protected channel is required the client can authenticate.
var tap = ; var public_channel = tap;public_channel; tap;var protected_channel = tap;protected_channel;
Authentication Input
The authentication can be done either by providing an API token ID and secret, JWT token, or callback.
Token ID and Secret
var tap = auth: tokenId: token_id tokenSecret: token_secret ;
var tap = ;tap;
Signed JWT
var tap = auth: signed_jwt ;
var tap = ;tap;
Callback (return string)
var tap = jwt;
Callback (return Promise)
The authentication process inside TapClient will wait for the promise to resolve before authenticating.
const createJwtWhenReady = { return <string> { }}var tap = auth: createJwtWhenReady;
TapClient will also wrap the promise to allow process order management
var tap = ;const createJwtWhenReady = { return <string> { }}tap
Callback (which takes another callback)
var tap = ; // Create a service to manage nonce and JWT creationconst createJwtWhenReady = { } tap
Troubleshooting
Open the chrome dev tools and inspect the network traffic as shown in the image below:
Contributing
Setup
npm install
Development
npm run build:dev
npm run sample
Testing
npm test
Ensure changes are also thoroughly tested with the real world server responses.
Building
npm run build
Ensure to commit compiled assets in dist
.