Documentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
The idle timeout feature automatically ends a call session when a participant is alone for a specified period. This prevents abandoned calls from running indefinitely.
Set the idle timeout period when creating call settings:
import { CometChatCalls } from '@cometchat/calls-sdk-react-native';
const callSettings = new CometChatCalls.CallSettingsBuilder()
.setIdleTimeoutPeriod(180) // 180 seconds (3 minutes)
.build();
| Parameter | Type | Default | Description |
|---|
idleTimeoutPeriod | number | 180 | Seconds before auto-ending when alone |
How It Works
- When all other participants leave the call, the idle timeout timer starts
- A prompt appears 60 seconds before the timeout, allowing the user to extend the session
- If the user doesn’t respond, the session ends automatically
- If another participant joins, the timer is cancelled
Listen for Timeout Events
Session Timeout Event
Listen for when the session times out:
CometChatCalls.addEventListener('onSessionTimedOut', () => {
console.log('Session timed out due to inactivity');
// Navigate away from call screen
});
Using OngoingCallListener
const callListener = new CometChatCalls.OngoingCallListener({
onSessionTimeout: () => {
console.log('Session timed out');
// Handle timeout
},
onCallEnded: () => {
console.log('Call ended');
},
});
const callSettings = new CometChatCalls.CallSettingsBuilder()
.setIdleTimeoutPeriod(180)
.setCallEventListener(callListener)
.build();
Disable Idle Timeout
Set a very high value to effectively disable the timeout:
const callSettings = new CometChatCalls.CallSettingsBuilder()
.setIdleTimeoutPeriod(86400) // 24 hours
.build();
Complete Example
import React, { useEffect, useCallback } from 'react';
import { Alert } from 'react-native';
import { CometChatCalls } from '@cometchat/calls-sdk-react-native';
interface CallScreenProps {
sessionId: string;
onCallEnd: () => void;
}
function CallScreen({ sessionId, onCallEnd }: CallScreenProps) {
const handleSessionTimeout = useCallback(() => {
Alert.alert(
'Session Ended',
'The call has ended due to inactivity.',
[
{
text: 'OK',
onPress: onCallEnd,
},
]
);
}, [onCallEnd]);
useEffect(() => {
const unsubscribe = CometChatCalls.addEventListener(
'onSessionTimedOut',
handleSessionTimeout
);
return () => unsubscribe();
}, [handleSessionTimeout]);
useEffect(() => {
async function initializeCall() {
try {
const { token } = await CometChatCalls.generateToken(sessionId);
const listener = new CometChatCalls.OngoingCallListener({
onSessionTimeout: handleSessionTimeout,
onCallEnded: onCallEnd,
});
const settings = new CometChatCalls.CallSettingsBuilder()
.setIdleTimeoutPeriod(180) // 3 minutes
.setCallEventListener(listener)
.build();
// Render call component with token and settings
} catch (error) {
console.error('Failed to initialize call:', error);
}
}
initializeCall();
}, [sessionId, handleSessionTimeout, onCallEnd]);
// ... render call UI
return null;
}
export default CallScreen;
Timeout Behavior
| Scenario | Behavior |
|---|
| User is alone | Timer starts counting down |
| Another participant joins | Timer is cancelled |
| User extends session | Timer resets |
| Timer expires | Session ends, onSessionTimedOut fires |