refactor: clean up code structure and improve error handling in media controllers

This commit is contained in:
MythEclipse
2026-05-16 23:11:46 +07:00
parent 9b211f05cf
commit 7dedac2094
6 changed files with 44 additions and 23 deletions
+14 -2
View File
@@ -6,7 +6,10 @@ import {
Utils,
} from "@dank074/discord-video-stream";
import { AppError } from "../errors";
import { createChildLogger } from "../logger";
import { discordPlayer } from "../player";
const logger = createChildLogger("screen-share");
import type { DiscordPlayerOwner, ScreenSharePlayback } from "./mediaTypes";
import { createYtDlp } from "./ytdlp";
@@ -77,8 +80,8 @@ export function createScreenShareController(
);
}
if (active || getPlayerOwner() !== "none") {
throw new AppError("Another media mode is active", "MEDIA_BUSY", 409);
if (active) {
active.stop();
}
try {
@@ -93,6 +96,15 @@ export function createScreenShareController(
videoCodec: Utils.normalizeVideoCodec("H264"),
});
// Add FFmpeg error logging
if (command && "stderr" in command && (command as any).stderr) {
(command as any).stderr.on("data", (data: Buffer) => {
if (data.toString().includes("Error")) {
logger.error({ error: data.toString() }, "FFmpeg Screen Error");
}
});
}
let stopped = false;
const done = playStream(output, dependencies.streamer, {
type: "go-live",