feat: 修复通知初始化问题
This commit is contained in:
@@ -329,10 +329,18 @@ class SocketService {
|
||||
onSubscribed,
|
||||
} = options;
|
||||
|
||||
if (!this.socket || !this.connected) {
|
||||
logger.warn('socketService', 'Cannot subscribe: socket not connected');
|
||||
// 自动连接
|
||||
this.connect();
|
||||
// ⚡ 改进状态检查:同时检查 this.connected 和 socket.connected
|
||||
// 解决 connect 回调中 this.connected 尚未更新的竞争条件
|
||||
const isReady = this.socket && (this.socket.connected || this.connected);
|
||||
|
||||
if (!isReady) {
|
||||
logger.debug('socketService', 'Socket 尚未就绪,等待连接后订阅');
|
||||
|
||||
if (!this.socket) {
|
||||
// 自动连接
|
||||
this.connect();
|
||||
}
|
||||
|
||||
// 等待连接成功后再订阅
|
||||
this.socket.once('connect', () => {
|
||||
this._doSubscribe(eventType, importance, onNewEvent, onSubscribed);
|
||||
|
||||
Reference in New Issue
Block a user