UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

141 lines 6.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionServiceSdk = void 0; const errors_1 = require("../utils/errors"); const sdk_1 = require("../sdk"); class SessionServiceSdk { constructor(authConfig, serviceConfig) { this.authConfig = authConfig; this.config = serviceConfig; } async getSessionList(options) { this.validateListOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const params = { channelId: (options.channelId !== undefined && options.channelId !== '') ? parseInt(options.channelId, 10) : undefined, }; if (options.page !== undefined) { params.pageNumber = options.page; } if (options.pageSize !== undefined) { params.pageSize = options.pageSize; } const result = await client.v4Channel.sessionList(params); return { contents: (result.contents || []).map((item) => this.transformToDisplayItem(item)), pageNumber: result.pageNumber, pageSize: result.pageSize, totalItems: result.totalItems || 0, totalPages: result.totalPages || 0, }; } async getSession(channelId, sessionId) { this.validateGetParams(channelId, sessionId); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const result = await client.v4Channel.sessionGet({ channelId: parseInt(channelId, 10), sessionId, }); return this.transformToDisplayItem(result); } async listLegacyChannelSessions(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.listChannelSessions(options); } async getSessionDataList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.getSessionDataList(options); } async getSessionExternalBySession(channelId, sessionId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.v4Channel.getSessionExternalBySession({ channelId, sessionId }); } async createSession(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.v4Channel.sessionCreate(options); } async updateSession(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); await client.v4Channel.sessionUpdate(options); } async deleteSession(channelId, sessionId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); await client.v4Channel.sessionDelete({ channelId, sessionId }); } async getSessionByExternal(channelId, externalSessionId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.getSessionByExternal({ channelId, externalSessionId }); } async listFileIdByExternal(channelId, externalSessionId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.listFileIdByExternal({ channelId, externalSessionId }); } async relevanceSession(channelId, externalSessionId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return client.channel.relevanceSession({ channelId, externalSessionId }); } transformToDisplayItem(item) { const displayItem = { sessionId: item.sessionId, channelId: String(item.channelId), status: item.status, }; if (item.name !== undefined) displayItem.name = item.name; if (item.startTime !== undefined) displayItem.startTime = item.startTime; if (item.endTime !== undefined) displayItem.endTime = item.endTime; if (item.createdTime !== undefined) displayItem.createdTime = item.createdTime; if (item.planStartTime !== undefined) displayItem.planStartTime = item.planStartTime; if (item.planEndTime !== undefined) displayItem.planEndTime = item.planEndTime; if (item.streamType !== undefined) displayItem.streamType = item.streamType; if (item.pushClient !== undefined) displayItem.pushClient = item.pushClient; if (item.watchUrl !== undefined) displayItem.watchUrl = item.watchUrl; if (item.userId !== undefined) displayItem.userId = item.userId; if (item.splashImg !== undefined) displayItem.splashImg = item.splashImg; if (item.splashLargeImg !== undefined) displayItem.splashLargeImg = item.splashLargeImg; return displayItem; } validateListOptions(options) { const errors = []; if (options.channelId !== undefined && options.channelId !== '' && (typeof options.channelId !== 'string' || options.channelId.trim().length === 0)) { errors.push('channelId must be a non-empty string if provided'); } if (options.page !== undefined && (!Number.isInteger(options.page) || options.page < 1)) { errors.push('page must be a positive integer'); } if (options.pageSize !== undefined && (!Number.isInteger(options.pageSize) || options.pageSize < 1)) { errors.push('pageSize must be a positive integer'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Session list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateGetParams(channelId, sessionId) { const errors = []; if (!channelId || typeof channelId !== 'string' || channelId.trim().length === 0) { errors.push('channelId is required and must be a non-empty string'); } if (!sessionId || typeof sessionId !== 'string' || sessionId.trim().length === 0) { errors.push('sessionId is required and must be a non-empty string'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Session get parameters validation failed: ${errors.join(', ')}`, 'params', { channelId, sessionId }, 'validation_failed'); } } } exports.SessionServiceSdk = SessionServiceSdk; //# sourceMappingURL=session.service.sdk.js.map