feat: 消息与socket的优化调整

This commit is contained in:
2026-01-08 16:26:10 +08:00
parent fb15b8aec1
commit af615f666c
2 changed files with 268 additions and 95 deletions

View File

@@ -28,10 +28,11 @@ export class WebSocketManager {
// 回调函数
this.callbacks = {
onConnect: options.onConnect || (() => {}),
onDisconnect: options.onDisconnect || (() => {}),
onError: options.onError || (() => {}),
onMessage: options.onMessage || (() => {}),
// 支持两套回调命名onConnect/onDisconnect 与 onOpen/onClose兼容调用方
onConnect: options.onConnect || options.onOpen || (() => { }),
onDisconnect: options.onDisconnect || options.onClose || (() => { }),
onError: options.onError || (() => { }),
onMessage: options.onMessage || (() => { }),
getConversationId: options.getConversationId || (() => ""),
getAgentId: options.getAgentId || (() => ""),
};
@@ -327,7 +328,7 @@ export class WebSocketManager {
const messageData = {
...message,
timestamp: Date.now(),
retryCount: 0,
retryCount: typeof message.retryCount === 'number' ? message.retryCount : 0,
};
if (this.connectionState) {
@@ -392,7 +393,7 @@ export class WebSocketManager {
agentId: this.callbacks.getAgentId
? this.callbacks.getAgentId()
: "",
messageType: 3, // 心跳检测
messageType: '3', // 心跳检测
messageContent: "heartbeat",
messageId: IdUtils.generateMessageId(),
};