krishgokul92 commited on
Commit
53b045a
·
verified ·
1 Parent(s): 651e4af

Upload index.html

Browse files
Files changed (1) hide show
  1. public/index.html +112 -0
public/index.html ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Timer Interface</title>
7
+ <style>
8
+ /* Shared Styles for Admin and Client */
9
+ body { font-family: Arial, sans-serif; background: #121820; color: #e6edf3; }
10
+ .wrapper { margin: 0 auto; padding: 20px; max-width: 1200px; }
11
+ .btn { border: none; border-radius: 8px; padding: 10px 15px; font-size: 16px; cursor: pointer; }
12
+ .btn:hover { background: #333; }
13
+ .start-btn { background-color: #2261ff; }
14
+ .stop-btn { background-color: #f43f5e; }
15
+ .reset-btn { background-color: #0ea5e9; }
16
+ .blackout-btn { background-color: #000; color: #fff; }
17
+ .btn-group { display: flex; gap: 10px; margin-bottom: 20px; }
18
+ .time-display { font-size: 100px; margin-bottom: 20px; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+
23
+ <div class="wrapper" id="app">
24
+ <!-- The Timer will dynamically show the Admin or Client UI -->
25
+ <div id="admin" style="display: none;">
26
+ <h2>Admin Controls</h2>
27
+ <div class="btn-group">
28
+ <button class="btn start-btn" id="start">Start</button>
29
+ <button class="btn stop-btn" id="stop">Stop</button>
30
+ <button class="btn reset-btn" id="reset">Reset</button>
31
+ </div>
32
+ <div class="btn-group">
33
+ <button class="btn blackout-btn" id="blackoutOn">Blackout ON</button>
34
+ <button class="btn blackout-btn" id="blackoutOff">Blackout OFF</button>
35
+ </div>
36
+ </div>
37
+
38
+ <div id="client" style="display: none;">
39
+ <h2>Client Timer</h2>
40
+ <div class="time-display" id="time">00:00</div>
41
+ </div>
42
+ </div>
43
+
44
+ <script src="/socket.io/socket.io.js"></script>
45
+ <script>
46
+ const params = new URLSearchParams(window.location.search);
47
+ const role = params.get('role') || 'client'; // Default to 'client'
48
+ const socket = io({ query: { role, room: 'default' } });
49
+
50
+ // Show either admin or client interface
51
+ if (role === 'admin') {
52
+ document.getElementById('admin').style.display = 'block';
53
+ document.getElementById('client').style.display = 'none';
54
+ } else {
55
+ document.getElementById('admin').style.display = 'none';
56
+ document.getElementById('client').style.display = 'block';
57
+ }
58
+
59
+ // Admin controls
60
+ document.getElementById('start').onclick = () => socket.emit('admin:start', { delayMs: 3000, label: 'Start Timer' });
61
+ document.getElementById('stop').onclick = () => socket.emit('admin:stop');
62
+ document.getElementById('reset').onclick = () => socket.emit('admin:reset');
63
+ document.getElementById('blackoutOn').onclick = () => socket.emit('admin:blackout', { on: true });
64
+ document.getElementById('blackoutOff').onclick = () => socket.emit('admin:blackout', { on: false });
65
+
66
+ // Client timer
67
+ let startTime = 0;
68
+ let isRunning = false;
69
+ let interval;
70
+ socket.on('cmd', (cmd) => {
71
+ if (cmd.type === 'start') {
72
+ startTime = Date.now() + (cmd.startAt - Date.now());
73
+ isRunning = true;
74
+ startTimer();
75
+ }
76
+ if (cmd.type === 'stop') {
77
+ clearInterval(interval);
78
+ isRunning = false;
79
+ }
80
+ if (cmd.type === 'reset') {
81
+ startTime = 0;
82
+ isRunning = false;
83
+ clearInterval(interval);
84
+ updateTime();
85
+ }
86
+ if (cmd.type === 'blackout') {
87
+ if (cmd.on) {
88
+ document.body.style.background = 'black';
89
+ } else {
90
+ document.body.style.background = '#121820';
91
+ }
92
+ }
93
+ });
94
+
95
+ function startTimer() {
96
+ interval = setInterval(() => {
97
+ if (isRunning) {
98
+ const elapsed = Date.now() - startTime;
99
+ const seconds = Math.floor(elapsed / 1000);
100
+ const milliseconds = Math.floor((elapsed % 1000) / 10);
101
+ document.getElementById('time').textContent = `${String(seconds).padStart(2, '0')}:${String(milliseconds).padStart(2, '0')}`;
102
+ }
103
+ }, 50); // Update every 50ms
104
+ }
105
+
106
+ function updateTime() {
107
+ document.getElementById('time').textContent = '00:00';
108
+ }
109
+ </script>
110
+
111
+ </body>
112
+ </html>