mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-31 01:09:18 +02:00
audio device changes for linux
This commit is contained in:
+30
-12
@@ -1,9 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const fs = require('fs');
|
||||||
|
const filePath = '/proc/asound/cards';
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
|
|
||||||
function parseAudioDevice(options, callback) {
|
function parseAudioDevice(options, callback) {
|
||||||
|
let videoDevices = [];
|
||||||
|
let audioDevices = [];
|
||||||
|
let isVideo = true;
|
||||||
|
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = null;
|
options = null;
|
||||||
@@ -28,15 +34,29 @@ function parseAudioDevice(options, callback) {
|
|||||||
deviceParams = /^\[AVFoundation.*?\]\s\[(\d*?)\]\s(.*)$/;
|
deviceParams = /^\[AVFoundation.*?\]\s\[(\d*?)\]\s(.*)$/;
|
||||||
break;
|
break;
|
||||||
case 'linux':
|
case 'linux':
|
||||||
exec("cat /proc/asound/cards | sed -r 's/^ *([0-9]+) \\[(.*) *\\]: (.*)/hw:\\2/' | grep -E '^hw:'", (err, stdout) => {
|
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||||
audioDevices = stdout.trim().split('\n').map(device => ({ name: device }));
|
if (err) {
|
||||||
const result = { audioDevices };
|
console.error(`Error reading file: ${err.message}`);
|
||||||
if (callbackExists) {
|
return;
|
||||||
callback(result);
|
}
|
||||||
} else {
|
|
||||||
Promise.resolve(result);
|
// Extract values between square brackets, trim whitespace, and prefix with 'hw:'
|
||||||
}
|
const regex = /\[([^\]]+)\]/g;
|
||||||
});
|
const matches = (data.match(regex) || []).map(match => 'hw:' + match.replace(/\s+/g, '').slice(1, -1));
|
||||||
|
|
||||||
|
if (matches.length > 0) {
|
||||||
|
// Process the extracted values
|
||||||
|
matches.forEach(function(match) {
|
||||||
|
if (typeof match === 'string') {
|
||||||
|
audioDevices.push({ name: match });
|
||||||
|
} else if (typeof match === 'object' && match.name) {
|
||||||
|
audioDevices.push(match);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('No matches found.');
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,9 +65,6 @@ function parseAudioDevice(options, callback) {
|
|||||||
const searchAudioSeparator = (line) => isVideo && (line.search(audioSeparator) > -1);
|
const searchAudioSeparator = (line) => isVideo && (line.search(audioSeparator) > -1);
|
||||||
const searchAlternativeName = (line) => (platform === 'win32') && (line.search(/Alternative\sname/) > -1);
|
const searchAlternativeName = (line) => (platform === 'win32') && (line.search(/Alternative\sname/) > -1);
|
||||||
|
|
||||||
let videoDevices = [];
|
|
||||||
let audioDevices = [];
|
|
||||||
let isVideo = true;
|
|
||||||
|
|
||||||
const execute = (fulfill, reject) => {
|
const execute = (fulfill, reject) => {
|
||||||
exec(`${ffmpegPath} -f ${inputDevice} -list_devices true -i ""`, (err, stdout, stderr) => {
|
exec(`${ffmpegPath} -f ${inputDevice} -list_devices true -i ""`, (err, stdout, stderr) => {
|
||||||
@@ -88,6 +105,7 @@ function parseAudioDevice(options, callback) {
|
|||||||
deviceList.push(device);
|
deviceList.push(device);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
audioDevices = audioDevices.filter(device => device.name !== undefined);
|
||||||
const result = { videoDevices, audioDevices };
|
const result = { videoDevices, audioDevices };
|
||||||
if (callbackExists) {
|
if (callbackExists) {
|
||||||
callback(result);
|
callback(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user