« get me outta code hell

basic party sources creation for other sockets - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-04-23 12:18:18 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 22:00:51 -0300
commit897673852bac805c9c7a129ffc426ad27e0d9b3e (patch)
tree30b2b67be6b0586557b48ec1ace08d6d431f2fdd
parent8a44b3c4088a1d3a6720f1d9c47627d50d5ef39c (diff)
basic party sources creation for other sockets
-rw-r--r--backend.js4
-rwxr-xr-xindex.js2
-rw-r--r--socket.js31
3 files changed, 30 insertions, 7 deletions
diff --git a/backend.js b/backend.js
index dea4429..39f2225 100644
--- a/backend.js
+++ b/backend.js
@@ -891,6 +891,10 @@ export default class Backend extends EventEmitter {
     this.emit('log message', messageInfo)
   }
 
+  setPartyNickname(nickname) {
+    this.emit('set party nickname', nickname)
+  }
+
   announceJoinParty() {
     this.emit('announce join party')
   }
diff --git a/index.js b/index.js
index 79b940e..ec79f05 100755
--- a/index.js
+++ b/index.js
@@ -209,7 +209,7 @@ async function main() {
     if (options['socket-name']) {
       nickname = options['socket-name']
     }
-    socketClient.setNickname(nickname)
+    backend.setPartyNickname(nickname)
     backend.announceJoinParty()
   }
 
diff --git a/socket.js b/socket.js
index 1cd6c35..1e25e6c 100644
--- a/socket.js
+++ b/socket.js
@@ -428,12 +428,6 @@ export function makeSocketClient() {
     client.emit('sent-command', command)
   }
 
-  client.setNickname = function(nickname) {
-    let oldNickname = client.nickname
-    client.nickname = nickname
-    client.sendCommand({code: 'set-nickname', nickname, oldNickname})
-  }
-
   client.socket.on('data', perLine(line => {
     // Same sort of "guarding" deserialization/validation as in the server
     // code, because it's possible the client and server backends mismatch.
@@ -614,6 +608,16 @@ export function attachBackendToSocketClient(backend, client, {
         )
 
         switch (command.code) {
+          case 'announce-join': {
+            const partyGrouplike = {
+              name: `Party Sources - ${command.senderNickname}`,
+              isPartySources: true,
+              items: []
+            }
+            partyGrouplikeMap[command.senderSocketId] = partyGrouplike
+            backend.loadPartyGrouplike(command.senderSocketId, partyGrouplike)
+            return
+          }
           case 'clear-queue':
             if (QP) silenceEvents(QP, ['clear-queue'], () => QP.clearQueue())
             return
@@ -669,6 +673,14 @@ export function attachBackendToSocketClient(backend, client, {
           case 'seek-to':
             if (QP) silenceEvents(QP, ['seek-to'], () => QP.seekTo(command.time))
             return
+          case 'set-nickname': {
+            const partyGrouplike = partyGrouplikeMap[command.senderSocketId]
+            if (partyGrouplike) {
+              partyGrouplike.name = `Party Sources - ${command.senderNickname}`
+              backend.partyGrouplikeUpdated(client.socketId, partyGrouplike)
+            }
+            return
+          }
           case 'set-pause': {
             // TODO: there's an event leak here when toggling pause while
             // nothing is playing
@@ -780,6 +792,13 @@ export function attachBackendToSocketClient(backend, client, {
   backend.on('seek-back', handleSeek)
   backend.on('seek-to', handleSeek)
 
+  backend.on('set party nickname', nickname => {
+    let oldNickname = client.nickname
+    partyGrouplike.name = `Party Sources - ${nickname}`
+    client.nickname = nickname
+    client.sendCommand({code: 'set-nickname', nickname, oldNickname})
+  })
+
   backend.on('shuffle-queue', queuePlayer => {
     client.sendCommand({
       code: 'restore-queue',