@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.10

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/dist/rtm.d.ts ADDED
@@ -0,0 +1,639 @@
1
+ export as namespace rtm;
2
+
3
+ declare namespace rtm {
4
+ export type RTMProtocol = 'fpnn' | 'tlv-v1';
5
+ /** Selects the page API contract; FPNN already uses the legacy RTM contract, while TLV needs mapping. */
6
+ export type RTMCompatibility = 'native' | 'legacy-rtm';
7
+ export type RTMId = string | number | { toString(): string };
8
+ /** Payloads accepted by FPNN legacy RTM, including MessagePack objects. */
9
+ export type RTMLegacyMessagePayload = string | ArrayBuffer | ArrayBufferView | Record<string, unknown>;
10
+ /** TLV v1 message.send accepts only a string or a binary payload. */
11
+ export type RTMLegacyTlvMessagePayload = string | ArrayBuffer | ArrayBufferView;
12
+
13
+ export interface RTMCompatibilityError extends Error {
14
+ name: 'RTMCompatibilityError';
15
+ code: 'RTM_COMPATIBILITY_UNSUPPORTED' | 'RTM_COMPATIBILITY_MAPPING_FAILED';
16
+ method?: string;
17
+ protocol?: RTMProtocol;
18
+ compatibility: 'legacy-rtm';
19
+ }
20
+
21
+ export interface RTMLegacySendResult {
22
+ mid: RTMId;
23
+ payload: { mtime?: RTMId; [key: string]: unknown };
24
+ }
25
+
26
+ export interface RTMLegacySendError {
27
+ mid: RTMId;
28
+ error: Error & { code?: number; status?: number; reason?: string };
29
+ }
30
+
31
+ export interface RTMLegacyHistoryMessage {
32
+ id: RTMId;
33
+ direction?: number;
34
+ from?: RTMId;
35
+ mtype: number;
36
+ mid: RTMId;
37
+ deleted: boolean;
38
+ msg?: RTMLegacyMessagePayload;
39
+ binary: RTMLegacyMessagePayload;
40
+ attrs?: RTMLegacyMessagePayload;
41
+ mtime: RTMId;
42
+ }
43
+
44
+ export interface RTMLegacyHistoryResponse {
45
+ num: number;
46
+ msgs: RTMLegacyHistoryMessage[];
47
+ lastid: RTMId;
48
+ begin: RTMId;
49
+ end: RTMId;
50
+ }
51
+
52
+ export interface RTMLegacyPushMessage {
53
+ from: RTMId;
54
+ mtype: number;
55
+ mid: RTMId;
56
+ msg?: RTMLegacyMessagePayload;
57
+ binary?: RTMLegacyMessagePayload;
58
+ attrs?: RTMLegacyMessagePayload;
59
+ mtime: RTMId;
60
+ to?: RTMId;
61
+ gid?: RTMId;
62
+ rid?: RTMId;
63
+ }
64
+
65
+ export interface RTMLoginPromiseResult {
66
+ accepted: true;
67
+ errorCode: number;
68
+ }
69
+
70
+ type RTMPromiseExcludedMethod = 'close' | 'destroy' | 'emit' | 'listenerCount' | 'off' | 'on'
71
+ | 'removeEvent' | 'startAutoReconnect' | 'promises' | 'processor';
72
+
73
+ /** Promise versions of callback-based RTM requests. Parameters keep the original order, without callback. */
74
+ export type RTMPromiseApi = {
75
+ [Method in Exclude<keyof RTMClient, RTMPromiseExcludedMethod>]:
76
+ RTMClient[Method] extends (...args: any[]) => any ? (...args: any[]) => Promise<any> : never;
77
+ } & {
78
+ login(uid: RTMId, credential: string, timeout?: number): Promise<RTMLoginPromiseResult>;
79
+ bye(timeout?: number): Promise<any>;
80
+ sendChat(to: RTMId, msg: string | ArrayBuffer | Uint8Array, attrs?: string, mid?: RTMId, timeout?: number): Promise<any>;
81
+ sendGroupChat(gid: RTMId, msg: string | ArrayBuffer | Uint8Array, attrs?: string, mid?: RTMId, timeout?: number): Promise<any>;
82
+ sendRoomChat(rid: RTMId, msg: string | ArrayBuffer | Uint8Array, attrs?: string, mid?: RTMId, timeout?: number): Promise<any>;
83
+ getP2PMessage(ouid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<any>;
84
+ getGroupMessage(gid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<any>;
85
+ getRoomMessage(rid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<any>;
86
+ getSession(timeout?: number): Promise<any>;
87
+ getUnreadMessage(clear?: boolean, withLogout?: boolean, timeout?: number): Promise<any>;
88
+ };
89
+
90
+ export type RTMSharedWorkerPromiseApi = RTMPromiseApi;
91
+
92
+ export type RTMDefaultPromiseApi = Omit<RTMPromiseApi, 'login'> & {
93
+ /** Only the first same-UID page requires a credential. */
94
+ login(uid: RTMId, credential?: string, timeout?: number): Promise<RTMLoginPromiseResult>;
95
+ };
96
+
97
+ export interface RTMRegressiveStrategy {
98
+ startConnectFailedCount: number;
99
+ maxIntervalSeconds: number;
100
+ linearRegressiveCount: number;
101
+ }
102
+
103
+ interface RTMWebSocket {
104
+ binaryType?: string;
105
+ send(data: unknown): void;
106
+ close(code?: number, reason?: string): void;
107
+ onopen?: ((event?: unknown) => void) | null;
108
+ onmessage?: ((event: { data: unknown }) => void) | null;
109
+ onerror?: ((event?: unknown) => void) | null;
110
+ onclose?: ((event?: unknown) => void) | null;
111
+ }
112
+
113
+ export interface RTMClientBaseOptions {
114
+ pid: number;
115
+ autoReconnect?: boolean;
116
+ connectionTimeout?: number;
117
+ requestTimeout?: number;
118
+ locale?: string;
119
+ clientVersion?: string;
120
+ authSec?: number;
121
+ authVer?: 2;
122
+ requestMetadata?: Record<string, unknown> | (() => Record<string, unknown>);
123
+ requestMetadataProvider?: () => Record<string, unknown>;
124
+ webSocketFactory?: (url: string) => RTMWebSocket;
125
+ attrs?: Record<string, string>;
126
+ tlvHeartbeatIdleMs?: number;
127
+ tlvHeartbeatTimeoutMs?: number;
128
+ pushDedupTtlMs?: number;
129
+ regressiveStrategy?: RTMRegressiveStrategy;
130
+ [key: string]: unknown;
131
+ }
132
+
133
+ /** Protocol is FPNN by default; TLV requires an explicit protocol. Legacy WebSocket URL aliases remain supported for TLV. */
134
+ export type RTMClientOptions = RTMClientBaseOptions & (
135
+ | ({ protocol?: 'fpnn' } & (
136
+ { endpoint: string; ssl_endpoint?: string }
137
+ | { ssl_endpoint: string; endpoint?: string }
138
+ ))
139
+ | ({ protocol: 'tlv-v1' } & (
140
+ { tlvEndpoint: string; tlv_endpoint?: string }
141
+ | { tlvEndpoint?: string; tlv_endpoint: string }
142
+ | { endpoint: string; ssl_endpoint?: string }
143
+ | { ssl_endpoint: string; endpoint?: string }
144
+ ))
145
+ );
146
+
147
+ export class RTMClient {
148
+ constructor(options: RTMClientOptions & { compatibility?: never });
149
+ /** Promise facade for callback-based business request methods. */
150
+ readonly promises: RTMPromiseApi;
151
+ processor;
152
+ login(uid, token, callback, timeout);
153
+ destroy();
154
+ getServerTime(timeout, callback);
155
+ sendMessage(to, mtype, msg, attrs, mid, timeout, callback);
156
+ sendMessages(tos, mtype, msg, attrs, mid, timeout, callback);
157
+ sendGroupMessage(gid, mtype, msg, attrs, mid, timeout, callback);
158
+ sendRoomMessage(rid, mtype, msg, attrs, mid, timeout, callback);
159
+ getUnreadMessage(clear?: boolean, timeout?: number, callback?: (err: any, data: any) => void): void;
160
+ getUnreadMessage(clear: boolean | undefined, withLogout: boolean | undefined, timeout?: number, callback?: (err: any, data: any) => void): void;
161
+ getUnreadMessage(clear: boolean | undefined, withLogout: boolean | undefined, callback?: (err: any, data: any) => void): void;
162
+ getP2PUnreadMessageNum(uids, mtime, mtypes, timeout, callback);
163
+ getGroupUnreadMessageNum(gids, mtime, mtypes, timeout, callback);
164
+ cleanUnreadMessage(timeout, callback);
165
+ setSessionRead(category, xid, readSeq, timeout, callback);
166
+ getSession(timeout, callback);
167
+ getGroupMessage(gid, desc, num, begin, end, lastid, mtypes, timeout, callback);
168
+ getRoomMessage(rid, desc, num, begin, end, lastid, mtypes, timeout, callback);
169
+ getBroadcastMessage(desc, num, begin, end, lastid, mtypes, timeout, callback);
170
+ getP2PMessage(ouid, desc, num, begin, end, lastid, mtypes, timeout, callback);
171
+ getP2PMessageByMessageId(ouid, mid, desc, num, begin, end, mtypes, timeout, callback);
172
+ getGroupMessageByMessageId(gid, mid, desc, num, begin, end, mtypes, timeout, callback);
173
+ getRoomMessageByMessageId(rid, mid, desc, num, begin, end, mtypes, timeout, callback);
174
+ getBroadcastMessageByMessageId(mid, desc, num, begin, end, mtypes, timeout, callback);
175
+ getP2PMessageCount(ouid, begin, end, mtypes, timeout, callback);
176
+ getGroupMessageCount(gid, begin, end, mtypes, timeout, callback);
177
+ getRoomMessageCount(rid, begin, end, mtypes, timeout, callback);
178
+ getBroadcastMessageCount(begin, end, mtypes, timeout, callback);
179
+ fileToken(cmd, tos, to, rid, gid, timeout, callback);
180
+ close();
181
+ startAutoReconnect();
182
+ bye(callback?: (err?: Error | null, data?: any) => void): void;
183
+ bye(timeout?: number, callback?: (err?: Error | null, data?: any) => void): void;
184
+ addAttrs(attrs, timeout, callback);
185
+ getAttrs(timeout, callback);
186
+ addDebugLog(msg, attrs, timeout, callback);
187
+ addDevice(apptype, devicetoken, timeout, callback);
188
+ removeDevice(devicetoken, timeout, callback);
189
+ setTranslationLanguage(targetLanguage, timeout, callback);
190
+ translate(originalMessage, originalLanguage, targetLanguage, type, profanity, timeout, callback);
191
+ profanity(text, classify, timeout, callback);
192
+ textCheck(text, strategyId, timeout, callback);
193
+ textCheck(text: any, timeout?: number, callback?: (err: any, data: any) => void): void;
194
+ imageCheck(image, type, strategyId, timeout, callback);
195
+ audioCheck(audio, type, lang, codec, srate, strategyId, timeout, callback);
196
+ videoCheck(video, type, videoName, strategyId, timeout, callback);
197
+ speech2Text(audio, type, lang, codec, srate, timeout, callback);
198
+ getGroupsOpenInfo(gids, timeout, callback);
199
+ getRoomsOpenInfo(rids, timeout, callback);
200
+ getRoomMembers(rid, timeout, callback);
201
+ getRoomCount(rids, timeout, callback);
202
+ addDevicePushOption(type, xid, mtypes, timeout, callback);
203
+ removeDevicePushOption(type, xid, mtypes, timeout, callback);
204
+ getDevicePushOption(timeout, callback);
205
+ addFriends(friends, timeout, callback);
206
+ deleteFriends(friends, timeout, callback);
207
+ getFriends(timeout, callback);
208
+ addGroupMembers(gid, uids, timeout, callback);
209
+ deleteGroupMembers(gid, uids, timeout, callback);
210
+ getGroupMembers(gid, online, timeout, callback);
211
+ getGroupCount(gid, online, timeout, callback);
212
+ getUserGroups(timeout, callback);
213
+ enterRoom(rid, timeout, callback);
214
+ enterRooms(rids, timeout, callback);
215
+ leaveRoom(rid, timeout, callback);
216
+ getUserRooms(timeout, callback);
217
+ getUserRoomsAndLastMessage(mtypes, timeout, callback);
218
+ getOnlineUsers(uids, timeout, callback);
219
+ deleteMessage(from, mid, xid, type, timeout, callback);
220
+ getMessage(from, mid, xid, type, timeout, callback);
221
+ sendChat(to, msg, attrs, mid, timeout, callback);
222
+ sendAudio(to, msg, attrs, mid, timeout, callback);
223
+ sendCmd(to, msg, attrs, mid, timeout, callback);
224
+ sendGroupChat(gid, msg, attrs, mid, timeout, callback);
225
+ sendGroupAudio(gid, msg, attrs, mid, timeout, callback);
226
+ sendGroupCmd(gid, msg, attrs, mid, timeout, callback);
227
+ sendRoomChat(rid, msg, attrs, mid, timeout, callback);
228
+ sendRoomAudio(rid, msg, attrs, mid, timeout, callback);
229
+ sendRoomCmd(rid, msg, attrs, mid, timeout, callback);
230
+ getGroupChat(gid, desc, num, begin, end, lastid, timeout, callback);
231
+ getRoomChat(rid, desc, num, begin, end, lastid, timeout, callback);
232
+ getP2PChat(ouid, desc, num, begin, end, lastid, timeout, callback);
233
+ getBroadcastChat(desc, num, begin, end, lastid, timeout, callback);
234
+ deleteChat(from, mid, xid, type, timeout, callback);
235
+ getChat(from, mid, xid, type, timeout, callback);
236
+ setUserInfo(oinfo, pinfo, timeout, callback);
237
+ getUserInfo(timeout, callback);
238
+ getUserOpenInfo(uids, timeout, callback);
239
+ setGroupInfo(gid, oinfo, pinfo, timeout, callback);
240
+ getGroupInfo(gid, timeout, callback);
241
+ getGroupOpenInfo(gid, timeout, callback);
242
+ setRoomInfo(rid, oinfo, pinfo, timeout, callback);
243
+ setRoomProfile(rid, publicData, privateData, label, avatar, timeout, callback);
244
+ getRoomInfo(rid, timeout, callback);
245
+ getRoomOpenInfo(rid, timeout, callback);
246
+ dataGet(key, timeout, callback);
247
+ dataSet(key, value, timeout, callback);
248
+ dataDelete(key, timeout, callback);
249
+ addBlacks(blacks, timeout, callback);
250
+ deleteBlacks(blacks, timeout, callback);
251
+ getBlacks(timeout, callback);
252
+ sendFile(mtype, to, file, mid, timeout, callback);
253
+ sendGroupFile(mtype, gid, file, mid, timeout, callback);
254
+ sendRoomFile(mtype, rid, file, mid, timeout, callback);
255
+ getP2PConversationList(mtime, mtypes, timeout, callback);
256
+ getP2PUnreadConversationList(mtime, mtypes, timeout, callback);
257
+ getGroupConversationList(mtime, mtypes, timeout, callback);
258
+ getGroupUnreadConversationList(mtime, mtypes, timeout, callback);
259
+ getUnreadConversationList(clear, mtime, mtypes, timeout, callback);
260
+ removeSession(to: RTMId, timeout?: number, callback?: (err: any, data: any) => void): void;
261
+ removeSession(to: RTMId, localOnly: boolean | undefined, timeout?: number, callback?: (err: any, data: any) => void): void;
262
+ removeSession(to: RTMId, localOnly: boolean | undefined, callback?: (err: any, data: any) => void): void;
263
+ on(type, callback);
264
+ emit();
265
+ listenerCount(type: string): number;
266
+ removeEvent();
267
+ }
268
+
269
+ export interface RTMSharedWorkerBaseClientOptions {
270
+ pid: number;
271
+ maxPingIntervalSeconds?: number;
272
+ autoReconnect?: boolean;
273
+ connectionTimeout?: number;
274
+ requestTimeout?: number;
275
+ /** Static TLV metadata; only trace and sent_ms are sent on the wire. */
276
+ requestMetadata?: Record<string, unknown>;
277
+ locale?: string;
278
+ clientVersion?: string;
279
+ authSec?: number;
280
+ authVer?: 2;
281
+ attrs?: Record<string, string>;
282
+ tlvHeartbeatIdleMs?: number;
283
+ tlvHeartbeatTimeoutMs?: number;
284
+ pushDedupTtlMs?: number;
285
+ regressiveStrategy?: RTMRegressiveStrategy;
286
+ }
287
+
288
+ /** Defaults to FPNN; use protocol: 'tlv-v1' to opt into TLV. Functions cannot cross the Worker boundary. */
289
+ export type RTMSharedWorkerClientOptions = RTMSharedWorkerBaseClientOptions & (
290
+ ({ protocol?: 'fpnn' } & (
291
+ { endpoint: string; ssl_endpoint?: string } | { ssl_endpoint: string; endpoint?: string }
292
+ ))
293
+ | ({ protocol: 'tlv-v1' } & (
294
+ { tlvEndpoint: string; tlv_endpoint?: string }
295
+ | { tlvEndpoint?: string; tlv_endpoint: string }
296
+ | { endpoint: string; ssl_endpoint?: string }
297
+ | { ssl_endpoint: string; endpoint?: string }
298
+ ))
299
+ );
300
+
301
+ export type RTMConversationType = 'direct' | 'group' | 'room';
302
+
303
+ export interface RTMConversation {
304
+ type: RTMConversationType;
305
+ /** Use a decimal string for IDs larger than Number.MAX_SAFE_INTEGER. */
306
+ id: string | number | { toString(): string };
307
+ }
308
+
309
+ export interface RTMSharedWorkerOptions {
310
+ /** Optional same-origin override. Package ESM entries and bundler adapters provide a default; classic scripts infer the Worker beside the SDK script. */
311
+ workerUrl?: string;
312
+ /** Explicit stable name. When omitted and uid is provided, the SDK derives one from protocol, pid, uid, endpoint, and workerNamespace. */
313
+ workerName?: string;
314
+ /** UID used only to derive workerName when workerName is omitted; it does not log in automatically. */
315
+ uid?: RTMId;
316
+ /** Optional application/environment scope included in the derived workerName. */
317
+ workerNamespace?: string;
318
+ /** Maximum time to wait for the SharedWorker init response; defaults to 10000 ms. */
319
+ readyTimeout?: number;
320
+ /** Close and release the RTC session after the last page detaches; defaults to 5000 ms. Use 0 to close immediately. All tabs sharing a Worker must use the same value. */
321
+ idleShutdownTimeout?: number;
322
+ /** Structured-cloneable SDK options. Capabilities follow RTMClient, including FPNN file uploads. */
323
+ clientOptions: RTMSharedWorkerClientOptions;
324
+ /** Optional page-side event filter. The Worker broadcasts all SDK events; omitted means no filtering. */
325
+ conversation?: RTMConversation | null;
326
+ }
327
+
328
+ /** Flat createClient options. Unlike RTMSharedWorkerClient, createClient accepts the full RTMClient runtime config and falls back to a page-local client when a value cannot be preserved across Worker messaging. */
329
+ export interface RTMFactoryCompatibilityOptions {
330
+ /** Page-side API contract adapter. It does not affect SharedWorker identity or the selected wire protocol. */
331
+ compatibility?: RTMCompatibility;
332
+ }
333
+
334
+ /** Flat client options. Sharing is preferred by default; protocol defaults to FPNN in both modes. */
335
+ export type RTMSharedCreateClientOptions = RTMClientOptions &
336
+ Omit<RTMSharedWorkerOptions, 'clientOptions'> & { sharing?: true } & RTMFactoryCompatibilityOptions;
337
+ export type RTMIndependentCreateClientOptions = RTMClientOptions &
338
+ Omit<RTMSharedWorkerOptions, 'clientOptions'> & { sharing: false } & RTMFactoryCompatibilityOptions;
339
+ export type RTMCreateClientOptions = RTMSharedCreateClientOptions | RTMIndependentCreateClientOptions;
340
+
341
+ export interface RTMConnectionInfo {
342
+ /** `shared` uses the SharedWorker backend; `direct` uses an RTMClient in this page. */
343
+ mode: 'shared' | 'direct';
344
+ /** Null when direct mode was explicitly requested or no fallback was needed. */
345
+ fallbackReason: string | null;
346
+ }
347
+
348
+ export interface RTMConnectionInfoProvider {
349
+ /** Reports the selected backend and the reason createClient fell back to direct mode, if any. */
350
+ getConnectionInfo(): RTMConnectionInfo;
351
+ }
352
+
353
+ /** createClient facade for either backend. The Worker attaches on login, or immediately when options.uid is set. */
354
+ export interface RTMDefaultClient extends Omit<RTMSharedWorkerClient, 'promises' | 'login' | 'whenReady'>, RTMConnectionInfoProvider {
355
+ readonly promises: RTMDefaultPromiseApi;
356
+ on(type: 'SharedWorkerReady' | 'SharedSessionState', callback: (session: RTMSharedSessionSnapshot) => void): this;
357
+ on(type: string, callback: (...args: any[]) => void): this;
358
+ off(type: string, callback?: (...args: any[]) => void): this;
359
+ removeEvent(type?: string, callback?: (...args: any[]) => void): this;
360
+ setConversation(conversation: RTMConversation | null, callback?: (error?: Error | null) => void): this;
361
+ /** All callback failures use (false, numericCode); local/Worker details are emitted as SharedWorkerError. */
362
+ login(uid: RTMId, credential?: string, callback?: (accepted: boolean, errorCode?: number) => void, timeout?: number): void;
363
+ /** Requires a UID from options.uid, login(), or this argument. Never waits for an unspecified UID. */
364
+ whenReady(uid?: RTMId): Promise<RTMSharedSessionSnapshot>;
365
+ emit(type: string, ...args: any[]): void;
366
+ }
367
+
368
+ type RTMLegacyFpnnOnlyMethods = 'fileToken' | 'sendFile' | 'sendGroupFile' | 'sendRoomFile'
369
+ | 'addDevice' | 'removeDevice' | 'addDevicePushOption' | 'removeDevicePushOption' | 'getDevicePushOption'
370
+ | 'addFriends' | 'deleteFriends' | 'getFriends'
371
+ | 'profanity' | 'imageCheck' | 'audioCheck' | 'videoCheck' | 'speech2Text';
372
+ type RTMLegacySendMethodNames = 'sendMessage' | 'sendMessages' | 'sendGroupMessage' | 'sendRoomMessage'
373
+ | 'sendChat' | 'sendAudio' | 'sendCmd' | 'sendGroupChat' | 'sendGroupAudio' | 'sendGroupCmd'
374
+ | 'sendRoomChat' | 'sendRoomAudio' | 'sendRoomCmd';
375
+ type RTMLegacySendCallback = (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void;
376
+ type RTMLegacyPromiseSendApi<TMessage> = {
377
+ sendMessage(to: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
378
+ sendMessages(tos: RTMId[], mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
379
+ sendGroupMessage(gid: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
380
+ sendRoomMessage(rid: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
381
+ sendChat(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
382
+ sendAudio(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
383
+ sendCmd(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
384
+ sendGroupChat(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
385
+ sendGroupAudio(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
386
+ sendGroupCmd(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
387
+ sendRoomChat(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
388
+ sendRoomAudio(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
389
+ sendRoomCmd(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
390
+ };
391
+ type RTMLegacyCallbackSendApi<TMessage> = {
392
+ sendMessage(to: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
393
+ sendMessages(tos: RTMId[], mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
394
+ sendGroupMessage(gid: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
395
+ sendRoomMessage(rid: RTMId, mtype: number, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
396
+ sendChat(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
397
+ sendAudio(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
398
+ sendCmd(to: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
399
+ sendGroupChat(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
400
+ sendGroupAudio(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
401
+ sendGroupCmd(gid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
402
+ sendRoomChat(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
403
+ sendRoomAudio(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
404
+ sendRoomCmd(rid: RTMId, msg: TMessage, attrs: string, mid?: RTMId, timeout?: number, callback?: RTMLegacySendCallback): void;
405
+ };
406
+
407
+ export type RTMLegacyPromiseApi = Omit<RTMDefaultPromiseApi,
408
+ RTMLegacySendMethodNames | 'sendFile' | 'sendGroupFile' | 'sendRoomFile'
409
+ | RTMLegacyFpnnOnlyMethods
410
+ | 'getP2PMessage' | 'getGroupMessage' | 'getRoomMessage' | 'getBroadcastMessage'
411
+ | 'getP2PChat' | 'getGroupChat' | 'getRoomChat' | 'getBroadcastChat'
412
+ | 'getUnreadMessage' | 'removeSession'> & {
413
+ sendMessage(to: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
414
+ sendMessages(tos: RTMId[], mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
415
+ sendGroupMessage(gid: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
416
+ sendRoomMessage(rid: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
417
+ sendChat(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
418
+ sendAudio(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
419
+ sendCmd(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
420
+ sendGroupChat(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
421
+ sendGroupAudio(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
422
+ sendGroupCmd(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
423
+ sendRoomChat(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
424
+ sendRoomAudio(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
425
+ sendRoomCmd(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number): Promise<RTMLegacySendResult>;
426
+ getP2PMessage(ouid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<RTMLegacyHistoryResponse>;
427
+ getGroupMessage(gid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<RTMLegacyHistoryResponse>;
428
+ getRoomMessage(rid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<RTMLegacyHistoryResponse>;
429
+ getBroadcastMessage(desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number): Promise<RTMLegacyHistoryResponse>;
430
+ getP2PChat(ouid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number): Promise<RTMLegacyHistoryResponse>;
431
+ getGroupChat(gid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number): Promise<RTMLegacyHistoryResponse>;
432
+ getRoomChat(rid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number): Promise<RTMLegacyHistoryResponse>;
433
+ getBroadcastChat(desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number): Promise<RTMLegacyHistoryResponse>;
434
+ getUnreadMessage(clear?: boolean, withLogoutOrTimeout?: boolean | number, timeout?: number): Promise<Record<string, unknown>>;
435
+ removeSession(to: RTMId, localOnlyOrTimeout?: boolean | number, timeout?: number): Promise<unknown>;
436
+ };
437
+
438
+ interface RTMLegacyProcessorControls {
439
+ off(type: string, callback?: (...args: any[]) => void): this;
440
+ removeEvent(type?: string, callback?: (...args: any[]) => void): this;
441
+ emit(type: string, ...args: any[]): void;
442
+ listenerCount(type: string): number;
443
+ }
444
+
445
+ type RTMLegacyPushEvent = 'pushmsg' | 'pushgroupmsg' | 'pushroommsg' | 'pushbroadcastmsg'
446
+ | 'pushfile' | 'pushgroupfile' | 'pushroomfile' | 'pushbroadcastfile'
447
+ | 'pushchat' | 'pushcmd' | 'pushgroupchat' | 'pushgroupcmd'
448
+ | 'pushroomchat' | 'pushroomcmd' | 'pushbroadcastchat' | 'pushbroadcastcmd';
449
+ type RTMLegacyPushCallback = (message: RTMLegacyPushMessage) => void;
450
+
451
+ /** Push events shared by the legacy FPNN and TLV compatibility surfaces. */
452
+ export interface RTMLegacyProcessor extends RTMLegacyProcessorControls {
453
+ on(type: RTMLegacyPushEvent, callback: RTMLegacyPushCallback): this;
454
+ on(type: 'kickout' | 'kickoutroom', callback: (message: { rid?: RTMId }) => void): this;
455
+ }
456
+
457
+ /** TLV legacy compatibility additionally emits local adapter diagnostics, but rejects raw TLV/ping/audio-only subscriptions. */
458
+ export interface RTMLegacyTlvProcessor extends RTMLegacyProcessorControls {
459
+ on(type: RTMLegacyPushEvent, callback: RTMLegacyPushCallback): this;
460
+ on(type: 'kickout' | 'kickoutroom', callback: (message: { rid?: RTMId }) => void): this;
461
+ on(type: 'CompatibilityError', callback: (error: RTMCompatibilityError) => void): this;
462
+ }
463
+
464
+ /** FPNN legacy compatibility retains its native ping event. */
465
+ export interface RTMLegacyFpnnProcessor extends RTMLegacyProcessorControls {
466
+ on(type: RTMLegacyPushEvent, callback: RTMLegacyPushCallback): this;
467
+ on(type: 'kickout' | 'kickoutroom', callback: (message: { rid?: RTMId }) => void): this;
468
+ on(type: 'ping', callback: (message: unknown) => void): this;
469
+ }
470
+
471
+ export type RTMLegacyDefaultClient = Omit<RTMDefaultClient,
472
+ 'promises' | 'processor' | RTMLegacySendMethodNames | 'sendFile' | 'sendGroupFile' | 'sendRoomFile'
473
+ | RTMLegacyFpnnOnlyMethods
474
+ | 'getP2PMessage' | 'getGroupMessage' | 'getRoomMessage' | 'getBroadcastMessage'
475
+ | 'getP2PChat' | 'getGroupChat' | 'getRoomChat' | 'getBroadcastChat'
476
+ | 'getUnreadMessage' | 'removeSession'> & {
477
+ readonly promises: RTMLegacyPromiseApi;
478
+ processor: RTMLegacyTlvProcessor;
479
+ sendMessage(to: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
480
+ sendMessages(tos: RTMId[], mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
481
+ sendGroupMessage(gid: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
482
+ sendRoomMessage(rid: RTMId, mtype: number, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
483
+ sendChat(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
484
+ sendAudio(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
485
+ sendCmd(to: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
486
+ sendGroupChat(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
487
+ sendGroupAudio(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
488
+ sendGroupCmd(gid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
489
+ sendRoomChat(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
490
+ sendRoomAudio(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
491
+ sendRoomCmd(rid: RTMId, msg: RTMLegacyTlvMessagePayload, attrs: string, mid?: RTMId, timeout?: number, callback?: (error: RTMLegacySendError | Error | null, result: RTMLegacySendResult | null) => void): void;
492
+ getP2PMessage(ouid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
493
+ getGroupMessage(gid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
494
+ getRoomMessage(rid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
495
+ getBroadcastMessage(desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, mtypes?: number[], timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
496
+ getP2PChat(ouid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
497
+ getGroupChat(gid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
498
+ getRoomChat(rid: RTMId, desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
499
+ getBroadcastChat(desc?: boolean, num?: number, begin?: RTMId, end?: RTMId, lastid?: RTMId, timeout?: number, callback?: (error: Error | null, data: RTMLegacyHistoryResponse | null) => void): void;
500
+ getUnreadMessage(clear?: boolean, withLogoutOrTimeout?: boolean | number, timeoutOrCallback?: number | ((error: Error | null, data: Record<string, unknown> | null) => void), callback?: (error: Error | null, data: Record<string, unknown> | null) => void): void;
501
+ removeSession(to: RTMId, localOnlyOrTimeout?: boolean | number, timeoutOrCallback?: number | ((error: Error | null, data: unknown) => void), callback?: (error: Error | null, data: unknown) => void): void;
502
+ };
503
+
504
+ export type RTMLegacyFpnnPromiseApi = Omit<RTMLegacyPromiseApi, RTMLegacySendMethodNames>
505
+ & RTMLegacyPromiseSendApi<RTMLegacyMessagePayload>
506
+ & Pick<RTMDefaultPromiseApi, RTMLegacyFpnnOnlyMethods>;
507
+ /** FPNN supports all legacy RTM methods; TLV legacy compatibility omits the FPNN-only methods. */
508
+ export type RTMLegacyFpnnDefaultClient = Omit<RTMLegacyDefaultClient, 'promises' | 'processor' | RTMLegacySendMethodNames>
509
+ & Pick<RTMDefaultClient, RTMLegacyFpnnOnlyMethods>
510
+ & { readonly promises: RTMLegacyFpnnPromiseApi; processor: RTMLegacyFpnnProcessor }
511
+ & RTMLegacyCallbackSendApi<RTMLegacyMessagePayload>;
512
+
513
+ /** FPNN already follows the old RTM public contract; this does not apply a second conversion. */
514
+ export function createClient(options: RTMCreateClientOptions & { protocol?: 'fpnn'; compatibility: 'legacy-rtm' }): RTMLegacyFpnnDefaultClient;
515
+ /** TLV maps its native request/Push contract to the old RTM page API. */
516
+ export function createClient(options: RTMCreateClientOptions & { protocol: 'tlv-v1'; compatibility: 'legacy-rtm' }): RTMLegacyDefaultClient;
517
+ /** A runtime-selected protocol exposes only the common legacy surface. */
518
+ export function createClient(options: RTMCreateClientOptions & { compatibility: 'legacy-rtm' }): RTMLegacyFpnnDefaultClient | RTMLegacyDefaultClient;
519
+ export function createClient(options: RTMCreateClientOptions & { compatibility: 'native' }): RTMDefaultClient;
520
+ export function createClient(options: RTMCreateClientOptions & { compatibility: RTMCompatibility }): RTMDefaultClient | RTMLegacyFpnnDefaultClient | RTMLegacyDefaultClient;
521
+ export function createClient(options: RTMIndependentCreateClientOptions): RTMDefaultClient;
522
+ export function createClient(options: RTMSharedCreateClientOptions): RTMDefaultClient;
523
+ export function createClient(options?: RTMCreateClientOptions): RTMDefaultClient;
524
+
525
+ export interface RTMSharedSessionSnapshot {
526
+ status: 'idle' | 'connecting' | 'authenticated';
527
+ /** Decimal UID string for the shared session; null while idle. */
528
+ uid: string | null;
529
+ }
530
+
531
+ export interface RTMSharedLoginResult {
532
+ accepted: boolean;
533
+ errorCode: number;
534
+ /** True when this call reused an authenticated session or joined its login attempt. */
535
+ reused: boolean;
536
+ /** Decimal UID of the resulting or conflicting shared session. */
537
+ uid: string | null;
538
+ }
539
+
540
+ interface RTMSharedProcessor {
541
+ on(type: string, callback: (...args: any[]) => void): this;
542
+ off(type: string, callback?: (...args: any[]) => void): this;
543
+ removeEvent(type?: string, callback?: (...args: any[]) => void): this;
544
+ emit(type: string, ...args: any[]): void;
545
+ listenerCount(type: string): number;
546
+ }
547
+
548
+ export class RTMSharedWorkerClient {
549
+ constructor(options: RTMSharedWorkerOptions & { compatibility?: never });
550
+ /** Creates a stable protocol/project/UID/environment name; endpoint and namespace isolate different environments. */
551
+ static createWorkerName(identity: RTMSharedWorkerIdentity): string;
552
+ /** Promise facade for callback-based business request methods. */
553
+ readonly promises: RTMSharedWorkerPromiseApi;
554
+ processor: RTMSharedProcessor;
555
+ /** Resolves with the initial snapshot after this page attaches. Use getSharedSession() for current state. */
556
+ whenReady(): Promise<RTMSharedSessionSnapshot>;
557
+ /** Returns the latest session snapshot observed by this page. */
558
+ getSharedSession(): RTMSharedSessionSnapshot;
559
+ /** Reuses/joins a same-UID login; credential is required only when the shared session is idle. */
560
+ loginIfNeeded(uid: string | number | { toString(): string }, credential?: string, timeout?: number): Promise<RTMSharedLoginResult>;
561
+ /** Receives the current snapshot on ready and whenever a shared tab's login state changes. */
562
+ on(type: 'SharedWorkerReady' | 'SharedSessionState', callback: (session: RTMSharedSessionSnapshot) => void): this;
563
+ on(type: string, callback: (...args: any[]) => void): this;
564
+ off(type: string, callback?: (...args: any[]) => void): this;
565
+ removeEvent(type?: string, callback?: (...args: any[]) => void): this;
566
+ emit(type: string, ...args: any[]): void;
567
+ listenerCount(type: string): number;
568
+ /** Filter this page's listeners locally; the Worker broadcasts all events. Pass null to disable filtering. */
569
+ setConversation(conversation: RTMConversation | null, callback?: (error?: Error | null) => void): this;
570
+ /** Detaches this page; also called automatically on pagehide (except BFCache). It does not close the shared connection. */
571
+ destroy(): void;
572
+ }
573
+
574
+ export interface RTMSharedWorkerIdentity {
575
+ /** Defaults to fpnn. TLV names are isolated from FPNN names. */
576
+ protocol?: RTMProtocol;
577
+ pid: string | number;
578
+ uid: RTMId;
579
+ /** Optional explicit environment isolation; omitted in default client identities. */
580
+ endpoint?: string;
581
+ namespace?: string;
582
+ }
583
+
584
+ export function createSharedWorkerName(identity: RTMSharedWorkerIdentity): string;
585
+
586
+ type RTMSharedWorkerClientMethods = Pick<RTMClient, Exclude<keyof RTMClient,
587
+ 'emit' | 'promises'>>;
588
+
589
+ export interface RTMSharedWorkerClient extends RTMSharedWorkerClientMethods {}
590
+
591
+ export class RTMConfig {
592
+ static ERROR_CODE;
593
+ static Int64;
594
+ static Uint64;
595
+ static MsgPack;
596
+ static FILE_TYPE;
597
+ static CHAT_TYPE;
598
+ static SERVER_PUSH;
599
+ static TLV_SERVER_PUSH;
600
+ static MID_TTL;
601
+ static API_VERSION;
602
+ static SDK_VERSION;
603
+ static MAX_PING_SECONDS;
604
+ }
605
+
606
+ export class RTMProcessor {
607
+ constructor();
608
+ service(data, cb);
609
+ destroy();
610
+ kickout(data);
611
+ kickoutroom(data);
612
+ pushmsg(data);
613
+ pushgroupmsg(data);
614
+ pushroommsg(data);
615
+ pushbroadcastmsg(data);
616
+ ping(data);
617
+ on(type, callback);
618
+ emit();
619
+ removeEvent();
620
+ }
621
+
622
+ export class TLVCodec {
623
+ static encodeFrame(sequence, mt, uri, payload);
624
+ static decodeFrame(frame);
625
+ }
626
+
627
+ export class TLVWebSocketClient {
628
+ constructor(options);
629
+ connect();
630
+ close();
631
+ destroy();
632
+ markAuthenticated();
633
+ sendQuest(options, callback, timeout);
634
+ on(type, callback);
635
+ off(type, callback);
636
+ }
637
+ }
638
+
639
+ export = rtm;