This commit is contained in:
dank074
2025-05-06 19:38:09 -05:00
parent 5bae44faf0
commit 1ff38287a6
4 changed files with 56 additions and 32 deletions
+11
View File
@@ -5,6 +5,7 @@ import {
generateStreamKey,
} from "@spacebar/gateway";
import {
Channel,
Config,
emitEvent,
Region,
@@ -28,6 +29,16 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
// TODO: permissions check - if it's a guild, check if user is allowed to create stream in this guild
const channel = await Channel.findOne({
where: { id: body.channel_id },
});
if (
!channel ||
(body.type === "guild" && channel.guild_id != body.guild_id)
)
return this.close(4000, "invalid channel");
// TODO: actually apply preferred_region from the event payload
const regions = Config.get().regions;
const guildRegion = regions.available.filter(
+7 -7
View File
@@ -40,6 +40,13 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
if (type === "guild" && stream.channel.guild_id != guildId)
return this.close(4000, "Invalid stream key");
const regions = Config.get().regions;
const guildRegion = regions.available.find(
(r) => r.endpoint === stream.endpoint,
);
if (!guildRegion) return this.close(4000, "Unknown region");
const streamSession = StreamSession.create({
stream_id: stream.id,
user_id: this.user_id,
@@ -49,13 +56,6 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
await streamSession.save();
const regions = Config.get().regions;
const guildRegion = regions.available.find(
(r) => r.endpoint === stream.endpoint,
);
if (!guildRegion) return this.close(4000, "Unknown region");
const viewers = await StreamSession.find({
where: { stream_id: stream.id },
});