@saiboniuma/realtime-core 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 +68 -0
- package/dist/index.d.ts +1044 -0
- package/dist/realtime-core.js +1265 -0
- package/dist/realtime-core.umd.cjs +1 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1044 @@
|
|
|
1
|
+
import { HubConnection } from '@microsoft/signalr';
|
|
2
|
+
|
|
3
|
+
/** 通用 API 响应 */
|
|
4
|
+
export declare interface ApiResponse<T = unknown> {
|
|
5
|
+
code: number;
|
|
6
|
+
message: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
data: T;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 分配的客服信息 */
|
|
12
|
+
export declare interface AssignedAgentInfo {
|
|
13
|
+
agentUserId: string;
|
|
14
|
+
nickname: string;
|
|
15
|
+
avatar: string;
|
|
16
|
+
onlineStatus: KefuOnlineStatus;
|
|
17
|
+
isOnline: boolean;
|
|
18
|
+
welcomeMessage?: string;
|
|
19
|
+
autoSendWelcome: boolean;
|
|
20
|
+
/** 预计算的 Realtime 会话 ID */
|
|
21
|
+
conversationId?: string;
|
|
22
|
+
/** 会话群组 ID(统一群聊模式) */
|
|
23
|
+
groupId?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 认证服务,处理 Token 获取和用户信息更新 */
|
|
27
|
+
export declare class AuthService {
|
|
28
|
+
private baseURL;
|
|
29
|
+
constructor(baseURL: string);
|
|
30
|
+
/** 获取 Token(完整参数版) */
|
|
31
|
+
getToken(request: GetTokenRequest): Promise<GetTokenResponse>;
|
|
32
|
+
/** 获取 Token(简化参数版) */
|
|
33
|
+
getTokenSimple(platformKey: string, userId?: string, platformType?: PlatformType, options?: {
|
|
34
|
+
nickname?: string;
|
|
35
|
+
avatar?: string;
|
|
36
|
+
deviceId?: string;
|
|
37
|
+
metadata?: string;
|
|
38
|
+
source?: string;
|
|
39
|
+
}): Promise<GetTokenResponse>;
|
|
40
|
+
/** 更新用户信息 */
|
|
41
|
+
updateUserInfo(platformKey: string, deviceId: string, userId?: string, nickname?: string, avatar?: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 聊天用户资料 */
|
|
45
|
+
export declare interface ChatUserProfile {
|
|
46
|
+
userId: string;
|
|
47
|
+
userType: ChatUserType;
|
|
48
|
+
isNewUser: boolean;
|
|
49
|
+
nickname: string;
|
|
50
|
+
avatar: string;
|
|
51
|
+
externalUserId?: string;
|
|
52
|
+
deviceId?: string;
|
|
53
|
+
firstVisitTime?: string;
|
|
54
|
+
tags?: string[];
|
|
55
|
+
metadata?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 聊天用户类型枚举 */
|
|
59
|
+
export declare const ChatUserType: {
|
|
60
|
+
readonly Anonymous: 0;
|
|
61
|
+
readonly Authenticated: 1;
|
|
62
|
+
readonly VIP: 2;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export declare type ChatUserType = (typeof ChatUserType)[keyof typeof ChatUserType];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 熔断器
|
|
69
|
+
* 三态模式:Closed -> Open -> HalfOpen -> Closed
|
|
70
|
+
*/
|
|
71
|
+
export declare class CircuitBreaker {
|
|
72
|
+
private readonly failureThreshold;
|
|
73
|
+
private readonly resetTimeout;
|
|
74
|
+
private readonly successThreshold;
|
|
75
|
+
private _state;
|
|
76
|
+
private failureCount;
|
|
77
|
+
private successCount;
|
|
78
|
+
private openTimestamp;
|
|
79
|
+
private stateChangeListeners;
|
|
80
|
+
constructor(options?: CircuitBreakerOptions);
|
|
81
|
+
/** 当前熔断器状态 */
|
|
82
|
+
get state(): CircuitState;
|
|
83
|
+
/** 注册状态变化监听 */
|
|
84
|
+
onStateChanged(callback: (data: CircuitStateChangedData) => void): void;
|
|
85
|
+
/** 移除状态变化监听 */
|
|
86
|
+
offStateChanged(callback: (data: CircuitStateChangedData) => void): void;
|
|
87
|
+
/** 切换状态 */
|
|
88
|
+
private transitionTo;
|
|
89
|
+
/** 记录成功 */
|
|
90
|
+
recordSuccess(): void;
|
|
91
|
+
/** 记录失败,达到阈值则打开 */
|
|
92
|
+
recordFailure(): void;
|
|
93
|
+
/** 是否可以尝试(半开时探测) */
|
|
94
|
+
canAttempt(): boolean;
|
|
95
|
+
/** 重置为关闭状态 */
|
|
96
|
+
reset(): void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 熔断器配置 */
|
|
100
|
+
export declare interface CircuitBreakerOptions {
|
|
101
|
+
/** 失败阈值,达到后熔断器打开,默认 10 */
|
|
102
|
+
failureThreshold?: number;
|
|
103
|
+
/** 重置超时时间(毫秒),打开状态持续多久后进入半开,默认 60000 */
|
|
104
|
+
resetTimeout?: number;
|
|
105
|
+
/** 半开状态下成功阈值,达到后熔断器关闭,默认 3 */
|
|
106
|
+
successThreshold?: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 熔断器状态 */
|
|
110
|
+
export declare enum CircuitState {
|
|
111
|
+
/** 关闭状态:正常通行,记录失败次数 */
|
|
112
|
+
Closed = "Closed",
|
|
113
|
+
/** 打开状态:失败达到阈值,拒绝请求 */
|
|
114
|
+
Open = "Open",
|
|
115
|
+
/** 半开状态:超时后探测,尝试少量请求 */
|
|
116
|
+
HalfOpen = "HalfOpen"
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 熔断器状态变化事件数据 */
|
|
120
|
+
export declare interface CircuitStateChangedData {
|
|
121
|
+
from: CircuitState;
|
|
122
|
+
to: CircuitState;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 统一消息分类函数
|
|
127
|
+
*/
|
|
128
|
+
export declare function classifyMessage(message: Message): MessageClassification;
|
|
129
|
+
|
|
130
|
+
/** 客户端设备信息 */
|
|
131
|
+
export declare interface ClientDeviceInfo {
|
|
132
|
+
userAgent: string;
|
|
133
|
+
platform: string;
|
|
134
|
+
screenWidth: number;
|
|
135
|
+
screenHeight: number;
|
|
136
|
+
viewportWidth: number;
|
|
137
|
+
viewportHeight: number;
|
|
138
|
+
devicePixelRatio: number;
|
|
139
|
+
colorDepth: number;
|
|
140
|
+
connectionType?: string;
|
|
141
|
+
effectiveType?: string;
|
|
142
|
+
downlink?: number;
|
|
143
|
+
rtt?: number;
|
|
144
|
+
language: string;
|
|
145
|
+
languages: string[];
|
|
146
|
+
timezone: string;
|
|
147
|
+
timezoneOffset: number;
|
|
148
|
+
currentUrl: string;
|
|
149
|
+
pageTitle: string;
|
|
150
|
+
referrer: string;
|
|
151
|
+
touchSupport: boolean;
|
|
152
|
+
maxTouchPoints: number;
|
|
153
|
+
deviceMemory?: number;
|
|
154
|
+
hardwareConcurrency?: number;
|
|
155
|
+
cookieEnabled: boolean;
|
|
156
|
+
prefersDarkMode: boolean;
|
|
157
|
+
online: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 采集设备信息 */
|
|
161
|
+
export declare function collectDeviceInfo(): ClientDeviceInfo;
|
|
162
|
+
|
|
163
|
+
/** 连接状态枚举 */
|
|
164
|
+
export declare const ConnectionStatus: {
|
|
165
|
+
readonly CONNECTING: 0;
|
|
166
|
+
readonly CONNECTED: 1;
|
|
167
|
+
readonly DISCONNECTED: 2;
|
|
168
|
+
readonly FAILED: 3;
|
|
169
|
+
readonly RECONNECTING: 4;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export declare type ConnectionStatus = (typeof ConnectionStatus)[keyof typeof ConnectionStatus];
|
|
173
|
+
|
|
174
|
+
/** 会话对象 */
|
|
175
|
+
export declare interface Conversation {
|
|
176
|
+
conversationID: string;
|
|
177
|
+
conversationType: number;
|
|
178
|
+
userID: string;
|
|
179
|
+
groupID: string;
|
|
180
|
+
showName: string;
|
|
181
|
+
faceURL: string;
|
|
182
|
+
recvMsgOpt: number;
|
|
183
|
+
unreadCount: number;
|
|
184
|
+
latestMsg: string;
|
|
185
|
+
latestMsgSendTime: number;
|
|
186
|
+
draftText: string;
|
|
187
|
+
draftTextTime: number;
|
|
188
|
+
isPinned: boolean;
|
|
189
|
+
isPrivateChat: boolean;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** 会话服务(基于 SignalR Hub) */
|
|
193
|
+
export declare class ConversationService {
|
|
194
|
+
private client;
|
|
195
|
+
constructor(client: IRealtimeClient_3);
|
|
196
|
+
/** 获取会话列表 */
|
|
197
|
+
getList(count?: number): Promise<Conversation[]>;
|
|
198
|
+
/** 根据用户 ID 获取单个会话 */
|
|
199
|
+
getOne(userID: string, sessionType?: number): Promise<Conversation | null>;
|
|
200
|
+
/** 加入会话组(接收该会话的实时消息推送) */
|
|
201
|
+
joinConversation(conversationId: string): Promise<void>;
|
|
202
|
+
/** 离开会话组 */
|
|
203
|
+
leaveConversation(conversationId: string): Promise<void>;
|
|
204
|
+
/** 获取历史消息 */
|
|
205
|
+
getHistory(conversationID: string, count?: number, startClientMsgID?: string): Promise<Message[]>;
|
|
206
|
+
/** 标记会话消息已读 */
|
|
207
|
+
markAsRead(conversationID: string): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 创建 Realtime 核心客户端实例(工厂函数) */
|
|
211
|
+
export declare function createRealtimeCore(config: RealtimeCoreConfig): RealtimeClient;
|
|
212
|
+
|
|
213
|
+
/** 自定义消息元素 */
|
|
214
|
+
export declare interface CustomElem {
|
|
215
|
+
data: string;
|
|
216
|
+
extension: string;
|
|
217
|
+
description: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 自定义图片消息数据 */
|
|
221
|
+
export declare interface CustomImageData {
|
|
222
|
+
type: 'image';
|
|
223
|
+
url: string;
|
|
224
|
+
width: number;
|
|
225
|
+
height: number;
|
|
226
|
+
size: number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 送达回执信息 */
|
|
230
|
+
export declare interface DeliveryReceiptInfo {
|
|
231
|
+
conversationId: string;
|
|
232
|
+
userId: string;
|
|
233
|
+
seq: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** 事件回调函数 */
|
|
237
|
+
export declare type EventCallback<T = unknown> = (data: T) => void;
|
|
238
|
+
|
|
239
|
+
/** 类型安全的事件管理器 */
|
|
240
|
+
export declare class EventManager {
|
|
241
|
+
private listeners;
|
|
242
|
+
/** 注册事件监听 */
|
|
243
|
+
on<E extends RealtimeEventType>(event: E, callback: EventCallback<RealtimeEventMap[E]>): void;
|
|
244
|
+
/** 移除事件监听 */
|
|
245
|
+
off<E extends RealtimeEventType>(event: E, callback: EventCallback<RealtimeEventMap[E]>): void;
|
|
246
|
+
/** 触发事件 */
|
|
247
|
+
emit<E extends RealtimeEventType>(event: E, data: RealtimeEventMap[E]): void;
|
|
248
|
+
/** 清除所有事件监听 */
|
|
249
|
+
clear(): void;
|
|
250
|
+
/** 清除指定事件的所有监听 */
|
|
251
|
+
clearEvent(event: RealtimeEventType): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** 功能开关 */
|
|
255
|
+
export declare interface FeatureFlags {
|
|
256
|
+
allowImage: boolean;
|
|
257
|
+
allowFile: boolean;
|
|
258
|
+
allowVoice: boolean;
|
|
259
|
+
showOnlineStatus: boolean;
|
|
260
|
+
showReadStatus: boolean;
|
|
261
|
+
enableSatisfactionRating: boolean;
|
|
262
|
+
enableVisitorForm: boolean;
|
|
263
|
+
enableQueue: boolean;
|
|
264
|
+
enableBroadcast: boolean;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** 获取或生成客户端 ID(持久化到 localStorage) */
|
|
268
|
+
export declare function getClientId(): string;
|
|
269
|
+
|
|
270
|
+
export declare function getLogLevel(): number;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 获取消息的摘要文本(用于会话列表预览)
|
|
274
|
+
*/
|
|
275
|
+
export declare function getMessagePreview(message: Message): string;
|
|
276
|
+
|
|
277
|
+
/** 获取系统消息的显示文本,非系统消息或 session_init 返回空字符串 */
|
|
278
|
+
export declare function getSystemMessageLabel(message: Message): string;
|
|
279
|
+
|
|
280
|
+
/** 从消息中提取系统消息类型,非系统消息返回 null */
|
|
281
|
+
export declare function getSystemMessageType(message: Message): SystemMessageType | null;
|
|
282
|
+
|
|
283
|
+
/** 获取 Token 请求参数 */
|
|
284
|
+
export declare interface GetTokenRequest {
|
|
285
|
+
platformKey: string;
|
|
286
|
+
deviceId?: string;
|
|
287
|
+
userId?: string;
|
|
288
|
+
clientId?: string;
|
|
289
|
+
nickname?: string;
|
|
290
|
+
avatar?: string;
|
|
291
|
+
metadata?: string;
|
|
292
|
+
platformType?: PlatformType;
|
|
293
|
+
deviceInfo?: string;
|
|
294
|
+
/** 接入来源标识:js | vue | chat */
|
|
295
|
+
source?: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** 获取 Token 响应 */
|
|
299
|
+
export declare interface GetTokenResponse {
|
|
300
|
+
userID: string;
|
|
301
|
+
token: string;
|
|
302
|
+
expireTime: number;
|
|
303
|
+
user: ChatUserProfile;
|
|
304
|
+
agent: AssignedAgentInfo | null;
|
|
305
|
+
platform: PlatformConfigInfo | null;
|
|
306
|
+
features: FeatureFlags;
|
|
307
|
+
/** 排队信息(当并发会话超限时返回) */
|
|
308
|
+
queue?: QueueInfo;
|
|
309
|
+
/** 访客表单配置(启用时返回) */
|
|
310
|
+
visitorForm?: VisitorFormConfig;
|
|
311
|
+
/** Realtime 连接配置(服务端下发) */
|
|
312
|
+
realtimeConfig?: RealtimeConfig;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** 检查是否已有客户端 ID */
|
|
316
|
+
export declare function hasClientId(): boolean;
|
|
317
|
+
|
|
318
|
+
/** RealtimeClient 接口(避免循环依赖) */
|
|
319
|
+
declare interface IRealtimeClient {
|
|
320
|
+
login(userId: string, token: string): Promise<boolean>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** RealtimeClient 接口(避免循环依赖) */
|
|
324
|
+
declare interface IRealtimeClient_2 {
|
|
325
|
+
getHub(): HubConnection;
|
|
326
|
+
getConversationId(): string;
|
|
327
|
+
getCurrentUserId(): string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** RealtimeClient 接口(避免循环依赖) */
|
|
331
|
+
declare interface IRealtimeClient_3 {
|
|
332
|
+
getHub(): HubConnection;
|
|
333
|
+
getConversationId(): string;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 判断是否为应在聊天窗口中显示的系统消息
|
|
338
|
+
* session_init 不显示,其余(上线/离线/信息更新)显示
|
|
339
|
+
*/
|
|
340
|
+
export declare function isDisplayableSystemMessage(message: Message): boolean;
|
|
341
|
+
|
|
342
|
+
/** 判断消息是否为系统消息 */
|
|
343
|
+
export declare function isSystemMessage(message: Message): boolean;
|
|
344
|
+
|
|
345
|
+
/** 客服在线状态枚举 */
|
|
346
|
+
export declare const KefuOnlineStatus: {
|
|
347
|
+
readonly Offline: 0;
|
|
348
|
+
readonly Online: 1;
|
|
349
|
+
readonly Busy: 2;
|
|
350
|
+
readonly Away: 3;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export declare type KefuOnlineStatus = (typeof KefuOnlineStatus)[keyof typeof KefuOnlineStatus];
|
|
354
|
+
|
|
355
|
+
export declare const logger: {
|
|
356
|
+
verbose: (tag: string, ...args: unknown[]) => false | void;
|
|
357
|
+
debug: (tag: string, ...args: unknown[]) => false | void;
|
|
358
|
+
info: (tag: string, ...args: unknown[]) => false | void;
|
|
359
|
+
warn: (tag: string, ...args: unknown[]) => false | void;
|
|
360
|
+
error: (tag: string, ...args: unknown[]) => false | void;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/** 将 C# RealtimeConversation 映射为 JS Conversation */
|
|
364
|
+
export declare function mapToConversation(raw: any): Conversation | null;
|
|
365
|
+
|
|
366
|
+
/** 将 C# RealtimeConversation 数组映射为 JS Conversation 数组 */
|
|
367
|
+
export declare function mapToConversationList(raw: any): Conversation[];
|
|
368
|
+
|
|
369
|
+
/** 将 C# RealtimeMessage 映射为 JS Message */
|
|
370
|
+
export declare function mapToMessage(raw: any): Message | null;
|
|
371
|
+
|
|
372
|
+
/** 将 C# RealtimeUserInfo 映射为 JS UserInfo */
|
|
373
|
+
export declare function mapToUserInfo(raw: any): UserInfo | null;
|
|
374
|
+
|
|
375
|
+
/** 消息对象 */
|
|
376
|
+
export declare interface Message {
|
|
377
|
+
clientMsgID: string;
|
|
378
|
+
serverMsgID: string;
|
|
379
|
+
createTime: number;
|
|
380
|
+
sendTime: number;
|
|
381
|
+
sendID: string;
|
|
382
|
+
recvID: string;
|
|
383
|
+
msgFrom: number;
|
|
384
|
+
contentType: MessageType | number | string;
|
|
385
|
+
senderNickname: string;
|
|
386
|
+
senderFaceUrl: string;
|
|
387
|
+
content: string;
|
|
388
|
+
textElem?: TextElement;
|
|
389
|
+
pictureElem?: PictureElem;
|
|
390
|
+
customElem?: CustomElem;
|
|
391
|
+
conversationID: string;
|
|
392
|
+
isRead: boolean;
|
|
393
|
+
/** 消息状态(对应 MessageStatus) */
|
|
394
|
+
status: number;
|
|
395
|
+
/** 送达时间(ISO 字符串) */
|
|
396
|
+
deliveredAt?: string;
|
|
397
|
+
/** 已读时间(ISO 字符串) */
|
|
398
|
+
readAt?: string;
|
|
399
|
+
/** 编辑时间(ISO 字符串) */
|
|
400
|
+
editedAt?: string;
|
|
401
|
+
/** 编辑前内容 */
|
|
402
|
+
previousContent?: string;
|
|
403
|
+
/** 撤回标记(与 status=Withdrawn 同步) */
|
|
404
|
+
isWithdrawn?: boolean;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** 消息分类结果 */
|
|
408
|
+
export declare interface MessageClassification {
|
|
409
|
+
showInChat: boolean;
|
|
410
|
+
showInListPreview: boolean;
|
|
411
|
+
previewText: string;
|
|
412
|
+
systemType: SystemMessageType | null;
|
|
413
|
+
systemLabel: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** 消息删除事件数据 */
|
|
417
|
+
declare interface MessageDeletedInfo {
|
|
418
|
+
conversationId: string;
|
|
419
|
+
seq: number;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** 数据解析工具 — SignalR 返回的数据已经是对象,无需 JSON.parse */
|
|
423
|
+
export declare class MessageParser {
|
|
424
|
+
/** 透传数据(SignalR 自动反序列化 JSON 为对象) */
|
|
425
|
+
static parse<T>(data: unknown): T;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** 消息收发服务(基于 SignalR Hub) */
|
|
429
|
+
export declare class MessageService {
|
|
430
|
+
private client;
|
|
431
|
+
/** 前端消息类型注册表 */
|
|
432
|
+
readonly types: MessageTypeRegistry;
|
|
433
|
+
constructor(client: IRealtimeClient_2);
|
|
434
|
+
/** 判断是否为系统消息(静态方法,供外部调用) */
|
|
435
|
+
static isSystemMessage(message: Message): boolean;
|
|
436
|
+
/** 发送文本消息 */
|
|
437
|
+
sendText(_recvID: string, text: string, _isGroup?: boolean): Promise<Message>;
|
|
438
|
+
/** 发送图片消息 */
|
|
439
|
+
sendImage(_recvID: string, _file: File, imageUrl: string, imageInfo: {
|
|
440
|
+
width: number;
|
|
441
|
+
height: number;
|
|
442
|
+
size: number;
|
|
443
|
+
type: string;
|
|
444
|
+
}, _isGroup?: boolean): Promise<Message>;
|
|
445
|
+
/** 发送自定义消息 */
|
|
446
|
+
sendCustomMessage(_recvID: string, data: string, extension: string, description: string): Promise<Message>;
|
|
447
|
+
/** 发送系统消息(通用) */
|
|
448
|
+
sendSystemMessage(type: string, data: Record<string, unknown>): Promise<void>;
|
|
449
|
+
/** 发送用户信息更新系统消息 */
|
|
450
|
+
sendUserInfoUpdated(_agentUserID: string, updates: {
|
|
451
|
+
nickname?: string;
|
|
452
|
+
avatar?: string;
|
|
453
|
+
userId?: string;
|
|
454
|
+
}, previousValues?: {
|
|
455
|
+
nickname?: string;
|
|
456
|
+
avatar?: string;
|
|
457
|
+
userId?: string;
|
|
458
|
+
}): Promise<void>;
|
|
459
|
+
/** 发送会话初始化系统消息 */
|
|
460
|
+
sendSessionInit(_agentUserID: string, info: {
|
|
461
|
+
visitorId: string;
|
|
462
|
+
platformKey: string;
|
|
463
|
+
reason: 'login' | 'reconnect' | 'refresh';
|
|
464
|
+
}): Promise<void>;
|
|
465
|
+
/** 发送访客离线系统消息 */
|
|
466
|
+
sendVisitorOffline(_agentUserID: string, info: {
|
|
467
|
+
visitorId: string;
|
|
468
|
+
reason: string;
|
|
469
|
+
sessionDuration?: number;
|
|
470
|
+
}): Promise<void>;
|
|
471
|
+
/** 发送访客上线系统消息 */
|
|
472
|
+
sendVisitorOnline(_agentUserID: string, visitorInfo: {
|
|
473
|
+
visitorId: string;
|
|
474
|
+
deviceId: string;
|
|
475
|
+
nickname: string;
|
|
476
|
+
avatar: string;
|
|
477
|
+
isAnonymous: boolean;
|
|
478
|
+
userType?: number;
|
|
479
|
+
source: string;
|
|
480
|
+
platformType: number;
|
|
481
|
+
metadata?: Record<string, unknown>;
|
|
482
|
+
pageUrl?: string;
|
|
483
|
+
pageTitle?: string;
|
|
484
|
+
referrer?: string;
|
|
485
|
+
}): Promise<void>;
|
|
486
|
+
/**
|
|
487
|
+
* 上报消息送达(AcknowledgeDelivery)
|
|
488
|
+
* @param conversationId 会话 ID
|
|
489
|
+
* @param seq 消息序号
|
|
490
|
+
*/
|
|
491
|
+
acknowledgeDelivery(conversationId: string, seq: number): Promise<void>;
|
|
492
|
+
/**
|
|
493
|
+
* 上报消息已读(AcknowledgeRead)
|
|
494
|
+
* @param conversationId 会话 ID
|
|
495
|
+
* @param lastReadSeq 最后已读消息序号
|
|
496
|
+
*/
|
|
497
|
+
acknowledgeRead(conversationId: string, lastReadSeq: number): Promise<void>;
|
|
498
|
+
/**
|
|
499
|
+
* 撤回消息(WithdrawMessage)
|
|
500
|
+
* @param conversationId 会话 ID
|
|
501
|
+
* @param seq 消息序号
|
|
502
|
+
* @returns 撤回后的消息对象(status=Withdrawn),失败返回 null
|
|
503
|
+
*/
|
|
504
|
+
withdraw(conversationId: string, seq: number): Promise<Message | null>;
|
|
505
|
+
/**
|
|
506
|
+
* 编辑消息(EditMessage)
|
|
507
|
+
* @param conversationId 会话 ID
|
|
508
|
+
* @param seq 消息序号
|
|
509
|
+
* @param newContent 新内容
|
|
510
|
+
* @returns 编辑后的消息对象(status=Edited),失败返回 null
|
|
511
|
+
*/
|
|
512
|
+
edit(conversationId: string, seq: number, newContent: string): Promise<Message | null>;
|
|
513
|
+
/**
|
|
514
|
+
* 删除消息(DeleteMessage)
|
|
515
|
+
* @param conversationId 会话 ID
|
|
516
|
+
* @param seq 消息序号
|
|
517
|
+
*/
|
|
518
|
+
deleteMessage(conversationId: string, seq: number): Promise<void>;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** 消息状态枚举(8 态) */
|
|
522
|
+
export declare const MessageStatus: {
|
|
523
|
+
readonly Sending: 1;
|
|
524
|
+
readonly Sent: 2;
|
|
525
|
+
/** @deprecated 请使用 MessageStatus.Sent,值相同,向后兼容 */
|
|
526
|
+
readonly Success: 2;
|
|
527
|
+
readonly Delivered: 3;
|
|
528
|
+
readonly Read: 4;
|
|
529
|
+
readonly Failed: 5;
|
|
530
|
+
readonly Withdrawn: 6;
|
|
531
|
+
readonly Edited: 7;
|
|
532
|
+
readonly Deleted: 8;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
export declare type MessageStatus = (typeof MessageStatus)[keyof typeof MessageStatus];
|
|
536
|
+
|
|
537
|
+
/** 消息类型枚举(数字类型 + 命名空间字符串类型) */
|
|
538
|
+
export declare const MessageType: {
|
|
539
|
+
readonly TextMessage: 101;
|
|
540
|
+
readonly PictureMessage: 102;
|
|
541
|
+
readonly VoiceMessage: 103;
|
|
542
|
+
readonly VideoMessage: 104;
|
|
543
|
+
readonly FileMessage: 105;
|
|
544
|
+
readonly AtTextMessage: 106;
|
|
545
|
+
readonly MergeMessage: 107;
|
|
546
|
+
readonly CardMessage: 108;
|
|
547
|
+
readonly LocationMessage: 109;
|
|
548
|
+
readonly CustomMessage: 110;
|
|
549
|
+
readonly TypingMessage: 113;
|
|
550
|
+
readonly QuoteMessage: 114;
|
|
551
|
+
readonly FaceMessage: 115;
|
|
552
|
+
readonly SystemNotice: "system.notice";
|
|
553
|
+
readonly SystemMember: "system.member";
|
|
554
|
+
readonly SystemMute: "system.mute";
|
|
555
|
+
readonly CallVoice: "call.voice";
|
|
556
|
+
readonly CallVideo: "call.video";
|
|
557
|
+
readonly CallMissed: "call.missed";
|
|
558
|
+
readonly InteractPoke: "interact.poke";
|
|
559
|
+
readonly InteractShake: "interact.shake";
|
|
560
|
+
readonly InteractFlash: "interact.flash";
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
export declare type MessageType = (typeof MessageType)[keyof typeof MessageType];
|
|
564
|
+
|
|
565
|
+
/** 消息类型处理器 */
|
|
566
|
+
export declare interface MessageTypeHandler {
|
|
567
|
+
onClick?(message: any): void;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* 前端消息类型注册表
|
|
572
|
+
*
|
|
573
|
+
* 用于注册自定义消息类型的渲染器和处理器,
|
|
574
|
+
* 支持业务层动态扩展消息类型的展示与交互逻辑。
|
|
575
|
+
*/
|
|
576
|
+
export declare class MessageTypeRegistry {
|
|
577
|
+
private types;
|
|
578
|
+
/**
|
|
579
|
+
* 注册一种消息类型
|
|
580
|
+
* @param typeName 消息类型名称(如 'custom.card')
|
|
581
|
+
* @param renderer 渲染器
|
|
582
|
+
* @param handler 处理器(可选)
|
|
583
|
+
*/
|
|
584
|
+
register(typeName: string, renderer: MessageTypeRenderer, handler?: MessageTypeHandler): void;
|
|
585
|
+
/**
|
|
586
|
+
* 尝试解析已注册的消息类型
|
|
587
|
+
* @param typeName 消息类型名称
|
|
588
|
+
* @returns 渲染器与处理器,或 null(未注册)
|
|
589
|
+
*/
|
|
590
|
+
tryResolve(typeName: string): {
|
|
591
|
+
renderer: MessageTypeRenderer;
|
|
592
|
+
handler: MessageTypeHandler;
|
|
593
|
+
} | null;
|
|
594
|
+
/**
|
|
595
|
+
* 判断某类型是否已注册
|
|
596
|
+
* @param typeName 消息类型名称
|
|
597
|
+
*/
|
|
598
|
+
isRegistered(typeName: string): boolean;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** 消息类型渲染器 */
|
|
602
|
+
export declare interface MessageTypeRenderer {
|
|
603
|
+
canRender(message: any): boolean;
|
|
604
|
+
render(message: any, container: HTMLElement): void;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** 消息撤回事件数据 */
|
|
608
|
+
declare interface MessageWithdrawnInfo {
|
|
609
|
+
conversationId: string;
|
|
610
|
+
seq: number;
|
|
611
|
+
message?: Message;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** 图片基础信息 */
|
|
615
|
+
export declare interface Picture {
|
|
616
|
+
uuid: string;
|
|
617
|
+
type: string;
|
|
618
|
+
size: number;
|
|
619
|
+
width: number;
|
|
620
|
+
height: number;
|
|
621
|
+
url: string;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** 图片消息元素 */
|
|
625
|
+
export declare interface PictureElem {
|
|
626
|
+
sourcePath: string;
|
|
627
|
+
sourcePicture: Picture;
|
|
628
|
+
bigPicture: Picture;
|
|
629
|
+
snapshotPicture: Picture;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** 平台配置信息 */
|
|
633
|
+
export declare interface PlatformConfigInfo {
|
|
634
|
+
platformId: number;
|
|
635
|
+
platformName: string;
|
|
636
|
+
domain?: string;
|
|
637
|
+
logo?: string;
|
|
638
|
+
offlineMessage?: string;
|
|
639
|
+
allowOfflineMessage: boolean;
|
|
640
|
+
isWorkingHours: boolean;
|
|
641
|
+
nonWorkingMessage?: string;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** 平台类型枚举 */
|
|
645
|
+
export declare const PlatformType: {
|
|
646
|
+
readonly Web: 0;
|
|
647
|
+
readonly iOS: 1;
|
|
648
|
+
readonly Android: 2;
|
|
649
|
+
readonly Windows: 3;
|
|
650
|
+
readonly MacOS: 4;
|
|
651
|
+
readonly Linux: 5;
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
export declare type PlatformType = (typeof PlatformType)[keyof typeof PlatformType];
|
|
655
|
+
|
|
656
|
+
/** 排队信息 */
|
|
657
|
+
export declare interface QueueInfo {
|
|
658
|
+
isQueued: boolean;
|
|
659
|
+
position: number;
|
|
660
|
+
totalWaiting: number;
|
|
661
|
+
estimatedWaitMinutes: number;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** C2C 已读回执信息 */
|
|
665
|
+
export declare interface ReadReceiptInfo {
|
|
666
|
+
userID: string;
|
|
667
|
+
msgIDList: string[];
|
|
668
|
+
readTime: number;
|
|
669
|
+
sessionType: number;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** Realtime 核心客户端(基于 SignalR) */
|
|
673
|
+
export declare class RealtimeClient {
|
|
674
|
+
private config;
|
|
675
|
+
private hub;
|
|
676
|
+
private currentUserId;
|
|
677
|
+
private currentToken;
|
|
678
|
+
private currentConversationId;
|
|
679
|
+
private hubListenersRegistered;
|
|
680
|
+
private heartbeatTimer;
|
|
681
|
+
/** 连接状态 */
|
|
682
|
+
private _connectionStatus;
|
|
683
|
+
/** 主动关闭标志(logout/destroy 时设置,断开不触发重连) */
|
|
684
|
+
private _isManualClose;
|
|
685
|
+
/** 重连管理器 */
|
|
686
|
+
private reconnectManager;
|
|
687
|
+
/** 熔断器 */
|
|
688
|
+
private circuitBreaker;
|
|
689
|
+
/** 事件管理器 */
|
|
690
|
+
readonly events: EventManager;
|
|
691
|
+
/** 认证服务 */
|
|
692
|
+
readonly auth: AuthService;
|
|
693
|
+
/** 会话管理 */
|
|
694
|
+
readonly session: SessionManager;
|
|
695
|
+
/** Token 自动续期 */
|
|
696
|
+
readonly tokenRefresher: TokenRefresher;
|
|
697
|
+
/** 消息服务 */
|
|
698
|
+
readonly message: MessageService;
|
|
699
|
+
/** 会话服务 */
|
|
700
|
+
readonly conversation: ConversationService;
|
|
701
|
+
/** 文件上传服务 */
|
|
702
|
+
readonly upload: UploadService;
|
|
703
|
+
constructor(config: RealtimeCoreConfig);
|
|
704
|
+
/** 获取当前连接状态 */
|
|
705
|
+
get connectionStatus(): ConnectionStatus;
|
|
706
|
+
/** 设置连接状态 */
|
|
707
|
+
private setConnectionStatus;
|
|
708
|
+
/** 获取 Hub 连接实例 */
|
|
709
|
+
getHub(): HubConnection;
|
|
710
|
+
/** 获取当前会话 ID */
|
|
711
|
+
getConversationId(): string;
|
|
712
|
+
/** 设置当前会话 ID(登录后由外部设置) */
|
|
713
|
+
setConversationId(conversationId: string): void;
|
|
714
|
+
/** 获取配置 */
|
|
715
|
+
getConfig(): RealtimeCoreConfig;
|
|
716
|
+
/** 动态更新 Realtime 服务器地址(用于接收服务端下发的配置) */
|
|
717
|
+
updateRealtimeAddrs(wsUrl: string): void;
|
|
718
|
+
/** 检查是否已连接 */
|
|
719
|
+
isConnected(): Promise<boolean>;
|
|
720
|
+
/** 登录 — 建立 SignalR 连接 */
|
|
721
|
+
login(userId: string, token: string): Promise<boolean>;
|
|
722
|
+
/** 登出 */
|
|
723
|
+
logout(): Promise<void>;
|
|
724
|
+
/** 获取当前登录用户 ID */
|
|
725
|
+
getCurrentUserId(): string;
|
|
726
|
+
/** 启动心跳定时器(间隔从配置读取,默认 15 秒) */
|
|
727
|
+
private startHeartbeat;
|
|
728
|
+
/** 停止心跳定时器 */
|
|
729
|
+
private stopHeartbeat;
|
|
730
|
+
/** 启动重连流程 */
|
|
731
|
+
private startReconnect;
|
|
732
|
+
/** 执行单次重连尝试(由 ReconnectManager 回调) */
|
|
733
|
+
private handleReconnectAttempt;
|
|
734
|
+
/** 重连最终失败回调 */
|
|
735
|
+
private handleReconnectFinalFail;
|
|
736
|
+
/** 获取当前登录用户信息(通过 Hub 查询) */
|
|
737
|
+
getUserInfo(): Promise<UserInfo | null>;
|
|
738
|
+
/** 注册事件监听(快捷方法) */
|
|
739
|
+
on<E extends RealtimeEventType>(event: E, callback: EventCallback<RealtimeEventMap[E]>): void;
|
|
740
|
+
/** 移除事件监听(快捷方法) */
|
|
741
|
+
off<E extends RealtimeEventType>(event: E, callback: EventCallback<RealtimeEventMap[E]>): void;
|
|
742
|
+
/** 销毁客户端实例,清理所有资源 */
|
|
743
|
+
destroy(): void;
|
|
744
|
+
/** 注册 Hub 事件监听器(仅注册一次) */
|
|
745
|
+
private setupHubListeners;
|
|
746
|
+
/** 解析消息数据(自动映射 C# RealtimeMessage → JS Message) */
|
|
747
|
+
private parseMessage;
|
|
748
|
+
/** 通用数据解析 */
|
|
749
|
+
private parseData;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/** Realtime 连接配置(服务端下发) */
|
|
753
|
+
export declare interface RealtimeConfig {
|
|
754
|
+
/** API 基础地址 */
|
|
755
|
+
apiUrl: string;
|
|
756
|
+
/** Realtime Hub WebSocket 地址 */
|
|
757
|
+
wsUrl: string;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** Realtime 核心库配置 */
|
|
761
|
+
export declare interface RealtimeCoreConfig {
|
|
762
|
+
/** Realtime Hub WebSocket 地址(可选,支持服务端下发) */
|
|
763
|
+
wsAddr?: string;
|
|
764
|
+
/** 业务后端 API 地址 */
|
|
765
|
+
baseURL: string;
|
|
766
|
+
/** 平台密钥 */
|
|
767
|
+
platformKey: string;
|
|
768
|
+
/** 日志级别(0=Error, 1=Warn, 2=Info, 3=Debug, 4=Verbose) */
|
|
769
|
+
logLevel?: number;
|
|
770
|
+
/** 重连配置 */
|
|
771
|
+
reconnect?: {
|
|
772
|
+
/** 最大重试次数,默认 10 */
|
|
773
|
+
maxRetries?: number;
|
|
774
|
+
/** 基础延迟(毫秒),默认 1000 */
|
|
775
|
+
baseDelay?: number;
|
|
776
|
+
/** 最大延迟(毫秒),默认 30000 */
|
|
777
|
+
maxDelay?: number;
|
|
778
|
+
/** 抖动因子(0~1),默认 0.2 */
|
|
779
|
+
jitterFactor?: number;
|
|
780
|
+
};
|
|
781
|
+
/** 熔断器配置 */
|
|
782
|
+
circuitBreaker?: {
|
|
783
|
+
/** 失败阈值,达到后熔断器打开,默认 10 */
|
|
784
|
+
failureThreshold?: number;
|
|
785
|
+
/** 重置超时时间(毫秒),打开状态持续多久后进入半开,默认 60000 */
|
|
786
|
+
resetTimeout?: number;
|
|
787
|
+
/** 半开状态下成功阈值,达到后熔断器关闭,默认 3 */
|
|
788
|
+
successThreshold?: number;
|
|
789
|
+
};
|
|
790
|
+
/** 心跳间隔(毫秒),默认 15000 */
|
|
791
|
+
heartbeatInterval?: number;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** 事件数据映射 */
|
|
795
|
+
export declare interface RealtimeEventMap {
|
|
796
|
+
'connection:connecting': undefined;
|
|
797
|
+
'connection:success': undefined;
|
|
798
|
+
'connection:failed': unknown;
|
|
799
|
+
'connection:reconnecting': {
|
|
800
|
+
attempt: number;
|
|
801
|
+
};
|
|
802
|
+
'connection:circuit-open': undefined;
|
|
803
|
+
'connection:circuit-half-open': undefined;
|
|
804
|
+
'kicked:offline': undefined;
|
|
805
|
+
'token:expired': undefined;
|
|
806
|
+
'sync:finished': undefined;
|
|
807
|
+
'sync:failed': unknown;
|
|
808
|
+
'message:received': Message;
|
|
809
|
+
'message:received:raw': Message;
|
|
810
|
+
'message:read-receipt': ReadReceiptInfo[];
|
|
811
|
+
'message:delivered': DeliveryReceiptInfo;
|
|
812
|
+
'message:withdrawn': MessageWithdrawnInfo;
|
|
813
|
+
'message:edited': Message;
|
|
814
|
+
'message:deleted': MessageDeletedInfo;
|
|
815
|
+
'conversation:changed': Conversation[];
|
|
816
|
+
'conversation:new': {
|
|
817
|
+
conversationId: string;
|
|
818
|
+
visitorName?: string;
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/** 事件类型(冒号分隔) */
|
|
823
|
+
export declare type RealtimeEventType = 'connection:connecting' | 'connection:success' | 'connection:failed' | 'connection:reconnecting' | 'connection:circuit-open' | 'connection:circuit-half-open' | 'kicked:offline' | 'token:expired' | 'sync:finished' | 'sync:failed' | 'message:received' | 'message:received:raw' | 'message:read-receipt' | 'message:delivered' | 'message:withdrawn' | 'message:edited' | 'message:deleted' | 'conversation:changed' | 'conversation:new';
|
|
824
|
+
|
|
825
|
+
/** 插件接口(预留) */
|
|
826
|
+
export declare interface RealtimePlugin {
|
|
827
|
+
/** 插件名称 */
|
|
828
|
+
name: string;
|
|
829
|
+
/** 插件版本 */
|
|
830
|
+
version: string;
|
|
831
|
+
/** 安装插件 */
|
|
832
|
+
install(client: RealtimeClient): void;
|
|
833
|
+
/** 卸载插件 */
|
|
834
|
+
uninstall?(): void;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** 重连事件类型 */
|
|
838
|
+
export declare type ReconnectEvent = 'reconnecting' | 'reconnected' | 'failed';
|
|
839
|
+
|
|
840
|
+
/** 重连事件回调 */
|
|
841
|
+
export declare type ReconnectEventCallback = (attempt: number) => void;
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* 重连管理器
|
|
845
|
+
* 实现指数退避 + 抖动算法,与 C# RetryUtil 算法一致
|
|
846
|
+
*/
|
|
847
|
+
export declare class ReconnectManager {
|
|
848
|
+
private readonly maxRetries;
|
|
849
|
+
private readonly baseDelay;
|
|
850
|
+
private readonly maxDelay;
|
|
851
|
+
private readonly jitterFactor;
|
|
852
|
+
private readonly useExponentialBackoff;
|
|
853
|
+
private _currentAttempt;
|
|
854
|
+
private _isRetrying;
|
|
855
|
+
private retryTimer;
|
|
856
|
+
private stopped;
|
|
857
|
+
private readonly onReconnect;
|
|
858
|
+
private readonly onFinalFail;
|
|
859
|
+
private readonly eventListeners;
|
|
860
|
+
constructor(options: ReconnectManagerOptions, onReconnect: (attempt: number) => Promise<void>, onFinalFail: () => void);
|
|
861
|
+
/** 当前重试次数 */
|
|
862
|
+
get currentAttempt(): number;
|
|
863
|
+
/** 是否正在重连中 */
|
|
864
|
+
get isRetrying(): boolean;
|
|
865
|
+
/** 注册事件监听 */
|
|
866
|
+
on(event: ReconnectEvent, callback: ReconnectEventCallback): void;
|
|
867
|
+
/** 移除事件监听 */
|
|
868
|
+
off(event: ReconnectEvent, callback: ReconnectEventCallback): void;
|
|
869
|
+
/** 触发事件 */
|
|
870
|
+
private emit;
|
|
871
|
+
/**
|
|
872
|
+
* 计算下次重试延迟
|
|
873
|
+
* 指数退避 + 抖动算法
|
|
874
|
+
*/
|
|
875
|
+
private calculateDelay;
|
|
876
|
+
/** 开始重连流程 */
|
|
877
|
+
start(): void;
|
|
878
|
+
/** 安排下一次重试 */
|
|
879
|
+
private scheduleNextRetry;
|
|
880
|
+
/** 停止重连(主动关闭时调用) */
|
|
881
|
+
stop(): void;
|
|
882
|
+
/** 重置重试计数(连接成功后调用) */
|
|
883
|
+
reset(): void;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** 重连管理器配置 */
|
|
887
|
+
export declare interface ReconnectManagerOptions {
|
|
888
|
+
/** 最大重试次数,默认 10 */
|
|
889
|
+
maxRetries?: number;
|
|
890
|
+
/** 基础延迟(毫秒),默认 1000 */
|
|
891
|
+
baseDelay?: number;
|
|
892
|
+
/** 最大延迟(毫秒),默认 30000 */
|
|
893
|
+
maxDelay?: number;
|
|
894
|
+
/** 抖动因子(0~1),默认 0.2 */
|
|
895
|
+
jitterFactor?: number;
|
|
896
|
+
/** 是否使用指数退避,默认 true */
|
|
897
|
+
useExponentialBackoff?: boolean;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** RefreshSession 响应 */
|
|
901
|
+
declare interface RefreshSessionResponse {
|
|
902
|
+
token: string;
|
|
903
|
+
expireTimeSeconds: number;
|
|
904
|
+
agentUserId: string | null;
|
|
905
|
+
agentOnline: boolean;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/** 重置客户端 ID */
|
|
909
|
+
export declare function resetClientId(): string;
|
|
910
|
+
|
|
911
|
+
/** 会话持久化管理器(基于 localStorage) */
|
|
912
|
+
export declare class SessionManager {
|
|
913
|
+
/** 保存认证数据到 localStorage */
|
|
914
|
+
saveAuthData(data: GetTokenResponse): void;
|
|
915
|
+
/** 从 localStorage 加载认证数据(过期则返回 null) */
|
|
916
|
+
loadAuthData(): StoredSessionData | null;
|
|
917
|
+
/** 清除认证数据 */
|
|
918
|
+
clearAuthData(): void;
|
|
919
|
+
/** 更新本地存储中的用户资料 */
|
|
920
|
+
updateUserProfile(updates: {
|
|
921
|
+
nickname?: string;
|
|
922
|
+
avatar?: string;
|
|
923
|
+
}): void;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
export declare function setLogLevel(level: number): void;
|
|
927
|
+
|
|
928
|
+
/** 会话数据(含过期时间) */
|
|
929
|
+
declare interface StoredSessionData extends GetTokenResponse {
|
|
930
|
+
expireAt: number;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** 所有系统消息类型值数组(用于 isSystemMessage 判断) */
|
|
934
|
+
export declare const SYSTEM_MESSAGE_TYPES: ("session_init" | "visitor_online" | "visitor_offline" | "user_info_updated" | "message_read")[];
|
|
935
|
+
|
|
936
|
+
declare type SystemMessageType = (typeof SystemMsg)[keyof typeof SystemMsg];
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* 系统消息类型常量 — 与 C# SystemMessageTypes.cs 对齐
|
|
940
|
+
*
|
|
941
|
+
* 系统消息使用 contentType=110 (CustomMessage),
|
|
942
|
+
* data.type 标识具体类型,extension 包含 {systemMessage:true, notDisplay:true}。
|
|
943
|
+
*/
|
|
944
|
+
export declare const SystemMsg: {
|
|
945
|
+
readonly SessionInit: "session_init";
|
|
946
|
+
readonly VisitorOnline: "visitor_online";
|
|
947
|
+
readonly VisitorOffline: "visitor_offline";
|
|
948
|
+
readonly UserInfoUpdated: "user_info_updated";
|
|
949
|
+
readonly MessageRead: "message_read";
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
/** 文本消息元素 */
|
|
953
|
+
export declare interface TextElement {
|
|
954
|
+
content: string;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** Token 自动续期管理器 */
|
|
958
|
+
export declare class TokenRefresher {
|
|
959
|
+
private authService;
|
|
960
|
+
private client;
|
|
961
|
+
private lastLoginRequest;
|
|
962
|
+
private active;
|
|
963
|
+
private baseURL;
|
|
964
|
+
private chatUserId;
|
|
965
|
+
private clientId;
|
|
966
|
+
private platformKey;
|
|
967
|
+
/** 当 agent 因滑落而变化时触发 */
|
|
968
|
+
onAgentChanged: ((newAgentUserId: string) => void) | null;
|
|
969
|
+
constructor(authService: AuthService, client: IRealtimeClient);
|
|
970
|
+
/** 设置上次登录请求参数(用于自动续期) */
|
|
971
|
+
setLastLoginRequest(request: GetTokenRequest): void;
|
|
972
|
+
/** 设置容灾恢复所需的参数 */
|
|
973
|
+
setSessionInfo(info: {
|
|
974
|
+
baseURL: string;
|
|
975
|
+
chatUserId: string;
|
|
976
|
+
clientId: string;
|
|
977
|
+
platformKey: string;
|
|
978
|
+
}): void;
|
|
979
|
+
/** Token 过期时的自动刷新回调 */
|
|
980
|
+
refresh(): Promise<void>;
|
|
981
|
+
/** 容灾恢复:调用 RefreshSession 做完整重置 */
|
|
982
|
+
refreshSession(): Promise<RefreshSessionResponse>;
|
|
983
|
+
/** 是否已激活 */
|
|
984
|
+
isActive(): boolean;
|
|
985
|
+
/** 停止自动续期 */
|
|
986
|
+
stop(): void;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/** 更新用户信息请求 */
|
|
990
|
+
export declare interface UpdateUserInfoRequest {
|
|
991
|
+
platformKey: string;
|
|
992
|
+
deviceId: string;
|
|
993
|
+
userId?: string;
|
|
994
|
+
nickname?: string;
|
|
995
|
+
avatar?: string;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/** 上传响应 */
|
|
999
|
+
export declare interface UploadResponse {
|
|
1000
|
+
fileName: string;
|
|
1001
|
+
absfileName: string;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/** 文件上传服务 */
|
|
1005
|
+
export declare class UploadService {
|
|
1006
|
+
private baseURL;
|
|
1007
|
+
constructor(baseURL: string);
|
|
1008
|
+
/** 上传文件 */
|
|
1009
|
+
uploadFile(file: File): Promise<UploadResponse>;
|
|
1010
|
+
/** 获取图片宽高 */
|
|
1011
|
+
getImageDimensions(file: File): Promise<{
|
|
1012
|
+
width: number;
|
|
1013
|
+
height: number;
|
|
1014
|
+
}>;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/** 用户信息 */
|
|
1018
|
+
export declare interface UserInfo {
|
|
1019
|
+
userID: string;
|
|
1020
|
+
nickname: string;
|
|
1021
|
+
faceURL: string;
|
|
1022
|
+
createTime: number;
|
|
1023
|
+
ex: string;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** 访客表单配置 */
|
|
1027
|
+
export declare interface VisitorFormConfig {
|
|
1028
|
+
formId: number;
|
|
1029
|
+
formName: string;
|
|
1030
|
+
formFields: VisitorFormField[];
|
|
1031
|
+
isRequired: boolean;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/** 访客表单字段 */
|
|
1035
|
+
export declare interface VisitorFormField {
|
|
1036
|
+
key: string;
|
|
1037
|
+
label: string;
|
|
1038
|
+
type: 'text' | 'email' | 'phone' | 'select' | 'textarea';
|
|
1039
|
+
required: boolean;
|
|
1040
|
+
placeholder?: string;
|
|
1041
|
+
options?: string[];
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
export { }
|