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

@@ -75,7 +75,7 @@ function makeContext(html: string, script: string, { media = false } = {}) {
: /\/api\/(popular|directory)/.test(String(url))
? [{ id: 'f', title: 'A Feed', image: null, subscribers: 2, subscribed: true },
{ id: 'g', title: null, image: null, subscribers: 1, subscribed: false }]
: /entries/.test(String(url)) ? { total: 0, entries: [] } : []),
: /entries|\/api\/queue/.test(String(url)) ? { total: 0, entries: [] } : []),
}),
EventSource: class { close() {} },
MediaMetadata: class {},

View File

@@ -230,6 +230,21 @@ ctx.window.ipxNative.on({ t: 'nowPlaying', feedId: 'f', guid: 'g2', enc: 7, titl
playing: false, cur: 130 });
ok(audio.paused === true && audio.currentTime === 130, 'told again on coming forward, the bar did not follow');
// Up Next (#473): the app is told what follows, to play it with the screen locked, and taking it
// up from nowPlaying takes it out of Up Next.
const queued = { feed_id: 'f', guid: 'n1', title: 'Next One', position: 0, duration: 60, image: null,
enclosures: [{ id: 9, mime: 'audio/mpeg', path: '/n.mp3', url: 'http://x/n.mp3' }] };
since();
vm.runInContext(`upNext=[${JSON.stringify(queued)}]; hostNext()`, ctx);
ok(!last('next'), 'an app that never said it can was told what follows');
ctx.window.ipxNative.on({ t: 'host', can: ['next'] });
ok(last('next')?.guid === 'n1' && last('next')?.enc === 9 && last('next')?.url === '/media/9', 'the app was not told what plays next');
ctx.window.ipxNative.on({ t: 'nowPlaying', feedId: 'f', guid: 'n1', enc: 9, title: 'Next One', feedTitle: 'A Feed',
playing: true, cur: 0, dur: 60 });
ok(vm.runInContext('player.guid', ctx) === 'n1', 'the bar did not take up the next one');
ok(vm.runInContext('upNext.length', ctx) === 0, 'the one under way is still in Up Next');
ok(!!last('next') && !last('next')?.guid, 'the app was not told nothing follows');
if (failed) { console.error(`\n${failed} failed`); process.exit(1); }
console.log('OK: native-bridge: the host takes playback, keeping, the sleep timer and haptics, and the page follows it');
console.log('OK: native-bridge: the host takes playback, keeping, the sleep timer, haptics and Up Next, and the page follows it');
process.exit(0);

View File

@@ -389,3 +389,13 @@ test('wireDecode reads protobuf into what the JSON would have been (#470)', () =
assert.equal(run(`wireType('application/x-protobuf; messageType=ipx.FeedRows')`), 'ipx.FeedRows');
assert.equal(run(`wireType('application/json')`), undefined);
});
test('nextUp is the first in Up Next that can play, passing over the one playing', () => {
const ep = (guid: string, path: string | null) =>
({ feed_id: 'f', guid, enclosures: [{ id: 1, mime: 'audio/mpeg', path, url: 'http://x/a.mp3' }] });
const list = JSON.stringify([ep('a', '/a.mp3'), ep('b', null), ep('c', '/c.mp3')]);
assert.equal(run(`nextUp(${list}, null)?.guid`), 'a');
assert.equal(run(`nextUp(${list}, 'f\\na')?.guid`), 'c', 'b is not downloaded yet');
assert.equal(run(`nextUp(${list}, 'f\\nc')?.guid`), 'a');
assert.equal(run(`nextUp([], null)`), undefined);
});

View File

@@ -425,6 +425,43 @@ test('Currently Listening, its own place below the Directory, resumes an episode
await expect(row.locator('.eq')).toBeHidden();
});
test('Up Next lines episodes up, moves them, and plays the next when one ends (#473)', async ({ page }) => {
await page.evaluate(() => saveUpNext([]));
await page.locator('.feed', { hasText: 'Test Show' }).click();
for (const name of ['First Episode', 'Second Episode']) {
const ep = page.locator('#eps .ep', { hasText: name });
await ep.hover();
await ep.locator('[data-a=queue]').click();
await expect(ep.locator('[data-a=queue]')).toHaveAttribute('aria-pressed', 'true');
}
const place = page.locator('#feedlist .place', { hasText: 'Up Next' });
await expect(place.locator('.badge')).toHaveText('2');
await place.click();
const rows = page.locator('#listening .childrow .txt b');
await expect(rows).toHaveText(['First Episode', 'Second Episode']);
// Moved by its handle's arrow keys, and kept so on the server.
await page.locator('#listening .childrow', { hasText: 'Second Episode' }).locator('.grip').press('ArrowUp');
await expect(rows).toHaveText(['Second Episode', 'First Episode']);
await expect.poll(() => page.evaluate(async () => (await api('/api/queue')).entries.map((e: Entry) => e.guid)))
.toEqual(['ui-2', 'ui-1']);
// Playing one takes it out; the end of it plays the next.
await page.locator('#listening .childrow', { hasText: 'Second Episode' }).click();
await expect(page.locator('#ptitle')).toHaveText('Second Episode');
await expect(rows).toHaveText(['First Episode']);
await expect(page.locator('#pnext')).toBeVisible();
// The fixture files are not real audio, so the end is said rather than played to.
await page.evaluate(() => audio.dispatchEvent(new Event('ended')));
await expect(page.locator('#ptitle')).toHaveText('First Episode', { timeout: 20_000 });
await expect(page.locator('#listening')).toContainText('Nothing lined up');
await expect(page.locator('#pnext')).toBeHidden();
await page.locator('#pclose').click();
await page.evaluate(() => api('/api/entries/test-show/ui-1/position', { method: 'POST', body: JSON.stringify({ secs: 0 }) }));
await page.evaluate(() => api('/api/entries/test-show/ui-2/position', { method: 'POST', body: JSON.stringify({ secs: 0 }) }));
});
test('a player nobody has played since it last saved does not save again', async ({ page }) => {
// A tab left paused at 41:15 saved that as it reloaded, over the 32:48 another had reached,
// and the episode dropped out of Currently Listening. The fixture audio does not decode, so