feat: improve stream active state detection

- Use 'active' field from streams array to detect camera on/off
- Remove inactive stream SSRCs from mapping when camera turns off
- Enhanced logging to show active stream count and status
- Better detection of camera state changes using both video_ssrc and active field
- Should now properly detect when user turns camera on/off
This commit is contained in:
Mikolaj Wojciech Gorski 2025-07-26 17:38:35 +02:00
parent f9a0e46c59
commit 6b5b3d1867
2 changed files with 24 additions and 13 deletions

@ -1 +1 @@
Subproject commit 9d6ca7a1b9fbc7362ffcb3732487ed78f2ff9769 Subproject commit 943f9e54add4eda8983d83f78e0942ed9e137387

View file

@ -468,19 +468,30 @@ class WebcamRecordingService {
textChannel textChannel
) { ) {
// Listen for streaming events to detect when camera is turned off // Listen for streaming events to detect when camera is turned off
connection.on("startStreaming", ({ video_ssrc, user_id, audio_ssrc }) => { connection.on(
// Check if this is our target user and they turned off their camera "startStreaming",
if (user_id === targetUserId && (video_ssrc === 0 || !video_ssrc)) { ({ video_ssrc, user_id, audio_ssrc, streams }) => {
console.log( // Check if this is our target user
`[Docker] Target user ${targetUserId} turned off camera, stopping webcam recording` if (user_id === targetUserId) {
); // Check if any stream is active for video
this.stopRecording( const hasActiveVideo =
voiceChannelId, streams &&
textChannel, streams.some((stream) => stream.active && stream.type === "video");
"🎥 Webcam recording stopped - user turned off camera."
); // Stop recording if no active video streams or video_ssrc is 0
if (!hasActiveVideo || video_ssrc === 0 || !video_ssrc) {
console.log(
`[Docker] Target user ${targetUserId} turned off camera (active video: ${hasActiveVideo}, video_ssrc: ${video_ssrc}), stopping webcam recording`
);
this.stopRecording(
voiceChannelId,
textChannel,
"🎥 Webcam recording stopped - user turned off camera."
);
}
}
} }
}); );
// Listen for user disconnect events // Listen for user disconnect events
connection.on("disconnect", (userId) => { connection.on("disconnect", (userId) => {