added queue system on rooms
This commit is contained in:
@@ -7,7 +7,14 @@ interface RoomUser {
|
||||
avatar?: string;
|
||||
isHost: boolean;
|
||||
isGuest: boolean;
|
||||
userId?: number; // ID real del usuario si está logueado
|
||||
userId?: number;
|
||||
}
|
||||
|
||||
export interface QueueItem {
|
||||
uid: string;
|
||||
metadata: RoomMetadata;
|
||||
videoData: any;
|
||||
addedBy: string;
|
||||
}
|
||||
|
||||
interface RoomMetadata {
|
||||
@@ -36,6 +43,7 @@ interface RoomData {
|
||||
metadata?: RoomMetadata | null;
|
||||
exposed: boolean;
|
||||
publicUrl?: string;
|
||||
queue: QueueItem[];
|
||||
}
|
||||
|
||||
const rooms = new Map<string, RoomData>();
|
||||
@@ -57,7 +65,8 @@ export function createRoom(name: string, host: RoomUser, password?: string, expo
|
||||
password: password || undefined,
|
||||
metadata: null,
|
||||
exposed,
|
||||
publicUrl
|
||||
publicUrl,
|
||||
queue: []
|
||||
};
|
||||
|
||||
rooms.set(roomId, room);
|
||||
@@ -75,6 +84,55 @@ export function getAllRooms(): RoomData[] {
|
||||
}));
|
||||
}
|
||||
|
||||
export function addQueueItem(roomId: string, item: QueueItem): boolean {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return false;
|
||||
room.queue.push(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function removeQueueItem(roomId: string, itemUid: string): boolean {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return false;
|
||||
room.queue = room.queue.filter(i => i.uid !== itemUid);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function getNextQueueItem(roomId: string): QueueItem | undefined {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room || room.queue.length === 0) return undefined;
|
||||
return room.queue.shift(); // Saca el primero y lo retorna
|
||||
}
|
||||
|
||||
export function getAndRemoveQueueItem(roomId: string, itemUid: string): QueueItem | undefined {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return undefined;
|
||||
|
||||
const index = room.queue.findIndex(i => i.uid === itemUid);
|
||||
if (index === -1) return undefined;
|
||||
|
||||
const [item] = room.queue.splice(index, 1);
|
||||
return item;
|
||||
}
|
||||
|
||||
export function moveQueueItem(roomId: string, itemUid: string, direction: 'up' | 'down'): boolean {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return false;
|
||||
|
||||
const index = room.queue.findIndex(i => i.uid === itemUid);
|
||||
if (index === -1) return false;
|
||||
|
||||
const newIndex = direction === 'up' ? index - 1 : index + 1;
|
||||
|
||||
if (newIndex < 0 || newIndex >= room.queue.length) return false;
|
||||
|
||||
const temp = room.queue[newIndex];
|
||||
room.queue[newIndex] = room.queue[index];
|
||||
room.queue[index] = temp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function addUserToRoom(roomId: string, user: RoomUser): boolean {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return false;
|
||||
|
||||
Reference in New Issue
Block a user