aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-13 04:39:06 +0000
committerAdam Soltys <[email protected]>2026-10-13 04:39:06 +0000
commitb22832ffd5df280811559cdbf0455305321e160c (patch)
tree16c347bf0efb4e3b0b53e0877cd9dd07e38af918 /tools
parent492bc22788ba8c0e1589591d687b741021d2368e (diff)
downloadcoinosv3-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
Diffstat (limited to 'tools')
-rw-r--r--tools/video-touch-tap-test.js122
1 files changed, 122 insertions, 0 deletions
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);