nim-web-sdk-ng 0.9.2 → 0.11.0

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.
Files changed (65) hide show
  1. package/README.md +54 -26
  2. package/dist/CHATROOM_BROWSER_SDK/ChatroomInterface.d.ts +54 -0
  3. package/dist/CHATROOM_BROWSER_SDK/ChatroomMsgServiceInterface.d.ts +11 -0
  4. package/dist/CHATROOM_BROWSER_SDK/CloudStorageServiceInterface.d.ts +80 -0
  5. package/dist/CHATROOM_BROWSER_SDK/index.d.ts +22 -3
  6. package/dist/CHATROOM_BROWSER_SDK.js +11 -1
  7. package/dist/CHATROOM_MINIAPP_SDK/ChatroomInterface.d.ts +54 -0
  8. package/dist/CHATROOM_MINIAPP_SDK/ChatroomMsgServiceInterface.d.ts +11 -0
  9. package/dist/CHATROOM_MINIAPP_SDK/CloudStorageServiceInterface.d.ts +80 -0
  10. package/dist/CHATROOM_MINIAPP_SDK/index.d.ts +22 -3
  11. package/dist/CHATROOM_MINIAPP_SDK.js +11 -1
  12. package/dist/CHATROOM_UNIAPP_SDK.js +11 -1
  13. package/dist/NIM_BROWSER_SDK/CloudStorageServiceInterface.d.ts +1 -1
  14. package/dist/NIM_BROWSER_SDK/EventServiceInterface.d.ts +11 -11
  15. package/dist/NIM_BROWSER_SDK/MsgServiceInterface.d.ts +2 -2
  16. package/dist/NIM_BROWSER_SDK/NIMInterface.d.ts +63 -3
  17. package/dist/NIM_BROWSER_SDK/PluginServiceInterface.d.ts +1 -1
  18. package/dist/NIM_BROWSER_SDK/SessionServiceInterface.d.ts +2 -0
  19. package/dist/NIM_BROWSER_SDK/SuperTeamServiceInterface.d.ts +8 -11
  20. package/dist/NIM_BROWSER_SDK/TeamServiceInterface.d.ts +8 -11
  21. package/dist/NIM_BROWSER_SDK/index.d.ts +31 -4
  22. package/dist/NIM_BROWSER_SDK.js +11 -1
  23. package/dist/NIM_MINIAPP_SDK/CloudStorageServiceInterface.d.ts +1 -1
  24. package/dist/NIM_MINIAPP_SDK/EventServiceInterface.d.ts +11 -11
  25. package/dist/NIM_MINIAPP_SDK/MsgServiceInterface.d.ts +2 -2
  26. package/dist/NIM_MINIAPP_SDK/NIMInterface.d.ts +63 -3
  27. package/dist/NIM_MINIAPP_SDK/PluginServiceInterface.d.ts +1 -1
  28. package/dist/NIM_MINIAPP_SDK/SessionServiceInterface.d.ts +2 -0
  29. package/dist/NIM_MINIAPP_SDK/SuperTeamServiceInterface.d.ts +8 -11
  30. package/dist/NIM_MINIAPP_SDK/TeamServiceInterface.d.ts +8 -11
  31. package/dist/NIM_MINIAPP_SDK/index.d.ts +31 -4
  32. package/dist/NIM_MINIAPP_SDK.js +11 -1
  33. package/dist/NIM_UNIAPP_SDK.js +11 -1
  34. package/dist/QCHAT_BROWSER_SDK/CloudStorageServiceInterface.d.ts +32 -0
  35. package/dist/QCHAT_BROWSER_SDK/QChatChannelServiceInterface.d.ts +77 -9
  36. package/dist/QCHAT_BROWSER_SDK/QChatInterface.d.ts +55 -1
  37. package/dist/QCHAT_BROWSER_SDK/QChatMediaServiceInterface.d.ts +4 -0
  38. package/dist/QCHAT_BROWSER_SDK/QChatMsgServiceInterface.d.ts +19 -4
  39. package/dist/QCHAT_BROWSER_SDK/QChatServerServiceInterface.d.ts +95 -25
  40. package/dist/QCHAT_BROWSER_SDK/index.d.ts +21 -2
  41. package/dist/QCHAT_BROWSER_SDK.js +11 -1
  42. package/dist/QCHAT_UNIAPP_SDK.js +11 -1
  43. package/dist/esm/chatroom/src/ChatroomInterface.d.ts +54 -0
  44. package/dist/esm/chatroom/src/ChatroomMsgServiceInterface.d.ts +11 -0
  45. package/dist/esm/chatroom/src/CloudStorageServiceInterface.d.ts +80 -0
  46. package/dist/esm/chatroom/src/index.d.ts +22 -3
  47. package/dist/esm/index.d.ts +1 -1
  48. package/dist/esm/index.js +11 -1
  49. package/dist/esm/nim/src/CloudStorageServiceInterface.d.ts +1 -1
  50. package/dist/esm/nim/src/EventServiceInterface.d.ts +11 -11
  51. package/dist/esm/nim/src/MsgServiceInterface.d.ts +2 -2
  52. package/dist/esm/nim/src/NIMInterface.d.ts +63 -3
  53. package/dist/esm/nim/src/PluginServiceInterface.d.ts +1 -1
  54. package/dist/esm/nim/src/SessionServiceInterface.d.ts +2 -0
  55. package/dist/esm/nim/src/SuperTeamServiceInterface.d.ts +8 -11
  56. package/dist/esm/nim/src/TeamServiceInterface.d.ts +8 -11
  57. package/dist/esm/nim/src/index.d.ts +31 -4
  58. package/dist/esm/qchat/src/CloudStorageServiceInterface.d.ts +32 -0
  59. package/dist/esm/qchat/src/QChatChannelServiceInterface.d.ts +77 -9
  60. package/dist/esm/qchat/src/QChatInterface.d.ts +55 -1
  61. package/dist/esm/qchat/src/QChatMediaServiceInterface.d.ts +4 -0
  62. package/dist/esm/qchat/src/QChatMsgServiceInterface.d.ts +19 -4
  63. package/dist/esm/qchat/src/QChatServerServiceInterface.d.ts +95 -25
  64. package/dist/esm/qchat/src/index.d.ts +21 -2
  65. package/package.json +6 -5
package/README.md CHANGED
@@ -41,7 +41,8 @@ import NIM from 'nim-web-sdk-ng/dist/NIM_BROWSER_SDK'
41
41
  // 若使用聊天室能力则引入
42
42
  import Chatroom from 'nim-web-sdk-ng/dist/CHATROOM_BROWSER_SDK'
43
43
 
44
- const nim = new NIM(
44
+ // 0.11.0 版开始支持单例模式获取实例, 在此之前通过 new 创建实例
45
+ const nim = NIM.getInstance(
45
46
  {
46
47
  debugLevel: 'debug',
47
48
  appkey: 'YOUR_APPKEY',
@@ -51,7 +52,8 @@ const nim = new NIM(
51
52
  {}
52
53
  )
53
54
 
54
- const chatroom = new Chatroom({
55
+ // 0.11.0 版开始支持单例模式获取实例, 在此之前通过 new 创建实例
56
+ const chatroom = Chatroom.getInstance({
55
57
  debugLevel: 'debug',
56
58
  appkey: 'YOUR_APPKEY',
57
59
  account: 'YOUR_ACCOUNT',
@@ -62,9 +64,21 @@ const chatroom = new Chatroom({
62
64
  })
63
65
 
64
66
  async function init() {
65
- await nim.connect()
66
-
67
- await chatroom.connect()
67
+ try {
68
+ if (nim.status === 'unconnected' || nim.status === 'waitReconnect') {
69
+ await nim.connect()
70
+ }
71
+ } catch (err) {
72
+ console.error('login failed cause', err)
73
+ }
74
+
75
+ try {
76
+ if (chatroom.status === 'unconnected' || chatroom.status === 'waitReconnect') {
77
+ await chatroom.connect()
78
+ }
79
+ } catch (err) {
80
+ console.error('login failed cause', err)
81
+ }
68
82
  }
69
83
 
70
84
  init()
@@ -89,7 +103,8 @@ NIM.setAdapters(browserAppAdapters)
89
103
  NIM.registerService(MsgService, 'msg')
90
104
  NIM.registerService(SessionService, 'session')
91
105
 
92
- const nim = new NIM(
106
+ // 0.11.0 版开始支持单例模式获取实例, 在此之前通过 new 创建实例
107
+ const nim = NIM.getInstance(
93
108
  {
94
109
  debugLevel: 'debug',
95
110
  appkey: 'YOUR_APPKEY',
@@ -100,7 +115,13 @@ const nim = new NIM(
100
115
  )
101
116
 
102
117
  async function init() {
103
- await nim.connect()
118
+ try {
119
+ if (nim.status === 'unconnected' || nim.status === 'waitReconnect') {
120
+ await nim.connect()
121
+ }
122
+ } catch (err) {
123
+ console.error('login failed cause', err)
124
+ }
104
125
  }
105
126
 
106
127
  init()
@@ -114,7 +135,8 @@ import browserAdapters from 'nim-web-sdk-ng/dist/esm/browserAdapters'
114
135
 
115
136
  Chatroom.setAdapters(browserAppAdapters)
116
137
 
117
- const chatroom = new Chatroom({
138
+ // 0.11.0 版开始支持单例模式获取实例, 在此之前通过 new 创建实例
139
+ const chatroom = Chatroom.getInstance({
118
140
  debugLevel: 'debug',
119
141
  appkey: 'YOUR_APPKEY',
120
142
  account: 'YOUR_ACCOUNT',
@@ -125,7 +147,13 @@ const chatroom = new Chatroom({
125
147
  })
126
148
 
127
149
  async function init() {
128
- await chatroom.connect()
150
+ try {
151
+ if (chatroom.status === 'unconnected' || chatroom.status === 'waitReconnect') {
152
+ await chatroom.connect()
153
+ }
154
+ } catch (err) {
155
+ console.error('login failed cause', err)
156
+ }
129
157
  }
130
158
 
131
159
  init()
@@ -135,29 +163,29 @@ init()
135
163
 
136
164
  IM
137
165
 
138
- - [快速开始](https://doc.yunxin.163.com/docs/TM5MzM5Njk/zg2Nzg2MDM?platformId=120901)
139
- - [初始化与登录](https://doc.yunxin.163.com/docs/TM5MzM5Njk/zA5MzQ3NDc?platformId=120901)
140
- - [消息收发](https://doc.yunxin.163.com/docs/TM5MzM5Njk/Dc5NTIyMDk?platformId=120901)
141
- - [消息扩展](https://doc.yunxin.163.com/docs/TM5MzM5Njk/zA0NDIyMzA?platformId=120901)
142
- - [会话](https://doc.yunxin.163.com/docs/TM5MzM5Njk/TIwNDYzNTE?platformId=120901)
143
- - [用户](https://doc.yunxin.163.com/docs/TM5MzM5Njk/Tg0MzYyODA?platformId=120901)
144
- - [好友](https://doc.yunxin.163.com/docs/TM5MzM5Njk/jI1NDQzNjk?platformId=120901)
145
- - [订阅](https://doc.yunxin.163.com/docs/TM5MzM5Njk/TU5NzgyMTY?platformId=120901)
146
- - [系统通知](https://doc.yunxin.163.com/docs/TM5MzM5Njk/DY2NDE5MzI?platformId=120901)
147
- - [群组](https://doc.yunxin.163.com/docs/TM5MzM5Njk/Tg0MDA3NjA?platformId=120901)
148
- - [超级群](https://doc.yunxin.163.com/docs/TM5MzM5Njk/DI5NDY3ODM?platformId=120901)
149
- - [uniapp 推送相关](https://doc.yunxin.163.com/docs/TM5MzM5Njk/jAzOTIwMDk?platformId=120901)
166
+ - [快速开始](https://doc.yunxin.163.com/messaging-enhanced/docs/DQwMDE5MDk?platform=web)
167
+ - [初始化与登录](https://doc.yunxin.163.com/messaging-enhanced/docs/DE1MTcxNzg?platform=web)
168
+ - [消息收发](https://doc.yunxin.163.com/messaging-enhanced/docs/TQ2NTUxNTM?platform=web)
169
+ - [消息扩展](https://doc.yunxin.163.com/messaging-enhanced/docs/DYzMDAyMjg?platform=web)
170
+ - [会话](https://doc.yunxin.163.com/messaging-enhanced/docs/TgxNjczNzk?platform=web)
171
+ - [用户](https://doc.yunxin.163.com/messaging-enhanced/docs/Dc0Njg0NjY?platform=web)
172
+ - [好友](https://doc.yunxin.163.com/messaging-enhanced/docs/zc2MTk2MjE?platform=web)
173
+ - [订阅](https://doc.yunxin.163.com/messaging-enhanced/docs/TE2ODU3NjM?platform=web)
174
+ - [系统通知](https://doc.yunxin.163.com/messaging-enhanced/docs/DIyMDE2NDM?platform=web)
175
+ - [群组](https://doc.yunxin.163.com/messaging-enhanced/docs/DA4OTc3NDc?platform=web)
176
+ - [超级群](https://doc.yunxin.163.com/messaging-enhanced/docs/TY3MzM1ODg?platform=web)
177
+ - [uniapp 推送相关](https://doc.yunxin.163.com/messaging-enhanced/docs/TAwMTEyNzE?platform=web)
150
178
 
151
179
  聊天室
152
180
 
153
- - [聊天室](https://doc.yunxin.163.com/docs/TM5MzM5Njk/jk5NTk1NTg?platformId=120901)
181
+ - [聊天室](https://doc.yunxin.163.com/messaging-enhanced/docs/jM2MzczOTE?platform=web)
154
182
 
155
183
  圈组
156
184
 
157
- - [圈组](https://doc.yunxin.163.com/docs/TM5MzM5Njk/Tc4ODUzODk?platformId=120901)
185
+ - [圈组](https://doc.yunxin.163.com/messaging-enhanced/docs/TczMjgzMzU?platform=web)
158
186
 
159
187
  其他
160
188
 
161
- - [API 参考](https://doc.yunxin.163.com/docs/TM5MzM5Njk/Tg4NDU5Mjg?platformId=120901)
162
- - [已知问题](https://doc.yunxin.163.com/docs/TM5MzM5Njk/DMwNjQzNjY?platformId=120901)
163
- - [更新日志](https://doc.yunxin.163.com/docs/TM5MzM5Njk/DE2MTUzMDE?platformId=120901)
189
+ - [API 参考](https://doc.yunxin.163.com/docs/interface/messaging-enhanced/web/typedoc/Latest/zh/NIM/index.html)
190
+ - [已知问题](https://doc.yunxin.163.com/messaging-enhanced/docs/jE5NTczNTI?platform=web)
191
+ - [更新日志](https://doc.yunxin.163.com/messaging-enhanced/docs/zMwOTk5MjI?platform=web)
@@ -1,5 +1,9 @@
1
1
  import { Chatroom, ChatroomMember, ChatroomMessage } from './types';
2
2
  export interface ChatroomInterface {
3
+ /**
4
+ * 实例状态
5
+ */
6
+ status: NIMEChatroomInstanceStatus;
3
7
  /**
4
8
  * @Multi_Lang_Tag
5
9
  * @locale cn
@@ -252,6 +256,56 @@ export declare type ChatroomOtherOptions = {
252
256
  s3?: any;
253
257
  };
254
258
  };
259
+ /**
260
+ * @Multi_Lang_Tag
261
+ * @locale cn
262
+ * 静态方法
263
+ * @locale
264
+ *
265
+ * @locale en
266
+ * Static method
267
+ * @locale
268
+ */
269
+ export interface ChatroomInterfaceStatic {
270
+ /**
271
+ * 构造函数
272
+ */
273
+ new (options?: ChatroomInitializeOptions, otherOptions?: ChatroomOtherOptions): ChatroomInterface;
274
+ /**
275
+ * 单例模式获取实例
276
+ */
277
+ getInstance(_options?: ChatroomInitializeOptions, _otherOptions?: ChatroomOtherOptions): ChatroomInterface;
278
+ /**
279
+ * 设置适配器
280
+ * @param _newAdapters 适配器
281
+ */
282
+ setAdapters(_newAdapters: any): void;
283
+ }
284
+ /**
285
+ * @Multi_Lang_Tag
286
+ * @locale cn
287
+ * 实例的状态标识
288
+ *
289
+ * - unconnected: 尚未建立连接(初始化、主动登出、达到最大重连次数)
290
+ * - connecting: 正在建立连接中
291
+ * - connected: 已连接,尚未完成鉴权认证
292
+ * - logined: 已连接, 并且完成了鉴权认证,可以正常开始发送协议
293
+ * - waitReconnect: 等待重连中
294
+ * - destroyed: 实例已经销毁
295
+ * @locale
296
+ *
297
+ * @locale en
298
+ * Status of the instance
299
+ *
300
+ * - unconnected: no connection has been established(Initialization, active logout, and maximum reconnection times)
301
+ * - connecting: Establishing connection
302
+ * - connected: Connected, authentication has not been completed
303
+ * - logined: Connected and completed the authentication
304
+ * - waitReconnect: Waiting for reconnection
305
+ * - destroyed: The instance has been destroyed
306
+ * @locale
307
+ */
308
+ export declare type NIMEChatroomInstanceStatus = 'unconnected' | 'connecting' | 'connected' | 'logined' | 'waitReconnect' | 'destroyed';
255
309
  /**
256
310
  * Example:
257
311
  *
@@ -103,6 +103,17 @@ export interface ChatroomMsgServiceInterface {
103
103
  * @locale
104
104
  */
105
105
  queryMessageHistory(options: QueryMessageHistoryOptions): Promise<ChatroomMessage[]>;
106
+ /**
107
+ * @Multi_Lang_Tag
108
+ * @locale cn
109
+ * 根据标签查询历史消息
110
+ * @locale
111
+ *
112
+ * @locale en
113
+ * Query historical messages by tags
114
+ * @locale
115
+ */
116
+ getHistoryMsgsByTags(options: GetHistoryMsgsByTagsOptions): Promise<ChatroomMessage[]>;
106
117
  }
107
118
  export declare type QueryMessageHistoryOptions = {
108
119
  timetag?: number;
@@ -22,4 +22,84 @@ export interface CloudStorageServiceInterface {
22
22
  * @locale
23
23
  */
24
24
  getOriginUrl(options: string): Promise<string>;
25
+ /**
26
+ * @Multi_Lang_Tag
27
+ * @locale cn
28
+ * 获取文件鉴权的token
29
+ * @locale
30
+ * @locale en
31
+ * Get the token for the authorization of file access.
32
+ * @locale
33
+ */
34
+ getFileToken(options: GetFileTokenOptions): Promise<GetFileTokenResult | void>;
25
35
  }
36
+ export declare type GetFileTokenOptions = {
37
+ /**
38
+ * @Multi_Lang_Tag
39
+ * @locale cn
40
+ * 类型 2表示带过期时间的全局token鉴权,3表示文件级别的url鉴权
41
+ * @locale
42
+ *
43
+ * @locale en
44
+ *
45
+ * @locale
46
+ */
47
+ type: 2 | 3;
48
+ /**
49
+ * @Multi_Lang_Tag
50
+ * @locale cn
51
+ * 如果type=3,是url鉴权,需要传url数组
52
+ * @locale
53
+ *
54
+ * @locale en
55
+ *
56
+ * @locale
57
+ */
58
+ urls?: string[] | string;
59
+ };
60
+ export declare type GetFileTokenResult = {
61
+ /**
62
+ * @Multi_Lang_Tag
63
+ * @locale cn
64
+ * 类型 2表示带过期时间的全局token鉴权,3表示文件级别的url鉴权
65
+ * @locale
66
+ *
67
+ * @locale en
68
+ *
69
+ * @locale
70
+ */
71
+ type: 2 | 3;
72
+ /**
73
+ * @Multi_Lang_Tag
74
+ * @locale cn
75
+ * 如果是url鉴权,就返回url数组对应的tokens
76
+ * @locale
77
+ *
78
+ * @locale en
79
+ *
80
+ * @locale
81
+ */
82
+ tokens?: string[];
83
+ /**
84
+ * @Multi_Lang_Tag
85
+ * @locale cn
86
+ * 基于过期时间鉴权的token
87
+ * @locale
88
+ *
89
+ * @locale en
90
+ *
91
+ * @locale
92
+ */
93
+ token?: string;
94
+ /**
95
+ * @Multi_Lang_Tag
96
+ * @locale cn
97
+ * token的过期时间,单位s
98
+ * @locale
99
+ *
100
+ * @locale en
101
+ *
102
+ * @locale
103
+ */
104
+ ttl: number;
105
+ };
@@ -1,11 +1,22 @@
1
- import { ChatroomEventInterface, ChatroomInitializeOptions, ChatroomInterface } from './ChatroomInterface';
1
+ import { ChatroomEventInterface, ChatroomInitializeOptions, ChatroomInterface, ChatroomOtherOptions, NIMEChatroomInstanceStatus } from './ChatroomInterface';
2
2
  import { ChatroomServiceInterface } from './ChatroomServiceInterface';
3
3
  import { ChatroomMsgServiceInterface } from './ChatroomMsgServiceInterface';
4
4
  import { ChatroomMemberServiceInterface } from './ChatroomMemberServiceInterface';
5
5
  import { CloudStorageServiceInterface } from './CloudStorageServiceInterface';
6
6
  import { EventEmitter } from 'eventemitter3';
7
- export default class QChat extends EventEmitter<ChatroomEventInterface> implements ChatroomInterface {
7
+ export default class Chatroom extends EventEmitter<ChatroomEventInterface> implements ChatroomInterface {
8
+ static instance: Chatroom | null;
9
+ /**
10
+ * 实例的状态
11
+ */
12
+ status: NIMEChatroomInstanceStatus;
13
+ /**
14
+ * 账号
15
+ */
8
16
  account: string;
17
+ /**
18
+ * 连接参数
19
+ */
9
20
  options: ChatroomInitializeOptions;
10
21
  chatroom: ChatroomServiceInterface;
11
22
  chatroomMsg: ChatroomMsgServiceInterface;
@@ -16,5 +27,13 @@ export default class QChat extends EventEmitter<ChatroomEventInterface> implemen
16
27
  setOptions(): Promise<void>;
17
28
  disconnect(): Promise<void>;
18
29
  destroy(): Promise<void>;
19
- static setAdapters(newAdapters: any): void;
30
+ /**
31
+ * 单例模式获取实例
32
+ */
33
+ static getInstance(_options?: ChatroomInitializeOptions, _otherOptions?: ChatroomOtherOptions): Chatroom;
34
+ /**
35
+ * 设置适配器
36
+ * @param _newAdapters 适配器
37
+ */
38
+ static setAdapters(_newAdapters: any): void;
20
39
  }