Skip to content

Commit 369f2a0

Browse files
committed
fix(player): Check for 0 duration before finalizing listen session with duration-based calculation
1 parent 8adc28a commit 369f2a0

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/backend/sources/PlayerState/PositionalPlayerState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class PositionalPlayerState extends AbstractPlayerState {
9090
duration,
9191
} = {}
9292
} = this.currentPlay;
93-
if(duration !== undefined && (duration - this.currentListenRange.end.position) < this.gracefulEndBuffer) {
93+
if(duration !== undefined && duration !== 0 && (duration - this.currentListenRange.end.position) < this.gracefulEndBuffer) {
9494
// likely the track was listened to until it ended
9595
// but polling interval or network delays caused MS to not get data on the very end
9696
// also...within 3 seconds of ending is close enough to call this complete IMO

src/backend/tests/player/player.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ describe('Player listen ranges', function () {
234234
assert.equal(player.getListenDuration(), 7);
235235
});
236236

237+
it('Listened for is track duration invariant', function () {
238+
const player = new TestPositionalPlayerState(logger, [NO_DEVICE, NO_USER]);
239+
240+
const positioned = clone(newPlay);
241+
positioned.data.duration = 0;
242+
243+
player.update(testState({play: positioned, position: 3, status: REPORTED_PLAYER_STATUSES.playing}));
244+
245+
player.currentListenRange.rtPlayer.setPosition(10000);
246+
player.update(testState({play: positioned, position: 10, status: REPORTED_PLAYER_STATUSES.playing}), dayjs().add(10, 'seconds'));
247+
248+
player.currentListenRange.rtPlayer.setPosition(20000);
249+
player.update(testState({play: positioned, position: 20, status: REPORTED_PLAYER_STATUSES.playing}), dayjs().add(20, 'seconds'));
250+
251+
const otherPlay = clone(positioned);
252+
otherPlay.data.track = "A New Track";
253+
player.currentListenRange.rtPlayer.setPosition(30000);
254+
const [currPlay, prevPlay] = player.update(testState({play: otherPlay, position: 2, status: REPORTED_PLAYER_STATUSES.playing}), dayjs().add(30, 'seconds'));
255+
256+
assert.isDefined(prevPlay);
257+
assert.equal(prevPlay.data.listenedFor, 17);
258+
});
259+
237260
it('Range ends if position over drifts', function () {
238261
const player = new TestPositionalPlayerState(logger, [NO_DEVICE, NO_USER]);
239262

0 commit comments

Comments
 (0)