Major updates to core
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user