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 |
|---|---|---|
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#getSubscribedChannels. |
connectionState |
'disconnected' | 'connecting' | 'connected' | 'error' | 'denied' | Service connection state |
reachabilityEnabled |
Boolean | State of reachability feature |
user |
User | Information for logged in user |
version |
String | Current version of Chat client |
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:userSubscribed
- Client#event:userUnsubscribed
- Client#event:userUpdated
- Client#event:connectionStateChanged
Methods
-
createChannel( [options])
-
Create a channel on the server.
Parameters:
Name Type Argument Description optionsClient#CreateChannelOptions <optional>
Options for the Channel Returns:
- Type
- Promise.<Channel>
-
getChannelBySid(channelSid)
-
Get a Channel by its SID.
Parameters:
Name Type Description channelSidString 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 uniqueNameString The unique identifier name of the Channel to get. Returns:
- Type
- Promise.<Channel>
-
getPublicChannelDescriptors()
-
Get the public channels directory content
Returns:
- Type
- Promise.<Paginator.<ChannelDescriptor>>
-
getSubscribedChannels()
-
Get the current list of all subscribed Channels.
Returns:
-
getSubscribedUsers()
-
Returns:
returns list of subscribed User objects {@see User}- Type
- Promise.<Array.<User>>
-
getUser(identity)
-
Gets user for given identity, if it's in subscribed list - then return the user object from it, if not - then subscribes and adds user to the subscribed list
Parameters:
Name Type Description identityString Identity of User. Returns:
Fully initialized user- Type
- Promise.<User>
-
getUserChannelDescriptors()
-
Returns paginated user's channels descriptors
Returns:
- Type
- Promise.<Paginator.<ChannelDescriptor>>
-
getUserDescriptor(identity)
-
Gets user descriptor for given identity
Parameters:
Name Type Description identityString Identity of User. Returns:
User descriptor- Type
- Promise.<UserDescriptor>
-
handlePushNotification(notificationPayload)
-
Incoming push notification handler
Parameters:
Name Type Description notificationPayloadstring Push notification payload -
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>
-
setPushRegistrationId(channelType, registrationId)
-
Registers for push notifications
Parameters:
Name Type Description channelTypestring 'gcm', 'apn' and 'fcm' are supported registrationIdstring Push notification id provided by platform -
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 tokenString 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 logLevelString <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 attributesObject <optional>
Any custom attributes to attach to the Channel. friendlyNameString <optional>
The non-unique display name of the Channel. isPrivateBoolean <optional>
Whether or not this Channel should be visible to uninvited Clients. uniqueNameString <optional>
The unique identity name of the Channel.