From fc2bd3baf15ba0e13223aa99028cb29b4c9f45e7 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Mon, 8 Jun 2026 23:09:19 +0700 Subject: [PATCH] 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 --- .../src/shared/hooks/useAudioTransmit.ts | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/services/frontend/src/shared/hooks/useAudioTransmit.ts b/services/frontend/src/shared/hooks/useAudioTransmit.ts index ac823e3..9f62c05 100644 --- a/services/frontend/src/shared/hooks/useAudioTransmit.ts +++ b/services/frontend/src/shared/hooks/useAudioTransmit.ts @@ -5,29 +5,16 @@ import { getAPIURL } from "../api/client"; const SAMPLE_RATE = 24000; async function sendTransmitCommand(command: string): Promise { - // Send via WebSocket (primary) - try { - const wsUrl = import.meta.env.VITE_BE_WS_URL || - `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/ws`; - const ws = new WebSocket(wsUrl); - ws.binaryType = "arraybuffer"; - await new Promise((resolve, reject) => { - ws.onopen = () => { - ws.send(JSON.stringify({ type: "voice_command", command })); - ws.close(); - 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 }), - }); + // Send via HTTP API + const resp = await fetch(`${getAPIURL()}/voice/command`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ command }), + }); + if (!resp.ok) { + const text = await resp.text().catch(() => resp.statusText); + console.warn("HTTP command failed:", text); + throw new Error(`HTTP ${resp.status}: ${text}`); } }