49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
// Modules
|
|
const { promisify } = require('util');
|
|
const { exec } = require("child_process");
|
|
// Debug
|
|
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
|
// Global Vars
|
|
const log = new DebugBuilder("client-bot", "executeConsoleCommands");
|
|
const execCommand = promisify(exec);
|
|
|
|
|
|
exports.executeAsyncConsoleCommand = async function executeAsyncConsoleCommand(consoleCommand) {
|
|
// Check to see if the command is a real command
|
|
// TODO needs to be improved
|
|
const acceptableCommands = [ "arecord -L" ];
|
|
if (!acceptableCommands.includes(consoleCommand)) {
|
|
log.WARN("Console command is not acceptable: ", consoleCommand);
|
|
return undefined;
|
|
}
|
|
log.DEBUG("Running console command: ", consoleCommand);
|
|
|
|
const tempOutput = await execCommand(consoleCommand);
|
|
const output = tempOutput.stdout.trim();
|
|
|
|
log.DEBUG("Executed Console Command Response: ", output)
|
|
|
|
// TODO add some error checking
|
|
return output;
|
|
}
|
|
|
|
exports.returnAlsaDeviceObject = async function returnAlsaDeviceObject() {
|
|
const listAlsaDevicesCommand = "arecord -L";
|
|
const commandResponse = await executeAsyncConsoleCommand(listAlsaDevicesCommand);
|
|
const brokenCommand = String(commandResponse).split('\n');
|
|
var devices = [];
|
|
var i = 0;
|
|
|
|
for (const responseLine of brokenCommand) {
|
|
if (String(responseLine) && !String(responseLine).match(/^\s/g)) {
|
|
const tempDevice = {
|
|
id: i,
|
|
name: responseLine
|
|
}
|
|
devices.push(tempDevice);
|
|
i += 1;
|
|
}
|
|
}
|
|
|
|
return devices;
|
|
} |