From 897673852bac805c9c7a129ffc426ad27e0d9b3e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 23 Apr 2021 12:18:18 -0300 Subject: basic party sources creation for other sockets --- backend.js | 4 ++++ index.js | 2 +- socket.js | 31 +++++++++++++++++++++++++------ 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', -- cgit 1.3.0-6-gf8a5