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 cli from './utils/cli.js'
|
||||||
import { sceneHelp, sceneList, sceneSwitch, sceneCurrent } from './utils/scene.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 { streamHelp, streamStart, streamStop, streamStatus } from './utils/stream.js'
|
||||||
import { recordHelp, recordStart, recordStop, recordStatus } from './utils/record.js'
|
import { recordHelp, recordStart, recordStop, recordStatus } from './utils/record.js'
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ socket.onopen = function () {
|
|||||||
case 'list':
|
case 'list':
|
||||||
channel = new QWebChannel(socket, function (channel) {
|
channel = new QWebChannel(socket, function (channel) {
|
||||||
sceneList(channel, flags.id)
|
sceneList(channel, flags.id)
|
||||||
.then((scenes) => {
|
.then((table) => {
|
||||||
console.log(scenes)
|
console.log(table.toString())
|
||||||
socket.close()
|
socket.close()
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
@ -96,6 +96,21 @@ socket.onopen = function () {
|
|||||||
const audioCommand = input[1]
|
const audioCommand = input[1]
|
||||||
const audioName = input[2]
|
const audioName = input[2]
|
||||||
switch (audioCommand) {
|
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':
|
case 'mute':
|
||||||
if (!audioName) {
|
if (!audioName) {
|
||||||
console.error('Error: Audio name is required for the mute command.')
|
console.error('Error: Audio name is required for the mute command.')
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import meowHelp from 'cli-meow-help'
|
import meowHelp from 'cli-meow-help'
|
||||||
|
import Table from 'cli-table3'
|
||||||
|
|
||||||
import { highlight, error } from './style.js'
|
import { highlight, error } from './style.js'
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
|
list: {
|
||||||
|
desc: 'List all audio devices'
|
||||||
|
},
|
||||||
mute: {
|
mute: {
|
||||||
desc: 'Mute the audio'
|
desc: 'Mute the audio'
|
||||||
},
|
},
|
||||||
@ -33,6 +37,40 @@ const audioHelp = meowHelp({
|
|||||||
defaults: false
|
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) {
|
function audioMute (channel, audioName) {
|
||||||
if (!channel.objects || !channel.objects.meld) {
|
if (!channel.objects || !channel.objects.meld) {
|
||||||
return Promise.reject(new Error(error('Meld object not found in channel.')))
|
return Promise.reject(new Error(error('Meld object not found in channel.')))
|
||||||
@ -151,6 +189,7 @@ function audioStatus (channel, audioName) {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
audioHelp,
|
audioHelp,
|
||||||
|
audioList,
|
||||||
audioMute,
|
audioMute,
|
||||||
audioUnmute,
|
audioUnmute,
|
||||||
audioToggle,
|
audioToggle,
|
||||||
|
@ -65,7 +65,7 @@ function sceneList (channel, showId) {
|
|||||||
if (table.length === 0) {
|
if (table.length === 0) {
|
||||||
return Promise.reject(new Error('No scenes found.'))
|
return Promise.reject(new Error('No scenes found.'))
|
||||||
}
|
}
|
||||||
return Promise.resolve(table.toString())
|
return Promise.resolve(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sceneSwitch (channel, sceneName) {
|
function sceneSwitch (channel, sceneName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user