New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trtc-sdk-v5

Package Overview
Dependencies
Maintainers
9
Versions
290
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trtc-sdk-v5 - npm Package Compare versions

Comparing version 5.3.2-beta.3 to 5.3.2-beta.4

plugins/cdn-streaming/cdn-streaming.js

2

package.json
{
"name": "trtc-sdk-v5",
"version": "5.3.2-beta.3",
"version": "5.3.2-beta.4",
"description": "Tencent Cloud RTC SDK for Web",

@@ -5,0 +5,0 @@ "main": "trtc.js",

@@ -1,1 +0,1 @@

var ue=Object.create;var q=Object.defineProperty,de=Object.defineProperties,me=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,he=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var F=(l,e,i)=>e in l?q(l,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[e]=i,I=(l,e)=>{for(var i in e||(e={}))z.call(e,i)&&F(l,i,e[i]);if(W)for(var i of W(e))pe.call(e,i)&&F(l,i,e[i]);return l},j=(l,e)=>de(l,le(e));var ge=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var Se=(l,e,i,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of ce(e))!z.call(l,d)&&d!==i&&q(l,d,{get:()=>e[d],enumerable:!(u=me(e,d))||u.enumerable});return l};var Y=(l,e,i)=>(i=l!=null?ue(he(l)):{},Se(e||!l||!l.__esModule?q(i,"default",{value:l,enumerable:!0}):i,l));var S=(l,e,i)=>(F(l,typeof e!="symbol"?e+"":e,i),i);var J=ge((Z,B)=>{(function(l){"use strict";function e(t,h){var r=(t&65535)+(h&65535),g=(t>>16)+(h>>16)+(r>>16);return g<<16|r&65535}function i(t,h){return t<<h|t>>>32-h}function u(t,h,r,g,C,D){return e(i(e(e(h,t),e(g,D)),C),r)}function d(t,h,r,g,C,D,f){return u(h&r|~h&g,t,h,C,D,f)}function c(t,h,r,g,C,D,f){return u(h&g|r&~g,t,h,C,D,f)}function m(t,h,r,g,C,D,f){return u(h^r^g,t,h,C,D,f)}function p(t,h,r,g,C,D,f){return u(r^(h|~g),t,h,C,D,f)}function b(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var r,g,C,D,f,o=1732584193,a=-271733879,s=-1732584194,n=271733878;for(r=0;r<t.length;r+=16)g=o,C=a,D=s,f=n,o=d(o,a,s,n,t[r],7,-680876936),n=d(n,o,a,s,t[r+1],12,-389564586),s=d(s,n,o,a,t[r+2],17,606105819),a=d(a,s,n,o,t[r+3],22,-1044525330),o=d(o,a,s,n,t[r+4],7,-176418897),n=d(n,o,a,s,t[r+5],12,1200080426),s=d(s,n,o,a,t[r+6],17,-1473231341),a=d(a,s,n,o,t[r+7],22,-45705983),o=d(o,a,s,n,t[r+8],7,1770035416),n=d(n,o,a,s,t[r+9],12,-1958414417),s=d(s,n,o,a,t[r+10],17,-42063),a=d(a,s,n,o,t[r+11],22,-1990404162),o=d(o,a,s,n,t[r+12],7,1804603682),n=d(n,o,a,s,t[r+13],12,-40341101),s=d(s,n,o,a,t[r+14],17,-1502002290),a=d(a,s,n,o,t[r+15],22,1236535329),o=c(o,a,s,n,t[r+1],5,-165796510),n=c(n,o,a,s,t[r+6],9,-1069501632),s=c(s,n,o,a,t[r+11],14,643717713),a=c(a,s,n,o,t[r],20,-373897302),o=c(o,a,s,n,t[r+5],5,-701558691),n=c(n,o,a,s,t[r+10],9,38016083),s=c(s,n,o,a,t[r+15],14,-660478335),a=c(a,s,n,o,t[r+4],20,-405537848),o=c(o,a,s,n,t[r+9],5,568446438),n=c(n,o,a,s,t[r+14],9,-1019803690),s=c(s,n,o,a,t[r+3],14,-187363961),a=c(a,s,n,o,t[r+8],20,1163531501),o=c(o,a,s,n,t[r+13],5,-1444681467),n=c(n,o,a,s,t[r+2],9,-51403784),s=c(s,n,o,a,t[r+7],14,1735328473),a=c(a,s,n,o,t[r+12],20,-1926607734),o=m(o,a,s,n,t[r+5],4,-378558),n=m(n,o,a,s,t[r+8],11,-2022574463),s=m(s,n,o,a,t[r+11],16,1839030562),a=m(a,s,n,o,t[r+14],23,-35309556),o=m(o,a,s,n,t[r+1],4,-1530992060),n=m(n,o,a,s,t[r+4],11,1272893353),s=m(s,n,o,a,t[r+7],16,-155497632),a=m(a,s,n,o,t[r+10],23,-1094730640),o=m(o,a,s,n,t[r+13],4,681279174),n=m(n,o,a,s,t[r],11,-358537222),s=m(s,n,o,a,t[r+3],16,-722521979),a=m(a,s,n,o,t[r+6],23,76029189),o=m(o,a,s,n,t[r+9],4,-640364487),n=m(n,o,a,s,t[r+12],11,-421815835),s=m(s,n,o,a,t[r+15],16,530742520),a=m(a,s,n,o,t[r+2],23,-995338651),o=p(o,a,s,n,t[r],6,-198630844),n=p(n,o,a,s,t[r+7],10,1126891415),s=p(s,n,o,a,t[r+14],15,-1416354905),a=p(a,s,n,o,t[r+5],21,-57434055),o=p(o,a,s,n,t[r+12],6,1700485571),n=p(n,o,a,s,t[r+3],10,-1894986606),s=p(s,n,o,a,t[r+10],15,-1051523),a=p(a,s,n,o,t[r+1],21,-2054922799),o=p(o,a,s,n,t[r+8],6,1873313359),n=p(n,o,a,s,t[r+15],10,-30611744),s=p(s,n,o,a,t[r+6],15,-1560198380),a=p(a,s,n,o,t[r+13],21,1309151649),o=p(o,a,s,n,t[r+4],6,-145523070),n=p(n,o,a,s,t[r+11],10,-1120210379),s=p(s,n,o,a,t[r+2],15,718787259),a=p(a,s,n,o,t[r+9],21,-343485551),o=e(o,g),a=e(a,C),s=e(s,D),n=e(n,f);return[o,a,s,n]}function _(t){var h,r="",g=t.length*32;for(h=0;h<g;h+=8)r+=String.fromCharCode(t[h>>5]>>>h%32&255);return r}function T(t){var h,r=[];for(r[(t.length>>2)-1]=void 0,h=0;h<r.length;h+=1)r[h]=0;var g=t.length*8;for(h=0;h<g;h+=8)r[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return r}function R(t){return _(b(T(t),t.length*8))}function w(t,h){var r,g=T(t),C=[],D=[],f;for(C[15]=D[15]=void 0,g.length>16&&(g=b(g,t.length*8)),r=0;r<16;r+=1)C[r]=g[r]^909522486,D[r]=g[r]^1549556828;return f=b(C.concat(T(h)),512+h.length*8),_(b(D.concat(f),512+128))}function E(t){var h="0123456789abcdef",r="",g,C;for(C=0;C<t.length;C+=1)g=t.charCodeAt(C),r+=h.charAt(g>>>4&15)+h.charAt(g&15);return r}function O(t){return unescape(encodeURIComponent(t))}function U(t){return R(O(t))}function K(t){return E(U(t))}function k(t,h){return w(O(t),O(h))}function A(t,h){return E(k(t,h))}function G(t,h,r){return h?r?k(h,t):A(h,t):r?U(t):K(t)}typeof define=="function"&&define.amd?define(function(){return G}):typeof B=="object"&&B.exports?B.exports=G:l.md5=G})(Z)});var Q=Y(J(),1);var y=(u=>(u.PublishMainStreamToCDN="publish-main-stream-to-cdn",u.PublishSubStreamToCDN="publish-sub-stream-to-cdn",u.PublishMixStreamToCDN="publish-mix-stream-to-cdn",u))(y||{}),X=(i=>(i.Main="main",i.Sub="sub",i))(X||{});var V={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var M=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_paramsForGivenCDN");S(this,"_publishGivenCDNData",null);S(this,"_isPublishingGivenCDN",!1);this._core=e,this._room=e.room,this._log=i,this._paramsForGivenCDN=new Map([["publish-main-stream-to-cdn",null],["publish-sub-stream-to-cdn",null],["publish-mix-stream-to-cdn",null]])}async startPublishGivenCDN(e){this._log.info(`[CDNStreaming] startPublishGivenCDN() ${JSON.stringify(e)}`),this._paramsForGivenCDN.set(e.publishMode,e);let i={pushRequestTime:Date.now(),pushAppId:e.appId,pushBizId:e.bizId,pushCdnUrl:e.url,pushStreamType:this.convertStreamType(e==null?void 0:e.publishMode),pushStreamId:e.streamId};this._publishGivenCDNData=i;try{this._isPublishingGivenCDN&&await this.stopPublishGivenCDN();let u=await this._room.sendStartPublishCDN(i,!1),{code:d,message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: start given cdn."),this._isPublishingGivenCDN=!0;else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${d} errMsg: ${c} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${d} errMsg: ${c}`)}catch(u){throw this.resetGivenCDN(),u}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this._isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c}=this._publishGivenCDNData,m={pushRequestTime:Date.now(),pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c},p=await this._room.sendStopPublishCDN(m,!1),{code:b,message:_}=p.data;if(b===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_} data: ${JSON.stringify(m)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._isPublishingGivenCDN=!1}convertStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}};var L=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_config",null);S(this,"_data",null);S(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=i,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,i,u;return((e=this._config)==null?void 0:e.target.appId)&&((i=this._config)==null?void 0:i.target.bizId)&&((u=this._config)==null?void 0:u.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let i=this.getInputParam(e),u=this.getOutputParam(e),d=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&d!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:d,inputParam:i,outputParam:u});let{appId:c,bizId:m,url:p,streamId:b=""}=this._config.target;c&&m&&p&&(this._givenCDNManager||(this._givenCDNManager=new M(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:m,url:p,streamId:b}))}catch(i){throw this.reset(),i}}async doStartMixTranscode({outputSessionId:e,inputParam:i,outputParam:u}){let d={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:i,outputParam:u};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(d)}`);let c=await this._room.sendStartMixTranscode(d),{code:m}=c.data,{message:p}=c.data;if(m===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=d;else throw m===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${m} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${m} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let i=await this._room.sendStopMixTranscode(e),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`)}reset(){this._config=null,this._data=null,this.uninstallEvents()}installEvents(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}async handleRoomJoined(){this._log.info(`[CDNStreaming] handleJoined: ${JSON.stringify(this._config)}`),this.isStarted&&this._config&&await this.startMixTranscode(this._config)}async handleRoomLeft(){this._log.info(`[CDNStreaming] handleRoomLeft: ${JSON.stringify(this._config)}`),this._data=null}getOutputSessionId({config:e,userId:i,roomId:u}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,Q.default)(`${u}_${i}_main`)}getStringRoomId(e,i){return e?String(e):i}getInputParam(e){let{mix:i={}}=e,{audioMixUserList:u=[],videoLayoutList:d=[]}=i,c=d.map(m=>({userId:m.fixedVideoUser.userId,roomId:this.getStringRoomId(m.fixedVideoUser.roomId,m.fixedVideoUser.strRoomId)||this._core.room.roomId,width:m.width||0,height:m.height||0,locationX:m.locationX||0,locationY:m.locationY||0,zOrder:m.zOrder||1,streamType:m.fixedVideoStreamType==="sub"?1:0,inputType:V.IT_PURE_VIDEO,renderMode:m.fillMode||0}));return u.forEach(m=>{let p=c.findIndex(b=>b.userId===m.userId&&b.roomId===this.getStringRoomId(m.roomId,m.strRoomId));p!==-1?c[p].inputType=V.IT_AUDIO_VIDEO:c.push({userId:m.userId,roomId:m.roomId||m.strRoomId,inputType:V.IT_PURE_AUDIO})}),c}getOutputParam(e){let i=e.target.streamId||"",{encoding:u={},mix:d={}}=e;return{streamId:i,streamType:i.length>0?1:0,width:this._core.utils.isUndefined(u.videoWidth)?640:u.videoWidth,height:this._core.utils.isUndefined(u.videoHeight)?480:u.videoHeight,videoBps:u.videoBitrate||0,fps:u.videoFramerate||15,gop:u.videoGOP||2,audioSampleRate:u.audioSampleRate||48e3,audioBps:u.audioBitrate||64,audioChannels:u.audioChannels||1,backgroundColor:d.backgroundColor||0,backgroundImg:d.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var H=Y(J(),1);var x=class{constructor(e,i){S(this,"_room");S(this,"_core");S(this,"_log");S(this,"_paramsForTencentCDN");S(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=i,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])}installEvents(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}async handlePublished({track:e}){var d;this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(d=e==null?void 0:e.room)==null?void 0:d.roomId}`);let i=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",u=this._paramsForTencentCDN.get(i)||null;u!=null&&u.target&&u.isStarted&&await this.startPublishTencentCDN(u.target)}async handleRoomLeft(){this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1})}isStreamPublished(e){return e==="publish-main-stream-to-cdn"&&!this._room.isMainStreamPublished?(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1):e==="publish-sub-stream-to-cdn"&&!this._room.isAuxStreamPublished?(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):!0}changeDataStatus(e,i){let u=this._paramsForTencentCDN.get(e),d=I(I({},u),i);this._paramsForTencentCDN.set(e,d)}async startPublishTencentCDN(e){if(this._log.info(`[CDNStreaming] startPublishTencentCDN ${JSON.stringify(e)}`),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),!this.isStreamPublished(e.publishMode))return;let i=e.streamId||"",u=this.generatePublishCDNStreamId(i,e.publishMode),d=this.generatePublishCDNSessionId(e.publishMode),c=e.publishMode==="publish-sub-stream-to-cdn"?1:0,m={requestTime:Date.now(),sessionId:d,streamId:u,streamType:c};await this.doStartPublishTencentCDN(m,e.publishMode);let{appId:p,bizId:b,url:_}=e;if(p&&b&&_){let T=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;T!=null&&T.givenCDNManager||(T.givenCDNManager=new M(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,T)),await T.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:b,url:_,streamId:u})}}async doStartPublishTencentCDN(e,i){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let u=6,d=500,c=0;for(;;){let m=await this._room.sendStartPublishCDN(e,!0),{code:p}=m.data,{message:b}=m.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(i,{isPublished:!0});break}else if(p===-10006&&c<u)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${c+1}/6, reason: ${b}`),c+=1,await new Promise(_=>setTimeout(_,d));else throw this.changeDataStatus(i,{isPublished:!1}),p===-102083&&(b=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let i=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(i.isPublished){let{target:u}=i;u!=null&&u.bizId&&u.appId&&u.url&&(i!=null&&i.givenCDNManager)&&await(i==null?void 0:i.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let i={requestTime:Date.now(),sessionId:(0,H.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(i)}`);let u=await this._room.sendStopPublishCDN(i,!0),{code:d}=u.data,{message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw d===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),c=`can not stop in auto relayed-push mode ${c}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,i){if(e===""){let u=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(i)}`;return/^[A-Za-z\d_-]*$/.test(u)||(u=(0,H.default)(u)),`${this._room.sdkAppId}_${u}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,H.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var ee=l=>typeof l=="string";var P;function Ce(l,e,i,u){if(!/^[A-Za-z\d_-]*$/.test(l)){let{RtcError:c,ErrorCode:m,ErrorCodeDictionary:p}=P;throw new c({code:m.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function De(l,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:m}=P;if(ee(l))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_INTEGER_STRING,fnName:i,messageParams:{key:"roomId"}});if(l===void 0)return;if(!(/^[1-9]\d*$/.test(String(l))&&l<4294967295))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_INTEGER,fnName:i,messageParams:{key:"roomId"}})}function Te(l,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:m}=P;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(l))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_STRING,fnName:i,messageParams:{key:"strRoomId"}})}var N={type:"number",notLessThanZero:!0},te={type:"object",required:!0,properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:De},strRoomId:{type:"string",validate:Te}}},re={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]},streamId:{required:!1,type:"string",validate:Ce},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1}}},ie={required:!1,type:"object",properties:{videoWidth:N,videoHeight:N,videoBitrate:j(I({},N),{allowEmpty:!1}),videoFramerate:{type:"number",validate(l,e,i,u){if(l<=0||l>30){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(l,e,i,u){if(l<1||l>8){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:N,audioBitrate:{type:"number",validate(l,e,i,u){if(l<32||l>192){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},oe={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:I({},te)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:I({},te),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(l,e,i,u){if(l<1||l>15){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:N,height:N,locationX:N,locationY:N}}}}};function ae(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},re),encoding:I({},ie),mix:I({},oe)},validate(e,i,u,d){var b,_;let{publishMode:c}=e.target,{encoding:m,mix:p}=e;if(c==="publish-mix-stream-to-cdn"){let{RtcError:T,ErrorCode:R,ErrorCodeDictionary:w}=l.errorModule;if(!m)throw new T({code:R.INVALID_PARAMETER,extraCode:w.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"encoding"}});if(!p)throw new T({code:R.INVALID_PARAMETER,extraCode:w.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let E=0,O=0,U=[];if(p.videoLayoutList.forEach((A,G)=>{U.push(A.fixedVideoUser.userId),A.width+A.locationX>E&&(E=A.width+A.locationX),A.height+A.locationY>O&&(O=A.height+A.locationY)}),U.indexOf(l.room.userId)<0)throw new T({code:R.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let K=(b=m==null?void 0:m.videoWidth)!=null?b:640,k=(_=m==null?void 0:m.videoHeight)!=null?_:480;if(K<E||k<O)throw new T({code:R.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function se(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},re),encoding:I({},ie),mix:I({},oe)}}}function ne(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:{required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]}}}}}}var v=0,$=class{constructor(e){this.core=e;S(this,"_mixTranscodeManager");S(this,"_publishCDNManager");S(this,"_core");S(this,"_modeOptions");S(this,"seq");S(this,"_log");v=v+1,this.seq=v,this._log=e.log.createChild({id:`${this.getAlias()}${v}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${v}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new L(e,this._log),this._publishCDNManager=new x(e,this._log)}getName(){return"CDNStreaming"}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return ae(this._core);case"update":return se(this._core);case"stop":return ne(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),await this.doStart(e)}async update(e){let i=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(i,e),await this.doStart(i)}async stop(e){switch(e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.stopMixTranscode();break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);break}}this._modeOptions.delete(e.target.publishMode)}async doStart(e){switch(this._log.info(`[CDNStreaming] doStart: ${JSON.stringify(e)}`),e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.startMixTranscode(e);break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.startPublishTencentCDN(e.target);break}}}};S($,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn"}});var rt=$;export{$ as CDNStreaming,y as PublishMode,X as TRTCStreamType,rt as default};
var ue=Object.create;var J=Object.defineProperty,de=Object.defineProperties,me=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,he=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var F=(l,e,i)=>e in l?J(l,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[e]=i,I=(l,e)=>{for(var i in e||(e={}))z.call(e,i)&&F(l,i,e[i]);if(W)for(var i of W(e))pe.call(e,i)&&F(l,i,e[i]);return l},j=(l,e)=>de(l,le(e));var ge=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var Se=(l,e,i,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of ce(e))!z.call(l,d)&&d!==i&&J(l,d,{get:()=>e[d],enumerable:!(u=me(e,d))||u.enumerable});return l};var Y=(l,e,i)=>(i=l!=null?ue(he(l)):{},Se(e||!l||!l.__esModule?J(i,"default",{value:l,enumerable:!0}):i,l));var S=(l,e,i)=>(F(l,typeof e!="symbol"?e+"":e,i),i);var q=ge((Z,B)=>{(function(l){"use strict";function e(t,h){var r=(t&65535)+(h&65535),g=(t>>16)+(h>>16)+(r>>16);return g<<16|r&65535}function i(t,h){return t<<h|t>>>32-h}function u(t,h,r,g,C,D){return e(i(e(e(h,t),e(g,D)),C),r)}function d(t,h,r,g,C,D,f){return u(h&r|~h&g,t,h,C,D,f)}function c(t,h,r,g,C,D,f){return u(h&g|r&~g,t,h,C,D,f)}function m(t,h,r,g,C,D,f){return u(h^r^g,t,h,C,D,f)}function p(t,h,r,g,C,D,f){return u(r^(h|~g),t,h,C,D,f)}function b(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var r,g,C,D,f,o=1732584193,a=-271733879,s=-1732584194,n=271733878;for(r=0;r<t.length;r+=16)g=o,C=a,D=s,f=n,o=d(o,a,s,n,t[r],7,-680876936),n=d(n,o,a,s,t[r+1],12,-389564586),s=d(s,n,o,a,t[r+2],17,606105819),a=d(a,s,n,o,t[r+3],22,-1044525330),o=d(o,a,s,n,t[r+4],7,-176418897),n=d(n,o,a,s,t[r+5],12,1200080426),s=d(s,n,o,a,t[r+6],17,-1473231341),a=d(a,s,n,o,t[r+7],22,-45705983),o=d(o,a,s,n,t[r+8],7,1770035416),n=d(n,o,a,s,t[r+9],12,-1958414417),s=d(s,n,o,a,t[r+10],17,-42063),a=d(a,s,n,o,t[r+11],22,-1990404162),o=d(o,a,s,n,t[r+12],7,1804603682),n=d(n,o,a,s,t[r+13],12,-40341101),s=d(s,n,o,a,t[r+14],17,-1502002290),a=d(a,s,n,o,t[r+15],22,1236535329),o=c(o,a,s,n,t[r+1],5,-165796510),n=c(n,o,a,s,t[r+6],9,-1069501632),s=c(s,n,o,a,t[r+11],14,643717713),a=c(a,s,n,o,t[r],20,-373897302),o=c(o,a,s,n,t[r+5],5,-701558691),n=c(n,o,a,s,t[r+10],9,38016083),s=c(s,n,o,a,t[r+15],14,-660478335),a=c(a,s,n,o,t[r+4],20,-405537848),o=c(o,a,s,n,t[r+9],5,568446438),n=c(n,o,a,s,t[r+14],9,-1019803690),s=c(s,n,o,a,t[r+3],14,-187363961),a=c(a,s,n,o,t[r+8],20,1163531501),o=c(o,a,s,n,t[r+13],5,-1444681467),n=c(n,o,a,s,t[r+2],9,-51403784),s=c(s,n,o,a,t[r+7],14,1735328473),a=c(a,s,n,o,t[r+12],20,-1926607734),o=m(o,a,s,n,t[r+5],4,-378558),n=m(n,o,a,s,t[r+8],11,-2022574463),s=m(s,n,o,a,t[r+11],16,1839030562),a=m(a,s,n,o,t[r+14],23,-35309556),o=m(o,a,s,n,t[r+1],4,-1530992060),n=m(n,o,a,s,t[r+4],11,1272893353),s=m(s,n,o,a,t[r+7],16,-155497632),a=m(a,s,n,o,t[r+10],23,-1094730640),o=m(o,a,s,n,t[r+13],4,681279174),n=m(n,o,a,s,t[r],11,-358537222),s=m(s,n,o,a,t[r+3],16,-722521979),a=m(a,s,n,o,t[r+6],23,76029189),o=m(o,a,s,n,t[r+9],4,-640364487),n=m(n,o,a,s,t[r+12],11,-421815835),s=m(s,n,o,a,t[r+15],16,530742520),a=m(a,s,n,o,t[r+2],23,-995338651),o=p(o,a,s,n,t[r],6,-198630844),n=p(n,o,a,s,t[r+7],10,1126891415),s=p(s,n,o,a,t[r+14],15,-1416354905),a=p(a,s,n,o,t[r+5],21,-57434055),o=p(o,a,s,n,t[r+12],6,1700485571),n=p(n,o,a,s,t[r+3],10,-1894986606),s=p(s,n,o,a,t[r+10],15,-1051523),a=p(a,s,n,o,t[r+1],21,-2054922799),o=p(o,a,s,n,t[r+8],6,1873313359),n=p(n,o,a,s,t[r+15],10,-30611744),s=p(s,n,o,a,t[r+6],15,-1560198380),a=p(a,s,n,o,t[r+13],21,1309151649),o=p(o,a,s,n,t[r+4],6,-145523070),n=p(n,o,a,s,t[r+11],10,-1120210379),s=p(s,n,o,a,t[r+2],15,718787259),a=p(a,s,n,o,t[r+9],21,-343485551),o=e(o,g),a=e(a,C),s=e(s,D),n=e(n,f);return[o,a,s,n]}function _(t){var h,r="",g=t.length*32;for(h=0;h<g;h+=8)r+=String.fromCharCode(t[h>>5]>>>h%32&255);return r}function T(t){var h,r=[];for(r[(t.length>>2)-1]=void 0,h=0;h<r.length;h+=1)r[h]=0;var g=t.length*8;for(h=0;h<g;h+=8)r[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return r}function R(t){return _(b(T(t),t.length*8))}function w(t,h){var r,g=T(t),C=[],D=[],f;for(C[15]=D[15]=void 0,g.length>16&&(g=b(g,t.length*8)),r=0;r<16;r+=1)C[r]=g[r]^909522486,D[r]=g[r]^1549556828;return f=b(C.concat(T(h)),512+h.length*8),_(b(D.concat(f),512+128))}function E(t){var h="0123456789abcdef",r="",g,C;for(C=0;C<t.length;C+=1)g=t.charCodeAt(C),r+=h.charAt(g>>>4&15)+h.charAt(g&15);return r}function N(t){return unescape(encodeURIComponent(t))}function U(t){return R(N(t))}function K(t){return E(U(t))}function k(t,h){return w(N(t),N(h))}function A(t,h){return E(k(t,h))}function G(t,h,r){return h?r?k(h,t):A(h,t):r?U(t):K(t)}typeof define=="function"&&define.amd?define(function(){return G}):typeof B=="object"&&B.exports?B.exports=G:l.md5=G})(Z)});var Q=Y(q(),1);var y=(u=>(u.PublishMainStreamToCDN="publish-main-stream-to-cdn",u.PublishSubStreamToCDN="publish-sub-stream-to-cdn",u.PublishMixStreamToCDN="publish-mix-stream-to-cdn",u))(y||{}),X=(i=>(i.Main="main",i.Sub="sub",i))(X||{});var V={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var M=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_params");S(this,"_publishGivenCDNData",null);this._core=e,this._room=e.room,this._log=i}get isPublishingGivenCDN(){return!!this._params}async startPublishGivenCDN(e){if(this._log.info(`[CDNStreaming] startPublishGivenCDN() current: ${JSON.stringify(this._params)}, params: ${JSON.stringify(e)}`),this.isPublishingGivenCDN){let{appId:i,bizId:u,url:d}=this._params||{};if(i===e.appId&&u===e.bizId&&d===e.url)return;await this.stopPublishGivenCDN()}this._params=e,this._publishGivenCDNData={pushRequestTime:Date.now(),pushAppId:e.appId,pushBizId:e.bizId,pushCdnUrl:e.url,pushStreamType:this.convertStreamType(e==null?void 0:e.publishMode),pushStreamId:e.streamId};try{let i=await this._room.sendStartPublishCDN(this._publishGivenCDNData,!1),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: start given cdn.");else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${u} errMsg: ${d} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${u} errMsg: ${d}`)}catch(i){throw this.resetGivenCDN(),i}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this.isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c}=this._publishGivenCDNData,m={pushRequestTime:Date.now(),pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c},p=await this._room.sendStopPublishCDN(m,!1),{code:b,message:_}=p.data;if(b===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_} data: ${JSON.stringify(m)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._params=void 0}convertStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}};var L=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_config",null);S(this,"_data",null);S(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=i,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,i,u;return((e=this._config)==null?void 0:e.target.appId)&&((i=this._config)==null?void 0:i.target.bizId)&&((u=this._config)==null?void 0:u.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let i=this.getInputParam(e),u=this.getOutputParam(e),d=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&d!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:d,inputParam:i,outputParam:u});let{appId:c,bizId:m,url:p,streamId:b=""}=e.target;c&&m&&p&&(this._givenCDNManager||(this._givenCDNManager=new M(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:m,url:p,streamId:b}))}catch(i){throw this.reset(),i}}async doStartMixTranscode({outputSessionId:e,inputParam:i,outputParam:u}){let d={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:i,outputParam:u};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(d)}`);let c=await this._room.sendStartMixTranscode(d),{code:m}=c.data,{message:p}=c.data;if(m===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=d;else throw m===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${m} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${m} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let i=await this._room.sendStopMixTranscode(e),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`)}reset(){this._config=null,this._data=null,this.uninstallEvents()}installEvents(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}async handleRoomJoined(){this._log.info(`[CDNStreaming] handleJoined: ${JSON.stringify(this._config)}`),this.isStarted&&this._config&&await this.startMixTranscode(this._config)}async handleRoomLeft(){this._log.info(`[CDNStreaming] handleRoomLeft: ${JSON.stringify(this._config)}`),this._data=null}getOutputSessionId({config:e,userId:i,roomId:u}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,Q.default)(`${u}_${i}_main`)}getStringRoomId(e,i){return e?String(e):i}getInputParam(e){let{mix:i={}}=e,{audioMixUserList:u=[],videoLayoutList:d=[]}=i,c=d.map(m=>({userId:m.fixedVideoUser.userId,roomId:this.getStringRoomId(m.fixedVideoUser.roomId,m.fixedVideoUser.strRoomId)||this._core.room.roomId,width:m.width||0,height:m.height||0,locationX:m.locationX||0,locationY:m.locationY||0,zOrder:m.zOrder||1,streamType:m.fixedVideoStreamType==="sub"?1:0,inputType:V.IT_PURE_VIDEO,renderMode:m.fillMode||0}));return u.forEach(m=>{let p=c.findIndex(b=>b.userId===m.userId&&b.roomId===this.getStringRoomId(m.roomId,m.strRoomId));p!==-1?c[p].inputType=V.IT_AUDIO_VIDEO:c.push({userId:m.userId,roomId:m.roomId||m.strRoomId,inputType:V.IT_PURE_AUDIO})}),c}getOutputParam(e){let i=e.target.streamId||"",{encoding:u={},mix:d={}}=e;return{streamId:i,streamType:i.length>0?1:0,width:this._core.utils.isUndefined(u.videoWidth)?640:u.videoWidth,height:this._core.utils.isUndefined(u.videoHeight)?480:u.videoHeight,videoBps:u.videoBitrate||0,fps:u.videoFramerate||15,gop:u.videoGOP||2,audioSampleRate:u.audioSampleRate||48e3,audioBps:u.audioBitrate||64,audioChannels:u.audioChannels||1,backgroundColor:d.backgroundColor||0,backgroundImg:d.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var H=Y(q(),1);var x=class{constructor(e,i){S(this,"_room");S(this,"_core");S(this,"_log");S(this,"_paramsForTencentCDN");S(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=i,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])}installEvents(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}async handlePublished({track:e}){var d;if(e.room!==this._room||(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(d=e==null?void 0:e.room)==null?void 0:d.roomId}, ${this._room.isMainStreamPublished}`),e.mediaType===1))return;let i=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",u=this._paramsForTencentCDN.get(i)||null;u!=null&&u.target&&u.isStarted&&await this.startPublishTencentCDN(u.target)}async handleRoomLeft(){this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1})}isStreamPublished(e){return e==="publish-main-stream-to-cdn"&&!this._room.isMainStreamPublished?(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1):e==="publish-sub-stream-to-cdn"&&!this._room.isAuxStreamPublished?(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):!0}changeDataStatus(e,i){let u=this._paramsForTencentCDN.get(e),d=I(I({},u),i);this._paramsForTencentCDN.set(e,d)}async startPublishTencentCDN(e){if(this._log.info(`[CDNStreaming] startPublishTencentCDN ${JSON.stringify(e)}`),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),!this.isStreamPublished(e.publishMode))return;let i=e.streamId||"",u=this.generatePublishCDNStreamId(i,e.publishMode),d=this.generatePublishCDNSessionId(e.publishMode),c=e.publishMode==="publish-sub-stream-to-cdn"?1:0,m={requestTime:Date.now(),sessionId:d,streamId:u,streamType:c};await this.doStartPublishTencentCDN(m,e.publishMode);let{appId:p,bizId:b,url:_}=e;if(p&&b&&_){let T=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;T!=null&&T.givenCDNManager||(T.givenCDNManager=new M(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,T)),await T.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:b,url:_,streamId:u})}}async doStartPublishTencentCDN(e,i){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let u=6,d=500,c=0;for(;;){let m=await this._room.sendStartPublishCDN(e,!0),{code:p}=m.data,{message:b}=m.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(i,{isPublished:!0});break}else if(p===-10006&&c<u)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${c+1}/6, reason: ${b}`),c+=1,await new Promise(_=>setTimeout(_,d));else throw this.changeDataStatus(i,{isPublished:!1}),p===-102083&&(b=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let i=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(i.isPublished){let{target:u}=i;u!=null&&u.bizId&&u.appId&&u.url&&(i!=null&&i.givenCDNManager)&&await(i==null?void 0:i.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let i={requestTime:Date.now(),sessionId:(0,H.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(i)}`);let u=await this._room.sendStopPublishCDN(i,!0),{code:d}=u.data,{message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw d===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),c=`can not stop in auto relayed-push mode ${c}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,i){if(e===""){let u=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(i)}`;return/^[A-Za-z\d_-]*$/.test(u)||(u=(0,H.default)(u)),`${this._room.sdkAppId}_${u}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,H.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var ee=l=>typeof l=="string";var P;function Ce(l,e,i,u){if(!/^[A-Za-z\d_-]*$/.test(l)){let{RtcError:c,ErrorCode:m,ErrorCodeDictionary:p}=P;throw new c({code:m.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function De(l,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:m}=P;if(ee(l))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_INTEGER_STRING,fnName:i,messageParams:{key:"roomId"}});if(l===void 0)return;if(!(/^[1-9]\d*$/.test(String(l))&&l<4294967295))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_INTEGER,fnName:i,messageParams:{key:"roomId"}})}function Te(l,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:m}=P;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(l))throw new d({code:c.INVALID_PARAMETER,extraCode:m.INVALID_ROOM_ID_STRING,fnName:i,messageParams:{key:"strRoomId"}})}var O={type:"number",notLessThanZero:!0},te={type:"object",required:!0,properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:De},strRoomId:{type:"string",validate:Te}}},re={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]},streamId:{required:!1,type:"string",validate:Ce},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1}}},ie={required:!1,type:"object",properties:{videoWidth:O,videoHeight:O,videoBitrate:j(I({},O),{allowEmpty:!1}),videoFramerate:{type:"number",validate(l,e,i,u){if(l<=0||l>30){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(l,e,i,u){if(l<1||l>8){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:O,audioBitrate:{type:"number",validate(l,e,i,u){if(l<32||l>192){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},oe={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:I({},te)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:I({},te),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(l,e,i,u){if(l<1||l>15){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:O,height:O,locationX:O,locationY:O}}}}};function ae(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},re),encoding:I({},ie),mix:I({},oe)},validate(e,i,u,d){var b,_;let{publishMode:c}=e.target,{encoding:m,mix:p}=e;if(c==="publish-mix-stream-to-cdn"){let{RtcError:T,ErrorCode:R,ErrorCodeDictionary:w}=l.errorModule;if(!m)throw new T({code:R.INVALID_PARAMETER,extraCode:w.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"encoding"}});if(!p)throw new T({code:R.INVALID_PARAMETER,extraCode:w.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let E=0,N=0,U=[];if(p.videoLayoutList.forEach((A,G)=>{U.push(A.fixedVideoUser.userId),A.width+A.locationX>E&&(E=A.width+A.locationX),A.height+A.locationY>N&&(N=A.height+A.locationY)}),U.indexOf(l.room.userId)<0)throw new T({code:R.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let K=(b=m==null?void 0:m.videoWidth)!=null?b:640,k=(_=m==null?void 0:m.videoHeight)!=null?_:480;if(K<E||k<N)throw new T({code:R.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function se(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},re),encoding:I({},ie),mix:I({},oe)}}}function ne(l){return P=l.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:{required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]}}}}}}var v=0,$=class{constructor(e){this.core=e;S(this,"_mixTranscodeManager");S(this,"_publishCDNManager");S(this,"_core");S(this,"_modeOptions");S(this,"seq");S(this,"_log");v=v+1,this.seq=v,this._log=e.log.createChild({id:`${this.getAlias()}${v}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${v}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new L(e,this._log),this._publishCDNManager=new x(e,this._log)}getName(){return"CDNStreaming"}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return ae(this._core);case"update":return se(this._core);case"stop":return ne(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),await this.doStart(e)}async update(e){let i=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(i,e),await this.doStart(i)}async stop(e){switch(e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.stopMixTranscode();break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);break}}this._modeOptions.delete(e.target.publishMode)}async doStart(e){switch(this._log.info(`[CDNStreaming] doStart: ${JSON.stringify(e)}`),e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.startMixTranscode(e);break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.startPublishTencentCDN(e.target);break}}}};S($,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn"}});var it=$;export{$ as CDNStreaming,y as PublishMode,X as TRTCStreamType,it as default};

@@ -1,1 +0,1 @@

"use strict";var CDNStreaming=(()=>{var de=Object.create;var L=Object.defineProperty,me=Object.defineProperties,le=Object.getOwnPropertyDescriptor,ce=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,pe=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var J=(m,e,i)=>e in m?L(m,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):m[e]=i,I=(m,e)=>{for(var i in e||(e={}))z.call(e,i)&&J(m,i,e[i]);if(W)for(var i of W(e))ge.call(e,i)&&J(m,i,e[i]);return m},j=(m,e)=>me(m,ce(e));var Se=(m,e)=>()=>(e||m((e={exports:{}}).exports,e),e.exports),be=(m,e)=>{for(var i in e)L(m,i,{get:e[i],enumerable:!0})},Y=(m,e,i,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of he(e))!z.call(m,d)&&d!==i&&L(m,d,{get:()=>e[d],enumerable:!(u=le(e,d))||u.enumerable});return m};var Z=(m,e,i)=>(i=m!=null?de(pe(m)):{},Y(e||!m||!m.__esModule?L(i,"default",{value:m,enumerable:!0}):i,m)),Ce=m=>Y(L({},"__esModule",{value:!0}),m);var S=(m,e,i)=>(J(m,typeof e!="symbol"?e+"":e,i),i);var X=Se((Q,H)=>{(function(m){"use strict";function e(t,h){var r=(t&65535)+(h&65535),g=(t>>16)+(h>>16)+(r>>16);return g<<16|r&65535}function i(t,h){return t<<h|t>>>32-h}function u(t,h,r,g,C,D){return e(i(e(e(h,t),e(g,D)),C),r)}function d(t,h,r,g,C,D,f){return u(h&r|~h&g,t,h,C,D,f)}function c(t,h,r,g,C,D,f){return u(h&g|r&~g,t,h,C,D,f)}function l(t,h,r,g,C,D,f){return u(h^r^g,t,h,C,D,f)}function p(t,h,r,g,C,D,f){return u(r^(h|~g),t,h,C,D,f)}function b(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var r,g,C,D,f,o=1732584193,a=-271733879,s=-1732584194,n=271733878;for(r=0;r<t.length;r+=16)g=o,C=a,D=s,f=n,o=d(o,a,s,n,t[r],7,-680876936),n=d(n,o,a,s,t[r+1],12,-389564586),s=d(s,n,o,a,t[r+2],17,606105819),a=d(a,s,n,o,t[r+3],22,-1044525330),o=d(o,a,s,n,t[r+4],7,-176418897),n=d(n,o,a,s,t[r+5],12,1200080426),s=d(s,n,o,a,t[r+6],17,-1473231341),a=d(a,s,n,o,t[r+7],22,-45705983),o=d(o,a,s,n,t[r+8],7,1770035416),n=d(n,o,a,s,t[r+9],12,-1958414417),s=d(s,n,o,a,t[r+10],17,-42063),a=d(a,s,n,o,t[r+11],22,-1990404162),o=d(o,a,s,n,t[r+12],7,1804603682),n=d(n,o,a,s,t[r+13],12,-40341101),s=d(s,n,o,a,t[r+14],17,-1502002290),a=d(a,s,n,o,t[r+15],22,1236535329),o=c(o,a,s,n,t[r+1],5,-165796510),n=c(n,o,a,s,t[r+6],9,-1069501632),s=c(s,n,o,a,t[r+11],14,643717713),a=c(a,s,n,o,t[r],20,-373897302),o=c(o,a,s,n,t[r+5],5,-701558691),n=c(n,o,a,s,t[r+10],9,38016083),s=c(s,n,o,a,t[r+15],14,-660478335),a=c(a,s,n,o,t[r+4],20,-405537848),o=c(o,a,s,n,t[r+9],5,568446438),n=c(n,o,a,s,t[r+14],9,-1019803690),s=c(s,n,o,a,t[r+3],14,-187363961),a=c(a,s,n,o,t[r+8],20,1163531501),o=c(o,a,s,n,t[r+13],5,-1444681467),n=c(n,o,a,s,t[r+2],9,-51403784),s=c(s,n,o,a,t[r+7],14,1735328473),a=c(a,s,n,o,t[r+12],20,-1926607734),o=l(o,a,s,n,t[r+5],4,-378558),n=l(n,o,a,s,t[r+8],11,-2022574463),s=l(s,n,o,a,t[r+11],16,1839030562),a=l(a,s,n,o,t[r+14],23,-35309556),o=l(o,a,s,n,t[r+1],4,-1530992060),n=l(n,o,a,s,t[r+4],11,1272893353),s=l(s,n,o,a,t[r+7],16,-155497632),a=l(a,s,n,o,t[r+10],23,-1094730640),o=l(o,a,s,n,t[r+13],4,681279174),n=l(n,o,a,s,t[r],11,-358537222),s=l(s,n,o,a,t[r+3],16,-722521979),a=l(a,s,n,o,t[r+6],23,76029189),o=l(o,a,s,n,t[r+9],4,-640364487),n=l(n,o,a,s,t[r+12],11,-421815835),s=l(s,n,o,a,t[r+15],16,530742520),a=l(a,s,n,o,t[r+2],23,-995338651),o=p(o,a,s,n,t[r],6,-198630844),n=p(n,o,a,s,t[r+7],10,1126891415),s=p(s,n,o,a,t[r+14],15,-1416354905),a=p(a,s,n,o,t[r+5],21,-57434055),o=p(o,a,s,n,t[r+12],6,1700485571),n=p(n,o,a,s,t[r+3],10,-1894986606),s=p(s,n,o,a,t[r+10],15,-1051523),a=p(a,s,n,o,t[r+1],21,-2054922799),o=p(o,a,s,n,t[r+8],6,1873313359),n=p(n,o,a,s,t[r+15],10,-30611744),s=p(s,n,o,a,t[r+6],15,-1560198380),a=p(a,s,n,o,t[r+13],21,1309151649),o=p(o,a,s,n,t[r+4],6,-145523070),n=p(n,o,a,s,t[r+11],10,-1120210379),s=p(s,n,o,a,t[r+2],15,718787259),a=p(a,s,n,o,t[r+9],21,-343485551),o=e(o,g),a=e(a,C),s=e(s,D),n=e(n,f);return[o,a,s,n]}function _(t){var h,r="",g=t.length*32;for(h=0;h<g;h+=8)r+=String.fromCharCode(t[h>>5]>>>h%32&255);return r}function T(t){var h,r=[];for(r[(t.length>>2)-1]=void 0,h=0;h<r.length;h+=1)r[h]=0;var g=t.length*8;for(h=0;h<g;h+=8)r[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return r}function E(t){return _(b(T(t),t.length*8))}function G(t,h){var r,g=T(t),C=[],D=[],f;for(C[15]=D[15]=void 0,g.length>16&&(g=b(g,t.length*8)),r=0;r<16;r+=1)C[r]=g[r]^909522486,D[r]=g[r]^1549556828;return f=b(C.concat(T(h)),512+h.length*8),_(b(D.concat(f),512+128))}function y(t){var h="0123456789abcdef",r="",g,C;for(C=0;C<t.length;C+=1)g=t.charCodeAt(C),r+=h.charAt(g>>>4&15)+h.charAt(g&15);return r}function O(t){return unescape(encodeURIComponent(t))}function U(t){return E(O(t))}function q(t){return y(U(t))}function B(t,h){return G(O(t),O(h))}function A(t,h){return y(B(t,h))}function V(t,h,r){return h?r?B(h,t):A(h,t):r?U(t):q(t)}typeof define=="function"&&define.amd?define(function(){return V}):typeof H=="object"&&H.exports?H.exports=V:m.md5=V})(Q)});var Ae={};be(Ae,{CDNStreaming:()=>k,PublishMode:()=>M,TRTCStreamType:()=>$,default:()=>Ie});var ee=Z(X(),1);var M=(u=>(u.PublishMainStreamToCDN="publish-main-stream-to-cdn",u.PublishSubStreamToCDN="publish-sub-stream-to-cdn",u.PublishMixStreamToCDN="publish-mix-stream-to-cdn",u))(M||{}),$=(i=>(i.Main="main",i.Sub="sub",i))($||{});var K={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var R=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_paramsForGivenCDN");S(this,"_publishGivenCDNData",null);S(this,"_isPublishingGivenCDN",!1);this._core=e,this._room=e.room,this._log=i,this._paramsForGivenCDN=new Map([["publish-main-stream-to-cdn",null],["publish-sub-stream-to-cdn",null],["publish-mix-stream-to-cdn",null]])}async startPublishGivenCDN(e){this._log.info(`[CDNStreaming] startPublishGivenCDN() ${JSON.stringify(e)}`),this._paramsForGivenCDN.set(e.publishMode,e);let i={pushRequestTime:Date.now(),pushAppId:e.appId,pushBizId:e.bizId,pushCdnUrl:e.url,pushStreamType:this.convertStreamType(e==null?void 0:e.publishMode),pushStreamId:e.streamId};this._publishGivenCDNData=i;try{this._isPublishingGivenCDN&&await this.stopPublishGivenCDN();let u=await this._room.sendStartPublishCDN(i,!1),{code:d,message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: start given cdn."),this._isPublishingGivenCDN=!0;else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${d} errMsg: ${c} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${d} errMsg: ${c}`)}catch(u){throw this.resetGivenCDN(),u}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this._isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c}=this._publishGivenCDNData,l={pushRequestTime:Date.now(),pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c},p=await this._room.sendStopPublishCDN(l,!1),{code:b,message:_}=p.data;if(b===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_} data: ${JSON.stringify(l)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._isPublishingGivenCDN=!1}convertStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}};var x=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_config",null);S(this,"_data",null);S(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=i,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,i,u;return((e=this._config)==null?void 0:e.target.appId)&&((i=this._config)==null?void 0:i.target.bizId)&&((u=this._config)==null?void 0:u.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let i=this.getInputParam(e),u=this.getOutputParam(e),d=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&d!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:d,inputParam:i,outputParam:u});let{appId:c,bizId:l,url:p,streamId:b=""}=this._config.target;c&&l&&p&&(this._givenCDNManager||(this._givenCDNManager=new R(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:l,url:p,streamId:b}))}catch(i){throw this.reset(),i}}async doStartMixTranscode({outputSessionId:e,inputParam:i,outputParam:u}){let d={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:i,outputParam:u};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(d)}`);let c=await this._room.sendStartMixTranscode(d),{code:l}=c.data,{message:p}=c.data;if(l===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=d;else throw l===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${l} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${l} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let i=await this._room.sendStopMixTranscode(e),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`)}reset(){this._config=null,this._data=null,this.uninstallEvents()}installEvents(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}async handleRoomJoined(){this._log.info(`[CDNStreaming] handleJoined: ${JSON.stringify(this._config)}`),this.isStarted&&this._config&&await this.startMixTranscode(this._config)}async handleRoomLeft(){this._log.info(`[CDNStreaming] handleRoomLeft: ${JSON.stringify(this._config)}`),this._data=null}getOutputSessionId({config:e,userId:i,roomId:u}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,ee.default)(`${u}_${i}_main`)}getStringRoomId(e,i){return e?String(e):i}getInputParam(e){let{mix:i={}}=e,{audioMixUserList:u=[],videoLayoutList:d=[]}=i,c=d.map(l=>({userId:l.fixedVideoUser.userId,roomId:this.getStringRoomId(l.fixedVideoUser.roomId,l.fixedVideoUser.strRoomId)||this._core.room.roomId,width:l.width||0,height:l.height||0,locationX:l.locationX||0,locationY:l.locationY||0,zOrder:l.zOrder||1,streamType:l.fixedVideoStreamType==="sub"?1:0,inputType:K.IT_PURE_VIDEO,renderMode:l.fillMode||0}));return u.forEach(l=>{let p=c.findIndex(b=>b.userId===l.userId&&b.roomId===this.getStringRoomId(l.roomId,l.strRoomId));p!==-1?c[p].inputType=K.IT_AUDIO_VIDEO:c.push({userId:l.userId,roomId:l.roomId||l.strRoomId,inputType:K.IT_PURE_AUDIO})}),c}getOutputParam(e){let i=e.target.streamId||"",{encoding:u={},mix:d={}}=e;return{streamId:i,streamType:i.length>0?1:0,width:this._core.utils.isUndefined(u.videoWidth)?640:u.videoWidth,height:this._core.utils.isUndefined(u.videoHeight)?480:u.videoHeight,videoBps:u.videoBitrate||0,fps:u.videoFramerate||15,gop:u.videoGOP||2,audioSampleRate:u.audioSampleRate||48e3,audioBps:u.audioBitrate||64,audioChannels:u.audioChannels||1,backgroundColor:d.backgroundColor||0,backgroundImg:d.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var F=Z(X(),1);var v=class{constructor(e,i){S(this,"_room");S(this,"_core");S(this,"_log");S(this,"_paramsForTencentCDN");S(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=i,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])}installEvents(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}async handlePublished({track:e}){var d;this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(d=e==null?void 0:e.room)==null?void 0:d.roomId}`);let i=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",u=this._paramsForTencentCDN.get(i)||null;u!=null&&u.target&&u.isStarted&&await this.startPublishTencentCDN(u.target)}async handleRoomLeft(){this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1})}isStreamPublished(e){return e==="publish-main-stream-to-cdn"&&!this._room.isMainStreamPublished?(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1):e==="publish-sub-stream-to-cdn"&&!this._room.isAuxStreamPublished?(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):!0}changeDataStatus(e,i){let u=this._paramsForTencentCDN.get(e),d=I(I({},u),i);this._paramsForTencentCDN.set(e,d)}async startPublishTencentCDN(e){if(this._log.info(`[CDNStreaming] startPublishTencentCDN ${JSON.stringify(e)}`),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),!this.isStreamPublished(e.publishMode))return;let i=e.streamId||"",u=this.generatePublishCDNStreamId(i,e.publishMode),d=this.generatePublishCDNSessionId(e.publishMode),c=e.publishMode==="publish-sub-stream-to-cdn"?1:0,l={requestTime:Date.now(),sessionId:d,streamId:u,streamType:c};await this.doStartPublishTencentCDN(l,e.publishMode);let{appId:p,bizId:b,url:_}=e;if(p&&b&&_){let T=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;T!=null&&T.givenCDNManager||(T.givenCDNManager=new R(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,T)),await T.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:b,url:_,streamId:u})}}async doStartPublishTencentCDN(e,i){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let u=6,d=500,c=0;for(;;){let l=await this._room.sendStartPublishCDN(e,!0),{code:p}=l.data,{message:b}=l.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(i,{isPublished:!0});break}else if(p===-10006&&c<u)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${c+1}/6, reason: ${b}`),c+=1,await new Promise(_=>setTimeout(_,d));else throw this.changeDataStatus(i,{isPublished:!1}),p===-102083&&(b=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let i=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(i.isPublished){let{target:u}=i;u!=null&&u.bizId&&u.appId&&u.url&&(i!=null&&i.givenCDNManager)&&await(i==null?void 0:i.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let i={requestTime:Date.now(),sessionId:(0,F.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(i)}`);let u=await this._room.sendStopPublishCDN(i,!0),{code:d}=u.data,{message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw d===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),c=`can not stop in auto relayed-push mode ${c}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,i){if(e===""){let u=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(i)}`;return/^[A-Za-z\d_-]*$/.test(u)||(u=(0,F.default)(u)),`${this._room.sdkAppId}_${u}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,F.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var te=m=>typeof m=="string";var P;function Te(m,e,i,u){if(!/^[A-Za-z\d_-]*$/.test(m)){let{RtcError:c,ErrorCode:l,ErrorCodeDictionary:p}=P;throw new c({code:l.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function _e(m,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:l}=P;if(te(m))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_INTEGER_STRING,fnName:i,messageParams:{key:"roomId"}});if(m===void 0)return;if(!(/^[1-9]\d*$/.test(String(m))&&m<4294967295))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_INTEGER,fnName:i,messageParams:{key:"roomId"}})}function fe(m,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:l}=P;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(m))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_STRING,fnName:i,messageParams:{key:"strRoomId"}})}var N={type:"number",notLessThanZero:!0},re={type:"object",required:!0,properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:_e},strRoomId:{type:"string",validate:fe}}},ie={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]},streamId:{required:!1,type:"string",validate:Te},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1}}},oe={required:!1,type:"object",properties:{videoWidth:N,videoHeight:N,videoBitrate:j(I({},N),{allowEmpty:!1}),videoFramerate:{type:"number",validate(m,e,i,u){if(m<=0||m>30){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(m,e,i,u){if(m<1||m>8){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:N,audioBitrate:{type:"number",validate(m,e,i,u){if(m<32||m>192){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},ae={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:I({},re)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:I({},re),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(m,e,i,u){if(m<1||m>15){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:N,height:N,locationX:N,locationY:N}}}}};function se(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},ie),encoding:I({},oe),mix:I({},ae)},validate(e,i,u,d){var b,_;let{publishMode:c}=e.target,{encoding:l,mix:p}=e;if(c==="publish-mix-stream-to-cdn"){let{RtcError:T,ErrorCode:E,ErrorCodeDictionary:G}=m.errorModule;if(!l)throw new T({code:E.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"encoding"}});if(!p)throw new T({code:E.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let y=0,O=0,U=[];if(p.videoLayoutList.forEach((A,V)=>{U.push(A.fixedVideoUser.userId),A.width+A.locationX>y&&(y=A.width+A.locationX),A.height+A.locationY>O&&(O=A.height+A.locationY)}),U.indexOf(m.room.userId)<0)throw new T({code:E.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let q=(b=l==null?void 0:l.videoWidth)!=null?b:640,B=(_=l==null?void 0:l.videoHeight)!=null?_:480;if(q<y||B<O)throw new T({code:E.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function ne(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},ie),encoding:I({},oe),mix:I({},ae)}}}function ue(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:{required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]}}}}}}var w=0,k=class{constructor(e){this.core=e;S(this,"_mixTranscodeManager");S(this,"_publishCDNManager");S(this,"_core");S(this,"_modeOptions");S(this,"seq");S(this,"_log");w=w+1,this.seq=w,this._log=e.log.createChild({id:`${this.getAlias()}${w}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${w}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new x(e,this._log),this._publishCDNManager=new v(e,this._log)}getName(){return"CDNStreaming"}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return se(this._core);case"update":return ne(this._core);case"stop":return ue(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),await this.doStart(e)}async update(e){let i=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(i,e),await this.doStart(i)}async stop(e){switch(e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.stopMixTranscode();break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);break}}this._modeOptions.delete(e.target.publishMode)}async doStart(e){switch(this._log.info(`[CDNStreaming] doStart: ${JSON.stringify(e)}`),e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.startMixTranscode(e);break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.startPublishTencentCDN(e.target);break}}}};S(k,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn"}});var Ie=k;return Ce(Ae);})().default;
"use strict";var CDNStreaming=(()=>{var de=Object.create;var L=Object.defineProperty,me=Object.defineProperties,le=Object.getOwnPropertyDescriptor,ce=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,pe=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var q=(m,e,i)=>e in m?L(m,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):m[e]=i,I=(m,e)=>{for(var i in e||(e={}))z.call(e,i)&&q(m,i,e[i]);if(W)for(var i of W(e))ge.call(e,i)&&q(m,i,e[i]);return m},j=(m,e)=>me(m,ce(e));var Se=(m,e)=>()=>(e||m((e={exports:{}}).exports,e),e.exports),be=(m,e)=>{for(var i in e)L(m,i,{get:e[i],enumerable:!0})},Y=(m,e,i,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of he(e))!z.call(m,d)&&d!==i&&L(m,d,{get:()=>e[d],enumerable:!(u=le(e,d))||u.enumerable});return m};var Z=(m,e,i)=>(i=m!=null?de(pe(m)):{},Y(e||!m||!m.__esModule?L(i,"default",{value:m,enumerable:!0}):i,m)),Ce=m=>Y(L({},"__esModule",{value:!0}),m);var S=(m,e,i)=>(q(m,typeof e!="symbol"?e+"":e,i),i);var X=Se((Q,H)=>{(function(m){"use strict";function e(t,h){var r=(t&65535)+(h&65535),g=(t>>16)+(h>>16)+(r>>16);return g<<16|r&65535}function i(t,h){return t<<h|t>>>32-h}function u(t,h,r,g,C,D){return e(i(e(e(h,t),e(g,D)),C),r)}function d(t,h,r,g,C,D,f){return u(h&r|~h&g,t,h,C,D,f)}function c(t,h,r,g,C,D,f){return u(h&g|r&~g,t,h,C,D,f)}function l(t,h,r,g,C,D,f){return u(h^r^g,t,h,C,D,f)}function p(t,h,r,g,C,D,f){return u(r^(h|~g),t,h,C,D,f)}function b(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var r,g,C,D,f,o=1732584193,a=-271733879,s=-1732584194,n=271733878;for(r=0;r<t.length;r+=16)g=o,C=a,D=s,f=n,o=d(o,a,s,n,t[r],7,-680876936),n=d(n,o,a,s,t[r+1],12,-389564586),s=d(s,n,o,a,t[r+2],17,606105819),a=d(a,s,n,o,t[r+3],22,-1044525330),o=d(o,a,s,n,t[r+4],7,-176418897),n=d(n,o,a,s,t[r+5],12,1200080426),s=d(s,n,o,a,t[r+6],17,-1473231341),a=d(a,s,n,o,t[r+7],22,-45705983),o=d(o,a,s,n,t[r+8],7,1770035416),n=d(n,o,a,s,t[r+9],12,-1958414417),s=d(s,n,o,a,t[r+10],17,-42063),a=d(a,s,n,o,t[r+11],22,-1990404162),o=d(o,a,s,n,t[r+12],7,1804603682),n=d(n,o,a,s,t[r+13],12,-40341101),s=d(s,n,o,a,t[r+14],17,-1502002290),a=d(a,s,n,o,t[r+15],22,1236535329),o=c(o,a,s,n,t[r+1],5,-165796510),n=c(n,o,a,s,t[r+6],9,-1069501632),s=c(s,n,o,a,t[r+11],14,643717713),a=c(a,s,n,o,t[r],20,-373897302),o=c(o,a,s,n,t[r+5],5,-701558691),n=c(n,o,a,s,t[r+10],9,38016083),s=c(s,n,o,a,t[r+15],14,-660478335),a=c(a,s,n,o,t[r+4],20,-405537848),o=c(o,a,s,n,t[r+9],5,568446438),n=c(n,o,a,s,t[r+14],9,-1019803690),s=c(s,n,o,a,t[r+3],14,-187363961),a=c(a,s,n,o,t[r+8],20,1163531501),o=c(o,a,s,n,t[r+13],5,-1444681467),n=c(n,o,a,s,t[r+2],9,-51403784),s=c(s,n,o,a,t[r+7],14,1735328473),a=c(a,s,n,o,t[r+12],20,-1926607734),o=l(o,a,s,n,t[r+5],4,-378558),n=l(n,o,a,s,t[r+8],11,-2022574463),s=l(s,n,o,a,t[r+11],16,1839030562),a=l(a,s,n,o,t[r+14],23,-35309556),o=l(o,a,s,n,t[r+1],4,-1530992060),n=l(n,o,a,s,t[r+4],11,1272893353),s=l(s,n,o,a,t[r+7],16,-155497632),a=l(a,s,n,o,t[r+10],23,-1094730640),o=l(o,a,s,n,t[r+13],4,681279174),n=l(n,o,a,s,t[r],11,-358537222),s=l(s,n,o,a,t[r+3],16,-722521979),a=l(a,s,n,o,t[r+6],23,76029189),o=l(o,a,s,n,t[r+9],4,-640364487),n=l(n,o,a,s,t[r+12],11,-421815835),s=l(s,n,o,a,t[r+15],16,530742520),a=l(a,s,n,o,t[r+2],23,-995338651),o=p(o,a,s,n,t[r],6,-198630844),n=p(n,o,a,s,t[r+7],10,1126891415),s=p(s,n,o,a,t[r+14],15,-1416354905),a=p(a,s,n,o,t[r+5],21,-57434055),o=p(o,a,s,n,t[r+12],6,1700485571),n=p(n,o,a,s,t[r+3],10,-1894986606),s=p(s,n,o,a,t[r+10],15,-1051523),a=p(a,s,n,o,t[r+1],21,-2054922799),o=p(o,a,s,n,t[r+8],6,1873313359),n=p(n,o,a,s,t[r+15],10,-30611744),s=p(s,n,o,a,t[r+6],15,-1560198380),a=p(a,s,n,o,t[r+13],21,1309151649),o=p(o,a,s,n,t[r+4],6,-145523070),n=p(n,o,a,s,t[r+11],10,-1120210379),s=p(s,n,o,a,t[r+2],15,718787259),a=p(a,s,n,o,t[r+9],21,-343485551),o=e(o,g),a=e(a,C),s=e(s,D),n=e(n,f);return[o,a,s,n]}function _(t){var h,r="",g=t.length*32;for(h=0;h<g;h+=8)r+=String.fromCharCode(t[h>>5]>>>h%32&255);return r}function T(t){var h,r=[];for(r[(t.length>>2)-1]=void 0,h=0;h<r.length;h+=1)r[h]=0;var g=t.length*8;for(h=0;h<g;h+=8)r[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return r}function E(t){return _(b(T(t),t.length*8))}function G(t,h){var r,g=T(t),C=[],D=[],f;for(C[15]=D[15]=void 0,g.length>16&&(g=b(g,t.length*8)),r=0;r<16;r+=1)C[r]=g[r]^909522486,D[r]=g[r]^1549556828;return f=b(C.concat(T(h)),512+h.length*8),_(b(D.concat(f),512+128))}function y(t){var h="0123456789abcdef",r="",g,C;for(C=0;C<t.length;C+=1)g=t.charCodeAt(C),r+=h.charAt(g>>>4&15)+h.charAt(g&15);return r}function N(t){return unescape(encodeURIComponent(t))}function U(t){return E(N(t))}function J(t){return y(U(t))}function B(t,h){return G(N(t),N(h))}function A(t,h){return y(B(t,h))}function V(t,h,r){return h?r?B(h,t):A(h,t):r?U(t):J(t)}typeof define=="function"&&define.amd?define(function(){return V}):typeof H=="object"&&H.exports?H.exports=V:m.md5=V})(Q)});var Ae={};be(Ae,{CDNStreaming:()=>k,PublishMode:()=>M,TRTCStreamType:()=>$,default:()=>Ie});var ee=Z(X(),1);var M=(u=>(u.PublishMainStreamToCDN="publish-main-stream-to-cdn",u.PublishSubStreamToCDN="publish-sub-stream-to-cdn",u.PublishMixStreamToCDN="publish-mix-stream-to-cdn",u))(M||{}),$=(i=>(i.Main="main",i.Sub="sub",i))($||{});var K={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var R=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_params");S(this,"_publishGivenCDNData",null);this._core=e,this._room=e.room,this._log=i}get isPublishingGivenCDN(){return!!this._params}async startPublishGivenCDN(e){if(this._log.info(`[CDNStreaming] startPublishGivenCDN() current: ${JSON.stringify(this._params)}, params: ${JSON.stringify(e)}`),this.isPublishingGivenCDN){let{appId:i,bizId:u,url:d}=this._params||{};if(i===e.appId&&u===e.bizId&&d===e.url)return;await this.stopPublishGivenCDN()}this._params=e,this._publishGivenCDNData={pushRequestTime:Date.now(),pushAppId:e.appId,pushBizId:e.bizId,pushCdnUrl:e.url,pushStreamType:this.convertStreamType(e==null?void 0:e.publishMode),pushStreamId:e.streamId};try{let i=await this._room.sendStartPublishCDN(this._publishGivenCDNData,!1),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: start given cdn.");else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${u} errMsg: ${d} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${u} errMsg: ${d}`)}catch(i){throw this.resetGivenCDN(),i}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this.isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c}=this._publishGivenCDNData,l={pushRequestTime:Date.now(),pushAppId:e,pushBizId:i,pushCdnUrl:u,pushStreamType:d,pushStreamId:c},p=await this._room.sendStopPublishCDN(l,!1),{code:b,message:_}=p.data;if(b===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_} data: ${JSON.stringify(l)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${b} errMsg: ${_}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._params=void 0}convertStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}};var x=class{constructor(e,i){S(this,"_core");S(this,"_room");S(this,"_log");S(this,"_config",null);S(this,"_data",null);S(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=i,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,i,u;return((e=this._config)==null?void 0:e.target.appId)&&((i=this._config)==null?void 0:i.target.bizId)&&((u=this._config)==null?void 0:u.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let i=this.getInputParam(e),u=this.getOutputParam(e),d=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&d!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:d,inputParam:i,outputParam:u});let{appId:c,bizId:l,url:p,streamId:b=""}=e.target;c&&l&&p&&(this._givenCDNManager||(this._givenCDNManager=new R(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:l,url:p,streamId:b}))}catch(i){throw this.reset(),i}}async doStartMixTranscode({outputSessionId:e,inputParam:i,outputParam:u}){let d={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:i,outputParam:u};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(d)}`);let c=await this._room.sendStartMixTranscode(d),{code:l}=c.data,{message:p}=c.data;if(l===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=d;else throw l===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${l} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${l} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let i=await this._room.sendStopMixTranscode(e),{code:u,message:d}=i.data;if(u===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${u} errMsg: ${d}`)}reset(){this._config=null,this._data=null,this.uninstallEvents()}installEvents(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}async handleRoomJoined(){this._log.info(`[CDNStreaming] handleJoined: ${JSON.stringify(this._config)}`),this.isStarted&&this._config&&await this.startMixTranscode(this._config)}async handleRoomLeft(){this._log.info(`[CDNStreaming] handleRoomLeft: ${JSON.stringify(this._config)}`),this._data=null}getOutputSessionId({config:e,userId:i,roomId:u}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,ee.default)(`${u}_${i}_main`)}getStringRoomId(e,i){return e?String(e):i}getInputParam(e){let{mix:i={}}=e,{audioMixUserList:u=[],videoLayoutList:d=[]}=i,c=d.map(l=>({userId:l.fixedVideoUser.userId,roomId:this.getStringRoomId(l.fixedVideoUser.roomId,l.fixedVideoUser.strRoomId)||this._core.room.roomId,width:l.width||0,height:l.height||0,locationX:l.locationX||0,locationY:l.locationY||0,zOrder:l.zOrder||1,streamType:l.fixedVideoStreamType==="sub"?1:0,inputType:K.IT_PURE_VIDEO,renderMode:l.fillMode||0}));return u.forEach(l=>{let p=c.findIndex(b=>b.userId===l.userId&&b.roomId===this.getStringRoomId(l.roomId,l.strRoomId));p!==-1?c[p].inputType=K.IT_AUDIO_VIDEO:c.push({userId:l.userId,roomId:l.roomId||l.strRoomId,inputType:K.IT_PURE_AUDIO})}),c}getOutputParam(e){let i=e.target.streamId||"",{encoding:u={},mix:d={}}=e;return{streamId:i,streamType:i.length>0?1:0,width:this._core.utils.isUndefined(u.videoWidth)?640:u.videoWidth,height:this._core.utils.isUndefined(u.videoHeight)?480:u.videoHeight,videoBps:u.videoBitrate||0,fps:u.videoFramerate||15,gop:u.videoGOP||2,audioSampleRate:u.audioSampleRate||48e3,audioBps:u.audioBitrate||64,audioChannels:u.audioChannels||1,backgroundColor:d.backgroundColor||0,backgroundImg:d.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var F=Z(X(),1);var v=class{constructor(e,i){S(this,"_room");S(this,"_core");S(this,"_log");S(this,"_paramsForTencentCDN");S(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=i,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])}installEvents(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}async handlePublished({track:e}){var d;if(e.room!==this._room||(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(d=e==null?void 0:e.room)==null?void 0:d.roomId}, ${this._room.isMainStreamPublished}`),e.mediaType===1))return;let i=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",u=this._paramsForTencentCDN.get(i)||null;u!=null&&u.target&&u.isStarted&&await this.startPublishTencentCDN(u.target)}async handleRoomLeft(){this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1})}isStreamPublished(e){return e==="publish-main-stream-to-cdn"&&!this._room.isMainStreamPublished?(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1):e==="publish-sub-stream-to-cdn"&&!this._room.isAuxStreamPublished?(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):!0}changeDataStatus(e,i){let u=this._paramsForTencentCDN.get(e),d=I(I({},u),i);this._paramsForTencentCDN.set(e,d)}async startPublishTencentCDN(e){if(this._log.info(`[CDNStreaming] startPublishTencentCDN ${JSON.stringify(e)}`),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),!this.isStreamPublished(e.publishMode))return;let i=e.streamId||"",u=this.generatePublishCDNStreamId(i,e.publishMode),d=this.generatePublishCDNSessionId(e.publishMode),c=e.publishMode==="publish-sub-stream-to-cdn"?1:0,l={requestTime:Date.now(),sessionId:d,streamId:u,streamType:c};await this.doStartPublishTencentCDN(l,e.publishMode);let{appId:p,bizId:b,url:_}=e;if(p&&b&&_){let T=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;T!=null&&T.givenCDNManager||(T.givenCDNManager=new R(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,T)),await T.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:b,url:_,streamId:u})}}async doStartPublishTencentCDN(e,i){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let u=6,d=500,c=0;for(;;){let l=await this._room.sendStartPublishCDN(e,!0),{code:p}=l.data,{message:b}=l.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(i,{isPublished:!0});break}else if(p===-10006&&c<u)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${c+1}/6, reason: ${b}`),c+=1,await new Promise(_=>setTimeout(_,d));else throw this.changeDataStatus(i,{isPublished:!1}),p===-102083&&(b=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${b}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let i=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(i.isPublished){let{target:u}=i;u!=null&&u.bizId&&u.appId&&u.url&&(i!=null&&i.givenCDNManager)&&await(i==null?void 0:i.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let i={requestTime:Date.now(),sessionId:(0,F.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(i)}`);let u=await this._room.sendStopPublishCDN(i,!0),{code:d}=u.data,{message:c}=u.data;if(d===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw d===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),c=`can not stop in auto relayed-push mode ${c}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${d} errMsg: ${c}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,i){if(e===""){let u=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(i)}`;return/^[A-Za-z\d_-]*$/.test(u)||(u=(0,F.default)(u)),`${this._room.sdkAppId}_${u}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,F.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var te=m=>typeof m=="string";var P;function Te(m,e,i,u){if(!/^[A-Za-z\d_-]*$/.test(m)){let{RtcError:c,ErrorCode:l,ErrorCodeDictionary:p}=P;throw new c({code:l.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function _e(m,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:l}=P;if(te(m))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_INTEGER_STRING,fnName:i,messageParams:{key:"roomId"}});if(m===void 0)return;if(!(/^[1-9]\d*$/.test(String(m))&&m<4294967295))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_INTEGER,fnName:i,messageParams:{key:"roomId"}})}function fe(m,e,i,u){let{RtcError:d,ErrorCode:c,ErrorCodeDictionary:l}=P;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(m))throw new d({code:c.INVALID_PARAMETER,extraCode:l.INVALID_ROOM_ID_STRING,fnName:i,messageParams:{key:"strRoomId"}})}var O={type:"number",notLessThanZero:!0},re={type:"object",required:!0,properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:_e},strRoomId:{type:"string",validate:fe}}},ie={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]},streamId:{required:!1,type:"string",validate:Te},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1}}},oe={required:!1,type:"object",properties:{videoWidth:O,videoHeight:O,videoBitrate:j(I({},O),{allowEmpty:!1}),videoFramerate:{type:"number",validate(m,e,i,u){if(m<=0||m>30){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(m,e,i,u){if(m<1||m>8){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:O,audioBitrate:{type:"number",validate(m,e,i,u){if(m<32||m>192){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},ae={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:I({},re)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:I({},re),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(m,e,i,u){if(m<1||m>15){let{RtcError:d,ErrorCode:c}=P;throw new d({code:c.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:O,height:O,locationX:O,locationY:O}}}}};function se(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},ie),encoding:I({},oe),mix:I({},ae)},validate(e,i,u,d){var b,_;let{publishMode:c}=e.target,{encoding:l,mix:p}=e;if(c==="publish-mix-stream-to-cdn"){let{RtcError:T,ErrorCode:E,ErrorCodeDictionary:G}=m.errorModule;if(!l)throw new T({code:E.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"encoding"}});if(!p)throw new T({code:E.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:u,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let y=0,N=0,U=[];if(p.videoLayoutList.forEach((A,V)=>{U.push(A.fixedVideoUser.userId),A.width+A.locationX>y&&(y=A.width+A.locationX),A.height+A.locationY>N&&(N=A.height+A.locationY)}),U.indexOf(m.room.userId)<0)throw new T({code:E.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let J=(b=l==null?void 0:l.videoWidth)!=null?b:640,B=(_=l==null?void 0:l.videoHeight)!=null?_:480;if(J<y||B<N)throw new T({code:E.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function ne(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:I({},ie),encoding:I({},oe),mix:I({},ae)}}}function ue(m){return P=m.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:{required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn"]}}}}}}var w=0,k=class{constructor(e){this.core=e;S(this,"_mixTranscodeManager");S(this,"_publishCDNManager");S(this,"_core");S(this,"_modeOptions");S(this,"seq");S(this,"_log");w=w+1,this.seq=w,this._log=e.log.createChild({id:`${this.getAlias()}${w}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${w}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new x(e,this._log),this._publishCDNManager=new v(e,this._log)}getName(){return"CDNStreaming"}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return se(this._core);case"update":return ne(this._core);case"stop":return ue(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),await this.doStart(e)}async update(e){let i=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(i,e),await this.doStart(i)}async stop(e){switch(e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.stopMixTranscode();break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);break}}this._modeOptions.delete(e.target.publishMode)}async doStart(e){switch(this._log.info(`[CDNStreaming] doStart: ${JSON.stringify(e)}`),e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.startMixTranscode(e);break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.startPublishTencentCDN(e.target);break}}}};S(k,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn"}});var Ie=k;return Ce(Ae);})().default;
{
"name": "@rtc-plugin/cdn-streaming",
"version": "5.3.2-beta.3",
"version": "5.3.2-beta.4",
"description": "TRTC Web SDK 5.x CDN streaming plugin",

@@ -5,0 +5,0 @@ "main": "./cdn-streaming.esm.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc