@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.6 → 1.0.0-cg.7
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 +21 -11
- package/dist/rtm.d.cts +3 -0
- package/dist/rtm.d.mts +40 -0
- package/dist/rtm.d.ts +51 -23
- package/dist/rtm.min.js +5 -5
- package/dist/rtm.mjs +17 -0
- package/dist/rtm.shared-worker.js +6 -6
- package/dist/rtm.vite-plugin.d.mts +8 -0
- package/dist/rtm.vite-plugin.mjs +23 -0
- package/dist/rtm.vite.d.ts +27 -0
- package/dist/rtm.vite.mjs +13 -15
- package/dist/rtm.webpack4-adapter.cjs +29 -0
- package/dist/rtm.webpack4-plugin.cjs +50 -0
- package/dist/rtm.webpack4-plugin.d.cts +5 -0
- package/docs/CAPABILITIES.md +8 -8
- package/docs/Chat.md +7 -5
- package/docs/Data.md +2 -0
- package/docs/EventProcess.md +2 -0
- package/docs/Files.md +2 -0
- package/docs/Friends.md +2 -0
- package/docs/Groups.md +2 -0
- package/docs/Messages.md +4 -1
- package/docs/NPM_MODERNIZATION_PLAN.md +474 -0
- package/docs/PROTOCOL_MIGRATION.md +6 -5
- package/docs/RTM_MIGRATION.md +205 -0
- package/docs/Rooms.md +2 -0
- package/docs/System.md +2 -0
- package/docs/USAGE.md +70 -27
- package/docs/Users.md +2 -0
- package/docs/ValueAdded.md +10 -4
- package/package.json +29 -7
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ RTC WebSocket Client SDK。新接入建议使用 `protocol: 'tlv-v1'`;`fpnn`
|
|
|
8
8
|
npm install @cg-devcenter/rtc-fpnn-webjs-sdk@latest
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
包根 ESM 入口和 `/vite-plugin` 是本次仓库改造内容,目前尚未发布到 npm。发布前可在仓库执行 `npm run build`,并用 Vue 3 Demo 的 `npm run sdk:local` 链接本地包;发布状态见 [实现与验证记录](docs/NPM_MODERNIZATION_PLAN.md)。
|
|
12
|
+
|
|
13
|
+
## 本地构建
|
|
14
|
+
|
|
15
|
+
从源码构建或打包 SDK 需要 Node.js 18 或更高版本(`esbuild` 的构建工具要求);这是仓库维护和发包环境要求,不会提高浏览器 SDK 使用方的 Node.js 运行时要求。运行 `npm run build` 会生成 UMD、SharedWorker、ESM、Vite/Webpack 插件和类型声明产物。
|
|
16
|
+
|
|
11
17
|
浏览器可加载 `dist/rtm.min.js` 并从 `window.rtm` 使用;CommonJS:
|
|
12
18
|
|
|
13
19
|
```js
|
|
@@ -20,10 +26,10 @@ Node.js 使用 TLV v1 时,需自行提供 `webSocketFactory(url)`。SDK 不携
|
|
|
20
26
|
|
|
21
27
|
### 默认共享入口
|
|
22
28
|
|
|
23
|
-
`createClient()`
|
|
29
|
+
`createClient()` 在浏览器支持 SharedWorker 时默认共享连接;不支持时自动使用当前页面的独立连接。省略 `protocol` 时默认使用 FPNN,以兼容旧 `RTMClient` 接入。新项目使用 TLV 时请显式设置 `protocol: 'tlv-v1'`。支持共享的环境中,SDK 自动按 PID、协议、UID 和 Gate 地址隔离会话;同一环境的页面自动复用,业务无需配置 Worker 名称或路径。UID 可直接从 `login()` 获取。
|
|
24
30
|
|
|
25
31
|
```js
|
|
26
|
-
const client = rtm.createClient({ pid, tlvEndpoint: endpoint });
|
|
32
|
+
const client = rtm.createClient({ protocol: 'tlv-v1', pid, tlvEndpoint: endpoint });
|
|
27
33
|
client.processor.on(rtm.RTMConfig.TLV_SERVER_PUSH.recvMessage, renderMessage);
|
|
28
34
|
await client.promises.login(uid, credential); // 同 UID 已登录时 credential 可省略
|
|
29
35
|
await client.promises.sendChat(peerUid, 'hello', '{}');
|
|
@@ -31,7 +37,7 @@ await client.promises.sendChat(peerUid, 'hello', '{}');
|
|
|
31
37
|
client.destroy();
|
|
32
38
|
```
|
|
33
39
|
|
|
34
|
-
片段中的 `rtm`、项目参数、credential 和 `renderMessage` 由应用提供;完整流程和能力边界见 [默认共享接入](docs/USAGE.md#默认共享接入当前源码)
|
|
40
|
+
片段中的 `rtm`、项目参数、credential 和 `renderMessage` 由应用提供;完整流程和能力边界见 [默认共享接入](docs/USAGE.md#默认共享接入当前源码)。从旧 `new RTMClient()` 迁移且继续使用 FPNN 时,可将构造器替换为 `createClient()` 并沿用 `endpoint` 配置;工厂默认协议为 FPNN。在浏览器支持 SharedWorker 时自动共享,不支持时自动使用独立连接;显式设置 `sharing: false` 也会使用独立连接。现代 ESM 项目从包根导入;Vite 项目在配置中增加一次 `/vite-plugin` 插件,Worker 由构建流程打包。详见 [npm 接入现代化说明](docs/NPM_MODERNIZATION_PLAN.md)。
|
|
35
41
|
|
|
36
42
|
### 原有单连接入口
|
|
37
43
|
|
|
@@ -68,11 +74,17 @@ async function startChat(rtm, { pid, endpoint, uid, peerUid, credential }) {
|
|
|
68
74
|
|
|
69
75
|
## 同 UID 多窗口
|
|
70
76
|
|
|
71
|
-
需要同一浏览器内多个同源页面共用一个 UID 的 RTC 登录和 WebSocket 时,新接入推荐使用 SDK 的 `createClient()`
|
|
77
|
+
需要同一浏览器内多个同源页面共用一个 UID 的 RTC 登录和 WebSocket 时,新接入推荐使用 SDK 的 `createClient()` 默认共享入口。支持 SharedWorker 时,SDK 按 PID、协议、UID 和 Gate 地址确定共享会话,业务代码无需维护 Worker 配置;普通浏览器部署时将 `rtm.min.js` 和 `rtm.shared-worker.js` 放在同一同源目录即可。浏览器不支持 SharedWorker 时,`createClient()` 自动改用当前页面的独立连接,各页面不共享登录态。首次登录需要 credential;同 UID 后续页面在支持共享的环境中复用会话。完整说明见 [默认共享接入](docs/USAGE.md#默认共享接入当前源码)。
|
|
78
|
+
|
|
79
|
+
Vite 项目从 `@cg-devcenter/rtc-fpnn-webjs-sdk` 导入 ESM 入口,并在 Vite 配置中增加一次 `rtmSdkVitePlugin()`;Worker 由构建流程打包,业务无需填写路径。旧 `/vite` 导入仍保留兼容。若使用底层 `RTMSharedWorkerClient` 构造器,可通过 `uid` 自动生成 Worker 名称,或显式传入 `workerName`;`createClient()` 会按登录 UID 自动绑定,不要求手动设置名称。最后一个页面 detach 后默认 5 秒关闭共享连接。
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
常规接入不需要传 `workerUrl`:普通 HTML 将 `rtm.min.js` 与 `rtm.shared-worker.js` 放在同源同目录;Vite 项目配置上述插件;Webpack 4 项目配置 SDK 的 `/webpack4` 插件。Vue、React 或普通 JS 使用相同的 SDK API,Worker 配置取决于构建工具。只有自定义 Worker 部署位置时,才需要用 `workerUrl` 覆盖默认解析结果。详见[接入指南的 SharedWorker 章节](docs/USAGE.md#4-同-uid-多窗口sharedworker)。
|
|
74
82
|
|
|
75
|
-
SharedWorker
|
|
83
|
+
如果直接从 unpkg 或 jsDelivr 加载 UMD,默认 Worker URL 会指向 CDN,无法用于页面的 SharedWorker。请把同版本 Worker 放到应用同源目录并传入 `workerUrl`,或设置 `sharing: false`。详见[CDN 与 Worker 同源要求](docs/USAGE.md#引用与运行环境)。
|
|
84
|
+
|
|
85
|
+
`createClient()` 和直接构造 `RTMSharedWorkerClient` 都默认使用 FPNN;只有显式设置 `protocol: 'tlv-v1'` 才使用 TLV。登录共享和会话路由沿用同一套业务 API。用法与限制见 [FPNN 多窗口接入](docs/USAGE.md#fpnn-多窗口接入)。
|
|
86
|
+
|
|
87
|
+
SharedWorker 共享底层 SDK 实例和登录状态,业务 API 自动转发给 `RTMClient`,包括 FPNN 文件发送。Worker 原样广播 SDK 事件;`conversation` / `setConversation()` 只在页面端执行可选筛选。协议校验、上传、重连、ACK 和去重均由底层 SDK 处理。
|
|
76
88
|
|
|
77
89
|
仓库的演示页面可用以下命令启动:
|
|
78
90
|
|
|
@@ -81,11 +93,7 @@ npm run build
|
|
|
81
93
|
npm run demo:shared-worker
|
|
82
94
|
```
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
HTML 与 Vue 3 Demo 共用同一份框架无关的 RTC 工作流控制器,覆盖发送账号登录与发送、收件箱登录、历史、Push 路由、回复和重试。两者展示相同的核心 RTC 流程;页面适配、credential 签发器和本地模拟由各自 Demo 提供。Demo 不复制 SDK 的 SharedWorker 连接、登录态复用或 Push 分发逻辑。窗口内的消息列表、草稿和未读展示仍属于页面状态,不会由 SDK 跨窗口同步。文件结构和职责边界见 `examples/shared-worker-demo/README.md` 的职责边界章节(仅源码仓库)。
|
|
87
|
-
|
|
88
|
-
另有使用 Vue 3、Vite 和 npm 包导入方式的同功能示例;本次新入口需先通过 yalc 链接本地构建:`examples/vue3-shared-worker-demo/README.md`(仅源码仓库)。
|
|
96
|
+
HTML/JavaScript、Vue 3、Vue 2.7 和 React 的发送台与收件箱 Demo 见源码仓库 `examples/README.md`(仅源码仓库,不包含在 npm 包中)。该指南列出各框架的 SDK import、Vite 插件和启动方式。四种页面覆盖相同的发送账号、credential、收件箱、历史、Push 路由、回复、重试和本地模拟流程;Vue 3、Vue 2 与 React 共用同一框架适配层、RTC 工作流和样式,HTML 继续共用底层配置与控制器。Demo 不复制 SDK 的 SharedWorker 连接、登录态复用或 Push 分发逻辑。窗口内的消息列表、草稿和未读展示仍属于页面状态,不会由 SDK 跨窗口同步。详细职责见 `examples/shared-worker-demo/README.md`(仅源码仓库)。
|
|
89
97
|
|
|
90
98
|
## TLV v1 最小接入 Demo
|
|
91
99
|
|
|
@@ -94,6 +102,8 @@ HTML 与 Vue 3 Demo 共用同一份框架无关的 RTC 工作流控制器,覆
|
|
|
94
102
|
## 文档
|
|
95
103
|
|
|
96
104
|
- [接入指南与 API 参数](docs/USAGE.md)
|
|
105
|
+
- [从 GitHub 上游 SDK 迁移:新增 API、签名变化与兼容差异](docs/RTM_MIGRATION.md)
|
|
106
|
+
- [npm 接入现代化实施、验证与发布记录](docs/NPM_MODERNIZATION_PLAN.md)
|
|
97
107
|
- [FPNN 与 TLV v1 迁移对照](docs/PROTOCOL_MIGRATION.md)
|
|
98
108
|
- [能力总览与典型业务流程](docs/CAPABILITIES.md)
|
|
99
109
|
- [TLV v1 URI、请求字段与返回值](docs/TLV_CONTRACT.md)
|
package/dist/rtm.d.cts
ADDED
package/dist/rtm.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import rtm = require('./rtm');
|
|
2
|
+
|
|
3
|
+
declare const sdk: typeof rtm;
|
|
4
|
+
|
|
5
|
+
export default sdk;
|
|
6
|
+
export type RTMProtocol = rtm.RTMProtocol;
|
|
7
|
+
export type RTMId = rtm.RTMId;
|
|
8
|
+
export type RTMLoginPromiseResult = rtm.RTMLoginPromiseResult;
|
|
9
|
+
export type RTMPromiseApi = rtm.RTMPromiseApi;
|
|
10
|
+
export type RTMSharedWorkerPromiseApi = rtm.RTMSharedWorkerPromiseApi;
|
|
11
|
+
export type RTMDefaultPromiseApi = rtm.RTMDefaultPromiseApi;
|
|
12
|
+
export type RTMRegressiveStrategy = rtm.RTMRegressiveStrategy;
|
|
13
|
+
export type RTMClientBaseOptions = rtm.RTMClientBaseOptions;
|
|
14
|
+
export type RTMClientOptions = rtm.RTMClientOptions;
|
|
15
|
+
export type RTMSharedWorkerBaseClientOptions = rtm.RTMSharedWorkerBaseClientOptions;
|
|
16
|
+
export type RTMSharedWorkerClientOptions = rtm.RTMSharedWorkerClientOptions;
|
|
17
|
+
export type RTMConversationType = rtm.RTMConversationType;
|
|
18
|
+
export type RTMConversation = rtm.RTMConversation;
|
|
19
|
+
export type RTMSharedWorkerOptions = rtm.RTMSharedWorkerOptions;
|
|
20
|
+
export type RTMSharedCreateClientOptions = rtm.RTMSharedCreateClientOptions;
|
|
21
|
+
export type RTMIndependentCreateClientOptions = rtm.RTMIndependentCreateClientOptions;
|
|
22
|
+
export type RTMCreateClientOptions = rtm.RTMCreateClientOptions;
|
|
23
|
+
export type RTMDefaultClient = rtm.RTMDefaultClient;
|
|
24
|
+
export type RTMSharedSessionSnapshot = rtm.RTMSharedSessionSnapshot;
|
|
25
|
+
export type RTMSharedLoginResult = rtm.RTMSharedLoginResult;
|
|
26
|
+
export type RTMSharedWorkerIdentity = rtm.RTMSharedWorkerIdentity;
|
|
27
|
+
export type RTMClient = rtm.RTMClient;
|
|
28
|
+
export type RTMSharedWorkerClient = rtm.RTMSharedWorkerClient;
|
|
29
|
+
export type RTMConfig = rtm.RTMConfig;
|
|
30
|
+
export type RTMProcessor = rtm.RTMProcessor;
|
|
31
|
+
export type TLVCodec = rtm.TLVCodec;
|
|
32
|
+
export type TLVWebSocketClient = rtm.TLVWebSocketClient;
|
|
33
|
+
export const RTMClient: typeof rtm.RTMClient;
|
|
34
|
+
export const createClient: typeof rtm.createClient;
|
|
35
|
+
export const RTMSharedWorkerClient: typeof rtm.RTMSharedWorkerClient;
|
|
36
|
+
export const RTMConfig: typeof rtm.RTMConfig;
|
|
37
|
+
export const RTMProcessor: typeof rtm.RTMProcessor;
|
|
38
|
+
export const TLVCodec: typeof rtm.TLVCodec;
|
|
39
|
+
export const TLVWebSocketClient: typeof rtm.TLVWebSocketClient;
|
|
40
|
+
export const createSharedWorkerName: typeof rtm.createSharedWorkerName;
|
package/dist/rtm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export as namespace rtm;
|
|
2
2
|
|
|
3
3
|
declare namespace rtm {
|
|
4
|
-
type RTMProtocol = 'fpnn' | 'tlv-v1';
|
|
4
|
+
export type RTMProtocol = 'fpnn' | 'tlv-v1';
|
|
5
5
|
export type RTMId = string | number | { toString(): string };
|
|
6
6
|
|
|
7
7
|
export interface RTMLoginPromiseResult {
|
|
@@ -9,7 +9,7 @@ declare namespace rtm {
|
|
|
9
9
|
errorCode: number;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
type RTMPromiseExcludedMethod = 'close' | 'destroy' | 'emit' | 'off' | 'on'
|
|
12
|
+
type RTMPromiseExcludedMethod = 'close' | 'destroy' | 'emit' | 'listenerCount' | 'off' | 'on'
|
|
13
13
|
| 'removeEvent' | 'startAutoReconnect' | 'promises' | 'processor';
|
|
14
14
|
|
|
15
15
|
/** Promise versions of callback-based RTM requests. Parameters keep the original order, without callback. */
|
|
@@ -36,7 +36,7 @@ declare namespace rtm {
|
|
|
36
36
|
login(uid: RTMId, credential?: string, timeout?: number): Promise<RTMLoginPromiseResult>;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
interface RTMRegressiveStrategy {
|
|
39
|
+
export interface RTMRegressiveStrategy {
|
|
40
40
|
startConnectFailedCount: number;
|
|
41
41
|
maxIntervalSeconds: number;
|
|
42
42
|
linearRegressiveCount: number;
|
|
@@ -52,13 +52,8 @@ declare namespace rtm {
|
|
|
52
52
|
onclose?: ((event?: unknown) => void) | null;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
interface
|
|
55
|
+
export interface RTMClientBaseOptions {
|
|
56
56
|
pid: number;
|
|
57
|
-
protocol?: RTMProtocol;
|
|
58
|
-
endpoint?: string;
|
|
59
|
-
ssl_endpoint?: string;
|
|
60
|
-
tlvEndpoint?: string;
|
|
61
|
-
tlv_endpoint?: string;
|
|
62
57
|
autoReconnect?: boolean;
|
|
63
58
|
connectionTimeout?: number;
|
|
64
59
|
requestTimeout?: number;
|
|
@@ -77,6 +72,20 @@ declare namespace rtm {
|
|
|
77
72
|
[key: string]: unknown;
|
|
78
73
|
}
|
|
79
74
|
|
|
75
|
+
/** Protocol is FPNN by default; TLV requires an explicit protocol. Legacy WebSocket URL aliases remain supported for TLV. */
|
|
76
|
+
export type RTMClientOptions = RTMClientBaseOptions & (
|
|
77
|
+
| ({ protocol?: 'fpnn' } & (
|
|
78
|
+
{ endpoint: string; ssl_endpoint?: string }
|
|
79
|
+
| { ssl_endpoint: string; endpoint?: string }
|
|
80
|
+
))
|
|
81
|
+
| ({ protocol: 'tlv-v1' } & (
|
|
82
|
+
{ tlvEndpoint: string; tlv_endpoint?: string }
|
|
83
|
+
| { tlvEndpoint?: string; tlv_endpoint: string }
|
|
84
|
+
| { endpoint: string; ssl_endpoint?: string }
|
|
85
|
+
| { ssl_endpoint: string; endpoint?: string }
|
|
86
|
+
))
|
|
87
|
+
);
|
|
88
|
+
|
|
80
89
|
export class RTMClient {
|
|
81
90
|
constructor(options: RTMClientOptions);
|
|
82
91
|
/** Promise facade for callback-based business request methods. */
|
|
@@ -89,7 +98,9 @@ declare namespace rtm {
|
|
|
89
98
|
sendMessages(tos, mtype, msg, attrs, mid, timeout, callback);
|
|
90
99
|
sendGroupMessage(gid, mtype, msg, attrs, mid, timeout, callback);
|
|
91
100
|
sendRoomMessage(rid, mtype, msg, attrs, mid, timeout, callback);
|
|
92
|
-
getUnreadMessage(clear
|
|
101
|
+
getUnreadMessage(clear?: boolean, timeout?: number, callback?: (err: any, data: any) => void): void;
|
|
102
|
+
getUnreadMessage(clear: boolean | undefined, withLogout: boolean | undefined, timeout?: number, callback?: (err: any, data: any) => void): void;
|
|
103
|
+
getUnreadMessage(clear: boolean | undefined, withLogout: boolean | undefined, callback?: (err: any, data: any) => void): void;
|
|
93
104
|
getP2PUnreadMessageNum(uids, mtime, mtypes, timeout, callback);
|
|
94
105
|
getGroupUnreadMessageNum(gids, mtime, mtypes, timeout, callback);
|
|
95
106
|
cleanUnreadMessage(timeout, callback);
|
|
@@ -121,6 +132,7 @@ declare namespace rtm {
|
|
|
121
132
|
translate(originalMessage, originalLanguage, targetLanguage, type, profanity, timeout, callback);
|
|
122
133
|
profanity(text, classify, timeout, callback);
|
|
123
134
|
textCheck(text, strategyId, timeout, callback);
|
|
135
|
+
textCheck(text: any, timeout?: number, callback?: (err: any, data: any) => void): void;
|
|
124
136
|
imageCheck(image, type, strategyId, timeout, callback);
|
|
125
137
|
audioCheck(audio, type, lang, codec, srate, strategyId, timeout, callback);
|
|
126
138
|
videoCheck(video, type, videoName, strategyId, timeout, callback);
|
|
@@ -187,9 +199,12 @@ declare namespace rtm {
|
|
|
187
199
|
getGroupConversationList(mtime, mtypes, timeout, callback);
|
|
188
200
|
getGroupUnreadConversationList(mtime, mtypes, timeout, callback);
|
|
189
201
|
getUnreadConversationList(clear, mtime, mtypes, timeout, callback);
|
|
190
|
-
removeSession(to
|
|
202
|
+
removeSession(to: RTMId, timeout?: number, callback?: (err: any, data: any) => void): void;
|
|
203
|
+
removeSession(to: RTMId, localOnly: boolean | undefined, timeout?: number, callback?: (err: any, data: any) => void): void;
|
|
204
|
+
removeSession(to: RTMId, localOnly: boolean | undefined, callback?: (err: any, data: any) => void): void;
|
|
191
205
|
on(type, callback);
|
|
192
206
|
emit();
|
|
207
|
+
listenerCount(type: string): number;
|
|
193
208
|
removeEvent();
|
|
194
209
|
}
|
|
195
210
|
|
|
@@ -212,12 +227,17 @@ declare namespace rtm {
|
|
|
212
227
|
regressiveStrategy?: RTMRegressiveStrategy;
|
|
213
228
|
}
|
|
214
229
|
|
|
215
|
-
/** Defaults to
|
|
230
|
+
/** Defaults to FPNN; use protocol: 'tlv-v1' to opt into TLV. Functions cannot cross the Worker boundary. */
|
|
216
231
|
export type RTMSharedWorkerClientOptions = RTMSharedWorkerBaseClientOptions & (
|
|
217
|
-
{ protocol?: '
|
|
218
|
-
| ({ protocol: 'fpnn' } & (
|
|
232
|
+
({ protocol?: 'fpnn' } & (
|
|
219
233
|
{ endpoint: string; ssl_endpoint?: string } | { ssl_endpoint: string; endpoint?: string }
|
|
220
234
|
))
|
|
235
|
+
| ({ protocol: 'tlv-v1' } & (
|
|
236
|
+
{ tlvEndpoint: string; tlv_endpoint?: string }
|
|
237
|
+
| { tlvEndpoint?: string; tlv_endpoint: string }
|
|
238
|
+
| { endpoint: string; ssl_endpoint?: string }
|
|
239
|
+
| { ssl_endpoint: string; endpoint?: string }
|
|
240
|
+
))
|
|
221
241
|
);
|
|
222
242
|
|
|
223
243
|
export type RTMConversationType = 'direct' | 'group' | 'room';
|
|
@@ -229,7 +249,7 @@ declare namespace rtm {
|
|
|
229
249
|
}
|
|
230
250
|
|
|
231
251
|
export interface RTMSharedWorkerOptions {
|
|
232
|
-
/** Optional same-origin
|
|
252
|
+
/** Optional same-origin override. Package ESM entries and bundler adapters provide a default; classic scripts infer the Worker beside the SDK script. */
|
|
233
253
|
workerUrl?: string;
|
|
234
254
|
/** Explicit stable name. When omitted and uid is provided, the SDK derives one from protocol, pid, uid, endpoint, and workerNamespace. */
|
|
235
255
|
workerName?: string;
|
|
@@ -241,15 +261,18 @@ declare namespace rtm {
|
|
|
241
261
|
readyTimeout?: number;
|
|
242
262
|
/** 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. */
|
|
243
263
|
idleShutdownTimeout?: number;
|
|
244
|
-
/** Structured-cloneable
|
|
264
|
+
/** Structured-cloneable SDK options. Capabilities follow RTMClient, including FPNN file uploads. */
|
|
245
265
|
clientOptions: RTMSharedWorkerClientOptions;
|
|
246
|
-
/** Optional
|
|
266
|
+
/** Optional page-side event filter. The Worker broadcasts all SDK events; omitted means no filtering. */
|
|
247
267
|
conversation?: RTMConversation | null;
|
|
248
268
|
}
|
|
249
269
|
|
|
250
|
-
|
|
251
|
-
export type RTMCreateClientOptions = RTMSharedWorkerClientOptions &
|
|
270
|
+
export type RTMSharedCreateClientOptions = RTMSharedWorkerClientOptions &
|
|
252
271
|
Omit<RTMSharedWorkerOptions, 'clientOptions'> & { sharing?: true };
|
|
272
|
+
export type RTMIndependentCreateClientOptions = RTMClientOptions & { sharing: false };
|
|
273
|
+
|
|
274
|
+
/** Flat client options. Sharing defaults to true; protocol defaults to FPNN in both modes. */
|
|
275
|
+
export type RTMCreateClientOptions = RTMSharedCreateClientOptions | RTMIndependentCreateClientOptions;
|
|
253
276
|
|
|
254
277
|
/** Default shared facade. Worker is attached on login, or immediately when options.uid is set. */
|
|
255
278
|
export interface RTMDefaultClient extends Omit<RTMSharedWorkerClient, 'promises' | 'login' | 'whenReady'> {
|
|
@@ -266,8 +289,9 @@ declare namespace rtm {
|
|
|
266
289
|
emit(type: string, ...args: any[]): void;
|
|
267
290
|
}
|
|
268
291
|
|
|
269
|
-
export function createClient(options:
|
|
270
|
-
export function createClient(options:
|
|
292
|
+
export function createClient(options: RTMIndependentCreateClientOptions): RTMClient;
|
|
293
|
+
export function createClient(options: RTMSharedCreateClientOptions): RTMDefaultClient;
|
|
294
|
+
export function createClient(options: RTMCreateClientOptions): RTMDefaultClient | RTMClient;
|
|
271
295
|
|
|
272
296
|
export interface RTMSharedSessionSnapshot {
|
|
273
297
|
status: 'idle' | 'connecting' | 'authenticated';
|
|
@@ -288,6 +312,8 @@ declare namespace rtm {
|
|
|
288
312
|
on(type: string, callback: (...args: any[]) => void): this;
|
|
289
313
|
off(type: string, callback?: (...args: any[]) => void): this;
|
|
290
314
|
removeEvent(type?: string, callback?: (...args: any[]) => void): this;
|
|
315
|
+
emit(type: string, ...args: any[]): void;
|
|
316
|
+
listenerCount(type: string): number;
|
|
291
317
|
}
|
|
292
318
|
|
|
293
319
|
export class RTMSharedWorkerClient {
|
|
@@ -308,14 +334,16 @@ declare namespace rtm {
|
|
|
308
334
|
on(type: string, callback: (...args: any[]) => void): this;
|
|
309
335
|
off(type: string, callback?: (...args: any[]) => void): this;
|
|
310
336
|
removeEvent(type?: string, callback?: (...args: any[]) => void): this;
|
|
311
|
-
|
|
337
|
+
emit(type: string, ...args: any[]): void;
|
|
338
|
+
listenerCount(type: string): number;
|
|
339
|
+
/** Filter this page's listeners locally; the Worker broadcasts all events. Pass null to disable filtering. */
|
|
312
340
|
setConversation(conversation: RTMConversation | null, callback?: (error?: Error | null) => void): this;
|
|
313
341
|
/** Detaches this page; also called automatically on pagehide (except BFCache). It does not close the shared connection. */
|
|
314
342
|
destroy(): void;
|
|
315
343
|
}
|
|
316
344
|
|
|
317
345
|
export interface RTMSharedWorkerIdentity {
|
|
318
|
-
/** Defaults to
|
|
346
|
+
/** Defaults to fpnn. TLV names are isolated from FPNN names. */
|
|
319
347
|
protocol?: RTMProtocol;
|
|
320
348
|
pid: string | number;
|
|
321
349
|
uid: RTMId;
|