Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions images/chromium-headful/client/src/components/video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
@touchend.stop.prevent="resumeVideo"
@click.stop.prevent="resumeVideo"
>
Tap to resume video
Resume video
</button>
<neko-resolution ref="resolution" v-if="admin" />
<neko-clipboard
Expand Down Expand Up @@ -727,9 +727,11 @@
await this._video.play()
} catch (err: any) {
// if it still fails, we're not playing anything
this.videoBlocked = true
this.$accessor.video.pause()
}
} else {
this.videoBlocked = true
this.$accessor.video.pause()
}
}
Expand Down Expand Up @@ -1194,10 +1196,10 @@
this.gestures.touchEnd(e)
}

// A phone browser can stop the video with nothing left to restart it while
// input still reaches the remote, so touch input checks it each time.
// Desktop Safari can refuse even muted autoplay. The recovery button and
// visibility changes must be able to resume playback on every device.
resumeVideo() {
if (this.is_touch_device && this.playable) this.videoResume.resume()
if (this.playable) this.videoResume.resume()
}

resumeVideoWhenVisible() {
Expand Down
59 changes: 59 additions & 0 deletions images/chromium-headful/client/tests/video-autoplay.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { 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'
import { VideoResume } from '../src/utils/video-resume'

// Exercise the actual component's autoplay watcher and recovery button handler.
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
const exports: { default?: { prototype: Record<string, any> } } = {}
const noDecorator = () => () => undefined
runInNewContext(compiled, {
exports,
require: (name: string) => name === 'vue-property-decorator' ? {
Vue: class {},
Component: () => (type: unknown) => type,
Ref: noDecorator,
Watch: noDecorator,
Prop: noDecorator,
} : {},
})
const methods = exports.default!.prototype

for (const initiallyMuted of [false, true]) {
test(`desktop autoplay refusal exposes a working resume control (muted=${initiallyMuted})`, async () => {
let activated = false
const video = {
paused: true,
muted: initiallyMuted,
currentTime: 0,
srcObject: {},
async play() {
if (!activated) throw new Error('NotAllowedError')
this.paused = false
},
}
const component = {
_video: video,
isVideoSyncing: false,
is_touch_device: false,
playable: true,
videoBlocked: false,
$accessor: { video: { setMuted: () => {}, pause: () => {} } },
videoResume: new VideoResume(video, () => 0, () => {}, (blocked) => { component.videoBlocked = blocked }),
}
await methods.onPlayingChanged.call(component, true)
expect(video.paused).toBe(true)
expect(component.videoBlocked).toBe(true)
activated = true
methods.resumeVideo.call(component)
await Promise.resolve()
expect(video.paused).toBe(false)
expect(component.videoBlocked).toBe(false)
})
}
4 changes: 2 additions & 2 deletions images/chromium-headful/client/tests/video-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ describe('resuming the video', () => {
expect(calls).toEqual(['resume'])
})

test('leaves desktop alone', () => {
test('desktop can resume from the recovery control or when the tab is shown', () => {
const { methods, ctx, calls } = player(false)
methods.resumeVideo.call(ctx)
methods.resumeVideoWhenVisible.call(ctx)
expect(calls).toEqual([])
expect(calls).toEqual(['resume', 'resume'])
})

test('waits for the stream to be playable', () => {
Expand Down