diff --git a/README.md b/README.md index 2eff3a8..20f3b08 100644 --- a/README.md +++ b/README.md @@ -542,11 +542,11 @@ For synchronization, all timing is relative to the server's monotonic clock. The Client sends state updates to the server. Contains client-level state and role-specific state objects. -Sent once the client is ready to report its operational status (`available`), and whenever any state changes thereafter. A player reports `available: true` only after it has established [clock synchronization](#clock-synchronization). The server MUST NOT send binary data to a client before that client has sent its initial `client/state`. When a role becomes active in `active_roles`, send its full state. +Sent once the client is ready to report its operational status (`available`), and whenever any state changes thereafter. A player reports `available: true` only after it has established [clock synchronization](#clock-synchronization). The server MUST NOT send binary data to a client before that client has sent its initial `client/state`. When a role becomes active in `active_roles`, send an update that includes that role's object. A client whose `active_roles` include `artwork` or `visualizer` sends the initial `client/state` even when none of its roles defines a state object; `available` alone unlocks the server's streams. -The initial message MUST include all state fields. In subsequent messages, the client MAY send only the fields that have changed; the server MUST merge each update into existing state, retaining the last value of any field that is absent. A client MAY instead resend unchanged fields, up to its full state. +Every message MUST carry `available` and the full state of each role object it includes. Omitting a role object leaves that role's state unchanged. - `available`: boolean - whether the client is available to participate in Sendspin playback - `true` - client is operational and ready to participate in playback; for a player or source this means its clock is synchronized with the server. @@ -582,7 +582,7 @@ If the client is in a multi-client group: If the client is already in a solo group: - Stop playback and send [`stream/end`](#server--client-streamend) for all active streams -- If `playback_state` was not already `'stopped'`, send [`group/update`](#server--client-groupupdate) with `playback_state: 'stopped'` +- If `playback_state` was not already `'stopped'`, send [`group/update`](#server--client-groupupdate) reporting `playback_state: 'stopped'` When a client returns to `available: true`, the server MUST NOT auto-rejoin it to its previous group or restart playback; the client remains in the solo group and rejoins only via an explicit [`switch`](#switch-command-cycle). @@ -598,13 +598,9 @@ Client sends commands to the server. Contains command objects based on the clien Server sends state updates to the client. Contains role-specific state objects. -Only include fields that have changed. The client will merge these updates into existing state. A leaf field set to `null` should be cleared from the client's state; a whole role object set to `null` clears all of that role's state. +Every message MUST carry the full state of each role object it includes. Omitting a role object leaves that role's state unchanged. -The merge is shallow: a nested object (e.g., `metadata.progress`) is replaced or cleared as a whole, never deep-merged, so nested objects are always sent complete. - -The first `server/state` sent for a role on a connection, and the first after that role is re-added to `active_roles`, MUST carry the role's full state. - -The asymmetry with [`client/state`](#client--server-clientstate) is deliberate: server-to-client updates carry only changed fields; clients MAY resend unchanged fields. +A role object set to `null` clears all of that role's state. - `metadata?`: object | null - only sent to clients with `metadata` role ([see metadata state object details](#server--client-serverstate-metadata-object)) - `controller?`: object | null - only sent to clients with `controller` role ([see controller state object details](#server--client-serverstate-controller-object)) @@ -678,13 +674,11 @@ Sending `stream/end` in these cases is explicitly prohibited because it signals State update of the group this client is part of. -Contains delta updates with only the changed fields. The client should merge these updates into existing state. +Every message MUST carry the full group state. -The first `group/update` on a connection MUST carry the full group state (all fields below), so the client has a baseline to merge later deltas into. - -- `playback_state?`: 'playing' | 'stopped' - playback state of the group -- `group_id?`: string - group identifier -- `group_name?`: string - friendly name of the group +- `playback_state`: 'playing' | 'stopped' - playback state of the group +- `group_id`: string - group identifier +- `group_name`: string - friendly name of the group ### Server → Client: `server/unpair` @@ -1311,12 +1305,10 @@ State updates must be sent whenever any state changes, including when the volume - `player`: object - `volume?`: integer - range 0-100, MUST be included if 'volume' is in `supported_commands` from [`player@v1_support`](#client--server-clienthello-playerv1-support-object) - `muted?`: boolean - mute state, MUST be included if 'mute' is in `supported_commands` from [`player@v1_support`](#client--server-clienthello-playerv1-support-object) - - `output_delay_ms`: integer - output delay in milliseconds (0-5000), REQUIRED for players - - `required_lead_time_ms`: integer - minimum startup lead time in milliseconds (e.g., codec init, decode warmup, audio backend buffering, DAC latency), REQUIRED for players. Measured from the server transmit time of the start/restart trigger (the `server_transmitted` field in [`stream/start`](#server--client-streamstart) or [`stream/clear`](#server--client-streamclear)) to the playback timestamp of the first audio chunk that can be played in full. The server treats this as a hint and MAY give less lead (see [Server behavior](#client--server-clienthello-playerv1-support-object)). - - `min_buffer_ms`: integer - requested minimum ongoing buffer duration in milliseconds during playback (primarily for live streams), used to absorb network jitter and ongoing decode/playback timing variance. REQUIRED for players. - - `supported_commands?`: string[] - subset of: 'set_output_delay' - -**Delta updates:** The presence requirements above (REQUIRED fields, and fields that MUST be included when a command is supported) describe a player's full state, reported in the initial message. In any later update a player MAY omit fields whose values have not changed, per the delta rules in [`client/state`](#client--server-clientstate). + - `output_delay_ms`: integer - output delay in milliseconds (0-5000) + - `required_lead_time_ms`: integer - minimum startup lead time in milliseconds (e.g., codec init, decode warmup, audio backend buffering, DAC latency). Measured from the server transmit time of the start/restart trigger (the `server_transmitted` field in [`stream/start`](#server--client-streamstart) or [`stream/clear`](#server--client-streamclear)) to the playback timestamp of the first audio chunk that can be played in full. The server treats this as a hint and MAY give less lead (see [Server behavior](#client--server-clienthello-playerv1-support-object)). + - `min_buffer_ms`: integer - requested minimum ongoing buffer duration in milliseconds during playback (primarily for live streams), used to absorb network jitter and ongoing decode/playback timing variance. + - `supported_commands`: string[] - subset of: 'set_output_delay', empty when the player accepts no commands **Output delay:** The default is 0, meaning audio exits the device's audio port at the timestamp. `output_delay_ms` compensates for additional delay beyond the port (external speakers, amplifiers); it does not cover processing delays before the port (DAC latency, audio buffers), which the client compensates itself. Negative values are not supported and should never be required for any compliant implementation. Clients must persist `output_delay_ms` locally across reboots and server reconnections. Clients may update `output_delay_ms` and `supported_commands` when audio output changes (e.g., external speaker connected), persisting separate delays per output. @@ -1623,21 +1615,21 @@ The `metadata` object in [`server/state`](#server--client-serverstate) has this - `metadata`: object - `timestamp`: integer - server clock time in microseconds for when this metadata is valid - - `title?`: string | null - track title - - `artist?`: string | null - primary artist(s) - - `album_artist?`: string | null - album artist(s) - - `album?`: string | null - name of the album or release that this track belongs to - - `artwork_url?`: string | null - URL to artwork image. Useful for clients that want to forward metadata to external systems or for powerful clients that can fetch and process images themselves - - `year?`: integer | null - release year in YYYY format - - `track?`: integer | null - track number on the album (1-indexed), null if unknown or not applicable - - `progress?`: object | null - playback progress information. The server must send this object whenever playback state changes (play, pause, resume, seek, playback speed change) - - `track_progress`: integer - current playback position in milliseconds since start of track + - `title?`: string - track title + - `artist?`: string - primary artist(s) + - `album_artist?`: string - album artist(s) + - `album?`: string - name of the album or release that this track belongs to + - `artwork_url?`: string - URL to artwork image. Useful for clients that want to forward metadata to external systems or for powerful clients that can fetch and process images themselves + - `year?`: integer - release year in YYYY format + - `track?`: integer - track number on the album (1-indexed), absent if unknown or not applicable + - `progress?`: object - playback progress information. Omitting it clears the client's position, so include it in every `metadata` state that has a position to report. The server must send a new `metadata` state whenever playback state changes (play, pause, resume, seek, playback speed change) + - `track_progress`: integer - playback position in milliseconds since start of track, measured at `timestamp` - `track_duration`: integer - total track length in milliseconds, 0 for unlimited/unknown duration (e.g., live radio streams) - `playback_speed`: integer - playback speed multiplier * 1000 (e.g., 1000 = normal speed, 1500 = 1.5x speed, 500 = 0.5x speed, 0 = paused) #### Calculating current track position -Clients can calculate the current track position at any time using the `timestamp` and `progress` values from the last metadata message that included the `progress` object: +Clients can calculate the current track position at any time using the `timestamp` and `progress` values from the current metadata state: ```python calculated_progress = metadata.progress.track_progress + (current_time - metadata.timestamp) * metadata.progress.playback_speed / 1000000 @@ -1830,9 +1822,9 @@ The `color` object in [`server/state`](#server--client-serverstate) has this str - `color`: object - `timestamp`: integer - server clock time in microseconds for when these colors are valid - - `background_dark?`: integer[] | null - background color suitable for dark mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with white text and with `on_dark` (if also present). - - `background_light?`: integer[] | null - background color suitable for light mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with black text and with `on_light` (if also present). - - `primary?`: integer[] | null - the dominant color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. - - `accent?`: integer[] | null - a secondary or complementary color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. - - `on_dark?`: integer[] | null - a light color suitable for use on dark backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_dark` (if also present) and with black text, so it can also serve as an alternative light background. - - `on_light?`: integer[] | null - a dark color suitable for use on light backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_light` (if also present) and with white text, so it can also serve as an alternative dark background. + - `background_dark?`: integer[] - background color suitable for dark mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with white text and with `on_dark` (if also present). + - `background_light?`: integer[] - background color suitable for light mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with black text and with `on_light` (if also present). + - `primary?`: integer[] - the dominant color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. + - `accent?`: integer[] - a secondary or complementary color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. + - `on_dark?`: integer[] - a light color suitable for use on dark backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_dark` (if also present) and with black text, so it can also serve as an alternative light background. + - `on_light?`: integer[] - a dark color suitable for use on light backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_light` (if also present) and with white text, so it can also serve as an alternative dark background. diff --git a/messaging.md b/messaging.md index 6b15ece..763b850 100644 --- a/messaging.md +++ b/messaging.md @@ -252,11 +252,11 @@ For synchronization, all timing is relative to the server's monotonic clock. The Client sends state updates to the server. Contains client-level state and role-specific state objects. -Sent once the client is ready to report its operational status (`available`), and whenever any state changes thereafter. A player reports `available: true` only after it has established [clock synchronization](#clock-synchronization). The server MUST NOT send binary data to a client before that client has sent its initial `client/state`. When a role becomes active in `active_roles`, send its full state. +Sent once the client is ready to report its operational status (`available`), and whenever any state changes thereafter. A player reports `available: true` only after it has established [clock synchronization](#clock-synchronization). The server MUST NOT send binary data to a client before that client has sent its initial `client/state`. When a role becomes active in `active_roles`, send an update that includes that role's object. A client whose `active_roles` include `artwork` or `visualizer` sends the initial `client/state` even when none of its roles defines a state object; `available` alone unlocks the server's streams. -The initial message MUST include all state fields. In subsequent messages, the client MAY send only the fields that have changed; the server MUST merge each update into existing state, retaining the last value of any field that is absent. A client MAY instead resend unchanged fields, up to its full state. +Every message MUST carry `available` and the full state of each role object it includes. Omitting a role object leaves that role's state unchanged. - `available`: boolean - whether the client is available to participate in Sendspin playback - `true` - client is operational and ready to participate in playback; for a player or source this means its clock is synchronized with the server. @@ -292,7 +292,7 @@ If the client is in a multi-client group: If the client is already in a solo group: - Stop playback and send [`stream/end`](#server--client-streamend) for all active streams -- If `playback_state` was not already `'stopped'`, send [`group/update`](#server--client-groupupdate) with `playback_state: 'stopped'` +- If `playback_state` was not already `'stopped'`, send [`group/update`](#server--client-groupupdate) reporting `playback_state: 'stopped'` When a client returns to `available: true`, the server MUST NOT auto-rejoin it to its previous group or restart playback; the client remains in the solo group and rejoins only via an explicit [`switch`](roles/controller/v1.md#switch-command-cycle). @@ -308,13 +308,9 @@ Client sends commands to the server. Contains command objects based on the clien Server sends state updates to the client. Contains role-specific state objects. -Only include fields that have changed. The client will merge these updates into existing state. A leaf field set to `null` should be cleared from the client's state; a whole role object set to `null` clears all of that role's state. +Every message MUST carry the full state of each role object it includes. Omitting a role object leaves that role's state unchanged. -The merge is shallow: a nested object (e.g., `metadata.progress`) is replaced or cleared as a whole, never deep-merged, so nested objects are always sent complete. - -The first `server/state` sent for a role on a connection, and the first after that role is re-added to `active_roles`, MUST carry the role's full state. - -The asymmetry with [`client/state`](#client--server-clientstate) is deliberate: server-to-client updates carry only changed fields; clients MAY resend unchanged fields. +A role object set to `null` clears all of that role's state. - `metadata?`: object | null - only sent to clients with `metadata` role ([see metadata state object details](roles/metadata/v1.md#server--client-serverstate-metadata-object)) - `controller?`: object | null - only sent to clients with `controller` role ([see controller state object details](roles/controller/v1.md#server--client-serverstate-controller-object)) @@ -388,13 +384,11 @@ Sending `stream/end` in these cases is explicitly prohibited because it signals State update of the group this client is part of. -Contains delta updates with only the changed fields. The client should merge these updates into existing state. - -The first `group/update` on a connection MUST carry the full group state (all fields below), so the client has a baseline to merge later deltas into. +Every message MUST carry the full group state. -- `playback_state?`: 'playing' | 'stopped' - playback state of the group -- `group_id?`: string - group identifier -- `group_name?`: string - friendly name of the group +- `playback_state`: 'playing' | 'stopped' - playback state of the group +- `group_id`: string - group identifier +- `group_name`: string - friendly name of the group ### Server → Client: `server/unpair` diff --git a/roles/color/v1.md b/roles/color/v1.md index add0858..4bb531a 100644 --- a/roles/color/v1.md +++ b/roles/color/v1.md @@ -7,9 +7,9 @@ The `color` object in [`server/state`](../../messaging.md#server--client-servers - `color`: object - `timestamp`: integer - server clock time in microseconds for when these colors are valid - - `background_dark?`: integer[] | null - background color suitable for dark mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with white text and with `on_dark` (if also present). - - `background_light?`: integer[] | null - background color suitable for light mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with black text and with `on_light` (if also present). - - `primary?`: integer[] | null - the dominant color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. - - `accent?`: integer[] | null - a secondary or complementary color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. - - `on_dark?`: integer[] | null - a light color suitable for use on dark backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_dark` (if also present) and with black text, so it can also serve as an alternative light background. - - `on_light?`: integer[] | null - a dark color suitable for use on light backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_light` (if also present) and with white text, so it can also serve as an alternative dark background. + - `background_dark?`: integer[] - background color suitable for dark mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with white text and with `on_dark` (if also present). + - `background_light?`: integer[] - background color suitable for light mode as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with black text and with `on_light` (if also present). + - `primary?`: integer[] - the dominant color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. + - `accent?`: integer[] - a secondary or complementary color, as `[R, G, B]` with values 0-255. Not adjusted for contrast. + - `on_dark?`: integer[] - a light color suitable for use on dark backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_dark` (if also present) and with black text, so it can also serve as an alternative light background. + - `on_light?`: integer[] - a dark color suitable for use on light backgrounds, as `[R, G, B]` with values 0-255. The server must ensure a minimum WCAG contrast ratio of 4.5:1 with `background_light` (if also present) and with white text, so it can also serve as an alternative dark background. diff --git a/roles/metadata/v1.md b/roles/metadata/v1.md index 9b85f81..0887f62 100644 --- a/roles/metadata/v1.md +++ b/roles/metadata/v1.md @@ -7,21 +7,21 @@ The `metadata` object in [`server/state`](../../messaging.md#server--client-serv - `metadata`: object - `timestamp`: integer - server clock time in microseconds for when this metadata is valid - - `title?`: string | null - track title - - `artist?`: string | null - primary artist(s) - - `album_artist?`: string | null - album artist(s) - - `album?`: string | null - name of the album or release that this track belongs to - - `artwork_url?`: string | null - URL to artwork image. Useful for clients that want to forward metadata to external systems or for powerful clients that can fetch and process images themselves - - `year?`: integer | null - release year in YYYY format - - `track?`: integer | null - track number on the album (1-indexed), null if unknown or not applicable - - `progress?`: object | null - playback progress information. The server must send this object whenever playback state changes (play, pause, resume, seek, playback speed change) - - `track_progress`: integer - current playback position in milliseconds since start of track + - `title?`: string - track title + - `artist?`: string - primary artist(s) + - `album_artist?`: string - album artist(s) + - `album?`: string - name of the album or release that this track belongs to + - `artwork_url?`: string - URL to artwork image. Useful for clients that want to forward metadata to external systems or for powerful clients that can fetch and process images themselves + - `year?`: integer - release year in YYYY format + - `track?`: integer - track number on the album (1-indexed), absent if unknown or not applicable + - `progress?`: object - playback progress information. Omitting it clears the client's position, so include it in every `metadata` state that has a position to report. The server must send a new `metadata` state whenever playback state changes (play, pause, resume, seek, playback speed change) + - `track_progress`: integer - playback position in milliseconds since start of track, measured at `timestamp` - `track_duration`: integer - total track length in milliseconds, 0 for unlimited/unknown duration (e.g., live radio streams) - `playback_speed`: integer - playback speed multiplier * 1000 (e.g., 1000 = normal speed, 1500 = 1.5x speed, 500 = 0.5x speed, 0 = paused) #### Calculating current track position -Clients can calculate the current track position at any time using the `timestamp` and `progress` values from the last metadata message that included the `progress` object: +Clients can calculate the current track position at any time using the `timestamp` and `progress` values from the current metadata state: ```python calculated_progress = metadata.progress.track_progress + (current_time - metadata.timestamp) * metadata.progress.playback_speed / 1000000 diff --git a/roles/player/v1.md b/roles/player/v1.md index a1be6cb..ecdb21c 100644 --- a/roles/player/v1.md +++ b/roles/player/v1.md @@ -54,12 +54,10 @@ State updates must be sent whenever any state changes, including when the volume - `player`: object - `volume?`: integer - range 0-100, MUST be included if 'volume' is in `supported_commands` from [`player@v1_support`](#client--server-clienthello-playerv1-support-object) - `muted?`: boolean - mute state, MUST be included if 'mute' is in `supported_commands` from [`player@v1_support`](#client--server-clienthello-playerv1-support-object) - - `output_delay_ms`: integer - output delay in milliseconds (0-5000), REQUIRED for players - - `required_lead_time_ms`: integer - minimum startup lead time in milliseconds (e.g., codec init, decode warmup, audio backend buffering, DAC latency), REQUIRED for players. Measured from the server transmit time of the start/restart trigger (the `server_transmitted` field in [`stream/start`](../../messaging.md#server--client-streamstart) or [`stream/clear`](../../messaging.md#server--client-streamclear)) to the playback timestamp of the first audio chunk that can be played in full. The server treats this as a hint and MAY give less lead (see [Server behavior](#client--server-clienthello-playerv1-support-object)). - - `min_buffer_ms`: integer - requested minimum ongoing buffer duration in milliseconds during playback (primarily for live streams), used to absorb network jitter and ongoing decode/playback timing variance. REQUIRED for players. - - `supported_commands?`: string[] - subset of: 'set_output_delay' - -**Delta updates:** The presence requirements above (REQUIRED fields, and fields that MUST be included when a command is supported) describe a player's full state, reported in the initial message. In any later update a player MAY omit fields whose values have not changed, per the delta rules in [`client/state`](../../messaging.md#client--server-clientstate). + - `output_delay_ms`: integer - output delay in milliseconds (0-5000) + - `required_lead_time_ms`: integer - minimum startup lead time in milliseconds (e.g., codec init, decode warmup, audio backend buffering, DAC latency). Measured from the server transmit time of the start/restart trigger (the `server_transmitted` field in [`stream/start`](../../messaging.md#server--client-streamstart) or [`stream/clear`](../../messaging.md#server--client-streamclear)) to the playback timestamp of the first audio chunk that can be played in full. The server treats this as a hint and MAY give less lead (see [Server behavior](#client--server-clienthello-playerv1-support-object)). + - `min_buffer_ms`: integer - requested minimum ongoing buffer duration in milliseconds during playback (primarily for live streams), used to absorb network jitter and ongoing decode/playback timing variance. + - `supported_commands`: string[] - subset of: 'set_output_delay', empty when the player accepts no commands **Output delay:** The default is 0, meaning audio exits the device's audio port at the timestamp. `output_delay_ms` compensates for additional delay beyond the port (external speakers, amplifiers); it does not cover processing delays before the port (DAC latency, audio buffers), which the client compensates itself. Negative values are not supported and should never be required for any compliant implementation. Clients must persist `output_delay_ms` locally across reboots and server reconnections. Clients may update `output_delay_ms` and `supported_commands` when audio output changes (e.g., external speaker connected), persisting separate delays per output.