[PR #376] [CLOSED] Introduce a web socket server for faster communications and ability to re-authenticate. #894

Closed
opened 2026-02-27 20:00:21 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/376
Author: @yyjhao
Created: 9/28/2019
Status: Closed

Base: devHead: add-ws-server


📝 Commits (2)

📊 Changes

7 files changed (+341 additions, -7 deletions)

View changed files

📝 Cargo.lock (+66 -0)
📝 Cargo.toml (+2 -0)
📝 connect/src/spirc.rs (+12 -0)
📝 src/main.rs (+50 -6)
📝 src/player_event_handler.rs (+1 -1)
src/player_ws_server.rs (+90 -0)
src/ws_server.rs (+120 -0)

📄 Description

This introduces a web socket server so to allow sending player events more efficiently. It also supports a "reauth" event to allow the player to reauthenticate again (if username/password is provided in the command line interface).

The purpose of this is to make it easier to build smart player interfaces around librespot. In particular, "reauth" is useful in dealing with the occasional connection dropping issue making the player not appearing in the sportily web API player list unless the user actively connect to it through an official spotify app in the same network again.

To use this, add --ws-port <port_number> to the command, this will start a web socket server listening at <port_number>. Then, with any web socket client can connect to this port. Once connected, the client will receive messages when the player state is updated like so:

  1. track update:
{
    "event": "track_update",
    "old_track_id": uid_of_old_track,
    "new_track_id": uid_of_new_track,
    "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"],
    "current_index": index_of_current_track_in_queue
}
  1. start to play
{
    "event": "track_started",
    "track_id": uid_of_current_track,
    "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"],
    "current_index": index_of_current_track_in_queue
}
3. paused/stopped
```json
{
    "event": "track_stopped",
    "track_id": uid_of_current_track,
    "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"],
    "current_index": index_of_current_track_in_queue
}

The client can also send the following message to the server:

  1. "reauth": authenticate again with username/password provided in the command line
  2. "play": start to play if it's currently paused
  3. "pause": pause if it's currently playing
  4. "next": jump to next song
  5. "previous": jump to previous song

If--ws-port <port_number> is not provided it will not spawn any web socket server.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/376 **Author:** [@yyjhao](https://github.com/yyjhao) **Created:** 9/28/2019 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `add-ws-server` --- ### 📝 Commits (2) - [`ba7b27f`](https://github.com/librespot-org/librespot/commit/ba7b27f47fb4a8547e970a0e05e07450d8430c31) wip - [`c5e75cd`](https://github.com/librespot-org/librespot/commit/c5e75cdcd4dde1dcec51d2458e044b3c65650210) Remove accidentally added file. ### 📊 Changes **7 files changed** (+341 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+66 -0) 📝 `Cargo.toml` (+2 -0) 📝 `connect/src/spirc.rs` (+12 -0) 📝 `src/main.rs` (+50 -6) 📝 `src/player_event_handler.rs` (+1 -1) ➕ `src/player_ws_server.rs` (+90 -0) ➕ `src/ws_server.rs` (+120 -0) </details> ### 📄 Description This introduces a web socket server so to allow sending player events more efficiently. It also supports a "reauth" event to allow the player to reauthenticate again (if username/password is provided in the command line interface). The purpose of this is to make it easier to build smart player interfaces around librespot. In particular, "reauth" is useful in dealing with the occasional connection dropping issue making the player not appearing in the sportily web API player list unless the user actively connect to it through an official spotify app in the same network again. To use this, add `--ws-port <port_number>` to the command, this will start a web socket server listening at `<port_number>`. Then, with any web socket client can connect to this port. Once connected, the client will receive messages when the player state is updated like so: 1. track update: ```javascript { "event": "track_update", "old_track_id": uid_of_old_track, "new_track_id": uid_of_new_track, "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"], "current_index": index_of_current_track_in_queue } ``` 2. start to play ```javascript { "event": "track_started", "track_id": uid_of_current_track, "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"], "current_index": index_of_current_track_in_queue } 3. paused/stopped ```json { "event": "track_stopped", "track_id": uid_of_current_track, "current_queue": ["list", "of", "uids", "in", "the", "current", "queue"], "current_index": index_of_current_track_in_queue } ``` The client can also send the following message to the server: 1. "reauth": authenticate again with username/password provided in the command line 2. "play": start to play if it's currently paused 3. "pause": pause if it's currently playing 4. "next": jump to next song 5. "previous": jump to previous song If`--ws-port <port_number>` is not provided it will not spawn any web socket server. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:00:21 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#894
No description provided.