krishgokul92 commited on
Commit
e907a38
·
verified ·
1 Parent(s): a4ce88a

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +9 -6
public/index.html CHANGED
@@ -135,7 +135,7 @@
135
  // --- URL params ---
136
  const qs = new URLSearchParams(location.search);
137
  const role = (qs.get('role') || 'client').toLowerCase(); // 'admin' | 'client'
138
- const room = qs.get('room') || 'default';
139
 
140
  // --- Elements ---
141
  const adminView = document.getElementById('adminView');
@@ -157,6 +157,9 @@
157
  // --- Socket.IO connection (rooms + role passed as query) ---
158
  const socket = io({ query: { role, room } });
159
 
 
 
 
160
  // --- Wake lock (client) ---
161
  let wakeLock;
162
  async function keepAwake() {
@@ -170,7 +173,7 @@
170
  });
171
  }
172
 
173
- // --- Admin: stats + server clock via NTP-style sync ---
174
  const roomNameEl = document.getElementById('roomName');
175
  const statsEl = document.getElementById('stats');
176
  const serverNowEl = document.getElementById('serverNow');
@@ -236,7 +239,6 @@
236
  // --- Client timer state machine ---
237
  const State = { IDLE:'IDLE', RUNNING:'RUNNING', STOPPED:'STOPPED' };
238
  let state = State.IDLE;
239
- let label = '';
240
  let zeroPerfTs = null; // when timer hits 00:00 (in performance.now() space)
241
  let rafId = 0;
242
 
@@ -281,7 +283,7 @@
281
  renderElapsed(0);
282
  }
283
 
284
- // --- Command handling (both roles listen so admin preview works too) ---
285
  socket.on('cmd', (msg) => {
286
  if (!msg || !msg.type) return;
287
  switch (msg.type) {
@@ -289,7 +291,8 @@
289
  case 'stop': stopPause(); break;
290
  case 'reset': resetAll(); break;
291
  case 'blackout':
292
- if (role === 'client'){
 
293
  blackoutEl.style.display = msg.on ? 'block' : 'none';
294
  document.documentElement.style.cursor = msg.on ? 'none' : 'auto';
295
  }
@@ -297,7 +300,7 @@
297
  }
298
  });
299
 
300
- // Initial UI
301
  if (role === 'client') {
302
  document.getElementById('roomBadge').textContent = `room: ${room}`;
303
  setState(State.IDLE);
 
135
  // --- URL params ---
136
  const qs = new URLSearchParams(location.search);
137
  const role = (qs.get('role') || 'client').toLowerCase(); // 'admin' | 'client'
138
+ const room = (qs.get('room') || 'default').toLowerCase();
139
 
140
  // --- Elements ---
141
  const adminView = document.getElementById('adminView');
 
157
  // --- Socket.IO connection (rooms + role passed as query) ---
158
  const socket = io({ query: { role, room } });
159
 
160
+ // Ask server to refresh stats on admin load
161
+ if (role === 'admin') socket.emit('stats:refresh');
162
+
163
  // --- Wake lock (client) ---
164
  let wakeLock;
165
  async function keepAwake() {
 
173
  });
174
  }
175
 
176
+ // --- Admin: server clock via NTP-style sync ---
177
  const roomNameEl = document.getElementById('roomName');
178
  const statsEl = document.getElementById('stats');
179
  const serverNowEl = document.getElementById('serverNow');
 
239
  // --- Client timer state machine ---
240
  const State = { IDLE:'IDLE', RUNNING:'RUNNING', STOPPED:'STOPPED' };
241
  let state = State.IDLE;
 
242
  let zeroPerfTs = null; // when timer hits 00:00 (in performance.now() space)
243
  let rafId = 0;
244
 
 
283
  renderElapsed(0);
284
  }
285
 
286
+ // --- Command handling ---
287
  socket.on('cmd', (msg) => {
288
  if (!msg || !msg.type) return;
289
  switch (msg.type) {
 
291
  case 'stop': stopPause(); break;
292
  case 'reset': resetAll(); break;
293
  case 'blackout':
294
+ // Only clients should go black
295
+ if (role === 'client') {
296
  blackoutEl.style.display = msg.on ? 'block' : 'none';
297
  document.documentElement.style.cursor = msg.on ? 'none' : 'auto';
298
  }
 
300
  }
301
  });
302
 
303
+ // Initial UI (client)
304
  if (role === 'client') {
305
  document.getElementById('roomBadge').textContent = `room: ${room}`;
306
  setState(State.IDLE);