jspteroapi
Version:
A pterodactyl v1 api using undici
37 lines (36 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.consoleMethods = void 0;
const Websocket_1 = require("../Websocket");
class consoleMethods {
client;
errorHandler;
constructor(client, errorHandler) {
this.client = client;
this.errorHandler = errorHandler;
}
/**
* @internal
*/
getWebsocketAuthData = async (serverId) => {
return this.client.request('GET', null, 'data', `/api/client/servers/${serverId}/websocket`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @remarks This method is used to connect to server websocket and have automatic authentication. This exposes the websocket client.
* @returns WebsocketClient
* @example
* ```ts
* const res = await client.startConsoleConnection('c2f5a3b6') // res = WebsocketClient
* ```
* @example
* ```ts
* client.startConsoleConnection('c2f5a3b6').then((res) => console.log(res)) // res = WebsocketClient
* ```
*/
startConsoleConnection = async (serverId) => {
const auth = await this.getWebsocketAuthData(serverId);
return new Websocket_1.WebsocketClient(this.errorHandler, auth, this.getWebsocketAuthData.bind(this, serverId));
};
}
exports.consoleMethods = consoleMethods;