Sofia Casadei commited on
Commit
953b94e
·
1 Parent(s): c1d862e

fix: stop button

Browse files
Files changed (1) hide show
  1. index.html +9 -4
index.html CHANGED
@@ -205,6 +205,7 @@
205
  let audioContext, analyser, audioSource;
206
  let audioLevel = 0;
207
  let animationFrame;
 
208
 
209
  const startButton = document.getElementById('start-button');
210
  const transcriptDiv = document.getElementById('transcript');
@@ -358,7 +359,7 @@
358
  await peerConnection.setRemoteDescription(serverResponse);
359
 
360
  // Create event stream to receive transcripts
361
- const eventSource = new EventSource('/transcript?webrtc_id=' + webrtc_id);
362
  eventSource.addEventListener("output", (event) => {
363
  appendTranscript(event.data);
364
  });
@@ -403,9 +404,13 @@
403
  });
404
  }
405
 
406
- setTimeout(() => {
407
- peerConnection.close();
408
- }, 500);
 
 
 
 
409
  }
410
  audioLevel = 0;
411
  updateButtonState();
 
205
  let audioContext, analyser, audioSource;
206
  let audioLevel = 0;
207
  let animationFrame;
208
+ let eventSource;
209
 
210
  const startButton = document.getElementById('start-button');
211
  const transcriptDiv = document.getElementById('transcript');
 
359
  await peerConnection.setRemoteDescription(serverResponse);
360
 
361
  // Create event stream to receive transcripts
362
+ eventSource = new EventSource('/transcript?webrtc_id=' + webrtc_id);
363
  eventSource.addEventListener("output", (event) => {
364
  appendTranscript(event.data);
365
  });
 
404
  });
405
  }
406
 
407
+ peerConnection.close();
408
+ peerConnection = null;
409
+ }
410
+ // Close EventSource connection
411
+ if (eventSource) {
412
+ eventSource.close();
413
+ eventSource = null;
414
  }
415
  audioLevel = 0;
416
  updateButtonState();