From f112f84c2f9f314dddb96eca74c90d8a74d2de52 Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Sun, 14 Dec 2025 16:50:41 +0100 Subject: [PATCH] debug dashboard --- backend/Board.js | 21 ++- backend/Client.js | 41 +++++- backend/Music.js | 9 ++ backend/Qr.js | 7 +- backend/Queue.js | 82 ++++++----- env.js | 7 +- package.json | 4 + pages/debug.html | 345 ++++++++++++++++++++++++++++++++++++++++++++++ pnpm-lock.yaml | 259 ++++++++++++++++++++++++++++++++++ server.js | 21 ++- 10 files changed, 751 insertions(+), 45 deletions(-) create mode 100644 pages/debug.html diff --git a/backend/Board.js b/backend/Board.js index eb59871..57bce41 100644 --- a/backend/Board.js +++ b/backend/Board.js @@ -2,11 +2,7 @@ import logger from '../logger.js' import Client from './Client.js' class Board { - static scores = { - '::1': 10, - '::2': 20, - '::3': 30, - } + static scores = {} static addPlayer(client) { if (this.scores[client.ip]) return @@ -47,6 +43,21 @@ class Board { } }) } + + static debug() { + return { + scores: Object.entries(this.scores).map(([ip, score]) => { + const client = Client.getBy.ip(ip) + return { + ip, + nick: client?.nick || '---', + score, + connected: client ? client.ws.readyState === 1 : false, + } + }), + totalPlayers: Object.keys(this.scores).length, + } + } } export default Board diff --git a/backend/Client.js b/backend/Client.js index 951c51e..078ee70 100644 --- a/backend/Client.js +++ b/backend/Client.js @@ -1,22 +1,44 @@ import logger from '../logger.js' import Board from './Board.js' import Music from './Music.js' +import { UAParser } from 'ua-parser-js' + +function getUA(req) { + const uaString = req.headers['user-agent'] || null + + if (uaString) { + const parser = new UAParser(uaString) + const result = parser.getResult() + return { + raw: uaString, + browser: result.browser.name ? `${result.browser.name} ${result.browser.version || ''}`.trim() : null, + os: result.os.name ? `${result.os.name} ${result.os.version || ''}`.trim() : null, + device: result.device.type || 'desktop', + } + } +} class Client { static list = [] static listeners = new Map() type = null + nick = null + ip = null + ws = null + userAgent = null constructor(ws, req) { this.ws = ws ws.client = this this.ip = req.socket.remoteAddress + this.userAgent = getUA(req) logger.debug('Client', 'up', this.ip) Client.list.push(this) + Client.emit('debug') ws.on('close', () => { logger.debug('Client', 'down', this.ip) @@ -29,6 +51,8 @@ class Client { listeners.filter(listener => listener.who !== this) ) }) + + Client.emit('debug') }) ws.on('message', data => { @@ -57,7 +81,7 @@ class Client { } handleRegistration(clientType) { - const validTypes = ['tv', 'host', 'player'] + const validTypes = ['tv', 'host', 'player', 'debug'] if (!validTypes.includes(clientType)) return this.type = clientType @@ -73,6 +97,8 @@ class Client { action: 'metadata', data: Music.metadata, }) + } else if (this.type == 'debug') { + Client.emit('update') } } @@ -113,6 +139,19 @@ class Client { type: type => Client.list.filter(client => client.type == type), } } + + static debug() { + return { + clients: Client.list.map(client => ({ + ip: client.ip, + type: client.type, + nick: client.nick || null, + userAgent: client.userAgent, + connected: client.ws.readyState === 1, + })), + totalClients: Client.list.length, + } + } } export default Client diff --git a/backend/Music.js b/backend/Music.js index c93269b..d1761ec 100644 --- a/backend/Music.js +++ b/backend/Music.js @@ -240,6 +240,15 @@ class Music { static emit(payload) { this.listeners.forEach(callback => callback(payload)) } + + static debug() { + return { + status: this.status, + metadata: this.metadata, + platform: this.#platform, + listenerCount: this.listeners.size, + } + } } export default Music diff --git a/backend/Qr.js b/backend/Qr.js index d81b29d..2a95e9d 100644 --- a/backend/Qr.js +++ b/backend/Qr.js @@ -7,9 +7,9 @@ export default class Qr { static #host = null static init(host) { - this.#host = host - logger.info('Qr', 'host for qr', host) - if (!host) logger.warn('env', 'SERVER_HOST is not defined, QR codes will not be generated') + if (!host) return logger.warn('env', 'SERVER_HOST is not defined, QR codes will not be generated') + this.#host = host + logger.info('Qr', 'host for qr', host) } static serve() { @@ -18,6 +18,7 @@ export default class Qr { try { if (this.host === null) { + res.status(500).send('QR code generation is not configured') throw new Error('SERVER_HOST is not defined') } diff --git a/backend/Queue.js b/backend/Queue.js index d71ffcb..54810f2 100644 --- a/backend/Queue.js +++ b/backend/Queue.js @@ -1,47 +1,67 @@ import logger from '../logger.js' class Queue { - static array = [] - static active = null + static array = [] + static active = null - static add(client) { - if (this.isClientInQueue(client)) { - // if (Music.status == 'playing') this.active++ - return - } + static add(client) { + if (this.isClientInQueue(client)) { + // if (Music.status == 'playing') this.active++ + return + } - if (this.isEmpty) this.active = 0 - this.array.push(client) + if (this.isEmpty) this.active = 0 + this.array.push(client) - logger.debug('Queue', `client added to queue`, client.ip) - } + logger.debug('Queue', `client added to queue`, client.ip) + } - static get isEmpty() { - return this.array.length == 0 - } + static get isEmpty() { + return this.array.length == 0 + } - static isClientInQueue(client) { - return this.array.some(c => c.ip === client.ip) - } + static isClientInQueue(client) { + return this.array.some(c => c.ip === client.ip) + } - static clear() { - this.array = [] - this.active = null + static clear() { + this.array = [] + this.active = null - logger.debug('Queue', `queue cleared`) - } + logger.debug('Queue', `queue cleared`) + } - static nextPlayer() { - this.active = (this.active + 1) % this.array.length - } + static nextPlayer() { + this.active = (this.active + 1) % this.array.length + } - static get rendered() { - return this.array.map(client => client.nick) - } + static get rendered() { + return this.array.map(client => client.nick) + } - static get activeClient() { - return this.array[this.active] - } + static get activeClient() { + return this.array[this.active] + } + + static debug() { + return { + queue: this.array.map((client, index) => ({ + position: index, + ip: client.ip, + nick: client.nick || null, + isActive: index === this.active, + })), + active: this.active, + length: this.array.length, + isEmpty: this.isEmpty, + activeClient: this.activeClient + ? { + ip: this.activeClient.ip, + nick: this.activeClient.nick || null, + } + : null, + } + } } export default Queue diff --git a/env.js b/env.js index fa33bc8..ebd52a4 100644 --- a/env.js +++ b/env.js @@ -12,9 +12,10 @@ const NODE_ENV = process.env.NODE_ENV, dotenv.config({ path: `./${dotfile}` }) const env = { - HTTP_PORT: 2500, - WS_PORT: 2501, - LOG_LEVEL: 'info', + HTTP_PORT: 2500, + WS_PORT: 2501, + LOG_LEVEL: 'info', + SERVER_HOST: '', } // Override defaults with environment variables if they exist diff --git a/package.json b/package.json index 256e90a..58ad620 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,10 @@ "dotenv": "^16.4.5", "express": "^4.18.2", "qrcode": "^1.5.4", + "ua-parser-js": "^2.0.7", "ws": "^8.11.0" + }, + "devDependencies": { + "nodemon": "^3.1.11" } } \ No newline at end of file diff --git a/pages/debug.html b/pages/debug.html new file mode 100644 index 0000000..821d943 --- /dev/null +++ b/pages/debug.html @@ -0,0 +1,345 @@ + + + + + + + SongDash Debug + + + + +

SongDash Debug Panel --

+ +
+

Music Status

+
+
Status:
+
--
+
+
+
Platform:
+
--
+
+
+
Listeners:
+
--
+
+
+
Metadata:
+
+
--
+
--
+
+
+
+ +
+

Queue (0 players)

+ + + + + + + + + + + + + + +
PosIPNickStatus
No players in queue
+
+ +
+

Scoreboard (0 players)

+ + + + + + + + + + + + + + +
IPNickScoreConnected
No scores recorded
+
+ +
+

Clients (0 total)

+ + + + + + + + + + + + + + +
IPTypeNickUser-Agent
No clients connected
+
+ + + + + + \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 117f578..7567fdf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,16 @@ importers: qrcode: specifier: ^1.5.4 version: 1.5.4 + ua-parser-js: + specifier: ^2.0.7 + version: 2.0.7 ws: specifier: ^8.11.0 version: 8.11.0 + devDependencies: + nodemon: + specifier: ^3.1.11 + version: 3.1.11 packages: @@ -35,13 +42,31 @@ packages: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} + anymatch@3.1.3: + resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} + engines: {node: '>= 8'} + array-flatten@1.1.1: resolution: {integrity: sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==} + balanced-match@1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + + binary-extensions@2.3.0: + resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} + engines: {node: '>=8'} + body-parser@1.20.1: resolution: {integrity: sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} + brace-expansion@1.1.12: + resolution: {integrity: sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==} + + braces@3.0.3: + resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} + engines: {node: '>=8'} + bytes@3.1.2: resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==} engines: {node: '>= 0.8'} @@ -53,6 +78,10 @@ packages: resolution: {integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==} engines: {node: '>=6'} + chokidar@3.6.0: + resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} + engines: {node: '>= 8.10.0'} + cliui@6.0.0: resolution: {integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==} @@ -63,6 +92,9 @@ packages: color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + content-disposition@0.5.4: resolution: {integrity: sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==} engines: {node: '>= 0.6'} @@ -86,6 +118,15 @@ packages: supports-color: optional: true + debug@4.4.3: + resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + decamelize@1.2.0: resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} engines: {node: '>=0.10.0'} @@ -98,6 +139,9 @@ packages: resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} + detect-europe-js@0.1.2: + resolution: {integrity: sha512-lgdERlL3u0aUdHocoouzT10d9I89VVhk0qNRmll7mXdGfJT1/wqZ2ZLA4oJAjeACPY5fT1wsbq2AT+GkuInsow==} + dijkstrajs@1.0.3: resolution: {integrity: sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==} @@ -126,6 +170,10 @@ packages: resolution: {integrity: sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==} engines: {node: '>= 0.10.0'} + fill-range@7.1.1: + resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} + engines: {node: '>=8'} + finalhandler@1.2.0: resolution: {integrity: sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==} engines: {node: '>= 0.8'} @@ -142,6 +190,11 @@ packages: resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==} engines: {node: '>= 0.6'} + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + function-bind@1.1.1: resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} @@ -152,6 +205,14 @@ packages: get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} + glob-parent@5.1.2: + resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} + engines: {node: '>= 6'} + + has-flag@3.0.0: + resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} + engines: {node: '>=4'} + has-proto@1.0.1: resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==} engines: {node: '>= 0.4'} @@ -172,6 +233,9 @@ packages: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} + ignore-by-default@1.0.1: + resolution: {integrity: sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==} + inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -179,10 +243,29 @@ packages: resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==} engines: {node: '>= 0.10'} + is-binary-path@2.1.0: + resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} + engines: {node: '>=8'} + + is-extglob@2.1.1: + resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} + engines: {node: '>=0.10.0'} + is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} + is-glob@4.0.3: + resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} + engines: {node: '>=0.10.0'} + + is-number@7.0.0: + resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} + engines: {node: '>=0.12.0'} + + is-standalone-pwa@0.1.1: + resolution: {integrity: sha512-9Cbovsa52vNQCjdXOzeQq5CnCbAcRk05aU62K20WO372NrTv0NxibLFCK6lQ4/iZEFdEA3p3t2VNOn8AJ53F5g==} + locate-path@5.0.0: resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} engines: {node: '>=8'} @@ -211,6 +294,9 @@ packages: engines: {node: '>=4'} hasBin: true + minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + ms@2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} @@ -221,6 +307,15 @@ packages: resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} engines: {node: '>= 0.6'} + nodemon@3.1.11: + resolution: {integrity: sha512-is96t8F/1//UHAjNPHpbsNY46ELPpftGUoSVNXwUfMk/qdjSylYrWSu1XavVTBOn526kFiOR733ATgNBCQyH0g==} + engines: {node: '>=10'} + hasBin: true + + normalize-path@3.0.0: + resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} + engines: {node: '>=0.10.0'} + object-inspect@1.12.3: resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} @@ -251,6 +346,10 @@ packages: path-to-regexp@0.1.7: resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==} + picomatch@2.3.1: + resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} + engines: {node: '>=8.6'} + pngjs@5.0.0: resolution: {integrity: sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==} engines: {node: '>=10.13.0'} @@ -259,6 +358,9 @@ packages: resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==} engines: {node: '>= 0.10'} + pstree.remy@1.1.8: + resolution: {integrity: sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==} + qrcode@1.5.4: resolution: {integrity: sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==} engines: {node: '>=10.13.0'} @@ -276,6 +378,10 @@ packages: resolution: {integrity: sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==} engines: {node: '>= 0.8'} + readdirp@3.6.0: + resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} + engines: {node: '>=8.10.0'} + require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -289,6 +395,11 @@ packages: safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} + semver@7.7.3: + resolution: {integrity: sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==} + engines: {node: '>=10'} + hasBin: true + send@0.18.0: resolution: {integrity: sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==} engines: {node: '>= 0.8.0'} @@ -306,6 +417,10 @@ packages: side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} + simple-update-notifier@2.0.0: + resolution: {integrity: sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==} + engines: {node: '>=10'} + statuses@2.0.1: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} @@ -318,14 +433,36 @@ packages: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} + supports-color@5.5.0: + resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} + engines: {node: '>=4'} + + to-regex-range@5.0.1: + resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} + engines: {node: '>=8.0'} + toidentifier@1.0.1: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} + touch@3.1.1: + resolution: {integrity: sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==} + hasBin: true + type-is@1.6.18: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} + ua-is-frozen@0.1.2: + resolution: {integrity: sha512-RwKDW2p3iyWn4UbaxpP2+VxwqXh0jpvdxsYpZ5j/MLLiQOfbsV5shpgQiw93+KMYQPcteeMQ289MaAFzs3G9pw==} + + ua-parser-js@2.0.7: + resolution: {integrity: sha512-CFdHVHr+6YfbktNZegH3qbYvYgC7nRNEUm2tk7nSFXSODUu4tDBpaFpP1jdXBUOKKwapVlWRfTtS8bCPzsQ47w==} + hasBin: true + + undefsafe@2.0.5: + resolution: {integrity: sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==} + unpipe@1.0.0: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} @@ -381,8 +518,17 @@ snapshots: dependencies: color-convert: 2.0.1 + anymatch@3.1.3: + dependencies: + normalize-path: 3.0.0 + picomatch: 2.3.1 + array-flatten@1.1.1: {} + balanced-match@1.0.2: {} + + binary-extensions@2.3.0: {} + body-parser@1.20.1: dependencies: bytes: 3.1.2 @@ -400,6 +546,15 @@ snapshots: transitivePeerDependencies: - supports-color + brace-expansion@1.1.12: + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + + braces@3.0.3: + dependencies: + fill-range: 7.1.1 + bytes@3.1.2: {} call-bind@1.0.2: @@ -409,6 +564,18 @@ snapshots: camelcase@5.3.1: {} + chokidar@3.6.0: + dependencies: + anymatch: 3.1.3 + braces: 3.0.3 + glob-parent: 5.1.2 + is-binary-path: 2.1.0 + is-glob: 4.0.3 + normalize-path: 3.0.0 + readdirp: 3.6.0 + optionalDependencies: + fsevents: 2.3.3 + cliui@6.0.0: dependencies: string-width: 4.2.3 @@ -421,6 +588,8 @@ snapshots: color-name@1.1.4: {} + concat-map@0.0.1: {} + content-disposition@0.5.4: dependencies: safe-buffer: 5.2.1 @@ -435,12 +604,20 @@ snapshots: dependencies: ms: 2.0.0 + debug@4.4.3(supports-color@5.5.0): + dependencies: + ms: 2.1.3 + optionalDependencies: + supports-color: 5.5.0 + decamelize@1.2.0: {} depd@2.0.0: {} destroy@1.2.0: {} + detect-europe-js@0.1.2: {} + dijkstrajs@1.0.3: {} dotenv@16.4.5: {} @@ -491,6 +668,10 @@ snapshots: transitivePeerDependencies: - supports-color + fill-range@7.1.1: + dependencies: + to-regex-range: 5.0.1 + finalhandler@1.2.0: dependencies: debug: 2.6.9 @@ -512,6 +693,9 @@ snapshots: fresh@0.5.2: {} + fsevents@2.3.3: + optional: true + function-bind@1.1.1: {} get-caller-file@2.0.5: {} @@ -523,6 +707,12 @@ snapshots: has-proto: 1.0.1 has-symbols: 1.0.3 + glob-parent@5.1.2: + dependencies: + is-glob: 4.0.3 + + has-flag@3.0.0: {} + has-proto@1.0.1: {} has-symbols@1.0.3: {} @@ -543,12 +733,28 @@ snapshots: dependencies: safer-buffer: 2.1.2 + ignore-by-default@1.0.1: {} + inherits@2.0.4: {} ipaddr.js@1.9.1: {} + is-binary-path@2.1.0: + dependencies: + binary-extensions: 2.3.0 + + is-extglob@2.1.1: {} + is-fullwidth-code-point@3.0.0: {} + is-glob@4.0.3: + dependencies: + is-extglob: 2.1.1 + + is-number@7.0.0: {} + + is-standalone-pwa@0.1.1: {} + locate-path@5.0.0: dependencies: p-locate: 4.1.0 @@ -567,12 +773,31 @@ snapshots: mime@1.6.0: {} + minimatch@3.1.2: + dependencies: + brace-expansion: 1.1.12 + ms@2.0.0: {} ms@2.1.3: {} negotiator@0.6.3: {} + nodemon@3.1.11: + dependencies: + chokidar: 3.6.0 + debug: 4.4.3(supports-color@5.5.0) + ignore-by-default: 1.0.1 + minimatch: 3.1.2 + pstree.remy: 1.1.8 + semver: 7.7.3 + simple-update-notifier: 2.0.0 + supports-color: 5.5.0 + touch: 3.1.1 + undefsafe: 2.0.5 + + normalize-path@3.0.0: {} + object-inspect@1.12.3: {} on-finished@2.4.1: @@ -595,6 +820,8 @@ snapshots: path-to-regexp@0.1.7: {} + picomatch@2.3.1: {} + pngjs@5.0.0: {} proxy-addr@2.0.7: @@ -602,6 +829,8 @@ snapshots: forwarded: 0.2.0 ipaddr.js: 1.9.1 + pstree.remy@1.1.8: {} + qrcode@1.5.4: dependencies: dijkstrajs: 1.0.3 @@ -621,6 +850,10 @@ snapshots: iconv-lite: 0.4.24 unpipe: 1.0.0 + readdirp@3.6.0: + dependencies: + picomatch: 2.3.1 + require-directory@2.1.1: {} require-main-filename@2.0.0: {} @@ -629,6 +862,8 @@ snapshots: safer-buffer@2.1.2: {} + semver@7.7.3: {} + send@0.18.0: dependencies: debug: 2.6.9 @@ -666,6 +901,10 @@ snapshots: get-intrinsic: 1.2.1 object-inspect: 1.12.3 + simple-update-notifier@2.0.0: + dependencies: + semver: 7.7.3 + statuses@2.0.1: {} string-width@4.2.3: @@ -678,13 +917,33 @@ snapshots: dependencies: ansi-regex: 5.0.1 + supports-color@5.5.0: + dependencies: + has-flag: 3.0.0 + + to-regex-range@5.0.1: + dependencies: + is-number: 7.0.0 + toidentifier@1.0.1: {} + touch@3.1.1: {} + type-is@1.6.18: dependencies: media-typer: 0.3.0 mime-types: 2.1.35 + ua-is-frozen@0.1.2: {} + + ua-parser-js@2.0.7: + dependencies: + detect-europe-js: 0.1.2 + is-standalone-pwa: 0.1.1 + ua-is-frozen: 0.1.2 + + undefsafe@2.0.5: {} + unpipe@1.0.0: {} utils-merge@1.0.1: {} diff --git a/server.js b/server.js index 0c73621..7ea3e44 100644 --- a/server.js +++ b/server.js @@ -16,7 +16,7 @@ app.use(express.static('public')) // Serve pages from /pages directory with clean URLs app.get('/:page', (req, res, next) => { - const allowedPages = ['host', 'player', 'tv'] + const allowedPages = ['host', 'player', 'tv', 'debug'] if (allowedPages.includes(req.params.page)) { res.sendFile(`pages/${req.params.page}.html`, { root: '.' }) } else { @@ -32,7 +32,7 @@ const wss = new WebSocketServer({ port: env.WS_PORT, }).on('listening', () => logger.info('server', 'websocket port is', env.WS_PORT)) -Qr.init(process.env.SERVER_HOST) +Qr.init(env.SERVER_HOST) Music.init(os.platform()) wss.on('connection', (ws, req) => new Client(ws, req)) @@ -64,6 +64,23 @@ Client.on('update', () => { }, }) }) + + Client.emit('debug') +}) + +Client.on('debug', () => { + Client.getBy.type('debug').forEach(debug => { + debug.send({ + action: 'update', + data: { + client: Client.debug(), + board: Board.debug(), + music: Music.debug(), + queue: Queue.debug(), + timestamp: new Date().toISOString(), + }, + }) + }) }) Client.on('hostAction-play', () => Music.control('Play'))