trtc-sdk-v5 5.9.2 → 5.9.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-zh_CN.md +2 -1
- package/README.md +2 -1
- package/assets/debug-dialog.js +1 -0
- package/{plugins/ai-denoiser → assets}/denoiser-wasm.js +1 -1
- package/assets/selfie_segmentation/package.json +27 -0
- package/assets/selfie_segmentation/selfie_segmentation.binarypb +0 -0
- package/assets/selfie_segmentation/selfie_segmentation.tflite +0 -0
- package/assets/selfie_segmentation/selfie_segmentation_landscape.tflite +0 -0
- package/assets/selfie_segmentation/selfie_segmentation_solution_simd_wasm_bin.data +0 -0
- package/assets/selfie_segmentation/selfie_segmentation_solution_simd_wasm_bin.wasm +0 -0
- package/assets/selfie_segmentation/selfie_segmentation_solution_wasm_bin.wasm +0 -0
- package/{plugins/video-decoder → assets}/videodec.wasm +0 -0
- package/{plugins/video-decoder → assets}/videodec_simd.wasm +0 -0
- package/index.d.ts +1808 -1791
- package/package.json +1 -1
- package/plugins/cdn-streaming/cdn-streaming.esm.js +1 -1
- package/plugins/cdn-streaming/cdn-streaming.umd.js +1 -0
- package/plugins/cdn-streaming/package.json +1 -2
- package/plugins/cross-room/cross-room.esm.js +1 -1
- package/plugins/cross-room/cross-room.umd.js +1 -0
- package/plugins/cross-room/package.json +1 -2
- package/plugins/custom-encryption/custom-encryption.esm.d.ts +31 -0
- package/plugins/custom-encryption/custom-encryption.esm.js +1 -0
- package/plugins/custom-encryption/custom-encryption.umd.js +1 -0
- package/plugins/custom-encryption/package.json +7 -0
- package/plugins/device-detector/device-detector.esm.js +93 -1234
- package/plugins/device-detector/device-detector.umd.js +39 -0
- package/plugins/device-detector/package.json +1 -2
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-decoder/video-decoder.esm.d.ts +20 -20
- package/plugins/video-decoder/video-decoder.esm.js +1 -43
- package/plugins/video-decoder/video-decoder.umd.js +1 -0
- package/plugins/video-effect/basic-beauty/basic-beauty.esm.js +1 -2
- package/plugins/video-effect/basic-beauty/basic-beauty.umd.js +1 -0
- package/plugins/video-effect/basic-beauty/package.json +1 -2
- package/plugins/video-effect/beauty/beauty.esm.js +1 -2954
- package/plugins/video-effect/beauty/beauty.umd.js +1 -0
- package/plugins/video-effect/beauty/package.json +1 -2
- package/plugins/video-effect/virtual-background/package.json +1 -2
- package/plugins/video-effect/virtual-background/virtual-background.esm.js +1 -60
- package/plugins/video-effect/virtual-background/virtual-background.umd.js +1 -0
- package/plugins/video-effect/watermark/package.json +1 -2
- package/plugins/video-effect/watermark/watermark.esm.d.ts +10 -2
- package/plugins/video-effect/watermark/watermark.esm.js +1 -1
- package/plugins/video-effect/watermark/watermark.umd.js +1 -0
- package/plugins/voice-changer/package.json +9 -0
- package/plugins/voice-changer/voice-changer.esm.d.ts +20 -0
- package/plugins/voice-changer/voice-changer.esm.js +1 -0
- package/plugins/voice-changer/voice-changer.umd.js +1 -0
- package/trtc.esm.js +28 -28
- package/trtc.js +1 -1
- package/plugins/cdn-streaming/cdn-streaming.iife.js +0 -1
- package/plugins/cross-room/cross-room.iife.js +0 -1
- package/plugins/device-detector/device-detector.iife.js +0 -1472
- package/plugins/video-decoder/video-decoder.iife.js +0 -43
- package/plugins/video-effect/basic-beauty/basic-beauty.iife.js +0 -2
- package/plugins/video-effect/beauty/beauty.iife.js +0 -2954
- package/plugins/video-effect/virtual-background/virtual-background.iife.js +0 -60
- package/plugins/video-effect/watermark/watermark.iife.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var CDNStreaming=(()=>{var ce=Object.create;var E=Object.defineProperty,he=Object.defineProperties,pe=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols,Se=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var j=(c,e,r)=>e in c?E(c,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):c[e]=r,_=(c,e)=>{for(var r in e||(e={}))ee.call(e,r)&&j(c,r,e[r]);if(Q)for(var r of Q(e))Te.call(e,r)&&j(c,r,e[r]);return c},W=(c,e)=>he(c,ge(e));var _e=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),Ce=(c,e)=>{for(var r in e)E(c,r,{get:e[r],enumerable:!0})},re=(c,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of be(e))!ee.call(c,i)&&i!==r&&E(c,i,{get:()=>e[i],enumerable:!(o=pe(e,i))||o.enumerable});return c};var Y=(c,e,r)=>(r=c!=null?ce(Se(c)):{},re(e||!c||!c.__esModule?E(r,"default",{value:c,enumerable:!0}):r,c)),De=c=>re(E({},"__esModule",{value:!0}),c);var g=(c,e,r)=>j(c,typeof e!="symbol"?e+"":e,r);var F=_e((te,K)=>{"use strict";(function(c){"use strict";function e(t,h){var a=(t&65535)+(h&65535),b=(t>>16)+(h>>16)+(a>>16);return b<<16|a&65535}function r(t,h){return t<<h|t>>>32-h}function o(t,h,a,b,T,D){return e(r(e(e(h,t),e(b,D)),T),a)}function i(t,h,a,b,T,D,f){return o(h&a|~h&b,t,h,T,D,f)}function l(t,h,a,b,T,D,f){return o(h&b|a&~b,t,h,T,D,f)}function s(t,h,a,b,T,D,f){return o(h^a^b,t,h,T,D,f)}function p(t,h,a,b,T,D,f){return o(a^(h|~b),t,h,T,D,f)}function S(t,h){t[h>>5]|=128<<h%32,t[(h+64>>>9<<4)+14]=h;var a,b,T,D,f,n=1732584193,m=-271733879,u=-1732584194,d=271733878;for(a=0;a<t.length;a+=16)b=n,T=m,D=u,f=d,n=i(n,m,u,d,t[a],7,-680876936),d=i(d,n,m,u,t[a+1],12,-389564586),u=i(u,d,n,m,t[a+2],17,606105819),m=i(m,u,d,n,t[a+3],22,-1044525330),n=i(n,m,u,d,t[a+4],7,-176418897),d=i(d,n,m,u,t[a+5],12,1200080426),u=i(u,d,n,m,t[a+6],17,-1473231341),m=i(m,u,d,n,t[a+7],22,-45705983),n=i(n,m,u,d,t[a+8],7,1770035416),d=i(d,n,m,u,t[a+9],12,-1958414417),u=i(u,d,n,m,t[a+10],17,-42063),m=i(m,u,d,n,t[a+11],22,-1990404162),n=i(n,m,u,d,t[a+12],7,1804603682),d=i(d,n,m,u,t[a+13],12,-40341101),u=i(u,d,n,m,t[a+14],17,-1502002290),m=i(m,u,d,n,t[a+15],22,1236535329),n=l(n,m,u,d,t[a+1],5,-165796510),d=l(d,n,m,u,t[a+6],9,-1069501632),u=l(u,d,n,m,t[a+11],14,643717713),m=l(m,u,d,n,t[a],20,-373897302),n=l(n,m,u,d,t[a+5],5,-701558691),d=l(d,n,m,u,t[a+10],9,38016083),u=l(u,d,n,m,t[a+15],14,-660478335),m=l(m,u,d,n,t[a+4],20,-405537848),n=l(n,m,u,d,t[a+9],5,568446438),d=l(d,n,m,u,t[a+14],9,-1019803690),u=l(u,d,n,m,t[a+3],14,-187363961),m=l(m,u,d,n,t[a+8],20,1163531501),n=l(n,m,u,d,t[a+13],5,-1444681467),d=l(d,n,m,u,t[a+2],9,-51403784),u=l(u,d,n,m,t[a+7],14,1735328473),m=l(m,u,d,n,t[a+12],20,-1926607734),n=s(n,m,u,d,t[a+5],4,-378558),d=s(d,n,m,u,t[a+8],11,-2022574463),u=s(u,d,n,m,t[a+11],16,1839030562),m=s(m,u,d,n,t[a+14],23,-35309556),n=s(n,m,u,d,t[a+1],4,-1530992060),d=s(d,n,m,u,t[a+4],11,1272893353),u=s(u,d,n,m,t[a+7],16,-155497632),m=s(m,u,d,n,t[a+10],23,-1094730640),n=s(n,m,u,d,t[a+13],4,681279174),d=s(d,n,m,u,t[a],11,-358537222),u=s(u,d,n,m,t[a+3],16,-722521979),m=s(m,u,d,n,t[a+6],23,76029189),n=s(n,m,u,d,t[a+9],4,-640364487),d=s(d,n,m,u,t[a+12],11,-421815835),u=s(u,d,n,m,t[a+15],16,530742520),m=s(m,u,d,n,t[a+2],23,-995338651),n=p(n,m,u,d,t[a],6,-198630844),d=p(d,n,m,u,t[a+7],10,1126891415),u=p(u,d,n,m,t[a+14],15,-1416354905),m=p(m,u,d,n,t[a+5],21,-57434055),n=p(n,m,u,d,t[a+12],6,1700485571),d=p(d,n,m,u,t[a+3],10,-1894986606),u=p(u,d,n,m,t[a+10],15,-1051523),m=p(m,u,d,n,t[a+1],21,-2054922799),n=p(n,m,u,d,t[a+8],6,1873313359),d=p(d,n,m,u,t[a+15],10,-30611744),u=p(u,d,n,m,t[a+6],15,-1560198380),m=p(m,u,d,n,t[a+13],21,1309151649),n=p(n,m,u,d,t[a+4],6,-145523070),d=p(d,n,m,u,t[a+11],10,-1120210379),u=p(u,d,n,m,t[a+2],15,718787259),m=p(m,u,d,n,t[a+9],21,-343485551),n=e(n,b),m=e(m,T),u=e(u,D),d=e(d,f);return[n,m,u,d]}function C(t){var h,a="",b=t.length*32;for(h=0;h<b;h+=8)a+=String.fromCharCode(t[h>>5]>>>h%32&255);return a}function I(t){var h,a=[];for(a[(t.length>>2)-1]=void 0,h=0;h<a.length;h+=1)a[h]=0;var b=t.length*8;for(h=0;h<b;h+=8)a[h>>5]|=(t.charCodeAt(h/8)&255)<<h%32;return a}function U(t){return C(S(I(t),t.length*8))}function V(t,h){var a,b=I(t),T=[],D=[],f;for(T[15]=D[15]=void 0,b.length>16&&(b=S(b,t.length*8)),a=0;a<16;a+=1)T[a]=b[a]^909522486,D[a]=b[a]^1549556828;return f=S(T.concat(I(h)),512+h.length*8),C(S(D.concat(f),640))}function M(t){var h="0123456789abcdef",a="",b,T;for(T=0;T<t.length;T+=1)b=t.charCodeAt(T),a+=h.charAt(b>>>4&15)+h.charAt(b&15);return a}function R(t){return unescape(encodeURIComponent(t))}function x(t){return U(R(t))}function z(t){return M(x(t))}function H(t,h){return V(R(t),R(h))}function P(t,h){return M(H(t,h))}function $(t,h,a){return h?a?H(h,t):P(h,t):a?x(t):z(t)}typeof define=="function"&&define.amd?define(function(){return $}):typeof K=="object"&&K.exports?K.exports=$:c.md5=$})(te)});var Re={};Ce(Re,{CDNStreaming:()=>X,PublishMode:()=>O,TRTCStreamType:()=>L,default:()=>Ne});var ae=Y(F(),1);var O=(i=>(i.PublishMainStreamToCDN="publish-main-stream-to-cdn",i.PublishSubStreamToCDN="publish-sub-stream-to-cdn",i.PublishMixStreamToCDN="publish-mix-stream-to-cdn",i.PublishMixStreamToRoom="publish-mix-stream-to-room",i))(O||{}),L=(r=>(r.Main="main",r.Sub="sub",r))(L||{});var q={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5};var y=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_params");g(this,"_publishGivenCDNData",null);this._core=e,this._room=e.room,this._log=r}get isPublishingGivenCDN(){return!!this._params}async startPublishGivenCDN(e){if(this._log.info(`[CDNStreaming] startPublishGivenCDN() current: ${JSON.stringify(this._params)}, params: ${JSON.stringify(e)}`),this.isPublishingGivenCDN){let{appId:r,bizId:o,url:i}=this._params||{};if(r===e.appId&&o===e.bizId&&i===e.url)return;await this.stopPublishGivenCDN()}this._params=e,this._publishGivenCDNData={pushRequestTime:Date.now(),pushAppId:e.appId,pushBizId:e.bizId,pushCdnUrl:e.url,pushStreamType:this.convertStreamType(e==null?void 0:e.publishMode),pushStreamId:e.streamId};try{let r=await this._room.sendStartPublishCDN(this._publishGivenCDNData,!1),{code:o,message:i}=r.data;if(o===0)this._log.info("[CDNStreaming] server success: start given cdn.");else throw this.resetGivenCDN(),this._log.error(`[CDNStreaming] server failed: start given cdn errCode: ${o} errMsg: ${i} options: ${JSON.stringify(e)}`),new Error(`[CDNStreaming] server failed: start given cdn errCode: ${o} errMsg: ${i}`)}catch(r){throw this.resetGivenCDN(),r}}async stopPublishGivenCDN(){if(this._log.info("[CDNStreaming] stopPublishGivenCDN"),!this.isPublishingGivenCDN||!this._publishGivenCDNData){this.resetGivenCDN();return}let{pushAppId:e,pushBizId:r,pushCdnUrl:o,pushStreamType:i,pushStreamId:l}=this._publishGivenCDNData,s={pushRequestTime:Date.now(),pushAppId:e,pushBizId:r,pushCdnUrl:o,pushStreamType:i,pushStreamId:l},p=await this._room.sendStopPublishCDN(s,!1),{code:S,message:C}=p.data;if(S===0)this._log.info("[CDNStreaming] server success: stop given cdn."),this.resetGivenCDN();else throw this._log.error(`[CDNStreaming] server failed: stop given cdn errCode: ${S} errMsg: ${C} data: ${JSON.stringify(s)}`),new Error(`[CDNStreaming] server failed: stop given cdn errCode: ${S} errMsg: ${C}`)}resetGivenCDN(){this._publishGivenCDNData=null,this._params=void 0}convertStreamType(e){return e==="publish-sub-stream-to-cdn"?"aux":"main"}};var v=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_config",null);g(this,"_data",null);g(this,"_givenCDNManager");this._core=e,this._room=e.room,this._log=r,this.reset()}get isMixing(){return!!this._data}get isStarted(){return!!this._config}get hasCustomCDN(){var e,r,o;return((e=this._config)==null?void 0:e.target.appId)&&((r=this._config)==null?void 0:r.target.bizId)&&((o=this._config)==null?void 0:o.target.url)}async startMixTranscode(e){if(this._log.info(`startMixTranscode: ${JSON.stringify(e)}`),this._config=e,this.installEvents(),!!this._core.room.isJoined)try{let r=this.getInputParam(e),o=this.getOutputParam(e),i=this.getOutputSessionId({config:e,roomId:this._room.roomId,userId:this._room.userId});this.isMixing&&this._data&&i!==this._data.outputSessionId&&(this._log.info("[CDNStreaming] streamId changed, auto stop mixing before start"),await this.doStopMixTranscode()),await this.doStartMixTranscode({outputSessionId:i,inputParam:r,outputParam:o});let{appId:l,bizId:s,url:p,streamId:S=""}=e.target;l&&s&&p&&(this._givenCDNManager||(this._givenCDNManager=new y(this._core,this._log)),await this._givenCDNManager.startPublishGivenCDN({publishMode:e.target.publishMode,appId:l,bizId:s,url:p,streamId:S}))}catch(r){throw this.reset(),r}}async doStartMixTranscode({outputSessionId:e,inputParam:r,outputParam:o}){let i={roomId:String(this._room.roomId),mcuRequestTime:Date.now(),outputSessionId:e,inputParam:r,outputParam:o};this._log.info(`[CDNStreaming] doStartMixTranscode: ${JSON.stringify(i)}`);let l=await this._room.sendStartMixTranscode(i),{code:s}=l.data,{message:p}=l.data;if(s===0)this._log.info("[CDNStreaming] server success: start mix"),this._data=i;else throw s===-102083&&(p=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start mix errCode: ${s} errMsg: ${p}`),new Error(`[CDNStreaming] server failed: start mix errCode: ${s} errMsg: ${p}`)}async stopMixTranscode(){this._log.info("[CDNStreaming] stopMixTranscode");try{this.isStarted&&this.isMixing&&(await this.doStopMixTranscode(),this._config&&this.hasCustomCDN&&this._givenCDNManager&&await this._givenCDNManager.stopPublishGivenCDN())}catch(e){throw e}this.reset()}async doStopMixTranscode(){let e={mcuRequestTime:Date.now(),outputSessionId:this._data.outputSessionId,streamType:this._data.outputParam.streamType};this._log.info(`[CDNStreaming] doStopMixTranscode: ${JSON.stringify(e)}`);let r=await this._room.sendStopMixTranscode(e),{code:o,message:i}=r.data;if(o===0)this._log.info("[CDNStreaming] server success: stop mix"),this.reset();else throw this._log.error(`[CDNStreaming] server failed: stop mix errCode: ${o} errMsg: ${i}`),new Error(`[CDNStreaming] server failed: stop mix errCode: ${o} errMsg: ${i}`)}reset(){this._config=null,this._data=null,this.uninstallEvents()}installEvents(){this._core.room.on("joined",this.handleRoomJoined,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.room.off("joined",this.handleRoomJoined,this),this._core.room.off("left",this.handleRoomLeft,this)}async handleRoomJoined(){this._log.info(`[CDNStreaming] handleJoined: ${JSON.stringify(this._config)}`),this.isStarted&&this._config&&await this.startMixTranscode(this._config)}async handleRoomLeft(){this._log.info(`[CDNStreaming] handleRoomLeft: ${JSON.stringify(this._config)}`),this._data=null}getOutputSessionId({config:e,userId:r,roomId:o}){return this._core.utils.isString(e.target.streamId)&&e.target.streamId.length>0?e.target.streamId:(0,ae.default)(`${o}_${r}_main`)}getStringRoomId(e,r){return e?String(e):r}getInputParam(e){let{mix:r={}}=e,{audioMixUserList:o=[],videoLayoutList:i=[]}=r,l=i.map(s=>({userId:s.fixedVideoUser.userId,roomId:this.getStringRoomId(s.fixedVideoUser.roomId,s.fixedVideoUser.strRoomId)||this._core.room.roomId,width:s.width||0,height:s.height||0,locationX:s.locationX||0,locationY:s.locationY||0,zOrder:s.zOrder||1,streamType:s.fixedVideoStreamType==="sub"?1:0,inputType:q.IT_PURE_VIDEO,renderMode:s.fillMode||0}));return o.forEach(s=>{let p=this._core.room.roomId;(s.roomId||s.strRoomId)&&(p=this.getStringRoomId(s.roomId,s.strRoomId));let S=l.findIndex(C=>C.userId===s.userId&&C.roomId===p);S!==-1?l[S].inputType=q.IT_AUDIO_VIDEO:l.push({userId:s.userId,roomId:s.roomId||s.strRoomId||this._core.room.roomId,inputType:q.IT_PURE_AUDIO})}),l}getOutputParam(e){let r=e.target.streamId||"",{encoding:o={},mix:i={}}=e;return{streamId:r,streamType:r.length>0?1:0,width:this._core.utils.isUndefined(o.videoWidth)?640:o.videoWidth,height:this._core.utils.isUndefined(o.videoHeight)?480:o.videoHeight,videoBps:o.videoBitrate||0,fps:o.videoFramerate||15,gop:o.videoGOP||2,audioSampleRate:o.audioSampleRate||48e3,audioBps:o.audioBitrate||64,audioChannels:o.audioChannels||1,backgroundColor:i.backgroundColor||0,backgroundImg:i.backgroundImage||"",extraInfo:"",videoCodec:2,audioCodec:0}}};var J=Y(F(),1);var k=class{constructor(e,r){g(this,"_room");g(this,"_core");g(this,"_log");g(this,"_paramsForTencentCDN");g(this,"_initParamsForTencentCDN",{isPublished:!1,isStarted:!1});this._core=e,this._room=e.room,this._log=r,this._paramsForTencentCDN=new Map([["publish-main-stream-to-cdn",this._initParamsForTencentCDN],["publish-sub-stream-to-cdn",this._initParamsForTencentCDN]])}installEvents(){this._core.innerEmitter.on("104",this.handlePublished,this),this._core.room.on("left",this.handleRoomLeft,this)}uninstallEvents(){this._core.innerEmitter.off("104",this.handlePublished,this),this._core.room.off("left",this.handleRoomLeft,this)}async handlePublished({track:e}){var i;if(e.room!==this._room||(this._log.info(`[CDNStreaming] handlePublished: mediaType ${e.mediaType}, roomID ${(i=e==null?void 0:e.room)==null?void 0:i.roomId}`),e.mediaType===1))return;let r=e.mediaType===4?"publish-main-stream-to-cdn":"publish-sub-stream-to-cdn",o=this._paramsForTencentCDN.get(r)||null;o!=null&&o.target&&o.isStarted&&await this.startPublishTencentCDN(o.target)}async handleRoomLeft(){this._log.info("[CDNStreaming] handleRoomLeft"),this.changeDataStatus("publish-main-stream-to-cdn",{isPublished:!1}),this.changeDataStatus("publish-sub-stream-to-cdn",{isPublished:!1})}isStreamPublished(e){return e==="publish-main-stream-to-cdn"&&!this._room.isMainStreamPublished?(this._log.info("[CDNStreaming] Main stream has not already published, will auto reStart after published."),!1):e==="publish-sub-stream-to-cdn"&&!this._room.isAuxStreamPublished?(this._log.info("[CDNStreaming] Sub has not already published, will auto reStart after published."),!1):!0}changeDataStatus(e,r){let o=this._paramsForTencentCDN.get(e),i=_(_({},o),r);this._paramsForTencentCDN.set(e,i)}async startPublishTencentCDN(e){if(this._log.info(`[CDNStreaming] startPublishTencentCDN ${JSON.stringify(e)}`),this.installEvents(),this.changeDataStatus(e.publishMode,{target:e,isStarted:!0}),!this.isStreamPublished(e.publishMode))return;let r=e.streamId||"",o=this.generatePublishCDNStreamId(r,e.publishMode),i=this.generatePublishCDNSessionId(e.publishMode),l=e.publishMode==="publish-sub-stream-to-cdn"?1:0,s={requestTime:Date.now(),sessionId:i,streamId:o,streamType:l};await this.doStartPublishTencentCDN(s,e.publishMode);let{appId:p,bizId:S,url:C}=e;if(p&&S&&C){let I=this._paramsForTencentCDN.get(e.publishMode)||this._initParamsForTencentCDN;I!=null&&I.givenCDNManager||(I.givenCDNManager=new y(this._core,this._log),this._paramsForTencentCDN.set(e.publishMode,I)),await I.givenCDNManager.startPublishGivenCDN({publishMode:e.publishMode,appId:p,bizId:S,url:C,streamId:o})}}async doStartPublishTencentCDN(e,r){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let o=6,i=500,l=0;for(;;){let s=await this._room.sendStartPublishCDN(e,!0),{code:p}=s.data,{message:S}=s.data;if(p===0){this._log.info("[CDNStreaming] server success: start tencent cdn"),this.changeDataStatus(r,{isPublished:!0});break}else if(p===-10006&&l<o)this._log.warn(`[CDNStreaming] doStartPublishTencentCDN: retry...${l+1}/6, reason: ${S}`),l+=1,await new Promise(C=>setTimeout(C,i));else throw this.changeDataStatus(r,{isPublished:!1}),p===-102083&&(S=`Please enable relayed-push in ${this._core.constants.CLOUD_CONSOLE_URL} and try later, refer to ${this._core.constants.DOC_URL}tutorial-26-advanced-publish-cdn-stream.html`),this._log.error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${S}`),new Error(`[CDNStreaming] server failed: start tencent cdn errCode: ${p} errMsg: ${S}`)}}async stopPublishTencentCDN(e){this._log.info(`[CDNStreaming] doStartPublishTencentCDN: ${JSON.stringify(e)}`);let r=this._paramsForTencentCDN.get(e)||this._initParamsForTencentCDN;if(r.isPublished){let{target:o}=r;o!=null&&o.bizId&&o.appId&&o.url&&(r!=null&&r.givenCDNManager)&&await(r==null?void 0:r.givenCDNManager.stopPublishGivenCDN()),await this.doStopPublishTencentCDN(e)}this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}async doStopPublishTencentCDN(e){let r={requestTime:Date.now(),sessionId:(0,J.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)};this._log.info(`[CDNStreaming] doStopPublishTencentCDN: ${JSON.stringify(r)}`);let o=await this._room.sendStopPublishCDN(r,!0),{code:i}=o.data,{message:l}=o.data;if(i===0)this._log.info("[CDNStreaming] server success: stop tencent cdn"),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),this.reset(e);else throw i===-102069&&(this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN),l=`can not stop in auto relayed-push mode ${l}`),this._log.error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${i} errMsg: ${l}`),new Error(`[CDNStreaming] server failed: stop tencent cdn errCode: ${i} errMsg: ${l}`)}reset(e){this.uninstallEvents(),this._paramsForTencentCDN.set(e,this._initParamsForTencentCDN)}generatePublishCDNStreamId(e,r){if(e===""){let o=`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(r)}`;return/^[A-Za-z\d_-]*$/.test(o)||(o=(0,J.default)(o)),`${this._room.sdkAppId}_${o}`}return e}convertPublishModeToStreamType(e){return e==="publish-main-stream-to-cdn"?"main":"aux"}generatePublishCDNSessionId(e){return(0,J.default)(`${this._room.roomId}_${this._room.userId}_${this.convertPublishModeToStreamType(e)}`)}};var oe=Y(F(),1);var w=class{constructor(e,r){g(this,"_core");g(this,"_room");g(this,"_log");g(this,"_seq");g(this,"_taskId",null);g(this,"_startData",null);g(this,"_updateData",null);g(this,"_stopData",null);this._core=e,this._room=e.room,this._log=r,this._seq=0}async startPushStreamToRoom(e){var l,s;this._seq+=1,this._startData=_({roomid:String(this._room.roomId),roomType:this._room.useStringRoomId?1:0,sessionId:(0,oe.default)(`${this._room.roomId}_${this._room.userId}_start`),agentParam:{cdnRobotUserid:`mcu_robot_${this._room.roomId}_${this._room.userId}`}},this.getCommonParams(e)),this._log.info(`startPushStreamToRoom: ${JSON.stringify(this._startData)}`);let r=await this._room.sendStartPushStreamToRoom(this._startData),{code:o,message:i}=r.data;o===0?(this._taskId=(s=(l=r.data)==null?void 0:l.data)==null?void 0:s.taskId,this._taskId||this.reportServerError("startPushStreamToRoom",o,`can't resolve task id: ${JSON.stringify(r.data)}`),this._log.info("[CDNStreaming] server success: taskId",this._taskId)):this.reportServerError("startPushStreamToRoom",o,i)}async updatePushStreamToRoom(e){this._seq+=1,this._updateData=W(_({taskid:this._taskId},this.getCommonParams(e)),{enableNtpSync:!0}),this._log.info(`updatePushStreamToRoom: ${JSON.stringify(this._updateData)}`);let r=await this._room.sendUpdatePushStreamToRoom(this._updateData),{code:o,message:i}=r.data;o===0?this._log.info("server success: updatePushStreamToRoom"):this.reportServerError("updatePushStreamToRoom",o,i)}async stopPushStreamToRoom(){this._seq+=1,this._stopData={sdkappid:this._room.sdkAppId,taskid:this._taskId},this._log.info(`stopPushStreamToRoom: ${JSON.stringify(this._stopData)}`);let e=await this._room.sendStopPushStreamToRoom(this._stopData),{code:r,message:o}=e.data;r===0?this._log.info("server success: start mix"):this.reportServerError("stopPushStreamToRoom",r,o)}reportServerError(e,r,o){let i=`server failed: ${e} errCode: ${r} errMsg: ${o}`;throw this._log.error(i),new Error(i)}getPushRtcRoomParams(e){let{robotUser:r}=e.target;return r?[{roomid:String((r==null?void 0:r.roomId)||(r==null?void 0:r.strRoomId))||this._room.roomId,roomType:r!=null&&r.roomId?0:1,pushRobotUserid:r==null?void 0:r.userId}]:[]}getCommonParams(e){return{sdkappid:this._room.sdkAppId,transcode:!0,audioParam:this.getAudioParam(e),videoParam:this.getVideoParam(e),pushRtcRoomParams:this.getPushRtcRoomParams(e),sequenceNumber:this._seq}}getAudioParam(e){let{mix:r={},encoding:o={}}=e,i={audioSamplerate:o.audioSampleRate||48e3,audioBitrateKbps:o.audioBitrate||64,audioChannels:o.audioChannels||1},{audioMixUserList:l}=r;return{audioEncodeParam:i,mixAudioUsers:(l==null?void 0:l.map(s=>({roomid:String(s.roomId||s.strRoomId)||this._room.roomId,userid:s.userId,roomType:s.roomId?0:1})))||[]}}getVideoParam(e){let{mix:r={},encoding:o={}}=e,i={videoCodec:2,videoWidth:o.videoWidth||640,videoHeight:o.videoHeight||480,videoFramerate:o.videoFramerate||15,videoGop:o.videoGOP||2,videoBitrateKbps:o.videoBitrate||800},{videoLayoutList:l}=r;return{videoEncodeParam:i,layoutParams:(l==null?void 0:l.map(s=>({userMediaStream:{userInfo:{roomid:String(s.fixedVideoUser.roomId||s.fixedVideoUser.strRoomId)||this._room.roomId,userid:s.fixedVideoUser.userId,roomType:s.fixedVideoUser.roomId?0:1},streamType:s.fixedVideoStreamType==="sub"?1:0},imageWidth:s.width||0,imageHeight:s.height||0,locationX:s.locationX||0,locationY:s.locationY||0,imageZorder:s.zOrder||1,renderMode:s.fillMode||0})))||[],backgroundColor:r.backgroundColor||0,backgroundImageUrl:r.backgroundImage||""}}};var ie=c=>typeof c=="string";var A;function fe(c,e,r,o){if(!/^[A-Za-z\d_-]*$/.test(c)){let{RtcError:l,ErrorCode:s,ErrorCodeDictionary:p}=A;throw new l({code:s.INVALID_PARAMETER,extraCode:p.INVALID_STREAM_ID,messageParams:{key:"streamId"}})}}function Pe(c,e,r,o){let{RtcError:i,ErrorCode:l,ErrorCodeDictionary:s}=A;if(ie(c))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER_STRING,fnName:r,messageParams:{key:"roomId"}});if(c===void 0)return;if(!(/^[1-9]\d*$/.test(String(c))&&c<4294967295))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_INTEGER,fnName:r,messageParams:{key:"roomId"}})}function Ae(c,e,r,o){let{RtcError:i,ErrorCode:l,ErrorCodeDictionary:s}=A;if(!/^[A-Za-z\d\s!#$%&()+\-:;<=.>?@[\]^_{}|~,]{1,64}$/.test(c))throw new i({code:l.INVALID_PARAMETER,extraCode:s.INVALID_ROOM_ID_STRING,fnName:r,messageParams:{key:"strRoomId"}})}var N={type:"number",notLessThanZero:!0},Z={type:"object",properties:{userId:{required:!0,type:"string"},roomId:{type:["string","number"],validate:Pe},strRoomId:{type:"string",validate:Ae}}},se={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:fe},appId:{type:"number",allowEmpty:!1},bizId:{type:"number",allowEmpty:!1},url:{type:"string",allowEmpty:!1},robotUser:_({},Z)},validate(c,e,r,o){let{publishMode:i,robotUser:l}=c;if(i==="publish-mix-stream-to-room"&&!l){let{RtcError:s,ErrorCode:p}=A;throw new s({code:p.INVALID_PARAMETER,message:"Invalid parameter target, the value of publishMode is PublishMixStreamToRoom, robotUser is required."})}}},ne={required:!1,type:"object",properties:{videoWidth:N,videoHeight:N,videoBitrate:W(_({},N),{allowEmpty:!1}),videoFramerate:{type:"number",validate(c,e,r,o){if(c<=0||c>30){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoFramerate, the value must be between (0, 30]."})}}},videoGOP:{type:"number",validate(c,e,r,o){if(c<1||c>8){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> videoGOP, the value must be between [1, 8]."})}}},audioSampleRate:N,audioBitrate:{type:"number",validate(c,e,r,o){if(c<32||c>192){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mixConfig -> audioBitrate, the value must be between [32, 192]."})}}},audioChannels:{type:"number",values:[1,2]}}},me={required:!1,type:"object",properties:{backgroundColor:{type:"number"},backgroundImage:{type:"string"},audioMixUserList:{type:"array",arrayItem:_({},Z)},videoLayoutList:{type:"array",required:!0,arrayItem:{type:"object",properties:{fixedVideoUser:_({},Z),fixedVideoStreamType:{type:"string",required:!0,values:["main","sub"]},fillMode:{type:"number",values:[0,1,2,4]},zOrder:{type:"number",required:!0,validate(c,e,r,o){if(c<1||c>15){let{RtcError:i,ErrorCode:l}=A;throw new i({code:l.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList -> zOrder, the value must be between [1, 15]."})}}},width:N,height:N,locationX:N,locationY:N}}}}};function ue(c){return A=c.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:_({},se),encoding:_({},ne),mix:_({},me)},validate(e,r,o,i){var S,C;let{publishMode:l}=e.target,{encoding:s,mix:p}=e;if(l==="publish-mix-stream-to-cdn"){let{RtcError:I,ErrorCode:U,ErrorCodeDictionary:V}=c.errorModule;if(!s)throw new I({code:U.INVALID_PARAMETER,extraCode:V.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"encoding"}});if(!p)throw new I({code:U.INVALID_PARAMETER,extraCode:V.INVALID_PARAMETER_REQUIRED,fnName:o,messageParams:{key:"mix"}});if(p&&p.videoLayoutList){let M=0,R=0,x=[];if(p.videoLayoutList.forEach((P,$)=>{x.push(P.fixedVideoUser.userId),P.width+P.locationX>M&&(M=P.width+P.locationX),P.height+P.locationY>R&&(R=P.height+P.locationY)}),x.indexOf(c.room.userId)<0)throw new I({code:U.INVALID_PARAMETER,message:"Invalid parameter mix -> videoLayoutList, the value must be include self."});let z=(S=s==null?void 0:s.videoWidth)!=null?S:640,H=(C=s==null?void 0:s.videoHeight)!=null?C:480;if(z<M||H<R)throw new I({code:U.INVALID_PARAMETER,message:"Invalid parameter encoding, the width and height of the mixed video must encompass all the mixed-in video streams."})}}}}}function de(c){return A=c.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:_({},se),encoding:_({},ne),mix:_({},me)}}}function le(c){return A=c.errorModule,{name:"CDNStreamingOptions",type:"object",required:!0,allowEmpty:!1,properties:{target:{required:!0,properties:{publishMode:{required:!0,values:["publish-main-stream-to-cdn","publish-mix-stream-to-cdn","publish-sub-stream-to-cdn","publish-mix-stream-to-room"]}}}}}}var G=0,B=class B{constructor(e){this.core=e;g(this,"_mixTranscodeManager");g(this,"_publishCDNManager");g(this,"_pushStreamToRoomManager");g(this,"_core");g(this,"_modeOptions");g(this,"seq");g(this,"_log");G=G+1,this.seq=G,this._log=e.log.createChild({id:`${this.getAlias()}${G}`}),this._log.info(`[CDNStreaming] created id=${this.getAlias()}${G}`),this._core=e,this._modeOptions=new Map,this._mixTranscodeManager=new v(e,this._log),this._publishCDNManager=new k(e,this._log),this._pushStreamToRoomManager=new w(e,this._log)}getName(){return B.Name}getAlias(){return"cdn"}getValidateRule(e){switch(e){case"start":return ue(this._core);case"update":return de(this._core);case"stop":return le(this._core)}}getGroup(e){return e.target.publishMode}async start(e){return this._modeOptions.set(e.target.publishMode,e),e.target.publishMode==="publish-mix-stream-to-room"?this._pushStreamToRoomManager.startPushStreamToRoom(e):await this.doStart(e)}async update(e){let r=this._modeOptions.get(e.target.publishMode);return this._core.utils.deepMerge(r,e),e.target.publishMode==="publish-mix-stream-to-room"?this._pushStreamToRoomManager.updatePushStreamToRoom(r):await this.doStart(r)}async stop(e){switch(e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.stopMixTranscode();break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.stopPublishTencentCDN(e.target.publishMode);break}case"publish-mix-stream-to-room":{this._pushStreamToRoomManager.stopPushStreamToRoom();break}}this._modeOptions.delete(e.target.publishMode)}async doStart(e){switch(this._log.info(`[CDNStreaming] doStart: ${JSON.stringify(e)}`),e.target.publishMode){case"publish-mix-stream-to-cdn":{await this._mixTranscodeManager.startMixTranscode(e);break}case"publish-main-stream-to-cdn":case"publish-sub-stream-to-cdn":{await this._publishCDNManager.startPublishTencentCDN(e.target);break}}}};g(B,"TYPE",{PublishMode:{PublishMainStreamToCDN:"publish-main-stream-to-cdn",PublishSubStreamToCDN:"publish-sub-stream-to-cdn",PublishMixStreamToCDN:"publish-mix-stream-to-cdn",PublishMixStreamToRoom:"publish-mix-stream-to-room"}}),g(B,"Name","CDNStreaming");var X=B;var Ne=X;return De(Re);})().default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var CrossRoom=(()=>{var y=Object.defineProperty,W=Object.defineProperties,D=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,K=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var E=(o,e,r)=>e in o?y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[e]=r,A=(o,e)=>{for(var r in e||(e={}))k.call(e,r)&&E(o,r,e[r]);if(C)for(var r of C(e))j.call(e,r)&&E(o,r,e[r]);return o},N=(o,e)=>W(o,H(e));var F=(o,e)=>{for(var r in e)y(o,r,{get:e[r],enumerable:!0})},X=(o,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of K(e))!k.call(o,t)&&t!==r&&y(o,t,{get:()=>e[t],enumerable:!(a=D(e,t))||a.enumerable});return o};var q=o=>X(y({},"__esModule",{value:!0}),o),x=(o,e,r,a)=>{for(var t=a>1?void 0:a?D(e,r):e,s=o.length-1,n;s>=0;s--)(n=o[s])&&(t=(a?n(e,r,t):n(t))||t);return a&&t&&y(e,r,t),t};var b=(o,e,r)=>E(o,typeof e!="symbol"?e+"":e,r);var $={};F($,{CrossRoom:()=>I,default:()=>Z});var L={properties:{roomId:{type:"number"},strRoomId:{type:"string"}}},U={name:"option",required:!0,properties:N(A({},L.properties),{userId:{type:"string"}})},V={name:"option",required:!0,properties:{updateList:{type:"array",required:!0,arrayItem:{required:!0,type:"object",properties:N(A({},U.properties),{userId:{required:!1,type:"string"},muteAudio:{type:"boolean"},muteVideo:{type:"boolean"},muteSubStream:{type:"boolean"}})}}}},B={name:"option",properties:A({},L.properties)};var p=o=>typeof o=="function";var v=0,J=1,M=2;function z({retryFunction:o,settings:e,onError:r,onRetrying:a,onRetryFailed:t,onRetrySuccess:s,context:n}){return function(...d){let{retries:m=5,timeout:u=1e3}=e,i=0,l=-1,c=v,g=async(h,f)=>{let w=n||this;try{let R=await o.apply(w,d);i>0&&s&&s.call(this,i),i=0,h(R)}catch(R){let P=()=>{clearTimeout(l),i=0,c=M,f(R)},_=()=>{c!==M&&i<(p(m)?m():m)?(i++,c=J,p(a)&&a.call(this,i,P),l=window.setTimeout(()=>{l=-1,g(h,f)},p(u)?u(i):u)):(P(),p(t)&&t.call(this,R))};p(r)?r.call(this,{error:R,retry:_,reject:f,retryFuncArgs:d,retriedCount:i}):_()}};return new Promise(g)}}var G=z;var T=new WeakMap;function O({settings:o={retries:5,timeout:2e3},onError:e,onRetrying:r,onRetryFailed:a}){return function(t,s,n){let d=G({retryFunction:n.value,settings:o,onError({error:m,retry:u,reject:i,retryFuncArgs:l}){var c;e?e.call(this,m,()=>{var g;(g=T.get(t))!=null&&g.has(s)?u():i(m)},i,l):(c=T.get(t))!=null&&c.has(s)?u():i(m)},onRetrying(m,u){var i;p(r)&&r.call(this,m,u),(i=T.get(t))!=null&&i.has(s)&&(T.get(t).get(s).stopRetry=u)},onRetryFailed:a});return n.value=function(...m){let u=T.get(t);return u?u.set(s,{args:m}):T.set(t,new Map([[s,{args:m}]])),d.apply(this,m).finally(()=>{var i;return(i=T.get(t))==null?void 0:i.delete(s)})},n}}var S=class S{constructor(e){this.core=e;b(this,"disableRandomCall",!0);b(this,"connectedRoomIdSet",new Set);b(this,"updateSeq",0);b(this,"_log");this._log=this.core.log.createChild({id:`${this.getAlias()}`})}getName(){return S.Name}getAlias(){return"crs-r"}getGroup(e){var a;let r=(e==null?void 0:e.userId)||((a=e==null?void 0:e.updateList)==null?void 0:a[0].userId)||"";return r||(e?e.updateList?String(e.updateList[0].roomId)||e.updateList[0].strRoomId||"":String(e.roomId)||e.strRoomId||"":"*")}getValidateRule(e){switch(e){case"start":return U;case"update":return V;case"stop":return B}}async start({roomId:e,strRoomId:r,userId:a}){let{RtcError:t,ErrorCode:s}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new t({code:s.ENV_NOT_SUPPORTED});let n=e||r,d=await this.core.room.sendSignalMessage({command:"connect_other_room",responseCommand:String(8209),data:{roomId:n,userId:a,localRoomId:a?void 0:this.core.room.roomId},retries:3});if(d.data.code!==0)throw new t({code:s.SERVER_ERROR,extraCode:d.data.code,message:d.data.message});a||this.connectedRoomIdSet.add(n)}async update({updateList:e}){var n;let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=e.find(d=>d.userId)?0:1,s=await this.core.room.sendSignalMessage({command:"update_other_room_forward_mode",responseCommand:String(8213),data:{seq:++this.updateSeq,operationType:t,updateList:e.map(({roomId:d,strRoomId:m,userId:u,muteAudio:i,muteVideo:l,muteSubStream:c})=>({roomId:d||m,userId:u,muteAudio:i,muteVideo:l,muteSubStream:c}))},retries:3});if(s.data.data.expectSeq)return this.updateSeq=s.data.data.expectSeq,this.update({updateList:e});if(s.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:s.data.code,message:s.data.message});if(((n=s.data.data.errorList)==null?void 0:n.length)>0)throw new r({code:a.UNKNOWN_ERROR,message:s.data.data.errorList[0].message})}async stop({roomId:e,strRoomId:r}={}){let a=e||r;if(a)await this.doStop(a);else if(this.connectedRoomIdSet.size>0)for(let t of[...this.connectedRoomIdSet.values()])await this.doStop(t);else await this.doStop()}async doStop(e){let{RtcError:r,ErrorCode:a}=this.core.errorModule;if(!this.core.room.sendSignalMessage)throw new r({code:a.ENV_NOT_SUPPORTED});let t=await this.core.room.sendSignalMessage({command:"disconnect_other_room",responseCommand:String(8211),data:{roomId:e,localRoomId:this.core.room.roomId},retries:3});if(t.data.code!==0)throw new r({code:a.SERVER_ERROR,extraCode:t.data.code,message:t.data.message});this.connectedRoomIdSet.delete(e)}destroy(){}};b(S,"Name","CrossRoom"),x([O({settings:{retries:3,timeout:1e3},onRetrying(e){this._log.warn(`retry start: ${e}`)}})],S.prototype,"start",1),x([O({settings:{retries:3,timeout:1e3},onRetrying(e){this._log.warn(`retry update: ${e}`)}})],S.prototype,"update",1);var I=S;var Z=I;return q($);})().default;
|