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:
@@ -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. 关闭数据库连接
|
||||
|
||||
Reference in New Issue
Block a user