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

# In-meeting chat and file messages

> Group and private in-meeting chat, sending chat files (presignedPutObject for a signed URL → PUT the file yourself → sendRoomChatMessage with the key), the JSON format of file messages, receiving and downloading (presignedGetObject), and fetching history with roomChatMsgList

### Overview

In-meeting chat has a single send API, `sendRoomChatMessage`, used for text, files, images, and voice alike.

**The SDK doesn't transfer files.** `ChatMsgType.File` / `Pic` / `Sound` only tag the message type; `msg` is always a string,
and neither the SDK nor the server parses it. So sending a file takes three steps:

1. `presignedPutObject(PresignedPutObjectType.Chat, ...)` to get a signed upload URL
2. `PUT` the file to that URL yourself (the SDK doesn't do this step)
3. Serialize the file info into a JSON string and send it with `sendRoomChatMessage(msg, ChatMsgType.File)`

The receiver parses the JSON, and when downloading calls `presignedGetObject(key)` to get a download URL.

***

### Send a text message

```typescript theme={null}
import { ChatMsgType } from '@seastart/smeeting-web-sdk';

// Send to everyone in the room
await smeeting.sendRoomChatMessage('Hello everyone');

// Private message: pass the other user's uid as the third argument
await smeeting.sendRoomChatMessage('Just for you', ChatMsgType.Text, targetUid);
```

```typescript theme={null}
sendRoomChatMessage(msg: string, msgType?: ChatMsgType, targetId?: string): Promise<void>
```

| Parameter | Description |
| - | - |
| `msg` | Message content, **always a string**; file-type messages pass a JSON string |
| `msgType` | `ChatMsgType`, defaults to `Text` (1); `File` = 2, `Pic` = 3, `Sound` = 4 |
| `targetId` | Recipient uid; set it for a private message, omit it to send to everyone |

Must be called while in a meeting, otherwise it fails with "not in meeting". The server rejects it when chat is disabled for the meeting or for you.

***

### Send a file message

```typescript theme={null}
import { ChatMsgType, PresignedPutObjectType } from '@seastart/smeeting-web-sdk';

async function sendChatFile(file: File) {
  const meetingId = smeeting.getRoomInfo()?.id;
  if (!meetingId) throw new Error('Not in a meeting');

  // 1. Get a signed upload URL. ext is the extension without the dot and sets the file suffix in storage; it's required, so pass bin when there is none
  const ext = (file.name.includes('.') ? file.name.split('.').pop()!.toLowerCase() : '') || 'bin';
  const put = await smeeting.presignedPutObject(PresignedPutObjectType.Chat, meetingId, ext);
  // put.url  Upload URL (signed, valid for 2 hours)
  // put.key  Key of the file in storage; this is what the message carries
  // put.ext  Extension

  // 2. PUT the file yourself, with the file binary as the body
  const rsp = await fetch(put.url, {
    method: 'PUT',
    headers: { 'Content-Type': 'application/octet-stream' },
    body: file,
  });
  if (!rsp.ok) throw new Error(`Upload failed: ${rsp.status}`);

  // 3. Send the message: msg is a JSON string of the file info
  const msg = JSON.stringify({
    key: put.key,          // Required; the receiver uses it to get a download URL
    name: file.name,       // Original file name, for display and save-as
    size: formatSize(file.size), // Display size, e.g. "1.20MB" (the official demo format: two decimals, no space; under 1 KB as whole bytes, e.g. "512B")
  });
  await smeeting.sendRoomChatMessage(msg, ChatMsgType.File);
}
```

To show upload progress, replace step 2 with `XMLHttpRequest` or axios `onUploadProgress`; the URL and method stay the same.

#### `presignedPutObject`

```typescript theme={null}
presignedPutObject(type: PresignedPutObjectType, meetingId: string, ext: string): Promise<{ url: string, key: string, ext: string }>
```

| Parameter | Description |
| - | - |
| `type` | Resource category; pass `PresignedPutObjectType.Chat` for chat files |
| `meetingId` | Current meeting ID (`getRoomInfo().id`) |
| `ext` | Extension without the dot, such as `pdf` or `png`. **Required** and can't be an empty string; for files without an extension pass something like `bin` (the original file name goes in the message's `name`) |

Values of `PresignedPutObjectType`:

| Value | Purpose |
| - | - |
| `Attach` (`'attach'`) | Meeting attachment |
| `Background` (`'background'`) | Meeting background image |
| `User` (`'user'`) | User resource |
| `Chat` (`'chat'`) | Chat file |

> [!WARNING]
>
> When the deployment has file features turned off, `presignedPutObject` fails right away with `2125` (file features disabled);
> hide the send-file entry in chat in that case. The SDK doesn't limit file size; enforce a per-file limit in your app.

#### `msg` format of file messages

The structure of `msg` is agreed between you and your own clients; the SDK doesn't validate it. We recommend matching the official Web demo:

```json theme={null}
{
  "key": "chat/2611/meeting-xxxx/a1b2c3d4e5f6.pdf",
  "name": "requirements.pdf",
  "size": "1.20MB"
}
```

| Field | Type | Description |
| - | - | - |
| `key` | string | The `key` returned by `presignedPutObject`. **Don't send the `url`**: the upload URL is signed and expires |
| `name` | string | Original file name |
| `size` | string | Display file size. The official demos use two decimals plus the unit with no space, such as `1.20MB` or `42.40KB`, and whole bytes under 1 KB, such as `512B` |

Add your own fields if you need more (such as image dimensions or voice duration); receivers just ignore fields they don't recognize.

> [!NOTE]
>
> All your clients (Web / Android / iOS, etc.) must use the same `msg` structure; otherwise the other side receives the message but can't parse the file out of it.

***

### Receive messages

```typescript theme={null}
import { RoomEvent, RoomEventType, ChatMsgType, RoomChatMsgEventData } from '@seastart/smeeting-web-sdk';

smeeting.onNotifyRoomEvent = (event: RoomEvent) => {
  if (event.type !== RoomEventType.ROOM_CHAT_MSG) return;
  const data = event.data as RoomChatMsgEventData;

  if (data.msg_type === ChatMsgType.File) {
    const file = JSON.parse(data.msg); // { key, name, size }
    showFileMessage(data.uid, file, data.private);
  } else {
    showTextMessage(data.uid, data.msg, data.private);
  }
};
```

`RoomChatMsgEventData`:

```typescript theme={null}
interface RoomChatMsgEventData {
    /** Message type */
    msg_type: ChatMsgType;
    /** Message content; a JSON string for file-type messages */
    msg: string;
    /** Sender uid */
    uid?: string;
    /** Whether it's a private message */
    private: boolean;
}
```

Messages you send also come back through this event (`uid` equals your own), so don't append them to the UI a second time.

***

### Download a file

```typescript theme={null}
async function downloadChatFile(file: { key: string, name: string }) {
  // Exchange the key for a signed download URL (valid for 2 hours; get a new one each time, don't cache it)
  const { url } = await smeeting.presignedGetObject(file.key);

  // <a download> ignores the file name on cross-origin URLs, so fetch it as a blob first to keep the original name
  const blob = await (await fetch(url)).blob();
  const blobUrl = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = blobUrl;
  a.download = file.name;
  a.click();
  URL.revokeObjectURL(blobUrl);
}
```

```typescript theme={null}
presignedGetObject(resKey?: string, id?: string): Promise<{ url: string }>
```

Pass the `key` (the first argument). The server doesn't support the `id` parameter yet, so always pass `resKey`.

***

### Fetch message history

People who join later don't see earlier events; use `roomChatMsgList` to fetch them:

```typescript theme={null}
const { data, _meta } = await smeeting.roomChatMsgList(meetingId, 1, 50);
for (const m of data) {
  const content = m.msg_type === ChatMsgType.File ? JSON.parse(m.msg) : m.msg;
  // m.sender_id / m.sender_name / m.created_at (timestamp in seconds)
}
```

```typescript theme={null}
roomChatMsgList(meetingId: string, page: number, perPage: number): Promise<{ data: ChatMsgInfo[], _meta: MetaRes }>
```

`ChatMsgInfo`:

```typescript theme={null}
interface ChatMsgInfo {
    /** Message id */
    id: string;
    /** Meeting ID */
    meeting_id: string;
    /** Message content (a JSON string for files / images, etc.) */
    msg: string;
    /** Message type */
    msg_type: ChatMsgType;
    /** Sender id */
    sender_id: string;
    /** Sender name */
    sender_name: string;
    /** Creation time (timestamp in seconds) */
    created_at: number;
}
```

***

### Related reading

* [SMeeting API](https://docs.stmlink.com/en/meeting/web/api-reference/SMeeting.md)
* [Events](https://docs.stmlink.com/en/meeting/web/events.md) — `ROOM_CHAT_MSG` and chat-disabled state changes
* [Types](https://docs.stmlink.com/en/meeting/web/types.md) — `ChatMsgType`, `PresignedPutObjectType`


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