From 71f2e89072650c038b47b88284dd8693c73f0b78 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Mon, 10 Nov 2025 15:30:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=E9=80=9A=E7=9F=A5moc?= =?UTF-8?q?k=E7=9B=B8=E5=85=B3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/NotificationContext.js | 43 ++++++++++------------------- 1 file changed, 15 insertions(+), 28 deletions(-) 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');