fix(voice): use HTTP-only for transmit commands

Send voice:transmit:start/stop via POST /api/voice/command
instead of WebSocket. The WebSocket approach failed because:
1. Separate WS connections weren't handled by backend
2. HTTP fallback wasn't working correctly

Now uses HTTP API directly which is more reliable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-08 23:09:19 +07:00
co-authored by Claude Opus 4.8
parent 52f2968d8f
commit fc2bd3baf1
@@ -5,29 +5,16 @@ import { getAPIURL } from "../api/client";
const SAMPLE_RATE = 24000; const SAMPLE_RATE = 24000;
async function sendTransmitCommand(command: string): Promise<void> { async function sendTransmitCommand(command: string): Promise<void> {
// Send via WebSocket (primary) // Send via HTTP API
try { const resp = await fetch(`${getAPIURL()}/voice/command`, {
const wsUrl = import.meta.env.VITE_BE_WS_URL || method: "POST",
`${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/ws`; headers: { "Content-Type": "application/json" },
const ws = new WebSocket(wsUrl); body: JSON.stringify({ command }),
ws.binaryType = "arraybuffer"; });
await new Promise<void>((resolve, reject) => { if (!resp.ok) {
ws.onopen = () => { const text = await resp.text().catch(() => resp.statusText);
ws.send(JSON.stringify({ type: "voice_command", command })); console.warn("HTTP command failed:", text);
ws.close(); throw new Error(`HTTP ${resp.status}: ${text}`);
resolve();
};
ws.onerror = () => reject(new Error("WS failed"));
setTimeout(() => reject(new Error("WS timeout")), 3000);
});
} catch (err) {
console.warn("WebSocket command failed, trying HTTP:", err);
// Fallback: send via HTTP API
await fetch(`${getAPIURL()}/voice/command`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ command }),
});
} }
} }