Skip to content

Commit a8c3e4c

Browse files
authored
fix(ui): explain pending voice microphone access (#133353)
* fix(ui): explain pending voice microphone access * test(ui): share WebRTC peer lookup in lifecycle cases
1 parent 42396a0 commit a8c3e4c

22 files changed

Lines changed: 328 additions & 96 deletions

‎docs/nodes/talk.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ browser at up to one frame per second, while `describe_view` reports the
5454
camera-stream state. In both cases, camera frames bypass the Gateway, and
5555
stopping Talk releases the camera and microphone tracks.
5656

57+
Browser Talk shows startup progress while preparing the session, waiting for
58+
microphone access, and connecting. Talk and dictation show microphone guidance
59+
while the browser's capture request is pending: bring the tab to the foreground
60+
and allow access if prompted. The browser can keep an unanswered permission
61+
request pending. In Talk, **Stop voice input** cancels startup and releases any
62+
microphone stream granted after cancellation.
63+
5764
If the microphone disconnects or its permission is revoked, browser Talk ends
5865
the call and shows an error. Choose an available **Microphone input**, restore
5966
permission if needed, and start Talk again. An unexpected GPT-Live connection

‎ui/src/e2e/browser-talk-microphone-lifetime.e2e.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,68 @@ const suite = createControlUiE2eSuite({
1717
});
1818

1919
suite.define(() => {
20+
it("guides a pending microphone request and clears guidance when voice connects", async () => {
21+
await suite.withPage({ permissions: ["microphone"] }, async ({ page }) => {
22+
await installMockGateway(page, {
23+
methodResponses: {
24+
"talk.catalog": videoTalkCatalog("openai"),
25+
"talk.client.create": {
26+
provider: "openai",
27+
voiceSessionId: "voice-microphone-access-e2e",
28+
transport: "webrtc",
29+
clientSecret: "test-client-secret",
30+
},
31+
},
32+
});
33+
await installMicrophoneLossWebRtcFixture(page);
34+
await page.addInitScript(() => {
35+
const getUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
36+
let release = () => {};
37+
const permission = new Promise<void>((resolve) => {
38+
release = resolve;
39+
});
40+
const proof = { requested: false, release: () => release() };
41+
Object.defineProperty(window, "openclawMicrophoneAccessE2e", { value: proof });
42+
navigator.mediaDevices.getUserMedia = (constraints) => {
43+
proof.requested = true;
44+
return permission.then(() => getUserMedia(constraints));
45+
};
46+
});
47+
await page.goto(`${suite.server.baseUrl}chat`);
48+
await page.getByRole("button", { name: "Start voice input" }).click();
49+
await expect
50+
.poll(() =>
51+
page.evaluate(
52+
() =>
53+
(window as Window & { openclawMicrophoneAccessE2e?: { requested: boolean } })
54+
.openclawMicrophoneAccessE2e?.requested,
55+
),
56+
)
57+
.toBe(true);
58+
await captureMicrophoneLossProof(page, "microphone-access-pending.png");
59+
const guidance = page.locator('.agent-chat__talk-status[role="status"]');
60+
await expect
61+
.poll(() => guidance.allTextContents())
62+
.toEqual([
63+
expect.stringContaining(
64+
"Waiting for microphone access. Bring this tab to the foreground and allow access if prompted.",
65+
),
66+
]);
67+
await expect.poll(() => guidance.isVisible()).toBe(true);
68+
await page.evaluate(() =>
69+
(
70+
window as Window & { openclawMicrophoneAccessE2e?: { release: () => void } }
71+
).openclawMicrophoneAccessE2e?.release(),
72+
);
73+
await expect
74+
.poll(() => page.locator('.agent-chat__voice-activity[data-status="listening"]').count())
75+
.toBe(1);
76+
await expect.poll(() => guidance.count()).toBe(0);
77+
await captureMicrophoneLossProof(page, "microphone-access-ready.png");
78+
await page.getByRole("button", { name: "Stop voice input" }).click();
79+
});
80+
});
81+
2082
it("surfaces microphone loss and closes native browser call resources", async () => {
2183
await suite.withPage({ permissions: ["microphone"] }, async ({ page }) => {
2284
const gateway = await installMockGateway(page, {

‎ui/src/i18n/locales/en.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6293,6 +6293,8 @@ export const en: TranslationMap = {
62936293
cameraPreview: "Camera preview",
62946294
dismissVoiceInputError: "Dismiss voice input error",
62956295
microphoneAccessFailed: "Unable to access microphone inputs.",
6296+
microphoneAccessPending:
6297+
"Waiting for microphone access. Bring this tab to the foreground and allow access if prompted.",
62966298
microphoneBusy: "Microphone inputs are busy or unavailable to the browser.",
62976299
microphoneStopped: "Microphone input stopped. Choose an available input and start again.",
62986300
microphoneFallback: "Microphone {number}",
@@ -6320,7 +6322,6 @@ export const en: TranslationMap = {
63206322
"Hold until dictation starts, then release and keep speaking. Tap Stop to insert the transcript.",
63216323
dictationAudioUnsupported: "The Gateway returned an unsupported dictation audio format.",
63226324
dictationBrowserAudioUnsupported: "This browser cannot capture dictation audio at 8 kHz.",
6323-
dictationConnecting: "Starting dictation…",
63246325
dictationDisconnected: "Dictation stopped because the Gateway disconnected.",
63256326
dictationFailed: "Dictation failed.",
63266327
dictationInterruptedRecovery:
@@ -6369,6 +6370,7 @@ export const en: TranslationMap = {
63696370
},
63706371
voice: {
63716372
asking: "Asking OpenClaw...",
6373+
preparing: "Preparing voice session...",
63726374
connecting: "Connecting voice input...",
63736375
listening: "Listening...",
63746376
},

‎ui/src/pages/chat/chat-composer.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,49 @@ afterEach(async () => {
127127
});
128128

129129
describe("renderChatComposer controls", () => {
130+
it("shows actionable connecting guidance in a visible status region", () => {
131+
const detail =
132+
"Waiting for microphone access. Bring this tab to the foreground and allow access if prompted.";
133+
const { container } = renderComposer({
134+
realtimeTalkActive: true,
135+
realtimeTalkStatus: "connecting",
136+
realtimeTalkDetail: detail,
137+
onToggleRealtimeTalk: vi.fn(),
138+
});
139+
const pending = container.querySelector('.agent-chat__talk-status[role="status"]');
140+
expect(pending?.textContent).toContain(detail);
141+
expect(pending?.closest(".sr-only")).toBeNull();
142+
expect(container.querySelector('[role="alert"]')).toBeNull();
143+
expect(button(container, t("chat.composer.stopVoiceInput")).disabled).toBe(false);
144+
});
145+
146+
it("shows the same microphone guidance while dictation waits for access", async () => {
147+
vi.useFakeTimers();
148+
openMicrophoneMock.mockReturnValue(new Promise(() => {}));
149+
const container = document.createElement("div");
150+
document.body.append(container);
151+
const composerProps = props({
152+
gatewayClient: {
153+
request: vi.fn(async () => ({ transcription: { ready: true } })),
154+
} as unknown as GatewayBrowserClient,
155+
onToggleRealtimeTalk: vi.fn(),
156+
});
157+
const draw = () => render(renderChatComposer(composerProps), container);
158+
composerProps.onRequestUpdate = draw;
159+
draw();
160+
await vi.advanceTimersByTimeAsync(0);
161+
button(container, t("chat.composer.startVoiceInput")).dispatchEvent(
162+
dictationPointer("pointerdown", 15),
163+
);
164+
await vi.advanceTimersByTimeAsync(800);
165+
expect(
166+
container.querySelector('.agent-chat__talk-status[role="status"]')?.textContent,
167+
).toContain(
168+
"Waiting for microphone access. Bring this tab to the foreground and allow access if prompted.",
169+
);
170+
expect(container.querySelector(".agent-chat__dictation-phase")).toBeNull();
171+
});
172+
130173
it("labels the message input independently of its placeholder", () => {
131174
const { container } = renderComposer();
132175
const textarea = container.querySelector<HTMLTextAreaElement>("textarea");

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,7 +3570,7 @@ describe("chat voice controls", () => {
35703570
["connecting", "Connecting voice input..."],
35713571
["listening", "Listening..."],
35723572
["thinking", "Asking OpenClaw..."],
3573-
] as const)("renders %s voice activity without visible status copy", (status, label) => {
3573+
] as const)("renders %s voice activity with the appropriate status region", (status, label) => {
35743574
const inputLevel = new RealtimeTalkLevelSignal();
35753575
inputLevel.set(0.64);
35763576
const container = renderChatView({
@@ -3587,11 +3587,17 @@ describe("chat voice controls", () => {
35873587
expect(visualizer?.getAttribute("data-source")).toBe("microphone");
35883588
expect(visualizer?.getAttribute("aria-hidden")).toBe("true");
35893589
expect(visualizer?.querySelectorAll(".agent-chat__voice-activity-bar")).toHaveLength(7);
3590-
const statusRegion = container.querySelector('[role="status"].agent-chat__voice-status');
3590+
const statusRegion = container.querySelector(
3591+
status === "connecting"
3592+
? '[role="status"].agent-chat__talk-status'
3593+
: '[role="status"].agent-chat__voice-status',
3594+
);
35913595
expect(statusRegion?.getAttribute("aria-live")).toBe("polite");
35923596
expect(statusRegion?.getAttribute("aria-atomic")).toBe("true");
35933597
expect(statusRegion?.textContent?.trim()).toBe(label);
3594-
expect(container.querySelector(".agent-chat__talk-status")).toBeNull();
3598+
if (status !== "connecting") {
3599+
expect(container.querySelector(".agent-chat__talk-status")).toBeNull();
3600+
}
35953601
});
35963602

35973603
it("keeps the stop control without a live meter when a running session errors", () => {

‎ui/src/pages/chat/components/chat-composer-controls.ts‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
} from "../realtime-talk-input.ts";
1515
import type { RealtimeTalkLevelSignal } from "../realtime-talk-level.ts";
1616
import type { RealtimeTalkStatus } from "../realtime-talk.ts";
17-
import { renderMicrophoneActivity, voiceStatusLabel } from "./chat-voice-activity.ts";
17+
import {
18+
renderChatVoiceStatus,
19+
renderMicrophoneActivity,
20+
voiceStatusLabel,
21+
} from "./chat-voice-activity.ts";
1822

1923
export type ChatRunControlsProps = {
2024
canAbort: boolean;
@@ -369,13 +373,13 @@ export function renderComposerDictationSendAction(
369373
return nothing;
370374
}
371375
return html`
372-
<span class="sr-only" role="status" aria-live="polite" aria-atomic="true"
373-
>${dictation.finalizing
374-
? t("chat.composer.dictationFinalizing")
375-
: dictation.connecting
376-
? t("chat.composer.dictationConnecting")
377-
: t("chat.composer.dictationListening")}</span
378-
>
376+
${dictation.connecting
377+
? nothing
378+
: html`<span class="sr-only" role="status" aria-live="polite" aria-atomic="true"
379+
>${dictation.finalizing
380+
? t("chat.composer.dictationFinalizing")
381+
: t("chat.composer.dictationListening")}</span
382+
>`}
379383
<openclaw-tooltip .content=${t("chat.runControls.send")}>
380384
<button
381385
class="chat-send-btn chat-send-btn--send chat-send-btn--dictation-commit"
@@ -401,7 +405,13 @@ export function renderComposerDictationStatus(dictation?: ComposerDictationContr
401405
if (!dictation?.active) {
402406
return nothing;
403407
}
404-
const listening = !dictation.connecting && !dictation.finalizing;
408+
if (dictation.connecting) {
409+
return renderChatVoiceStatus({
410+
status: "connecting",
411+
detail: t("chat.composer.microphoneAccessPending"),
412+
});
413+
}
414+
const listening = !dictation.finalizing;
405415
return html`
406416
<div class="agent-chat__composer-status-stack">
407417
<div
@@ -412,11 +422,9 @@ export function renderComposerDictationStatus(dictation?: ComposerDictationContr
412422
? " agent-chat__dictation-phase--listening"
413423
: ""}"
414424
>
415-
${dictation.connecting
416-
? t("chat.composer.dictationConnecting")
417-
: dictation.finalizing
418-
? t("chat.composer.dictationFinalizing")
419-
: t("chat.composer.dictationListening")}
425+
${dictation.finalizing
426+
? t("chat.composer.dictationFinalizing")
427+
: t("chat.composer.dictationListening")}
420428
</span>
421429
</div>
422430
</div>
@@ -606,7 +614,7 @@ export function renderChatPrimaryActions(props: ChatRunControlsProps) {
606614
</openclaw-tooltip>
607615
${props.microphonePicker}
608616
</span>
609-
${voiceErrored
617+
${voiceErrored || props.voiceStatus === "connecting"
610618
? nothing
611619
: html`
612620
<span

‎ui/src/pages/chat/components/chat-composer-view.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
restorePointerOpenedChatComposerTrigger,
5151
} from "./chat-picker-overlay.ts";
5252
import type { createGatewayQuestionPanelProps } from "./chat-question-card.ts";
53-
import { renderChatVoiceError } from "./chat-voice-activity.ts";
53+
import { renderChatVoiceStatus } from "./chat-voice-activity.ts";
5454

5555
type ChatComposerViewContext = {
5656
props: ChatComposerProps;
@@ -183,21 +183,15 @@ export function renderChatComposerView(context: ChatComposerViewContext) {
183183
state.capabilityMenuView = "root";
184184
}
185185
const disabledReasonId = paneDomId(props.paneId, "disabled-reason");
186-
const voiceError = showComposerInput
187-
? renderChatVoiceError({
186+
const composerAlerts = showComposerInput
187+
? renderChatVoiceStatus({
188188
status: props.realtimeTalkCameraError ? "error" : props.realtimeTalkStatus,
189189
detail: props.realtimeTalkDetail,
190190
onDismissError: props.realtimeTalkCameraError
191191
? undefined
192192
: props.onDismissRealtimeTalkError,
193193
})
194194
: nothing;
195-
const composerAlerts =
196-
voiceError !== nothing
197-
? html`<div class="agent-chat__composer-errors agent-chat__composer-errors--standalone">
198-
${voiceError}
199-
</div>`
200-
: nothing;
201195
const offlineText = props.offline
202196
? props.queuedOutboxCount
203197
? t("chat.composer.offlineQueuedHint", { count: String(props.queuedOutboxCount) })

‎ui/src/pages/chat/components/chat-voice-activity.ts‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,48 @@ export function renderMicrophoneActivity(props: MicrophoneActivityProps): Templa
141141
`;
142142
}
143143

144-
type ChatVoiceErrorProps = {
144+
type ChatVoiceStatusProps = {
145145
status?: RealtimeTalkStatus;
146146
detail?: string | null;
147147
onDismissError?: () => void;
148148
};
149149

150-
export function renderChatVoiceError(props: ChatVoiceErrorProps): TemplateResult | typeof nothing {
150+
export function renderChatVoiceStatus(
151+
props: ChatVoiceStatusProps,
152+
): TemplateResult | typeof nothing {
153+
if (props.status === "connecting") {
154+
return html`<div
155+
class="callout agent-chat__talk-status"
156+
role="status"
157+
aria-live="polite"
158+
aria-atomic="true"
159+
>
160+
${voiceStatusLabel(props.status, props.detail)}
161+
</div>`;
162+
}
151163
if (props.status !== "error" || !props.detail) {
152164
return nothing;
153165
}
154166
return html`
155-
<div class="agent-chat__composer-error agent-chat__talk-status" role="alert">
156-
<span class="agent-chat__composer-error-icon" aria-hidden="true">${icons.alertTriangle}</span>
157-
<span class="agent-chat__talk-status-text">${props.detail}</span>
158-
${props.onDismissError
159-
? html`
160-
<button
161-
class="callout__dismiss"
162-
type="button"
163-
@click=${props.onDismissError}
164-
aria-label=${t("chat.composer.dismissVoiceInputError")}
165-
>
166-
${icons.x}
167-
</button>
168-
`
169-
: nothing}
167+
<div class="agent-chat__composer-errors agent-chat__composer-errors--standalone">
168+
<div class="agent-chat__composer-error agent-chat__talk-status" role="alert">
169+
<span class="agent-chat__composer-error-icon" aria-hidden="true"
170+
>${icons.alertTriangle}</span
171+
>
172+
<span class="agent-chat__talk-status-text">${props.detail}</span>
173+
${props.onDismissError
174+
? html`
175+
<button
176+
class="callout__dismiss"
177+
type="button"
178+
@click=${props.onDismissError}
179+
aria-label=${t("chat.composer.dismissVoiceInputError")}
180+
>
181+
${icons.x}
182+
</button>
183+
`
184+
: nothing}
185+
</div>
170186
</div>
171187
`;
172188
}

0 commit comments

Comments
 (0)