mirror of
https://github.com/onyx-and-iris/meld-cli.git
synced 2025-07-12 02:11:46 +00:00
add stream/record toggle
This commit is contained in:
parent
d70e4f112c
commit
06330f8ed6
34
index.js
34
index.js
@ -6,8 +6,8 @@ import WebSocket from 'ws'
|
||||
import cli from './utils/cli.js'
|
||||
import { sceneHelp, sceneList, sceneSwitch, sceneCurrent } from './utils/scene.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'
|
||||
import { streamHelp, streamStart, streamStop, streamToggle, streamStatus } from './utils/stream.js'
|
||||
import { recordHelp, recordStart, recordStop, recordToggle, recordStatus } from './utils/record.js'
|
||||
|
||||
const input = cli.input
|
||||
const flags = cli.flags
|
||||
@ -225,6 +225,21 @@ socket.onopen = function () {
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'toggle':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
streamToggle(channel)
|
||||
.then((message) => {
|
||||
console.log(message)
|
||||
socket.close()
|
||||
process.exit(0)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`${err}`)
|
||||
socket.close()
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'status':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
streamStatus(channel)
|
||||
@ -284,6 +299,21 @@ socket.onopen = function () {
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'toggle':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
recordToggle(channel)
|
||||
.then((message) => {
|
||||
console.log(message)
|
||||
socket.close()
|
||||
process.exit(0)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`${err}`)
|
||||
socket.close()
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'status':
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
recordStatus(channel)
|
||||
|
@ -7,6 +7,9 @@ const commands = {
|
||||
stop: {
|
||||
desc: 'Stop recording'
|
||||
},
|
||||
toggle: {
|
||||
desc: 'Toggle recording state'
|
||||
},
|
||||
status: {
|
||||
desc: 'Show the current recording status'
|
||||
}
|
||||
@ -70,6 +73,23 @@ function recordStop (channel) {
|
||||
})
|
||||
}
|
||||
|
||||
function recordToggle (channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error('Meld object not found in channel.'))
|
||||
}
|
||||
|
||||
const meld = channel.objects.meld
|
||||
return new Promise((resolve, reject) => {
|
||||
meld.toggleRecord()
|
||||
.then(() => {
|
||||
resolve(`Recording ${meld.isRecording ? 'stopped' : 'started'} successfully.`)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function recordStatus (channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error('Meld object not found in channel.'))
|
||||
@ -83,5 +103,6 @@ export {
|
||||
recordHelp,
|
||||
recordStart,
|
||||
recordStop,
|
||||
recordToggle,
|
||||
recordStatus
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ const commands = {
|
||||
stop: {
|
||||
desc: 'Stop streaming'
|
||||
},
|
||||
toggle: {
|
||||
desc: 'Toggle streaming state'
|
||||
},
|
||||
status: {
|
||||
desc: 'Show the current streaming status'
|
||||
}
|
||||
@ -70,6 +73,23 @@ function streamStop (channel) {
|
||||
})
|
||||
}
|
||||
|
||||
function streamToggle (channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error('Meld object not found in channel.'))
|
||||
}
|
||||
|
||||
const meld = channel.objects.meld
|
||||
return new Promise((resolve, reject) => {
|
||||
meld.toggleStream()
|
||||
.then(() => {
|
||||
resolve(`Streaming ${meld.isStreaming ? 'stopped' : 'started'} successfully.`)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function streamStatus (channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error('Meld object not found in channel.'))
|
||||
@ -82,6 +102,7 @@ function streamStatus (channel) {
|
||||
export {
|
||||
streamStart,
|
||||
streamStop,
|
||||
streamToggle,
|
||||
streamStatus,
|
||||
streamHelp
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user