Compare commits

..
Author SHA1 Message Date
Mateusz Pstrucha 6c86a219e4 ai garbage 2025-12-14 20:58:34 +01:00
28 changed files with 5199 additions and 681 deletions

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
name: Build Binaries
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build client
run: pnpm build:client
# NOTE: Binary building disabled due to nexe ESM compatibility issues
# To be re-enabled once ESM support improves or alternative tool is used
# - name: Build server binaries
# run: pnpm build:server
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: songdash-dist
path: dist/
retention-days: 30
# - name: Upload Windows binary
# uses: actions/upload-artifact@v4
# with:
# name: songdash-windows-x64
# path: build/songdash-windows-x64.exe
# retention-days: 30
# - name: Upload Linux binary
# uses: actions/upload-artifact@v4
# with:
# name: songdash-linux-x64
# path: build/songdash-linux-x64
# retention-days: 30
# - name: Create Release (on tag)
# if: startsWith(github.ref, 'refs/tags/')
# uses: softprops/action-gh-release@v1
# with:
# files: |
# build/songdash-windows-x64.exe
# build/songdash-linux-x64
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+4 -1
View File
@@ -1,2 +1,5 @@
node_modules/
.env
.env
dist/
build/
+28 -7
View File
@@ -15,27 +15,48 @@ When a player presses their button, the music pauses and they join the queue. Th
## Setup
### Development
1. Clone the repository
2. Install dependencies:
```bash
pnpm install
```
3. Modifications:
3. Configuration (optional):
For customizations, look at `.env.example` for possible values, and change them in `.env` before launching
For customizations, look at `.env.example` for possible values, and change them in `.env` before launching
IMPORTANT: for a working QR code generation, create a `.env` file with at least `SERVER_HOST`
4. Start the server:
4. Start the development server:
```bash
pnpm start
pnpm dev
```
5. Open the interfaces:
- Host: `http://<ip-address>:2500/host.html`
- TV: `http://<ip-address>:2500/tv.html`
- Players: `http://<ip-address>:2500/player.html`
- Host: `http://<ip-address>:2500/host`
- TV: `http://<ip-address>:2500/tv`
- Players: `http://<ip-address>:2500/player`
- Debug: `http://<ip-address>:2500/debug`
### Production Build
Build optimized client files and server:
```bash
pnpm build
```
This will:
1. Bundle and minify all client-side code with Vite
2. Generate standalone binaries for Windows and Linux (Note: Binary generation currently has ESM compatibility issues and is under development)
Run the production server:
```bash
pnpm start
```
## Technical Details
+1 -1
View File
@@ -82,7 +82,7 @@ class Client {
handleRegistration(clientType) {
const validTypes = ['tv', 'host', 'player', 'debug']
if (!validTypes.includes(clientType)) throw new Error(`Invalid client type: ${clientType}`)
if (!validTypes.includes(clientType)) return
this.type = clientType
logger.info('Client', `'${this.ip}' registered as`, this.type)
+1 -5
View File
@@ -183,7 +183,6 @@ class Music {
static metadata = null
static listeners = new Set()
static #platform = null
static playingSince = null
static init(platform) {
this.#platform = platform
@@ -195,7 +194,7 @@ class Music {
const allowed = ['Play', 'Pause', 'Stop', 'Next', 'Previous', 'PlayPause']
if (!allowed.includes(action)) return
if (this.status == newStateLookup[action]) return
// if (this.status == newStateLookup[action]) return
let controller = {
linux: controlLinux,
@@ -215,9 +214,6 @@ class Music {
if (!allowed.includes(status)) return
this.status = status
if (status === 'playing') {
this.playingSince = new Date()
}
logger.debug('Music', `status changed to`, status)
}
+38 -41
View File
@@ -3,54 +3,51 @@ import logger from '../logger.js'
import env from '../env.js'
export default class Qr {
static #cache = null
static #host = null
static #cache = null
static #host = null
static init(host) {
if (!host) return logger.warn('env', 'SERVER_HOST is not defined, QR codes will not be generated')
static init(host) {
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() {
return async (req, res, next) => {
if (req.path !== '/qr') return next()
static serve() {
return async (req, res, next) => {
if (req.path !== '/qr') return next()
try {
if (this.#host === null) {
res.status(500).send('QR code generation is not configured')
throw new Error('SERVER_HOST is not defined')
}
if (!this.#cache) {
const payload = this.#payload()
this.#cache = await this.#generate(payload)
}
try {
if (this.host === null) {
res.status(500).send('QR code generation is not configured')
throw new Error('SERVER_HOST is not defined')
}
res.setHeader('Content-Type', 'image/png')
res.setHeader('Cache-Control', 'public, max-age=3600')
res.send(this.#cache)
} catch (error) {
logger.error('http', 'QR code generation error:', error)
res.status(500).send('Failed to generate QR code')
}
}
}
if (!this.#cache) {
const payload = this.#payload()
this.#cache = await this.#generate(payload)
}
static async #generate(data) {
return await QRCode.toBuffer(data, {
errorCorrectionLevel: 'M',
type: 'png',
width: 512,
margin: 2,
})
}
res.setHeader('Content-Type', 'image/png')
res.setHeader('Cache-Control', 'public, max-age=3600')
res.send(this.#cache)
} catch (error) {
logger.error('http', 'QR code generation error:', error)
res.status(500).send('Failed to generate QR code')
}
}
}
static #payload() {
const port = env.HTTP_PORT,
portSuffix = port == 80 || port === 443 ? '' : `:${port}`,
url = `http://${this.#host}${portSuffix}/player`
static async #generate(data) {
return await QRCode.toBuffer(data, {
errorCorrectionLevel: 'M',
type: 'png',
width: 512,
margin: 2,
})
}
logger.debug('Qr', 'Link:', url)
return url
}
static #payload() {
const port = env.HTTP_PORT
return `http://${this.#host}:${port}/player`
}
}
+9 -14
View File
@@ -1,21 +1,17 @@
import logger from '../logger.js'
import Music from './Music.js'
function getTime() {
if (!Music.playingSince) return null
return (new Date() - Music.playingSince) / 1000
}
class Queue {
static array = []
static active = null
static add(client) {
if (this.isClientInQueue(client)) return
if (this.isClientInQueue(client)) {
// if (Music.status == 'playing') this.active++
return
}
if (this.isEmpty) this.active = 0
this.array.push({ client, time: getTime() })
this.array.push(client)
logger.debug('Queue', `client added to queue`, client.ip)
}
@@ -25,7 +21,7 @@ class Queue {
}
static isClientInQueue(client) {
return this.array.some(({ client: c }) => c.ip === client.ip)
return this.array.some(c => c.ip === client.ip)
}
static clear() {
@@ -40,21 +36,20 @@ class Queue {
}
static get rendered() {
return this.array.map(({ client, time }) => [client.nick, time])
return this.array.map(client => client.nick)
}
static get activeClient() {
return this.array[this.active]?.client
return this.array[this.active]
}
static debug() {
return {
queue: this.array.map(({ client, time }, index) => ({
queue: this.array.map((client, index) => ({
position: index,
ip: client.ip,
nick: client.nick || null,
isActive: index === this.active,
time,
})),
active: this.active,
length: this.array.length,
+51
View File
@@ -0,0 +1,51 @@
import { compile } from 'nexe'
import { join } from 'path'
// NOTE: nexe currently has limited ESM (ES Modules) support
// The binary build works but has issues with ES module imports at runtime
// This is a known limitation: https://github.com/nexe/nexe/issues/836
// Workarounds:
// 1. Convert to CommonJS (require/module.exports)
// 2. Use a different tool like `pkg` or `caxa`
// 3. Wait for better ESM support in nexe
const targets = [
{ platform: 'windows', arch: 'x64' },
{ platform: 'linux', arch: 'x64' },
]
async function buildBinary(target) {
const outputName = `songdash-${target.platform}-${target.arch}${
target.platform === 'windows' ? '.exe' : ''
}`
console.log(`Building ${outputName}...`)
await compile({
input: './dist-server/server.cjs', // Use Vite-bundled CommonJS file
output: join('build', outputName),
target: `${target.platform}-${target.arch}-14.15.3`, // Node.js version with pre-built binaries
resources: ['./dist/**/*', './public/**/*'],
build: false, // Use pre-built Node binaries
loglevel: 'info',
})
console.log(`✓ Built ${outputName}`)
}
async function buildAll() {
console.log('Building binaries for all platforms...\n')
for (const target of targets) {
try {
await buildBinary(target)
} catch (error) {
console.error(`Failed to build for ${target.platform}-${target.arch}:`, error)
process.exit(1)
}
}
console.log('\n✓ All binaries built successfully!')
}
buildAll()
+11 -3
View File
@@ -5,8 +5,14 @@
"type": "module",
"main": "server.js",
"scripts": {
"start": "node .",
"dev": "NODE_ENV=development nodemon ."
"start": "NODE_ENV=production node .",
"dev": "nodemon .",
"build:client": "vite build",
"build:server-bundle": "vite build --config vite.config.server.js",
"build:server-binary": "node build.js",
"build:server": "pnpm build:server-bundle && pnpm build:server-binary",
"build": "pnpm build:client && pnpm build:server",
"preview": "NODE_ENV=production node ."
},
"repository": {
"type": "git",
@@ -34,6 +40,8 @@
"ws": "^8.11.0"
},
"devDependencies": {
"nodemon": "^3.1.11"
"nexe": "5.0.0-beta.4",
"nodemon": "^3.1.11",
"vite": "^7.2.7"
}
}
+280 -294
View File
@@ -1,348 +1,334 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SongDash Debug</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Courier New', monospace;
background: #1a1a1a;
color: #e0e0e0;
padding: 10px;
font-size: 12px;
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SongDash Debug</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1 {
font-size: 16px;
margin-bottom: 10px;
color: #00ff00;
border-bottom: 1px solid #333;
padding-bottom: 5px;
}
body {
font-family: 'Courier New', monospace;
background: #1a1a1a;
color: #e0e0e0;
padding: 10px;
font-size: 12px;
}
h2 {
font-size: 14px;
margin: 15px 0 5px 0;
color: #00aaff;
}
h1 {
font-size: 16px;
margin-bottom: 10px;
color: #00ff00;
border-bottom: 1px solid #333;
padding-bottom: 5px;
}
.section {
margin-bottom: 15px;
border: 1px solid #333;
padding: 10px;
background: #0a0a0a;
}
h2 {
font-size: 14px;
margin: 15px 0 5px 0;
color: #00aaff;
}
table {
width: 100%;
border-collapse: collapse;
margin: 5px 0;
}
.section {
margin-bottom: 15px;
border: 1px solid #333;
padding: 10px;
background: #0a0a0a;
}
th,
td {
text-align: left;
padding: 4px 8px;
border: 1px solid #333;
}
table {
width: 100%;
border-collapse: collapse;
margin: 5px 0;
}
th {
background: #222;
color: #ffaa00;
font-weight: bold;
}
th,
td {
text-align: left;
padding: 4px 8px;
border: 1px solid #333;
}
td {
background: #111;
}
th {
background: #222;
color: #ffaa00;
font-weight: bold;
}
.status {
display: inline-block;
padding: 2px 6px;
border-radius: 3px;
font-weight: bold;
}
td {
background: #111;
}
.status.connected {
background: #004400;
color: #00ff00;
}
.status {
display: inline-block;
padding: 2px 6px;
border-radius: 3px;
font-weight: bold;
}
.status.disconnected {
background: #440000;
color: #ff0000;
}
.status.connected {
background: #004400;
color: #00ff00;
}
.status.playing {
background: #004400;
color: #00ff00;
}
.status.disconnected {
background: #440000;
color: #ff0000;
}
.status.paused {
background: #444400;
color: #ffff00;
}
.status.playing {
background: #004400;
color: #00ff00;
}
.status.waiting {
background: #444444;
color: #888888;
}
.status.paused {
background: #444400;
color: #ffff00;
}
.status.active {
background: #000044;
color: #00aaff;
}
.status.waiting {
background: #444444;
color: #888888;
}
.type-tv {
background: #440044;
color: #ff00ff;
font-weight: bold;
}
.status.active {
background: #000044;
color: #00aaff;
}
.type-host {
background: #004444;
color: #00ffff;
font-weight: bold;
}
.type-tv {
background: #440044;
color: #ff00ff;
font-weight: bold;
}
.type-debug {
background: #444400;
color: #ffff00;
font-weight: bold;
}
.type-host {
background: #004444;
color: #00ffff;
font-weight: bold;
}
.timestamp {
float: right;
color: #666;
font-size: 11px;
}
.type-debug {
background: #444400;
color: #ffff00;
font-weight: bold;
}
.key-value {
display: grid;
grid-template-columns: 150px 1fr;
gap: 5px;
margin: 3px 0;
}
.timestamp {
float: right;
color: #666;
font-size: 11px;
}
.key {
color: #888;
}
.key-value {
display: grid;
grid-template-columns: 150px 1fr;
gap: 5px;
margin: 3px 0;
}
.value {
color: #e0e0e0;
word-break: break-all;
}
.key {
color: #888;
}
.empty {
color: #666;
font-style: italic;
}
.value {
color: #e0e0e0;
word-break: break-all;
}
.json {
background: #000;
border: 1px solid #333;
padding: 5px;
margin: 5px 0;
overflow-x: auto;
font-size: 11px;
}
</style>
</head>
.empty {
color: #666;
font-style: italic;
}
<body>
<h1>SongDash Debug Panel <span class="timestamp" id="timestamp">--</span></h1>
.json {
background: #000;
border: 1px solid #333;
padding: 5px;
margin: 5px 0;
overflow-x: auto;
font-size: 11px;
}
</style>
</head>
<div class="section">
<h2>Music Status</h2>
<div class="key-value">
<div class="key">Status:</div>
<div class="value"><span id="music-status" class="status">--</span></div>
</div>
<div class="key-value">
<div class="key">Platform:</div>
<div class="value" id="music-platform">--</div>
</div>
<div class="key-value">
<div class="key">Listeners:</div>
<div class="value" id="music-listeners">--</div>
</div>
<div class="key-value">
<div class="key">Metadata:</div>
<div class="value">
<div id="music-metadata-author">--</div>
<div id="music-metadata-track">--</div>
</div>
<body>
<h1>SongDash Debug Panel <span class="timestamp" id="timestamp">--</span></h1>
<div class="section">
<h2>Music Status</h2>
<div class="key-value">
<div class="key">Status:</div>
<div class="value"><span id="music-status" class="status">--</span></div>
</div>
<div class="key-value">
<div class="key">Platform:</div>
<div class="value" id="music-platform">--</div>
</div>
<div class="key-value">
<div class="key">Listeners:</div>
<div class="value" id="music-listeners">--</div>
</div>
<div class="key-value">
<div class="key">Metadata:</div>
<div class="value">
<div id="music-metadata-author">--</div>
<div id="music-metadata-track">--</div>
</div>
</div>
</div>
<div class="section">
<h2>Queue (<span id="queue-length">0</span> players)</h2>
<table id="queue-table">
<thead>
<tr>
<th>Pos</th>
<th>IP</th>
<th>Nick</th>
<th>Status</th>
<th>Time</th>
</tr>
</thead>
<tbody id="queue-body">
<tr>
<td colspan="5" class="empty">No players in queue</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Queue (<span id="queue-length">0</span> players)</h2>
<table id="queue-table">
<thead>
<tr>
<th>Pos</th>
<th>IP</th>
<th>Nick</th>
<th>Status</th>
</tr>
</thead>
<tbody id="queue-body">
<tr>
<td colspan="4" class="empty">No players in queue</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Scoreboard (<span id="board-total">0</span> players)</h2>
<table id="board-table">
<thead>
<tr>
<th>IP</th>
<th>Nick</th>
<th>Score</th>
<th>Connected</th>
</tr>
</thead>
<tbody id="board-body">
<tr>
<td colspan="4" class="empty">No scores recorded</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Scoreboard (<span id="board-total">0</span> players)</h2>
<table id="board-table">
<thead>
<tr>
<th>IP</th>
<th>Nick</th>
<th>Score</th>
<th>Connected</th>
</tr>
</thead>
<tbody id="board-body">
<tr>
<td colspan="4" class="empty">No scores recorded</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Clients (<span id="client-count">0</span> total)</h2>
<table id="client-table">
<thead>
<tr>
<th>IP</th>
<th>Type</th>
<th>Nick</th>
<th>User-Agent</th>
</tr>
</thead>
<tbody id="client-body">
<tr>
<td colspan="4" class="empty">No clients connected</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Clients (<span id="client-count">0</span> total)</h2>
<table id="client-table">
<thead>
<tr>
<th>IP</th>
<th>Type</th>
<th>Nick</th>
<th>User-Agent</th>
</tr>
</thead>
<tbody id="client-body">
<tr>
<td colspan="4" class="empty">No clients connected</td>
</tr>
</tbody>
</table>
</div>
<script src="/socket.js"></script>
<script>
const socket = new Socket('debug')
<script src="/socket.js"></script>
<script>
const socket = new Socket('debug')
socket.on('update', data => {
updateDebug(data)
})
socket.on('update', data => {
updateDebug(data)
})
function updateDebug(data) {
// Update timestamp
document.getElementById('timestamp').textContent = new Date(data.timestamp).toLocaleTimeString()
function updateDebug(data) {
// Update timestamp
document.getElementById('timestamp').textContent = new Date(data.timestamp).toLocaleTimeString()
// Update Music Status
const musicStatus = document.getElementById('music-status')
musicStatus.textContent = data.music.status
musicStatus.className = 'status ' + data.music.status
// Update Music Status
const musicStatus = document.getElementById('music-status')
musicStatus.textContent = data.music.status
musicStatus.className = 'status ' + data.music.status
document.getElementById('music-platform').textContent = data.music.platform || '--'
document.getElementById('music-listeners').textContent = data.music.listenerCount
document.getElementById('music-platform').textContent = data.music.platform || '--'
document.getElementById('music-listeners').textContent = data.music.listenerCount
if (data.music.metadata && data.music.metadata.author && data.music.metadata.track) {
const metadataText = `${data.music.metadata.author} - ${data.music.metadata.track}`
document.getElementById('music-metadata-author').textContent = metadataText
document.getElementById('music-metadata-track').textContent = ''
} else {
document.getElementById('music-metadata-author').textContent = '--'
document.getElementById('music-metadata-track').textContent = ''
}
if (data.music.metadata && data.music.metadata.author && data.music.metadata.track) {
const metadataText = `${data.music.metadata.author} - ${data.music.metadata.track}`
document.getElementById('music-metadata-author').textContent = metadataText
document.getElementById('music-metadata-track').textContent = ''
} else {
document.getElementById('music-metadata-author').textContent = '--'
document.getElementById('music-metadata-track').textContent = ''
}
// Update Queue
document.getElementById('queue-length').textContent = data.queue.length
const queueBody = document.getElementById('queue-body')
// Update Queue
document.getElementById('queue-length').textContent = data.queue.length
const queueBody = document.getElementById('queue-body')
if (data.queue.queue.length === 0) {
queueBody.innerHTML = '<tr><td colspan="5" class="empty">No players in queue</td></tr>'
} else {
queueBody.innerHTML = data.queue.queue
.map(
item => `
if (data.queue.queue.length === 0) {
queueBody.innerHTML = '<tr><td colspan="4" class="empty">No players in queue</td></tr>'
} else {
queueBody.innerHTML = data.queue.queue.map(item => `
<tr>
<td>${item.position + 1}</td>
<td>${item.ip}</td>
<td>${item.nick || '--'}</td>
<td>${item.isActive ? '<span class="status active">ACTIVE</span>' : ''}</td>
<td>${item.time !== null ? item.time.toFixed(4) + 's' : '--'}</td>
</tr>
`
)
.join('')
}
`).join('')
}
// Update Scoreboard
document.getElementById('board-total').textContent = data.board.totalPlayers
const boardBody = document.getElementById('board-body')
// Update Scoreboard
document.getElementById('board-total').textContent = data.board.totalPlayers
const boardBody = document.getElementById('board-body')
if (data.board.scores.length === 0) {
boardBody.innerHTML = '<tr><td colspan="4" class="empty">No scores recorded</td></tr>'
} else {
boardBody.innerHTML = data.board.scores
.map(
item => `
if (data.board.scores.length === 0) {
boardBody.innerHTML = '<tr><td colspan="4" class="empty">No scores recorded</td></tr>'
} else {
boardBody.innerHTML = data.board.scores.map(item => `
<tr>
<td>${item.ip}</td>
<td>${item.nick}</td>
<td>${item.score}</td>
<td><span class="status ${item.connected ? 'connected' : 'disconnected'}">${
item.connected ? 'YES' : 'NO'
}</span></td>
<td><span class="status ${item.connected ? 'connected' : 'disconnected'}">${item.connected ? 'YES' : 'NO'}</span></td>
</tr>
`
)
.join('')
}
`).join('')
}
// Update Clients
document.getElementById('client-count').textContent = data.client.clients.length
const clientBody = document.getElementById('client-body')
// Update Clients
document.getElementById('client-count').textContent = data.client.clients.length
const clientBody = document.getElementById('client-body')
if (data.client.clients.length === 0) {
clientBody.innerHTML = '<tr><td colspan="4" class="empty">No clients connected</td></tr>'
} else {
// Sort clients: special types (tv, host, debug) first, then players
const specialTypes = ['tv', 'host', 'debug']
const sortedClients = [...data.client.clients].sort((a, b) => {
const aSpecial = specialTypes.includes(a.type)
const bSpecial = specialTypes.includes(b.type)
if (aSpecial && !bSpecial) return -1
if (!aSpecial && bSpecial) return 1
return 0
})
if (data.client.clients.length === 0) {
clientBody.innerHTML = '<tr><td colspan="4" class="empty">No clients connected</td></tr>'
} else {
// Sort clients: special types (tv, host, debug) first, then players
const specialTypes = ['tv', 'host', 'debug']
const sortedClients = [...data.client.clients].sort((a, b) => {
const aSpecial = specialTypes.includes(a.type)
const bSpecial = specialTypes.includes(b.type)
if (aSpecial && !bSpecial) return -1
if (!aSpecial && bSpecial) return 1
return 0
})
clientBody.innerHTML = sortedClients
.map(item => {
let uaDisplay = '--'
let uaTitle = '--'
if (item.userAgent) {
uaDisplay = `${item.userAgent.browser || 'Unknown'} / ${item.userAgent.os || 'Unknown'} / ${
item.userAgent.device
}`
uaTitle = item.userAgent.raw
}
const typeClass = specialTypes.includes(item.type) ? `type-${item.type}` : ''
return `
clientBody.innerHTML = sortedClients.map(item => {
let uaDisplay = '--'
let uaTitle = '--'
if (item.userAgent) {
uaDisplay = `${item.userAgent.browser || 'Unknown'} / ${item.userAgent.os || 'Unknown'} / ${item.userAgent.device}`
uaTitle = item.userAgent.raw
}
const typeClass = specialTypes.includes(item.type) ? `type-${item.type}` : ''
return `
<tr>
<td>${item.ip}</td>
<td class="${typeClass}">${item.type || '--'}</td>
@@ -350,10 +336,10 @@
<td title="${uaTitle}">${uaDisplay}</td>
</tr>
`
})
.join('')
}
}).join('')
}
</script>
</body>
</html>
}
</script>
</body>
</html>
+91 -91
View File
@@ -1,118 +1,118 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Player - Jaka To Melodia</title>
<script src="/socket.js"></script>
<script src="/wakelock.js"></script>
<title>Player - Jaka To Melodia</title>
<script src="/socket.js"></script>
<script src="/wakelock.js"></script>
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="/pattern.css" />
<style>
body {
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
overflow: hidden;
<style>
body {
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
overflow: hidden;
--fgcolor: #e7213b;
--bgcolor: #b93834;
--pattern: 22px;
}
--fgcolor: #e7213b;
--bgcolor: #b93834;
--pattern: 22px;
}
button {
width: calc(100vw - 2rem);
height: calc(100vw - 2rem);
button {
width: calc(100vw - 2rem);
height: calc(100vw - 2rem);
border-radius: 100%;
margin: 1rem;
background-color: #ee1020;
user-select: none;
border-width: 4px;
}
border-radius: 100%;
margin: 1rem;
background-color: #ee1020;
user-select: none;
border-width: 4px;
}
button > img {
height: 50%;
transition: 0.2s;
}
button > img {
height: 50%;
transition: 0.2s;
}
button:active > img {
height: 60%;
transform: skewx(-49deg);
}
button:active > img {
height: 60%;
transform: skewx(-49deg);
}
button:active {
background-color: #bb1020;
}
button:active {
background-color: #bb1020;
}
input {
width: calc(100vw - 2rem);
box-sizing: border-box;
margin: 1rem;
margin-bottom: 0;
font-size: 1rem;
text-align: center;
font-family: monospace;
}
input {
width: calc(100vw - 2rem);
box-sizing: border-box;
margin: 1rem;
margin-bottom: 0;
font-size: 1rem;
text-align: center;
font-family: monospace;
}
#score {
font-family: monospace;
box-sizing: border-box;
padding: 1em;
background-color: #fff6;
font-size: 1rem;
}
</style>
</head>
<body class="patterned">
<!-- <div id="score">
#score {
font-family: monospace;
box-sizing: border-box;
padding: 1em;
background-color: #fff6;
font-size: 1rem;
}
</style>
</head>
<body class="patterned">
<!-- <div id="score">
<span>Punkty:</span>
<span id="points">0</span>
</div> -->
<input type="text" id="nick" placeholder="nick" maxlength="20" />
<input type="text" id="nick" placeholder="nick" maxlength="20" />
<button>
<!-- <img src="twerk.gif" alt="doopa" /> -->
</button>
<button>
<!-- <img src="twerk.gif" alt="doopa" /> -->
</button>
<script>
const socket = new Socket('player')
<script>
const socket = new Socket('player')
requestWakeLock()
requestWakeLock()
// Cache DOM elements
const nodeButton = document.querySelector('button'),
nodeNick = document.querySelector('#nick'),
nodePoints = document.querySelector('#points')
// Cache DOM elements
const nodeButton = document.querySelector('button'),
nodeNick = document.querySelector('#nick'),
nodePoints = document.querySelector('#points')
// Initialize nickname
const savedNick = localStorage.getItem('nick') || ''
nodeNick.value = savedNick
socket.player('setNick', { nick: savedNick })
// Initialize nickname
const savedNick = localStorage.getItem('nick') || ''
nodeNick.value = savedNick
socket.player('setNick', { nick: savedNick })
// Handle button press
nodeButton.addEventListener('mousedown', () => socket.player('enter'))
nodeButton.addEventListener('touchstart', () => socket.player('enter'), { passive: true })
// Handle button press
nodeButton.addEventListener('mousedown', () => socket.player('enter'))
nodeButton.addEventListener('touchstart', () => socket.player('enter'), { passive: true })
// Handle nickname changes
const setNick = e => {
const nick = e.target.value.trim().toLowerCase()
socket.player('setNick', { nick })
localStorage.setItem('nick', nick)
}
// Handle nickname changes
const setNick = e => {
const nick = e.target.value.trim().toLowerCase()
socket.player('setNick', { nick })
localStorage.setItem('nick', nick)
}
nodeNick.addEventListener('change', setNick)
nodeNick.addEventListener('change', setNick)
// // Update points display using custom event listener
// socket.on('points', points => {
// nodePoints.textContent = points
// })
</script>
</body>
// // Update points display using custom event listener
// socket.on('points', points => {
// nodePoints.textContent = points
// })
</script>
</body>
</html>
+202 -221
View File
@@ -1,250 +1,242 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TV - Jaka To Melodia</title>
<script src="/socket.js"></script>
<script src="/wakelock.js"></script>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/common.css" />
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="/loader.css" />
<title>TV - Jaka To Melodia</title>
<script src="/socket.js"></script>
<script src="/wakelock.js"></script>
<style>
body {
height: 100vh;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
--pattern: 22px;
overflow: hidden;
position: relative;
}
<link rel="stylesheet" href="/common.css" />
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="/loader.css" />
.section {
flex: 1;
padding: 2rem;
overflow-y: auto;
background: #0005;
--margin: 1em;
margin: var(--margin);
border-radius: 1em;
}
<style>
body {
height: 100vh;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
--pattern: 22px;
overflow: hidden;
position: relative;
}
.section.l {
margin-right: calc(var(--margin) / 2);
}
.section {
flex: 1;
padding: 2rem;
overflow-y: auto;
background: #0005;
--margin: 1em;
margin: var(--margin);
border-radius: 1em;
}
.section.r {
margin-left: calc(var(--margin) / 2);
}
.section.l {
margin-right: calc(var(--margin) / 2);
}
.section .title {
font-size: 2.5rem;
font-weight: bold;
margin-bottom: 1.5rem;
text-align: center;
color: #fff;
font-family: monospace;
border-bottom: 1px solid #fff3;
padding-bottom: 0.5em;
}
.section.r {
margin-left: calc(var(--margin) / 2);
}
#status {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: -1;
pointer-events: none;
/* display: flex;
align-items: center;
justify-content: center; */
font-size: 500px;
--opacity: 0.25;
text-shadow: 0 0 20px rgba(0, 0, 0, var(--opacity));
color: rgba(0, 0, 0, var(--opacity));
}
.section .title {
font-size: 2.5rem;
font-weight: bold;
margin-bottom: 1.5rem;
text-align: center;
color: #fff;
font-family: monospace;
border-bottom: 1px solid #fff3;
padding-bottom: 0.5em;
}
#queue {
font-size: 30px;
font-family: monospace;
text-align: left;
counter-reset: poz;
}
#status {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: -1;
pointer-events: none;
/* display: flex;
align-items: center;
justify-content: center; */
font-size: 500px;
--opacity: 0.25;
text-shadow: 0 0 20px rgba(0, 0, 0, var(--opacity));
color: rgba(0, 0, 0, var(--opacity));
}
#queue > .nick {
display: flex;
/* justify-content: space-between;
align-items: center; */
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#queue {
font-size: 30px;
font-family: monospace;
text-align: left;
counter-reset: poz;
}
#queue > .nick::before {
counter-increment: poz;
content: '#' counter(poz) ' ';
font-weight: bold;
color: #ccc;
padding-right: 1em;
width: 1.5em;
}
#queue>.nick {
display: flex;
/* justify-content: space-between;
align-items: center; */
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#queue > .nick::after {
content: attr(data-time);
margin-left: auto;
font-weight: bold;
color: #eee;
min-width: 4em;
text-align: right;
}
#queue>.nick::before {
counter-increment: poz;
content: '#' counter(poz) ' ';
font-weight: bold;
color: #ccc;
padding-right: 1em;
width: 1.5em;
}
#queue > img {
height: 10vh;
}
#queue>img {
height: 10vh;
}
#queue .nick.active {
outline: 2px solid #fff;
}
#queue .nick.active {
outline: 2px solid #fff;
}
#qr-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
z-index: 1000;
align-items: center;
justify-content: center;
}
#qr-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
z-index: 1000;
align-items: center;
justify-content: center;
}
#qr-modal.show {
display: flex;
}
#qr-modal.show {
display: flex;
}
#qr-modal .content {
background-color: white;
padding: 2rem;
border-radius: 1rem;
text-align: center;
max-width: 90vw;
max-height: 90vh;
}
#qr-modal .content {
background-color: white;
padding: 2rem;
border-radius: 1rem;
text-align: center;
max-width: 90vw;
max-height: 90vh;
}
#qr-modal .content img {
max-width: 100%;
height: auto;
border-radius: 0.5rem;
}
#qr-modal .content img {
max-width: 100%;
height: auto;
border-radius: 0.5rem;
}
#scoreboard {
width: 100%;
font-size: 1.5rem;
font-family: monospace;
}
#scoreboard {
width: 100%;
font-size: 1.5rem;
font-family: monospace;
}
#scoreboard .item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#scoreboard .item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#scoreboard .item .rank i {
font-size: 2rem;
}
#scoreboard .item .rank i {
font-size: 2rem;
}
#scoreboard .item:nth-child(1) .rank {
color: gold;
}
#scoreboard .item:nth-child(1) .rank {
color: gold;
}
#scoreboard .item:nth-child(2) .rank {
color: silver;
}
#scoreboard .item:nth-child(2) .rank {
color: silver;
}
#scoreboard .item:nth-child(3) .rank {
color: #cd7f32;
/* Bronze */
}
#scoreboard .item:nth-child(3) .rank {
color: #cd7f32;
/* Bronze */
}
#scoreboard .item > .rank {
font-weight: bold;
margin-right: 1rem;
min-width: 2.5rem;
}
#scoreboard .item>.rank {
font-weight: bold;
margin-right: 1rem;
min-width: 2.5rem;
}
#scoreboard .item > .nick {
flex: 1;
text-align: left;
}
#scoreboard .item>.nick {
flex: 1;
text-align: left;
}
#scoreboard .item > .score {
font-weight: bold;
min-width: 3rem;
text-align: right;
}
</style>
#scoreboard .item>.score {
font-weight: bold;
min-width: 3rem;
text-align: right;
}
</style>
</head>
<body class="patterned">
<!-- Status Indicator -->
<div id="status" class="status"></div>
<body class="patterned">
<!-- Status Indicator -->
<div id="status" class="status"></div>
<!-- Left: Queue -->
<div class="section l">
<div class="title">
<i class="icon-stopwatch"></i>
</div>
<div id="queue">
<!-- Example
<!-- Left: Queue -->
<div class="section l">
<div class="title">
<i class="icon-stopwatch"></i>
</div>
<div id="queue">
<!-- Example
<div class="nick active"> </div>
-->
</div>
</div>
</div>
<!-- Right: Scoreboard -->
<div class="section r">
<div class="title">
<i class="icon-award"></i>
</div>
<div id="scoreboard">
<!-- Example
<!-- Right: Scoreboard -->
<div class="section r">
<div class="title">
<i class="icon-award"></i>
</div>
<div id="scoreboard">
<!-- Example
<div class="item">
<span class="rank"> </span>
<span class="nick"> </span>
<span class="score"> </span>
</div>
-->
</div>
</div>
</div>
<!-- QR Modal -->
<div id="qr-modal">
<div class="content">
<img src="/qr" alt="QR Code" />
</div>
<!-- QR Modal -->
<div id="qr-modal">
<div class="content">
<img src="/qr" alt="QR Code" />
</div>
</div>
<script>
// SETUP
const statuses = {
paused: '<i class="icon-pause-circled"></i>',
playing: '<i class="icon-play-circled"></i>',
waiting: '<i class="icon-stop-circled"></i>',
}
<script>
// SETUP
const statuses = {
paused: '<i class="icon-pause-circled"></i>',
playing: '<i class="icon-play-circled"></i>',
waiting: '<i class="icon-stop-circled"></i>',
}
const nodeStatus = document.querySelector('#status'),
nodeQueue = document.querySelector('#queue'),
@@ -271,21 +263,9 @@
document.body.style.setProperty('--bgcolor', patternColors[status].bg)
}
function queueTimeFormat(seconds) {
if (seconds === null) return ''
if (seconds > 15) return `...`
// two significant digits in seconds with decimals
return seconds.toFixed(2) + 's'
}
function setQueue(queue, active = 0) {
nodeQueue.innerHTML = queue
.map(
([nick, time], i) =>
`<div class="nick ${i == active ? 'active' : ''}" data-time="${queueTimeFormat(
time
)}">${nick}</div>`
)
.map((nick, i) => `<div class="nick ${i == active ? 'active' : ''}">${nick}</div>`)
.join('')
}
@@ -307,13 +287,13 @@
<span class="score">${player.score}</span>
</div>`
})
.join('')
}
</script>
.join('')
}
</script>
<script>
requestWakeLock()
setStatus()
<script>
requestWakeLock()
setStatus()
socket.on('update', ({ board, active, queue, status }) => {
setQueue(queue, active)
@@ -326,4 +306,5 @@
})
</script>
</body>
</html>
</html>
+3379
View File
File diff suppressed because it is too large. Load diff
+34 -3
View File
@@ -1,6 +1,8 @@
import { WebSocketServer } from 'ws'
import express from 'express'
import os from 'os'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import env from './env.js'
import logger from './logger.js'
@@ -10,15 +12,44 @@ import Qr from './backend/Qr.js'
import Queue from './backend/Queue.js'
import Board from './backend/Board.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const app = express()
app.use(express.static('public'))
// Determine if we're in production (built) or development
const isProduction = process.env.NODE_ENV === 'production'
const pagesDir = isProduction ? 'dist' : 'src/pages'
// Serve pages from /pages directory with clean URLs
// When running as nexe binary, use process.cwd() as base path
// Otherwise use __dirname (for normal node execution)
const isNexeBinary = process.argv[0].includes('songdash')
const basePath = isNexeBinary ? process.cwd() : __dirname
// Serve static files from public directory
app.use(express.static(join(basePath, 'public')))
// In development, also serve src directory for Vite assets
if (!isProduction) {
app.use('/src', express.static(join(basePath, 'src')))
// Serve styles and scripts directly for relative imports from HTML
app.use('/styles', express.static(join(basePath, 'src/styles')))
app.use('/scripts', express.static(join(basePath, 'src/scripts')))
}
// Serve built pages from /dist in production
if (isProduction) {
app.use(express.static(join(basePath, 'dist')))
}
// Serve pages with clean URLs
app.get('/:page', (req, res, next) => {
const allowedPages = ['host', 'player', 'tv', 'debug']
if (allowedPages.includes(req.params.page)) {
res.sendFile(`pages/${req.params.page}.html`, { root: '.' })
const filePath = isProduction
? join(basePath, 'dist', `${req.params.page}.html`)
: join(basePath, pagesDir, `${req.params.page}.html`)
res.sendFile(filePath)
} else {
next()
}
+98
View File
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SongDash Debug</title>
<link rel="stylesheet" href="../styles/debug.css">
</head>
<body>
<h1>SongDash Debug Panel <span class="timestamp" id="timestamp">--</span></h1>
<div class="section">
<h2>Music Status</h2>
<div class="key-value">
<div class="key">Status:</div>
<div class="value"><span id="music-status" class="status">--</span></div>
</div>
<div class="key-value">
<div class="key">Platform:</div>
<div class="value" id="music-platform">--</div>
</div>
<div class="key-value">
<div class="key">Listeners:</div>
<div class="value" id="music-listeners">--</div>
</div>
<div class="key-value">
<div class="key">Metadata:</div>
<div class="value">
<div id="music-metadata-author">--</div>
<div id="music-metadata-track">--</div>
</div>
</div>
</div>
<div class="section">
<h2>Queue (<span id="queue-length">0</span> players)</h2>
<table id="queue-table">
<thead>
<tr>
<th>Pos</th>
<th>IP</th>
<th>Nick</th>
<th>Status</th>
</tr>
</thead>
<tbody id="queue-body">
<tr>
<td colspan="4" class="empty">No players in queue</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Scoreboard (<span id="board-total">0</span> players)</h2>
<table id="board-table">
<thead>
<tr>
<th>IP</th>
<th>Nick</th>
<th>Score</th>
<th>Connected</th>
</tr>
</thead>
<tbody id="board-body">
<tr>
<td colspan="4" class="empty">No scores recorded</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Clients (<span id="client-count">0</span> total)</h2>
<table id="client-table">
<thead>
<tr>
<th>IP</th>
<th>Type</th>
<th>Nick</th>
<th>User-Agent</th>
</tr>
</thead>
<tbody id="client-body">
<tr>
<td colspan="4" class="empty">No clients connected</td>
</tr>
</tbody>
</table>
</div>
<script src="/socket.js"></script>
<script type="module" src="../scripts/debug.js"></script>
</body>
</html>
+57
View File
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Host - Jaka To Melodia</title>
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="../styles/host.css" />
</head>
<body class="patterned">
<div class="container">
<h1>Host Panel</h1>
<div class="track-info">
<div class="track" id="track">—</div>
<div class="artist" id="artist">—</div>
</div>
<div class="section">
<div class="section-title">Playback</div>
<div class="button-group">
<button onclick="socket.host('play')">Play</button>
<button onclick="socket.host('pause')">Pause</button>
<button onclick="socket.host('next')">Next</button>
<button onclick="socket.host('clear')">Clear</button>
</div>
</div>
<div class="section">
<div class="section-title">Points</div>
<div class="button-group">
<button onclick="socket.host('points', { points: 0.5 })">+0.5</button>
<button onclick="socket.host('points', { points: 1 })">+1</button>
<button onclick="socket.host('points', { points: 2 })">+2</button>
<button onclick="socket.host('nextPlayer')">Next Player</button>
</div>
</div>
<div class="section">
<div class="section-title">QR Code</div>
<div class="button-group">
<button onclick="socket.host('showQr', { show: true })">Show QR</button>
<button onclick="socket.host('showQr', { show: false })">Hide QR</button>
</div>
</div>
</div>
<script src="/socket.js"></script>
<script type="module" src="../scripts/host.js"></script>
</body>
</html>
+32
View File
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Player - Jaka To Melodia</title>
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="../styles/player.css" />
</head>
<body class="patterned">
<!-- <div id="score">
<span>Punkty:</span>
<span id="points">0</span>
</div> -->
<input type="text" id="nick" placeholder="nick" maxlength="20" />
<button>
<!-- <img src="twerk.gif" alt="doopa" /> -->
</button>
<script src="/wakelock.js"></script>
<script src="/socket.js"></script>
<script type="module" src="../scripts/player.js"></script>
</body>
</html>
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TV - Jaka To Melodia</title>
<link rel="stylesheet" href="/common.css" />
<link rel="stylesheet" href="/pattern.css" />
<link rel="stylesheet" href="/loader.css" />
<link rel="stylesheet" href="../styles/tv.css" />
</head>
<body class="patterned">
<!-- Status Indicator -->
<div id="status" class="status"></div>
<!-- Left: Queue -->
<div class="section l">
<div class="title">
<i class="icon-stopwatch"></i>
</div>
<div id="queue">
<!-- Example
<div class="nick active"> </div>
-->
</div>
</div>
<!-- Right: Scoreboard -->
<div class="section r">
<div class="title">
<i class="icon-award"></i>
</div>
<div id="scoreboard">
<!-- Example
<div class="item">
<span class="rank"> </span>
<span class="nick"> </span>
<span class="score"> </span>
</div>
-->
</div>
</div>
<!-- QR Modal -->
<div id="qr-modal">
<div class="content">
<img src="/qr" alt="QR Code" />
</div>
</div>
<script src="/wakelock.js"></script>
<script src="/socket.js"></script>
<script type="module" src="../scripts/tv.js"></script>
</body>
</html>
+111
View File
@@ -0,0 +1,111 @@
const socket = new Socket('debug')
socket.on('update', data => {
updateDebug(data)
})
function updateDebug(data) {
// Update timestamp
document.getElementById('timestamp').textContent = new Date(data.timestamp).toLocaleTimeString()
// Update Music Status
const musicStatus = document.getElementById('music-status')
musicStatus.textContent = data.music.status
musicStatus.className = 'status ' + data.music.status
document.getElementById('music-platform').textContent = data.music.platform || '--'
document.getElementById('music-listeners').textContent = data.music.listenerCount
if (data.music.metadata && data.music.metadata.author && data.music.metadata.track) {
const metadataText = `${data.music.metadata.author} - ${data.music.metadata.track}`
document.getElementById('music-metadata-author').textContent = metadataText
document.getElementById('music-metadata-track').textContent = ''
} else {
document.getElementById('music-metadata-author').textContent = '--'
document.getElementById('music-metadata-track').textContent = ''
}
// Update Queue
document.getElementById('queue-length').textContent = data.queue.length
const queueBody = document.getElementById('queue-body')
if (data.queue.queue.length === 0) {
queueBody.innerHTML = '<tr><td colspan="4" class="empty">No players in queue</td></tr>'
} else {
queueBody.innerHTML = data.queue.queue
.map(
item => `
<tr>
<td>${item.position + 1}</td>
<td>${item.ip}</td>
<td>${item.nick || '--'}</td>
<td>${item.isActive ? '<span class="status active">ACTIVE</span>' : ''}</td>
</tr>
`
)
.join('')
}
// Update Scoreboard
document.getElementById('board-total').textContent = data.board.totalPlayers
const boardBody = document.getElementById('board-body')
if (data.board.scores.length === 0) {
boardBody.innerHTML = '<tr><td colspan="4" class="empty">No scores recorded</td></tr>'
} else {
boardBody.innerHTML = data.board.scores
.map(
item => `
<tr>
<td>${item.ip}</td>
<td>${item.nick}</td>
<td>${item.score}</td>
<td><span class="status ${item.connected ? 'connected' : 'disconnected'}">${
item.connected ? 'YES' : 'NO'
}</span></td>
</tr>
`
)
.join('')
}
// Update Clients
document.getElementById('client-count').textContent = data.client.clients.length
const clientBody = document.getElementById('client-body')
if (data.client.clients.length === 0) {
clientBody.innerHTML = '<tr><td colspan="4" class="empty">No clients connected</td></tr>'
} else {
// Sort clients: special types (tv, host, debug) first, then players
const specialTypes = ['tv', 'host', 'debug']
const sortedClients = [...data.client.clients].sort((a, b) => {
const aSpecial = specialTypes.includes(a.type)
const bSpecial = specialTypes.includes(b.type)
if (aSpecial && !bSpecial) return -1
if (!aSpecial && bSpecial) return 1
return 0
})
clientBody.innerHTML = sortedClients
.map(item => {
let uaDisplay = '--'
let uaTitle = '--'
if (item.userAgent) {
uaDisplay = `${item.userAgent.browser || 'Unknown'} / ${item.userAgent.os || 'Unknown'} / ${
item.userAgent.device
}`
uaTitle = item.userAgent.raw
}
const typeClass = specialTypes.includes(item.type) ? `type-${item.type}` : ''
return `
<tr>
<td>${item.ip}</td>
<td class="${typeClass}">${item.type || '--'}</td>
<td>${item.nick || '--'}</td>
<td title="${uaTitle}">${uaDisplay}</td>
</tr>
`
})
.join('')
}
}
+11
View File
@@ -0,0 +1,11 @@
// Create socket and expose globally for inline onclick handlers
window.socket = new Socket('host')
const artistElement = document.querySelector('#artist')
const trackElement = document.querySelector('#track')
// Use custom event listener for metadata updates
socket.on('metadata', metadata => {
artistElement.textContent = metadata.author
trackElement.textContent = metadata.track
})
+31
View File
@@ -0,0 +1,31 @@
const socket = new Socket('player')
requestWakeLock()
// Cache DOM elements
const nodeButton = document.querySelector('button'),
nodeNick = document.querySelector('#nick'),
nodePoints = document.querySelector('#points')
// Initialize nickname
const savedNick = localStorage.getItem('nick') || ''
nodeNick.value = savedNick
socket.player('setNick', { nick: savedNick })
// Handle button press
nodeButton.addEventListener('mousedown', () => socket.player('enter'))
nodeButton.addEventListener('touchstart', () => socket.player('enter'), { passive: true })
// Handle nickname changes
const setNick = e => {
const nick = e.target.value.trim().toLowerCase()
socket.player('setNick', { nick })
localStorage.setItem('nick', nick)
}
nodeNick.addEventListener('change', setNick)
// // Update points display using custom event listener
// socket.on('points', points => {
// nodePoints.textContent = points
// })
+72
View File
@@ -0,0 +1,72 @@
// SETUP
const statuses = {
paused: '<i class="icon-pause-circled"></i>',
playing: '<i class="icon-play-circled"></i>',
waiting: '<i class="icon-stop-circled"></i>',
}
const nodeStatus = document.querySelector('#status'),
nodeQueue = document.querySelector('#queue'),
nodeScore = document.querySelector('#scoreboard'),
nodeQrModal = document.querySelector('#qr-modal')
const socket = new Socket('tv')
var localStatus = 'waiting',
localQueue = [],
localActive = 0
function setStatus(status = 'waiting') {
const patternColors = {
playing: { fg: '#18dd5c', bg: '#1bc957' },
paused: { fg: '#82abdd', bg: '#88b2e3' },
waiting: { fg: '#9e82dd', bg: '#ab91e5' },
}
console.info('status', status)
nodeStatus.innerHTML = statuses[status]
document.body.style.setProperty('--fgcolor', patternColors[status].fg)
document.body.style.setProperty('--bgcolor', patternColors[status].bg)
}
function setQueue(queue, active = 0) {
nodeQueue.innerHTML = queue
.map((nick, i) => `<div class="nick ${i == active ? 'active' : ''}">${nick}</div>`)
.join('')
}
function showQrModal(show = true) {
if (show) nodeQrModal.classList.add('show')
else nodeQrModal.classList.remove('show')
}
function setScoreboard(scoreboard) {
const sorted = [...scoreboard].sort((a, b) => b.score - a.score)
const icon = '<i class="icon-award-1"></i>'
nodeScore.innerHTML = sorted
.map((player, i) => {
return `<div class="item">
<span class="rank">${i < 3 ? icon : `#${i + 1}`}</span>
<span class="nick">${player.nick || '---'}</span>
<span class="score">${player.score}</span>
</div>`
})
.join('')
}
// Initialize
requestWakeLock()
setStatus()
socket.on('update', ({ board, active, queue, status }) => {
setQueue(queue, active)
setStatus(status)
setScoreboard(board)
})
socket.on('showQr', data => {
showQrModal(data.show)
})
+148
View File
@@ -0,0 +1,148 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Courier New', monospace;
background: #1a1a1a;
color: #e0e0e0;
padding: 10px;
font-size: 12px;
}
h1 {
font-size: 16px;
margin-bottom: 10px;
color: #00ff00;
border-bottom: 1px solid #333;
padding-bottom: 5px;
}
h2 {
font-size: 14px;
margin: 15px 0 5px 0;
color: #00aaff;
}
.section {
margin-bottom: 15px;
border: 1px solid #333;
padding: 10px;
background: #0a0a0a;
}
table {
width: 100%;
border-collapse: collapse;
margin: 5px 0;
}
th,
td {
text-align: left;
padding: 4px 8px;
border: 1px solid #333;
}
th {
background: #222;
color: #ffaa00;
font-weight: bold;
}
td {
background: #111;
}
.status {
display: inline-block;
padding: 2px 6px;
border-radius: 3px;
font-weight: bold;
}
.status.connected {
background: #004400;
color: #00ff00;
}
.status.disconnected {
background: #440000;
color: #ff0000;
}
.status.playing {
background: #004400;
color: #00ff00;
}
.status.paused {
background: #444400;
color: #ffff00;
}
.status.waiting {
background: #444444;
color: #888888;
}
.status.active {
background: #000044;
color: #00aaff;
}
.type-tv {
background: #440044;
color: #ff00ff;
font-weight: bold;
}
.type-host {
background: #004444;
color: #00ffff;
font-weight: bold;
}
.type-debug {
background: #444400;
color: #ffff00;
font-weight: bold;
}
.timestamp {
float: right;
color: #666;
font-size: 11px;
}
.key-value {
display: grid;
grid-template-columns: 150px 1fr;
gap: 5px;
margin: 3px 0;
}
.key {
color: #888;
}
.value {
color: #e0e0e0;
word-break: break-all;
}
.empty {
color: #666;
font-style: italic;
}
.json {
background: #000;
border: 1px solid #333;
padding: 5px;
margin: 5px 0;
overflow-x: auto;
font-size: 11px;
}
+95
View File
@@ -0,0 +1,95 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
--fgcolor: #e77021;
--bgcolor: #f97a1e;
--pattern: 22px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 1rem;
}
.container {
width: 100%;
max-width: 600px;
border-radius: 1rem;
padding: 2rem;
background: #1a1a1a;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
h1 {
text-align: center;
margin-bottom: 1.5rem;
color: #f0f0f0;
font-size: 2rem;
}
.track-info {
background: var(--bgcolor);
border-radius: 0.75rem;
padding: 1.5rem;
margin-bottom: 2rem;
color: white;
text-align: center;
}
.track-info .artist {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.5rem;
opacity: 0.95;
}
.track-info .track {
font-size: 1.5rem;
font-weight: 700;
}
.section {
margin-bottom: 1.5rem;
}
.section-title {
font-size: 0.875rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
color: #999;
margin-bottom: 0.75rem;
}
.button-group {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 0.75rem;
}
button {
padding: 1rem;
font-size: 1rem;
font-weight: 600;
color: white;
background: var(--bgcolor);
border: none;
border-radius: 0.5rem;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
box-shadow: 0 4px 12px rgba(255, 68, 68, 0.4);
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255, 68, 68, 0.6);
}
button:active {
transform: translateY(0);
}
+55
View File
@@ -0,0 +1,55 @@
body {
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
overflow: hidden;
--fgcolor: #e7213b;
--bgcolor: #b93834;
--pattern: 22px;
}
button {
width: calc(100vw - 2rem);
height: calc(100vw - 2rem);
border-radius: 100%;
margin: 1rem;
background-color: #ee1020;
user-select: none;
border-width: 4px;
}
button > img {
height: 50%;
transition: 0.2s;
}
button:active > img {
height: 60%;
transform: skewx(-49deg);
}
button:active {
background-color: #bb1020;
}
input {
width: calc(100vw - 2rem);
box-sizing: border-box;
margin: 1rem;
margin-bottom: 0;
font-size: 1rem;
text-align: center;
font-family: monospace;
}
#score {
font-family: monospace;
box-sizing: border-box;
padding: 1em;
background-color: #fff6;
font-size: 1rem;
}
+168
View File
@@ -0,0 +1,168 @@
body {
height: 100vh;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
--pattern: 22px;
overflow: hidden;
position: relative;
}
.section {
flex: 1;
padding: 2rem;
overflow-y: auto;
background: #0005;
--margin: 1em;
margin: var(--margin);
border-radius: 1em;
}
.section.l {
margin-right: calc(var(--margin) / 2);
}
.section.r {
margin-left: calc(var(--margin) / 2);
}
.section .title {
font-size: 2.5rem;
font-weight: bold;
margin-bottom: 1.5rem;
text-align: center;
color: #fff;
font-family: monospace;
border-bottom: 1px solid #fff3;
padding-bottom: 0.5em;
}
#status {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: -1;
pointer-events: none;
font-size: 500px;
--opacity: 0.25;
text-shadow: 0 0 20px rgba(0, 0, 0, var(--opacity));
color: rgba(0, 0, 0, var(--opacity));
}
#queue {
font-size: 30px;
font-family: monospace;
text-align: left;
counter-reset: poz;
}
#queue>.nick {
display: flex;
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#queue>.nick::before {
counter-increment: poz;
content: '#' counter(poz) ' ';
font-weight: bold;
color: #ccc;
padding-right: 1em;
width: 1.5em;
}
#queue>img {
height: 10vh;
}
#queue .nick.active {
outline: 2px solid #fff;
}
#qr-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
z-index: 1000;
align-items: center;
justify-content: center;
}
#qr-modal.show {
display: flex;
}
#qr-modal .content {
background-color: white;
padding: 2rem;
border-radius: 1rem;
text-align: center;
max-width: 90vw;
max-height: 90vh;
}
#qr-modal .content img {
max-width: 100%;
height: auto;
border-radius: 0.5rem;
}
#scoreboard {
width: 100%;
font-size: 1.5rem;
font-family: monospace;
}
#scoreboard .item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.8rem 1.5rem;
margin: 0.5rem 0;
background-color: rgba(255, 255, 255, 0.15);
border-radius: 0.5rem;
color: #fff;
}
#scoreboard .item .rank i {
font-size: 2rem;
}
#scoreboard .item:nth-child(1) .rank {
color: gold;
}
#scoreboard .item:nth-child(2) .rank {
color: silver;
}
#scoreboard .item:nth-child(3) .rank {
color: #cd7f32;
/* Bronze */
}
#scoreboard .item>.rank {
font-weight: bold;
margin-right: 1rem;
min-width: 2.5rem;
}
#scoreboard .item>.nick {
flex: 1;
text-align: left;
}
#scoreboard .item>.score {
font-weight: bold;
min-width: 3rem;
text-align: right;
}
+25
View File
@@ -0,0 +1,25 @@
import { defineConfig } from 'vite'
import { resolve } from 'path'
export default defineConfig({
root: 'src/pages',
build: {
outDir: '../../dist',
emptyOutDir: true,
rollupOptions: {
input: {
debug: resolve(__dirname, 'src/pages/debug.html'),
host: resolve(__dirname, 'src/pages/host.html'),
player: resolve(__dirname, 'src/pages/player.html'),
tv: resolve(__dirname, 'src/pages/tv.html'),
},
},
// Inline assets to reduce HTTP requests
assetsInlineLimit: 10000, // 10kb - inline smaller assets
},
server: {
port: 5173,
open: false,
},
publicDir: '../../public',
})
+25
View File
@@ -0,0 +1,25 @@
import { defineConfig } from 'vite'
import { resolve } from 'path'
export default defineConfig({
build: {
ssr: true,
outDir: 'dist-server',
emptyOutDir: true,
rollupOptions: {
input: './server.js',
output: {
format: 'cjs', // CommonJS for nexe compatibility
entryFileNames: 'server.cjs',
},
},
target: 'node14',
minify: false, // Keep readable for debugging
},
ssr: {
// Bundle most dependencies, but exclude native modules
noExternal: true,
// Keep native/binary modules external for nexe to handle
external: ['ws'],
},
})