add mute button

This commit is contained in:
liamcottle
2024-05-20 16:53:38 +12:00
parent c3d972afdf
commit c38384c45f

View File

@@ -9,6 +9,10 @@
<button onclick="stopListening()">Stop Listening</button>
</div>
<div>
<input id="checkbox-mute-mic" type="checkbox"/> Mute Mic
</div>
<div>
<select id="codec-mode">
<option value="3200">3200</option>
@@ -35,6 +39,7 @@
// find elements
const codecModeElement = document.getElementById("codec-mode");
const encodedBytesSentElement = document.getElementById("encoded-bytes-sent");
const checkboxMuteMicElement = document.getElementById("checkbox-mute-mic");
var encodedBytesSent = 0;
@@ -83,11 +88,19 @@
encodedBytesSent += encoded.length;
encodedBytesSentElement.innerText = formatBytes(encodedBytesSent);
// send encoded audio to websocket
if(callWebsocket.readyState === WebSocket.OPEN){
callWebsocket.send(encoded);
// do nothing if websocket closed
if(callWebsocket.readyState !== WebSocket.OPEN){
return;
}
// do nothing when audio muted
if(checkboxMuteMicElement.checked){
return;
}
// send encoded audio to websocket
callWebsocket.send(encoded);
};
// request access to the microphone