Quick Reference for AI Agents & Developers// Configure idle timeout (in seconds)
const callSettings = new CometChatCalls.CallSettingsBuilder()
.enableDefaultLayout(true)
.setIdleTimeoutPeriod(180) // 3 minutes (warning at 120s, auto-end at 180s)
.setCallListener({
onSessionTimeout: () => {
console.log("Call auto-terminated due to inactivity");
CometChatCalls.endSession();
}
})
.build();
Automatically terminate call sessions when participants are idle to prevent abandoned calls and optimize resource usage.
Available since Calls SDK v4.1.0
Overview
When a participant is alone in a call session, the SDK monitors for inactivity and can automatically terminate the call:
- After 120 seconds alone, a warning dialog appears
- User can choose to stay or leave immediately
- If no action within 60 seconds, the call auto-terminates
onSessionTimeout callback fires when auto-terminated
Timeout Flow
Configuration
Set the idle timeout period using setIdleTimeoutPeriod():
const callSettings = new CometChatCalls.CallSettingsBuilder()
.enableDefaultLayout(true)
.setIdleTimeoutPeriod(300) // 5 minutes (in seconds)
.setCallListener({
onSessionTimeout: () => {
console.log("Call auto-terminated due to inactivity");
// Clean up and close call UI
},
// ... other listeners
})
.build();
const callSettings = new CometChatCalls.CallSettingsBuilder()
.enableDefaultLayout(true)
.setIdleTimeoutPeriod(300)
.setCallListener({
onSessionTimeout: (): void => {
console.log("Call auto-terminated due to inactivity");
},
// ... other listeners
})
.build();
Settings
| Method | Description | Default |
|---|
setIdleTimeoutPeriod(seconds) | Time in seconds before warning appears (warning shows 60s before termination) | 180 (3 minutes) |
The warning dialog appears 60 seconds before the timeout. So if you set setIdleTimeoutPeriod(180), the warning appears at 120 seconds and auto-terminates at 180 seconds.
Handling Timeout
Listen for the onSessionTimeout event to handle automatic termination:
const callListener = new CometChatCalls.OngoingCallListener({
onSessionTimeout: () => {
console.log("Session timed out");
// Clean up resources
CometChatCalls.endSession();
// Update UI
hideCallScreen();
showTimeoutMessage();
},
onCallEnded: () => {
// Normal call end (user action)
CometChatCalls.endSession();
hideCallScreen();
},
// ... other listeners
});
const callListener = new CometChatCalls.OngoingCallListener({
onSessionTimeout: (): void => {
console.log("Session timed out");
CometChatCalls.endSession();
hideCallScreen();
showTimeoutMessage();
},
onCallEnded: (): void => {
CometChatCalls.endSession();
hideCallScreen();
},
// ... other listeners
});
Use Cases
| Scenario | Recommended Timeout |
|---|
| Quick calls | 120 seconds (2 min) |
| Standard calls | 180 seconds (3 min, default) |
| Meetings/webinars | 300-600 seconds (5-10 min) |
| Always-on rooms | Disable or very long timeout |
Complete Example
const callListener = new CometChatCalls.OngoingCallListener({
onUserJoined: (user) => {
console.log("User joined:", user.getName());
},
onUserLeft: (user) => {
console.log("User left:", user.getName());
},
onCallEnded: () => {
console.log("Call ended normally");
cleanup();
},
onCallEndButtonPressed: () => {
CometChat.endCall(sessionId).then(() => {
CometChat.clearActiveCall();
CometChatCalls.endSession();
cleanup();
});
},
onSessionTimeout: () => {
console.log("Call auto-terminated due to inactivity");
CometChat.clearActiveCall();
CometChatCalls.endSession();
cleanup();
showNotification("Call ended due to inactivity");
},
onError: (error) => {
console.error("Call error:", error);
}
});
const callSettings = new CometChatCalls.CallSettingsBuilder()
.enableDefaultLayout(true)
.setIsAudioOnlyCall(false)
.setIdleTimeoutPeriod(180) // 3 minutes
.setCallListener(callListener)
.build();
function cleanup() {
// Hide call UI
document.getElementById("call-container").style.display = "none";
}
function showNotification(message) {
// Show user-friendly notification
alert(message);
}
const callListener = new CometChatCalls.OngoingCallListener({
onUserJoined: (user: any): void => {
console.log("User joined:", user.getName());
},
onUserLeft: (user: any): void => {
console.log("User left:", user.getName());
},
onCallEnded: (): void => {
console.log("Call ended normally");
cleanup();
},
onCallEndButtonPressed: (): void => {
CometChat.endCall(sessionId).then(() => {
CometChat.clearActiveCall();
CometChatCalls.endSession();
cleanup();
});
},
onSessionTimeout: (): void => {
console.log("Call auto-terminated due to inactivity");
CometChat.clearActiveCall();
CometChatCalls.endSession();
cleanup();
showNotification("Call ended due to inactivity");
},
onError: (error: any): void => {
console.error("Call error:", error);
}
});
const callSettings = new CometChatCalls.CallSettingsBuilder()
.enableDefaultLayout(true)
.setIsAudioOnlyCall(false)
.setIdleTimeoutPeriod(180)
.setCallListener(callListener)
.build();
function cleanup(): void {
const container = document.getElementById("call-container");
if (container) container.style.display = "none";
}
function showNotification(message: string): void {
alert(message);
}
Next Steps