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:
Logan Cusano
2024-05-05 23:39:05 -04:00
parent fee40dd609
commit 03c940e07c
2 changed files with 26 additions and 22 deletions

View File

@@ -19,9 +19,17 @@ const __dirname = dirname(__filename);
let botCallback; let botCallback;
const port = process.env.PDAB_PORT || 3000; export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
botCallback = callback;
io.on('connection', (socket) => { 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 startPdabSocketServer = () => {
const port = process.env.PDAB_PORT || 3000;
io.on('connection', (socket) => {
console.log('A user connected'); console.log('A user connected');
socket.on('disconnect', () => { socket.on('disconnect', () => {
@@ -33,17 +41,12 @@ io.on('connection', (socket) => {
console.log("Message from local client", message); console.log("Message from local client", message);
botCallback(); 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}`);
}); });
return
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 = () => {

View File

@@ -1,4 +1,4 @@
import { connectToChannel, leaveVoiceChannel, checkIfConnectedToVC, initDiscordBotClient, requestDiscordUsername, requestDiscordID, requestDiscordClientClose, closePdabSocketServer, setDiscordClientPrsense } from './pdabHandler.mjs'; import { connectToChannel, leaveVoiceChannel, checkIfConnectedToVC, initDiscordBotClient, requestDiscordUsername, requestDiscordID, requestDiscordClientClose, closePdabSocketServer, setDiscordClientPrsense, startPdabSocketServer } from './pdabHandler.mjs';
import { openOP25, closeOP25 } from '../op25Handler/op25Handler.mjs'; import { openOP25, closeOP25 } from '../op25Handler/op25Handler.mjs';
let activeDiscordClient = undefined; let activeDiscordClient = undefined;
@@ -14,6 +14,7 @@ export const joinDiscordVC = async (joinData) => {
console.log("Checking if there is a client open"); console.log("Checking if there is a client open");
if (!await checkIfClientIsOpen()) { if (!await checkIfClientIsOpen()) {
console.log("There is no open client, starting it now"); console.log("There is no open client, starting it now");
await startPdabSocketServer();
// Open an instance of OP25 // Open an instance of OP25
console.log("Starting OP25") console.log("Starting OP25")
openOP25(joinData.system); openOP25(joinData.system);