You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

trtc-sdk-v5

Package Overview
Dependencies
Maintainers
9
Versions
352
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

to
5.9.2-beta.5

plugins/cdn-streaming/cdn-streaming.umd.js

2

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

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

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

var le=Object.create;var z=Object.defineProperty,ce=Object.defineProperties,he=Object.getOwnPropertyDescriptor,pe=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols,be=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var X=(c,e,r)=>e in c?z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):c[e]=r,_=(c,e)=>{for(var r in e||(e={}))ee.call(e,r)&&X(c,r,e[r]);if(Q)for(var r of Q(e))Se.call(e,r)&&X(c,r,e[r]);return c},H=(c,e)=>ce(c,pe(e));var Te=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports);var _e=(c,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ge(e))!ee.call(c,i)&&i!==r&&z(c,i,{get:()=>e[i],enumerable:!(o=he(e,i))||o.enumerable});return c};var j=(c,e,r)=>(r=c!=null?le(be(c)):{},_e(e||!c||!c.__esModule?z(r,"default",{value:c,enumerable:!0}):r,c));var g=(c,e,r)=>X(c,typeof e!="symbol"?e+"":e,r);var W=Te((re,$)=>{"use strict";(function(c){"use strict";function e(t,h){var a=(t&65535)+(h&65535),b=(t>>16)+(h>>16)+(a>>16);return b<<16|a&65535}function r(t,h){return t<<h|t>>>32-h}function o(t,h,a,b,T,D){return e(r(e(e(h,t),e(b,D)),T),a)}function i(t,h,a,b,T,D,f){return o(h&a|~h&b,t,h,T,D,f)}function l(t,h,a,b,T,D,f){return o(h&b|a&~b,t,h,T,D,f)}function s(t,h,a,b,T,D,f){return o(h^a^b,t,h,T,D,f)}function p(t,h,a,b,T,D,f){return o(a^(h|~b),t,h,T,D,f)}function S(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var a,b,T,D,f,n=1732584193,m=-271733879,d=-1732584194,u=271733878;for(a=0;a<t.length;a+=16)b=n,T=m,D=d,f=u,n=i(n,m,d,u,t[a],7,-680876936),u=i(u,n,m,d,t[a+1],12,-389564586),d=i(d,u,n,m,t[a+2],17,606105819),m=i(m,d,u,n,t[a+3],22,-1044525330),n=i(n,m,d,u,t[a+4],7,-176418897),u=i(u,n,m,d,t[a+5],12,1200080426),d=i(d,u,n,m,t[a+6],17,-1473231341),m=i(m,d,u,n,t[a+7],22,-45705983),n=i(n,m,d,u,t[a+8],7,1770035416),u=i(u,n,m,d,t[a+9],12,-1958414417),d=i(d,u,n,m,t[a+10],17,-42063),m=i(m,d,u,n,t[a+11],22,-1990404162),n=i(n,m,d,u,t[a+12],7,1804603682),u=i(u,n,m,d,t[a+13],12,-40341101),d=i(d,u,n,m,t[a+14],17,-1502002290),m=i(m,d,u,n,t[a+15],22,1236535329),n=l(n,m,d,u,t[a+1],5,-165796510),u=l(u,n,m,d,t[a+6],9,-1069501632),d=l(d,u,n,m,t[a+11],14,643717713),m=l(m,d,u,n,t[a],20,-373897302),n=l(n,m,d,u,t[a+5],5,-701558691),u=l(u,n,m,d,t[a+10],9,38016083),d=l(d,u,n,m,t[a+15],14,-660478335),m=l(m,d,u,n,t[a+4],20,-405537848),n=l(n,m,d,u,t[a+9],5,568446438),u=l(u,n,m,d,t[a+14],9,-1019803690),d=l(d,u,n,m,t[a+3],14,-187363961),m=l(m,d,u,n,t[a+8],20,1163531501),n=l(n,m,d,u,t[a+13],5,-1444681467),u=l(u,n,m,d,t[a+2],9,-51403784),d=l(d,u,n,m,t[a+7],14,1735328473),m=l(m,d,u,n,t[a+12],20,-1926607734),n=s(n,m,d,u,t[a+5],4,-378558),u=s(u,n,m,d,t[a+8],11,-2022574463),d=s(d,u,n,m,t[a+11],16,1839030562),m=s(m,d,u,n,t[a+14],23,-35309556),n=s(n,m,d,u,t[a+1],4,-1530992060),u=s(u,n,m,d,t[a+4],11,1272893353),d=s(d,u,n,m,t[a+7],16,-155497632),m=s(m,d,u,n,t[a+10],23,-1094730640),n=s(n,m,d,u,t[a+13],4,681279174),u=s(u,n,m,d,t[a],11,-358537222),d=s(d,u,n,m,t[a+3],16,-722521979),m=s(m,d,u,n,t[a+6],23,76029189),n=s(n,m,d,u,t[a+9],4,-640364487),u=s(u,n,m,d,t[a+12],11,-421815835),d=s(d,u,n,m,t[a+15],16,530742520),m=s(m,d,u,n,t[a+2],23,-995338651),n=p(n,m,d,u,t[a],6,-198630844),u=p(u,n,m,d,t[a+7],10,1126891415),d=p(d,u,n,m,t[a+14],15,-1416354905),m=p(m,d,u,n,t[a+5],21,-57434055),n=p(n,m,d,u,t[a+12],6,1700485571),u=p(u,n,m,d,t[a+3],10,-1894986606),d=p(d,u,n,m,t[a+10],15,-1051523),m=p(m,d,u,n,t[a+1],21,-2054922799),n=p(n,m,d,u,t[a+8],6,1873313359),u=p(u,n,m,d,t[a+15],10,-30611744),d=p(d,u,n,m,t[a+6],15,-1560198380),m=p(m,d,u,n,t[a+13],21,1309151649),n=p(n,m,d,u,t[a+4],6,-145523070),u=p(u,n,m,d,t[a+11],10,-1120210379),d=p(d,u,n,m,t[a+2],15,718787259),m=p(m,d,u,n,t[a+9],21,-343485551),n=e(n,b),m=e(m,T),d=e(d,D),u=e(u,f);return[n,m,d,u]}function C(t){var h,a="",b=t.length*32;for(h=0;h<b;h+=8)a+=String.fromCharCode(t[h>>5]>>>h%32&255);return a}function I(t){var h,a=[];for(a[(t.length>>2)-1]=void 0,h=0;h<a.length;h+=1)a[h]=0;var b=t.length*8;for(h=0;h<b;h+=8)a[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return a}function U(t){return C(S(I(t),t.length*8))}function G(t,h){var a,b=I(t),T=[],D=[],f;for(T[15]=D[15]=void 0,b.length>16&&(b=S(b,t.length*8)),a=0;a<16;a+=1)T[a]=b[a]^909522486,D[a]=b[a]^1549556828;return f=S(T.concat(I(h)),512+h.length*8),C(S(D.concat(f),640))}function M(t){var h="0123456789abcdef",a="",b,T;for(T=0;T<t.length;T+=1)b=t.charCodeAt(T),a+=h.charAt(b>>>4&15)+h.charAt(b&15);return a}function R(t){return unescape(encodeURIComponent(t))}function E(t){return U(R(t))}function J(t){return M(E(t))}function B(t,h){return G(R(t),R(h))}function P(t,h){return M(B(t,h))}function V(t,h,a){return h?a?B(h,t):P(h,t):a?E(t):J(t)}typeof define=="function"&&define.amd?define(function(){return V}):typeof $=="object"&&$.exports?$.exports=V:c.md5=V})(re)});var te=j(W(),1);var y=(i=>(i.PublishMainStreamToCDN="publish-main-stream-to-cdn",i.PublishSubStreamToCDN="publish-sub-stream-to-cdn",i.PublishMixStreamToCDN="publish-mix-stream-to-cdn",i.PublishMixStreamToRoom="publish-mix-stream-to-room",i))(y||{}),K=(r=>(r.Main="main",r.Sub="sub",r))(K||{});var F={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var O=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_params");g(this,"_publishGivenCDNData",null);this._core=e,this._room=e.room,this._log=r}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:r,bizId:o,url:i}=this._params||{};if(r===e.appId&&o===e.bizId&&i===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 r=await this._room.sendStartPublishCDN(this._publishGivenCDNData,!1),{code:o,message:i}=r.data;if(o===0)this._log.info("[CDNStreaming] server success: start given cdn.");else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${o} errMsg: ${i} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${o} errMsg: ${i}`)}catch(r){throw this.resetGivenCDN(),r}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this.isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:r,pushCdnUrl:o,pushStreamType:i,pushStreamId:l}=this._publishGivenCDNData,s={pushRequestTime:Date.now(),pushAppId:e,pushBizId:r,pushCdnUrl:o,pushStreamType:i,pushStreamId:l},p=await this._room.sendStopPublishCDN(s,!1),{code:S,message:C}=p.data;if(S===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${S} errMsg: ${C} data: ${JSON.stringify(s)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${S} errMsg: ${C}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._params=void 0}convertStreamType(e){return e==="publish-sub-stream-to-cdn"?"aux":"main"}};var x=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_config",null);g(this,"_data",null);g(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=r,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,r,o;return((e=this._config)==null?void 0:e.target.appId)&&((r=this._config)==null?void 0:r.target.bizId)&&((o=this._config)==null?void 0:o.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let r=this.getInputParam(e),o=this.getOutputParam(e),i=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&i!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:i,inputParam:r,outputParam:o});let{appId:l,bizId:s,url:p,streamId:S=""}=e.target;l&&s&&p&&(this._givenCDNManager||(this._givenCDNManager=new O(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:l,bizId:s,url:p,streamId:S}))}catch(r){throw this.reset(),r}}async doStartMixTranscode({outputSessionId:e,inputParam:r,outputParam:o}){let i={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:r,outputParam:o};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(i)}`);let l=await this._room.sendStartMixTranscode(i),{code:s}=l.data,{message:p}=l.data;if(s===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=i;else throw s===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${s} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${s} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let r=await this._room.sendStopMixTranscode(e),{code:o,message:i}=r.data;if(o===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: stop mix errCode: ${o} errMsg: ${i}`),new Error(`[CDNStreaming] server failed: stop mix errCode: ${o} errMsg: ${i}`)}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:r,roomId:o}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,te.default)(`${o}_${r}_main`)}getStringRoomId(e,r){return e?String(e):r}getInputParam(e){let{mix:r={}}=e,{audioMixUserList:o=[],videoLayoutList:i=[]}=r,l=i.map(s=>({userId:s.fixedVideoUser.userId,roomId:this.getStringRoomId(s.fixedVideoUser.roomId,s.fixedVideoUser.strRoomId)||this._core.room.roomId,width:s.width||0,height:s.height||0,locationX:s.locationX||0,locationY:s.locationY||0,zOrder:s.zOrder||1,streamType:s.fixedVideoStreamType==="sub"?1:0,inputType:F.IT_PURE_VIDEO,renderMode:s.fillMode||0}));return o.forEach(s=>{let p=this._core.room.roomId;(s.roomId||s.strRoomId)&&(p=this.getStringRoomId(s.roomId,s.strRoomId));let S=l.findIndex(C=>C.userId===s.userId&&C.roomId===p);S!==-1?l[S].inputType=F.IT_AUDIO_VIDEO:l.push({userId:s.userId,roomId:s.roomId||s.strRoomId||this._core.room.roomId,inputType:F.IT_PURE_AUDIO})}),l}getOutputParam(e){let r=e.target.streamId||"",{encoding:o={},mix:i={}}=e;return{streamId:r,streamType:r.length>0?1:0,width:this._core.utils.isUndefined(o.videoWidth)?640:o.videoWidth,height:this._core.utils.isUndefined(o.videoHeight)?480:o.videoHeight,videoBps:o.videoBitrate||0,fps:o.videoFramerate||15,gop:o.videoGOP||2,audioSampleRate:o.audioSampleRate||48e3,audioBps:o.audioBitrate||64,audioChannels:o.audioChannels||1,backgroundColor:i.backgroundColor||0,backgroundImg:i.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var q=j(W(),1);var L=class{constructor(e,r){g(this,"_room");g(this,"_core");g(this,"_log");g(this,"_paramsForTencentCDN");g(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=r,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 i;if(e.room!==this._room||(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(i=e==null?void 0:e.room)==null?void 0:i.roomId}`),e.mediaType===1))return;let r=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",o=this._paramsForTencentCDN.get(r)||null;o!=null&&o.target&&o.isStarted&&await this.startPublishTencentCDN(o.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,r){let o=this._paramsForTencentCDN.get(e),i=_(_({},o),r);this._paramsForTencentCDN.set(e,i)}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 r=e.streamId||"",o=this.generatePublishCDNStreamId(r,e.publishMode),i=this.generatePublishCDNSessionId(e.publishMode),l=e.publishMode==="publish-sub-stream-to-cdn"?1:0,s={requestTime:Date.now(),sessionId:i,streamId:o,streamType:l};await this.doStartPublishTencentCDN(s,e.publishMode);let{appId:p,bizId:S,url:C}=e;if(p&&S&&C){let I=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;I!=null&&I.givenCDNManager||(I.givenCDNManager=new O(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,I)),await I.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:S,url:C,streamId:o})}}async doStartPublishTencentCDN(e,r){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let o=6,i=500,l=0;for(;;){let s=await this._room.sendStartPublishCDN(e,!0),{code:p}=s.data,{message:S}=s.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(r,{isPublished:!0});break}else if(p===-10006&&l<o)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${l+1}/6, reason: ${S}`),l+=1,await new Promise(C=>setTimeout(C,i));else throw this.changeDataStatus(r,{isPublished:!1}),p===-102083&&(S=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${S}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${S}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let r=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(r.isPublished){let{target:o}=r;o!=null&&o.bizId&&o.appId&&o.url&&(r!=null&&r.givenCDNManager)&&await(r==null?void 0:r.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let r={requestTime:Date.now(),sessionId:(0,q.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(r)}`);let o=await this._room.sendStopPublishCDN(r,!0),{code:i}=o.data,{message:l}=o.data;if(i===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw i===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),l=`can not stop in auto relayed-push mode ${l}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${i} errMsg: ${l}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${i} errMsg: ${l}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,r){if(e===""){let o=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(r)}`;return/^[A-Za-z\d_-]*$/.test(o)||(o=(0,q.default)(o)),`${this._room.sdkAppId}_${o}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,q.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var ae=j(W(),1);var v=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_seq");g(this,"_taskId",null);g(this,"_startData",null);g(this,"_updateData",null);g(this,"_stopData",null);this._core=e,this._room=e.room,this._log=r,this._seq=0}async startPushStreamToRoom(e){var l,s;this._seq+=1,this._startData=_({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,ae.default)(`${this._room.roomId}_${this._room.userId}_start`),agentParam:{cdnRobotUserid:`mcu_robot_${this._room.roomId}_${this._room.userId}`}},this.getCommonParams(e)),this._log.info(`startPushStreamToRoom: ${JSON.stringify(this._startData)}`);let r=await this._room.sendStartPushStreamToRoom(this._startData),{code:o,message:i}=r.data;o===0?(this._taskId=(s=(l=r.data)==null?void 0:l.data)==null?void 0:s.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",o,`can't resolve task id: ${JSON.stringify(r.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",o,i)}async updatePushStreamToRoom(e){this._seq+=1,this._updateData=H(_({taskid:this._taskId},this.getCommonParams(e)),{enableNtpSync:!0}),this._log.info(`updatePushStreamToRoom: ${JSON.stringify(this._updateData)}`);let r=await this._room.sendUpdatePushStreamToRoom(this._updateData),{code:o,message:i}=r.data;o===0?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i)}async stopPushStreamToRoom(){this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info(`stopPushStreamToRoom: ${JSON.stringify(this._stopData)}`);let e=await this._room.sendStopPushStreamToRoom(this._stopData),{code:r,message:o}=e.data;r===0?this._log.info("server success: start mix"):this.reportServerError("stopPushStreamToRoom",r,o)}reportServerError(e,r,o){let i=`server failed: ${e} errCode: ${r} errMsg: ${o}`;throw this._log.error(i),new Error(i)}getPushRtcRoomParams(e){let{robotUser:r}=e.target;return r?[{roomid:String((r==null?void 0:r.roomId)||(r==null?void 0:r.strRoomId))||this._room.roomId,roomType:r!=null&&r.roomId?0:1,pushRobotUserid:r==null?void 0:r.userId}]:[]}getCommonParams(e){return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(e),videoParam:this.getVideoParam(e),pushRtcRoomParams:this.getPushRtcRoomParams(e),sequenceNumber:this._seq}}getAudioParam(e){let{mix:r={},encoding:o={}}=e,i={audioSamplerate:o.audioSampleRate||48e3,audioBitrateKbps:o.audioBitrate||64,audioChannels:o.audioChannels||1},{audioMixUserList:l}=r;return{audioEncodeParam:i,mixAudioUsers:(l==null?void 0:l.map(s=>({roomid:String(s.roomId||s.strRoomId)||this._room.roomId,userid:s.userId,roomType:s.roomId?0:1})))||[]}}getVideoParam(e){let{mix:r={},encoding:o={}}=e,i={videoCodec:2,videoWidth:o.videoWidth||640,videoHeight:o.videoHeight||480,videoFramerate:o.videoFramerate||15,videoGop:o.videoGOP||2,videoBitrateKbps:o.videoBitrate||800},{videoLayoutList:l}=r;return{videoEncodeParam:i,layoutParams:(l==null?void 0:l.map(s=>({userMediaStream:{userInfo:{roomid:String(s.fixedVideoUser.roomId||s.fixedVideoUser.strRoomId)||this._room.roomId,userid:s.fixedVideoUser.userId,roomType:s.fixedVideoUser.roomId?0:1},streamType:s.fixedVideoStreamType==="sub"?1:0},imageWidth:s.width||0,imageHeight:s.height||0,locationX:s.locationX||0,locationY:s.locationY||0,imageZorder:s.zOrder||1,renderMode:s.fillMode||0})))||[],backgroundColor:r.backgroundColor||0,backgroundImageUrl:r.backgroundImage||""}}};var oe=c=>typeof c=="string";var A;function De(c,e,r,o){if(!/^[A-Za-z\d_-]*$/.test(c)){let{RtcError:l,ErrorCode:s,ErrorCodeDictionary:p}=A;throw new l({code:s.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function Ie(c,e,r,o){let{RtcError:i,ErrorCode:l,ErrorCodeDictionary:s}=A;if(oe(c))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER_STRING,fnName:r,messageParams:{key:"roomId"}});if(c===void 0)return;if(!(/^[1-9]\d*$/.test(String(c))&&c<4294967295))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER,fnName:r,messageParams:{key:"roomId"}})}function fe(c,e,r,o){let{RtcError:i,ErrorCode:l,ErrorCodeDictionary:s}=A;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(c))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_STRING,fnName:r,messageParams:{key:"strRoomId"}})}var N={type:"number",notLessThanZero:!0},Y={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:Ie},strRoomId:{type:"string",validate:fe}}},ie={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn","publish-mix-stream-to-room"]},streamId:{required:!1,type:"string",validate:De},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1},robotUser:_({},Y)},validate(c,e,r,o){let{publishMode:i,robotUser:l}=c;if(i==="publish-mix-stream-to-room"&&!l){let{RtcError:s,ErrorCode:p}=A;throw new s({code:p.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},se={required:!1,type:"object",properties:{videoWidth:N,videoHeight:N,videoBitrate:H(_({},N),{allowEmpty:!1}),videoFramerate:{type:"number",validate(c,e,r,o){if(c<=0||c>30){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(c,e,r,o){if(c<1||c>8){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:N,audioBitrate:{type:"number",validate(c,e,r,o){if(c<32||c>192){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},ne={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:_({},Y)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:_({},Y),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(c,e,r,o){if(c<1||c>15){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:N,height:N,locationX:N,locationY:N}}}}};function me(c){return A=c.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:_({},ie),encoding:_({},se),mix:_({},ne)},validate(e,r,o,i){var S,C;let{publishMode:l}=e.target,{encoding:s,mix:p}=e;if(l==="publish-mix-stream-to-cdn"){let{RtcError:I,ErrorCode:U,ErrorCodeDictionary:G}=c.errorModule;if(!s)throw new I({code:U.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"encoding"}});if(!p)throw new I({code:U.INVALID_PARAMETER,extraCode:G.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let M=0,R=0,E=[];if(p.videoLayoutList.forEach((P,V)=>{E.push(P.fixedVideoUser.userId),P.width+P.locationX>M&&(M=P.width+P.locationX),P.height+P.locationY>R&&(R=P.height+P.locationY)}),E.indexOf(c.room.userId)<0)throw new I({code:U.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let J=(S=s==null?void 0:s.videoWidth)!=null?S:640,B=(C=s==null?void 0:s.videoHeight)!=null?C:480;if(J<M||B<R)throw new I({code:U.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function de(c){return A=c.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:_({},ie),encoding:_({},se),mix:_({},ne)}}}function ue(c){return A=c.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","publish-mix-stream-to-room"]}}}}}}var k=0,w=class w{constructor(e){this.core=e;g(this,"_mixTranscodeManager");g(this,"_publishCDNManager");g(this,"_pushStreamToRoomManager");g(this,"_core");g(this,"_modeOptions");g(this,"seq");g(this,"_log");k=k+1,this.seq=k,this._log=e.log.createChild({id:`${this.getAlias()}${k}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${k}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new x(e,this._log),this._publishCDNManager=new L(e,this._log),this._pushStreamToRoomManager=new v(e,this._log)}getName(){return w.Name}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return me(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),e.target.publishMode==="publish-mix-stream-to-room"?this._pushStreamToRoomManager.startPushStreamToRoom(e):await this.doStart(e)}async update(e){let r=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(r,e),e.target.publishMode==="publish-mix-stream-to-room"?this._pushStreamToRoomManager.updatePushStreamToRoom(r):await this.doStart(r)}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}case"publish-mix-stream-to-room":{this._pushStreamToRoomManager.stopPushStreamToRoom();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}}}};g(w,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn",PublishMixStreamToRoom:"publish-mix-stream-to-room"}}),g(w,"Name","CDNStreaming");var Z=w;var lr=Z;export{Z as CDNStreaming,y as PublishMode,K as TRTCStreamType,lr as default};
var errorModule,__create=Object.create,__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropNames=Object.getOwnPropertyNames,__getOwnPropSymbols=Object.getOwnPropertySymbols,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t)),__commonJS=(e,t)=>function(){return t||(0,e[__getOwnPropNames(e)[0]])((t={exports:{}}).exports,t),t.exports},__copyProps=(e,t,r,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of __getOwnPropNames(t))__hasOwnProp.call(e,i)||i===r||__defProp(e,i,{get:()=>t[i],enumerable:!(o=__getOwnPropDesc(t,i))||o.enumerable});return e},__toESM=(e,t,r)=>(r=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?r:__defProp(r,"default",{value:e,enumerable:!0}),e)),__publicField=(e,t,r)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,r),require_md5=__commonJS({"../node_modules/.pnpm/blueimp-md5@2.19.0/node_modules/blueimp-md5/js/md5.js"(e,t){"use strict";!function(e){function r(e,t){var r=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(r>>16)<<16|65535&r}function o(e,t,o,i,s,a){return r((n=r(r(t,e),r(i,a)))<<(d=s)|n>>>32-d,o);var n,d}function i(e,t,r,i,s,a,n){return o(t&r|~t&i,e,t,s,a,n)}function s(e,t,r,i,s,a,n){return o(t&i|r&~i,e,t,s,a,n)}function a(e,t,r,i,s,a,n){return o(t^r^i,e,t,s,a,n)}function n(e,t,r,i,s,a,n){return o(r^(t|~i),e,t,s,a,n)}function d(e,t){var o,d,u,l,h;e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;var m=1732584193,_=-271733879,p=-1732584194,c=271733878;for(o=0;o<e.length;o+=16)d=m,u=_,l=p,h=c,m=i(m,_,p,c,e[o],7,-680876936),c=i(c,m,_,p,e[o+1],12,-389564586),p=i(p,c,m,_,e[o+2],17,606105819),_=i(_,p,c,m,e[o+3],22,-1044525330),m=i(m,_,p,c,e[o+4],7,-176418897),c=i(c,m,_,p,e[o+5],12,1200080426),p=i(p,c,m,_,e[o+6],17,-1473231341),_=i(_,p,c,m,e[o+7],22,-45705983),m=i(m,_,p,c,e[o+8],7,1770035416),c=i(c,m,_,p,e[o+9],12,-1958414417),p=i(p,c,m,_,e[o+10],17,-42063),_=i(_,p,c,m,e[o+11],22,-1990404162),m=i(m,_,p,c,e[o+12],7,1804603682),c=i(c,m,_,p,e[o+13],12,-40341101),p=i(p,c,m,_,e[o+14],17,-1502002290),m=s(m,_=i(_,p,c,m,e[o+15],22,1236535329),p,c,e[o+1],5,-165796510),c=s(c,m,_,p,e[o+6],9,-1069501632),p=s(p,c,m,_,e[o+11],14,643717713),_=s(_,p,c,m,e[o],20,-373897302),m=s(m,_,p,c,e[o+5],5,-701558691),c=s(c,m,_,p,e[o+10],9,38016083),p=s(p,c,m,_,e[o+15],14,-660478335),_=s(_,p,c,m,e[o+4],20,-405537848),m=s(m,_,p,c,e[o+9],5,568446438),c=s(c,m,_,p,e[o+14],9,-1019803690),p=s(p,c,m,_,e[o+3],14,-187363961),_=s(_,p,c,m,e[o+8],20,1163531501),m=s(m,_,p,c,e[o+13],5,-1444681467),c=s(c,m,_,p,e[o+2],9,-51403784),p=s(p,c,m,_,e[o+7],14,1735328473),m=a(m,_=s(_,p,c,m,e[o+12],20,-1926607734),p,c,e[o+5],4,-378558),c=a(c,m,_,p,e[o+8],11,-2022574463),p=a(p,c,m,_,e[o+11],16,1839030562),_=a(_,p,c,m,e[o+14],23,-35309556),m=a(m,_,p,c,e[o+1],4,-1530992060),c=a(c,m,_,p,e[o+4],11,1272893353),p=a(p,c,m,_,e[o+7],16,-155497632),_=a(_,p,c,m,e[o+10],23,-1094730640),m=a(m,_,p,c,e[o+13],4,681279174),c=a(c,m,_,p,e[o],11,-358537222),p=a(p,c,m,_,e[o+3],16,-722521979),_=a(_,p,c,m,e[o+6],23,76029189),m=a(m,_,p,c,e[o+9],4,-640364487),c=a(c,m,_,p,e[o+12],11,-421815835),p=a(p,c,m,_,e[o+15],16,530742520),m=n(m,_=a(_,p,c,m,e[o+2],23,-995338651),p,c,e[o],6,-198630844),c=n(c,m,_,p,e[o+7],10,1126891415),p=n(p,c,m,_,e[o+14],15,-1416354905),_=n(_,p,c,m,e[o+5],21,-57434055),m=n(m,_,p,c,e[o+12],6,1700485571),c=n(c,m,_,p,e[o+3],10,-1894986606),p=n(p,c,m,_,e[o+10],15,-1051523),_=n(_,p,c,m,e[o+1],21,-2054922799),m=n(m,_,p,c,e[o+8],6,1873313359),c=n(c,m,_,p,e[o+15],10,-30611744),p=n(p,c,m,_,e[o+6],15,-1560198380),_=n(_,p,c,m,e[o+13],21,1309151649),m=n(m,_,p,c,e[o+4],6,-145523070),c=n(c,m,_,p,e[o+11],10,-1120210379),p=n(p,c,m,_,e[o+2],15,718787259),_=n(_,p,c,m,e[o+9],21,-343485551),m=r(m,d),_=r(_,u),p=r(p,l),c=r(c,h);return[m,_,p,c]}function u(e){var t,r="",o=32*e.length;for(t=0;t<o;t+=8)r+=String.fromCharCode(e[t>>5]>>>t%32&255);return r}function l(e){var t,r=[];for(r[(e.length>>2)-1]=void 0,t=0;t<r.length;t+=1)r[t]=0;var o=8*e.length;for(t=0;t<o;t+=8)r[t>>5]|=(255&e.charCodeAt(t/8))<<t%32;return r}function h(e){var t,r,o="0123456789abcdef",i="";for(r=0;r<e.length;r+=1)t=e.charCodeAt(r),i+=o.charAt(t>>>4&15)+o.charAt(15&t);return i}function m(e){return unescape(encodeURIComponent(e))}function _(e){return function(e){return u(d(l(e),8*e.length))}(m(e))}function p(e,t){return function(e,t){var r,o,i=l(e),s=[],a=[];for(s[15]=a[15]=void 0,i.length>16&&(i=d(i,8*e.length)),r=0;r<16;r+=1)s[r]=909522486^i[r],a[r]=1549556828^i[r];return o=d(s.concat(l(t)),512+8*t.length),u(d(a.concat(o),640))}(m(e),m(t))}function c(e,t,r){return t?r?p(t,e):h(p(t,e)):r?_(e):h(_(e))}"function"==typeof define&&define.amd?define((function(){return c})):"object"==typeof t&&t.exports?t.exports=c:e.md5=c}(e)}}),import_blueimp_md5=__toESM(require_md5(),1),MIX_INPUT_TYPE={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5},GivenCDNManager=class{constructor(e,t){__publicField(this,"_core"),__publicField(this,"_room"),__publicField(this,"_log"),__publicField(this,"_params"),__publicField(this,"_publishGivenCDNData",null),this._core=e,this._room=e.room,this._log=t}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){const{appId:t,bizId:r,url:o}=this._params||{};if(t===e.appId&&r===e.bizId&&o===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(null==e?void 0:e.publishMode),pushStreamId:e.streamId};try{const t=await this._room.sendStartPublishCDN(this._publishGivenCDNData,!1),{code:r,message:o}=t.data;if(0!==r)throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${r} errMsg: ${o} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${r} errMsg: ${o}`);this._log.info("[CDNStreaming] server success: start given cdn.")}catch(e){throw this.resetGivenCDN(),e}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this.isPublishingGivenCDN||!this._publishGivenCDNData)return void this.resetGivenCDN();const{pushAppId:e,pushBizId:t,pushCdnUrl:r,pushStreamType:o,pushStreamId:i}=this._publishGivenCDNData,s={pushRequestTime:Date.now(),pushAppId:e,pushBizId:t,pushCdnUrl:r,pushStreamType:o,pushStreamId:i},a=await this._room.sendStopPublishCDN(s,!1),{code:n,message:d}=a.data;if(0!==n)throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${n} errMsg: ${d} data: ${JSON.stringify(s)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${n} errMsg: ${d}`);this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN()}resetGivenCDN(){this._publishGivenCDNData=null,this._params=void 0}convertStreamType(e){return"publish-sub-stream-to-cdn"===e?"aux":"main"}},MixTranscodeManager=class{constructor(e,t){__publicField(this,"_core"),__publicField(this,"_room"),__publicField(this,"_log"),__publicField(this,"_config",null),__publicField(this,"_data",null),__publicField(this,"_givenCDNManager"),this._core=e,this._room=e.room,this._log=t,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,t,r;return(null==(e=this._config)?void 0:e.target.appId)&&(null==(t=this._config)?void 0:t.target.bizId)&&(null==(r=this._config)?void 0:r.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),this._core.room.isJoined)try{const t=this.getInputParam(e),r=this.getOutputParam(e),o=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&o!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:o,inputParam:t,outputParam:r});const{appId:i,bizId:s,url:a,streamId:n=""}=e.target;i&&s&&a&&(this._givenCDNManager||(this._givenCDNManager=new GivenCDNManager(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:i,bizId:s,url:a,streamId:n}))}catch(e){throw this.reset(),e}}async doStartMixTranscode({outputSessionId:e,inputParam:t,outputParam:r}){const o={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:t,outputParam:r};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(o)}`);const i=await this._room.sendStartMixTranscode(o),{code:s}=i.data;let{message:a}=i.data;if(0!==s)throw-102083===s&&(a=`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: ${s} errMsg: ${a}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${s} errMsg: ${a}`);this._log.info("[CDNStreaming] server success: start mix"),this._data=o}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(){const e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);const t=await this._room.sendStopMixTranscode(e),{code:r,message:o}=t.data;if(0!==r)throw this._log.error(`[CDNStreaming] server failed: stop mix errCode: ${r} errMsg: ${o}`),new Error(`[CDNStreaming] server failed: stop mix errCode: ${r} errMsg: ${o}`);this._log.info("[CDNStreaming] server success: stop mix"),this.reset()}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:t,roomId:r}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,import_blueimp_md5.default)(`${r}_${t}_main`)}getStringRoomId(e,t){return e?String(e):t}getInputParam(e){const{mix:t={}}=e,{audioMixUserList:r=[],videoLayoutList:o=[]}=t,i=o.map((e=>({userId:e.fixedVideoUser.userId,roomId:this.getStringRoomId(e.fixedVideoUser.roomId,e.fixedVideoUser.strRoomId)||this._core.room.roomId,width:e.width||0,height:e.height||0,locationX:e.locationX||0,locationY:e.locationY||0,zOrder:e.zOrder||1,streamType:"sub"===e.fixedVideoStreamType?1:0,inputType:MIX_INPUT_TYPE.IT_PURE_VIDEO,renderMode:e.fillMode||0})));return r.forEach((e=>{let t=this._core.room.roomId;(e.roomId||e.strRoomId)&&(t=this.getStringRoomId(e.roomId,e.strRoomId));const r=i.findIndex((r=>r.userId===e.userId&&r.roomId===t));-1!==r?i[r].inputType=MIX_INPUT_TYPE.IT_AUDIO_VIDEO:i.push({userId:e.userId,roomId:e.roomId||e.strRoomId||this._core.room.roomId,inputType:MIX_INPUT_TYPE.IT_PURE_AUDIO})})),i}getOutputParam(e){const t=e.target.streamId||"",{encoding:r={},mix:o={}}=e;return{streamId:t,streamType:t.length>0?1:0,width:this._core.utils.isUndefined(r.videoWidth)?640:r.videoWidth,height:this._core.utils.isUndefined(r.videoHeight)?480:r.videoHeight,videoBps:r.videoBitrate||0,fps:r.videoFramerate||15,gop:r.videoGOP||2,audioSampleRate:r.audioSampleRate||48e3,audioBps:r.audioBitrate||64,audioChannels:r.audioChannels||1,backgroundColor:o.backgroundColor||0,backgroundImg:o.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}},import_blueimp_md52=__toESM(require_md5(),1),PublishCDNManager=class{constructor(e,t){__publicField(this,"_room"),__publicField(this,"_core"),__publicField(this,"_log"),__publicField(this,"_paramsForTencentCDN"),__publicField(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1}),this._core=e,this._room=e.room,this._log=t,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 t;if(e.room!==this._room)return;if(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${null==(t=null==e?void 0:e.room)?void 0:t.roomId}`),1===e.mediaType)return;const r=4===e.mediaType?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",o=this._paramsForTencentCDN.get(r)||null;(null==o?void 0:o.target)&&o.isStarted&&await this.startPublishTencentCDN(o.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"publish-main-stream-to-cdn"!==e||this._room.isMainStreamPublished?!("publish-sub-stream-to-cdn"===e&&!this._room.isAuxStreamPublished)||(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1)}changeDataStatus(e,t){const r=this._paramsForTencentCDN.get(e),o=__spreadValues(__spreadValues({},r),t);this._paramsForTencentCDN.set(e,o)}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;const t=e.streamId||"",r=this.generatePublishCDNStreamId(t,e.publishMode),o=this.generatePublishCDNSessionId(e.publishMode),i="publish-sub-stream-to-cdn"===e.publishMode?1:0,s={requestTime:Date.now(),sessionId:o,streamId:r,streamType:i};await this.doStartPublishTencentCDN(s,e.publishMode);const{appId:a,bizId:n,url:d}=e;if(a&&n&&d){const t=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;(null==t?void 0:t.givenCDNManager)||(t.givenCDNManager=new GivenCDNManager(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,t)),await t.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:a,bizId:n,url:d,streamId:r})}}async doStartPublishTencentCDN(e,t){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let r=0;for(;;){const o=await this._room.sendStartPublishCDN(e,!0),{code:i}=o.data;let{message:s}=o.data;if(0===i){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(t,{isPublished:!0});break}if(!(-10006===i&&r<6))throw this.changeDataStatus(t,{isPublished:!1}),-102083===i&&(s=`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: ${i} errMsg: ${s}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${i} errMsg: ${s}`);this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${r+1}/6, reason: ${s}`),r+=1,await new Promise((e=>setTimeout(e,500)))}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);const t=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(t.isPublished){const{target:r}=t;(null==r?void 0:r.bizId)&&r.appId&&r.url&&(null==t?void 0:t.givenCDNManager)&&await(null==t?void 0:t.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){const t={requestTime:Date.now(),sessionId:(0,import_blueimp_md52.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(t)}`);const r=await this._room.sendStopPublishCDN(t,!0),{code:o}=r.data;let{message:i}=r.data;if(0!==o)throw-102069===o&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),i=`can not stop in auto relayed-push mode ${i}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${o} errMsg: ${i}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${o} errMsg: ${i}`);this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,t){if(""===e){let e=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(t)}`;return/^[A-Za-z\d_-]*$/.test(e)||(e=(0,import_blueimp_md52.default)(e)),`${this._room.sdkAppId}_${e}`}return e}convertPublishModeToStreamType(e){return"publish-main-stream-to-cdn"===e?"main":"aux"}generatePublishCDNSessionId(e){return(0,import_blueimp_md52.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}},import_blueimp_md53=__toESM(require_md5(),1),PushStreamToRoom=class{constructor(e,t){__publicField(this,"_core"),__publicField(this,"_room"),__publicField(this,"_log"),__publicField(this,"_seq"),__publicField(this,"_taskId",null),__publicField(this,"_startData",null),__publicField(this,"_updateData",null),__publicField(this,"_stopData",null),this._core=e,this._room=e.room,this._log=t,this._seq=0}async startPushStreamToRoom(e){var t,r;this._seq+=1,this._startData=__spreadValues({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,import_blueimp_md53.default)(`${this._room.roomId}_${this._room.userId}_start`),agentParam:{cdnRobotUserid:`mcu_robot_${this._room.roomId}_${this._room.userId}`}},this.getCommonParams(e)),this._log.info(`startPushStreamToRoom: ${JSON.stringify(this._startData)}`);const o=await this._room.sendStartPushStreamToRoom(this._startData),{code:i,message:s}=o.data;0===i?(this._taskId=null==(r=null==(t=o.data)?void 0:t.data)?void 0:r.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",i,`can't resolve task id: ${JSON.stringify(o.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",i,s)}async updatePushStreamToRoom(e){this._seq+=1,this._updateData=__spreadProps(__spreadValues({taskid:this._taskId},this.getCommonParams(e)),{enableNtpSync:!0}),this._log.info(`updatePushStreamToRoom: ${JSON.stringify(this._updateData)}`);const t=await this._room.sendUpdatePushStreamToRoom(this._updateData),{code:r,message:o}=t.data;0===r?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",r,o)}async stopPushStreamToRoom(){this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info(`stopPushStreamToRoom: ${JSON.stringify(this._stopData)}`);const e=await this._room.sendStopPushStreamToRoom(this._stopData),{code:t,message:r}=e.data;0===t?this._log.info("server success: start mix"):this.reportServerError("stopPushStreamToRoom",t,r)}reportServerError(e,t,r){const o=`server failed: ${e} errCode: ${t} errMsg: ${r}`;throw this._log.error(o),new Error(o)}getPushRtcRoomParams(e){const{robotUser:t}=e.target;return t?[{roomid:String((null==t?void 0:t.roomId)||(null==t?void 0:t.strRoomId))||this._room.roomId,roomType:(null==t?void 0:t.roomId)?0:1,pushRobotUserid:null==t?void 0:t.userId}]:[]}getCommonParams(e){return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(e),videoParam:this.getVideoParam(e),pushRtcRoomParams:this.getPushRtcRoomParams(e),sequenceNumber:this._seq}}getAudioParam(e){const{mix:t={},encoding:r={}}=e,o={audioSamplerate:r.audioSampleRate||48e3,audioBitrateKbps:r.audioBitrate||64,audioChannels:r.audioChannels||1},{audioMixUserList:i}=t;return{audioEncodeParam:o,mixAudioUsers:(null==i?void 0:i.map((e=>({roomid:String(e.roomId||e.strRoomId)||this._room.roomId,userid:e.userId,roomType:e.roomId?0:1}))))||[]}}getVideoParam(e){const{mix:t={},encoding:r={}}=e,o={videoCodec:2,videoWidth:r.videoWidth||640,videoHeight:r.videoHeight||480,videoFramerate:r.videoFramerate||15,videoGop:r.videoGOP||2,videoBitrateKbps:r.videoBitrate||800},{videoLayoutList:i}=t;return{videoEncodeParam:o,layoutParams:(null==i?void 0:i.map((e=>({userMediaStream:{userInfo:{roomid:String(e.fixedVideoUser.roomId||e.fixedVideoUser.strRoomId)||this._room.roomId,userid:e.fixedVideoUser.userId,roomType:e.fixedVideoUser.roomId?0:1},streamType:"sub"===e.fixedVideoStreamType?1:0},imageWidth:e.width||0,imageHeight:e.height||0,locationX:e.locationX||0,locationY:e.locationY||0,imageZorder:e.zOrder||1,renderMode:e.fillMode||0}))))||[],backgroundColor:t.backgroundColor||0,backgroundImageUrl:t.backgroundImage||""}}},isString=e=>"string"==typeof e;function streamIdValidate(e,t,r,o){if(!/^[A-Za-z\d_-]*$/.test(e)){const{RtcError:e,ErrorCode:t,ErrorCodeDictionary:r}=errorModule;throw new e({code:t.INVALID_PARAMETER,extraCode:r.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function roomIdValidate(e,t,r,o){const{RtcError:i,ErrorCode:s,ErrorCodeDictionary:a}=errorModule;if(isString(e))throw new i({code:s.INVALID_PARAMETER,extraCode:a.INVALID_ROOM_ID_INTEGER_STRING,fnName:r,messageParams:{key:"roomId"}});if(void 0!==e){if(!(/^[1-9]\d*$/.test(String(e))&&e<4294967295))throw new i({code:s.INVALID_PARAMETER,extraCode:a.INVALID_ROOM_ID_INTEGER,fnName:r,messageParams:{key:"roomId"}})}}function strRoomIdValidate(e,t,r,o){const{RtcError:i,ErrorCode:s,ErrorCodeDictionary:a}=errorModule;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(e))throw new i({code:s.INVALID_PARAMETER,extraCode:a.INVALID_ROOM_ID_STRING,fnName:r,messageParams:{key:"strRoomId"}})}var notLessThanZero={type:"number",notLessThanZero:!0},UserRule={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:roomIdValidate},strRoomId:{type:"string",validate:strRoomIdValidate}}},TargetRule={required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn","publish-mix-stream-to-room"]},streamId:{required:!1,type:"string",validate:streamIdValidate},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1},robotUser:__spreadValues({},UserRule)},validate(e,t,r,o){const{publishMode:i,robotUser:s}=e;if("publish-mix-stream-to-room"===i&&!s){const{RtcError:e,ErrorCode:t}=errorModule;throw new e({code:t.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},EncodingRule={required:!1,type:"object",properties:{videoWidth:notLessThanZero,videoHeight:notLessThanZero,videoBitrate:__spreadProps(__spreadValues({},notLessThanZero),{allowEmpty:!1}),videoFramerate:{type:"number",validate(e,t,r,o){if(e<=0||e>30){const{RtcError:e,ErrorCode:t}=errorModule;throw new e({code:t.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(e,t,r,o){if(e<1||e>8){const{RtcError:e,ErrorCode:t}=errorModule;throw new e({code:t.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:notLessThanZero,audioBitrate:{type:"number",validate(e,t,r,o){if(e<32||e>192){const{RtcError:e,ErrorCode:t}=errorModule;throw new e({code:t.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},MixRule={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:__spreadValues({},UserRule)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:__spreadValues({},UserRule),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(e,t,r,o){if(e<1||e>15){const{RtcError:e,ErrorCode:t}=errorModule;throw new e({code:t.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:notLessThanZero,height:notLessThanZero,locationX:notLessThanZero,locationY:notLessThanZero}}}}};function startValidateRule(e){return errorModule=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:__spreadValues({},TargetRule),encoding:__spreadValues({},EncodingRule),mix:__spreadValues({},MixRule)},validate(t,r,o,i){var s,a;const{publishMode:n}=t.target,{encoding:d,mix:u}=t;if("publish-mix-stream-to-cdn"===n){const{RtcError:t,ErrorCode:r,ErrorCodeDictionary:i}=e.errorModule;if(!d)throw new t({code:r.INVALID_PARAMETER,extraCode:i.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"encoding"}});if(!u)throw new t({code:r.INVALID_PARAMETER,extraCode:i.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"mix"}});if(u&&u.videoLayoutList){let o=0,i=0;const n=[];if(u.videoLayoutList.forEach(((e,t)=>{n.push(e.fixedVideoUser.userId),e.width+e.locationX>o&&(o=e.width+e.locationX),e.height+e.locationY>i&&(i=e.height+e.locationY)})),n.indexOf(e.room.userId)<0)throw new t({code:r.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});const l=null!=(s=null==d?void 0:d.videoWidth)?s:640,h=null!=(a=null==d?void 0:d.videoHeight)?a:480;if(l<o||h<i)throw new t({code:r.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function updateValidateRule(e){return errorModule=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:__spreadValues({},TargetRule),encoding:__spreadValues({},EncodingRule),mix:__spreadValues({},MixRule)}}}function stopValidateRule(e){return errorModule=e.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","publish-mix-stream-to-room"]}}}}}}var cdnSeq=0,_CDNStreaming=class e{constructor(e){this.core=e,__publicField(this,"_mixTranscodeManager"),__publicField(this,"_publishCDNManager"),__publicField(this,"_pushStreamToRoomManager"),__publicField(this,"_core"),__publicField(this,"_modeOptions"),__publicField(this,"seq"),__publicField(this,"_log"),cdnSeq+=1,this.seq=cdnSeq,this._log=e.log.createChild({id:`${this.getAlias()}${cdnSeq}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${cdnSeq}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new MixTranscodeManager(e,this._log),this._publishCDNManager=new PublishCDNManager(e,this._log),this._pushStreamToRoomManager=new PushStreamToRoom(e,this._log)}getName(){return e.Name}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return startValidateRule(this._core);case"update":return updateValidateRule(this._core);case"stop":return stopValidateRule(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),"publish-mix-stream-to-room"===e.target.publishMode?this._pushStreamToRoomManager.startPushStreamToRoom(e):await this.doStart(e)}async update(e){const t=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(t,e),"publish-mix-stream-to-room"===e.target.publishMode?this._pushStreamToRoomManager.updatePushStreamToRoom(t):await this.doStart(t)}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;case"publish-mix-stream-to-room":this._pushStreamToRoomManager.stopPushStreamToRoom()}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)}}};__publicField(_CDNStreaming,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn",PublishMixStreamToRoom:"publish-mix-stream-to-room"}}),__publicField(_CDNStreaming,"Name","CDNStreaming");var CDNStreaming=_CDNStreaming,index_default=CDNStreaming;export{index_default as default};export{CDNStreaming};export const PublishMode=CDNStreaming.TYPE.PublishMode;
{
"name": "@rtc-plugin/cdn-streaming",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x CDN streaming plugin",
"main": "./cdn-streaming.esm.js",
"author": "longyuqi <longyuqi@tencent.com>",
"module": "./cdn-streaming.esm.js",

@@ -8,0 +7,0 @@ "repository": {

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

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

@@ -8,0 +7,0 @@ "repository": {

{
"name": "@rtc-plugin/device-detector",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x device detector plugin",
"main": "./device-detector.esm.js",
"author": "edwards <edwards@tencent.com>",
"module": "./device-detector.esm.js",

@@ -8,0 +7,0 @@ "repository": {

{
"name": "@rtc-plugin/video-decoder",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "Video decoder plugin for TRTC",

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

{
"name": "@rtc-plugin/basic-beauty",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x basic-beauty plugin",
"main": "./basic-beauty.esm.js",
"author": "longyuqi <longyuqi@tencent.com>",
"module": "./basic-beauty.esm.js",

@@ -8,0 +7,0 @@ "repository": {

{
"name": "@rtc-plugin/beauty",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x beauty plugin",
"main": "./beauty.esm.js",
"author": "longyuqi <longyuqi@tencent.com>",
"module": "./beauty.esm.js",

@@ -8,0 +7,0 @@ "repository": {

{
"name": "@rtc-plugin/virtual-background",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x virtual background plugin",
"main": "./virtual-background.esm.js",
"author": "longyuqi <longyuqi@tencent.com>",
"module": "./virtual-background.esm.js",

@@ -8,0 +7,0 @@ "repository": {

{
"name": "@rtc-plugin/watermark",
"version": "5.9.2-beta.4",
"version": "5.9.2-beta.5",
"description": "TRTC Web SDK 5.x watermark plugin",
"main": "./watermark.esm.js",
"author": "longyuqi <longyuqi@tencent.com>",
"module": "./watermark.esm.js",

@@ -8,0 +7,0 @@ "repository": {

@@ -1,4 +0,12 @@

import { WatermarkOptions } from '../src/enums';
export interface WatermarkOptions {
imageUrl: string;
x: number;
y: number;
size?: Size | number | 'contain' | 'cover';
}
export { WatermarkOptions };
export interface Size {
height?: number;
width?: number;
}

@@ -5,0 +13,0 @@ export declare class Watermark {

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

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

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

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

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

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