feat: enhance screen share controller with Streamer integration and voice channel management

This commit is contained in:
MythEclipse
2026-05-17 01:01:40 +07:00
parent d04093ec6e
commit 518577d79d
10 changed files with 321 additions and 183 deletions

View File

@@ -71,93 +71,111 @@ export function createVoiceRoutes(
});
// GET /api/guilds/:guildId/voice-channels - List voice channels in a guild
router.get("/guilds/:guildId/voice-channels", async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId } = req.params;
router.get(
"/guilds/:guildId/voice-channels",
async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId } = req.params;
if (!guildId) {
throw new AppError("Guild ID is required", "MISSING_GUILD_ID", 400);
if (!guildId) {
throw new AppError("Guild ID is required", "MISSING_GUILD_ID", 400);
}
const channels = await voiceController.listVoiceChannels(
guildId as string,
);
res.json(channels);
} catch (error) {
next(error);
}
const channels = await voiceController.listVoiceChannels(guildId as string);
res.json(channels);
} catch (error) {
next(error);
}
});
},
);
// GET /api/guilds/:guildId/channels - List text channels in a guild
router.get("/guilds/:guildId/channels", async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId } = req.params;
router.get(
"/guilds/:guildId/channels",
async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId } = req.params;
if (!guildId) {
throw new AppError("Guild ID is required", "MISSING_GUILD_ID", 400);
if (!guildId) {
throw new AppError("Guild ID is required", "MISSING_GUILD_ID", 400);
}
const channels = await voiceController.listWatchableChannels(
guildId as string,
);
res.json(channels);
} catch (error) {
next(error);
}
const channels = await voiceController.listWatchableChannels(guildId as string);
res.json(channels);
} catch (error) {
next(error);
}
});
},
);
// POST /api/connect - Connect to a voice channel
router.post("/connect", adminAuth, async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId, channelId } = req.body as {
guildId?: string;
channelId?: string;
};
router.post(
"/connect",
adminAuth,
async (req: Request, res: Response, next: NextFunction) => {
try {
const { guildId, channelId } = req.body as {
guildId?: string;
channelId?: string;
};
if (!guildId || !channelId) {
throw new AppError(
"guildId and channelId are required",
"MISSING_CONNECT_FIELDS",
400,
);
if (!guildId || !channelId) {
throw new AppError(
"guildId and channelId are required",
"MISSING_CONNECT_FIELDS",
400,
);
}
logger.info({ guildId, channelId }, "Connecting to voice channel");
const status = await voiceController.connect(guildId, channelId);
// Update UI state and broadcast to connected clients
if (patchSharedUIState && broadcaster) {
const updatedState = patchSharedUIState({
selectedVoiceGuild: guildId,
selectedVoiceChannel: channelId,
});
broadcaster.uiState(updatedState);
}
res.json(status);
} catch (error) {
next(error);
}
logger.info({ guildId, channelId }, "Connecting to voice channel");
const status = await voiceController.connect(guildId, channelId);
// Update UI state and broadcast to connected clients
if (patchSharedUIState && broadcaster) {
const updatedState = patchSharedUIState({
selectedVoiceGuild: guildId,
selectedVoiceChannel: channelId,
});
broadcaster.uiState(updatedState);
}
res.json(status);
} catch (error) {
next(error);
}
});
},
);
// POST /api/disconnect - Disconnect from voice channel
router.post("/disconnect", adminAuth, async (_req: Request, res: Response, next: NextFunction) => {
try {
logger.info("Disconnecting from voice channel");
router.post(
"/disconnect",
adminAuth,
async (_req: Request, res: Response, next: NextFunction) => {
try {
logger.info("Disconnecting from voice channel");
const status = await voiceController.disconnect();
const status = await voiceController.disconnect();
// Update UI state and broadcast to connected clients
if (patchSharedUIState && broadcaster) {
const updatedState = patchSharedUIState({
selectedVoiceGuild: "",
selectedVoiceChannel: "",
});
broadcaster.uiState(updatedState);
// Update UI state and broadcast to connected clients
if (patchSharedUIState && broadcaster) {
const updatedState = patchSharedUIState({
selectedVoiceGuild: "",
selectedVoiceChannel: "",
});
broadcaster.uiState(updatedState);
}
res.json(status);
} catch (error) {
next(error);
}
res.json(status);
} catch (error) {
next(error);
}
});
},
);
return router;
}