From b47f2968742b77378791f171c819957546b4fc7d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 22 Apr 2021 20:06:58 -0300 Subject: "party sources" ui (no socket functionality yet) --- socket.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'socket.js') diff --git a/socket.js b/socket.js index c6c3d19..5f3ded0 100644 --- a/socket.js +++ b/socket.js @@ -40,6 +40,8 @@ import { // clients / the server otherwise. const DEFAULT_NICKNAME = '(Unnamed)' +const originalSymbol = Symbol('Original item') + function serializeCommandToData(command) { // Turn a command into a string/buffer that can be sent over a socket. return JSON.stringify(command) @@ -422,8 +424,11 @@ export function attachBackendToSocketClient(backend, client, { // All actual logic for instances of the mtui backend interacting with each // other through commands lives here. + const partyGrouplike = {name: 'My Party Sources', isPartySources: true, items: []} + backend.setAlwaysStartPaused(true) backend.setWaitWhenDonePlaying(true) + backend.loadPartyGrouplike(partyGrouplike) function logCommand(command) { const nickToMessage = nickname => `\x1b[32;1m${nickname}\x1b[0m` @@ -744,6 +749,27 @@ export function attachBackendToSocketClient(backend, client, { topItem: saveItemReference(topItem) }) }) + + backend.on('share with party', origItem => { + let newItem = { + ...origItem, + [parentSymbol]: partyGrouplike, + [originalSymbol]: origItem + } + + if (isGroup(newItem)) { + newItem = updateGroupFormat(newItem) + } else if (isTrack(newItem)) { + newItem = updateTrackFormat(newItem) + } else { + return + } + + if (partyGrouplike.items.every(x => x[originalSymbol] !== origItem)) { + partyGrouplike.items.push(newItem) + backend.partyGrouplikeUpdated(partyGrouplike) + } + }) } export function attachSocketServerToBackend(server, backend) { -- cgit 1.3.0-6-gf8a5