import { io } from "socket.io-client"; import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID } from '../discordAudioBot/dab.mjs'; export function initSocketConnection(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', () => { console.log('Connected to the server'); logIntoServer(socket, localNodeConfig.node); }); socket.on('node-join', async (joinData) => { console.log("Join requested: ", joinData) // TODO - Implement logic to control OP25 for the requested channel // Join the requested channel with the requested ID initDiscordBotClient(joinData.clientID, client => { console.log("Client:", 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("All done?"); }); socket.on('node-leave', () => { console.log("Leave requested"); }); socket.on('disconnect', () => { 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); }