@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.6 → 1.0.0-cg.8
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 +23 -11
- package/dist/rtm.d.cts +3 -0
- package/dist/rtm.d.mts +42 -0
- package/dist/rtm.d.ts +67 -25
- 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 +29 -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 +475 -0
- package/docs/PROTOCOL_MIGRATION.md +6 -5
- package/docs/RTM_MIGRATION.md +207 -0
- package/docs/Rooms.md +2 -0
- package/docs/System.md +2 -0
- package/docs/USAGE.md +86 -35
- package/docs/Users.md +2 -0
- package/docs/ValueAdded.md +10 -4
- package/package.json +29 -7
package/README.md
CHANGED
|
@@ -8,6 +8,14 @@ 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 `latest` 中。普通业务项目和三个框架 Demo 直接从 npm 安装 SDK;HTML Demo 使用仓库构建出的 UMD 文件。发布包入口与验证范围见 [实现与验证记录](docs/NPM_MODERNIZATION_PLAN.md)。
|
|
12
|
+
|
|
13
|
+
当前工作区包版本为 `1.0.0-cg.8`,是本地构建版本,尚未发布到 npm;registry `latest` 仍为 `1.0.0-cg.7`。本地 `npm pack` 可生成并审计 `cg.8` tarball;发布前使用 `@latest` 仍会安装 `cg.7`。
|
|
14
|
+
|
|
15
|
+
## 本地构建
|
|
16
|
+
|
|
17
|
+
从源码构建或打包 SDK 需要 Node.js 18 或更高版本(`esbuild` 的构建工具要求);这是仓库维护和发包环境要求,不会提高浏览器 SDK 使用方的 Node.js 运行时要求。运行 `npm run build` 会生成 UMD、SharedWorker、ESM、Vite/Webpack 插件和类型声明产物。
|
|
18
|
+
|
|
11
19
|
浏览器可加载 `dist/rtm.min.js` 并从 `window.rtm` 使用;CommonJS:
|
|
12
20
|
|
|
13
21
|
```js
|
|
@@ -20,10 +28,10 @@ Node.js 使用 TLV v1 时,需自行提供 `webSocketFactory(url)`。SDK 不携
|
|
|
20
28
|
|
|
21
29
|
### 默认共享入口
|
|
22
30
|
|
|
23
|
-
`createClient()`
|
|
31
|
+
工作区当前的 `createClient()` 在浏览器支持 SharedWorker 且配置可安全传递时默认共享连接;浏览器不支持或配置含页面运行时值时自动使用当前页面的独立连接。`1.0.0-cg.8` 工作区构建版可通过 `client.getConnectionInfo()` 报告所选模式和回退原因。npm `latest` `1.0.0-cg.7` 尚未包含配置回退和此诊断 API:它只会在浏览器没有 SharedWorker 时改用页面内连接。省略 `protocol` 时默认使用 FPNN,以兼容旧 `RTMClient` 接入。新项目使用 TLV 时请显式设置 `protocol: 'tlv-v1'`。支持共享的环境中,SDK 自动按 PID、协议、UID 和 Gate 地址隔离会话;同一环境的页面自动复用,业务无需配置 Worker 名称或路径。UID 可直接从 `login()` 获取。
|
|
24
32
|
|
|
25
33
|
```js
|
|
26
|
-
const client = rtm.createClient({ pid, tlvEndpoint: endpoint });
|
|
34
|
+
const client = rtm.createClient({ protocol: 'tlv-v1', pid, tlvEndpoint: endpoint });
|
|
27
35
|
client.processor.on(rtm.RTMConfig.TLV_SERVER_PUSH.recvMessage, renderMessage);
|
|
28
36
|
await client.promises.login(uid, credential); // 同 UID 已登录时 credential 可省略
|
|
29
37
|
await client.promises.sendChat(peerUid, 'hello', '{}');
|
|
@@ -31,7 +39,7 @@ await client.promises.sendChat(peerUid, 'hello', '{}');
|
|
|
31
39
|
client.destroy();
|
|
32
40
|
```
|
|
33
41
|
|
|
34
|
-
片段中的 `rtm`、项目参数、credential 和 `renderMessage` 由应用提供;完整流程和能力边界见 [默认共享接入](docs/USAGE.md
|
|
42
|
+
片段中的 `rtm`、项目参数、credential 和 `renderMessage` 由应用提供;完整流程和能力边界见 [默认共享接入](docs/USAGE.md#默认共享接入)。从旧 `new RTMClient()` 迁移且继续使用 FPNN 时,可将构造器替换为 `createClient()` 并沿用 `endpoint` 配置;工厂默认协议为 FPNN。在浏览器支持 SharedWorker 且配置可传递时自动共享;当前工作区新版在不支持或存在函数、自定义实例等运行时配置时自动使用独立连接,并可通过 `client.getConnectionInfo()` 报告实际模式和回退原因。npm `latest` `1.0.0-cg.7` 尚无配置回退或诊断方法,仅在 SharedWorker 不可用时使用独立连接。显式设置 `sharing: false` 也会选择独立连接。现代 ESM 项目从包根导入;Vite 项目另在配置中注册 `/vite-plugin`,避免开发依赖预构建改写 SDK 的 Worker URL;Worker 资源由 Vite 构建输出。详见 [npm 接入现代化说明](docs/NPM_MODERNIZATION_PLAN.md)。
|
|
35
43
|
|
|
36
44
|
### 原有单连接入口
|
|
37
45
|
|
|
@@ -68,11 +76,17 @@ async function startChat(rtm, { pid, endpoint, uid, peerUid, credential }) {
|
|
|
68
76
|
|
|
69
77
|
## 同 UID 多窗口
|
|
70
78
|
|
|
71
|
-
需要同一浏览器内多个同源页面共用一个 UID 的 RTC 登录和 WebSocket 时,新接入推荐使用 SDK 的 `createClient()`
|
|
79
|
+
需要同一浏览器内多个同源页面共用一个 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#默认共享接入)。
|
|
80
|
+
|
|
81
|
+
Vite 项目从 `@cg-devcenter/rtc-fpnn-webjs-sdk` 导入 ESM 入口,并在 Vite 配置中增加一次 `rtmSdkVitePlugin()`;Worker 由构建流程打包,业务无需填写路径。旧 `/vite` 导入仍保留兼容。若使用底层 `RTMSharedWorkerClient` 构造器,可通过 `uid` 自动生成 Worker 名称,或显式传入 `workerName`;`createClient()` 会按登录 UID 自动绑定,不要求手动设置名称。最后一个页面 detach 后默认 5 秒关闭共享连接。
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
常规接入不需要传 `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
84
|
|
|
75
|
-
SharedWorker
|
|
85
|
+
如果直接从 unpkg 或 jsDelivr 加载 UMD,默认 Worker URL 会指向 CDN,无法用于页面的 SharedWorker。请把同版本 Worker 放到应用同源目录并传入 `workerUrl`,或设置 `sharing: false`。详见[CDN 与 Worker 同源要求](docs/USAGE.md#引用与运行环境)。
|
|
86
|
+
|
|
87
|
+
`createClient()` 和直接构造 `RTMSharedWorkerClient` 都默认使用 FPNN;只有显式设置 `protocol: 'tlv-v1'` 才使用 TLV。登录共享和会话路由沿用同一套业务 API。用法与限制见 [FPNN 多窗口接入](docs/USAGE.md#fpnn-多窗口接入)。
|
|
88
|
+
|
|
89
|
+
SharedWorker 共享底层 SDK 实例和登录状态,业务 API 自动转发给 `RTMClient`,包括 FPNN 文件发送。Worker 原样广播 SDK 事件;`conversation` / `setConversation()` 只在页面端执行可选筛选。协议校验、上传、重连、ACK 和去重均由底层 SDK 处理。
|
|
76
90
|
|
|
77
91
|
仓库的演示页面可用以下命令启动:
|
|
78
92
|
|
|
@@ -81,11 +95,7 @@ npm run build
|
|
|
81
95
|
npm run demo:shared-worker
|
|
82
96
|
```
|
|
83
97
|
|
|
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`(仅源码仓库)。
|
|
98
|
+
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
99
|
|
|
90
100
|
## TLV v1 最小接入 Demo
|
|
91
101
|
|
|
@@ -94,6 +104,8 @@ HTML 与 Vue 3 Demo 共用同一份框架无关的 RTC 工作流控制器,覆
|
|
|
94
104
|
## 文档
|
|
95
105
|
|
|
96
106
|
- [接入指南与 API 参数](docs/USAGE.md)
|
|
107
|
+
- [从 GitHub 上游 SDK 迁移:新增 API、签名变化与兼容差异](docs/RTM_MIGRATION.md)
|
|
108
|
+
- [npm 接入现代化实施、验证与发布记录](docs/NPM_MODERNIZATION_PLAN.md)
|
|
97
109
|
- [FPNN 与 TLV v1 迁移对照](docs/PROTOCOL_MIGRATION.md)
|
|
98
110
|
- [能力总览与典型业务流程](docs/CAPABILITIES.md)
|
|
99
111
|
- [TLV v1 URI、请求字段与返回值](docs/TLV_CONTRACT.md)
|
package/dist/rtm.d.cts
ADDED
package/dist/rtm.d.mts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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 RTMConnectionInfo = rtm.RTMConnectionInfo;
|
|
24
|
+
export type RTMConnectionInfoProvider = rtm.RTMConnectionInfoProvider;
|
|
25
|
+
export type RTMDefaultClient = rtm.RTMDefaultClient;
|
|
26
|
+
export type RTMSharedSessionSnapshot = rtm.RTMSharedSessionSnapshot;
|
|
27
|
+
export type RTMSharedLoginResult = rtm.RTMSharedLoginResult;
|
|
28
|
+
export type RTMSharedWorkerIdentity = rtm.RTMSharedWorkerIdentity;
|
|
29
|
+
export type RTMClient = rtm.RTMClient;
|
|
30
|
+
export type RTMSharedWorkerClient = rtm.RTMSharedWorkerClient;
|
|
31
|
+
export type RTMConfig = rtm.RTMConfig;
|
|
32
|
+
export type RTMProcessor = rtm.RTMProcessor;
|
|
33
|
+
export type TLVCodec = rtm.TLVCodec;
|
|
34
|
+
export type TLVWebSocketClient = rtm.TLVWebSocketClient;
|
|
35
|
+
export const RTMClient: typeof rtm.RTMClient;
|
|
36
|
+
export const createClient: typeof rtm.createClient;
|
|
37
|
+
export const RTMSharedWorkerClient: typeof rtm.RTMSharedWorkerClient;
|
|
38
|
+
export const RTMConfig: typeof rtm.RTMConfig;
|
|
39
|
+
export const RTMProcessor: typeof rtm.RTMProcessor;
|
|
40
|
+
export const TLVCodec: typeof rtm.TLVCodec;
|
|
41
|
+
export const TLVWebSocketClient: typeof rtm.TLVWebSocketClient;
|
|
42
|
+
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,18 +261,35 @@ 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
|
-
/** Flat
|
|
251
|
-
export type
|
|
270
|
+
/** 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. */
|
|
271
|
+
export type RTMSharedCreateClientOptions = RTMClientOptions &
|
|
252
272
|
Omit<RTMSharedWorkerOptions, 'clientOptions'> & { sharing?: true };
|
|
273
|
+
export type RTMIndependentCreateClientOptions = RTMClientOptions &
|
|
274
|
+
Omit<RTMSharedWorkerOptions, 'clientOptions'> & { sharing: false };
|
|
253
275
|
|
|
254
|
-
/**
|
|
255
|
-
export
|
|
276
|
+
/** Flat client options. Sharing is preferred by default; protocol defaults to FPNN in both modes. */
|
|
277
|
+
export type RTMCreateClientOptions = RTMSharedCreateClientOptions | RTMIndependentCreateClientOptions;
|
|
278
|
+
|
|
279
|
+
export interface RTMConnectionInfo {
|
|
280
|
+
/** `shared` uses the SharedWorker backend; `direct` uses an RTMClient in this page. */
|
|
281
|
+
mode: 'shared' | 'direct';
|
|
282
|
+
/** Null when direct mode was explicitly requested or no fallback was needed. */
|
|
283
|
+
fallbackReason: string | null;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface RTMConnectionInfoProvider {
|
|
287
|
+
/** Reports the selected backend and the reason createClient fell back to direct mode, if any. */
|
|
288
|
+
getConnectionInfo(): RTMConnectionInfo;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** createClient facade for either backend. The Worker attaches on login, or immediately when options.uid is set. */
|
|
292
|
+
export interface RTMDefaultClient extends Omit<RTMSharedWorkerClient, 'promises' | 'login' | 'whenReady'>, RTMConnectionInfoProvider {
|
|
256
293
|
readonly promises: RTMDefaultPromiseApi;
|
|
257
294
|
on(type: 'SharedWorkerReady' | 'SharedSessionState', callback: (session: RTMSharedSessionSnapshot) => void): this;
|
|
258
295
|
on(type: string, callback: (...args: any[]) => void): this;
|
|
@@ -266,8 +303,9 @@ declare namespace rtm {
|
|
|
266
303
|
emit(type: string, ...args: any[]): void;
|
|
267
304
|
}
|
|
268
305
|
|
|
269
|
-
export function createClient(options:
|
|
270
|
-
export function createClient(options:
|
|
306
|
+
export function createClient(options: RTMIndependentCreateClientOptions): RTMDefaultClient;
|
|
307
|
+
export function createClient(options: RTMSharedCreateClientOptions): RTMDefaultClient;
|
|
308
|
+
export function createClient(options?: RTMCreateClientOptions): RTMDefaultClient;
|
|
271
309
|
|
|
272
310
|
export interface RTMSharedSessionSnapshot {
|
|
273
311
|
status: 'idle' | 'connecting' | 'authenticated';
|
|
@@ -288,6 +326,8 @@ declare namespace rtm {
|
|
|
288
326
|
on(type: string, callback: (...args: any[]) => void): this;
|
|
289
327
|
off(type: string, callback?: (...args: any[]) => void): this;
|
|
290
328
|
removeEvent(type?: string, callback?: (...args: any[]) => void): this;
|
|
329
|
+
emit(type: string, ...args: any[]): void;
|
|
330
|
+
listenerCount(type: string): number;
|
|
291
331
|
}
|
|
292
332
|
|
|
293
333
|
export class RTMSharedWorkerClient {
|
|
@@ -308,14 +348,16 @@ declare namespace rtm {
|
|
|
308
348
|
on(type: string, callback: (...args: any[]) => void): this;
|
|
309
349
|
off(type: string, callback?: (...args: any[]) => void): this;
|
|
310
350
|
removeEvent(type?: string, callback?: (...args: any[]) => void): this;
|
|
311
|
-
|
|
351
|
+
emit(type: string, ...args: any[]): void;
|
|
352
|
+
listenerCount(type: string): number;
|
|
353
|
+
/** Filter this page's listeners locally; the Worker broadcasts all events. Pass null to disable filtering. */
|
|
312
354
|
setConversation(conversation: RTMConversation | null, callback?: (error?: Error | null) => void): this;
|
|
313
355
|
/** Detaches this page; also called automatically on pagehide (except BFCache). It does not close the shared connection. */
|
|
314
356
|
destroy(): void;
|
|
315
357
|
}
|
|
316
358
|
|
|
317
359
|
export interface RTMSharedWorkerIdentity {
|
|
318
|
-
/** Defaults to
|
|
360
|
+
/** Defaults to fpnn. TLV names are isolated from FPNN names. */
|
|
319
361
|
protocol?: RTMProtocol;
|
|
320
362
|
pid: string | number;
|
|
321
363
|
uid: RTMId;
|