Skip to content

Commit 312fb56

Browse files
Merge branch 'default' into assets
2 parents ce412a5 + 4ebb71e commit 312fb56

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
"@types/express": "^4.17.11",
8686
"@types/has": "^1.0.0",
8787
"@types/htmlescape": "^1.1.1",
88-
"@types/http-errors": "^1.8.0",
89-
"@types/ioredis": "^4.22.1",
88+
"@types/http-errors": "^2.0.0",
89+
"@types/ioredis": "^5.0.0",
9090
"@types/json-merge-patch": "^0.0.8",
9191
"@types/jsonwebtoken": "^8.5.1",
9292
"@types/lodash": "^4.14.168",

src/plugins/booth.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Booth {
4343

4444
#locker;
4545

46+
/** @type {Promise<unknown>|null} */
47+
#awaitAdvance = null;
48+
4649
/**
4750
* @param {import('../Uwave')} uw
4851
*/
@@ -62,19 +65,28 @@ class Booth {
6265
const endTime = Number(current.playedAt) + duration;
6366
if (endTime > Date.now()) {
6467
this.#timeout = setTimeout(
65-
() => this.advance(),
68+
() => this.#advanceAutomatically(),
6669
endTime - Date.now(),
6770
);
6871
} else {
69-
this.advance();
72+
this.#advanceAutomatically();
7073
}
7174
}
7275

73-
/** @type {import('../Uwave').Boot} */ (this.#uw).onClose(() => {
76+
/** @type {import('../Uwave').Boot} */ (this.#uw).onClose(async () => {
7477
this.#onStop();
78+
await this.#awaitAdvance;
7579
});
7680
}
7781

82+
async #advanceAutomatically() {
83+
try {
84+
await this.advance();
85+
} catch (error) {
86+
this.#logger.error({ err: error }, 'advance failed');
87+
}
88+
}
89+
7890
#onStop() {
7991
this.#maybeStop();
8092
}
@@ -237,7 +249,7 @@ class Booth {
237249
#play(entry) {
238250
this.#maybeStop();
239251
this.#timeout = setTimeout(
240-
() => this.advance(),
252+
() => this.#advanceAutomatically(),
241253
(entry.media.end - entry.media.start) * 1000,
242254
);
243255
}
@@ -316,6 +328,7 @@ class Booth {
316328
* @typedef {object} AdvanceOptions
317329
* @prop {boolean} [remove]
318330
* @prop {boolean} [publish]
331+
* @prop {import('redlock').RedlockAbortSignal} [signal]
319332
*
320333
* @param {AdvanceOptions} [opts]
321334
* @returns {Promise<PopulatedHistoryEntry|null>}
@@ -341,6 +354,10 @@ class Booth {
341354
throw err;
342355
}
343356

357+
if (opts.signal?.aborted) {
358+
throw opts.signal.error;
359+
}
360+
344361
if (previous) {
345362
await this.#saveStats(previous);
346363

@@ -391,7 +408,13 @@ class Booth {
391408
* @returns {Promise<PopulatedHistoryEntry|null>}
392409
*/
393410
advance(opts = {}) {
394-
return this.#locker.using(['booth:advancing'], 10_000, () => this.#advanceLocked(opts));
411+
const result = this.#locker.using(
412+
['booth:advancing'],
413+
10_000,
414+
(signal) => this.#advanceLocked({ ...opts, signal }),
415+
);
416+
this.#awaitAdvance = result;
417+
return result;
395418
}
396419
}
397420

test/playlists.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ describe('Playlists', () => {
4747
sourceID: id,
4848
artist: `artist ${id}`,
4949
title: `title ${id}`,
50-
start: 0,
51-
end: 60,
50+
duration: 60,
5251
}));
5352
},
5453
async search() {

test/waitlist.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ describe('Waitlist', () => {
1515
uw.source({
1616
name: 'test-source',
1717
api: 2,
18-
async get(context, ids) {
18+
async get(_context, ids) {
1919
return ids.map((id) => ({
2020
sourceID: id,
2121
artist: `artist ${id}`,
2222
title: `title ${id}`,
23-
start: 0,
24-
end: 60,
23+
duration: 60,
2524
}));
2625
},
2726
async search() {
@@ -76,7 +75,7 @@ describe('Waitlist', () => {
7675
});
7776
});
7877

79-
describe.skip('POST /waitlist', () => {
78+
describe('POST /waitlist', () => {
8079
it('requires authentication', async () => {
8180
await supertest(uw.server)
8281
.post('/api/waitlist')

0 commit comments

Comments
 (0)