added public watch parties with cloudflared
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
import { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import * as roomService from './rooms.service';
|
||||
import { getUserById } from '../user/user.service';
|
||||
import { openTunnel } from "./tunnel.manager";
|
||||
|
||||
interface CreateRoomBody {
|
||||
name: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
interface JoinRoomBody {
|
||||
password?: string;
|
||||
guestName?: string;
|
||||
expose?: boolean;
|
||||
}
|
||||
|
||||
export async function createRoom(req: any, reply: FastifyReply) {
|
||||
try {
|
||||
const { name, password } = req.body as CreateRoomBody;
|
||||
const { name, password, expose } = req.body as CreateRoomBody;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!userId) {
|
||||
@@ -39,7 +36,23 @@ export async function createRoom(req: any, reply: FastifyReply) {
|
||||
userId
|
||||
};
|
||||
|
||||
const room = roomService.createRoom(name, host, password);
|
||||
let publicUrl: string | undefined;
|
||||
|
||||
if (expose) {
|
||||
publicUrl = await openTunnel();
|
||||
}
|
||||
|
||||
const room = roomService.createRoom(
|
||||
name,
|
||||
host,
|
||||
password,
|
||||
!!expose,
|
||||
publicUrl
|
||||
);
|
||||
|
||||
if (expose && publicUrl) {
|
||||
room.publicUrl = `${publicUrl}/room?id=${room.id}`;
|
||||
}
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -47,7 +60,9 @@ export async function createRoom(req: any, reply: FastifyReply) {
|
||||
id: room.id,
|
||||
name: room.name,
|
||||
hasPassword: !!room.password,
|
||||
userCount: room.users.size
|
||||
userCount: room.users.size,
|
||||
exposed: room.exposed,
|
||||
publicUrl: room.publicUrl
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -104,7 +119,9 @@ export async function getRoom(req: FastifyRequest, reply: FastifyReply) {
|
||||
isGuest: u.isGuest
|
||||
})),
|
||||
hasPassword: !!room.password,
|
||||
currentVideo: room.currentVideo
|
||||
currentVideo: room.currentVideo,
|
||||
exposed: room.exposed,
|
||||
publicUrl: room.publicUrl
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user