diff --git a/pkg/web/public/assets/js/harmony.js b/pkg/web/public/assets/js/harmony.js index c57af5a..7ae72d7 100644 --- a/pkg/web/public/assets/js/harmony.js +++ b/pkg/web/public/assets/js/harmony.js @@ -9,6 +9,14 @@ var ptt = false; var printStats = false; var pc; +var RTCConstraints = { + audio: { + autoGainControl: true, + echoCancellation: true, + noiseSuppression: true, + }, + video: false +}; var RTCOfferOptions = { offerToReceiveAudio: 1, offerToReceiveVideo: 0, @@ -75,48 +83,47 @@ $(document).ready(function () { } }; - navigator.mediaDevices.getUserMedia({audio: true, video: false}) - .then(localStream => { - audioTracks = localStream.getAudioTracks(); - if (audioTracks.length > 0) { - console.log(`Using Audio device: ${audioTracks[0].label} - tracks available: ${audioTracks}`); + navigator.mediaDevices.getUserMedia(RTCConstraints).then(localStream => { + audioTracks = localStream.getAudioTracks(); + if (audioTracks.length > 0) { + console.log(`Using Audio device: ${audioTracks[0].label} - tracks available: ${audioTracks}`); + } + + audioTrack = audioTracks[0]; + + pc.addTrack(audioTrack); + pc.getSenders()[0].replaceTrack(null); + + pc.ontrack = function (event) { + console.log(`onTrack ${event.streams.length}`); + + pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'}); + + var el = document.getElementById('audioplayer'); + el.autoplay = true; + el.srcObject = event.streams[0]; + + voice = true; + + if (!shownPTTHelp) { + shownPTTHelp = true; + + Log("* Note: Push-to-talk is bound to <F8>"); } - audioTrack = audioTracks[0]; + $('#voicepttcontainer').css('display', 'table-row'); + $('#voiceinactiveleft').css('display', 'none'); + $('#voiceactiveleft').css('display', 'inline-block'); + $('#voiceinactiveright').css('display', 'none'); + $('#voiceactiveright').css('display', 'inline-block'); + $('#voiceButton').html('Quit voice chat'); - pc.addTrack(audioTrack); - pc.getSenders()[0].replaceTrack(null); + updateVoiceStatus(); + }; - pc.ontrack = function (event) { - console.log(`onTrack ${event.streams.length}`); - - pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'}); - - var el = document.getElementById('audioplayer'); - el.autoplay = true; - el.srcObject = event.streams[0]; - - voice = true; - - if (!shownPTTHelp) { - shownPTTHelp = true; - - Log("* Note: Push-to-talk is bound to <F8>"); - } - - $('#voicepttcontainer').css('display', 'table-row'); - $('#voiceinactiveleft').css('display', 'none'); - $('#voiceactiveleft').css('display', 'inline-block'); - $('#voiceinactiveright').css('display', 'none'); - $('#voiceactiveright').css('display', 'inline-block'); - $('#voiceButton').html('Quit voice chat'); - - updateVoiceStatus(); - }; - - pc.createOffer(RTCOfferOptions) - .then(onRTCDescription, onRTCDescriptionError); - }).catch(Log); + pc.createOffer(RTCOfferOptions) + .then(onRTCDescription, onRTCDescriptionError); + }).catch(Log); }); $("#voiceptt").on("touchstart", function (e) {