> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Session Timeout

> Handle idle session timeouts in CometChat calls, including automatic termination, user prompts, and the onSessionTimeout event.

<Accordion title="AI Integration Quick Reference">
  ```javascript theme={null}
  // Set custom timeout (in seconds)
  const callSettings = new CometChatCalls.CallSettingsBuilder()
    .setIdleTimeoutPeriod(300) // 5 minutes
    .setCallListener(new CometChatCalls.OngoingCallListener({
      onSessionTimeout: () => {
        console.log("Session timed out");
        CometChatCalls.endSession();
      }
    }))
    .build();
  ```

  * Default idle timeout: 180 seconds (3 minutes) alone in a session
  * Warning dialog appears 60 seconds before auto-termination
  * Listen for `onSessionTimeout` to handle auto-termination
  * Customize with `setIdleTimeoutPeriod(seconds)` in CallSettings (v4.1.0+)
</Accordion>

*Available since v4.1.0*

The Calls SDK automatically terminates call sessions when a participant is alone for too long, preventing abandoned calls from consuming resources. You can customize the timeout duration and handle the termination event.

## How It Works

When a participant is alone in a session:

1. A warning dialog appears 60 seconds before the timeout, with "Stay" or "Leave" options
2. If no action is taken, the call auto-terminates and the `onSessionTimeout` event fires

The default timeout is 180 seconds (3 minutes).

## Configuration

Set a custom timeout period using `setIdleTimeoutPeriod()` in `CallSettingsBuilder`. The warning dialog will always appear 60 seconds before the configured timeout.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    const callSettings: any = new CometChatCalls.CallSettingsBuilder()
      .setIdleTimeoutPeriod(300) // 5 minutes
      .enableDefaultLayout(true)
      .setCallListener(callListener)
      .build();
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const callSettings = new CometChatCalls.CallSettingsBuilder()
      .setIdleTimeoutPeriod(300) // 5 minutes
      .enableDefaultLayout(true)
      .setCallListener(callListener)
      .build();
    ```
  </Tab>
</Tabs>

## Handling the Timeout Event

Listen for `onSessionTimeout` in your `OngoingCallListener` to clean up when the call auto-terminates:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    const callListener = new CometChatCalls.OngoingCallListener({
      onSessionTimeout: () => {
        console.log("Session timed out due to inactivity");
        CometChatCalls.endSession();
        // Close the calling screen
      },
      // ... other listeners
    });
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const callListener = new CometChatCalls.OngoingCallListener({
      onSessionTimeout: () => {
        console.log("Session timed out due to inactivity");
        CometChatCalls.endSession();
        // Close the calling screen
      },
      // ... other listeners
    });
    ```
  </Tab>
</Tabs>

See [Call Session — Call Listeners](/sdk/javascript/direct-call#call-listeners) for the full list of events.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Default Calling" icon="phone" href="/sdk/javascript/default-call">
    Implement ringing call flows with accept/reject functionality
  </Card>

  <Card title="Call Session" icon="video" href="/sdk/javascript/direct-call">
    Configure call settings including idle timeout
  </Card>

  <Card title="Standalone Calling" icon="video" href="/sdk/javascript/standalone-calling">
    Implement calling without the Chat SDK
  </Card>
</CardGroup>
