From 3a3d0fc3d4733f8908e23a03f860d76340479ec4 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Tue, 11 Jun 2019 23:53:30 +0200 Subject: Reorganize Project structure --- .../src/js/src_old/modules/server-client.js | 93 ---------------------- 1 file changed, 93 deletions(-) delete mode 100644 WebInterface/NodeJSServer/src/js/src_old/modules/server-client.js (limited to 'WebInterface/NodeJSServer/src/js/src_old/modules/server-client.js') diff --git a/WebInterface/NodeJSServer/src/js/src_old/modules/server-client.js b/WebInterface/NodeJSServer/src/js/src_old/modules/server-client.js deleted file mode 100644 index 2f712b5..0000000 --- a/WebInterface/NodeJSServer/src/js/src_old/modules/server-client.js +++ /dev/null @@ -1,93 +0,0 @@ -import * as signalR from '@aspnet/signalr'; -import ServerListing from './ui/server-listing.js'; - -/** - * Class for communication to server - */ -export default class ServerClient { - /** - * Creates new connection - * @param {string} url URL of server running signalR - * @param {string} serverListingId HTML ID of server-listing element, - * to populate with available games - * @param {BannerController} notifications Notification Manager - * @param {array} ui UI Elements to reload on login - * @param {boolean} [debug=false] Enable debug output? - */ - constructor(url, serverListingId, notifications, ui, debug = false) { - this.ui = ui; - const connectionBuilder = new signalR.HubConnectionBuilder() - .withUrl(url); - - if (debug) { - connectionBuilder.configureLogging(signalR.LogLevel.Debug); - } else { - connectionBuilder.configureLogging(signalR.LogLevel.Error); - } - - this.connection = connectionBuilder.build(); - this.connection.start() - .then(() => this.loadServers()) // Load games list, once connected - .catch((err) => console.error(err.toString())); - - // Initialize refreshing (blocks new refreshes if true) - this.refreshing = false; - - this.serverListing = new ServerListing(serverListingId, notifications); - } - - /** - * Requests list of avalable games on the server - */ - loadServers() { - if (this.refreshing) return; // If already refreshing, no new request - - this.connection.on('ListGroups', (groups) => { - // Populate server listing - this.serverListing.flushElements(); - this.serverListing.addElements(groups, this, this.ui); - this.connection.off('ListGroups'); - - this.refreshing = false; - }); - - this.connection.invoke('GetGroups') - .catch((err) => { - this.refreshing = false; - console.error(err.toString()); - }); - this.refreshing = true; - } - - /** - * Sends a game creating request to the server - * @param {string} name Name of the new game - * @param {string} password Password - */ - createServer(name, password) { - // TODO: Create - } - - /** - * Sends a login request - * @param {string} group Group name to join - * @param {string} password Password to send as SHA-256 Base64 String - * @param {string} username Display name to use - * @param {ServerClient~loginCallback} callback Callback function to use - */ - sendLogin(group, password, username, callback) { - this.connection.on('LoginResponse', (result) => { - callback(result, this.connection); - this.connection.off('LoginResponse'); - }); - this.connection.invoke('Login', group, username, password); - } -} - -/** - * Callback to call with response to login request - * @callback ServerClient~loginCallback - * @param {number} result 0: Success, 1: PasswordError, 2:UsernameTaken, - * 3:Unknown Error - * @param {ConnectionHub} connection Connection to the server - */ -- cgit v1.2.3-70-g09d2