dcim-web-sdk 0.1.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.
- package/README.md +0 -0
- package/dist/index.cjs +798 -0
- package/dist/index.d.cts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +771 -0
- package/package.json +37 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
type EventName = string;
|
|
2
|
+
type EventListener<T = unknown> = (event: T) => void;
|
|
3
|
+
type CompatEventPayload = {
|
|
4
|
+
name?: string;
|
|
5
|
+
data?: unknown;
|
|
6
|
+
};
|
|
7
|
+
type LoginOptions = {
|
|
8
|
+
userID: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
apiAddr?: string;
|
|
11
|
+
wsAddr?: string;
|
|
12
|
+
};
|
|
13
|
+
type CreateOptions = {
|
|
14
|
+
userID?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
apiAddr: string;
|
|
17
|
+
wsAddr: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
uploader?: UploadProvider;
|
|
20
|
+
/** 闲置超时断开,单位毫秒。默认 0(禁用)。设置后,在超时时间内无 sendMessage 等操作会自动登出。 */
|
|
21
|
+
inactiveTimeout?: number;
|
|
22
|
+
};
|
|
23
|
+
type CompatibleImageInfo = {
|
|
24
|
+
type?: number;
|
|
25
|
+
size?: number;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
30
|
+
type CompatibleMessage = {
|
|
31
|
+
ID?: string;
|
|
32
|
+
to: string;
|
|
33
|
+
conversationType: string;
|
|
34
|
+
type: 'TIMTextElem' | 'TIMImageElem' | 'TIMFileElem';
|
|
35
|
+
payload: Record<string, unknown>;
|
|
36
|
+
cloudCustomData?: string;
|
|
37
|
+
_raw?: unknown;
|
|
38
|
+
};
|
|
39
|
+
type CompatibleIncomingMessage = {
|
|
40
|
+
ID?: string;
|
|
41
|
+
type: 'TIMTextElem' | 'TIMImageElem' | 'TIMFileElem';
|
|
42
|
+
payload?: {
|
|
43
|
+
text?: string;
|
|
44
|
+
imageInfoArray?: CompatibleImageInfo[];
|
|
45
|
+
imageFormat?: string;
|
|
46
|
+
fileUrl?: string;
|
|
47
|
+
fileName?: string;
|
|
48
|
+
fileSize?: number;
|
|
49
|
+
};
|
|
50
|
+
cloudCustomData: string;
|
|
51
|
+
time?: number;
|
|
52
|
+
clientTime?: number;
|
|
53
|
+
conversationID?: string;
|
|
54
|
+
_raw?: unknown;
|
|
55
|
+
};
|
|
56
|
+
type SendMessageResult = {
|
|
57
|
+
data?: {
|
|
58
|
+
message?: {
|
|
59
|
+
payload?: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
message?: {
|
|
63
|
+
payload?: Record<string, unknown>;
|
|
64
|
+
};
|
|
65
|
+
raw?: unknown;
|
|
66
|
+
};
|
|
67
|
+
type UploadImageResult = {
|
|
68
|
+
url: string;
|
|
69
|
+
uuid?: string;
|
|
70
|
+
imageFormat?: string;
|
|
71
|
+
imageInfoArray?: CompatibleImageInfo[];
|
|
72
|
+
width?: number;
|
|
73
|
+
height?: number;
|
|
74
|
+
size?: number;
|
|
75
|
+
};
|
|
76
|
+
type UploadFileResult = {
|
|
77
|
+
url: string;
|
|
78
|
+
uuid?: string;
|
|
79
|
+
fileName?: string;
|
|
80
|
+
fileSize?: number;
|
|
81
|
+
fileType?: string;
|
|
82
|
+
};
|
|
83
|
+
type UploadProvider = {
|
|
84
|
+
uploadImage(args: {
|
|
85
|
+
file: File;
|
|
86
|
+
onProgress?: (event: unknown) => void;
|
|
87
|
+
}): Promise<UploadImageResult>;
|
|
88
|
+
uploadFile(args: {
|
|
89
|
+
file: File;
|
|
90
|
+
onProgress?: (event: unknown) => void;
|
|
91
|
+
}): Promise<UploadFileResult>;
|
|
92
|
+
};
|
|
93
|
+
interface ChatIMClient {
|
|
94
|
+
registerPlugin(plugins: Record<string, unknown>): void;
|
|
95
|
+
setLogLevel(level: number): void;
|
|
96
|
+
on(eventName: EventName, listener: EventListener): void;
|
|
97
|
+
off(eventName: EventName, listener: EventListener): void;
|
|
98
|
+
login(options: LoginOptions): Promise<unknown>;
|
|
99
|
+
logout(): Promise<void>;
|
|
100
|
+
destroy(): Promise<void>;
|
|
101
|
+
isReady(): boolean;
|
|
102
|
+
createTextMessage(input: {
|
|
103
|
+
to: string;
|
|
104
|
+
conversationType: string;
|
|
105
|
+
payload: {
|
|
106
|
+
text: string;
|
|
107
|
+
};
|
|
108
|
+
cloudCustomData?: string;
|
|
109
|
+
}): CompatibleMessage;
|
|
110
|
+
createImageMessage(input: {
|
|
111
|
+
to: string;
|
|
112
|
+
conversationType: string;
|
|
113
|
+
payload: {
|
|
114
|
+
file: File;
|
|
115
|
+
};
|
|
116
|
+
onProgress?: (event: unknown) => void;
|
|
117
|
+
cloudCustomData?: string;
|
|
118
|
+
}): CompatibleMessage;
|
|
119
|
+
createFileMessage(input: {
|
|
120
|
+
to: string;
|
|
121
|
+
conversationType: string;
|
|
122
|
+
payload: {
|
|
123
|
+
file: File;
|
|
124
|
+
};
|
|
125
|
+
onProgress?: (event: unknown) => void;
|
|
126
|
+
cloudCustomData?: string;
|
|
127
|
+
}): CompatibleMessage;
|
|
128
|
+
sendMessage(message: CompatibleMessage): Promise<SendMessageResult>;
|
|
129
|
+
/** 重置闲置超时计时器。仅在 inactiveTimeout > 0 时有效。业务层可在用户交互(点击、滚动等)时调用。 */
|
|
130
|
+
resetInactiveTimer(): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare const EVENT: {
|
|
134
|
+
readonly SDK_READY: "SDK_READY";
|
|
135
|
+
readonly SDK_NOT_READY: "SDK_NOT_READY";
|
|
136
|
+
readonly NET_STATE_CHANGE: "NET_STATE_CHANGE";
|
|
137
|
+
readonly ERROR: "ERROR";
|
|
138
|
+
readonly KICKED_OUT: "KICKED_OUT";
|
|
139
|
+
readonly MESSAGE_RECEIVED: "MESSAGE_RECEIVED";
|
|
140
|
+
readonly MESSAGE_MODIFIED: "MESSAGE_MODIFIED";
|
|
141
|
+
};
|
|
142
|
+
declare const TYPES: {
|
|
143
|
+
readonly CONV_C2C: "C2C";
|
|
144
|
+
};
|
|
145
|
+
declare const DEFAULT_PLATFORM_ID = 5;
|
|
146
|
+
|
|
147
|
+
type DcimUploadProviderOptions = {
|
|
148
|
+
baseURL: string;
|
|
149
|
+
getToken?: () => Promise<string | undefined> | string | undefined;
|
|
150
|
+
getObjectName?: (file: File) => Promise<string | undefined> | string | undefined;
|
|
151
|
+
imageEndpoint?: string;
|
|
152
|
+
fileEndpoint?: string;
|
|
153
|
+
fetchImpl?: typeof fetch;
|
|
154
|
+
};
|
|
155
|
+
declare const createDcimUploadProvider: (options: DcimUploadProviderOptions) => UploadProvider;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* DCIMUploadPlugin — dcim-web-sdk 内置上传插件。
|
|
159
|
+
*
|
|
160
|
+
* 用法(和 Tencent IM 插件模式一致):
|
|
161
|
+
* import ChatIMSDK, { DCIMUploadPlugin } from 'dcim-web-sdk'
|
|
162
|
+
* const chat = ChatIMSDK.create({ apiAddr: '...', wsAddr: '...' })
|
|
163
|
+
* chat.registerPlugin({ 'dcim-upload-plugin': DCIMUploadPlugin })
|
|
164
|
+
*
|
|
165
|
+
* SDK 自动从 create() 的 apiAddr 和 login() 的 token 读取上传所需配置,
|
|
166
|
+
* 调用方无需额外传参。
|
|
167
|
+
*/
|
|
168
|
+
declare const DCIMUploadPlugin: {
|
|
169
|
+
__brand: "dcim-upload-plugin";
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
declare const create: (options: CreateOptions) => ChatIMClient;
|
|
173
|
+
declare const ChatIMSDK: {
|
|
174
|
+
EVENT: {
|
|
175
|
+
readonly SDK_READY: "SDK_READY";
|
|
176
|
+
readonly SDK_NOT_READY: "SDK_NOT_READY";
|
|
177
|
+
readonly NET_STATE_CHANGE: "NET_STATE_CHANGE";
|
|
178
|
+
readonly ERROR: "ERROR";
|
|
179
|
+
readonly KICKED_OUT: "KICKED_OUT";
|
|
180
|
+
readonly MESSAGE_RECEIVED: "MESSAGE_RECEIVED";
|
|
181
|
+
readonly MESSAGE_MODIFIED: "MESSAGE_MODIFIED";
|
|
182
|
+
};
|
|
183
|
+
TYPES: {
|
|
184
|
+
readonly CONV_C2C: "C2C";
|
|
185
|
+
};
|
|
186
|
+
create: (options: CreateOptions) => ChatIMClient;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export { type ChatIMClient, type CompatEventPayload, type CompatibleImageInfo, type CompatibleIncomingMessage, type CompatibleMessage, type CreateOptions, DCIMUploadPlugin, DEFAULT_PLATFORM_ID, EVENT, type EventListener, type EventName, type LoginOptions, type SendMessageResult, TYPES, type UploadFileResult, type UploadImageResult, type UploadProvider, create, createDcimUploadProvider, ChatIMSDK as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
type EventName = string;
|
|
2
|
+
type EventListener<T = unknown> = (event: T) => void;
|
|
3
|
+
type CompatEventPayload = {
|
|
4
|
+
name?: string;
|
|
5
|
+
data?: unknown;
|
|
6
|
+
};
|
|
7
|
+
type LoginOptions = {
|
|
8
|
+
userID: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
apiAddr?: string;
|
|
11
|
+
wsAddr?: string;
|
|
12
|
+
};
|
|
13
|
+
type CreateOptions = {
|
|
14
|
+
userID?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
apiAddr: string;
|
|
17
|
+
wsAddr: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
uploader?: UploadProvider;
|
|
20
|
+
/** 闲置超时断开,单位毫秒。默认 0(禁用)。设置后,在超时时间内无 sendMessage 等操作会自动登出。 */
|
|
21
|
+
inactiveTimeout?: number;
|
|
22
|
+
};
|
|
23
|
+
type CompatibleImageInfo = {
|
|
24
|
+
type?: number;
|
|
25
|
+
size?: number;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
30
|
+
type CompatibleMessage = {
|
|
31
|
+
ID?: string;
|
|
32
|
+
to: string;
|
|
33
|
+
conversationType: string;
|
|
34
|
+
type: 'TIMTextElem' | 'TIMImageElem' | 'TIMFileElem';
|
|
35
|
+
payload: Record<string, unknown>;
|
|
36
|
+
cloudCustomData?: string;
|
|
37
|
+
_raw?: unknown;
|
|
38
|
+
};
|
|
39
|
+
type CompatibleIncomingMessage = {
|
|
40
|
+
ID?: string;
|
|
41
|
+
type: 'TIMTextElem' | 'TIMImageElem' | 'TIMFileElem';
|
|
42
|
+
payload?: {
|
|
43
|
+
text?: string;
|
|
44
|
+
imageInfoArray?: CompatibleImageInfo[];
|
|
45
|
+
imageFormat?: string;
|
|
46
|
+
fileUrl?: string;
|
|
47
|
+
fileName?: string;
|
|
48
|
+
fileSize?: number;
|
|
49
|
+
};
|
|
50
|
+
cloudCustomData: string;
|
|
51
|
+
time?: number;
|
|
52
|
+
clientTime?: number;
|
|
53
|
+
conversationID?: string;
|
|
54
|
+
_raw?: unknown;
|
|
55
|
+
};
|
|
56
|
+
type SendMessageResult = {
|
|
57
|
+
data?: {
|
|
58
|
+
message?: {
|
|
59
|
+
payload?: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
message?: {
|
|
63
|
+
payload?: Record<string, unknown>;
|
|
64
|
+
};
|
|
65
|
+
raw?: unknown;
|
|
66
|
+
};
|
|
67
|
+
type UploadImageResult = {
|
|
68
|
+
url: string;
|
|
69
|
+
uuid?: string;
|
|
70
|
+
imageFormat?: string;
|
|
71
|
+
imageInfoArray?: CompatibleImageInfo[];
|
|
72
|
+
width?: number;
|
|
73
|
+
height?: number;
|
|
74
|
+
size?: number;
|
|
75
|
+
};
|
|
76
|
+
type UploadFileResult = {
|
|
77
|
+
url: string;
|
|
78
|
+
uuid?: string;
|
|
79
|
+
fileName?: string;
|
|
80
|
+
fileSize?: number;
|
|
81
|
+
fileType?: string;
|
|
82
|
+
};
|
|
83
|
+
type UploadProvider = {
|
|
84
|
+
uploadImage(args: {
|
|
85
|
+
file: File;
|
|
86
|
+
onProgress?: (event: unknown) => void;
|
|
87
|
+
}): Promise<UploadImageResult>;
|
|
88
|
+
uploadFile(args: {
|
|
89
|
+
file: File;
|
|
90
|
+
onProgress?: (event: unknown) => void;
|
|
91
|
+
}): Promise<UploadFileResult>;
|
|
92
|
+
};
|
|
93
|
+
interface ChatIMClient {
|
|
94
|
+
registerPlugin(plugins: Record<string, unknown>): void;
|
|
95
|
+
setLogLevel(level: number): void;
|
|
96
|
+
on(eventName: EventName, listener: EventListener): void;
|
|
97
|
+
off(eventName: EventName, listener: EventListener): void;
|
|
98
|
+
login(options: LoginOptions): Promise<unknown>;
|
|
99
|
+
logout(): Promise<void>;
|
|
100
|
+
destroy(): Promise<void>;
|
|
101
|
+
isReady(): boolean;
|
|
102
|
+
createTextMessage(input: {
|
|
103
|
+
to: string;
|
|
104
|
+
conversationType: string;
|
|
105
|
+
payload: {
|
|
106
|
+
text: string;
|
|
107
|
+
};
|
|
108
|
+
cloudCustomData?: string;
|
|
109
|
+
}): CompatibleMessage;
|
|
110
|
+
createImageMessage(input: {
|
|
111
|
+
to: string;
|
|
112
|
+
conversationType: string;
|
|
113
|
+
payload: {
|
|
114
|
+
file: File;
|
|
115
|
+
};
|
|
116
|
+
onProgress?: (event: unknown) => void;
|
|
117
|
+
cloudCustomData?: string;
|
|
118
|
+
}): CompatibleMessage;
|
|
119
|
+
createFileMessage(input: {
|
|
120
|
+
to: string;
|
|
121
|
+
conversationType: string;
|
|
122
|
+
payload: {
|
|
123
|
+
file: File;
|
|
124
|
+
};
|
|
125
|
+
onProgress?: (event: unknown) => void;
|
|
126
|
+
cloudCustomData?: string;
|
|
127
|
+
}): CompatibleMessage;
|
|
128
|
+
sendMessage(message: CompatibleMessage): Promise<SendMessageResult>;
|
|
129
|
+
/** 重置闲置超时计时器。仅在 inactiveTimeout > 0 时有效。业务层可在用户交互(点击、滚动等)时调用。 */
|
|
130
|
+
resetInactiveTimer(): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare const EVENT: {
|
|
134
|
+
readonly SDK_READY: "SDK_READY";
|
|
135
|
+
readonly SDK_NOT_READY: "SDK_NOT_READY";
|
|
136
|
+
readonly NET_STATE_CHANGE: "NET_STATE_CHANGE";
|
|
137
|
+
readonly ERROR: "ERROR";
|
|
138
|
+
readonly KICKED_OUT: "KICKED_OUT";
|
|
139
|
+
readonly MESSAGE_RECEIVED: "MESSAGE_RECEIVED";
|
|
140
|
+
readonly MESSAGE_MODIFIED: "MESSAGE_MODIFIED";
|
|
141
|
+
};
|
|
142
|
+
declare const TYPES: {
|
|
143
|
+
readonly CONV_C2C: "C2C";
|
|
144
|
+
};
|
|
145
|
+
declare const DEFAULT_PLATFORM_ID = 5;
|
|
146
|
+
|
|
147
|
+
type DcimUploadProviderOptions = {
|
|
148
|
+
baseURL: string;
|
|
149
|
+
getToken?: () => Promise<string | undefined> | string | undefined;
|
|
150
|
+
getObjectName?: (file: File) => Promise<string | undefined> | string | undefined;
|
|
151
|
+
imageEndpoint?: string;
|
|
152
|
+
fileEndpoint?: string;
|
|
153
|
+
fetchImpl?: typeof fetch;
|
|
154
|
+
};
|
|
155
|
+
declare const createDcimUploadProvider: (options: DcimUploadProviderOptions) => UploadProvider;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* DCIMUploadPlugin — dcim-web-sdk 内置上传插件。
|
|
159
|
+
*
|
|
160
|
+
* 用法(和 Tencent IM 插件模式一致):
|
|
161
|
+
* import ChatIMSDK, { DCIMUploadPlugin } from 'dcim-web-sdk'
|
|
162
|
+
* const chat = ChatIMSDK.create({ apiAddr: '...', wsAddr: '...' })
|
|
163
|
+
* chat.registerPlugin({ 'dcim-upload-plugin': DCIMUploadPlugin })
|
|
164
|
+
*
|
|
165
|
+
* SDK 自动从 create() 的 apiAddr 和 login() 的 token 读取上传所需配置,
|
|
166
|
+
* 调用方无需额外传参。
|
|
167
|
+
*/
|
|
168
|
+
declare const DCIMUploadPlugin: {
|
|
169
|
+
__brand: "dcim-upload-plugin";
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
declare const create: (options: CreateOptions) => ChatIMClient;
|
|
173
|
+
declare const ChatIMSDK: {
|
|
174
|
+
EVENT: {
|
|
175
|
+
readonly SDK_READY: "SDK_READY";
|
|
176
|
+
readonly SDK_NOT_READY: "SDK_NOT_READY";
|
|
177
|
+
readonly NET_STATE_CHANGE: "NET_STATE_CHANGE";
|
|
178
|
+
readonly ERROR: "ERROR";
|
|
179
|
+
readonly KICKED_OUT: "KICKED_OUT";
|
|
180
|
+
readonly MESSAGE_RECEIVED: "MESSAGE_RECEIVED";
|
|
181
|
+
readonly MESSAGE_MODIFIED: "MESSAGE_MODIFIED";
|
|
182
|
+
};
|
|
183
|
+
TYPES: {
|
|
184
|
+
readonly CONV_C2C: "C2C";
|
|
185
|
+
};
|
|
186
|
+
create: (options: CreateOptions) => ChatIMClient;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export { type ChatIMClient, type CompatEventPayload, type CompatibleImageInfo, type CompatibleIncomingMessage, type CompatibleMessage, type CreateOptions, DCIMUploadPlugin, DEFAULT_PLATFORM_ID, EVENT, type EventListener, type EventName, type LoginOptions, type SendMessageResult, TYPES, type UploadFileResult, type UploadImageResult, type UploadProvider, create, createDcimUploadProvider, ChatIMSDK as default };
|