From fb04a947e681e5182775875d0477eb69c9201e84 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 19:23:33 -0700 Subject: A PAFF film pauses when its post scrolls off screen and carries on when it comes back. "can you ask paff to do the pause command?" (Adam, 2026-11-17). PAFF's embed now takes {source:'paff', command:'pause'|'play'|…} and reports {source:'paff', event:'playing'|'pause'|'ended'}. Each loaded film box is watched: once it's fully off screen while playing, it's told to pause. When it's back at least half in view, it's told to play, but only if we paused it; a viewer's own pause stays paused. link-preview-test runs a stand-in paff.club (self-signed TLS, host-resolver-rules) whose player speaks the protocol. In it the film pauses when scrolled away and plays when scrolled back (commands logged: pause, play). features-smoke passes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- tools/link-preview-test.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'tools/link-preview-test.js') diff --git a/tools/link-preview-test.js b/tools/link-preview-test.js index a780c73..fb83dae 100644 --- a/tools/link-preview-test.js +++ b/tools/link-preview-test.js @@ -40,7 +40,27 @@ const server = Bun.serve({ port: 5311, fetch: (req) => { if (u.pathname.startsWith('/punks') || u.pathname === '/verify-worker.js') return new Response(Bun.file('dist' + u.pathname)); return new Response(html, { headers: { 'content-type': 'text/html' } }); } }); -const browser = await puppeteer.launch({ relays: 'read', executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); +// a stand-in paff.club (self-signed, resolved here): its embed player speaks +// PAFF's postMessage protocol and logs the commands it gets +const certDir = (await import('node:fs')).mkdtempSync((await import('node:os')).tmpdir() + '/paff-cert-'); +Bun.spawnSync(['openssl', 'req', '-x509', '-newkey', 'ec', '-pkeyopt', 'ec_paramgen_curve:prime256v1', '-nodes', '-days', '1', '-subj', '/CN=paff.club', + '-keyout', certDir + '/k.pem', '-out', certDir + '/c.pem']); +const paffLog = []; +const paffServer = Bun.serve({ port: 5313, tls: { cert: Bun.file(certDir + '/c.pem'), key: Bun.file(certDir + '/k.pem') }, fetch: async (req) => { + const u = new URL(req.url); + if (u.pathname === '/log') { paffLog.push(await req.text()); return new Response('ok'); } + return new Response(`player`, { headers: { 'content-type': 'text/html' } }); +} }); +const browser = await puppeteer.launch({ relays: 'read', executablePath: '/usr/bin/google-chrome', headless: 'new', + args: ['--no-sandbox', '--host-resolver-rules=MAP paff.club:443 127.0.0.1:5313', '--ignore-certificate-errors'] }); const page = await browser.newPage(); await page.evaluateOnNewDocument((posts, profile) => { // the registrar's preview endpoint answers from this test's server @@ -125,12 +145,20 @@ try { check('a PAFF film link shows as a player with its backdrop and title', !!paff && paff.poster && /Hackers/.test(paff.title || '') && !paff.frame, JSON.stringify(paff)); const src = await page.evaluate(() => { const b = [...document.querySelectorAll('.paff-embed')][0]; + b.scrollIntoView({ block: 'center' }); b.querySelector('.yt-play').click(); - const f = b.querySelector('iframe'), s = f && f.getAttribute('src'); - if (f) f.src = 'about:blank'; // (the test doesn't stream the film) - return s; + return b.querySelector('iframe')?.getAttribute('src'); }); check('...and a tap loads PAFF\'s embed player there, the link\'s query kept', src === 'https://paff.club/embed/movie/1382-hackers-1995?q=1080p&t=4910', src); + await sleep(900); // the stand-in reports it's playing + await page.evaluate(() => scrollTo(0, document.documentElement.scrollHeight + 5000)); + await page.evaluate(() => { const s = document.createElement('div'); s.style.height = '3000px'; s.id = 'pad'; document.body.append(s); scrollTo(0, document.documentElement.scrollHeight); }); + for (let i = 0; i < 20 && !paffLog.includes('pause'); i++) await sleep(150); + check('a playing film pauses once its post is off the screen', paffLog.includes('pause'), JSON.stringify(paffLog)); + await page.evaluate(() => document.querySelector('.paff-embed').scrollIntoView({ block: 'center' })); + for (let i = 0; i < 20 && !paffLog.includes('play'); i++) await sleep(150); + check('...and carries on when it comes back', paffLog.join() === 'pause,play', JSON.stringify(paffLog)); + await page.evaluate(() => { document.getElementById('pad')?.remove(); scrollTo(0, 0); }); check('the registrar was asked once per link', previewHits.filter((u) => u === 'https://news.example/story/1').length === 1 && !previewHits.some((u) => u.endsWith('.png')), JSON.stringify(previewHits)); let kept = 0; // written behind, a second after the card was learned for (let i = 0; i < 12 && kept < 2; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (kept < 2) await sleep(300); } @@ -147,6 +175,6 @@ try { check('a draft\'s preview shows the link as its card', opened && draft?.card && /Hackers/.test(draft.title || ''), JSON.stringify(draft)); check('...asked for once the typing settled, not per keystroke', previewHits.filter((u) => u.startsWith('https://movies.example')).length === 1, JSON.stringify(previewHits)); check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); -} finally { await browser.close(); server.stop(true); } +} finally { await browser.close(); server.stop(true); paffServer.stop(true); } console.log(ok ? '\n✅ links show as the cards their pages describe' : '\n❌ failed'); process.exit(ok ? 0 : 1); -- cgit v1.2.3