Files
DRBv3/client/modules/socketClient.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

46 lines
1.8 KiB
JavaScript

import { io } from "socket.io-client";
import { logIntoServerWrapper, nodeCheckStatus, nodeJoinServer, nodeLeaveServer, nodeGetUsername, nodeCheckDiscordClientStatus, nodeCheckCurrentSystem } from "./socketClientWrappers.mjs";
/**
* Initialize the socket connection with the server, this will handle disconnects within itself
* @param {Object} localNodeConfig The local node config object
* @returns {any}
*/
export const initSocketConnection = async (localNodeConfig) => {
const serverEndpoint = `http://${localNodeConfig.serverIp}:${localNodeConfig.serverPort}` || 'http://localhost:3000'; // Adjust the server endpoint
const socket = io.connect(serverEndpoint);
// 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);
});
// 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;
}