« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/socket.js
diff options
context:
space:
mode:
Diffstat (limited to 'socket.js')
-rw-r--r--socket.js31
1 files changed, 25 insertions, 6 deletions
diff --git a/socket.js b/socket.js
index 53dd4b9..f20edae 100644
--- a/socket.js
+++ b/socket.js
@@ -435,12 +435,6 @@ 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.
@@ -621,6 +615,16 @@ 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
@@ -676,6 +680,14 @@ 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
@@ -787,6 +799,13 @@ 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',