Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trtc-sdk-v5

Package Overview
Dependencies
Maintainers
0
Versions
242
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.8.3-beta.4 to 5.8.3-beta.5

2

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

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

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

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

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

var N=Object.defineProperty,G=Object.defineProperties,M=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var O=(i,e,r)=>e in i?N(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r,y=(i,e)=>{for(var r in e||(e={}))K.call(e,r)&&O(i,r,e[r]);if(x)for(var r of x(e))F.call(e,r)&&O(i,r,e[r]);return i},A=(i,e)=>G(i,H(e));var I=(i,e,r,o)=>{for(var t=o>1?void 0:o?M(e,r):e,a=i.length-1,n;a>=0;a--)(n=i[a])&&(t=(o?n(e,r,t):n(t))||t);return o&&t&&N(e,r,t),t};var b=(i,e,r)=>(O(i,typeof e!="symbol"?e+"":e,r),r);var P={properties:{roomId:{type:"number"},strRoomId:{type:"string"}}},_={name:"option",required:!0,properties:A(y({},P.properties),{userId:{type:"string"}})},L={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:A(y({},_.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},k={name:"option",properties:y({},P.properties)};var p=i=>typeof i=="function";var j=0,W=1,V=2;function q({retryFunction:i,settings:e,onError:r,onRetrying:o,onRetryFailed:t,onRetrySuccess:a,context:n}){return function(...d){let{retries:m=5,timeout:u=1e3}=e,s=0,l=-1,c=j,R=async(f,E)=>{let w=n||this;try{let g=await i.apply(w,d);s>0&&a&&a.call(this,s),s=0,f(g)}catch(g){let U=()=>{clearTimeout(l),s=0,c=V,E(g)},h=()=>{c!==V&&s<(p(m)?m():m)?(s++,c=W,p(o)&&o.call(this,s,U),l=window.setTimeout(()=>{l=-1,R(f,E)},p(u)?u(s):u)):(U(),p(t)&&t.call(this,g))};p(r)?r.call(this,{error:g,retry:h,reject:E,retryFuncArgs:d,retriedCount:s}):h()}};return new Promise(R)}}var B=q;var T=new WeakMap;function D({settings:i={retries:5,timeout:2e3},onError:e,onRetrying:r,onRetryFailed:o}){return function(t,a,n){let d=B({retryFunction:n.value,settings:i,onError({error:m,retry:u,reject:s,retryFuncArgs:l}){var c;e?e.call(this,m,()=>{var R;(R=T.get(t))!=null&&R.has(a)?u():s(m)},s,l):(c=T.get(t))!=null&&c.has(a)?u():s(m)},onRetrying(m,u){var s;p(r)&&r.call(this,m,u),(s=T.get(t))!=null&&s.has(a)&&(T.get(t).get(a).stopRetry=u)},onRetryFailed:o});return n.value=function(...m){let u=T.get(t);return u?u.set(a,{args:m}):T.set(t,new Map([[a,{args:m}]])),d.apply(this,m).finally(()=>{var s;return(s=T.get(t))==null?void 0:s.delete(a)})},n}}var S=class S{constructor(e){this.core=e;b(this,"disableRandomCall",!0);b(this,"connectedRoomIdSet",new Set);b(this,"updateSeq",0);b(this,"_log");this._log=this.core.log.createChild({id:`${this.getAlias()}`})}getName(){return S.Name}getAlias(){return"crs-r"}getGroup(e){var o;let r=(e==null?void 0:e.userId)||((o=e==null?void 0:e.updateList)==null?void 0:o[0].userId)||"";return r||(e?e.updateList?String(e.updateList[0].roomId)||e.updateList[0].strRoomId||"":String(e.roomId)||e.strRoomId||"":"*")}getValidateRule(e){switch(e){case"start":return _;case"update":return L;case"stop":return k}}async start({roomId:e,strRoomId:r,userId:o}){let{RtcError:t,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:a.ENV_NOT_SUPPORTED});let n=e||r,d=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:n,userId:o,localRoomId:o?void 0:this.core.room.roomId},retries:3});if(d.data.code!==0)throw new t({code:a.SERVER_ERROR,extraCode:d.data.code,message:d.data.message});o||this.connectedRoomIdSet.add(n)}async update({updateList:e}){var n;let{RtcError:r,ErrorCode:o}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:o.ENV_NOT_SUPPORTED});let t=e.find(d=>d.userId)?0:1,a=await this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:t,updateList:e.map(({roomId:d,strRoomId:m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c})=>({roomId:d||m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c}))},retries:3});if(a.data.data.expectSeq)return this.updateSeq=a.data.data.expectSeq,this.update({updateList:e});if(a.data.code!==0)throw new r({code:o.SERVER_ERROR,extraCode:a.data.code,message:a.data.message});if(((n=a.data.data.errorList)==null?void 0:n.length)>0)throw new r({code:o.UNKNOWN_ERROR,message:a.data.data.errorList[0].message})}async stop({roomId:e,strRoomId:r}={}){let o=e||r;if(o)await this.doStop(o);else if(this.connectedRoomIdSet.size>0)for(let t of[...this.connectedRoomIdSet.values()])await this.doStop(t);else await this.doStop()}async doStop(e){let{RtcError:r,ErrorCode:o}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:o.ENV_NOT_SUPPORTED});let t=await this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});if(t.data.code!==0)throw new r({code:o.SERVER_ERROR,extraCode:t.data.code,message:t.data.message});this.connectedRoomIdSet.delete(e)}destroy(){}};b(S,"Name","CrossRoom"),I([D({settings:{retries:3,timeout:1e3},onRetrying(i){this._log.warn(`retry start: ${i}`)}})],S.prototype,"start",1),I([D({settings:{retries:3,timeout:1e3},onRetrying(i){this._log.warn(`retry update: ${i}`)}})],S.prototype,"update",1);var C=S;var ne=C;export{C as CrossRoom,ne as default};
var N=Object.defineProperty,G=Object.defineProperties,M=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var O=(i,e,r)=>e in i?N(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r,y=(i,e)=>{for(var r in e||(e={}))K.call(e,r)&&O(i,r,e[r]);if(x)for(var r of x(e))F.call(e,r)&&O(i,r,e[r]);return i},A=(i,e)=>G(i,H(e));var I=(i,e,r,o)=>{for(var t=o>1?void 0:o?M(e,r):e,a=i.length-1,n;a>=0;a--)(n=i[a])&&(t=(o?n(e,r,t):n(t))||t);return o&&t&&N(e,r,t),t};var b=(i,e,r)=>(O(i,typeof e!="symbol"?e+"":e,r),r);var P={properties:{roomId:{type:"number"},strRoomId:{type:"string"}}},_={name:"option",required:!0,properties:A(y({},P.properties),{userId:{type:"string"}})},L={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:A(y({},_.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},k={name:"option",properties:y({},P.properties)};var p=i=>typeof i=="function";var j=0,W=1,V=2;function q({retryFunction:i,settings:e,onError:r,onRetrying:o,onRetryFailed:t,onRetrySuccess:a,context:n}){return function(...d){let{retries:m=5,timeout:u=1e3}=e,s=0,l=-1,c=j,R=async(C,E)=>{let w=n||this;try{let g=await i.apply(w,d);s>0&&a&&a.call(this,s),s=0,C(g)}catch(g){let U=()=>{clearTimeout(l),s=0,c=V,E(g)},h=()=>{c!==V&&s<(p(m)?m():m)?(s++,c=W,p(o)&&o.call(this,s,U),l=window.setTimeout(()=>{l=-1,R(C,E)},p(u)?u(s):u)):(U(),p(t)&&t.call(this,g))};p(r)?r.call(this,{error:g,retry:h,reject:E,retryFuncArgs:d,retriedCount:s}):h()}};return new Promise(R)}}var B=q;var T=new WeakMap;function D({settings:i={retries:5,timeout:2e3},onError:e,onRetrying:r,onRetryFailed:o}){return function(t,a,n){let d=B({retryFunction:n.value,settings:i,onError({error:m,retry:u,reject:s,retryFuncArgs:l}){var c;e?e.call(this,m,()=>{var R;(R=T.get(t))!=null&&R.has(a)?u():s(m)},s,l):(c=T.get(t))!=null&&c.has(a)?u():s(m)},onRetrying(m,u){var s;p(r)&&r.call(this,m,u),(s=T.get(t))!=null&&s.has(a)&&(T.get(t).get(a).stopRetry=u)},onRetryFailed:o});return n.value=function(...m){let u=T.get(t);return u?u.set(a,{args:m}):T.set(t,new Map([[a,{args:m}]])),d.apply(this,m).finally(()=>{var s;return(s=T.get(t))==null?void 0:s.delete(a)})},n}}var S=class S{constructor(e){this.core=e;b(this,"disableRandomCall",!0);b(this,"connectedRoomIdSet",new Set);b(this,"updateSeq",0);b(this,"_log");this._log=this.core.log.createChild({id:`${this.getAlias()}`})}getName(){return S.Name}getAlias(){return"crs-r"}getGroup(e){var o;let r=(e==null?void 0:e.userId)||((o=e==null?void 0:e.updateList)==null?void 0:o[0].userId)||"";return r||(e?e.updateList?String(e.updateList[0].roomId)||e.updateList[0].strRoomId||"":String(e.roomId)||e.strRoomId||"":"*")}getValidateRule(e){switch(e){case"start":return _;case"update":return L;case"stop":return k}}async start({roomId:e,strRoomId:r,userId:o}){let{RtcError:t,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:a.ENV_NOT_SUPPORTED});let n=e||r,d=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:n,userId:o,localRoomId:o?void 0:this.core.room.roomId},retries:3});if(d.data.code!==0)throw new t({code:a.SERVER_ERROR,extraCode:d.data.code,message:d.data.message});o||this.connectedRoomIdSet.add(n)}async update({updateList:e}){var n;let{RtcError:r,ErrorCode:o}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:o.ENV_NOT_SUPPORTED});let t=e.find(d=>d.userId)?0:1,a=await this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:t,updateList:e.map(({roomId:d,strRoomId:m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c})=>({roomId:d||m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c}))},retries:3});if(a.data.data.expectSeq)return this.updateSeq=a.data.data.expectSeq,this.update({updateList:e});if(a.data.code!==0)throw new r({code:o.SERVER_ERROR,extraCode:a.data.code,message:a.data.message});if(((n=a.data.data.errorList)==null?void 0:n.length)>0)throw new r({code:o.UNKNOWN_ERROR,message:a.data.data.errorList[0].message})}async stop({roomId:e,strRoomId:r}={}){let o=e||r;if(o)await this.doStop(o);else if(this.connectedRoomIdSet.size>0)for(let t of[...this.connectedRoomIdSet.values()])await this.doStop(t);else await this.doStop()}async doStop(e){let{RtcError:r,ErrorCode:o}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:o.ENV_NOT_SUPPORTED});let t=await this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});if(t.data.code!==0)throw new r({code:o.SERVER_ERROR,extraCode:t.data.code,message:t.data.message});this.connectedRoomIdSet.delete(e)}destroy(){}};b(S,"Name","CrossRoom"),I([D({settings:{retries:3,timeout:1e3},onRetrying(i){this._log.warn(`retry start: ${i}`)}})],S.prototype,"start",1),I([D({settings:{retries:3,timeout:1e3},onRetrying(i){this._log.warn(`retry update: ${i}`)}})],S.prototype,"update",1);var f=S;var ne=f;export{f as CrossRoom,ne as default};

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

"use strict";var CrossRoom=(()=>{var y=Object.defineProperty,H=Object.defineProperties,P=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var I=(o,e,r)=>e in o?y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[e]=r,E=(o,e)=>{for(var r in e||(e={}))L.call(e,r)&&I(o,r,e[r]);if(N)for(var r of N(e))j.call(e,r)&&I(o,r,e[r]);return o},_=(o,e)=>H(o,K(e));var W=(o,e)=>{for(var r in e)y(o,r,{get:e[r],enumerable:!0})},q=(o,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of F(e))!L.call(o,t)&&t!==r&&y(o,t,{get:()=>e[t],enumerable:!(a=P(e,t))||a.enumerable});return o};var X=o=>q(y({},"__esModule",{value:!0}),o),D=(o,e,r,a)=>{for(var t=a>1?void 0:a?P(e,r):e,i=o.length-1,n;i>=0;i--)(n=o[i])&&(t=(a?n(e,r,t):n(t))||t);return a&&t&&y(e,r,t),t};var b=(o,e,r)=>(I(o,typeof e!="symbol"?e+"":e,r),r);var Z={};W(Z,{CrossRoom:()=>O,default:()=>Y});var k={properties:{roomId:{type:"number"},strRoomId:{type:"string"}}},C={name:"option",required:!0,properties:_(E({},k.properties),{userId:{type:"string"}})},V={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:_(E({},C.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},B={name:"option",properties:E({},k.properties)};var p=o=>typeof o=="function";var J=0,$=1,w=2;function z({retryFunction:o,settings:e,onError:r,onRetrying:a,onRetryFailed:t,onRetrySuccess:i,context:n}){return function(...d){let{retries:m=5,timeout:u=1e3}=e,s=0,l=-1,c=J,R=async(U,A)=>{let M=n||this;try{let g=await o.apply(M,d);s>0&&i&&i.call(this,s),s=0,U(g)}catch(g){let h=()=>{clearTimeout(l),s=0,c=w,A(g)},x=()=>{c!==w&&s<(p(m)?m():m)?(s++,c=$,p(a)&&a.call(this,s,h),l=window.setTimeout(()=>{l=-1,R(U,A)},p(u)?u(s):u)):(h(),p(t)&&t.call(this,g))};p(r)?r.call(this,{error:g,retry:x,reject:A,retryFuncArgs:d,retriedCount:s}):x()}};return new Promise(R)}}var G=z;var T=new WeakMap;function f({settings:o={retries:5,timeout:2e3},onError:e,onRetrying:r,onRetryFailed:a}){return function(t,i,n){let d=G({retryFunction:n.value,settings:o,onError({error:m,retry:u,reject:s,retryFuncArgs:l}){var c;e?e.call(this,m,()=>{var R;(R=T.get(t))!=null&&R.has(i)?u():s(m)},s,l):(c=T.get(t))!=null&&c.has(i)?u():s(m)},onRetrying(m,u){var s;p(r)&&r.call(this,m,u),(s=T.get(t))!=null&&s.has(i)&&(T.get(t).get(i).stopRetry=u)},onRetryFailed:a});return n.value=function(...m){let u=T.get(t);return u?u.set(i,{args:m}):T.set(t,new Map([[i,{args:m}]])),d.apply(this,m).finally(()=>{var s;return(s=T.get(t))==null?void 0:s.delete(i)})},n}}var S=class S{constructor(e){this.core=e;b(this,"disableRandomCall",!0);b(this,"connectedRoomIdSet",new Set);b(this,"updateSeq",0);b(this,"_log");this._log=this.core.log.createChild({id:`${this.getAlias()}`})}getName(){return S.Name}getAlias(){return"crs-r"}getGroup(e){var a;let r=(e==null?void 0:e.userId)||((a=e==null?void 0:e.updateList)==null?void 0:a[0].userId)||"";return r||(e?e.updateList?String(e.updateList[0].roomId)||e.updateList[0].strRoomId||"":String(e.roomId)||e.strRoomId||"":"*")}getValidateRule(e){switch(e){case"start":return C;case"update":return V;case"stop":return B}}async start({roomId:e,strRoomId:r,userId:a}){let{RtcError:t,ErrorCode:i}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:i.ENV_NOT_SUPPORTED});let n=e||r,d=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:n,userId:a,localRoomId:a?void 0:this.core.room.roomId},retries:3});if(d.data.code!==0)throw new t({code:i.SERVER_ERROR,extraCode:d.data.code,message:d.data.message});a||this.connectedRoomIdSet.add(n)}async update({updateList:e}){var n;let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=e.find(d=>d.userId)?0:1,i=await this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:t,updateList:e.map(({roomId:d,strRoomId:m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c})=>({roomId:d||m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c}))},retries:3});if(i.data.data.expectSeq)return this.updateSeq=i.data.data.expectSeq,this.update({updateList:e});if(i.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:i.data.code,message:i.data.message});if(((n=i.data.data.errorList)==null?void 0:n.length)>0)throw new r({code:a.UNKNOWN_ERROR,message:i.data.data.errorList[0].message})}async stop({roomId:e,strRoomId:r}={}){let a=e||r;if(a)await this.doStop(a);else if(this.connectedRoomIdSet.size>0)for(let t of[...this.connectedRoomIdSet.values()])await this.doStop(t);else await this.doStop()}async doStop(e){let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=await this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});if(t.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:t.data.code,message:t.data.message});this.connectedRoomIdSet.delete(e)}destroy(){}};b(S,"Name","CrossRoom"),D([f({settings:{retries:3,timeout:1e3},onRetrying(o){this._log.warn(`retry start: ${o}`)}})],S.prototype,"start",1),D([f({settings:{retries:3,timeout:1e3},onRetrying(o){this._log.warn(`retry update: ${o}`)}})],S.prototype,"update",1);var O=S;var Y=O;return X(Z);})().default;
"use strict";var CrossRoom=(()=>{var y=Object.defineProperty,H=Object.defineProperties,P=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var I=(o,e,r)=>e in o?y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[e]=r,E=(o,e)=>{for(var r in e||(e={}))L.call(e,r)&&I(o,r,e[r]);if(N)for(var r of N(e))j.call(e,r)&&I(o,r,e[r]);return o},_=(o,e)=>H(o,K(e));var W=(o,e)=>{for(var r in e)y(o,r,{get:e[r],enumerable:!0})},q=(o,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of F(e))!L.call(o,t)&&t!==r&&y(o,t,{get:()=>e[t],enumerable:!(a=P(e,t))||a.enumerable});return o};var X=o=>q(y({},"__esModule",{value:!0}),o),D=(o,e,r,a)=>{for(var t=a>1?void 0:a?P(e,r):e,i=o.length-1,n;i>=0;i--)(n=o[i])&&(t=(a?n(e,r,t):n(t))||t);return a&&t&&y(e,r,t),t};var b=(o,e,r)=>(I(o,typeof e!="symbol"?e+"":e,r),r);var Z={};W(Z,{CrossRoom:()=>O,default:()=>Y});var k={properties:{roomId:{type:"number"},strRoomId:{type:"string"}}},f={name:"option",required:!0,properties:_(E({},k.properties),{userId:{type:"string"}})},V={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:_(E({},f.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},B={name:"option",properties:E({},k.properties)};var p=o=>typeof o=="function";var J=0,$=1,w=2;function z({retryFunction:o,settings:e,onError:r,onRetrying:a,onRetryFailed:t,onRetrySuccess:i,context:n}){return function(...d){let{retries:m=5,timeout:u=1e3}=e,s=0,l=-1,c=J,R=async(U,A)=>{let M=n||this;try{let g=await o.apply(M,d);s>0&&i&&i.call(this,s),s=0,U(g)}catch(g){let h=()=>{clearTimeout(l),s=0,c=w,A(g)},x=()=>{c!==w&&s<(p(m)?m():m)?(s++,c=$,p(a)&&a.call(this,s,h),l=window.setTimeout(()=>{l=-1,R(U,A)},p(u)?u(s):u)):(h(),p(t)&&t.call(this,g))};p(r)?r.call(this,{error:g,retry:x,reject:A,retryFuncArgs:d,retriedCount:s}):x()}};return new Promise(R)}}var G=z;var T=new WeakMap;function C({settings:o={retries:5,timeout:2e3},onError:e,onRetrying:r,onRetryFailed:a}){return function(t,i,n){let d=G({retryFunction:n.value,settings:o,onError({error:m,retry:u,reject:s,retryFuncArgs:l}){var c;e?e.call(this,m,()=>{var R;(R=T.get(t))!=null&&R.has(i)?u():s(m)},s,l):(c=T.get(t))!=null&&c.has(i)?u():s(m)},onRetrying(m,u){var s;p(r)&&r.call(this,m,u),(s=T.get(t))!=null&&s.has(i)&&(T.get(t).get(i).stopRetry=u)},onRetryFailed:a});return n.value=function(...m){let u=T.get(t);return u?u.set(i,{args:m}):T.set(t,new Map([[i,{args:m}]])),d.apply(this,m).finally(()=>{var s;return(s=T.get(t))==null?void 0:s.delete(i)})},n}}var S=class S{constructor(e){this.core=e;b(this,"disableRandomCall",!0);b(this,"connectedRoomIdSet",new Set);b(this,"updateSeq",0);b(this,"_log");this._log=this.core.log.createChild({id:`${this.getAlias()}`})}getName(){return S.Name}getAlias(){return"crs-r"}getGroup(e){var a;let r=(e==null?void 0:e.userId)||((a=e==null?void 0:e.updateList)==null?void 0:a[0].userId)||"";return r||(e?e.updateList?String(e.updateList[0].roomId)||e.updateList[0].strRoomId||"":String(e.roomId)||e.strRoomId||"":"*")}getValidateRule(e){switch(e){case"start":return f;case"update":return V;case"stop":return B}}async start({roomId:e,strRoomId:r,userId:a}){let{RtcError:t,ErrorCode:i}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:i.ENV_NOT_SUPPORTED});let n=e||r,d=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:n,userId:a,localRoomId:a?void 0:this.core.room.roomId},retries:3});if(d.data.code!==0)throw new t({code:i.SERVER_ERROR,extraCode:d.data.code,message:d.data.message});a||this.connectedRoomIdSet.add(n)}async update({updateList:e}){var n;let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=e.find(d=>d.userId)?0:1,i=await this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:t,updateList:e.map(({roomId:d,strRoomId:m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c})=>({roomId:d||m,userId:u,muteAudio:s,muteVideo:l,muteSubStream:c}))},retries:3});if(i.data.data.expectSeq)return this.updateSeq=i.data.data.expectSeq,this.update({updateList:e});if(i.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:i.data.code,message:i.data.message});if(((n=i.data.data.errorList)==null?void 0:n.length)>0)throw new r({code:a.UNKNOWN_ERROR,message:i.data.data.errorList[0].message})}async stop({roomId:e,strRoomId:r}={}){let a=e||r;if(a)await this.doStop(a);else if(this.connectedRoomIdSet.size>0)for(let t of[...this.connectedRoomIdSet.values()])await this.doStop(t);else await this.doStop()}async doStop(e){let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=await this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});if(t.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:t.data.code,message:t.data.message});this.connectedRoomIdSet.delete(e)}destroy(){}};b(S,"Name","CrossRoom"),D([C({settings:{retries:3,timeout:1e3},onRetrying(o){this._log.warn(`retry start: ${o}`)}})],S.prototype,"start",1),D([C({settings:{retries:3,timeout:1e3},onRetrying(o){this._log.warn(`retry update: ${o}`)}})],S.prototype,"update",1);var O=S;var Y=O;return X(Z);})().default;
{
"name": "@rtc-plugin/cross-room",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x Cross Room plugin",

@@ -5,0 +5,0 @@ "main": "./cross-room.esm.js",

{
"name": "@rtc-plugin/debug",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK Debug Plugin",

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

{
"name": "@rtc-plugin/device-detector",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x device detector plugin",

@@ -5,0 +5,0 @@ "main": "./device-detector.esm.js",

{
"name": "@rtc-plugin/basic-beauty",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x basic-beauty plugin",

@@ -5,0 +5,0 @@ "main": "./basic-beauty.esm.js",

{
"name": "@rtc-plugin/beauty",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x beauty plugin",

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

{
"name": "@rtc-plugin/virtual-background",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x virtual background plugin",

@@ -5,0 +5,0 @@ "main": "./virtual-background.esm.js",

{
"name": "@rtc-plugin/watermark",
"version": "5.8.3-beta.4",
"version": "5.8.3-beta.5",
"description": "TRTC Web SDK 5.x watermark plugin",

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

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

var U=Object.defineProperty;var C=(a,e,t)=>e in a?U(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var u=(a,e,t)=>(C(a,typeof e!="symbol"?e+"":e,t),t);function D(a){return{name:"WatermarkOptions",type:"object",required:!0,allowEmpty:!1,properties:{imageUrl:{required:!0,type:"string"},x:{required:!1,type:"number"},y:{required:!1,type:"number"},size:{required:!1,type:["string","object","number"]}},validate(e,t,n,S){var p;let{RtcError:r,ErrorCode:d,ErrorCodeDictionary:o}=a.errorModule;if(!e)return;let{imageUrl:m}=e,c=m.split("?")[0].split(".").pop();if((c==="jpg"||c==="jpeg")&&a.log.warn("The image format is not recommended to be jpg/jpeg, because the format does not support transparency."),!((p=a.room.videoManager.cameraTrack)!=null&&p.mediaTrack))throw new r({code:d.INVALID_OPERATION,extraCode:o.INVALID_OPERATION_NEED_VIDEO,fnName:n});if(a.utils.isString(e.size)&&e.size!=="contain"&&e.size!=="cover")throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_TYPE,message:"The size parameter must be 'contain' or 'cover'",fnName:n});if(a.utils.isNumber(e.size)&&(e.size<=0||e.size>1))throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n});if(a.utils.isObject(e.size)){if(!e.size.width||!e.size.height)throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_TYPE,message:"The size parameter must be an object with width and height properties",fnName:n});if(e.size.width<=0||e.size.height<=0)throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n})}}}}function R(a){return{name:"StopWatermarkOptions",required:!1}}var g=0,E=class E{constructor(e){this.core=e;u(this,"seq");u(this,"_core");u(this,"log");u(this,"startResolve");u(this,"startReject");g=g+1,this.seq=g,this._core=e,this.log=e.log.createChild({id:`${this.getAlias()}${g}`}),this.log.info("created")}getName(){return E.Name}getAlias(){return"w"}getValidateRule(e){switch(e){case"start":return D(this._core);case"update":return R(this._core);case"stop":return R(this._core)}}getGroup(){return"w"}async start(e){return this.doStart(e)}async update(e){return await this.stop(),this.doStart(e)}async stop(){return this._core.room.videoManager.deleteWatermark()}async doStart(e){let{imageUrl:t,x:n=0,y:S=0,size:r="cover"}=e,{settings:d}=this._core.room.videoManager.cameraTrack,o;try{o=await this._core.utils.loadImage(t)}catch(y){let{RtcError:h,ErrorCode:N}=this.core.errorModule;throw new h({code:N.INVALID_PARAMETER,message:`load image failed, url: ${t}`})}let{width:m,height:l}=d,{width:c,height:p}=o,i=c,s=p;this._core.utils.isObject(r)&&(i=(r==null?void 0:r.width)||i,s=(r==null?void 0:r.height)||s),this._core.utils.isNumber(r)&&(i=c*r,s=p*r);let T=c/p,O=m/l,I=T>O;r==="contain"&&(I?(i=m,s=m/T):(i=l*T,s=l)),r==="cover"&&(I?(s=l,i=l*T):(i=m,s=m/T));let b=document.createElement("canvas"),A=b.getContext("2d");return b.width=Math.min(m-n,i),b.height=Math.min(l-S,s),A==null||A.drawImage(o,0,0,i,s),this._core.room.videoManager.setWatermark({x:n,y:S,imageUrl:b.toDataURL("image/png")})}};u(E,"Name","Watermark");var _=E;var G=_;export{_ as Watermark,G as default};
var U=Object.defineProperty;var C=(a,e,t)=>e in a?U(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var u=(a,e,t)=>(C(a,typeof e!="symbol"?e+"":e,t),t);function D(a){return{name:"WatermarkOptions",type:"object",required:!0,allowEmpty:!1,properties:{imageUrl:{required:!0,type:"string"},x:{required:!1,type:"number"},y:{required:!1,type:"number"},size:{required:!1,type:["string","object","number"]}},validate(e,t,n,S){var p;let{RtcError:r,ErrorCode:d,ErrorCodeDictionary:o}=a.errorModule;if(!e)return;let{imageUrl:m}=e,c=m.split("?")[0].split(".").pop();if((c==="jpg"||c==="jpeg")&&a.log.warn("The image format is not recommended to be jpg/jpeg, because the format does not support transparency."),!((p=a.room.videoManager.cameraTrack)!=null&&p.mediaTrack))throw new r({code:d.INVALID_OPERATION,extraCode:o.INVALID_OPERATION_NEED_VIDEO,fnName:n});if(a.utils.isString(e.size)&&e.size!=="contain"&&e.size!=="cover")throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_TYPE,message:"The size parameter must be 'contain' or 'cover'",fnName:n});if(a.utils.isNumber(e.size)&&(e.size<=0||e.size>1))throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n});if(a.utils.isObject(e.size)){if(!e.size.width||!e.size.height)throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_TYPE,message:"The size parameter must be an object with width and height properties",fnName:n});if(e.size.width<=0||e.size.height<=0)throw new r({code:d.INVALID_PARAMETER,extraCode:o.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n})}}}}function A(a){return{name:"StopWatermarkOptions",required:!1}}var g=0,E=class E{constructor(e){this.core=e;u(this,"seq");u(this,"_core");u(this,"log");u(this,"startResolve");u(this,"startReject");g=g+1,this.seq=g,this._core=e,this.log=e.log.createChild({id:`${this.getAlias()}${g}`}),this.log.info("created")}getName(){return E.Name}getAlias(){return"w"}getValidateRule(e){switch(e){case"start":return D(this._core);case"update":return A(this._core);case"stop":return A(this._core)}}getGroup(){return"w"}async start(e){return this.doStart(e)}async update(e){return await this.stop(),this.doStart(e)}async stop(){return this._core.room.videoManager.deleteWatermark()}async doStart(e){let{imageUrl:t,x:n=0,y:S=0,size:r="cover"}=e,{settings:d}=this._core.room.videoManager.cameraTrack,o;try{o=await this._core.utils.loadImage(t)}catch(P){let{RtcError:h,ErrorCode:N}=this.core.errorModule;throw new h({code:N.INVALID_PARAMETER,message:`load image failed, url: ${t}`})}let{width:m,height:l}=d,{width:c,height:p}=o,i=c,s=p;this._core.utils.isObject(r)&&(i=(r==null?void 0:r.width)||i,s=(r==null?void 0:r.height)||s),this._core.utils.isNumber(r)&&(i=c*r,s=p*r);let T=c/p,O=m/l,I=T>O;r==="contain"&&(I?(i=m,s=m/T):(i=l*T,s=l)),r==="cover"&&(I?(s=l,i=l*T):(i=m,s=m/T));let b=document.createElement("canvas"),R=b.getContext("2d");return b.width=Math.min(m-n,i),b.height=Math.min(l-S,s),R==null||R.drawImage(o,0,0,i,s),this._core.room.videoManager.setWatermark({x:n,y:S,imageUrl:b.toDataURL("image/png")})}};u(E,"Name","Watermark");var _=E;var G=_;export{_ as Watermark,G as default};

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

"use strict";var Watermark=(()=>{var E=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var x=(r,e,t)=>e in r?E(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e)=>{for(var t in e)E(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of y(e))!P.call(r,i)&&i!==t&&E(r,i,{get:()=>e[i],enumerable:!(o=C(e,i))||o.enumerable});return r};var k=r=>L(E({},"__esModule",{value:!0}),r);var d=(r,e,t)=>(x(r,typeof e!="symbol"?e+"":e,t),t);var B={};f(B,{Watermark:()=>A,default:()=>V});function O(r){return{name:"WatermarkOptions",type:"object",required:!0,allowEmpty:!1,properties:{imageUrl:{required:!0,type:"string"},x:{required:!1,type:"number"},y:{required:!1,type:"number"},size:{required:!1,type:["string","object","number"]}},validate(e,t,o,i){var T;let{RtcError:a,ErrorCode:l,ErrorCodeDictionary:s}=r.errorModule;if(!e)return;let{imageUrl:u}=e,p=u.split("?")[0].split(".").pop();if((p==="jpg"||p==="jpeg")&&r.log.warn("The image format is not recommended to be jpg/jpeg, because the format does not support transparency."),!((T=r.room.videoManager.cameraTrack)!=null&&T.mediaTrack))throw new a({code:l.INVALID_OPERATION,extraCode:s.INVALID_OPERATION_NEED_VIDEO,fnName:o});if(r.utils.isString(e.size)&&e.size!=="contain"&&e.size!=="cover")throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be 'contain' or 'cover'",fnName:o});if(r.utils.isNumber(e.size)&&(e.size<=0||e.size>1))throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:o});if(r.utils.isObject(e.size)){if(!e.size.width||!e.size.height)throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be an object with width and height properties",fnName:o});if(e.size.width<=0||e.size.height<=0)throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:o})}}}}function I(r){return{name:"StopWatermarkOptions",required:!1}}var S=0,R=class R{constructor(e){this.core=e;d(this,"seq");d(this,"_core");d(this,"log");d(this,"startResolve");d(this,"startReject");S=S+1,this.seq=S,this._core=e,this.log=e.log.createChild({id:`${this.getAlias()}${S}`}),this.log.info("created")}getName(){return R.Name}getAlias(){return"w"}getValidateRule(e){switch(e){case"start":return O(this._core);case"update":return I(this._core);case"stop":return I(this._core)}}getGroup(){return"w"}async start(e){return this.doStart(e)}async update(e){return await this.stop(),this.doStart(e)}async stop(){return this._core.room.videoManager.deleteWatermark()}async doStart(e){let{imageUrl:t,x:o=0,y:i=0,size:a="cover"}=e,{settings:l}=this._core.room.videoManager.cameraTrack,s;try{s=await this._core.utils.loadImage(t)}catch(G){let{RtcError:N,ErrorCode:U}=this.core.errorModule;throw new N({code:U.INVALID_PARAMETER,message:`load image failed, url: ${t}`})}let{width:u,height:c}=l,{width:p,height:T}=s,n=p,m=T;this._core.utils.isObject(a)&&(n=(a==null?void 0:a.width)||n,m=(a==null?void 0:a.height)||m),this._core.utils.isNumber(a)&&(n=p*a,m=T*a);let b=p/T,h=u/c,D=b>h;a==="contain"&&(D?(n=u,m=u/b):(n=c*b,m=c)),a==="cover"&&(D?(m=c,n=c*b):(n=u,m=u/b));let g=document.createElement("canvas"),_=g.getContext("2d");return g.width=Math.min(u-o,n),g.height=Math.min(c-i,m),_==null||_.drawImage(s,0,0,n,m),this._core.room.videoManager.setWatermark({x:o,y:i,imageUrl:g.toDataURL("image/png")})}};d(R,"Name","Watermark");var A=R;var V=A;return k(B);})().default;
"use strict";var Watermark=(()=>{var E=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var x=(r,e,t)=>e in r?E(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e)=>{for(var t in e)E(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of P(e))!y.call(r,i)&&i!==t&&E(r,i,{get:()=>e[i],enumerable:!(o=C(e,i))||o.enumerable});return r};var k=r=>L(E({},"__esModule",{value:!0}),r);var d=(r,e,t)=>(x(r,typeof e!="symbol"?e+"":e,t),t);var B={};f(B,{Watermark:()=>R,default:()=>V});function O(r){return{name:"WatermarkOptions",type:"object",required:!0,allowEmpty:!1,properties:{imageUrl:{required:!0,type:"string"},x:{required:!1,type:"number"},y:{required:!1,type:"number"},size:{required:!1,type:["string","object","number"]}},validate(e,t,o,i){var T;let{RtcError:a,ErrorCode:l,ErrorCodeDictionary:s}=r.errorModule;if(!e)return;let{imageUrl:u}=e,p=u.split("?")[0].split(".").pop();if((p==="jpg"||p==="jpeg")&&r.log.warn("The image format is not recommended to be jpg/jpeg, because the format does not support transparency."),!((T=r.room.videoManager.cameraTrack)!=null&&T.mediaTrack))throw new a({code:l.INVALID_OPERATION,extraCode:s.INVALID_OPERATION_NEED_VIDEO,fnName:o});if(r.utils.isString(e.size)&&e.size!=="contain"&&e.size!=="cover")throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be 'contain' or 'cover'",fnName:o});if(r.utils.isNumber(e.size)&&(e.size<=0||e.size>1))throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:o});if(r.utils.isObject(e.size)){if(!e.size.width||!e.size.height)throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be an object with width and height properties",fnName:o});if(e.size.width<=0||e.size.height<=0)throw new a({code:l.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:o})}}}}function I(r){return{name:"StopWatermarkOptions",required:!1}}var S=0,A=class A{constructor(e){this.core=e;d(this,"seq");d(this,"_core");d(this,"log");d(this,"startResolve");d(this,"startReject");S=S+1,this.seq=S,this._core=e,this.log=e.log.createChild({id:`${this.getAlias()}${S}`}),this.log.info("created")}getName(){return A.Name}getAlias(){return"w"}getValidateRule(e){switch(e){case"start":return O(this._core);case"update":return I(this._core);case"stop":return I(this._core)}}getGroup(){return"w"}async start(e){return this.doStart(e)}async update(e){return await this.stop(),this.doStart(e)}async stop(){return this._core.room.videoManager.deleteWatermark()}async doStart(e){let{imageUrl:t,x:o=0,y:i=0,size:a="cover"}=e,{settings:l}=this._core.room.videoManager.cameraTrack,s;try{s=await this._core.utils.loadImage(t)}catch(G){let{RtcError:N,ErrorCode:U}=this.core.errorModule;throw new N({code:U.INVALID_PARAMETER,message:`load image failed, url: ${t}`})}let{width:u,height:c}=l,{width:p,height:T}=s,n=p,m=T;this._core.utils.isObject(a)&&(n=(a==null?void 0:a.width)||n,m=(a==null?void 0:a.height)||m),this._core.utils.isNumber(a)&&(n=p*a,m=T*a);let b=p/T,h=u/c,D=b>h;a==="contain"&&(D?(n=u,m=u/b):(n=c*b,m=c)),a==="cover"&&(D?(m=c,n=c*b):(n=u,m=u/b));let g=document.createElement("canvas"),_=g.getContext("2d");return g.width=Math.min(u-o,n),g.height=Math.min(c-i,m),_==null||_.drawImage(s,0,0,n,m),this._core.room.videoManager.setWatermark({x:o,y:i,imageUrl:g.toDataURL("image/png")})}};d(A,"Name","Watermark");var R=A;var V=R;return k(B);})().default;

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

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