trtc-sdk-v5 5.15.0-beta.29 → 5.15.0-beta.30
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 +1 -1
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/plugins/cdn-streaming/package.json +1 -1
- package/plugins/chorus/package.json +1 -1
- package/plugins/cross-room/package.json +1 -1
- package/plugins/custom-encryption/package.json +1 -1
- package/plugins/device-detector/package.json +1 -1
- package/plugins/lebplayer/package.json +1 -1
- package/plugins/small-stream-auto-switcher/package.json +1 -1
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-effect/basic-beauty/package.json +1 -1
- package/plugins/video-effect/beauty/package.json +1 -1
- package/plugins/video-effect/video-mixer/package.json +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.esm.d.ts +4 -0
- package/plugins/video-effect/video-mixer/video-mixer.esm.js +1 -1
- package/plugins/video-effect/video-mixer/video-mixer.umd.js +1 -1
- package/plugins/video-effect/virtual-background/package.json +1 -1
- package/plugins/video-effect/watermark/package.json +1 -1
- package/plugins/voice-changer/package.json +1 -1
- package/trtc.esm.js +29 -29
- package/trtc.js +1 -1
package/index.d.ts
CHANGED
|
@@ -353,6 +353,7 @@ export interface AudioProfile { sampleRate: number, channelCount: number, bitrat
|
|
|
353
353
|
export declare interface LocalVideoConfig {
|
|
354
354
|
view?: string | HTMLElement | HTMLElement[] | null;
|
|
355
355
|
publish?: boolean;
|
|
356
|
+
forcePublish?: boolean;
|
|
356
357
|
mute?: boolean | string;
|
|
357
358
|
option?: {
|
|
358
359
|
cameraId?: string;
|
package/package.json
CHANGED
|
@@ -35,6 +35,7 @@ export interface CameraSource {
|
|
|
35
35
|
videoTrack?: MediaStreamTrack;
|
|
36
36
|
profile?: keyof typeof videoProfileMap | VideoProfile;
|
|
37
37
|
layout: LayerOption;
|
|
38
|
+
useInternalTrack?: boolean;
|
|
38
39
|
}
|
|
39
40
|
export interface ScreenSource {
|
|
40
41
|
// 参数与 startScreenShare 对齐
|
|
@@ -44,6 +45,9 @@ export interface ScreenSource {
|
|
|
44
45
|
preferDisplaySurface?: 'current-tab' | 'tab' | 'window' | 'monitor';
|
|
45
46
|
layout: LayerOption;
|
|
46
47
|
systemAudio?: boolean;
|
|
48
|
+
videoTrack?: MediaStreamTrack;
|
|
49
|
+
audioTrack?: MediaStreamTrack;
|
|
50
|
+
useInternalTrack?: boolean;
|
|
47
51
|
}
|
|
48
52
|
export interface TextSource {
|
|
49
53
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,i,r)=>i in e?__defProp(e,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[i]=r,__spreadValues=(e,i)=>{for(var r in i||(i={}))__hasOwnProp.call(i,r)&&__defNormalProp(e,r,i[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(i))__propIsEnum.call(i,r)&&__defNormalProp(e,r,i[r]);return e},__publicField=(e,i,r)=>__defNormalProp(e,"symbol"!=typeof i?i+"":i,r),layoutProperty={x:{required:!0,type:"number"},y:{required:!0,type:"number"},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},zIndex:{required:!0,type:"number"},fillMode:{required:!1,type:"string"},mirror:{required:!1,type:"boolean"},rotation:{required:!1,type:"number"},hidden:{required:!1,type:"boolean"}},canvasValidateRule=(e,i=!1)=>({type:"object",required:i,properties:{canvasColor:{required:!1,type:["string",CanvasGradient,CanvasPattern]},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},frameRate:{required:!1,type:"number",notLessThanZero:!0,min:1,max:60}},validate(i,r,t){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(!i)return;const{width:n,height:c}=i;if(n&&c&&n*c>8294400)throw new o({code:a.INVALID_PARAMETER,message:"The mix resolution cannot be set higher than 3840 * 2160."})}}),viewValidateRule=e=>({required:!1,type:["string",HTMLElement,null],validate(i,r,t){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(e.utils.isString(i)){if(!document.getElementById(i))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ELEMENT_ID,fnName:t,messageParams:{key:r}})}}}),layoutValidateRule=(e,i=!0)=>({type:"object",required:i,properties:__spreadValues({},layoutProperty),validate(i,r,t){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(i){if(i.fillMode&&!["contain","cover","fill"].includes(i.fillMode))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The fillMode parameter must be 'contain', 'cover' or 'fill'",fnName:t});if(i.rotation&&![0,90,180,270].includes(i.rotation))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The rotation parameter must be 0, 90, 180 or 270",fnName:t})}}}),cameraValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},cameraId:{required:!1,type:"string"},videoTrack:{required:!1,instanceof:MediaStreamTrack},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},layout:__spreadValues({},layoutValidateRule(e))}}}),screenValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},captureElement:{required:!1,type:HTMLElement},preferDisplaySurface:{required:!1,type:"string"},layout:__spreadValues({},layoutValidateRule(e))},validate(i,r,t){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(!e.rtcDectection.isScreenCaptureApiAvailable())throw new o({code:a.ENV_NOT_SUPPORTED,fnName:t,extraCode:s.NOT_SUPPORTED_SCREEN_SHARE})}}}),textValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},content:{required:!0,type:"string"},font:{required:!1,type:"string"},color:{required:!1,type:["string",CanvasGradient,CanvasPattern]},layout:__spreadValues({},layoutValidateRule(e))}}}),imageValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:__spreadValues({},layoutValidateRule(e))}}}),videoValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:__spreadValues({},layoutValidateRule(e))}}});function startValidateRule(e){return{name:"VideoMixerOptions",type:"object",required:!0,allowEmpty:!1,properties:{view:__spreadValues({},viewValidateRule(e)),canvasInfo:__spreadValues({},canvasValidateRule(e,!0)),camera:__spreadValues({},cameraValidateRule(e)),screen:__spreadValues({},screenValidateRule(e)),text:__spreadValues({},textValidateRule(e)),image:__spreadValues({},imageValidateRule(e)),video:__spreadValues({},videoValidateRule(e))},validate(i,r,t,o){const{RtcError:a,ErrorCode:s,ErrorCodeDictionary:n}=e.errorModule;if(e.environment.isMobile())throw new a({code:s.ENV_NOT_SUPPORTED,message:"VideoMixer is not supported on mobile devices currently"});const{onScreenShareStop:c}=i;if(c&&!e.utils.isFunction(c))throw new a({code:s.INVALID_PARAMETER,extraCode:n.INVALID_PARAMETER_TYPE,fnName:t,messageParams:{key:"onScreenShareStop",value:typeof c,rule:{type:"Function"}}})}}}function updateValidateRule(e){return{name:"VideoMixerOptions",type:"object",required:!1,allowEmpty:!1,properties:{view:__spreadValues({},viewValidateRule(e)),canvasInfo:__spreadValues({},canvasValidateRule(e)),camera:__spreadValues({},cameraValidateRule(e)),screen:__spreadValues({},screenValidateRule(e)),text:__spreadValues({},textValidateRule(e)),image:__spreadValues({},imageValidateRule(e)),video:__spreadValues({},videoValidateRule(e))}}}function stopValidateRule(e){return{name:"StopVideoMixerOptions",required:!1}}var videoMixSeq=0,_VideoMixer=class e{constructor(e){this.core=e,__publicField(this,"seq"),__publicField(this,"log"),__publicField(this,"localMixVideoTrack",null),__publicField(this,"systemAudioTrackList",{}),__publicField(this,"_mixVideoConfig"),__publicField(this,"onScreenShareStop"),videoMixSeq+=1,this.seq=videoMixSeq,this.log=e.log.createChild({id:`${this.getAlias()}${videoMixSeq}`}),this.log.info("created")}getName(){return e.Name}getAlias(){return"vmix"}getValidateRule(e){switch(e){case"start":return startValidateRule(this.core);case"update":return updateValidateRule(this.core);case"stop":return stopValidateRule(this.core)}}getGroup(){return"vmix"}async start(e){this.localMixVideoTrack||(this.localMixVideoTrack=new this.core.LocalMixVideoTrack(this.core.room.videoManager)),this._mixVideoConfig={canvasInfo:{width:1920,height:1080}},e=this.core.utils.deepCloneBasic(e);const{view:i,onScreenShareStop:r}=e,t=await this.parseMixOptions(e);return r&&(this.onScreenShareStop=r,this._mixVideoConfig.onScreenShareStop=r),this._updatePreview({view:i,track:this.localMixVideoTrack}),this.core.utils.isUndefined(i)||(this._mixVideoConfig.view=i),await this.localMixVideoTrack.startMix(),{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:t}}async update(e){const{RtcError:i,ErrorCode:r}=this.core.errorModule;if(!this.localMixVideoTrack)throw new i({code:r.INVALID_OPERATION,message:"mixTrack doesn't initialize!"});e=this.core.utils.deepCloneBasic(e);const{view:t}=e,o=await this.parseMixOptions(e);return await this._updatePreview({view:t,track:this.localMixVideoTrack,prevConfig:this._mixVideoConfig}),this.core.utils.isUndefined(t)||(this._mixVideoConfig.view=t),{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:o}}async parseMixOptions(e){let i={successOptions:{},failedDetails:[]};const{RtcError:r,ErrorCode:t,ErrorCodeDictionary:o}=this.core.errorModule;if(!this.localMixVideoTrack||!this._mixVideoConfig)return i;const a=[],s=__spreadValues({},e),{canvasInfo:n,camera:c,screen:d,text:l,image:u,video:p}=e;let h=0,m=0;if(n){const{canvasColor:e,width:i,height:r,frameRate:t}=n;e&&this.localMixVideoTrack.setMixBackground(e),t&&this.localMixVideoTrack.setFps(t),this.localMixVideoTrack.resizeMixCanvas(i,r),this._mixVideoConfig.canvasInfo=n}if(c){h++;const{finalOptions:e,errors:i}=await this.parseCameraOptions(this.localMixVideoTrack,c,this._mixVideoConfig.camera);this._mixVideoConfig.camera=e,s.camera=e,i.length>0&&(a.push(...i),i.length===c.length&&m++)}if(d){h++;const{finalOptions:e,errors:i}=await this.parseScreenOptions(this.localMixVideoTrack,d,this._mixVideoConfig.screen);this._mixVideoConfig.screen=e,s.screen=e,i.length>0&&(a.push(...i),i.length===d.length&&m++)}if(l){h++;const{finalOptions:e,errors:i}=await this.parseTextOptions(this.localMixVideoTrack,l,this._mixVideoConfig.text);this._mixVideoConfig.text=e,s.text=e,i.length>0&&(a.push(...i),i.length===l.length&&m++)}if(u){h++;const{finalOptions:e,errors:i}=await this.parseImageOptions(this.localMixVideoTrack,u,this._mixVideoConfig.image);this._mixVideoConfig.image=e,s.image=e,i.length>0&&(a.push(...i),i.length===u.length&&m++)}if(p){h++;const{finalOptions:e,errors:i}=await this.parseVideoOptions(this.localMixVideoTrack,p,this._mixVideoConfig.video);this._mixVideoConfig.video=e,s.video=e,i.length>0&&(a.push(...i),i.length===p.length&&m++)}if(m>0&&m===h)throw new r({code:t.INVALID_PARAMETER,message:"all sources mix failed",data:{failedDetails:a}});return i={successOptions:s,failedDetails:a},i}async parseCameraOptions(e,i,r=[]){var t,o;const a=new Set(i.map((e=>e.id))),s=r.filter((e=>!a.has(e.id))).map((e=>e.id));for(const i of s)e.removeCameraSource(i);const n=new Map(r.map((e=>[e.id,e]))),c=[],d=[];for(const r of i){const{id:i,layout:a,profile:s}=r;try{if(e.inputLocalVideoTracks.has(i)){const n=null==(t=e.inputLocalVideoTracks.get(i))?void 0:t.mediaTrack;await this.updateCameraProfile(r);const c=null==(o=e.inputLocalVideoTracks.get(i))?void 0:o.mediaTrack;let d;s&&(d=this.core.utils.isString(s)?this.core.constants.videoProfileMap[s]:s),c!==n?e.updateCameraSource(i,a,c,d):e.updateCameraSource(i,a,null,d)}else{const t=await this.captureCamera(r);try{e.addCameraSource(i,t,a)}catch(e){throw t.close(),e}}c.push(r)}catch(e){d.push({id:i,error:e}),n.has(i)&&c.push(n.get(i))}}return{finalOptions:c,errors:d}}async parseScreenOptions(e,i,r=[]){const{removeIdList:t,preOptionsMap:o}=this.prepareScreenOptions(i,r);this.removeUnusedScreenSources(e,t);const{finalOptions:a,errors:s}=await this.processScreenSources(e,i,o);return{finalOptions:a,errors:s}}prepareScreenOptions(e,i){const r=new Set(e.map((e=>e.id)));return{removeIdList:i.filter((e=>!r.has(e.id))).map((e=>e.id)),preOptionsMap:new Map(i.map((e=>[e.id,e])))}}removeUnusedScreenSources(e,i){for(const r of i)e.removeScreenSource(r),this.removeSystemAudioTrack(r)}async processScreenSources(e,i,r){const t=[],o=[];for(const a of i)try{await this.processSingleScreenSource(e,a,r,t)}catch(e){this.handleScreenSourceError(a.id,e,r,t,o)}return{finalOptions:t,errors:o}}async processSingleScreenSource(e,i,r,t){const{id:o,layout:a}=i,s=r.get(o),n=e.inputLocalScreenTracks.has(o),c=!(null==s?void 0:s.systemAudio)&&i.systemAudio;n&&!c?await this.updateExistingScreenSource(e,o,a,s,i):await this.addNewScreenSource(e,i,s),t.push(i)}async updateExistingScreenSource(e,i,r,t,o){e.updateScreenSource(i,r),(null==t?void 0:t.systemAudio)&&!o.systemAudio&&this.removeSystemAudioTrack(i)}async addNewScreenSource(e,i,r){const t=await this.captureScreen(i);!(null==r?void 0:r.systemAudio)&&i.systemAudio&&e.inputLocalScreenTracks.has(i.id)&&e.removeScreenSource(i.id);try{e.addScreenSource(i.id,t,i.layout)}catch(e){throw t.close(),e}}handleScreenSourceError(e,i,r,t,o){o.push({id:e,error:i}),r.has(e)&&t.push(r.get(e))}async parseTextOptions(e,i,r=[]){const t=new Set(i.map((e=>e.id))),o=r.filter((e=>!t.has(e.id))).map((e=>e.id));for(const i of o)e.removeTextSource(i);const a=new Map(r.map((e=>[e.id,e]))),s=[],n=[];for(const t of i){const{id:i}=t;try{r.some((e=>e.id===i))?e.updateTextSource(t):e.addTextSource(t),s.push(t)}catch(e){n.push({id:i,error:e}),a.has(i)&&s.push(a.get(i))}}return{finalOptions:s,errors:n}}async parseImageOptions(e,i,r=[]){const t=new Set(i.map((e=>e.id))),o=r.filter((e=>!t.has(e.id))).map((e=>e.id));for(const i of o)e.removeImageSource(i);const a=new Map(r.map((e=>[e.id,e]))),s=[],n=[];for(const t of i){const{id:i,url:o,layout:c}=t;try{const a=r.find((e=>e.id===i));if(a){let r;a.url!==o&&(r=await this.core.utils.loadImage(o)),e.updateImageSource(i,c,r)}else{const r=await this.core.utils.loadImage(o);e.addImageSource(i,r,c)}s.push(t)}catch(e){n.push({id:i,error:e}),a.has(i)&&s.push(a.get(i))}}return{finalOptions:s,errors:n}}async parseVideoOptions(e,i,r=[]){const t=new Set(i.map((e=>e.id))),o=r.filter((e=>!t.has(e.id))).map((e=>e.id));for(const i of o)e.removeVideoSource(i);const a=new Map(r.map((e=>[e.id,e]))),s=[],n=[];for(const t of i){const{id:i,url:o,layout:c}=t;try{const a=r.find((e=>e.id===i));let n;if(a)a.url!==o&&(n=await this.core.utils.loadVideo(o)),e.updateVideoSource(i,c,n);else{const r=await this.core.utils.loadVideo(o);e.addVideoSource(i,r,c)}s.push(t)}catch(e){n.push({id:i,error:e}),a.has(i)&&s.push(a.get(i))}}return{finalOptions:s,errors:n}}async captureCamera(e){const{id:i,cameraId:r,videoTrack:t,profile:o}=e,a=new this.core.LocalVideoTrack;a.log.id+=`-${i}`;const s={};return r?s.deviceId=r:this.core.utils.isUndefined(t)||(s.customSource=t),this.core.utils.isUndefined(o)||(this.core.utils.isString(o)?this.core.constants.videoProfileMap[o]&&a.setProfile(this.core.constants.videoProfileMap[o]):a.setProfile(o)),await a.capture(s),a}async updateCameraProfile(e){var i;const{id:r,cameraId:t,videoTrack:o,profile:a}=e,s=null==(i=this.localMixVideoTrack)?void 0:i.inputLocalVideoTracks.get(r);s&&(t?await s.switchDevice(t):this.core.utils.isUndefined(o)||await s.setInputMediaStreamTrack(o),this.core.utils.isUndefined(a)||(this.core.utils.isString(a)?this.core.constants.videoProfileMap[a]&&s.setProfile(this.core.constants.videoProfileMap[a]):s.setProfile(a),t&&s.isNeedToSwitchDevice(t)||await s.applyProfile()))}async captureScreen(e){const{id:i,profile:r,captureElement:t,preferDisplaySurface:o}=e,a=new this.core.LocalScreenTrack;a.log.id+=`-${i}`;const s={};this.core.utils.isUndefined(r)||(this.core.utils.isString(r)?this.core.constants.screenProfileMap[r]&&a.setProfile(this.core.constants.screenProfileMap[r]):a.setProfile(r)),t&&(s.captureElement=t),o&&(s.preferDisplaySurface=o),s.systemAudio=e.systemAudio;const n=await a.capture(s);return s.systemAudio&&n.getAudioTracks().length>0?(this.systemAudioTrackList[i]=n.getAudioTracks()[0],this.log.info(i+" system audio track captured")):this.removeSystemAudioTrack(i),a.mediaTrack.addEventListener(this.core.constants.NAME.ENDED,(()=>{var e,r,t;null==(e=this.localMixVideoTrack)||e.removeScreenSource(i),(null==(r=this._mixVideoConfig)?void 0:r.screen)&&(this._mixVideoConfig.screen=this._mixVideoConfig.screen.filter((e=>e.id!==i))),null==(t=this.onScreenShareStop)||t.call(this,i)})),a}async _updatePreview({view:e,track:i,prevConfig:r}){if(this.core.utils.isUndefined(e)&&r&&r.view){const e=this.core.utils.getViewListFromView(r.view);e.length>0&&await i.play(e)}if(!this.core.utils.isUndefined(e)){const r=this.core.utils.getViewListFromView(e);r.length>0?await i.play(r):i.stop()}}stop(){var e;null==(e=this.localMixVideoTrack)||e.close(),this.localMixVideoTrack=null,Object.values(this.systemAudioTrackList).forEach((e=>e.stop())),this.systemAudioTrackList={},delete this.onScreenShareStop,delete this._mixVideoConfig}removeSystemAudioTrack(e){this.systemAudioTrackList[e]&&(this.systemAudioTrackList[e].stop(),this.log.info(e+" system audio track stop"),delete this.systemAudioTrackList[e])}};__publicField(_VideoMixer,"Name","VideoMixer");var VideoMixer=_VideoMixer,index_default=VideoMixer;export{index_default as default};export{VideoMixer};
|
|
1
|
+
var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,r,t)=>r in e?__defProp(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,__spreadValues=(e,r)=>{for(var t in r||(r={}))__hasOwnProp.call(r,t)&&__defNormalProp(e,t,r[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(r))__propIsEnum.call(r,t)&&__defNormalProp(e,t,r[t]);return e},__publicField=(e,r,t)=>__defNormalProp(e,"symbol"!=typeof r?r+"":r,t),layoutProperty={x:{required:!0,type:"number"},y:{required:!0,type:"number"},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},zIndex:{required:!0,type:"number"},fillMode:{required:!1,type:"string"},mirror:{required:!1,type:"boolean"},rotation:{required:!1,type:"number"},hidden:{required:!1,type:"boolean"}},canvasValidateRule=(e,r=!1)=>({type:"object",required:r,properties:{canvasColor:{required:!1,type:["string",CanvasGradient,CanvasPattern]},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},frameRate:{required:!1,type:"number",notLessThanZero:!0,min:1,max:60}},validate(r,t,i){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(!r)return;const{width:c,height:n}=r;if(c&&n&&c*n>8294400)throw new o({code:a.INVALID_PARAMETER,message:"The mix resolution cannot be set higher than 3840 * 2160."})}}),viewValidateRule=e=>({required:!1,type:["string",HTMLElement,null],validate(r,t,i){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(e.utils.isString(r)){if(!document.getElementById(r))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ELEMENT_ID,fnName:i,messageParams:{key:t}})}}}),layoutValidateRule=(e,r=!0)=>({type:"object",required:r,properties:__spreadValues({},layoutProperty),validate(r,t,i){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(r){if(r.fillMode&&!["contain","cover","fill"].includes(r.fillMode))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The fillMode parameter must be 'contain', 'cover' or 'fill'",fnName:i});if(r.rotation&&![0,90,180,270].includes(r.rotation))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The rotation parameter must be 0, 90, 180 or 270",fnName:i})}}}),cameraValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},cameraId:{required:!1,type:"string"},videoTrack:{required:!1,instanceof:MediaStreamTrack},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},layout:__spreadValues({},layoutValidateRule(e))}}}),screenValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},captureElement:{required:!1,type:HTMLElement},preferDisplaySurface:{required:!1,type:"string"},layout:__spreadValues({},layoutValidateRule(e))},validate(r,t,i){const{RtcError:o,ErrorCode:a,ErrorCodeDictionary:s}=e.errorModule;if(!e.rtcDectection.isScreenCaptureApiAvailable())throw new o({code:a.ENV_NOT_SUPPORTED,fnName:i,extraCode:s.NOT_SUPPORTED_SCREEN_SHARE})}}}),textValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},content:{required:!0,type:"string"},font:{required:!1,type:"string"},color:{required:!1,type:["string",CanvasGradient,CanvasPattern]},layout:__spreadValues({},layoutValidateRule(e))}}}),imageValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:__spreadValues({},layoutValidateRule(e))}}}),videoValidateRule=e=>({type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:__spreadValues({},layoutValidateRule(e))}}});function startValidateRule(e){return{name:"VideoMixerOptions",type:"object",required:!0,allowEmpty:!1,properties:{view:__spreadValues({},viewValidateRule(e)),canvasInfo:__spreadValues({},canvasValidateRule(e,!0)),camera:__spreadValues({},cameraValidateRule(e)),screen:__spreadValues({},screenValidateRule(e)),text:__spreadValues({},textValidateRule(e)),image:__spreadValues({},imageValidateRule(e)),video:__spreadValues({},videoValidateRule(e))},validate(r,t,i,o){const{RtcError:a,ErrorCode:s,ErrorCodeDictionary:c}=e.errorModule;if(e.environment.isMobile())throw new a({code:s.ENV_NOT_SUPPORTED,message:"VideoMixer is not supported on mobile devices currently"});const{onScreenShareStop:n}=r;if(n&&!e.utils.isFunction(n))throw new a({code:s.INVALID_PARAMETER,extraCode:c.INVALID_PARAMETER_TYPE,fnName:i,messageParams:{key:"onScreenShareStop",value:typeof n,rule:{type:"Function"}}})}}}function updateValidateRule(e){return{name:"VideoMixerOptions",type:"object",required:!1,allowEmpty:!1,properties:{view:__spreadValues({},viewValidateRule(e)),canvasInfo:__spreadValues({},canvasValidateRule(e)),camera:__spreadValues({},cameraValidateRule(e)),screen:__spreadValues({},screenValidateRule(e)),text:__spreadValues({},textValidateRule(e)),image:__spreadValues({},imageValidateRule(e)),video:__spreadValues({},videoValidateRule(e))}}}function stopValidateRule(e){return{name:"StopVideoMixerOptions",required:!1}}var videoMixSeq=0,_VideoMixer=class e{constructor(e){this.core=e,__publicField(this,"seq"),__publicField(this,"log"),__publicField(this,"localMixVideoTrack",null),__publicField(this,"systemAudioTrackList",{}),__publicField(this,"_mixVideoConfig"),__publicField(this,"onScreenShareStop"),__publicField(this,"eventListeners",new Map),videoMixSeq+=1,this.seq=videoMixSeq,this.log=e.log.createChild({id:`${this.getAlias()}${videoMixSeq}`}),this.log.info("created")}getName(){return e.Name}getAlias(){return"vmix"}getValidateRule(e){switch(e){case"start":return startValidateRule(this.core);case"update":return updateValidateRule(this.core);case"stop":return stopValidateRule(this.core)}}getGroup(){return"vmix"}async start(e){this.localMixVideoTrack||(this.localMixVideoTrack=new this.core.LocalMixVideoTrack(this.core.room.videoManager)),this._mixVideoConfig={canvasInfo:{width:1920,height:1080}},e=this.core.utils.deepCloneBasic(e);const{view:r,onScreenShareStop:t}=e,i=await this.parseMixOptions(e);return t&&(this.onScreenShareStop=t,this._mixVideoConfig.onScreenShareStop=t),this._updatePreview({view:r,track:this.localMixVideoTrack}),this.core.utils.isUndefined(r)||(this._mixVideoConfig.view=r),await this.localMixVideoTrack.startMix(),{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:i}}async update(e){const{RtcError:r,ErrorCode:t}=this.core.errorModule;if(!this.localMixVideoTrack)throw new r({code:t.INVALID_OPERATION,message:"mixTrack doesn't initialize!"});e=this.core.utils.deepCloneBasic(e);const{view:i}=e,o=await this.parseMixOptions(e);return await this._updatePreview({view:i,track:this.localMixVideoTrack,prevConfig:this._mixVideoConfig}),this.core.utils.isUndefined(i)||(this._mixVideoConfig.view=i),{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:o}}stop(){var e;this.eventListeners.forEach(((e,r)=>{this.removeEventListeners(r)})),this.eventListeners.clear(),null==(e=this.localMixVideoTrack)||e.close(),this.localMixVideoTrack=null,Object.values(this.systemAudioTrackList).forEach((e=>e.stop())),this.systemAudioTrackList={},delete this.onScreenShareStop,delete this._mixVideoConfig}async parseMixOptions(e){const{RtcError:r,ErrorCode:t}=this.core.errorModule;if(!this.localMixVideoTrack||!this._mixVideoConfig)return{successOptions:{},failedDetails:[]};const i=[],o=__spreadValues({},e),{canvasInfo:a,camera:s,screen:c,text:n,image:d,video:l}=e;a&&this.parseCanvasOptions(a);let u=0,p=0;const h=[{key:"camera",options:s,parser:this.parseCameraOptions.bind(this)},{key:"screen",options:c,parser:this.parseScreenOptions.bind(this)},{key:"text",options:n,parser:this.parseTextOptions.bind(this)},{key:"image",options:d,parser:this.parseImageOptions.bind(this)},{key:"video",options:l,parser:this.parseVideoOptions.bind(this)}];for(const{key:e,options:r,parser:t}of h)if(r){u++;const a=await t(this.localMixVideoTrack,r,this._mixVideoConfig[e]||[]);this._mixVideoConfig[e]=a.finalOptions,o[e]=a.finalOptions,a.errors.length>0&&(i.push(...a.errors),a.errors.length===r.length&&p++)}if(p>0&&p===u)throw new r({code:t.INVALID_PARAMETER,message:"all sources mix failed",data:{failedDetails:i}});return{successOptions:o,failedDetails:i}}parseCanvasOptions(e){if(!this.localMixVideoTrack||!this._mixVideoConfig)return;const{canvasColor:r,width:t,height:i,frameRate:o}=e;r&&this.localMixVideoTrack.setMixBackground(r),o&&this.localMixVideoTrack.setFps(o),this.localMixVideoTrack.resizeMixCanvas(t,i),this._mixVideoConfig.canvasInfo=e}prepareSourceOptions(e,r){const t=new Set(e.map((e=>e.id)));return{removeIdList:r.filter((e=>!t.has(e.id))).map((e=>e.id)),preOptionsMap:new Map(r.map((e=>[e.id,e])))}}recordSourceError(e,r,t,i,o){o.push({id:e,error:r}),t.has(e)&&i.push(t.get(e))}async parseCameraOptions(e,r,t=[]){const{removeIdList:i,preOptionsMap:o}=this.prepareSourceOptions(r,t);for(const r of i)e.removeCameraSource(r);const a=[],s=[];for(const t of r)try{await this.processSingleCameraSource(e,t),a.push(t)}catch(e){this.recordSourceError(t.id,e,o,a,s)}return{finalOptions:a,errors:s}}async processSingleCameraSource(e,r){var t;const{id:i,layout:o,profile:a,useInternalTrack:s}=r;s&&((null==(t=this.core.trtc.localVideoTrack)?void 0:t.sourceTrack)?r.videoTrack=this.core.trtc.localVideoTrack.sourceTrack:r.videoTrack=this.createPlaceholderVideoTrack()),this.log.info(`videomixer camera option ${JSON.stringify(r)}`),e.inputLocalVideoTracks.has(i)?await this.updateExistingCameraSource(e,r):await this.addNewCameraSource(e,r)}async updateExistingCameraSource(e,r){var t,i;const{id:o,layout:a,profile:s}=r,c=null==(t=e.inputLocalVideoTracks.get(o))?void 0:t.mediaTrack;await this.updateCameraProfile(r);const n=null==(i=e.inputLocalVideoTracks.get(o))?void 0:i.mediaTrack,d=this.resolveVideoProfile(s);n!==c?e.updateCameraSource(o,a,n,d):e.updateCameraSource(o,a,null,d)}async addNewCameraSource(e,r){const{id:t,layout:i,useInternalTrack:o}=r,a=await this.captureCamera(r);if(this.removeEventListeners(t),o){const r=r=>{var i,o;if(null==(i=r.track)?void 0:i.isScreen)return;this.log.info("videomixer camera LOCAL_TRACK_CAPTURE_SUCCESS");const a=e.inputLocalVideoTracks.get(t);a&&(null==(o=r.track)?void 0:o.sourceTrack)&&a.setInputMediaStreamTrack(r.track.sourceTrack)};this.core.innerEmitter.on("102",r),this.eventListeners.has(t)||this.eventListeners.set(t,{}),this.eventListeners.get(t).captureSuccess=()=>{this.core.innerEmitter.off("102",r)}}try{e.addCameraSource(t,a,i)}catch(e){throw a.close(),e}}resolveVideoProfile(e){if(!this.core.utils.isUndefined(e))return this.core.utils.isString(e)?this.core.constants.videoProfileMap[e]:e}async parseScreenOptions(e,r,t=[]){const{removeIdList:i,preOptionsMap:o}=this.prepareSourceOptions(r,t);for(const r of i)e.removeScreenSource(r),this.removeSystemAudioTrack(r);const a=[],s=[];for(const t of r)try{await this.processSingleScreenSource(e,t,o),a.push(t)}catch(e){this.recordSourceError(t.id,e,o,a,s)}return{finalOptions:a,errors:s}}async processSingleScreenSource(e,r,t){var i,o;const{id:a,layout:s,useInternalTrack:c}=r;c&&((null==(i=this.core.trtc.localScreenTrack)?void 0:i.mediaTrack)?(r.videoTrack=this.core.trtc.localScreenTrack.mediaTrack,(null==(o=this.core.trtc.localScreenAudioTrack)?void 0:o.mediaTrack)&&(r.audioTrack=this.core.trtc.localScreenAudioTrack.mediaTrack),delete r.captureElement,delete r.preferDisplaySurface,delete r.systemAudio):r.videoTrack=this.createPlaceholderVideoTrack()),this.log.info(`videomixer screen option ${JSON.stringify(r)}`);const n=t.get(a),d=e.inputLocalScreenTracks.has(a),l=!(null==n?void 0:n.systemAudio)&&r.systemAudio;d&&!l?this.updateExistingScreenSource(e,a,s,n,r):await this.addNewScreenSource(e,r,n)}updateExistingScreenSource(e,r,t,i,o){e.updateScreenSource(r,t),(null==i?void 0:i.systemAudio)&&!o.systemAudio&&this.removeSystemAudioTrack(r)}async addNewScreenSource(e,r,t){const{id:i,useInternalTrack:o}=r,a=await this.captureScreen(r);if(this.removeEventListeners(i),o){const r=r=>{var t,o,a;if(!(null==(t=r.track)?void 0:t.isScreen))return;this.log.info("videomixer screen LOCAL_TRACK_CAPTURE_SUCCESS");const s=e.inputLocalScreenTracks.get(i);s&&(null==(o=r.track)?void 0:o.mediaTrack)&&s.setInputMediaStreamTrack(r.track.mediaTrack),this.systemAudioTrackList[i]&&(null==(a=r.track)?void 0:a.mediaTrack)&&(this.systemAudioTrackList[i]=r.track.mediaTrack)};this.core.innerEmitter.on("102",r),this.eventListeners.has(i)||this.eventListeners.set(i,{}),this.eventListeners.get(i).captureSuccess=()=>{this.core.innerEmitter.off("102",r)}}!(null==t?void 0:t.systemAudio)&&r.systemAudio&&e.inputLocalScreenTracks.has(r.id)&&e.removeScreenSource(r.id);try{e.addScreenSource(r.id,a,r.layout)}catch(e){throw a.close(),e}}async parseTextOptions(e,r,t=[]){const{removeIdList:i,preOptionsMap:o}=this.prepareSourceOptions(r,t);for(const r of i)e.removeTextSource(r);const a=[],s=[];for(const t of r)try{o.has(t.id)?e.updateTextSource(t):e.addTextSource(t),a.push(t)}catch(e){this.recordSourceError(t.id,e,o,a,s)}return{finalOptions:a,errors:s}}async parseImageOptions(e,r,t=[]){const{removeIdList:i,preOptionsMap:o}=this.prepareSourceOptions(r,t);for(const r of i)e.removeImageSource(r);const a=[],s=[];for(const t of r)try{await this.processSingleImageSource(e,t,o),a.push(t)}catch(e){this.recordSourceError(t.id,e,o,a,s)}return{finalOptions:a,errors:s}}async processSingleImageSource(e,r,t){const{id:i,url:o,layout:a}=r,s=t.get(i);if(s){let r;s.url!==o&&(r=await this.core.utils.loadImage(o)),e.updateImageSource(i,a,r)}else{const r=await this.core.utils.loadImage(o);e.addImageSource(i,r,a)}}async parseVideoOptions(e,r,t=[]){const{removeIdList:i,preOptionsMap:o}=this.prepareSourceOptions(r,t);for(const r of i)e.removeVideoSource(r);const a=[],s=[];for(const t of r)try{await this.processSingleVideoSource(e,t,o),a.push(t)}catch(e){this.recordSourceError(t.id,e,o,a,s)}return{finalOptions:a,errors:s}}async processSingleVideoSource(e,r,t){const{id:i,url:o,layout:a}=r,s=t.get(i);if(s){let r;s.url!==o&&(r=await this.core.utils.loadVideo(o)),e.updateVideoSource(i,a,r)}else{const r=await this.core.utils.loadVideo(o);e.addVideoSource(i,r,a)}}createPlaceholderVideoTrack(){const e=document.createElement("canvas");e.width=640,e.height=480;const r=e.getContext("2d");r&&(r.fillStyle="black",r.fillRect(0,0,e.width,e.height));return e.captureStream(1).getVideoTracks()[0]}removeEventListeners(e){const r=this.eventListeners.get(e);r&&(r.inputMediaTrackChanged&&r.inputMediaTrackChanged(),r.captureSuccess&&r.captureSuccess(),this.eventListeners.delete(e))}async captureCamera(e){const{id:r,cameraId:t,videoTrack:i,profile:o}=e,a=new this.core.LocalVideoTrack;a.log.id+=`-${r}`;const s={};if(t?s.deviceId=t:this.core.utils.isUndefined(i)||(s.customSource=i),!this.core.utils.isUndefined(o)){const e=this.resolveVideoProfile(o);e&&a.setProfile(e)}return await a.capture(s),a}async updateCameraProfile(e){var r;const{id:t,cameraId:i,videoTrack:o,profile:a}=e,s=null==(r=this.localMixVideoTrack)?void 0:r.inputLocalVideoTracks.get(t);if(s&&(i?await s.switchDevice(i):this.core.utils.isUndefined(o)||await s.setInputMediaStreamTrack(o),!this.core.utils.isUndefined(a))){const e=this.resolveVideoProfile(a);e&&s.setProfile(e),i&&s.isNeedToSwitchDevice(i)||await s.applyProfile()}}async captureScreen(e){const{id:r,profile:t,captureElement:i,preferDisplaySurface:o,systemAudio:a,videoTrack:s,audioTrack:c}=e,n=new this.core.LocalScreenTrack;n.log.id+=`-${r}`;const d={captureElement:i,preferDisplaySurface:o,systemAudio:a,videoTrack:s,audioTrack:c};if(!this.core.utils.isUndefined(t))if(this.core.utils.isString(t)){const e=this.core.constants.screenProfileMap[t];e&&n.setProfile(e)}else n.setProfile(t);const l=await n.capture(d);return a&&l.getAudioTracks().length>0?(this.systemAudioTrackList[r]=l.getAudioTracks()[0],this.log.info(`${r} system audio track captured`)):this.removeSystemAudioTrack(r),n.mediaTrack.addEventListener(this.core.constants.NAME.ENDED,(()=>{this.handleScreenShareEnded(r)})),n}handleScreenShareEnded(e){var r,t,i;null==(r=this.localMixVideoTrack)||r.removeScreenSource(e),(null==(t=this._mixVideoConfig)?void 0:t.screen)&&(this._mixVideoConfig.screen=this._mixVideoConfig.screen.filter((r=>r.id!==e))),null==(i=this.onScreenShareStop)||i.call(this,e)}async _updatePreview({view:e,track:r,prevConfig:t}){if(this.core.utils.isUndefined(e)&&(null==t?void 0:t.view)){const e=this.core.utils.getViewListFromView(t.view);e.length>0&&await r.play(e)}else if(!this.core.utils.isUndefined(e)){const t=this.core.utils.getViewListFromView(e);t.length>0?await r.play(t):r.stop()}}removeSystemAudioTrack(e){const r=this.systemAudioTrackList[e];r&&(r.stop(),this.log.info(`${e} system audio track stop`),delete this.systemAudioTrackList[e])}};__publicField(_VideoMixer,"Name","VideoMixer");var VideoMixer=_VideoMixer,index_default=VideoMixer;export{index_default as default};export{VideoMixer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).VideoMixer=r()}(this,(function(){"use strict";function e(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function r(e,r,t,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void t(e)}s.done?r(c):Promise.resolve(c).then(n,i)}function t(e){return function(){var t=this,n=arguments;return new Promise((function(i,o){var a=e.apply(t,n);function s(e){r(a,i,o,s,c,"next",e)}function c(e){r(a,i,o,s,c,"throw",e)}s(void 0)}))}}function n(e,r,t){return r&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,s(n.key),n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=u(e))||r){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},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 o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function o(){o=function(){return r};var e,r={},t=Object.prototype,n=t.hasOwnProperty,i=Object.defineProperty||function(e,r,t){e[r]=t.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function l(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{l({},"")}catch(e){l=function(e,r,t){return e[r]=t}}function p(e,r,t,n){var o=r&&r.prototype instanceof x?r:x,a=Object.create(o.prototype),s=new O(n||[]);return i(a,"_invoke",{value:M(e,t,s)}),a}function f(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var d="suspendedStart",h="suspendedYield",y="executing",v="completed",m={};function x(){}function g(){}function b(){}var k={};l(k,s,(function(){return this}));var w=Object.getPrototypeOf,S=w&&w(w(_([])));S&&S!==t&&n.call(S,s)&&(k=S);var T=b.prototype=x.prototype=Object.create(k);function E(e){["next","throw","return"].forEach((function(r){l(e,r,(function(e){return this._invoke(r,e)}))}))}function V(e,r){function t(i,o,a,s){var c=f(e[i],e,o);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(e){t("next",e,a,s)}),(function(e){t("throw",e,a,s)})):r.resolve(l).then((function(e){u.value=e,a(u)}),(function(e){return t("throw",e,a,s)}))}s(c.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new r((function(r,i){t(e,n,r,i)}))}return o=o?o.then(i,i):i()}})}function M(r,t,n){var i=d;return function(o,a){if(i===y)throw Error("Generator is already running");if(i===v){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var c=A(s,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var u=f(r,t,n);if("normal"===u.type){if(i=n.done?v:h,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(i=v,n.method="throw",n.arg=u.arg)}}}function A(r,t){var n=t.method,i=r.iterator[n];if(i===e)return t.delegate=null,"throw"===n&&r.iterator.return&&(t.method="return",t.arg=e,A(r,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var o=f(i,r.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,m;var a=o.arg;return a?a.done?(t[r.resultName]=a.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=e),t.delegate=null,m):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function L(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function C(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function _(r){if(r||""===r){var t=r[s];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function t(){for(;++i<r.length;)if(n.call(r,i))return t.value=r[i],t.done=!1,t;return t.value=e,t.done=!0,t};return o.next=o}}throw new TypeError(typeof r+" is not iterable")}return g.prototype=b,i(T,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:g,configurable:!0}),g.displayName=l(b,u,"GeneratorFunction"),r.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,l(e,u,"GeneratorFunction")),e.prototype=Object.create(T),e},r.awrap=function(e){return{__await:e}},E(V.prototype),l(V.prototype,c,(function(){return this})),r.AsyncIterator=V,r.async=function(e,t,n,i,o){void 0===o&&(o=Promise);var a=new V(p(e,t,n,i),o);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(T),l(T,u,"Generator"),l(T,s,(function(){return this})),l(T,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=_,O.prototype={constructor:O,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(C),!r)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var t=this;function i(n,i){return s.type="throw",s.arg=r,t.next=n,i&&(t.method="next",t.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=r,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(a)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),m},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),C(t),m}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var i=n.arg;C(t)}return i}}throw Error("illegal catch attempt")},delegateYield:function(r,t,n){return this.delegate={iterator:_(r),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=e),m}},r}function a(r){return function(r){if(Array.isArray(r))return e(r)}(r)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(r)||u(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof r?r:r+""}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(r,t){if(r){if("string"==typeof r)return e(r,t);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(r,t):void 0}}var l=Object.defineProperty,p=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,h=function(e,r,t){return r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t},y=function(e,r){for(var t in r||(r={}))f.call(r,t)&&h(e,t,r[t]);if(p){var n,o=i(p(r));try{for(o.s();!(n=o.n()).done;){t=n.value;d.call(r,t)&&h(e,t,r[t])}}catch(e){o.e(e)}finally{o.f()}}return e},v=function(e,r,t){return h(e,"symbol"!==c(r)?r+"":r,t)},m={x:{required:!0,type:"number"},y:{required:!0,type:"number"},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},zIndex:{required:!0,type:"number"},fillMode:{required:!1,type:"string"},mirror:{required:!1,type:"boolean"},rotation:{required:!1,type:"number"},hidden:{required:!1,type:"boolean"}},x=function(e){return{type:"object",required:arguments.length>1&&void 0!==arguments[1]&&arguments[1],properties:{canvasColor:{required:!1,type:["string",CanvasGradient,CanvasPattern]},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},frameRate:{required:!1,type:"number",notLessThanZero:!0,min:1,max:60}},validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode;if(i.ErrorCodeDictionary,r){var s=r.width,c=r.height;if(s&&c&&s*c>8294400)throw new o({code:a.INVALID_PARAMETER,message:"The mix resolution cannot be set higher than 3840 * 2160."})}}}},g=function(e){return{required:!1,type:["string",HTMLElement,null],validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(e.utils.isString(r)&&!document.getElementById(r))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ELEMENT_ID,fnName:n,messageParams:{key:t}})}}},b=function(e){return{type:"object",required:!(arguments.length>1&&void 0!==arguments[1])||arguments[1],properties:y({},m),validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(r){if(r.fillMode&&!["contain","cover","fill"].includes(r.fillMode))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The fillMode parameter must be 'contain', 'cover' or 'fill'",fnName:n});if(r.rotation&&![0,90,180,270].includes(r.rotation))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The rotation parameter must be 0, 90, 180 or 270",fnName:n})}}}},k=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},cameraId:{required:!1,type:"string"},videoTrack:{required:!1,instanceof:MediaStreamTrack},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},layout:y({},b(e))}}}},w=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},captureElement:{required:!1,type:HTMLElement},preferDisplaySurface:{required:!1,type:"string"},layout:y({},b(e))},validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(!e.rtcDectection.isScreenCaptureApiAvailable())throw new o({code:a.ENV_NOT_SUPPORTED,fnName:n,extraCode:s.NOT_SUPPORTED_SCREEN_SHARE})}}}},S=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},content:{required:!0,type:"string"},font:{required:!1,type:"string"},color:{required:!1,type:["string",CanvasGradient,CanvasPattern]},layout:y({},b(e))}}}},T=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:y({},b(e))}}}},E=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:y({},b(e))}}}};var V=0,M=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.core=r,v(this,"seq"),v(this,"log"),v(this,"localMixVideoTrack",null),v(this,"systemAudioTrackList",{}),v(this,"_mixVideoConfig"),v(this,"onScreenShareStop"),V+=1,this.seq=V,this.log=r.log.createChild({id:"".concat(this.getAlias()).concat(V)}),this.log.info("created")}return n(e,[{key:"getName",value:function(){return e.Name}},{key:"getAlias",value:function(){return"vmix"}},{key:"getValidateRule",value:function(e){switch(e){case"start":return r=this.core,{name:"VideoMixerOptions",type:"object",required:!0,allowEmpty:!1,properties:{view:y({},g(r)),canvasInfo:y({},x(r,!0)),camera:y({},k(r)),screen:y({},w(r)),text:y({},S(r)),image:y({},T(r)),video:y({},E(r))},validate:function(e,t,n,i){var o=r.errorModule,a=o.RtcError,s=o.ErrorCode,u=o.ErrorCodeDictionary;if(r.environment.isMobile())throw new a({code:s.ENV_NOT_SUPPORTED,message:"VideoMixer is not supported on mobile devices currently"});var l=e.onScreenShareStop;if(l&&!r.utils.isFunction(l))throw new a({code:s.INVALID_PARAMETER,extraCode:u.INVALID_PARAMETER_TYPE,fnName:n,messageParams:{key:"onScreenShareStop",value:c(l),rule:{type:"Function"}}})}};case"update":return function(e){return{name:"VideoMixerOptions",type:"object",required:!1,allowEmpty:!1,properties:{view:y({},g(e)),canvasInfo:y({},x(e)),camera:y({},k(e)),screen:y({},w(e)),text:y({},S(e)),image:y({},T(e)),video:y({},E(e))}}}(this.core);case"stop":return this.core,{name:"StopVideoMixerOptions",required:!1}}var r}},{key:"getGroup",value:function(){return"vmix"}},{key:"start",value:(_=t(o().mark((function e(r){var t,n,i,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.localMixVideoTrack||(this.localMixVideoTrack=new this.core.LocalMixVideoTrack(this.core.room.videoManager)),this._mixVideoConfig={canvasInfo:{width:1920,height:1080}},r=this.core.utils.deepCloneBasic(r),n=(t=r).view,i=t.onScreenShareStop,e.next=6,this.parseMixOptions(r);case 6:return a=e.sent,i&&(this.onScreenShareStop=i,this._mixVideoConfig.onScreenShareStop=i),this._updatePreview({view:n,track:this.localMixVideoTrack}),this.core.utils.isUndefined(n)||(this._mixVideoConfig.view=n),e.next=12,this.localMixVideoTrack.startMix();case 12:return e.abrupt("return",{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:a});case 13:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"update",value:(O=t(o().mark((function e(r){var t,n,i,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.core.errorModule,n=t.RtcError,i=t.ErrorCode,this.localMixVideoTrack){e.next=3;break}throw new n({code:i.INVALID_OPERATION,message:"mixTrack doesn't initialize!"});case 3:return r=this.core.utils.deepCloneBasic(r),a=r.view,e.next=7,this.parseMixOptions(r);case 7:return s=e.sent,e.next=10,this._updatePreview({view:a,track:this.localMixVideoTrack,prevConfig:this._mixVideoConfig});case 10:return this.core.utils.isUndefined(a)||(this._mixVideoConfig.view=a),e.abrupt("return",{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:s});case 12:case"end":return e.stop()}}),e,this)}))),function(e){return O.apply(this,arguments)})},{key:"parseMixOptions",value:(C=t(o().mark((function e(r){var t,n,i,s,c,u,l,p,f,d,h,v,m,x,g,b,k,w,S,T,E,V,M,A,L,C,O,_,I,P,q,N,j;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t={successOptions:{},failedDetails:[]},n=this.core.errorModule,i=n.RtcError,s=n.ErrorCode,n.ErrorCodeDictionary,this.localMixVideoTrack&&this._mixVideoConfig){e.next=4;break}return e.abrupt("return",t);case 4:if(c=[],u=y({},r),l=r.canvasInfo,p=r.camera,f=r.screen,d=r.text,h=r.image,v=r.video,m=0,x=0,l&&(g=l.canvasColor,b=l.width,k=l.height,w=l.frameRate,g&&this.localMixVideoTrack.setMixBackground(g),w&&this.localMixVideoTrack.setFps(w),this.localMixVideoTrack.resizeMixCanvas(b,k),this._mixVideoConfig.canvasInfo=l),!p){e.next=20;break}return m++,e.next=14,this.parseCameraOptions(this.localMixVideoTrack,p,this._mixVideoConfig.camera);case 14:S=e.sent,T=S.finalOptions,E=S.errors,this._mixVideoConfig.camera=T,u.camera=T,E.length>0&&(c.push.apply(c,a(E)),E.length===p.length&&x++);case 20:if(!f){e.next=30;break}return m++,e.next=24,this.parseScreenOptions(this.localMixVideoTrack,f,this._mixVideoConfig.screen);case 24:V=e.sent,M=V.finalOptions,A=V.errors,this._mixVideoConfig.screen=M,u.screen=M,A.length>0&&(c.push.apply(c,a(A)),A.length===f.length&&x++);case 30:if(!d){e.next=40;break}return m++,e.next=34,this.parseTextOptions(this.localMixVideoTrack,d,this._mixVideoConfig.text);case 34:L=e.sent,C=L.finalOptions,O=L.errors,this._mixVideoConfig.text=C,u.text=C,O.length>0&&(c.push.apply(c,a(O)),O.length===d.length&&x++);case 40:if(!h){e.next=50;break}return m++,e.next=44,this.parseImageOptions(this.localMixVideoTrack,h,this._mixVideoConfig.image);case 44:_=e.sent,I=_.finalOptions,P=_.errors,this._mixVideoConfig.image=I,u.image=I,P.length>0&&(c.push.apply(c,a(P)),P.length===h.length&&x++);case 50:if(!v){e.next=60;break}return m++,e.next=54,this.parseVideoOptions(this.localMixVideoTrack,v,this._mixVideoConfig.video);case 54:q=e.sent,N=q.finalOptions,j=q.errors,this._mixVideoConfig.video=N,u.video=N,j.length>0&&(c.push.apply(c,a(j)),j.length===v.length&&x++);case 60:if(!(x>0&&x===m)){e.next=62;break}throw new i({code:s.INVALID_PARAMETER,message:"all sources mix failed",data:{failedDetails:c}});case 62:return t={successOptions:u,failedDetails:c},e.abrupt("return",t);case 64:case"end":return e.stop()}}),e,this)}))),function(e){return C.apply(this,arguments)})},{key:"parseCameraOptions",value:(L=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,f,d,h,y,v,m,x,g,b,k,w,S,T,E,V=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=V.length>2&&void 0!==V[2]?V[2]:[],c=new Set(t.map((function(e){return e.id}))),u=n.filter((function(e){return!c.has(e.id)})).map((function(e){return e.id})),l=i(u);try{for(l.s();!(p=l.n()).done;)f=p.value,r.removeCameraSource(f)}catch(e){l.e(e)}finally{l.f()}d=new Map(n.map((function(e){return[e.id,e]}))),h=[],y=[],v=i(t),e.prev=9,v.s();case 11:if((m=v.n()).done){e.next=45;break}if(x=m.value,g=x.id,b=x.layout,k=x.profile,e.prev=14,!r.inputLocalVideoTracks.has(g)){e.next=25;break}return w=null==(a=r.inputLocalVideoTracks.get(g))?void 0:a.mediaTrack,e.next=19,this.updateCameraProfile(x);case 19:S=null==(s=r.inputLocalVideoTracks.get(g))?void 0:s.mediaTrack,T=void 0,k&&(T=this.core.utils.isString(k)?this.core.constants.videoProfileMap[k]:k),S!==w?r.updateCameraSource(g,b,S,T):r.updateCameraSource(g,b,null,T),e.next=36;break;case 25:return e.next=27,this.captureCamera(x);case 27:E=e.sent,e.prev=28,r.addCameraSource(g,E,b),e.next=36;break;case 32:throw e.prev=32,e.t0=e.catch(28),E.close(),e.t0;case 36:h.push(x),e.next=43;break;case 39:e.prev=39,e.t1=e.catch(14),y.push({id:g,error:e.t1}),d.has(g)&&h.push(d.get(g));case 43:e.next=11;break;case 45:e.next=50;break;case 47:e.prev=47,e.t2=e.catch(9),v.e(e.t2);case 50:return e.prev=50,v.f(),e.finish(50);case 53:return e.abrupt("return",{finalOptions:h,errors:y});case 54:case"end":return e.stop()}}),e,this,[[9,47,50,53],[14,39],[28,32]])}))),function(e,r){return L.apply(this,arguments)})},{key:"parseScreenOptions",value:(A=t(o().mark((function e(r,t){var n,i,a,s,c,u,l,p=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=p.length>2&&void 0!==p[2]?p[2]:[],i=this.prepareScreenOptions(t,n),a=i.removeIdList,s=i.preOptionsMap,this.removeUnusedScreenSources(r,a),e.next=5,this.processScreenSources(r,t,s);case 5:return c=e.sent,u=c.finalOptions,l=c.errors,e.abrupt("return",{finalOptions:u,errors:l});case 9:case"end":return e.stop()}}),e,this)}))),function(e,r){return A.apply(this,arguments)})},{key:"prepareScreenOptions",value:function(e,r){var t=new Set(e.map((function(e){return e.id})));return{removeIdList:r.filter((function(e){return!t.has(e.id)})).map((function(e){return e.id})),preOptionsMap:new Map(r.map((function(e){return[e.id,e]})))}}},{key:"removeUnusedScreenSources",value:function(e,r){var t,n=i(r);try{for(n.s();!(t=n.n()).done;){var o=t.value;e.removeScreenSource(o),this.removeSystemAudioTrack(o)}}catch(e){n.e(e)}finally{n.f()}}},{key:"processScreenSources",value:(M=t(o().mark((function e(r,t,n){var a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=[],s=[],c=i(t),e.prev=3,c.s();case 5:if((u=c.n()).done){e.next=17;break}return l=u.value,e.prev=7,e.next=10,this.processSingleScreenSource(r,l,n,a);case 10:e.next=15;break;case 12:e.prev=12,e.t0=e.catch(7),this.handleScreenSourceError(l.id,e.t0,n,a,s);case 15:e.next=5;break;case 17:e.next=22;break;case 19:e.prev=19,e.t1=e.catch(3),c.e(e.t1);case 22:return e.prev=22,c.f(),e.finish(22);case 25:return e.abrupt("return",{finalOptions:a,errors:s});case 26:case"end":return e.stop()}}),e,this,[[3,19,22,25],[7,12]])}))),function(e,r,t){return M.apply(this,arguments)})},{key:"processSingleScreenSource",value:(b=t(o().mark((function e(r,t,n,i){var a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=t.id,s=t.layout,c=n.get(a),u=r.inputLocalScreenTracks.has(a),l=!(null==c?void 0:c.systemAudio)&&t.systemAudio,!u||l){e.next=9;break}return e.next=7,this.updateExistingScreenSource(r,a,s,c,t);case 7:e.next=11;break;case 9:return e.next=11,this.addNewScreenSource(r,t,c);case 11:i.push(t);case 12:case"end":return e.stop()}}),e,this)}))),function(e,r,t,n){return b.apply(this,arguments)})},{key:"updateExistingScreenSource",value:(m=t(o().mark((function e(r,t,n,i,a){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r.updateScreenSource(t,n),(null==i?void 0:i.systemAudio)&&!a.systemAudio&&this.removeSystemAudioTrack(t);case 2:case"end":return e.stop()}}),e,this)}))),function(e,r,t,n,i){return m.apply(this,arguments)})},{key:"addNewScreenSource",value:(h=t(o().mark((function e(r,t,n){var i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.captureScreen(t);case 2:i=e.sent,!(null==n?void 0:n.systemAudio)&&t.systemAudio&&r.inputLocalScreenTracks.has(t.id)&&r.removeScreenSource(t.id),e.prev=4,r.addScreenSource(t.id,i,t.layout),e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(4),i.close(),e.t0;case 12:case"end":return e.stop()}}),e,this,[[4,8]])}))),function(e,r,t){return h.apply(this,arguments)})},{key:"handleScreenSourceError",value:function(e,r,t,n,i){i.push({id:e,error:r}),t.has(e)&&n.push(t.get(e))}},{key:"parseTextOptions",value:(d=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,f,d,h,y,v,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=new Set(t.map((function(e){return e.id}))),s=n.filter((function(e){return!a.has(e.id)})).map((function(e){return e.id})),c=i(s);try{for(c.s();!(u=c.n()).done;)l=u.value,r.removeTextSource(l)}catch(e){c.e(e)}finally{c.f()}p=new Map(n.map((function(e){return[e.id,e]}))),f=[],d=[],h=i(t),e.prev=9,v=o().mark((function e(){var t,i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=y.value,i=t.id;try{n.some((function(e){return e.id===i}))?r.updateTextSource(t):r.addTextSource(t),f.push(t)}catch(e){d.push({id:i,error:e}),p.has(i)&&f.push(p.get(i))}case 3:case"end":return e.stop()}}),e)})),h.s();case 12:if((y=h.n()).done){e.next=16;break}return e.delegateYield(v(),"t0",14);case 14:e.next=12;break;case 16:e.next=21;break;case 18:e.prev=18,e.t1=e.catch(9),h.e(e.t1);case 21:return e.prev=21,h.f(),e.finish(21);case 24:return e.abrupt("return",{finalOptions:f,errors:d});case 25:case"end":return e.stop()}}),e,null,[[9,18,21,24]])}))),function(e,r){return d.apply(this,arguments)})},{key:"parseImageOptions",value:(f=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,f,d,h,y,v,m=this,x=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=x.length>2&&void 0!==x[2]?x[2]:[],a=new Set(t.map((function(e){return e.id}))),s=n.filter((function(e){return!a.has(e.id)})).map((function(e){return e.id})),c=i(s);try{for(c.s();!(u=c.n()).done;)l=u.value,r.removeImageSource(l)}catch(e){c.e(e)}finally{c.f()}p=new Map(n.map((function(e){return[e.id,e]}))),f=[],d=[],h=i(t),e.prev=9,v=o().mark((function e(){var t,i,a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=y.value,i=t.id,a=t.url,s=t.layout,e.prev=2,!(c=n.find((function(e){return e.id===i})))){e.next=12;break}if(c.url===a){e.next=9;break}return e.next=8,m.core.utils.loadImage(a);case 8:u=e.sent;case 9:r.updateImageSource(i,s,u),e.next=16;break;case 12:return e.next=14,m.core.utils.loadImage(a);case 14:l=e.sent,r.addImageSource(i,l,s);case 16:f.push(t),e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),d.push({id:i,error:e.t0}),p.has(i)&&f.push(p.get(i));case 23:case"end":return e.stop()}}),e,null,[[2,19]])})),h.s();case 12:if((y=h.n()).done){e.next=16;break}return e.delegateYield(v(),"t0",14);case 14:e.next=12;break;case 16:e.next=21;break;case 18:e.prev=18,e.t1=e.catch(9),h.e(e.t1);case 21:return e.prev=21,h.f(),e.finish(21);case 24:return e.abrupt("return",{finalOptions:f,errors:d});case 25:case"end":return e.stop()}}),e,null,[[9,18,21,24]])}))),function(e,r){return f.apply(this,arguments)})},{key:"parseVideoOptions",value:(p=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,f,d,h,y,v,m=this,x=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=x.length>2&&void 0!==x[2]?x[2]:[],a=new Set(t.map((function(e){return e.id}))),s=n.filter((function(e){return!a.has(e.id)})).map((function(e){return e.id})),c=i(s);try{for(c.s();!(u=c.n()).done;)l=u.value,r.removeVideoSource(l)}catch(e){c.e(e)}finally{c.f()}p=new Map(n.map((function(e){return[e.id,e]}))),f=[],d=[],h=i(t),e.prev=9,v=o().mark((function e(){var t,i,a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=y.value,i=t.id,a=t.url,s=t.layout,e.prev=2,!(c=n.find((function(e){return e.id===i})))){e.next=12;break}if(c.url===a){e.next=9;break}return e.next=8,m.core.utils.loadVideo(a);case 8:u=e.sent;case 9:r.updateVideoSource(i,s,u),e.next=16;break;case 12:return e.next=14,m.core.utils.loadVideo(a);case 14:l=e.sent,r.addVideoSource(i,l,s);case 16:f.push(t),e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),d.push({id:i,error:e.t0}),p.has(i)&&f.push(p.get(i));case 23:case"end":return e.stop()}}),e,null,[[2,19]])})),h.s();case 12:if((y=h.n()).done){e.next=16;break}return e.delegateYield(v(),"t0",14);case 14:e.next=12;break;case 16:e.next=21;break;case 18:e.prev=18,e.t1=e.catch(9),h.e(e.t1);case 21:return e.prev=21,h.f(),e.finish(21);case 24:return e.abrupt("return",{finalOptions:f,errors:d});case 25:case"end":return e.stop()}}),e,null,[[9,18,21,24]])}))),function(e,r){return p.apply(this,arguments)})},{key:"captureCamera",value:(l=t(o().mark((function e(r){var t,n,i,a,s,c;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.id,n=r.cameraId,i=r.videoTrack,a=r.profile,(s=new this.core.LocalVideoTrack).log.id+="-".concat(t),c={},n?c.deviceId=n:this.core.utils.isUndefined(i)||(c.customSource=i),this.core.utils.isUndefined(a)||(this.core.utils.isString(a)?this.core.constants.videoProfileMap[a]&&s.setProfile(this.core.constants.videoProfileMap[a]):s.setProfile(a)),e.next=8,s.capture(c);case 8:return e.abrupt("return",s);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"updateCameraProfile",value:(u=t(o().mark((function e(r){var t,n,i,a,s,c;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.id,i=r.cameraId,a=r.videoTrack,s=r.profile,c=null==(t=this.localMixVideoTrack)?void 0:t.inputLocalVideoTracks.get(n)){e.next=4;break}return e.abrupt("return");case 4:if(!i){e.next=9;break}return e.next=7,c.switchDevice(i);case 7:e.next=12;break;case 9:if(this.core.utils.isUndefined(a)){e.next=12;break}return e.next=12,c.setInputMediaStreamTrack(a);case 12:if(this.core.utils.isUndefined(s)){e.next=17;break}if(this.core.utils.isString(s)?this.core.constants.videoProfileMap[s]&&c.setProfile(this.core.constants.videoProfileMap[s]):c.setProfile(s),i&&c.isNeedToSwitchDevice(i)){e.next=17;break}return e.next=17,c.applyProfile();case 17:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"captureScreen",value:(s=t(o().mark((function e(r){var t,n,i,a,s,c,u,l=this;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.id,n=r.profile,i=r.captureElement,a=r.preferDisplaySurface,(s=new this.core.LocalScreenTrack).log.id+="-".concat(t),c={},this.core.utils.isUndefined(n)||(this.core.utils.isString(n)?this.core.constants.screenProfileMap[n]&&s.setProfile(this.core.constants.screenProfileMap[n]):s.setProfile(n)),i&&(c.captureElement=i),a&&(c.preferDisplaySurface=a),c.systemAudio=r.systemAudio,e.next=10,s.capture(c);case 10:return u=e.sent,c.systemAudio&&u.getAudioTracks().length>0?(this.systemAudioTrackList[t]=u.getAudioTracks()[0],this.log.info(t+" system audio track captured")):this.removeSystemAudioTrack(t),s.mediaTrack.addEventListener(this.core.constants.NAME.ENDED,(function(){var e,r,n;null==(e=l.localMixVideoTrack)||e.removeScreenSource(t),(null==(r=l._mixVideoConfig)?void 0:r.screen)&&(l._mixVideoConfig.screen=l._mixVideoConfig.screen.filter((function(e){return e.id!==t}))),null==(n=l.onScreenShareStop)||n.call(l,t)})),e.abrupt("return",s);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_updatePreview",value:(r=t(o().mark((function e(r){var t,n,i,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.view,n=r.track,i=r.prevConfig,!(this.core.utils.isUndefined(t)&&i&&i.view)){e.next=6;break}if(!((a=this.core.utils.getViewListFromView(i.view)).length>0)){e.next=6;break}return e.next=6,n.play(a);case 6:if(this.core.utils.isUndefined(t)){e.next=14;break}if(!((s=this.core.utils.getViewListFromView(t)).length>0)){e.next=13;break}return e.next=11,n.play(s);case 11:e.next=14;break;case 13:n.stop();case 14:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"stop",value:function(){var e;null==(e=this.localMixVideoTrack)||e.close(),this.localMixVideoTrack=null,Object.values(this.systemAudioTrackList).forEach((function(e){return e.stop()})),this.systemAudioTrackList={},delete this.onScreenShareStop,delete this._mixVideoConfig}},{key:"removeSystemAudioTrack",value:function(e){this.systemAudioTrackList[e]&&(this.systemAudioTrackList[e].stop(),this.log.info(e+" system audio track stop"),delete this.systemAudioTrackList[e])}}]);var r,s,u,l,p,f,d,h,m,b,M,A,L,C,O,_}();return v(M,"Name","VideoMixer"),M}));
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).VideoMixer=r()}(this,(function(){"use strict";function e(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function r(e,r,t,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void t(e)}s.done?r(c):Promise.resolve(c).then(n,i)}function t(e){return function(){var t=this,n=arguments;return new Promise((function(i,o){var a=e.apply(t,n);function s(e){r(a,i,o,s,c,"next",e)}function c(e){r(a,i,o,s,c,"throw",e)}s(void 0)}))}}function n(e,r,t){return r&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,s(n.key),n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=u(e))||r){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},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 o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function o(){o=function(){return r};var e,r={},t=Object.prototype,n=t.hasOwnProperty,i=Object.defineProperty||function(e,r,t){e[r]=t.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function l(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{l({},"")}catch(e){l=function(e,r,t){return e[r]=t}}function p(e,r,t,n){var o=r&&r.prototype instanceof k?r:k,a=Object.create(o.prototype),s=new O(n||[]);return i(a,"_invoke",{value:V(e,t,s)}),a}function d(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var f="suspendedStart",h="suspendedYield",v="executing",y="completed",m={};function k(){}function g(){}function x(){}var b={};l(b,s,(function(){return this}));var S=Object.getPrototypeOf,w=S&&S(S(I([])));w&&w!==t&&n.call(w,s)&&(b=w);var T=x.prototype=k.prototype=Object.create(b);function E(e){["next","throw","return"].forEach((function(r){l(e,r,(function(e){return this._invoke(r,e)}))}))}function L(e,r){function t(i,o,a,s){var c=d(e[i],e,o);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(e){t("next",e,a,s)}),(function(e){t("throw",e,a,s)})):r.resolve(l).then((function(e){u.value=e,a(u)}),(function(e){return t("throw",e,a,s)}))}s(c.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new r((function(r,i){t(e,n,r,i)}))}return o=o?o.then(i,i):i()}})}function V(r,t,n){var i=f;return function(o,a){if(i===v)throw Error("Generator is already running");if(i===y){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var c=A(s,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===f)throw i=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=v;var u=d(r,t,n);if("normal"===u.type){if(i=n.done?y:h,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(i=y,n.method="throw",n.arg=u.arg)}}}function A(r,t){var n=t.method,i=r.iterator[n];if(i===e)return t.delegate=null,"throw"===n&&r.iterator.return&&(t.method="return",t.arg=e,A(r,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var o=d(i,r.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,m;var a=o.arg;return a?a.done?(t[r.resultName]=a.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=e),t.delegate=null,m):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function C(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function M(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function I(r){if(r||""===r){var t=r[s];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function t(){for(;++i<r.length;)if(n.call(r,i))return t.value=r[i],t.done=!1,t;return t.value=e,t.done=!0,t};return o.next=o}}throw new TypeError(typeof r+" is not iterable")}return g.prototype=x,i(T,"constructor",{value:x,configurable:!0}),i(x,"constructor",{value:g,configurable:!0}),g.displayName=l(x,u,"GeneratorFunction"),r.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,l(e,u,"GeneratorFunction")),e.prototype=Object.create(T),e},r.awrap=function(e){return{__await:e}},E(L.prototype),l(L.prototype,c,(function(){return this})),r.AsyncIterator=L,r.async=function(e,t,n,i,o){void 0===o&&(o=Promise);var a=new L(p(e,t,n,i),o);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(T),l(T,u,"Generator"),l(T,s,(function(){return this})),l(T,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=I,O.prototype={constructor:O,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!r)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var t=this;function i(n,i){return s.type="throw",s.arg=r,t.next=n,i&&(t.method="next",t.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=r,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(a)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),m},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),M(t),m}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var i=n.arg;M(t)}return i}}throw Error("illegal catch attempt")},delegateYield:function(r,t,n){return this.delegate={iterator:I(r),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=e),m}},r}function a(r){return function(r){if(Array.isArray(r))return e(r)}(r)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(r)||u(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof r?r:r+""}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(r,t){if(r){if("string"==typeof r)return e(r,t);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(r,t):void 0}}var l=Object.defineProperty,p=Object.getOwnPropertySymbols,d=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,h=function(e,r,t){return r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t},v=function(e,r){for(var t in r||(r={}))d.call(r,t)&&h(e,t,r[t]);if(p){var n,o=i(p(r));try{for(o.s();!(n=o.n()).done;){t=n.value;f.call(r,t)&&h(e,t,r[t])}}catch(e){o.e(e)}finally{o.f()}}return e},y=function(e,r,t){return h(e,"symbol"!==c(r)?r+"":r,t)},m={x:{required:!0,type:"number"},y:{required:!0,type:"number"},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},zIndex:{required:!0,type:"number"},fillMode:{required:!1,type:"string"},mirror:{required:!1,type:"boolean"},rotation:{required:!1,type:"number"},hidden:{required:!1,type:"boolean"}},k=function(e){return{type:"object",required:arguments.length>1&&void 0!==arguments[1]&&arguments[1],properties:{canvasColor:{required:!1,type:["string",CanvasGradient,CanvasPattern]},width:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},height:{required:!0,type:"number",notLessThanZero:!0,min:1,max:3840},frameRate:{required:!1,type:"number",notLessThanZero:!0,min:1,max:60}},validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode;if(i.ErrorCodeDictionary,r){var s=r.width,c=r.height;if(s&&c&&s*c>8294400)throw new o({code:a.INVALID_PARAMETER,message:"The mix resolution cannot be set higher than 3840 * 2160."})}}}},g=function(e){return{required:!1,type:["string",HTMLElement,null],validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(e.utils.isString(r)&&!document.getElementById(r))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_ELEMENT_ID,fnName:n,messageParams:{key:t}})}}},x=function(e){return{type:"object",required:!(arguments.length>1&&void 0!==arguments[1])||arguments[1],properties:v({},m),validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(r){if(r.fillMode&&!["contain","cover","fill"].includes(r.fillMode))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The fillMode parameter must be 'contain', 'cover' or 'fill'",fnName:n});if(r.rotation&&![0,90,180,270].includes(r.rotation))throw new o({code:a.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The rotation parameter must be 0, 90, 180 or 270",fnName:n})}}}},b=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},cameraId:{required:!1,type:"string"},videoTrack:{required:!1,instanceof:MediaStreamTrack},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},layout:v({},x(e))}}}},S=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},profile:{required:!1,type:["string","object"],properties:{width:{type:"number"},height:{type:"number"},frameRate:{type:"number"},bitrate:{type:"number"}}},captureElement:{required:!1,type:HTMLElement},preferDisplaySurface:{required:!1,type:"string"},layout:v({},x(e))},validate:function(r,t,n){var i=e.errorModule,o=i.RtcError,a=i.ErrorCode,s=i.ErrorCodeDictionary;if(!e.rtcDectection.isScreenCaptureApiAvailable())throw new o({code:a.ENV_NOT_SUPPORTED,fnName:n,extraCode:s.NOT_SUPPORTED_SCREEN_SHARE})}}}},w=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},content:{required:!0,type:"string"},font:{required:!1,type:"string"},color:{required:!1,type:["string",CanvasGradient,CanvasPattern]},layout:v({},x(e))}}}},T=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:v({},x(e))}}}},E=function(e){return{type:"array",required:!1,arrayItem:{type:"object",properties:{id:{required:!0,type:"string"},url:{required:!0,type:"string"},layout:v({},x(e))}}}};var L=0,V=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.core=r,y(this,"seq"),y(this,"log"),y(this,"localMixVideoTrack",null),y(this,"systemAudioTrackList",{}),y(this,"_mixVideoConfig"),y(this,"onScreenShareStop"),y(this,"eventListeners",new Map),L+=1,this.seq=L,this.log=r.log.createChild({id:"".concat(this.getAlias()).concat(L)}),this.log.info("created")}return n(e,[{key:"getName",value:function(){return e.Name}},{key:"getAlias",value:function(){return"vmix"}},{key:"getValidateRule",value:function(e){switch(e){case"start":return r=this.core,{name:"VideoMixerOptions",type:"object",required:!0,allowEmpty:!1,properties:{view:v({},g(r)),canvasInfo:v({},k(r,!0)),camera:v({},b(r)),screen:v({},S(r)),text:v({},w(r)),image:v({},T(r)),video:v({},E(r))},validate:function(e,t,n,i){var o=r.errorModule,a=o.RtcError,s=o.ErrorCode,u=o.ErrorCodeDictionary;if(r.environment.isMobile())throw new a({code:s.ENV_NOT_SUPPORTED,message:"VideoMixer is not supported on mobile devices currently"});var l=e.onScreenShareStop;if(l&&!r.utils.isFunction(l))throw new a({code:s.INVALID_PARAMETER,extraCode:u.INVALID_PARAMETER_TYPE,fnName:n,messageParams:{key:"onScreenShareStop",value:c(l),rule:{type:"Function"}}})}};case"update":return function(e){return{name:"VideoMixerOptions",type:"object",required:!1,allowEmpty:!1,properties:{view:v({},g(e)),canvasInfo:v({},k(e)),camera:v({},b(e)),screen:v({},S(e)),text:v({},w(e)),image:v({},T(e)),video:v({},E(e))}}}(this.core);case"stop":return this.core,{name:"StopVideoMixerOptions",required:!1}}var r}},{key:"getGroup",value:function(){return"vmix"}},{key:"start",value:(N=t(o().mark((function e(r){var t,n,i,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.localMixVideoTrack||(this.localMixVideoTrack=new this.core.LocalMixVideoTrack(this.core.room.videoManager)),this._mixVideoConfig={canvasInfo:{width:1920,height:1080}},r=this.core.utils.deepCloneBasic(r),n=(t=r).view,i=t.onScreenShareStop,e.next=6,this.parseMixOptions(r);case 6:return a=e.sent,i&&(this.onScreenShareStop=i,this._mixVideoConfig.onScreenShareStop=i),this._updatePreview({view:n,track:this.localMixVideoTrack}),this.core.utils.isUndefined(n)||(this._mixVideoConfig.view=n),e.next=12,this.localMixVideoTrack.startMix();case 12:return e.abrupt("return",{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:a});case 13:case"end":return e.stop()}}),e,this)}))),function(e){return N.apply(this,arguments)})},{key:"update",value:(P=t(o().mark((function e(r){var t,n,i,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.core.errorModule,n=t.RtcError,i=t.ErrorCode,this.localMixVideoTrack){e.next=3;break}throw new n({code:i.INVALID_OPERATION,message:"mixTrack doesn't initialize!"});case 3:return r=this.core.utils.deepCloneBasic(r),a=r.view,e.next=7,this.parseMixOptions(r);case 7:return s=e.sent,e.next=10,this._updatePreview({view:a,track:this.localMixVideoTrack,prevConfig:this._mixVideoConfig});case 10:return this.core.utils.isUndefined(a)||(this._mixVideoConfig.view=a),e.abrupt("return",{track:this.localMixVideoTrack._outputTrack,systemAudioTrackList:this.systemAudioTrackList,result:s});case 12:case"end":return e.stop()}}),e,this)}))),function(e){return P.apply(this,arguments)})},{key:"stop",value:function(){var e,r=this;this.eventListeners.forEach((function(e,t){r.removeEventListeners(t)})),this.eventListeners.clear(),null==(e=this.localMixVideoTrack)||e.close(),this.localMixVideoTrack=null,Object.values(this.systemAudioTrackList).forEach((function(e){return e.stop()})),this.systemAudioTrackList={},delete this.onScreenShareStop,delete this._mixVideoConfig}},{key:"parseMixOptions",value:(_=t(o().mark((function e(r){var t,n,i,s,c,u,l,p,d,f,h,y,m,k,g,x,b,S,w,T,E,L;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t={successOptions:{},failedDetails:[]},n=this.core.errorModule,i=n.RtcError,s=n.ErrorCode,this.localMixVideoTrack&&this._mixVideoConfig){e.next=4;break}return e.abrupt("return",t);case 4:c=[],u=v({},r),l=r.canvasInfo,p=r.camera,d=r.screen,f=r.text,h=r.image,y=r.video,l&&this.parseCanvasOptions(l),m=0,k=0,g=[{key:"camera",options:p,parser:this.parseCameraOptions.bind(this)},{key:"screen",options:d,parser:this.parseScreenOptions.bind(this)},{key:"text",options:f,parser:this.parseTextOptions.bind(this)},{key:"image",options:h,parser:this.parseImageOptions.bind(this)},{key:"video",options:y,parser:this.parseVideoOptions.bind(this)}],x=0,b=g;case 12:if(!(x<b.length)){e.next=25;break}if(S=b[x],w=S.key,T=S.options,E=S.parser,!T){e.next=22;break}return m++,e.next=18,E(this.localMixVideoTrack,T,this._mixVideoConfig[w]||[]);case 18:L=e.sent,this._mixVideoConfig[w]=L.finalOptions,u[w]=L.finalOptions,L.errors.length>0&&(c.push.apply(c,a(L.errors)),L.errors.length===T.length&&k++);case 22:x++,e.next=12;break;case 25:if(!(k>0&&k===m)){e.next=27;break}throw new i({code:s.INVALID_PARAMETER,message:"all sources mix failed",data:{failedDetails:c}});case 27:return e.abrupt("return",{successOptions:u,failedDetails:c});case 28:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"parseCanvasOptions",value:function(e){if(this.localMixVideoTrack&&this._mixVideoConfig){var r=e.canvasColor,t=e.width,n=e.height,i=e.frameRate;r&&this.localMixVideoTrack.setMixBackground(r),i&&this.localMixVideoTrack.setFps(i),this.localMixVideoTrack.resizeMixCanvas(t,n),this._mixVideoConfig.canvasInfo=e}}},{key:"prepareSourceOptions",value:function(e,r){var t=new Set(e.map((function(e){return e.id})));return{removeIdList:r.filter((function(e){return!t.has(e.id)})).map((function(e){return e.id})),preOptionsMap:new Map(r.map((function(e){return[e.id,e]})))}}},{key:"recordSourceError",value:function(e,r,t,n,i){i.push({id:e,error:r}),t.has(e)&&n.push(t.get(e))}},{key:"parseCameraOptions",value:(I=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,d,f,h,v,y,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=this.prepareSourceOptions(t,n),s=a.removeIdList,c=a.preOptionsMap,u=i(s);try{for(u.s();!(l=u.n()).done;)p=l.value,r.removeCameraSource(p)}catch(e){u.e(e)}finally{u.f()}d=[],f=[],h=i(t),e.prev=7,h.s();case 9:if((v=h.n()).done){e.next=22;break}return y=v.value,e.prev=11,e.next=14,this.processSingleCameraSource(r,y);case 14:d.push(y),e.next=20;break;case 17:e.prev=17,e.t0=e.catch(11),this.recordSourceError(y.id,e.t0,c,d,f);case 20:e.next=9;break;case 22:e.next=27;break;case 24:e.prev=24,e.t1=e.catch(7),h.e(e.t1);case 27:return e.prev=27,h.f(),e.finish(27);case 30:return e.abrupt("return",{finalOptions:d,errors:f});case 31:case"end":return e.stop()}}),e,this,[[7,24,27,30],[11,17]])}))),function(e,r){return I.apply(this,arguments)})},{key:"processSingleCameraSource",value:(O=t(o().mark((function e(r,t){var n,i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.id,t.layout,t.profile,t.useInternalTrack&&((null==(n=this.core.trtc.localVideoTrack)?void 0:n.sourceTrack)?t.videoTrack=this.core.trtc.localVideoTrack.sourceTrack:t.videoTrack=this.createPlaceholderVideoTrack()),this.log.info("videomixer camera option ".concat(JSON.stringify(t))),!r.inputLocalVideoTracks.has(i)){e.next=8;break}return e.next=6,this.updateExistingCameraSource(r,t);case 6:e.next=10;break;case 8:return e.next=10,this.addNewCameraSource(r,t);case 10:case"end":return e.stop()}}),e,this)}))),function(e,r){return O.apply(this,arguments)})},{key:"updateExistingCameraSource",value:(M=t(o().mark((function e(r,t){var n,i,a,s,c,u,l,p;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t.id,s=t.layout,c=t.profile,u=null==(n=r.inputLocalVideoTracks.get(a))?void 0:n.mediaTrack,e.next=4,this.updateCameraProfile(t);case 4:l=null==(i=r.inputLocalVideoTracks.get(a))?void 0:i.mediaTrack,p=this.resolveVideoProfile(c),l!==u?r.updateCameraSource(a,s,l,p):r.updateCameraSource(a,s,null,p);case 7:case"end":return e.stop()}}),e,this)}))),function(e,r){return M.apply(this,arguments)})},{key:"addNewCameraSource",value:(C=t(o().mark((function e(r,t){var n,i,a,s,c,u=this;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.id,i=t.layout,a=t.useInternalTrack,e.next=3,this.captureCamera(t);case 3:s=e.sent,this.removeEventListeners(n),a&&(c=function(e){var t,i;if(!(null==(t=e.track)?void 0:t.isScreen)){u.log.info("videomixer camera LOCAL_TRACK_CAPTURE_SUCCESS");var o=r.inputLocalVideoTracks.get(n);o&&(null==(i=e.track)?void 0:i.sourceTrack)&&o.setInputMediaStreamTrack(e.track.sourceTrack)}},this.core.innerEmitter.on("102",c),this.eventListeners.has(n)||this.eventListeners.set(n,{}),this.eventListeners.get(n).captureSuccess=function(){u.core.innerEmitter.off("102",c)}),e.prev=6,r.addCameraSource(n,s,i),e.next=14;break;case 10:throw e.prev=10,e.t0=e.catch(6),s.close(),e.t0;case 14:case"end":return e.stop()}}),e,this,[[6,10]])}))),function(e,r){return C.apply(this,arguments)})},{key:"resolveVideoProfile",value:function(e){if(!this.core.utils.isUndefined(e))return this.core.utils.isString(e)?this.core.constants.videoProfileMap[e]:e}},{key:"parseScreenOptions",value:(A=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,d,f,h,v,y,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=this.prepareSourceOptions(t,n),s=a.removeIdList,c=a.preOptionsMap,u=i(s);try{for(u.s();!(l=u.n()).done;)p=l.value,r.removeScreenSource(p),this.removeSystemAudioTrack(p)}catch(e){u.e(e)}finally{u.f()}d=[],f=[],h=i(t),e.prev=7,h.s();case 9:if((v=h.n()).done){e.next=22;break}return y=v.value,e.prev=11,e.next=14,this.processSingleScreenSource(r,y,c);case 14:d.push(y),e.next=20;break;case 17:e.prev=17,e.t0=e.catch(11),this.recordSourceError(y.id,e.t0,c,d,f);case 20:e.next=9;break;case 22:e.next=27;break;case 24:e.prev=24,e.t1=e.catch(7),h.e(e.t1);case 27:return e.prev=27,h.f(),e.finish(27);case 30:return e.abrupt("return",{finalOptions:d,errors:f});case 31:case"end":return e.stop()}}),e,this,[[7,24,27,30],[11,17]])}))),function(e,r){return A.apply(this,arguments)})},{key:"processSingleScreenSource",value:(V=t(o().mark((function e(r,t,n){var i,a,s,c,u,l,p;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=t.id,c=t.layout,t.useInternalTrack&&((null==(i=this.core.trtc.localScreenTrack)?void 0:i.mediaTrack)?(t.videoTrack=this.core.trtc.localScreenTrack.mediaTrack,(null==(a=this.core.trtc.localScreenAudioTrack)?void 0:a.mediaTrack)&&(t.audioTrack=this.core.trtc.localScreenAudioTrack.mediaTrack),delete t.captureElement,delete t.preferDisplaySurface,delete t.systemAudio):t.videoTrack=this.createPlaceholderVideoTrack()),this.log.info("videomixer screen option ".concat(JSON.stringify(t))),u=n.get(s),l=r.inputLocalScreenTracks.has(s),p=!(null==u?void 0:u.systemAudio)&&t.systemAudio,!l||p){e.next=10;break}this.updateExistingScreenSource(r,s,c,u,t),e.next=12;break;case 10:return e.next=12,this.addNewScreenSource(r,t,u);case 12:case"end":return e.stop()}}),e,this)}))),function(e,r,t){return V.apply(this,arguments)})},{key:"updateExistingScreenSource",value:function(e,r,t,n,i){e.updateScreenSource(r,t),(null==n?void 0:n.systemAudio)&&!i.systemAudio&&this.removeSystemAudioTrack(r)}},{key:"addNewScreenSource",value:(x=t(o().mark((function e(r,t,n){var i,a,s,c,u=this;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=t.id,a=t.useInternalTrack,e.next=3,this.captureScreen(t);case 3:s=e.sent,this.removeEventListeners(i),a&&(c=function(e){var t,n,o;if(null==(t=e.track)?void 0:t.isScreen){u.log.info("videomixer screen LOCAL_TRACK_CAPTURE_SUCCESS");var a=r.inputLocalScreenTracks.get(i);a&&(null==(n=e.track)?void 0:n.mediaTrack)&&a.setInputMediaStreamTrack(e.track.mediaTrack),u.systemAudioTrackList[i]&&(null==(o=e.track)?void 0:o.mediaTrack)&&(u.systemAudioTrackList[i]=e.track.mediaTrack)}},this.core.innerEmitter.on("102",c),this.eventListeners.has(i)||this.eventListeners.set(i,{}),this.eventListeners.get(i).captureSuccess=function(){u.core.innerEmitter.off("102",c)}),!(null==n?void 0:n.systemAudio)&&t.systemAudio&&r.inputLocalScreenTracks.has(t.id)&&r.removeScreenSource(t.id),e.prev=7,r.addScreenSource(t.id,s,t.layout),e.next=15;break;case 11:throw e.prev=11,e.t0=e.catch(7),s.close(),e.t0;case 15:case"end":return e.stop()}}),e,this,[[7,11]])}))),function(e,r,t){return x.apply(this,arguments)})},{key:"parseTextOptions",value:(m=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,d,f,h,v,y,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=this.prepareSourceOptions(t,n),s=a.removeIdList,c=a.preOptionsMap,u=i(s);try{for(u.s();!(l=u.n()).done;)p=l.value,r.removeTextSource(p)}catch(e){u.e(e)}finally{u.f()}d=[],f=[],h=i(t);try{for(h.s();!(v=h.n()).done;){y=v.value;try{c.has(y.id)?r.updateTextSource(y):r.addTextSource(y),d.push(y)}catch(e){this.recordSourceError(y.id,e,c,d,f)}}}catch(e){h.e(e)}finally{h.f()}return e.abrupt("return",{finalOptions:d,errors:f});case 9:case"end":return e.stop()}}),e,this)}))),function(e,r){return m.apply(this,arguments)})},{key:"parseImageOptions",value:(h=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,d,f,h,v,y,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=this.prepareSourceOptions(t,n),s=a.removeIdList,c=a.preOptionsMap,u=i(s);try{for(u.s();!(l=u.n()).done;)p=l.value,r.removeImageSource(p)}catch(e){u.e(e)}finally{u.f()}d=[],f=[],h=i(t),e.prev=7,h.s();case 9:if((v=h.n()).done){e.next=22;break}return y=v.value,e.prev=11,e.next=14,this.processSingleImageSource(r,y,c);case 14:d.push(y),e.next=20;break;case 17:e.prev=17,e.t0=e.catch(11),this.recordSourceError(y.id,e.t0,c,d,f);case 20:e.next=9;break;case 22:e.next=27;break;case 24:e.prev=24,e.t1=e.catch(7),h.e(e.t1);case 27:return e.prev=27,h.f(),e.finish(27);case 30:return e.abrupt("return",{finalOptions:d,errors:f});case 31:case"end":return e.stop()}}),e,this,[[7,24,27,30],[11,17]])}))),function(e,r){return h.apply(this,arguments)})},{key:"processSingleImageSource",value:(f=t(o().mark((function e(r,t,n){var i,a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.id,a=t.url,s=t.layout,!(c=n.get(i))){e.next=10;break}if(c.url===a){e.next=7;break}return e.next=6,this.core.utils.loadImage(a);case 6:u=e.sent;case 7:r.updateImageSource(i,s,u),e.next=14;break;case 10:return e.next=12,this.core.utils.loadImage(a);case 12:l=e.sent,r.addImageSource(i,l,s);case 14:case"end":return e.stop()}}),e,this)}))),function(e,r,t){return f.apply(this,arguments)})},{key:"parseVideoOptions",value:(d=t(o().mark((function e(r,t){var n,a,s,c,u,l,p,d,f,h,v,y,m=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=m.length>2&&void 0!==m[2]?m[2]:[],a=this.prepareSourceOptions(t,n),s=a.removeIdList,c=a.preOptionsMap,u=i(s);try{for(u.s();!(l=u.n()).done;)p=l.value,r.removeVideoSource(p)}catch(e){u.e(e)}finally{u.f()}d=[],f=[],h=i(t),e.prev=7,h.s();case 9:if((v=h.n()).done){e.next=22;break}return y=v.value,e.prev=11,e.next=14,this.processSingleVideoSource(r,y,c);case 14:d.push(y),e.next=20;break;case 17:e.prev=17,e.t0=e.catch(11),this.recordSourceError(y.id,e.t0,c,d,f);case 20:e.next=9;break;case 22:e.next=27;break;case 24:e.prev=24,e.t1=e.catch(7),h.e(e.t1);case 27:return e.prev=27,h.f(),e.finish(27);case 30:return e.abrupt("return",{finalOptions:d,errors:f});case 31:case"end":return e.stop()}}),e,this,[[7,24,27,30],[11,17]])}))),function(e,r){return d.apply(this,arguments)})},{key:"processSingleVideoSource",value:(p=t(o().mark((function e(r,t,n){var i,a,s,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.id,a=t.url,s=t.layout,!(c=n.get(i))){e.next=10;break}if(c.url===a){e.next=7;break}return e.next=6,this.core.utils.loadVideo(a);case 6:u=e.sent;case 7:r.updateVideoSource(i,s,u),e.next=14;break;case 10:return e.next=12,this.core.utils.loadVideo(a);case 12:l=e.sent,r.addVideoSource(i,l,s);case 14:case"end":return e.stop()}}),e,this)}))),function(e,r,t){return p.apply(this,arguments)})},{key:"createPlaceholderVideoTrack",value:function(){var e=document.createElement("canvas");e.width=640,e.height=480;var r=e.getContext("2d");return r&&(r.fillStyle="black",r.fillRect(0,0,e.width,e.height)),e.captureStream(1).getVideoTracks()[0]}},{key:"removeEventListeners",value:function(e){var r=this.eventListeners.get(e);r&&(r.inputMediaTrackChanged&&r.inputMediaTrackChanged(),r.captureSuccess&&r.captureSuccess(),this.eventListeners.delete(e))}},{key:"captureCamera",value:(l=t(o().mark((function e(r){var t,n,i,a,s,c,u;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.id,n=r.cameraId,i=r.videoTrack,a=r.profile,(s=new this.core.LocalVideoTrack).log.id+="-".concat(t),c={},n?c.deviceId=n:this.core.utils.isUndefined(i)||(c.customSource=i),this.core.utils.isUndefined(a)||(u=this.resolveVideoProfile(a))&&s.setProfile(u),e.next=8,s.capture(c);case 8:return e.abrupt("return",s);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"updateCameraProfile",value:(u=t(o().mark((function e(r){var t,n,i,a,s,c,u;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.id,i=r.cameraId,a=r.videoTrack,s=r.profile,c=null==(t=this.localMixVideoTrack)?void 0:t.inputLocalVideoTracks.get(n)){e.next=4;break}return e.abrupt("return");case 4:if(!i){e.next=9;break}return e.next=7,c.switchDevice(i);case 7:e.next=12;break;case 9:if(this.core.utils.isUndefined(a)){e.next=12;break}return e.next=12,c.setInputMediaStreamTrack(a);case 12:if(this.core.utils.isUndefined(s)){e.next=18;break}if((u=this.resolveVideoProfile(s))&&c.setProfile(u),i&&c.isNeedToSwitchDevice(i)){e.next=18;break}return e.next=18,c.applyProfile();case 18:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"captureScreen",value:(s=t(o().mark((function e(r){var t,n,i,a,s,c,u,l,p,d,f,h=this;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.id,n=r.profile,i=r.captureElement,a=r.preferDisplaySurface,s=r.systemAudio,c=r.videoTrack,u=r.audioTrack,(l=new this.core.LocalScreenTrack).log.id+="-".concat(t),p={captureElement:i,preferDisplaySurface:a,systemAudio:s,videoTrack:c,audioTrack:u},this.core.utils.isUndefined(n)||(this.core.utils.isString(n)?(d=this.core.constants.screenProfileMap[n])&&l.setProfile(d):l.setProfile(n)),e.next=7,l.capture(p);case 7:return f=e.sent,s&&f.getAudioTracks().length>0?(this.systemAudioTrackList[t]=f.getAudioTracks()[0],this.log.info("".concat(t," system audio track captured"))):this.removeSystemAudioTrack(t),l.mediaTrack.addEventListener(this.core.constants.NAME.ENDED,(function(){h.handleScreenShareEnded(t)})),e.abrupt("return",l);case 11:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"handleScreenShareEnded",value:function(e){var r,t,n;null==(r=this.localMixVideoTrack)||r.removeScreenSource(e),(null==(t=this._mixVideoConfig)?void 0:t.screen)&&(this._mixVideoConfig.screen=this._mixVideoConfig.screen.filter((function(r){return r.id!==e}))),null==(n=this.onScreenShareStop)||n.call(this,e)}},{key:"_updatePreview",value:(r=t(o().mark((function e(r){var t,n,i,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.view,n=r.track,i=r.prevConfig,!this.core.utils.isUndefined(t)||!(null==i?void 0:i.view)){e.next=7;break}if(!((a=this.core.utils.getViewListFromView(i.view)).length>0)){e.next=6;break}return e.next=6,n.play(a);case 6:return e.abrupt("return");case 7:if(this.core.utils.isUndefined(t)){e.next=15;break}if(!((s=this.core.utils.getViewListFromView(t)).length>0)){e.next=14;break}return e.next=12,n.play(s);case 12:e.next=15;break;case 14:n.stop();case 15:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"removeSystemAudioTrack",value:function(e){var r=this.systemAudioTrackList[e];r&&(r.stop(),this.log.info("".concat(e," system audio track stop")),delete this.systemAudioTrackList[e])}}]);var r,s,u,l,p,d,f,h,m,x,V,A,C,M,O,I,_,P,N}();return y(V,"Name","VideoMixer"),V}));
|