> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Actions

> CometChat Calling SDK v5 - Actions for Flutter

Use call actions to create your own custom controls or trigger call functionality dynamically based on your use case. All actions are called on the `CallSession` singleton instance during an active call session.

## Get CallSession Instance

The `CallSession` is a singleton that manages the active call. All actions are accessed through this instance.

```dart theme={null}
CallSession? callSession = CallSession.getInstance();
```

<Note>
  `CallSession.getInstance()` returns `null` if no active session exists. Always use the null-aware `?.` operator when calling actions, or check `isCallSessionActive()` before calling actions to ensure there's an active call.
</Note>

## Actions

### Mute Audio

Mutes your local microphone, stopping audio transmission to other participants.

```dart theme={null}
await CallSession.getInstance()?.muteAudio();
```

### Unmute Audio

Unmutes your local microphone, resuming audio transmission.

```dart theme={null}
await CallSession.getInstance()?.unMuteAudio();
```

### Set Audio Mode

Changes the audio output device during a call.

```dart theme={null}
await CallSession.getInstance()?.setAudioModeType(AudioMode.speaker);
await CallSession.getInstance()?.setAudioModeType(AudioMode.earpiece);
await CallSession.getInstance()?.setAudioModeType(AudioMode.bluetooth);
```

<Accordion title="AudioMode Values">
  | Value                 | Description                                     |
  | --------------------- | ----------------------------------------------- |
  | `AudioMode.speaker`   | Routes audio through device loudspeaker         |
  | `AudioMode.earpiece`  | Routes audio through phone earpiece             |
  | `AudioMode.bluetooth` | Routes audio through connected Bluetooth device |
</Accordion>

### Pause Video

Turns off your local camera, stopping video transmission. Other participants see your avatar.

```dart theme={null}
await CallSession.getInstance()?.pauseVideo();
```

### Resume Video

Turns on your local camera, resuming video transmission.

```dart theme={null}
await CallSession.getInstance()?.resumeVideo();
```

### Switch Camera

Toggles between front and rear cameras without interrupting the video stream.

```dart theme={null}
await CallSession.getInstance()?.switchCamera();
```

### Start Recording

Begins server-side recording of the call. All participants are notified.

```dart theme={null}
await CallSession.getInstance()?.startRecording();
```

<Warning>
  Recording requires the feature to be enabled for your CometChat app.
</Warning>

### Stop Recording

Stops the current recording. The recording is saved and accessible via the dashboard.

```dart theme={null}
await CallSession.getInstance()?.stopRecording();
```

### Mute Participant

Mutes a specific participant's audio. This is a moderator action.

```dart theme={null}
await CallSession.getInstance()?.muteParticipant(participant.uid);
```

### Pause Participant Video

Pauses a specific participant's video. This is a moderator action.

```dart theme={null}
await CallSession.getInstance()?.pauseParticipantVideo(participant.uid);
```

### Pin Participant

Pins a participant to keep them prominently displayed regardless of who is speaking.

```dart theme={null}
await CallSession.getInstance()?.pinParticipant(participant.uid);
```

### Unpin Participant

Removes the pin, returning to automatic speaker highlighting.

```dart theme={null}
await CallSession.getInstance()?.unPinParticipant();
```

### Set Layout

Changes the call layout. Each participant can choose their own layout independently.

```dart theme={null}
await CallSession.getInstance()?.setLayout(LayoutType.tile);
await CallSession.getInstance()?.setLayout(LayoutType.spotlight);
await CallSession.getInstance()?.setLayout(LayoutType.sidebar);
```

<Accordion title="LayoutType Values">
  | Value                  | Description                                           |
  | ---------------------- | ----------------------------------------------------- |
  | `LayoutType.tile`      | Grid layout with equally-sized tiles                  |
  | `LayoutType.spotlight` | Large view for active speaker, small tiles for others |
  | `LayoutType.sidebar`   | Main speaker with participants in a sidebar           |
</Accordion>

### Enable Picture In Picture Layout

Enables PiP mode, allowing the call to continue in a floating window.

```dart theme={null}
await CallSession.getInstance()?.enablePictureInPictureLayout();
```

### Disable Picture In Picture Layout

Disables PiP mode, returning to full-screen call interface.

```dart theme={null}
await CallSession.getInstance()?.disablePictureInPictureLayout();
```

### Enter PiP Mode

Enters the system Picture-in-Picture mode directly.

```dart theme={null}
await CallSession.getInstance()?.enterPipMode();
```

<Note>
  PiP behavior differs between platforms. Android uses the system PiP window, while iOS uses a custom overlay. Use `isPipSupported()` to check availability before calling this method.
</Note>

### Set Chat Button Unread Count

Updates the badge count on the chat button. Pass 0 to hide the badge.

```dart theme={null}
await CallSession.getInstance()?.setChatButtonUnreadCount(5);
```

### Is Session Active

Returns `true` if a call session is active, `false` otherwise.

```dart theme={null}
bool? isActive = CallSession.getInstance()?.isCallSessionActive();
```

### Leave Session

Ends your participation and disconnects gracefully. The call continues for other participants.

```dart theme={null}
await CallSession.getInstance()?.leaveSession();
```

### Raise Hand

Shows a hand-raised indicator to get attention from other participants.

```dart theme={null}
await CallSession.getInstance()?.raiseHand();
```

### Lower Hand

Removes the hand-raised indicator.

```dart theme={null}
await CallSession.getInstance()?.lowerHand();
```

## Toggle Methods

Convenience methods that toggle between two states. These check the current state and call the appropriate action automatically.

### Toggle Mute Audio

Toggles between muted and unmuted audio.

```dart theme={null}
await CallSession.getInstance()?.toggleMuteAudio();
```

### Toggle Pause Video

Toggles between paused and resumed video.

```dart theme={null}
await CallSession.getInstance()?.togglePauseVideo();
```

### Toggle Camera Source

Toggles between front and rear camera.

```dart theme={null}
await CallSession.getInstance()?.toggleCameraSource();
```

### Toggle Raise Hand

Toggles between raised and lowered hand.

```dart theme={null}
await CallSession.getInstance()?.toggleRaiseHand();
```

## Alias Methods

These methods are aliases for existing actions, provided for naming convenience.

### End Call Session

Alias for `leaveSession()`. Ends your participation and disconnects gracefully.

```dart theme={null}
await CallSession.getInstance()?.endCallSession();
```

### Start Call Recording

Alias for `startRecording()`. Begins server-side recording of the call.

```dart theme={null}
await CallSession.getInstance()?.startCallRecording();
```

### Stop Call Recording

Alias for `stopRecording()`. Stops the current recording.

```dart theme={null}
await CallSession.getInstance()?.stopCallRecording();
```

### Set Call Layout Type

Alias for `setLayout()`. Changes the call layout.

```dart theme={null}
await CallSession.getInstance()?.setCallLayoutType(LayoutType.tile);
```

## Settings Panel Methods

Methods for controlling the in-call settings panel.

### Hide Settings Panel

Hides the settings panel if it is currently visible.

```dart theme={null}
await CallSession.getInstance()?.hideSettingsPanel();
```

### Open Call Settings Panel

Opens the general call settings panel.

```dart theme={null}
await CallSession.getInstance()?.openCallSettingsPanel();
```

### Open Virtual Background Settings Panel

Opens the virtual background settings panel.

```dart theme={null}
await CallSession.getInstance()?.openVirtualBackgroundSettingsPanel();
```

## State Getters

Read-only properties on `CallSession` that return the current state of the local user in the call.

| Property        | Type   | Description                                  |
| --------------- | ------ | -------------------------------------------- |
| `isAudioMuted`  | `bool` | Whether local audio is currently muted       |
| `isVideoPaused` | `bool` | Whether local video is currently paused      |
| `isHandRaised`  | `bool` | Whether the local user's hand is raised      |
| `isRecording`   | `bool` | Whether the call is currently being recorded |

```dart theme={null}
CallSession? session = CallSession.getInstance();

bool? muted = session?.isAudioMuted;
bool? videoPaused = session?.isVideoPaused;
bool? handRaised = session?.isHandRaised;
bool? recording = session?.isRecording;
```

<Accordion title="Participant Object Reference">
  | Property              | Type     | Description                           |
  | --------------------- | -------- | ------------------------------------- |
  | `uid`                 | `String` | Unique identifier (CometChat user ID) |
  | `name`                | `String` | Display name                          |
  | `avatar`              | `String` | URL of avatar image                   |
  | `pid`                 | `String` | Participant ID for this call session  |
  | `role`                | `String` | Role in the call                      |
  | `audioMuted`          | `bool`   | Whether audio is muted                |
  | `videoPaused`         | `bool`   | Whether video is paused               |
  | `isPinned`            | `bool`   | Whether pinned in layout              |
  | `isPresenting`        | `bool`   | Whether screen sharing                |
  | `raisedHandTimestamp` | `int`    | Timestamp when hand was raised        |
</Accordion>
