Major updates to core

This commit is contained in:
Logan Cusano
2024-02-10 15:10:35 -05:00
parent d563021866
commit 9c46792959
22 changed files with 977 additions and 156 deletions

View File

@@ -1,34 +1,28 @@
import { io } from "socket.io-client";
import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID } from '../discordAudioBot/dab.mjs';
import { logIntoServerWrapper, sendNodeUpdateWrapper } from "./socketClientWrappers.mjs";
export function initSocketConnection(localNodeConfig) {
export const initSocketConnection = async (localNodeConfig) => {
const serverEndpoint = `http://${localNodeConfig.serverIp}:${localNodeConfig.serverPort}` || 'http://localhost:3000'; // Adjust the server endpoint
const socket = io.connect(serverEndpoint);
return socket;
}
export function initSocketListeners(socket, localNodeConfig) {
socket.on('connect', () => {
socket.on('connect', async () => {
console.log('Connected to the server');
logIntoServer(socket, localNodeConfig.node);
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
// TODO - Implement logic to control OP25 for the requested channel/system
// Join the requested channel with the requested ID
initDiscordBotClient(joinData.clientID, client => {
console.log("Client:", client);
initDiscordBotClient(joinData.clientID, client => {
getVoiceChannelFromID(client, joinData.channelID).then(vc => {
console.log("Voice Channel:", vc);
console.log("Voice Channel Guild:", vc.Guild);
const connection = connectToChannel(vc);
console.log("Bot Connected to VC");
})
});
console.log("All done?");
});
});
socket.on('node-leave', () => {
@@ -39,12 +33,5 @@ export function initSocketListeners(socket, localNodeConfig) {
console.log('Disconnected from the server');
});
}
export function logIntoServer(socket, nodeData) {
socket.emit("node-login", nodeData);
}
export function sendNodeUpdate(socket, nodeData) {
socket.emit('node-update', nodeData);
return socket;
}