From a0f39302919fbacf7a0d407f01b1a50413ea6f70 Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Mon, 02 Mar 2026 23:15:13 +0100
Subject: [PATCH] feat: on-device speech recognition, navigation screen, session picker
---
contexts/ConnectionContext.tsx | 33 ++++++++++++++++++++++-----------
1 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/contexts/ConnectionContext.tsx b/contexts/ConnectionContext.tsx
index 69d6193..860ec59 100644
--- a/contexts/ConnectionContext.tsx
+++ b/contexts/ConnectionContext.tsx
@@ -7,7 +7,12 @@
useState,
} from "react";
import * as SecureStore from "expo-secure-store";
-import { ConnectionStatus, ServerConfig, WebSocketMessage } from "../types";
+import {
+ ConnectionStatus,
+ ServerConfig,
+ WsIncoming,
+ WsOutgoing,
+} from "../types";
import { wsClient } from "../services/websocket";
const SECURE_STORE_KEY = "pailot_server_config";
@@ -19,9 +24,10 @@
disconnect: () => void;
sendTextMessage: (text: string) => boolean;
sendVoiceMessage: (audioBase64: string, transcript?: string) => boolean;
+ sendCommand: (command: string, args?: Record<string, unknown>) => boolean;
saveServerConfig: (config: ServerConfig) => Promise<void>;
onMessageReceived: React.MutableRefObject<
- ((data: WebSocketMessage) => void) | null
+ ((data: WsIncoming) => void) | null
>;
}
@@ -34,9 +40,7 @@
}) {
const [serverConfig, setServerConfig] = useState<ServerConfig | null>(null);
const [status, setStatus] = useState<ConnectionStatus>("disconnected");
- const onMessageReceived = useRef<((data: WebSocketMessage) => void) | null>(
- null
- );
+ const onMessageReceived = useRef<((data: WsIncoming) => void) | null>(null);
useEffect(() => {
loadConfig();
@@ -48,7 +52,7 @@
onClose: () => setStatus("disconnected"),
onError: () => setStatus("disconnected"),
onMessage: (data) => {
- onMessageReceived.current?.(data);
+ onMessageReceived.current?.(data as WsIncoming);
},
});
}, []);
@@ -92,18 +96,24 @@
}, []);
const sendTextMessage = useCallback((text: string): boolean => {
- const msg: WebSocketMessage = { type: "text", content: text };
- return wsClient.send(msg);
+ return wsClient.send({ type: "text", content: text });
}, []);
const sendVoiceMessage = useCallback(
(audioBase64: string, transcript: string = ""): boolean => {
- const msg: WebSocketMessage = {
+ return wsClient.send({
type: "voice",
content: transcript,
audioBase64,
- };
- return wsClient.send(msg);
+ });
+ },
+ []
+ );
+
+ const sendCommand = useCallback(
+ (command: string, args?: Record<string, unknown>): boolean => {
+ const msg: WsOutgoing = { type: "command", command, args };
+ return wsClient.send(msg as any);
},
[]
);
@@ -117,6 +127,7 @@
disconnect,
sendTextMessage,
sendVoiceMessage,
+ sendCommand,
saveServerConfig,
onMessageReceived,
}}
--
Gitblit v1.3.1