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:
@@ -17,7 +17,8 @@ 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;
|
const port = process.env.PDAB_PORT || 3000;
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
@@ -30,25 +31,30 @@ export const initDiscordBotClient = (clientId, callback) => {
|
|||||||
// Listen for the discord client ready event
|
// Listen for the discord client ready event
|
||||||
socket.on('discord_ready', (message) => {
|
socket.on('discord_ready', (message) => {
|
||||||
console.log("Message from local client", message);
|
console.log("Message from local client", message);
|
||||||
callback();
|
botCallback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(port, async () => {
|
server.listen(port, async () => {
|
||||||
console.log(`Server is running on port ${port}`);
|
console.log(`Server is running on port ${port}`);
|
||||||
|
|
||||||
if (process.env.NODE_ENV == "production") {
|
|
||||||
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 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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user