Join a call session using one of two approaches: the quick start method with a session ID, or the advanced flow with manual token generation for more control.
Overview
The CometChat Calls SDK provides two ways to join a session:
| Approach | Best For | Complexity |
|---|
| Join with Session ID | Most use cases - simple and straightforward | Low - One method call |
| Join with Token | Custom token management, pre-generation, caching | Medium - Two-step process |
Both approaches require a container view in your layout and properly configured SessionSettings.
Container Setup
Add a container view to your layout where the call interface will be rendered:
<RelativeLayout
android:id="@+id/call_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The call UI will be dynamically added to this container when you join the session.
Join with Session ID
The simplest way to join a session. Pass a session ID and the SDK automatically generates the token and joins the call.
val sessionId = "SESSION_ID"
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build()
CometChatCalls.joinSession(sessionId, sessionSettings, callViewContainer,
object : CometChatCalls.CallbackListener<CallSession>() {
override fun onSuccess(callSession: CallSession) {
Log.d(TAG, "Joined session successfully")
}
override fun onError(e: CometChatException) {
Log.e(TAG, "Failed: ${e.message}")
}
}
)
String sessionId = "SESSION_ID";
RelativeLayout callViewContainer = findViewById(R.id.call_view_container);
SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build();
CometChatCalls.joinSession(sessionId, sessionSettings, callViewContainer,
new CometChatCalls.CallbackListener<CallSession>() {
@Override
public void onSuccess(CallSession callSession) {
Log.d(TAG, "Joined session successfully");
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "Failed: " + e.getMessage());
}
}
);
| Parameter | Type | Description |
|---|
sessionId | String | Unique identifier for the call session |
sessionSettings | SessionSettings | Configuration for the session |
callViewContainer | RelativeLayout | Container view for the call UI |
listener | CallbackListener | Callback for success/error handling |
All participants joining the same call must use the same session ID.
Join with Token
For scenarios requiring more control over token generation, such as pre-generating tokens, implementing custom caching strategies, or managing token lifecycle separately.
Step 1: Generate Token
Generate a call token for the session. Each token is unique to a specific session and user combination.
val sessionId = "SESSION_ID"
CometChatCalls.generateToken(sessionId, object : CometChatCalls.CallbackListener<GenerateToken>() {
override fun onSuccess(token: GenerateToken) {
Log.d(TAG, "Token generated: ${token.token}")
// Store or use the token
}
override fun onError(e: CometChatException) {
Log.e(TAG, "Token generation failed: ${e.message}")
}
})
String sessionId = "SESSION_ID";
CometChatCalls.generateToken(sessionId, new CometChatCalls.CallbackListener<GenerateToken>() {
@Override
public void onSuccess(GenerateToken token) {
Log.d(TAG, "Token generated: " + token.getToken());
// Store or use the token
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "Token generation failed: " + e.getMessage());
}
});
| Parameter | Type | Description |
|---|
sessionId | String | Unique identifier for the call session |
listener | CallbackListener | Callback returning the generated token |
Step 2: Join with Token
Use the generated token to join the session. This gives you control over when and how the token is used.
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build()
// Use the previously generated token
CometChatCalls.joinSession(generatedToken, sessionSettings, callViewContainer,
object : CometChatCalls.CallbackListener<CallSession>() {
override fun onSuccess(callSession: CallSession) {
Log.d(TAG, "Joined session successfully")
}
override fun onError(e: CometChatException) {
Log.e(TAG, "Failed: ${e.message}")
}
}
)
RelativeLayout callViewContainer = findViewById(R.id.call_view_container);
SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build();
// Use the previously generated token
CometChatCalls.joinSession(generatedToken, sessionSettings, callViewContainer,
new CometChatCalls.CallbackListener<CallSession>() {
@Override
public void onSuccess(CallSession callSession) {
Log.d(TAG, "Joined session successfully");
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "Failed: " + e.getMessage());
}
}
);
| Parameter | Type | Description |
|---|
callToken | GenerateToken | Previously generated token object |
sessionSettings | SessionSettings | Configuration for the session |
callViewContainer | RelativeLayout | Container view for the call UI |
listener | CallbackListener | Callback for success/error handling |
Complete Example
val sessionId = "SESSION_ID"
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)
// Step 1: Generate token
CometChatCalls.generateToken(sessionId, object : CometChatCalls.CallbackListener<GenerateToken>() {
override fun onSuccess(token: GenerateToken) {
// Step 2: Join with token
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build()
CometChatCalls.joinSession(token, sessionSettings, callViewContainer,
object : CometChatCalls.CallbackListener<CallSession>() {
override fun onSuccess(callSession: CallSession) {
Log.d(TAG, "Joined session successfully")
}
override fun onError(e: CometChatException) {
Log.e(TAG, "Failed to join: ${e.message}")
}
}
)
}
override fun onError(e: CometChatException) {
Log.e(TAG, "Token generation failed: ${e.message}")
}
})
String sessionId = "SESSION_ID";
RelativeLayout callViewContainer = findViewById(R.id.call_view_container);
// Step 1: Generate token
CometChatCalls.generateToken(sessionId, new CometChatCalls.CallbackListener<GenerateToken>() {
@Override
public void onSuccess(GenerateToken token) {
// Step 2: Join with token
SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
.setDisplayName("John Doe")
.setType(SessionType.VIDEO)
.build();
CometChatCalls.joinSession(token, sessionSettings, callViewContainer,
new CometChatCalls.CallbackListener<CallSession>() {
@Override
public void onSuccess(CallSession callSession) {
Log.d(TAG, "Joined session successfully");
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "Failed to join: " + e.getMessage());
}
}
);
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "Token generation failed: " + e.getMessage());
}
});
Error Handling
Common errors when joining a session:
| Error Code | Description |
|---|
ERROR_COMETCHAT_CALLS_SDK_INIT | SDK not initialized - call init() first |
ERROR_AUTH_TOKEN | User not logged in or auth token invalid |
ERROR_CALL_SESSION_ID | Session ID is null or empty |
ERROR_CALL_TOKEN | Invalid or missing call token |
ERROR_CALLING_VIEW_REF_NULL | Container view is null |
ERROR_JSON_EXCEPTION | Invalid session settings or response parsing error |