UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

163 lines 7.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlayerServiceSdk = void 0; const errors_1 = require("../utils/errors"); const sdk_1 = require("../sdk"); class PlayerServiceSdk { constructor(authConfig, serviceConfig) { this.authConfig = authConfig; this.config = serviceConfig; } async getChannelDecorate(options) { this.validateGetOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const result = await client.player.getChannelDecorate(parseInt(options.channelId, 10)); const player = result.player; return { watermarkEnabled: player.watermarkEnabled, watermarkUrl: player.iconUrl || '', watermarkPosition: player.iconPosition || 'br', watermarkOpacity: String(player.logoOpacity ?? 1), watermarkLink: player.iconLink || '', warmupEnabled: player.warmUpEnabled || 'N', warmupImageUrl: player.warmUpImageUrl || '', coverJumpUrl: player.coverJumpUrl || '', backgroundImageUrl: player.backgroundUrl || '', basePv: player.basePV ?? 0, actualPv: player.actualPV ?? 0, }; } async updateChannelDecorate(options) { this.validateUpdateOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const params = {}; const updatedFields = []; if (options.watermarkEnabled !== undefined) { params.watermarkEnabled = options.watermarkEnabled; updatedFields.push('watermarkEnabled'); } if (options.watermarkUrl !== undefined) { params.iconUrl = options.watermarkUrl; updatedFields.push('watermarkUrl'); } if (options.watermarkPosition !== undefined) { params.iconPosition = options.watermarkPosition; updatedFields.push('watermarkPosition'); } if (options.watermarkOpacity !== undefined) { params.logoOpacity = options.watermarkOpacity; updatedFields.push('watermarkOpacity'); } if (options.warmupImageUrl !== undefined) { params.warmUpImageUrl = options.warmupImageUrl; updatedFields.push('warmupImageUrl'); } if (options.basePv !== undefined) { params.basePV = options.basePv; updatedFields.push('basePv'); } const hasDecorateUpdates = Object.keys(params).length > 0; let warmupEnabledToRestore; if (hasDecorateUpdates && options.warmupEnabled === undefined) { const currentDecorate = await client.player.getChannelDecorate(parseInt(options.channelId, 10)); const currentWarmupEnabled = currentDecorate?.player?.warmUpEnabled; if (currentWarmupEnabled === 'Y' || currentWarmupEnabled === 'N') { warmupEnabledToRestore = currentWarmupEnabled; } } if (hasDecorateUpdates) { await client.player.updateChannelDecorate(parseInt(options.channelId, 10), params); } const warmupEnabled = options.warmupEnabled ?? warmupEnabledToRestore; if (warmupEnabled !== undefined) { await client.channel.updateWarmupSwitch({ channelId: options.channelId, warmUpEnabled: warmupEnabled, }); } if (options.warmupEnabled !== undefined) { updatedFields.push('warmupEnabled'); } return { success: true, updatedFields, }; } async getAntiRecordSettings(channelId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.getAntiRecordSettings(channelId === undefined ? undefined : Number(channelId)); } async setAntiRecordSettings(channelId, params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.setAntiRecordSettings(Number(channelId), params); } async setMarqueeUrl(channelId, params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.setMarqueeUrl(Number(channelId), params); } async updateHeadAdvert(channelId, params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.updateHeadAdvert(Number(channelId), params); } async updateStopAdvert(channelId, params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.updateStopAdvert(Number(channelId), params); } async getWatchFeedbackList(params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.player.getWatchFeedbackList(params); } async updatePlayerLogo(channelId, params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.updatePlayerLogo(String(channelId), params); } async updateWarmupSwitch(params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.updateWarmupSwitch(params); } async updateSkinBatch(params) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.v4Channel.updateSkinBatch(params); } validateGetOptions(options) { const errors = []; if (!options.channelId || typeof options.channelId !== 'string' || options.channelId.trim().length === 0) { errors.push('channelId is required and must be a non-empty string'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Player config get options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateUpdateOptions(options) { const errors = []; if (!options.channelId || typeof options.channelId !== 'string' || options.channelId.trim().length === 0) { errors.push('channelId is required and must be a non-empty string'); } if (options.watermarkPosition !== undefined) { const validPositions = ['tl', 'tr', 'bl', 'br']; if (!validPositions.includes(options.watermarkPosition)) { errors.push(`watermarkPosition must be one of: ${validPositions.join(', ')}`); } } if (options.watermarkOpacity !== undefined) { if (typeof options.watermarkOpacity !== 'number' || options.watermarkOpacity < 0 || options.watermarkOpacity > 1) { errors.push('watermarkOpacity must be a number between 0 and 1'); } } if (options.watermarkEnabled !== undefined) { if (options.watermarkEnabled !== 'Y' && options.watermarkEnabled !== 'N') { errors.push('watermarkEnabled must be "Y" or "N"'); } } if (options.warmupEnabled !== undefined) { if (options.warmupEnabled !== 'Y' && options.warmupEnabled !== 'N') { errors.push('warmupEnabled must be "Y" or "N"'); } } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Player config update options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } } exports.PlayerServiceSdk = PlayerServiceSdk; //# sourceMappingURL=player.service.sdk.js.map