polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
101 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckinServiceSdk = void 0;
const polyv_live_api_sdk_1 = require("polyv-live-api-sdk");
const errors_1 = require("../utils/errors");
class CheckinServiceSdk {
constructor(authConfig, _serviceConfig) {
this.client = new polyv_live_api_sdk_1.PolyVClient(authConfig);
this.v4Chat = this.client.v4Chat;
this.liveInteraction = this.client.liveInteraction;
}
async startCheckin(params) {
try {
const channelIds = params.channelId.includes(',')
? params.channelId.split(',').map(id => id.trim())
: [params.channelId];
const items = channelIds.map(channelId => {
const item = { channelId };
if (params.limitTime !== undefined) {
item.limitTime = params.limitTime;
}
if (params.delayTime !== undefined) {
item.delayTime = params.delayTime;
}
if (params.message !== undefined) {
item.message = params.message;
}
if (params.forceCheckInEnabled !== undefined) {
item.forceCheckInEnabled = params.forceCheckInEnabled;
}
return item;
});
const result = await this.v4Chat.batchCheckin({ items });
return result;
}
catch (error) {
throw this.wrapError(error, 'startCheckin');
}
}
async listCheckins(params) {
try {
const result = await this.liveInteraction.getCheckinList({
channelId: params.channelId,
page: params.page,
pageSize: params.pageSize,
date: params.date,
sessionId: params.sessionId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listCheckins');
}
}
async getCheckinResult(params) {
try {
const result = await this.liveInteraction.getCheckinByCheckinId({
channelId: params.channelId,
checkinId: params.checkinId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getCheckinResult');
}
}
async getCheckinBySessionId(params) {
try {
const result = await this.liveInteraction.getCheckinBySessionId({
channelId: params.channelId,
sessionId: params.sessionId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getCheckinBySessionId');
}
}
async listSessions(params) {
try {
const result = await this.liveInteraction.getCheckinByTime({
channelId: params.channelId,
startDate: params.startDate,
endDate: params.endDate,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listSessions');
}
}
wrapError(error, operation) {
if (error instanceof errors_1.PolyVError) {
return error;
}
const message = error instanceof Error ? error.message : String(error);
return new errors_1.PolyVError(`${operation} failed: ${message}`, 'CHECKIN_API_ERROR', 1, { originalError: error });
}
}
exports.CheckinServiceSdk = CheckinServiceSdk;
//# sourceMappingURL=checkin-service.js.map