"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLivestream = getLivestream; exports.getStreamObj = getStreamObj; exports.getPlayBackUrl = getPlayBackUrl; const assert_1 = require("oak-domain/lib/utils/assert"); const getContextConfig_1 = require("./getContextConfig"); /** * 创建直播流并生成推拉流地址 * @param streamTitle 直播流名称 * @param expireAt 推流过期时间 * @param context context * @returns Livestream 对象 */ async function getLivestream(params, context) { const { streamTitle, expireAt, origin } = params; // 获取七牛直播云信息 const { instance, config, } = (0, getContextConfig_1.getConfig)(context.getApplication().system.config, 'Live', origin); (0, assert_1.assert)(origin === 'qiniu'); const { hub, liveHost, publishDomain, playDomainType, playDomain, playKey, publishKey, publishSecurity } = config; const r = await instance.getLiveStream(hub, streamTitle, liveHost, publishDomain, playDomainType, playDomain, expireAt, publishSecurity, publishKey, playKey); return { streamTitle, hub, rtmpPushUrl: r.rtmpPushUrl, rtmpPlayUrl: r.playUrl, pcPushUrl: r.pcPushUrl, streamKey: r.streamKey, expireAt, }; } // 获取推拉流地址 /** * 直播流已存在的情况下,获取推拉流地址 * @param streamTitle 直播流名称 * @param expireAt 推流过期时间 * @param context context * @returns livestream对象 */ async function getStreamObj(params, context) { const { streamTitle, expireAt, origin } = params; const { instance, config, } = (0, getContextConfig_1.getConfig)(context.getApplication().system.config, 'Live', origin); (0, assert_1.assert)(origin === 'qiniu'); const { playDomainType, publishDomain, publishSecurity, publishKey, playDomain, playKey, hub } = config; const r = instance.getStreamObj(hub, streamTitle, expireAt, publishDomain, playDomainType, playDomain, publishSecurity, publishKey, playKey); return { streamTitle, hub, rtmpPushUrl: r.rtmpPushUrl, rtmpPlayUrl: r.playUrl, pcPushUrl: r.pcPushUrl, streamKey: r.streamKey, expireAt, }; } // 生成直播回放 async function getPlayBackUrl(params, context) { const { streamTitle, start, end, origin } = params; // 获取七牛直播云信息 const { config, instance } = (0, getContextConfig_1.getConfig)(context.getApplication().system.config, 'Live', origin); const { hub, playBackDomain, liveHost } = config; return instance.getPlayBackUrl(hub, playBackDomain, streamTitle, start, end, 'POST', liveHost); }