/** * The Rooms tab (DESIGN.md §12.7): live rooms now (watching, heat, a live * line of chat), Moments (today's hero, live detections, your clips), Need * eyes near you, and crews: yours, and ones to discover. */ import { icon } from './icons.js'; import { $, esc, ago, haptic, toast, esriThumb, reducedMotion } from './dom.js'; import { BAND_COLOR, bandOf } from './bands.js'; import { viewerCount, sampleLines, chatGenre } from './chatSim.js'; import { richText } from './emotes.js'; import { simTier, hashStr } from './signal.js'; import { crewAvatar, fmtM } from './crews.js'; const fmtV = (v) => (v >= 1000 ? `${(v / 1000).toFixed(1)}k` : String(v)); export function createRoomsTab(el, core) { let tickers = []; let tickTimer = 0; let live = []; let moments = []; el.classList.add('rooms-tab'); core.ctx.bindScroll?.(el); el.addEventListener( 'scroll', () => el.classList.toggle('is-scrolled', el.scrollTop > 44), { passive: true }, ); function heatBars(s) { let x = hashStr(s.id); const bars = []; for (let i = 0; i < 12; i += 1) { x = (Math.imul(x, 1103515245) + 12345) >>> 0; bars.push(0.25 + ((x >>> 8) % 100) / 133 + i / 30); } return ``; } function liveRow(s, i) { const band = bandOf(s); const v = viewerCount(s) + Math.max(0, core.rt.presence(String(s.id)).length - 1); const thumb = core.globe?.cachedThumbnail?.(s) || s.thumbUrl || s.thumbnail || ''; return ``; } function momentHero(m) { const ms = Math.max( 1, Math.round(((+m.time?.end || 0) - (+m.time?.start || 0)) / 60e3), ); return `
Live is fast. The Record is true. Signal rewards being right, early, with receipts.
Simulated chat and example crews are labelled. Your posts, votes, captures and Signal are real and stay on this device.
`; // Tickers: a real-feeling line of each room's chat. tickers = live.map((s) => ({ s, lines: sampleLines(s, 8), i: 0 })); tickAll(true); clearInterval(tickTimer); tickTimer = setInterval(() => tickAll(false), 2600); } function tickAll(first) { if (!el.isConnected || (el.offsetParent === null && !first)) return; tickers.forEach((t, k) => { const node = $(`[data-tick="${k}"]`, el); if (!node || !t.lines.length) return; // Stagger so the list shimmers rather than blinks. if (!first && Math.random() < 0.45) return; const m = t.lines[t.i % t.lines.length]; t.i += 1; const tier = m.tier || simTier(m.handle); node.innerHTML = `${esc(m.handle.slice(1))} ${richText(m.text).html}`; }); } el.addEventListener('click', async (e) => { const room = e.target.closest('[data-room]'); if (room) { const sits = await core.situations(); const s = sits.find((x) => String(x.id) === room.dataset.room); if (s) core.openRoom(s, { lane: 'live' }); return; } const mo = e.target.closest('[data-mo]'); if (mo) { haptic('light'); const m = moments.find((x) => x.id === mo.dataset.id) || (await core.moment(mo.dataset.id)); if (mo.dataset.mo === 'play') { if (core.ctx.onPlayMoment) core.ctx.onPlayMoment(m); else core.openRoom(m, { lane: 'live' }); } else core.openRoom(m, { lane: mo.dataset.mo === 'record' ? 'record' : 'live', }); return; } const nd = e.target.closest('[data-need-act]'); if (nd) { core.needs.act(nd.dataset.needAct, nd.dataset.need); return; } const jn = e.target.closest('[data-join]'); if (jn) { core.crews.toggle(jn.dataset.join); haptic('success'); toast('Joined', { icon: icon('users') }); render(); return; } const cr = e.target.closest('[data-crew]'); if (cr) core.crews.open(cr.dataset.crew); }); const offN = core.needs.on('change', () => el.isConnected && render()); const offC = core.crews.on('change', () => el.isConnected && render()); render(); return { refresh: render, destroy() { clearInterval(tickTimer); offN?.(); offC?.(); el.innerHTML = ''; }, }; }