Up Next: a queue that plays on by itself (#473)

Playing was one episode at a time: when one ended nothing followed. Up Next
is a per-account queue on the server (table `queue`, GET and PUT
/api/queue), so the phone and the browser share it. The page adds to it from
a row or the reader, reorders it by drag or arrow keys, and plays the next
when one ends; what is playing leaves it as it starts, as Overcast's does. An
episode 90% played leaves it on the server too, which covers the phone
playing on while the page is frozen.

The iOS app is told what follows (`{t:'next'}`, gated on the app saying it
can) and starts it at the end of an episode; the page takes it up through
nowPlaying as it does the car's pick. The Swift is not compiled here.

The page stub answered every unknown address with [], whose `.entries` is
Array.prototype.entries, so the queue read a function as its list; it now
answers /api/queue as an entry list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 14:31:40 +00:00
parent 2ebe77b21e
commit c65b80a06c
24 changed files with 445 additions and 41 deletions

View File

@@ -115,6 +115,14 @@ function wireDeviceSettings(){
$<HTMLButtonElement>('#sptokenclear').onclick=()=>host({t:'clearToken'});
}
/// An episode as the phone's player takes it, to play now (`load`) or after this one (`next`).
function hostItem(e: Entry|null, enc: {id: number}, url: string){
return {url, enc:enc.id, feedId:e?.feed_id ?? player.feed, guid:e?.guid ?? player.guid,
title:e ? entryName(e).text : '', feedTitle:feedName(e?.feed_id ?? player.feed),
artwork:(e && e.image) || feedArt(e?.feed_id ?? player.feed) || null,
position:(e && e.position) || 0, duration:(e && e.duration) || null};
}
function installNativePlayback(){
const post = ipxHost!;
const M = HTMLMediaElement.prototype;
@@ -165,15 +173,10 @@ function installNativePlayback(){
realPause.call(audio);
realRemoveAttribute('src');
realLoad.call(audio);
const e = player.entry, f = player.feed;
post({t:'load', url:v, enc:player.enc, feedId:f, guid:player.guid,
title:e ? entryName(e).text : '', feedTitle:feedName(f),
artwork:(e && e.image) || feedArt(f) || null,
// Where the host starts is not this: the seek to where you left off is player.ts's, on
// loadedmetadata, so one piece of code decides it. This is for the host's now-playing
// display before the file has loaded.
position:(e && e.position) || 0, duration:(e && e.duration) || null,
rate:audio.playbackRate, volume:audio.volume});
// Where the host starts is not the position in it: the seek to where you left off is
// player.ts's, on loadedmetadata, so one piece of code decides it. That is for the host's
// now-playing display before the file has loaded.
post({t:'load', ...hostItem(player.entry, {id:player.enc!}, v), rate:audio.playbackRate, volume:audio.volume});
},
});
@@ -222,6 +225,9 @@ function installNativePlayback(){
// Not moved: nothing here played it, so there is no place of the page's own to save.
player.guid=m.guid; player.feed=m.feedId; player.entry=e; player.enc=m.enc;
player.src=enc?mediaSrc(enc):undefined; player.moved=false; player.marked=false; player.saveAt=m.cur||0;
// The phone went on to the next in Up Next by itself (#473): it is under way, so out of it.
const was=upNext.find(x=>x.guid===m.guid&&x.feed_id===m.feedId);
if(was){ player.entry=e||was; startedPlaying(was); }
$('#partwrap').innerHTML=artHTML(m.artwork||feedArt(m.feedId),feedName(m.feedId));
$('#ptitle').textContent=m.title||'';
$('#pfeed').textContent=m.feedTitle||'';
@@ -262,7 +268,7 @@ function installNativePlayback(){
// Not playback's, so not gated on it: the app says what it keeps whether or not it plays.
if(m.t==='kept'||m.t==='keepFailed'){ hostKept(m); return; }
// Sent at ready, so a page newer than the app offers only what the app can do.
if(m.t==='host'){ hostCan.clear(); for(const c of m.can||[]) hostCan.add(c); paintRoute(); return; }
if(m.t==='host'){ hostCan.clear(); for(const c of m.can||[]) hostCan.add(c); paintRoute(); hostNext(); return; }
if(m.t==='sleep'||m.t==='slept'){ hostSleep(m); return; }
if(m.t==='push'){ hostPush(m); return; }
if(m.t==='appSettings'){ hostAppSettings(m); return; }