Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
|
@@ -14,20 +14,21 @@ const io = new Server(server, {
|
|
| 14 |
// Serve static files
|
| 15 |
app.use(express.static(path.join(__dirname, 'public')));
|
| 16 |
|
| 17 |
-
// Handle
|
| 18 |
-
app.get('/', (req, res) => res.
|
| 19 |
app.get('/admin', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
|
| 20 |
app.get('/client', (req, res) => res.sendFile(path.join(__dirname, 'public', 'client.html')));
|
| 21 |
|
| 22 |
const HOST = '0.0.0.0';
|
| 23 |
const PORT = process.env.PORT || 7860;
|
| 24 |
|
| 25 |
-
//
|
| 26 |
io.on('connection', (socket) => {
|
| 27 |
const room = socket.handshake.query.room || 'default';
|
| 28 |
const role = socket.handshake.query.role || 'client';
|
| 29 |
socket.join(room);
|
| 30 |
|
|
|
|
| 31 |
socket.on('sync:ping', (msg = {}) => {
|
| 32 |
const t1 = Date.now();
|
| 33 |
socket.emit('sync:pong', { t0: msg.t0, t1, t2: Date.now() });
|
|
@@ -38,9 +39,14 @@ io.on('connection', (socket) => {
|
|
| 38 |
const startAt = Date.now() + Math.max(500, Number(delayMs));
|
| 39 |
io.to(room).emit('cmd', { type: 'start', startAt, label });
|
| 40 |
});
|
|
|
|
| 41 |
socket.on('admin:stop', () => { io.to(room).emit('cmd', { type: 'stop' }); });
|
| 42 |
socket.on('admin:reset', () => { io.to(room).emit('cmd', { type: 'reset' }); });
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
socket.on('disconnect', () => {});
|
| 46 |
});
|
|
|
|
| 14 |
// Serve static files
|
| 15 |
app.use(express.static(path.join(__dirname, 'public')));
|
| 16 |
|
| 17 |
+
// Handle the routes directly
|
| 18 |
+
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
|
| 19 |
app.get('/admin', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
|
| 20 |
app.get('/client', (req, res) => res.sendFile(path.join(__dirname, 'public', 'client.html')));
|
| 21 |
|
| 22 |
const HOST = '0.0.0.0';
|
| 23 |
const PORT = process.env.PORT || 7860;
|
| 24 |
|
| 25 |
+
// Socket.io handling
|
| 26 |
io.on('connection', (socket) => {
|
| 27 |
const room = socket.handshake.query.room || 'default';
|
| 28 |
const role = socket.handshake.query.role || 'client';
|
| 29 |
socket.join(room);
|
| 30 |
|
| 31 |
+
// Emit stats about room
|
| 32 |
socket.on('sync:ping', (msg = {}) => {
|
| 33 |
const t1 = Date.now();
|
| 34 |
socket.emit('sync:pong', { t0: msg.t0, t1, t2: Date.now() });
|
|
|
|
| 39 |
const startAt = Date.now() + Math.max(500, Number(delayMs));
|
| 40 |
io.to(room).emit('cmd', { type: 'start', startAt, label });
|
| 41 |
});
|
| 42 |
+
|
| 43 |
socket.on('admin:stop', () => { io.to(room).emit('cmd', { type: 'stop' }); });
|
| 44 |
socket.on('admin:reset', () => { io.to(room).emit('cmd', { type: 'reset' }); });
|
| 45 |
+
|
| 46 |
+
// Blackout toggle
|
| 47 |
+
socket.on('admin:blackout', ({ on = true }) => {
|
| 48 |
+
io.to(room).emit('cmd', { type: 'blackout', on });
|
| 49 |
+
});
|
| 50 |
|
| 51 |
socket.on('disconnect', () => {});
|
| 52 |
});
|