@555platform/555-connection 中文文档教程

发布于 3年前 浏览 23 更新于 3年前

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';
  1. 使用 555tokenConnectOptionsMessageAdapter

    const sdk = SDK.Client.create(
                userData.access_token,
                {
              url: '',
              automaticReconnect: true
                },
                new SDK.QueuedMessageAdapter<SDK.MessagePayload>()
            );
    
    
    sdk.connect();
    
  2. 回调

    javascript 建立连接 sdk.onTokenAboutToExpire(() =>; // renewToken 是你需要实现的函数来获取新的令牌 // 来自应用服务器 renewToken(renewedToken => sdk.updateToken(renewedToken)); );

APIs

Connect

Methods

<static> create(accessToken, ConnectOptions, messageAdapter)

创建和初始化客户端的工厂方法

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)

更新当前令牌。 用于使用刷新的令牌更新客户端。

参数

NameTypeArgumentDescription
accessTokenstringrequired555 Platform access token

返回

类型

void

connect()

连接到平台。

参数

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

这些选项是连接平台的参数。

类型

对象

属性

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

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();
    
  2. 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

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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文