From e04a8a78f2efeb113c883ae608dec2edb93f2f54 Mon Sep 17 00:00:00 2001 From: masnwilliams <43387599+masnwilliams@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:30:31 +0000 Subject: [PATCH 1/6] Prompt for a tap when a phone refuses the live view's first play --- .../client/src/components/video.vue | 9 ++ .../client/tests/video-autoplay.test.ts | 123 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 images/chromium-headful/client/tests/video-autoplay.test.ts diff --git a/images/chromium-headful/client/src/components/video.vue b/images/chromium-headful/client/src/components/video.vue index ff26ee83..4882ed31 100644 --- a/images/chromium-headful/client/src/components/video.vue +++ b/images/chromium-headful/client/src/components/video.vue @@ -728,9 +728,11 @@ } catch (err: any) { // if it still fails, we're not playing anything this.$accessor.video.pause() + this.askForTapIfRefused(err) } } else { this.$accessor.video.pause() + this.askForTapIfRefused(err) } } } @@ -1204,6 +1206,13 @@ if (!document.hidden) this.resumeVideo() } + // iOS Safari in Low Power Mode refuses even a muted play() until a tap, so + // without a prompt the first load is a black box. Other rejections, such as + // an AbortError from a new stream replacing a pending play(), retry on their own. + askForTapIfRefused(err: any) { + if (this.is_touch_device && err?.name === 'NotAllowedError') this.videoBlocked = true + } + onTouchCancel() { this.gestures.touchCancel() } diff --git a/images/chromium-headful/client/tests/video-autoplay.test.ts b/images/chromium-headful/client/tests/video-autoplay.test.ts new file mode 100644 index 00000000..452566aa --- /dev/null +++ b/images/chromium-headful/client/tests/video-autoplay.test.ts @@ -0,0 +1,123 @@ +import { describe, expect, test } from 'bun:test' +import { readFileSync } from 'node:fs' +import { runInNewContext } from 'node:vm' +import ts from 'typescript' +import { parseComponent } from 'vue-template-compiler' + +// Load the real component methods without mounting its media player or child components. +const script = parseComponent(readFileSync(new URL('../src/components/video.vue', import.meta.url), 'utf8')).script! + .content +const compiled = ts.transpileModule(script, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020, experimentalDecorators: true }, +}).outputText + +function videoPrototype() { + const exports: { default?: { prototype: Record } } = {} + const noDecorator = () => () => undefined + runInNewContext(compiled, { + exports, + require: (name: string) => { + if (name === 'vue-property-decorator') { + return { + Vue: class {}, + Component: () => (type: unknown) => type, + Ref: noDecorator, + Watch: noDecorator, + Prop: noDecorator, + } + } + return {} + }, + }) + return exports.default!.prototype +} + +function refusal(name: string) { + return Object.assign(new Error(name), { name }) +} + +// The first play() after the stream loads, with the browser's answer to an +// unmuted and a muted play(): null plays, a string rejects with that error. +function firstLoad(options: { touch: boolean; unmuted: string | null; muted: string | null; startMuted?: boolean }) { + const store: string[] = [] + const video = { + paused: true, + muted: !!options.startMuted, + play() { + const error = this.muted ? options.muted : options.unmuted + if (error) return Promise.reject(refusal(error)) + this.paused = false + return Promise.resolve() + }, + } + const component = Object.create(videoPrototype(), { + is_touch_device: { get: () => options.touch }, + }) + Object.assign(component, { + _video: video, + isVideoSyncing: false, + videoBlocked: false, + $accessor: { + video: { + setMuted: (muted: boolean) => store.push(`muted ${muted}`), + pause: () => store.push('pause'), + }, + }, + }) + return { component, video, store, start: () => component.onPlayingChanged(true) } +} + +describe('first load autoplay', () => { + test('asks for a tap on a phone that refuses even a muted play', async () => { + // iOS Safari in Low Power Mode + const { component, video, store, start } = firstLoad({ + touch: true, + unmuted: 'NotAllowedError', + muted: 'NotAllowedError', + }) + await start() + expect(video.paused).toBe(true) + expect(store).toEqual(['muted true', 'pause']) + expect(component.videoBlocked).toBe(true) + }) + + test('asks for a tap when an already muted play is refused', async () => { + const { component, start } = firstLoad({ + touch: true, + unmuted: 'NotAllowedError', + muted: 'NotAllowedError', + startMuted: true, + }) + await start() + expect(component.videoBlocked).toBe(true) + }) + + test('plays muted without a prompt when only sound is refused', async () => { + // iOS and Android browsers outside Low Power Mode + const { component, video, store, start } = firstLoad({ touch: true, unmuted: 'NotAllowedError', muted: null }) + await start() + expect(video).toMatchObject({ paused: false, muted: true }) + expect(store).toEqual(['muted true']) + expect(component.videoBlocked).toBe(false) + }) + + test('plays with sound without a prompt when allowed', async () => { + const { component, video, store, start } = firstLoad({ touch: true, unmuted: null, muted: null }) + await start() + expect(video).toMatchObject({ paused: false, muted: false }) + expect(store).toEqual([]) + expect(component.videoBlocked).toBe(false) + }) + + test('shows no prompt for a play interrupted by a new stream', async () => { + const { component, start } = firstLoad({ touch: true, unmuted: 'AbortError', muted: 'AbortError' }) + await start() + expect(component.videoBlocked).toBe(false) + }) + + test('shows no prompt on a desktop, where the button cannot resume the video', async () => { + const { component, start } = firstLoad({ touch: false, unmuted: 'NotAllowedError', muted: 'NotAllowedError' }) + await start() + expect(component.videoBlocked).toBe(false) + }) +}) From 86e4a8fdeba87dd4e1a9df48a1925c511e70d146 Mon Sep 17 00:00:00 2001 From: masnwilliams <43387599+masnwilliams@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:40:20 +0000 Subject: [PATCH 2/6] Reconnect the live view after a dropped connection --- images/chromium-headful/client/src/app.vue | 6 +- .../client/src/components/disconnected.vue | 23 +- .../client/src/components/video.vue | 8 +- .../chromium-headful/client/src/neko/base.ts | 48 ++++- .../client/src/neko/events.ts | 2 + .../chromium-headful/client/src/neko/index.ts | 81 ++++++- .../client/src/store/index.ts | 6 + .../client/src/utils/reconnect.ts | 114 ++++++++++ .../client/tests/connect-bound.test.ts | 132 ++++++++++++ .../client/tests/reconnect.test.ts | 202 ++++++++++++++++++ .../client/tests/video-autoplay.test.ts | 15 ++ 11 files changed, 620 insertions(+), 17 deletions(-) create mode 100644 images/chromium-headful/client/src/utils/reconnect.ts create mode 100644 images/chromium-headful/client/tests/reconnect.test.ts diff --git a/images/chromium-headful/client/src/app.vue b/images/chromium-headful/client/src/app.vue index 0bcfdace..57c36601 100644 --- a/images/chromium-headful/client/src/app.vue +++ b/images/chromium-headful/client/src/app.vue @@ -34,7 +34,7 @@ - + -
+
- {{ $t('disconnected.message') }} + {{ reconnecting ? $t('connection.reconnecting') : $t('disconnected.message') }}
@@ -15,6 +15,19 @@ justify-content: center; align-items: center; + // the last frame stays visible underneath while the session is restored + &.reconnecting { + position: fixed; + top: 0; + left: 0; + z-index: 10; + background: rgba($color: #000, $alpha: 0.6); + + .message { + color: #fff; + } + } + .message-container { display: flex; justify-content: center; @@ -31,8 +44,10 @@ diff --git a/images/chromium-headful/client/src/components/video.vue b/images/chromium-headful/client/src/components/video.vue index 4882ed31..4ac46ce4 100644 --- a/images/chromium-headful/client/src/components/video.vue +++ b/images/chromium-headful/client/src/components/video.vue @@ -118,7 +118,7 @@
{{ touchNotice }}
0 + return coarse ? 'Tap to start live view' : 'Click to start live view' + } + get connecting() { return this.$accessor.connecting } diff --git a/images/chromium-headful/client/tests/video-autoplay.test.ts b/images/chromium-headful/client/tests/video-autoplay.test.ts index 3873a51c..145b0236 100644 --- a/images/chromium-headful/client/tests/video-autoplay.test.ts +++ b/images/chromium-headful/client/tests/video-autoplay.test.ts @@ -11,7 +11,7 @@ const compiled = ts.transpileModule(script, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020, experimentalDecorators: true }, }).outputText -function videoPrototype() { +function videoPrototype(globals: Record = {}) { const exports: { default?: { prototype: Record } } = {} const noDecorator = () => () => undefined runInNewContext(compiled, { @@ -28,6 +28,7 @@ function videoPrototype() { } return {} }, + ...globals, }) return exports.default!.prototype } @@ -136,3 +137,34 @@ describe('first load autoplay', () => { expect(component.videoBlocked).toBe(true) }) }) + +describe('start prompt', () => { + const template = parseComponent(readFileSync(new URL('../src/components/video.vue', import.meta.url), 'utf8')) + .template!.content + + function prompt(globals: Record) { + const proto = videoPrototype(globals) + return Object.getOwnPropertyDescriptor(proto, 'startPrompt')!.get!.call({}) + } + + test('asks for a tap on a coarse pointer', () => { + const matchMedia = (query: string) => ({ matches: query === '(pointer: coarse)' }) + expect(prompt({ window: { matchMedia }, navigator: {} })).toBe('Tap to start live view') + }) + + test('asks for a click on a fine pointer', () => { + const matchMedia = () => ({ matches: false }) + expect(prompt({ window: { matchMedia }, navigator: { maxTouchPoints: 5 } })).toBe('Click to start live view') + }) + + test('falls back to touch support without matchMedia', () => { + expect(prompt({ window: { ontouchstart: null }, navigator: {} })).toBe('Tap to start live view') + expect(prompt({ window: {}, navigator: { maxTouchPoints: 0 } })).toBe('Click to start live view') + }) + + test('the button reads and announces the same prompt', () => { + const button = template.slice(template.indexOf('class="touch-button video-resume"')) + expect(button.slice(0, button.indexOf(''))).toContain(':aria-label="startPrompt"') + expect(button.slice(0, button.indexOf(''))).toContain('{{ startPrompt }}') + }) +})