mirror of
https://github.com/onyx-and-iris/meld-cli.git
synced 2025-07-12 02:11:46 +00:00
implement stream commands
This commit is contained in:
parent
19a2bc8448
commit
38e279fe3c
61
index.js
61
index.js
@ -3,6 +3,7 @@
|
||||
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 { streamHelp, streamStart, streamStop, streamStatus } from "./utils/stream.js";
|
||||
import { QWebChannel } from "qwebchannel";
|
||||
|
||||
|
||||
@ -180,6 +181,66 @@ socket.onopen = function() {
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
case "stream":
|
||||
if (flags.help) {
|
||||
console.log(streamHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const streamCommand = input[1];
|
||||
switch (streamCommand) {
|
||||
case "start":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
streamStart(channel)
|
||||
.then((message) => {
|
||||
console.log(message);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`${err}`);
|
||||
socket.close();
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case "stop":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
streamStop(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)
|
||||
.then((isStreaming) => {
|
||||
console.log(`Streaming is currently ${isStreaming ? "active" : "inactive"}`);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Error fetching stream status: ${err}`);
|
||||
socket.close();
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.log(streamHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error handling CLI flags:", error);
|
||||
|
@ -8,6 +8,9 @@ const commands = {
|
||||
audio: {
|
||||
desc: "Manage audio settings",
|
||||
},
|
||||
stream: {
|
||||
desc: "Manage streaming",
|
||||
},
|
||||
};
|
||||
|
||||
const flags = {
|
||||
|
83
utils/stream.js
Normal file
83
utils/stream.js
Normal file
@ -0,0 +1,83 @@
|
||||
import meowHelp from "cli-meow-help";
|
||||
|
||||
const commands = {
|
||||
start: {
|
||||
desc: "Start streaming",
|
||||
},
|
||||
stop: {
|
||||
desc: "Stop streaming",
|
||||
},
|
||||
status: {
|
||||
desc: "Show the current streaming status",
|
||||
},
|
||||
};
|
||||
|
||||
const flags = {
|
||||
help: {
|
||||
type: "boolean",
|
||||
shortFlag: "h",
|
||||
desc: "Display help information",
|
||||
},
|
||||
};
|
||||
|
||||
const streamHelp = meowHelp({
|
||||
name: "meld-cli stream",
|
||||
flags,
|
||||
commands,
|
||||
description: "Manage streaming in Meld",
|
||||
defaults: false,
|
||||
});
|
||||
|
||||
function streamStart(channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error("Meld object not found in channel."));
|
||||
}
|
||||
|
||||
const meld = channel.objects.meld;
|
||||
if (meld.isStreaming) {
|
||||
return Promise.reject(new Error("Streaming is already active."));
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
meld.toggleStream()
|
||||
.then(() => {
|
||||
resolve("Streaming started successfully.");
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function streamStop(channel) {
|
||||
if (!channel.objects || !channel.objects.meld) {
|
||||
return Promise.reject(new Error("Meld object not found in channel."));
|
||||
}
|
||||
|
||||
const meld = channel.objects.meld;
|
||||
if (!meld.isStreaming) {
|
||||
return Promise.reject(new Error("Streaming is not currently active."));
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
meld.toggleStream()
|
||||
.then(() => {
|
||||
resolve("Streaming stopped 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."));
|
||||
}
|
||||
|
||||
const meld = channel.objects.meld;
|
||||
return Promise.resolve(meld.isStreaming);
|
||||
}
|
||||
|
||||
export { streamHelp, streamStart, streamStop, streamStatus };
|
Loading…
x
Reference in New Issue
Block a user