Skip to content

Commit b765944

Browse files
steipeteampagent
andauthored
1 parent 20b0ed4 commit b765944

3 files changed

Lines changed: 66 additions & 9 deletions

File tree

‎ui/src/e2e/browser-talk-start-stop.e2e.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,44 @@ suite.define(() => {
10141014
});
10151015
});
10161016

1017+
it("shows actionable guidance when Talk microphone permission is blocked", async () => {
1018+
await suite.withPage(undefined, async ({ page }) => {
1019+
const relaySessionId = "relay-blocked-microphone-e2e";
1020+
const gateway = await installMockGateway(page, {
1021+
methodResponses: {
1022+
"talk.client.create": {
1023+
provider: "openai",
1024+
transport: "gateway-relay",
1025+
relaySessionId,
1026+
audio: {
1027+
inputEncoding: "pcm16",
1028+
inputSampleRateHz: 16_000,
1029+
outputEncoding: "pcm16",
1030+
outputSampleRateHz: 24_000,
1031+
},
1032+
},
1033+
"talk.session.close": {},
1034+
},
1035+
});
1036+
await installBlockedMicrophoneFixture(page);
1037+
1038+
await page.setViewportSize({ width: 320, height: 720 });
1039+
await page.goto(`${suite.server.baseUrl}chat`);
1040+
await page.getByRole("button", { name: "Start voice input" }).click();
1041+
await gateway.waitForRequest("talk.client.create");
1042+
1043+
await expect
1044+
.poll(() => page.getByRole("alert").locator(".agent-chat__talk-status-text").textContent())
1045+
.toBe("Microphone access is blocked. Allow it in browser site settings to list inputs.");
1046+
await expect
1047+
.poll(() => gateway.getRequests("talk.session.close").then((requests) => requests.length))
1048+
.toBe(1);
1049+
await expect
1050+
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
1051+
.toBe(true);
1052+
});
1053+
});
1054+
10171055
it("keeps blocked microphone guidance readable in a narrow viewport", async () => {
10181056
await suite.withPage(undefined, async ({ page }) => {
10191057
await installMockGateway(page);

‎ui/src/pages/chat/realtime-talk-input.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ describe("realtime Talk microphone inputs", () => {
134134
});
135135
});
136136

137+
it("reports microphone permission denial with actionable guidance", async () => {
138+
const getUserMedia = vi.fn().mockRejectedValue(new DOMException("denied", "NotAllowedError"));
139+
vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });
140+
141+
await expect(openRealtimeTalkInput(undefined)).rejects.toThrow(
142+
"Microphone access is blocked. Allow it in browser site settings to list inputs.",
143+
);
144+
});
145+
137146
it("does not silently fall back when the selected microphone is unavailable", async () => {
138147
const getUserMedia = vi.fn(async () => {
139148
throw new DOMException("missing", "OverconstrainedError");

‎ui/src/pages/chat/realtime-talk-input.ts‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,17 @@ export async function openRealtimeTalkInput(
221221
if (!devices?.getUserMedia) {
222222
throw new Error(t("chat.composer.realtimeTalkRequiresMicrophone"));
223223
}
224-
let audio: MediaStream;
224+
let acquisition: { stream: MediaStream } | { failure: string };
225225
try {
226-
audio = await awaitRealtimeTalkMediaRequest(
227-
() =>
228-
devices.getUserMedia({
229-
audio: realtimeTalkAudioConstraints(inputDeviceId),
230-
}),
231-
options.signal,
232-
);
226+
acquisition = {
227+
stream: await awaitRealtimeTalkMediaRequest(
228+
() =>
229+
devices.getUserMedia({
230+
audio: realtimeTalkAudioConstraints(inputDeviceId),
231+
}),
232+
options.signal,
233+
),
234+
};
233235
} catch (error) {
234236
if (
235237
inputDeviceId?.trim() &&
@@ -238,8 +240,16 @@ export async function openRealtimeTalkInput(
238240
) {
239241
throw new Error(t("chat.composer.selectedMicrophoneUnavailable"), { cause: error });
240242
}
241-
throw error;
243+
if (error instanceof DOMException && error.name !== "AbortError") {
244+
acquisition = { failure: describeRealtimeTalkInputError(error) };
245+
} else {
246+
throw error;
247+
}
248+
}
249+
if ("failure" in acquisition) {
250+
throw new Error(acquisition.failure);
242251
}
252+
const { stream: audio } = acquisition;
243253
if (options.signal?.aborted) {
244254
audio.getTracks().forEach((track) => track.stop());
245255
throw realtimeTalkAbortReason(options.signal);

0 commit comments

Comments
 (0)