polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
112 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatStreamStatusForTable = formatStreamStatusForTable;
exports.formatStreamStatusForJson = formatStreamStatusForJson;
exports.formatStatusWithIcon = formatStatusWithIcon;
exports.formatDuration = formatDuration;
exports.formatBandwidth = formatBandwidth;
exports.formatCompactStatus = formatCompactStatus;
exports.formatTable = formatTable;
exports.formatJSON = formatJSON;
const Table = require('cli-table3');
function formatStreamStatusForTable(status) {
const formattedStatus = {
'Channel ID': status.channelId,
'Status': formatStatusWithIcon(status.status, status.statusText),
'Last Updated': status.lastUpdated.toLocaleString()
};
if (status.isLive && status.durationText) {
formattedStatus['Duration'] = status.durationText;
}
if (status.metrics) {
formattedStatus['FPS'] = status.metrics.fps.toFixed(2);
if (status.metrics.lfr > 0) {
formattedStatus['Frame Loss'] = `${status.metrics.lfr.toFixed(2)}%`;
}
formattedStatus['Bandwidth'] = status.metrics.bandwidthText;
}
if (status.network) {
if (status.network.deployAddress) {
formattedStatus['Deploy Address'] = status.network.deployAddress;
}
if (status.network.inAddress) {
formattedStatus['Input Address'] = status.network.inAddress;
}
if (status.network.streamName) {
formattedStatus['Stream Name'] = status.network.streamName;
}
}
if (status.error) {
formattedStatus['Error'] = `${status.error.code}: ${status.error.message}`;
}
return formattedStatus;
}
function formatStreamStatusForJson(status) {
return status;
}
function formatStatusWithIcon(status, statusText) {
switch (status) {
case 'live':
return `🟢 ${statusText}`;
case 'stopped':
return `⚫ ${statusText}`;
case 'waiting':
return `🟡 ${statusText}`;
case 'error':
return `🔴 ${statusText}`;
case 'unknown':
default:
return `⚪ ${statusText}`;
}
}
function formatDuration(duration) {
const seconds = Math.floor(duration / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
if (hours > 0) {
return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
}
else if (minutes > 0) {
return `${minutes}m ${seconds % 60}s`;
}
else {
return `${seconds}s`;
}
}
function formatBandwidth(bandwidth) {
if (bandwidth === 0)
return '0 bps';
const units = ['bps', 'Kbps', 'Mbps', 'Gbps'];
let unitIndex = 0;
let value = bandwidth;
while (value >= 1024 && unitIndex < units.length - 1) {
value /= 1024;
unitIndex++;
}
return `${value.toFixed(2)} ${units[unitIndex]}`;
}
function formatCompactStatus(status) {
const icon = formatStatusWithIcon(status.status, '').trim();
let summary = `${icon} ${status.statusText}`;
if (status.isLive && status.durationText) {
summary += ` (${status.durationText})`;
}
return summary;
}
function formatTable(options) {
const table = new Table({
head: options.headers,
style: {
head: ['cyan'],
border: ['gray'],
},
});
options.data.forEach(row => {
table.push(row);
});
return table.toString();
}
function formatJSON(data) {
return JSON.stringify(data, null, 2);
}
//# sourceMappingURL=formatter.js.map