fix(qconnect): WS-authoritative shuffle/repeat gating, button reflection, pause-to-iOS

Shuffle and Repeat now go to the CLOUD whenever connected (renderer OR controller),
gating on transport_connected like Tauri's v2_toggle_shuffle / v2_set_repeat_mode,
instead of the old peer-active gate that fell through to a LOCAL reshuffle when QBZ
was the active renderer — that did nothing visible AND risked a divergent local
order. QBZ sends only the seed + pivot; the cloud owns the order; the toggle reads
the cloud-authoritative queue.shuffle_mode. The local shuffle path is now reachable
only when NOT connected.

- shuffle/repeat button reflects the cloud queue flag (queue.shuffle_mode for the
  controller branch, core queue state via refresh_transport_modes for the renderer
  branch), not the per-renderer field the cloud never populates for a peer — fixes
  the iOS-reflects / WebPlayer-doesn't asymmetry.
- pause/play to a peer renderer: send a BARE SetPlayerState (playing_state only).
  iOS reports current_queue_item_id=null while playing, so resolving the qid landed
  on queue_item_id 0 — the protocol's "unknown" placeholder — and iOS could not
  anchor the pause, auto-resuming. A bare transport toggle is spec-sanctioned: the
  renderer pauses/resumes its own current item in place.
- skip_serializing_if on the SetPlayerState request structs so a None field is
  OMITTED, not serialized as null; and the mapper now treats a null current_queue_item
  as absent. Without this the bare command failed to encode and was never sent.
- log the outbound SetPlayerState payload for controller diagnostics.

cc
This commit is contained in:
vicrodh committed 2026-06-05 17:44:11 -06:00
1 parent 1072195740
commit b4c3bab91b
6 files changed
+204 -66

No files matched your search

+40
View File
@@ -882,6 +882,13 @@ fn parse_set_player_state_queue_item(
let nested = payload
.get("current_queue_item")
.or_else(|| payload.get("currentQueueItem"));
// A present-but-null `current_queue_item` means "no item" — a bare play/pause
// toggle. Treat it as ABSENT rather than hard-failing the whole command encode
// (the old behavior aborted the send before it reached the wire). Defense in
// depth alongside `skip_serializing_if` on the request struct.
if matches!(nested, Some(Value::Null)) {
return Ok(None);
}
let source = match nested {
Some(value) => value,
None => payload,
@@ -1096,6 +1103,39 @@ mod tests {
);
}
#[test]
fn encodes_bare_set_player_state_pause_without_queue_item() {
// A bare play/pause toggle sends ONLY playing_state — the renderer
// pauses/resumes its current item in place. Two shapes must both encode
// cleanly with NO current_queue_item: the key omitted (via
// skip_serializing_if), and present-but-null (defense in depth). The old
// mapper rejected the null shape ("must be an object") and aborted the
// whole send, which is why pause-to-an-iOS-renderer silently failed.
for payload in [
json!({ "playing_state": 3 }),
json!({ "playing_state": 3, "current_position": null, "current_queue_item": null }),
] {
let command = QueueCommand::new(
QueueCommandType::CtrlSrvrSetPlayerState,
"132db70b-d293-4576-bfd6-747c40ab764f",
QueueVersion::new(5, 3),
payload,
);
let encoded =
encode_queue_command_batch(&command).expect("bare pause must encode (not abort)");
let decoded = QConnectMessages::decode(encoded.as_slice()).expect("decode batch");
let player_state = decoded.messages[0]
.ctrl_srvr_set_player_state
.as_ref()
.expect("player state payload");
assert_eq!(player_state.playing_state, Some(3));
assert!(
player_state.current_queue_item.is_none(),
"bare pause must carry NO current_queue_item (qid 0 is the placeholder iOS rejects)"
);
}
}
#[test]
fn encodes_queue_load_tracks_with_android_like_fields() {
let command = QueueCommand::new(