A play that needed a download was ACKed SUCCESS and then nothing was
visible until playback started — and a failed download was only logged.
- New PlayerStatus::LOADING: status/playback publishes action "loading"
(pid/speed/duration/source set) before the ACK, then "playing" on success
or "idle" on failure.
- On failure after the ACK, control/reports gets
{ "type": "playback_failed", "payload": { "pid", "reason" } } (and a WS
INFO of the same). The download task re-checks bells-disabled/overload
before playing.
- playback.stop / forceStop during LOADING cancels the pending start
("Download cancelled — playback will not start"); the transfer finishes
and is discarded. New plays are refused until it does, since the task
still owns pid/_melodySteps. A mutex serialises the task's cancel-check +
play() against the cancel path.
- "loading" is MQTT-only: v1 tablets map unknown WS playback actions to
"unavailable" (F-061 symptom). system.status reports LOADING; the v1
adapter maps it to "idle".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.5 KiB
C++
57 lines
2.5 KiB
C++
#include "LegacyResponseAdapter.hpp"
|
|
#include "CommandResult.hpp"
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Known v2 → v1 reply divergences.
|
|
//
|
|
// Each entry here corresponds to a v2 CommandResult "type" that a v1 client
|
|
// polls for and parses with hardcoded v1 field names/shapes. Add a new case
|
|
// only when a real v1 caller is confirmed to depend on the old shape — see
|
|
// the file header for why this stays a narrow allowlist rather than a
|
|
// generic mapper.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// system.status → current_status
|
|
// v1 app: docs/reference/dart-command-handler.dart SystemInfo.getDeviceStatus()
|
|
// matches on type=="current_status", reads payload.player_status (lowercase),
|
|
// payload.time_elapsed, payload.strike_counters as an array.
|
|
static bool translateSystemStatus(const CommandResult& result, JsonDocument& out) {
|
|
JsonObjectConst data = result.data.as<JsonObjectConst>();
|
|
|
|
out["status"] = "SUCCESS";
|
|
out["type"] = "current_status";
|
|
JsonObject payload = out["payload"].to<JsonObject>();
|
|
|
|
// v2 sends UPPERCASE enum names (PLAYING/PAUSED/STOPPING/STOPPED/LOADING);
|
|
// v1 expects lowercase state words, with STOPPED spelled "idle". LOADING
|
|
// deliberately falls through to "idle" — v1 apps have no loading state and
|
|
// treat unknown words as "unavailable".
|
|
const char* v2Status = data["player_status"] | "STOPPED";
|
|
const char* v1Status = "idle";
|
|
if (strcmp(v2Status, "PLAYING") == 0) v1Status = "playing";
|
|
else if (strcmp(v2Status, "PAUSED") == 0) v1Status = "paused";
|
|
else if (strcmp(v2Status, "STOPPING") == 0) v1Status = "stopping";
|
|
|
|
payload["player_status"] = v1Status;
|
|
payload["time_elapsed"] = data["time_elapsed_ms"] | 0; // same unit (ms), renamed key
|
|
payload["projected_run_time"] = data["projected_run_time"] | 0;
|
|
|
|
// v2 sends strike_counters as an object keyed "0".."15"; v1 expects an array.
|
|
JsonArray strikes = payload["strike_counters"].to<JsonArray>();
|
|
JsonObjectConst v2Strikes = data["strike_counters"].as<JsonObjectConst>();
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
strikes.add(v2Strikes[String(i)] | 0);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool translateLegacyResponse(const CommandResult& result, JsonDocument& out) {
|
|
if (result.type == "system.status" && result.hasData) {
|
|
return translateSystemStatus(result, out);
|
|
}
|
|
|
|
// Not a known divergence — caller falls back to standard v2 serialisation.
|
|
return false;
|
|
}
|