37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { io } from "socket.io-client";
|
|
import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID } from '../discordAudioBot/dab.mjs';
|
|
import { logIntoServerWrapper, sendNodeUpdateWrapper } from "./socketClientWrappers.mjs";
|
|
|
|
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.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, client => {
|
|
getVoiceChannelFromID(client, joinData.channelID).then(vc => {
|
|
const connection = connectToChannel(vc);
|
|
console.log("Bot Connected to VC");
|
|
})
|
|
});
|
|
});
|
|
|
|
socket.on('node-leave', () => {
|
|
console.log("Leave requested");
|
|
});
|
|
|
|
socket.on('disconnect', () => {
|
|
console.log('Disconnected from the server');
|
|
});
|
|
|
|
return socket;
|
|
} |