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
This commit is contained in:
Logan Cusano
2024-03-03 00:10:43 -05:00
parent 63ad20b9b3
commit 35f3f07793
8 changed files with 504 additions and 64 deletions

View File

@@ -1,6 +1,5 @@
import { io } from "socket.io-client";
import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID, checkIfConnectedToVC, getVoiceConnectionFromGuild } from '../discordAudioBot/dab.mjs';
import { logIntoServerWrapper, sendNodeUpdateWrapper, nodeCheckStatus } from "./socketClientWrappers.mjs";
import { logIntoServerWrapper, nodeCheckStatus, nodeJoinServer, nodeLeaveServer, nodeGetUsername, nodeCheckDiscordClientStatus, nodeCheckCurrentSystem } from "./socketClientWrappers.mjs";
/**
* Initialize the socket connection with the server, this will handle disconnects within itself
@@ -12,53 +11,36 @@ export const initSocketConnection = async (localNodeConfig) => {
const socket = io.connect(serverEndpoint);
const discordClients = {};
// Socket Events ('system' events persay)
// When the socket connects to the node server
socket.on('connect', async () => {
console.log('Connected to the server');
await logIntoServerWrapper(socket, localNodeConfig);
});
socket.on('node-join', async (joinData) => {
console.log("Join requested: ", joinData)
// TODO - Implement logic to control OP25 for the requested channel/system
// Join the requested channel with the requested ID
initDiscordBotClient(joinData.clientID, joinData.system, client => {
getVoiceChannelFromID(client, joinData.channelID).then(vc => {
// Add the client object to the IO instance
discordClients[vc.guild.id] = client;
const connection = connectToChannel(vc);
console.log("Bot Connected to VC");
})
});
});
socket.on('node-leave', async (guildId) => {
console.log("Leave requested");
if (await checkIfConnectedToVC(guildId)) {
const connection = await getVoiceConnectionFromGuild(guildId);
if (connection) {
console.log("There is an open VC connection, closing it now");
// Destroy the open VC connection
connection.destroy();
// Remove the client from the socket connection
delete discordClients[guildId];
}
}
});
socket.on('node-get-discord-username', async (guildId, socketCallback) => {
console.log("Requested username");
socketCallback(discordClients[guildId].user.username);
});
socket.on('node-check-connected-status', nodeCheckStatus);
// When the socket disconnects from the node server
socket.on('disconnect', () => {
console.log('Disconnected from the server');
});
// Node events/commands
// Requested to join a discord guild and listen to a system
socket.on('node-join', nodeJoinServer);
// Requested to leave a discord guild
socket.on('node-leave', nodeLeaveServer);
// Requested to get the discord username in a given guild
socket.on('node-get-discord-username', nodeGetUsername);
// Requested to check if the node is connected to VC in a given guild
socket.on('node-check-connected-status', nodeCheckStatus);
// Requested to check if the node has an open discord client
socket.on('node-check-discord-open-client', nodeCheckDiscordClientStatus);
// Requested to get the current listening system
socket.on('node-check-current-system', nodeCheckCurrentSystem);
return socket;
}