Compare commits
2 Commits
3950d57b7f
...
3e7b387092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e7b387092 | ||
|
|
7fb67f6ddf |
@@ -22,7 +22,7 @@ let botCallback;
|
|||||||
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
||||||
botCallback = callback;
|
botCallback = callback;
|
||||||
|
|
||||||
if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
|
if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, false, join(__dirname, "./pdab"));
|
||||||
pdabProcess = true; // TODO - Make this more dynamic
|
pdabProcess = true; // TODO - Make this more dynamic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import express from 'express';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { generateUniqueID } from '../../modules/baseUtils.mjs';
|
import { generateUniqueID } from '../../modules/baseUtils.mjs';
|
||||||
import { restartApplication } from '../../modules/selfUpdater.mjs'
|
import { restartApplication } from '../../modules/selfUpdater.mjs'
|
||||||
|
import { launchProcess } from '../../modules/subprocessHandler.mjs'
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Define __dirname for ESM
|
const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Define __dirname for ESM
|
||||||
@@ -12,8 +13,10 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Define __dirn
|
|||||||
let systemsData = [];
|
let systemsData = [];
|
||||||
let nodeData = {};
|
let nodeData = {};
|
||||||
|
|
||||||
router.get('/', (req, res) => {
|
router.get('/', async (req, res) => {
|
||||||
res.render('setup/setup');
|
const output = await launchProcess('python', ['./discordAudioBot/pdab/getDevices.py'], true, true)
|
||||||
|
console.log("Device List", output);
|
||||||
|
res.render('setup/setup', { deviceList: output });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Route to serve the page for adding nearby systems
|
// Route to serve the page for adding nearby systems
|
||||||
@@ -23,13 +26,14 @@ router.get('/add-system', (req, res) => {
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
// Handle form submission here
|
// Handle form submission here
|
||||||
const { clientName, clientLocation, clientCapabilities } = req.body;
|
const { clientName, clientLocation, clientCapabilities, audioDeviceId } = req.body;
|
||||||
|
|
||||||
console.log(clientName, clientLocation, clientCapabilities);
|
console.log(clientName, clientLocation, clientCapabilities, audioDeviceId);
|
||||||
|
|
||||||
nodeData.clientName = clientName;
|
nodeData.clientName = clientName;
|
||||||
nodeData.clientLocation = clientLocation;
|
nodeData.clientLocation = clientLocation;
|
||||||
nodeData.clientCapabilities = clientCapabilities;
|
nodeData.clientCapabilities = clientCapabilities;
|
||||||
|
nodeData.audioDeviceId = audioDeviceId;
|
||||||
|
|
||||||
res.redirect('/setup/add-system');
|
res.redirect('/setup/add-system');
|
||||||
});
|
});
|
||||||
@@ -86,8 +90,11 @@ const exportCsv = (nodeData) => {
|
|||||||
CLIENT_CAPABILITIES: nodeData.clientCapabilities,
|
CLIENT_CAPABILITIES: nodeData.clientCapabilities,
|
||||||
SERVER_IP: "",
|
SERVER_IP: "",
|
||||||
SERVER_PORT: 0,
|
SERVER_PORT: 0,
|
||||||
OP25_FULL_PATH: `${__dirname}/op25/op25/gr-op25_repeater/apps`,
|
OP25_FULL_PATH: path.resolve(__dirname, '../../op25/op25/gr-op25_repeater/apps'),
|
||||||
CONFIG_PATH: "./config/radioPresets.json",
|
CONFIG_PATH: "./config/radioPresets.json",
|
||||||
|
AUDIO_DEVICE_ID: nodeData.audioDeviceId,
|
||||||
|
PDAB_PORT: 3110,
|
||||||
|
NODE_ENV: "production",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate .env file content
|
// Generate .env file content
|
||||||
|
|||||||
@@ -19,7 +19,14 @@
|
|||||||
<label for="clientCapabilities">Client Capabilities (comma-separated):</label>
|
<label for="clientCapabilities">Client Capabilities (comma-separated):</label>
|
||||||
<input type="text" id="clientCapabilities" name="clientCapabilities" required>
|
<input type="text" id="clientCapabilities" name="clientCapabilities" required>
|
||||||
<br>
|
<br>
|
||||||
|
<label for="audioDeviceId">Audio Device ID (typically 'default'):</label>
|
||||||
|
<input type="text" id="audioDeviceId" name="audioDeviceId" required>
|
||||||
|
<br>
|
||||||
<button type="submit">Next</button>
|
<button type="submit">Next</button>
|
||||||
|
<div>
|
||||||
|
<h3>Audio Devices</h3>
|
||||||
|
<p><%- deviceList.replace(/\n/g, '<br>') %> </p>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ const runningProcesses = {};
|
|||||||
* @param {string} processName - The name of the process to launch.
|
* @param {string} processName - The name of the process to launch.
|
||||||
* @param {string[]} args - The arguments to pass to the process.
|
* @param {string[]} args - The arguments to pass to the process.
|
||||||
* @param {boolean} waitForClose - Set this to wait to return until the process exits
|
* @param {boolean} waitForClose - Set this to wait to return until the process exits
|
||||||
|
* @param {boolean} returnOutput - Set this in addition to 'waitForClose' to return the script output when the process closes
|
||||||
|
* @param {boolean} waitForClose - Set the current working directory of the process being launched
|
||||||
*/
|
*/
|
||||||
export const launchProcess = (processName, args, waitForClose = false, pcwd = undefined) => {
|
export const launchProcess = (processName, args, waitForClose = false, returnOutput = false, pcwd = undefined) => {
|
||||||
if (!runningProcesses[processName]) {
|
if (!runningProcesses[processName]) {
|
||||||
let childProcess;
|
let childProcess;
|
||||||
if (pcwd) {
|
if (pcwd) {
|
||||||
@@ -44,18 +46,22 @@ export const launchProcess = (processName, args, waitForClose = false, pcwd = un
|
|||||||
scriptOutput += data.toString();
|
scriptOutput += data.toString();
|
||||||
})
|
})
|
||||||
|
|
||||||
let code = new Promise(res => {
|
let output = new Promise(res => {
|
||||||
childProcess.on('exit', (code, signal) => {
|
childProcess.on('exit', (code, signal) => {
|
||||||
// Remove reference to the process when it exits
|
// Remove reference to the process when it exits
|
||||||
delete runningProcesses[processName];
|
delete runningProcesses[processName];
|
||||||
console.log(`${processName} process exited with code ${code} and signal ${signal}`);
|
console.log(`${processName} process exited with code ${code} and signal ${signal}`);
|
||||||
console.log("Child process console output: ", scriptOutput);
|
console.log("Child process console output: ", scriptOutput);
|
||||||
res(code);
|
// Return the full script output if requested
|
||||||
|
if (returnOutput === true) {
|
||||||
|
return res(scriptOutput)
|
||||||
|
}
|
||||||
|
return res(code);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (waitForClose === true) {
|
if (waitForClose === true) {
|
||||||
return code
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`${processName} process started.`);
|
console.log(`${processName} process started.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user