Skip to content

Refactor playback status start/stop logic#160

Open
rlauuzo wants to merge 1 commit into
masterfrom
playback-statu
Open

Refactor playback status start/stop logic#160
rlauuzo wants to merge 1 commit into
masterfrom
playback-statu

Conversation

@rlauuzo
Copy link
Copy Markdown
Member

@rlauuzo rlauuzo commented May 25, 2026

Summary by Sourcery

Refine playback status start/stop handling and syncing with Jellyfin playback state.

Bug Fixes:

  • Ensure stale Jellyfin playback sessions are stopped only when the current session is not a start event.
  • Stop current Jellyfin playback status when Jellyfin playback sync is disabled based on the latest flag.

Copilot AI review requested due to automatic review settings May 25, 2026 10:53
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 25, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors Jellyfin playback status start/stop handling so that stale sessions are stopped only when the current session is not the active start, and simplifies how playback sync toggling is wired to the Jellyfin sync flag in the video player hook.

Sequence diagram for Jellyfin playback status start/stop decision

sequenceDiagram
  participant VideoPlayer
  participant usePlaybackStatus
  participant JellyfinServer

  VideoPlayer->>usePlaybackStatus: updateSession(nextSession)
  usePlaybackStatus->>usePlaybackStatus: isCurrentPlaybackStatusStart()
  alt [isCurrentPlaybackStatusStart]
    usePlaybackStatus->>usePlaybackStatus: activePlaybackStatusRef.current = nextSession
  else [not isCurrentPlaybackStatusStart]
    usePlaybackStatus->>JellyfinServer: stopPlaybackStatus(nextSession)
  end
Loading

Sequence diagram for syncPlaybackStatus reacting to jellyfinPlaybackSyncEnabled

sequenceDiagram
  participant ReactEffect
  participant useVideoPlayer
  participant JellyfinServer

  ReactEffect->>useVideoPlayer: jellyfinPlaybackSyncEnabled changed
  ReactEffect->>useVideoPlayer: syncPlaybackStatus()
  alt [jellyfinPlaybackSyncEnabled is false]
    useVideoPlayer->>JellyfinServer: stopCurrentPlaybackStatus()
  else [jellyfinPlaybackSyncEnabled is true]
    useVideoPlayer->>useVideoPlayer: playbackSyncEnabledRef.current remains true
  end
Loading

File-Level Changes

Change Details Files
Adjust playback status start logic to only stop stale sessions when the current session is not the active start and set the active session otherwise.
  • Invert the condition around isCurrentPlaybackStatusStart to treat true as the path where the next playback session becomes active.
  • Call stopPlaybackStatus only in the branch where the current playback status is not the active start, passing latestPositionTicks as positionTicks.
  • Set activePlaybackStatusRef.current to nextSession only when isCurrentPlaybackStatusStart returns true, removing the early return.
src/hooks/use-playback-status.ts
Simplify and centralize playback status sync enabling logic based on the jellyfinPlaybackSyncEnabled flag.
  • Change syncPlaybackStatus from accepting an enabled boolean parameter to reading jellyfinPlaybackSyncEnabled directly inside the effect event.
  • Update syncPlaybackStatus to stop the current playback status when jellyfinPlaybackSyncEnabled is false and start syncing when it is true.
  • Update the effect that reacts to jellyfinPlaybackSyncEnabled changes to call syncPlaybackStatus without arguments.
src/hooks/use-video-player.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link
Copy Markdown

React Doctor

Score: 96 / 100

react-doctor v0.2.6

✔ Select projects to scan › segment-editor-react
Scanning changes: playback-statu → master

Scanning /home/runner/work/segment-editor/segment-editor...


No issues found!

  ┌─────┐  100 / 100 Great
  │ ◠ ◠ │  ██████████████████████████████████████████████████
  │  ▽  │  React Doctor (www.react.doctor)
  └─────┘

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • With syncPlaybackStatus no longer updating playbackSyncEnabledRef.current, double-check whether that ref is still needed elsewhere; if it is, reintroduce an update here or remove the ref entirely to avoid stale or unused state.
  • Now that syncPlaybackStatus does not take any arguments and only depends on jellyfinPlaybackSyncEnabled, consider inlining this logic directly into the useEffect or explicitly documenting why it remains a separate useEffectEvent callback to keep the control flow clear.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- With `syncPlaybackStatus` no longer updating `playbackSyncEnabledRef.current`, double-check whether that ref is still needed elsewhere; if it is, reintroduce an update here or remove the ref entirely to avoid stale or unused state.
- Now that `syncPlaybackStatus` does not take any arguments and only depends on `jellyfinPlaybackSyncEnabled`, consider inlining this logic directly into the `useEffect` or explicitly documenting why it remains a separate `useEffectEvent` callback to keep the control flow clear.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 25, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The two changes are functionally correct:

  • use-playback-status.ts: Inverting the isCurrentPlaybackStatusStart() condition and replacing the early return with an if/else block is semantically equivalent to the old code. Both paths behave identically — the active ref is set only when isCurrentPlaybackStatusStart() is true, and stopPlaybackStatus is called only otherwise.

  • use-video-player.ts: Removing the enabled parameter from syncPlaybackStatus and reading jellyfinPlaybackSyncEnabled directly via useEffectEvent is safe. The closure inside useEffectEvent always captures the latest value of reactive variables. The removal of the explicit playbackSyncEnabledRef.current = enabled assignment is also safe because line 135 (playbackSyncEnabledRef.current = jellyfinPlaybackSyncEnabled) already keeps the ref in sync on every render.

Files Reviewed (2 files)
  • src/hooks/use-playback-status.ts
  • src/hooks/use-video-player.ts

Reviewed by claude-sonnet-4.6 · 211,416 tokens

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Jellyfin playback-status start/stop synchronization to rely on the current jellyfinPlaybackSyncEnabled value directly, and simplifies the “stale start” cleanup logic in the playback-status hook.

Changes:

  • Simplified syncPlaybackStatus in useVideoPlayer to stop/start based on jellyfinPlaybackSyncEnabled without passing an enabled argument.
  • Refactored usePlaybackStatus to set activePlaybackStatusRef only when the start request is still current; otherwise, it stops the stale session without an early return.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/hooks/use-video-player.ts Simplifies playback-status sync effect by reading jellyfinPlaybackSyncEnabled directly and invoking syncPlaybackStatus() without parameters.
src/hooks/use-playback-status.ts Refactors post-start validation to either activate the session or stop it as stale based on isCurrentPlaybackStatusStart().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants