Orbit Companion phase 1: the phone page becomes a remote for the TV
Remote, Guide, Catch Up, Rooms and More, served by the TV in its own look. New phone routes for what's on, the remote's buttons, volume, channels, sections, the guide, Catch Up and rooms, set before any screen returns so they work in every section. Settings gets Connect a phone; the last setup step mentions it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
<!doctype html>
|
||||
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><title>Orbit</title>
|
||||
<meta name="theme-color" content="#071632">
|
||||
<style>
|
||||
/* Orbit Companion (design/companion v2): the TV's look, filled in from /api/now. Orbit Night until then. */
|
||||
:root{--bg:#071632;--surface:#12356B;--raised:#194C91;--deep:#0C2148;--accent:#FFDE59;--on-accent:#071632;--ink:#FFFFFF;--muted:#B7CBE8;--mint:#7EE0A8;--sky:#7FD1FF}
|
||||
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
|
||||
html,body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.35 system-ui,-apple-system,"Segoe UI",sans-serif}
|
||||
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer}
|
||||
main{max-width:460px;margin:0 auto;padding:16px 16px 96px}
|
||||
header{display:flex;align-items:center;gap:8px;margin:4px 0 14px}
|
||||
.brand{font-weight:800;letter-spacing:.14em;font-size:18px}.brand svg{vertical-align:-4px;margin-right:6px}
|
||||
.page{color:var(--muted);font-size:16px}
|
||||
.room{display:flex;align-items:center;gap:10px;background:var(--surface);border-radius:14px;padding:10px 14px;margin-bottom:12px;font-size:13px}
|
||||
.dot{width:8px;height:8px;border-radius:50%;background:var(--mint);flex:none}.dot.off{background:var(--muted);opacity:.5}
|
||||
.room b{font-size:14px}.room span{color:var(--muted)}
|
||||
.card{background:var(--surface);border-radius:16px;padding:14px}
|
||||
.now{display:flex;gap:14px;align-items:center}
|
||||
.tile{width:68px;height:68px;border-radius:12px;background:var(--raised);display:flex;align-items:center;justify-content:center;flex:none;font-weight:800;font-size:20px;color:var(--accent)}
|
||||
.pill{display:inline-block;background:var(--accent);color:var(--on-accent);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:800;letter-spacing:.04em}
|
||||
.pill.mint{background:var(--mint)}
|
||||
.small{color:var(--muted);font-size:12px}.title{font-size:21px;font-weight:700;margin:2px 0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.grow{flex:1;min-width:0}
|
||||
.bar{height:4px;border-radius:2px;background:var(--deep);margin:12px 0 10px;overflow:hidden}.bar i{display:block;height:100%;background:var(--accent)}
|
||||
.next{font-size:12px;color:var(--muted)}.next b{color:var(--ink);font-weight:600;letter-spacing:.04em}
|
||||
.pad{position:relative;width:240px;height:240px;margin:28px auto 22px;border-radius:50%;background:var(--surface)}
|
||||
.pad button{position:absolute;width:64px;height:64px;display:flex;align-items:center;justify-content:center;border-radius:50%}
|
||||
.pad button:active{background:var(--raised)}
|
||||
.pad .up{left:88px;top:6px}.pad .down{left:88px;bottom:6px}.pad .left{left:6px;top:88px}.pad .right{right:6px;top:88px}
|
||||
.pad .ok{left:70px;top:70px;width:100px;height:100px;background:var(--accent);color:var(--on-accent);font-weight:800;font-size:24px}
|
||||
.pad .ok:active{filter:brightness(.9);background:var(--accent)}
|
||||
.row{display:flex;gap:10px;align-items:center;justify-content:center}
|
||||
.round{width:52px;height:52px;border-radius:50%;background:var(--surface);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:800;letter-spacing:.04em}
|
||||
.rocker{display:flex;align-items:center;background:var(--surface);border-radius:999px;height:52px}
|
||||
.rocker button{width:44px;height:52px;font-size:22px;font-weight:500}.rocker span{font-size:10px;font-weight:800;color:var(--muted);letter-spacing:.06em}
|
||||
button:active{opacity:.75}
|
||||
.link{display:block;margin:18px auto 0;background:var(--surface);border-radius:999px;padding:8px 18px;font-size:13px;font-weight:600}
|
||||
.label{color:var(--muted);font-size:11px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;margin:18px 0 8px}
|
||||
.jumps{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
|
||||
.jumps button{background:var(--raised);border-radius:12px;padding:12px 4px;font-size:12px;font-weight:600;display:flex;flex-direction:column;align-items:center;gap:6px}
|
||||
.jumps svg{color:var(--accent)}
|
||||
.line{display:flex;justify-content:space-between;align-items:center;background:var(--raised);border-radius:12px;padding:13px 14px;margin-bottom:8px;width:100%;text-align:left;font-weight:600}
|
||||
.line span{color:var(--accent);font-size:13px}
|
||||
.chips{display:flex;gap:8px;overflow-x:auto;margin-bottom:10px;padding-bottom:2px}
|
||||
.chips button{background:var(--surface);border-radius:999px;padding:6px 14px;font-size:13px;font-weight:600;white-space:nowrap}
|
||||
.chips button.on{background:var(--accent);color:var(--on-accent)}
|
||||
.ch{display:flex;gap:12px;align-items:center;background:var(--surface);border-radius:14px;padding:11px 14px;margin-bottom:8px;width:100%;text-align:left}
|
||||
.ch.on{background:var(--raised);outline:2px solid var(--accent)}
|
||||
.ch .num{width:74px;flex:none}.ch .num b{display:block;color:var(--accent);font-size:15px}.ch .num small{color:var(--muted);font-size:11px;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.ch .what{font-weight:700;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ch .then{color:var(--muted);font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.sheet{position:fixed;left:0;right:0;bottom:0;z-index:5;background:var(--deep);border-radius:22px 22px 0 0;padding:10px 18px calc(84px + env(safe-area-inset-bottom));box-shadow:0 -10px 40px #0008;transform:translateY(110%);transition:transform .2s ease}
|
||||
.sheet.open{transform:none}.sheet .grab{width:40px;height:4px;border-radius:2px;background:var(--muted);opacity:.5;margin:0 auto 12px}
|
||||
.sheet .inner{max-width:460px;margin:0 auto}
|
||||
.btn{border-radius:999px;padding:12px 16px;font-weight:700;background:var(--raised);width:100%}.btn.gold{background:var(--accent);color:var(--on-accent)}
|
||||
.shade{position:fixed;inset:0;background:#0006;z-index:4;display:none}.shade.open{display:block}
|
||||
.cu{display:flex;gap:12px;align-items:center;background:var(--surface);border-radius:14px;padding:11px 14px;margin-bottom:8px;width:100%;text-align:left}
|
||||
.cu .play{width:34px;height:34px;border-radius:50%;border:2px solid var(--accent);display:flex;align-items:center;justify-content:center;flex:none;color:var(--accent)}
|
||||
.rm{background:var(--surface);border-radius:16px;padding:14px;margin-bottom:10px}.rm.here{outline:2px solid var(--accent)}
|
||||
.rm h3{margin:0;font-size:17px;display:flex;justify-content:space-between;align-items:center}
|
||||
.tags{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}.tags span{background:var(--raised);border-radius:999px;padding:3px 10px;font-size:11px;font-weight:700}
|
||||
a.btn{display:block;text-align:center;text-decoration:none;color:inherit;margin-top:10px}
|
||||
nav{position:fixed;left:0;right:0;bottom:0;z-index:6;background:var(--bg);border-top:1px solid var(--surface);padding:6px 6px calc(6px + env(safe-area-inset-bottom))}
|
||||
nav div{max-width:460px;margin:0 auto;display:flex}
|
||||
nav button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;padding:6px 0;font-size:11px;color:var(--muted)}
|
||||
nav button i{display:flex;align-items:center;justify-content:center;width:46px;height:28px;border-radius:999px}
|
||||
nav button.on{color:var(--accent);font-weight:700}nav button.on i{background:var(--surface)}
|
||||
.toast{position:fixed;left:50%;bottom:90px;transform:translateX(-50%);background:var(--accent);color:var(--on-accent);padding:9px 16px;border-radius:999px;font-weight:700;font-size:13px;z-index:9;display:none;max-width:90vw;text-align:center}
|
||||
.empty{color:var(--muted);text-align:center;padding:30px 10px}
|
||||
</style></head><body>
|
||||
<main id="app"></main>
|
||||
<div class="shade" id="shade"></div><div class="sheet" id="sheet"><div class="grab"></div><div class="inner" id="sheetIn"></div></div>
|
||||
<nav><div id="tabs"></div></nav>
|
||||
<div class="toast" id="toast"></div>
|
||||
<script>
|
||||
const $ = s => document.querySelector(s);
|
||||
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
const api = async (path, body) => {
|
||||
const r = await fetch(path, body ? {method:'POST', headers:{'Content-Type':'application/json','X-Orbit':'1'}, body:JSON.stringify(body)} : {cache:'no-store'});
|
||||
if (r.headers.get('content-type')?.includes('text/html')) { location.reload(); throw new Error('Join again'); }
|
||||
const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error || 'Something went wrong'); return j;
|
||||
};
|
||||
const toast = t => { const e = $('#toast'); e.textContent = t; e.style.display = 'block'; clearTimeout(toast.t); toast.t = setTimeout(() => e.style.display = 'none', 2200); };
|
||||
const buzz = () => navigator.vibrate?.(12);
|
||||
const hm = ms => new Date(ms).toLocaleTimeString('en-GB', {hour:'2-digit', minute:'2-digit', hourCycle:'h23'});
|
||||
let skew = 0; const now = () => Date.now() + skew;
|
||||
const left = p => Math.max(0, Math.round((p.endMs - now()) / 60000));
|
||||
|
||||
const I = {
|
||||
remote:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="7" y="2.5" width="10" height="19" rx="3"/><circle cx="12" cy="8" r="2"/><path d="M10 14h4M10 17h4"/></svg>',
|
||||
guide:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 9h18M9 9v11M15 9v11"/></svg>',
|
||||
catchup:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M3.5 12a8.5 8.5 0 1 0 2.5-6"/><path d="M3 4v4h4M12 8v4l3 2"/></svg>',
|
||||
rooms:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="2.5" y="5" width="13" height="10" rx="1.5"/><path d="M6 19h6"/><rect x="17.5" y="9" width="4" height="10" rx="1"/></svg>',
|
||||
more:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/></svg>',
|
||||
chev:d => `<svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="${{up:'M6 15l6-6 6 6',down:'M6 9l6 6 6-6',left:'M15 6l-6 6 6 6',right:'M9 6l6 6-6 6'}[d]}"/></svg>`,
|
||||
back:'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 7L4 12l5 5"/><path d="M4 12h10a6 6 0 0 1 0 12"/></svg>',
|
||||
play:'<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M7 4l14 8-14 8z"/></svg>',
|
||||
drivein:'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M14 3a9 9 0 1 0 7 13A7 7 0 0 1 14 3z"/></svg>',
|
||||
arcade:'<svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l10 10-10 10L2 12z"/></svg>',
|
||||
home:'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 11l9-7 9 7v9h-6v-6H9v6H3z"/></svg>',
|
||||
mark:'<svg width="24" height="20" viewBox="0 0 24 20" fill="none"><path d="M4 16 C1 10 6 3 14 2 C9 5 6 10 8 16" fill="currentColor" opacity=".9"/><circle cx="18" cy="5" r="2.2" fill="var(--accent)"/></svg>'
|
||||
};
|
||||
const TABS = [['remote','Remote'],['guide','Guide'],['catchup','Catch Up'],['rooms','Rooms'],['more','More']];
|
||||
let tab = (() => { try { return localStorage.getItem('orbit.tab') || 'remote'; } catch { return 'remote'; } })();
|
||||
if (!TABS.some(t => t[0] === tab)) tab = 'remote';
|
||||
let state = {now:null, guide:null, catchup:null, rooms:null, filter:'all'};
|
||||
|
||||
function look(l) {
|
||||
if (!l) return; const r = document.documentElement.style;
|
||||
const map = {bg:l.background, surface:l.surface, raised:l.raised, deep:l.deep, accent:l.accent, 'on-accent':l.onAccent, ink:l.ink, muted:l.muted, mint:l.mint, sky:l.sky};
|
||||
for (const [k, v] of Object.entries(map)) if (v) r.setProperty('--' + k, v);
|
||||
document.querySelector('meta[name=theme-color]').content = l.background;
|
||||
}
|
||||
function tabs() {
|
||||
$('#tabs').innerHTML = TABS.map(([k, n]) => `<button class="${k === tab ? 'on' : ''}" data-tab="${k}"><i>${I[k]}</i>${n}</button>`).join('');
|
||||
}
|
||||
function head(page) {
|
||||
const n = state.now; const ch = n?.channel;
|
||||
const where = !n ? 'Connecting…' : ch ? `${n.watching ? 'Watching' : 'On'} ${ch.number} ${esc(ch.name)}` : 'Orbit is open';
|
||||
return `<header><span class="brand">${I.mark}ORBIT</span><span class="page">${page}</span></header>
|
||||
<div class="room"><span class="dot ${n ? '' : 'off'}"></span><b>${esc(n?.room || 'This TV')}</b><span>${where}</span></div>`;
|
||||
}
|
||||
function nowCard() {
|
||||
const n = state.now; if (!n?.channel) return `<div class="card"><div class="small">Nothing's tuned yet. Pick a channel in the Guide.</div></div>`;
|
||||
const p = n.now, pct = Math.min(100, Math.max(0, (now() + (n.catchingUp ? 0 : 0) - p.startMs) / (p.endMs - p.startMs) * 100));
|
||||
const tag = n.catchingUp ? '<span class="pill mint">CATCH UP</span>' : '<span class="pill">LIVE</span>';
|
||||
return `<div class="card"><div class="now"><div class="tile">${n.channel.number}</div><div class="grow">
|
||||
<div class="small">${tag} ${n.channel.number} ${esc(n.channel.name)}</div>
|
||||
<div class="title">${esc(p.title)}</div>
|
||||
<div class="small">${p.sub ? esc(p.sub) + ' · ' : ''}${n.catchingUp ? 'catching up' : left(p) + ' min left · ends ' + hm(p.endMs)}</div></div></div>
|
||||
${n.catchingUp ? '' : `<div class="bar"><i style="width:${pct}%"></i></div>`}
|
||||
<div class="next"><b>NEXT</b> ${n.catchingUp ? '' : hm(n.next.startMs)} ${esc(n.next.title)}</div></div>`;
|
||||
}
|
||||
function remote() {
|
||||
return head('Remote') + nowCard() + `
|
||||
<div class="pad"><button class="up" data-key="up" aria-label="Up">${I.chev('up')}</button><button class="left" data-key="left" aria-label="Left">${I.chev('left')}</button>
|
||||
<button class="ok" data-key="ok">OK</button><button class="right" data-key="right" aria-label="Right">${I.chev('right')}</button><button class="down" data-key="down" aria-label="Down">${I.chev('down')}</button></div>
|
||||
<div class="row"><button class="round" data-key="back" aria-label="Back">${I.back}</button>
|
||||
<div class="rocker"><button data-ch="1" aria-label="Channel up">+</button><span>CH</span><button data-ch="-1" aria-label="Channel down">−</button></div>
|
||||
<div class="rocker"><button data-vol="down" aria-label="Volume down">−</button><span>VOL</span><button data-vol="up" aria-label="Volume up">+</button></div>
|
||||
<button class="round" data-vol="mute">MUTE</button></div>
|
||||
<button class="link" data-sheet="more">More controls</button>`;
|
||||
}
|
||||
function moreControls() {
|
||||
return `<div class="label">Jump to</div><div class="jumps">
|
||||
<button data-go="guide">${I.guide}Guide</button><button data-go="catchup">${I.catchup}Catch Up</button>
|
||||
<button data-go="drivein">${I.drivein}Drive-In</button><button data-go="arcade">${I.arcade}Arcade</button></div>
|
||||
<div class="label">On the TV now</div>
|
||||
<button class="line" data-key="right">Subtitles, sound and sleep <span>Opens on the TV</span></button>
|
||||
<button class="line" data-key="playpause">Play or pause <span>Catch Up and films</span></button>
|
||||
<button class="line" data-go="home">Home <span>Orbit's front page</span></button>`;
|
||||
}
|
||||
function guide() {
|
||||
const g = state.guide; if (!g) return head('Guide') + '<div class="empty">Loading the guide…</div>';
|
||||
const cats = ['all', ...new Set(g.channels.map(c => c.category).filter(Boolean))];
|
||||
const f = cats.includes(state.filter) ? state.filter : 'all', list = g.channels.filter(c => f === 'all' || c.category === f);
|
||||
return head('Guide') + `<div class="chips">${cats.map(k => `<button class="${k === f ? 'on' : ''}" data-filter="${esc(k)}">${k === 'all' ? 'All' : esc(k)}</button>`).join('')}</div>` +
|
||||
(list.map(c => `<button class="ch ${c.number === g.selected ? 'on' : ''}" data-pick="${c.number}"><div class="num"><b>${c.number}</b><small>${esc(c.name)}</small></div>
|
||||
<div class="grow"><div class="what">${esc(c.now.title)}</div><div class="then">${hm(c.now.startMs)}–${hm(c.now.endMs)} · then ${esc(c.next.title)}</div></div>
|
||||
${c.number === g.selected && state.now?.watching ? '<span class="pill mint">ON TV</span>' : '<span class="pill">LIVE</span>'}</button>`).join('') || '<div class="empty">No channels here.</div>');
|
||||
}
|
||||
function pickSheet(n) {
|
||||
const c = state.guide?.channels.find(c => c.number === n); if (!c) return '';
|
||||
return `<div class="title">${esc(c.now.title)}</div><div class="small">${c.number} ${esc(c.name)} · Live now · ends ${hm(c.now.endMs)}${c.now.sub ? ' · ' + esc(c.now.sub) : ''}</div>
|
||||
<div class="room" style="margin-top:12px"><span class="dot"></span>Watching on: <b>${esc(state.now?.room || 'this TV')}</b></div>
|
||||
<button class="btn gold" data-tune="${c.number}">Watch on this TV</button>
|
||||
<div class="small" style="margin-top:10px">Next at ${hm(c.next.startMs)}: ${esc(c.next.title)}</div>`;
|
||||
}
|
||||
function catchup() {
|
||||
const c = state.catchup; if (!c) return head('Catch Up') + '<div class="empty">Loading Catch Up…</div>';
|
||||
const shelves = c.shelves.filter(s => s.entries.length);
|
||||
if (!shelves.length) return head('Catch Up') + '<div class="empty">Nothing to catch up on yet. Programmes your channels show appear here for two days.</div>';
|
||||
return head('Catch Up') + shelves.map(s => `<div class="label">${esc(s.title)}</div>` + s.entries.map(e => `
|
||||
<button class="cu" data-cu="${e.number}:${e.startMs}"><div class="grow"><div class="what" style="font-weight:700">${esc(e.title)}</div>
|
||||
<div class="small">${e.sub ? esc(e.sub) + ' · ' : ''}${e.number} ${esc(e.channel)} · aired ${hm(e.startMs)}${e.continues ? ' · carries on' : ''}</div></div><span class="play">${I.play}</span></button>`).join('')).join('') +
|
||||
'<div class="small" style="text-align:center;margin-top:12px">Plays from the start on this TV, and carries on as it aired.</div>';
|
||||
}
|
||||
function rooms() {
|
||||
const r = state.rooms, n = state.now;
|
||||
let h = head('Rooms') + '<div class="small" style="margin-bottom:10px">Every Orbit in the house, on this Wi-Fi.</div>';
|
||||
h += `<div class="rm here"><h3>${esc(n?.room || 'This TV')}<span class="dot"></span></h3>
|
||||
<div class="small">${n?.channel ? `${n.watching ? 'Watching' : 'On'} ${esc(n.now.title)} · ${n.channel.number} ${esc(n.channel.name)}` : 'Orbit open'}</div>
|
||||
<div class="tags"><span>Online</span><span>This phone's TV</span></div></div>`;
|
||||
if (!r) return h + '<div class="empty">Looking for other rooms…</div>';
|
||||
h += r.online.map(o => `<div class="rm"><h3>${esc(o.name)}<span class="dot"></span></h3><div class="small">Orbit open</div>
|
||||
<div class="tags"><span>Online</span></div><a class="btn" href="http://${esc(o.address)}:8099/">Open its remote</a>
|
||||
<div class="small" style="margin-top:6px">Each TV connects a phone once, from its own Settings.</div></div>`).join('');
|
||||
h += r.asleep.map(a => `<div class="rm"><h3>${esc(a)}<span class="dot off"></span></h3><div class="small">Orbit closed</div><div class="tags"><span>Asleep</span></div></div>`).join('');
|
||||
if (!r.online.length && !r.asleep.length) h += '<div class="empty">No other rooms yet. Add one from Settings › Rooms and phones on the TV.</div>';
|
||||
return h;
|
||||
}
|
||||
function more() {
|
||||
return head('More') + `<div class="label">Your channels</div>
|
||||
<a class="line" href="/create" style="text-decoration:none;color:inherit">Create a channel <span>Name, shows, style, hours</span></a>
|
||||
<div class="label">Look</div><div class="card small">This phone wears the TV's look${state.now?.look ? ': <b style="color:var(--ink)">' + esc(state.now.look.name) + '</b>' : ''}. Change it on the TV in Settings › Look.</div>
|
||||
<div class="label">About</div><div class="card small">Orbit Companion runs on the TV itself, over your home Wi-Fi. Nothing to install, no account. It works while Orbit is open on the TV.
|
||||
To stop this phone, remove it in Settings › Rooms and phones.</div>`;
|
||||
}
|
||||
function render() {
|
||||
tabs();
|
||||
$('#app').innerHTML = ({remote, guide, catchup, rooms, more})[tab]();
|
||||
}
|
||||
function openSheet(html) { $('#sheetIn').innerHTML = html; $('#sheet').classList.add('open'); $('#shade').classList.add('open'); }
|
||||
function closeSheet() { $('#sheet').classList.remove('open'); $('#shade').classList.remove('open'); }
|
||||
$('#shade').onclick = closeSheet;
|
||||
|
||||
async function load(what) {
|
||||
try {
|
||||
if (what === 'now') { const n = await api('/api/now'); skew = n.serverMs - Date.now(); look(n.look); state.now = n; }
|
||||
if (what === 'guide') state.guide = await api('/api/guide');
|
||||
if (what === 'catchup') state.catchup = await api('/api/catchup');
|
||||
if (what === 'rooms') state.rooms = await api('/api/rooms');
|
||||
offline = false;
|
||||
} catch (e) { if (!offline) toast(e.message === 'Failed to fetch' ? "Orbit isn't open on the TV" : e.message); offline = true; }
|
||||
render();
|
||||
}
|
||||
let offline = false;
|
||||
const send = (path, body, done) => { buzz(); api(path, body).then(j => { done?.(j); setTimeout(() => load('now'), 600); }).catch(e => toast(e.message === 'Failed to fetch' ? "Orbit isn't open on the TV" : e.message)); };
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
const b = e.target.closest('button,[data-tab]'); if (!b) return;
|
||||
const d = b.dataset;
|
||||
if (d.tab) { tab = d.tab; try { localStorage.setItem('orbit.tab', tab); } catch {} closeSheet(); render(); if (tab !== 'remote' && tab !== 'more') load(tab); return; }
|
||||
if (d.key) send('/api/key', {key: d.key});
|
||||
if (d.vol) send('/api/volume', {change: d.vol});
|
||||
if (d.ch) send('/api/channel', {step: +d.ch});
|
||||
if (d.sheet) openSheet(moreControls());
|
||||
if (d.go) send('/api/section', {section: d.go}, () => { closeSheet(); toast('On the TV now'); });
|
||||
if (d.filter) { state.filter = d.filter; render(); }
|
||||
if (d.pick) openSheet(pickSheet(+d.pick));
|
||||
if (d.tune) send('/api/tune', {number: +d.tune}, () => { closeSheet(); toast('Watching on the TV'); setTimeout(() => load('guide'), 700); });
|
||||
if (d.cu) { const [number, startMs] = d.cu.split(':').map(Number); send('/api/catchup/watch', {number, startMs}, () => toast('Playing from the start on the TV')); }
|
||||
});
|
||||
render(); load('now'); if (tab !== 'remote' && tab !== 'more') load(tab);
|
||||
// Kept fresh while the phone is looking: what's on every 15 seconds, and the open list every minute.
|
||||
setInterval(() => { if (!document.hidden) load('now'); }, 15000);
|
||||
setInterval(() => { if (!document.hidden && ['guide','catchup','rooms'].includes(tab)) load(tab); }, 60000);
|
||||
document.addEventListener('visibilitychange', () => { if (!document.hidden) load('now'); });
|
||||
</script>
|
||||
</body></html>
|
||||
Reference in New Issue
Block a user