> ## 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.

# 设备检测（会前 / 会中预览）

> 在入会前或会中做摄像头、麦克风、扬声器检测：枚举设备、requestOpenCamera(publish: false) 只预览不推流、isCameraOpened 判断要不要关、麦克风音量与扬声器试听在苹果平台上的限制与做法

### 概述

入会前的设备检测页、会中的设置页，都需要「打开设备看一眼，但不推给其他人」。各项检测在 Swift 会议层的做法：

| 检测项 | 做法 | 支持情况 |
| - | - | - |
| 设备列表 | `getDevices(kind:)` | iOS / macOS |
| 摄像头预览 | `requestOpenCamera(publish: false)` | iOS / macOS，会前会中都可用，自 1.9.0 起 |
| 麦克风音量 | 会中开麦后看 `activeSpeakersDidChange` 里自己那一条 | **暂不支持会外 / 只采集测麦**，原因见下 |
| 扬声器试听 | macOS 用 `setAudioOutput(deviceId:)` 选设备，测试音由业务自己播放 | SDK 不提供试听接口 |

***

### 设备列表

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

设备插拔、切换设备见 [外设管理](https://docs.stmlink.com/zh/meeting/swift/advanced/device-management.md)。

***

### 摄像头预览

`requestOpenCamera` 传 `publish: false` 时只采集、只预览：不请求会控、不发布、不发摄像头状态事件，会前会中都可以调用。主持人关闭摄像头、全员禁画也不影响只预览的轨。

```swift theme={null}
// 打开预览（UIKit / AppKit 传 view；SwiftUI 传 nil，再用 SRTCVideoView(track:) 渲染）
let track = try await meeting.requestOpenCamera(
    view: previewView,
    deviceId: selectedCameraId,
    publish: false
)

// 用户在检测页里换了摄像头：再调一次，传新的 deviceId
try await meeting.requestOpenCamera(view: previewView, deviceId: newCameraId, publish: false)

// 关闭预览：只预览的才关，会议摄像头开着时不动
if !meeting.isCameraOpened {
    await meeting.closeCamera()
}
```

几种组合的结果：

* **预览后决定开摄像头**：以默认的 `publish: true` 再调一次 `requestOpenCamera()`，会请求会控并发布**同一条轨**，不重新采集，画面不闪。
* **会议摄像头已开着时打开预览**：`publish: false` 直接返回正在用的轨，不会再开一路采集；这时 `isCameraOpened` 为 `true`，关预览时不要调 `closeCamera()`。
* **会前用默认参数打开的摄像头**：入会后再调用一次 `requestOpenCamera()` 会补发布到会议。

***

### 麦克风音量

Swift 会议层的 `requestOpenMic` **没有** `publish: false`，暂不支持会外或只采集不发布的测麦。这是苹果平台音频链路的限制：麦克风在发布前一直处于静音，会外的录音链路也要入会后才启动，此时读不到有效的音量。

会中开麦之后，可以用活跃说话人事件里自己那一条（`isLocal == true`）显示本端音量：

```swift theme={null}
func meeting(_ meeting: SMeetingEngine, activeSpeakersDidChange snapshot: ActiveSpeakersSnapshot) {
    let myLevel = snapshot.speakers.first(where: { $0.isLocal })?.level ?? 0
    micLevelView.update(myLevel)   // 0~1
}
```

会前检测页如果一定要测麦，可以用系统 `AVAudioRecorder` / `AVAudioEngine` 自己采一段读电平，测完释放后再入会。

***

### 扬声器试听

SDK 不提供播放测试音的接口，测试音由业务自己用 `AVAudioPlayer` 播放：

* **macOS**：先 `try meeting.setAudioOutput(deviceId:)` 选中要测的输出设备，再播放测试音。
* **iOS**：输出路由由系统决定，可用 `setSpeakerOutputEnabled(_:)` 在外放与听筒之间切换，蓝牙等外设交给系统路由选择器，见 [音频路由](https://docs.stmlink.com/zh/meeting/swift/advanced/audio-routing.md)。

***

### 相关页面

* [外设管理](https://docs.stmlink.com/zh/meeting/swift/advanced/device-management.md)
* [音视频控制接口](https://docs.stmlink.com/zh/meeting/swift/api-reference/media-control.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.