Improved server info behaviour
Signed-off-by: WolverinDEV <git@teaspeak.de>
This commit is contained in:
parent
b0adcb3c5d
commit
f7b0e4814d
3 changed files with 93 additions and 50 deletions
|
@ -2,8 +2,8 @@ namespace net.graph {
|
|||
export type Entry = {
|
||||
timestamp: number;
|
||||
|
||||
upload: number;
|
||||
download: number;
|
||||
upload?: number;
|
||||
download?: number;
|
||||
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
@ -163,8 +163,11 @@ namespace net.graph {
|
|||
}
|
||||
|
||||
for(const entry of this._entries) {
|
||||
this._entry_max.upload = Math.max(this._entry_max.upload, entry.upload);
|
||||
this._entry_max.download = Math.max(this._entry_max.download, entry.download);
|
||||
if(typeof(entry.upload) === "number")
|
||||
this._entry_max.upload = Math.max(this._entry_max.upload, entry.upload);
|
||||
|
||||
if(typeof(entry.download) === "number")
|
||||
this._entry_max.download = Math.max(this._entry_max.download, entry.download);
|
||||
}
|
||||
|
||||
this._entry_max.upload *= this._max_space;
|
||||
|
@ -177,8 +180,11 @@ namespace net.graph {
|
|||
|
||||
this._entries.push(entry);
|
||||
|
||||
this._entry_max.upload = Math.max(this._entry_max.upload, entry.upload * this._max_space);
|
||||
this._entry_max.download = Math.max(this._entry_max.download, entry.download * this._max_space);
|
||||
if(typeof(entry.upload) === "number")
|
||||
this._entry_max.upload = Math.max(this._entry_max.upload, entry.upload * this._max_space);
|
||||
|
||||
if(typeof(entry.download) === "number")
|
||||
this._entry_max.download = Math.max(this._entry_max.download, entry.download * this._max_space);
|
||||
}
|
||||
|
||||
insert_entries(entries: Entry[]) {
|
||||
|
@ -310,7 +316,10 @@ namespace net.graph {
|
|||
const floor = a => a; //Math.floor;
|
||||
for(const entry of this._entries) {
|
||||
x = floor((entry.timestamp - tb) * dtw);
|
||||
y = floor(hy - direction * Math.max(hy * (entry[type] / max), this.style[type].strike_width));
|
||||
if(typeof entry[type] === "number")
|
||||
y = floor(hy - direction * Math.max(hy * (entry[type] / max), this.style[type].strike_width));
|
||||
else
|
||||
y = hy - direction * this.style[type].strike_width;
|
||||
|
||||
if(entry.timestamp < tb) {
|
||||
lx = x;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
namespace Modals {
|
||||
type InfoUpdateCallback = (info: ServerConnectionInfo | boolean) => any;
|
||||
export function openServerInfo(server: ServerEntry) {
|
||||
let modal: Modal;
|
||||
let update_callbacks: InfoUpdateCallback[] = [];
|
||||
let update_callbacks: ServerBandwidthInfoUpdateCallback[] = [];
|
||||
|
||||
modal = createModal({
|
||||
header: tr("Server Information: ") + server.properties.virtualserver_name,
|
||||
|
@ -43,20 +42,24 @@ namespace Modals {
|
|||
});
|
||||
|
||||
const updater = setInterval(() => {
|
||||
server.request_connection_info().then(info => update_callbacks.forEach(e => e(info))).catch(error => update_callbacks.forEach(e => e(false)));
|
||||
server.request_connection_info().then(info => update_callbacks.forEach(e => e(RequestInfoStatus.SUCCESS, info))).catch(error => {
|
||||
if(error instanceof CommandResult && error.id == ErrorID.PERMISSION_ERROR) {
|
||||
update_callbacks.forEach(e => e(RequestInfoStatus.NO_PERMISSION));
|
||||
return;
|
||||
}
|
||||
update_callbacks.forEach(e => e(RequestInfoStatus.UNKNOWN));
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
|
||||
modal.htmlTag.find(".button-close").on('click', event => modal.close());
|
||||
modal.htmlTag.find(".button-show-bandwidth").on('click', event => {
|
||||
const intervals = [];
|
||||
const updater = (info) => {
|
||||
intervals.forEach(e => e(info));
|
||||
};
|
||||
const custom_callbacks = [];
|
||||
const custom_callback_caller = (status, info) => { custom_callbacks.forEach(e => e(status, info)); };
|
||||
|
||||
update_callbacks.push(updater);
|
||||
Modals.openServerInfoBandwidth(server, intervals).close_listener.push(() => {
|
||||
update_callbacks.remove(updater);
|
||||
update_callbacks.push(custom_callback_caller);
|
||||
Modals.openServerInfoBandwidth(server, custom_callbacks).close_listener.push(() => {
|
||||
update_callbacks.remove(custom_callback_caller);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -80,7 +83,7 @@ namespace Modals {
|
|||
});
|
||||
}
|
||||
|
||||
function apply_category_1(server: ServerEntry, tag: JQuery, update_callbacks: InfoUpdateCallback[]) {
|
||||
function apply_category_1(server: ServerEntry, tag: JQuery, update_callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
/* server name */
|
||||
{
|
||||
const container = tag.find(".server-name");
|
||||
|
@ -131,7 +134,7 @@ namespace Modals {
|
|||
}
|
||||
}
|
||||
|
||||
function apply_category_2(server: ServerEntry, tag: JQuery, update_callbacks: InfoUpdateCallback[]) {
|
||||
function apply_category_2(server: ServerEntry, tag: JQuery, update_callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
/* ip */
|
||||
{
|
||||
const container = tag.find(".server-ip");
|
||||
|
@ -164,28 +167,32 @@ namespace Modals {
|
|||
{
|
||||
const container = tag.find(".server-ping");
|
||||
container.text(tr("calculating..."));
|
||||
update_callbacks.push(data => {
|
||||
if(typeof(data) === "boolean")
|
||||
update_callbacks.push((status, data) => {
|
||||
if(status === RequestInfoStatus.SUCCESS)
|
||||
container.text(data.connection_ping.toFixed(0) + " " + "ms");
|
||||
else if(status === RequestInfoStatus.NO_PERMISSION)
|
||||
container.text(tr("No Permissions"));
|
||||
else
|
||||
container.text(data.connection_ping.toFixed(0) + " " + "ms");
|
||||
container.text(tr("receiving..."));
|
||||
});
|
||||
}
|
||||
|
||||
/* packet loss */
|
||||
{
|
||||
const container = tag.find(".server-packet-loss");
|
||||
container.text(tr("calculating..."));
|
||||
update_callbacks.push(data => {
|
||||
if(typeof(data) === "boolean")
|
||||
container.text(tr("receiving..."));
|
||||
update_callbacks.push((status, data) => {
|
||||
if(status === RequestInfoStatus.SUCCESS)
|
||||
container.text(data.connection_packetloss_total.toFixed(2) + "%");
|
||||
else if(status === RequestInfoStatus.NO_PERMISSION)
|
||||
container.text(tr("No Permissions"));
|
||||
else
|
||||
container.text(data.connection_packetloss_total.toFixed(2) + "%");
|
||||
container.text(tr("receiving..."));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function apply_category_3(server: ServerEntry, tag: JQuery, update_callbacks: InfoUpdateCallback[]) {
|
||||
function apply_category_3(server: ServerEntry, tag: JQuery, update_callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
/* unique id */
|
||||
{
|
||||
const container = tag.find(".server-unique-id");
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
namespace Modals {
|
||||
export type InfoUpdateCallback = (info: ServerConnectionInfo | boolean) => any;
|
||||
export function openServerInfoBandwidth(server: ServerEntry, update_callbacks?: InfoUpdateCallback[]) : Modal {
|
||||
export enum RequestInfoStatus {
|
||||
SUCCESS,
|
||||
UNKNOWN,
|
||||
NO_PERMISSION
|
||||
}
|
||||
export type ServerBandwidthInfoUpdateCallback = (status: RequestInfoStatus, info?: ServerConnectionInfo) => any;
|
||||
export function openServerInfoBandwidth(server: ServerEntry, update_callbacks?: ServerBandwidthInfoUpdateCallback[]) : Modal {
|
||||
let modal: Modal;
|
||||
let own_callbacks = !update_callbacks;
|
||||
update_callbacks = update_callbacks || [];
|
||||
|
@ -24,7 +29,13 @@ namespace Modals {
|
|||
|
||||
if(own_callbacks) {
|
||||
const updater = setInterval(() => {
|
||||
server.request_connection_info().then(info => update_callbacks.forEach(e => e(info))).catch(error => update_callbacks.forEach(e => e(false)));
|
||||
server.request_connection_info().then(info => update_callbacks.forEach(e => e(RequestInfoStatus.SUCCESS, info))).catch(error => {
|
||||
if(error instanceof CommandResult && error.id == ErrorID.PERMISSION_ERROR) {
|
||||
update_callbacks.forEach(e => e(RequestInfoStatus.NO_PERMISSION));
|
||||
return;
|
||||
}
|
||||
update_callbacks.forEach(e => e(RequestInfoStatus.UNKNOWN));
|
||||
});
|
||||
}, 1000);
|
||||
modal.close_listener.push(() => clearInterval(updater));
|
||||
}
|
||||
|
@ -36,38 +47,41 @@ namespace Modals {
|
|||
return modal;
|
||||
}
|
||||
|
||||
function initialize_graph(modal: Modal, tag: JQuery, callbacks: InfoUpdateCallback[], fields: {uplaod: string, download: string}) {
|
||||
function initialize_graph(modal: Modal, tag: JQuery, callbacks: ServerBandwidthInfoUpdateCallback[], fields: {uplaod: string, download: string}) {
|
||||
const canvas = tag.find("canvas")[0] as HTMLCanvasElement;
|
||||
const label_upload = tag.find(".upload");
|
||||
const label_download = tag.find(".download");
|
||||
let last_info: ServerConnectionInfo | false = false;
|
||||
let last_info: { status: RequestInfoStatus, info: ServerConnectionInfo };
|
||||
let custom_info = false;
|
||||
|
||||
const show_info = (upload: number | undefined, download: number | undefined) => {
|
||||
let fallback_text = last_info && last_info.status === RequestInfoStatus.NO_PERMISSION ? tr("No permission") : tr("receiving...");
|
||||
|
||||
if(typeof upload !== "number")
|
||||
upload = last_info ? last_info[fields.uplaod] : undefined;
|
||||
|
||||
if(typeof download !== "number")
|
||||
download = last_info ? last_info[fields.download] : undefined;
|
||||
|
||||
if(typeof upload !== "number")
|
||||
label_upload.text(tr("receiving..."));
|
||||
label_upload.text(fallback_text);
|
||||
else
|
||||
label_upload.text(MessageHelper.network.format_bytes(upload, {unit: "Bytes", time: "s", exact: false}));
|
||||
|
||||
if(typeof download !== "number")
|
||||
label_download.text(tr("receiving..."));
|
||||
label_download.text(fallback_text);
|
||||
else
|
||||
label_download.text(MessageHelper.network.format_bytes(download, {unit: "Bytes", time: "s", exact: false}));
|
||||
};
|
||||
show_info(undefined, undefined);
|
||||
|
||||
const graph = new net.graph.Graph(canvas);
|
||||
graph.insert_entry({ timestamp: Date.now(), upload: 0, download: 0});
|
||||
callbacks.push((values: ServerConnectionInfo | false) => {
|
||||
last_info = values;
|
||||
graph.insert_entry({ timestamp: Date.now(), upload: undefined, download: undefined});
|
||||
callbacks.push((status, values) => {
|
||||
last_info = {status: status, info: values};
|
||||
|
||||
if(!values) {
|
||||
graph.insert_entry({ timestamp: Date.now(), upload: 0, download: 0});
|
||||
graph.insert_entry({ timestamp: Date.now(), upload: undefined, download: undefined});
|
||||
} else {
|
||||
graph.insert_entry({
|
||||
timestamp: Date.now(),
|
||||
|
@ -110,21 +124,21 @@ namespace Modals {
|
|||
tag.addClass("window-resize-listener").on('resize', event => graph.resize());
|
||||
}
|
||||
|
||||
function initialize_current_bandwidth(modal: Modal, tag: JQuery, callbacks: InfoUpdateCallback[]) {
|
||||
function initialize_current_bandwidth(modal: Modal, tag: JQuery, callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
initialize_graph(modal, tag, callbacks, {
|
||||
uplaod: "connection_bandwidth_sent_last_second_total",
|
||||
download: "connection_bandwidth_received_last_second_total"
|
||||
});
|
||||
}
|
||||
|
||||
function initialize_ft_bandwidth(modal: Modal, tag: JQuery, callbacks: InfoUpdateCallback[]) {
|
||||
function initialize_ft_bandwidth(modal: Modal, tag: JQuery, callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
initialize_graph(modal, tag, callbacks, {
|
||||
uplaod: "connection_filetransfer_bandwidth_sent",
|
||||
download: "connection_filetransfer_bandwidth_received"
|
||||
});
|
||||
}
|
||||
|
||||
function initialize_general(tag: JQuery, callbacks: InfoUpdateCallback[]) {
|
||||
function initialize_general(tag: JQuery, callbacks: ServerBandwidthInfoUpdateCallback[]) {
|
||||
const tag_packets_upload = tag.find(".statistic-packets .upload");
|
||||
const tag_packets_download = tag.find(".statistic-packets .download");
|
||||
|
||||
|
@ -134,24 +148,37 @@ namespace Modals {
|
|||
const tag_ft_bytes_upload = tag.find(".statistic-ft-bytes .upload");
|
||||
const tag_ft_bytes_download = tag.find(".statistic-ft-bytes .download");
|
||||
|
||||
const update = (tag, value) => {
|
||||
const update = (tag, value: undefined | null | number) => {
|
||||
if(typeof value === "undefined")
|
||||
tag.text(tr("receiving..."));
|
||||
else if(value === null)
|
||||
tag.text(tr("no permissions"));
|
||||
else
|
||||
tag.text(MessageHelper.network.format_bytes(value, {unit: "Bytes", exact: false}));
|
||||
};
|
||||
|
||||
callbacks.push((info: ServerConnectionInfo) => {
|
||||
info = info ? info : {} as ServerConnectionInfo;
|
||||
const props = [
|
||||
{tag: tag_packets_download, property: "connection_packets_received_total"},
|
||||
{tag: tag_packets_upload, property: "connection_packets_sent_total"},
|
||||
|
||||
update(tag_packets_download, info.connection_packets_received_total);
|
||||
update(tag_packets_upload, info.connection_packets_sent_total);
|
||||
{tag: tag_bytes_download, property: "connection_bytes_received_total"},
|
||||
{tag: tag_bytes_upload, property: "connection_bytes_sent_total"},
|
||||
|
||||
update(tag_bytes_download, info.connection_bytes_received_total);
|
||||
update(tag_bytes_upload, info.connection_bytes_sent_total);
|
||||
{tag: tag_ft_bytes_upload, property: "connection_filetransfer_bytes_received_total"},
|
||||
{tag: tag_ft_bytes_download, property: "connection_filetransfer_bytes_sent_total"},
|
||||
];
|
||||
|
||||
update(tag_ft_bytes_upload, info.connection_filetransfer_bytes_received_total);
|
||||
update(tag_ft_bytes_download, info.connection_filetransfer_bytes_sent_total);
|
||||
callbacks.push((status, info) => {
|
||||
if(status === RequestInfoStatus.SUCCESS) {
|
||||
for(const entry of props)
|
||||
update(entry.tag, info[entry.property]);
|
||||
} else if(status === RequestInfoStatus.NO_PERMISSION) {
|
||||
for(const entry of props)
|
||||
update(entry.tag, null);
|
||||
} else {
|
||||
for(const entry of props)
|
||||
update(entry.tag, undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue