diff --git a/index.js b/index.js index 3ddec1f..7e8e019 100755 --- a/index.js +++ b/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) diff --git a/utils/record.js b/utils/record.js index 8bfc6e8..5e5e938 100644 --- a/utils/record.js +++ b/utils/record.js @@ -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 } diff --git a/utils/stream.js b/utils/stream.js index 1dcc0bb..15ae549 100644 --- a/utils/stream.js +++ b/utils/stream.js @@ -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 }