polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
246 lines • 8.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InteractionServiceSdk = void 0;
const polyv_live_api_sdk_1 = require("polyv-live-api-sdk");
const fs_1 = require("fs");
const errors_1 = require("../utils/errors");
class InteractionServiceSdk {
constructor(authConfig, _serviceConfig) {
this.client = new polyv_live_api_sdk_1.PolyVClient(authConfig);
this.liveInteraction = this.client.liveInteraction;
this.v4Channel = this.client.v4Channel;
}
async sendFavor(params) {
try {
const result = await this.liveInteraction.sendFavor({
channelId: params.channelId,
viewerId: params.viewerId,
times: params.times,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'sendFavor');
}
}
async sendRewardMsg(params) {
try {
const result = await this.liveInteraction.sendRewardMsg({
channelId: params.channelId,
nickname: params.nickname,
avatar: params.avatar,
viewerId: params.viewerId,
donateType: params.donateType,
content: params.content,
goodImage: params.goodImage,
sessionId: params.sessionId,
goodNum: params.goodNum,
needUserImage: params.needUserImage,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'sendRewardMsg');
}
}
async getStudentQuestionWebhook(params) {
try {
const result = await this.liveInteraction.getStudentQuestionWebhook({
roomId: params.roomId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getStudentQuestionWebhook');
}
}
async setStudentQuestionWebhook(params) {
try {
const result = await this.liveInteraction.setStudentQuestionWebhook({
roomId: params.roomId,
callbackUrl: params.callbackUrl,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'setStudentQuestionWebhook');
}
}
async deleteStudentQuestionWebhook(params) {
try {
const result = await this.liveInteraction.deleteStudentQuestionWebhook({
roomId: params.roomId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'deleteStudentQuestionWebhook');
}
}
async sendTeacherAnswer(params) {
try {
const result = await this.liveInteraction.sendTeacherAnswer({
roomId: params.roomId,
content: params.content,
viewerUserId: params.viewerUserId,
teacherNick: params.teacherNick,
teacherPic: params.teacherPic,
msgType: params.msgType,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'sendTeacherAnswer');
}
}
async listInteractionEvents(params) {
try {
return await this.v4Channel.listInteractionEvents(params);
}
catch (error) {
throw this.wrapError(error, 'listInteractionEvents');
}
}
async saveInteractionEvent(params) {
try {
return await this.v4Channel.interactionEventSave(params);
}
catch (error) {
throw this.wrapError(error, 'saveInteractionEvent');
}
}
async deleteInteractionEvent(params) {
try {
return await this.v4Channel.interactionEventDelete(params);
}
catch (error) {
throw this.wrapError(error, 'deleteInteractionEvent');
}
}
async createInvitePoster(params) {
try {
return await this.v4Channel.createInvitePoster(params);
}
catch (error) {
throw this.wrapError(error, 'createInvitePoster');
}
}
async queryDiskVideoCustomScript(params) {
try {
return await this.v4Channel.queryDiskVideoCustomScript(params);
}
catch (error) {
throw this.wrapError(error, 'queryDiskVideoCustomScript');
}
}
async uploadDiskVideoCustomScript(params) {
try {
const filePath = String(params.filePath ?? '');
const bytes = (0, fs_1.readFileSync)(filePath);
const file = new Blob([bytes]);
return await this.v4Channel.uploadDiskVideoCustomScript({
channelId: params.channelId,
diskVideoId: params.diskVideoId,
labelId: params.labelId,
file,
});
}
catch (error) {
throw this.wrapError(error, 'uploadDiskVideoCustomScript');
}
}
async deleteInteractionScript(params) {
try {
await this.v4Channel.deleteInteractionScript(params);
return { success: true };
}
catch (error) {
throw this.wrapError(error, 'deleteInteractionScript');
}
}
async createTaskRewardActivity(params) {
try {
return await this.v4Channel.createTaskRewardActivity(params);
}
catch (error) {
throw this.wrapError(error, 'createTaskRewardActivity');
}
}
async listTaskRewardActivities(params) {
try {
return await this.v4Channel.listTaskRewardActivities(params);
}
catch (error) {
throw this.wrapError(error, 'listTaskRewardActivities');
}
}
async listTaskRewardStats(params) {
try {
return await this.v4Channel.listTaskRewardStats(params);
}
catch (error) {
throw this.wrapError(error, 'listTaskRewardStats');
}
}
async listTaskRewardViewerDetails(params) {
try {
return await this.v4Channel.listTaskRewardViewerDetails(params);
}
catch (error) {
throw this.wrapError(error, 'listTaskRewardViewerDetails');
}
}
async updateTaskRewardActivity(params) {
try {
await this.v4Channel.updateTaskRewardActivity(params);
return { success: true };
}
catch (error) {
throw this.wrapError(error, 'updateTaskRewardActivity');
}
}
async deleteTaskRewardActivity(params) {
try {
await this.v4Channel.deleteTaskRewardActivity(params);
return { success: true };
}
catch (error) {
throw this.wrapError(error, 'deleteTaskRewardActivity');
}
}
async stopTaskRewardActivity(params) {
try {
await this.v4Channel.stopTaskRewardActivity(params);
return { success: true };
}
catch (error) {
throw this.wrapError(error, 'stopTaskRewardActivity');
}
}
async listViewerTaskRewardDetails(params) {
try {
return await this.v4Channel.listViewerTaskRewardDetails(params);
}
catch (error) {
throw this.wrapError(error, 'listViewerTaskRewardDetails');
}
}
async submitViewerTaskRewardAcceptInfo(params) {
try {
await this.v4Channel.submitViewerTaskRewardAcceptInfo(params);
return { success: true };
}
catch (error) {
throw this.wrapError(error, 'submitViewerTaskRewardAcceptInfo');
}
}
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}`, 'INTERACTION_API_ERROR', 1, { originalError: error });
}
}
exports.InteractionServiceSdk = InteractionServiceSdk;
//# sourceMappingURL=interaction-service.js.map