From 8a44b3c4088a1d3a6720f1d9c47627d50d5ef39c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 23 Apr 2021 11:59:59 -0300 Subject: announce joining party --- socket.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'socket.js') diff --git a/socket.js b/socket.js index 42f4057..1cd6c35 100644 --- a/socket.js +++ b/socket.js @@ -111,6 +111,8 @@ function validateCommand(command) { // clients too. case 'client': switch (command.code) { + case 'announce-join': + return true case 'clear-queue': return typeof command.queuePlayer === 'string' case 'clear-queue-past': @@ -252,6 +254,7 @@ export function makeSocketServer() { socketMap[socketId] = socket + let hasAnnouncedJoin = false let nickname = DEFAULT_NICKNAME socket.on('close', () => { @@ -278,6 +281,18 @@ export function makeSocketServer() { return } + // If the socket hasn't announced its joining yet, it only has access to + // a few commands. + + if (!hasAnnouncedJoin) { + if (![ + 'announce-join', + 'set-nickname' + ].includes(command.code)) { + return + } + } + // If it's a status command, respond appropriately, and return so that it // is not relayed. @@ -357,6 +372,13 @@ export function makeSocketServer() { nickname = command.nickname } + // If the socket hasn't announced its joining yet - and this isn't the + // command where it does so - don't relay the command. + + if (!hasAnnouncedJoin && command.code !== 'announce-join') { + return + } + // Relay the command to client sockets besides the sender. const otherSockets = Object.values(socketMap).filter(s => s !== socket) @@ -439,6 +461,8 @@ export function attachBackendToSocketClient(backend, client, { // All actual logic for instances of the mtui backend interacting with each // other through commands lives here. + let hasAnnouncedJoin = false + const partyGrouplike = { name: `Party Sources - ${client.nickname}`, isPartySources: true, @@ -447,6 +471,7 @@ export function attachBackendToSocketClient(backend, client, { const partyGrouplikeMap = Object.create(null) + backend.setHasAnnouncedJoin(false) backend.setAlwaysStartPaused(true) backend.setWaitWhenDonePlaying(true) @@ -467,6 +492,9 @@ export function attachBackendToSocketClient(backend, client, { let isVerbose = false switch (command.code) { + case 'announce-join': + actionmsg = `joined the party` + break case 'clear-queue': actionmsg = 'cleared the queue' break @@ -777,6 +805,12 @@ export function attachBackendToSocketClient(backend, client, { }) }) + backend.on('announce join party', () => { + client.sendCommand({ + code: 'announce-join' + }) + }) + backend.on('share with party', origItem => { let newItem = { ...origItem, -- cgit 1.3.0-6-gf8a5