Refactor playback status start/stop logic#160
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors 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 decisionsequenceDiagram
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
Sequence diagram for syncPlaybackStatus reacting to jellyfinPlaybackSyncEnabledsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
React DoctorScore: |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- With
syncPlaybackStatusno longer updatingplaybackSyncEnabledRef.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
syncPlaybackStatusdoes not take any arguments and only depends onjellyfinPlaybackSyncEnabled, consider inlining this logic directly into theuseEffector explicitly documenting why it remains a separateuseEffectEventcallback 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The two changes are functionally correct:
Files Reviewed (2 files)
Reviewed by claude-sonnet-4.6 · 211,416 tokens |
There was a problem hiding this comment.
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
syncPlaybackStatusinuseVideoPlayerto stop/start based onjellyfinPlaybackSyncEnabledwithout passing anenabledargument. - Refactored
usePlaybackStatusto setactivePlaybackStatusRefonly when the start request is still current; otherwise, it stops the stale session without an earlyreturn.
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.
Summary by Sourcery
Refine playback status start/stop handling and syncing with Jellyfin playback state.
Bug Fixes: