initial commit

This commit is contained in:
Nicola
2026-06-24 13:00:51 +02:00
commit 2d4c3864ef
11 changed files with 2555 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
node_modules/
.env
*.log
.DS_Store
Thumbs.db
+161
View File
@@ -0,0 +1,161 @@
# 🎾 Tennis Roots
Overlay per streaming tennis (OBS) con controller remoto via WebSocket.
## Architettura
```
┌─────────────────────┐ WebSocket ┌──────────────────────┐
│ Controller (admin) │────────────────────→│ │
│ /controller/ │←── STATE_UPDATE ───│ Express + WebSocket │
└─────────────────────┘ │ Server (hub) │
│ Port 3000 │
┌─────────────────────┐ WebSocket │ │
│ Scoreboard (OBS) │←── STATE_UPDATE ───│ │
│ Match Info (OBS) │←── STATE_UPDATE ───│ │
│ Clock (OBS) │←── STATE_UPDATE ───│ │
│ Server Ind. (OBS) │←── STATE_UPDATE ───│ │
└─────────────────────┘ └──────────────────────┘
```
## Quick Start
```bash
# Clona / entra nel progetto
cd tennis-roots
# Avvia tutto con uno script
chmod +x start.sh
./start.sh
```
Oppure manualmente:
```bash
cd server
npm install
npm start
```
Apri nel browser:
- **Controller**: http://localhost:3000/
- **Scoreboard**: http://localhost:3000/overlay/scoreboard.html
- **Match info**: http://localhost:3000/overlay/match-info.html
- **Clock**: http://localhost:3000/overlay/clock.html
- **Server indicator**: http://localhost:3000/overlay/server-indicator.html
## Widget Overlay (per OBS)
Ogni widget è un file HTML indipendente, dimensionabile e posizionabile
liberamente in OBS come **Browser Source**.
| Widget | URL | Dimensioni suggerite |
|--------|-----|---------------------|
| **Scoreboard** | `/overlay/scoreboard.html` | 820×130 px |
| **Match Info** | `/overlay/match-info.html` | 600×50 px |
| **Clock** | `/overlay/clock.html` | 150×50 px |
| **Server Indicator** | `/overlay/server-indicator.html` | 250×50 px |
### Setup in OBS
1. Aggiungi **Browser Source**
2. Inserisci URL del widget (es. `http://localhost:3000/overlay/scoreboard.html`)
3. Imposta larghezza/altezza come da tabella
4. **Importante**: spunta "Controlla audio/visibilità del browser nella sorgente"
5. Usa filtri di ritaglio/posizionamento per sistemare l'overlay
## Controller
Il pannello di controllo admin è accessibile a `/controller/`.
### Sezioni
- **Stato corrente**: live view del match
- **Punteggio**: pulsanti punto P1/P2, Deuce, Reset Game/Match
- **Servizio**: cambio battuta manuale
- **Giocatori**: modifica nomi e bandiere
- **Info Match**: torneo e round
### Scorciatoie da tastiera
| Tasto | Azione |
|-------|--------|
| `1` | Punto P1 |
| `2` | Punto P2 |
| `D` | Deuce |
| `R` | Reset Game |
| `M` | Reset Match |
## API HTTP
```bash
# Stato corrente
curl http://localhost:3000/api/state
# Aggiornamento parziale
curl -X POST http://localhost:3000/api/state \
-H 'Content-Type: application/json' \
-d '{"player1":"N. Djokovic","tournament":"US Open"}'
# Comando
curl -X POST http://localhost:3000/api/command \
-H 'Content-Type: application/json' \
-d '{"command":"ADD_POINT","player":1}'
```
## WebSocket
I widget si connettono automaticamente a `ws://localhost:3000/ws`.
Il server propaga gli aggiornamenti a tutti i client connessi.
### Formato messaggi
**Da controller a server:**
```json
{ "type": "COMMAND", "command": "ADD_POINT", "player": 1 }
{ "type": "COMMAND", "command": "SET_DEUCE" }
{ "type": "COMMAND", "command": "RESET_GAME" }
{ "type": "COMMAND", "command": "RESET_MATCH" }
{ "type": "COMMAND", "command": "SET_SERVER", "player": 2 }
{ "type": "STATE_UPDATE", "state": { "player1": "...", ... } }
```
**Da server a tutti:**
```json
{ "type": "STATE_UPDATE", "state": { ... } }
```
## Sviluppo
```bash
cd server
npm run dev # node --watch
```
## Regole punteggio implementate
- Punti game: 0, 15, 30, 40, Deuce, Vantaggio
- Set: primo a 6 game con 2 di scarto
- **Tiebreak**: a 6-6, primi a 7 punti con 2 di scarto
- Servizio nel tiebreak: punto 1 → P1, punto 2 → P2, poi cambio ogni 2 punti
- Match: al meglio dei 3 set
## Struttura file
```
tennis-roots/
├── server/
│ ├── package.json
│ ├── index.js # Server Express + WebSocket
│ └── node_modules/
├── overlay/
│ ├── common.js # Client WebSocket condiviso
│ ├── scoreboard.html
│ ├── match-info.html
│ ├── clock.html
│ └── server-indicator.html
├── controller/
│ └── index.html # Pannello di controllo
├── start.sh # Script avvio rapido
└── README.md
```
+539
View File
@@ -0,0 +1,539 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>🎾 Tennis Roots Controller</title>
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
background: #0f0f1a;
color: #e0e0e0;
padding: 24px;
min-height: 100vh;
}
h1 {
font-size: 28px;
font-weight: 700;
color: #facc15;
margin-bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
}
h1 small {
font-size: 14px;
font-weight: 400;
color: rgba(255,255,255,0.4);
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
max-width: 1100px;
}
.card {
background: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px;
padding: 18px 20px;
}
.card.full { grid-column: 1 / -1; }
.card h2 {
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
color: rgba(255,255,255,0.4);
margin-bottom: 14px;
}
.field {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.field label {
min-width: 80px;
font-size: 14px;
font-weight: 500;
color: rgba(255,255,255,0.6);
}
.field input,
.field select {
flex: 1;
background: rgba(255,255,255,0.08);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 6px;
padding: 8px 12px;
font-size: 15px;
color: #fff;
transition: border-color 0.2s;
}
.field input:focus,
.field select:focus {
outline: none;
border-color: #facc15;
}
.field input::placeholder { color: rgba(255,255,255,0.25); }
.field input.short { flex: 0 0 70px; text-align: center; }
.field .flag-select {
flex: 0 0 70px;
text-align: center;
font-size: 20px;
}
.btn-group {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 6px;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.15s;
display: inline-flex;
align-items: center;
gap: 6px;
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: #3b82f6; color: #fff; }
.btn-success { background: #22c55e; color: #fff; }
.btn-warning { background: #facc15; color: #000; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-ghost { background: rgba(255,255,255,0.08); color: #e0e0e0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.score-display {
display: flex;
justify-content: center;
align-items: center;
gap: 24px;
padding: 12px 0;
font-size: 32px;
font-weight: 700;
}
.score-display .vs {
font-size: 18px;
font-weight: 400;
color: rgba(255,255,255,0.25);
}
.score-display .p-score {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
}
.score-display .p-name {
font-size: 16px;
font-weight: 600;
color: rgba(255,255,255,0.7);
}
.score-display .p-points {
font-size: 36px;
font-weight: 800;
color: #facc15;
}
.score-display .p-points.adv { color: #4ade80; }
.score-display .playing-now {
font-size: 12px;
color: #facc15;
letter-spacing: 1px;
}
.sets-display {
display: flex;
justify-content: center;
gap: 32px;
font-size: 15px;
color: rgba(255,255,255,0.5);
margin-bottom: 8px;
}
.sets-display span {
display: flex;
align-items: center;
gap: 12px;
}
.sets-display .set-score {
font-weight: 700;
font-size: 18px;
color: #fff;
}
.sets-display .set-label {
font-size: 12px;
text-transform: uppercase;
color: rgba(255,255,255,0.3);
}
.status-bar {
display: flex;
align-items: center;
gap: 16px;
padding: 8px 0;
font-size: 14px;
color: rgba(255,255,255,0.5);
}
.status-bar .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #22c55e;
}
.status-bar .dot.disconnected { background: #ef4444; }
.status-bar .status-text {
color: #fff;
font-weight: 600;
}
.connection-status {
position: fixed;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: rgba(255,255,255,0.5);
}
.connection-status .led {
width: 10px;
height: 10px;
border-radius: 50%;
background: #ef4444;
transition: background 0.3s;
}
.connection-status .led.connected { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,0.5); }
@media (max-width: 700px) {
.grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="connection-status" id="connStatus">
<span class="led" id="connLed"></span>
<span id="connLabel">Disconnesso</span>
</div>
<h1>
🎾 Tennis Roots
<small>Controller</small>
</h1>
<div class="grid">
<!-- STATO IN TEMPO REALE -->
<div class="card full">
<h2>📊 Stato corrente</h2>
<div class="sets-display" id="setsDisplay"></div>
<div class="score-display">
<div class="p-score" id="p1score">
<span class="p-name" id="liveP1Name">P1</span>
<span class="playing-now" id="liveP1Serving"></span>
<span class="p-points" id="liveP1Points">0</span>
</div>
<span class="vs">VS</span>
<div class="p-score" id="p2score">
<span class="p-name" id="liveP2Name">P2</span>
<span class="playing-now" id="liveP2Serving"></span>
<span class="p-points" id="liveP2Points">0</span>
</div>
</div>
<div class="status-bar">
<span class="dot" id="statusDot"></span>
<span class="status-text" id="liveStatus">In attesa...</span>
</div>
</div>
<!-- PUNTEGGIO -->
<div class="card">
<h2>🎾 Punteggio</h2>
<div class="btn-group">
<button class="btn btn-success" onclick="addPoint(1)">🎾 Punto P1</button>
<button class="btn btn-success" onclick="addPoint(2)">🎾 Punto P2</button>
</div>
<div class="btn-group" style="margin-top:8px">
<button class="btn btn-warning" onclick="setDeuce()">⚖️ Deuce</button>
<button class="btn btn-ghost" onclick="resetGame()">🔄 Reset Game</button>
</div>
<div class="btn-group" style="margin-top:8px">
<button class="btn btn-danger" onclick="resetMatch()">🗑️ Reset Match</button>
</div>
</div>
<!-- SERVIZIO -->
<div class="card">
<h2>🎾 Servizio</h2>
<div class="field">
<label>Battuta:</label>
<select id="serverSelect">
<option value="1">P1</option>
<option value="2">P2</option>
</select>
<button class="btn btn-primary btn-sm" onclick="setServer()">Imposta</button>
</div>
</div>
<!-- GIOCATORI -->
<div class="card">
<h2>👤 Giocatori</h2>
<div class="field">
<label>P1 Nome:</label>
<input type="text" id="p1Name" value="J. Sinner" />
</div>
<div class="field">
<label>P1 Bandiera:</label>
<select class="flag-select" id="p1Flag">
<option value="it">🇮🇹</option>
<option value="es">🇪🇸</option>
<option value="us">🇺🇸</option>
<option value="fr">🇫🇷</option>
<option value="gb">🇬🇧</option>
<option value="de">🇩🇪</option>
<option value="au">🇦🇺</option>
<option value="ch">🇨🇭</option>
<option value="rs">🇷🇸</option>
<option value="gr">🇬🇷</option>
<option value="br">🇧🇷</option>
<option value="ar">🇦🇷</option>
</select>
</div>
<div class="field">
<label>P2 Nome:</label>
<input type="text" id="p2Name" value="C. Alcaraz" />
</div>
<div class="field">
<label>P2 Bandiera:</label>
<select class="flag-select" id="p2Flag">
<option value="it">🇮🇹</option>
<option value="es" selected>🇪🇸</option>
<option value="us">🇺🇸</option>
<option value="fr">🇫🇷</option>
<option value="gb">🇬🇧</option>
<option value="de">🇩🇪</option>
<option value="au">🇦🇺</option>
<option value="ch">🇨🇭</option>
<option value="rs">🇷🇸</option>
<option value="gr">🇬🇷</option>
<option value="br">🇧🇷</option>
<option value="ar">🇦🇷</option>
</select>
</div>
<div class="btn-group" style="margin-top:6px">
<button class="btn btn-primary" onclick="updatePlayers()">💾 Salva Giocatori</button>
</div>
</div>
<!-- MATCH INFO -->
<div class="card">
<h2>📋 Info Match</h2>
<div class="field">
<label>Torneo:</label>
<input type="text" id="tournament" value="Wimbledon" />
</div>
<div class="field">
<label>Round:</label>
<input type="text" id="round" value="Finale · Uomini · Singolare" />
</div>
<div class="btn-group" style="margin-top:6px">
<button class="btn btn-primary" onclick="updateMatchInfo()">💾 Salva Info</button>
</div>
</div>
<!-- SCORCIATOIE -->
<div class="card">
<h2>⌨️ Scorciatoie</h2>
<div style="font-size:13px; color:rgba(255,255,255,0.5); line-height:1.8">
<kbd style="background:rgba(255,255,255,0.1); padding:2px 6px; border-radius:3px;">1</kbd> Punto P1 &nbsp;
<kbd style="background:rgba(255,255,255,0.1); padding:2px 6px; border-radius:3px;">2</kbd> Punto P2 &nbsp;
<kbd style="background:rgba(255,255,255,0.1); padding:2px 6px; border-radius:3px;">D</kbd> Deuce &nbsp;
<kbd style="background:rgba(255,255,255,0.1); padding:2px 6px; border-radius:3px;">R</kbd> Reset Game &nbsp;
<kbd style="background:rgba(255,255,255,0.1); padding:2px 6px; border-radius:3px;">M</kbd> Reset Match
</div>
</div>
</div>
<script>
// ---- WebSocket ----
const WS_URL = `ws://${location.host}/ws`;
let ws = null;
let currentState = {};
let reconnectTimer = null;
function connect() {
if (ws && (ws.readyState === 0 || ws.readyState === 1)) return;
ws = new WebSocket(WS_URL);
ws.onopen = () => {
document.getElementById('connLed').className = 'led connected';
document.getElementById('connLabel').textContent = 'Connesso';
};
ws.onmessage = (event) => {
try {
const msg = JSON.parse(event.data);
if (msg.type === 'STATE_UPDATE') {
currentState = msg.state;
updateUI();
}
} catch (e) {}
};
ws.onclose = () => {
document.getElementById('connLed').className = 'led';
document.getElementById('connLabel').textContent = 'Disconnesso';
scheduleReconnect();
};
ws.onerror = () => ws.close();
}
function scheduleReconnect() {
if (reconnectTimer) clearTimeout(reconnectTimer);
reconnectTimer = setTimeout(connect, 2000);
}
function send(msg) {
if (ws && ws.readyState === 1) {
ws.send(JSON.stringify(msg));
}
}
// ---- UI Update ----
function pointLabel(state) {
if (state.tiebreak) {
return [String(state.tiebreakPoints[0]), String(state.tiebreakPoints[1])];
}
const p1 = state.points[0];
const p2 = state.points[1];
if (state.deuce) {
if (state.advantage === 1) return ['AD', '40'];
if (state.advantage === 2) return ['40', 'AD'];
return ['40', '40'];
}
const map = ['0', '15', '30', '40'];
return [map[p1] || '40', map[p2] || '40'];
}
function updateUI() {
const s = currentState;
if (!s || !s.player1) return;
// Giocatori
document.getElementById('liveP1Name').textContent = s.player1;
document.getElementById('liveP2Name').textContent = s.player2;
document.getElementById('p1Name').value = s.player1;
document.getElementById('p2Name').value = s.player2;
document.getElementById('p1Flag').value = s.flag1 || 'it';
document.getElementById('p2Flag').value = s.flag2 || 'es';
document.getElementById('serverSelect').value = s.server || 1;
// Punti
const labels = pointLabel(s);
const p1el = document.getElementById('liveP1Points');
const p2el = document.getElementById('liveP2Points');
p1el.textContent = labels[0];
p2el.textContent = labels[1];
p1el.className = 'p-points' + (s.advantage === 1 ? ' adv' : '');
p2el.className = 'p-points' + (s.advantage === 2 ? ' adv' : '');
// Servizio
document.getElementById('liveP1Serving').textContent = s.server === 1 ? '● Serve' : '';
document.getElementById('liveP2Serving').textContent = s.server === 2 ? '● Serve' : '';
// Set
const setsEl = document.getElementById('setsDisplay');
let setsHtml = '';
const setLabels = ['S1', 'S2', 'S3'];
for (let i = 0; i < 3; i++) {
const ss = s.sets[i] || [0, 0];
const active = i === s.currentSet ? ' style="color:#facc15"' : '';
setsHtml += `<span><span class="set-label">${setLabels[i]}</span><span class="set-score"${active}>${ss[0]}${ss[1]}</span></span>`;
}
setsEl.innerHTML = setsHtml;
// Stato
document.getElementById('liveStatus').textContent = s.matchStatus || 'In corso';
document.getElementById('statusDot').style.background = s.matchOver ? '#22c55e' : '#facc15';
// Info match
document.getElementById('tournament').value = s.tournament || '';
document.getElementById('round').value = s.round || '';
}
// ---- Comandi ----
function addPoint(player) {
send({ type: 'COMMAND', command: 'ADD_POINT', player });
}
function resetGame() {
send({ type: 'COMMAND', command: 'RESET_GAME' });
}
function resetMatch() {
if (confirm('Reset totale del match?')) {
send({ type: 'COMMAND', command: 'RESET_MATCH' });
}
}
function setDeuce() {
send({ type: 'COMMAND', command: 'SET_DEUCE' });
}
function setServer() {
const val = parseInt(document.getElementById('serverSelect').value);
send({ type: 'COMMAND', command: 'SET_SERVER', player: val });
}
function updatePlayers() {
send({
type: 'STATE_UPDATE',
state: {
player1: document.getElementById('p1Name').value || 'P1',
player2: document.getElementById('p2Name').value || 'P2',
flag1: document.getElementById('p1Flag').value,
flag2: document.getElementById('p2Flag').value,
}
});
}
function updateMatchInfo() {
send({
type: 'STATE_UPDATE',
state: {
tournament: document.getElementById('tournament').value || 'Torneo',
round: document.getElementById('round').value || '',
}
});
}
// ---- Keyboard shortcuts ----
document.addEventListener('keydown', (e) => {
if (e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT') return;
if (e.key === '1') addPoint(1);
if (e.key === '2') addPoint(2);
if (e.key === 'd' || e.key === 'D') setDeuce();
if (e.key === 'r') resetGame();
if (e.key === 'm' || e.key === 'M') resetMatch();
});
// ---- Init ----
connect();
</script>
</body>
</html>
+62
View File
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock</title>
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
overflow: hidden;
font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
background: transparent;
color: #fff;
user-select: none;
}
.widget {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.clock {
background: rgba(0,0,0,0.5);
backdrop-filter: blur(6px);
border: 1px solid rgba(255,255,255,0.08);
border-radius: calc(min(8px, 0.6vw));
padding: 0.4em 1em;
font-size: clamp(16px, 2vw, 32px);
font-weight: 600;
letter-spacing: 1px;
color: rgba(255,255,255,0.7);
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.clock { animation: fadeIn 0.8s ease-out; }
</style>
</head>
<body>
<div class="widget">
<div class="clock" id="clock">00:00:00</div>
</div>
<script>
function updateClock() {
const now = new Date();
document.getElementById('clock').textContent =
now.toLocaleTimeString('it-IT', { hour12: false });
}
setInterval(updateClock, 1000);
updateClock();
</script>
</body>
</html>
+131
View File
@@ -0,0 +1,131 @@
/**
* common.js Stato condiviso tra i widget overlay via WebSocket
*
* Ogni widget si connette al server Express+WS e ascolta gli aggiornamenti.
* Il pannello di controllo invia comandi/aggiornamenti, il server li
* propaga a tutti i widget connessi.
*/
// ---- Config ----
const WS_URL = (() => {
const loc = window.location;
const protocol = loc.protocol === 'https:' ? 'wss:' : 'ws:';
return `${protocol}//${loc.host}/ws`;
})();
let ws = null;
let currentState = {};
let subscribers = [];
let reconnectTimer = null;
let connectAttempts = 0;
// ---- WebSocket connection ----
function connect() {
if (ws && (ws.readyState === 0 || ws.readyState === 1)) return;
ws = new WebSocket(WS_URL);
ws.onopen = () => {
console.log('🟢 WS connected');
connectAttempts = 0;
};
ws.onmessage = (event) => {
try {
const msg = JSON.parse(event.data);
if (msg.type === 'STATE_UPDATE' && msg.state) {
currentState = msg.state;
notifySubscribers();
}
} catch (err) {
console.error('❌ WS message error:', err);
}
};
ws.onclose = () => {
console.log('🔴 WS disconnected, reconnecting...');
scheduleReconnect();
};
ws.onerror = (err) => {
console.error('❌ WS error:', err);
ws.close();
};
}
function scheduleReconnect() {
if (reconnectTimer) clearTimeout(reconnectTimer);
const delay = Math.min(1000 * 2 ** connectAttempts, 10000);
connectAttempts++;
reconnectTimer = setTimeout(connect, delay);
}
// ---- Subscribe to state updates ----
/**
* Si iscrive agli aggiornamenti di stato.
* @param {(state: object) => void} callback
* @returns {() => void} unsubscribe function
*/
function onStateUpdate(callback) {
subscribers.push(callback);
// Chiamata immediata con stato corrente (se già presente)
if (Object.keys(currentState).length > 0) {
callback({ ...currentState });
}
return () => {
subscribers = subscribers.filter((cb) => cb !== callback);
};
}
function notifySubscribers() {
const state = { ...currentState };
for (const cb of subscribers) {
try { cb(state); } catch (e) { console.error(e); }
}
}
/**
* Invia un comando al server (ADD_POINT, RESET_GAME, RESET_MATCH, SET_DEUCE, SET_SERVER)
*/
function sendCommand(command, player = null) {
const msg = { type: 'COMMAND', command };
if (player !== null) msg.player = player;
sendMessage(msg);
}
/**
* Invia un aggiornamento parziale di stato al server
*/
function sendStateUpdate(partial) {
sendMessage({ type: 'STATE_UPDATE', state: partial });
}
function sendMessage(msg) {
if (ws && ws.readyState === 1) {
ws.send(JSON.stringify(msg));
} else {
console.warn('⚠️ WS not connected, cannot send');
}
}
/**
* Utility: mappa punti → label tennis
*/
function pointLabel(state) {
// Tiebreak: mostra punti numerici
if (state.tiebreak) {
return [String(state.tiebreakPoints[0]), String(state.tiebreakPoints[1])];
}
const p1 = state.points[0];
const p2 = state.points[1];
if (state.deuce) {
if (state.advantage === 1) return ['AD', '40'];
if (state.advantage === 2) return ['40', 'AD'];
return ['40', '40'];
}
const map = ['0', '15', '30', '40'];
return [map[p1] || '40', map[p2] || '40'];
}
// ---- Auto-connect ----
connect();
+105
View File
@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Match Info</title>
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
overflow: hidden;
font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
background: transparent;
color: #fff;
user-select: none;
}
.widget {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.match-info {
background: linear-gradient(135deg, rgba(0,0,0,0.85), rgba(20,20,30,0.85));
backdrop-filter: blur(8px);
border: 1px solid rgba(255,255,255,0.12);
border-radius: calc(min(12px, 0.8vw));
padding: 0.6em 1.6em;
display: inline-flex;
align-items: center;
gap: 1em;
font-size: clamp(12px, 1.4vw, 20px);
letter-spacing: 0.5px;
white-space: nowrap;
box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.match-info .tournament {
font-weight: 700;
color: #facc15;
text-transform: uppercase;
}
.match-info .separator {
width: 1px;
height: 1.2em;
background: rgba(255,255,255,0.2);
flex-shrink: 0;
}
.match-info .round {
font-weight: 400;
color: rgba(255,255,255,0.7);
}
.match-info .status {
font-weight: 600;
color: rgba(255,255,255,0.9);
}
.match-info .status.winner {
color: #4ade80;
}
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.match-info { animation: fadeInUp 0.5s ease-out; }
</style>
</head>
<body>
<div class="widget">
<div class="match-info">
<span class="tournament" id="tournament">🎾 Wimbledon</span>
<span class="separator"></span>
<span class="round" id="round">Finale · Uomini · Singolare</span>
<span class="separator" id="statusSep"></span>
<span class="status" id="status">🎾 In corso · Set 1</span>
</div>
</div>
<script src="common.js"></script>
<script>
function updateMatchInfo(state) {
document.getElementById('tournament').textContent = state.tournament || '🎾 Torneo';
document.getElementById('round').textContent = state.round || '';
const statusEl = document.getElementById('status');
if (state.matchOver) {
const winner = state.sets.reduce((a, s) => a + (s[0] > s[1] ? 1 : 0), 0) >= 2
? state.player1 : state.player2;
statusEl.textContent = '🏆 ' + winner + ' vince!';
statusEl.classList.add('winner');
document.getElementById('statusSep').style.display = '';
} else {
statusEl.textContent = state.matchStatus || '🎾 In corso · Set ' + (state.currentSet + 1);
statusEl.classList.remove('winner');
document.getElementById('statusSep').style.display = '';
}
}
const unsub = onStateUpdate(updateMatchInfo);
</script>
</body>
</html>
+254
View File
@@ -0,0 +1,254 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Scoreboard</title>
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
overflow: hidden;
font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
background: transparent;
color: #fff;
user-select: none;
}
/* Contenitore responsive centra il widget */
.widget {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
/* Scoreboard si adatta al contenuto */
.scoreboard {
display: inline-block;
min-width: 380px;
max-width: 100%;
background: linear-gradient(160deg, rgba(0,0,0,0.88), rgba(10,10,20,0.88));
backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.1);
border-radius: calc(min(16px, 1.2vw));
overflow: hidden;
box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
/* Header (Sets) */
.sb-header {
display: grid;
grid-template-columns: minmax(0, 1fr) 48px 48px 48px 60px;
background: rgba(255,255,255,0.06);
border-bottom: 1px solid rgba(255,255,255,0.06);
padding: 0.5em 1.2em;
font-size: clamp(10px, 1.2vw, 14px);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
color: rgba(255,255,255,0.5);
}
.sb-header .col-player { text-align: left; }
.sb-header .col-set,
.sb-header .col-points { text-align: center; }
/* Player Row */
.player-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 48px 48px 48px 60px;
align-items: center;
padding: 0.6em 1.2em;
border-bottom: 1px solid rgba(255,255,255,0.04);
transition: background 0.3s;
position: relative;
font-size: clamp(14px, 1.8vw, 22px);
}
.player-row:last-child { border-bottom: none; }
.player-row.serving {
background: rgba(250, 204, 21, 0.06);
}
.player-row.serving::before {
content: '●';
position: absolute;
left: 0.3em;
top: 50%;
transform: translateY(-50%);
font-size: 0.5em;
color: #facc15;
text-shadow: 0 0 8px rgba(250,204,21,0.6);
}
.player-row .player-name {
font-weight: 700;
letter-spacing: 0.5px;
display: flex;
align-items: center;
gap: 0.5em;
}
.player-row .player-name .flag {
display: inline-block;
width: 1.6em;
height: 1.1em;
border-radius: 2px;
background-size: cover;
background-position: center;
flex-shrink: 0;
}
/* Bandiere inline SVG base64 */
.flag-it { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="1" height="2" fill="%23009246"/><rect x="1" width="1" height="2" fill="%23fff"/><rect x="2" width="1" height="2" fill="%23ce2b37"/></svg>'); }
.flag-es { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23c60b1e"/><rect y="0.5" width="3" height="1" fill="%23ffc400"/></svg>'); }
.flag-us { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23fff"/><rect width="3" height="1" fill="%23b22234"/><rect y="1" width="3" height="1" fill="%233b3b6d"/></svg>'); }
.flag-fr { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="1" height="2" fill="%23005240"/><rect x="1" width="1" height="2" fill="%23fff"/><rect x="2" width="1" height="2" fill="%23ce2b37"/></svg>'); }
.flag-gb { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23012369"/><rect width="3" height="1" fill="%23c8102e"/><rect y="0.33" width="3" height="0.33" fill="%23fff"/><rect y="1.33" width="3" height="0.33" fill="%23fff"/></svg>'); }
.flag-au { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%2300008b"/><rect width="1.5" height="1" fill="%23fff"/><path d="M0 0L1.5 1M0 1L1.5 0" stroke="%23c8102e" stroke-width="0.15"/></svg>'); }
.flag-de { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="0.67" fill="%23000"/><rect y="0.67" width="3" height="0.67" fill="%23dd0000"/><rect y="1.33" width="3" height="0.67" fill="%23ffce00"/></svg>'); }
.flag-ch { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23d52b1e"/><rect x="1.2" y="0.4" width="0.6" height="1.2" fill="%23fff"/><rect x="0.8" y="0.8" width="1.4" height="0.4" fill="%23fff"/></svg>'); }
.flag-rs { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23fff"/><rect y="0.67" width="3" height="0.67" fill="%23005240"/><rect y="1.33" width="3" height="0.67" fill="%23c8102e"/></svg>'); }
.flag-gr { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23005b94"/><rect x="0.5" y="0.5" width="1" height="1" fill="%23fff"/><rect y="0.5" width="3" height="0.2" fill="%23fff"/></svg>'); }
.flag-br { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23009246"/><circle cx="1.5" cy="1" r="0.6" fill="%23ffcc00"/><path d="M1.5 0.6l0.3 0.5h-0.6z" fill="%23005240"/></svg>'); }
.flag-ar { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23fff"/><rect y="0.33" width="3" height="0.67" fill="%2375aadb"/><rect y="1" width="3" height="0.67" fill="%2375aadb"/></svg>'); }
.player-row .set-score {
text-align: center;
font-weight: 700;
}
.player-row .set-score.current-set {
color: #facc15;
}
.player-row .points {
text-align: center;
font-weight: 800;
letter-spacing: 1px;
font-size: 1.2em;
}
.player-row .points.deuce {
font-size: 0.7em;
font-weight: 600;
text-transform: uppercase;
color: #facc15;
}
.player-row .points.advantage {
color: #4ade80;
}
/* Animazioni */
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.scoreboard { animation: fadeInUp 0.5s ease-out; }
@keyframes pointFlash {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.25); }
}
.points.flash {
animation: pointFlash 0.25s ease;
}
</style>
</head>
<body>
<div class="widget">
<div class="scoreboard" id="scoreboard">
<div class="sb-header">
<span class="col-player">Giocatore</span>
<span class="col-set">S1</span>
<span class="col-set">S2</span>
<span class="col-set">S3</span>
<span class="col-points">Punti</span>
</div>
<div class="player-row" id="player1Row">
<div class="player-name">
<span class="flag" id="flag1"></span>
<span id="player1Name">J. Sinner</span>
</div>
<span class="set-score" id="p1s1">0</span>
<span class="set-score" id="p1s2">0</span>
<span class="set-score" id="p1s3">0</span>
<span class="points" id="p1points">0</span>
</div>
<div class="player-row" id="player2Row">
<div class="player-name">
<span class="flag" id="flag2"></span>
<span id="player2Name">C. Alcaraz</span>
</div>
<span class="set-score" id="p2s1">0</span>
<span class="set-score" id="p2s2">0</span>
<span class="set-score" id="p2s3">0</span>
<span class="points" id="p2points">0</span>
</div>
</div>
</div>
<script src="common.js"></script>
<script>
let prevPoints = [0, 0];
let prevDeuce = false;
let prevAdv = 0;
function updateScoreboard(state) {
// Nomi e bandiere
document.getElementById('player1Name').textContent = state.player1;
document.getElementById('player2Name').textContent = state.player2;
document.getElementById('flag1').className = 'flag flag-' + (state.flag1 || 'it');
document.getElementById('flag2').className = 'flag flag-' + (state.flag2 || 'es');
// Set
for (let s = 0; s < 3; s++) {
const e1 = document.getElementById('p1s' + (s + 1));
const e2 = document.getElementById('p2s' + (s + 1));
if (state.sets[s]) {
e1.textContent = state.sets[s][0] ?? '0';
e2.textContent = state.sets[s][1] ?? '0';
} else {
e1.textContent = '0';
e2.textContent = '0';
}
e1.classList.toggle('current-set', s === state.currentSet);
e2.classList.toggle('current-set', s === state.currentSet);
}
// Punti
const labels = pointLabel(state);
const p1el = document.getElementById('p1points');
const p2el = document.getElementById('p2points');
p1el.textContent = labels[0];
p2el.textContent = labels[1];
// Classi punti
p1el.className = 'points';
p2el.className = 'points';
if (state.deuce) {
p1el.classList.add('deuce');
p2el.classList.add('deuce');
if (state.advantage === 1) p1el.classList.add('advantage');
if (state.advantage === 2) p2el.classList.add('advantage');
}
// Flash su cambio punti
const pNow = state.points;
if (pNow[0] !== prevPoints[0] || pNow[1] !== prevPoints[1] ||
state.deuce !== prevDeuce || state.advantage !== prevAdv) {
const changed = pNow[0] !== prevPoints[0] ? 1 : 2;
const el = document.getElementById('p' + changed + 'points');
el.classList.remove('flash');
void el.offsetWidth;
el.classList.add('flash');
}
prevPoints = [...pNow];
prevDeuce = state.deuce;
prevAdv = state.advantage;
// Servizio
document.getElementById('player1Row').classList.toggle('serving', state.server === 1);
document.getElementById('player2Row').classList.toggle('serving', state.server === 2);
}
// Ascolta aggiornamenti
const unsub = onStateUpdate(updateScoreboard);
</script>
</body>
</html>
+87
View File
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Server Indicator</title>
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
overflow: hidden;
font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
background: transparent;
color: #fff;
user-select: none;
}
.widget {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.server-indicator {
background: rgba(0,0,0,0.6);
backdrop-filter: blur(6px);
border: 1px solid rgba(255,255,255,0.1);
border-radius: calc(min(10px, 0.7vw));
padding: 0.5em 1.2em;
display: inline-flex;
align-items: center;
gap: 0.6em;
font-size: clamp(12px, 1.4vw, 20px);
font-weight: 600;
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.server-indicator .dot {
display: inline-block;
width: 0.6em;
height: 0.6em;
border-radius: 50%;
background: #facc15;
box-shadow: 0 0 10px rgba(250,204,21,0.6);
animation: pulse 1.5s ease-in-out infinite;
}
.server-indicator .player-label {
color: rgba(255,255,255,0.8);
}
.server-indicator .player-name {
color: #fff;
font-weight: 700;
}
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(0.9); }
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.server-indicator { animation: fadeIn 0.5s ease-out; }
</style>
</head>
<body>
<div class="widget">
<div class="server-indicator" id="indicator">
<span class="dot"></span>
<span class="player-label">Serve:</span>
<span class="player-name" id="serverName">J. Sinner</span>
</div>
</div>
<script src="common.js"></script>
<script>
function updateServer(state) {
const name = state.server === 1 ? state.player1 : state.player2;
document.getElementById('serverName').textContent = name;
}
const unsub = onStateUpdate(updateServer);
</script>
</body>
</html>
+348
View File
@@ -0,0 +1,348 @@
/**
* Tennis Roots Server Express + WebSocket
*
* Funge da hub centrale:
* - Serve gli overlay (statici)
* - Serve il pannello di controllo (statico)
* - Gestisce le connessioni WebSocket per lo stato in tempo reale
*/
import express from 'express';
import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PORT = process.env.PORT || 3000;
// ---- Stato di default ----
const defaultState = {
player1: 'J. Sinner',
player2: 'C. Alcaraz',
flag1: 'it',
flag2: 'es',
sets: [
[0, 0],
[0, 0],
[0, 0],
],
games: [0, 0],
points: [0, 0],
server: 1,
currentSet: 0,
matchOver: false,
deuce: false,
advantage: 0,
tiebreak: false,
tiebreakPoints: [0, 0],
tiebreakFirstServer: 1,
tournament: 'Wimbledon',
round: 'Finale · Uomini · Singolare',
matchStatus: '🎾 In corso · Set 1',
};
let currentState = { ...defaultState };
// ---- Utility punteggio tennis ----
function computeMatchStatus(state) {
if (state.matchOver) {
const p1Sets = state.sets.reduce((a, s) => a + (s[0] > s[1] ? 1 : 0), 0);
const winner = p1Sets >= 2 ? state.player1 : state.player2;
return `🏆 ${winner} vince!`;
}
const set = state.currentSet + 1;
if (state.tiebreak) {
return `🎾 Tiebreak · Set ${set} · ${state.tiebreakPoints[0]}-${state.tiebreakPoints[1]}`;
}
return `🎾 In corso · Set ${set}`;
}
function pointLabel(state) {
// Tiebreak: mostra punti numerici
if (state.tiebreak) {
return [String(state.tiebreakPoints[0]), String(state.tiebreakPoints[1])];
}
const p1 = state.points[0];
const p2 = state.points[1];
if (state.deuce) {
if (state.advantage === 1) return ['AD', '40'];
if (state.advantage === 2) return ['40', 'AD'];
return ['40', '40'];
}
const map = ['0', '15', '30', '40'];
return [map[p1] || '40', map[p2] || '40'];
}
// ---- Express ----
const app = express();
const server = createServer(app);
// Static files: overlay
app.use('/overlay', express.static(resolve(__dirname, '..', 'overlay')));
// Static files: controller
app.use('/controller', express.static(resolve(__dirname, '..', 'controller')));
// Redirect root → controller
app.get('/', (req, res) => {
res.redirect('/controller/');
});
// API: GET stato corrente
app.get('/api/state', (req, res) => {
res.json(currentState);
});
// API: POST aggiornamento stato (da controller via HTTP)
app.post('/api/state', express.json(), (req, res) => {
const partial = req.body;
currentState = { ...currentState, ...partial, matchStatus: undefined };
currentState.matchStatus = computeMatchStatus(currentState);
currentState.timestamp = Date.now();
broadcast({ type: 'STATE_UPDATE', state: currentState });
res.json({ ok: true, state: currentState });
});
// API: POST comando (ADD_POINT, RESET_GAME, RESET_MATCH)
app.post('/api/command', express.json(), (req, res) => {
const { command, player } = req.body;
handleCommand(command, player);
res.json({ ok: true, state: currentState });
});
// ---- WebSocket ----
const wss = new WebSocketServer({ server, path: '/ws' });
wss.on('connection', (ws) => {
console.log('🟢 WebSocket client connected');
// Invia stato corrente al nuovo client
ws.send(JSON.stringify({ type: 'STATE_UPDATE', state: currentState }));
ws.on('message', (data) => {
try {
const msg = JSON.parse(data.toString());
if (msg.type === 'COMMAND') {
handleCommand(msg.command, msg.player);
return;
}
if (msg.type === 'STATE_UPDATE') {
currentState = { ...currentState, ...msg.state, matchStatus: undefined };
currentState.matchStatus = computeMatchStatus(currentState);
currentState.timestamp = Date.now();
broadcast({ type: 'STATE_UPDATE', state: currentState }, ws);
return;
}
} catch (err) {
console.error('❌ Invalid message:', err.message);
}
});
ws.on('close', () => {
console.log('🔴 WebSocket client disconnected');
});
});
function broadcast(message, exclude = null) {
const payload = JSON.stringify(message);
for (const client of wss.clients) {
if (client !== exclude && client.readyState === 1) {
client.send(payload);
}
}
}
// ---- Comandi ----
function handleCommand(command, player) {
switch (command) {
case 'ADD_POINT':
addPoint(player);
break;
case 'RESET_GAME':
currentState.points = [0, 0];
currentState.deuce = false;
currentState.advantage = 0;
currentState.tiebreak = false;
currentState.tiebreakPoints = [0, 0];
currentState.tiebreakFirstServer = 1;
break;
case 'RESET_MATCH':
currentState = { ...defaultState, timestamp: Date.now() };
break;
case 'SET_DEUCE':
currentState.deuce = true;
currentState.advantage = 0;
currentState.points = [3, 3];
break;
case 'SET_SERVER':
currentState.server = player; // player = 1 o 2
break;
default:
return;
}
currentState.matchStatus = computeMatchStatus(currentState);
currentState.timestamp = Date.now();
broadcast({ type: 'STATE_UPDATE', state: currentState });
}
function addPoint(player) {
const idx = player - 1;
if (currentState.matchOver) return;
// ---- TIEBREAK ----
if (currentState.tiebreak) {
currentState.tiebreakPoints[idx]++;
const tp1 = currentState.tiebreakPoints[0];
const tp2 = currentState.tiebreakPoints[1];
// Aggiorna server per il punto successivo nel tiebreak
updateTiebreakServer(currentState);
// Vinta se ≥7 punti e 2 di scarto
if ((tp1 >= 7 || tp2 >= 7) && Math.abs(tp1 - tp2) >= 2) {
// Ha vinto il tiebreak → set 7-6
const won = tp1 > tp2 ? 0 : 1;
currentState.sets[currentState.currentSet][won] = 7;
currentState.sets[currentState.currentSet][1 - won] = 6;
currentState.tiebreak = false;
currentState.tiebreakPoints = [0, 0];
currentState.games = [0, 0];
// Controlla match vinto
let p1Sets = 0, p2Sets = 0;
for (let i = 0; i < 3; i++) {
if (currentState.sets[i][0] > currentState.sets[i][1]) p1Sets++;
else if (currentState.sets[i][1] > currentState.sets[i][0]) p2Sets++;
}
if (p1Sets >= 2 || p2Sets >= 2) {
currentState.matchOver = true;
} else {
currentState.currentSet++;
}
currentState.server = currentState.server === 1 ? 2 : 1;
}
return;
}
// ---- GIOCO NORMALE ----
if (currentState.deuce) {
if (currentState.advantage === player) {
currentState.points = [0, 0];
currentState.deuce = false;
currentState.advantage = 0;
addGame(player);
} else if (currentState.advantage === 0) {
currentState.advantage = player;
} else {
currentState.advantage = 0;
}
return;
}
currentState.points[idx]++;
const p1 = currentState.points[0];
const p2 = currentState.points[1];
if (p1 >= 3 && p2 >= 3 && p1 === p2) {
currentState.deuce = true;
currentState.advantage = 0;
return;
}
if ((p1 >= 4 || p2 >= 4) && Math.abs(p1 - p2) >= 2) {
currentState.points = [0, 0];
addGame(player);
return;
}
}
function addGame(player) {
const idx = player - 1;
currentState.games[idx]++;
const [g1, g2] = currentState.games;
const set = currentState.currentSet;
// 6-6 → si entra in tiebreak
if (g1 === 6 && g2 === 6) {
currentState.tiebreak = true;
currentState.tiebreakPoints = [0, 0];
currentState.points = [0, 0];
currentState.deuce = false;
currentState.advantage = 0;
// Il primo a servire nel tiebreak è il giocatore che NON ha servito l'ultimo game
currentState.tiebreakFirstServer = currentState.server === 1 ? 2 : 1;
currentState.server = currentState.tiebreakFirstServer;
return;
}
if ((g1 >= 6 || g2 >= 6) && Math.abs(g1 - g2) >= 2) {
currentState.sets[set][0] = g1;
currentState.sets[set][1] = g2;
currentState.games = [0, 0];
let p1Sets = 0, p2Sets = 0;
for (let i = 0; i < 3; i++) {
if (currentState.sets[i][0] > currentState.sets[i][1]) p1Sets++;
else if (currentState.sets[i][1] > currentState.sets[i][0]) p2Sets++;
}
if (p1Sets >= 2 || p2Sets >= 2) {
currentState.matchOver = true;
} else {
currentState.currentSet++;
}
} else {
currentState.sets[set][0] = g1;
currentState.sets[set][1] = g2;
}
currentState.server = currentState.server === 1 ? 2 : 1;
}
/**
* Determina il servitore nel tiebreak.
* Nel tiebreak:
* - Punto 1: servito dal giocatore designato (tiebreakFirstServer)
* - Punto 2: servito dall'altro giocatore
* - Dal punto 3 in poi: cambio servizio ogni 2 punti
*/
function updateTiebreakServer(state) {
const total = state.tiebreakPoints[0] + state.tiebreakPoints[1];
const first = state.tiebreakFirstServer;
if (total === 0) {
state.server = first;
} else if (total === 1) {
// Dopo il primo punto, serve l'altro giocatore
state.server = first === 1 ? 2 : 1;
} else {
// Gruppi da 2: alternati
const groupIndex = Math.floor((total - 1) / 2);
if (groupIndex % 2 === 0) {
// Gruppi pari (0, 2, 4...): serve l'altro giocatore
state.server = first === 1 ? 2 : 1;
} else {
// Gruppi dispari (1, 3, 5...): serve il primo giocatore
state.server = first;
}
}
}
// ---- Avvio ----
server.listen(PORT, () => {
console.log(`
╔═══════════════════════════════════════╗
║ 🎾 Tennis Roots Server ║
║ ────────────────────────── ║
║ HTTP : http://localhost:${PORT}
║ WS : ws://localhost:${PORT}/ws ║
║ ║
║ Controller : http://localhost:${PORT}/ ║
║ Overlay : http://localhost:${PORT}/overlay/ ║
╚═══════════════════════════════════════╝
`);
});
+849
View File
@@ -0,0 +1,849 @@
{
"name": "tennis-roots-server",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "tennis-roots-server",
"version": "0.1.0",
"dependencies": {
"express": "^4.21.0",
"ws": "^8.18.0"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
"license": "MIT",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"license": "MIT"
},
"node_modules/body-parser": {
"version": "1.20.5",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz",
"integrity": "sha512-3grm+/2tUOvu2cjJkvsIxrv/wVpfXQW4PsQHYm7yk4vfpu7Ekl6nEsYBoJUL6qDwZUx8wUhQ8tR2qz+ad9c9OA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "~1.2.0",
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"on-finished": "~2.4.1",
"qs": "~6.15.1",
"raw-body": "~2.5.3",
"type-is": "~1.6.18",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
"license": "MIT",
"dependencies": {
"safe-buffer": "5.2.1"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
"license": "MIT"
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "4.22.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.22.2.tgz",
"integrity": "sha512-IuL+Elrou2ZvCFHs18/CIzy2Nzvo25nZ1/D2eIZlz7c+QUayAcYoiM2BthCjs+EBHVpjYjcuLDAiCWgeIX3X1Q==",
"license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "~1.20.5",
"content-disposition": "~0.5.4",
"content-type": "~1.0.4",
"cookie": "~0.7.1",
"cookie-signature": "~1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "~1.3.1",
"fresh": "~0.5.2",
"http-errors": "~2.0.0",
"merge-descriptors": "1.0.3",
"methods": "~1.1.2",
"on-finished": "~2.4.1",
"parseurl": "~1.3.3",
"path-to-regexp": "~0.1.12",
"proxy-addr": "~2.0.7",
"qs": "~6.15.1",
"range-parser": "~1.2.1",
"safe-buffer": "5.2.1",
"send": "~0.19.0",
"serve-static": "~1.16.2",
"setprototypeof": "1.2.0",
"statuses": "~2.0.1",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"engines": {
"node": ">= 0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
"integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"on-finished": "~2.4.1",
"parseurl": "~1.3.3",
"statuses": "~2.0.2",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/merge-descriptors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"license": "MIT",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz",
"integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==",
"license": "MIT"
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/qs": {
"version": "6.15.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz",
"integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.1.0"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/raw-body": {
"version": "2.5.3",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
"integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
"integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "~0.5.2",
"http-errors": "~2.0.1",
"mime": "1.6.0",
"ms": "2.1.3",
"on-finished": "~2.4.1",
"range-parser": "~1.2.1",
"statuses": "~2.0.2"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/send/node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/serve-static": {
"version": "1.16.3",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
"integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
"license": "MIT",
"dependencies": {
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "~0.19.1"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4",
"side-channel-list": "^1.0.1",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"license": "MIT",
"dependencies": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/ws": {
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"name": "tennis-roots-server",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "node --watch index.js"
},
"dependencies": {
"express": "^4.21.0",
"ws": "^8.18.0"
}
}