Files
DRBv3/client/modules/socketClientWrappers.mjs
Logan Cusano 35f3f07793 Working on #9
- Can join and leave from voice channels
- Will check to make sure that the bot is in a given system or no system before joining
- Cleaned up the socket client with wrappers
- Added a new module to handle subprocesses for the client
- Beginning workings on OP25 handler
- Added OP25 config object generator with config exporter
2024-03-03 00:10:43 -05:00

85 lines
2.8 KiB
JavaScript

import { checkIfDiscordVCConnected, joinDiscordVC, leaveDiscordVC, getDiscordUsername, checkIfClientIsOpen } from '../discordAudioBot/dabWrappers.mjs';
import { getCurrentSystem } from '../op25Handler/op25Handler.mjs';
/**
* 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));
}
/**
* 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());
}