« get me outta code hell

support stop-playing over client sockets - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-07-12 17:56:33 -0300
committerFlorrie <towerofnix@gmail.com>2020-07-12 17:57:07 -0300
commit1230a2cfac4b0d907631eddb4d0dc798f5bb3564 (patch)
tree47cf02cf7c9651699c7124d799266f3423141bfb
parent1db8576654d43978426a6f3703df532a688872d1 (diff)
support stop-playing over client sockets
-rw-r--r--backend.js1
-rw-r--r--socket.js10
2 files changed, 11 insertions, 0 deletions
diff --git a/backend.js b/backend.js
index 573a4fc..20aec7d 100644
--- a/backend.js
+++ b/backend.js
@@ -523,6 +523,7 @@ class QueuePlayer extends EventEmitter {
       this.playingTrack = null
       this.timeData = null
       this.time = null
+      this.emit('playing details', null, oldTrack, this)
       this.emit('playing', null, oldTrack, this)
     }
   }
diff --git a/socket.js b/socket.js
index acc1a21..ab23a28 100644
--- a/socket.js
+++ b/socket.js
@@ -162,6 +162,8 @@ function validateCommand(command) {
             ) ||
             command.status === 'sync-playback'
           )
+        case 'stop-playing':
+          return typeof command.queuePlayer === 'string'
         case 'unqueue':
           return (
             typeof command.queuePlayer === 'string' &&
@@ -450,6 +452,9 @@ function attachBackendToSocketClient(backend, client, {
             }, command.startingTrack ? 500 : 0)
             return
           }
+          case 'stop-playing':
+            if (QP) silenceEvents(QP, ['playing'], () => QP.stopPlaying())
+            return
           case 'unqueue':
             if (QP) silenceEvents(QP, ['unqueue'], () => QP.unqueue(
               restoreNewItem(command.topItem, getPlaylistSources())
@@ -506,6 +511,11 @@ function attachBackendToSocketClient(backend, client, {
           queuePlayer: queuePlayer.id
         })
       })
+    } else {
+      client.sendCommand({
+        code: 'stop-playing',
+        queuePlayer: queuePlayer.id
+      })
     }
   })