Repository navigation
Make client/hello advertisement configurable - #31
Conversation
Add three additive, non-breaking ClientPreferences knobs; the defaults reproduce the current hello byte-for-byte: - advertiseOptionalRoles (default true): when false, client/hello advertises only the mandatory player@v1 role and omits the optional metadata/artwork/controller/color/visualizer roles and their *_support blocks, for servers that reject a hello carrying unexpected roles. - playerBufferCapacity, playerSupportedCommands: expose the previously hardcoded player@v1_support values. buildClientHello() honours all three. Adds 4 tests covering the only-player case, the default-advertises case, and custom/default buffer_capacity + supported_commands. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
OnFreund
left a comment
There was a problem hiding this comment.
Suggestion: make the optional-role gate granular instead of all-or-nothing
advertiseOptionalRoles: Boolean is either "advertise all five optional roles" or "advertise none." That doesn't cover a host that only implements a subset — e.g. controller@v1 + metadata@v1 but not artwork@v1/color@v1.
Suggest replacing it with a typed set so hosts get real autocomplete/compile-time safety instead of a raw string list:
enum class OptionalRole(val roleName: String) {
METADATA("metadata@v1"),
ARTWORK("artwork@v1"),
CONTROLLER("controller@v1"),
COLOR("color@v1"),
VISUALIZER("visualizer@v1"),
}data class ClientPreferences(
...
val supportedOptionalRoles: Set<OptionalRole> = OptionalRole.entries.toSet(),
)Each role and its *_support block would gate on OptionalRole.X in preferences.supportedOptionalRoles instead of the single shared boolean. Defaulting to the full set keeps existing/undecided hosts on today's byte-for-byte client/hello output, so it's still non-breaking.
Fold visualizer@v1's gate into the same mechanism
Right now visualizer@v1 is included whenever visualizerSupport != null — a second, separate gate that would sit alongside the new boolean/set. Once supportedOptionalRoles exists there's no need for two mechanisms: require both signals to agree, OptionalRole.VISUALIZER in supportedOptionalRoles && visualizerSupport != null. That removes the possibility of the two disagreeing (e.g. a host lists VISUALIZER in the set but forgets to also pass visualizerSupport, or supplies visualizerSupport without adding VISUALIZER to the set).
A boolean could only advertise all five optional roles or none. A host that implements a subset, for example controller@v1 and metadata@v1 but not artwork@v1, had no way to say so. Add OptionalRole and gate each role and its *_support block on membership in ClientPreferences.supportedOptionalRoles. The set defaults to every role, so client/hello output is unchanged for existing hosts. Fold the separate visualizerSupport != null gate into the same predicate: visualizer@v1 needs both OptionalRole.VISUALIZER in the set and a non-null support block, so the two signals cannot disagree. Iterate OptionalRole.entries rather than the caller's Set so supported_roles order stays deterministic.
Great addition! Did it! |
OnFreund
left a comment
There was a problem hiding this comment.
Follow-up now that OptionalRole + supportedOptionalRoles have landed — thanks, that's exactly the shape we discussed. A few more suggestions in the same spirit, on player@v1:
1. Fold player@v1 into OptionalRole too — it isn't spec-mandatory
The OptionalRole KDoc says player@v1 "is mandatory and not listed," but checking Sendspin/spec:
"Players that can output audio should have the role
player."
player@v1_support?: object - required ifplayer@v1is listed, absent otherwise
That's the same conditional phrasing used for source@v1/artwork@v1/visualizer@v1 — the spec treats player@v1 symmetrically with every other role and explicitly anticipates non-player clients (controller-only, metadata-only, source-only). So "mandatory" describes this library's current implementation choice, not a protocol requirement.
The fix is small — sendClientState() already derives whether to include the player object in client/state from the server's activeRoles, not from any hardcoded assumption, so nothing there needs to change:
enum class OptionalRole(val roleName: String) {
PLAYER("player@v1"),
METADATA("metadata@v1"),
ARTWORK("artwork@v1"),
CONTROLLER("controller@v1"),
COLOR("color@v1"),
VISUALIZER("visualizer@v1"),
}- Drop the hardcoded
add("player@v1")inbuildClientHello(); let it fall out of the sameOptionalRole.entries.filter { advertises(it) }loop as the rest. playerSupport = if (advertises(OptionalRole.PLAYER)) PlayerSupport(...) else null— same pattern asmetadataSupport/artworkSupport.- Default set (
OptionalRole.entries.toSet()) includesPLAYERautomatically, so existing hosts see no change.
2. Make audioPlayerFactory optional to match
Today audioPlayerFactory: (AudioBuffer, ClockSync) -> AudioPlayer is a required constructor param, so a host built around (1) that doesn't want the player role would still have to hand-write a stub AudioPlayer. Since AudioPlayer is a small 6-method interface, the library can supply that stub itself and fail fast if the two settings disagree:
// AudioPlayer.kt — matches the existing NoOpClientSettingsStore convention
object NoOpAudioPlayer : AudioPlayer {
override val isPlaying = false
override val droppedDecodeFrames = 0L
override fun configure(format: StreamFormat) {}
override fun start() {}
override fun flush() {}
override fun stop() {}
override fun transition(format: StreamFormat) {}
override fun setVolume(gain: Float) {}
}// SendSpinClient.kt
audioPlayerFactory: ((AudioBuffer, ClockSync) -> AudioPlayer)? = null,
...
val audioPlayer: AudioPlayer = audioPlayerFactory?.invoke(audioBuffer, clockSync) ?: run {
require(OptionalRole.PLAYER !in preferences.supportedOptionalRoles) {
"player@v1 is in supportedOptionalRoles but no audioPlayerFactory was provided"
}
NoOpAudioPlayer
}This keeps audioPlayer non-nullable throughout the class (it's used in ~10 places, and is a public property, so a nullable AudioPlayer? would ripple into every call site and break existing consumers — not worth it). require() fits since it's the idiomatic Kotlin constructor-precondition check and there's no other exception convention in sendspin-protocol/src/main to follow instead.
I checked all existing SendSpinClient(...) call sites (tests in this repo) — they all pass audioPlayerFactory by name, so making it nullable-with-default is source-compatible; no other call site needs to change.
The spec phrases player@v1 like every other role: "players that can output audio should have the role player", and player@v1_support is required only if player@v1 is listed. A controller-only or metadata-only client had to advertise a player role it does not implement and supply a stub AudioPlayer. Add OptionalRole.PLAYER and gate player@v1 and player@v1_support on set membership, the same way as the other roles. PLAYER is first in the enum, so the default set produces the same supported_roles as before. Make audioPlayerFactory nullable with a NoOpAudioPlayer fallback, and fail fast when PLAYER is advertised without a factory. audioPlayer stays non-null, so no call site changes. Gate the client/state player object on our own advertisement too: active_roles is null before the server hello, and the volume, mute and static delay setters can report state before then.
Adds three additive, non-breaking
ClientPreferencesknobs so hosts can control whatclient/helloadvertises. All defaults reproduce the current hello byte-for-byte, so existing hosts are unaffected.What & why
advertiseOptionalRoles(defaulttrue) — whenfalse, the hello advertises only the mandatoryplayer@v1role and omits the optionalmetadata/artwork/controller/color/visualizerroles and their*_supportblocks. This is for servers that reject a hello carrying roles they don't expect.playerBufferCapacity(default262144) andplayerSupportedCommands(default["volume", "mute"]) — expose the previously-hardcodedplayer@v1_supportvalues so hosts can advertise their real capacity and command set.buildClientHello()honours all three.Tests
Adds 4 cases to
SendSpinClientHelloTest:advertiseOptionalRoles = falseadvertises onlyplayer@v1and omits every optional support block.player@v1_supportreflects custombuffer_capacity/supported_commands.buffer_capacity = 262144and["volume", "mute"].Full
:sendspin-protocol:testsuite green on JDK 17.