4.4.27 • Published 2 years ago

@555platform/555-js-sdk v4.4.27

Weekly downloads
192
License
Apache-2.0
Repository
-
Last release
2 years ago

555-js-sdk

Build Status

555 JavaScript SDK

555-js-sdk provides simple APIs to build chat based applications using 555 Platform.

Getting started

npm i @555platform/555-js-sdk

Usage - Examples

import SDK from '@555platform/555-js-sdk';
  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.chat.connect();
  2. Get list of rooms current user is a member of.

    const iter: SDK.Paginator<
        SDK.RoomDescriptor,
        SDK.RoomIterator
      > = await sdk.chat.getUserRoomDescriptors(0, 0);
  3. Callbacks and Events from SDK.

    SDK.Client.Chat.on(
    	SDK.CMF.ChatServerEventTypes.RoomAdded,
    	this.onRoomsChanged
     );
    
    SDK.Client.Chat.on(
      SDK.CMF.ChatServerEventTypes.UserJoinedRoom,
      this.onRoomsChanged
    );
    
    SDK.Client.Chat.on(
      SDK.CMF.ChatServerEventTypes.UserLeftRoom,
      this.onRoomsChanged
    );
    
    SDK.Client.Chat.on(
      SDK.CMF.ChatServerEventTypes.RoomReceivedMessage,
      this.onRoomReceivedMessage
    );
    
    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>

on(event, callback)

Register handler for event.

Parameters

NameTypeDescription
eventEventEvent type
callbackFunctionCallback function

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

Chat

Methods

createRoom(options)

Create room on the server with current user as the member.

Parameters

NameTypeArgumentDescription
optionsCreateRoomOptionsCreate room options

Returns

Type

Promise.<Room>

getRoomById(roomId)

Get room by its ID.

Parameters

NameTypeDescription
roomIdStringroom ID

Returns

Type

Promise.<Room>

getPublicRoomDescriptors()

Get list of public rooms.

Returns

Type

Promis.<Paginator.<RoomDescriptor>>

getUserRoomDescriptors()

Get list of rooms current user is a member of.

Returns

Type

Promise.<Paginator.<RoomDescriptor>>

getUser(userId)

Return User object for the user ID.

Parameters

NameTypeDescription
userIdStringUser ID

Returns

Type

Promise.<User>

getCurrentUser()

Return User object for currently logged in user.

Returns

Type

Promise.<User>

disconnect()

Gracefully disconnect SDK from the platform

Returns

Type

Promise.<void>

updateLastConsumedMessageIndex(index)

Set last consumed message index to new index.

Parameters

NameTypeDescription
indexNumberMessage index to set last read to

Returns

Type

Promise.<number|Error>

Events

roomReceivedMessage

Type

Object

Properties

NameTypeDescription
roomRoomDescriptorRoom descriptor with updated last message and consumed message index
messageMessageMessage object with the new message

UserJoinedRoom

Triggered when user joins the room.

Type

User

UserLeftRoom

Triggered when user leaves the room.

Type

User

MessageUpdated

Triggered when message was updated.

Type

Object

Properties

NameTypeDescription
messageMessageUpdated Message
indexNumberIndex of the updated message

UserIsTyping

Triggered when a user in the room started typing.

Type

User

Options

CreateRoomOptions

These options are parameters for creating a room.

Type

Object

Properties

NameTypeArgument
attributesObjectoptional
friendlyNameStringrequired
createdBystringrequired
isPrivatebooleanrequired
isDirectbooleanrequired
isSMSbooleanoptional
smsNumberstringoptional
membersstring[]required

Room

Properties

NameTypeDescription
roomIdStringRoom ID
friendlyNameStringRoom display name
createdAtDateDate of creation
createdByUserUser who created the room
updatedAtDateDate of update
membersArray.<User>Users who are members of this room
isPrivateBooleanIs room private or public ('public' or 'private')
isArchivebooleanIs room archived
isSmsbooleanIs sms
smsNumberstringsms number
attributesObjectObject with room's custom attributes
lastMessageIndexnumberIndex of last message
lastConsumedMessageIndexnumberIndex of last consumed message
consumedMessageOffsetnumberNumber of unread messages by user this message is directed to

Methods

inviteUsers(userId)

Invite a user to the room.

Parameters

NameTypeDescription
userIdStringUser ID

Returns

Type

Promise.<Room|Error>

leaveRoom(options)

Leave the Room.

Returns

Type

Promise.<Room|Error>

options

Properties

NameTypeArgument
roomIdstringrequired

removeUser(roomId, userId)

Remove user from the Room.

Returns

Type

Promise.<Room|Error>

archiveRoom()

Archives the Room.

Returns

Type

Promise.<Room|Error>

deleteRoom()

Deletes the Room.

Returns

Type

Promise.<Room|Error>

updateRoom(room)

Update the Room.

Returns

Type

Promise.<Void|Error>

updateMessage(messageId, messageUpdate)

update message.

Returns

Type

Promise.<Void|Error>

deleteMessage(options)

delete message.

Returns

Type

Promise.<Message|Error>

options

Properties

NameTypeArgument
roomIdstringrequired
messageIdstringrequired

removeUser(userId)

Remove user from this Room.

Parameters

NameTypeDescription
userIdStringUser ID

Returns

Type

Promise.<void|Error>

Events

UserJoinedRoom

Triggered when user joins the room.

Type

User

UserLeftRoom

Triggered when user leaves the room.

Type

User

MessageUpdated

Triggered when message was updated.

Type

Object

Properties

NameTypeDescription
messageMessageUpdated Message
indexNumberIndex of the updated message

UserIsTyping

Triggered when a user in the room started typing.

Type

User

RTC JS SDK

Import JS SDK as below:

import { JSSDK } from '@555platform/555-js-sdk';

And declare global variables inside .ts wrapper to access Rtc components via window object.

declare var window: any;

or

declare var IrisRtcSession: any;

JS SDK Documenation is available here

4.4.27

2 years ago

4.4.27-beta.0

2 years ago

4.4.25

2 years ago

4.4.26

2 years ago

4.4.24

2 years ago

4.4.23

2 years ago

4.4.22

2 years ago

4.4.21

2 years ago

4.4.20

3 years ago

4.4.20-beta1

3 years ago

4.4.19-beta1

3 years ago

4.4.19

3 years ago

4.4.18

3 years ago

4.4.17

3 years ago

4.4.16-beta2

3 years ago

4.4.16-beta

3 years ago

4.4.16

3 years ago

4.4.15-beta2

3 years ago

4.4.15-beta

3 years ago

4.4.15

3 years ago

4.4.14-beta

3 years ago

4.4.14

4 years ago

4.4.1-3.1

4 years ago

4.4.1-3.2

4 years ago

4.4.13

4 years ago

4.4.12

4 years ago

4.4.11

4 years ago

4.4.10

4 years ago

4.4.9

4 years ago

4.4.8

4 years ago

4.4.7

4 years ago

4.4.6

4 years ago

4.4.5

4 years ago

4.4.4

4 years ago

4.4.3

4 years ago

4.4.1

4 years ago

4.4.2

4 years ago

4.4.0

4 years ago

4.3.9

4 years ago

4.3.8

4 years ago

4.3.7

4 years ago

4.3.6

4 years ago

4.3.5

4 years ago

4.3.4

4 years ago

4.3.3

4 years ago

4.3.2

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.2

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.3

4 years ago

4.1.2

4 years ago

4.1.1

4 years ago

4.0.3

4 years ago