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

@@ -684,31 +684,37 @@ export interface GroupAnnouncementListResponse {
total_pages: number;
}
// ==================== SSE Event Types ====================
// ==================== WS Event Types ====================
// SSE 事件类型
export type SSEEventType = 'message' | 'notice' | 'request' | 'meta';
// WS 事件类型
export type WSEventType = 'message' | 'notice' | 'request' | 'meta';
// SSE 消息详细类型
export type SSEDetailType = 'private' | 'group' | 'follow' | 'like' | 'comment' | 'request' | 'typing' | 'heartbeat' | 'read';
// WS 消息详细类型
export type WSDetailType = 'private' | 'group' | 'follow' | 'like' | 'comment' | 'request' | 'typing' | 'heartbeat' | 'read';
// SSE 事件消息段(与后端 message 字段一致)
export interface SSESegment {
// WS 事件消息段(与后端 message 字段一致)
export interface WSSegment {
type: string;
data: Record<string, any>;
}
// SSE 事件(后端推送的事件格式)
export interface SSEEvent {
// WS 事件(后端推送的事件格式)
export interface WSEvent {
id: string; // 事件唯一ID
time: number; // 事件时间戳(毫秒)
type: SSEEventType; // 事件类型: message(消息), notice(通知), request(请求), meta(元事件)
detail_type: SSEDetailType; // 详细类型: private(私聊), group(群聊), follow(关注), like(点赞)等
type: WSEventType; // 事件类型: message(消息), notice(通知), request(请求), meta(元事件)
detail_type: WSDetailType; // 详细类型: private(私聊), group(群聊), follow(关注), like(点赞)等
seq: string; // 消息序号
message?: SSESegment[]; // 消息内容数组
message?: WSSegment[]; // 消息内容数组
conversation_id: string; // 会话ID
}
// 旧的类型名称,保持向后兼容
export type SSEEventType = WSEventType;
export type SSEDetailType = WSDetailType;
export interface SSESegment extends WSSegment {}
export interface SSEEvent extends WSEvent {}
/**
* 从消息segments中提取纯文本内容
* 用于消息列表显示、通知等场景