Mike W commited on
Commit
c8c7d92
·
1 Parent(s): 9cbfee0

Fix: Initial runtime errors with integration

Browse files
Files changed (1) hide show
  1. index.html +9 -9
index.html CHANGED
@@ -22,7 +22,7 @@
22
  <script>
23
  const startButton = document.getElementById('startButton');
24
  const stopButton = document.getElementById('stopButton');
25
- const statusDiv = document.getElementById('status'); // Corrected from status to statusDiv
26
  let socket;
27
  let mediaRecorder;
28
  let audioContext;
@@ -32,11 +32,11 @@
32
  const connectWebSocket = () => {
33
  const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
34
  const wsUri = `${proto}//${window.location.host}/ws`;
35
- statusDiv.textContent = `Status: Connecting to ${wsUri}...`;
36
  socket = new WebSocket(wsUri);
37
 
38
  socket.onopen = () => {
39
- statusDiv.textContent = 'Status: Connected. Ready to start.';
40
  startButton.disabled = false;
41
  };
42
 
@@ -64,14 +64,14 @@
64
  };
65
 
66
  socket.onclose = () => {
67
- statusDiv.textContent = 'Status: Disconnected';
68
  startButton.disabled = false; // Allow user to try starting again
69
  stopButton.disabled = true;
70
  };
71
 
72
  socket.onerror = (error) => {
73
  console.error("WebSocket Error:", error);
74
- statusDiv.textContent = 'Status: Connection error';
75
  };
76
  };
77
 
@@ -91,7 +91,7 @@
91
  };
92
 
93
  startButton.onclick = async () => {
94
- // AudioContext must be resumed by a user gesture.
95
  if (!audioContext) {
96
  audioContext = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 });
97
  } else if (audioContext.state === 'suspended') {
@@ -110,11 +110,11 @@
110
 
111
  startButton.disabled = true;
112
  stopButton.disabled = false;
113
- statusDiv.textContent = 'Status: Translating...';
114
  })
115
  .catch(err => {
116
  console.error('Error getting user media:', err);
117
- statusDiv.textContent = 'Error: Could not access microphone.';
118
  });
119
  };
120
 
@@ -126,7 +126,7 @@
126
  // The user might want to start and stop multiple times in one session.
127
  startButton.disabled = false;
128
  stopButton.disabled = true;
129
- statusDiv.textContent = 'Status: Stopped. Press Start to translate again.';
130
  };
131
 
132
  window.onload = () => {
 
22
  <script>
23
  const startButton = document.getElementById('startButton');
24
  const stopButton = document.getElementById('stopButton');
25
+ const status = document.getElementById('status');
26
  let socket;
27
  let mediaRecorder;
28
  let audioContext;
 
32
  const connectWebSocket = () => {
33
  const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
34
  const wsUri = `${proto}//${window.location.host}/ws`;
35
+ status.textContent = `Status: Connecting to ${wsUri}...`;
36
  socket = new WebSocket(wsUri);
37
 
38
  socket.onopen = () => {
39
+ status.textContent = 'Status: Connected. Ready to start.';
40
  startButton.disabled = false;
41
  };
42
 
 
64
  };
65
 
66
  socket.onclose = () => {
67
+ status.textContent = 'Status: Disconnected. Please refresh the page.';
68
  startButton.disabled = false; // Allow user to try starting again
69
  stopButton.disabled = true;
70
  };
71
 
72
  socket.onerror = (error) => {
73
  console.error("WebSocket Error:", error);
74
+ status.textContent = 'Status: Connection error. Check console for details.';
75
  };
76
  };
77
 
 
91
  };
92
 
93
  startButton.onclick = async () => {
94
+ // AudioContext must be created or resumed by a user gesture.
95
  if (!audioContext) {
96
  audioContext = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 });
97
  } else if (audioContext.state === 'suspended') {
 
110
 
111
  startButton.disabled = true;
112
  stopButton.disabled = false;
113
+ status.textContent = 'Status: Translating...';
114
  })
115
  .catch(err => {
116
  console.error('Error getting user media:', err);
117
+ status.textContent = 'Error: Could not access microphone.';
118
  });
119
  };
120
 
 
126
  // The user might want to start and stop multiple times in one session.
127
  startButton.disabled = false;
128
  stopButton.disabled = true;
129
+ status.textContent = 'Status: Stopped. Press Start to translate again.';
130
  };
131
 
132
  window.onload = () => {