@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.4 → 1.0.0-cg.6
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 +12 -12
- package/dist/rtm.d.ts +3 -2
- package/dist/rtm.min.js +1 -1
- package/docs/CAPABILITIES.md +3 -3
- package/docs/Chat.md +276 -0
- package/docs/Data.md +31 -0
- package/docs/EventProcess.md +124 -0
- package/docs/Files.md +50 -0
- package/docs/Friends.md +48 -0
- package/docs/Groups.md +62 -0
- package/docs/Messages.md +180 -0
- package/docs/PROTOCOL_MIGRATION.md +1 -1
- package/docs/Rooms.md +65 -0
- package/docs/System.md +47 -0
- package/docs/USAGE.md +64 -38
- package/docs/Users.md +46 -0
- package/docs/ValueAdded.md +76 -0
- package/package.json +17 -4
package/docs/Messages.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# RTM Client Websocket SDK Message API Docs
|
|
2
|
+
|
|
3
|
+
## Index
|
|
4
|
+
|
|
5
|
+
[TOC]
|
|
6
|
+
|
|
7
|
+
## Apis
|
|
8
|
+
|
|
9
|
+
* `sendMessage(to, mtype, msg, attrs, mid, timeout, callback)`: 发送消息
|
|
10
|
+
* `to`: **(Required | Int64)** 接收方uid
|
|
11
|
+
* `mtype`: **(Required | number)** 消息类型
|
|
12
|
+
* `msg`: **(Required | string)** 消息内容
|
|
13
|
+
* `attrs`: **(Required | string)** 消息附加信息, 没有可传`''`
|
|
14
|
+
* `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
|
|
15
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
16
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
17
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
18
|
+
* `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
|
|
19
|
+
|
|
20
|
+
* `sendGroupMessage(gid, mtype, msg, attrs, mid, timeout, callback)`: 发送group消息
|
|
21
|
+
* `gid`: **(Required | Int64)** group id
|
|
22
|
+
* `mtype`: **(Required | number)** 消息类型
|
|
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
|
+
* `sendRoomMessage(rid, mtype, msg, attrs, mid, timeout, callback)`: 发送room消息
|
|
32
|
+
* `rid`: **(Required | Int64)** room id
|
|
33
|
+
* `mtype`: **(Required | number)** 消息类型
|
|
34
|
+
* `msg`: **(Required | string)** 消息内容
|
|
35
|
+
* `attrs`: **(Required | string)** 消息附加信息, 可传`''`
|
|
36
|
+
* `mid`: **(Optional | Int64)** 消息 id, 用于过滤重复消息, 非重发时为`Int64(0)`
|
|
37
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
38
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
39
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
40
|
+
* `data`: **(object[mid:Int64, payload:object[mtime:Int64]])**
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
* `getUnreadMessage(clear, timeout, callback)`: 检测未读消息数目
|
|
45
|
+
* `clear`: **(Optional | bool)** 是否除离线提醒
|
|
46
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
47
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
48
|
+
* `err`: **(Error)**
|
|
49
|
+
* `data`: **(object[p2p:array(Int64), group:array(Int64)])** 对应值为未读消息数目
|
|
50
|
+
|
|
51
|
+
* `cleanUnreadMessage(timeout, callback)`: 清除未读消息
|
|
52
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
53
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
54
|
+
* `err`: **(Error)**
|
|
55
|
+
* `data`: **(object)**
|
|
56
|
+
|
|
57
|
+
* `getP2PUnreadMessageNum(uids, mtime, mtypes, timeout, callback)`: 获取未读P2P消息数目
|
|
58
|
+
* `uids`: **(Required | [int64])** uid列表
|
|
59
|
+
* `mtime`: **(Required | int64)** 毫秒级时间戳,获取这个时间戳之后的未读消息,如果mtime 为空,则获取上一次logout后的未读消息
|
|
60
|
+
* `mtypes`: **(Required | [number])** 获取指定mtype的未读消息,为空或undefined,则获取聊天相关未读消息
|
|
61
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
62
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
63
|
+
* `err`: **(Error)**
|
|
64
|
+
* `data`:
|
|
65
|
+
* `p2p` : **({ uid => num})**
|
|
66
|
+
* `ltime` : **({ session_id => time})** 每个session的的最新一条消息时间
|
|
67
|
+
|
|
68
|
+
* `getGroupUnreadMessageNum(gids, mtime, mtypes, timeout, callback)`: 获取未读Group消息数目
|
|
69
|
+
* `gids`: **(Required | [int64])** gid列表
|
|
70
|
+
* `mtime`: **(Required | int64)** 毫秒级时间戳,获取这个时间戳之后的未读消息,如果mtime 为空,则获取上一次logout后的未读消息
|
|
71
|
+
* `mtypes`: **(Required | [number])** 获取指定mtype的未读消息,为空或undefined,则获取聊天相关未读消息
|
|
72
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
73
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
74
|
+
* `err`: **(Error)**
|
|
75
|
+
* `data`:
|
|
76
|
+
* `group` : **({ gid => num})**
|
|
77
|
+
* `ltime` : **({ session_id => time})** 每个session的的最新一条消息时间
|
|
78
|
+
|
|
79
|
+
* `getGroupMessage(gid, desc, num, begin, end, lastid, mtypes, timeout, callback)`: 获取Group历史消息
|
|
80
|
+
* `gid`: **(Required | Int64)** Group id
|
|
81
|
+
* `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
|
|
82
|
+
* `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
|
|
83
|
+
* `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
|
|
84
|
+
* `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
|
|
85
|
+
* `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
|
|
86
|
+
* `mtypes`: **(Optional | array(number))** 获取哪些mtype的历史
|
|
87
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
88
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
89
|
+
* `err`: **(Error)**
|
|
90
|
+
* `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[GroupMsg]])**
|
|
91
|
+
* `GroupMsg.id` **(Int64)**
|
|
92
|
+
* `GroupMsg.from` **(Int64)**
|
|
93
|
+
* `GroupMsg.mtype` **(number)**
|
|
94
|
+
* `GroupMsg.mid` **(Int64)**
|
|
95
|
+
* `GroupMsg.deleted` **(bool)**
|
|
96
|
+
* `GroupMsg.msg` **(string)**
|
|
97
|
+
* `GroupMsg.attrs` **(string)**
|
|
98
|
+
* `GroupMsg.mtime` **(Int64)**
|
|
99
|
+
|
|
100
|
+
* `getRoomMessage(rid, desc, num, begin, end, lastid, mtypes, timeout, callback)`: 获取Room历史消息
|
|
101
|
+
* `rid`: **(Required | Int64)** Room id
|
|
102
|
+
* `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
|
|
103
|
+
* `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
|
|
104
|
+
* `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
|
|
105
|
+
* `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
|
|
106
|
+
* `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
|
|
107
|
+
* `mtypes`: **(Optional | array(number))** 获取哪些mtype的历史
|
|
108
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
109
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
110
|
+
* `err`: **(Error)**
|
|
111
|
+
* `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[RoomMsg]])**
|
|
112
|
+
* `RoomMsg.id` **(Int64)**
|
|
113
|
+
* `RoomMsg.from` **(Int64)**
|
|
114
|
+
* `RoomMsg.mtype` **(number)**
|
|
115
|
+
* `RoomMsg.mid` **(Int64)**
|
|
116
|
+
* `RoomMsg.deleted` **(bool)**
|
|
117
|
+
* `RoomMsg.msg` **(string)**
|
|
118
|
+
* `RoomMsg.attrs` **(string)**
|
|
119
|
+
* `RoomMsg.mtime` **(Int64)**
|
|
120
|
+
|
|
121
|
+
* `getBroadcastMessage(desc, num, begin, end, lastid, mtypes, timeout, callback)`: 获取广播历史消息
|
|
122
|
+
* `desc`: **(Required | bool)** `true`: 则从`end`的时间戳开始倒序翻页, `false`: 则从`begin`的时间戳顺序翻页
|
|
123
|
+
* `num`: **(Required | number)** 获取数量, **一次最多获取20条, 建议10条**
|
|
124
|
+
* `begin`: **(Optional | Int64)** 开始时间戳, 毫秒, 默认`0`, 条件:`>=`
|
|
125
|
+
* `end`: **(Optional | Int64)** 结束时间戳, 毫秒, 默认`0`, 条件:`<=`
|
|
126
|
+
* `lastid`: **(Optional | Int64)** 最后一条消息的id, 第一次默认传`0`, 条件:`> or <`
|
|
127
|
+
* `mtypes`: **(Optional | array(number))** 获取哪些mtype的历史
|
|
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[BroadcastMsg]])**
|
|
132
|
+
* `BroadcastMsg.id` **(Int64)**
|
|
133
|
+
* `BroadcastMsg.from` **(Int64)**
|
|
134
|
+
* `BroadcastMsg.mtype` **(number)**
|
|
135
|
+
* `BroadcastMsg.mid` **(Int64)**
|
|
136
|
+
* `BroadcastMsg.deleted` **(bool)**
|
|
137
|
+
* `BroadcastMsg.msg` **(string)**
|
|
138
|
+
* `BroadcastMsg.attrs` **(string)**
|
|
139
|
+
* `BroadcastMsg.mtime` **(Int64)**
|
|
140
|
+
|
|
141
|
+
* `getP2PMessage(ouid, desc, num, begin, end, lastid, mtypes, timeout, callback)`: 获取P2P历史消息
|
|
142
|
+
* `ouid`: **(Required | Int64)** 获取和哪个用户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
|
+
* `mtypes`: **(Optional | array(number))** 获取哪些mtype的历史
|
|
149
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
150
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
151
|
+
* `err`: **(Error)**
|
|
152
|
+
* `data`: **(object[num:number, lastid:Int64, begin:Int64, end:Int64, msgs:array[P2PMsg]])**
|
|
153
|
+
* `P2PMsg.id` **(Int64)**
|
|
154
|
+
* `P2PMsg.direction` **(number)**
|
|
155
|
+
* `P2PMsg.mtype` **(number)**
|
|
156
|
+
* `P2PMsg.mid` **(Int64)**
|
|
157
|
+
* `P2PMsg.deleted` **(bool)**
|
|
158
|
+
* `P2PMsg.msg` **(string)**
|
|
159
|
+
* `P2PMsg.attrs` **(string)**
|
|
160
|
+
* `P2PMsg.mtime` **(Int64)**
|
|
161
|
+
|
|
162
|
+
* `getMessage(frrom, mid, xid, type, timeout, callback)`: 获取消息
|
|
163
|
+
* `from`: **(Required | Int64)** 发送者用户 id
|
|
164
|
+
* `mid`: **(Required | Int64)** 消息 id
|
|
165
|
+
* `xid`: **(Required | Int64)** 消息接收方 id (userId/RoomId/GroupId)
|
|
166
|
+
* `type`: **(Required | number)** 接收方类型 (1:p2p, 2:group, 3:room)
|
|
167
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
168
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
169
|
+
* `err`: **(Error)**
|
|
170
|
+
* `data`: **(object[id: Int64, mtype: number, msg: string, attrs: string, mtime: Int64])**
|
|
171
|
+
|
|
172
|
+
* `deleteMessage(from, mid, xid, type, timeout, callback)`: 删除消息
|
|
173
|
+
* `from`: **(Required | Int64)** 发送者用户 id
|
|
174
|
+
* `mid`: **(Required | Int64)** 消息 id
|
|
175
|
+
* `xid`: **(Required | Int64)** 消息接收方 id (userId/RoomId/GroupId)
|
|
176
|
+
* `type`: **(Required | number)** 接收方类型 (1:p2p, 2:group, 3:room)
|
|
177
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
178
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
179
|
+
* `err`: **(Error)**
|
|
180
|
+
* `data`: **(object)**
|
|
@@ -35,7 +35,7 @@ await client.promises.login(uid, credential);
|
|
|
35
35
|
await client.promises.sendChat(peerUid, 'hello', '{}');
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
`credential` 仍须由业务服务端或受控签发工具为当前 UID 签发。不要把项目 `SecretKey` 放入浏览器。其余连接、登录、发送、监听 Push 的业务调用可以继续使用同一套 `RTMClient` API;若使用 `RTMSharedWorkerClient`,默认仍为 TLV v1
|
|
38
|
+
`credential` 仍须由业务服务端或受控签发工具为当前 UID 签发。不要把项目 `SecretKey` 放入浏览器。其余连接、登录、发送、监听 Push 的业务调用可以继续使用同一套 `RTMClient` API;若使用 `RTMSharedWorkerClient`,默认仍为 TLV v1,也可显式选择 FPNN。SharedWorker 配置和能力边界见 [FPNN 多窗口接入](USAGE.md#fpnn-多窗口接入)。
|
|
39
39
|
|
|
40
40
|
## API 与 wire 名称对照
|
|
41
41
|
|
package/docs/Rooms.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# RTM Client Websocket SDK Room API Docs
|
|
2
|
+
|
|
3
|
+
## Index
|
|
4
|
+
|
|
5
|
+
[TOC]
|
|
6
|
+
|
|
7
|
+
## Apis
|
|
8
|
+
|
|
9
|
+
* `enterRoom(rid, timeout, callback)`: 进入房间
|
|
10
|
+
* `rid`: **(Required | Int64)** 房间 id
|
|
11
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
12
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
13
|
+
* `err`: **(Error)**
|
|
14
|
+
* `data`: **(object)**
|
|
15
|
+
|
|
16
|
+
* `leaveRoom(rid, timeout, callback)`: 离开房间
|
|
17
|
+
* `rid`: **(Required | Int64)** 房间 id
|
|
18
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
19
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
20
|
+
* `err`: **(Error)**
|
|
21
|
+
* `data`: **(object)**
|
|
22
|
+
|
|
23
|
+
* `getUserRooms(timeout, callback)`: 获取用户所在的Room
|
|
24
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
25
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
26
|
+
* `err`: **(Error)**
|
|
27
|
+
* `data`: **(array[Int64])**
|
|
28
|
+
|
|
29
|
+
* `setRoomInfo(rid, oinfo, pinfo, timeout, callback) `: 设置房间信息
|
|
30
|
+
* `rid`: **(Required | Int64)** 房间id
|
|
31
|
+
* `oinfo`: **(Optional | string)** 公开信息
|
|
32
|
+
* `pinfo`: **(Optional | string)** 私有信息
|
|
33
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
34
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
35
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
36
|
+
* `data`: **(object)**
|
|
37
|
+
|
|
38
|
+
* `getRoomInfo(rid, timeout, callback) `: 获取房间的公开信息和私有信息,会检查用户是否在房间内
|
|
39
|
+
* `rid`: **(Required | Int64)** 房间id
|
|
40
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
41
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
42
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
43
|
+
* `data`: **(object[oinfo:string, pinfo:string])**
|
|
44
|
+
|
|
45
|
+
* `getRoomOpenInfo(rid, timeout, callback) `: 获取房间的公开信息
|
|
46
|
+
* `rid`: **(Required | Int64)** 房间id
|
|
47
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
48
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
49
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
50
|
+
* `data`: **(object[oinfo:string, pinfo:string])**
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
* `getRoomMembers(rid, timeout, callback)`: 获取房间成员
|
|
54
|
+
* `rid`: **(Required | int64)** RoomID
|
|
55
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
56
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
57
|
+
* `err`: **(Error)**
|
|
58
|
+
* `data`: **(uids: [int64])** 成员列表
|
|
59
|
+
|
|
60
|
+
* `getRoomCount(rids, timeout, callback)`: 获取房间成员数量
|
|
61
|
+
* `rids`: **(Required | [int64])** RoomID列表
|
|
62
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
63
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
64
|
+
* `err`: **(Error)**
|
|
65
|
+
* `data`: **(cn: [string => int])** 房间人数
|
package/docs/System.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# RTM Client Websocket SDK System API Docs
|
|
2
|
+
|
|
3
|
+
## Index
|
|
4
|
+
|
|
5
|
+
[TOC]
|
|
6
|
+
|
|
7
|
+
## Apis
|
|
8
|
+
|
|
9
|
+
* `addAttrs(attrs, timeout, callback)`: 设置客户端信息, 保存在当前链接中, 客户端可以获取到
|
|
10
|
+
* `attrs`: **(Required | object[string, string])** key-value形式的变量
|
|
11
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
12
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
13
|
+
* `err`: **(Error)**
|
|
14
|
+
* `data`: **(object)**
|
|
15
|
+
|
|
16
|
+
* `getAttrs(timeout, callback)`: 获取客户端信息
|
|
17
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
18
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
19
|
+
* `err`: **(Error)**
|
|
20
|
+
* `data`: **(object[attrs:array[Map])**
|
|
21
|
+
* `Map.login` **(string)** 登录时间, UTC时间戳
|
|
22
|
+
* `Map.my` **(string)** 当前链接的`attrs`
|
|
23
|
+
|
|
24
|
+
* `addDebugLog(msg, attrs, timeout, callback)`: 添加debug日志
|
|
25
|
+
* `msg`: **(Required | string)** 调试信息msg
|
|
26
|
+
* `attrs`: **(Required | string)** 调试信息attrs
|
|
27
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
28
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
29
|
+
* `err`: **(Error)**
|
|
30
|
+
* `data`: **(object)**
|
|
31
|
+
|
|
32
|
+
* `addDevice(apptype, devicetoken, timeout, callback)`: 添加设备, 应用信息
|
|
33
|
+
* `apptype`: **(Required | string)** 应用信息
|
|
34
|
+
* `devicetoken`: **(Required | string)** 设备信息
|
|
35
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
36
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
37
|
+
* `err`: **(Error)**
|
|
38
|
+
* `data`: **(object)**
|
|
39
|
+
|
|
40
|
+
* `removeDevice(devicetoken, timeout, callback)`: 删除设备, 应用信息
|
|
41
|
+
* `devicetoken`: **(Required | string)** 设备信息
|
|
42
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
43
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
44
|
+
* `err`: **(Error)**
|
|
45
|
+
* `data`: **(object)**
|
|
46
|
+
|
|
47
|
+
|
package/docs/USAGE.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
| 入口 | 运行环境 | 能力范围 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| `
|
|
9
|
+
| `createClient()` | 支持 SharedWorker 的浏览器 | 推荐入口,默认 TLV、同 UID 多窗口共享连接。 |
|
|
10
|
+
| `createClient({sharing: false})` / `RTMClient` + `protocol: 'tlv-v1'` | 浏览器;Node.js 需注入 `webSocketFactory` | 独立连接;本文 TLV v1 支持矩阵列出的 API。 |
|
|
10
11
|
| `RTMClient` + `protocol: 'fpnn'` | 浏览器 | 旧版兼容入口;兼容 API 仍受 FPNN 服务端能力和部署配置限制。 |
|
|
11
12
|
| `RTMSharedWorkerClient` | 支持 SharedWorker 的浏览器、同源页面 | TLV v1 / FPNN;多个同源页面共享一个 UID 的 RTC 会话,并由 SDK 路由实时 Push。 |
|
|
12
13
|
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
|
|
19
20
|
请随文提供以下环境信息,避免接入者猜测项目配置或尝试从浏览器获取项目密钥:
|
|
20
21
|
|
|
21
|
-
- SDK
|
|
22
|
+
- SDK:测试项目可安装 npm `latest` 标签对应的版本:`npm install @cg-devcenter/rtc-fpnn-webjs-sdk@latest`。若验证的功能尚未进入 npm `latest`,请同时提供 yalc 链接、本地 tarball 或源码工作区。
|
|
22
23
|
- RTC 环境:`pid`、协议(通常为 `tlv-v1`)、完整 WebSocket endpoint,以及应用页面的 origin。
|
|
23
24
|
- 测试身份:发送 UID、接收 UID、账号权限和预期验证场景;不要在文档或任务描述中粘贴长期凭证。
|
|
24
25
|
- credential 获取方式:由哪个业务服务端接口签发、请求需要的登录态/参数、响应 JSON 字段名和 credential 有效期。项目 `SecretKey` 只保留在受控服务端或本机签发工具中。
|
|
@@ -26,11 +27,19 @@
|
|
|
26
27
|
|
|
27
28
|
缺少以上信息时,接入者仍可完成 API 集成,但不能独立验证真实 Gate 登录和消息收发。
|
|
28
29
|
|
|
30
|
+
### 用于实际项目的实时信令
|
|
31
|
+
|
|
32
|
+
- 先确认协议、PID、Gate 地址与签发 credential 的服务端属于同一环境。线上 HTTPS 页面使用 WSS;共享 Worker 应部署在应用同源地址,并被站点 CSP 的 `worker-src` 允许。Vite 优先使用 `/vite` 入口。
|
|
33
|
+
- 全局信令接收器保持 `conversation: null`;设置会话过滤后,该页面只收到匹配的消息 Push。UI 不可见或失去焦点不会改变 SDK 路由,但浏览器挂起页面会延后 JS 执行,静默回收 Worker 的恢复边界见下文。
|
|
34
|
+
- SDK 传送实时消息和信令,不提供音视频采集、编解码或媒体连接。业务应定义消息类型、业务 ID、有效期与处理确认;Gate 接受发送不等于对方业务已处理。
|
|
35
|
+
- 请求中断时发送结果可能未知,SDK 不自动重放。业务根据业务 ID 做幂等处理,并自行决定重试与断线补偿;需要历史补偿时也要确认项目启用对应服务能力。
|
|
36
|
+
- 每个业务调用都处理 callback / Promise 错误,不能只依赖全局事件。TLV 发送错误的嵌套结构、超时、鉴权与支持矩阵见本文对应章节。
|
|
37
|
+
|
|
29
38
|
## 2. 快速开始:登录、收 Push、发消息、关闭
|
|
30
39
|
|
|
31
40
|
### 默认共享接入(当前源码)
|
|
32
41
|
|
|
33
|
-
新入口 `createClient(options)` 默认启用 SharedWorker,默认使用 TLV;显式 `protocol: 'fpnn'`
|
|
42
|
+
新入口 `createClient(options)` 默认启用 SharedWorker,默认使用 TLV;显式 `protocol: 'fpnn'` 也可共享。请使用 npm `latest` 标签对应的版本;若该标签尚未包含此入口或 FPNN 共享扩展,请使用本地构建/yalc。旧 `RTMClient`、`RTMSharedWorkerClient` 的业务 API 保留;SharedWorker 自动按 PID、协议、UID 和 Gate endpoint 区分环境;同一环境下两种 SDK 入口复用同一会话。
|
|
34
43
|
|
|
35
44
|
Vite 项目从 `/vite` 导入,普通 HTML 把 SDK 与 Worker bundle 部署到同源目录;业务不需要填写 Worker 名称。下面可作为 Vite 页面脚本使用,替换项目配置和 credential 接口:
|
|
36
45
|
|
|
@@ -53,7 +62,8 @@ client.on('SharedWorkerError', (error) => console.error('Shared connection', err
|
|
|
53
62
|
|
|
54
63
|
async function start() {
|
|
55
64
|
// 按 UID 挂接共享会话,尚未登录时不会建立 Gate WebSocket。
|
|
56
|
-
|
|
65
|
+
await client.whenReady(uid);
|
|
66
|
+
const session = client.getSharedSession();
|
|
57
67
|
let credential;
|
|
58
68
|
if (session.status === 'idle') {
|
|
59
69
|
const response = await fetch('/api/rtc/credential?uid=' + encodeURIComponent(uid), {
|
|
@@ -80,14 +90,16 @@ UID 使用正整数或十进制字符串;超过 JavaScript 安全整数范围
|
|
|
80
90
|
| `createClient(options)` | 使用扁平客户端配置,默认 `sharing: true`、`protocol: 'tlv-v1'`;浏览器没有 SharedWorker 时明确抛出 `RTM_SHARED_WORKER_UNSUPPORTED`。 |
|
|
81
91
|
| `sharing: false` | 返回独立的 `RTMClient`,新入口仍默认 TLV;Node.js 或需要文件上传/函数型配置时显式选择,FPNN 仍仅支持浏览器。不会因共享初始化失败自动降级。 |
|
|
82
92
|
| `uid` | 可选;提供时立即挂接共享 Worker,适合收件箱自动观察其他页面登录。省略时在 `login()` / `loginIfNeeded()` / `whenReady(uid)` 时挂接。一个实例固定一个 UID;切换账号需 detach 后创建新实例。 |
|
|
83
|
-
| `workerName` / `workerUrl` |
|
|
84
|
-
| `whenReady(uid?)` |
|
|
93
|
+
| `workerName` / `workerUrl` | 可选高级覆盖项;默认共享身份由 PID、协议、UID 和 Gate endpoint 生成,endpoint 不需要单独配置。默认路径沿用脚本同目录规则,Vite `/vite` 自动打包。`workerNamespace` 仍可隔离应用。 |
|
|
94
|
+
| `whenReady(uid?)` | 等待首次挂接并返回当时的快照;后续状态用 `getSharedSession()` 或 `SharedSessionState` 读取。尚未绑定 UID 且未传 UID 时立即 reject `RTM_SHARED_UID_REQUIRED`,不会无限等待。 |
|
|
85
95
|
| `promises.login(uid, credential?, timeout?)` | 成功 resolve `{accepted: true, errorCode}`,RTC 拒绝或本地/Worker 错误 reject;并发同 UID 登录只发一次鉴权。`loginIfNeeded()` 保留 `{accepted, errorCode, reused, uid}` 的结果约定。 |
|
|
86
96
|
| `login(uid, credential?, callback?, timeout?)` | RTC 拒绝与本地/Worker 失败均回调 `callback(false, numericCode)`;本地/Worker 失败的详细错误通过 `SharedWorkerError` 事件提供。仅 `accepted === true` 表示登录成功;`promises.login()` 会 reject 详细错误。 |
|
|
87
97
|
| `destroy()` | 只 detach 当前页面;最后一页离开后按 `idleShutdownTimeout` 回收共享连接。`bye()` / `close()` 才结束所有共享页面的会话。 |
|
|
88
98
|
| 会话路由与业务 API | 沿用 `setConversation()`、`processor`、重连和原协议的业务返回;共享模式不支持文件发送或函数型配置。绑定 UID 前的业务请求明确报 `RTM_SHARED_UID_REQUIRED`。 |
|
|
89
99
|
|
|
90
|
-
共享还要求同一浏览器配置文件、origin 和 Worker URL
|
|
100
|
+
共享还要求同一浏览器配置文件、origin 和 Worker URL。同一浏览器配置文件、origin、Worker URL、PID、协议、UID 和 Gate endpoint 的页面会复用一条连接;Gate 地址不同会自动隔离。**同一共享身份下的 `clientOptions` 必须一致**;认证、重连或其他参数不同会初始化失败,不会覆盖已有连接。`createClient()` 和 `RTMSharedWorkerClient` 自动使用相同规则,同一应用混用入口也能加入同一会话。显式传入 `workerName` 或 `workerNamespace` 时,共享页面仍须保持一致。
|
|
101
|
+
|
|
102
|
+
Gate endpoint 已自动区分测试、预发和生产环境,通常不需要设置 `workerNamespace`。只有同一 endpoint 下确实需要两组独立登录态时,才为各组设置不同 namespace。
|
|
91
103
|
|
|
92
104
|
### 原有单连接接入
|
|
93
105
|
|
|
@@ -232,7 +244,7 @@ import rtm from '@cg-devcenter/rtc-fpnn-webjs-sdk/vite';
|
|
|
232
244
|
|
|
233
245
|
`ErrorRecorder(error)` 用于连接、协议、自动重连和登录错误,不会代替普通业务请求的 callback 或 Promise rejection。业务失败应检查各自调用结果。请求超时与连接中断会结束挂起调用;连接中断时写入结果可能未知,SDK 不自动重放,业务应按幂等规则决定是否重试。
|
|
234
246
|
|
|
235
|
-
`bye()`
|
|
247
|
+
`bye()` 与普通业务调用不同,是异步的协议关闭握手。结束整个会话时,使用有超时的 Promise,并在 `finally` 中 `close()` 后 `destroy()`;不必等待 `SessionClosed` 才能清理:
|
|
236
248
|
|
|
237
249
|
```js
|
|
238
250
|
try {
|
|
@@ -240,22 +252,22 @@ try {
|
|
|
240
252
|
} catch (error) {
|
|
241
253
|
console.warn('Gate did not confirm close', error);
|
|
242
254
|
} finally {
|
|
243
|
-
client.destroy();
|
|
255
|
+
try { client.close(); } finally { client.destroy(); }
|
|
244
256
|
}
|
|
245
257
|
```
|
|
246
258
|
|
|
247
|
-
Promise 成功表示 Gate
|
|
259
|
+
Promise 成功表示 Gate 已应答关闭请求。直接结束整个会话可调用 `close()`,这可能中止尚未完成的 `bye()`。共享模式下只关闭当前页面或卸载组件时仅调用 `destroy()`,不要调用 `bye()` / `close()`,其他页面会继续使用共享会话。独立 `RTMClient.destroy()` 则会关闭其自身连接。
|
|
248
260
|
|
|
249
261
|
常用事件:`ErrorRecorder(error)`、`ReloginCompleted(successful, retryAgain, errorCode, retriedCount)`、`SessionClosed(errorCode)`。TLV 可靠 Push 由 SDK 自动 ACK,并按 `message_ref` 去重;这不等于离线补拉或业务存储。
|
|
250
262
|
|
|
251
263
|
## 4. 同 UID 多窗口:SharedWorker
|
|
252
264
|
|
|
253
|
-
`RTMSharedWorkerClient` 是 SDK 提供的同源多页面连接复用能力。每个页面创建一个客户端端口,SDK 在 SharedWorker 内维护一个 `RTMClient` 和一条 WebSocket。普通浏览器脚本加载时,SDK 默认从主 SDK 脚本地址推导同目录下的 `rtm.shared-worker.js`;部署在其他位置时,需显式传入同源 `workerUrl`。Vite 项目推荐从 `@cg-devcenter/rtc-fpnn-webjs-sdk/vite` 导入,SDK 会自动把 Worker 作为构建资源并配置地址。其他构建工具可在其资源管线支持时导入 `@cg-devcenter/rtc-fpnn-webjs-sdk/shared-worker?url`,再将解析出的 URL 传给 `workerUrl`。共享身份需要相同浏览器配置文件、origin、解析后的 Worker URL、`workerName` 和结构一致的 `clientOptions`。一个 Worker 只登录一个 UID、使用一种协议;传入 `uid`
|
|
265
|
+
`RTMSharedWorkerClient` 是 SDK 提供的同源多页面连接复用能力。每个页面创建一个客户端端口,SDK 在 SharedWorker 内维护一个 `RTMClient` 和一条 WebSocket。普通浏览器脚本加载时,SDK 默认从主 SDK 脚本地址推导同目录下的 `rtm.shared-worker.js`;部署在其他位置时,需显式传入同源 `workerUrl`。Vite 项目推荐从 `@cg-devcenter/rtc-fpnn-webjs-sdk/vite` 导入,SDK 会自动把 Worker 作为构建资源并配置地址。其他构建工具可在其资源管线支持时导入 `@cg-devcenter/rtc-fpnn-webjs-sdk/shared-worker?url`,再将解析出的 URL 传给 `workerUrl`。共享身份需要相同浏览器配置文件、origin、解析后的 Worker URL、`workerName` 和结构一致的 `clientOptions`。一个 Worker 只登录一个 UID、使用一种协议;传入 `uid` 后,SDK 根据协议、PID、UID 和实际 Gate endpoint 自动生成稳定身份,因此不同 Gate 环境自动使用不同连接;同一名称下其他 `clientOptions` 不一致会明确报错。`createSharedWorkerName()` 可显式传 `endpoint` 构造隔离名称。SDK 升级后请刷新同一 origin 下需要共享会话的旧页面,避免新旧版本各自挂在不同 Worker 身份上。
|
|
254
266
|
|
|
255
267
|
| API / 选项 | 参数与结果 |
|
|
256
268
|
| --- | --- |
|
|
257
|
-
| `new RTMSharedWorkerClient(options)` | `clientOptions` 必填;`protocol` 省略时仍为 TLV v1,提供 `pid` 和完整 `tlvEndpoint`。选择 FPNN 时显式设置 `protocol: 'fpnn'`,并提供 `endpoint` 或 `ssl_endpoint`(`host[:port]`,不含 URL scheme 和路径)。`workerUrl` 可选,同源 Worker 脚本 URL;普通浏览器脚本省略时 SDK 推导加载 SDK 的脚本同目录下的 `rtm.shared-worker.js`,Vite 项目应使用 `/vite` 入口自动打包 Worker。提供 `uid` 且省略 `workerName` 时,SDK 根据协议、`clientOptions.pid`、`uid
|
|
258
|
-
| `whenReady()` | 等 Worker
|
|
269
|
+
| `new RTMSharedWorkerClient(options)` | `clientOptions` 必填;`protocol` 省略时仍为 TLV v1,提供 `pid` 和完整 `tlvEndpoint`。选择 FPNN 时显式设置 `protocol: 'fpnn'`,并提供 `endpoint` 或 `ssl_endpoint`(`host[:port]`,不含 URL scheme 和路径)。`workerUrl` 可选,同源 Worker 脚本 URL;普通浏览器脚本省略时 SDK 推导加载 SDK 的脚本同目录下的 `rtm.shared-worker.js`,Vite 项目应使用 `/vite` 入口自动打包 Worker。提供 `uid` 且省略 `workerName` 时,SDK 根据协议、`clientOptions.pid`、`uid`、实际 Gate endpoint 和 `workerNamespace` 生成稳定名称;若需要自行构造名称,可调用 `createSharedWorkerName({protocol, pid, uid, endpoint, namespace})`。若 `uid` 和 `workerName` 都省略,会使用通用默认名称;多账号应用应传其中一个,避免不同 UID 页面加入同一个 Worker。`readyTimeout` 默认 10000 毫秒;`idleShutdownTimeout` 默认 5000 毫秒,最后一个页面 detach 后等待这段时间再关闭共享连接,设为 `0` 表示立即关闭;同一 Worker 的所有页面必须使用相同值。`conversation` 可选,默认 `null` 接收全部会话 Push。 |
|
|
270
|
+
| `whenReady()` | 等 Worker 首次初始化并返回 `{status, uid}` 初始快照;再次调用不会刷新快照,当前状态用 `getSharedSession()`。初始化失败时 Promise reject,SDK 会自动 detach 并关闭当前页面的端口。 |
|
|
259
271
|
| `getSharedSession()` | 同步返回本页面最近观察到的 `{status, uid}`。 |
|
|
260
272
|
| `loginIfNeeded(uid, credential?, timeout?)` | 同 UID 会话已登录则复用;登录中则加入该登录;会话空闲时须提供服务端签发的 credential。resolve `{accepted, errorCode, reused, uid}`。 |
|
|
261
273
|
| `setConversation(conversation, callback?)` | 修改当前页面 Push 路由;传 `null` 接收全部会话。出错时通过可选 callback 返回。 |
|
|
@@ -277,54 +289,68 @@ async function getCredential() {
|
|
|
277
289
|
return result.credential;
|
|
278
290
|
}
|
|
279
291
|
|
|
280
|
-
const shared = new rtm.RTMSharedWorkerClient({
|
|
281
|
-
uid, // SDK 用 PID、UID 和 endpoint 生成稳定的 Worker 名称;仅用于命名,不会自动登录。
|
|
282
|
-
clientOptions: {
|
|
283
|
-
protocol: 'tlv-v1',
|
|
284
|
-
pid: 12345,
|
|
285
|
-
tlvEndpoint: 'wss://<gate-host>/service/websocket',
|
|
286
|
-
autoReconnect: true,
|
|
287
|
-
},
|
|
288
|
-
conversation: null, // 收件箱接收所有会话;聊天页可只订阅一个会话。
|
|
289
|
-
});
|
|
290
|
-
|
|
291
292
|
function renderPush(event) { console.log('RTC Push', event); }
|
|
292
293
|
function renderSession(session) { console.log('Shared RTC session', session); }
|
|
293
294
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
rtm.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
295
|
+
let shared = null;
|
|
296
|
+
function createSharedClient() {
|
|
297
|
+
const client = new rtm.RTMSharedWorkerClient({
|
|
298
|
+
uid, // SDK 自动按 PID、协议、UID 和 Gate endpoint 复用同环境会话;此 UID 仅用于挂接,不会自动登录。
|
|
299
|
+
clientOptions: {
|
|
300
|
+
protocol: 'tlv-v1',
|
|
301
|
+
pid: 12345,
|
|
302
|
+
tlvEndpoint: 'wss://<gate-host>/service/websocket',
|
|
303
|
+
autoReconnect: true,
|
|
304
|
+
},
|
|
305
|
+
conversation: null, // 收件箱接收所有会话;聊天页可只订阅一个会话。
|
|
306
|
+
});
|
|
307
|
+
[
|
|
308
|
+
rtm.RTMConfig.TLV_SERVER_PUSH.recvMessage,
|
|
309
|
+
rtm.RTMConfig.TLV_SERVER_PUSH.recvGroupMessage,
|
|
310
|
+
rtm.RTMConfig.TLV_SERVER_PUSH.recvRoomMessage,
|
|
311
|
+
rtm.RTMConfig.TLV_SERVER_PUSH.recvBroadcastMessage,
|
|
312
|
+
].forEach((name) => client.processor.on(name, renderPush));
|
|
313
|
+
client.on('SharedSessionState', renderSession);
|
|
314
|
+
client.on('SharedWorkerError', (error) => {
|
|
315
|
+
console.error('SharedWorker client is no longer usable', error);
|
|
316
|
+
client.destroy();
|
|
317
|
+
if (shared === client) shared = null;
|
|
318
|
+
// 显示“重新连接”操作;用户触发后再次调用 connectInbox()。
|
|
319
|
+
});
|
|
320
|
+
return client;
|
|
321
|
+
}
|
|
301
322
|
|
|
302
323
|
async function connectInbox() {
|
|
303
|
-
|
|
324
|
+
if (!shared) shared = createSharedClient();
|
|
325
|
+
const client = shared;
|
|
326
|
+
await client.whenReady();
|
|
327
|
+
const snapshot = client.getSharedSession();
|
|
304
328
|
// 建议先让一个页面登录,再打开其余页面。已登录/正在登录时无需再取 credential。
|
|
305
329
|
const credential = snapshot.status === 'idle' ? await getCredential() : undefined;
|
|
306
|
-
const result = await
|
|
330
|
+
const result = await client.loginIfNeeded(uid, credential);
|
|
307
331
|
if (!result.accepted) throw Object.assign(new Error('RTM login rejected'), { code: result.errorCode });
|
|
308
332
|
console.log('Shared session ready', result);
|
|
309
333
|
}
|
|
310
334
|
|
|
311
335
|
connectInbox().catch(console.error);
|
|
336
|
+
// 只有 SDK 报告 SharedWorkerError 后才重建 client;新 client 的登录快照可能是 idle,届时再取 credential。
|
|
312
337
|
// 当前页关闭时 SDK 会自动 detach(BFCache 页面例外);应用也可主动调用:
|
|
313
|
-
// shared
|
|
338
|
+
// shared?.destroy();
|
|
314
339
|
```
|
|
315
340
|
|
|
316
341
|
- 首个页面在 UID 尚未登录时传入服务端签发的 credential;其他同 UID 页面在已登录时不需要 credential。若它们赶在首次登录完成前打开,`loginIfNeeded()` 会加入同一次登录。
|
|
317
|
-
- `whenReady()`
|
|
342
|
+
- `whenReady()` 返回首次挂接快照 `{status, uid}`,当前状态用 `getSharedSession()`;`loginIfNeeded(uid, credential?, timeout?)` 返回 `{accepted, errorCode, reused, uid}`。credential 不会广播到页面。
|
|
318
343
|
- `conversation: {type: 'direct'|'group'|'room', id}` 只把匹配的私聊发送者、群或房间 Push 路由到该页面;`null` 接收全量会话 Push。运行中可调用 `setConversation(...)` 切换路由。
|
|
319
344
|
- `event.broadcast` 和 `event.kicked` 发给全部页面;`event.room_removed` 发给订阅该房间的页面。页面自己的消息监听器由 SDK 端口分发。
|
|
320
345
|
- `destroy()` 只 detach 当前页面;还有页面连接时共享连接继续运行。任一页面调用 `bye()` / `close()` 会结束所有页面共享的 RTC 会话。
|
|
321
|
-
- 最后一个页面 detach 后,SDK 默认等待 5 秒再销毁 RTMClient
|
|
346
|
+
- 最后一个页面 detach 后,SDK 默认等待 5 秒再销毁 RTMClient 和连接;宽限期内新页面接入会取消回收。浏览器也可能在页面挂起或资源回收时结束 Worker,但 SDK 当前没有就绪后的心跳检测,浏览器静默回收不保证触发事件。
|
|
347
|
+
- 收到 `SharedWorkerError` 时,表示 SDK 检测到当前页面到 Worker 的错误(例如初始化失败、Worker `error` 或消息端口错误),可丢弃旧 client 并用相同连接配置创建新 client。此事件不是 Worker 被浏览器回收的通用通知;如果浏览器静默结束 Worker,页面可能无法及时获知。新 client 的登录快照若为 `idle`,重新登录时必须取得服务端为该 UID 签发的 credential。SDK 不在页面、Worker 或存储中持久化 credential,也不会在 Worker 进程丢失后自动重登。
|
|
322
348
|
- SharedWorker 仅共享实时连接和 Push,不同步页面草稿、未读 UI 或消息列表,也不持久化登录态。它不跨 origin、浏览器配置文件或 InPrivate 窗口共享;不支持时 SDK 不静默降级为每页一条连接。
|
|
323
349
|
- `clientOptions` 必须可结构化克隆;不能包含 `requestMetadataProvider`、元数据函数或 `webSocketFactory`。SharedWorker 只接受静态 `requestMetadata` 对象。
|
|
324
350
|
|
|
325
351
|
### FPNN 多窗口接入
|
|
326
352
|
|
|
327
|
-
|
|
353
|
+
FPNN SharedWorker 的可用性以 npm `latest` 标签对应的 SDK 版本为准;若该标签版本尚未包含此扩展,请使用本地构建或 yalc。Node.js 仍只支持 TLV。
|
|
328
354
|
|
|
329
355
|
首次登录、后续窗口 `loginIfNeeded()`、`SharedSessionState`、路由和 detach 的使用方式与上面的 TLV 示例相同。FPNN 只改变连接配置和 Push 订阅;以下片段假定已加载 `rtm` 并取得 `pid`、`uid`、`peerUid`、FPNN Gate 地址及首次登录所需的 credential:
|
|
330
356
|
|
|
@@ -352,7 +378,7 @@ await shared.promises.sendChat(peerUid, 'hello', '{}');
|
|
|
352
378
|
// 页面离开时 SDK 自动 detach;也可显式 shared.destroy()。
|
|
353
379
|
```
|
|
354
380
|
|
|
355
|
-
FPNN 的 `endpoint` / `ssl_endpoint` 接收 `host[:port]`,SDK 补上 `ws://` / `wss://` 和 `/service/websocket`;它与 TLV 的完整 URL 配置不同。自动 Worker identity
|
|
381
|
+
FPNN 的 `endpoint` / `ssl_endpoint` 接收 `host[:port]`,SDK 补上 `ws://` / `wss://` 和 `/service/websocket`;它与 TLV 的完整 URL 配置不同。自动 Worker identity 包含协议,因此同 UID 的 FPNN / TLV 页面不会共享一条连接。若显式指定相同 `workerName` 却传入不同协议或配置,后加入页面初始化失败,不会覆盖已有会话。
|
|
356
382
|
|
|
357
383
|
FPNN Push 保留 `SERVER_PUSH` 事件和 `from / gid / rid / mid / msg` 等字段;TLV 保留 `TLV_SERVER_PUSH` 事件及其字段。共享层只提取内部会话路由,不把 FPNN 业务数据包装成 TLV,也不执行额外的 ACK 或去重。FPNN 的聊天、命令、通用消息、文件接收事件均按会话过滤;广播和被踢下线事件发给所有页面。`sendFile` / `sendGroupFile` / `sendRoomFile` 在两种模式下都本地拒绝,文件接收和 FPNN `fileToken` 查询不在此限制内。传统参数与 Push 细节见 [协议迁移对照](PROTOCOL_MIGRATION.md) 和 [事件处理说明](EventProcess.md)。
|
|
358
384
|
|
package/docs/Users.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# RTM Client Websocket SDK User API Docs
|
|
2
|
+
|
|
3
|
+
## Index
|
|
4
|
+
|
|
5
|
+
[TOC]
|
|
6
|
+
|
|
7
|
+
## Apis
|
|
8
|
+
|
|
9
|
+
* `getUserGroups(timeout, callback)`: 获取用户所在的Group
|
|
10
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
11
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
12
|
+
* `err`: **(Error)**
|
|
13
|
+
* `data`: **(array[Int64])**
|
|
14
|
+
|
|
15
|
+
* `getOnlineUsers(uids, timeout, callback)`: 获取在线用户
|
|
16
|
+
* `uids`: **(Required | array[Int64])** 多个用户 id
|
|
17
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
18
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
19
|
+
* `err`: **(Error)**
|
|
20
|
+
* `data`: **(array[Int64])**
|
|
21
|
+
|
|
22
|
+
* `setUserInfo(oinfo, pinfo, timeout, callback) `: 设置用户信息
|
|
23
|
+
* `oinfo`: **(Optional | string)** 公开信息
|
|
24
|
+
* `pinfo`: **(Optional | string)** 私有信息
|
|
25
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
26
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
27
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
28
|
+
* `data`: **(object)**
|
|
29
|
+
|
|
30
|
+
* `getUserInfo(timeout, callback) `: 获取用户信息
|
|
31
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
32
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
33
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
34
|
+
* `data`: **(object[oinfo:string, pinfo:string])**
|
|
35
|
+
|
|
36
|
+
* `getUserOpenInfo(uids, timeout, callback) `: 获取用户信息
|
|
37
|
+
* `uids`: **(Required | array(Int64))** 用户id列表
|
|
38
|
+
* `timeout`: **(Optional | number)** 超时时间(ms), 默认: `20 * 1000`
|
|
39
|
+
* `callback`: **(Optional | function)** 回调方法, `callback(err, data)`
|
|
40
|
+
* `err`: **(object[mid:Int64, error:Error])**
|
|
41
|
+
* `data`: **(object[info:map<string, string>])**
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|