555-connection
555 JavaScript SDK for connection
555-connection provides simple APIs to make connection with 555 Platform.
Getting started
npm i @555platform/555-connection
Usage - Examples
import SDK from '@555platform/555-connection';
-
Make connection using 555token
, ConnectOptions
and MessageAdapter
const sdk = SDK.Client.create(
userData.access_token,
{
url: '',
automaticReconnect: true
},
new SDK.QueuedMessageAdapter<SDK.MessagePayload>()
);
sdk.connect();
-
Callbacks
sdk.onTokenAboutToExpire(() =>
renewToken(renewedToken => sdk.updateToken(renewedToken));
);
APIs
Connect
Methods
<static> create(accessToken, ConnectOptions, messageAdapter)
Factory method to create and initialize Client
Parameters
Name | Type | Argument | Description |
---|
accessToken | string | required | 555 Platform access token |
options | ConnectOptions | required | Options to customize 555 Connection behavior |
messageAdapter | MessageAdapter | required | Message adapter class conforming to MessageAdapter interface |
Returns
Type
Client|Error
updateToken(accessToken)
Updates current token. Used to update Client with refreshed token.
Parameters
Name | Type | Argument | Description |
---|
accessToken | string | required | 555 Platform access token |
Returns
Type
void
connect()
Connect to platform.
Parameters
Name | Type | Argument | Description |
---|
options | ConnectOptions | optional | Connection options |
Returns
Type
Promise.<Client|void>
disconnect()
Manually disconnect the client.
Returns
Type
Promise.<void|Error>
AccessTokenAboutToExpire
Triggered 5 minutes before access token is to expire.
client.onTokenAboutToExpire(() =>
// renewToken is a function you need to implement to fetch new token
// from application server
renewToken(renewedToken => sdk.updateToken(renewedToken));
);
Options
ConnectOptions
These options are parameters for connecting to platform.
Type
Object
Properties
Name | Type | Argument |
---|
url | string | required |
protocol | string[] | optional |
automaticReconnect | boolean | optional |
reconnectionAttempts | number | optional |
reconnectDelay | number | optional |
reconnectBackoffAlgorithm | BackoffAlgorithm | optional |
pollInterval | number | optional |
requestTimeout | number | optional |
requestRetries | number | optional |
paginatorDefaultPageSize | number | optional |
nextPingDelay | number | optional |
pingWaitDelay | number | optional |