@555platform/555-connection 中文文档教程
555-connection
555 JavaScript SDK for connection
555-connection 提供简单的 API 来与 555 平台建立连接。
Getting started
npm i @555platform/555-connection
Usage - Examples
import SDK from '@555platform/555-connection';
使用
555token
、ConnectOptions
和MessageAdapter
const sdk = SDK.Client.create( userData.access_token, { url: '', automaticReconnect: true }, new SDK.QueuedMessageAdapter<SDK.MessagePayload>() ); sdk.connect();
回调
javascript 建立连接 sdk.onTokenAboutToExpire(() =>; // renewToken 是你需要实现的函数来获取新的令牌 // 来自应用服务器 renewToken(renewedToken => sdk.updateToken(renewedToken)); );
APIs
Connect
Methods
<static> create(accessToken, ConnectOptions, messageAdapter)
创建和初始化客户端的工厂方法
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)
更新当前令牌。 用于使用刷新的令牌更新客户端。
参数
Name | Type | Argument | Description |
---|---|---|---|
accessToken | string | required | 555 Platform access token |
返回
类型
void
connect()
连接到平台。
参数
Name | Type | Argument | Description |
---|---|---|---|
options | ConnectOptions | optional | Connection options |
返回
类型
Promise.
disconnect()
手动断开客户端。
返回
类型
Promise.
AccessTokenAboutToExpire
在访问令牌到期前 5 分钟触发。
client.onTokenAboutToExpire(() =>
// renewToken is a function you need to implement to fetch new token
// from application server
renewToken(renewedToken => sdk.updateToken(renewedToken));
);
Options
ConnectOptions
这些选项是连接平台的参数。
类型
对象
属性
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 |
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
andMessageAdapter
const sdk = SDK.Client.create( userData.access_token, { url: '', automaticReconnect: true }, new SDK.QueuedMessageAdapter<SDK.MessagePayload>() ); sdk.connect();
Callbacks
javascript 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
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 |