diff --git a/src/client/index.ts b/src/client/index.ts index 790a716d..6fa67cd6 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -37,6 +37,7 @@ class Client { this.getServerResources = servermethods.getServerResources; this.sendCommand = servermethods.sendCommand; this.setPowerState = servermethods.setPowerState; + this.getWebsocketUrl = servermethods.getWebsocketUrl; // Console const consolemethods = new consoleMethods(this, this.errorHandler); this.startConsoleConnection = consolemethods.startConsoleConnection; @@ -154,6 +155,7 @@ class Client { public getAllBackups; public getBackupInfo; public getBackupDownloadLink; + public getWebsocketUrl; // POST public sendCommand; public setPowerState; diff --git a/src/client/methods/server.ts b/src/client/methods/server.ts index 09b4b60a..99ff96c7 100644 --- a/src/client/methods/server.ts +++ b/src/client/methods/server.ts @@ -8,6 +8,7 @@ import { Servers } from '../interfaces/Server'; import { ServerResources } from '../interfaces/ServerResources'; +import { WebsocketAuthData } from '../interfaces/WebsocketAuthData'; export class serverMethods { constructor(private readonly client: Client) {} @@ -142,4 +143,26 @@ export class serverMethods { `/api/client/servers/${serverId}/power` ); }; + /** + * @param serverId - ID of the server to get a websocket url for + * @returns Websocket url and token for the server + * @example + * ```ts + * const res = await client.getWebsocketUrl('c2f5a3b6') // res = wss://panel.example.xyz/api/client/servers/c2f5a3b6/ws + * ``` + * @example + * ```ts + * client.getWebsocketUrl('c2f5a3b6').then((res) => console.log(res)) // res = wss://panel.example.xyz/api/client/servers/c2f5a3b6/ws + * ``` + */ + public getWebsocketUrl = async ( + serverId: string + ): Promise => { + return this.client.request( + 'GET', + null, + '', + `/api/client/servers/${serverId}/websocket` + ); + }; }