trtc-sdk-v5 5.15.0-beta.14 → 5.15.0-beta.16
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/debug-dialog.js +2 -2
- package/index.d.ts +8 -4
- package/package.json +1 -1
- 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/chorus/chorus.esm.d.ts +0 -2
- package/plugins/chorus/package.json +1 -1
- package/plugins/cross-room/cross-room.esm.d.ts +0 -2
- package/plugins/cross-room/package.json +1 -1
- package/plugins/custom-encryption/package.json +1 -1
- package/plugins/device-detector/package.json +1 -1
- package/plugins/fast-webrtc/fast-webrtc.esm.d.ts +27 -0
- package/plugins/fast-webrtc/fast-webrtc.esm.js +1 -0
- package/plugins/fast-webrtc/fast-webrtc.umd.js +1 -0
- package/plugins/{video-effect/face-detection → fast-webrtc}/package.json +8 -8
- package/plugins/lebplayer/lebplayer.esm.d.ts +260 -0
- package/plugins/lebplayer/lebplayer.esm.js +1 -0
- package/plugins/lebplayer/lebplayer.umd.js +1 -0
- package/plugins/lebplayer/package.json +29 -0
- package/plugins/small-stream-auto-switcher/package.json +1 -1
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-decoder/video-decoder.esm.d.ts +1 -2
- 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/package.json +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/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/voice-changer/package.json +1 -1
- package/trtc.esm.js +39 -35
- package/trtc.js +1 -1
- package/plugins/video-effect/face-detection/face-detection.esm.d.ts +0 -22
- package/plugins/video-effect/face-detection/face-detection.esm.js +0 -1
- package/plugins/video-effect/face-detection/face-detection.umd.js +0 -1
package/index.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ import { CustomEncryption, EncryptionOptions } from './plugins/custom-encryption
|
|
|
9
9
|
import { VideoMixerOptions, UpdateVideoMixerOptions, VideoMixer } from './plugins/video-effect/video-mixer';
|
|
10
10
|
import { SmallStreamAutoSwitcher, SmallStreamAutoSwitcherOptions } from './plugins/small-stream-auto-switcher';
|
|
11
11
|
import { Chorus, StartChorusOption, UpdateChorusOption } from './plugins/chorus';
|
|
12
|
+
import { LEBPlayer, StartLEBPlayerOption, UpdateLEBPlayerOption } from './plugins/lebplayer';
|
|
12
13
|
|
|
13
14
|
export { CDNStreamingOptions, DeviceDetectorOptions, VirtualBackgroundOptions, UpdateVirtualBackgroundOptions, WatermarkOptions, BeautyOptions, UpdateBeautyOptions, BasicBeautyOptions, StartCrossRoomOption, UpdateCrossRoomOption, StopCrossRoomOption, SmallStreamAutoSwitcherOptions, VideoMixerOptions, UpdateVideoMixerOptions };
|
|
14
|
-
type TRTCPlugin = typeof CrossRoom | typeof CDNStreaming | typeof DeviceDetector | typeof VirtualBackground | typeof Watermark | typeof Beauty | typeof BasicBeauty | typeof CustomEncryption | typeof SmallStreamAutoSwitcher | typeof VideoMixer | typeof Chorus;
|
|
15
|
+
type TRTCPlugin = typeof CrossRoom | typeof CDNStreaming | typeof DeviceDetector | typeof VirtualBackground | typeof Watermark | typeof Beauty | typeof BasicBeauty | typeof CustomEncryption | typeof SmallStreamAutoSwitcher | typeof VideoMixer | typeof Chorus | typeof LEBPlayer;
|
|
15
16
|
export type ExperimentalAPIFunctionMap = {
|
|
16
17
|
'enableAudioFrameEvent': EnableAudioFrameEventOptions;
|
|
17
18
|
'resumeRemotePlayer': RemotePlayerOptions;
|
|
@@ -36,6 +37,7 @@ export declare type PluginStartOptionsMap = {
|
|
|
36
37
|
'SmallStreamAutoSwitcher': SmallStreamAutoSwitcherOptions;
|
|
37
38
|
'AudioProcessor': InitAudioProcessorOptions;
|
|
38
39
|
'Chorus': StartChorusOption;
|
|
40
|
+
'LEBPlayer': StartLEBPlayerOption;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export declare type PluginUpdateOptionsMap = {
|
|
@@ -51,6 +53,7 @@ export declare type PluginUpdateOptionsMap = {
|
|
|
51
53
|
'AudioProcessor': UpdateAudioProcessorOptions;
|
|
52
54
|
'Debug': UpdateDebugOptions;
|
|
53
55
|
'Chorus': UpdateChorusOption;
|
|
56
|
+
'LEBPlayer': UpdateLEBPlayerOption;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
export declare type PluginStopOptionsMap = {
|
|
@@ -69,6 +72,7 @@ export declare type PluginStopOptionsMap = {
|
|
|
69
72
|
'AudioProcessor': undefined;
|
|
70
73
|
'CustomEncryption': undefined;
|
|
71
74
|
'Chorus': undefined;
|
|
75
|
+
'LEBPlayer': undefined;
|
|
72
76
|
};
|
|
73
77
|
|
|
74
78
|
export declare class RtcError extends Error implements RTCErrorInterface {
|
|
@@ -338,6 +342,7 @@ export declare type PluginWithAssets = {
|
|
|
338
342
|
export declare interface TRTCOptions {
|
|
339
343
|
plugins?: Array<TRTCPlugin>;
|
|
340
344
|
enableSEI?: boolean;
|
|
345
|
+
enableAutoPlayDialog?: boolean;
|
|
341
346
|
assetsPath?: string;
|
|
342
347
|
volumeType?: number;
|
|
343
348
|
enableAutoSwitchWhenRecapturing?: boolean;
|
|
@@ -411,7 +416,6 @@ export declare interface SwitchRoomConfig {
|
|
|
411
416
|
export declare interface ScreenShareConfig {
|
|
412
417
|
view?: string | HTMLElement | HTMLElement[] | null;
|
|
413
418
|
publish?: boolean;
|
|
414
|
-
streamType?: TRTCStreamType;
|
|
415
419
|
muteSystemAudio?: boolean;
|
|
416
420
|
option?: {
|
|
417
421
|
profile?: keyof typeof screenProfileMap | VideoProfile;
|
|
@@ -431,8 +435,6 @@ export declare interface UpdateScreenShareConfig extends ScreenShareConfig {
|
|
|
431
435
|
option?: {
|
|
432
436
|
fillMode?: 'contain' | 'cover' | 'fill';
|
|
433
437
|
qosPreference?: typeof TRTCType.QOS_PREFERENCE_SMOOTH | typeof TRTCType.QOS_PREFERENCE_CLEAR;
|
|
434
|
-
audioTrack?: MediaStreamTrack;
|
|
435
|
-
videoTrack?: MediaStreamTrack;
|
|
436
438
|
};
|
|
437
439
|
}
|
|
438
440
|
export declare interface RemoteVideoConfig {
|
|
@@ -448,6 +450,8 @@ export declare interface RemoteVideoConfig {
|
|
|
448
450
|
canvasRender?: boolean;
|
|
449
451
|
poster?: string;
|
|
450
452
|
draggable?:boolean;
|
|
453
|
+
pictureInPicture?: boolean;
|
|
454
|
+
fullScreen?: boolean;
|
|
451
455
|
};
|
|
452
456
|
}
|
|
453
457
|
export declare interface StopRemoteVideoConfig {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __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,c=-1732584194,p=271733878;for(o=0;o<e.length;o+=16)d=m,u=_,l=c,h=p,m=i(m,_,c,p,e[o],7,-680876936),p=i(p,m,_,c,e[o+1],12,-389564586),c=i(c,p,m,_,e[o+2],17,606105819),_=i(_,c,p,m,e[o+3],22,-1044525330),m=i(m,_,c,p,e[o+4],7,-176418897),p=i(p,m,_,c,e[o+5],12,1200080426),c=i(c,p,m,_,e[o+6],17,-1473231341),_=i(_,c,p,m,e[o+7],22,-45705983),m=i(m,_,c,p,e[o+8],7,1770035416),p=i(p,m,_,c,e[o+9],12,-1958414417),c=i(c,p,m,_,e[o+10],17,-42063),_=i(_,c,p,m,e[o+11],22,-1990404162),m=i(m,_,c,p,e[o+12],7,1804603682),p=i(p,m,_,c,e[o+13],12,-40341101),c=i(c,p,m,_,e[o+14],17,-1502002290),m=s(m,_=i(_,c,p,m,e[o+15],22,1236535329),c,p,e[o+1],5,-165796510),p=s(p,m,_,c,e[o+6],9,-1069501632),c=s(c,p,m,_,e[o+11],14,643717713),_=s(_,c,p,m,e[o],20,-373897302),m=s(m,_,c,p,e[o+5],5,-701558691),p=s(p,m,_,c,e[o+10],9,38016083),c=s(c,p,m,_,e[o+15],14,-660478335),_=s(_,c,p,m,e[o+4],20,-405537848),m=s(m,_,c,p,e[o+9],5,568446438),p=s(p,m,_,c,e[o+14],9,-1019803690),c=s(c,p,m,_,e[o+3],14,-187363961),_=s(_,c,p,m,e[o+8],20,1163531501),m=s(m,_,c,p,e[o+13],5,-1444681467),p=s(p,m,_,c,e[o+2],9,-51403784),c=s(c,p,m,_,e[o+7],14,1735328473),m=a(m,_=s(_,c,p,m,e[o+12],20,-1926607734),c,p,e[o+5],4,-378558),p=a(p,m,_,c,e[o+8],11,-2022574463),c=a(c,p,m,_,e[o+11],16,1839030562),_=a(_,c,p,m,e[o+14],23,-35309556),m=a(m,_,c,p,e[o+1],4,-1530992060),p=a(p,m,_,c,e[o+4],11,1272893353),c=a(c,p,m,_,e[o+7],16,-155497632),_=a(_,c,p,m,e[o+10],23,-1094730640),m=a(m,_,c,p,e[o+13],4,681279174),p=a(p,m,_,c,e[o],11,-358537222),c=a(c,p,m,_,e[o+3],16,-722521979),_=a(_,c,p,m,e[o+6],23,76029189),m=a(m,_,c,p,e[o+9],4,-640364487),p=a(p,m,_,c,e[o+12],11,-421815835),c=a(c,p,m,_,e[o+15],16,530742520),m=n(m,_=a(_,c,p,m,e[o+2],23,-995338651),c,p,e[o],6,-198630844),p=n(p,m,_,c,e[o+7],10,1126891415),c=n(c,p,m,_,e[o+14],15,-1416354905),_=n(_,c,p,m,e[o+5],21,-57434055),m=n(m,_,c,p,e[o+12],6,1700485571),p=n(p,m,_,c,e[o+3],10,-1894986606),c=n(c,p,m,_,e[o+10],15,-1051523),_=n(_,c,p,m,e[o+1],21,-2054922799),m=n(m,_,c,p,e[o+8],6,1873313359),p=n(p,m,_,c,e[o+15],10,-30611744),c=n(c,p,m,_,e[o+6],15,-1560198380),_=n(_,c,p,m,e[o+13],21,1309151649),m=n(m,_,c,p,e[o+4],6,-145523070),p=n(p,m,_,c,e[o+11],10,-1120210379),c=n(c,p,m,_,e[o+2],15,718787259),_=n(_,c,p,m,e[o+9],21,-343485551),m=r(m,d),_=r(_,u),c=r(c,l),p=r(p,h);return[m,_,c,p]}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 c(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 p(e,t,r){return t?r?c(t,e):h(c(t,e)):r?_(e):h(_(e))}"function"==typeof define&&define.amd?define((function(){return p})):"object"==typeof t&&t.exports?t.exports=p:e.md5=p}(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){this._log.info(`startMixTranscode: ${JSON.stringify(e)}`);const t=this._config,r=this._data;if(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 r?(this._log.warn("[CDNStreaming] update failed, restore previous state"),this._config=t,this._data=r):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;this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${null==(t=null==e?void 0:e.room)?void 0:t.roomId}`);const r="main"===e.streamType?"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 e{constructor(t,r){__publicField(this,"_core"),__publicField(this,"_room"),__publicField(this,"_log"),__publicField(this,"_seq"),__publicField(this,"_taskId"),__publicField(this,"_startData",null),__publicField(this,"_updateData",null),__publicField(this,"_stopData",null),this._core=t,this._room=t.room,this._log=r,this._seq=0;const o=localStorage.getItem(e.TASK_ID_KEY);o&&(this._taskId=o)}async startPushStreamToRoom(t){var r,o;try{this._taskId&&await this.stopPushStreamToRoom()}catch(e){this._log.warn("stopPushStreamToRoom prev taskId failed",e)}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(t)),this._log.info(`startPushStreamToRoom: ${JSON.stringify(this._startData)}`);const i=await this._room.sendStartPushStreamToRoom(this._startData),{code:s,message:a}=i.data;0===s?(this._taskId=null==(o=null==(r=i.data)?void 0:r.data)?void 0:o.taskId,this._taskId?localStorage.setItem(e.TASK_ID_KEY,this._taskId):this.reportServerError("startPushStreamToRoom",s,`can't resolve task id: ${JSON.stringify(i.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",s,a)}async updatePushStreamToRoom(e){var t;this._seq+=1,this._updateData=__spreadValues({taskid:this._taskId},this.getCommonParams(e)),this._core.utils.isBoolean(null==(t=e.mix)?void 0:t.enableNtpSync)&&(this._updateData.enableNtpSync=e.mix.enableNtpSync),this._log.info(`updatePushStreamToRoom: ${JSON.stringify(this._updateData)}`);const r=await this._room.sendUpdatePushStreamToRoom(this._updateData),{code:o,message:i}=r.data;0===o?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i)}async stopPushStreamToRoom(){if(!this._taskId)return;this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info(`stopPushStreamToRoom: ${JSON.stringify(this._stopData)}`);const t=await this._room.sendStopPushStreamToRoom(this._stopData),{code:r,message:o}=t.data;0===r?(delete this._taskId,localStorage.removeItem(e.TASK_ID_KEY),this._log.info("server success: start mix")):this.reportServerError("stopPushStreamToRoom",r,o)}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){var t;return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(e),videoParam:this.getVideoParam(e),pushRtcRoomParams:this.getPushRtcRoomParams(e),sequenceNumber:this._seq,enableNtpSync:(null==(t=e.mix)?void 0:t.enableNtpSync)||!1}}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||""}}};__publicField(_PushStreamToRoom,"TASK_ID_KEY","trtc_mix_to_room_taskId");var errorModule,PushStreamToRoom=_PushStreamToRoom,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":await 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
|
+
var __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,c=-1732584194,p=271733878;for(o=0;o<e.length;o+=16)d=m,u=_,l=c,h=p,m=i(m,_,c,p,e[o],7,-680876936),p=i(p,m,_,c,e[o+1],12,-389564586),c=i(c,p,m,_,e[o+2],17,606105819),_=i(_,c,p,m,e[o+3],22,-1044525330),m=i(m,_,c,p,e[o+4],7,-176418897),p=i(p,m,_,c,e[o+5],12,1200080426),c=i(c,p,m,_,e[o+6],17,-1473231341),_=i(_,c,p,m,e[o+7],22,-45705983),m=i(m,_,c,p,e[o+8],7,1770035416),p=i(p,m,_,c,e[o+9],12,-1958414417),c=i(c,p,m,_,e[o+10],17,-42063),_=i(_,c,p,m,e[o+11],22,-1990404162),m=i(m,_,c,p,e[o+12],7,1804603682),p=i(p,m,_,c,e[o+13],12,-40341101),c=i(c,p,m,_,e[o+14],17,-1502002290),m=s(m,_=i(_,c,p,m,e[o+15],22,1236535329),c,p,e[o+1],5,-165796510),p=s(p,m,_,c,e[o+6],9,-1069501632),c=s(c,p,m,_,e[o+11],14,643717713),_=s(_,c,p,m,e[o],20,-373897302),m=s(m,_,c,p,e[o+5],5,-701558691),p=s(p,m,_,c,e[o+10],9,38016083),c=s(c,p,m,_,e[o+15],14,-660478335),_=s(_,c,p,m,e[o+4],20,-405537848),m=s(m,_,c,p,e[o+9],5,568446438),p=s(p,m,_,c,e[o+14],9,-1019803690),c=s(c,p,m,_,e[o+3],14,-187363961),_=s(_,c,p,m,e[o+8],20,1163531501),m=s(m,_,c,p,e[o+13],5,-1444681467),p=s(p,m,_,c,e[o+2],9,-51403784),c=s(c,p,m,_,e[o+7],14,1735328473),m=a(m,_=s(_,c,p,m,e[o+12],20,-1926607734),c,p,e[o+5],4,-378558),p=a(p,m,_,c,e[o+8],11,-2022574463),c=a(c,p,m,_,e[o+11],16,1839030562),_=a(_,c,p,m,e[o+14],23,-35309556),m=a(m,_,c,p,e[o+1],4,-1530992060),p=a(p,m,_,c,e[o+4],11,1272893353),c=a(c,p,m,_,e[o+7],16,-155497632),_=a(_,c,p,m,e[o+10],23,-1094730640),m=a(m,_,c,p,e[o+13],4,681279174),p=a(p,m,_,c,e[o],11,-358537222),c=a(c,p,m,_,e[o+3],16,-722521979),_=a(_,c,p,m,e[o+6],23,76029189),m=a(m,_,c,p,e[o+9],4,-640364487),p=a(p,m,_,c,e[o+12],11,-421815835),c=a(c,p,m,_,e[o+15],16,530742520),m=n(m,_=a(_,c,p,m,e[o+2],23,-995338651),c,p,e[o],6,-198630844),p=n(p,m,_,c,e[o+7],10,1126891415),c=n(c,p,m,_,e[o+14],15,-1416354905),_=n(_,c,p,m,e[o+5],21,-57434055),m=n(m,_,c,p,e[o+12],6,1700485571),p=n(p,m,_,c,e[o+3],10,-1894986606),c=n(c,p,m,_,e[o+10],15,-1051523),_=n(_,c,p,m,e[o+1],21,-2054922799),m=n(m,_,c,p,e[o+8],6,1873313359),p=n(p,m,_,c,e[o+15],10,-30611744),c=n(c,p,m,_,e[o+6],15,-1560198380),_=n(_,c,p,m,e[o+13],21,1309151649),m=n(m,_,c,p,e[o+4],6,-145523070),p=n(p,m,_,c,e[o+11],10,-1120210379),c=n(c,p,m,_,e[o+2],15,718787259),_=n(_,c,p,m,e[o+9],21,-343485551),m=r(m,d),_=r(_,u),c=r(c,l),p=r(p,h);return[m,_,c,p]}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 c(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 p(e,t,r){return t?r?c(t,e):h(c(t,e)):r?_(e):h(_(e))}"function"==typeof define&&define.amd?define((function(){return p})):"object"==typeof t&&t.exports?t.exports=p:e.md5=p}(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;this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${null==(t=null==e?void 0:e.room)?void 0:t.roomId}`);const r="main"===e.streamType?"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 e{constructor(t,r){__publicField(this,"_core"),__publicField(this,"_room"),__publicField(this,"_log"),__publicField(this,"_seq"),__publicField(this,"_taskId"),__publicField(this,"_startData",null),__publicField(this,"_updateData",null),__publicField(this,"_stopData",null),this._core=t,this._room=t.room,this._log=r,this._seq=0;const o=localStorage.getItem(e.TASK_ID_KEY);o&&(this._taskId=o)}async startPushStreamToRoom(t){var r,o;try{this._taskId&&await this.stopPushStreamToRoom()}catch(e){this._log.warn("stopPushStreamToRoom prev taskId failed",e)}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(t)),this._log.info(`startPushStreamToRoom: ${JSON.stringify(this._startData)}`);const i=await this._room.sendStartPushStreamToRoom(this._startData),{code:s,message:a}=i.data;0===s?(this._taskId=null==(o=null==(r=i.data)?void 0:r.data)?void 0:o.taskId,this._taskId?localStorage.setItem(e.TASK_ID_KEY,this._taskId):this.reportServerError("startPushStreamToRoom",s,`can't resolve task id: ${JSON.stringify(i.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",s,a)}async updatePushStreamToRoom(e){var t;this._seq+=1,this._updateData=__spreadValues({taskid:this._taskId},this.getCommonParams(e)),this._core.utils.isBoolean(null==(t=e.mix)?void 0:t.enableNtpSync)&&(this._updateData.enableNtpSync=e.mix.enableNtpSync),this._log.info(`updatePushStreamToRoom: ${JSON.stringify(this._updateData)}`);const r=await this._room.sendUpdatePushStreamToRoom(this._updateData),{code:o,message:i}=r.data;0===o?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i)}async stopPushStreamToRoom(){if(!this._taskId)return;this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info(`stopPushStreamToRoom: ${JSON.stringify(this._stopData)}`);const t=await this._room.sendStopPushStreamToRoom(this._stopData),{code:r,message:o}=t.data;0===r?(delete this._taskId,localStorage.removeItem(e.TASK_ID_KEY),this._log.info("server success: start mix")):this.reportServerError("stopPushStreamToRoom",r,o)}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){var t;return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(e),videoParam:this.getVideoParam(e),pushRtcRoomParams:this.getPushRtcRoomParams(e),sequenceNumber:this._seq,enableNtpSync:(null==(t=e.mix)?void 0:t.enableNtpSync)||!1}}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||""}}};__publicField(_PushStreamToRoom,"TASK_ID_KEY","trtc_mix_to_room_taskId");var errorModule,PushStreamToRoom=_PushStreamToRoom,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":await 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,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 D=_.prototype=b.prototype=Object.create(I);function C(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=k(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 k(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,k(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 P(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(P,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(D,"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(D),t},e.awrap=function(t){return{__await:t}},C(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()}))},C(D),h(D,c,"Generator"),h(D,s,(function(){return this})),h(D,"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=Object.create,l=Object.defineProperty,m=Object.defineProperties,p=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,b=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,I=function(t,e,r){return e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},S=function(t,e){for(var r in e||(e={}))y.call(e,r)&&I(t,r,e[r]);if(v){var n,o=i(v(e));try{for(o.s();!(n=o.n()).done;){r=n.value;_.call(e,r)&&I(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t},x=function(t,e,r){return r=null!=t?d(b(t)):{},function(t,e,r,n){if(e&&"object"===u(e)||"function"==typeof e){var o,a=i(g(e));try{var s=function(){var i=o.value;y.call(t,i)||i===r||l(t,i,{get:function(){return e[i]},enumerable:!(n=p(e,i))||n.enumerable})};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}}return t}(l(r,"default",{value:t,enumerable:!0}),t)},D=function(t,e,r){return I(t,"symbol"!==u(e)?e+"":e,r)},C=(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[g(c)[0]])((h={exports:{}}).exports,h),h.exports}),N=x(C()),w=0,k=4,P=5,T=function(){return o((function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_params"),D(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}(),M=function(){return o((function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_config",null),D(this,"_data",null),D(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,l,m;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._log.info("startMixTranscode: ".concat(JSON.stringify(e))),r=this._config,n=this._data,this._config=e,this.installEvents(),this._core.room.isJoined){t.next=7;break}return t.abrupt("return");case 7:if(t.prev=7,o=this.getInputParam(e),i=this.getOutputParam(e),s=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId}),!this.isMixing||!this._data||s===this._data.outputSessionId){t.next=15;break}return this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),t.next=15,this.doStopMixTranscode();case 15:return t.next=17,this.doStartMixTranscode({outputSessionId:s,inputParam:o,outputParam:i});case 17:if(u=e.target,c=u.appId,h=u.bizId,d=u.url,l=u.streamId,m=void 0===l?"":l,!(c&&h&&d)){t.next=22;break}return this._givenCDNManager||(this._givenCDNManager=new T(this._core,this._log)),t.next=22,this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:h,url:d,streamId:m});case 22:t.next=28;break;case 24:throw t.prev=24,t.t0=t.catch(7),n?(this._log.warn("[CDNStreaming] update failed, restore previous state"),this._config=r,this._data=n):this.reset(),t.t0;case 28:case"end":return t.stop()}}),t,this,[[7,24]])}))),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,N.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:P,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=w:s.push({userId:t.userId,roomId:t.roomId||t.strRoomId||e._core.room.roomId,inputType:k})})),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}(),E=x(C()),R=function(){return o((function t(e,r){n(this,t),D(this,"_room"),D(this,"_core"),D(this,"_log"),D(this,"_paramsForTencentCDN"),D(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)),o="main"===r.streamType?"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=9;break}return t.next=9,this.startPublishTencentCDN(i.target);case 9: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=S(S({},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 T(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,E.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,E.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,E.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(t)))}}]);var t,e,i,s,u,c}(),O=x(C()),A=function(){function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_seq"),D(this,"_taskId"),D(this,"_startData",null),D(this,"_updateData",null),D(this,"_stopData",null),this._core=e,this._room=e.room,this._log=r,this._seq=0;var o=localStorage.getItem(t.TASK_ID_KEY);o&&(this._taskId=o)}return o(t,[{key:"startPushStreamToRoom",value:(s=r(a().mark((function e(r){var n,o,i,s,u,c;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!this._taskId){e.next=4;break}return e.next=4,this.stopPushStreamToRoom();case 4:e.next=9;break;case 6:e.prev=6,e.t0=e.catch(0),this._log.warn("stopPushStreamToRoom prev taskId failed",e.t0);case 9:return this._seq+=1,this._startData=S({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,O.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_start")),agentParam:{cdnRobotUserid:"mcu_robot_".concat(this._room.roomId,"_").concat(this._room.userId)}},this.getCommonParams(r)),this._log.info("startPushStreamToRoom: ".concat(JSON.stringify(this._startData))),e.next=14,this._room.sendStartPushStreamToRoom(this._startData);case 14:i=e.sent,s=i.data,u=s.code,c=s.message,0===u?(this._taskId=null==(o=null==(n=i.data)?void 0:n.data)?void 0:o.taskId,this._taskId?localStorage.setItem(t.TASK_ID_KEY,this._taskId):this.reportServerError("startPushStreamToRoom",u,"can't resolve task id: ".concat(JSON.stringify(i.data))),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",u,c);case 17:case"end":return e.stop()}}),e,this,[[0,6]])}))),function(t){return s.apply(this,arguments)})},{key:"updatePushStreamToRoom",value:(i=r(a().mark((function t(e){var r,n,o,i,s;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._updateData=S({taskid:this._taskId},this.getCommonParams(e)),this._core.utils.isBoolean(null==(r=e.mix)?void 0:r.enableNtpSync)&&(this._updateData.enableNtpSync=e.mix.enableNtpSync),this._log.info("updatePushStreamToRoom: ".concat(JSON.stringify(this._updateData))),t.next=6,this._room.sendUpdatePushStreamToRoom(this._updateData);case 6:n=t.sent,o=n.data,i=o.code,s=o.message,0===i?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",i,s);case 9:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"stopPushStreamToRoom",value:(e=r(a().mark((function e(){var r,n,o,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._taskId){e.next=2;break}return e.abrupt("return");case 2:return this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info("stopPushStreamToRoom: ".concat(JSON.stringify(this._stopData))),e.next=7,this._room.sendStopPushStreamToRoom(this._stopData);case 7:r=e.sent,n=r.data,o=n.code,i=n.message,0===o?(delete this._taskId,localStorage.removeItem(t.TASK_ID_KEY),this._log.info("server success: start mix")):this.reportServerError("stopPushStreamToRoom",o,i);case 10:case"end":return e.stop()}}),e,this)}))),function(){return e.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){var e;return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(t),videoParam:this.getVideoParam(t),pushRtcRoomParams:this.getPushRtcRoomParams(t),sequenceNumber:this._seq,enableNtpSync:(null==(e=t.mix)?void 0:e.enableNtpSync)||!1}}},{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 e,i,s}();D(A,"TASK_ID_KEY","trtc_mix_to_room_taskId");var L,j=A;var G,U,V={type:"number",notLessThanZero:!0},F={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:function(t,e,r,n){var o=L,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=L,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"}})}}}},q={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=L,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:S({},F)},validate:function(t,e,r,n){var o=t.publishMode,i=t.robotUser;if("publish-mix-stream-to-room"===o&&!i){var a=L;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:V,videoHeight:V,videoBitrate:(G=S({},V),U={allowEmpty:!1},m(G,f(U))),videoFramerate:{type:"number",validate:function(t,e,r,n){if(t<=0||t>30){var o=L;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=L;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:V,audioBitrate:{type:"number",validate:function(t,e,r,n){if(t<32||t>192){var o=L;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]}}},z={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:S({},F)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:S({},F),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=L;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:V,height:V,locationX:V,locationY:V}}}}};var B=0,Y=function(){function t(e){n(this,t),this.core=e,D(this,"_mixTranscodeManager"),D(this,"_publishCDNManager"),D(this,"_pushStreamToRoomManager"),D(this,"_core"),D(this,"_modeOptions"),D(this,"seq"),D(this,"_log"),B+=1,this.seq=B,this._log=e.log.createChild({id:"".concat(this.getAlias()).concat(B)}),this._log.info("[CDNStreaming] created id=".concat(this.getAlias()).concat(B)),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new M(e,this._log),this._publishCDNManager=new R(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,L=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:S({},q),encoding:S({},J),mix:S({},z)},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 L=t.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:S({},q),encoding:S({},J),mix:S({},z)}}}(this._core);case"stop":return function(t){return L=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:12;break;case 3:return t.next=5,this._mixTranscodeManager.stopMixTranscode();case 5:return t.abrupt("break",12);case 6:return t.next=8,this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);case 8:return t.abrupt("break",12);case 9:return t.next=11,this._pushStreamToRoomManager.stopPushStreamToRoom();case 11:return t.abrupt("break",12);case 12:this._modeOptions.delete(e.target.publishMode);case 13: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 D(Y,"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"}}),D(Y,"Name","CDNStreaming"),Y}));
|
|
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 D=_.prototype=b.prototype=Object.create(I);function C(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=k(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 k(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,k(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 P(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(P,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(D,"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(D),t},e.awrap=function(t){return{__await:t}},C(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()}))},C(D),h(D,c,"Generator"),h(D,s,(function(){return this})),h(D,"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=Object.create,l=Object.defineProperty,m=Object.defineProperties,p=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,b=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,I=function(t,e,r){return e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},S=function(t,e){for(var r in e||(e={}))y.call(e,r)&&I(t,r,e[r]);if(v){var n,o=i(v(e));try{for(o.s();!(n=o.n()).done;){r=n.value;_.call(e,r)&&I(t,r,e[r])}}catch(t){o.e(t)}finally{o.f()}}return t},x=function(t,e,r){return r=null!=t?d(b(t)):{},function(t,e,r,n){if(e&&"object"===u(e)||"function"==typeof e){var o,a=i(g(e));try{var s=function(){var i=o.value;y.call(t,i)||i===r||l(t,i,{get:function(){return e[i]},enumerable:!(n=p(e,i))||n.enumerable})};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}}return t}(l(r,"default",{value:t,enumerable:!0}),t)},D=function(t,e,r){return I(t,"symbol"!==u(e)?e+"":e,r)},C=(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[g(c)[0]])((h={exports:{}}).exports,h),h.exports}),N=x(C()),w=0,k=4,P=5,T=function(){return o((function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_params"),D(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}(),M=function(){return o((function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_config",null),D(this,"_data",null),D(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 T(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,N.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:P,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=w:s.push({userId:t.userId,roomId:t.roomId||t.strRoomId||e._core.room.roomId,inputType:k})})),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}(),E=x(C()),R=function(){return o((function t(e,r){n(this,t),D(this,"_room"),D(this,"_core"),D(this,"_log"),D(this,"_paramsForTencentCDN"),D(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)),o="main"===r.streamType?"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=9;break}return t.next=9,this.startPublishTencentCDN(i.target);case 9: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=S(S({},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 T(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,E.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,E.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,E.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(t)))}}]);var t,e,i,s,u,c}(),O=x(C()),A=function(){function t(e,r){n(this,t),D(this,"_core"),D(this,"_room"),D(this,"_log"),D(this,"_seq"),D(this,"_taskId"),D(this,"_startData",null),D(this,"_updateData",null),D(this,"_stopData",null),this._core=e,this._room=e.room,this._log=r,this._seq=0;var o=localStorage.getItem(t.TASK_ID_KEY);o&&(this._taskId=o)}return o(t,[{key:"startPushStreamToRoom",value:(s=r(a().mark((function e(r){var n,o,i,s,u,c;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!this._taskId){e.next=4;break}return e.next=4,this.stopPushStreamToRoom();case 4:e.next=9;break;case 6:e.prev=6,e.t0=e.catch(0),this._log.warn("stopPushStreamToRoom prev taskId failed",e.t0);case 9:return this._seq+=1,this._startData=S({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,O.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_start")),agentParam:{cdnRobotUserid:"mcu_robot_".concat(this._room.roomId,"_").concat(this._room.userId)}},this.getCommonParams(r)),this._log.info("startPushStreamToRoom: ".concat(JSON.stringify(this._startData))),e.next=14,this._room.sendStartPushStreamToRoom(this._startData);case 14:i=e.sent,s=i.data,u=s.code,c=s.message,0===u?(this._taskId=null==(o=null==(n=i.data)?void 0:n.data)?void 0:o.taskId,this._taskId?localStorage.setItem(t.TASK_ID_KEY,this._taskId):this.reportServerError("startPushStreamToRoom",u,"can't resolve task id: ".concat(JSON.stringify(i.data))),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",u,c);case 17:case"end":return e.stop()}}),e,this,[[0,6]])}))),function(t){return s.apply(this,arguments)})},{key:"updatePushStreamToRoom",value:(i=r(a().mark((function t(e){var r,n,o,i,s;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this._seq+=1,this._updateData=S({taskid:this._taskId},this.getCommonParams(e)),this._core.utils.isBoolean(null==(r=e.mix)?void 0:r.enableNtpSync)&&(this._updateData.enableNtpSync=e.mix.enableNtpSync),this._log.info("updatePushStreamToRoom: ".concat(JSON.stringify(this._updateData))),t.next=6,this._room.sendUpdatePushStreamToRoom(this._updateData);case 6:n=t.sent,o=n.data,i=o.code,s=o.message,0===i?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",i,s);case 9:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"stopPushStreamToRoom",value:(e=r(a().mark((function e(){var r,n,o,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._taskId){e.next=2;break}return e.abrupt("return");case 2:return this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info("stopPushStreamToRoom: ".concat(JSON.stringify(this._stopData))),e.next=7,this._room.sendStopPushStreamToRoom(this._stopData);case 7:r=e.sent,n=r.data,o=n.code,i=n.message,0===o?(delete this._taskId,localStorage.removeItem(t.TASK_ID_KEY),this._log.info("server success: start mix")):this.reportServerError("stopPushStreamToRoom",o,i);case 10:case"end":return e.stop()}}),e,this)}))),function(){return e.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){var e;return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(t),videoParam:this.getVideoParam(t),pushRtcRoomParams:this.getPushRtcRoomParams(t),sequenceNumber:this._seq,enableNtpSync:(null==(e=t.mix)?void 0:e.enableNtpSync)||!1}}},{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 e,i,s}();D(A,"TASK_ID_KEY","trtc_mix_to_room_taskId");var L,j=A;var G,U,V={type:"number",notLessThanZero:!0},F={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:function(t,e,r,n){var o=L,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=L,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"}})}}}},q={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=L,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:S({},F)},validate:function(t,e,r,n){var o=t.publishMode,i=t.robotUser;if("publish-mix-stream-to-room"===o&&!i){var a=L;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:V,videoHeight:V,videoBitrate:(G=S({},V),U={allowEmpty:!1},m(G,f(U))),videoFramerate:{type:"number",validate:function(t,e,r,n){if(t<=0||t>30){var o=L;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=L;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:V,audioBitrate:{type:"number",validate:function(t,e,r,n){if(t<32||t>192){var o=L;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]}}},z={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:S({},F)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:S({},F),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=L;throw new(0,o.RtcError)({code:o.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:V,height:V,locationX:V,locationY:V}}}}};var B=0,Y=function(){function t(e){n(this,t),this.core=e,D(this,"_mixTranscodeManager"),D(this,"_publishCDNManager"),D(this,"_pushStreamToRoomManager"),D(this,"_core"),D(this,"_modeOptions"),D(this,"seq"),D(this,"_log"),B+=1,this.seq=B,this._log=e.log.createChild({id:"".concat(this.getAlias()).concat(B)}),this._log.info("[CDNStreaming] created id=".concat(this.getAlias()).concat(B)),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new M(e,this._log),this._publishCDNManager=new R(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,L=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:S({},q),encoding:S({},J),mix:S({},z)},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 L=t.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:S({},q),encoding:S({},J),mix:S({},z)}}}(this._core);case"stop":return function(t){return L=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:12;break;case 3:return t.next=5,this._mixTranscodeManager.stopMixTranscode();case 5:return t.abrupt("break",12);case 6:return t.next=8,this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);case 8:return t.abrupt("break",12);case 9:return t.next=11,this._pushStreamToRoomManager.stopPushStreamToRoom();case 11:return t.abrupt("break",12);case 12:this._modeOptions.delete(e.target.publishMode);case 13: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 D(Y,"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"}}),D(Y,"Name","CDNStreaming"),Y}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface StartCrossRoomOption {
|
|
2
|
+
roomId?: number,
|
|
3
|
+
strRoomId?: string,
|
|
4
|
+
userId?: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface UpdateCrossRoomOptionItem extends StartCrossRoomOption {
|
|
8
|
+
muteAudio: boolean,
|
|
9
|
+
muteVideo: boolean,
|
|
10
|
+
muteSubStream: boolean,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UpdateCrossRoomOption {
|
|
14
|
+
updateList: UpdateCrossRoomOptionItem[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface StopCrossRoomOption {
|
|
18
|
+
roomId?: number,
|
|
19
|
+
strRoomId?: string,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export declare class CrossRoom {
|
|
24
|
+
start(option: StartCrossRoomOption): Promise<void>;
|
|
25
|
+
update(option: UpdateCrossRoomOption): Promise<void>;
|
|
26
|
+
stop(option?: StopCrossRoomOption): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__publicField=(e,t,r)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,r),StartValidateRule={name:"option",required:!0,properties:{view:{type:["string",HTMLElement],required:!0},url:{type:"string",required:!0},licenseConfig:{type:"object",required:!0,properties:{secretKey:{type:"string",required:!0},encrypted:{type:"string",required:!0},signature:{type:"string",required:!0}}}}},updateSdpForFirefox=e=>{if(!navigator.userAgent.includes("Firefox"))return e;const t=e.split("\r\n"),r=[],o=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)})),r.length>1&&o.push(...r.slice(1));const s=o.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),i=[];return t.forEach((e=>{let t=e;if(e.includes("a=setup")&&(t="a=setup:passive"),(e.includes("m=audio")||e.includes("m=video"))&&(t=e.split(" ").filter(((e,t)=>t<3||!s.includes(e))).join(" ")),e.includes("a=fmtp")||e.includes("a=rtcp-fb")||e.includes("a=rtpmap")){const t=/a=(?:fmtp|rtcp-fb|rtpmap):(\d+)\s/.exec(e);if(t&&t.length>1&&s.includes(t[1]))return}i.push(t)})),i.join("\r\n")},updateSdpRestriction=e=>{const t=e.split("\r\n"),r=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)}));const o=r.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),s=[];t.forEach((e=>{let t=e;if(e.includes("a=fmtp:111")&&(t=`${e};stereo=1`),e.includes("a=fmtp")){const r=/a=fmtp:(\d+)\s/.exec(e);r&&r.length>1&&o.includes(r[1])&&(t=`${e};sps-pps-idr-in-keyframe=1`)}s.push(t)}));const i=s.join("\r\n");return updateSdpForFirefox(i)},urlAlphabet="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=urlAlphabet[63&r[e]];return t},SIGNAL_DOMAIN_NAME_LIST=["overseas-webrtc.tlivewebrtc.com","oswebrtc-lint.tliveplay.com"],_FastWebRTC=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"fwrtc"}getGroup(){return""}getValidateRule(e){switch(e){case"start":return StartValidateRule;case"update":case"stop":return{}}}async start(e){const{view:t,url:r,licenseConfig:o}=e}async connect(e){const t=new RTCPeerConnection({iceServers:[],sdpSemantics:"unified-plan",bundlePolicy:"max-bundle",rtcpMuxPolicy:"require",tcpCandidatePolicy:"disable",IceTransportsType:"nohost"});t.addTransceiver("audio",{direction:"recvonly"}),t.addTransceiver("video",{direction:"recvonly"});const r=await t.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0,voiceActivityDetection:!1});r.sdp=updateSdpRestriction(r.sdp),await t.setLocalDescription(r);const o={sessionId:nanoid(),streamurl:e,clientinfo:"macos chrome115",localsdp:t.localDescription},{remoteSdp:s,svrSig:i}=await this.core.utils.promiseAny(SIGNAL_DOMAIN_NAME_LIST.map((e=>this.exchangeSDP(e,o,3))));await t.setRemoteDescription(s)}async exchangeSDP(e,t,r){const o=`${e}/webrtc/v1/pullstream`,s=await fetchPost(o,t,{timeout:r}),{errcode:i,errmsg:n,remotesdp:a,svrsig:c}=s;if(0!==i){const e=new Error(`errCode:${i}, errMsg:${n}`);throw e.name="RequestSignalError",e}return{url:e,remoteSdp:a,svrSig:c}}async update(e){}async stop(){}destroy(){}};__publicField(_FastWebRTC,"Name","FastWebRTC");var FastWebRTC=_FastWebRTC,fetchPost=async(e,t,r={})=>{const{timeout:o=10}=r;let s,i=0,n={};window.AbortController&&(s=new window.AbortController,n={signal:s.signal},i=window.setTimeout((()=>s.abort()),1e3*o));const a=await fetch(e,__spreadValues({body:JSON.stringify(t),cache:"no-cache",credentials:"same-origin",headers:{"content-type":"text/plain;charset=utf-8"},method:"POST",mode:"cors"},n));if(i&&window.clearTimeout(i),200!==a.status)throw new Error(`Network Error, status code:${a.status}`);return a.json()},index_default=FastWebRTC;export{index_default as default};export{FastWebRTC};
|