Browse Source

Enable auto gain control, echo cancellation and noise suppression

wip
Trevor Slocum 3 years ago
parent
commit
5739b433ec
  1. 69
      pkg/web/public/assets/js/harmony.js

69
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];
audioTrack = audioTracks[0];
pc.addTrack(audioTrack);
pc.getSenders()[0].replaceTrack(null);
pc.addTrack(audioTrack);
pc.getSenders()[0].replaceTrack(null);
pc.ontrack = function (event) {
console.log(`onTrack ${event.streams.length}`);
pc.ontrack = function (event) {
console.log(`onTrack ${event.streams.length}`);
pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'});
pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'});
var el = document.getElementById('audioplayer');
el.autoplay = true;
el.srcObject = event.streams[0];
var el = document.getElementById('audioplayer');
el.autoplay = true;
el.srcObject = event.streams[0];
voice = true;
voice = true;
if (!shownPTTHelp) {
shownPTTHelp = true;
if (!shownPTTHelp) {
shownPTTHelp = true;
Log("* Note: Push-to-talk is bound to <F8>");
}
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');
$('#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();
};
updateVoiceStatus();
};
pc.createOffer(RTCOfferOptions)
.then(onRTCDescription, onRTCDescriptionError);
}).catch(Log);
pc.createOffer(RTCOfferOptions)
.then(onRTCDescription, onRTCDescriptionError);
}).catch(Log);
});
$("#voiceptt").on("touchstart", function (e) {

Loading…
Cancel
Save