1.0.2 • Published 4 years ago

@555platform/555-connection v1.0.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

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';
  1. 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();
  1. Callbacks
    sdk.onTokenAboutToExpire(() =>
     // renewToken is a function you need to implement to fetch new token
     // from application server
     renewToken(renewedToken => sdk.updateToken(renewedToken));
    );

APIs

Connect

Methods

<static> create(accessToken, ConnectOptions, messageAdapter)

Factory method to create and initialize Client

Parameters

NameTypeArgumentDescription
accessTokenstringrequired555 Platform access token
optionsConnectOptionsrequiredOptions to customize 555 Connection behavior
messageAdapterMessageAdapterrequiredMessage adapter class conforming to MessageAdapter interface

Returns

Type

Client|Error

updateToken(accessToken)

Updates current token. Used to update Client with refreshed token.

Parameters

NameTypeArgumentDescription
accessTokenstringrequired555 Platform access token

Returns

Type

void

connect()

Connect to platform.

Parameters

NameTypeArgumentDescription
optionsConnectOptionsoptionalConnection 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

NameTypeArgument
urlstringrequired
protocolstring[]optional
automaticReconnectbooleanoptional
reconnectionAttemptsnumberoptional
reconnectDelaynumberoptional
reconnectBackoffAlgorithmBackoffAlgorithmoptional
pollIntervalnumberoptional
requestTimeoutnumberoptional
requestRetriesnumberoptional
paginatorDefaultPageSizenumberoptional
nextPingDelaynumberoptional
pingWaitDelaynumberoptional