Files
DRB-Client/modules/socketClientWrappers.mjs
2024-05-12 12:55:00 -04:00

108 lines
3.4 KiB
JavaScript

import { checkIfDiscordVCConnected, joinDiscordVC, leaveDiscordVC, getDiscordUsername, checkIfClientIsOpen, getDiscordID } from '../discordAudioBot/pdabWrappers.mjs';
import { getCurrentSystem } from '../op25Handler/op25Handler.mjs';
import { checkForUpdates } from './selfUpdater.mjs';
/**
* Check if the bot has an update available
* @param {any} socketCallback The callback function to return the result
* @callback {boolean} If the node has an update available or not
*/
export const nodeUpdate = async (socketCallback) => {
socketCallback(await checkForUpdates());
}
/**
* Wrapper to log into the server
* @param {any} socket The socket connection with the server
* @param {object} localNodeConfig The local node object
* @returns {any}
*/
export const logIntoServerWrapper = async (socket, localNodeConfig) => {
// Log into the server
socket.emit("node-login", localNodeConfig.node);
// Send an update to the server
sendNodeUpdateWrapper(socket, localNodeConfig);
}
/**
* Send the server an update
* @param {any} socket The socket connection with the server
* @param {object} localNodeConfig The local node object
*/
export const sendNodeUpdateWrapper = async (socket, localNodeConfig) => {
socket.emit('node-update', {
'node': localNodeConfig.node,
'nearbySystems': localNodeConfig.nearbySystems
});
}
/**
* Join the requested server VC and listen to the requested system
* @param {object} joinData The object containing all the information to join the server
*/
export const nodeJoinServer = async (joinData) => {
await joinDiscordVC(joinData);
}
/**
* Leave VC on the requested server
* @param {string} guildId The guild ID to disconnect from VC
*/
export const nodeLeaveServer = async (guildId) => {
await leaveDiscordVC(guildId);
}
/**
* Check if the bot is connected to a discord VC in the given server
* @param {string} guildId The guild id to check the connection status in
* @param {any} socketCallback The callback function to return the result to
* @callback {boolean} If the node is connected to VC in the given guild
*/
export const nodeCheckStatus = async (guildId, socketCallback) => {
socketCallback(await checkIfDiscordVCConnected(guildId));
}
/**
* Get the username of the bot in a given guild
* (there may be a server nickname given to the bot in a certain guild)
* @param {string} guildId The guild id to check the connection status in
* @param {any} socketCallback The callback function to return the result to
* @callback {any}
*/
export const nodeGetUsername = async (guildId, socketCallback) => {
socketCallback(await getDiscordUsername(guildId));
}
/**
* Get the ID of the active client
* @param {any} socketCallback The callback function to return the result to
* @callback {any}
*/
export const nodeGetDiscordID = async (socketCallback) => {
socketCallback(await getDiscordID());
}
/**
* Check if the local node has an open discord client in any server
* @callback {boolean} If the node has an open discord client or not
*/
export const nodeCheckDiscordClientStatus = async (socketCallback) => {
socketCallback(await checkIfClientIsOpen());
}
/**
* Check what system the local node is currently listening to
* @callback {boolean} If the node has an open discord client or not
*/
export const nodeCheckCurrentSystem = async (socketCallback) => {
socketCallback(await getCurrentSystem());
}