Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(web): show voice connection state on the Meetings entry only

Ethand53b63c34592
diff --git a/apps/web/src/features/rooms/voice-control/recording-entry.test.tsx b/apps/web/src/features/rooms/voice-control/recording-entry.test.tsx
new file mode 100644
index 00000000..0af977fa
--- /dev/null
+++ b/apps/web/src/features/rooms/voice-control/recording-entry.test.tsx
@@ -0,0 +1,41 @@
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { RecordingEntry } from "./recording-entry";
+import {
+ VoiceCapabilitiesContext,
+ VoiceConnectionRetryContext,
+} from "./voice-control-context";
+
+vi.mock("./recording-window-store", () => ({ openRecordingWindow: vi.fn() }));
+
+afterEach(cleanup);
+
+function renderEntry(retryConnection?: () => void) {
+ return render(
+ <VoiceCapabilitiesContext value={undefined}>
+ <VoiceConnectionRetryContext value={retryConnection}>
+ <RecordingEntry anotherMeRoomId="another-me" />
+ </VoiceConnectionRetryContext>
+ </VoiceCapabilitiesContext>,
+ );
+}
+
+describe("RecordingEntry voice connection", () => {
+ it("spins without offering a retry while voice connects", () => {
+ renderEntry();
+ const button = screen.getByRole("button", { name: "Meetings" });
+ expect(button).toBeDisabled();
+ expect(button.querySelector(".animate-spin")).not.toBeNull();
+ });
+
+ it("retries a failed connection from the Meetings entry", () => {
+ const retry = vi.fn();
+ renderEntry(retry);
+ const button = screen.getByRole("button", {
+ name: "Retry voice connection",
+ });
+ expect(button).toBeEnabled();
+ fireEvent.click(button);
+ expect(retry).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/apps/web/src/features/rooms/voice-control/recording-entry.tsx b/apps/web/src/features/rooms/voice-control/recording-entry.tsx
index 0f3bb9b2..5f458299 100644
--- a/apps/web/src/features/rooms/voice-control/recording-entry.tsx
+++ b/apps/web/src/features/rooms/voice-control/recording-entry.tsx
@@ -10,6 +10,7 @@ import {
isTranscriptRecoveryPaused,
useOptionalVoiceControl,
VoiceCapabilitiesContext,
+ VoiceConnectionRetryContext,
} from "./voice-control-context";
/**
@@ -26,6 +27,8 @@ export function RecordingEntry({
const voice = livekit;
// Recording transcribes with Soniox; xAI alone does not offer it.
const capabilities = use(VoiceCapabilitiesContext);
+ const retryConnection = use(VoiceConnectionRetryContext);
+ const connectionFailed = Boolean(retryConnection);
const [error, setError] = useState<string>();
const [pending, setPending] = useState(false);
const status = voice?.captureState?.status;
@@ -35,21 +38,31 @@ export function RecordingEntry({
(status === "recovering" &&
!(voice && isTranscriptRecoveryPaused(voice.captureState)));
const standby = voice?.listenerStatus === "standby";
+ // Until voice connects, including while it reconnects, the icon spins.
+ const connecting = !voice && !connectionFailed;
const label = recording
? "Return to recording"
: saving
? "View save progress"
- : "Meetings";
+ : connectionFailed
+ ? "Retry voice connection"
+ : "Meetings";
const hint =
error ??
- (!voice || !anotherMeRoomId
- ? "Meeting is loading"
- : voice.composerMicrophoneActive
- ? "Finish voice input first"
- : standby
- ? "Recording is active in another tab"
- : label);
+ (connectionFailed
+ ? "Voice connection is unavailable. Click to retry."
+ : !voice || !anotherMeRoomId
+ ? "Meeting is loading"
+ : voice.composerMicrophoneActive
+ ? "Finish voice input first"
+ : standby
+ ? "Recording is active in another tab"
+ : label);
function start() {
+ if (retryConnection) {
+ retryConnection();
+ return;
+ }
if (!voice || !anotherMeRoomId || pending || voice.composerMicrophoneActive)
return;
setPending(true);
@@ -80,21 +93,25 @@ export function RecordingEntry({
aria-label={label}
className="xs-nav-btn relative"
disabled={
- pending || !voice || !anotherMeRoomId || voice.composerMicrophoneActive
+ !connectionFailed &&
+ (pending ||
+ !voice ||
+ !anotherMeRoomId ||
+ voice.composerMicrophoneActive)
}
onClick={start}
title={hint}
type="button"
>
- {saving ? (
+ {saving || connecting ? (
<Icon icon={Loading03Icon} className="animate-spin" size={16} />
) : (
<Icon icon={AiTranscribeAudioIcon} size={16} />
)}
- {recording ? (
+ {recording || connectionFailed ? (
<span
aria-hidden="true"
- className="absolute top-1 right-1 size-2 rounded-full bg-app-danger ring-2 ring-app-sidebar"
+ className={`absolute top-1 right-1 size-2 rounded-full ring-2 ring-app-sidebar ${recording ? "bg-app-danger" : "bg-app-warning"}`}
/>
) : null}
{error ? (
diff --git a/apps/web/src/features/rooms/voice-control/voice-backend-controller.tsx b/apps/web/src/features/rooms/voice-control/voice-backend-controller.tsx
index a02474c3..58d83c9b 100644
--- a/apps/web/src/features/rooms/voice-control/voice-backend-controller.tsx
+++ b/apps/web/src/features/rooms/voice-control/voice-backend-controller.tsx
@@ -9,7 +9,6 @@ import {
type Dispatch,
type SetStateAction,
} from "react";
-import { Button } from "@/components/ui/button";
import { teamHubData } from "@/features/teamhub/teamhub-api";
import { useTeamHubRuntime } from "@/features/teamhub/teamhub-runtime";
import {
@@ -58,6 +57,14 @@ export function VoiceBackendController({
const [backend, setBackend] = useState<TeamHubVoiceMediaPolicy>();
const [error, setError] = useState<"recovering" | "failed">();
const retryRef = useRef<(() => void) | undefined>(undefined);
+ // The Meetings entry offers the retry where the Human uses voice.
+ useEffect(() => {
+ onChange((current) => ({
+ ...current,
+ retryConnection:
+ error === "failed" ? () => retryRef.current?.() : undefined,
+ }));
+ }, [error, onChange]);
useEffect(() => {
let pending = false;
let failures = 0;
@@ -116,28 +123,16 @@ export function VoiceBackendController({
};
}, [client, tenantId, onChange]);
return (
- <>
- <Suspense fallback={null}>
- {backend?.voice_media_supported ? (
- <LiveKitProvider
- tenantId={tenantId}
- activeRoomId={backend.active_room_id}
- >
- <VoiceContextBridge onChange={onChange} />
- </LiveKitProvider>
- ) : null}
- </Suspense>
- {error === "recovering" ? (
- <div role="status">Reconnecting voice…</div>
- ) : error === "failed" ? (
- <div role="alert" className="flex items-center gap-3">
- Voice connection is temporarily unavailable.
- <Button onClick={() => retryRef.current?.()}>
- Retry voice connection
- </Button>
- </div>
+ <Suspense fallback={null}>
+ {backend?.voice_media_supported ? (
+ <LiveKitProvider
+ tenantId={tenantId}
+ activeRoomId={backend.active_room_id}
+ >
+ <VoiceContextBridge onChange={onChange} />
+ </LiveKitProvider>
) : null}
- </>
+ </Suspense>
);
}
diff --git a/apps/web/src/features/rooms/voice-control/voice-backend-provider.test.tsx b/apps/web/src/features/rooms/voice-control/voice-backend-provider.test.tsx
index b975d608..a2b0cbf3 100644
--- a/apps/web/src/features/rooms/voice-control/voice-backend-provider.test.tsx
+++ b/apps/web/src/features/rooms/voice-control/voice-backend-provider.test.tsx
@@ -20,6 +20,7 @@ import {
import {
VoiceCapabilitiesContext,
+ VoiceConnectionRetryContext,
VoiceControlContext,
useOptionalVoiceControl,
type VoiceControlContextValue,
@@ -100,6 +101,7 @@ const httpError = (status: number) =>
const ui = (tenantId = "tenant-a", text = "Room content") => (
<VoiceControlProvider tenantId={tenantId}>
<p>{text}</p>
+ <ConnectionProbe />
</VoiceControlProvider>
);
const advance = async (ms = 0) => {
@@ -160,6 +162,13 @@ function VoiceProbe() {
return <p>Target: {livekit?.targetRoomId ?? "loading"}</p>;
}
+function ConnectionProbe() {
+ const retryConnection = useContext(VoiceConnectionRetryContext);
+ return retryConnection ? (
+ <button onClick={retryConnection}>Retry voice connection</button>
+ ) : null;
+}
+
function CapabilitiesProbe() {
const capabilities = useContext(VoiceCapabilitiesContext);
return (
@@ -353,7 +362,9 @@ describe("voice backend bootstrap recovery", () => {
render(ui());
await advance(10_000);
expect(fixture.policy).toHaveBeenCalledTimes(1);
- expect(screen.getByRole("alert")).toBeVisible();
+ expect(
+ screen.getByRole("button", { name: "Retry voice connection" }),
+ ).toBeVisible();
expect(
screen.queryByRole("region", { name: "legacy:tenant-a" }),
).not.toBeInTheDocument();
@@ -363,7 +374,9 @@ describe("voice backend bootstrap recovery", () => {
);
await advance();
expect(fixture.policy).toHaveBeenCalledTimes(2);
- expect(screen.queryByRole("alert")).not.toBeInTheDocument();
+ expect(
+ screen.queryByRole("button", { name: "Retry voice connection" }),
+ ).not.toBeInTheDocument();
expect(
screen.getByRole("region", { name: "livekit:tenant-a" }),
).toBeVisible();
@@ -373,7 +386,9 @@ describe("voice backend bootstrap recovery", () => {
fixture.policy.mockRejectedValue(httpError(404));
render(ui());
await advance();
- expect(screen.getByRole("alert")).toBeVisible();
+ expect(
+ screen.getByRole("button", { name: "Retry voice connection" }),
+ ).toBeVisible();
expect(fixture.mounted).not.toHaveBeenCalled();
await advance(10_000);
expect(fixture.policy).toHaveBeenCalledTimes(1);
diff --git a/apps/web/src/features/rooms/voice-control/voice-backend-provider.tsx b/apps/web/src/features/rooms/voice-control/voice-backend-provider.tsx
index c9d58634..ac51a857 100644
--- a/apps/web/src/features/rooms/voice-control/voice-backend-provider.tsx
+++ b/apps/web/src/features/rooms/voice-control/voice-backend-provider.tsx
@@ -9,12 +9,14 @@ import {
import type { TeamHubVoiceMediaPolicy } from "@/features/teamhub/teamhub-types";
import {
VoiceCapabilitiesContext,
+ VoiceConnectionRetryContext,
VoiceControlContext,
} from "./voice-control-context";
export interface VoiceContexts {
livekit: ContextType<typeof VoiceControlContext>;
policy?: TeamHubVoiceMediaPolicy;
+ retryConnection?: () => void;
}
const VoiceBackendController = lazy(async () => ({
@@ -43,7 +45,7 @@ function TenantVoiceControlProvider({
() => <VoiceBackendController tenantId={tenantId} onChange={setContexts} />,
[tenantId],
);
- const { livekit, policy } = contexts;
+ const { livekit, policy, retryConnection } = contexts;
const ready = Boolean(policy && (!policy.voice_media_supported || livekit));
const capabilities = useMemo(
() =>
@@ -57,7 +59,9 @@ function TenantVoiceControlProvider({
<Suspense fallback={null}>{controller}</Suspense>
<VoiceControlContext value={livekit}>
<VoiceCapabilitiesContext value={capabilities}>
- {children}
+ <VoiceConnectionRetryContext value={retryConnection}>
+ {children}
+ </VoiceConnectionRetryContext>
</VoiceCapabilitiesContext>
</VoiceControlContext>
</>
diff --git a/apps/web/src/features/rooms/voice-control/voice-control-context.ts b/apps/web/src/features/rooms/voice-control/voice-control-context.ts
index aa828480..b4b3b3d7 100644
--- a/apps/web/src/features/rooms/voice-control/voice-control-context.ts
+++ b/apps/web/src/features/rooms/voice-control/voice-control-context.ts
@@ -91,6 +91,12 @@ export const VoiceCapabilitiesContext = createContext<
VoiceCapabilities | undefined
>({ voiceMedia: true });
+// Present only once the voice backend stopped retrying on its own; calling it
+// tries again.
+export const VoiceConnectionRetryContext = createContext<
+ (() => void) | undefined
+>(undefined);
+
export const VoiceControlContext =
createContext<VoiceControlContextValue | null>(null);