You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Client is the main interface for interacting with the Twilio SDKs.
Usage
// create the clientconstclient=newClient(token);// specify any global eventsclient.onError=({error, userInfo})=>console.log(error);// initialize the clientclient.initialize();// wait for sync to finishclient.onClientSynchronized=()=>{client.getUserChannels().then((channelPaginator)=>console.log(channelPaginator));// create a new channelclient.createChannel({friendlyName: 'My Channel',uniqueName: 'my_channel',type: Constants.TCHChannelType.Private}).then((channel)=>console.log(channel));}
new Client(token[, synchronizationStrategy[, initialMessageCount]])
Name
Type
Description
token
String
The Access Token provided by your server
synchronizationStrategy
Constants.TCHClientSynchronizationStrategy
Optional. The synchronization strategy to use during client initialization. Default: ChannelsList See Twilio Docs
initialMessageCount
Number
Optional. The number of most recent messages to fetch automatically when synchronizing a channel. Default: 100
Properties
Name
Type
Description
userInfo
UserInfo
The current user properties
version
String
The version of the SDK
synchronizationStatus
Constants.TCHClientSynchronizationStatus
The current status of the client's initialization
isReachabilityEnabled
Boolean
Whether or not reachability has been enabled for the messaging instance
Methods
createChannel(options) : Promise
Name
Type
Description
options
Object
Specify the options of the channel you're creating (see below)
Options
Name
Type
Description
friendlyName
String
Optional. Friendly name of channel
uniqueName
String
Optional. Unique name of channel
type
Constants.TCHChannelType
Optional. Whether the channel will be private or public (default)
attributes
Object
Optional. Attributes to attach to the channel
Create a new channel. Returns Channel.
getChannel(sid) : Promise
Name
Type
Description
sid
String
Sid of the channel to return
Get a single instance of a Channel. Returns Channel.
getPublicChannels() : Promise
Get all of the public channels. Returns an instance of Paginator.
getUserChannels() : Promise
Get all of the user's channels. Returns an instance of Paginator.
handleNotification(notification)
Queue the incoming notification with the messaging library for processing - for React Native, this will come in PushNotificationIOS.addEventListener('notification', handleNotification).
Name
Type
Description
notification
Object
The incoming notification.
initialize()
Initialize the Client with the provided Access Manager and begin synchronization.
register(token)
Register APNS token for push notifications. This can be obtained in PushNotificationIOS.addListener('register', handler).
Name
Type
Description
token
String
The APNS token which usually comes from ‘didRegisterForRemoteNotificationsWithDeviceToken’.
setLogLevel(logLevel)
Name
Type
Description
logLevel
Constants.TCHLogLevel
Set the log level of the SDK
shutdown()
Terminate the instance of the client, and remove all the listeners. Note: this does not remove channel specific listeners.
unregister(token)
Unregister from push notification updates.
Name
Type
Description
token
String
The APNS token which usually comes from ‘didRegisterForRemoteNotificationsWithDeviceToken’.
Events
Instead of having to worry about creating native listeners, simply specify handlers on the client instance for the events you want to be notified about.