H-Liu1997 commited on
Commit
4da9546
·
1 Parent(s): 5f2882e

feat: spectators see 'Take Over' button to seamlessly take control

Browse files
Files changed (1) hide show
  1. static/js/main.js +14 -7
static/js/main.js CHANGED
@@ -188,6 +188,7 @@ class MotionApp {
188
  // Track state
189
  this.isPaused = false;
190
  this.isIdle = true;
 
191
  this.isProcessing = false; // Prevent concurrent API calls
192
  this.pendingStartRequest = null; // Store pending start request data
193
 
@@ -226,10 +227,10 @@ class MotionApp {
226
 
227
  async toggleStartReset() {
228
  if (this.isProcessing) return; // Prevent concurrent operations
229
-
230
- if (this.isIdle) {
231
- // Currently idle, so start
232
- await this.startGeneration();
233
  } else {
234
  // Currently running/paused, so reset
235
  await this.reset();
@@ -565,6 +566,7 @@ class MotionApp {
565
  this.isRunning = false;
566
  this.isPaused = false;
567
  this.isIdle = true;
 
568
  this.frameCount = 0;
569
  this.motionFpsCounter = 0;
570
  this.isFetchingFrame = false;
@@ -733,17 +735,22 @@ class MotionApp {
733
  }
734
 
735
  // Auto-start spectator mode if someone else is generating
736
- if (data.is_generating && !data.is_active_session && this.isIdle && !this.isRunning) {
 
737
  this.isRunning = true;
738
- this.isIdle = false;
739
  this.statusEl.textContent = 'Watching';
 
 
 
740
  this.startFrameLoop();
741
  }
742
  // Stop spectator mode when generation stops
743
- if (!data.is_generating && !data.is_active_session && this.isRunning && this.statusEl.textContent === 'Watching') {
 
744
  this.isRunning = false;
745
  this.isIdle = true;
746
  this.statusEl.textContent = 'Idle';
 
747
  this.localFrameQueue = [];
748
  this.broadcastLastId = 0;
749
  }
 
188
  // Track state
189
  this.isPaused = false;
190
  this.isIdle = true;
191
+ this.isWatching = false; // Spectator mode
192
  this.isProcessing = false; // Prevent concurrent API calls
193
  this.pendingStartRequest = null; // Store pending start request data
194
 
 
227
 
228
  async toggleStartReset() {
229
  if (this.isProcessing) return; // Prevent concurrent operations
230
+
231
+ if (this.isIdle || this.isWatching) {
232
+ // Idle or spectator watching, so start (will force takeover if needed)
233
+ await this.startGeneration(this.isWatching);
234
  } else {
235
  // Currently running/paused, so reset
236
  await this.reset();
 
566
  this.isRunning = false;
567
  this.isPaused = false;
568
  this.isIdle = true;
569
+ this.isWatching = false;
570
  this.frameCount = 0;
571
  this.motionFpsCounter = 0;
572
  this.isFetchingFrame = false;
 
735
  }
736
 
737
  // Auto-start spectator mode if someone else is generating
738
+ if (data.is_generating && !data.is_active_session && this.isIdle && !this.isWatching) {
739
+ this.isWatching = true;
740
  this.isRunning = true;
 
741
  this.statusEl.textContent = 'Watching';
742
+ this.startResetBtn.textContent = 'Take Over';
743
+ this.startResetBtn.classList.remove('btn-danger');
744
+ this.startResetBtn.classList.add('btn-primary');
745
  this.startFrameLoop();
746
  }
747
  // Stop spectator mode when generation stops
748
+ if (!data.is_generating && !data.is_active_session && this.isWatching) {
749
+ this.isWatching = false;
750
  this.isRunning = false;
751
  this.isIdle = true;
752
  this.statusEl.textContent = 'Idle';
753
+ this.startResetBtn.textContent = 'Start';
754
  this.localFrameQueue = [];
755
  this.broadcastLastId = 0;
756
  }