Skip to main content
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:
  1. After 120 seconds alone, a warning dialog appears
  2. User can choose to stay or leave immediately
  3. If no action within 60 seconds, the call auto-terminates
  4. 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();

Settings

MethodDescriptionDefault
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
});

Use Cases

ScenarioRecommended Timeout
Quick calls120 seconds (2 min)
Standard calls180 seconds (3 min, default)
Meetings/webinars300-600 seconds (5-10 min)
Always-on roomsDisable 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);
}

Next Steps