public/script/control_connection.js
// when the connection has been established, or NULL will be returned when that fails.
when the connection has been established, or NULL will be returned when that fails.
when the connection has been established or NULL will be returned when that fails .
async connect() {
        if (this.#state !== ControlConnection.STATE_DISCONNECTED)
            throw new Error('The control connection is not in a disconnected state.');
        for (const pendingPromise of this.#responses.values())
            pendingPromise(null );
        this.#state = ControlConnection.STATE_CONNECTING;
        this.#responses = new Map();
        this.#socket = new WebSocket(`ws://${window.location.host}/control`);
        this.#socket.addEventListener('open', ControlConnection.prototype.onOpen.bind(this));
        this.#socket.addEventListener('error', ControlConnection.prototype.onError.bind(this));
        this.#socket.addEventListener('message', ControlConnection.prototype.onMessage.bind(this));
        this.#socket.addEventListener('close', ControlConnection.prototype.onClose.bind(this));
    }
async connect ( ) { if ( this . #state !== ControlConnection . STATE_DISCONNECTED ) throw new Error ( 'The control connection is not in a disconnected state.' ) ; for ( const pendingPromise of this . #responses . values ( ) ) pendingPromise ( null ) ; this . #state = ControlConnection . STATE_CONNECTING ; this . #responses = new Map ( ) ; this . #socket = new WebSocket ( ` ${ window . location . host } ` ) ; this . #socket . addEventListener ( 'open' , ControlConnection . prototype . onOpen . bind ( this ) ) ; this . #socket . addEventListener ( 'error' , ControlConnection . prototype . onError . bind ( this ) ) ; this . #socket . addEventListener ( 'message' , ControlConnection . prototype . onMessage . bind ( this ) ) ; this . #socket . addEventListener ( 'close' , ControlConnection . prototype . onClose . bind ( this ) ) ; }
when the connection has been established, or NULL will be returned when that fails.
when the connection has been established or NULL will be returned when that fails .
// Resolve all pending message promises, as we won't be getting responses anymore. /* no response */