diff --git a/discord.js-selfbot-v13 b/discord.js-selfbot-v13 index 0941764..c1d0b98 160000 --- a/discord.js-selfbot-v13 +++ b/discord.js-selfbot-v13 @@ -1 +1 @@ -Subproject commit 094176414b94e6f01c9460c060834d4bee3be4d7 +Subproject commit c1d0b98a487eda0557d29135024d1eb3c72b968d diff --git a/src/services/webcamRecording.js b/src/services/webcamRecording.js index f0a7284..110de59 100644 --- a/src/services/webcamRecording.js +++ b/src/services/webcamRecording.js @@ -302,12 +302,64 @@ class WebcamRecordingService { } _setupWebcamStreamHandlers(webcamStream, textChannel, voiceChannelId) { + let frameCount = 0; + let lastFrameTime = Date.now(); + webcamStream.on("ready", () => { console.log("[Docker] FFmpeg process ready for webcam recording!"); textChannel.send("🎥 Webcam recording started successfully!"); + webcamStream.stream.stderr.on("data", (data) => { - console.log(`[Docker] Webcam FFmpeg: ${data}`); + const dataStr = data.toString(); + console.log(`[Docker] Webcam FFmpeg: ${dataStr}`); + + // Track frame production + const frameMatch = dataStr.match(/frame=\s*(\d+)/); + if (frameMatch) { + frameCount = parseInt(frameMatch[1]); + lastFrameTime = Date.now(); + } }); + + // Monitor for frame production - stop if no frames after 30 seconds + setTimeout(() => { + if (frameCount === 0) { + console.log( + "[Docker] No frames produced after 30 seconds, stopping webcam recording" + ); + textChannel.send( + "⚠️ Webcam recording stopped - no video frames were captured. User may not have camera enabled." + ); + this.stopRecording( + voiceChannelId, + textChannel, + "🎥 Webcam recording stopped - no frames detected." + ); + } + }, 30000); + + // Check for stalled recording every 60 seconds + const stallCheckInterval = setInterval(() => { + const timeSinceLastFrame = Date.now() - lastFrameTime; + if (frameCount > 0 && timeSinceLastFrame > 60000) { + console.log( + `[Docker] Webcam recording stalled - no frames for ${timeSinceLastFrame}ms` + ); + textChannel.send("⚠️ Webcam recording appears stalled - stopping."); + this.stopRecording( + voiceChannelId, + textChannel, + "🎥 Webcam recording stopped - stream stalled." + ); + clearInterval(stallCheckInterval); + } + }, 60000); + + // Store interval for cleanup + const recording = activeWebcamRecordings.get(voiceChannelId); + if (recording) { + recording.stallCheckInterval = stallCheckInterval; + } }); webcamStream.on("error", (error) => { @@ -380,6 +432,11 @@ class WebcamRecordingService { } _cleanupRecording(recording) { + // Clear any monitoring intervals + if (recording.stallCheckInterval) { + clearInterval(recording.stallCheckInterval); + } + // Remove all event listeners first if (recording.connection) { recording.connection.removeAllListeners("startStreaming");