trtc-sdk-v5 5.15.0-wasm.2 → 5.15.0
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 +92 -0
- package/package.json +6 -4
- package/plugins/cdn-streaming/cdn-streaming.esm.js +1 -1
- package/plugins/cdn-streaming/cdn-streaming.umd.js +3 -1
- package/plugins/cdn-streaming/package.json +1 -1
- package/plugins/chorus/chorus.esm.js +1 -1
- package/plugins/chorus/chorus.umd.js +3 -1
- package/plugins/chorus/package.json +1 -1
- package/plugins/cross-room/cross-room.esm.js +1 -1
- package/plugins/cross-room/cross-room.umd.js +3 -1
- package/plugins/cross-room/package.json +1 -1
- package/plugins/custom-encryption/custom-encryption.esm.js +1 -1
- package/plugins/custom-encryption/custom-encryption.umd.js +3 -1
- package/plugins/custom-encryption/package.json +1 -1
- package/plugins/device-detector/device-detector.esm.js +44 -56
- package/plugins/device-detector/device-detector.umd.js +4 -14
- package/plugins/device-detector/package.json +1 -1
- package/plugins/lebplayer/lebplayer.esm.d.ts +7 -0
- package/plugins/lebplayer/lebplayer.esm.js +1 -1
- package/plugins/lebplayer/lebplayer.umd.js +3 -1
- package/plugins/lebplayer/package.json +1 -1
- package/plugins/realtime-transcriber/package.json +29 -0
- package/plugins/realtime-transcriber/realtime-transcriber.esm.d.ts +16 -0
- package/plugins/realtime-transcriber/realtime-transcriber.esm.js +1 -0
- package/plugins/realtime-transcriber/realtime-transcriber.umd.js +3 -0
- package/plugins/small-stream-auto-switcher/package.json +1 -1
- package/plugins/small-stream-auto-switcher/small-stream-auto-switcher.esm.js +1 -1
- package/plugins/small-stream-auto-switcher/small-stream-auto-switcher.umd.js +1 -1
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-decoder/video-decoder.esm.js +1 -1
- package/plugins/video-decoder/video-decoder.umd.js +3 -1
- package/plugins/video-effect/basic-beauty/basic-beauty.esm.js +1 -1
- package/plugins/video-effect/basic-beauty/basic-beauty.umd.js +3 -1
- package/plugins/video-effect/basic-beauty/package.json +1 -1
- package/plugins/video-effect/beauty/beauty.esm.js +1 -1
- package/plugins/video-effect/beauty/beauty.umd.js +3 -1
- package/plugins/video-effect/beauty/package.json +1 -1
- package/plugins/video-effect/face-detection/face-detection.esm.js +1 -1
- package/plugins/video-effect/face-detection/face-detection.umd.js +3 -1
- package/plugins/video-effect/face-detection/package.json +1 -1
- package/plugins/video-effect/video-mixer/package.json +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.esm.js +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.umd.js +3 -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 +3 -1
- package/plugins/video-effect/watermark/package.json +1 -1
- package/plugins/video-effect/watermark/watermark.umd.js +3 -1
- package/plugins/voice-changer/package.json +1 -1
- package/plugins/voice-changer/voice-changer.esm.js +1 -1
- package/plugins/voice-changer/voice-changer.umd.js +3 -1
- package/trtc.esm.js +41 -69
- package/trtc.js +1 -1
- package/assets/av_processing.wasm +0 -0
- package/assets/worker.js +0 -17
package/index.d.ts
CHANGED
|
@@ -443,6 +443,8 @@ export declare interface UpdateScreenShareConfig extends ScreenShareConfig {
|
|
|
443
443
|
option?: {
|
|
444
444
|
fillMode?: 'contain' | 'cover' | 'fill';
|
|
445
445
|
qosPreference?: typeof TRTCType.QOS_PREFERENCE_SMOOTH | typeof TRTCType.QOS_PREFERENCE_CLEAR;
|
|
446
|
+
audioTrack?: MediaStreamTrack;
|
|
447
|
+
videoTrack?: MediaStreamTrack;
|
|
446
448
|
};
|
|
447
449
|
}
|
|
448
450
|
export declare interface RemoteVideoConfig {
|
|
@@ -520,6 +522,30 @@ export declare interface PermissionOption {
|
|
|
520
522
|
types?: ('camera' | 'microphone')[];
|
|
521
523
|
}
|
|
522
524
|
|
|
525
|
+
export declare interface RealtimeTranscriberStateEvent {
|
|
526
|
+
state: 'started' | 'stopped';
|
|
527
|
+
roomId: string | number;
|
|
528
|
+
transcriberRobotId: string;
|
|
529
|
+
sourceLanguage?: string;
|
|
530
|
+
error?: number;
|
|
531
|
+
errorMessage?: string;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export declare interface TranslationText {
|
|
535
|
+
language: string;
|
|
536
|
+
text: string;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export declare interface RealtimeTranscriberMessageEvent {
|
|
540
|
+
segmentId: string;
|
|
541
|
+
speakerUserId: string;
|
|
542
|
+
sourceText: string;
|
|
543
|
+
translationTexts: TranslationText[];
|
|
544
|
+
timestamp: number;
|
|
545
|
+
isCompleted: boolean;
|
|
546
|
+
robotId: string;
|
|
547
|
+
}
|
|
548
|
+
|
|
523
549
|
export declare interface PermissionResult {
|
|
524
550
|
camera: PermissionState | null;
|
|
525
551
|
microphone: PermissionState | null;
|
|
@@ -1269,6 +1295,55 @@ export declare const TRTCEvent: {
|
|
|
1269
1295
|
* })
|
|
1270
1296
|
*/
|
|
1271
1297
|
readonly VIDEO_SIZE_CHANGED: 'video-size-changed';
|
|
1298
|
+
/**
|
|
1299
|
+
* @since v5.15.0
|
|
1300
|
+
* @description Realtime transcriber message
|
|
1301
|
+
* @default 'realtime-transcriber-message'
|
|
1302
|
+
* @memberof module:EVENT
|
|
1303
|
+
* @example
|
|
1304
|
+
* trtc.on(TRTC.EVENT.REALTIME_TRANSCRIBER_MESSAGE, event => {
|
|
1305
|
+
* // event.data: custom message data, type is ArrayBuffer.
|
|
1306
|
+
* })
|
|
1307
|
+
*/
|
|
1308
|
+
readonly REALTIME_TRANSCRIBER_MESSAGE: 'realtime-transcriber-message';
|
|
1309
|
+
/**
|
|
1310
|
+
* @since v5.15.0
|
|
1311
|
+
* @description Realtime transcriber state changed
|
|
1312
|
+
* @default 'realtime-transcriber-state-changed'
|
|
1313
|
+
* @memberof module:EVENT
|
|
1314
|
+
* @example
|
|
1315
|
+
* trtc.on(TRTC.EVENT.REALTIME_TRANSCRIBER_STATE_CHANGED, event => {
|
|
1316
|
+
* // event.state: transcriber state.
|
|
1317
|
+
* })
|
|
1318
|
+
*/
|
|
1319
|
+
readonly REALTIME_TRANSCRIBER_STATE_CHANGED: 'realtime-transcriber-state-changed';
|
|
1320
|
+
/**
|
|
1321
|
+
* @since v5.15.0
|
|
1322
|
+
* @description Picture in picture state change event
|
|
1323
|
+
* @default 'picture-in-picture-state-changed'
|
|
1324
|
+
* @memberof module:EVENT
|
|
1325
|
+
* @example
|
|
1326
|
+
* trtc.on(TRTC.EVENT.PICTURE_IN_PICTURE_STATE_CHANGED, event => {
|
|
1327
|
+
* // event.userId: userId.
|
|
1328
|
+
* // event.streamType: video stream type.
|
|
1329
|
+
* // event.isPictureInPicture: is in picture in picture.
|
|
1330
|
+
* // event.pictureInPictureWindow: Exist when isPictureInPicture is true. See: https://developer.mozilla.org/en-US/docs/Web/API/PictureInPictureWindow
|
|
1331
|
+
* })
|
|
1332
|
+
*/
|
|
1333
|
+
readonly PICTURE_IN_PICTURE_STATE_CHANGED: 'picture-in-picture-state-changed',
|
|
1334
|
+
/**
|
|
1335
|
+
* @since v5.15.0
|
|
1336
|
+
* @description Full screen state change event
|
|
1337
|
+
* @default 'full-screen-state-changed'
|
|
1338
|
+
* @memberof module:EVENT
|
|
1339
|
+
* @example
|
|
1340
|
+
* trtc.on(TRTC.EVENT.FULL_SCREEN_STATE_CHANGED, event => {
|
|
1341
|
+
* // event.userId: userId.
|
|
1342
|
+
* // event.streamType: video stream type.
|
|
1343
|
+
* // event.isFullScreen: is in full screen.
|
|
1344
|
+
* })
|
|
1345
|
+
*/
|
|
1346
|
+
readonly FULL_SCREEN_STATE_CHANGED: 'full-screen-state-changed'
|
|
1272
1347
|
};
|
|
1273
1348
|
export declare interface TRTCEventTypes {
|
|
1274
1349
|
[TRTCEvent.ERROR]: [RtcError];
|
|
@@ -1373,6 +1448,23 @@ export declare interface TRTCEventTypes {
|
|
|
1373
1448
|
width: number;
|
|
1374
1449
|
height: number;
|
|
1375
1450
|
}];
|
|
1451
|
+
[TRTCEvent.REALTIME_TRANSCRIBER_MESSAGE]: [RealtimeTranscriberMessageEvent];
|
|
1452
|
+
[TRTCEvent.REALTIME_TRANSCRIBER_STATE_CHANGED]: [RealtimeTranscriberStateEvent];
|
|
1453
|
+
[TRTCEvent.PICTURE_IN_PICTURE_STATE_CHANGED]: [PictureInPictureStateChangedEvent];
|
|
1454
|
+
[TRTCEvent.FULL_SCREEN_STATE_CHANGED]: [FullScreenStateChangedEvent]
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
export interface PictureInPictureStateChangedEvent {
|
|
1458
|
+
userId: string;
|
|
1459
|
+
streamType: TRTCStreamType;
|
|
1460
|
+
isPictureInPicture: boolean;
|
|
1461
|
+
pictureInPictureWindow?: PictureInPictureWindow;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
export interface FullScreenStateChangedEvent {
|
|
1465
|
+
userId: string;
|
|
1466
|
+
streamType: TRTCStreamType;
|
|
1467
|
+
isFullScreen: boolean;
|
|
1376
1468
|
}
|
|
1377
1469
|
|
|
1378
1470
|
export declare interface CustomMessageData {
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trtc-sdk-v5",
|
|
3
|
-
"version": "5.15.0
|
|
3
|
+
"version": "5.15.0",
|
|
4
4
|
"description": "Tencent Cloud RTC SDK for Web",
|
|
5
|
-
"
|
|
6
|
-
"type": "module",
|
|
5
|
+
"main": "trtc.js",
|
|
7
6
|
"types": "index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"webrtc-adapter": "^8.2.3"
|
|
9
|
+
},
|
|
8
10
|
"keywords": [
|
|
9
11
|
"webrtc",
|
|
10
12
|
"TRTC",
|
|
@@ -27,4 +29,4 @@
|
|
|
27
29
|
},
|
|
28
30
|
"author": "Tencent Cloud Client R&D Center",
|
|
29
31
|
"license": "ISC"
|
|
30
|
-
}
|
|
32
|
+
}
|
|
@@ -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){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 +1,3 @@
|
|
|
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,o=Array(e);r<e;r++)o[r]=t[r];return o}function e(t,e,r,o,n,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(o,n)}function r(t){return function(){var r=this,o=arguments;return new Promise(function(n,i){var a=t.apply(r,o);function s(t){e(a,n,i,s,u,"next",t)}function u(t){e(a,n,i,s,u,"throw",t)}s(void 0)})}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,u(o.key),o)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(e,r){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!o){if(Array.isArray(e)||(o=function(e,r){if(e){if("string"==typeof e)return t(e,r);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?t(e,r):void 0}}(e))||r){o&&(e=o);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},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(){o=o.call(e)},n:function(){var t=o.next();return s=t.done,t},e:function(t){u=!0,a=t},f:function(){try{s||null==o.return||o.return()}finally{if(u)throw a}}}}function a(){
|
|
2
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
+
var t,e,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",n=r.toStringTag||"@@toStringTag";function i(r,o,n,i){var a=o&&o.prototype instanceof c?o:c,d=Object.create(a.prototype);return s(d,"_invoke",function(r,o,n){var i,a,s,c=0,d=n||[],h=!1,l={p:0,n:0,v:t,a:m,f:m.bind(t,4),d:function(e,r){return i=e,a=0,s=t,l.n=r,u}};function m(r,o){for(a=r,s=o,e=0;!h&&c&&!n&&e<d.length;e++){var n,i=d[e],m=l.p,p=i[2];r>3?(n=p===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=m&&((n=r<2&&m<i[1])?(a=0,l.v=o,l.n=i[1]):m<p&&(n=r<3||i[0]>o||o>p)&&(i[4]=r,i[5]=o,l.n=p,a=0))}if(n||r>1)return u;throw h=!0,o}return function(n,d,p){if(c>1)throw TypeError("Generator is already running");for(h&&1===d&&m(d,p),a=d,s=p;(e=a<2?t:s)||!h;){i||(a?a<3?(a>1&&(l.n=-1),m(a,s)):l.n=s:l.v=s);try{if(c=2,i){if(a||(n="next"),e=i[n]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+n+"' method"),a=1);i=t}else if((e=(h=l.n<0)?s:r.call(o,l))!==u)break}catch(e){i=t,a=1,s=e}finally{c=1}}return{value:e,done:h}}}(r,n,i),!0),d}var u={};function c(){}function d(){}function h(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(s(e={},o,function(){return this}),e),m=h.prototype=c.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,n,"GeneratorFunction")),t.prototype=Object.create(m),t}return d.prototype=h,s(m,"constructor",h),s(h,"constructor",d),d.displayName="GeneratorFunction",s(h,n,"GeneratorFunction"),s(m),s(m,n,"Generator"),s(m,o,function(){return this}),s(m,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:p}})()}function s(t,e,r,o){var n=Object.defineProperty;try{n({},"",{})}catch(t){n=0}s=function(t,e,r,o){function i(e,r){s(t,e,function(t){return this._invoke(e,r,t)})}e?n?n(t,e,{value:r,enumerable:!o,configurable:!o,writable:!o}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},s(t,e,r,o)}function u(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}var d,h,l=Object.create,m=Object.defineProperty,p=Object.defineProperties,f=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols,_=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,I=function(t,e,r){return e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r},D=function(t,e){for(var r in e||(e={}))y.call(e,r)&&I(t,r,e[r]);if(b){var o,n=i(b(e));try{for(n.s();!(o=n.n()).done;){r=o.value;S.call(e,r)&&I(t,r,e[r])}}catch(t){n.e(t)}finally{n.f()}}return t},C=function(t,e,r){return r=null!=t?l(_(t)):{},function(t,e,r,o){if(e&&"object"===c(e)||"function"==typeof e){var n,a=i(v(e));try{var s=function(){var i=n.value;y.call(t,i)||i===r||m(t,i,{get:function(){return e[i]},enumerable:!(o=f(e,i))||o.enumerable})};for(a.s();!(n=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}}return t}(m(r,"default",{value:t,enumerable:!0}),t)},N=function(t,e,r){return I(t,"symbol"!==c(e)?e+"":e,r)},P=(d={"../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 o(t,e,o,n,i,a){return r((s=r(r(e,t),r(n,a)))<<(u=i)|s>>>32-u,o);var s,u}function n(t,e,r,n,i,a,s){return o(e&r|~e&n,t,e,i,a,s)}function i(t,e,r,n,i,a,s){return o(e&n|r&~n,t,e,i,a,s)}function a(t,e,r,n,i,a,s){return o(e^r^n,t,e,i,a,s)}function s(t,e,r,n,i,a,s){return o(r^(e|~n),t,e,i,a,s)}function u(t,e){var o,u,c,d,h;t[e>>5]|=128<<e%32,t[14+(e+64>>>9<<4)]=e;var l=1732584193,m=-271733879,p=-1732584194,f=271733878;for(o=0;o<t.length;o+=16)u=l,c=m,d=p,h=f,l=n(l,m,p,f,t[o],7,-680876936),f=n(f,l,m,p,t[o+1],12,-389564586),p=n(p,f,l,m,t[o+2],17,606105819),m=n(m,p,f,l,t[o+3],22,-1044525330),l=n(l,m,p,f,t[o+4],7,-176418897),f=n(f,l,m,p,t[o+5],12,1200080426),p=n(p,f,l,m,t[o+6],17,-1473231341),m=n(m,p,f,l,t[o+7],22,-45705983),l=n(l,m,p,f,t[o+8],7,1770035416),f=n(f,l,m,p,t[o+9],12,-1958414417),p=n(p,f,l,m,t[o+10],17,-42063),m=n(m,p,f,l,t[o+11],22,-1990404162),l=n(l,m,p,f,t[o+12],7,1804603682),f=n(f,l,m,p,t[o+13],12,-40341101),p=n(p,f,l,m,t[o+14],17,-1502002290),l=i(l,m=n(m,p,f,l,t[o+15],22,1236535329),p,f,t[o+1],5,-165796510),f=i(f,l,m,p,t[o+6],9,-1069501632),p=i(p,f,l,m,t[o+11],14,643717713),m=i(m,p,f,l,t[o],20,-373897302),l=i(l,m,p,f,t[o+5],5,-701558691),f=i(f,l,m,p,t[o+10],9,38016083),p=i(p,f,l,m,t[o+15],14,-660478335),m=i(m,p,f,l,t[o+4],20,-405537848),l=i(l,m,p,f,t[o+9],5,568446438),f=i(f,l,m,p,t[o+14],9,-1019803690),p=i(p,f,l,m,t[o+3],14,-187363961),m=i(m,p,f,l,t[o+8],20,1163531501),l=i(l,m,p,f,t[o+13],5,-1444681467),f=i(f,l,m,p,t[o+2],9,-51403784),p=i(p,f,l,m,t[o+7],14,1735328473),l=a(l,m=i(m,p,f,l,t[o+12],20,-1926607734),p,f,t[o+5],4,-378558),f=a(f,l,m,p,t[o+8],11,-2022574463),p=a(p,f,l,m,t[o+11],16,1839030562),m=a(m,p,f,l,t[o+14],23,-35309556),l=a(l,m,p,f,t[o+1],4,-1530992060),f=a(f,l,m,p,t[o+4],11,1272893353),p=a(p,f,l,m,t[o+7],16,-155497632),m=a(m,p,f,l,t[o+10],23,-1094730640),l=a(l,m,p,f,t[o+13],4,681279174),f=a(f,l,m,p,t[o],11,-358537222),p=a(p,f,l,m,t[o+3],16,-722521979),m=a(m,p,f,l,t[o+6],23,76029189),l=a(l,m,p,f,t[o+9],4,-640364487),f=a(f,l,m,p,t[o+12],11,-421815835),p=a(p,f,l,m,t[o+15],16,530742520),l=s(l,m=a(m,p,f,l,t[o+2],23,-995338651),p,f,t[o],6,-198630844),f=s(f,l,m,p,t[o+7],10,1126891415),p=s(p,f,l,m,t[o+14],15,-1416354905),m=s(m,p,f,l,t[o+5],21,-57434055),l=s(l,m,p,f,t[o+12],6,1700485571),f=s(f,l,m,p,t[o+3],10,-1894986606),p=s(p,f,l,m,t[o+10],15,-1051523),m=s(m,p,f,l,t[o+1],21,-2054922799),l=s(l,m,p,f,t[o+8],6,1873313359),f=s(f,l,m,p,t[o+15],10,-30611744),p=s(p,f,l,m,t[o+6],15,-1560198380),m=s(m,p,f,l,t[o+13],21,1309151649),l=s(l,m,p,f,t[o+4],6,-145523070),f=s(f,l,m,p,t[o+11],10,-1120210379),p=s(p,f,l,m,t[o+2],15,718787259),m=s(m,p,f,l,t[o+9],21,-343485551),l=r(l,u),m=r(m,c),p=r(p,d),f=r(f,h);return[l,m,p,f]}function d(t){var e,r="",o=32*t.length;for(e=0;e<o;e+=8)r+=String.fromCharCode(t[e>>5]>>>e%32&255);return r}function h(t){var e,r=[];for(r[(t.length>>2)-1]=void 0,e=0;e<r.length;e+=1)r[e]=0;var o=8*t.length;for(e=0;e<o;e+=8)r[e>>5]|=(255&t.charCodeAt(e/8))<<e%32;return r}function l(t){var e,r,o="0123456789abcdef",n="";for(r=0;r<t.length;r+=1)e=t.charCodeAt(r),n+=o.charAt(e>>>4&15)+o.charAt(15&e);return n}function m(t){return unescape(encodeURIComponent(t))}function p(t){return function(t){return d(u(h(t),8*t.length))}(m(t))}function f(t,e){return function(t,e){var r,o,n=h(t),i=[],a=[];for(i[15]=a[15]=void 0,n.length>16&&(n=u(n,8*t.length)),r=0;r<16;r+=1)i[r]=909522486^n[r],a[r]=1549556828^n[r];return o=u(i.concat(h(e)),512+8*e.length),d(u(a.concat(o),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"===c(e)&&e.exports?e.exports=g:t.md5=g}(t)}},function(){return h||(0,d[v(d)[0]])((h={exports:{}}).exports,h),h.exports}),T=C(P()),w=0,k=4,M=5,R=function(){return n(function t(e,r){o(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_params"),N(this,"_publishGivenCDNData",null),this._core=e,this._room=e.room,this._log=r},[{key:"isPublishingGivenCDN",get:function(){return!!this._params}},{key:"startPublishGivenCDN",value:(e=r(a().m(function t(e){var r,o,n,i,s,u,c,d,h;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this._log.info("[CDNStreaming] startPublishGivenCDN() current: ".concat(JSON.stringify(this._params),", params: ").concat(JSON.stringify(e))),!this.isPublishingGivenCDN){t.n=2;break}if(r=this._params||{},o=r.appId,n=r.bizId,i=r.url,o!==e.appId||n!==e.bizId||i!==e.url){t.n=1;break}return t.a(2);case 1:return t.n=2,this.stopPublishGivenCDN();case 2: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.p=3,t.n=4,this._room.sendStartPublishCDN(this._publishGivenCDNData,!1);case 4:if(s=t.v,u=s.data,c=u.code,d=u.message,0!==c){t.n=5;break}this._log.info("[CDNStreaming] server success: start given cdn."),t.n=6;break;case 5:throw this.resetGivenCDN(),this._log.error("[CDNStreaming] server failed: start given cdn errCode: ".concat(c," errMsg: ").concat(d," options: ").concat(JSON.stringify(e))),new Error("[CDNStreaming] server failed: start given cdn errCode: ".concat(c," errMsg: ").concat(d));case 6:t.n=8;break;case 7:throw t.p=7,h=t.v,this.resetGivenCDN(),h;case 8:return t.a(2)}},t,this,[[3,7]])})),function(t){return e.apply(this,arguments)})},{key:"stopPublishGivenCDN",value:(t=r(a().m(function t(){var e,r,o,n,i,s,u,c,d,h,l;return a().w(function(t){for(;;)switch(t.n){case 0:if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),this.isPublishingGivenCDN&&this._publishGivenCDNData){t.n=1;break}return this.resetGivenCDN(),t.a(2);case 1:return e=this._publishGivenCDNData,r=e.pushAppId,o=e.pushBizId,n=e.pushCdnUrl,i=e.pushStreamType,s=e.pushStreamId,u={pushRequestTime:Date.now(),pushAppId:r,pushBizId:o,pushCdnUrl:n,pushStreamType:i,pushStreamId:s},t.n=2,this._room.sendStopPublishCDN(u,!1);case 2:if(c=t.v,d=c.data,h=d.code,l=d.message,0!==h){t.n=3;break}this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN(),t.n=4;break;case 3:throw this._log.error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(h," errMsg: ").concat(l," data: ").concat(JSON.stringify(u))),new Error("[CDNStreaming] server failed: stop given cdn errCode: ".concat(h," errMsg: ").concat(l));case 4:return t.a(2)}},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}(),E=function(){return n(function t(e,r){o(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_config",null),N(this,"_data",null),N(this,"_givenCDNManager"),this._core=e,this._room=e.room,this._log=r,this.reset()},[{key:"isMixing",get:function(){return!!this._data}},{key:"isStarted",get:function(){return!!this._config}},{key:"hasCustomCDN",get:function(){var t,e,r;return(null==(t=this._config)?void 0:t.target.appId)&&(null==(e=this._config)?void 0:e.target.bizId)&&(null==(r=this._config)?void 0:r.target.url)}},{key:"startMixTranscode",value:(c=r(a().m(function t(e){var r,o,n,i,s,u,c,d,h,l,m,p;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this._log.info("startMixTranscode: ".concat(JSON.stringify(e))),r=this._config,o=this._data,this._config=e,this.installEvents(),this._core.room.isJoined){t.n=1;break}return t.a(2);case 1:if(t.p=1,n=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.n=2;break}return this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),t.n=2,this.doStopMixTranscode();case 2:return t.n=3,this.doStartMixTranscode({outputSessionId:s,inputParam:n,outputParam:i});case 3:if(u=e.target,c=u.appId,d=u.bizId,h=u.url,l=u.streamId,m=void 0===l?"":l,!(c&&d&&h)){t.n=4;break}return this._givenCDNManager||(this._givenCDNManager=new R(this._core,this._log)),t.n=4,this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:c,bizId:d,url:h,streamId:m});case 4:t.n=6;break;case 5:throw t.p=5,p=t.v,o?(this._log.warn("[CDNStreaming] update failed, restore previous state"),this._config=r,this._data=o):this.reset(),p;case 6:return t.a(2)}},t,this,[[1,5]])})),function(t){return c.apply(this,arguments)})},{key:"doStartMixTranscode",value:(u=r(a().m(function t(e){var r,o,n,i,s,u,c;return a().w(function(t){for(;;)switch(t.n){case 0:return r=e.outputSessionId,o=e.inputParam,n=e.outputParam,i={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:r,inputParam:o,outputParam:n},this._log.info("[CDNStreaming] doStartMixTranscode: ".concat(JSON.stringify(i))),t.n=1,this._room.sendStartMixTranscode(i);case 1:if(s=t.v,u=s.data.code,c=s.data.message,0!==u){t.n=2;break}this._log.info("[CDNStreaming] server success: start mix"),this._data=i,t.n=3;break;case 2: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 3:return t.a(2)}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"stopMixTranscode",value:(s=r(a().m(function t(){return a().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this._log.info("[CDNStreaming] stopMixTranscode"),t.p=1,!this.isStarted||!this.isMixing){t.n=3;break}return t.n=2,this.doStopMixTranscode();case 2:if(!(this._config&&this.hasCustomCDN&&this._givenCDNManager)){t.n=3;break}return t.n=3,this._givenCDNManager.stopPublishGivenCDN();case 3:t.n=5;break;case 4:throw t.p=4,t.v;case 5:this.reset();case 6:return t.a(2)}},t,this,[[1,4]])})),function(){return s.apply(this,arguments)})},{key:"doStopMixTranscode",value:(i=r(a().m(function t(){var e,r,o,n,i;return a().w(function(t){for(;;)switch(t.n){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.n=1,this._room.sendStopMixTranscode(e);case 1:if(r=t.v,o=r.data,n=o.code,i=o.message,0!==n){t.n=2;break}this._log.info("[CDNStreaming] server success: stop mix"),this.reset(),t.n=3;break;case 2:throw this._log.error("[CDNStreaming] server failed: stop mix errCode: ".concat(n," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop mix errCode: ".concat(n," errMsg: ").concat(i));case 3:return t.a(2)}},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().m(function t(){return a().w(function(t){for(;;)switch(t.n){case 0:if(this._log.info("[CDNStreaming] handleJoined: ".concat(JSON.stringify(this._config))),!this.isStarted||!this._config){t.n=1;break}return t.n=1,this.startMixTranscode(this._config);case 1:return t.a(2)}},t,this)})),function(){return e.apply(this,arguments)})},{key:"handleRoomLeft",value:(t=r(a().m(function t(){return a().w(function(t){for(;;)switch(t.n){case 0:this._log.info("[CDNStreaming] handleRoomLeft: ".concat(JSON.stringify(this._config))),this._data=null;case 1:return t.a(2)}},t,this)})),function(){return t.apply(this,arguments)})},{key:"getOutputSessionId",value:function(t){var e=t.config,r=t.userId,o=t.roomId;return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,T.default)("".concat(o,"_").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,o=void 0===r?{}:r,n=o.audioMixUserList,i=void 0===n?[]:n,a=o.videoLayoutList,s=(void 0===a?[]:a).map(function(t){return{userId:t.fixedVideoUser.userId,roomId:e.getStringRoomId(t.fixedVideoUser.roomId,t.fixedVideoUser.strRoomId)||e._core.room.roomId,width:t.width||0,height:t.height||0,locationX:t.locationX||0,locationY:t.locationY||0,zOrder:t.zOrder||1,streamType:"sub"===t.fixedVideoStreamType?1:0,inputType:M,renderMode:t.fillMode||0}});return i.forEach(function(t){var r=e._core.room.roomId;(t.roomId||t.strRoomId)&&(r=e.getStringRoomId(t.roomId,t.strRoomId));var o=s.findIndex(function(e){return e.userId===t.userId&&e.roomId===r});-1!==o?s[o].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,o=void 0===r?{}:r,n=t.mix,i=void 0===n?{}:n;return{streamId:e,streamType:e.length>0?1:0,width:this._core.utils.isUndefined(o.videoWidth)?640:o.videoWidth,height:this._core.utils.isUndefined(o.videoHeight)?480:o.videoHeight,videoBps:o.videoBitrate||0,fps:o.videoFramerate||15,gop:o.videoGOP||2,audioSampleRate:o.audioSampleRate||48e3,audioBps:o.audioBitrate||64,audioChannels:o.audioChannels||1,backgroundColor:i.backgroundColor||0,backgroundImg:i.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}}]);var t,e,i,s,u,c}(),x=C(P()),O=function(){return n(function t(e,r){o(this,t),N(this,"_room"),N(this,"_core"),N(this,"_log"),N(this,"_paramsForTencentCDN"),N(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1}),this._core=e,this._room=e.room,this._log=r,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])},[{key:"installEvents",value:function(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}},{key:"uninstallEvents",value:function(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}},{key:"handlePublished",value:(c=r(a().m(function t(e){var r,o,n,i;return a().w(function(t){for(;;)switch(t.n){case 0:if((r=e.track).room===this._room){t.n=1;break}return t.a(2);case 1:if(this._log.info("[CDNStreaming] handlePublished: mediaType ".concat(r.mediaType,", roomID ").concat(null==(o=null==r?void 0:r.room)?void 0:o.roomId)),n="main"===r.streamType?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",!(null==(i=this._paramsForTencentCDN.get(n)||null)?void 0:i.target)||!i.isStarted){t.n=2;break}return t.n=2,this.startPublishTencentCDN(i.target);case 2:return t.a(2)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"handleRoomLeft",value:(u=r(a().m(function t(){return a().w(function(t){for(;;)switch(t.n){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 1:return t.a(2)}},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),o=D(D({},r),e);this._paramsForTencentCDN.set(t,o)}},{key:"startPublishTencentCDN",value:(s=r(a().m(function t(e){var r,o,n,i,s,u,c,d,h;return a().w(function(t){for(;;)switch(t.n){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.n=1;break}return t.a(2);case 1:return r=e.streamId||"",o=this.generatePublishCDNStreamId(r,e.publishMode),n=this.generatePublishCDNSessionId(e.publishMode),i="publish-sub-stream-to-cdn"===e.publishMode?1:0,s={requestTime:Date.now(),sessionId:n,streamId:o,streamType:i},t.n=2,this.doStartPublishTencentCDN(s,e.publishMode);case 2:if(u=e.appId,c=e.bizId,d=e.url,!(u&&c&&d)){t.n=3;break}return(null==(h=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN)?void 0:h.givenCDNManager)||(h.givenCDNManager=new R(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,h)),t.n=3,h.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:u,bizId:c,url:d,streamId:o});case 3:return t.a(2)}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"doStartPublishTencentCDN",value:(i=r(a().m(function t(e,r){var o,n,i,s,u,c;return a().w(function(t){for(;;)switch(t.n){case 0:this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),o=6,n=500,i=0;case 1:return t.n=2,this._room.sendStartPublishCDN(e,!0);case 2:if(s=t.v,u=s.data.code,c=s.data.message,0!==u){t.n=3;break}return this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(r,{isPublished:!0}),t.a(3,7);case 3:if(!(-10006===u&&i<o)){t.n=5;break}return this._log.warn("[CDNStreaming] doStartPublishTencentCDN: retry...".concat(i+1,"/6, reason: ").concat(c)),i+=1,t.n=4,new Promise(function(t){return setTimeout(t,n)});case 4:t.n=6;break;case 5: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 6:t.n=1;break;case 7:return t.a(2)}},t,this)})),function(t,e){return i.apply(this,arguments)})},{key:"stopPublishTencentCDN",value:(e=r(a().m(function t(e){var r,o;return a().w(function(t){for(;;)switch(t.n){case 0:if(this._log.info("[CDNStreaming] doStartPublishTencentCDN: ".concat(JSON.stringify(e))),!(r=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN).isPublished){t.n=2;break}if(!((null==(o=r.target)?void 0:o.bizId)&&o.appId&&o.url&&(null==r?void 0:r.givenCDNManager))){t.n=1;break}return t.n=1,null==r?void 0:r.givenCDNManager.stopPublishGivenCDN();case 1:return t.n=2,this.doStopPublishTencentCDN(e);case 2:this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN);case 3:return t.a(2)}},t,this)})),function(t){return e.apply(this,arguments)})},{key:"doStopPublishTencentCDN",value:(t=r(a().m(function t(e){var r,o,n,i;return a().w(function(t){for(;;)switch(t.n){case 0:return r={requestTime:Date.now(),sessionId:(0,x.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(e)))},this._log.info("[CDNStreaming] doStopPublishTencentCDN: ".concat(JSON.stringify(r))),t.n=1,this._room.sendStopPublishCDN(r,!0);case 1:if(o=t.v,n=o.data.code,i=o.data.message,0!==n){t.n=2;break}this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e),t.n=3;break;case 2:throw-102069===n&&(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(n," errMsg: ").concat(i)),new Error("[CDNStreaming] server failed: stop tencent cdn errCode: ".concat(n," errMsg: ").concat(i));case 3:return t.a(2)}},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,x.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,x.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_").concat(this.convertPublishModeToStreamType(t)))}}]);var t,e,i,s,u,c}(),A=C(P()),L=function(){function t(e,r){o(this,t),N(this,"_core"),N(this,"_room"),N(this,"_log"),N(this,"_seq"),N(this,"_taskId"),N(this,"_startData",null),N(this,"_updateData",null),N(this,"_stopData",null),this._core=e,this._room=e.room,this._log=r,this._seq=0;var n=localStorage.getItem(t.TASK_ID_KEY);n&&(this._taskId=n)}return n(t,[{key:"startPushStreamToRoom",value:(s=r(a().m(function e(r){var o,n,i,s,u,c,d;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!this._taskId){e.n=1;break}return e.n=1,this.stopPushStreamToRoom();case 1:e.n=3;break;case 2:e.p=2,d=e.v,this._log.warn("stopPushStreamToRoom prev taskId failed",d);case 3:return this._seq+=1,this._startData=D({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,A.default)("".concat(this._room.roomId,"_").concat(this._room.userId,"_start")),agentParam:{cdnRobotUserid:"mcu_robot_".concat(this._room.roomId,"_").concat(this._room.userId)}},this.getCommonParams(r)),this._log.info("startPushStreamToRoom: ".concat(JSON.stringify(this._startData))),e.n=4,this._room.sendStartPushStreamToRoom(this._startData);case 4:i=e.v,s=i.data,u=s.code,c=s.message,0===u?(this._taskId=null==(n=null==(o=i.data)?void 0:o.data)?void 0:n.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 5:return e.a(2)}},e,this,[[0,2]])})),function(t){return s.apply(this,arguments)})},{key:"updatePushStreamToRoom",value:(i=r(a().m(function t(e){var r,o,n,i,s;return a().w(function(t){for(;;)switch(t.n){case 0:return this._seq+=1,this._updateData=D({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.n=1,this._room.sendUpdatePushStreamToRoom(this._updateData);case 1:o=t.v,n=o.data,i=n.code,s=n.message,0===i?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",i,s);case 2:return t.a(2)}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"stopPushStreamToRoom",value:(e=r(a().m(function e(){var r,o,n,i;return a().w(function(e){for(;;)switch(e.n){case 0:if(this._taskId){e.n=1;break}return e.a(2);case 1:return this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info("stopPushStreamToRoom: ".concat(JSON.stringify(this._stopData))),e.n=2,this._room.sendStopPushStreamToRoom(this._stopData);case 2:r=e.v,o=r.data,n=o.code,i=o.message,0===n?(delete this._taskId,localStorage.removeItem(t.TASK_ID_KEY),this._log.info("server success: start mix")):this.reportServerError("stopPushStreamToRoom",n,i);case 3:return e.a(2)}},e,this)})),function(){return e.apply(this,arguments)})},{key:"reportServerError",value:function(t,e,r){var o="server failed: ".concat(t," errCode: ").concat(e," errMsg: ").concat(r);throw this._log.error(o),new Error(o)}},{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,o=void 0===r?{}:r,n=t.encoding,i=void 0===n?{}:n,a={audioSamplerate:i.audioSampleRate||48e3,audioBitrateKbps:i.audioBitrate||64,audioChannels:i.audioChannels||1},s=o.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,o=void 0===r?{}:r,n=t.encoding,i=void 0===n?{}:n,a={videoCodec:2,videoWidth:i.videoWidth||640,videoHeight:i.videoHeight||480,videoFramerate:i.videoFramerate||15,videoGop:i.videoGOP||2,videoBitrateKbps:i.videoBitrate||800},s=o.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:o.backgroundColor||0,backgroundImageUrl:o.backgroundImage||""}}}]);var e,i,s}();N(L,"TASK_ID_KEY","trtc_mix_to_room_taskId");var j,G=L;var U,V,q={type:"number",notLessThanZero:!0},F={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:function(t,e,r,o){var n=j,i=n.RtcError,a=n.ErrorCode,s=n.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,o){var n=j,i=n.RtcError,a=n.ErrorCode,s=n.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"}})}}}},J={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,o){if(!/^[A-Za-z\d_-]*$/.test(t)){var n=j,i=n.RtcError,a=n.ErrorCode,s=n.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:D({},F)},validate:function(t,e,r,o){var n=t.publishMode,i=t.robotUser;if("publish-mix-stream-to-room"===n&&!i){var a=j;throw new(0,a.RtcError)({code:a.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},z={required:!1,type:"object",properties:{videoWidth:q,videoHeight:q,videoBitrate:(U=D({},q),V={allowEmpty:!1},p(U,g(V))),videoFramerate:{type:"number",validate:function(t,e,r,o){if(t<=0||t>30){var n=j;throw new(0,n.RtcError)({code:n.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate:function(t,e,r,o){if(t<1||t>8){var n=j;throw new(0,n.RtcError)({code:n.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:q,audioBitrate:{type:"number",validate:function(t,e,r,o){if(t<32||t>192){var n=j;throw new(0,n.RtcError)({code:n.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},B={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:D({},F)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:D({},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,o){if(t<1||t>15){var n=j;throw new(0,n.RtcError)({code:n.ErrorCode.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:q,height:q,locationX:q,locationY:q}}}}};var Y=0,K=function(){function t(e){o(this,t),this.core=e,N(this,"_mixTranscodeManager"),N(this,"_publishCDNManager"),N(this,"_pushStreamToRoomManager"),N(this,"_core"),N(this,"_modeOptions"),N(this,"seq"),N(this,"_log"),Y+=1,this.seq=Y,this._log=e.log.createChild({id:"".concat(this.getAlias()).concat(Y)}),this._log.info("[CDNStreaming] created id=".concat(this.getAlias()).concat(Y)),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new E(e,this._log),this._publishCDNManager=new O(e,this._log),this._pushStreamToRoomManager=new G(e,this._log)}return n(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,j=e.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:D({},J),encoding:D({},z),mix:D({},B)},validate:function(t,r,o,n){var i,a,s=t.target.publishMode,u=t.encoding,c=t.mix;if("publish-mix-stream-to-cdn"===s){var d=e.errorModule,h=d.RtcError,l=d.ErrorCode,m=d.ErrorCodeDictionary;if(!u)throw new h({code:l.INVALID_PARAMETER,extraCode:m.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"encoding"}});if(!c)throw new h({code:l.INVALID_PARAMETER,extraCode:m.INVALID_PARAMETER_REQUIRED,fnName:o,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 h({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 h({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 j=t.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:D({},J),encoding:D({},z),mix:D({},B)}}}(this._core);case"stop":return function(t){return j=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().m(function t(e){return a().w(function(t){for(;;)switch(t.n){case 0:if(this._modeOptions.set(e.target.publishMode,e),"publish-mix-stream-to-room"!==e.target.publishMode){t.n=1;break}return t.a(2,this._pushStreamToRoomManager.startPushStreamToRoom(e));case 1:return t.n=2,this.doStart(e);case 2:return t.a(2,t.v)}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"update",value:(s=r(a().m(function t(e){var r;return a().w(function(t){for(;;)switch(t.n){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.n=1;break}return t.a(2,this._pushStreamToRoomManager.updatePushStreamToRoom(r));case 1:return t.n=2,this.doStart(r);case 2:return t.a(2,t.v)}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"stop",value:(i=r(a().m(function t(e){var r;return a().w(function(t){for(;;)switch(t.n){case 0:r=e.target.publishMode,t.n="publish-mix-stream-to-cdn"===r?1:"publish-main-stream-to-cdn"===r||"publish-sub-stream-to-cdn"===r?3:"publish-mix-stream-to-room"===r?5:7;break;case 1:return t.n=2,this._mixTranscodeManager.stopMixTranscode();case 2:return t.a(3,7);case 3:return t.n=4,this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);case 4:return t.a(3,7);case 5:return t.n=6,this._pushStreamToRoomManager.stopPushStreamToRoom();case 6:return t.a(3,7);case 7:this._modeOptions.delete(e.target.publishMode);case 8:return t.a(2)}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"doStart",value:(e=r(a().m(function t(e){var r;return a().w(function(t){for(;;)switch(t.n){case 0:this._log.info("[CDNStreaming] doStart: ".concat(JSON.stringify(e))),r=e.target.publishMode,t.n="publish-mix-stream-to-cdn"===r?1:"publish-main-stream-to-cdn"===r||"publish-sub-stream-to-cdn"===r?3:5;break;case 1:return t.n=2,this._mixTranscodeManager.startMixTranscode(e);case 2:case 4:return t.a(3,5);case 3:return t.n=4,this._publishCDNManager.startPublishTencentCDN(e.target);case 5:return t.a(2)}},t,this)})),function(t){return e.apply(this,arguments)})}]);var e,i,s,u}();return N(K,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn",PublishMixStreamToRoom:"publish-mix-stream-to-room"}}),N(K,"Name","CDNStreaming"),K});
|