Sound check on the phone page (probe for issue #1); timing logs for name checks and previews; 0.4.1
- apps/even-client: a collapsed "Sound check" on the phone page. Finds out whether the page may play sound in the Even app, without a touch, in the background, and which outputs it can see. Plays only on a button press; sends nothing to the bridge. - services/bridge: wake.checked (every name check) and preview.done log the clip length and the duration, never the words. - tests: hands free after a recording in Agents with menu, wake and preview all on; the log lines carry only the fields above. - docs: 0.4.0 rollout and Dan's device report; security 3c, 3e, 3f; 0005 records that the Round 20 reading of "agent sub-app" was wrong (not changed here). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Controller, Snapshot } from '../core/controller.ts';
|
||||
import { BridgeApiError, BridgeNetworkError, normalizeBridgeUrl } from '../net/bridgeClient.ts';
|
||||
import { mountSoundCheck } from './soundCheck.ts';
|
||||
|
||||
/**
|
||||
* Phone-side page: pairing, status, diagnostics, typed input and disconnect.
|
||||
@@ -141,7 +142,7 @@ export function mountPhoneUi(root: HTMLElement, controller: Controller, defaults
|
||||
logView,
|
||||
]);
|
||||
|
||||
root.append(el('h1', { textContent: 'Hermeven' }), message, pairing, status, conversation, diagnostics);
|
||||
root.append(el('h1', { textContent: 'Hermeven' }), message, pairing, status, conversation, mountSoundCheck(document, window), diagnostics);
|
||||
|
||||
const rows = (list: HTMLElement, entries: Array<[string, string]>) => {
|
||||
list.replaceChildren(...entries.flatMap(([k, v]) => [el('dt', { textContent: k }), el('dd', { textContent: v })]));
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* Sound check: finds out what this page is allowed to do with sound inside the Even app, before
|
||||
* spoken answers are designed around it (issue #1). It answers four questions on a real phone:
|
||||
*
|
||||
* 1. Can the page make sound at all, and does Android send it to the earbuds or the car?
|
||||
* 2. Can it make sound without anyone touching the phone (a question asked from the glasses)?
|
||||
* 3. Does sound still play a while later, with the phone locked or the Even app in the background?
|
||||
* 4. Can the page tell which sound outputs are connected (so it stays quiet on a bare phone)?
|
||||
*
|
||||
* Nothing here talks to the bridge or to any agent, nothing is recorded, and nothing plays
|
||||
* unless a button on this page is pressed. Results are only shown on this page.
|
||||
*
|
||||
* NOT device-tested: this exists to be run on the device.
|
||||
*/
|
||||
type AudioContextCtor = typeof AudioContext;
|
||||
|
||||
function contextCtor(win: Window): AudioContextCtor | null {
|
||||
const w = win as unknown as { AudioContext?: AudioContextCtor; webkitAudioContext?: AudioContextCtor };
|
||||
return w.AudioContext ?? w.webkitAudioContext ?? null;
|
||||
}
|
||||
|
||||
function node<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, text = '', className = ''): HTMLElementTagNameMap[K] {
|
||||
const n = doc.createElement(tag);
|
||||
if (text) n.textContent = text;
|
||||
if (className) n.className = className;
|
||||
return n;
|
||||
}
|
||||
|
||||
const DELAY_SECONDS = 20;
|
||||
|
||||
export function mountSoundCheck(doc: Document, win: Window): HTMLElement {
|
||||
const results = new Map<string, string>();
|
||||
const list = node(doc, 'dl');
|
||||
const show = (key: string, value: string) => {
|
||||
results.set(key, value);
|
||||
list.replaceChildren(...[...results].flatMap(([k, v]) => [node(doc, 'dt', k), node(doc, 'dd', v)]));
|
||||
};
|
||||
const reason = (err: unknown) => (err instanceof Error ? `${err.name}: ${err.message}`.slice(0, 120) : 'unknown error');
|
||||
|
||||
const Ctor = contextCtor(win);
|
||||
let context: AudioContext | null = null;
|
||||
const getContext = (): AudioContext | null => {
|
||||
if (!Ctor) return null;
|
||||
try {
|
||||
context ??= new Ctor();
|
||||
} catch (err) {
|
||||
show('Sound engine', `could not start (${reason(err)})`);
|
||||
return null;
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
/** Two short notes. Resolves with whether the sound engine was actually running. */
|
||||
async function tone(): Promise<string> {
|
||||
const ctx = getContext();
|
||||
if (!ctx) return 'no sound engine in this page';
|
||||
try {
|
||||
await Promise.race([ctx.resume(), new Promise((r) => win.setTimeout(r, 800))]);
|
||||
} catch (err) {
|
||||
return `blocked (${reason(err)})`;
|
||||
}
|
||||
if (ctx.state !== 'running') return `blocked (sound engine is ${ctx.state})`;
|
||||
const gain = ctx.createGain();
|
||||
gain.gain.value = 0.2;
|
||||
gain.connect(ctx.destination);
|
||||
[660, 880].forEach((frequency, i) => {
|
||||
const osc = ctx.createOscillator();
|
||||
osc.frequency.value = frequency;
|
||||
osc.connect(gain);
|
||||
osc.start(ctx.currentTime + i * 0.45);
|
||||
osc.stop(ctx.currentTime + i * 0.45 + 0.35);
|
||||
});
|
||||
return 'played';
|
||||
}
|
||||
const stamp = () => new Date().toLocaleTimeString();
|
||||
|
||||
// 2. Without a touch: asked once when the page opens. Silent; it only reads the engine's state.
|
||||
void (async () => {
|
||||
const ctx = getContext();
|
||||
if (!ctx) {
|
||||
show('Without touching the phone', 'no sound engine in this page');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await Promise.race([ctx.resume(), new Promise((r) => win.setTimeout(r, 800))]);
|
||||
} catch {
|
||||
// The state below says what happened.
|
||||
}
|
||||
show('Without touching the phone', ctx.state === 'running' ? 'allowed' : `not allowed until a button here is pressed (${ctx.state})`);
|
||||
})();
|
||||
|
||||
// 1. A sound now.
|
||||
const playButton = node(doc, 'button', 'Play test sound', 'secondary');
|
||||
playButton.type = 'button';
|
||||
playButton.addEventListener('click', () => {
|
||||
void tone().then((outcome) => show('Test sound', `${outcome} at ${stamp()}`));
|
||||
});
|
||||
|
||||
// 3. A sound later, with nobody touching anything at that moment.
|
||||
const laterButton = node(doc, 'button', `Play again in ${DELAY_SECONDS} s`, 'secondary');
|
||||
laterButton.type = 'button';
|
||||
laterButton.addEventListener('click', () => {
|
||||
laterButton.disabled = true;
|
||||
show('Delayed sound', `waiting since ${stamp()}; lock the phone or leave the app now`);
|
||||
const due = Date.now() + DELAY_SECONDS * 1000;
|
||||
win.setTimeout(() => {
|
||||
const lateMs = Date.now() - due;
|
||||
void tone().then((outcome) => {
|
||||
show('Delayed sound', `${outcome} at ${stamp()}${lateMs > 1500 ? `, ${Math.round(lateMs / 1000)} s late` : ''}`);
|
||||
laterButton.disabled = false;
|
||||
});
|
||||
}, DELAY_SECONDS * 1000);
|
||||
});
|
||||
|
||||
// The phone's own voice, as a free fallback to a paid one.
|
||||
const speakButton = node(doc, 'button', 'Speak with the phone’s voice', 'secondary');
|
||||
speakButton.type = 'button';
|
||||
speakButton.addEventListener('click', () => {
|
||||
const synth = win.speechSynthesis;
|
||||
const Utterance = (win as unknown as { SpeechSynthesisUtterance?: typeof SpeechSynthesisUtterance }).SpeechSynthesisUtterance;
|
||||
if (!synth || !Utterance) {
|
||||
show('Phone voice', 'not available in this page');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const utterance = new Utterance('This is the Hermeven sound check.');
|
||||
utterance.onend = () => show('Phone voice', `spoke at ${stamp()} (${synth.getVoices().length} voices)`);
|
||||
utterance.onerror = (event) => show('Phone voice', `failed (${event.error})`);
|
||||
show('Phone voice', 'asked to speak…');
|
||||
synth.speak(utterance);
|
||||
} catch (err) {
|
||||
show('Phone voice', `failed (${reason(err)})`);
|
||||
}
|
||||
});
|
||||
|
||||
// 4. What the page can see of the sound outputs.
|
||||
async function outputs(): Promise<void> {
|
||||
const media = win.navigator.mediaDevices;
|
||||
if (!media?.enumerateDevices) {
|
||||
show('Outputs this page can see', 'none: the page is not told about sound devices');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const devices = await media.enumerateDevices();
|
||||
const out = devices.filter((d) => d.kind === 'audiooutput');
|
||||
const named = out.map((d) => d.label).filter(Boolean);
|
||||
show(
|
||||
'Outputs this page can see',
|
||||
out.length === 0
|
||||
? `none (of ${devices.length} devices listed)`
|
||||
: named.length
|
||||
? `${out.length}: ${named.join(' · ').slice(0, 300)}`
|
||||
: `${out.length}, without names`,
|
||||
);
|
||||
} catch (err) {
|
||||
show('Outputs this page can see', `could not ask (${reason(err)})`);
|
||||
}
|
||||
}
|
||||
const outputsButton = node(doc, 'button', 'List outputs', 'secondary');
|
||||
outputsButton.type = 'button';
|
||||
outputsButton.addEventListener('click', () => void outputs());
|
||||
try {
|
||||
win.navigator.mediaDevices?.addEventListener?.('devicechange', () => {
|
||||
show('Output change noticed', stamp());
|
||||
void outputs();
|
||||
});
|
||||
} catch {
|
||||
// Not supported here: the button still works.
|
||||
}
|
||||
void outputs();
|
||||
|
||||
const row = node(doc, 'div', '', 'row');
|
||||
row.append(playButton, laterButton, speakButton, outputsButton);
|
||||
const details = node(doc, 'details');
|
||||
details.append(
|
||||
node(doc, 'summary', 'Sound check'),
|
||||
node(
|
||||
doc,
|
||||
'p',
|
||||
'For finding out whether answers can be spoken through your earbuds or car. Nothing is recorded or sent anywhere, and nothing plays unless you press a button here.',
|
||||
'hint',
|
||||
),
|
||||
row,
|
||||
list,
|
||||
);
|
||||
return details;
|
||||
}
|
||||
Reference in New Issue
Block a user