Skip to content

Reconnect the built-in player after a dropped connection#1910

Open
marcelveldt wants to merge 3 commits into
mainfrom
fix/sendspin-reconnect
Open

Reconnect the built-in player after a dropped connection#1910
marcelveldt wants to merge 3 commits into
mainfrom
fix/sendspin-reconnect

Conversation

@marcelveldt

Copy link
Copy Markdown
Member

Problem

When the Music Assistant tab is left open and the connection drops (for example the browser suspends the tab overnight), the built-in player stays unavailable until the page is refreshed — pressing play returns "Player … is not available".

The built-in player runs on sendspin-js, which has its own auto-reconnect. But our /sendspin WebSocket interceptor threw whenever a connection wasn't pre-staged, so the first reconnect attempt failed and the loop gave up after a single try. The player never recovered on its own.

Changes

  • Rebuild the sendspin connection on demand inside the WebSocket interceptor, so sendspin-js's auto-reconnect can actually re-establish the transport (correct open/close ordering, one terminal event per attempt, buffered sends flushed before open).
  • Tie the sendspin session to the main API connection: tear down when the server connection is lost, reconnect when it is restored.
  • Let sendspin-js own transport-only drops (the sendspin socket dies while the main connection stays up).
  • Remove the now-redundant player-timeout restart path (and the double setTabMode it triggered).
  • Add a reconnect config with debug logging for observability.

sendspin-js auto-reconnect could never re-establish the connection: the WebSocket interceptor threw whenever no connection was pre-staged, killing the reconnect loop after a single attempt. The built-in player then stayed unavailable (e.g. after the browser suspended the tab) until a manual page refresh.

- Rebuild the sendspin connection on demand in the WebSocket interceptor so sendspin-js's auto-reconnect works
- Tie the sendspin session to the main API connection: tear down on disconnect, reconnect on restore
- Let sendspin-js own transport-only drops (sendspin socket dies while the main connection stays up)
- Remove the redundant player-timeout restart path
- Add reconnect config with debug logging for observability
@marcelveldt

Copy link
Copy Markdown
Member Author

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the built-in (sendspin) web player failing to recover after a dropped connection by making the /sendspin WebSocket interceptor resilient to sendspin-js auto-reconnect attempts and by aligning sendspin session lifecycle with the main API connection.

Changes:

  • Reworked the /sendspin WebSocket interceptor to (re)build a sendspin connection on demand during reconnect attempts, with deferred handler attachment and queued sends.
  • Updated the web player disconnect behavior to reset sendspin connection state and rely on App initialization to restore playback mode after reconnect.
  • Added a sendspin-js reconnect configuration with debug logging for transport-only drops.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/plugins/web_player.ts Removes the player-timeout restart path and resets sendspin connection on API disconnect so mode can be reapplied on reconnect.
src/plugins/sendspin-connection.ts Rebuilds sendspin bridges on demand in the interceptor and changes event/handler plumbing for reconnect behavior.
src/components/SendspinPlayer.vue Enables sendspin-js reconnect behavior with logging and backoff bounds.

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

Comment thread src/plugins/sendspin-connection.ts Outdated
Comment thread src/plugins/sendspin-connection.ts
Comment thread src/plugins/sendspin-connection.ts
Comment thread src/plugins/sendspin-connection.ts
- Bail before flushing queued sends when the rebuilt bridge isn't open
- Bind this to the wrapper when invoking the forwarded WebSocket handlers

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/plugins/sendspin-connection.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants