[codex] webui coverage for bluetooth and config backend routes #17

Merged
electron-rare merged 1 commits from codex/rtc-issue-10-webui-coverage into audit/telephony-webserver 2026-02-20 23:55:29 +00:00
2 changed files with 172 additions and 1 deletions
+38
View File
@@ -32,6 +32,29 @@
<button id="refreshConfigBtn">Rafraîchir configuration</button>
</div>
<pre id="configJson"></pre>
<div class="grid2">
<div>
<h3>Audio config (JSON)</h3>
<textarea id="audioConfigInput" rows="8" placeholder='{"volume":80}'></textarea>
<div class="inline-actions">
<button id="applyAudioConfigBtn">Appliquer audio</button>
</div>
</div>
<div>
<h3>MQTT config (JSON)</h3>
<textarea id="mqttConfigInput" rows="8" placeholder='{"enabled":false}'></textarea>
<div class="inline-actions">
<button id="applyMqttConfigBtn">Appliquer MQTT</button>
</div>
</div>
<div>
<h3>Pins config (JSON)</h3>
<textarea id="pinsConfigInput" rows="8" placeholder='{"slic":{"line":23}}'></textarea>
<div class="inline-actions">
<button id="applyPinsConfigBtn">Appliquer pins</button>
</div>
</div>
</div>
</section>
<section id="networkSection">
@@ -86,6 +109,21 @@
<pre id="espnowJson"></pre>
<pre id="espnowPeersJson"></pre>
</div>
<div>
<h3>Bluetooth</h3>
<form id="btHfpConnectForm">
<input type="text" id="btHfpAddr" placeholder="MAC téléphone HFP (AA:BB:CC:DD:EE:FF)">
<button type="submit">HFP Connect</button>
</form>
<div class="inline-actions">
<button id="btHfpDisconnectBtn">HFP Disconnect</button>
<button id="btBleStartBtn">BLE Start</button>
<button id="btBleStopBtn">BLE Stop</button>
<button id="btRefreshBtn">Rafraîchir BT</button>
</div>
<pre id="btJson"></pre>
</div>
</div>
</section>
+134 -1
View File
@@ -51,6 +51,14 @@ function jsonHeaders() {
return { "Content-Type": "application/json" };
}
function parseJsonInput(id) {
const raw = document.getElementById(id).value.trim();
if (!raw) {
return {};
}
return JSON.parse(raw);
}
function parsePayloadValue(rawPayload) {
const trimmed = rawPayload.trim();
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
@@ -90,6 +98,18 @@ async function refreshConfig() {
requestJson("/api/config/mqtt"),
]);
setJson("configJson", { pins, audio, mqtt });
const audioInput = document.getElementById("audioConfigInput");
const mqttInput = document.getElementById("mqttConfigInput");
const pinsInput = document.getElementById("pinsConfigInput");
if (audioInput) {
audioInput.value = JSON.stringify(audio, null, 2);
}
if (mqttInput) {
mqttInput.value = JSON.stringify(mqtt.config || mqtt, null, 2);
}
if (pinsInput) {
pinsInput.value = JSON.stringify(pins, null, 2);
}
} catch (error) {
setJson("configJson", { error: error.message });
}
@@ -116,6 +136,15 @@ async function refreshNetwork() {
}
}
async function refreshBluetooth() {
try {
const bt = await requestJson("/api/bluetooth");
setJson("btJson", bt);
} catch (error) {
setJson("btJson", { error: error.message });
}
}
async function sendControl(action) {
const result = await requestJson("/api/control", {
method: "POST",
@@ -137,6 +166,52 @@ function bindEvents() {
});
document.getElementById("refreshConfigBtn").addEventListener("click", refreshConfig);
document.getElementById("espnowRefreshBtn").addEventListener("click", refreshNetwork);
document.getElementById("btRefreshBtn").addEventListener("click", refreshBluetooth);
document.getElementById("applyAudioConfigBtn").addEventListener("click", async () => {
try {
const payload = parseJsonInput("audioConfigInput");
const result = await requestJson("/api/config/audio", {
method: "POST",
headers: jsonHeaders(),
body: JSON.stringify(payload),
});
setJson("actionResult", result);
await Promise.all([refreshConfig(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("applyMqttConfigBtn").addEventListener("click", async () => {
try {
const payload = parseJsonInput("mqttConfigInput");
const result = await requestJson("/api/config/mqtt", {
method: "POST",
headers: jsonHeaders(),
body: JSON.stringify(payload),
});
setJson("actionResult", result);
await Promise.all([refreshConfig(), refreshNetwork(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("applyPinsConfigBtn").addEventListener("click", async () => {
try {
const payload = parseJsonInput("pinsConfigInput");
const result = await requestJson("/api/config/pins", {
method: "POST",
headers: jsonHeaders(),
body: JSON.stringify(payload),
});
setJson("actionResult", result);
await Promise.all([refreshConfig(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("wifiConnectForm").addEventListener("submit", async (event) => {
event.preventDefault();
@@ -319,6 +394,64 @@ function bindEvents() {
}
});
document.getElementById("btHfpConnectForm").addEventListener("submit", async (event) => {
event.preventDefault();
const addr = document.getElementById("btHfpAddr").value.trim();
try {
const result = await requestJson("/api/bluetooth/hfp/connect", {
method: "POST",
headers: jsonHeaders(),
body: JSON.stringify({ addr }),
});
setJson("actionResult", result);
await Promise.all([refreshBluetooth(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("btHfpDisconnectBtn").addEventListener("click", async () => {
try {
const result = await requestJson("/api/bluetooth/hfp/disconnect", {
method: "POST",
headers: jsonHeaders(),
body: "{}",
});
setJson("actionResult", result);
await Promise.all([refreshBluetooth(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("btBleStartBtn").addEventListener("click", async () => {
try {
const result = await requestJson("/api/bluetooth/ble/start", {
method: "POST",
headers: jsonHeaders(),
body: "{}",
});
setJson("actionResult", result);
await Promise.all([refreshBluetooth(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.getElementById("btBleStopBtn").addEventListener("click", async () => {
try {
const result = await requestJson("/api/bluetooth/ble/stop", {
method: "POST",
headers: jsonHeaders(),
body: "{}",
});
setJson("actionResult", result);
await Promise.all([refreshBluetooth(), refreshStatus()]);
} catch (error) {
setJson("actionResult", { error: error.message });
}
});
document.querySelectorAll("#controlSection button[data-action]").forEach((button) => {
button.addEventListener("click", async () => {
try {
@@ -342,6 +475,6 @@ function bindEvents() {
document.addEventListener("DOMContentLoaded", async () => {
bindEvents();
await Promise.all([refreshStatus(), refreshConfig(), refreshNetwork()]);
await Promise.all([refreshStatus(), refreshConfig(), refreshNetwork(), refreshBluetooth()]);
showSection("dashboard");
});