polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
112 lines • 5.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransmitHandler = void 0;
const base_handler_1 = require("./base.handler");
const errors_1 = require("../utils/errors");
const api_command_1 = require("../utils/api-command");
const transmit_service_1 = require("../services/transmit-service");
class TransmitHandler extends base_handler_1.BaseHandler {
constructor(authConfig, serviceConfig) {
super();
this.transmitService = new transmit_service_1.TransmitServiceSdk(authConfig, serviceConfig);
}
async batchCreateTransmitChannels(options) {
const format = options.output || 'table';
this.validateChannelId(options.channelId);
this.validateNames(options.names);
const namesArray = options.names.split(',').map(name => name.trim()).filter(name => name.length > 0);
const createdChannels = await this.transmitService.batchCreateTransmitChannels(options.channelId, namesArray);
if (format === 'json') {
this.displayData(createdChannels, 'json');
}
else {
this.displayCreatedChannelsTable(createdChannels);
}
}
async getTransmitAssociations(options) {
const format = options.output || 'table';
this.validateChannelId(options.channelId);
const associations = await this.transmitService.getTransmitAssociations(options.channelId);
if (format === 'json') {
this.displayData(associations, 'json');
}
else {
this.displayAssociationsTable(associations);
}
}
async associationReceiveChannels(options) {
const format = options.output || 'table';
this.validateChannelId(options.channelId);
if (!options.receiveChannelIds || options.receiveChannelIds.length === 0) {
throw new errors_1.PolyVValidationError('receiveChannelIds is required (接收频道ID是必需的)', 'receiveChannelIds', options.receiveChannelIds, 'required');
}
await (0, api_command_1.confirmWrite)(options.force, `${options.type === 'cancel' ? 'Cancel' : 'Add'} transmit association(s) for channel ${options.channelId}?`);
const associationOptions = {
channelId: options.channelId,
receiveChannelIds: options.receiveChannelIds,
};
if (options.type) {
associationOptions.type = options.type;
}
const result = await this.transmitService.associationReceiveChannels(associationOptions);
if (format === 'json') {
this.displayData({ success: true, receiveChannelIds: result }, 'json');
}
else {
this.displaySuccess('Transmit associations updated successfully', {
channelId: options.channelId,
receiveChannelIds: result,
}, 'table');
}
}
validateChannelId(channelId) {
if (!channelId || channelId.trim() === '') {
throw new errors_1.PolyVValidationError('channelId is required (频道ID是必需的)', 'channelId', channelId, 'required');
}
}
validateNames(names) {
if (!names || names.trim() === '') {
throw new errors_1.PolyVValidationError('names is required (频道名称是必需的)', 'names', names, 'required');
}
const namesArray = names.split(',').map(name => name.trim()).filter(name => name.length > 0);
if (namesArray.length === 0) {
throw new errors_1.PolyVValidationError('names must contain at least one valid name (频道名称必须包含至少一个有效名称)', 'names', names, 'invalid');
}
if (namesArray.length > 100) {
throw new errors_1.PolyVValidationError('names count exceeds maximum of 100 (频道名称数量超过最大值100)', 'names', names, 'exceed_maximum');
}
}
displayCreatedChannelsTable(channels) {
if (channels.length === 0) {
console.log('No transmit channels created (未创建转播频道)');
return;
}
const tableData = channels.map((channel) => {
return {
'频道号': channel.channelId,
'频道名称': channel.name,
'频道密码': channel.channelPasswd,
'观看条件': channel.authType,
'推流方式': channel.streamType,
'状态': channel.status,
};
});
this.displayAsTable(tableData);
console.log(`\nCreated ${channels.length} transmit channel(s) successfully (成功创建 ${channels.length} 个转播频道)`);
}
displayAssociationsTable(associations) {
if (associations.length === 0) {
console.log('No transmit associations found (未找到转播关联)');
return;
}
const tableData = associations.map((assoc) => {
return {
'发起转播频道号': assoc.channelId || '-',
'接收转播频道号': assoc.receiveChannelId,
};
});
this.displayAsTable(tableData);
}
}
exports.TransmitHandler = TransmitHandler;
//# sourceMappingURL=transmit.handler.js.map