diff --git a/src/contexts/NotificationContext.js b/src/contexts/NotificationContext.js index 518ec9c5..f9efafcf 100644 --- a/src/contexts/NotificationContext.js +++ b/src/contexts/NotificationContext.js @@ -624,30 +624,22 @@ export const NotificationProvider = ({ children }) => { setConnectionStatus(CONNECTION_STATUS.CONNECTED); } - // 如果使用 mock,可以启动定期推送 - if (SOCKET_TYPE === 'MOCK') { - // 启动模拟推送:使用配置的间隔和数量 - const { interval, maxBatch } = NOTIFICATION_CONFIG.mockPush; - socket.startMockPush(interval, maxBatch); - logger.info('NotificationContext', 'Mock push started', { interval, maxBatch }); - } else { - // ✅ 真实模式下,订阅事件推送 - console.log('%c[NotificationContext] 🔔 订阅事件推送...', 'color: #FF9800; font-weight: bold;'); + // 订阅事件推送 + console.log('%c[NotificationContext] 🔔 订阅事件推送...', 'color: #FF9800; font-weight: bold;'); - if (socket.subscribeToEvents) { - socket.subscribeToEvents({ - eventType: 'all', - importance: 'all', - onSubscribed: (data) => { - console.log('%c[NotificationContext] ✅ 订阅成功!', 'color: #4CAF50; font-weight: bold;'); - console.log('[NotificationContext] 订阅确认:', data); - logger.info('NotificationContext', 'Events subscribed', data); - }, - // ⚠️ 不需要 onNewEvent 回调,因为 NotificationContext 已经通过 socket.on('new_event') 监听 - }); - } else { - console.warn('[NotificationContext] ⚠️ socket.subscribeToEvents 方法不可用'); - } + if (socket.subscribeToEvents) { + socket.subscribeToEvents({ + eventType: 'all', + importance: 'all', + onSubscribed: (data) => { + console.log('%c[NotificationContext] ✅ 订阅成功!', 'color: #4CAF50; font-weight: bold;'); + console.log('[NotificationContext] 订阅确认:', data); + logger.info('NotificationContext', 'Events subscribed', data); + }, + // ⚠️ 不需要 onNewEvent 回调,因为 NotificationContext 已经通过 socket.on('new_event') 监听 + }); + } else { + console.error('[NotificationContext] ❌ socket.subscribeToEvents 方法不可用'); } }); @@ -752,11 +744,6 @@ export const NotificationProvider = ({ children }) => { return () => { logger.info('NotificationContext', 'Cleaning up socket connection'); - // 如果是 mock service,停止推送 - if (SOCKET_TYPE === 'MOCK') { - socket.stopMockPush(); - } - socket.off('connect'); socket.off('disconnect'); socket.off('connect_error');