Update pdab handler

- Updated socket close
- Took server outside of the init (server is always running)
- initDiscordBotClient just starts the PDAB process
This commit is contained in:
Logan Cusano
2024-04-27 23:33:53 -04:00
parent 34aa5d17dc
commit e7229322e4

View File

@@ -17,38 +17,44 @@ let pdabProcess = false;
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
export const initDiscordBotClient = (clientId, callback) => { let botCallback;
const port = process.env.PDAB_PORT || 3000;
io.on('connection', (socket) => { const port = process.env.PDAB_PORT || 3000;
console.log('A user connected');
socket.on('disconnect', () => { io.on('connection', (socket) => {
console.log('User disconnected'); console.log('A user connected');
});
// Listen for the discord client ready event socket.on('disconnect', () => {
socket.on('discord_ready', (message) => { console.log('User disconnected');
console.log("Message from local client", message);
callback();
});
}); });
server.listen(port, async () => { // Listen for the discord client ready event
console.log(`Server is running on port ${port}`); socket.on('discord_ready', (message) => {
console.log("Message from local client", message);
if (process.env.NODE_ENV == "production") { botCallback();
launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
}
pdabProcess = true; // TODO - Make this more dynamic
}); });
});
server.listen(port, async () => {
console.log(`Server is running on port ${port}`);
});
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
botCallback = callback;
if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
pdabProcess = true; // TODO - Make this more dynamic
} }
export const closePdabSocketServer = () => { export const closePdabSocketServer = () => {
if (io.sockets && io.sockets.length > 0) {
io.sockets.forEach(socket => {
socket.destroy();
})
}
return io.close(); return io.close();
} }
// Function to emit a command to join a voice channel // Function to emit a command to join a voice channel
export const connectToChannel = (channelId) => { export const connectToChannel = (channelId) => {
return new Promise((res) => { return new Promise((res) => {