« get me outta code hell

WIP socket shenanigans [!!!] - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/backend.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-15 16:06:04 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 22:29:28 -0300
commitbb96788a3ab48776229985ca0a02f9c5c124b65a (patch)
tree7fab8749efb6f00f9448319c5011dd0183f930cc /backend.js
parent9a1d0c26338a7d0851c60b99296669cdc80673f2 (diff)
WIP socket shenanigans [!!!]
this commit is mostly trash lol

[!!!] Editor's note: Okay, after rebasing this commit is *super*
spooky! It's interacting with a bunch of stuff that was previously
handled in a merge commit and the revised changes may or may not
be totally broken. If in doubt, assume this commit is the root
of all evil (probably).
Diffstat (limited to 'backend.js')
-rw-r--r--backend.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/backend.js b/backend.js
index 93de487..ffa620a 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