36 lines
1.4 KiB
C++
36 lines
1.4 KiB
C++
#pragma once
|
||
|
||
#include "audio/audio_prompt.h"
|
||
#include <string>
|
||
|
||
// Connection error prompt config — decoupled from hard-coded logic.
|
||
// Server pushes a map via hello:
|
||
// connection_error_prompts: {
|
||
// "server_unreachable": "server_error",
|
||
// "no_network": "no_network"
|
||
// }
|
||
// Values are prompt group names that map to PromptGroup enum via GetGroupByName.
|
||
// Cached in NVS namespace "conn_err"; empty NVS falls back to hard-coded defaults.
|
||
|
||
enum class ConnErrorReason {
|
||
kServerUnreachable, // WiFi 已连,但 OpenAudioChannel 失败(DNS/404/timeout)
|
||
kNoNetwork, // WiFi 都没连上
|
||
};
|
||
|
||
namespace conn_error_config {
|
||
|
||
// Called from WebSocketProtocol hello parser. Writes NVS.
|
||
// If any value is invalid or unrecognized, it's ignored (not written).
|
||
void UpdateFromHello(const char* server_unreachable_name, const char* no_network_name);
|
||
|
||
// Called from application.cc when connection fails. Returns the group to play.
|
||
// Resolution order:
|
||
// 1. NVS value for this reason → lookup by name → PromptGroup (if HasPrompts)
|
||
// 2. Hard-coded fallback (kPromptServerError for server_unreachable;
|
||
// kPromptNoNetwork for no_network)
|
||
// 3. If fallback also lacks prompts, returns kPromptNoNetwork regardless
|
||
// (caller is expected to still HasPrompts-check before play)
|
||
PromptGroup GetGroupForReason(ConnErrorReason reason);
|
||
|
||
} // namespace conn_error_config
|