增加一起听功能

This commit is contained in:
mtvpls
2026-05-27 22:57:59 +08:00
parent 540614cef9
commit 23290f027b
9 changed files with 1167 additions and 22 deletions
+38 -2
View File
@@ -11,12 +11,12 @@ export interface Room {
ownerName: string;
ownerToken: string; // 房主令牌,用于重连时验证身份
memberCount: number;
currentState: PlayState | LiveState | ScreenState | null;
currentState: PlayState | LiveState | ScreenState | MusicState | null;
createdAt: number;
lastOwnerHeartbeat: number;
}
export type RoomType = 'sync' | 'screen';
export type RoomType = 'sync' | 'screen' | 'music';
export interface Member {
id: string;
@@ -53,6 +53,30 @@ export interface ScreenState {
startedAt?: number;
}
export interface MusicQueueItem {
id: string;
name: string;
artist: string;
album?: string;
pic?: string;
platform: string;
songmid?: string;
duration?: number;
durationText?: string;
}
export interface MusicState {
type: 'music';
queue: MusicQueueItem[];
currentIndex: number;
song: MusicQueueItem;
currentTime: number;
isPlaying: boolean;
quality: string;
playMode: 'loop' | 'single' | 'random';
updatedAt: number;
}
export interface ChatMessage {
id: string;
userId: string;
@@ -90,6 +114,12 @@ export interface ServerToClientEvents {
'screen:offer': (data: { userId: string; offer: RTCSessionDescriptionInit }) => void;
'screen:answer': (data: { userId: string; answer: RTCSessionDescriptionInit }) => void;
'screen:ice': (data: { userId: string; candidate: RTCIceCandidateInit }) => void;
'music:change': (state: MusicState) => void;
'music:update': (state: MusicState) => void;
'music:play': (state: MusicState) => void;
'music:pause': (state: MusicState) => void;
'music:seek': (state: MusicState) => void;
'music:queue': (state: MusicState) => void;
'chat:message': (message: ChatMessage) => void;
'voice:offer': (data: { userId: string; offer: RTCSessionDescriptionInit }) => void;
'voice:answer': (data: { userId: string; answer: RTCSessionDescriptionInit }) => void;
@@ -139,6 +169,12 @@ export interface ClientToServerEvents {
'screen:offer': (data: { targetUserId: string; offer: RTCSessionDescriptionInit }) => void;
'screen:answer': (data: { targetUserId: string; answer: RTCSessionDescriptionInit }) => void;
'screen:ice': (data: { targetUserId: string; candidate: RTCIceCandidateInit }) => void;
'music:change': (state: MusicState) => void;
'music:update': (state: MusicState) => void;
'music:play': (state: MusicState) => void;
'music:pause': (state: MusicState) => void;
'music:seek': (state: MusicState) => void;
'music:queue': (state: MusicState) => void;
'chat:message': (data: { content: string; type: 'text' | 'emoji' }) => void;