align naming + add js docs

This commit is contained in:
Mads Rasmussen
2023-11-10 13:55:29 +01:00
parent 213b527315
commit fa689b54aa

View File

@@ -3,20 +3,50 @@ import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import { tryExecute } from '@umbraco-cms/backoffice/resources';
export class UmbServerConnection {
#serverUrl: string;
#serverStatus: RuntimeLevelModel = RuntimeLevelModel.UNKNOWN;
#connected = new UmbBooleanState(false);
#url: string;
#status: RuntimeLevelModel = RuntimeLevelModel.UNKNOWN;
#isConnected = new UmbBooleanState(false);
isConnected = this.#isConnected.asObservable();
constructor(serverUrl: string) {
this.#serverUrl = serverUrl;
this.#url = serverUrl;
}
/**
* Connects to the server.
* @memberof UmbServerConnection
*/
async connect() {
await this.#setStatus();
}
/**
* Gets the URL of the server.
* @return {*}
* @memberof UmbServerConnection
*/
getUrl() {
return this.#url;
}
/**
* Gets the status of the server.
* @return {string}
* @memberof UmbServerConnection
*/
getStatus() {
return this.#serverStatus;
if (!this.getIsConnected()) throw new Error('Server is not connected. Remember to await connect()');
return this.#status;
}
/**
* Checks if the server is connected.
* @return {boolean}
* @memberof UmbServerConnection
*/
getIsConnected() {
return this.#isConnected.getValue();
}
async #setStatus() {
@@ -25,7 +55,7 @@ export class UmbServerConnection {
throw error;
}
this.#connected.next(true);
this.#serverStatus = data?.serverStatus ?? RuntimeLevelModel.UNKNOWN;
this.#isConnected.next(true);
this.#status = data?.serverStatus ?? RuntimeLevelModel.UNKNOWN;
}
}