TeaWeb/shared/js/ui/modal/ModalChangeLatency.ts

116 lines
4.1 KiB
TypeScript
Raw Normal View History

import {createModal, Modal} from "../../ui/elements/Modal";
import {ClientEntry} from "../../tree/Client";
import {Slider, sliderfy} from "../../ui/elements/Slider";
import * as htmltags from "../../ui/htmltags";
import {VoicePlayerLatencySettings} from "../../voice/VoicePlayer";
2020-03-30 13:44:18 +02:00
2020-09-07 12:42:00 +02:00
let modalInstance: Modal;
export function spawnChangeLatency(client: ClientEntry, current: VoicePlayerLatencySettings, reset: () => VoicePlayerLatencySettings, apply: (settings: VoicePlayerLatencySettings) => void, callback_flush?: () => any) {
if(modalInstance) {
modalInstance.close();
}
2020-03-30 13:44:18 +02:00
const begin = Object.assign({}, current);
current = Object.assign({}, current);
2020-09-07 12:42:00 +02:00
modalInstance = createModal({
2020-03-30 13:44:18 +02:00
header: tr("Change playback latency"),
body: function () {
let tag = $("#tmpl_change_latency").renderTag({
client: htmltags.generate_client_object({
add_braces: false,
client_name: client.clientNickName(),
client_unique_id: client.properties.client_unique_identifier,
client_id: client.clientId()
}),
have_flush: (typeof(callback_flush) === "function")
});
const update_value = () => {
2020-09-07 12:42:00 +02:00
const valid = current.minBufferTime < current.maxBufferTime;
2020-03-30 13:44:18 +02:00
2020-09-07 12:42:00 +02:00
modalInstance.htmlTag.find(".modal-body").toggleClass("modal-red", !valid);
modalInstance.htmlTag.find(".modal-body").toggleClass("modal-green", valid);
2020-03-30 13:44:18 +02:00
if(!valid)
return;
apply(current);
};
let slider_min: Slider, slider_max: Slider;
{
const container = tag.find(".container-min");
const tag_value = container.find(".value");
const slider_tag = container.find(".container-slider");
slider_min = sliderfy(slider_tag, {
2020-09-07 12:42:00 +02:00
initial_value: current.minBufferTime,
2020-03-30 13:44:18 +02:00
step: 20,
max_value: 1000,
min_value: 0,
unit: 'ms'
});
2020-03-30 13:44:18 +02:00
slider_tag.on('change', event => {
2020-09-07 12:42:00 +02:00
current.minBufferTime = parseInt(slider_tag.attr("value"));
tag_value.text(current.minBufferTime + "ms");
2020-03-30 13:44:18 +02:00
update_value();
});
2020-09-07 12:42:00 +02:00
tag_value.text(current.minBufferTime + "ms");
2020-03-30 13:44:18 +02:00
}
2020-03-30 13:44:18 +02:00
{
const container = tag.find(".container-max");
const tag_value = container.find(".value");
2020-03-30 13:44:18 +02:00
const slider_tag = container.find(".container-slider");
slider_max = sliderfy(slider_tag, {
2020-09-07 12:42:00 +02:00
initial_value: current.maxBufferTime,
2020-03-30 13:44:18 +02:00
step: 20,
max_value: 1020,
min_value: 20,
2020-03-30 13:44:18 +02:00
unit: 'ms'
});
2020-03-30 13:44:18 +02:00
slider_tag.on('change', event => {
2020-09-07 12:42:00 +02:00
current.maxBufferTime = parseInt(slider_tag.attr("value"));
tag_value.text(current.maxBufferTime + "ms");
2020-03-30 13:44:18 +02:00
update_value();
});
2020-09-07 12:42:00 +02:00
tag_value.text(current.maxBufferTime + "ms");
2020-03-30 13:44:18 +02:00
}
setTimeout(update_value, 0);
2020-03-30 13:44:18 +02:00
tag.find(".button-close").on('click', event => {
2020-09-07 12:42:00 +02:00
modalInstance.close();
2020-03-30 13:44:18 +02:00
});
tag.find(".button-cancel").on('click', event => {
apply(begin);
2020-09-07 12:42:00 +02:00
modalInstance.close();
2020-03-30 13:44:18 +02:00
});
tag.find(".button-reset").on('click', event => {
current = Object.assign({}, reset());
2020-09-07 12:42:00 +02:00
slider_max.value(current.maxBufferTime);
slider_min.value(current.minBufferTime);
2020-03-30 13:44:18 +02:00
});
2020-03-30 13:44:18 +02:00
tag.find(".button-flush").on('click', event => callback_flush());
2020-03-30 13:44:18 +02:00
return tag.children();
},
footer: null,
2020-03-30 13:44:18 +02:00
width: 600
});
2020-09-07 12:42:00 +02:00
modalInstance.close_listener.push(() => modalInstance = undefined);
modalInstance.open();
modalInstance.htmlTag.find(".modal-body").addClass("modal-latency");
}