async open_backend_connection() {
        // Closes the socket if it already exists //
        if (this.socket)
            this.socket.close();

        return new Promise((resolve, reject) => {
            this.socket = new WebSocket("ws://localhost:" + this.port);

            this.socket.onmessage = function (message) {
                var backend_message = JSON.parse(message.data)
                var uuid = backend_message.header.UUID
                var success = true;
                // If there was an error, set it as an error
                if(!backend_message.header.status) 
                    success = false;
                
                // Trigger an event with the ID of the object 
                var event = new CustomEvent(uuid, {
                    detail: {
                        "success": success,
                        "data": backend_message
                    }
                });
                // Trigger an event for that ID //
                document.dispatchEvent(event);
            }

            this.socket.onopen = () => {
                resolve();
            }

            this.socket.onclose = (code) => {
                if(!code.wasClean)
                    console.log("Error! Connection with backend closed:", code.code)
                else
                    console.log("Backend Connection Closed.")
            }

            this.socket.onerror = (err) => {
                if(this.socket.readyState == 3)
                    console.log("There was an error connecting to the application or the server closed the connection unexpectedly.")
                else
                    console.log("Error from the back end connection:", err);
                reject();
            }
        })
    }
/**
     * Opens a connection to the backend, async success is an open connection
     * the reject is a failed connection with any error. This allows for 
     * proxying of game data to a back end that processes the data. 
     */
Opens a connection to the backend, async success is an open connection
the reject is a failed connection with any error. This allows for
proxying of game data to a back end that processes the data.
Opens a connection to the backend async success is an open connection the reject is a failed connection with any error . This allows for proxying of game data to a back end that processes the data .
async open_backend_connection() {
        if (this.socket)
            this.socket.close();
        return new Promise((resolve, reject) => {
            this.socket = new WebSocket("ws://localhost:" + this.port);
            this.socket.onmessage = function (message) {
                var backend_message = JSON.parse(message.data)
                var uuid = backend_message.header.UUID
                var success = true;
                if(!backend_message.header.status) 
                    success = false;
                var event = new CustomEvent(uuid, {
                    detail: {
                        "success": success,
                        "data": backend_message
                    }
                });
                document.dispatchEvent(event);
            }
            this.socket.onopen = () => {
                resolve();
            }
            this.socket.onclose = (code) => {
                if(!code.wasClean)
                    console.log("Error! Connection with backend closed:", code.code)
                else
                    console.log("Backend Connection Closed.")
            }
            this.socket.onerror = (err) => {
                if(this.socket.readyState == 3)
                    console.log("There was an error connecting to the application or the server closed the connection unexpectedly.")
                else
                    console.log("Error from the back end connection:", err);
                reject();
            }
        })
    }
async open_backend_connection ( ) { if ( this . socket ) this . socket . close ( ) ; return new Promise ( ( resolve , reject ) => { this . socket = new WebSocket ( "ws://localhost:" + this . port ) ; this . socket . onmessage = function ( message ) { var backend_message = JSON . parse ( message . data ) var uuid = backend_message . header . UUID var success = true ; if ( ! backend_message . header . status ) success = false ; var event = new CustomEvent ( uuid , { detail : { "success" : success , "data" : backend_message } } ) ; document . dispatchEvent ( event ) ; } this . socket . onopen = ( ) => { resolve ( ) ; } this . socket . onclose = ( code ) => { if ( ! code . wasClean ) console . log ( "Error! Connection with backend closed:" , code . code ) else console . log ( "Backend Connection Closed." ) } this . socket . onerror = ( err ) => { if ( this . socket . readyState == 3 ) console . log ( "There was an error connecting to the application or the server closed the connection unexpectedly." ) else console . log ( "Error from the back end connection:" , err ) ; reject ( ) ; } } ) }
Opens a connection to the backend, async success is an open connection
 the reject is a failed connection with any error.
Opens a connection to the backend async success is an open connection the reject is a failed connection with any error .
// Closes the socket if it already exists // // If there was an error, set it as an error // Trigger an event with the ID of the object  // Trigger an event for that ID //