@onyx-p/imlib-web 1.2.2 → 1.2.4
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/dist/README.md +14 -0
- package/dist/index.esm.js +30737 -0
- package/dist/index.umd.js +30811 -0
- package/dist/types/index.d.ts +243 -0
- package/dist/types/model/baseMessage.d.ts +47 -0
- package/dist/types/model/iReceivedConversation.d.ts +70 -0
- package/dist/types/model/iReceivedMessage.d.ts +91 -0
- package/dist/types/model/mentionedInfo.d.ts +9 -0
- package/dist/types/model/messages/fileMessage.d.ts +24 -0
- package/dist/types/model/messages/gifMessage.d.ts +27 -0
- package/dist/types/model/messages/imageMessage.d.ts +32 -0
- package/dist/types/model/messages/index.d.ts +12 -0
- package/dist/types/model/messages/notificationMessages.d.ts +20 -0
- package/dist/types/model/messages/otherMediaMessages.d.ts +99 -0
- package/dist/types/model/messages/recallCommandMessage.d.ts +9 -0
- package/dist/types/model/messages/textMessage.d.ts +12 -0
- package/dist/types/model/messages/videoMessage.d.ts +30 -0
- package/dist/types/model/messages/voiceMessage.d.ts +18 -0
- package/dist/types/model/statusTypes.d.ts +409 -0
- package/dist/types/types.d.ts +297 -0
- package/package.json +57 -5
@@ -0,0 +1,297 @@
|
|
1
|
+
import { BaseMessage, IExtraData, IUserInfo } from './model/baseMessage';
|
2
|
+
import IReceivedMessage from './model/iReceivedMessage';
|
3
|
+
import { ConnectionStatus, ConversationType, ErrorCode, MessageDirection, NotificationLevel, NotificationStatus } from './model/statusTypes';
|
4
|
+
import IReceivedConversation from './model/iReceivedConversation';
|
5
|
+
export declare enum LogLevel {
|
6
|
+
DEBUG = 0,
|
7
|
+
INFO = 1,
|
8
|
+
WARN = 2,
|
9
|
+
ERROR = 3,
|
10
|
+
FATAL = 4,
|
11
|
+
NONE = 1000
|
12
|
+
}
|
13
|
+
export type IInitOption = {
|
14
|
+
appkey: string;
|
15
|
+
/**
|
16
|
+
* 修改 engine log 打印等级
|
17
|
+
*/
|
18
|
+
logLevel?: LogLevel;
|
19
|
+
/**
|
20
|
+
* 修改默认的 log 输出函数
|
21
|
+
*/
|
22
|
+
logStdout?: (logLevel: LogLevel, content: string) => void;
|
23
|
+
serverInfo?: string;
|
24
|
+
uploader?: IUploader;
|
25
|
+
deviceCode: string;
|
26
|
+
deviceType: number;
|
27
|
+
};
|
28
|
+
export interface ProfileInfo {
|
29
|
+
deviceId: string;
|
30
|
+
sessionId: string;
|
31
|
+
uid: string;
|
32
|
+
}
|
33
|
+
export declare enum Events {
|
34
|
+
CONNECTING = "CONNECTING",
|
35
|
+
CONNECTED = "CONNECTED",
|
36
|
+
DISCONNECT = "DISCONNECT",
|
37
|
+
SUSPEND = "SUSPEND",
|
38
|
+
MESSAGES = "MESSAGES",
|
39
|
+
PULL_OFFLINE_MESSAGE_FINISHED = "PULL_OFFLINE_MESSAGE_FINISHED",
|
40
|
+
CONVERSATION = "CONVERSATION",
|
41
|
+
PUSH = "PUSH",
|
42
|
+
RECALL = "RECALL",
|
43
|
+
ARRIVAL_RECEIPT_RECEIVED = "ARRIVAL_RECEIPT_RECEIVED",
|
44
|
+
READ_RECEIPT_RECEIVED = "READ_RECEIPT_RECEIVED"
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* 收到已读/已发送回执数据结构
|
48
|
+
* @category Interface
|
49
|
+
*/
|
50
|
+
export interface IReceiptReceivedEvent {
|
51
|
+
/**
|
52
|
+
* 会话信息,包含会话属性
|
53
|
+
*/
|
54
|
+
conversation: IConversationOption;
|
55
|
+
/**
|
56
|
+
* 消息的id列表
|
57
|
+
*/
|
58
|
+
messageUIdList: string[];
|
59
|
+
}
|
60
|
+
export type EventListeners = {
|
61
|
+
[Events.CONNECTING]: () => void;
|
62
|
+
[Events.CONNECTED]: () => void;
|
63
|
+
[Events.DISCONNECT]: (status: ConnectionStatus) => void;
|
64
|
+
[Events.SUSPEND]: (status: ConnectionStatus | ErrorCode) => void;
|
65
|
+
[Events.MESSAGES]: (events: {
|
66
|
+
messages: IReceivedMessage[];
|
67
|
+
}) => void;
|
68
|
+
[Events.PULL_OFFLINE_MESSAGE_FINISHED]: () => void;
|
69
|
+
[Events.CONVERSATION]: (event: {
|
70
|
+
conversations: IUpdatedConversation[];
|
71
|
+
}) => void;
|
72
|
+
[Events.PUSH]: (event: {
|
73
|
+
cmdId: number;
|
74
|
+
body: Uint8Array;
|
75
|
+
}) => void;
|
76
|
+
[Events.RECALL]: (messageUId: string) => void;
|
77
|
+
[Events.ARRIVAL_RECEIPT_RECEIVED]: (event: IReceiptReceivedEvent) => void;
|
78
|
+
[Events.READ_RECEIPT_RECEIVED]: (event: IReceiptReceivedEvent) => void;
|
79
|
+
};
|
80
|
+
export interface IBaseConversationInfo {
|
81
|
+
conversationType: ConversationType;
|
82
|
+
targetId: string;
|
83
|
+
}
|
84
|
+
export interface IConversationState extends IBaseConversationInfo {
|
85
|
+
unreadCount: number;
|
86
|
+
unreadMentionedCount: number;
|
87
|
+
notificationLevel: NotificationLevel;
|
88
|
+
notificationStatus: NotificationStatus;
|
89
|
+
isTop: boolean;
|
90
|
+
dialogTitle: string | null | undefined;
|
91
|
+
smallAvatarUrl: string | null | undefined;
|
92
|
+
updateTime: number | null | undefined;
|
93
|
+
}
|
94
|
+
/**
|
95
|
+
* 会话信息
|
96
|
+
*/
|
97
|
+
export type IConversationOption = IBaseConversationInfo;
|
98
|
+
export type IUpdatedConversationItemKeys = Extract<keyof IReceivedConversation, 'isTop' | 'notificationStatus' | 'notificationLevel' | 'unreadMessageCount' | 'hasMentioned' | 'unreadMentionedCount' | 'dialogTitle' | 'smallAvatarUrl' | 'latestMessage' | 'burnAfterReadingFlag' | 'burnAfterReadingTime'>;
|
99
|
+
export type IUpdatedConversationItem = Partial<Record<IUpdatedConversationItemKeys, {
|
100
|
+
time: number;
|
101
|
+
val: any;
|
102
|
+
}>>;
|
103
|
+
/**
|
104
|
+
* 会话更新内容
|
105
|
+
*/
|
106
|
+
export type IUpdatedConversation = {
|
107
|
+
conversation: IReceivedConversation;
|
108
|
+
updatedItems: IUpdatedConversationItem;
|
109
|
+
};
|
110
|
+
/**
|
111
|
+
* 消息的推送配置
|
112
|
+
*/
|
113
|
+
export type IPushConfig = {
|
114
|
+
/**
|
115
|
+
* 推送标题
|
116
|
+
如果没有设置,会使用下面的默认标题显示规则
|
117
|
+
默认标题显示规则:
|
118
|
+
内置消息:单聊通知标题显示为发送者名称,群聊通知标题显示为群名称。
|
119
|
+
自定义消息:默认不显示标题。
|
120
|
+
*/
|
121
|
+
pushTitle?: string;
|
122
|
+
/**
|
123
|
+
* 推送内容 在通知栏里会显示这个字段
|
124
|
+
* 自定义消息,该字段必须填写,否则无法收到 push 消息.
|
125
|
+
SDK 中默认的消息类型(如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg) 默认已经指定, 可设置为 nil
|
126
|
+
*/
|
127
|
+
pushContent?: string;
|
128
|
+
/**
|
129
|
+
* 远程推送附加信息
|
130
|
+
*/
|
131
|
+
pushData?: string;
|
132
|
+
};
|
133
|
+
/**
|
134
|
+
* 发送消息时的可选项信息
|
135
|
+
*/
|
136
|
+
export interface ISendMessageOptions {
|
137
|
+
/**
|
138
|
+
* 消息发送之前的回调
|
139
|
+
*/
|
140
|
+
onSendBefore?: (message: IReceivedMessage) => void;
|
141
|
+
/**
|
142
|
+
* 重发消息时用到,重发消息的 messageId。
|
143
|
+
* 当要重发消息时所有参数需与原始消息参数一致,messageId 必须存在。
|
144
|
+
* 正常发消息时无需传该参数。
|
145
|
+
*/
|
146
|
+
messageId?: string;
|
147
|
+
/**
|
148
|
+
* 推送配置,用于配置移动端远程推送的推送栏显示内容
|
149
|
+
*/
|
150
|
+
pushConfig?: IPushConfig;
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* 要发送的文件信息(本地资源)
|
154
|
+
*/
|
155
|
+
export type ISendBody = IUserInfo & IExtraData & {
|
156
|
+
file: Blob;
|
157
|
+
};
|
158
|
+
/**
|
159
|
+
* 上传过程中的回调钩子
|
160
|
+
*/
|
161
|
+
export interface IUploadHooks {
|
162
|
+
/**
|
163
|
+
* 文件上传进度回调
|
164
|
+
*/
|
165
|
+
onProgress?: (progress: number) => void;
|
166
|
+
/**
|
167
|
+
* 文件上传完成回调,可通过修改返回值以修改待发布的消息内容,如实现自定义消息
|
168
|
+
*/
|
169
|
+
onComplete?: (fileInfo: IUploadCompletedResult) => void | BaseMessage;
|
170
|
+
}
|
171
|
+
export type IUploadCompletedResult = {
|
172
|
+
urls: string[];
|
173
|
+
encryptedKey?: string;
|
174
|
+
};
|
175
|
+
export type IUploadCallback = {
|
176
|
+
onProgress?: (progress: number) => void;
|
177
|
+
onCompleted?: (result: IUploadCompletedResult) => void;
|
178
|
+
onError?: (reason: string) => void;
|
179
|
+
};
|
180
|
+
export interface IUploader {
|
181
|
+
upload(files: Blob[], callback: IUploadCallback): void;
|
182
|
+
cancel(): void;
|
183
|
+
}
|
184
|
+
/**
|
185
|
+
* 文件消息配置
|
186
|
+
*/
|
187
|
+
export interface IUploadMessageOption extends ISendMessageOptions {
|
188
|
+
}
|
189
|
+
/**
|
190
|
+
* 图片消息配置
|
191
|
+
*/
|
192
|
+
export interface IImageMessageOption extends IUploadMessageOption {
|
193
|
+
thumbnailConfig?: IThumbnailConfig;
|
194
|
+
}
|
195
|
+
/**
|
196
|
+
* 缩略图配置
|
197
|
+
*/
|
198
|
+
export interface IThumbnailConfig {
|
199
|
+
maxHeight?: number;
|
200
|
+
maxWidth?: number;
|
201
|
+
quality?: number;
|
202
|
+
scale?: number;
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* 撤回消息 option 参数
|
206
|
+
*/
|
207
|
+
export interface IRecallMessageOptions {
|
208
|
+
/**
|
209
|
+
* 消息的唯一id,服务端依赖此属性删除要撤回的消息
|
210
|
+
*/
|
211
|
+
messageUId: string;
|
212
|
+
}
|
213
|
+
/**
|
214
|
+
* 获取远程消息 option 参数
|
215
|
+
*/
|
216
|
+
export type GetHistoryMessageOption = {
|
217
|
+
/**
|
218
|
+
* 获取此时间之前的消息,0 为从当前时间拉取
|
219
|
+
*/
|
220
|
+
timestamp?: string;
|
221
|
+
/**
|
222
|
+
* 获取消息的数量,范围: 1-20
|
223
|
+
*/
|
224
|
+
count?: number;
|
225
|
+
/**
|
226
|
+
* 查询消息的方向
|
227
|
+
* * 0: 以 timestamp 为基准向前查询
|
228
|
+
* * 1: 以 timestamp 为基准向后查询
|
229
|
+
*/
|
230
|
+
order?: 0 | 1;
|
231
|
+
};
|
232
|
+
/**
|
233
|
+
* 获取远程消息回调结果
|
234
|
+
*/
|
235
|
+
export type GetHistoryMessageResult = {
|
236
|
+
list: IReceivedMessage[];
|
237
|
+
hasMore: boolean;
|
238
|
+
};
|
239
|
+
export type IDeleteMessageOptions = {
|
240
|
+
/**
|
241
|
+
* 消息 id
|
242
|
+
*/
|
243
|
+
messageUId: string;
|
244
|
+
/**
|
245
|
+
* 消息发送时间
|
246
|
+
*/
|
247
|
+
sentTime?: number;
|
248
|
+
/**
|
249
|
+
* 消息方向
|
250
|
+
* * 1: 发送
|
251
|
+
* * 2: 接收
|
252
|
+
*/
|
253
|
+
messageDirection?: MessageDirection;
|
254
|
+
};
|
255
|
+
export type IGetConversationListOptions = {
|
256
|
+
/**
|
257
|
+
* 会话数量
|
258
|
+
*/
|
259
|
+
count?: number;
|
260
|
+
/**
|
261
|
+
* 获取起始时间
|
262
|
+
* 默认值: 0
|
263
|
+
* order 为 0 startTime 默认值为当前时间,将返回最新的会话列表
|
264
|
+
* order 为 1 startTime 默认值为所有会话中最早的消息时间,将返回最早的会话列表数据
|
265
|
+
*/
|
266
|
+
startTime?: number;
|
267
|
+
/**
|
268
|
+
* 查询顺序
|
269
|
+
* 默认值: 0
|
270
|
+
* 0 获取 startTime 之前的
|
271
|
+
* 1 获取 startTime 之后的
|
272
|
+
*/
|
273
|
+
order?: 0 | 1;
|
274
|
+
};
|
275
|
+
/**
|
276
|
+
* 异步任务回调
|
277
|
+
*/
|
278
|
+
export interface IAsyncRes<T = any> {
|
279
|
+
/**
|
280
|
+
* Promise 执行结果
|
281
|
+
*/
|
282
|
+
code: ErrorCode;
|
283
|
+
/**
|
284
|
+
* 结果数据
|
285
|
+
*/
|
286
|
+
data?: T;
|
287
|
+
/**
|
288
|
+
* 错误消息
|
289
|
+
*/
|
290
|
+
msg?: string;
|
291
|
+
}
|
292
|
+
/**
|
293
|
+
* 异步任务结果定义
|
294
|
+
* @description
|
295
|
+
* 通过 `Promise.resolve` 来处理预期内的异常,进而通过 Uncatch Promise Error 暴露预期外的异常
|
296
|
+
*/
|
297
|
+
export type IPromiseResult<T> = Promise<IAsyncRes<T>>;
|
package/package.json
CHANGED
@@ -1,9 +1,41 @@
|
|
1
1
|
{
|
2
2
|
"name": "@onyx-p/imlib-web",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.4",
|
4
4
|
"main": "./dist/index.umd.js",
|
5
5
|
"module": "./dist/index.esm.js",
|
6
6
|
"types": "./dist/types/index.d.ts",
|
7
|
+
"scripts": {
|
8
|
+
"clean:dist": "rimraf dist",
|
9
|
+
"build:types": "npm run clean:dist && tsc -b ./tsconfig.types.json",
|
10
|
+
"build": "npm run build:types && rollup -c --bundleConfigAsCjs && node scripts/prepare-publish.js",
|
11
|
+
"dev": "npm run clean:dist && rollup -c --bundleConfigAsCjs",
|
12
|
+
"test": "node test/test.js"
|
13
|
+
},
|
14
|
+
"license": "MIT",
|
15
|
+
"devDependencies": {
|
16
|
+
"@babel/core": "^7.26.0",
|
17
|
+
"@babel/plugin-transform-runtime": "^7.25.9",
|
18
|
+
"@babel/preset-env": "^7.26.0",
|
19
|
+
"@babel/runtime-corejs3": "^7.26.0",
|
20
|
+
"@rollup/plugin-babel": "^6.0.4",
|
21
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
22
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
23
|
+
"@types/crypto-js": "^4.2.2",
|
24
|
+
"@types/node": "^22.10.2",
|
25
|
+
"electron": "^30.0.0",
|
26
|
+
"eslint": "^9.17.0",
|
27
|
+
"eslint-config-prettier": "^9.1.0",
|
28
|
+
"eslint-plugin-prettier": "^5.2.1",
|
29
|
+
"prettier": "^3.4.2",
|
30
|
+
"rollup": "^3.28.0",
|
31
|
+
"rollup-plugin-bundle-size": "^1.0.3",
|
32
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
33
|
+
"rollup-plugin-re": "^1.0.7",
|
34
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
35
|
+
"rollup-plugin-visualizer": "^5.12.0",
|
36
|
+
"tslib": "^2.8.1",
|
37
|
+
"typescript": "^5.7.2"
|
38
|
+
},
|
7
39
|
"files": [
|
8
40
|
"dist/index.umd.js",
|
9
41
|
"dist/index.esm.js",
|
@@ -12,7 +44,27 @@
|
|
12
44
|
"dist/types/model",
|
13
45
|
"README.md"
|
14
46
|
],
|
15
|
-
"
|
16
|
-
|
17
|
-
|
18
|
-
|
47
|
+
"dependencies": {
|
48
|
+
"crypto-js": "^4.2.0",
|
49
|
+
"electron-store": "^10.0.1",
|
50
|
+
"long": "^5.2.3",
|
51
|
+
"protobufjs": "^7.4.0"
|
52
|
+
},
|
53
|
+
"peerDependencies": {
|
54
|
+
"electron": ">=10.0.0"
|
55
|
+
},
|
56
|
+
"description": "",
|
57
|
+
"directories": {
|
58
|
+
"example": "examples",
|
59
|
+
"lib": "lib",
|
60
|
+
"test": "test"
|
61
|
+
},
|
62
|
+
"repository": {
|
63
|
+
"type": "git",
|
64
|
+
"url": ""
|
65
|
+
},
|
66
|
+
"keywords": [
|
67
|
+
"im"
|
68
|
+
],
|
69
|
+
"author": "zimu"
|
70
|
+
}
|