update event types + schema

This commit is contained in:
dank074
2025-05-06 19:38:09 -05:00
parent 2d4f3b0c6a
commit bbcd690620
5 changed files with 14968 additions and 7 deletions
+4 -2
View File
@@ -12,7 +12,9 @@ import {
Region,
Snowflake,
Stream,
StreamCreateEvent,
StreamCreateSchema,
StreamServerUpdateEvent,
StreamSession,
VoiceState,
VoiceStateUpdateEvent,
@@ -100,7 +102,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
paused: false,
},
user_id: this.user_id,
});
} as StreamCreateEvent);
await emitEvent({
event: "STREAM_SERVER_UPDATE",
@@ -111,7 +113,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
endpoint: stream.endpoint,
},
user_id: this.user_id,
});
} as StreamServerUpdateEvent);
voiceState.self_stream = true;
await voiceState.save();
+13 -3
View File
@@ -2,6 +2,7 @@ import { parseStreamKey, Payload, WebSocket } from "@spacebar/gateway";
import {
emitEvent,
Stream,
StreamDeleteEvent,
StreamDeleteSchema,
VoiceState,
VoiceStateUpdateEvent,
@@ -27,15 +28,24 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
const { userId, channelId, guildId, type } = parsedKey;
// when a user selects to stop watching another user stream, this event gets triggered
// just disconnect user without actually deleting stream
if (this.user_id !== userId) {
return this.close(4000, "Cannot delete stream for another user");
await emitEvent({
event: "STREAM_DELETE",
data: {
stream_key: body.stream_key,
},
user_id: this.user_id,
} as StreamDeleteEvent);
return;
}
const stream = await Stream.findOne({
where: { channel_id: channelId, owner_id: userId },
});
if (!stream) return this.close(4000, "Invalid stream key");
if (!stream) return;
await stream.remove();
@@ -62,5 +72,5 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
},
guild_id: guildId,
channel_id: channelId,
});
} as StreamDeleteEvent);
}
+4 -2
View File
@@ -8,6 +8,8 @@ import {
Config,
emitEvent,
Stream,
StreamCreateEvent,
StreamServerUpdateEvent,
StreamSession,
StreamWatchSchema,
} from "@spacebar/util";
@@ -81,7 +83,7 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
},
channel_id: channelId,
user_id: this.user_id,
});
} as StreamCreateEvent);
await emitEvent({
event: "STREAM_SERVER_UPDATE",
@@ -92,5 +94,5 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
endpoint: stream.endpoint,
},
user_id: this.user_id,
});
} as StreamServerUpdateEvent);
}
+11
View File
@@ -451,6 +451,9 @@ export interface StreamCreateEvent extends Event {
data: {
stream_key: string;
rtc_server_id: string;
viewer_ids: string[];
region: string;
paused: boolean;
};
}
@@ -460,6 +463,14 @@ export interface StreamServerUpdateEvent extends Event {
token: string;
stream_key: string;
endpoint: string;
guild_id: string | null;
};
}
export interface StreamDeleteEvent extends Event {
event: "STREAM_DELETE";
data: {
stream_key: string;
};
}