diff --git a/src/api/GlobalApi.js b/src/api/GlobalApi.js index cc297f8..51a3c8c 100644 --- a/src/api/GlobalApi.js +++ b/src/api/GlobalApi.js @@ -19,6 +19,7 @@ export default class GlobalApi { "e":[], "n":[] }, + "servers_map":{}, 'uniq': {"uniq":{"total":0,"month":0,"year":0,"day":0}}, 'builddate':0, 'ban_count':0, @@ -41,7 +42,15 @@ export default class GlobalApi { load_stages = new Stages(); + servers_ws = null; + servers_ws_first_payload = true; + constructor() { + this.servers_ws = new WebSocket("wss://tf2.pblr-nyk.pro/ws/servers") + this.servers_ws.onopen = () => {console.log("[WS] Websocket servers connected")}; + this.servers_ws.onmessage = (e) => { + this.update_server(JSON.parse(e.data)["servers"], false); + }; document.title = "Факты 13"; } @@ -55,20 +64,16 @@ export default class GlobalApi { } getHumanServerName(server) { - for (const mode in this.stats['servers']) { - for (const srv in this.stats['servers'][mode]) { - if (this.stats['servers'][mode][srv]['key'] === server) return this.stats['servers'][mode][srv]['name']; - } + for (const srv in this.stats.servers_map) { + if (srv['key'] === server) return srv['name']; } return "неизвестный"; } getServers4Selector() { let r = []; - for (const mode in this.stats['servers']) { - for (const srv in this.stats['servers'][mode]) { - r.push({"srv": this.stats['servers'][mode][srv]['key'], "name": this.stats['servers'][mode][srv]['name']}) - } + for (const srv in this.stats.servers_map) { + r.push({"srv": srv['key'], "name": srv['name']}) } return r; } @@ -106,6 +111,17 @@ export default class GlobalApi { }) } + update_server(response, first) { + if (first === true) { + for (let srv in response) + response[srv]['key'] = srv; + this.stats["servers_map"] = response; + } else { + for (let srv in response) { + this.stats["servers_map"][srv] = response[srv]; + } + } + } async fillServers() { this.load_stages.add("servers") @@ -113,19 +129,7 @@ export default class GlobalApi { return axios.get("/api/stats?filter=servers" + Random.getRndWebAppend()) .then(response => response.data['servers']) .then(response => { - let srvs = { - 'w':[], - "e":[], - 'n':[] - }; - for (let srv in response) { - response[srv]['key'] = srv; - if (response[srv]['status'] == false) srvs.n.push(response[srv]); - else if (response[srv]['player_count'] > 0) srvs.w.push(response[srv]); - else srvs.e.push(response[srv]); - } - srvs['w'] = srvs['w'].sort((s1,s2) => s2.player_count - s1.player_count); - this.stats['servers'] = srvs; + this.update_server(response, true); }) .catch(err => { console.log(`[API] cannot request servers, err: ${err}`); diff --git a/src/components/ActionDialogs/ServerStatsDialog.vue b/src/components/ActionDialogs/ServerStatsDialog.vue index 4f51ad6..2373a88 100644 --- a/src/components/ActionDialogs/ServerStatsDialog.vue +++ b/src/components/ActionDialogs/ServerStatsDialog.vue @@ -20,7 +20,7 @@
Использование памяти: {{docker.mem.percent}}% ({{bytesToHigh(docker.mem.usage)}} / {{bytesToHigh(docker.mem.limit)}})
Всего трафика (rx/tx): {{bytesToHigh(docker.net.input)}} / {{bytesToHigh(docker.net.output)}}
Записи на диск (rx/tx): {{bytesToHigh(docker.io.input)}} / {{bytesToHigh(docker.io.output)}}
-Обновленно: {{(new Date(docker.utime * 1000)).toLocaleString()}}
+