cduss commited on
Commit
9174608
·
1 Parent(s): 9847ddb

fix mute button

Browse files
Files changed (1) hide show
  1. index.html +21 -53
index.html CHANGED
@@ -509,18 +509,14 @@
509
  <button class="btn btn-primary" id="startBtn" onclick="startStream()" disabled>Start</button>
510
  <button class="btn btn-danger" id="stopBtn" onclick="stopStream()" disabled>Stop</button>
511
  <button class="btn btn-mute muted" id="muteBtn" onclick="toggleMute()" disabled>
512
- <svg id="micOffIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
513
- <line x1="1" y1="1" x2="23" y2="23"></line>
514
- <path d="M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6"></path>
515
- <path d="M17 16.95A7 7 0 0 1 5 12v-2m14 0v2a7 7 0 0 1-.11 1.23"></path>
516
- <line x1="12" y1="19" x2="12" y2="23"></line>
517
- <line x1="8" y1="23" x2="16" y2="23"></line>
518
  </svg>
519
- <svg id="micOnIcon" class="hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
520
- <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path>
521
- <path d="M19 10v2a7 7 0 0 1-14 0v-2"></path>
522
- <line x1="12" y1="19" x2="12" y2="23"></line>
523
- <line x1="8" y1="23" x2="16" y2="23"></line>
524
  </svg>
525
  <span id="muteText">Unmute</span>
526
  </button>
@@ -620,8 +616,7 @@
620
  // Latency monitor
621
  let latencyMonitorId = null;
622
 
623
- // Microphone state
624
- let localStream = null;
625
  let isMuted = true; // Default to muted
626
 
627
  // Export functions
@@ -813,31 +808,16 @@
813
  if (!selectedProducerId) return;
814
  updateStatus('connecting', 'Connecting...');
815
 
816
- // Get microphone access
817
- try {
818
- localStream = await navigator.mediaDevices.getUserMedia({ audio: true });
819
- // Start muted by default
820
- localStream.getAudioTracks().forEach(track => {
821
- track.enabled = false;
822
- });
823
- isMuted = true;
824
- updateMuteButton();
825
- } catch (e) {
826
- console.warn('Could not access microphone:', e);
827
- localStream = null;
828
- }
829
 
830
  peerConnection = new RTCPeerConnection({
831
  iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
832
  });
833
 
834
- // Add microphone track to peer connection
835
- if (localStream) {
836
- localStream.getAudioTracks().forEach(track => {
837
- peerConnection.addTrack(track, localStream);
838
- });
839
- }
840
-
841
  peerConnection.ontrack = (e) => {
842
  if (e.track.kind === 'video') {
843
  const video = document.getElementById('remoteVideo');
@@ -936,21 +916,12 @@
936
  if (peerConnection) peerConnection.close();
937
  if (dataChannel) dataChannel.close();
938
 
939
- // Stop microphone
940
- if (localStream) {
941
- localStream.getTracks().forEach(track => track.stop());
942
- localStream = null;
943
- }
944
- isMuted = true;
945
- updateMuteButton();
946
-
947
  peerConnection = null;
948
  dataChannel = null;
949
  currentSessionId = null;
950
  document.getElementById('remoteVideo').srcObject = null;
951
  document.getElementById('startBtn').disabled = !selectedProducerId;
952
  document.getElementById('stopBtn').disabled = true;
953
- document.getElementById('muteBtn').disabled = true;
954
  document.getElementById('robotSelector').classList.remove('hidden');
955
  enableControls(false);
956
  updateStatus('connected', 'Connected');
@@ -958,33 +929,30 @@
958
 
959
  function enableControls(enabled) {
960
  document.getElementById('btnPlaySound').disabled = !enabled;
961
- document.getElementById('muteBtn').disabled = !enabled || !localStream;
962
  }
963
 
964
  function toggleMute() {
965
- if (!localStream) return;
966
  isMuted = !isMuted;
967
- localStream.getAudioTracks().forEach(track => {
968
- track.enabled = !isMuted;
969
- });
970
  updateMuteButton();
971
  }
972
 
973
  function updateMuteButton() {
974
  const btn = document.getElementById('muteBtn');
975
- const micOffIcon = document.getElementById('micOffIcon');
976
- const micOnIcon = document.getElementById('micOnIcon');
977
  const muteText = document.getElementById('muteText');
978
 
979
  if (isMuted) {
980
  btn.classList.add('muted');
981
- micOffIcon.classList.remove('hidden');
982
- micOnIcon.classList.add('hidden');
983
  muteText.textContent = 'Unmute';
984
  } else {
985
  btn.classList.remove('muted');
986
- micOffIcon.classList.add('hidden');
987
- micOnIcon.classList.remove('hidden');
988
  muteText.textContent = 'Mute';
989
  }
990
  }
 
509
  <button class="btn btn-primary" id="startBtn" onclick="startStream()" disabled>Start</button>
510
  <button class="btn btn-danger" id="stopBtn" onclick="stopStream()" disabled>Stop</button>
511
  <button class="btn btn-mute muted" id="muteBtn" onclick="toggleMute()" disabled>
512
+ <svg id="speakerOffIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
513
+ <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon>
514
+ <line x1="23" y1="9" x2="17" y2="15"></line>
515
+ <line x1="17" y1="9" x2="23" y2="15"></line>
 
 
516
  </svg>
517
+ <svg id="speakerOnIcon" class="hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
518
+ <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon>
519
+ <path d="M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path>
 
 
520
  </svg>
521
  <span id="muteText">Unmute</span>
522
  </button>
 
616
  // Latency monitor
617
  let latencyMonitorId = null;
618
 
619
+ // Audio mute state (for robot's audio playback)
 
620
  let isMuted = true; // Default to muted
621
 
622
  // Export functions
 
808
  if (!selectedProducerId) return;
809
  updateStatus('connecting', 'Connecting...');
810
 
811
+ // Ensure video is muted by default
812
+ const video = document.getElementById('remoteVideo');
813
+ video.muted = true;
814
+ isMuted = true;
815
+ updateMuteButton();
 
 
 
 
 
 
 
 
816
 
817
  peerConnection = new RTCPeerConnection({
818
  iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
819
  });
820
 
 
 
 
 
 
 
 
821
  peerConnection.ontrack = (e) => {
822
  if (e.track.kind === 'video') {
823
  const video = document.getElementById('remoteVideo');
 
916
  if (peerConnection) peerConnection.close();
917
  if (dataChannel) dataChannel.close();
918
 
 
 
 
 
 
 
 
 
919
  peerConnection = null;
920
  dataChannel = null;
921
  currentSessionId = null;
922
  document.getElementById('remoteVideo').srcObject = null;
923
  document.getElementById('startBtn').disabled = !selectedProducerId;
924
  document.getElementById('stopBtn').disabled = true;
 
925
  document.getElementById('robotSelector').classList.remove('hidden');
926
  enableControls(false);
927
  updateStatus('connected', 'Connected');
 
929
 
930
  function enableControls(enabled) {
931
  document.getElementById('btnPlaySound').disabled = !enabled;
932
+ document.getElementById('muteBtn').disabled = !enabled;
933
  }
934
 
935
  function toggleMute() {
 
936
  isMuted = !isMuted;
937
+ document.getElementById('remoteVideo').muted = isMuted;
 
 
938
  updateMuteButton();
939
  }
940
 
941
  function updateMuteButton() {
942
  const btn = document.getElementById('muteBtn');
943
+ const speakerOffIcon = document.getElementById('speakerOffIcon');
944
+ const speakerOnIcon = document.getElementById('speakerOnIcon');
945
  const muteText = document.getElementById('muteText');
946
 
947
  if (isMuted) {
948
  btn.classList.add('muted');
949
+ speakerOffIcon.classList.remove('hidden');
950
+ speakerOnIcon.classList.add('hidden');
951
  muteText.textContent = 'Unmute';
952
  } else {
953
  btn.classList.remove('muted');
954
+ speakerOffIcon.classList.add('hidden');
955
+ speakerOnIcon.classList.remove('hidden');
956
  muteText.textContent = 'Mute';
957
  }
958
  }