/** * Pick the first LIVE track of a kind across a set of streams — used to find * the audio/video track the session is currently capturing with (webcam * observer, or an in-flight clip recording), so the checkpoint can read its * liveness. Ended tracks are ignored: a finished clip isn't a mic/camera * failure, just a finished clip. */ export function pickLiveTrack( kind: "audio" | "video", streams: Array, ): MediaStreamTrack | null { for (const stream of streams) { if (!stream) continue; const tracks = kind === "audio" ? stream.getAudioTracks() : stream.getVideoTracks(); for (const track of tracks) { if (track.readyState === "live") return track; } } return null; }