trtc-sdk-v5 5.13.0-beta.16 → 5.13.0-wasm.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/av_processing.wasm +0 -0
- package/assets/worker.js +17 -0
- package/index.d.ts +1 -25
- package/package.json +4 -6
- package/plugins/cdn-streaming/cdn-streaming.esm.js +1 -1
- package/plugins/cdn-streaming/cdn-streaming.umd.js +1 -1
- package/plugins/cdn-streaming/package.json +1 -1
- package/plugins/cross-room/cross-room.esm.js +1 -1
- package/plugins/cross-room/cross-room.umd.js +1 -1
- package/plugins/cross-room/package.json +1 -1
- package/plugins/custom-encryption/custom-encryption.esm.js +1 -1
- package/plugins/custom-encryption/custom-encryption.umd.js +1 -1
- package/plugins/custom-encryption/package.json +1 -1
- package/plugins/device-detector/device-detector.esm.js +14 -28
- package/plugins/device-detector/device-detector.umd.js +7 -21
- package/plugins/device-detector/package.json +1 -1
- package/plugins/small-stream-auto-switcher/package.json +1 -1
- package/plugins/small-stream-auto-switcher/small-stream-auto-switcher.esm.js +1 -1
- package/plugins/small-stream-auto-switcher/small-stream-auto-switcher.umd.js +1 -1
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-decoder/video-decoder.esm.js +1 -1
- package/plugins/video-decoder/video-decoder.umd.js +1 -1
- package/plugins/video-effect/basic-beauty/basic-beauty.esm.js +1 -1
- package/plugins/video-effect/basic-beauty/basic-beauty.umd.js +1 -1
- package/plugins/video-effect/basic-beauty/package.json +1 -1
- package/plugins/video-effect/beauty/beauty.esm.js +1 -1
- package/plugins/video-effect/beauty/beauty.umd.js +1 -1
- package/plugins/video-effect/beauty/package.json +1 -1
- package/plugins/video-effect/video-mixer/package.json +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.esm.js +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.umd.js +1 -1
- package/plugins/video-effect/virtual-background/package.json +1 -1
- package/plugins/video-effect/virtual-background/virtual-background.esm.js +1 -1
- package/plugins/video-effect/virtual-background/virtual-background.umd.js +1 -1
- package/plugins/video-effect/watermark/package.json +1 -1
- package/plugins/video-effect/watermark/watermark.esm.js +1 -1
- package/plugins/video-effect/watermark/watermark.umd.js +1 -1
- package/plugins/voice-changer/package.json +1 -1
- package/plugins/voice-changer/voice-changer.esm.js +1 -1
- package/plugins/voice-changer/voice-changer.umd.js +1 -1
- package/trtc.esm.js +65 -44
- package/trtc.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var errorModule,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__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)),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,m,h,u;e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;var l=1732584193,c=-271733879,p=-1732584194,g=271733878;for(o=0;o<e.length;o+=16)d=l,m=c,h=p,u=g,l=i(l,c,p,g,e[o],7,-680876936),g=i(g,l,c,p,e[o+1],12,-389564586),p=i(p,g,l,c,e[o+2],17,606105819),c=i(c,p,g,l,e[o+3],22,-1044525330),l=i(l,c,p,g,e[o+4],7,-176418897),g=i(g,l,c,p,e[o+5],12,1200080426),p=i(p,g,l,c,e[o+6],17,-1473231341),c=i(c,p,g,l,e[o+7],22,-45705983),l=i(l,c,p,g,e[o+8],7,1770035416),g=i(g,l,c,p,e[o+9],12,-1958414417),p=i(p,g,l,c,e[o+10],17,-42063),c=i(c,p,g,l,e[o+11],22,-1990404162),l=i(l,c,p,g,e[o+12],7,1804603682),g=i(g,l,c,p,e[o+13],12,-40341101),p=i(p,g,l,c,e[o+14],17,-1502002290),l=s(l,c=i(c,p,g,l,e[o+15],22,1236535329),p,g,e[o+1],5,-165796510),g=s(g,l,c,p,e[o+6],9,-1069501632),p=s(p,g,l,c,e[o+11],14,643717713),c=s(c,p,g,l,e[o],20,-373897302),l=s(l,c,p,g,e[o+5],5,-701558691),g=s(g,l,c,p,e[o+10],9,38016083),p=s(p,g,l,c,e[o+15],14,-660478335),c=s(c,p,g,l,e[o+4],20,-405537848),l=s(l,c,p,g,e[o+9],5,568446438),g=s(g,l,c,p,e[o+14],9,-1019803690),p=s(p,g,l,c,e[o+3],14,-187363961),c=s(c,p,g,l,e[o+8],20,1163531501),l=s(l,c,p,g,e[o+13],5,-1444681467),g=s(g,l,c,p,e[o+2],9,-51403784),p=s(p,g,l,c,e[o+7],14,1735328473),l=a(l,c=s(c,p,g,l,e[o+12],20,-1926607734),p,g,e[o+5],4,-378558),g=a(g,l,c,p,e[o+8],11,-2022574463),p=a(p,g,l,c,e[o+11],16,1839030562),c=a(c,p,g,l,e[o+14],23,-35309556),l=a(l,c,p,g,e[o+1],4,-1530992060),g=a(g,l,c,p,e[o+4],11,1272893353),p=a(p,g,l,c,e[o+7],16,-155497632),c=a(c,p,g,l,e[o+10],23,-1094730640),l=a(l,c,p,g,e[o+13],4,681279174),g=a(g,l,c,p,e[o],11,-358537222),p=a(p,g,l,c,e[o+3],16,-722521979),c=a(c,p,g,l,e[o+6],23,76029189),l=a(l,c,p,g,e[o+9],4,-640364487),g=a(g,l,c,p,e[o+12],11,-421815835),p=a(p,g,l,c,e[o+15],16,530742520),l=n(l,c=a(c,p,g,l,e[o+2],23,-995338651),p,g,e[o],6,-198630844),g=n(g,l,c,p,e[o+7],10,1126891415),p=n(p,g,l,c,e[o+14],15,-1416354905),c=n(c,p,g,l,e[o+5],21,-57434055),l=n(l,c,p,g,e[o+12],6,1700485571),g=n(g,l,c,p,e[o+3],10,-1894986606),p=n(p,g,l,c,e[o+10],15,-1051523),c=n(c,p,g,l,e[o+1],21,-2054922799),l=n(l,c,p,g,e[o+8],6,1873313359),g=n(g,l,c,p,e[o+15],10,-30611744),p=n(p,g,l,c,e[o+6],15,-1560198380),c=n(c,p,g,l,e[o+13],21,1309151649),l=n(l,c,p,g,e[o+4],6,-145523070),g=n(g,l,c,p,e[o+11],10,-1120210379),p=n(p,g,l,c,e[o+2],15,718787259),c=n(c,p,g,l,e[o+9],21,-343485551),l=r(l,d),c=r(c,m),p=r(p,h),g=r(g,u);return[l,c,p,g]}function m(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 h(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 u(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 l(e){return unescape(encodeURIComponent(e))}function c(e){return function(e){return m(d(h(e),8*e.length))}(l(e))}function p(e,t){return function(e,t){var r,o,i=h(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(h(t)),512+8*t.length),m(d(a.concat(o),640))}(l(e),l(t))}function g(e,t,r){return t?r?p(t,e):u(p(t,e)):r?c(e):u(c(e))}"function"==typeof define&&define.amd?define((function(){return g})):"object"==typeof t&&t.exports?t.exports=g:e.md5=g}(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{_core;_room;_log;_params;_publishGivenCDNData=null;get isPublishingGivenCDN(){return!!this._params}constructor(e,t){this._core=e,this._room=e.room,this._log=t}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(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{_core;_room;_log;_config=null;_data=null;_givenCDNManager;get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){return this._config?.target.appId&&this._config?.target.bizId&&this._config?.target.url}constructor(e,t){this._core=e,this._room=e.room,this._log=t,this.reset()}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{_room;_core;_log;_paramsForTencentCDN;_initParamsForTencentCDN={isPublished:!1,isStarted:!1};constructor(e,t){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}){if(e.room!==this._room)return;if(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${e?.room?.roomId}`),1===e.mediaType)return;const t=4===e.mediaType?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",r=this._paramsForTencentCDN.get(t)||null;r?.target&&r.isStarted&&await this.startPublishTencentCDN(r.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),...t};this._paramsForTencentCDN.set(e,r)}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;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;r?.bizId&&r.appId&&r.url&&t?.givenCDNManager&&await(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{_core;_room;_log;_seq;_taskId=null;_startData=null;_updateData=null;_stopData=null;constructor(e,t){this._core=e,this._room=e.room,this._log=t,this._seq=0}async startPushStreamToRoom(e){this._seq+=1,this._startData={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 t=await this._room.sendStartPushStreamToRoom(this._startData),{code:r,message:o}=t.data;0===r?(this._taskId=t.data?.data?.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",r,`can't resolve task id: ${JSON.stringify(t.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",r,o)}async updatePushStreamToRoom(e){this._seq+=1,this._updateData={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(t?.roomId||t?.strRoomId)||this._room.roomId,roomType:t?.roomId?0:1,pushRobotUserid: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: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: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:{...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:{...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:{...UserRule}},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:{...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:{...TargetRule},encoding:{...EncodingRule},mix:{...MixRule}},validate(t,r,o,i){const{publishMode:s}=t.target,{encoding:a,mix:n}=t;if("publish-mix-stream-to-cdn"===s){const{RtcError:t,ErrorCode:r,ErrorCodeDictionary:i}=e.errorModule;if(!a)throw new t({code:r.INVALID_PARAMETER,extraCode:i.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"encoding"}});if(!n)throw new t({code:r.INVALID_PARAMETER,extraCode:i.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"mix"}});if(n&&n.videoLayoutList){let o=0,i=0;const s=[];if(n.videoLayoutList.forEach(((e,t)=>{s.push(e.fixedVideoUser.userId),e.width+e.locationX>o&&(o=e.width+e.locationX),e.height+e.locationY>i&&(i=e.height+e.locationY)})),s.indexOf(e.room.userId)<0)throw new t({code:r.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});if((a?.videoWidth??640)<o||(a?.videoHeight??480)<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:{...TargetRule},encoding:{...EncodingRule},mix:{...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,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)}static 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"}};_mixTranscodeManager;_publishCDNManager;_pushStreamToRoomManager;_core;_modeOptions;seq;_log;static Name="CDNStreaming";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)}}},index_default=CDNStreaming;export{index_default as default};export{CDNStreaming};export const PublishMode=CDNStreaming.TYPE.PublishMode;
|
|
1
|
+
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CDNStreaming=e()}(this,(function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function s(t){e(a,o,i,s,u,"next",t)}function u(t){e(a,o,i,s,u,"throw",t)}s(void 0)}))}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,d(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))||r){n&&(e=n);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var t=n.next();return s=t.done,t},e:function(t){u=!0,a=t},f:function(){try{s||null==n.return||n.return()}finally{if(u)throw a}}}}function a(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(){c=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function d(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(t){d=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var i=e&&e.prototype instanceof b?e:b,a=Object.create(i.prototype),s=new M(n||[]);return o(a,"_invoke",{value:w(t,r,s)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var m="suspendedStart",p="suspendedYield",f="executing",v="completed",g={};function b(){}function y(){}function _(){}var S={};d(S,a,(function(){return this}));var I=Object.getPrototypeOf,x=I&&I(I(E([])));x&&x!==r&&n.call(x,a)&&(S=x);var C=_.prototype=b.prototype=Object.create(S);function D(t){["next","throw","return"].forEach((function(e){d(t,e,(function(t){return this._invoke(e,t)}))}))}function N(t,e){function r(o,i,a,s){var u=l(t[o],t,i);if("throw"!==u.type){var c=u.arg,d=c.value;return d&&"object"==typeof d&&n.call(d,"__await")?e.resolve(d.__await).then((function(t){r("next",t,a,s)}),(function(t){r("throw",t,a,s)})):e.resolve(d).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,s)}))}s(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function w(e,r,n){var o=m;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var u=P(s,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===m)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=f;var c=l(e,r,n);if("normal"===c.type){if(o=n.done?v:p,c.arg===g)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=v,n.method="throw",n.arg=c.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function M(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function E(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return y.prototype=_,o(C,"constructor",{value:_,configurable:!0}),o(_,"constructor",{value:y,configurable:!0}),y.displayName=d(_,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,_):(t.__proto__=_,d(t,u,"GeneratorFunction")),t.prototype=Object.create(C),t},e.awrap=function(t){return{__await:t}},D(N.prototype),d(N.prototype,s,(function(){return this})),e.AsyncIterator=N,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new N(h(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},D(C),d(C,u,"Generator"),d(C,a,(function(){return this})),d(C,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=E,M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return s.type="throw",s.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:E(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function d(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}function h(t){return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},h(t)}var l,m,p,f,v=Object.create,g=Object.defineProperty,b=Object.getOwnPropertyDescriptor,y=Object.getOwnPropertyNames,_=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty,I=function(t,e,r){return r=null!=t?v(_(t)):{},function(t,e,r,n){if(e&&"object"===h(e)||"function"==typeof e){var o,a=i(y(e));try{var s=function(){var i=o.value;S.call(t,i)||i===r||g(t,i,{get:function(){return e[i]},enumerable:!(n=b(e,i))||n.enumerable})};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}}return t}(g(r,"default",{value:t,enumerable:!0}),t)},x=(m={"../node_modules/.pnpm/blueimp-md5@2.19.0/node_modules/blueimp-md5/js/md5.js":function(t,e){!function(t){function r(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function n(t,e,n,o,i,a){return r((s=r(r(e,t),r(o,a)))<<(u=i)|s>>>32-u,n);var s,u}function o(t,e,r,o,i,a,s){return n(e&r|~e&o,t,e,i,a,s)}function i(t,e,r,o,i,a,s){return n(e&o|r&~o,t,e,i,a,s)}function a(t,e,r,o,i,a,s){return n(e^r^o,t,e,i,a,s)}function s(t,e,r,o,i,a,s){return n(r^(e|~o),t,e,i,a,s)}function u(t,e){var n,u,c,d,h;t[e>>5]|=128<<e%32,t[14+(e+64>>>9<<4)]=e;var l=1732584193,m=-271733879,p=-1732584194,f=271733878;for(n=0;n<t.length;n+=16)u=l,c=m,d=p,h=f,l=o(l,m,p,f,t[n],7,-680876936),f=o(f,l,m,p,t[n+1],12,-389564586),p=o(p,f,l,m,t[n+2],17,606105819),m=o(m,p,f,l,t[n+3],22,-1044525330),l=o(l,m,p,f,t[n+4],7,-176418897),f=o(f,l,m,p,t[n+5],12,1200080426),p=o(p,f,l,m,t[n+6],17,-1473231341),m=o(m,p,f,l,t[n+7],22,-45705983),l=o(l,m,p,f,t[n+8],7,1770035416),f=o(f,l,m,p,t[n+9],12,-1958414417),p=o(p,f,l,m,t[n+10],17,-42063),m=o(m,p,f,l,t[n+11],22,-1990404162),l=o(l,m,p,f,t[n+12],7,1804603682),f=o(f,l,m,p,t[n+13],12,-40341101),p=o(p,f,l,m,t[n+14],17,-1502002290),l=i(l,m=o(m,p,f,l,t[n+15],22,1236535329),p,f,t[n+1],5,-165796510),f=i(f,l,m,p,t[n+6],9,-1069501632),p=i(p,f,l,m,t[n+11],14,643717713),m=i(m,p,f,l,t[n],20,-373897302),l=i(l,m,p,f,t[n+5],5,-701558691),f=i(f,l,m,p,t[n+10],9,38016083),p=i(p,f,l,m,t[n+15],14,-660478335),m=i(m,p,f,l,t[n+4],20,-405537848),l=i(l,m,p,f,t[n+9],5,568446438),f=i(f,l,m,p,t[n+14],9,-1019803690),p=i(p,f,l,m,t[n+3],14,-187363961),m=i(m,p,f,l,t[n+8],20,1163531501),l=i(l,m,p,f,t[n+13],5,-1444681467),f=i(f,l,m,p,t[n+2],9,-51403784),p=i(p,f,l,m,t[n+7],14,1735328473),l=a(l,m=i(m,p,f,l,t[n+12],20,-1926607734),p,f,t[n+5],4,-378558),f=a(f,l,m,p,t[n+8],11,-2022574463),p=a(p,f,l,m,t[n+11],16,1839030562),m=a(m,p,f,l,t[n+14],23,-35309556),l=a(l,m,p,f,t[n+1],4,-1530992060),f=a(f,l,m,p,t[n+4],11,1272893353),p=a(p,f,l,m,t[n+7],16,-155497632),m=a(m,p,f,l,t[n+10],23,-1094730640),l=a(l,m,p,f,t[n+13],4,681279174),f=a(f,l,m,p,t[n],11,-358537222),p=a(p,f,l,m,t[n+3],16,-722521979),m=a(m,p,f,l,t[n+6],23,76029189),l=a(l,m,p,f,t[n+9],4,-640364487),f=a(f,l,m,p,t[n+12],11,-421815835),p=a(p,f,l,m,t[n+15],16,530742520),l=s(l,m=a(m,p,f,l,t[n+2],23,-995338651),p,f,t[n],6,-198630844),f=s(f,l,m,p,t[n+7],10,1126891415),p=s(p,f,l,m,t[n+14],15,-1416354905),m=s(m,p,f,l,t[n+5],21,-57434055),l=s(l,m,p,f,t[n+12],6,1700485571),f=s(f,l,m,p,t[n+3],10,-1894986606),p=s(p,f,l,m,t[n+10],15,-1051523),m=s(m,p,f,l,t[n+1],21,-2054922799),l=s(l,m,p,f,t[n+8],6,1873313359),f=s(f,l,m,p,t[n+15],10,-30611744),p=s(p,f,l,m,t[n+6],15,-1560198380),m=s(m,p,f,l,t[n+13],21,1309151649),l=s(l,m,p,f,t[n+4],6,-145523070),f=s(f,l,m,p,t[n+11],10,-1120210379),p=s(p,f,l,m,t[n+2],15,718787259),m=s(m,p,f,l,t[n+9],21,-343485551),l=r(l,u),m=r(m,c),p=r(p,d),f=r(f,h);return[l,m,p,f]}function c(t){var e,r="",n=32*t.length;for(e=0;e<n;e+=8)r+=String.fromCharCode(t[e>>5]>>>e%32&255);return r}function d(t){var e,r=[];for(r[(t.length>>2)-1]=void 0,e=0;e<r.length;e+=1)r[e]=0;var n=8*t.length;for(e=0;e<n;e+=8)r[e>>5]|=(255&t.charCodeAt(e/8))<<e%32;return r}function l(t){var e,r,n="0123456789abcdef",o="";for(r=0;r<t.length;r+=1)e=t.charCodeAt(r),o+=n.charAt(e>>>4&15)+n.charAt(15&e);return o}function m(t){return unescape(encodeURIComponent(t))}function p(t){return function(t){return c(u(d(t),8*t.length))}(m(t))}function f(t,e){return function(t,e){var r,n,o=d(t),i=[],a=[];for(i[15]=a[15]=void 0,o.length>16&&(o=u(o,8*t.length)),r=0;r<16;r+=1)i[r]=909522486^o[r],a[r]=1549556828^o[r];return n=u(i.concat(d(e)),512+8*e.length),c(u(a.concat(n),640))}(m(t),m(e))}function v(t,e,r){return e?r?f(e,t):l(f(e,t)):r?p(t):l(p(t))}"function"==typeof define&&define.amd?define((function(){return v})):"object"===h(e)&&e.exports?e.exports=v:t.md5=v}(t)}},function(){return p||(0,m[y(m)[0]])((p={exports:{}}).exports,p),p.exports}),C=I(x()),D=0,N=4,w=5,P=function(){return o((function t(e,r){n(this,t),a(this,"_core",void 0),a(this,"_room",void 0),a(this,"_log",void 0),a(this,"_params",void 0),a(this,"_publishGivenCDNData",null),this._core=e,this._room=e.room,this._log=r}),[{key:"isPublishingGivenCDN",get:function(){return!!this._params}},{key:"startPublishGivenCDN",value:(e=r(c().mark((function t(e){var r,n,o,i,a,s,u,d;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] startPublishGivenCDN() current: ".concat(JSON.stringify(this._params),", params: ").concat(JSON.stringify(e))),!this.isPublishingGivenCDN){t.next=7;break}if(r=this._params||{},n=r.appId,o=r.bizId,i=r.url,n!==e.appId||o!==e.bizId||i!==e.url){t.next=5;break}return t.abrupt("return");case 5:return t.next=7,this.stopPublishGivenCDN();case 7:return 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},t.prev=9,t.next=12,this._room.sendStartPublishCDN(this._publishGivenCDNData,!1);case 12:if(a=t.sent,s=a.data,u=s.code,d=s.message,0!==u){t.next=18;break}this._log.info("[CDNStreaming] server success: start given cdn."),t.next=21;break;case 18:throw this.resetGivenCDN(),this._log.error("[CDNStreaming] server failed: start given cdn errCode: ".concat(u," errMsg: ").concat(d," options: ").concat(JSON.stringify(e))),new Error("[CDNStreaming] server failed: start given cdn errCode: ".concat(u," errMsg: ").concat(d));case 21:t.next=27;break;case 23:throw t.prev=23,t.t0=t.catch(9),this.resetGivenCDN(),t.t0;case 27:case"end":return t.stop()}}),t,this,[[9,23]])}))),function(t){return e.apply(this,arguments)})},{key:"stopPublishGivenCDN",value:(t=r(c().mark((function t(){var e,r,n,o,i,a,s,u,d,h,l;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),this.isPublishingGivenCDN&&this._publishGivenCDNData){t.next=4;break}return this.resetGivenCDN(),t.abrupt("return");case 4:return e=this._publishGivenCDNData,r=e.pushAppId,n=e.pushBizId,o=e.pushCdnUrl,i=e.pushStreamType,a=e.pushStreamId,s={pushRequestTime:Date.now(),pushAppId:r,pushBizId:n,pushCdnUrl:o,pushStreamType:i,pushStreamId:a},t.next=8,this._room.sendStopPublishCDN(s,!1);case 8:if(u=t.sent,d=u.data,h=d.code,l=d.message,0!==h){t.next=15;break}this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN(),t.next=17;break;case 15:throw this._log.error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(h," errMsg: ").concat(l," data: ").concat(JSON.stringify(s))),new Error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(h," errMsg: ").concat(l));case 17:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"resetGivenCDN",value:function(){this._publishGivenCDNData=null,this._params=void 0}},{key:"convertStreamType",value:function(t){return"publish-sub-stream-to-cdn"===t?"aux":"main"}}]);var t,e}(),k=function(){return o((function t(e,r){n(this,t),a(this,"_core",void 0),a(this,"_room",void 0),a(this,"_log",void 0),a(this,"_config",null),a(this,"_data",null),a(this,"_givenCDNManager",void 0),this._core=e,this._room=e.room,this._log=r,this.reset()}),[{key:"isMixing",get:function(){return!!this._data}},{key:"isStarted",get:function(){return!!this._config}},{key:"hasCustomCDN",get:function(){var t,e,r;return(null===(t=this._config)||void 0===t?void 0:t.target.appId)&&(null===(e=this._config)||void 0===e?void 0:e.target.bizId)&&(null===(r=this._config)||void 0===r?void 0:r.target.url)}},{key:"startMixTranscode",value:(d=r(c().mark((function t(e){var r,n,o,i,a,s,u,d,h;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("startMixTranscode: ".concat(JSON.stringify(e))),this._config=e,this.installEvents(),this._core.room.isJoined){t.next=5;break}return t.abrupt("return");case 5:if(t.prev=5,r=this.getInputParam(e),n=this.getOutputParam(e),o=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId}),!this.isMixing||!this._data||o===this._data.outputSessionId){t.next=13;break}return this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),t.next=13,this.doStopMixTranscode();case 13:return t.next=15,this.doStartMixTranscode({outputSessionId:o,inputParam:r,outputParam:n});case 15:if(i=e.target,a=i.appId,s=i.bizId,u=i.url,d=i.streamId,h=void 0===d?"":d,!(a&&s&&u)){t.next=20;break}return this._givenCDNManager||(this._givenCDNManager=new P(this._core,this._log)),t.next=20,this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:a,bizId:s,url:u,streamId:h});case 20:t.next=26;break;case 22:throw t.prev=22,t.t0=t.catch(5),this.reset(),t.t0;case 26:case"end":return t.stop()}}),t,this,[[5,22]])}))),function(t){return d.apply(this,arguments)})},{key:"doStartMixTranscode",value:(u=r(c().mark((function t(e){var r,n,o,i,a,s,u;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.outputSessionId,n=e.inputParam,o=e.outputParam,i={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:r,inputParam:n,outputParam:o},this._log.info("[CDNStreaming] doStartMixTranscode: ".concat(JSON.stringify(i))),t.next=5,this._room.sendStartMixTranscode(i);case 5:if(a=t.sent,s=a.data.code,u=a.data.message,0!==s){t.next=13;break}this._log.info("[CDNStreaming] server success: start mix"),this._data=i,t.next=16;break;case 13:throw-102083===s&&(u="Please enable relayed-push in ".concat(this._core.constants.CLOUD_CONSOLE_URL," and try later, refer to ").concat(this._core.constants.DOC_URL,"tutorial-26-advanced-publish-cdn-stream.html")),this._log.error("[CDNStreaming] server failed: start mix errCode: ".concat(s," errMsg: ").concat(u)),new Error("[CDNStreaming] server failed: start mix errCode: ".concat(s," errMsg: ").concat(u));case 16:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"stopMixTranscode",value:(s=r(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] stopMixTranscode"),t.prev=1,!this.isStarted||!this.isMixing){t.next=8;break}return t.next=5,this.doStopMixTranscode();case 5:if(!(this._config&&this.hasCustomCDN&&this._givenCDNManager)){t.next=8;break}return t.next=8,this._givenCDNManager.stopPublishGivenCDN();case 8:t.next=13;break;case 10:throw t.prev=10,t.t0=t.catch(1),t.t0;case 13:this.reset();case 14:case"end":return t.stop()}}),t,this,[[1,10]])}))),function(){return s.apply(this,arguments)})},{key:"doStopMixTranscode",value:(i=r(c().mark((function t(){var e,r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType},this._log.info("[CDNStreaming] doStopMixTranscode: ".concat(JSON.stringify(e))),t.next=4,this._room.sendStopMixTranscode(e);case 4:if(r=t.sent,n=r.data,o=n.code,i=n.message,0!==o){t.next=11;break}this._log.info("[CDNStreaming] server success: stop mix"),this.reset(),t.next=13;break;case 11:throw this._log.error("[CDNStreaming] server failed: stop mix errCode: ".concat(o," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop mix errCode: ".concat(o," errMsg: ").concat(i));case 13:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})},{key:"reset",value:function(){this._config=null,this._data=null,this.uninstallEvents()}},{key:"installEvents",value:function(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}},{key:"uninstallEvents",value:function(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}},{key:"handleRoomJoined",value:(e=r(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] handleJoined: ".concat(JSON.stringify(this._config))),!this.isStarted||!this._config){t.next=4;break}return t.next=4,this.startMixTranscode(this._config);case 4:case"end":return t.stop()}}),t,this)}))),function(){return e.apply(this,arguments)})},{key:"handleRoomLeft",value:(t=r(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] handleRoomLeft: ".concat(JSON.stringify(this._config))),this._data=null;case 2:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"getOutputSessionId",value:function(t){var e=t.config,r=t.userId,n=t.roomId;return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,C.default)("".concat(n,"_").concat(r,"_main"))}},{key:"getStringRoomId",value:function(t,e){return t?String(t):e}},{key:"getInputParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=n.audioMixUserList,i=void 0===o?[]:o,a=n.videoLayoutList,s=(void 0===a?[]:a).map((function(t){return{userId:t.fixedVideoUser.userId,roomId:e.getStringRoomId(t.fixedVideoUser.roomId,t.fixedVideoUser.strRoomId)||e._core.room.roomId,width:t.width||0,height:t.height||0,locationX:t.locationX||0,locationY:t.locationY||0,zOrder:t.zOrder||1,streamType:"sub"===t.fixedVideoStreamType?1:0,inputType:w,renderMode:t.fillMode||0}}));return i.forEach((function(t){var r=e._core.room.roomId;(t.roomId||t.strRoomId)&&(r=e.getStringRoomId(t.roomId,t.strRoomId));var n=s.findIndex((function(e){return e.userId===t.userId&&e.roomId===r}));-1!==n?s[n].inputType=D:s.push({userId:t.userId,roomId:t.roomId||t.strRoomId||e._core.room.roomId,inputType:N})})),s}},{key:"getOutputParam",value:function(t){var e=t.target.streamId||"",r=t.encoding,n=void 0===r?{}:r,o=t.mix,i=void 0===o?{}:o;return{streamId:e,streamType:e.length>0?1:0,width:this._core.utils.isUndefined(n.videoWidth)?640:n.videoWidth,height:this._core.utils.isUndefined(n.videoHeight)?480:n.videoHeight,videoBps:n.videoBitrate||0,fps:n.videoFramerate||15,gop:n.videoGOP||2,audioSampleRate:n.audioSampleRate||48e3,audioBps:n.audioBitrate||64,audioChannels:n.audioChannels||1,backgroundColor:i.backgroundColor||0,backgroundImg:i.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}}]);var t,e,i,s,u,d}(),T=I(x()),M=function(){return o((function t(e,r){n(this,t),a(this,"_room",void 0),a(this,"_core",void 0),a(this,"_log",void 0),a(this,"_paramsForTencentCDN",void 0),a(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]])}),[{key:"installEvents",value:function(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}},{key:"uninstallEvents",value:function(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}},{key:"handlePublished",value:(h=r(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if((n=e.track).room===this._room){t.next=3;break}return t.abrupt("return");case 3:if(this._log.info("[CDNStreaming] handlePublished: mediaType ".concat(n.mediaType,", roomID ").concat(null==n||null===(r=n.room)||void 0===r?void 0:r.roomId)),1!==n.mediaType){t.next=6;break}return t.abrupt("return");case 6:if(o=4===n.mediaType?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",null==(i=this._paramsForTencentCDN.get(o)||null)||!i.target||!i.isStarted){t.next=11;break}return t.next=11,this.startPublishTencentCDN(i.target);case 11:case"end":return t.stop()}}),t,this)}))),function(t){return h.apply(this,arguments)})},{key:"handleRoomLeft",value:(d=r(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1});case 3:case"end":return t.stop()}}),t,this)}))),function(){return d.apply(this,arguments)})},{key:"isStreamPublished",value:function(t){return"publish-main-stream-to-cdn"!==t||this._room.isMainStreamPublished?!("publish-sub-stream-to-cdn"===t&&!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)}},{key:"changeDataStatus",value:function(t,e){var r=u(u({},this._paramsForTencentCDN.get(t)),e);this._paramsForTencentCDN.set(t,r)}},{key:"startPublishTencentCDN",value:(s=r(c().mark((function t(e){var r,n,o,i,a,s,u,d,h;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] startPublishTencentCDN ".concat(JSON.stringify(e))),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),this.isStreamPublished(e.publishMode)){t.next=5;break}return t.abrupt("return");case 5:return r=e.streamId||"",n=this.generatePublishCDNStreamId(r,e.publishMode),o=this.generatePublishCDNSessionId(e.publishMode),i="publish-sub-stream-to-cdn"===e.publishMode?1:0,a={requestTime:Date.now(),sessionId:o,streamId:n,streamType:i},t.next=12,this.doStartPublishTencentCDN(a,e.publishMode);case 12:if(s=e.appId,u=e.bizId,d=e.url,!(s&&u&&d)){t.next=18;break}return null!=(h=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN)&&h.givenCDNManager||(h.givenCDNManager=new P(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,h)),t.next=18,h.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:s,bizId:u,url:d,streamId:n});case 18:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"doStartPublishTencentCDN",value:(i=r(c().mark((function t(e,r){var n,o,i,a,s,u;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),n=6,o=500,i=0;case 4:return t.next=7,this._room.sendStartPublishCDN(e,!0);case 7:if(a=t.sent,s=a.data.code,u=a.data.message,0!==s){t.next=16;break}return this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(r,{isPublished:!0}),t.abrupt("break",29);case 16:if(!(-10006===s&&i<n)){t.next=23;break}return this._log.warn("[CDNStreaming] doStartPublishTencentCDN: retry...".concat(i+1,"/6, reason: ").concat(u)),i+=1,t.next=21,new Promise((function(t){return setTimeout(t,o)}));case 21:t.next=27;break;case 23:throw this.changeDataStatus(r,{isPublished:!1}),-102083===s&&(u="Please enable relayed-push in ".concat(this._core.constants.CLOUD_CONSOLE_URL," and try later, refer to ").concat(this._core.constants.DOC_URL,"tutorial-26-advanced-publish-cdn-stream.html")),this._log.error("[CDNStreaming] server failed: start tencent cdn errCode: ".concat(s," errMsg: ").concat(u)),new Error("[CDNStreaming] server failed: start tencent cdn errCode: ".concat(s," errMsg: ").concat(u));case 27:t.next=4;break;case 29:case"end":return t.stop()}}),t,this)}))),function(t,e){return i.apply(this,arguments)})},{key:"stopPublishTencentCDN",value:(e=r(c().mark((function t(e){var r,n;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),!(r=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN).isPublished){t.next=9;break}if(!(null!=(n=r.target)&&n.bizId&&n.appId&&n.url&&null!=r&&r.givenCDNManager)){t.next=7;break}return t.next=7,null==r?void 0:r.givenCDNManager.stopPublishGivenCDN();case 7:return t.next=9,this.doStopPublishTencentCDN(e);case 9:this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"doStopPublishTencentCDN",value:(t=r(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={requestTime:Date.now(),sessionId:(0,T.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(e)))},this._log.info("[CDNStreaming] doStopPublishTencentCDN: ".concat(JSON.stringify(r))),t.next=4,this._room.sendStopPublishCDN(r,!0);case 4:if(n=t.sent,o=n.data.code,i=n.data.message,0!==o){t.next=13;break}this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e),t.next=16;break;case 13:throw-102069===o&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),i="can not stop in auto relayed-push mode ".concat(i)),this._log.error("[CDNStreaming] server failed: stop tencent cdn errCode: ".concat(o," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop tencent cdn errCode: ".concat(o," errMsg: ").concat(i));case 16:case"end":return t.stop()}}),t,this)}))),function(e){return t.apply(this,arguments)})},{key:"reset",value:function(t){this.uninstallEvents(),this._paramsForTencentCDN.set(t,this._initParamsForTencentCDN)}},{key:"generatePublishCDNStreamId",value:function(t,e){if(""===t){var r="".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(e));return/^[A-Za-z\d_-]*$/.test(r)||(r=(0,T.default)(r)),"".concat(this._room.sdkAppId,"_").concat(r)}return t}},{key:"convertPublishModeToStreamType",value:function(t){return"publish-main-stream-to-cdn"===t?"main":"aux"}},{key:"generatePublishCDNSessionId",value:function(t){return(0,T.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(t)))}}]);var t,e,i,s,d,h}(),E=I(x()),R=function(){return o((function t(e,r){n(this,t),a(this,"_core",void 0),a(this,"_room",void 0),a(this,"_log",void 0),a(this,"_seq",void 0),a(this,"_taskId",null),a(this,"_startData",null),a(this,"_updateData",null),a(this,"_stopData",null),this._core=e,this._room=e.room,this._log=r,this._seq=0}),[{key:"startPushStreamToRoom",value:(i=r(c().mark((function t(e){var r,n,o,i,a;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._startData=u({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,E.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_start")),agentParam:{cdnRobotUserid:"mcu_robot_".concat(this._room.roomId,"_").concat(this._room.userId)}},this.getCommonParams(e)),this._log.info("startPushStreamToRoom: ".concat(JSON.stringify(this._startData))),t.next=5,this._room.sendStartPushStreamToRoom(this._startData);case 5:r=t.sent,n=r.data,o=n.code,i=n.message,0===o?(this._taskId=null===(a=r.data)||void 0===a||null===(a=a.data)||void 0===a?void 0:a.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",o,"can't resolve task id: ".concat(JSON.stringify(r.data))),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",o,i);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"updatePushStreamToRoom",value:(e=r(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._updateData=u(u({taskid:this._taskId},this.getCommonParams(e)),{},{enableNtpSync:!0}),this._log.info("updatePushStreamToRoom: ".concat(JSON.stringify(this._updateData))),t.next=5,this._room.sendUpdatePushStreamToRoom(this._updateData);case 5:r=t.sent,n=r.data,o=n.code,i=n.message,0===o?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"stopPushStreamToRoom",value:(t=r(c().mark((function t(){var e,r,n,o;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info("stopPushStreamToRoom: ".concat(JSON.stringify(this._stopData))),t.next=5,this._room.sendStopPushStreamToRoom(this._stopData);case 5:e=t.sent,r=e.data,n=r.code,o=r.message,0===n?this._log.info("server success: start mix"):this.reportServerError("stopPushStreamToRoom",n,o);case 8:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"reportServerError",value:function(t,e,r){var n="server failed: ".concat(t," errCode: ").concat(e," errMsg: ").concat(r);throw this._log.error(n),new Error(n)}},{key:"getPushRtcRoomParams",value:function(t){var e=t.target.robotUser;return e?[{roomid:String((null==e?void 0:e.roomId)||(null==e?void 0:e.strRoomId))||this._room.roomId,roomType:null!=e&&e.roomId?0:1,pushRobotUserid:null==e?void 0:e.userId}]:[]}},{key:"getCommonParams",value:function(t){return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(t),videoParam:this.getVideoParam(t),pushRtcRoomParams:this.getPushRtcRoomParams(t),sequenceNumber:this._seq}}},{key:"getAudioParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=t.encoding,i=void 0===o?{}:o,a={audioSamplerate:i.audioSampleRate||48e3,audioBitrateKbps:i.audioBitrate||64,audioChannels:i.audioChannels||1},s=n.audioMixUserList;return{audioEncodeParam:a,mixAudioUsers:(null==s?void 0:s.map((function(t){return{roomid:String(t.roomId||t.strRoomId)||e._room.roomId,userid:t.userId,roomType:t.roomId?0:1}})))||[]}}},{key:"getVideoParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=t.encoding,i=void 0===o?{}:o,a={videoCodec:2,videoWidth:i.videoWidth||640,videoHeight:i.videoHeight||480,videoFramerate:i.videoFramerate||15,videoGop:i.videoGOP||2,videoBitrateKbps:i.videoBitrate||800},s=n.videoLayoutList;return{videoEncodeParam:a,layoutParams:(null==s?void 0:s.map((function(t){return{userMediaStream:{userInfo:{roomid:String(t.fixedVideoUser.roomId||t.fixedVideoUser.strRoomId)||e._room.roomId,userid:t.fixedVideoUser.userId,roomType:t.fixedVideoUser.roomId?0:1},streamType:"sub"===t.fixedVideoStreamType?1:0},imageWidth:t.width||0,imageHeight:t.height||0,locationX:t.locationX||0,locationY:t.locationY||0,imageZorder:t.zOrder||1,renderMode:t.fillMode||0}})))||[],backgroundColor:n.backgroundColor||0,backgroundImageUrl:n.backgroundImage||""}}}]);var t,e,i}();var O={type:"number",notLessThanZero:!0},L={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:function(t,e,r,n){var o=f,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;if("string"==typeof t)throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER_STRING,fnName:r,messageParams:{key:"roomId"}});if(void 0!==t&&!(/^[1-9]\d*$/.test(String(t))&&t<4294967295))throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER,fnName:r,messageParams:{key:"roomId"}})}},strRoomId:{type:"string",validate:function(t,e,r,n){var o=f,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(t))throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_STRING,fnName:r,messageParams:{key:"strRoomId"}})}}}},A={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:function(t,e,r,n){if(!/^[A-Za-z\d_-]*$/.test(t)){var o=f,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1},robotUser:u({},L)},validate:function(t,e,r,n){var o=t.publishMode,i=t.robotUser;if("publish-mix-stream-to-room"===o&&!i){var a=f;throw new(0,a.RtcError)({code:a.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},j={required:!1,type:"object",properties:{videoWidth:O,videoHeight:O,videoBitrate:u(u({},O),{},{allowEmpty:!1}),videoFramerate:{type:"number",validate:function(t,e,r,n){if(t<=0||t>30){var o=f;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate:function(t,e,r,n){if(t<1||t>8){var o=f;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:O,audioBitrate:{type:"number",validate:function(t,e,r,n){if(t<32||t>192){var o=f;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},G={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:u({},L)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:u({},L),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate:function(t,e,r,n){if(t<1||t>15){var o=f;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:O,height:O,locationX:O,locationY:O}}}}};var U=0,V=(l=function(){function t(e){n(this,t),a(this,"_mixTranscodeManager",void 0),a(this,"_publishCDNManager",void 0),a(this,"_pushStreamToRoomManager",void 0),a(this,"_core",void 0),a(this,"_modeOptions",void 0),a(this,"seq",void 0),a(this,"_log",void 0),this.core=e,U+=1,this.seq=U,this._log=e.log.createChild({id:"".concat(this.getAlias()).concat(U)}),this._log.info("[CDNStreaming] created id=".concat(this.getAlias()).concat(U)),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new k(e,this._log),this._publishCDNManager=new M(e,this._log),this._pushStreamToRoomManager=new R(e,this._log)}return o(t,[{key:"getName",value:function(){return t.Name}},{key:"getAlias",value:function(){return"cdn"}},{key:"getValidateRule",value:function(t){switch(t){case"start":return e=this._core,f=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:u({},A),encoding:u({},j),mix:u({},G)},validate:function(t,r,n,o){var i=t.target.publishMode,a=t.encoding,s=t.mix;if("publish-mix-stream-to-cdn"===i){var u=e.errorModule,c=u.RtcError,d=u.ErrorCode,h=u.ErrorCodeDictionary;if(!a)throw new c({code:d.INVALID_PARAMETER,extraCode:h.INVALID_PARAMETER_REQUIRED,fnName:n,messageParams:{key:"encoding"}});if(!s)throw new c({code:d.INVALID_PARAMETER,extraCode:h.INVALID_PARAMETER_REQUIRED,fnName:n,messageParams:{key:"mix"}});if(s&&s.videoLayoutList){var l,m,p=0,f=0,v=[];if(s.videoLayoutList.forEach((function(t,e){v.push(t.fixedVideoUser.userId),t.width+t.locationX>p&&(p=t.width+t.locationX),t.height+t.locationY>f&&(f=t.height+t.locationY)})),v.indexOf(e.room.userId)<0)throw new c({code:d.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});var g=null!==(l=null==a?void 0:a.videoWidth)&&void 0!==l?l:640,b=null!==(m=null==a?void 0:a.videoHeight)&&void 0!==m?m:480;if(g<p||b<f)throw new c({code:d.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}};case"update":return function(t){return f=t.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:u({},A),encoding:u({},j),mix:u({},G)}}}(this._core);case"stop":return function(t){return f=t.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"]}}}}}}(this._core)}var e}},{key:"getGroup",value:function(t){return t.target.publishMode}},{key:"start",value:(d=r(c().mark((function t(e){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._modeOptions.set(e.target.publishMode,e),"publish-mix-stream-to-room"!==e.target.publishMode){t.next=3;break}return t.abrupt("return",this._pushStreamToRoomManager.startPushStreamToRoom(e));case 3:return t.next=5,this.doStart(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)}))),function(t){return d.apply(this,arguments)})},{key:"update",value:(s=r(c().mark((function t(e){var r;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this._modeOptions.get(e.target.publishMode),this._core.utils.deepMerge(r,e),"publish-mix-stream-to-room"!==e.target.publishMode){t.next=4;break}return t.abrupt("return",this._pushStreamToRoomManager.updatePushStreamToRoom(r));case 4:return t.next=6,this.doStart(r);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"stop",value:(i=r(c().mark((function t(e){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=e.target.publishMode,t.next="publish-mix-stream-to-cdn"===t.t0?3:"publish-main-stream-to-cdn"===t.t0||"publish-sub-stream-to-cdn"===t.t0?6:"publish-mix-stream-to-room"===t.t0?9:11;break;case 3:return t.next=5,this._mixTranscodeManager.stopMixTranscode();case 5:return t.abrupt("break",11);case 6:return t.next=8,this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);case 8:return t.abrupt("break",11);case 9:return this._pushStreamToRoomManager.stopPushStreamToRoom(),t.abrupt("break",11);case 11:this._modeOptions.delete(e.target.publishMode);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"doStart",value:(e=r(c().mark((function t(e){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] doStart: ".concat(JSON.stringify(e))),t.t0=e.target.publishMode,t.next="publish-mix-stream-to-cdn"===t.t0?4:"publish-main-stream-to-cdn"===t.t0||"publish-sub-stream-to-cdn"===t.t0?7:10;break;case 4:return t.next=6,this._mixTranscodeManager.startMixTranscode(e);case 6:case 9:return t.abrupt("break",10);case 7:return t.next=9,this._publishCDNManager.startPublishTencentCDN(e.target);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]);var e,i,s,d}(),a(l,"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"}}),a(l,"Name","CDNStreaming"),l);return V}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CDNStreaming=e()}(this,(function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function s(t){e(a,o,i,s,u,"next",t)}function u(t){e(a,o,i,s,u,"throw",t)}s(void 0)}))}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))||r){n&&(e=n);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var t=n.next();return s=t.done,t},e:function(t){u=!0,a=t},f:function(){try{s||null==n.return||n.return()}finally{if(u)throw a}}}}function a(){a=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function h(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch(t){h=function(t,e,r){return t[e]=r}}function d(t,e,r,n){var i=e&&e.prototype instanceof b?e:b,a=Object.create(i.prototype),s=new M(n||[]);return o(a,"_invoke",{value:w(t,r,s)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=d;var m="suspendedStart",p="suspendedYield",f="executing",g="completed",v={};function b(){}function y(){}function _(){}var I={};h(I,s,(function(){return this}));var S=Object.getPrototypeOf,x=S&&S(S(E([])));x&&x!==r&&n.call(x,s)&&(I=x);var C=_.prototype=b.prototype=Object.create(I);function D(t){["next","throw","return"].forEach((function(e){h(t,e,(function(t){return this._invoke(e,t)}))}))}function N(t,e){function r(o,i,a,s){var u=l(t[o],t,i);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,s)}),(function(t){r("throw",t,a,s)})):e.resolve(h).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,s)}))}s(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function w(e,r,n){var o=m;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var u=P(s,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===m)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=f;var c=l(e,r,n);if("normal"===c.type){if(o=n.done?g:p,c.arg===v)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=g,n.method="throw",n.arg=c.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function M(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function E(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return y.prototype=_,o(C,"constructor",{value:_,configurable:!0}),o(_,"constructor",{value:y,configurable:!0}),y.displayName=h(_,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,_):(t.__proto__=_,h(t,c,"GeneratorFunction")),t.prototype=Object.create(C),t},e.awrap=function(t){return{__await:t}},D(N.prototype),h(N.prototype,u,(function(){return this})),e.AsyncIterator=N,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new N(d(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},D(C),h(C,c,"Generator"),h(C,s,(function(){return this})),h(C,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=E,M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return s.type="throw",s.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:E(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function s(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}var c,h,d,l=Object.create,m=Object.defineProperty,p=Object.defineProperties,f=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols,y=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,S=function(t,e,r){return e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},x=function(t,e){for(var r in e||(e={}))_.call(e,r)&&S(t,r,e[r]);if(b){var n,o=i(b(e));try{for(o.s();!(n=o.n()).done;){r=n.value;I.call(e,r)&&S(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t},C=function(t,e){return p(t,g(e))},D=function(t,e,r){return r=null!=t?l(y(t)):{},function(t,e,r,n){if(e&&"object"===u(e)||"function"==typeof e){var o,a=i(v(e));try{var s=function(){var i=o.value;_.call(t,i)||i===r||m(t,i,{get:function(){return e[i]},enumerable:!(n=f(e,i))||n.enumerable})};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}}return t}(m(r,"default",{value:t,enumerable:!0}),t)},N=function(t,e,r){return S(t,"symbol"!==u(e)?e+"":e,r)},w=(c={"../node_modules/.pnpm/blueimp-md5@2.19.0/node_modules/blueimp-md5/js/md5.js":function(t,e){!function(t){function r(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function n(t,e,n,o,i,a){return r((s=r(r(e,t),r(o,a)))<<(u=i)|s>>>32-u,n);var s,u}function o(t,e,r,o,i,a,s){return n(e&r|~e&o,t,e,i,a,s)}function i(t,e,r,o,i,a,s){return n(e&o|r&~o,t,e,i,a,s)}function a(t,e,r,o,i,a,s){return n(e^r^o,t,e,i,a,s)}function s(t,e,r,o,i,a,s){return n(r^(e|~o),t,e,i,a,s)}function c(t,e){var n,u,c,h,d;t[e>>5]|=128<<e%32,t[14+(e+64>>>9<<4)]=e;var l=1732584193,m=-271733879,p=-1732584194,f=271733878;for(n=0;n<t.length;n+=16)u=l,c=m,h=p,d=f,l=o(l,m,p,f,t[n],7,-680876936),f=o(f,l,m,p,t[n+1],12,-389564586),p=o(p,f,l,m,t[n+2],17,606105819),m=o(m,p,f,l,t[n+3],22,-1044525330),l=o(l,m,p,f,t[n+4],7,-176418897),f=o(f,l,m,p,t[n+5],12,1200080426),p=o(p,f,l,m,t[n+6],17,-1473231341),m=o(m,p,f,l,t[n+7],22,-45705983),l=o(l,m,p,f,t[n+8],7,1770035416),f=o(f,l,m,p,t[n+9],12,-1958414417),p=o(p,f,l,m,t[n+10],17,-42063),m=o(m,p,f,l,t[n+11],22,-1990404162),l=o(l,m,p,f,t[n+12],7,1804603682),f=o(f,l,m,p,t[n+13],12,-40341101),p=o(p,f,l,m,t[n+14],17,-1502002290),l=i(l,m=o(m,p,f,l,t[n+15],22,1236535329),p,f,t[n+1],5,-165796510),f=i(f,l,m,p,t[n+6],9,-1069501632),p=i(p,f,l,m,t[n+11],14,643717713),m=i(m,p,f,l,t[n],20,-373897302),l=i(l,m,p,f,t[n+5],5,-701558691),f=i(f,l,m,p,t[n+10],9,38016083),p=i(p,f,l,m,t[n+15],14,-660478335),m=i(m,p,f,l,t[n+4],20,-405537848),l=i(l,m,p,f,t[n+9],5,568446438),f=i(f,l,m,p,t[n+14],9,-1019803690),p=i(p,f,l,m,t[n+3],14,-187363961),m=i(m,p,f,l,t[n+8],20,1163531501),l=i(l,m,p,f,t[n+13],5,-1444681467),f=i(f,l,m,p,t[n+2],9,-51403784),p=i(p,f,l,m,t[n+7],14,1735328473),l=a(l,m=i(m,p,f,l,t[n+12],20,-1926607734),p,f,t[n+5],4,-378558),f=a(f,l,m,p,t[n+8],11,-2022574463),p=a(p,f,l,m,t[n+11],16,1839030562),m=a(m,p,f,l,t[n+14],23,-35309556),l=a(l,m,p,f,t[n+1],4,-1530992060),f=a(f,l,m,p,t[n+4],11,1272893353),p=a(p,f,l,m,t[n+7],16,-155497632),m=a(m,p,f,l,t[n+10],23,-1094730640),l=a(l,m,p,f,t[n+13],4,681279174),f=a(f,l,m,p,t[n],11,-358537222),p=a(p,f,l,m,t[n+3],16,-722521979),m=a(m,p,f,l,t[n+6],23,76029189),l=a(l,m,p,f,t[n+9],4,-640364487),f=a(f,l,m,p,t[n+12],11,-421815835),p=a(p,f,l,m,t[n+15],16,530742520),l=s(l,m=a(m,p,f,l,t[n+2],23,-995338651),p,f,t[n],6,-198630844),f=s(f,l,m,p,t[n+7],10,1126891415),p=s(p,f,l,m,t[n+14],15,-1416354905),m=s(m,p,f,l,t[n+5],21,-57434055),l=s(l,m,p,f,t[n+12],6,1700485571),f=s(f,l,m,p,t[n+3],10,-1894986606),p=s(p,f,l,m,t[n+10],15,-1051523),m=s(m,p,f,l,t[n+1],21,-2054922799),l=s(l,m,p,f,t[n+8],6,1873313359),f=s(f,l,m,p,t[n+15],10,-30611744),p=s(p,f,l,m,t[n+6],15,-1560198380),m=s(m,p,f,l,t[n+13],21,1309151649),l=s(l,m,p,f,t[n+4],6,-145523070),f=s(f,l,m,p,t[n+11],10,-1120210379),p=s(p,f,l,m,t[n+2],15,718787259),m=s(m,p,f,l,t[n+9],21,-343485551),l=r(l,u),m=r(m,c),p=r(p,h),f=r(f,d);return[l,m,p,f]}function h(t){var e,r="",n=32*t.length;for(e=0;e<n;e+=8)r+=String.fromCharCode(t[e>>5]>>>e%32&255);return r}function d(t){var e,r=[];for(r[(t.length>>2)-1]=void 0,e=0;e<r.length;e+=1)r[e]=0;var n=8*t.length;for(e=0;e<n;e+=8)r[e>>5]|=(255&t.charCodeAt(e/8))<<e%32;return r}function l(t){var e,r,n="0123456789abcdef",o="";for(r=0;r<t.length;r+=1)e=t.charCodeAt(r),o+=n.charAt(e>>>4&15)+n.charAt(15&e);return o}function m(t){return unescape(encodeURIComponent(t))}function p(t){return function(t){return h(c(d(t),8*t.length))}(m(t))}function f(t,e){return function(t,e){var r,n,o=d(t),i=[],a=[];for(i[15]=a[15]=void 0,o.length>16&&(o=c(o,8*t.length)),r=0;r<16;r+=1)i[r]=909522486^o[r],a[r]=1549556828^o[r];return n=c(i.concat(d(e)),512+8*e.length),h(c(a.concat(n),640))}(m(t),m(e))}function g(t,e,r){return e?r?f(e,t):l(f(e,t)):r?p(t):l(p(t))}"function"==typeof define&&define.amd?define((function(){return g})):"object"===u(e)&&e.exports?e.exports=g:t.md5=g}(t)}},function(){return h||(0,c[v(c)[0]])((h={exports:{}}).exports,h),h.exports}),P=D(w()),k=0,T=4,M=5,E=function(){return o((function t(e,r){n(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_params"),N(this,"_publishGivenCDNData",null),this._core=e,this._room=e.room,this._log=r}),[{key:"isPublishingGivenCDN",get:function(){return!!this._params}},{key:"startPublishGivenCDN",value:(e=r(a().mark((function t(e){var r,n,o,i,s,u,c,h;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] startPublishGivenCDN() current: ".concat(JSON.stringify(this._params),", params: ").concat(JSON.stringify(e))),!this.isPublishingGivenCDN){t.next=7;break}if(r=this._params||{},n=r.appId,o=r.bizId,i=r.url,n!==e.appId||o!==e.bizId||i!==e.url){t.next=5;break}return t.abrupt("return");case 5:return t.next=7,this.stopPublishGivenCDN();case 7:return 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},t.prev=9,t.next=12,this._room.sendStartPublishCDN(this._publishGivenCDNData,!1);case 12:if(s=t.sent,u=s.data,c=u.code,h=u.message,0!==c){t.next=18;break}this._log.info("[CDNStreaming] server success: start given cdn."),t.next=21;break;case 18:throw this.resetGivenCDN(),this._log.error("[CDNStreaming] server failed: start given cdn errCode: ".concat(c," errMsg: ").concat(h," options: ").concat(JSON.stringify(e))),new Error("[CDNStreaming] server failed: start given cdn errCode: ".concat(c," errMsg: ").concat(h));case 21:t.next=27;break;case 23:throw t.prev=23,t.t0=t.catch(9),this.resetGivenCDN(),t.t0;case 27:case"end":return t.stop()}}),t,this,[[9,23]])}))),function(t){return e.apply(this,arguments)})},{key:"stopPublishGivenCDN",value:(t=r(a().mark((function t(){var e,r,n,o,i,s,u,c,h,d,l;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),this.isPublishingGivenCDN&&this._publishGivenCDNData){t.next=4;break}return this.resetGivenCDN(),t.abrupt("return");case 4:return e=this._publishGivenCDNData,r=e.pushAppId,n=e.pushBizId,o=e.pushCdnUrl,i=e.pushStreamType,s=e.pushStreamId,u={pushRequestTime:Date.now(),pushAppId:r,pushBizId:n,pushCdnUrl:o,pushStreamType:i,pushStreamId:s},t.next=8,this._room.sendStopPublishCDN(u,!1);case 8:if(c=t.sent,h=c.data,d=h.code,l=h.message,0!==d){t.next=15;break}this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN(),t.next=17;break;case 15:throw this._log.error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(d," errMsg: ").concat(l," data: ").concat(JSON.stringify(u))),new Error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(d," errMsg: ").concat(l));case 17:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"resetGivenCDN",value:function(){this._publishGivenCDNData=null,this._params=void 0}},{key:"convertStreamType",value:function(t){return"publish-sub-stream-to-cdn"===t?"aux":"main"}}]);var t,e}(),R=function(){return o((function t(e,r){n(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_config",null),N(this,"_data",null),N(this,"_givenCDNManager"),this._core=e,this._room=e.room,this._log=r,this.reset()}),[{key:"isMixing",get:function(){return!!this._data}},{key:"isStarted",get:function(){return!!this._config}},{key:"hasCustomCDN",get:function(){var t,e,r;return(null==(t=this._config)?void 0:t.target.appId)&&(null==(e=this._config)?void 0:e.target.bizId)&&(null==(r=this._config)?void 0:r.target.url)}},{key:"startMixTranscode",value:(c=r(a().mark((function t(e){var r,n,o,i,s,u,c,h,d;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("startMixTranscode: ".concat(JSON.stringify(e))),this._config=e,this.installEvents(),this._core.room.isJoined){t.next=5;break}return t.abrupt("return");case 5:if(t.prev=5,r=this.getInputParam(e),n=this.getOutputParam(e),o=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId}),!this.isMixing||!this._data||o===this._data.outputSessionId){t.next=13;break}return this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),t.next=13,this.doStopMixTranscode();case 13:return t.next=15,this.doStartMixTranscode({outputSessionId:o,inputParam:r,outputParam:n});case 15:if(i=e.target,s=i.appId,u=i.bizId,c=i.url,h=i.streamId,d=void 0===h?"":h,!(s&&u&&c)){t.next=20;break}return this._givenCDNManager||(this._givenCDNManager=new E(this._core,this._log)),t.next=20,this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:s,bizId:u,url:c,streamId:d});case 20:t.next=26;break;case 22:throw t.prev=22,t.t0=t.catch(5),this.reset(),t.t0;case 26:case"end":return t.stop()}}),t,this,[[5,22]])}))),function(t){return c.apply(this,arguments)})},{key:"doStartMixTranscode",value:(u=r(a().mark((function t(e){var r,n,o,i,s,u,c;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.outputSessionId,n=e.inputParam,o=e.outputParam,i={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:r,inputParam:n,outputParam:o},this._log.info("[CDNStreaming] doStartMixTranscode: ".concat(JSON.stringify(i))),t.next=5,this._room.sendStartMixTranscode(i);case 5:if(s=t.sent,u=s.data.code,c=s.data.message,0!==u){t.next=13;break}this._log.info("[CDNStreaming] server success: start mix"),this._data=i,t.next=16;break;case 13:throw-102083===u&&(c="Please enable relayed-push in ".concat(this._core.constants.CLOUD_CONSOLE_URL," and try later, refer to ").concat(this._core.constants.DOC_URL,"tutorial-26-advanced-publish-cdn-stream.html")),this._log.error("[CDNStreaming] server failed: start mix errCode: ".concat(u," errMsg: ").concat(c)),new Error("[CDNStreaming] server failed: start mix errCode: ".concat(u," errMsg: ").concat(c));case 16:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"stopMixTranscode",value:(s=r(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] stopMixTranscode"),t.prev=1,!this.isStarted||!this.isMixing){t.next=8;break}return t.next=5,this.doStopMixTranscode();case 5:if(!(this._config&&this.hasCustomCDN&&this._givenCDNManager)){t.next=8;break}return t.next=8,this._givenCDNManager.stopPublishGivenCDN();case 8:t.next=13;break;case 10:throw t.prev=10,t.t0=t.catch(1),t.t0;case 13:this.reset();case 14:case"end":return t.stop()}}),t,this,[[1,10]])}))),function(){return s.apply(this,arguments)})},{key:"doStopMixTranscode",value:(i=r(a().mark((function t(){var e,r,n,o,i;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType},this._log.info("[CDNStreaming] doStopMixTranscode: ".concat(JSON.stringify(e))),t.next=4,this._room.sendStopMixTranscode(e);case 4:if(r=t.sent,n=r.data,o=n.code,i=n.message,0!==o){t.next=11;break}this._log.info("[CDNStreaming] server success: stop mix"),this.reset(),t.next=13;break;case 11:throw this._log.error("[CDNStreaming] server failed: stop mix errCode: ".concat(o," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop mix errCode: ".concat(o," errMsg: ").concat(i));case 13:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})},{key:"reset",value:function(){this._config=null,this._data=null,this.uninstallEvents()}},{key:"installEvents",value:function(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}},{key:"uninstallEvents",value:function(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}},{key:"handleRoomJoined",value:(e=r(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] handleJoined: ".concat(JSON.stringify(this._config))),!this.isStarted||!this._config){t.next=4;break}return t.next=4,this.startMixTranscode(this._config);case 4:case"end":return t.stop()}}),t,this)}))),function(){return e.apply(this,arguments)})},{key:"handleRoomLeft",value:(t=r(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] handleRoomLeft: ".concat(JSON.stringify(this._config))),this._data=null;case 2:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"getOutputSessionId",value:function(t){var e=t.config,r=t.userId,n=t.roomId;return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,P.default)("".concat(n,"_").concat(r,"_main"))}},{key:"getStringRoomId",value:function(t,e){return t?String(t):e}},{key:"getInputParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=n.audioMixUserList,i=void 0===o?[]:o,a=n.videoLayoutList,s=(void 0===a?[]:a).map((function(t){return{userId:t.fixedVideoUser.userId,roomId:e.getStringRoomId(t.fixedVideoUser.roomId,t.fixedVideoUser.strRoomId)||e._core.room.roomId,width:t.width||0,height:t.height||0,locationX:t.locationX||0,locationY:t.locationY||0,zOrder:t.zOrder||1,streamType:"sub"===t.fixedVideoStreamType?1:0,inputType:M,renderMode:t.fillMode||0}}));return i.forEach((function(t){var r=e._core.room.roomId;(t.roomId||t.strRoomId)&&(r=e.getStringRoomId(t.roomId,t.strRoomId));var n=s.findIndex((function(e){return e.userId===t.userId&&e.roomId===r}));-1!==n?s[n].inputType=k:s.push({userId:t.userId,roomId:t.roomId||t.strRoomId||e._core.room.roomId,inputType:T})})),s}},{key:"getOutputParam",value:function(t){var e=t.target.streamId||"",r=t.encoding,n=void 0===r?{}:r,o=t.mix,i=void 0===o?{}:o;return{streamId:e,streamType:e.length>0?1:0,width:this._core.utils.isUndefined(n.videoWidth)?640:n.videoWidth,height:this._core.utils.isUndefined(n.videoHeight)?480:n.videoHeight,videoBps:n.videoBitrate||0,fps:n.videoFramerate||15,gop:n.videoGOP||2,audioSampleRate:n.audioSampleRate||48e3,audioBps:n.audioBitrate||64,audioChannels:n.audioChannels||1,backgroundColor:i.backgroundColor||0,backgroundImg:i.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}}]);var t,e,i,s,u,c}(),O=D(w()),L=function(){return o((function t(e,r){n(this,t),N(this,"_room"),N(this,"_core"),N(this,"_log"),N(this,"_paramsForTencentCDN"),N(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]])}),[{key:"installEvents",value:function(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}},{key:"uninstallEvents",value:function(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}},{key:"handlePublished",value:(c=r(a().mark((function t(e){var r,n,o,i;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if((r=e.track).room===this._room){t.next=3;break}return t.abrupt("return");case 3:if(this._log.info("[CDNStreaming] handlePublished: mediaType ".concat(r.mediaType,", roomID ").concat(null==(n=null==r?void 0:r.room)?void 0:n.roomId)),1!==r.mediaType){t.next=6;break}return t.abrupt("return");case 6:if(o=4===r.mediaType?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",!(null==(i=this._paramsForTencentCDN.get(o)||null)?void 0:i.target)||!i.isStarted){t.next=11;break}return t.next=11,this.startPublishTencentCDN(i.target);case 11:case"end":return t.stop()}}),t,this)}))),function(t){return c.apply(this,arguments)})},{key:"handleRoomLeft",value:(u=r(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1});case 3:case"end":return t.stop()}}),t,this)}))),function(){return u.apply(this,arguments)})},{key:"isStreamPublished",value:function(t){return"publish-main-stream-to-cdn"!==t||this._room.isMainStreamPublished?!("publish-sub-stream-to-cdn"===t&&!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)}},{key:"changeDataStatus",value:function(t,e){var r=this._paramsForTencentCDN.get(t),n=x(x({},r),e);this._paramsForTencentCDN.set(t,n)}},{key:"startPublishTencentCDN",value:(s=r(a().mark((function t(e){var r,n,o,i,s,u,c,h,d;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] startPublishTencentCDN ".concat(JSON.stringify(e))),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),this.isStreamPublished(e.publishMode)){t.next=5;break}return t.abrupt("return");case 5:return r=e.streamId||"",n=this.generatePublishCDNStreamId(r,e.publishMode),o=this.generatePublishCDNSessionId(e.publishMode),i="publish-sub-stream-to-cdn"===e.publishMode?1:0,s={requestTime:Date.now(),sessionId:o,streamId:n,streamType:i},t.next=12,this.doStartPublishTencentCDN(s,e.publishMode);case 12:if(u=e.appId,c=e.bizId,h=e.url,!(u&&c&&h)){t.next=18;break}return(null==(d=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN)?void 0:d.givenCDNManager)||(d.givenCDNManager=new E(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,d)),t.next=18,d.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:u,bizId:c,url:h,streamId:n});case 18:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"doStartPublishTencentCDN",value:(i=r(a().mark((function t(e,r){var n,o,i,s,u,c;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),n=6,o=500,i=0;case 4:return t.next=7,this._room.sendStartPublishCDN(e,!0);case 7:if(s=t.sent,u=s.data.code,c=s.data.message,0!==u){t.next=16;break}return this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(r,{isPublished:!0}),t.abrupt("break",29);case 16:if(!(-10006===u&&i<n)){t.next=23;break}return this._log.warn("[CDNStreaming] doStartPublishTencentCDN: retry...".concat(i+1,"/6, reason: ").concat(c)),i+=1,t.next=21,new Promise((function(t){return setTimeout(t,o)}));case 21:t.next=27;break;case 23:throw this.changeDataStatus(r,{isPublished:!1}),-102083===u&&(c="Please enable relayed-push in ".concat(this._core.constants.CLOUD_CONSOLE_URL," and try later, refer to ").concat(this._core.constants.DOC_URL,"tutorial-26-advanced-publish-cdn-stream.html")),this._log.error("[CDNStreaming] server failed: start tencent cdn errCode: ".concat(u," errMsg: ").concat(c)),new Error("[CDNStreaming] server failed: start tencent cdn errCode: ".concat(u," errMsg: ").concat(c));case 27:t.next=4;break;case 29:case"end":return t.stop()}}),t,this)}))),function(t,e){return i.apply(this,arguments)})},{key:"stopPublishTencentCDN",value:(e=r(a().mark((function t(e){var r,n;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),!(r=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN).isPublished){t.next=9;break}if(!((null==(n=r.target)?void 0:n.bizId)&&n.appId&&n.url&&(null==r?void 0:r.givenCDNManager))){t.next=7;break}return t.next=7,null==r?void 0:r.givenCDNManager.stopPublishGivenCDN();case 7:return t.next=9,this.doStopPublishTencentCDN(e);case 9:this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"doStopPublishTencentCDN",value:(t=r(a().mark((function t(e){var r,n,o,i;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={requestTime:Date.now(),sessionId:(0,O.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(e)))},this._log.info("[CDNStreaming] doStopPublishTencentCDN: ".concat(JSON.stringify(r))),t.next=4,this._room.sendStopPublishCDN(r,!0);case 4:if(n=t.sent,o=n.data.code,i=n.data.message,0!==o){t.next=13;break}this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e),t.next=16;break;case 13:throw-102069===o&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),i="can not stop in auto relayed-push mode ".concat(i)),this._log.error("[CDNStreaming] server failed: stop tencent cdn errCode: ".concat(o," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop tencent cdn errCode: ".concat(o," errMsg: ").concat(i));case 16:case"end":return t.stop()}}),t,this)}))),function(e){return t.apply(this,arguments)})},{key:"reset",value:function(t){this.uninstallEvents(),this._paramsForTencentCDN.set(t,this._initParamsForTencentCDN)}},{key:"generatePublishCDNStreamId",value:function(t,e){if(""===t){var r="".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(e));return/^[A-Za-z\d_-]*$/.test(r)||(r=(0,O.default)(r)),"".concat(this._room.sdkAppId,"_").concat(r)}return t}},{key:"convertPublishModeToStreamType",value:function(t){return"publish-main-stream-to-cdn"===t?"main":"aux"}},{key:"generatePublishCDNSessionId",value:function(t){return(0,O.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(t)))}}]);var t,e,i,s,u,c}(),A=D(w()),j=function(){return o((function t(e,r){n(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_seq"),N(this,"_taskId",null),N(this,"_startData",null),N(this,"_updateData",null),N(this,"_stopData",null),this._core=e,this._room=e.room,this._log=r,this._seq=0}),[{key:"startPushStreamToRoom",value:(i=r(a().mark((function t(e){var r,n,o,i,s,u;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._startData=x({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,A.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_start")),agentParam:{cdnRobotUserid:"mcu_robot_".concat(this._room.roomId,"_").concat(this._room.userId)}},this.getCommonParams(e)),this._log.info("startPushStreamToRoom: ".concat(JSON.stringify(this._startData))),t.next=5,this._room.sendStartPushStreamToRoom(this._startData);case 5:o=t.sent,i=o.data,s=i.code,u=i.message,0===s?(this._taskId=null==(n=null==(r=o.data)?void 0:r.data)?void 0:n.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",s,"can't resolve task id: ".concat(JSON.stringify(o.data))),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",s,u);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"updatePushStreamToRoom",value:(e=r(a().mark((function t(e){var r,n,o,i;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._updateData=C(x({taskid:this._taskId},this.getCommonParams(e)),{enableNtpSync:!0}),this._log.info("updatePushStreamToRoom: ".concat(JSON.stringify(this._updateData))),t.next=5,this._room.sendUpdatePushStreamToRoom(this._updateData);case 5:r=t.sent,n=r.data,o=n.code,i=n.message,0===o?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"stopPushStreamToRoom",value:(t=r(a().mark((function t(){var e,r,n,o;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info("stopPushStreamToRoom: ".concat(JSON.stringify(this._stopData))),t.next=5,this._room.sendStopPushStreamToRoom(this._stopData);case 5:e=t.sent,r=e.data,n=r.code,o=r.message,0===n?this._log.info("server success: start mix"):this.reportServerError("stopPushStreamToRoom",n,o);case 8:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})},{key:"reportServerError",value:function(t,e,r){var n="server failed: ".concat(t," errCode: ").concat(e," errMsg: ").concat(r);throw this._log.error(n),new Error(n)}},{key:"getPushRtcRoomParams",value:function(t){var e=t.target.robotUser;return e?[{roomid:String((null==e?void 0:e.roomId)||(null==e?void 0:e.strRoomId))||this._room.roomId,roomType:(null==e?void 0:e.roomId)?0:1,pushRobotUserid:null==e?void 0:e.userId}]:[]}},{key:"getCommonParams",value:function(t){return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(t),videoParam:this.getVideoParam(t),pushRtcRoomParams:this.getPushRtcRoomParams(t),sequenceNumber:this._seq}}},{key:"getAudioParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=t.encoding,i=void 0===o?{}:o,a={audioSamplerate:i.audioSampleRate||48e3,audioBitrateKbps:i.audioBitrate||64,audioChannels:i.audioChannels||1},s=n.audioMixUserList;return{audioEncodeParam:a,mixAudioUsers:(null==s?void 0:s.map((function(t){return{roomid:String(t.roomId||t.strRoomId)||e._room.roomId,userid:t.userId,roomType:t.roomId?0:1}})))||[]}}},{key:"getVideoParam",value:function(t){var e=this,r=t.mix,n=void 0===r?{}:r,o=t.encoding,i=void 0===o?{}:o,a={videoCodec:2,videoWidth:i.videoWidth||640,videoHeight:i.videoHeight||480,videoFramerate:i.videoFramerate||15,videoGop:i.videoGOP||2,videoBitrateKbps:i.videoBitrate||800},s=n.videoLayoutList;return{videoEncodeParam:a,layoutParams:(null==s?void 0:s.map((function(t){return{userMediaStream:{userInfo:{roomid:String(t.fixedVideoUser.roomId||t.fixedVideoUser.strRoomId)||e._room.roomId,userid:t.fixedVideoUser.userId,roomType:t.fixedVideoUser.roomId?0:1},streamType:"sub"===t.fixedVideoStreamType?1:0},imageWidth:t.width||0,imageHeight:t.height||0,locationX:t.locationX||0,locationY:t.locationY||0,imageZorder:t.zOrder||1,renderMode:t.fillMode||0}})))||[],backgroundColor:n.backgroundColor||0,backgroundImageUrl:n.backgroundImage||""}}}]);var t,e,i}();var G={type:"number",notLessThanZero:!0},U={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:function(t,e,r,n){var o=d,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;if("string"==typeof t)throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER_STRING,fnName:r,messageParams:{key:"roomId"}});if(void 0!==t&&!(/^[1-9]\d*$/.test(String(t))&&t<4294967295))throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER,fnName:r,messageParams:{key:"roomId"}})}},strRoomId:{type:"string",validate:function(t,e,r,n){var o=d,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(t))throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_STRING,fnName:r,messageParams:{key:"strRoomId"}})}}}},V={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:function(t,e,r,n){if(!/^[A-Za-z\d_-]*$/.test(t)){var o=d,i=o.RtcError,a=o.ErrorCode,s=o.ErrorCodeDictionary;throw new i({code:a.INVALID_PARAMETER,extraCode:s.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1},robotUser:x({},U)},validate:function(t,e,r,n){var o=t.publishMode,i=t.robotUser;if("publish-mix-stream-to-room"===o&&!i){var a=d;throw new(0,a.RtcError)({code:a.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},F={required:!1,type:"object",properties:{videoWidth:G,videoHeight:G,videoBitrate:C(x({},G),{allowEmpty:!1}),videoFramerate:{type:"number",validate:function(t,e,r,n){if(t<=0||t>30){var o=d;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate:function(t,e,r,n){if(t<1||t>8){var o=d;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:G,audioBitrate:{type:"number",validate:function(t,e,r,n){if(t<32||t>192){var o=d;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},q={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:x({},U)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:x({},U),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate:function(t,e,r,n){if(t<1||t>15){var o=d;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:G,height:G,locationX:G,locationY:G}}}}};var J=0,z=function(){function t(e){n(this,t),this.core=e,N(this,"_mixTranscodeManager"),N(this,"_publishCDNManager"),N(this,"_pushStreamToRoomManager"),N(this,"_core"),N(this,"_modeOptions"),N(this,"seq"),N(this,"_log"),J+=1,this.seq=J,this._log=e.log.createChild({id:"".concat(this.getAlias()).concat(J)}),this._log.info("[CDNStreaming] created id=".concat(this.getAlias()).concat(J)),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new R(e,this._log),this._publishCDNManager=new L(e,this._log),this._pushStreamToRoomManager=new j(e,this._log)}return o(t,[{key:"getName",value:function(){return t.Name}},{key:"getAlias",value:function(){return"cdn"}},{key:"getValidateRule",value:function(t){switch(t){case"start":return e=this._core,d=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:x({},V),encoding:x({},F),mix:x({},q)},validate:function(t,r,n,o){var i,a,s=t.target.publishMode,u=t.encoding,c=t.mix;if("publish-mix-stream-to-cdn"===s){var h=e.errorModule,d=h.RtcError,l=h.ErrorCode,m=h.ErrorCodeDictionary;if(!u)throw new d({code:l.INVALID_PARAMETER,extraCode:m.INVALID_PARAMETER_REQUIRED,fnName:n,messageParams:{key:"encoding"}});if(!c)throw new d({code:l.INVALID_PARAMETER,extraCode:m.INVALID_PARAMETER_REQUIRED,fnName:n,messageParams:{key:"mix"}});if(c&&c.videoLayoutList){var p=0,f=0,g=[];if(c.videoLayoutList.forEach((function(t,e){g.push(t.fixedVideoUser.userId),t.width+t.locationX>p&&(p=t.width+t.locationX),t.height+t.locationY>f&&(f=t.height+t.locationY)})),g.indexOf(e.room.userId)<0)throw new d({code:l.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});var v=null!=(i=null==u?void 0:u.videoWidth)?i:640,b=null!=(a=null==u?void 0:u.videoHeight)?a:480;if(v<p||b<f)throw new d({code:l.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}};case"update":return function(t){return d=t.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:x({},V),encoding:x({},F),mix:x({},q)}}}(this._core);case"stop":return function(t){return d=t.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"]}}}}}}(this._core)}var e}},{key:"getGroup",value:function(t){return t.target.publishMode}},{key:"start",value:(u=r(a().mark((function t(e){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._modeOptions.set(e.target.publishMode,e),"publish-mix-stream-to-room"!==e.target.publishMode){t.next=3;break}return t.abrupt("return",this._pushStreamToRoomManager.startPushStreamToRoom(e));case 3:return t.next=5,this.doStart(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"update",value:(s=r(a().mark((function t(e){var r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this._modeOptions.get(e.target.publishMode),this._core.utils.deepMerge(r,e),"publish-mix-stream-to-room"!==e.target.publishMode){t.next=4;break}return t.abrupt("return",this._pushStreamToRoomManager.updatePushStreamToRoom(r));case 4:return t.next=6,this.doStart(r);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"stop",value:(i=r(a().mark((function t(e){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=e.target.publishMode,t.next="publish-mix-stream-to-cdn"===t.t0?3:"publish-main-stream-to-cdn"===t.t0||"publish-sub-stream-to-cdn"===t.t0?6:"publish-mix-stream-to-room"===t.t0?9:11;break;case 3:return t.next=5,this._mixTranscodeManager.stopMixTranscode();case 5:return t.abrupt("break",11);case 6:return t.next=8,this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);case 8:return t.abrupt("break",11);case 9:return this._pushStreamToRoomManager.stopPushStreamToRoom(),t.abrupt("break",11);case 11:this._modeOptions.delete(e.target.publishMode);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"doStart",value:(e=r(a().mark((function t(e){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._log.info("[CDNStreaming] doStart: ".concat(JSON.stringify(e))),t.t0=e.target.publishMode,t.next="publish-mix-stream-to-cdn"===t.t0?4:"publish-main-stream-to-cdn"===t.t0||"publish-sub-stream-to-cdn"===t.t0?7:10;break;case 4:return t.next=6,this._mixTranscodeManager.startMixTranscode(e);case 6:case 9:return t.abrupt("break",10);case 7:return t.next=9,this._publishCDNManager.startPublishTencentCDN(e.target);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]);var e,i,s,u}();return N(z,"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"}}),N(z,"Name","CDNStreaming"),z}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,
|
|
1
|
+
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,r,t)=>r in e?__defProp(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,__spreadValues=(e,r)=>{for(var t in r||(r={}))__hasOwnProp.call(r,t)&&__defNormalProp(e,t,r[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(r))__propIsEnum.call(r,t)&&__defNormalProp(e,t,r[t]);return e},__spreadProps=(e,r)=>__defProps(e,__getOwnPropDescs(r)),__decorateClass=(e,r,t,o)=>{for(var s,a=o>1?void 0:o?__getOwnPropDesc(r,t):r,i=e.length-1;i>=0;i--)(s=e[i])&&(a=(o?s(r,t,a):s(a))||a);return o&&a&&__defProp(r,t,a),a},__publicField=(e,r,t)=>__defNormalProp(e,"symbol"!=typeof r?r+"":r,t),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:r,onError:t,onRetrying:o,onRetryFailed:s,onRetrySuccess:a,context:i}){return function(...d){const{retries:n=5,timeout:c=1e3}=r;let p=0,l=-1,u=RETRY_STATE_NOT_START;const _=async(r,m)=>{const R=i||this;try{const t=await e.apply(R,d);p>0&&a&&a.call(this,p),p=0,r(t)}catch(e){const a=()=>{clearTimeout(l),p=0,u=RETRY_STATE_STOPPED,m(e)},i=()=>{u!==RETRY_STATE_STOPPED&&p<(isFunction(n)?n():n)?(p++,u=RETRY_STATE_STARTED,isFunction(o)&&o.call(this,p,a),l=window.setTimeout((()=>{l=-1,_(r,m)}),isFunction(c)?c(p):c)):(a(),isFunction(s)&&s.call(this,e))};isFunction(t)?t.call(this,{error:e,retry:i,reject:m,retryFuncArgs:d,retriedCount:p}):i()}};return new Promise(_)}}var retry_default=promiseRetry,retryingMap=new WeakMap;function addPromiseRetry({settings:e={retries:5,timeout:2e3},onError:r,onRetrying:t,onRetryFailed:o}){return function(s,a,i){const d=retry_default({retryFunction:i.value,settings:e,onError({error:e,retry:t,reject:o,retryFuncArgs:i}){var d;r?r.call(this,e,(()=>{var r;(null==(r=retryingMap.get(s))?void 0:r.has(a))?t():o(e)}),o,i):(null==(d=retryingMap.get(s))?void 0:d.has(a))?t():o(e)},onRetrying(e,r){var o;isFunction(t)&&t.call(this,e,r),(null==(o=retryingMap.get(s))?void 0:o.has(a))&&(retryingMap.get(s).get(a).stopRetry=r)},onRetryFailed:o});return i.value=function(...e){const r=retryingMap.get(s);return r?r.set(a,{args:e}):retryingMap.set(s,new Map([[a,{args:e}]])),d.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 r;const t=(null==e?void 0:e.userId)||(null==(r=null==e?void 0:e.updateList)?void 0:r[0].userId)||"";return t||(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:r,userId:t}){const{RtcError:o,ErrorCode:s}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new o({code:s.ENV_NOT_SUPPORTED});const a=e||r;try{const e=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:a,userId:t,localRoomId:t?void 0:this.core.room.roomId},retries:3});if(0!==e.data.code)throw new o({code:s.SERVER_ERROR,extraCode:e.data.code,message:e.data.message})}catch(e){if(e.code!==this.core.errorModule.CoreErrorCode.API_CALL_ABORTED)throw e}t||this.connectedRoomIdSet.add(a)}async update({updateList:e}){var r;const{RtcError:t,ErrorCode:o}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:o.ENV_NOT_SUPPORTED});const s=e.find((e=>e.userId))?0:1;try{const 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:r,userId:t,muteAudio:o,muteVideo:s,muteSubStream:a})=>({roomId:e||r,userId:t,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 t({code:o.SERVER_ERROR,extraCode:a.data.code,message:a.data.message});if((null==(r=a.data.data.errorList)?void 0:r.length)>0)throw new t({code:o.UNKNOWN_ERROR,message:a.data.data.errorList[0].message})}catch(e){if(e.code!==this.core.errorModule.CoreErrorCode.API_CALL_ABORTED)throw e}}async stop({roomId:e,strRoomId:r}={}){const t=e||r;if(t)await this.doStop(t);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:r,ErrorCode:t}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:t.ENV_NOT_SUPPORTED});try{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 r({code:t.SERVER_ERROR,extraCode:o.data.code,message:o.data.message})}catch(e){if(e.code!==this.core.errorModule.CoreErrorCode.API_CALL_ABORTED)throw e}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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CrossRoom=e()}(this,(function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}function n(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e,r){return(e=s(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(){c=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof g?e:g,a=Object.create(i.prototype),c=new P(n||[]);return o(a,"_invoke",{value:L(t,r,c)}),a}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",y="executing",m="completed",v={};function g(){}function b(){}function w(){}var x={};l(x,a,(function(){return this}));var E=Object.getPrototypeOf,R=E&&E(E(A([])));R&&R!==r&&n.call(R,a)&&(x=R);var S=w.prototype=g.prototype=Object.create(x);function O(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(o,i,a,c){var u=d(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function L(e,r,n){var o=h;return function(i,a){if(o===y)throw Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=I(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=d(e,r,n);if("normal"===s.type){if(o=n.done?m:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function I(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,I(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=d(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function A(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return b.prototype=w,o(S,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,s,"GeneratorFunction")),t.prototype=Object.create(S),t},e.awrap=function(t){return{__await:t}},O(k.prototype),l(k.prototype,u,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new k(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(S),l(S,s,"Generator"),l(S,a,(function(){return this})),l(S,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=A,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(j),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:A(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function u(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var l,f=Object.defineProperty,d=Object.getOwnPropertyDescriptor,h=function(t,e,r,n){for(var o,i=d(e,r),a=t.length-1;a>=0;a--)(o=t[a])&&(i=o(e,r,i)||i);return i&&f(e,r,i),i},p={roomId:{type:"number"},strRoomId:{type:"string"}},y={name:"option",required:!0,properties:a(a({},p),{},{userId:{type:"string"}})},m={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:a(a({},y.properties),{},{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},v={name:"option",properties:a({},p)},g=function(t){return"function"==typeof t};var b=function(t){var e=t.retryFunction,n=t.settings,o=t.onError,i=t.onRetrying,a=t.onRetryFailed,u=t.onRetrySuccess,s=t.context;return function(){for(var t=this,l=arguments.length,f=new Array(l),d=0;d<l;d++)f[d]=arguments[d];var h=n.retries,p=void 0===h?5:h,y=n.timeout,m=void 0===y?1e3:y,v=0,b=-1,w=0,x=function(){var n=r(c().mark((function r(n,l){var d,h,y,E;return c().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return d=s||t,r.prev=1,r.next=4,e.apply(d,f);case 4:h=r.sent,v>0&&u&&u.call(t,v),v=0,n(h),r.next=15;break;case 10:r.prev=10,r.t0=r.catch(1),y=function(){clearTimeout(b),v=0,w=2,l(r.t0)},E=function(){2!==w&&v<(g(p)?p():p)?(v++,w=1,g(i)&&i.call(t,v,y),b=window.setTimeout((function(){b=-1,x(n,l)}),g(m)?m(v):m)):(y(),g(a)&&a.call(t,r.t0))},g(o)?o.call(t,{error:r.t0,retry:E,reject:l,retryFuncArgs:f,retriedCount:v}):E();case 15:case"end":return r.stop()}}),r,null,[[1,10]])})));return function(t,e){return n.apply(this,arguments)}}();return new Promise(x)}},w=new WeakMap;function x(t){var e=t.settings,r=void 0===e?{retries:5,timeout:2e3}:e,n=t.onError,o=t.onRetrying,i=t.onRetryFailed;return function(t,e,a){var c=b({retryFunction:a.value,settings:r,onError:function(r){var o,i=r.error,a=r.retry,c=r.reject,u=r.retryFuncArgs;n?n.call(this,i,(function(){var r;null!==(r=w.get(t))&&void 0!==r&&r.has(e)?a():c(i)}),c,u):null!==(o=w.get(t))&&void 0!==o&&o.has(e)?a():c(i)},onRetrying:function(r,n){var i;g(o)&&o.call(this,r,n),null!==(i=w.get(t))&&void 0!==i&&i.has(e)&&(w.get(t).get(e).stopRetry=n)},onRetryFailed:i});return a.value=function(){for(var r=w.get(t),n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return r?r.set(e,{args:o}):w.set(t,new Map([[e,{args:o}]])),c.apply(this,o).finally((function(){var r;return null===(r=w.get(t))||void 0===r?void 0:r.delete(e)}))},a}}var E=(l=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o(this,"disableRandomCall",!0),o(this,"connectedRoomIdSet",new Set),o(this,"updateSeq",0),o(this,"_log",void 0),this.core=e,this._log=this.core.log.createChild({id:"".concat(this.getAlias())})}return n(t,[{key:"getName",value:function(){return t.Name}},{key:"getAlias",value:function(){return"crs-r"}},{key:"getGroup",value:function(t){var e,r=(null==t?void 0:t.userId)||(null==t||null===(e=t.updateList)||void 0===e?void 0:e[0].userId)||"";return r||(t?t.updateList?String(t.updateList[0].roomId)||t.updateList[0].strRoomId||"":String(t.roomId)||t.strRoomId||"":"*")}},{key:"getValidateRule",value:function(t){switch(t){case"start":return y;case"update":return m;case"stop":return v}}},{key:"start",value:(s=r(c().mark((function t(e){var r,n,o,i,a,u,s,l;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.roomId,n=e.strRoomId,o=e.userId,i=this.core.errorModule,a=i.RtcError,u=i.ErrorCode,this.core.room.sendSignalMessage){t.next=4;break}throw new a({code:u.ENV_NOT_SUPPORTED});case 4:return s=r||n,t.prev=5,t.next=8,this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:s,userId:o,localRoomId:o?void 0:this.core.room.roomId},retries:3});case 8:if(0===(l=t.sent).data.code){t.next=11;break}throw new a({code:u.SERVER_ERROR,extraCode:l.data.code,message:l.data.message});case 11:t.next=17;break;case 13:if(t.prev=13,t.t0=t.catch(5),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=17;break}throw t.t0;case 17:o||this.connectedRoomIdSet.add(s);case 18:case"end":return t.stop()}}),t,this,[[5,13]])}))),function(t){return s.apply(this,arguments)})},{key:"update",value:(a=r(c().mark((function t(e){var r,n,o,i,a,u,s;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.updateList,n=this.core.errorModule,o=n.RtcError,i=n.ErrorCode,this.core.room.sendSignalMessage){t.next=4;break}throw new o({code:i.ENV_NOT_SUPPORTED});case 4:return a=r.find((function(t){return t.userId}))?0:1,t.prev=5,t.next=8,this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:a,updateList:r.map((function(t){var e=t.roomId,r=t.strRoomId;return{roomId:e||r,userId:t.userId,muteAudio:t.muteAudio,muteVideo:t.muteVideo,muteSubStream:t.muteSubStream}}))},retries:3});case 8:if(!(s=t.sent).data.data.expectSeq){t.next=12;break}return this.updateSeq=s.data.data.expectSeq,t.abrupt("return",this.update({updateList:r}));case 12:if(0===s.data.code){t.next=16;break}throw new o({code:i.SERVER_ERROR,extraCode:s.data.code,message:s.data.message});case 16:if(!((null===(u=s.data.data.errorList)||void 0===u?void 0:u.length)>0)){t.next=18;break}throw new o({code:i.UNKNOWN_ERROR,message:s.data.data.errorList[0].message});case 18:t.next=24;break;case 20:if(t.prev=20,t.t0=t.catch(5),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=24;break}throw t.t0;case 24:case"end":return t.stop()}}),t,this,[[5,20]])}))),function(t){return a.apply(this,arguments)})},{key:"stop",value:(i=r(c().mark((function t(){var e,r,n,o,i,a,s,l=arguments;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(e=l.length>0&&void 0!==l[0]?l[0]:{}).roomId,n=e.strRoomId,!(o=r||n)){t.next=7;break}return t.next=5,this.doStop(o);case 5:t.next=20;break;case 7:if(!(this.connectedRoomIdSet.size>0)){t.next=18;break}i=0,a=u(this.connectedRoomIdSet.values());case 9:if(!(i<a.length)){t.next=16;break}return s=a[i],t.next=13,this.doStop(s);case 13:i++,t.next=9;break;case 16:t.next=20;break;case 18:return t.next=20,this.doStop();case 20:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})},{key:"doStop",value:(e=r(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.core.errorModule,n=r.RtcError,o=r.ErrorCode,this.core.room.sendSignalMessage){t.next=3;break}throw new n({code:o.ENV_NOT_SUPPORTED});case 3:return t.prev=3,t.next=6,this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});case 6:if(0===(i=t.sent).data.code){t.next=9;break}throw new n({code:o.SERVER_ERROR,extraCode:i.data.code,message:i.data.message});case 9:t.next=15;break;case 11:if(t.prev=11,t.t0=t.catch(3),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=15;break}throw t.t0;case 15:this.connectedRoomIdSet.delete(e);case 16:case"end":return t.stop()}}),t,this,[[3,11]])}))),function(t){return e.apply(this,arguments)})},{key:"destroy",value:function(){}}]);var e,i,a,s}(),o(l,"Name","CrossRoom"),l);return h([x({settings:{retries:3,timeout:1e3},onRetrying:function(t){this._log.warn("retry start: ".concat(t))}})],E.prototype,"start"),h([x({settings:{retries:3,timeout:1e3},onRetrying:function(t){this._log.warn("retry update: ".concat(t))}})],E.prototype,"update"),E}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).CrossRoom=e()}(this,(function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function c(t){e(i,o,a,c,u,"next",t)}function u(t){e(i,o,a,c,u,"throw",t)}c(void 0)}))}}function n(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(){o=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},c=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,i=Object.create(o.prototype),c=new A(n||[]);return a(i,"_invoke",{value:L(t,r,c)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var p="suspendedStart",h="suspendedYield",y="executing",m="completed",v={};function g(){}function b(){}function w(){}var x={};l(x,c,(function(){return this}));var S=Object.getPrototypeOf,E=S&&S(S(P([])));E&&E!==r&&n.call(E,c)&&(x=E);var R=w.prototype=g.prototype=Object.create(x);function I(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(o,a,i,c){var u=d(t[o],t,a);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,i,c)}),(function(t){r("throw",t,i,c)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,c)}))}c(u.arg)}var o;a(this,"_invoke",{value:function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}})}function L(e,r,n){var o=p;return function(a,i){if(o===y)throw Error("Generator is already running");if(o===m){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=d(e,r,n);if("normal"===s.type){if(o=n.done?m:h,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function _(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var a=d(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,v;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function P(e){if(e||""===e){var r=e[c];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return b.prototype=w,a(R,"constructor",{value:w,configurable:!0}),a(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,s,"GeneratorFunction")),t.prototype=Object.create(R),t},e.awrap=function(t){return{__await:t}},I(k.prototype),l(k.prototype,u,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new k(f(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},I(R),l(R,s,"Generator"),l(R,c,(function(){return this})),l(R,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=P,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(j),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:P(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function a(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||u(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function u(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}var s=Object.defineProperty,l=Object.defineProperties,f=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyDescriptors,p=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,m=function(t,e,r){return e in t?s(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},v=function(t,e){for(var r in e||(e={}))h.call(e,r)&&m(t,r,e[r]);if(p){var n,o=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=u(t))||e){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){c=!0,a=t},f:function(){try{i||null==r.return||r.return()}finally{if(c)throw a}}}}(p(e));try{for(o.s();!(n=o.n()).done;){r=n.value;y.call(e,r)&&m(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t},g=function(t,e){return l(t,d(e))},b=function(t,e,r,n){for(var o,a=f(e,r),i=t.length-1;i>=0;i--)(o=t[i])&&(a=o(e,r,a)||a);return a&&s(e,r,a),a},w=function(t,e,r){return m(t,"symbol"!==c(e)?e+"":e,r)},x={roomId:{type:"number"},strRoomId:{type:"string"}},S={name:"option",required:!0,properties:g(v({},x),{userId:{type:"string"}})},E={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:g(v({},S.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},R={name:"option",properties:v({},x)},I=function(t){return"function"==typeof t};var k=function(t){var e=t.retryFunction,n=t.settings,a=t.onError,i=t.onRetrying,c=t.onRetryFailed,u=t.onRetrySuccess,s=t.context;return function(){for(var t=this,l=arguments.length,f=new Array(l),d=0;d<l;d++)f[d]=arguments[d];var p=n.retries,h=void 0===p?5:p,y=n.timeout,m=void 0===y?1e3:y,v=0,g=-1,b=0,w=function(){var n=r(o().mark((function r(n,l){var d,p,y,x;return o().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return d=s||t,r.prev=1,r.next=4,e.apply(d,f);case 4:p=r.sent,v>0&&u&&u.call(t,v),v=0,n(p),r.next=15;break;case 10:r.prev=10,r.t0=r.catch(1),y=function(){clearTimeout(g),v=0,b=2,l(r.t0)},x=function(){2!==b&&v<(I(h)?h():h)?(v++,b=1,I(i)&&i.call(t,v,y),g=window.setTimeout((function(){g=-1,w(n,l)}),I(m)?m(v):m)):(y(),I(c)&&c.call(t,r.t0))},I(a)?a.call(t,{error:r.t0,retry:x,reject:l,retryFuncArgs:f,retriedCount:v}):x();case 15:case"end":return r.stop()}}),r,null,[[1,10]])})));return function(t,e){return n.apply(this,arguments)}}();return new Promise(w)}},L=new WeakMap;function _(t){var e=t.settings,r=void 0===e?{retries:5,timeout:2e3}:e,n=t.onError,o=t.onRetrying,a=t.onRetryFailed;return function(t,e,i){var c=k({retryFunction:i.value,settings:r,onError:function(r){var o,a=r.error,i=r.retry,c=r.reject,u=r.retryFuncArgs;n?n.call(this,a,(function(){var r;(null==(r=L.get(t))?void 0:r.has(e))?i():c(a)}),c,u):(null==(o=L.get(t))?void 0:o.has(e))?i():c(a)},onRetrying:function(r,n){var a;I(o)&&o.call(this,r,n),(null==(a=L.get(t))?void 0:a.has(e))&&(L.get(t).get(e).stopRetry=n)},onRetryFailed:a});return i.value=function(){for(var r=L.get(t),n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];return r?r.set(e,{args:o}):L.set(t,new Map([[e,{args:o}]])),c.apply(this,o).finally((function(){var r;return null==(r=L.get(t))?void 0:r.delete(e)}))},i}}var O=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.core=e,w(this,"disableRandomCall",!0),w(this,"connectedRoomIdSet",new Set),w(this,"updateSeq",0),w(this,"_log"),this._log=this.core.log.createChild({id:"".concat(this.getAlias())})}return n(t,[{key:"getName",value:function(){return t.Name}},{key:"getAlias",value:function(){return"crs-r"}},{key:"getGroup",value:function(t){var e,r=(null==t?void 0:t.userId)||(null==(e=null==t?void 0:t.updateList)?void 0:e[0].userId)||"";return r||(t?t.updateList?String(t.updateList[0].roomId)||t.updateList[0].strRoomId||"":String(t.roomId)||t.strRoomId||"":"*")}},{key:"getValidateRule",value:function(t){switch(t){case"start":return S;case"update":return E;case"stop":return R}}},{key:"start",value:(u=r(o().mark((function t(e){var r,n,a,i,c,u,s,l;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.roomId,n=e.strRoomId,a=e.userId,i=this.core.errorModule,c=i.RtcError,u=i.ErrorCode,this.core.room.sendSignalMessage){t.next=4;break}throw new c({code:u.ENV_NOT_SUPPORTED});case 4:return s=r||n,t.prev=5,t.next=8,this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:s,userId:a,localRoomId:a?void 0:this.core.room.roomId},retries:3});case 8:if(0===(l=t.sent).data.code){t.next=11;break}throw new c({code:u.SERVER_ERROR,extraCode:l.data.code,message:l.data.message});case 11:t.next=17;break;case 13:if(t.prev=13,t.t0=t.catch(5),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=17;break}throw t.t0;case 17:a||this.connectedRoomIdSet.add(s);case 18:case"end":return t.stop()}}),t,this,[[5,13]])}))),function(t){return u.apply(this,arguments)})},{key:"update",value:(c=r(o().mark((function t(e){var r,n,a,i,c,u,s;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.updateList,a=this.core.errorModule,i=a.RtcError,c=a.ErrorCode,this.core.room.sendSignalMessage){t.next=4;break}throw new i({code:c.ENV_NOT_SUPPORTED});case 4:return u=r.find((function(t){return t.userId}))?0:1,t.prev=5,t.next=8,this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:u,updateList:r.map((function(t){var e=t.roomId,r=t.strRoomId;return{roomId:e||r,userId:t.userId,muteAudio:t.muteAudio,muteVideo:t.muteVideo,muteSubStream:t.muteSubStream}}))},retries:3});case 8:if(!(s=t.sent).data.data.expectSeq){t.next=12;break}return this.updateSeq=s.data.data.expectSeq,t.abrupt("return",this.update({updateList:r}));case 12:if(0===s.data.code){t.next=16;break}throw new i({code:c.SERVER_ERROR,extraCode:s.data.code,message:s.data.message});case 16:if(!((null==(n=s.data.data.errorList)?void 0:n.length)>0)){t.next=18;break}throw new i({code:c.UNKNOWN_ERROR,message:s.data.data.errorList[0].message});case 18:t.next=24;break;case 20:if(t.prev=20,t.t0=t.catch(5),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=24;break}throw t.t0;case 24:case"end":return t.stop()}}),t,this,[[5,20]])}))),function(t){return c.apply(this,arguments)})},{key:"stop",value:(i=r(o().mark((function t(){var e,r,n,i,c,u,s,l=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(e=l.length>0&&void 0!==l[0]?l[0]:{}).roomId,n=e.strRoomId,!(i=r||n)){t.next=7;break}return t.next=5,this.doStop(i);case 5:t.next=20;break;case 7:if(!(this.connectedRoomIdSet.size>0)){t.next=18;break}c=0,u=a(this.connectedRoomIdSet.values());case 9:if(!(c<u.length)){t.next=16;break}return s=u[c],t.next=13,this.doStop(s);case 13:c++,t.next=9;break;case 16:t.next=20;break;case 18:return t.next=20,this.doStop();case 20:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})},{key:"doStop",value:(e=r(o().mark((function t(e){var r,n,a,i;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.core.errorModule,n=r.RtcError,a=r.ErrorCode,this.core.room.sendSignalMessage){t.next=3;break}throw new n({code:a.ENV_NOT_SUPPORTED});case 3:return t.prev=3,t.next=6,this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});case 6:if(0===(i=t.sent).data.code){t.next=9;break}throw new n({code:a.SERVER_ERROR,extraCode:i.data.code,message:i.data.message});case 9:t.next=15;break;case 11:if(t.prev=11,t.t0=t.catch(3),t.t0.code===this.core.errorModule.CoreErrorCode.API_CALL_ABORTED){t.next=15;break}throw t.t0;case 15:this.connectedRoomIdSet.delete(e);case 16:case"end":return t.stop()}}),t,this,[[3,11]])}))),function(t){return e.apply(this,arguments)})},{key:"destroy",value:function(){}}]);var e,i,c,u}();return w(O,"Name","CrossRoom"),b([_({settings:{retries:3,timeout:1e3},onRetrying:function(t){this._log.warn("retry start: ".concat(t))}})],O.prototype,"start"),b([_({settings:{retries:3,timeout:1e3},onRetrying:function(t){this._log.warn("retry update: ".concat(t))}})],O.prototype,"update"),O}));
|