Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
2dec9360
Commit
2dec9360
authored
Dec 25, 2025
by
水玉婷
Browse files
feat:重连机制优化
parent
ced88523
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/utils/sseService.ts
View file @
2dec9360
...
@@ -117,6 +117,19 @@ export class SSEService {
...
@@ -117,6 +117,19 @@ export class SSEService {
this
.
closeSSE
();
this
.
closeSSE
();
// 检测服务器不可用情况
const
isServerUnavailable
=
error
&&
(
error
.
type
===
'
error
'
||
(
error
.
target
&&
error
.
target
.
readyState
===
0
)
||
(
error
.
message
&&
error
.
message
.
includes
(
'
CONNECTION_REFUSED
'
)));
if
(
isServerUnavailable
)
{
console
.
error
(
'
⛔ 服务器不可用,停止重连
'
);
// 重置重连状态,避免后续重连
this
.
reconnectAttempts
=
this
.
MAX_RECONNECT_ATTEMPTS
;
return
;
}
// 简单重连逻辑
// 简单重连逻辑
if
(
!
this
.
isReconnecting
.
value
&&
this
.
reconnectAttempts
<
this
.
MAX_RECONNECT_ATTEMPTS
)
{
if
(
!
this
.
isReconnecting
.
value
&&
this
.
reconnectAttempts
<
this
.
MAX_RECONNECT_ATTEMPTS
)
{
this
.
reconnectAttempts
++
;
this
.
reconnectAttempts
++
;
...
@@ -168,9 +181,9 @@ export class SSEService {
...
@@ -168,9 +181,9 @@ export class SSEService {
this
.
timeArr
.
push
(
reconnectTimeout
);
this
.
timeArr
.
push
(
reconnectTimeout
);
if
(
this
.
handlers
.
onReconnect
)
{
// 关键修复:移除这里的onReconnect回调,真正的重连成功应该在onopen事件中触发
this
.
handlers
.
onReconnect
(
newDialogSessionId
);
// 这样只有在连接真正建立成功时才会显示重连成功消息
}
console
.
log
(
'
⏳ 重连已启动,等待连接建立...
'
);
}
}
// 关闭SSE连接
// 关闭SSE连接
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment