mirror of
https://github.com/onyx-and-iris/meld-cli.git
synced 2025-07-12 02:11:46 +00:00
add audio list command
This commit is contained in:
parent
f66e7b9c75
commit
5ea2a4abe6
21
index.js
21
index.js
@ -5,7 +5,7 @@ import WebSocket from 'ws'
|
||||
|
||||
import cli from './utils/cli.js'
|
||||
import { sceneHelp, sceneList, sceneSwitch, sceneCurrent } from './utils/scene.js'
|
||||
import { audioHelp, audioMute, audioUnmute, audioToggle, audioStatus } from './utils/audio.js'
|
||||
import { audioHelp, audioList, audioMute, audioUnmute, audioToggle, audioStatus } from './utils/audio.js'
|
||||
import { streamHelp, streamStart, streamStop, streamStatus } from './utils/stream.js'
|
||||
import { recordHelp, recordStart, recordStop, recordStatus } from './utils/record.js'
|
||||
|
||||
@ -34,8 +34,8 @@ socket.onopen = function () {
|
||||
case 'list':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
sceneList(channel, flags.id)
|
||||
.then((scenes) => {
|
||||
console.log(scenes)
|
||||
.then((table) => {
|
||||
console.log(table.toString())
|
||||
socket.close()
|
||||
process.exit(0)
|
||||
})
|
||||
@ -96,6 +96,21 @@ socket.onopen = function () {
|
||||
const audioCommand = input[1]
|
||||
const audioName = input[2]
|
||||
switch (audioCommand) {
|
||||
case 'list':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
audioList(channel, flags.id)
|
||||
.then((table) => {
|
||||
console.log(table.toString())
|
||||
socket.close()
|
||||
process.exit(0)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`${err}`)
|
||||
socket.close()
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'mute':
|
||||
if (!audioName) {
|
||||
console.error('Error: Audio name is required for the mute command.')
|
||||
|
@ -1,8 +1,12 @@
|
||||
import meowHelp from 'cli-meow-help'
|
||||
import Table from 'cli-table3'
|
||||
|
||||
import { highlight, error } from './style.js'
|
||||
|
||||
const commands = {
|
||||
list: {
|
||||
desc: 'List all audio devices'
|
||||
},
|
||||
mute: {
|
||||
desc: 'Mute the audio'
|
||||
},
|
||||
@ -33,6 +37,40 @@ const audioHelp = meowHelp({
|
||||
defaults: false
|
||||
})
|
||||
|
||||
function audioList (channel, showId) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error('Meld object not found in channel.'))
|
||||
}
|
||||
|
||||
const headers = [{ content: 'Audio Name', hAlign: 'center' }, { content: 'Muted', hAlign: 'center' }]
|
||||
if (showId) {
|
||||
headers.push({ content: 'ID', hAlign: 'center' })
|
||||
}
|
||||
const table = new Table({
|
||||
style: {
|
||||
head: ['none'],
|
||||
compact: true
|
||||
},
|
||||
head: headers
|
||||
})
|
||||
|
||||
const meld = channel.objects.meld
|
||||
for (const [key, value] of Object.entries(meld.session.items)) {
|
||||
if (value.type === 'track') {
|
||||
if (showId) {
|
||||
table.push([highlight(value.name), { content: value.muted ? highlight('✓') : '✗', hAlign: 'center' }, highlight(key)])
|
||||
} else {
|
||||
table.push([highlight(value.name), { content: value.muted ? highlight('✓') : '✗', hAlign: 'center' }])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (table.length === 0) {
|
||||
return Promise.resolve('No audio devices found.')
|
||||
}
|
||||
return Promise.resolve(table)
|
||||
}
|
||||
|
||||
function audioMute (channel, audioName) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error(error('Meld object not found in channel.')))
|
||||
@ -151,6 +189,7 @@ function audioStatus (channel, audioName) {
|
||||
|
||||
export {
|
||||
audioHelp,
|
||||
audioList,
|
||||
audioMute,
|
||||
audioUnmute,
|
||||
audioToggle,
|
||||
|
@ -65,7 +65,7 @@ function sceneList (channel, showId) {
|
||||
if (table.length === 0) {
|
||||
return Promise.reject(new Error('No scenes found.'))
|
||||
}
|
||||
return Promise.resolve(table.toString())
|
||||
return Promise.resolve(table)
|
||||
}
|
||||
|
||||
function sceneSwitch (channel, sceneName) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user