CometChat Calling SDK for Android — Twilio migration guide
You can transfer your current project from the Twilio Video SDK to the ComeChat Calling SDK by following the instructions in this guide. For additional information about the features and application of the Video SDK, check the CometChat Calling SDK if you’re beginning a new project from scratch.
Create a developer account
Create a Developer account from https://app.cometchat.com/ to access your credentials. Choose a plan that suits your needs.
Or you can also choose trial period where you will get limited amount of MAU and calling minutes.

Get the credentials
Under the credentials section in your CometChat Developer Portal, you will find APP ID, Region, Auth Keys and Rest API Keys. You can store them as they will used further in development.

How it works?

Authorize User
Both Twilio and CometChat use JSON Web Tokens (JWT) for authorization. Replace your Twilio Video JWT generation logic with the CometChat Authorization logic on your authentication server. You can also check CometChat API Documentation to learn more about it.
To Migrate your User Data into CometChat you can use https://api-explorer.cometchat.com/reference/import-users
Install the SDK
Initialize CometChat Core SDK through the CloudSmith Repository. For example, if you’re building using Gradle or Groovy, first, add the repository URL to the project level build.gradle
file in the repositories
block under the allprojects
section:
allprojects {
repositories {
maven {
url "https://dl.cloudsmith.io/public/cometchat/cometchat/maven/"
}
}
}
Then, add CometChat Core SDK & Calling SDK to the app level build.gradle
file in the dependencies
section.
implementation 'com.cometchat:chat-sdk-android:4.0.3'
implementation 'com.cometchat:calls-sdk-android:4.0.0'
Remove Twilio SDK
If you like, you can also remove the Twilio SDK from your project with the following.
implementation 'com.twilio:video-android:<version>'
Set permissions
Ensure that you have all of the Android system permissions required by the Video SDK in your project (you can ignore permissions that you already have):
You can see AndroidManifest.xml
file to check these permissions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Initialize the Core SDK
You have to initialize the core SDK before you can use the CometChat Calling SDK. Normally, this happens when your app launches, and we suggest you call this method on app startup. It is crucial to determine where in your application to implement initialization logic because the Twilio Video SDK does not have an equivalent for this.
val appID:String="APP_ID" // Replace with your App ID
val region:String="REGION" // Replace with your App Region ("eu" or "us")
AppSettings appSetting = AppSettings.AppSettingsBuilder()
.setRegion(region)
.subscribePresenceForAllUsers()
.autoEstablishSocketConnection(true)
.build();
CometChat.init(this,appID,appSetting, object : CometChat.CallbackListener<String>() {
override fun onSuccess(p0: String?) {
Log.d(TAG, "Initialization completed successfully")
}
override fun onError(p0: CometChatException?) {
Log.d(TAG, "Initialization failed with exception: " + p0?.message)
}
})
For more details please check https://www.cometchat.com/docs/android-chat-sdk/setup
Initialize Calling SDK
Similarly, like core sdk you now need to initialize the calling SDK by passing credentials like APP_ID, and REGION. There is no
val context:Context = this // Replace with your App Region ("eu" or "us")
val appID:String ="APP_ID" // Replace with your App ID
val region:String ="REGION" // Replace with your App Region ("eu" or "us")
val callAppSettings = CallAppSettingBuilder()
.setAppId(appID)
.setRegion(region).build()
CometChatCalls.init(
context,
callAppSettings,
object : CometChatCalls.CallbackListener<String>() {
override fun onSuccess(s: String?) {
}
override fun onError(e: CometChatException) {
}
}
)
Callbacks
Both SDKs use listeners to detect and stay in sync with state changes. Replace the Twilio listener code with the CometChat Calling SDK code.
- Twilio
val roomListener = object : Room.Listener {...}
- CometChat
val callsEventsListener: CometChatCallsEventsListener{...}
val listenerId = "UNIQUE_ID"
CometChatCalls.addCallsEventListeners(listenerId,callsEventsListener)
The callbacks in these listeners can reflect a number of different changes including connection to the call session, status of other users, errors, and changes in state related to specific features.
For more details please check https://www.cometchat.com/docs/android-chat-sdk/direct-calling#add-multiple-calls-event-listeners
There are two main differences to be aware of when migrating to the CometChatCalls
:
- For most use cases, the CallsEventListener contains all of the callbacks you need. In Twilio there are multiple listeners depending on the area of functionality you are using. So it may require some refactoring to consolidate everything into one place.
- You can call
addCallsEventListener
whenever you're ready to receive callbacks from the Calling SDK, while Twilio'sconnect
method requires you to pass in aRoom.Listener
when connecting to a room.
Generate Call Token
Before start call session you have to generate call token.
val sessionId = "" //Random or available in call obecjt in case of default calling
val userAuthToken = CometChat.getUserAuthToken() //Logged in user auth token
CometChatCalls.generateToken(
sessionId,
userAuthToken,
object : CometChatCalls.CallbackListener<GenerateToken>() {
override fun onSuccess(generateToken: GenerateToken) {
//Store generatedToken as it will be used for joining session
}
override fun onError(e: CometChatException) {
}
}
)
Join session/room
The Calling SDK uses sessions, which are similar to Twilio’s concept of a room. Replace Twilio’s code with CometChat.
- Twilio
val connectOptions = ConnectOptions.Builder(joinToken)
.videoTracks(localVideoTracks)
.audioTracks(localAudioTracks)
.roomName(sessionId)
.build()
Video.connect(context, connectOptions, roomListener)
- CometChat
val videoContainer: RelativeLayout
val activityContext: Context = this //Your activity reference
val callToken = "" //Received on generate token onSuccess
val callSettings = CometChatCalls.CallSettingsBuilder(activityContext, videoContainer)
.setDefaultLayoutEnable(true)
.setIsAudioOnly(false)
.build()
CometChatCalls.startSession(callToken, callSettings, object : CometChatCalls.CallbackListener<String> {
override fun onSuccess(s: String) {
Log.e(TAG, "onSuccess" + s)
}
override fun onError(e: CometChatException) {
Log.e(TAG, "onError" + e)
}
})
Both SDKs use a token for authentication.
Video
See how to migrate from Twilio to CometChat Calling SDK for video controls.
Video controls
Turning your own video on or off is conceptually similar between the two SDKs.
- Twilio
val cameraEnumerator = Camera2Enumerator(context)
//To start Video
cameraEnumerator.deviceNames.firstOrNull { cameraEnumerator.isFrontFacing(it) }?.let {
val cameraCapturer = Camera2Capturer(context, it)
val localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer)
cameraCapturer.startCapture(width, height, framerate)
}
//To stop Video
cameraCapturer.stopCapture()
- CometChat
CometChatCalls.pauseVideo(true)
//if set to true the video Stream is muted and if set tofalse video Stream is transmitted.
The biggest difference between the implementations is the amount of setup that is required for Twilio. While Twilio requires manually setting up a Camera2Capturer
and LocalVideoTrack
to specify your input sources, this is all handled internally within the CometChat Calling SDK.
Audio controls
Similarly to video controls, both SDKs offer a relatively simple approach to controlling audio.
- Twilio
audioTrack.enable(enable)
- CometChat
CometChatCalls.muteAudio(true)
Leave a session
To leave a session, call the endSession
function.
- Twilio
room.disconnect()
- CometChat
CometChatCalls.endSession()
Calling SDK features and support
CometChat Calling SDK offers additional features, such as live transcription, cloud recording, chat, screen sharing, and much more. Refer to the CometChat Calling SDK documentation for more details.