refactor(messaging): replace WebSocket with SSE for real-time message handling
Some checks failed
Frontend CI / build-android-apk (push) Has been cancelled
Frontend CI / build-and-push-web (push) Has been cancelled
Frontend CI / ota-android (push) Has been cancelled
Frontend CI / ota-android (pull_request) Has been skipped
Frontend CI / build-and-push-web (pull_request) Has been cancelled
Frontend CI / build-android-apk (pull_request) Has been cancelled

Replace WebSocket-based real-time communication with Server-Sent Events (SSE) across the messaging infrastructure. This includes:

- Create new SSEClient datasource to manage SSE connections
- Create new SSEMessageHandler to process SSE events
- Update ProcessMessageUseCase to use SSEClient instead of WebSocketClient
- Update MessageManager and MessageStateManager to work with SSE handlers
- Rename connection state variables from `isWebSocketConnected` to `isSSEConnected`
- Update type definitions in dto.ts (WSEventType → SSEEventType, etc.)
- Delete obsolete WebSocketClient and WebSocketMessageHandler files
- Update comments and documentation to reflect SSE terminology

This refactoring aligns with the backend's SSE implementation for better compatibility with React Native's networking capabilities.
This commit is contained in:
2026-03-19 00:56:41 +08:00
parent 62b55aec31
commit a91637466c
11 changed files with 249 additions and 237 deletions

View File

@@ -31,7 +31,7 @@ export interface MessageState {
conversationList: Conversation[];
messagesMap: Map<string, Message[]>;
unreadCount: UnreadCount;
isWebSocketConnected: boolean;
isSSEConnected: boolean;
currentConversationId: string | null;
isLoading: boolean;
typingUsersMap: Map<string, string[]>;
@@ -50,7 +50,7 @@ export class MessageStateManager {
conversationList: [],
messagesMap: new Map(),
unreadCount: { total: 0, system: 0 },
isWebSocketConnected: false,
isSSEConnected: false,
currentConversationId: null,
isLoading: false,
typingUsersMap: new Map(),
@@ -86,7 +86,7 @@ export class MessageStateManager {
}
isConnected(): boolean {
return this.state.isWebSocketConnected;
return this.state.isSSEConnected;
}
getTypingUsers(groupId: string): string[] {
@@ -188,8 +188,8 @@ export class MessageStateManager {
this.notify({ type: 'unread_count_updated', payload: count });
}
setWebSocketConnected(connected: boolean): void {
this.state.isWebSocketConnected = connected;
setSSEConnected(connected: boolean): void {
this.state.isSSEConnected = connected;
this.notify({ type: 'connection_changed', payload: connected });
}
@@ -287,7 +287,7 @@ export class MessageStateManager {
conversationList: [],
messagesMap: new Map(),
unreadCount: { total: 0, system: 0 },
isWebSocketConnected: false,
isSSEConnected: false,
currentConversationId: null,
isLoading: false,
typingUsersMap: new Map(),