Update PDAB handler
- Move PDAB socket server startup to function - Updated join server wrapper to start the server before opening the python app
This commit is contained in:
@@ -19,26 +19,6 @@ const __dirname = dirname(__filename);
|
||||
|
||||
let botCallback;
|
||||
|
||||
const port = process.env.PDAB_PORT || 3000;
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('A user connected');
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('User disconnected');
|
||||
});
|
||||
|
||||
// Listen for the discord client ready event
|
||||
socket.on('discord_ready', (message) => {
|
||||
console.log("Message from local client", message);
|
||||
botCallback();
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(port, async () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
||||
|
||||
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
||||
botCallback = callback;
|
||||
|
||||
@@ -46,6 +26,29 @@ export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
||||
pdabProcess = true; // TODO - Make this more dynamic
|
||||
}
|
||||
|
||||
export const startPdabSocketServer = () => {
|
||||
const port = process.env.PDAB_PORT || 3000;
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('A user connected');
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('User disconnected');
|
||||
});
|
||||
|
||||
// Listen for the discord client ready event
|
||||
socket.on('discord_ready', (message) => {
|
||||
console.log("Message from local client", message);
|
||||
botCallback();
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(port, async () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
||||
return
|
||||
}
|
||||
|
||||
export const closePdabSocketServer = () => {
|
||||
if (io.sockets && io.sockets.length > 0) {
|
||||
io.sockets.forEach(socket => {
|
||||
@@ -80,7 +83,7 @@ export const setDiscordClientPrsense = (system) => {
|
||||
return new Promise((res) => {
|
||||
io.timeout(25000).emit('set_system', { system: system }, (status) => {
|
||||
res();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user