mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 23:18:44 +08:00
增强消息视图的SSE连接管理
This commit is contained in:
+10
-5
@@ -69,8 +69,8 @@ export class SSEManager {
|
||||
this.backgroundCloseTimer = null
|
||||
}
|
||||
|
||||
// 立即重新建立连接
|
||||
if (!this.eventSource || this.eventSource.readyState === EventSource.CLOSED) {
|
||||
// 只有在有活跃监听器时才重新建立连接
|
||||
if (this.listeners.size > 0 && (!this.eventSource || this.eventSource.readyState === EventSource.CLOSED)) {
|
||||
this.reconnectSSE()
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,11 @@ export class SSEManager {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果没有活跃的监听器,不进行重连
|
||||
if (this.listeners.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isConnecting = true
|
||||
this.reconnectAttempts = attemptCount
|
||||
|
||||
@@ -105,7 +110,7 @@ export class SSEManager {
|
||||
}
|
||||
|
||||
this.reconnectTimer = window.setTimeout(() => {
|
||||
if (!this.isBackground) {
|
||||
if (!this.isBackground && this.listeners.size > 0) {
|
||||
this.reconnectSSE(this.reconnectAttempts + 1)
|
||||
}
|
||||
}, this.options.reconnectDelay)
|
||||
@@ -131,7 +136,7 @@ export class SSEManager {
|
||||
}
|
||||
|
||||
this.reconnectTimer = window.setTimeout(() => {
|
||||
if (!this.isBackground) {
|
||||
if (!this.isBackground && this.listeners.size > 0) {
|
||||
this.reconnectSSE(this.reconnectAttempts + 1)
|
||||
}
|
||||
}, this.options.reconnectDelay)
|
||||
@@ -205,7 +210,7 @@ export class SSEManager {
|
||||
*/
|
||||
forceReconnect() {
|
||||
this.close()
|
||||
if (!this.isBackground) {
|
||||
if (!this.isBackground && this.listeners.size > 0) {
|
||||
this.reconnectSSE()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user