refactor(WebSocket): migrate from SSE to WebSocket for real-time messaging

- Replaced SSEClient with WSClient for handling real-time messaging.
- Updated ProcessMessageUseCase to initialize WebSocket listeners.
- Refactored messageService to prioritize WebSocket for sending messages, with fallback to HTTP.
- Removed sseService and adjusted imports across the application to utilize wsService.
- Enhanced message handling and connection management for improved performance and reliability.
This commit is contained in:
lafay
2026-03-26 22:04:46 +08:00
parent 4b89b50006
commit ba99900624
16 changed files with 986 additions and 659 deletions

View File

@@ -14,7 +14,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { create } from 'zustand';
import { User } from '../types';
import { authService, resolveAuthApiError, LoginRequest, RegisterRequest } from '../services';
import { sseService } from '../services/sseService';
import { wsService } from '../services/wsService';
import {
initDatabase,
closeDatabase,
@@ -95,7 +95,7 @@ function resolveLoginError(error: any): string {
// ── 启动 SSE 实时服务 ──
async function startRealtime(): Promise<void> {
try {
await sseService.start();
await wsService.start();
} catch (error) {
console.error('[AuthStore] 启动 SSE 服务失败:', error);
}
@@ -212,7 +212,7 @@ export const useAuthStore = create<AuthState>((set) => ({
// 1. 通知服务端Token 清理在 authService 内部完成)
await authService.logout();
// 2. 停止 SSE
sseService.stop();
wsService.stop();
// 3. 清除 DB 中的用户缓存DB 此时一定已初始化)
await clearCurrentUserCache().catch(() => {});
// 4. 关闭数据库连接