"use strict"; // Global objects for debugging purposes let client; let ui; /** * Class for handling the UI. */ class UI { constructor() { this.client = null; // Initialize the UI this.initUI(); // TODO start client only after the user entered their nickname this.initClient(); } /** * Initialize the web UI. */ initUI() { // TODO stub } /** * Create instance of Client and initialize connection. */ initClient() { const wsUri = AppSettings.serverWsUri; this.client = new Client(wsUri); // Subscribe to Client events this.client.on("initialized", this._onClientInit.bind(this)); this.client.on("disconnected", this._onClientDisconnect.bind(this)); this.client.on("connectionError", this._onClientError.bind(this)); this.client.on("receivedMessage", this._onClientReceivedMessage.bind(this)); } _onClientInit() { console.log("UI: Connection initialized!"); // Send a test message this.client.sendChatMessage("Meow meow! :3"); } _onClientDisconnect() { console.log("UI: Connection closed!"); } _onClientError() { console.log("UI: Connection error! :("); } _onClientReceivedMessage(msg) { console.log("UI: Message from '" + msg.from + "', text: '" + msg.text + "'"); } } // Execute this on start (wrapped in an anonymous function) (function() { // TODO ui = new UI(); client = ui.client; })();