aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-17 19:23:33 -0700
committerAdam Soltys <[email protected]>2026-11-17 19:23:33 -0700
commitfb04a947e681e5182775875d0477eb69c9201e84 (patch)
treed598cd8645913451fefd1f5a273c8129152fec9a
parentfd172aa8bf6f1bfd0c09f7a819bf2aeda65a5fbd (diff)
downloadcoinosv3-fb04a947e681e5182775875d0477eb69c9201e84.tar.gz
coinosv3-fb04a947e681e5182775875d0477eb69c9201e84.zip
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.HEADmaster
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ
-rw-r--r--src/features/messages.js39
-rw-r--r--tools/link-preview-test.js38
2 files changed, 71 insertions, 6 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 158f0ee..797534e 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -9010,7 +9010,7 @@ export function messagesFeature(ctx) {
// c copy, t start) in its place ("What would it take … to have it play in
// line like other videos and YouTube videos do?", Adam, 2026-11-17).
// Only ever on a tap, never on scroll: a PAFF film starts a torrent swarm
- // in the viewer's browser.
+ // in the viewer's browser. Scrolled off, it pauses (paffWatch).
function paffEmbedUrl(url) {
let u;
try { u = new URL(url); } catch { return null; }
@@ -9018,6 +9018,42 @@ export function messagesFeature(ctx) {
const m = u.pathname.match(/^\/(movie\/[^/]+|show\/[^/]+\/s\d+e\d+)(?:\/play)?\/?$/i);
return m ? 'https://paff.club/embed/' + m[1] + u.search : null;
}
+ // A playing film pauses once its post is off the screen and carries on
+ // when it comes back, if it was us that paused it ("can you ask paff to
+ // do the pause command?", Adam, 2026-11-17). The embed takes
+ // {source:'paff', command} and tells us its state as {source:'paff', event}.
+ let paffObserver = null, paffHeard = false;
+ const paffSay = (box, command) => {
+ const f = box.querySelector('iframe');
+ try { f?.contentWindow?.postMessage({ source: 'paff', command }, 'https://paff.club'); } catch {}
+ };
+ function paffWatch(box) {
+ if (typeof window === 'undefined') return;
+ if (!paffHeard) {
+ paffHeard = true;
+ window.addEventListener('message', (e) => {
+ if (e.origin !== 'https://paff.club' || e.data?.source !== 'paff') return;
+ for (const b of document.querySelectorAll('.paff-embed[data-playing]')) {
+ if (b.querySelector('iframe')?.contentWindow !== e.source) continue;
+ if (e.data.event === 'playing') { b._paffPlaying = true; b._pausedByUs = false; }
+ else if (e.data.event === 'pause' || e.data.event === 'ended') b._paffPlaying = false;
+ }
+ });
+ }
+ if (typeof IntersectionObserver === 'undefined') return;
+ if (!paffObserver) paffObserver = new IntersectionObserver((entries) => {
+ for (const en of entries) {
+ const b = en.target;
+ if (!b.isConnected) { paffObserver.unobserve(b); continue; }
+ if (!en.isIntersecting) {
+ if (b._paffPlaying) { b._pausedByUs = true; paffSay(b, 'pause'); }
+ } else if (en.intersectionRatio >= 0.5 && b._pausedByUs) {
+ b._pausedByUs = false; paffSay(b, 'play');
+ }
+ }
+ }, { threshold: [0, 0.5] });
+ paffObserver.observe(box);
+ }
function paffEmbed(url, pv) {
const embed = paffEmbedUrl(url);
const load = (box) => {
@@ -9033,6 +9069,7 @@ export function messagesFeature(ctx) {
f.allowFullscreen = true;
f.referrerPolicy = 'strict-origin-when-cross-origin';
box.append(f);
+ paffWatch(box);
};
return h('div', {
class: 'yt-embed paff-embed',
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(`<!doctype html><body style="background:#000;color:#fff">player<script>
+ const say = (event) => parent.postMessage({ source: 'paff', event, t: 0 }, '*');
+ setTimeout(() => say('playing'), 150);
+ addEventListener('message', (e) => {
+ if (e.data?.source !== 'paff' || !e.data.command) return;
+ fetch('/log', { method: 'POST', body: e.data.command });
+ say(e.data.command === 'pause' ? 'pause' : 'playing');
+ });
+ </script>`, { 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);