@sentinel-it/meowmeow-sdk 1.0.0-rc.b28bb80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # MeowMeow SDK
2
+
3
+ 可嵌入式群組聊天室 JavaScript / TypeScript SDK
4
+
5
+ [API Reference](api-docs/index.md)
6
+
7
+ ---
8
+
9
+ # 快速開始
10
+
11
+ ## 安裝
12
+
13
+ **npm / pnpm(ESM)**
14
+
15
+ ```bash
16
+ npm install @sentinel-it/meowmeow-sdk
17
+ # 或
18
+ pnpm add @sentinel-it/meowmeow-sdk
19
+ ```
20
+
21
+ **CDN(IIFE)**
22
+
23
+ ```html
24
+ <script src="https://cdn.jsdelivr.net/npm/@sentinel-it/meowmeow-sdk@latest/dist/meowmeow-sdk.js"></script>
25
+ <script>
26
+ const { MeowMeow, MeowMeowClient } = MeowMeowSDK
27
+ </script>
28
+ ```
29
+
30
+ ## Token
31
+
32
+ 呼叫 SDK 前,後端須向 MeowMeow 服務端取得使用者 JWT Token 並傳給前端。
33
+
34
+ 若提供 `onTokenRefresh`,SDK 會在 Token 到期前 30 秒自動呼叫以取得新 Token,連線不會中斷。若未提供,Token 過期後連線將會斷開。
35
+
36
+ ---
37
+
38
+ ## MeowMeow — 嵌入聊天室 UI
39
+
40
+ `MeowMeow` 可直接將聊天室 Widget 嵌入頁面。
41
+
42
+ ```ts
43
+ import { MeowMeow } from '@sentinel-it/meowmeow-sdk'
44
+
45
+ const chat = new MeowMeow({
46
+ token: 'YOUR_JWT_TOKEN',
47
+ room: 'YOUR_ROOM_ID',
48
+ locale: 'zh',
49
+ title: '客服聊天室',
50
+ onTokenRefresh: async () => {
51
+ const res = await fetch('/api/chat-token')
52
+ const { token } = await res.json()
53
+ return token
54
+ },
55
+ })
56
+
57
+ await chat.mount()
58
+ chat.show()
59
+ ```
60
+
61
+ ### 初始化選項
62
+
63
+ | 選項 | 型別 | 必填 | 說明 |
64
+ |------|------|:----:|------|
65
+ | `token` | `string` | ✓ | 使用者 JWT Token |
66
+ | `room` | `string` | ✓ | 房間 ID |
67
+ | `locale` | `string` | | 介面語言,預設 `'en'`,支援 `en`、`id`、`vi`、`tl` |
68
+ | `title` | `string \| Record<string, string>` | | 聊天室標題,可傳入語系對照物件 |
69
+ | `zIndex` | `number \| 'auto'` | | Widget 層級,預設 `'auto'` |
70
+ | `onTokenRefresh` | `() => Promise<string>` | | Token 刷新回呼 |
71
+
72
+ `title` 可傳入語系對照物件:
73
+
74
+ ```ts
75
+ title: {
76
+ en: 'Support Chat',
77
+ id: 'Obrolan Dukungan',
78
+ vi: 'Hỗ trợ trực tuyến',
79
+ }
80
+ ```
81
+
82
+ ### 方法
83
+
84
+ | 方法 | 說明 |
85
+ |------|------|
86
+ | `mount(): Promise<void>` | 掛載 Widget 至 DOM |
87
+ | `unmount(): void` | 卸載並釋放資源 |
88
+ | `show(): void` | 顯示 Widget |
89
+ | `hide(): void` | 隱藏 Widget |
90
+ | `setLocale(locale: string): void` | 動態切換介面語言(`en`、`id`、`vi`、`tl`) |
91
+
92
+ ### 事件
93
+
94
+ 使用 `chat.on(event, handler)` 監聽。
95
+
96
+ | 事件 | Payload | 說明 |
97
+ |------|---------|------|
98
+ | `ready` | — | Widget 掛載完成,可開始互動 |
99
+
100
+ ---
101
+
102
+ ## 無頭模式(`MeowMeowClient`)
103
+
104
+ 若不需要內建 UI,可直接使用 `MeowMeowClient`。
105
+
106
+ ```ts
107
+ import { MeowMeowClient } from '@sentinel-it/meowmeow-sdk'
108
+
109
+ const client = new MeowMeowClient({
110
+ token: 'YOUR_JWT_TOKEN',
111
+ roomId: 'YOUR_ROOM_ID',
112
+ onTokenRefresh: async () => fetchNewToken(),
113
+ })
114
+
115
+ const room = await client.join()
116
+
117
+ room.on('message', (msg) => {
118
+ if (msg.pending) return // 樂觀更新,等待伺服器確認
119
+ if (msg.errorCode) return // 傳送失敗
120
+ console.log(msg.userName, msg.content)
121
+ })
122
+
123
+ // 頁面卸載時釋放資源
124
+ client.dispose()
125
+ ```
126
+
127
+ ### 初始化選項
128
+
129
+ | 選項 | 型別 | 必填 | 說明 |
130
+ |------|------|:----:|------|
131
+ | `token` | `string` | ✓ | 使用者 JWT Token |
132
+ | `roomId` | `string` | ✓ | 要加入的聊天室 ID |
133
+ | `onTokenRefresh` | `() => Promise<string>` | | Token 刷新回呼 |
134
+
135
+ ### 方法
136
+
137
+ | 方法 | 說明 |
138
+ |------|------|
139
+ | `join(): Promise<Room>` | 建立連線並加入聊天室,回傳 `Room` 實例 |
140
+ | `dispose(): void` | 關閉連線並釋放所有資源 |
141
+
142
+ ### 屬性
143
+
144
+ | 屬性 | 型別 | 說明 |
145
+ |------|------|------|
146
+ | `currentUser` | `User \| null` | 目前已連線的使用者資訊 |
147
+
148
+ ### 事件
149
+
150
+ 使用 `client.on(event, handler)` 監聽。
151
+
152
+ | 事件 | Payload | 說明 |
153
+ |------|---------|------|
154
+ | `connected` | `{ user }` | WebSocket 連線成功 |
155
+ | `disconnected` | `{ reason, willReconnect }` | 連線斷開 |
156
+ | `reconnecting` | `{ attempt }` | 正在重新連線,`attempt` 為第幾次嘗試 |
157
+ | `reconnected` | — | 重連成功 |
158
+ | `room_joined` | `{ onlineUsers, cooldownSeconds, greetingMessage? }` | 成功加入聊天室 |
159
+ | `banned` | `{ until }` | 使用者被封禁 |
160
+ | `unbanned` | — | 封禁解除 |
161
+ | `error` | `{ code, message }` | 發生錯誤 |
162
+
163
+ ---
164
+
165
+ ## Room — 聊天室操作
166
+
167
+ `client.join()` 回傳的 `Room` 實例,用於發送訊息與監聽聊天室事件。
168
+
169
+ ### 方法
170
+
171
+ | 方法 | 說明 |
172
+ |------|------|
173
+ | `send(content, sender): Promise<void>` | 發送文字訊息(樂觀更新) |
174
+ | `sendSticker({ packId, code }, sender): Promise<void>` | 發送貼圖(樂觀更新) |
175
+
176
+ ### 事件
177
+
178
+ 使用 `room.on(event, handler)` 監聽。
179
+
180
+ | 事件 | Payload | 說明 |
181
+ |------|---------|------|
182
+ | `message` | `Message` | 收到新訊息(含樂觀更新與失敗訊息) |
183
+ | `presence` | `{ type, user, onlineCount }` | 使用者加入或離開 |
184
+ | `muted` | `{ until }` | 使用者被禁言 |
185
+ | `unmuted` | — | 禁言解除 |
186
+ | `room_updated` | `{ cooldownSeconds }` | 聊天室設定更新 |
187
+
188
+ ---
189
+
190
+ ## 錯誤碼
191
+
192
+ | 錯誤碼 | 說明 |
193
+ |--------|------|
194
+ | `TOKEN_INVALID` | Token 無效或已過期 |
195
+ | `FORBIDDEN` | 無操作權限 |
196
+ | `USER_MUTED` | 使用者已被禁言 |
197
+ | `USER_BANNED` | 使用者已被封禁 |
198
+ | `ROOM_NOT_FOUND` | 房間不存在 |
199
+ | `CHAT_MESSAGE_BLOCKED` | 訊息被過濾攔截 |
200
+ | `INTERNAL_SERVER_ERROR` | 伺服器內部錯誤 |
201
+ | `TOKEN_REFRESH_FAILED` | Token 刷新失敗 |
202
+
@@ -0,0 +1,431 @@
1
+ export declare type ClientErrorCode = 'WS_ERROR' | 'WS_MESSAGE_ERROR' | 'TOKEN_REFRESH_FAILED';
2
+
3
+ /** `MeowMeowClient` 可監聽的事件與其 payload 型別對應表 */
4
+ export declare interface ClientEventMap {
5
+ /** WebSocket 連線建立,伺服器已確認身份 */
6
+ connected: {
7
+ user: User;
8
+ };
9
+ /** 連線中斷;`willReconnect` 為 true 時 SDK 會自動重連 */
10
+ disconnected: {
11
+ reason: DisconnectReason;
12
+ willReconnect: boolean;
13
+ };
14
+ /** 正在嘗試重新連線,`attempt` 為目前第幾次嘗試 */
15
+ reconnecting: {
16
+ attempt: number;
17
+ };
18
+ /** 重連成功 */
19
+ reconnected: void;
20
+ /** 成功加入聊天室,`join()` 回傳的 Room 即可使用 */
21
+ room_joined: {
22
+ onlineUsers: User[];
23
+ cooldownSeconds: number;
24
+ greetingMessage?: string;
25
+ };
26
+ /** 目前使用者被封禁,`until` 為解封時間(ISO 8601),永久封禁為 null */
27
+ banned: {
28
+ until: string | null;
29
+ };
30
+ /** 目前使用者的封禁已解除 */
31
+ unbanned: void;
32
+ /** SDK 內部錯誤,`code` 為錯誤代碼 */
33
+ error: {
34
+ code: ClientErrorCode;
35
+ message: string;
36
+ };
37
+ }
38
+
39
+ declare interface ConnectionApi {
40
+ connect(roomId: string): Promise<void>;
41
+ disconnect(reason?: DisconnectReason): void;
42
+ sendMessage(roomId: string, payload: SendMessagePayload): Promise<void>;
43
+ getMessages(roomId: string, options?: GetMessagesOptions): Promise<MessagesResult>;
44
+ }
45
+
46
+ /** WebSocket 連線狀態 */
47
+ export declare type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'joined' | 'reconnecting';
48
+
49
+ /** 連線斷開原因 */
50
+ export declare type DisconnectReason = 'room_unavailable' | 'connection_replaced' | 'ping_timeout' | 'connected_timeout' | 'room_joined_timeout' | 'token_refresh_failed' | 'fetch_ticket_failed' | 'reconnect_failed' | 'user_banned' | (string & {});
51
+
52
+ /** 型別安全的事件發送器,`MeowMeowClient` 與 `Room` 皆繼承此類別。 */
53
+ declare class EventEmitter<TEventMap extends object = Record<string, unknown>> {
54
+ private _listeners;
55
+ /**
56
+ * 註冊事件監聽器。
57
+ * @param event 事件名稱
58
+ * @param handler 事件處理函式
59
+ */
60
+ on<E extends keyof TEventMap>(event: E, handler: (payload: TEventMap[E]) => void): void;
61
+ /**
62
+ * 移除已註冊的事件監聽器。
63
+ * @param event 事件名稱
64
+ * @param handler 要移除的處理函式(需與 `on` 傳入的參考相同)
65
+ */
66
+ off<E extends keyof TEventMap>(event: E, handler: (payload: TEventMap[E]) => void): void;
67
+ protected emit<E extends keyof TEventMap>(event: E, ...args: TEventMap[E] extends void ? [] : [payload: TEventMap[E]]): void;
68
+ /** 移除所有事件的所有監聽器。 */
69
+ removeAllListeners(): void;
70
+ }
71
+
72
+ /** 取得歷史訊息的查詢選項 */
73
+ declare interface GetMessagesOptions {
74
+ /** 單次最多取幾筆 */
75
+ limit: number;
76
+ /** 取在此訊息 ID 之前的訊息(用於分頁) */
77
+ before?: string;
78
+ }
79
+
80
+ /**
81
+ * MeowMeow 聊天室 UI Widget。
82
+ * 掛載後在頁面上顯示完整的聊天室介面(預覽泡泡 + 聊天室視窗)。
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const chat = new MeowMeow({ token: '...', room: 'room-1', locale: 'zh' })
87
+ * await chat.mount()
88
+ * chat.show()
89
+ * ```
90
+ */
91
+ export declare class MeowMeow extends EventEmitter {
92
+ private readonly options;
93
+ private readonly client;
94
+ private vueApp;
95
+ private hostElement;
96
+ private meowmeowStore;
97
+ private uiStore;
98
+ private localeSet;
99
+ constructor(options: MeowMeowOptions);
100
+ /** 顯示 MeowMeow */
101
+ show(): void;
102
+ /** 隱藏 MeowMeow */
103
+ hide(): void;
104
+ /**
105
+ * 動態設定語系
106
+ * @param locale 目前僅支援 en / id / vi / tl
107
+ */
108
+ setLocale(locale: string): void;
109
+ /**
110
+ * 建立 Shadow DOM、初始化 Vue 應用並掛載到 `document.body`。
111
+ * 掛載後聊天室預設為隱藏,需呼叫 {@link show} 顯示。
112
+ */
113
+ mount(): Promise<void>;
114
+ /** 卸載 Vue 應用、移除 DOM 元素並釋放所有資源。 */
115
+ unmount(): void;
116
+ }
117
+
118
+ /**
119
+ * MeowMeow SDK 的核心 Client,負責管理 WebSocket 連線與聊天室生命週期。
120
+ *
121
+ * @remarks
122
+ * 可透過 `on(event, handler)` 監聽以下事件:
123
+ *
124
+ * | 事件 | Payload | 說明 |
125
+ * |------|---------|------|
126
+ * | `connected` | `{ user }` | 連線建立並通過身份驗證 |
127
+ * | `disconnected` | `{ reason, willReconnect }` | 連線中斷 |
128
+ * | `reconnecting` | `{ attempt }` | 正在嘗試重連 |
129
+ * | `reconnected` | — | 重連成功 |
130
+ * | `room_joined` | `{ onlineUsers, cooldownSeconds, greetingMessage? }` | 成功加入聊天室 |
131
+ * | `banned` | `{ until }` | 被封禁 |
132
+ * | `unbanned` | — | 封禁解除 |
133
+ * | `error` | `{ code, message }` | SDK 內部錯誤 |
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const client = new MeowMeowClient({ token: '...', roomId: 'room-1' })
138
+ * const room = await client.join()
139
+ * room.on('message', msg => console.log(msg))
140
+ * client.on('disconnected', ({ reason }) => console.warn('disconnected:', reason))
141
+ * ```
142
+ */
143
+ export declare class MeowMeowClient extends EventEmitter<ClientEventMap> {
144
+ private readonly connectionApi;
145
+ private readonly roomId;
146
+ private currentRoom;
147
+ private _pendingJoinPromise;
148
+ private _pendingJoinResolve;
149
+ private _pendingJoinReject;
150
+ private _pendingJoinTimer;
151
+ private _connectionStatus;
152
+ private _currentUser;
153
+ private _isMuted;
154
+ private _mutedUntil;
155
+ private _isBanned;
156
+ private readonly _userStateFilter;
157
+ private readonly _onlineUsersFilter;
158
+ /** 目前的連線狀態 */
159
+ get connectionStatus(): ConnectionStatus;
160
+ /** 目前登入的使用者,連線前為 null */
161
+ get currentUser(): User | null;
162
+ /** 目前使用者是否被禁言 */
163
+ get isMuted(): boolean;
164
+ /** 禁言到期時間(ISO 8601),未被禁言時為 null */
165
+ get mutedUntil(): string | null;
166
+ /** 目前使用者是否被封禁 */
167
+ get isBanned(): boolean;
168
+ constructor(options: MeowMeowClientOptions);
169
+ /**
170
+ * 建立連線並加入聊天室,回傳 {@link Room} 實例。
171
+ *
172
+ * 若連線或加入超過 10 秒未完成,Promise 將 reject。
173
+ * 重複呼叫時回傳同一個 pending Promise,不會建立多條連線。
174
+ */
175
+ join(): Promise<Room>;
176
+ /**
177
+ * 主動斷開 WebSocket 連線。
178
+ * @param reason 斷線原因,預設為 `'manual disconnect'`
179
+ */
180
+ disconnect(reason?: DisconnectReason): void;
181
+ /** 斷開連線並移除所有事件監聽器,釋放資源。頁面卸載時應呼叫此方法。 */
182
+ dispose(): void;
183
+ /* Excluded from this release type: onConnected */
184
+ /* Excluded from this release type: onDisconnected */
185
+ /* Excluded from this release type: onReconnecting */
186
+ /* Excluded from this release type: onReconnected */
187
+ /* Excluded from this release type: onRoomJoined */
188
+ /* Excluded from this release type: onRoomUpdated */
189
+ /* Excluded from this release type: onMessage */
190
+ /* Excluded from this release type: onPresence */
191
+ /* Excluded from this release type: onMuted */
192
+ /* Excluded from this release type: onUnmuted */
193
+ /* Excluded from this release type: onBanned */
194
+ /* Excluded from this release type: onUnbanned */
195
+ /* Excluded from this release type: onWarned */
196
+ /* Excluded from this release type: onError */
197
+ private _startJoinTimer;
198
+ private _clearPendingJoin;
199
+ }
200
+
201
+ /** MeowMeowClient 建構所需的設定選項 */
202
+ export declare interface MeowMeowClientOptions {
203
+ /** 用於驗證身份的 JWT token */
204
+ token: string;
205
+ /** 要加入的聊天室 ID */
206
+ roomId: string;
207
+ /**
208
+ * Token 過期時的刷新回調,應回傳新的有效 token。
209
+ * 若未提供,token 過期後連線將直接斷開。
210
+ */
211
+ onTokenRefresh?: () => Promise<string>;
212
+ }
213
+
214
+ export declare interface MeowMeowOptions {
215
+ token: string;
216
+ room: string;
217
+ locale?: string;
218
+ title?: string | Record<string, string> | 'CHAT ROOM';
219
+ zIndex?: number | 'auto';
220
+ onTokenRefresh?: () => Promise<string>;
221
+ }
222
+
223
+ /** 聊天室訊息 */
224
+ export declare interface Message {
225
+ /** 訊息唯一識別碼 */
226
+ id: string;
227
+ /** 訊息的序號(用於排序) */
228
+ seq: number;
229
+ /** 同一 seq 下的子序號 */
230
+ subSeq: number;
231
+ /** 訊息類型:文字、貼圖或系統訊息 */
232
+ type: 'text' | 'sticker' | 'system';
233
+ /** 訊息內容文字 */
234
+ content: string;
235
+ /** 發送者的使用者 ID */
236
+ userId: string;
237
+ /** 發送者的顯示名稱 */
238
+ userName: string;
239
+ /** 發送者的頭像 URL,無頭像時為 null */
240
+ avatar: string | null;
241
+ /** 訊息建立時間(ISO 8601 格式) */
242
+ createdAt: string;
243
+ /** 訊息附帶的額外資料(例如貼圖資訊) */
244
+ metadata: {
245
+ sticker?: {
246
+ packId: string;
247
+ code: string;
248
+ url: string;
249
+ };
250
+ } | null;
251
+ /** 傳送失敗時的錯誤代碼 */
252
+ errorCode?: WsErrorCode;
253
+ /** 客戶端本地參考 ID,用於對應樂觀更新 */
254
+ clientRef?: string | null;
255
+ /** 是否為尚未確認的樂觀更新訊息 */
256
+ pending?: boolean;
257
+ }
258
+
259
+ /** `getMessages` / `loadMoreMessages` 的回傳結果 */
260
+ declare interface MessagesResult {
261
+ /** 取得的訊息列表(依序號排序) */
262
+ messages: Message[];
263
+ /** 是否還有更早的訊息可以載入 */
264
+ hasMore: boolean;
265
+ }
266
+
267
+ /** push event → payload 型別對應表(payload 為 undefined 表示該事件無附帶資料) */
268
+ declare interface PushEventPayloadMap {
269
+ connected: {
270
+ roomId?: string;
271
+ user: User & {
272
+ status: 'normal' | 'muted' | 'banned';
273
+ };
274
+ };
275
+ room_joined: {
276
+ onlineUsers: User[];
277
+ onlineCount: number;
278
+ latestMessageId: string;
279
+ greetingMessage?: string;
280
+ cooldownSeconds: number;
281
+ };
282
+ room_updated: {
283
+ cooldownSeconds: number;
284
+ };
285
+ presence: {
286
+ type: 'join' | 'leave';
287
+ user: User;
288
+ onlineCount: number;
289
+ };
290
+ muted: {
291
+ until: string | null;
292
+ };
293
+ unmuted: undefined;
294
+ banned: {
295
+ until: string | null;
296
+ };
297
+ unbanned: undefined;
298
+ warned: {
299
+ reason?: string;
300
+ };
301
+ room_unavailable: undefined;
302
+ connection_replaced: undefined;
303
+ }
304
+
305
+ /**
306
+ * 代表一個已加入的聊天室,提供發送訊息、載入歷史紀錄與監聽即時事件的能力。
307
+ * 由 {@link MeowMeowClient.join} 回傳,不應自行建構。
308
+ *
309
+ * @remarks
310
+ * 可透過 `on(event, handler)` 監聽以下事件:
311
+ *
312
+ * | 事件 | Payload | 說明 |
313
+ * |------|---------|------|
314
+ * | `message` | {@link Message} | 收到新訊息(含 pending 樂觀更新) |
315
+ * | `presence` | `{ type, user, onlineCount }` | 使用者加入或離開 |
316
+ * | `muted` | `{ until }` | 被禁言 |
317
+ * | `unmuted` | — | 禁言解除 |
318
+ * | `room_updated` | `{ cooldownSeconds }` | 聊天室設定更新 |
319
+ */
320
+ export declare class Room extends EventEmitter<RoomEventMap> {
321
+ /** 聊天室唯一識別碼 */
322
+ readonly id: string;
323
+ /** 聊天室顯示名稱 */
324
+ readonly name: string;
325
+ private readonly connectionApi;
326
+ private _onlineUsers;
327
+ private _cooldownSeconds;
328
+ private _messages;
329
+ private _hasMore;
330
+ /** 發送訊息冷卻秒數(0 表示無限制) */
331
+ get cooldownSeconds(): number;
332
+ /** 目前在線的使用者列表 */
333
+ get onlineUsers(): User[];
334
+ /** 目前已載入的訊息列表(依序號排序) */
335
+ get messages(): Message[];
336
+ /** 是否還有更早的歷史訊息可以載入 */
337
+ get hasMore(): boolean;
338
+ /* Excluded from this release type: __constructor */
339
+ /**
340
+ * 發送文字訊息。採樂觀更新,訊息會立即出現在 `messages` 並觸發 `message` 事件;
341
+ * 若伺服器回傳錯誤,該訊息的 `errorCode` 會被設定且 `pending` 設為 false。
342
+ * @param content 訊息文字內容
343
+ * @param sender 發送者資訊
344
+ */
345
+ send(content: string, sender: User): Promise<void>;
346
+ /**
347
+ * 發送貼圖訊息,行為同 {@link send}(樂觀更新)。
348
+ * @param options 貼圖包 ID 與貼圖代碼
349
+ * @param sender 發送者資訊
350
+ */
351
+ sendSticker(options: {
352
+ packId: string;
353
+ code: string;
354
+ }, sender: User): Promise<void>;
355
+ /* Excluded from this release type: getMessages */
356
+ /* Excluded from this release type: loadMoreMessages */
357
+ /* Excluded from this release type: _setOnlineUsers */
358
+ /* Excluded from this release type: _setCooldownSeconds */
359
+ /* Excluded from this release type: _initMessages */
360
+ /* Excluded from this release type: _handleMessage */
361
+ /* Excluded from this release type: _handleRoomUpdated */
362
+ /* Excluded from this release type: _handlePresence */
363
+ /* Excluded from this release type: _handleMuted */
364
+ /* Excluded from this release type: _handleUnmuted */
365
+ /* Excluded from this release type: _handleWarned */
366
+ /* Excluded from this release type: reset */
367
+ private _createPendingMessage;
368
+ private _markFailed;
369
+ private _insertMessage;
370
+ private _mergeSorted;
371
+ }
372
+
373
+ /** `Room` 可監聽的事件與其 payload 型別對應表 */
374
+ export declare interface RoomEventMap {
375
+ /** 收到新訊息(含樂觀更新的 pending 訊息與伺服器確認後的最終訊息) */
376
+ message: Message;
377
+ /** 使用者加入或離開聊天室 */
378
+ presence: {
379
+ type: 'join' | 'leave';
380
+ user: User;
381
+ onlineCount: number;
382
+ };
383
+ /** 目前使用者被禁言,`until` 為禁言到期時間(ISO 8601),永久禁言為 null */
384
+ muted: {
385
+ until: string | null;
386
+ };
387
+ /** 目前使用者的禁言已解除 */
388
+ unmuted: void;
389
+ /** 聊天室設定更新(目前僅有冷卻秒數) */
390
+ room_updated: {
391
+ cooldownSeconds: number;
392
+ };
393
+ }
394
+
395
+ declare type SendMessagePayload = {
396
+ type: 'text';
397
+ content: string;
398
+ clientRef: string;
399
+ } | {
400
+ type: 'sticker';
401
+ packId: string;
402
+ code: string;
403
+ clientRef: string;
404
+ };
405
+
406
+ /** 貼圖包資訊 */
407
+ export declare interface StickerPack {
408
+ /** 貼圖包唯一識別碼 */
409
+ id: string;
410
+ /** 貼圖包名稱 */
411
+ name: string;
412
+ /** 包含的貼圖列表 */
413
+ stickers: Array<{
414
+ code: string;
415
+ url: string;
416
+ }>;
417
+ }
418
+
419
+ /** 使用者資訊 */
420
+ export declare interface User {
421
+ /** 使用者唯一識別碼 */
422
+ id: string;
423
+ /** 使用者顯示名稱 */
424
+ name: string;
425
+ /** 頭像 URL,無頭像時為 null */
426
+ avatar: string | null;
427
+ }
428
+
429
+ export declare type WsErrorCode = 'BAD_REQUEST' | 'TOKEN_INVALID' | 'FORBIDDEN' | 'USER_MUTED' | 'USER_BANNED' | 'ROOM_NOT_FOUND' | 'CHAT_MESSAGE_STORE_UNAVAILABLE' | 'CHAT_MESSAGE_BLOCKED' | 'INTERNAL_SERVER_ERROR' | 'INVALID_TYPE' | 'INVALID_MESSAGE_TYPE' | 'MISSING_REF';
430
+
431
+ export { }