« get me outta code hell

Experimental telnet server - 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:
authorFlorrie <towerofnix@gmail.com>2019-07-06 00:16:02 -0300
committerFlorrie <towerofnix@gmail.com>2019-07-06 11:23:55 -0300
commit8512c44b6403c126bf961c0fd0c2798d6bfdfcea (patch)
tree626ac64af2fb889fd7ec1a1032d14df5a87d4ad6 /backend.js
parentf96eeceefc94256babe016b0e18b95f0cf467880 (diff)
Experimental telnet server
Diffstat (limited to 'backend.js')
-rw-r--r--backend.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/backend.js b/backend.js
index c59121a..35362b3 100644
--- a/backend.js
+++ b/backend.js
@@ -175,6 +175,7 @@ class Backend extends EventEmitter {
     }
 
     recursivelyAddTracks(topItem)
+    this.emitQueueUpdated()
 
     // This is the first new track, if a group was queued.
     const newTrack = items[newTrackIndex]
@@ -249,6 +250,8 @@ class Backend extends EventEmitter {
         items.splice(insertIndex, 0, item)
       }
     }
+
+    this.emitQueueUpdated()
   }
 
   unqueue(topItem, focusItem = null) {
@@ -292,6 +295,7 @@ class Backend extends EventEmitter {
     }
 
     recursivelyUnqueueTracks(topItem)
+    this.emitQueueUpdated()
 
     return focusItem
   }
@@ -323,6 +327,7 @@ class Backend extends EventEmitter {
     const remainingItems = queue.items.slice(index)
     const newItems = initialItems.concat(shuffleArray(remainingItems))
     queue.items = newItems
+    this.emitQueueUpdated()
   }
 
   clearQueue() {
@@ -330,8 +335,12 @@ class Backend extends EventEmitter {
     // the track that's currently playing).
     this.queueGrouplike.items = this.queueGrouplike.items
       .filter(item => item === this.playingTrack)
+    this.emitQueueUpdated()
   }
 
+  emitQueueUpdated() {
+    this.emit('queue updated')
+  }
 
   seekAhead(seconds) {
     this.player.seekAhead(seconds)
@@ -369,11 +378,11 @@ class Backend extends EventEmitter {
     this.player.setVolume(value)
   }
 
-  stopPlaying() {
+  async stopPlaying() {
     // We emit this so playTrack doesn't immediately start a new track.
     // We aren't *actually* about to play a new track.
     this.emit('playing new track')
-    this.player.kill()
+    await this.player.kill()
     this.clearPlayingTrack()
   }