@cg-devcenter/rtc-fpnn-webjs-sdk 1.0.0-cg.2
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 +61 -0
- package/dist/rtm.d.ts +208 -0
- package/dist/rtm.min.js +27 -0
- package/docs/TLV.md +62 -0
- package/docs/TLV_CONTRACT.md +180 -0
- package/docs/USAGE.md +168 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @cg-devcenter/rtc-fpnn-webjs-sdk
|
|
2
|
+
|
|
3
|
+
RTC WebSocket Client SDK。新接入使用 `tlv-v1`;`fpnn` 仅保留浏览器兼容能力。
|
|
4
|
+
|
|
5
|
+
## 模块导出
|
|
6
|
+
|
|
7
|
+
- `RTMClient`
|
|
8
|
+
- `RTMConfig`
|
|
9
|
+
- `RTMProcessor`
|
|
10
|
+
- `TLVCodec`
|
|
11
|
+
- `TLVWebSocketClient`
|
|
12
|
+
|
|
13
|
+
## 客户端构造
|
|
14
|
+
|
|
15
|
+
`new rtm.RTMClient(options)`
|
|
16
|
+
|
|
17
|
+
| 参数 | 类型 | TLV v1 规则 |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `pid` | `number` | 必填。 |
|
|
20
|
+
| `protocol` | `'tlv-v1' \| 'fpnn'` | 新接入为 `'tlv-v1'`。 |
|
|
21
|
+
| `tlvEndpoint` | `string` | 必填完整 WebSocket URL。 |
|
|
22
|
+
| `autoReconnect` | `boolean` | 缺省为 `true`。 |
|
|
23
|
+
| `connectionTimeout` | `number` | 毫秒。 |
|
|
24
|
+
| `requestMetadata` | `() => Record<string, unknown>` | 可返回 `trace`、`sent_ms`。 |
|
|
25
|
+
| `webSocketFactory` | `(url) => RTMWebSocket` | 无全局 `WebSocket` 时必填。 |
|
|
26
|
+
| `locale` | `string` | 映射为 `auth.login.locale`。 |
|
|
27
|
+
| `clientVersion` | `string` | 映射为 `auth.login.client_ver`。 |
|
|
28
|
+
|
|
29
|
+
`fpnn` 仅支持浏览器。TLV credential 由业务服务端签发,项目密钥不属于客户端参数。
|
|
30
|
+
|
|
31
|
+
## 生命周期 API
|
|
32
|
+
|
|
33
|
+
| API | 回调/结果 |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `login(uid, credential, callback, timeout)` | `callback(accepted, errorCode)` |
|
|
36
|
+
| `bye()` | 发送 `connection.close`。 |
|
|
37
|
+
| `close()` | 主动关闭。 |
|
|
38
|
+
| `startAutoReconnect()` | 关闭当前连接后重新登录。 |
|
|
39
|
+
| `destroy()` | 释放客户端资源。 |
|
|
40
|
+
| `getServerTime(timeout, callback)` | `callback(err, data)` |
|
|
41
|
+
|
|
42
|
+
`uid`、消息 ID、群 ID、房间 ID 和时间游标超出安全整数范围时使用 `RTMConfig.Int64`。
|
|
43
|
+
|
|
44
|
+
## Push API
|
|
45
|
+
|
|
46
|
+
通过 `client.processor.on(name, callback)` 注册:
|
|
47
|
+
|
|
48
|
+
- `RTMConfig.TLV_SERVER_PUSH.recvMessage`:`event.direct`
|
|
49
|
+
- `RTMConfig.TLV_SERVER_PUSH.recvGroupMessage`:`event.group`
|
|
50
|
+
- `RTMConfig.TLV_SERVER_PUSH.recvRoomMessage`:`event.room`
|
|
51
|
+
- `RTMConfig.TLV_SERVER_PUSH.recvBroadcastMessage`:`event.broadcast`
|
|
52
|
+
- `RTMConfig.TLV_SERVER_PUSH.kickOut`:`event.kicked`
|
|
53
|
+
- `RTMConfig.TLV_SERVER_PUSH.kickOutRoom`:`event.room_removed`
|
|
54
|
+
|
|
55
|
+
可靠消息 Push 由 SDK 自动 ACK 并按 `message_ref` 去重。
|
|
56
|
+
|
|
57
|
+
## API 文档
|
|
58
|
+
|
|
59
|
+
- [公开方法与参数](docs/USAGE.md)
|
|
60
|
+
- [TLV v1 wire 契约](docs/TLV_CONTRACT.md)
|
|
61
|
+
- [TLV v1 传输规则](docs/TLV.md)
|
package/dist/rtm.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
export as namespace rtm;
|
|
2
|
+
|
|
3
|
+
declare namespace rtm {
|
|
4
|
+
type RTMProtocol = 'fpnn' | 'tlv-v1';
|
|
5
|
+
|
|
6
|
+
interface RTMRegressiveStrategy {
|
|
7
|
+
startConnectFailedCount: number;
|
|
8
|
+
maxIntervalSeconds: number;
|
|
9
|
+
linearRegressiveCount: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface RTMWebSocket {
|
|
13
|
+
binaryType?: string;
|
|
14
|
+
send(data: unknown): void;
|
|
15
|
+
close(code?: number, reason?: string): void;
|
|
16
|
+
onopen?: ((event?: unknown) => void) | null;
|
|
17
|
+
onmessage?: ((event: { data: unknown }) => void) | null;
|
|
18
|
+
onerror?: ((event?: unknown) => void) | null;
|
|
19
|
+
onclose?: ((event?: unknown) => void) | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface RTMClientOptions {
|
|
23
|
+
pid: number;
|
|
24
|
+
protocol?: RTMProtocol;
|
|
25
|
+
endpoint?: string;
|
|
26
|
+
ssl_endpoint?: string;
|
|
27
|
+
tlvEndpoint?: string;
|
|
28
|
+
tlv_endpoint?: string;
|
|
29
|
+
autoReconnect?: boolean;
|
|
30
|
+
connectionTimeout?: number;
|
|
31
|
+
requestTimeout?: number;
|
|
32
|
+
locale?: string;
|
|
33
|
+
clientVersion?: string;
|
|
34
|
+
authSec?: number;
|
|
35
|
+
authVer?: 2;
|
|
36
|
+
requestMetadata?: () => Record<string, unknown>;
|
|
37
|
+
requestMetadataProvider?: () => Record<string, unknown>;
|
|
38
|
+
webSocketFactory?: (url: string) => RTMWebSocket;
|
|
39
|
+
attrs?: Record<string, string>;
|
|
40
|
+
tlvHeartbeatIdleMs?: number;
|
|
41
|
+
tlvHeartbeatTimeoutMs?: number;
|
|
42
|
+
pushDedupTtlMs?: number;
|
|
43
|
+
regressiveStrategy?: RTMRegressiveStrategy;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class RTMClient {
|
|
48
|
+
constructor(options: RTMClientOptions);
|
|
49
|
+
processor;
|
|
50
|
+
login(uid, token, callback, timeout);
|
|
51
|
+
destroy();
|
|
52
|
+
getServerTime(timeout, callback);
|
|
53
|
+
sendMessage(to, mtype, msg, attrs, mid, timeout, callback);
|
|
54
|
+
sendMessages(tos, mtype, msg, attrs, mid, timeout, callback);
|
|
55
|
+
sendGroupMessage(gid, mtype, msg, attrs, mid, timeout, callback);
|
|
56
|
+
sendRoomMessage(rid, mtype, msg, attrs, mid, timeout, callback);
|
|
57
|
+
getUnreadMessage(clear, withLogout, timeout, callback);
|
|
58
|
+
getP2PUnreadMessageNum(uids, mtime, mtypes, timeout, callback);
|
|
59
|
+
getGroupUnreadMessageNum(gids, mtime, mtypes, timeout, callback);
|
|
60
|
+
cleanUnreadMessage(timeout, callback);
|
|
61
|
+
setSessionRead(category, xid, readSeq, timeout, callback);
|
|
62
|
+
getSession(timeout, callback);
|
|
63
|
+
getGroupMessage(gid, desc, num, begin, end, lastid, mtypes, timeout, callback);
|
|
64
|
+
getRoomMessage(rid, desc, num, begin, end, lastid, mtypes, timeout, callback);
|
|
65
|
+
getBroadcastMessage(desc, num, begin, end, lastid, mtypes, timeout, callback);
|
|
66
|
+
getP2PMessage(ouid, desc, num, begin, end, lastid, mtypes, timeout, callback);
|
|
67
|
+
getP2PMessageByMessageId(ouid, mid, desc, num, begin, end, mtypes, timeout, callback);
|
|
68
|
+
getGroupMessageByMessageId(gid, mid, desc, num, begin, end, mtypes, timeout, callback);
|
|
69
|
+
getRoomMessageByMessageId(rid, mid, desc, num, begin, end, mtypes, timeout, callback);
|
|
70
|
+
getBroadcastMessageByMessageId(mid, desc, num, begin, end, mtypes, timeout, callback);
|
|
71
|
+
getP2PMessageCount(ouid, begin, end, mtypes, timeout, callback);
|
|
72
|
+
getGroupMessageCount(gid, begin, end, mtypes, timeout, callback);
|
|
73
|
+
getRoomMessageCount(rid, begin, end, mtypes, timeout, callback);
|
|
74
|
+
getBroadcastMessageCount(begin, end, mtypes, timeout, callback);
|
|
75
|
+
fileToken(cmd, tos, to, rid, gid, timeout, callback);
|
|
76
|
+
close();
|
|
77
|
+
startAutoReconnect();
|
|
78
|
+
bye();
|
|
79
|
+
addAttrs(attrs, timeout, callback);
|
|
80
|
+
getAttrs(timeout, callback);
|
|
81
|
+
addDebugLog(msg, attrs, timeout, callback);
|
|
82
|
+
addDevice(apptype, devicetoken, timeout, callback);
|
|
83
|
+
removeDevice(devicetoken, timeout, callback);
|
|
84
|
+
setTranslationLanguage(targetLanguage, timeout, callback);
|
|
85
|
+
translate(originalMessage, originalLanguage, targetLanguage, type, profanity, timeout, callback);
|
|
86
|
+
profanity(text, classify, timeout, callback);
|
|
87
|
+
textCheck(text, strategyId, timeout, callback);
|
|
88
|
+
imageCheck(image, type, strategyId, timeout, callback);
|
|
89
|
+
audioCheck(audio, type, lang, codec, srate, strategyId, timeout, callback);
|
|
90
|
+
videoCheck(video, type, videoName, strategyId, timeout, callback);
|
|
91
|
+
speech2Text(audio, type, lang, codec, srate, timeout, callback);
|
|
92
|
+
getGroupsOpenInfo(gids, timeout, callback);
|
|
93
|
+
getRoomsOpenInfo(rids, timeout, callback);
|
|
94
|
+
getRoomMembers(rid, timeout, callback);
|
|
95
|
+
getRoomCount(rids, timeout, callback);
|
|
96
|
+
addDevicePushOption(type, xid, mtypes, timeout, callback);
|
|
97
|
+
removeDevicePushOption(type, xid, mtypes, timeout, callback);
|
|
98
|
+
getDevicePushOption(timeout, callback);
|
|
99
|
+
addFriends(friends, timeout, callback);
|
|
100
|
+
deleteFriends(friends, timeout, callback);
|
|
101
|
+
getFriends(timeout, callback);
|
|
102
|
+
addGroupMembers(gid, uids, timeout, callback);
|
|
103
|
+
deleteGroupMembers(gid, uids, timeout, callback);
|
|
104
|
+
getGroupMembers(gid, online, timeout, callback);
|
|
105
|
+
getGroupCount(gid, online, timeout, callback);
|
|
106
|
+
getUserGroups(timeout, callback);
|
|
107
|
+
enterRoom(rid, timeout, callback);
|
|
108
|
+
enterRooms(rids, timeout, callback);
|
|
109
|
+
leaveRoom(rid, timeout, callback);
|
|
110
|
+
getUserRooms(timeout, callback);
|
|
111
|
+
getUserRoomsAndLastMessage(mtypes, timeout, callback);
|
|
112
|
+
getOnlineUsers(uids, timeout, callback);
|
|
113
|
+
deleteMessage(from, mid, xid, type, timeout, callback);
|
|
114
|
+
getMessage(from, mid, xid, type, timeout, callback);
|
|
115
|
+
sendChat(to, msg, attrs, mid, timeout, callback);
|
|
116
|
+
sendAudio(to, msg, attrs, mid, timeout, callback);
|
|
117
|
+
sendCmd(to, msg, attrs, mid, timeout, callback);
|
|
118
|
+
sendGroupChat(gid, msg, attrs, mid, timeout, callback);
|
|
119
|
+
sendGroupAudio(gid, msg, attrs, mid, timeout, callback);
|
|
120
|
+
sendGroupCmd(gid, msg, attrs, mid, timeout, callback);
|
|
121
|
+
sendRoomChat(rid, msg, attrs, mid, timeout, callback);
|
|
122
|
+
sendRoomAudio(rid, msg, attrs, mid, timeout, callback);
|
|
123
|
+
sendRoomCmd(rid, msg, attrs, mid, timeout, callback);
|
|
124
|
+
getGroupChat(gid, desc, num, begin, end, lastid, timeout, callback);
|
|
125
|
+
getRoomChat(rid, desc, num, begin, end, lastid, timeout, callback);
|
|
126
|
+
getP2PChat(ouid, desc, num, begin, end, lastid, timeout, callback);
|
|
127
|
+
getBroadcastChat(desc, num, begin, end, lastid, timeout, callback);
|
|
128
|
+
deleteChat(from, mid, xid, type, timeout, callback);
|
|
129
|
+
getChat(from, mid, xid, type, timeout, callback);
|
|
130
|
+
setUserInfo(oinfo, pinfo, timeout, callback);
|
|
131
|
+
getUserInfo(timeout, callback);
|
|
132
|
+
getUserOpenInfo(uids, timeout, callback);
|
|
133
|
+
setGroupInfo(gid, oinfo, pinfo, timeout, callback);
|
|
134
|
+
getGroupInfo(gid, timeout, callback);
|
|
135
|
+
getGroupOpenInfo(gid, timeout, callback);
|
|
136
|
+
setRoomInfo(rid, oinfo, pinfo, timeout, callback);
|
|
137
|
+
setRoomProfile(rid, publicData, privateData, label, avatar, timeout, callback);
|
|
138
|
+
getRoomInfo(rid, timeout, callback);
|
|
139
|
+
getRoomOpenInfo(rid, timeout, callback);
|
|
140
|
+
dataGet(key, timeout, callback);
|
|
141
|
+
dataSet(key, value, timeout, callback);
|
|
142
|
+
dataDelete(key, timeout, callback);
|
|
143
|
+
addBlacks(blacks, timeout, callback);
|
|
144
|
+
deleteBlacks(blacks, timeout, callback);
|
|
145
|
+
getBlacks(timeout, callback);
|
|
146
|
+
sendFile(mtype, to, file, mid, timeout, callback);
|
|
147
|
+
sendGroupFile(mtype, gid, file, mid, timeout, callback);
|
|
148
|
+
sendRoomFile(mtype, rid, file, mid, timeout, callback);
|
|
149
|
+
getP2PConversationList(mtime, mtypes, timeout, callback);
|
|
150
|
+
getP2PUnreadConversationList(mtime, mtypes, timeout, callback);
|
|
151
|
+
getGroupConversationList(mtime, mtypes, timeout, callback);
|
|
152
|
+
getGroupUnreadConversationList(mtime, mtypes, timeout, callback);
|
|
153
|
+
getUnreadConversationList(clear, mtime, mtypes, timeout, callback);
|
|
154
|
+
removeSession(to, localOnly, timeout, callback);
|
|
155
|
+
on(type, callback);
|
|
156
|
+
emit();
|
|
157
|
+
removeEvent();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class RTMConfig {
|
|
161
|
+
static ERROR_CODE;
|
|
162
|
+
static Int64;
|
|
163
|
+
static Uint64;
|
|
164
|
+
static MsgPack;
|
|
165
|
+
static FILE_TYPE;
|
|
166
|
+
static CHAT_TYPE;
|
|
167
|
+
static SERVER_PUSH;
|
|
168
|
+
static TLV_SERVER_PUSH;
|
|
169
|
+
static MID_TTL;
|
|
170
|
+
static API_VERSION;
|
|
171
|
+
static SDK_VERSION;
|
|
172
|
+
static MAX_PING_SECONDS;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class RTMProcessor {
|
|
176
|
+
constructor();
|
|
177
|
+
service(data, cb);
|
|
178
|
+
destroy();
|
|
179
|
+
kickout(data);
|
|
180
|
+
kickoutroom(data);
|
|
181
|
+
pushmsg(data);
|
|
182
|
+
pushgroupmsg(data);
|
|
183
|
+
pushroommsg(data);
|
|
184
|
+
pushbroadcastmsg(data);
|
|
185
|
+
ping(data);
|
|
186
|
+
on(type, callback);
|
|
187
|
+
emit();
|
|
188
|
+
removeEvent();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export class TLVCodec {
|
|
192
|
+
static encodeFrame(sequence, mt, uri, payload);
|
|
193
|
+
static decodeFrame(frame);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export class TLVWebSocketClient {
|
|
197
|
+
constructor(options);
|
|
198
|
+
connect();
|
|
199
|
+
close();
|
|
200
|
+
destroy();
|
|
201
|
+
markAuthenticated();
|
|
202
|
+
sendQuest(options, callback, timeout);
|
|
203
|
+
on(type, callback);
|
|
204
|
+
off(type, callback);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export = rtm;
|