diff --git a/orb_stream_worker/server.js b/orb_stream_worker/server.js index c538a52..5850ea2 100644 --- a/orb_stream_worker/server.js +++ b/orb_stream_worker/server.js @@ -563,22 +563,22 @@ const server = http.createServer(async (request, response) => { const action = String(body.action || "").trim(); if (action === "pause") { - if (!canPauseCommand(session.ffmpegCommand)) { - throw new Error("Pause is not available because FFmpeg is not active"); + if (session.playbackState !== "playing") { + throw new Error("Pause is not available because session is not playing"); } - session.positionSeconds = sessionPlaybackPosition(session); - session.startedAtSeconds = 0; - session.ffmpegCommand.ffmpegProc.kill("SIGSTOP"); + const pausedPos = sessionPlaybackPosition(session); + await stopSessionPlayback(session, false); + session.positionSeconds = pausedPos; session.playbackState = "paused"; session.workerStatus = "connected"; } else if (action === "resume") { - if (!canPauseCommand(session.ffmpegCommand)) { - throw new Error("Resume is not available because FFmpeg is not active"); + if (session.playbackState !== "paused") { + throw new Error("Resume is not available because session is not paused"); } - session.startedAtSeconds = nowSeconds(); - session.ffmpegCommand.ffmpegProc.kill("SIGCONT"); - session.playbackState = "playing"; - session.workerStatus = "streaming"; + if (!session.playback) { + throw new Error("Cannot resume because no playback metadata exists"); + } + await startPlayback(session, session.playback, session.positionSeconds); } else if (action === "stop" || action === "skip") { await stopSessionPlayback(session, true); } else if (action === "seek") {