From fdc5961a4b8423ffe5e6e4939f9f709f8e7e34c9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 15 May 2023 16:06:04 -0300 Subject: WIP socket shenanigans this commit is mostly trash lol --- backend.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 232d912..c04f4a9 100644 --- a/backend.js +++ b/backend.js @@ -11,7 +11,7 @@ import shortid from 'shortid' import {getDownloaderFor} from './downloaders.js' import {getMetadataReaderFor} from './metadata-readers.js' -import {getPlayer} from './players.js' +import {getPlayer, GhostPlayer} from './players.js' import RecordStore from './record-store.js' import { @@ -381,12 +381,6 @@ class QueuePlayer extends EventEmitter { throw new Error('Attempted to play before a player was loaded') } - let playingThisTrack = true - this.emit('playing new track') - this.once('playing new track', () => { - playingThisTrack = false - }) - // If it's a group, play the first track. if (isGroup(item)) { item = flattenGrouplike(item).items[0] @@ -402,13 +396,18 @@ class QueuePlayer extends EventEmitter { return } - playTrack: { + let playingThisTrack = true + this.emit('playing new track') + this.once('playing new track', () => { + playingThisTrack = false + }) + + if (this.player instanceof GhostPlayer) { + await this.#ghostPlay(item, startTime) + } else if (!item.downloaderArg) { // No downloader argument? That's no good - stop here. // TODO: An error icon on this item, or something??? - if (!item.downloaderArg) { - break playTrack - } - + } else { // If, by the time the track is downloaded, we're playing something // different from when the download started, assume that we just want to // keep listening to whatever new thing we started. @@ -452,6 +451,17 @@ class QueuePlayer extends EventEmitter { } } + async #ghostPlay(item, startTime) { + // If we're playing off a GhostPlayer, strip down the whole process. + // Downloading is totally unnecessary, for example. + + this.timeData = null + this.time = null + this.playingTrack = item + this.emit('playing', this.playingTrack) + await this.player.playFile('-', startTime) + } + playNext(track, automaticallyQueueNextTrack = false) { if (!track) return false -- cgit 1.3.0-6-gf8a5