Skip to contentSkip to navigationSkip to topbar
On this page

SDK Migration Guide - JS 1.0


(error)

Danger

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here(link takes you to an external page).

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.


Overview

overview page anchor

Twilio Programmable Chat 1.0 brings additional controls on data synchronization to enhance performance as well as many other improvements. This guide will help you migrate your existing Chat applications to the new release 1.0.

Client initialization has been simplified to reflect most users typical usage of the system. All user channels (channels for which the current user is joined to or an owner of) will be subscribed to from client startup but only the members roster will be synchronized initially. This keeps client startup fast while still reflecting the latest activity immediately to the client.


UserInfo has been deprecated and replaced with two distinct classed, User and UserDescriptor. Similar to ChannelDescriptor class, a UserDescriptor represents a snapshot of data in time that should be utilized directly after obtaining it but not retained since it will not be updated with new data over time.

User and UserDescriptor Classes

user-and-userdescriptor-classes page anchor

User class adds a new concept to Programmable Chat, subscriptions. A Programmable Chat primitive is subscribed if it will receive updates from the server. Channel objects at this time are always subscribed, and ChannelDescriptor objects are not. Similarly, UserDescriptor objects are not subscribed but a User object may or may not be subscribed. When a User is initially subscribed to on the client, you will receive the Client#event:userSubscribed event.

Users are no longer implicitly subscribed to improve performance on large instances. You can subscribe up to a maximum 100 of users at once after which your least recently subscribed User will be unsubscribed. Using either subscribed Users or User Descriptors appropriately is key to the performance of your application:

  • Subscribed Users will immediately reflect changes made on other clients, such as Friendly Name and Attributes and will also have the most up-to-date reachability and online status information. Subscribed Users are best for live display of messages or recently contacted Users by the client.
  • User Descriptors are a snapshot in time of that user's status in the system. These snapshot objects are ideal for temporary lists of users within your user interface or for visualizing large numbers of users on a Channel where constant data synchronization is not key.

When you first obtain a User object, it will be subscribed but there is a maximum 100 of User objects which may be subscribed at a time in the Programmable Chat client. Once this limit is exceeded, the least recently subscribed User object in memory will be unsubscribed. Several things happen when this occurs:

  • The new Client#event:userUnsubscribed event will be raised to let you know the object is no longer receiving updates
  • The isSubscribed property will start to return a false value for this User instance
  • Attempting to read data from the unsubscribed User object will return latest data known for it
  • The new Client#event:userSubscribed event will be raised to let you know the new object is receiving updates

The number of Users you can concurrently subscribe to in a given instance of the Chat client is large enough that many implementation of Chat will not be affected by User objects being unsubscribed. This is something you should provide for in your code though, and ensure you are using User objects when consistently updated representation of users is important and UserDescriptors when displaying a temporary UI such as a membership list.

The new UserDescriptor class has all of the accessors of the deprecated UserInfo object but none of the setters. It also has a function subscribe() that will return a subscribed User object.

The new User object has the full functionality of the old UserInfo object along with a isSubscribed property which should be checked to see if a User object is still subscribed. To reflect updates there is User#event:updated . There is an unsubscribe() function on this object which will remove the User object from the subscription pool explicitly if you no longer need updates for it at this time.


There is a new function, getSubscribedChannels() which will give you the list of currently subscribed and synchronized channels. This function replaces the deprecated getUserChannels() function.

The getPublicChannels() function has been renamed to getPublicChannelDescriptors() for clarity on its returned objects and a new function, getUserChannelDescriptors() has been added. The getUserChannelDescriptors() returns paginated ChannelDescriptor objects array with static information of all created or joined channels of currently logged in user.

The Client#event:userInfoUpdated event has been removed together with UserInfo class. Instead, new events are added: Client#event:userSubscribed , Client#event:userUnsubscribed and Client#event:userUpdated .

To manipulate the new UserDescriptor and User class instances new functions has been added to the Client class:

  • function getUserDescriptor(identity) returns UserDescriptor for given identity
  • function getUser(identity) returns User object for given identity and subscribes to it
  • function getSubscribedUsers() returns array of all currently subscribed Users

New function, getUserDescriptors() has been added to get the user descriptors for given channel members. Function returns paginated array of UserDescriptor.


ChannelDescriptor Class Changes

channeldescriptor-class-changes page anchor

ChannelDescriptor now is used to represent both public and user channels static(snapshot) information. To reflect this change additional properties are added: isPrivate , lastConsumedMessageIndex , status , type .


userInfo property is removed together with Member#event:userInfoUpdated event. Instead, two new convenience functions are added, getUserDescriptor() and getUser() to obtain a UserDescriptor and subscribed User object respectively.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.