2018-03-07 19:06:52 +01:00
|
|
|
/// <reference path="../../utils/modal.ts" />
|
|
|
|
/// <reference path="../../utils/tab.ts" />
|
|
|
|
/// <reference path="../../proto.ts" />
|
2018-05-05 14:58:30 +02:00
|
|
|
/// <reference path="../../voice/AudioController.ts" />
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
namespace Modals {
|
|
|
|
export function spawnSettingsModal() {
|
2018-03-08 15:40:31 +01:00
|
|
|
let modal;
|
|
|
|
modal = createModal({
|
2018-03-07 19:06:52 +01:00
|
|
|
header: "Settings",
|
|
|
|
body: () => {
|
|
|
|
let template = $("#tmpl_settings").tmpl();
|
|
|
|
template = $.spawn("div").append(template);
|
2018-03-08 15:40:31 +01:00
|
|
|
initialiseSettingListeners(modal,template = template.tabify());
|
2018-03-07 19:06:52 +01:00
|
|
|
return template;
|
|
|
|
},
|
|
|
|
footer: () => {
|
|
|
|
let footer = $.spawn("div");
|
|
|
|
footer.addClass("modal-button-group");
|
|
|
|
footer.css("margin-top", "5px");
|
|
|
|
footer.css("margin-bottom", "5px");
|
|
|
|
footer.css("text-align", "right");
|
|
|
|
|
|
|
|
let buttonOk = $.spawn("button");
|
|
|
|
buttonOk.text("Ok");
|
|
|
|
buttonOk.click(() => modal.close());
|
|
|
|
footer.append(buttonOk);
|
|
|
|
|
|
|
|
return footer;
|
|
|
|
},
|
|
|
|
width: 750
|
|
|
|
});
|
|
|
|
modal.open();
|
|
|
|
}
|
|
|
|
|
2018-03-08 15:40:31 +01:00
|
|
|
function initialiseSettingListeners(modal: Modal, tag: JQuery) {
|
2018-03-07 19:06:52 +01:00
|
|
|
//Voice
|
2018-03-08 15:40:31 +01:00
|
|
|
initialiseVoiceListeners(modal, tag.find(".settings_voice"));
|
2018-03-07 19:06:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-08 15:40:31 +01:00
|
|
|
function initialiseVoiceListeners(modal: Modal, tag: JQuery) {
|
2018-04-16 20:38:35 +02:00
|
|
|
let currentVAD = settings.global("vad_type");
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
tag.find("input[type=radio][name=\"vad_type\"]").change(function (this: HTMLButtonElement) {
|
|
|
|
tag.find(".vad_settings .vad_type").text($(this).attr("display"));
|
|
|
|
tag.find(".vad_settings .vad_type_settings").hide();
|
|
|
|
tag.find(".vad_settings .vad_type_" + this.value).show();
|
2018-04-16 20:38:35 +02:00
|
|
|
settings.changeGlobal("vad_type", this.value);
|
2018-04-11 17:56:09 +02:00
|
|
|
globalClient.voiceConnection.voiceRecorder.reinitialiseVAD();
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
switch (this.value) {
|
|
|
|
case "ppt":
|
2018-04-19 18:42:34 +02:00
|
|
|
let keyCode: number = parseInt(settings.global("vad_ppt_key", JQuery.Key.T.toString()));
|
2018-03-07 19:06:52 +01:00
|
|
|
tag.find(".vat_ppt_key").text(String.fromCharCode(keyCode));
|
2018-03-08 15:40:31 +01:00
|
|
|
break;
|
|
|
|
case "vad":
|
|
|
|
let slider = tag.find(".vad_vad_slider");
|
|
|
|
let vad: VoiceActivityDetectorVAD = globalClient.voiceConnection.voiceRecorder.getVADHandler() as VoiceActivityDetectorVAD;
|
|
|
|
slider.val(vad.percentageThreshold);
|
|
|
|
slider.trigger("change");
|
2018-03-17 08:05:37 +01:00
|
|
|
globalClient.voiceConnection.voiceRecorder.update(true);
|
2018-03-08 15:40:31 +01:00
|
|
|
vad.percentage_listener = per => {
|
|
|
|
tag.find(".vad_vad_bar_filler")
|
|
|
|
.css("width", per + "%");
|
|
|
|
};
|
|
|
|
break;
|
2018-03-07 19:06:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(!currentVAD)
|
|
|
|
currentVAD = "ppt";
|
|
|
|
let elm = tag.find("input[type=radio][name=\"vad_type\"][value=\"" + currentVAD + "\"]");
|
|
|
|
elm.attr("checked", "true");
|
|
|
|
|
|
|
|
|
|
|
|
tag.find(".vat_ppt_key").click(function () {
|
|
|
|
let modal = createModal({
|
|
|
|
body: "",
|
|
|
|
header: () => {
|
|
|
|
let head = $.spawn("div");
|
|
|
|
head.text("Type the key you wish");
|
|
|
|
head.css("background-color", "blue");
|
|
|
|
return head;
|
|
|
|
},
|
|
|
|
footer: ""
|
|
|
|
});
|
|
|
|
$(document).one("keypress", function (e) {
|
|
|
|
console.log("Got key " + e.keyCode);
|
|
|
|
modal.close();
|
2018-04-16 20:38:35 +02:00
|
|
|
settings.changeGlobal("vad_ppt_key", e.keyCode.toString());
|
2018-04-11 17:56:09 +02:00
|
|
|
globalClient.voiceConnection.voiceRecorder.reinitialiseVAD();
|
2018-03-07 19:06:52 +01:00
|
|
|
tag.find(".vat_ppt_key").text(String.fromCharCode(e.keyCode));
|
|
|
|
});
|
|
|
|
modal.open();
|
|
|
|
});
|
2018-03-08 15:40:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
//VAD VAD
|
|
|
|
let slider = tag.find(".vad_vad_slider");
|
|
|
|
slider.on("input change", () => {
|
2018-04-16 20:38:35 +02:00
|
|
|
settings.changeGlobal("vad_threshold", slider.val().toString());
|
2018-03-08 15:40:31 +01:00
|
|
|
let vad = globalClient.voiceConnection.voiceRecorder.getVADHandler();
|
|
|
|
if(vad instanceof VoiceActivityDetectorVAD)
|
|
|
|
vad.percentageThreshold = slider.val() as number;
|
|
|
|
tag.find(".vad_vad_slider_value").text(slider.val().toString());
|
|
|
|
});
|
|
|
|
modal.properties.registerCloseListener(() => {
|
|
|
|
let vad = globalClient.voiceConnection.voiceRecorder.getVADHandler();
|
|
|
|
if(vad instanceof VoiceActivityDetectorVAD)
|
|
|
|
vad.percentage_listener = undefined;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//Trigger radio button select for VAD setting setup
|
|
|
|
elm.trigger("change");
|
2018-03-17 08:05:37 +01:00
|
|
|
|
|
|
|
//Initialise microphones
|
2018-05-05 14:58:30 +02:00
|
|
|
let select_microphone = tag.find(".voice_microphone_select");
|
|
|
|
let select_error = tag.find(".voice_microphone_select_error");
|
|
|
|
|
2018-03-17 08:05:37 +01:00
|
|
|
navigator.mediaDevices.enumerateDevices().then(devices => {
|
|
|
|
let currentStream = globalClient.voiceConnection.voiceRecorder.getMediaStream();
|
|
|
|
let currentDeviceId;
|
|
|
|
if(currentStream) {
|
|
|
|
let audio = currentStream.getAudioTracks()[0];
|
|
|
|
currentDeviceId = audio.getSettings().deviceId;
|
|
|
|
}
|
|
|
|
console.log("Got " + devices.length + " devices:");
|
|
|
|
for(let device of devices) {
|
|
|
|
console.log(device);
|
|
|
|
if(device.kind == "audioinput") {
|
|
|
|
let dtag = $.spawn("option");
|
|
|
|
dtag.attr("device-id", device.deviceId);
|
|
|
|
dtag.attr("device-group", device.groupId);
|
|
|
|
dtag.text(device.label);
|
2018-05-05 14:58:30 +02:00
|
|
|
select_microphone.append(dtag);
|
2018-03-17 08:05:37 +01:00
|
|
|
|
2018-05-05 14:58:30 +02:00
|
|
|
dtag.prop("selected", currentDeviceId && device.deviceId == currentDeviceId);
|
2018-03-17 08:05:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
console.error("Could not enumerate over devices!");
|
|
|
|
console.error(error);
|
2018-05-05 14:58:30 +02:00
|
|
|
select_error.text("Could not get device list!").show();
|
2018-03-17 08:05:37 +01:00
|
|
|
});
|
|
|
|
|
2018-05-05 14:58:30 +02:00
|
|
|
select_microphone.change(event => {
|
|
|
|
let deviceSelected = select_microphone.find("option:selected");
|
2018-03-17 08:05:37 +01:00
|
|
|
let deviceId = deviceSelected.attr("device-id");
|
2018-05-05 14:58:30 +02:00
|
|
|
console.log("Selected microphone device: " + deviceId);
|
2018-03-17 08:05:37 +01:00
|
|
|
globalClient.voiceConnection.voiceRecorder.changeDevice(deviceId);
|
|
|
|
});
|
2018-05-05 14:58:30 +02:00
|
|
|
//Initialise speakers
|
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
}
|
|
|
|
}
|