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

# Key concepts

> Core model of the SRTC Web SDK: the SRTC instance and the Channel returned by join, tokens, the track class hierarchy and how each track is created, the local track lifecycle, channel and IM event callbacks, and audience mode. Read before writing code beyond the quickstart.

### SRTC instance

Create an instance with `new SRTC(initParams)`; almost all operations are exposed through this instance.

* One instance can call `join` multiple times to join several channels at once; each `join` returns that channel's Channel object
* In-channel events are delivered through the `srtc.onNotifyChannelEvent` callback; with multiple channels, use each channel's `channel.onNotifyEvent` to tell them apart. See [Multi-channel](/zh/rtc/web/advanced/multi-channel) (Chinese)

```typescript theme={null}
import { SRTC, LogLevel, LogTarget } from '@seastart/srtc-web-sdk';

const srtc = new SRTC({
  logLevel: LogLevel.DEBUG,   // DEBUG is recommended during development
  logTarget: LogTarget.CONSOLE,
});
```

***

### Channel and token

A **channel** is the container for a multi-user audio and video session, uniquely identified by its channel name. Users who join the same channel can send and receive audio and video streams with each other.

A **token** is the credential for joining a channel. Your server issues it through the STMLink server API, and it carries the channel name, user ID, permissions, and other information. Every join requires a valid token.

```typescript theme={null}
// After getting the token from your backend, call join; it returns a Channel object
const channel = await srtc.join(token);
console.log(channel.getInfo().channel); // Channel name
```

You can perform channel-level operations such as publishing, subscribing, and leaving directly on the **Channel object** returned by `join`. Single-channel apps don't need to care about it—the `srtc` instance keeps all channel-level methods (internally acting on the current channel); you only need it to specify the target when you join multiple channels at once. See [Multi-channel](/zh/rtc/web/advanced/multi-channel) (Chinese).

After joining, you can get channel and user information at any time with these methods:

```typescript theme={null}
// Get the current channel's info
const channelInfo = srtc.getChannelInfo();

// Get info for a user in the channel
const userInfo = srtc.getUserInfo(uid);

// Get all users in the channel (as a map)
const usersMap = srtc.getUsersInfo(true);   // Record<uid, UserInfo>

// Get all users in the channel (as an array)
const usersArr = srtc.getUsersInfo(false);  // UserInfo[]
```

***

### Track system

A track is the smallest unit of audio and video data; each audio or video stream is a track.

#### Class hierarchy

```text theme={null}
BaseTrack
├── LocalAudioTrack          ← Local audio base class (custom audio stream)
│   └── LocalMicTrack        ← Microphone stream
├── LocalVideoTrack          ← Local video base class (custom video stream)
│   ├── LocalCameraTrack     ← Camera stream
│   └── LocalScreenTrack     ← Screen sharing stream
├── RemoteAudioTrack         ← Single remote audio stream
│   └── RemoteAudioMixTrack  ← Remote channel-wide mixed audio stream
└── RemoteVideoTrack         ← Remote video stream
```

#### Track types

| Track type | How to create | Description |
| - | - | - |
| `LocalMicTrack` | `srtc.createLocalMicTrack()` | Microphone capture, supports switching devices |
| `LocalCameraTrack` | `srtc.createLocalCameraTrack()` | Camera capture, supports switching devices |
| `LocalScreenTrack` | `srtc.createLocalScreenTrack()` | Screen sharing, can capture system audio at the same time |
| `LocalAudioTrack` | `srtc.createLocalCustomAudioTrack(msTrack)` | Custom audio, pass in a `MediaStreamTrack` |
| `LocalVideoTrack` | `srtc.createLocalCustomVideoTrack(msTrack)` | Custom video, pass in a `MediaStreamTrack` |
| `RemoteAudioMixTrack` | `srtc.subscribeRemoteAudioMixTrack()` | Channel-wide mixed audio; in most scenarios this is the only audio you need to subscribe to |
| `RemoteAudioTrack` | `srtc.subscribeRemoteAudioTrack(uid, id)` | Subscribe to a single audio track of a given user |
| `RemoteVideoTrack` | `srtc.subscribeRemoteVideoTrack(uid, id)` | Subscribe to a given user's video |

#### Local track lifecycle

```text theme={null}
createLocalXxxTrack()
  → startCapture()        // Start capture (requests camera/microphone permission)
  → publishLocalTrack()   // Publish to the channel (other users can subscribe)
  → unpublishLocalTrack() // Unpublish (other users can't see it, but local capture continues)
  → stopCapture()         // Stop capture and release the device
```

***

### Event system

SRTC provides two sets of event callbacks:

#### In-channel events (onNotifyChannelEvent)

Listen for channel connection state, remote users joining and leaving, remote track changes, local device state, and more:

```typescript theme={null}
srtc.onNotifyChannelEvent = (evt: ChannelEvent) => {
  switch (evt.type) {
    case ChannelEventType.USER_JOIN:
      // A remote user joined; evt.data is UserInfo
      break;
    case ChannelEventType.USER_TRACK_ADD:
      // A remote user published a new track; evt.data is { user: UserInfo, track: TrackInfo }
      break;
    // ... for more events, see "Events"
  }
};
```

#### Out-of-channel message events (onNotifyImEvent)

Listen for IM messages (call `srtc.enableIm(token)` first to enable IM):

```typescript theme={null}
srtc.onNotifyImEvent = (evt: ImEvent) => {
  if (evt.type === ImEventType.IM_MSG) {
    // evt.data is ImMsgData
  }
};
```

For the full event list, see [Events](/zh/rtc/web/events) (Chinese).

***

### Audience mode (is\_audience)

When `UserInfo.is_audience` is `true`, the user has joined the channel as an audience member:

* Audience members only receive audio and video streams and **can't publish** local tracks
* Whether a user joins as audience is decided when the server issues the token
* Use the `ChannelEventType.ME_UPDATE` event to detect changes to your own audience status
