new Twilio.Chat.Client(token, options)
Parameters:
Name | Type | Description |
---|---|---|
token |
string | Access token |
options |
Client#ClientOptions | Options to customize the Client |
Properties:
Name | Type | Description |
---|---|---|
reachabilityEnabled |
Boolean | State of reachability feature |
channels |
Map.<sid, Channel> | A Map containing all Channels known locally on the Client. To ensure the Channels have loaded before getting a response, use Client#getChannels. |
userInfo |
UserInfo | User information for logged in user |
connectionState |
Client#connectionState | Connection state info |
Fires:
- Client#event:channelAdded
- Client#event:channelInvited
- Client#event:channelJoined
- Client#event:channelLeft
- Client#event:channelRemoved
- Client#event:channelUpdated
- Client#event:memberJoined
- Client#event:memberLeft
- Client#event:memberUpdated
- Client#event:messageAdded
- Client#event:messageRemoved
- Client#event:messageUpdated
- Client#event:typingEnded
- Client#event:typingStarted
- Client#event:userInfoUpdated
- Client#event:connectionStateChanged
Members
-
<readonly> connectionState :String
-
Service connection state
Type:
- String
Properties:
Name Type Default Description DISCONNECTED
String disconnected Client is offline and no connection attempt in process. CONNECTING
String connecting Client is offline and connection attempt is in process. CONNECTED
String connected Client is online and ready. ERROR
String error Client connection is in the erroneous state. DENIED
String denied Client connection is denied because of invalid token -
<readonly> version :String
-
Current version of Chat client.
Type:
- String
Methods
-
createChannel( [options])
-
Create a channel on the server.
Parameters:
Name Type Argument Description options
Client#CreateChannelOptions <optional>
Options for the Channel Returns:
- Type
- Promise.<Channel>
-
getChannelBySid(channelSid)
-
Get a Channel by its SID.
Parameters:
Name Type Description channelSid
String The sid of the Channel to get. Returns:
- Type
- Promise.<Channel>
-
getChannelByUniqueName(uniqueName)
-
Get a Channel by its unique identifier name.
Parameters:
Name Type Description uniqueName
String The unique identifier name of the Channel to get. Returns:
- Type
- Promise.<Channel>
-
getPublicChannels()
-
Get the public channels directory content
Returns:
- Type
- Promise.<Paginator.<ChannelDescriptor>>
-
getUserChannels()
-
Get the current list of all Channels the Client knows about.
Returns:
-
initialize()
-
Initializes library Library will be eventually initialized even without this method called, but client can use returned promise to track library initialization state. It's safe to call this method multiple times. It won't reinitialize library in ready state.
Returns:
- Type
- Promise.<Client>
-
shutdown()
-
Gracefully shutting down library instance
-
updateToken(token)
-
Update the token used by the Client and re-register with IP Messaging services.
Parameters:
Name Type Description token
String The JWT string of the new token. Returns:
- Type
- Promise.<Client>
Type Definitions
-
ClientOptions
-
These options can be passed to Client constructor
Type:
- Object
Properties:
Name Type Argument Default Description logLevel
String <optional>
'error' The level of logging to enable. Valid options (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace'] -
CreateChannelOptions
-
These options can be passed to Client.createChannel
Type:
- Object
Properties:
Name Type Argument Description attributes
Object <optional>
Any custom attributes to attach to the Channel. isPrivate
Boolean <optional>
Whether or not this Channel should be visible to uninvited Clients. friendlyName
String <optional>
The non-unique display name of the Channel. uniqueName
String <optional>
The unique identity name of the Channel.
Events
-
channelAdded
-
Fired when a Channel becomes visible to the Client. Only fired for private channels
Parameters:
Name Type Description channel
Channel -
channelInvited
-
Fired when the Client is invited to a Channel.
Parameters:
Name Type Description channel
Channel -
channelJoined
-
Fired when the Client joins a Channel.
Parameters:
Name Type Description channel
Channel -
channelLeft
-
Fired when the Client leaves a Channel.
Parameters:
Name Type Description channel
Channel -
channelRemoved
-
Fired when a Channel is no longer visible to the Client. Only fired for private channels
Parameters:
Name Type Description channel
Channel -
channelUpdated
-
Fired when a Channel's attributes or metadata have been updated.
Parameters:
Name Type Description channel
Channel -
connectionStateChanged
-
Fired when connection state has been changed.
Parameters:
Name Type Description ConnectionState
Client#connectionState -
memberJoined
-
Fired when a Member has joined the Channel.
Parameters:
Name Type Description member
Member -
memberLeft
-
Fired when a Member has left the Channel.
Parameters:
Name Type Description member
Member -
memberUpdated
-
Fired when a Member's fields has been updated.
Parameters:
Name Type Description member
Member -
messageAdded
-
Fired when a new Message has been added to the Channel on the server.
Parameters:
Name Type Description message
Message -
messageRemoved
-
Fired when Message is removed from Channel's message list.
Parameters:
Name Type Description message
Message -
messageUpdated
-
Fired when an existing Message's fields are updated with new values.
Parameters:
Name Type Description message
Message -
typingEnded
-
Fired when a member has stopped typing.
Parameters:
Name Type Description member
Member -
typingStarted
-
Fired when a member has begun typing.
Parameters:
Name Type Description member
Member -
userInfoUpdated
-
Fired when a userInfo has been updated.
Parameters:
Name Type Description UserInfo
UserInfo