Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 7.31 KB

v1.md

File metadata and controls

84 lines (62 loc) · 7.31 KB

Controller messages

This section describes messages specific to clients with the controller role, which enables the client to control the group this client is part of, and switch between groups.

Every client which lists the controller role in the supported_roles of the client/hello message MUST implement all messages in this section.

Client → Server: client/command controller object

The controller object in client/command has this structure:

Control the group that's playing and switch groups. Only valid from clients whose controller role is active.

  • controller: object
    • command: 'play' | 'pause' | 'stop' | 'next' | 'previous' | 'volume' | 'mute' | 'repeat_off' | 'repeat_one' | 'repeat_all' | 'shuffle' | 'unshuffle' | 'switch' | 'seek' | 'seek_relative' - MUST be one of the values listed in supported_commands from the latest controller state the client received in server/state. The server MUST ignore commands absent from its current supported_commands
    • volume?: integer - volume range 0-100, only set if command is volume
    • mute?: boolean - true to mute, false to unmute, only set if command is mute
    • position_ms?: integer - absolute playback position in milliseconds, range 0 to seek_max_ms, only set if command is seek
    • offset_ms?: integer - signed offset in milliseconds from the current position (positive forward, negative backward), only set if command is seek_relative

Command behaviour

  • 'play' - resume playback from current position. If nothing is currently playing, the server SHOULD resume the group's last playing media. The server SHOULD retain this history across server and client reboots
  • 'pause' - pause playback at current position
  • 'stop' - stop playback and reset position to beginning
  • 'next' - skip to next track, chapter, etc.
  • 'previous' - skip to previous track, chapter, restart current, etc.
  • 'volume' - set group volume (requires volume parameter)
  • 'mute' - set group mute state (requires mute parameter)
  • 'repeat_off' - disable repeat mode
  • 'repeat_one' - repeat the current track continuously
  • 'repeat_all' - repeat all tracks continuously
  • 'shuffle' - randomize playback order
  • 'unshuffle' - restore original playback order
  • 'switch' - move this client to the next group in a predefined cycle as described below
  • 'seek' - seek to an absolute position. The client MUST include position_ms; the server MUST ignore the command if position_ms is outside the range 0 to seek_max_ms
  • 'seek_relative' - seek by an offset from the current position. The client MUST include offset_ms; the server applies it on a best-effort basis and MUST clamp the result to the seekable range

Setting group volume: When setting group volume via the 'volume' command, the server MUST apply the following algorithm to the players in the group that support the volume command, preserving relative volume levels while achieving the requested volume as closely as player boundaries allow. Players without volume support are excluded and receive no volume command:

  1. Calculate the delta: delta = requested_volume - current_group_volume (where current group volume is the average of their volumes)
  2. Apply the delta to each player's volume
  3. Clamp any player volumes that exceed boundaries (0-100%)
  4. If any players were clamped:
    • Calculate the lost delta: sum of (proposed_volume - clamped_volume) for all clamped players
    • Divide the lost delta equally among non-clamped players
    • Repeat steps 1-4 until either:
      • All delta has been successfully applied, or
      • All players are clamped at their volume boundaries

After the loop, the server MUST round each final per-player volume to the nearest integer before sending commands.

The loop only computes the final per-player volumes; once it completes, the server sends each player a single volume command — intermediate values are never sent.

This ensures that when setting group volume to 100%, all players will reach 100% if possible, and the final group volume matches the requested volume as closely as player boundaries and rounding allow.

Setting group mute: When setting group mute via the 'mute' command, the server applies the mute state to each player in the group that supports the mute command. Group volume changes do not affect any player's muted state (see the player role).

Switch command cycle

Previous group priority: If the client is still in the solo group it was moved to on becoming unavailable (available: false) or on sending client/leave, the switch command prioritizes rejoining the previous group.

For clients with the player role, the cycle includes:

  1. Multi-client groups that are currently playing
  2. Single-client groups (other players playing alone)
  3. A solo group containing only this client

For clients without the player role, the cycle includes:

  1. Multi-client groups that are currently playing
  2. Single-client groups (other players playing alone)

Server → Client: server/state controller object

The controller object in server/state has this structure:

  • controller: object
    • supported_commands: string[] - subset of: 'play' | 'pause' | 'stop' | 'next' | 'previous' | 'volume' | 'mute' | 'repeat_off' | 'repeat_one' | 'repeat_all' | 'shuffle' | 'unshuffle' | 'switch' | 'seek' | 'seek_relative'
    • volume: integer - volume of the whole group, range 0-100
    • muted: boolean - mute state of the whole group
    • repeat: 'off' | 'one' | 'all' - repeat mode: 'off' = no repeat, 'one' = repeat current track, 'all' = repeat all tracks (in the queue, playlist, etc.)
    • shuffle: boolean - shuffle mode enabled/disabled
    • seek_max_ms?: integer - maximum absolute position in milliseconds a 'seek' may target (e.g., the end of the current track). The server MUST include this when 'seek' is in supported_commands, and MUST omit 'seek' when the seekable range is unknown (e.g., live streams); 'seek_relative' MAY still be offered

Reading group volume: Reported group volume is the average of the volumes of players in the group that support the volume command, rounded to an integer. Players without volume support are excluded from the calculation. If no player in the group supports volume, group volume is reported as 100 and 'volume' is dropped from the controller supported_commands. A player MAY change its supported_commands mid-session, so the server recomputes both the group volume and the controller supported_commands whenever a player's volume support changes.

Reading group mute: Group mute is true only when all mute-supporting players in the group are muted. Players without mute support are excluded. If some supporting players are muted and others are not, group mute is false. If no player in the group supports mute, group mute is reported as false and 'mute' is dropped from the controller supported_commands. The server recomputes group mute and the controller supported_commands the same way when a player's mute support changes.