added public watch parties with cloudflared
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import crypto from 'crypto';
|
||||
import { closeTunnelIfUnused } from "./tunnel.manager";
|
||||
|
||||
interface RoomUser {
|
||||
id: string;
|
||||
@@ -33,6 +34,8 @@ interface RoomData {
|
||||
} | null;
|
||||
password?: string;
|
||||
metadata?: RoomMetadata | null;
|
||||
exposed: boolean;
|
||||
publicUrl?: string;
|
||||
}
|
||||
|
||||
const rooms = new Map<string, RoomData>();
|
||||
@@ -41,7 +44,7 @@ export function generateRoomId(): string {
|
||||
return crypto.randomBytes(8).toString('hex');
|
||||
}
|
||||
|
||||
export function createRoom(name: string, host: RoomUser, password?: string): RoomData {
|
||||
export function createRoom(name: string, host: RoomUser, password?: string, exposed = false, publicUrl?: string): RoomData {
|
||||
const roomId = generateRoomId();
|
||||
|
||||
const room: RoomData = {
|
||||
@@ -53,6 +56,8 @@ export function createRoom(name: string, host: RoomUser, password?: string): Roo
|
||||
currentVideo: null,
|
||||
password: password || undefined,
|
||||
metadata: null,
|
||||
exposed,
|
||||
publicUrl
|
||||
};
|
||||
|
||||
rooms.set(roomId, room);
|
||||
@@ -84,13 +89,14 @@ export function removeUserFromRoom(roomId: string, userId: string): boolean {
|
||||
|
||||
room.users.delete(userId);
|
||||
|
||||
// Si no quedan usuarios, eliminar la sala
|
||||
if (room.users.size === 0) {
|
||||
if (room.exposed) {
|
||||
closeTunnelIfUnused();
|
||||
}
|
||||
rooms.delete(roomId);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si era el host, asignar nuevo host
|
||||
if (room.host.id === userId && room.users.size > 0) {
|
||||
const newHost = Array.from(room.users.values())[0];
|
||||
newHost.isHost = true;
|
||||
@@ -109,6 +115,13 @@ export function updateRoomVideo(roomId: string, videoData: any): boolean {
|
||||
}
|
||||
|
||||
export function deleteRoom(roomId: string): boolean {
|
||||
const room = rooms.get(roomId);
|
||||
if (!room) return false;
|
||||
|
||||
if (room.exposed) {
|
||||
closeTunnelIfUnused();
|
||||
}
|
||||
|
||||
return rooms.delete(roomId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user