managerbhingong commited on
Commit
2ecabe3
·
verified ·
1 Parent(s): 749d9e0

kenapa timernya tidak jalan ya?

Browse files
Files changed (1) hide show
  1. index.html +26 -15
index.html CHANGED
@@ -140,44 +140,51 @@
140
  const connectionStatus = document.getElementById('connectionStatus');
141
  const connectionText = document.getElementById('connectionText');
142
  const alertSound = document.getElementById('alertSound');
143
-
144
  // Timer state
145
  let countdown;
146
  let totalSeconds = 0;
147
  let isRunning = false;
148
-
149
- // Socket event listeners
 
 
 
 
 
 
 
150
  socket.on('connect', () => {
151
  connectionStatus.className = 'w-3 h-3 bg-green-500 rounded-full pulse-animation';
152
  connectionText.textContent = 'Connected';
 
 
153
  });
154
-
155
- socket.on('disconnect', () => {
156
  connectionStatus.className = 'w-3 h-3 bg-red-500 rounded-full';
157
  connectionText.textContent = 'Disconnected';
158
  });
159
-
160
  socket.on('timerUpdate', (data) => {
161
- updateTimerDisplay(data.remainingSeconds);
 
162
  isRunning = data.isRunning;
163
  updateStatus();
164
  });
165
-
166
  socket.on('timerComplete', () => {
167
  playAlertSound();
168
  isRunning = false;
 
 
169
  statusElement.textContent = 'Timer completed!';
170
  statusElement.className = 'text-sm text-red-600 font-semibold';
171
  });
172
-
173
- socket.on('timerReset', (data) => {
174
- updateTimerDisplay(data.duration * 60);
175
  isRunning = false;
176
  statusElement.textContent = 'Timer reset';
177
  statusElement.className = 'text-sm text-gray-600';
178
  });
179
-
180
- // Event Listeners
181
  resetBtn.addEventListener('click', () => {
182
  socket.emit('resetTimer');
183
  });
@@ -230,10 +237,14 @@
230
  statusElement.className = 'text-sm text-gray-600';
231
  }
232
  }
233
-
234
  // Initialize
235
  feather.replace();
236
  updateTimerDisplay(0);
237
- </script>
 
 
 
 
 
238
  </body>
239
  </html>
 
140
  const connectionStatus = document.getElementById('connectionStatus');
141
  const connectionText = document.getElementById('connectionText');
142
  const alertSound = document.getElementById('alertSound');
 
143
  // Timer state
144
  let countdown;
145
  let totalSeconds = 0;
146
  let isRunning = false;
147
+
148
+ // Add new event listener for timer state
149
+ socket.on('timerState', (data) => {
150
+ totalSeconds = data.remainingSeconds;
151
+ isRunning = data.isRunning;
152
+ updateTimerDisplay(totalSeconds);
153
+ updateStatus();
154
+ });
155
+ // Socket event listeners
156
  socket.on('connect', () => {
157
  connectionStatus.className = 'w-3 h-3 bg-green-500 rounded-full pulse-animation';
158
  connectionText.textContent = 'Connected';
159
+ // Request current timer state when connecting
160
+ socket.emit('getTimerState');
161
  });
162
+ socket.on('disconnect', () => {
 
163
  connectionStatus.className = 'w-3 h-3 bg-red-500 rounded-full';
164
  connectionText.textContent = 'Disconnected';
165
  });
 
166
  socket.on('timerUpdate', (data) => {
167
+ totalSeconds = data.remainingSeconds;
168
+ updateTimerDisplay(totalSeconds);
169
  isRunning = data.isRunning;
170
  updateStatus();
171
  });
 
172
  socket.on('timerComplete', () => {
173
  playAlertSound();
174
  isRunning = false;
175
+ totalSeconds = 0;
176
+ updateTimerDisplay(totalSeconds);
177
  statusElement.textContent = 'Timer completed!';
178
  statusElement.className = 'text-sm text-red-600 font-semibold';
179
  });
180
+ socket.on('timerReset', (data) => {
181
+ totalSeconds = data.duration * 60;
182
+ updateTimerDisplay(totalSeconds);
183
  isRunning = false;
184
  statusElement.textContent = 'Timer reset';
185
  statusElement.className = 'text-sm text-gray-600';
186
  });
187
+ // Event Listeners
 
188
  resetBtn.addEventListener('click', () => {
189
  socket.emit('resetTimer');
190
  });
 
237
  statusElement.className = 'text-sm text-gray-600';
238
  }
239
  }
 
240
  // Initialize
241
  feather.replace();
242
  updateTimerDisplay(0);
243
+
244
+ // Check if socket is connected and request state
245
+ if (socket.connected) {
246
+ socket.emit('getTimerState');
247
+ }
248
+ </script>
249
  </body>
250
  </html>