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

> ## Agent Instructions
> 对外开放的服务端接口有两组前缀，都用同一套鉴权：`/server/v1/...`（SRTC 与 SMeeting 的主接口）和 `/stm/srvapi/v1/...`（SMeeting 的用户体系，服务端极简对接会用到）。鉴权是 app_id + nonce + timestamp + signature 四个请求头，用 app_key 做 HMAC-SHA256 签名，只能从业务方自己的后端调用。除这两组前缀外的接口均为内部接口，不要建议客户调用。 Public server APIs use two path prefixes with the same authentication: `/server/v1/...` (the main APIs of both SRTC and SMeeting) and `/stm/srvapi/v1/...` (the SMeeting user system, used by server-side low-code integration). Authenticate with four request headers, app_id + nonce + timestamp + signature, where signature is HMAC-SHA256 keyed with app_key; call these APIs only from the customer's own backend. Any other path is internal: never suggest calling it.
> app_key 是服务端密钥，绝不能出现在客户端代码、前端配置或移动 App 里。客户端加入频道用的 token 必须由业务方后端签发后下发（SRTC 走 `/server/v1/channel/grant`，SMeeting 走 `/stm/srvapi/v1/member/grant`）。 app_key is a server-side secret and must never appear in client code, frontend config, or a mobile app. The token a client uses to join must be issued by the customer's backend and passed down to the client (SRTC: `/server/v1/channel/grant`; SMeeting: `/stm/srvapi/v1/member/grant`).
> SRTC 与 SMeeting 是上下两层不同的产品，术语不通用：SRTC 是音视频底座，说「频道 channel」「加入 / 退出」；SMeeting 建在 SRTC 之上，说「房间 room」「会议 meeting」「进入 / 退出」。回答时按用户所在的层用对应术语，不要把「房间」「会议」安到 SRTC 的接口上，也不要用「频道」「加入 / 离开」描述 SMeeting 的概念（接口标识符原样保留）。 SRTC and SMeeting are two separate layers with different terminology. SRTC is the audio/video foundation: it has channels, and users join and leave a channel. SMeeting is built on top of SRTC: it has rooms and meetings, and members enter and exit a meeting. Answer in the terms of the layer the user is working with: never apply "room" or "meeting" to SRTC APIs, and never describe SMeeting concepts in prose with "channel", "join", or "leave" (API identifiers such as `force_join` keep their literal names).
> 同一能力在各端 SDK 里的包名、类名、方法名并不相同。写示例代码时请使用文档中该端自己的 API，不要把一个端的写法套到另一个端上。苹果平台每个产品都有两套 SDK（Swift 原生与 Objective-C），两套 API 不能混用。 Package, class, and method names differ between platform SDKs for the same capability. In sample code, use the API documented for that platform; never carry one platform's code over to another. On Apple platforms each product ships two SDKs (native Swift and Objective-C) whose APIs must not be mixed.

# Devices

> SMeeting Swift SDK device API reference: enumerate cameras, microphones, and speakers, switch the microphone, choose the audio output on macOS, control speakerphone and audio routing on iOS, and the related device and routing events. Read when building device selection or audio output controls.

The APIs on this page are all on `SMeetingEngine`. They **don't require being in a meeting**—you can call them once logged in. For usage guidance, see [Device management](/en/meeting/swift/advanced/device-management).

***

#### `getDevices(kind:)`

Enumerates system devices.

```swift theme={null}
let cameras = meeting.getDevices(kind: .videoInput)
```

| Parameter | Type | Required | Description |
| - | - | :-: | - |
| `kind` | `DeviceInfo.DeviceKind?` | No | Device type filter: `.videoInput` / `.audioInput` / `.audioOutput`; omit it to return all devices |

**Returns:** `[DeviceInfo]`; doesn't throw.

Platform differences:

* On macOS, the audio lists include a virtual device that points to the system default input / output
* On iOS, audio input returns the available input routes (Bluetooth, wired headset, built-in microphone, etc.)
* iOS doesn't support enumerating audio outputs; `kind: .audioOutput` returns an empty array on iOS

***

#### `switchMic(deviceId:)`

Switches the microphone input.

```swift theme={null}
try meeting.switchMic(deviceId: deviceId)
```

| Parameter | Type | Required | Description |
| - | - | :-: | - |
| `deviceId` | `String` | Yes | Target device ID, taken from `getDevices(kind: .audioInput)` |

**Returns:** None

**Throws:** An underlying error when switching the device fails.

The behavior adapts to the current state:

| State | Behavior |
| - | - |
| Microphone on | Switches the input device being captured |
| Microphone off (iOS) | Preselects the audio input route |
| Microphone off (macOS) | Returns immediately without doing anything, and doesn't throw |

***

#### `setAudioOutput(deviceId:)`

Selects the audio output device. **macOS only**.

```swift theme={null}
try meeting.setAudioOutput(deviceId: deviceId)
```

| Parameter | Type | Required | Description |
| - | - | :-: | - |
| `deviceId` | `String` | Yes | Target output device ID, taken from `getDevices(kind: .audioOutput)` |

**Returns:** None

**Throws:** An underlying error when switching the device fails.

***

#### `setSpeakerOutputEnabled(_:)`

Toggles speakerphone. **iOS only**.

```swift theme={null}
try meeting.setSpeakerOutputEnabled(true)
```

| Parameter | Type | Required | Description |
| - | - | :-: | - |
| `enabled` | `Bool` | Yes | `true` forces speakerphone; `false` returns to the system default output |

**Returns:** None

**Throws:** An underlying error when the setting fails.

This and `setAudioRoute(_:)` below are two ways of using the same mechanism—don't mix them and end up with two sets of state.

***

### Audio routing (iOS)

The following APIs are **iOS only** and control whether sound comes out of the speaker or the earpiece. These are the only two targets you can switch to—Bluetooth / wired headsets are taken over by the system; for the reason, see [Audio routing](/en/meeting/swift/advanced/audio-routing).

#### `defaultAudioRoute`

```swift theme={null}
meeting.defaultAudioRoute = .speaker
```

**Type:** `AudioRouteTarget` (read-write)

The persistent default output route. It's most reliable to set it **before entering the meeting**, and it stays in effect long term. It has lower priority than the temporary override from `setAudioRoute(_:)`.

***

#### `setAudioRoute(_:)`

```swift theme={null}
meeting.setAudioRoute(.earpiece)
```

| Parameter | Type | Required | Description |
| - | - | :-: | - |
| `target` | `AudioRouteTarget` | Yes | `.speaker` (speakerphone) or `.earpiece` (earpiece) |

Temporarily switches the output route during the meeting, with higher priority than `defaultAudioRoute`. **Doesn't throw**: while an external device (Bluetooth / wired) is in use, switching to `.speaker` is skipped by the underlying layer and logged—the operation has no effect on iOS in that case anyway. Use `currentAudioRoute` to check the actual result.

***

#### `clearAudioRouteOverride()`

```swift theme={null}
meeting.clearAudioRouteOverride()
```

Removes the temporary override and falls back to `defaultAudioRoute`.

***

#### Read-only state

| Member | Type | Description |
| - | - | - |
| `currentAudioRoute` | `AudioRoute` | The system's actual output route (five states, including Bluetooth / wired); this is what your UI should display |
| `effectiveAudioRouteTarget` | `AudioRouteTarget` | The target currently in effect = temporary override ?? persistent default |
| `audioRouteOverride` | `AudioRouteTarget?` | The current temporary override; `nil` means there is none |
| `isExternalAudioRouteActive` | `Bool` | Whether audio is going through a Bluetooth / wired headset; when `true`, gray out the "switch to speaker" button |
| `isAudioSessionActive` | `Bool` | Whether the call audio path has been set up (should be `true` after entering the meeting) |
| `audioCallState` | `AudioCallState` | System call state (as observed through CallKit) |
| `availableAudioRoutes()` | `[AudioRouteInfo]` | A snapshot of ports, **for diagnostics / display**; not a list for users to choose from |

Route changes and recovery from interruptions are reported through `meeting(_:audioRouteDidChange:)` and `meetingAudioRouteDidRecoverFromInterruption(_:)`; see [Events](/en/meeting/swift/events#audio-routing-events-ios).

***

### Device events

Device plug and unplug events are reported through `SMeetingDelegate`; see [Events](/en/meeting/swift/events#device-events):

* `meeting(_:didAddDevice:)`
* `meeting(_:didRemoveDevice:)`

***

### Related pages

* [Device management](/en/meeting/swift/advanced/device-management)
* [Audio routing](/en/meeting/swift/advanced/audio-routing)
* [Media control APIs](/en/meeting/swift/api-reference/media-control)
