@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.5 → 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.
@@ -0,0 +1,8 @@
1
+ export interface RTMSDKVitePlugin {
2
+ name: string;
3
+ enforce: 'pre';
4
+ config(config: Record<string, any>): { optimizeDeps: Record<string, any> };
5
+ }
6
+
7
+ export function rtmSdkVitePlugin(): RTMSDKVitePlugin;
8
+ export default rtmSdkVitePlugin;
@@ -0,0 +1,23 @@
1
+ const packageName = '@cg-devcenter/rtc-fpnn-webjs-sdk';
2
+ const viteCompatibilityEntry = packageName + '/vite';
3
+
4
+ /** Keep both SDK ESM entries in Vite's transform pipeline so Worker URLs stay valid. */
5
+ export function rtmSdkVitePlugin() {
6
+ return {
7
+ name: 'rtc-fpnn-webjs-sdk',
8
+ enforce: 'pre',
9
+ config(config) {
10
+ const optimizeDeps = config.optimizeDeps || {};
11
+ const exclude = new Set(optimizeDeps.exclude || []);
12
+ exclude.add(packageName);
13
+ exclude.add(viteCompatibilityEntry);
14
+ return {
15
+ optimizeDeps: Object.assign({}, optimizeDeps, {
16
+ exclude: Array.from(exclude),
17
+ }),
18
+ };
19
+ },
20
+ };
21
+ }
22
+
23
+ export default rtmSdkVitePlugin;
@@ -3,6 +3,33 @@ import rtm = require('./rtm');
3
3
  declare const sdk: typeof rtm;
4
4
 
5
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;
6
33
  export const RTMClient: typeof rtm.RTMClient;
7
34
  export const createClient: typeof rtm.createClient;
8
35
  export const RTMSharedWorkerClient: typeof rtm.RTMSharedWorkerClient;
package/dist/rtm.vite.mjs CHANGED
@@ -1,32 +1,30 @@
1
- // Use the package export for the UMD bundle so Vite's dependency optimizer
2
- // provides CommonJS default interop. A relative import from this ESM wrapper
3
- // is served as native ESM in dev and has no default export.
1
+ // Source for the legacy `/vite` export. build-modern.mjs rewrites the Worker
2
+ // asset path when placing this file beside the generated dist assets.
4
3
  import rtmModule from '@cg-devcenter/rtc-fpnn-webjs-sdk/dist/rtm.min.js';
5
4
  import workerUrl from './rtm.shared-worker.js?url';
6
5
 
7
6
  const rtm = rtmModule.default || rtmModule;
8
7
 
9
8
  class RTMSharedWorkerClient extends rtm.RTMSharedWorkerClient {
10
- constructor(options) {
11
- const config = options || {};
12
- super(Object.assign({}, config, {
13
- workerUrl: config.workerUrl || workerUrl
14
- }));
15
- }
9
+ constructor(options) {
10
+ const config = options || {};
11
+ super(Object.assign({}, config, {
12
+ workerUrl: config.workerUrl || workerUrl,
13
+ }));
14
+ }
16
15
  }
17
16
 
18
17
  function createClient(options) {
19
- const config = options || {};
20
- return rtm.createClient(Object.assign({}, config, {
21
- workerUrl: config.workerUrl || workerUrl
22
- }));
18
+ const config = options || {};
19
+ return rtm.createClient(Object.assign({}, config, {
20
+ workerUrl: config.workerUrl || workerUrl,
21
+ }));
23
22
  }
24
23
 
25
24
  const sdk = Object.assign({}, rtm, { RTMSharedWorkerClient, createClient });
26
25
 
27
26
  export const RTMClient = sdk.RTMClient;
28
- export { createClient };
29
- export { RTMSharedWorkerClient };
27
+ export { createClient, RTMSharedWorkerClient };
30
28
  export const RTMConfig = sdk.RTMConfig;
31
29
  export const RTMProcessor = sdk.RTMProcessor;
32
30
  export const TLVCodec = sdk.TLVCodec;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const rtm = require('./rtm.min.js');
4
+
5
+ function workerUrl() {
6
+ const publicPath = typeof __webpack_public_path__ === 'string'
7
+ ? __webpack_public_path__
8
+ : '/';
9
+ return publicPath + 'rtm.shared-worker.js';
10
+ }
11
+
12
+ function withWorkerUrl(options) {
13
+ const config = options || {};
14
+ return Object.assign({}, config, {
15
+ workerUrl: config.workerUrl || workerUrl(),
16
+ });
17
+ }
18
+
19
+ class RTMSharedWorkerClient extends rtm.RTMSharedWorkerClient {
20
+ constructor(options) {
21
+ super(withWorkerUrl(options));
22
+ }
23
+ }
24
+
25
+ function createClient(options) {
26
+ return rtm.createClient(withWorkerUrl(options));
27
+ }
28
+
29
+ module.exports = Object.assign({}, rtm, { RTMSharedWorkerClient, createClient });
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const packageName = '@cg-devcenter/rtc-fpnn-webjs-sdk';
7
+ const workerFilename = 'rtm.shared-worker.js';
8
+
9
+ class RTMSDKWebpack4Plugin {
10
+ apply(compiler) {
11
+ const pluginName = 'RTMSDKWebpack4Plugin';
12
+ const distDirectory = __dirname;
13
+ const adapterPath = path.join(distDirectory, 'rtm.webpack4-adapter.cjs');
14
+ const workerPath = path.join(distDirectory, workerFilename);
15
+ const aliases = compiler.options.resolve && compiler.options.resolve.alias;
16
+
17
+ if (!compiler.options.resolve) compiler.options.resolve = {};
18
+ if (Array.isArray(aliases)) {
19
+ compiler.options.resolve.alias = aliases.concat({
20
+ name: packageName,
21
+ alias: adapterPath,
22
+ onlyModule: true,
23
+ });
24
+ } else {
25
+ compiler.options.resolve.alias = Object.assign({}, aliases || {}, {
26
+ [packageName + '$']: adapterPath,
27
+ });
28
+ }
29
+
30
+ compiler.hooks.emit.tapAsync(pluginName, (compilation, callback) => {
31
+ if (!fs.existsSync(workerPath)) {
32
+ callback(new Error(pluginName + ': SDK Worker file is missing: ' + workerPath));
33
+ return;
34
+ }
35
+ if (compilation.assets[workerFilename]) {
36
+ callback(new Error(pluginName + ': output already contains ' + workerFilename));
37
+ return;
38
+ }
39
+
40
+ const worker = fs.readFileSync(workerPath);
41
+ compilation.assets[workerFilename] = {
42
+ source: () => worker,
43
+ size: () => worker.length,
44
+ };
45
+ callback();
46
+ });
47
+ }
48
+ }
49
+
50
+ module.exports = RTMSDKWebpack4Plugin;
@@ -0,0 +1,5 @@
1
+ declare class RTMSDKWebpack4Plugin {
2
+ apply(compiler: any): void;
3
+ }
4
+
5
+ export = RTMSDKWebpack4Plugin;
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## 能力地图
10
10
 
11
- 当前源码推荐通过 `createClient()` 默认共享接入:扁平配置,UID 从登录参数取得,SDK 按 PID + 协议 + UID 自动命名并复用连接。`sharing: false` 显式选择独立连接;旧构造器保留原行为。已发布 `.3` 尚无此新入口,配置、错误和生命周期见 [默认共享接入](USAGE.md#默认共享接入当前源码)。
11
+ 推荐通过 `createClient()` 接入:扁平配置,UID 从登录参数取得;浏览器支持 SharedWorker 时,SDK 按 PID、协议、UID 和 Gate endpoint 自动隔离并复用连接,不支持时自动使用当前页面的独立连接。工厂和 `RTMSharedWorkerClient` 省略协议时均默认使用 FPNN,TLV 需显式选择。`sharing: false` 可显式选择独立连接;旧构造器保留业务 API。混用共享入口时,连接参数仍须保持一致。若 npm `latest` 尚未包含此入口,请使用本地构建;配置、错误和生命周期见 [默认共享接入](USAGE.md#默认共享接入当前源码)。
12
12
 
13
13
  | 业务目标 | SDK 能力 | 常用 API |
14
14
  | --- | --- | --- |
@@ -43,23 +43,23 @@
43
43
  | 能力 | `RTMClient` + TLV v1 | `RTMClient` + FPNN | `RTMSharedWorkerClient` |
44
44
  | --- | --- | --- | --- |
45
45
  | 连接环境 | 浏览器;Node.js 需传入 `webSocketFactory` | 浏览器 | 支持 SharedWorker 的浏览器,同源页面 |
46
- | 用户/群组/房间/广播消息 | 支持;按 TLV v1 契约字段校验 | 支持兼容 API | 沿用所选协议已开放 API(文件发送除外) |
47
- | Push ACK 与去重 | SDK 自动 ACK 可靠 Push,并按 `message_ref` 去重 | 沿用兼容实现 | 单条共享连接只 ACK 一次,再按页面会话路由给各端口 |
48
- | 文件、设备、好友、多媒体审核 | TLV v1 当前未开放的传统 API 不可用 | 兼容 API 可用,依赖对应服务端能力 | 两种模式都不支持文件发送;FPNN 设备/好友/审核可转发,TLV 按其支持范围 |
46
+ | 用户/群组/房间/广播消息 | 支持;按 TLV v1 契约字段校验 | 支持兼容 API | 沿用底层 SDK 的所选协议能力,包含 FPNN 文件发送 |
47
+ | Push ACK 与去重 | SDK 自动 ACK 可靠 Push,并按 `message_ref` 去重 | 沿用兼容实现 | 底层 SDK 只 ACK 一次;Worker 原样广播,页面可显式筛选 |
48
+ | 文件、设备、好友、多媒体审核 | TLV v1 当前未开放的传统 API 不可用 | 兼容 API 可用,依赖对应服务端能力 | FPNN 文件/设备/好友/审核由底层 SDK 处理,TLV 按其支持范围 |
49
49
  | 多页面连接共享 | 每个 `RTMClient` 实例各自管理连接 | 每个 `RTMClient` 实例各自管理连接 | 相同协议、Worker identity 与配置下,同一 UID 共用一条连接 |
50
50
  | 业务 UI 与消息存储 | 应用负责展示、缓存和历史补拉 | 应用负责展示、缓存和历史补拉 | 只路由实时 Push;不跨页同步草稿、未读 UI 状态或本地消息列表,也不持久化消息 |
51
51
 
52
- TLV v1 的能力以 [Client API 契约](TLV_CONTRACT.md) 的 URI 表为准;旧 API 名称存在不代表 TLV 服务端开放了该 wire。保留但未开放的 wire 返回 `200020`(`RTM_EC_FORBIDDEN_METHOD`);未知且未登记的 wire 返回 `20004`(`RTM_EC_UNKNOWN_METHOD`)。`RTMSharedWorkerClient` 的文件发送方法在本地拒绝:callback 收到 `{mid, error}`,Promise 版本 reject 同一对象,`error.code` 为 `200999`(`RTM_EC_UNKNOWN_ERROR`),不发送 wire 请求。以上情况均不会退回 FPNN。SharedWorker 不是另一套 RTC 协议,也不替业务服务端签发 credential。
52
+ TLV v1 的能力以 [Client API 契约](TLV_CONTRACT.md) 的 URI 表为准;旧 API 名称存在不代表 TLV 服务端开放了该 wire。保留但未开放的 wire 返回 `200020`(`RTM_EC_FORBIDDEN_METHOD`);未知且未登记的 wire 返回 `20004`(`RTM_EC_UNKNOWN_METHOD`)。共享层自动代理 SDK 公开业务方法;FPNN 文件发送可用,TLV 文件发送由底层 SDK 拒绝,callback 收到 `{mid, error}`、`error.code` 为 `200020`,Promise 版本 reject 同一对象。以上情况均不会退回 FPNN。SharedWorker 不是另一套 RTC 协议,也不替业务服务端签发 credential。
53
53
 
54
54
  ### SharedWorker 共享范围
55
55
 
56
- - SDK 会默认从加载它的页面脚本同目录定位 `rtm.shared-worker.js`;Vite 项目可从 `@cg-devcenter/rtc-fpnn-webjs-sdk/vite` 导入 ESM 入口,由 SDK 自动将 Worker 作为构建资源配置给客户端。部署时 Worker 必须在页面同源下可访问;非 Vite 自定义部署路径时可显式提供 `workerUrl`。
56
+ - 常规接入无需传 `workerUrl`:普通 HTML 将 SDK 脚本与 `rtm.shared-worker.js` 放在同源同目录;现代 ESM 项目从包根导入,Vite 配置 `/vite-plugin`,Webpack 4 配置 `/webpack4` 插件,Webpack 5 使用标准 ESM 资源解析。Worker 必须在页面同源下可访问;只有自定义 Worker 部署位置时才显式提供同源 `workerUrl`。直接从 unpkg / jsDelivr 加载 UMD 时,默认 Worker 通常会跨域;此时需在应用同源托管 Worker 并覆盖 `workerUrl`,或设置 `sharing: false`。Vue、React 和普通 JS 的用法相同,Worker 配置取决于构建工具。
57
57
  - 共享键由浏览器 origin、Worker URL、Worker 名称和完全相同的 `clientOptions` 共同决定;这些值不同的页面不会共用连接。
58
- - 支持 `clientOptions.protocol: 'tlv-v1'` 或 `'fpnn'`,默认仍为 TLV;FPNN 扩展目前为源码/本地构建能力,已发布 `.3` 尚不包含它。同 UID 使用不同协议会建立独立连接。
58
+ - 直接构造 `RTMSharedWorkerClient` 时支持 `clientOptions.protocol: 'tlv-v1'` 或 `'fpnn'`,省略时默认 FPNN;新工厂 `createClient()` 省略 `protocol` 时也默认 FPNN。只有显式传 `protocol: 'tlv-v1'` 才选择 TLV。FPNN 扩展是否可用以 npm `latest` 标签对应的 SDK 为准,同 UID 使用不同协议会建立独立连接。
59
59
  - 一个 Worker 只登录一个 UID。不同 UID 同时在线必须分别建立 Worker/RTC 连接;单 UID 的多页面共享登录态。
60
- - 每个页面有独立的 Push 监听端口。配置 `conversation` 后,SDK 按所选协议提取 direct sender、group ref 或 room ref 后过滤,保留原协议事件名和数据;未配置时该页面接收全部会话 Push。
60
+ - 每个页面有独立的 Push 监听端口。Worker 原样广播 SDK 事件。配置 `conversation` 后,由页面适配器按所选协议筛选监听器通知;未配置时该页面接收全部会话 Push。
61
61
  - SDK 负责连接、重连、Push ACK/去重和端口分发;业务仍负责消息展示、历史补拉、业务未读规则、草稿与页面状态。
62
- - 登录态保存在 Worker 内存。Worker 被浏览器回收或空闲回收完成后,需要业务重新创建 client 并登录;SDK 不持久化 credential,也不承诺把断线期间未投递的 Push 自动补齐。
62
+ - 登录态保存在 Worker 内存。底层 RTC 断线由 `autoReconnect` 处理;初始化失败、Worker `error` 或消息端口错误会报告 `SharedWorkerError`,此时业务可丢弃失效 client 并重新创建。SDK 目前没有 Worker 就绪后的心跳检测;浏览器静默回收 Worker 时不保证触发该事件,页面可能无法及时察觉。新 Worker 的登录快照为 `idle` 时,业务需重新提供服务端签发的 credential。SDK 不持久化 credential,也不承诺把断线期间未投递的 Push 自动补齐。
63
63
  - `destroy()` 只 detach 当前页面;最后一个页面 detach 后默认等待 5 秒再销毁共享 RTMClient,期间有新页面接入会取消回收。可通过 `idleShutdownTimeout` 调整,设为 0 表示立即关闭;同一个 Worker 的页面须使用相同值。`bye()` / `close()` 会结束所有共用页面的 RTC 会话。共享 Worker 初始化失败时不会静默降级为每页单独连接。
64
64
 
65
65
  TLV v1 使用 MessagePack 二进制 WebSocket frame。SDK 提供以下基础模块:
package/docs/Chat.md ADDED
@@ -0,0 +1,278 @@
1
+ # RTM Client Websocket SDK Chat API Docs
2
+
3
+ ## Index
4
+
5
+ [TOC]
6
+
7
+ ## Apis
8
+
9
+ **协议范围:** 本页记录 FPNN 兼容 API 的参数和事件名称;列出的方法不一定都能通过 TLV v1 调用。请先核对 [TLV v1 支持矩阵](USAGE.md#6-tlv-v1-api-支持矩阵);两协议的 method、URI 和 Push 对照见[协议迁移说明](PROTOCOL_MIGRATION.md)。
10
+
11
+ * `sendChat(to, msg, attrs, mid, timeout, callback)`: 发送文本聊天
12
+ * `to`: **(Required | Int64)** 接收方uid
13
+ * `msg`: **(Required | string)** 消息内容
14
+ * `attrs`: **(Required | string)** 消息附加信息, 没有可传`''`
15
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
16
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
17
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
18
+ * `err`: **(object[mid:Int64, error:Error])**
19
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
20
+
21
+ * `sendGroupChat(gid, msg, attrs, mid, timeout, callback)`: 发送group文本聊天
22
+ * `gid`: **(Required | Int64)** group id
23
+ * `msg`: **(Required | string)** 消息内容
24
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
25
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
26
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
27
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
28
+ * `err`: **(object[mid:Int64, error:Error])**
29
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
30
+
31
+ * `sendRoomChat(rid, msg, attrs, mid, timeout, callback)`: 发送room文本聊天
32
+ * `rid`: **(Required | Int64)** room id
33
+ * `msg`: **(Required | string)** 消息内容
34
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
35
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
36
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
37
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
38
+ * `err`: **(object[mid:Int64, error:Error])**
39
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
40
+
41
+ * `sendAudio(to, msg, attrs, mid, timeout, callback)`: 发送语音聊天
42
+ * `to`: **(Required | Int64)** 接收方uid
43
+ * `msg`: **(Required | string)** 消息内容
44
+ * `attrs`: **(Required | string)** 消息附加信息, 没有可传`''`
45
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
46
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
47
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
48
+ * `err`: **(object[mid:Int64, error:Error])**
49
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
50
+
51
+ * `sendGroupAudio(gid, msg, attrs, mid, timeout, callback)`: 发送group语音聊天
52
+ * `gid`: **(Required | Int64)** group id
53
+ * `msg`: **(Required | string)** 消息内容
54
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
55
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
56
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
57
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
58
+ * `err`: **(object[mid:Int64, error:Error])**
59
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
60
+
61
+ * `sendRoomAudio(rid, msg, attrs, mid, timeout, callback)`: 发送room语音聊天
62
+ * `rid`: **(Required | Int64)** room id
63
+ * `msg`: **(Required | string)** 消息内容
64
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
65
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
66
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
67
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
68
+ * `err`: **(object[mid:Int64, error:Error])**
69
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
70
+
71
+ * `sendCmd(to, msg, attrs, mid, timeout, callback)`: 发送聊天控制命令
72
+ * `to`: **(Required | Int64)** 接收方uid
73
+ * `msg`: **(Required | string)** 消息内容
74
+ * `attrs`: **(Required | string)** 消息附加信息, 没有可传`''`
75
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
76
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
77
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
78
+ * `err`: **(object[mid:Int64, error:Error])**
79
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
80
+
81
+ * `sendGroupCmd(gid, msg, attrs, mid, timeout, callback)`: 发送group聊天控制命令
82
+ * `gid`: **(Required | Int64)** group id
83
+ * `msg`: **(Required | string)** 消息内容
84
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
85
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
86
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
87
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
88
+ * `err`: **(object[mid:Int64, error:Error])**
89
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
90
+
91
+ * `sendRoomCmd(rid, msg, attrs, mid, timeout, callback)`: 发送room聊天控制命令
92
+ * `rid`: **(Required | Int64)** room id
93
+ * `msg`: **(Required | string)** 消息内容
94
+ * `attrs`: **(Required | string)** 消息附加信息, 可传`''`
95
+ * `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
96
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
97
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
98
+ * `err`: **(object[mid:Int64, error:Error])**
99
+ * `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
100
+
101
+ * `deleteChat(from, mid, xid, type, timeout, callback)`: 删除消息
102
+ * `from`: **(Required | Int64)** 发送者用户 id
103
+ * `mid`: **(Required | Int64)** 消息 id
104
+ * `xid`: **(Required | Int64)** 消息接收方 id (userId/RoomId/GroupId)
105
+ * `type`: **(Required | number)** 接收方类型 (1:p2p, 2:group, 3:room)
106
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
107
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
108
+ * `err`: **(Error)**
109
+ * `data`: **(object)**
110
+
111
+ * `getChat(from, mid, xid, type, timeout, callback)`: 获取聊天
112
+ * `from`: **(Required | Int64)** 发送者用户 id
113
+ * `mid`: **(Required | Int64)** 消息 id
114
+ * `xid`: **(Required | Int64)** 消息接收方 id (userId/RoomId/GroupId)
115
+ * `type`: **(Required | number)** 接收方类型 (1:p2p, 2:group, 3:room)
116
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
117
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
118
+ * `err`: **(Error)**
119
+ * `data`: **(object[id: Int64, mtype: number, msg: string, attrs: string, mtime: Int64])**
120
+
121
+ * `getGroupChat(gid, desc, num, begin, end, lastid, timeout, callback)`: 获取Group历史聊天
122
+ * `gid`: **(Required | Int64)** Group id
123
+ * `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
124
+ * `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
125
+ * `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
126
+ * `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
127
+ * `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
128
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
129
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
130
+ * `err`: **(Error)**
131
+ * `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[GroupMsg]])**
132
+ * `GroupMsg.id` **(Int64)**
133
+ * `GroupMsg.from` **(Int64)**
134
+ * `GroupMsg.mtype` **(number)**
135
+ * `GroupMsg.mid` **(Int64)**
136
+ * `GroupMsg.deleted` **(bool)**
137
+ * `GroupMsg.msg` **(string)**
138
+ * `GroupMsg.attrs` **(string)**
139
+ * `GroupMsg.mtime` **(Int64)**
140
+
141
+ * `getRoomChat(rid, desc, num, begin, end, lastid, timeout, callback)`: 获取Room历史聊天
142
+ * `rid`: **(Required | Int64)** Room id
143
+ * `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
144
+ * `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
145
+ * `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
146
+ * `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
147
+ * `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
148
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
149
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
150
+ * `err`: **(Error)**
151
+ * `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[RoomMsg]])**
152
+ * `RoomMsg.id` **(Int64)**
153
+ * `RoomMsg.from` **(Int64)**
154
+ * `RoomMsg.mtype` **(number)**
155
+ * `RoomMsg.mid` **(Int64)**
156
+ * `RoomMsg.deleted` **(bool)**
157
+ * `RoomMsg.msg` **(string)**
158
+ * `RoomMsg.attrs` **(string)**
159
+ * `RoomMsg.mtime` **(Int64)**
160
+
161
+ * `getBroadcastChat(desc, num, begin, end, lastid, timeout, callback)`: 获取广播历史聊天
162
+ * `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
163
+ * `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
164
+ * `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
165
+ * `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
166
+ * `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
167
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
168
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
169
+ * `err`: **(Error)**
170
+ * `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[BroadcastMsg]])**
171
+ * `BroadcastMsg.id` **(Int64)**
172
+ * `BroadcastMsg.from` **(Int64)**
173
+ * `BroadcastMsg.mtype` **(number)**
174
+ * `BroadcastMsg.mid` **(Int64)**
175
+ * `BroadcastMsg.deleted` **(bool)**
176
+ * `BroadcastMsg.msg` **(string)**
177
+ * `BroadcastMsg.attrs` **(string)**
178
+ * `BroadcastMsg.mtime` **(Int64)**
179
+
180
+ * `getP2PChat(ouid, desc, num, begin, end, lastid, timeout, callback)`: 获取P2P历史聊天
181
+ * `ouid`: **(Required | Int64)** 获取和哪个用户id的历史消息
182
+ * `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
183
+ * `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
184
+ * `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
185
+ * `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
186
+ * `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
187
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
188
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
189
+ * `err`: **(Error)**
190
+ * `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[P2PMsg]])**
191
+ * `P2PMsg.id` **(Int64)**
192
+ * `P2PMsg.direction` **(number)**
193
+ * `P2PMsg.mtype` **(number)**
194
+ * `P2PMsg.mid` **(Int64)**
195
+ * `P2PMsg.deleted` **(bool)**
196
+ * `P2PMsg.msg` **(string)**
197
+ * `P2PMsg.attrs` **(string)**
198
+ * `P2PMsg.mtime` **(Int64)**
199
+
200
+ * `getSession(timeout, callback)`: 获取所有会话
201
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
202
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
203
+ * `err`: **(Error)**
204
+ * `data`: **(object[p2p:object[string, Int64], group:object[string, Int64]])** 对应值为最后一次会话的UTC时间戳
205
+
206
+ * `setTranslationLanguage(targetLanguage, timeout, callback)`: 设置自动翻译的默认目标语言类型, 如果 targetLanguage 为空字符串, 则取消自动翻译
207
+ * `targetLanguage`: **(Required | string)** 翻译的目标语言类型
208
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
209
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
210
+ * `err`: **(Error)**
211
+ * `data`: **(object)**
212
+
213
+ * `getP2PConversationList(mtime, mtypes, timeout, callback)`: 获取所有p2p会话列表
214
+ * `mtime`: **(Optional | int64)** 毫秒级时间戳,大于该时间戳的消息被计为未读消息,未读消息的最后一条作为会话的最后一条消息。不传则默认取上次离线时间。
215
+ * `mtypes`: **(Optional | set<int8>)** 消息类型列表,不传则默认查询mtype为30-50的消息
216
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
217
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
218
+ * `err`: **(Error)**
219
+ * `data`: **(object)**
220
+ * conversations参数为会话id列表,为p2p会话中对方的uid
221
+ * unreads参数为未读数量列表
222
+ * msgs参数为最后一条消息列表
223
+
224
+ * `getP2PUnreadConversationList(mtime, mtypes, timeout, callback)`: 获取所有p2p会话列表
225
+ * `mtime`: **(Optional | int64)** 毫秒级时间戳,大于该时间戳的消息被计为未读消息,未读消息的最后一条作为会话的最后一条消息。不传则默认取上次离线时间。
226
+ * `mtypes`: **(Optional | set<int8>)** 消息类型列表,不传则默认查询mtype为30-50的消息
227
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
228
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
229
+ * `err`: **(Error)**
230
+ * `data`: **(object)**
231
+ * conversations参数为会话id列表,为p2p会话中对方的uid
232
+ * unreads参数为未读数量列表
233
+ * msgs参数为最后一条消息列表
234
+
235
+ * `getGroupConversationList(mtime, mtypes, timeout, callback)`: 获取所有群组会话列表
236
+ * `mtime`: **(Optional | int64)** 毫秒级时间戳,大于该时间戳的消息被计为未读消息,未读消息的最后一条作为会话的最后一条消息。不传则默认取上次离线时间。
237
+ * `mtypes`: **(Optional | set<int8>)** 消息类型列表,不传则默认查询mtype为30-50的消息
238
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
239
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
240
+ * `err`: **(Error)**
241
+ * `data`: **(object)**
242
+ * conversations参数为会话id列表,为p2p会话中对方的uid
243
+ * unreads参数为未读数量列表
244
+ * msgs参数为最后一条消息列表
245
+
246
+ * `getGroupUnreadConversationList(mtime, mtypes, timeout, callback)`: 获取所有群组未读会话列表
247
+ * `mtime`: **(Optional | int64)** 毫秒级时间戳,大于该时间戳的消息被计为未读消息,未读消息的最后一条作为会话的最后一条消息。不传则默认取上次离线时间。
248
+ * `mtypes`: **(Optional | set<int8>)** 消息类型列表,不传则默认查询mtype为30-50的消息
249
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
250
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
251
+ * `err`: **(Error)**
252
+ * `data`: **(object)**
253
+ * conversations参数为会话id列表,为p2p会话中对方的uid
254
+ * unreads参数为未读数量列表
255
+ * msgs参数为最后一条消息列表
256
+
257
+ * `getUnreadConversationList(clear, mtime, mtypes, timeout, callback)`: 获取所有群组未读会话列表
258
+ * `clear`: **(Optional | bool)** 是否清除会话未读状态
259
+ * `mtime`: **(Optional | int64)** 毫秒级时间戳,大于该时间戳的消息被计为未读消息,未读消息的最后一条作为会话的最后一条消息。不传则默认取上次离线时间。
260
+ * `mtypes`: **(Optional | set<int8>)** 消息类型列表,不传则默认查询mtype为30-50的消息
261
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
262
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
263
+ * `err`: **(Error)**
264
+ * `data`: **(object)**
265
+ * groupConversations参数为群组会话id列表,为群组id
266
+ * groupUnreads参数为群组会话未读数量列表
267
+ * groupMsgs参数为群组会话最后一条消息列表
268
+ * p2pConversations参数为P2P会话id列表,为p2p会话中对方的uid
269
+ * p2pUnreads参数为P2P会话未读数量列表
270
+ * p2pMsgs参数为P2P会话最后一条消息列表
271
+
272
+ * `removeSession(to, localOnly, timeout, callback)`: 删除 p2p 会话;旧调用 `removeSession(to, timeout, callback)` 仍兼容。
273
+ * `to`: **(Required | Int64)** p2p会话中对方的uid
274
+ * `localOnly`: **(Optional | bool)** 只在本地移除会话;省略时保留旧 FPNN 请求语义
275
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
276
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
277
+ * `err`: **(object[mid:Int64, error:Error])**
278
+ * `data`: **(object)**
package/docs/Data.md ADDED
@@ -0,0 +1,33 @@
1
+ # RTM Client Websocket SDK Data API Docs
2
+
3
+ ## Index
4
+
5
+ [TOC]
6
+
7
+ ## Apis
8
+
9
+ **协议范围:** 本页记录 FPNN 兼容 API 的参数和事件名称;列出的方法不一定都能通过 TLV v1 调用。请先核对 [TLV v1 支持矩阵](USAGE.md#6-tlv-v1-api-支持矩阵);两协议的 method、URI 和 Push 对照见[协议迁移说明](PROTOCOL_MIGRATION.md)。
10
+
11
+ * `dataSet(key, value, timeout, callback)`: 设置存储的数据信息(key:最长128字节,val:最长65535字节)
12
+ * `key`: **(Required | string)** 数据的key
13
+ * `value`: **(Optional | string)** 数据的value
14
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
15
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
16
+ * `err`: **(object[mid:Int64, error:Error])**
17
+ * `data`: **(object)**
18
+
19
+ * `dataGet(key, timeout, callback) `: 获取存储的数据信息(key:最长128字节,val:最长65535字节)
20
+ * `key`: **(Required | string)** 数据的key
21
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
22
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
23
+ * `err`: **(object[mid:Int64, error:Error])**
24
+ * `data`: **(object[val:string])**
25
+
26
+ * `dataDelete(key, timeout, callback)`: 删除存储的数据信息
27
+ * `key`: **(Required | string)** 数据的key
28
+ * `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
29
+ * `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
30
+ * `err`: **(object[mid:Int64, error:Error])**
31
+ * `data`: **(object)**
32
+
33
+