diff --git a/apps/even-client/src/core/controller.ts b/apps/even-client/src/core/controller.ts index 5e4ac9c..732efc0 100644 --- a/apps/even-client/src/core/controller.ts +++ b/apps/even-client/src/core/controller.ts @@ -41,6 +41,8 @@ export interface Snapshot { pairingExpiresAt: string; status: DeviceStatusResponse | null; hudReady: boolean; + /** What the glasses runtime has delivered, by type only (empty when the device cannot say). */ + glassesInput: string; /** Last settled turn, complete and untruncated, for the phone. */ lastTurn: TurnResult | null; log: DiagEntry[]; @@ -128,6 +130,9 @@ export class Controller { this.note('hud', this.hudReady ? 'HUD page created' : 'HUD page was refused by the host'); this.unsubscribers.push( this.device.onEvent((event) => this.onDeviceEvent(event)), + // Refresh the phone's Diagnostics when the glasses deliver something, even if it changes + // no state (an ignored or unrecognised event is exactly what needs to be visible). + this.device.onInputActivity?.(() => this.emit()) ?? (() => undefined), this.device.onConnection((connected) => { this.note('glasses', connected ? 'connected' : 'disconnected'); this.dispatch({ type: 'glasses_status', connected }); @@ -181,6 +186,7 @@ export class Controller { pairingExpiresAt: this.stored?.pairingExpiresAt ?? '', status: this.status, hudReady: this.hudReady, + glassesInput: this.device.inputSummary?.() ?? '', lastTurn: this.lastTurn, log: [...this.log], }; diff --git a/apps/even-client/src/device/evenAdapter.ts b/apps/even-client/src/device/evenAdapter.ts index acae165..a575613 100644 --- a/apps/even-client/src/device/evenAdapter.ts +++ b/apps/even-client/src/device/evenAdapter.ts @@ -170,10 +170,52 @@ export class EvenDevice implements DevicePort { onEvent(listener: (event: DeviceEvent) => void): () => void { return this.bridge.onEvenHubEvent((event) => { - for (const normalized of normalizeEvent(event as RawEvenHubEvent)) listener(normalized); + const normalized = normalizeEvent(event as RawEvenHubEvent); + this.recordInput(event as RawEvenHubEvent, normalized); + for (const one of normalized) listener(one); }); } + // ---- input diagnostics: what the host has delivered, by type only ------------------- + private input = { gestures: 0, audioFrames: 0, unrecognised: 0, last: 'none yet', lastAt: 0 }; + private readonly inputListeners = new Set<() => void>(); + + private recordInput(raw: RawEvenHubEvent, normalized: DeviceEvent[]): void { + const audioOnly = normalized.length > 0 && normalized.every((e) => e.type === 'audio'); + if (audioOnly) { + // Counted, not announced: frames arrive ten times a second. + this.input.audioFrames += 1; + return; + } + // Envelope names and numeric type codes only. Never payload content. + const envelopes = (['sysEvent', 'textEvent', 'listEvent', 'menuItemClickEvent'] as const) + .filter((key) => raw[key] !== undefined) + .map((key) => { + const env = raw[key] as { eventType?: number; eventSource?: number; itemID?: number }; + const parts = [`type=${env.eventType ?? 'none'}`]; + if (env.eventSource !== undefined) parts.push(`source=${env.eventSource}`); + if (env.itemID !== undefined) parts.push(`item=${env.itemID}`); + return `${key}(${parts.join(',')})`; + }); + const meaning = normalized.filter((e) => e.type !== 'audio').map((e) => e.type); + if (meaning.length) this.input.gestures += 1; + else this.input.unrecognised += 1; + this.input.last = `${envelopes.join('+') || 'no known envelope'} -> ${meaning.join(',') || 'ignored'}`; + this.input.lastAt = Date.now(); + for (const l of this.inputListeners) l(); + } + + inputSummary(): string { + const { gestures, audioFrames, unrecognised, last, lastAt } = this.input; + const when = lastAt ? ` at ${new Date(lastAt).toISOString().slice(11, 19)} UTC` : ''; + return `${gestures} gesture/lifecycle event(s), ${unrecognised} ignored, ${audioFrames} audio frame(s); last: ${last}${when}`; + } + + onInputActivity(listener: () => void): () => void { + this.inputListeners.add(listener); + return () => this.inputListeners.delete(listener); + } + onConnection(listener: (connected: boolean) => void): () => void { return this.bridge.onDeviceStatusChanged((status) => { if (status.connectType === DeviceConnectType.Connected) listener(true); diff --git a/apps/even-client/src/device/port.ts b/apps/even-client/src/device/port.ts index d2cb6a6..12f093a 100644 --- a/apps/even-client/src/device/port.ts +++ b/apps/even-client/src/device/port.ts @@ -27,4 +27,11 @@ export interface DevicePort { * land later, so `false` is "not confirmed", never "not written" and never "written". */ storageSet(key: string, value: string): Promise; + /** + * Optional, for the phone's Diagnostics only: a one-line summary of what the glasses runtime + * has delivered (counts and event types; never audio or any content). + */ + inputSummary?(): string; + /** Optional: called whenever `inputSummary()` would change. */ + onInputActivity?(listener: () => void): () => void; } diff --git a/apps/even-client/src/ui/phone.ts b/apps/even-client/src/ui/phone.ts index fb04cca..02caa31 100644 --- a/apps/even-client/src/ui/phone.ts +++ b/apps/even-client/src/ui/phone.ts @@ -198,6 +198,7 @@ export function mountPhoneUi(root: HTMLElement, controller: Controller, defaults ['Page origin', location.origin], ['Browser', navigator.userAgent], ['HUD page', s.hudReady ? 'created' : 'not created'], + ['Glasses input', s.glassesInput || 'not available in this mode'], ['Device id', s.deviceId || 'none'], ['Conversation id', s.state.conversationId ?? 'none'], ['Request id', s.state.requestId ?? 'none'], diff --git a/tests/integration/entryPoint.test.ts b/tests/integration/entryPoint.test.ts index c9ec2d7..8c8cc9f 100644 --- a/tests/integration/entryPoint.test.ts +++ b/tests/integration/entryPoint.test.ts @@ -179,6 +179,36 @@ describe('start-up when a callable Even host appears during the wait', () => { expect(diag['HUD page']).toBe('created'); }); + it('Diagnostics shows what the glasses deliver, by type only: a tap is visible, an unknown event is visible as ignored, audio is only counted', async () => { + const even = fakeEvenHost(); + (window as any).flutter_inappwebview = even.host; + booted = await boot(document, window); + expect(diagnostics()['Glasses input']).toContain('0 gesture/lifecycle event(s), 0 ignored, 0 audio frame(s); last: none yet'); + + // The Even app pushes events to the page through this SDK entry point. + const push = (type: string, jsonData: unknown) => (window as any)._listenEvenAppMessage({ type: 'listen_even_app_data', method: 'evenHubEvent', data: { type, jsonData } }); + push('sysEvent', { eventSource: 1 }); // a tap: no eventType on the wire + await wait(20); + const afterTap = diagnostics()['Glasses input']!; + expect(afterTap).toContain('1 gesture/lifecycle event(s)'); + expect(afterTap).toContain('sysEvent(type=none,source=1) -> tap'); + // The tap really drove the app: unpaired, so the state stays put, but it was delivered. + push('sysEvent', { eventType: 9, eventSource: 1 }); // long press: outside the contract + await wait(20); + const afterLongPress = diagnostics()['Glasses input']!; + expect(afterLongPress).toContain('1 ignored'); + expect(afterLongPress).toContain('sysEvent(type=9,source=1) -> ignored'); + push('audioEvent', { audioPcm: [1, 2, 3, 4] }); + await wait(20); + push('sysEvent', { eventType: 3 }); + await wait(20); + const afterAudio = diagnostics()['Glasses input']!; + expect(afterAudio).toContain('1 audio frame(s)'); + expect(afterAudio).toContain('-> double_tap'); + // Nothing from the audio payload appears anywhere in Diagnostics. + expect(JSON.stringify(diagnostics())).not.toContain('1,2,3,4'); + }); + it('a host present from the first instant is used without waiting out the timeout', async () => { const even = fakeEvenHost(); (window as any).flutter_inappwebview = even.host;