Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,6 +155,7 @@ class Client {
public getAllBackups;
public getBackupInfo;
public getBackupDownloadLink;
public getWebsocketUrl;
// POST
public sendCommand;
public setPowerState;
Expand Down
23 changes: 23 additions & 0 deletions src/client/methods/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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<WebsocketAuthData> => {
return this.client.request(
'GET',
null,
'',
`/api/client/servers/${serverId}/websocket`
);
};
}