diff options
| author | Adam Soltys <[email protected]> | 2026-10-13 04:39:06 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-13 04:39:06 +0000 |
| commit | b22832ffd5df280811559cdbf0455305321e160c (patch) | |
| tree | 16c347bf0efb4e3b0b53e0877cd9dd07e38af918 | |
| parent | 492bc22788ba8c0e1589591d687b741021d2368e (diff) | |
| download | coinosv3-b22832ffd5df280811559cdbf0455305321e160c.tar.gz coinosv3-b22832ffd5df280811559cdbf0455305321e160c.zip | |
Feed video: a touch on a clip that has been playing opens the pager. Adam tapped a feed clip away from its play button and nothing happened (his screenshot: the clip paused, the player's bar up — 0:09 / 0:18). Once a clip has played its own controls are up, and Chrome on Android keeps a tap on such a clip for them (it shows or hides the bar): the page gets the pointer events but never the click, and the click was all videoTap listened for — so the player's full screen before, and the pager since b01ec80, were out of reach by touch. Now a touch that lifts where it went down, within half a second, is taken at pointerup; the control bar and a paused clip's play button stay the player's, a drag stays a scroll. Where the click does come after, it is spent: on the clip (no thread opened, no second pager) and on the pager it opened (which would otherwise pause the clip and raise the details). tools/video-touch-tap-test.js plays the phone out by swallowing the click on a clip with controls: the touch opens the pager; the play button, the bar and a drag open nothing; with the click let through, one pager, no thread, the clip playing with nothing raised.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KPw21NEpWeTGu6swVASmBt
| -rw-r--r-- | src/features/messages.js | 34 | ||||
| -rw-r--r-- | tools/video-touch-tap-test.js | 122 |
2 files changed, 149 insertions, 7 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index f24e935..2580ed9 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -7563,9 +7563,10 @@ export function messagesFeature(ctx) { // paused one comes back out. The player's controls are inside the video // element, so where they sit is judged from the tap's position. const fsElement = () => (typeof document !== 'undefined' && (document.fullscreenElement || document.webkitFullscreenElement)) || null; + let videoTapAt = 0; // a touch's tap on a clip, taken at pointerup: the click after it lands on whatever opened function videoTap(e, url) { const v = e.currentTarget; - if (!v || v.tagName !== 'VIDEO') return; + if (!v || v.tagName !== 'VIDEO') return false; const r = v.getBoundingClientRect(); const x = e.clientX - r.left, y = e.clientY - r.top; // a video's taps are its own: never the post's (which opened the thread @@ -7574,26 +7575,27 @@ export function messagesFeature(ctx) { const fs = fsElement() === v; // full screen, the video's box is the screen; its controls sit along the bottom const H = fs ? window.innerHeight : r.height, W = fs ? window.innerWidth : r.width; - if (v.controls && y > H - 64) return; // the control bar - if (v.controls && v.paused && Math.hypot(x - W / 2, y - H / 2) < 48) return; // the big play button + if (v.controls && y > H - 64) return false; // the control bar + if (v.controls && v.paused && Math.hypot(x - W / 2, y - H / 2) < 48) return false; // the big play button e.preventDefault(); if (fs) { if (!v.paused) v.pause(); else (document.exitFullscreen || document.webkitExitFullscreen || (() => {})).call(document)?.catch?.(() => {}); - return; + return true; } - if (openClip(v, url)) return; + if (openClip(v, url)) return true; // a clip still idle (autoplaying, no controls) becomes the reader's wokeClips.add(url); const box = v.closest('.note-video-box'); if (box) { box.classList.remove('idle'); box._skipMorph = true; } v.controls = true; const go = v.requestFullscreen || v.webkitRequestFullscreen || v.webkitEnterFullscreen; - if (!go) return; + if (!go) return true; Promise.resolve(go.call(v)).then(() => { // a wide clip fills a phone on its side if (v.videoWidth > v.videoHeight) screen.orientation?.lock?.('landscape').catch(() => {}); }).catch(() => {}); + return true; } if (typeof document !== 'undefined') document.addEventListener('fullscreenchange', () => { if (fsElement()) return; @@ -7616,9 +7618,26 @@ export function messagesFeature(ctx) { style: stable ? videoBoxStyle(feedMedia(url)) : undefined, // learned now, used by the next paint of any row with this clip onLoadedmetadata: (e) => rememberVideo(url, e.target.videoWidth, e.target.videoHeight), - onClick: (e) => videoTap(e, url), + // a touch's tap was taken at pointerup (below): its click, if one comes, is spent + onClick: (e) => { if (Date.now() - (e.currentTarget._tapAt || 0) < 800) { e.stopPropagation(); e.preventDefault(); return; } videoTap(e, url); }, onError: (e) => { if (!stable && !(e.target.getAttribute('src') || '').startsWith(VMEDIA)) { const b = e.target.parentElement; if (b) b.style.display = 'none'; } } }); guardPicture(v, url); + // With its own controls up, Chrome on Android keeps a tap on the clip for + // them (it shows or hides the bar) and the page never gets the click — so + // a full-screen tap on a clip that had been played did nothing. The + // pointer events still arrive: a touch that lifts where it went down, + // quickly, is the tap. + v.addEventListener('pointerdown', (e) => { + if (e.pointerType === 'mouse') return; + e.currentTarget._touch = { x: e.clientX, y: e.clientY, t: Date.now(), id: e.pointerId }; + }); + v.addEventListener('pointercancel', (e) => { e.currentTarget._touch = null; }); + v.addEventListener('pointerup', (e) => { + const el = e.currentTarget, d = el._touch; + el._touch = null; + if (!d || d.id !== e.pointerId || Date.now() - d.t > 500 || Math.hypot(e.clientX - d.x, e.clientY - d.y) > 12) return; + if (videoTap(e, url)) el._tapAt = videoTapAt = Date.now(); + }); v.muted = !loud; // the property, not just the attribute: a script-made element autoplays only muted const box = h('div', { class: 'note-video-box' + (idle ? ' idle' : '') }, v); if (loud) box._skipMorph = true; @@ -12174,6 +12193,7 @@ export function messagesFeature(ctx) { // a tap shows (or hides) who posted it and what they said el.addEventListener('click', (e) => { if (e.target.closest('button, a, .mp-caption, .mp-seek')) return; + if (Date.now() - videoTapAt < 800) return; // the click of the touch that opened it if (pager && pager.fromFeed && video) { // A clip opened from the feed: a tap pauses it and brings up who // posted it, the ×, the seek bar to grab; another plays it on. diff --git a/tools/video-touch-tap-test.js b/tools/video-touch-tap-test.js new file mode 100644 index 0000000..6a45c9e --- /dev/null +++ b/tools/video-touch-tap-test.js @@ -0,0 +1,122 @@ +// A touch on a feed clip that has been playing (its own controls up) opens +// the pager. Chrome on Android keeps such a tap for the player's controls — +// the page gets pointer events but no click — so the tap is read from the +// pointer events; here that is played out by swallowing the click. A touch +// on the control bar or the paused clip's play button stays the player's, a +// drag is a scroll, and where the click does come it isn't taken twice. +// Run: bun tools/video-touch-tap-test.js +import puppeteer from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { buildHtml } from '../build.js'; +import { existsSync } from 'node:fs'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const SK = generateSecretKey(); const AUTHOR = getPublicKey(SK); +const now = Math.floor(Date.now() / 1000); +const CLIP = '/tmp/coinos-touch-clip.webm'; +if (!existsSync(CLIP)) Bun.spawnSync(['ffmpeg', '-y', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=320x180:rate=10', '-t', '30', '-c:v', 'libvpx', '-b:v', '100k', CLIP]); +const POSTS = [finalizeEvent({ kind: 1, created_at: now - 100, tags: [], content: 'watch this http://localhost:5315/clip.webm' }, SK)]; +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5315, fetch: (req) => { + const path = new URL(req.url).pathname; + if (path === '/clip.webm') return new Response(Bun.file(CLIP), { headers: { 'content-type': 'video/webm' } }); + if (path.startsWith('/punks') || path === '/verify-worker.js') return new Response(Bun.file('dist' + path)); + return new Response(html, { headers: { 'content-type': 'text/html' } }); +} }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox', '--autoplay-policy=no-user-gesture-required'] }); +const page = await browser.newPage(); +await page.evaluateOnNewDocument(() => { + const Real = window.WebSocket; + window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })), 0); return; } if (m[0] === 'EVENT') return; } catch {} return send(d); }; return ws; }; + window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); +}); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; }; +const st = () => page.evaluate(() => { const v = document.querySelector('.thread-card video.note-video') || document.querySelector('video.note-video'); return { fs: document.fullscreenElement === v, paused: v.paused, controls: v.controls, thread: !document.querySelector('video.note-video')?.isConnected }; }); +// tap the clip at a fraction of its box (or of the screen, full screen) +const tap = async (fx, fy) => { + const fs = await page.evaluate(() => !!document.fullscreenElement); + const r = fs ? { x: 0, y: 0, width: await page.evaluate(() => innerWidth), height: await page.evaluate(() => innerHeight) } + : await page.evaluate(() => { const b = (document.querySelector('.thread-card video.note-video') || document.querySelector('video.note-video')).getBoundingClientRect(); return { x: b.x, y: b.y, width: b.width, height: b.height }; }); + await page.mouse.click(r.x + r.width * fx, r.y + r.height * fy); + await sleep(700); +}; +try { + await page.setViewport({ width: 390, height: 844, hasTouch: true }); + await page.goto('http://localhost:5315/', { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400); + await click('create a new wallet'); await sleep(600); + await page.waitForSelector('.words .w .t'); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await click('skip verification'); + await waitText('receive', 20000); + const base = cacheKeyFor(mn + '\n'); + await page.evaluate(([k, pk, ns]) => { + localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', pk]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':feedNotes', JSON.stringify(ns)); + localStorage.setItem(k + ':profiles', JSON.stringify({ [pk]: { name: 'Clipper', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, AUTHOR, POSTS]); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + await page.waitForSelector('video.note-video', { timeout: 20000 }); + await page.evaluate(() => document.querySelector('video.note-video').scrollIntoView({ block: 'center' })); + const vid = () => page.evaluate(() => { const v = document.querySelector('.notes-feed video.note-video'); return v ? { paused: v.paused, controls: v.controls } : null; }); + for (let i = 0; i < 40 && (await vid())?.paused; i++) await sleep(250); + check('the clip plays in the feed, its controls up', (await vid())?.controls === true && !(await vid()).paused, JSON.stringify(await vid())); + const box = () => page.evaluate(() => { const b = document.querySelector('.notes-feed video.note-video').getBoundingClientRect(); return { x: b.x, y: b.y, w: b.width, h: b.height }; }); + const touch = async (fx, fy) => { const b = await box(); await page.touchscreen.tap(b.x + b.w * fx, b.y + b.h * fy); await sleep(700); }; + const state = () => page.evaluate(() => ({ pagers: document.querySelectorAll('.media-pager').length, thread: !!document.querySelector('.thread-card') })); + const close = async () => { await page.keyboard.press('Escape'); await sleep(800); }; + + console.log('\n[the phone keeps the click: the tap still opens the pager]'); + await page.evaluate(() => { window.__swallow = true; document.addEventListener('click', (e) => { if (window.__swallow && e.target.tagName === 'VIDEO' && e.target.controls) { e.stopImmediatePropagation(); window.__swallowed = (window.__swallowed || 0) + 1; } }, true); }); + await touch(0.2, 0.3); + let s = await state(); + check('a touch on the picture opens the pager', s.pagers === 1, JSON.stringify(s)); + check('…and not the thread', !s.thread); + await close(); + check('Escape closes it', (await state()).pagers === 0); + + console.log('\n[the player\'s own controls stay its own]'); + await page.evaluate(() => document.querySelector('.notes-feed video.note-video').pause()); await sleep(300); + await touch(0.5, 0.5); + check('a touch on the paused clip\'s play button: no pager', (await state()).pagers === 0); + await touch(0.3, 0.97); + check('a touch on the control bar: no pager', (await state()).pagers === 0); + + console.log('\n[a drag is a scroll]'); + const b = await box(); + await page.touchscreen.touchStart(b.x + b.w * 0.3, b.y + b.h * 0.4); + await page.touchscreen.touchMove(b.x + b.w * 0.3, b.y + b.h * 0.4 - 60); + await page.touchscreen.touchEnd(); + await sleep(700); + check('a drag across the clip opens nothing', (await state()).pagers === 0); + + console.log('\n[where the click does come, the tap is taken once]'); + await page.evaluate(() => { window.__swallow = false; }); + await page.evaluate(() => document.querySelector('.notes-feed video.note-video').scrollIntoView({ block: 'center' })); await sleep(300); + const hist = await page.evaluate(() => history.length); + await touch(0.2, 0.3); + s = await state(); + check('the touch opens one pager', s.pagers === 1, JSON.stringify(s)); + check('…the click after it doesn\'t open the thread', !s.thread); + check('…or a second place in history', (await page.evaluate(() => history.length)) - hist <= 1); + await sleep(1200); + check('…or land on the pager (pausing the clip, raising the details)', await page.evaluate(() => { + const p = document.querySelector('.media-pager'); const sc = p && p.querySelector('.mp-scroll'); + const cur = sc && [...sc.children].find((x) => Math.abs(x.offsetTop - sc.scrollTop) < 4); + const v = cur && cur.querySelector('video.mp-media'); + return !!p && !p.classList.contains('show') && !!v && !v.paused; + })); + await close(); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ a touch on a playing clip opens the pager' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
