summaryrefslogtreecommitdiff
path: root/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js
diff options
context:
space:
mode:
authorTrueKuehli <rctcoaster2000@hotmail.de>2018-11-27 12:16:33 +0100
committerTrueKuehli <rctcoaster2000@hotmail.de>2018-11-27 12:16:33 +0100
commit9f0b255f32dfa81bffe75f89335a78a659b4ce6a (patch)
treec4345ef6f98fee35f326bc06c29cada542a78e43 /WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js
parenta653a4efc60ef0bbc18e65cb11a4bd8c06c7ad5c (diff)
Reworked the code, but currently unable to test, so bugs are bound to be in there
Will test it sometime later. There also might still be stuff, that has yet to be reworked.
Diffstat (limited to 'WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js')
-rw-r--r--WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js b/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js
new file mode 100644
index 0000000..2c2bc11
--- /dev/null
+++ b/WebInterface/NodeJSServer/src/js/modules/networking/commands/login/listServers.js
@@ -0,0 +1,43 @@
+import Command from '../_command';
+
+/**
+ * Handles serverList commands
+ */
+export default class ListServers extends Command {
+ /**
+ * Registers interface for communication with other objects
+ * @param {Interface} iface
+ */
+ constructor(iface) {
+ super(iface);
+ this.registerPublic('listServers', 'listServers');
+ this.refreshing = false;
+ }
+
+ /**
+ * Requests server list from the server
+ */
+ listServers() {
+ if (this.refreshing) return; // If already refreshing, no new request
+
+ let listFn = (groups) => {
+ // Populate server listing
+ this.iface.callMethod('serverListing', 'flushElements');
+ this.iface.callMethod('serverListing', 'addElements', groups, this.iface);
+ // Unbind network function
+ this.iface.callMethod('networker', 'removeHandler', 'ListGroups');
+ this.refreshing = false;
+ };
+ let errorHandler = (err) => {
+ this.refreshing = false;
+ console.error(err.toString());
+ };
+
+ this.iface.callMethod('networker', 'registerHandler',
+ 'ListGroups', listFn);
+ this.iface.callMethod('networker', 'sendRequest',
+ 'GetGroups', errorHandler);
+
+ this.refreshing = true;
+ }
+}