@hysc/meeting 10.7.1 → 10.7.3

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var ni=Object.defineProperty,li=Object.defineProperties;var ci=Object.getOwnPropertyDescriptors;var Xt=Object.getOwnPropertySymbols;var ui=Object.prototype.hasOwnProperty,di=Object.prototype.propertyIsEnumerable;var Yt=(s,e,t)=>e in s?ni(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,P=(s,e)=>{for(var t in e||(e={}))ui.call(e,t)&&Yt(s,t,e[t]);if(Xt)for(var t of Xt(e))di.call(e,t)&&Yt(s,t,e[t]);return s},ke=(s,e)=>li(s,ci(e));var c=(s,e,t)=>new Promise((r,i)=>{var o=l=>{try{n(t.next(l))}catch(u){i(u)}},a=l=>{try{n(t.throw(l))}catch(u){i(u)}},n=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,a);n((t=t.apply(s,e)).next())});import ds,{checkSystemSupport as ms,createStream as hs,enumAudioInputDevices as ps,enumAudioOutputDevices as gs,enumVideoDevices as fs,getPermissions as Ss}from"@hysc/core";var R=class extends Error{constructor(t,r,i,o){super();this.code=t,this.error=i,this.BoomErrorFlag=!0,this.eName=o,this.message=r}static instanceOf(t){return!!(t&&t.BoomErrorFlag)}getCode(){return this.code}};var Zt=1,mi=2,Kt=3,hi=4;var pi=function(){},js=/BRTC/.test(pi.toString())?Zt:Kt;function et(s,e,t,r){let i=[];return t&&i.push(t),r&&i.push(r),`[${new Date().toLocaleTimeString("chinese",{hour12:!1})}] <${s}> [${i.join("|")}] ${e}`}function gi(s,e,t,r=[]){r.unshift(et("DEBUG",s,e,t)),console.log(...r)}function d(s,e,t,r=[]){Array.isArray(r)||(r=[r]),r.unshift(et("INFO",s,e,t)),console.log(...r)}function I(s,e,t,r=[]){Array.isArray(r)||(r=[r]),r.unshift(et("WARN",s,e,t)),console.log(...r)}function p(s,e,t,r=[]){typeof r=="string"?r=[r]:Array.isArray(r)||(r=[JSON.stringify(r)]),r.unshift(et("ERROR",s,e,t)),console.log(...r)}var Fs={[Zt]:gi,[mi]:d,[Kt]:I,[hi]:p};import{BehaviorSubject as ji}from"rxjs";var er="undefined";var fi=typeof window!==er?window:void 0;var $s=typeof global!==er?global:fi;var Js=Object.freeze({}),Qs=Object.freeze([]);var N="c";import{BehaviorSubject as vi}from"rxjs";var T="_screen",rt="screen-",it="xinhao_";var me="sub-message",he="user-sort-num-change",pe="bind-element",se="stream-connect-error",O="raise-hand",ge="manual-subscription",fe="unsubscribe-stream",Se="change-is-guest",be="bind-big-element",oe="no-container",Ie="model-sort-num-change",ye="add-pull-user",Ee="set-volume",Me="add-audio-play",V="stream-play";import Si from"mitt";var B=class B{static getInstance(){return B.emitter||(B.emitter=Si()),B.emitter}};B.emitter=void 0,B.removeEmitter=()=>{var e,t,r,i,o,a,n,l,u,m,h,f,S,b,M;(e=B.emitter)==null||e.off(me),(t=B.emitter)==null||t.off(he),(r=B.emitter)==null||r.off(se),(i=B.emitter)==null||i.off(O),(o=B.emitter)==null||o.off(fe),(a=B.emitter)==null||a.off(ge),(n=B.emitter)==null||n.off(Se),(l=B.emitter)==null||l.off(pe),(u=B.emitter)==null||u.off(be),(m=B.emitter)==null||m.off(oe),(h=B.emitter)==null||h.off(Ie),(f=B.emitter)==null||f.off(ye),(S=B.emitter)==null||S.off(Ee),(b=B.emitter)==null||b.off(Me),(M=B.emitter)==null||M.off(V),B.emitter=void 0};var y=B;function tr(s){return Mt===2?yi(s):Ii(s)}function Ii(s){let e=30;return s.isSharing?(s.isMaster?e=0:s.isManager&&s.audioEnable&&s.videoEnable?e=1:s.isManager&&s.audioEnable?e=2:s.isManager&&s.videoEnable?e=3:s.isManager?e=4:s.isCommonUser?s.audioEnable&&s.videoEnable?e=9:s.audioEnable?e=10:s.videoEnable?e=11:e=12:s.audioEnable&&s.videoEnable?e=5:s.audioEnable?e=6:s.videoEnable?e=7:e=8,e):(s.isMaster?e=13:s.isLocal?e=14:s.isManager?s.audioEnable&&s.videoEnable?e=15:s.audioEnable?e=16:s.videoEnable?e=17:e=18:s.raiseHand?e=19:s.isCommonUser?s.isSignal?e=26:s.isCommonUser&&(s.audioEnable&&s.videoEnable?e=27:s.audioEnable?e=28:s.videoEnable?e=29:e=30):s.audioEnable&&s.videoEnable?e=22:s.audioEnable?e=23:s.videoEnable?e=24:e=25,e)}function yi(s){let e;return s.isToupingma?e=0:s.raiseHand?e=19:s.raiseAudioHands?e=1:s.raiseVideoHands?e=2:s.isLocal?e=3:s.isMaster&&s.audioEnable&&s.videoEnable?e=4:s.isManager&&s.audioEnable&&s.videoEnable?e=5:s.audioEnable&&s.videoEnable?e=6:s.isMaster&&s.audioEnable?e=7:s.isManager&&s.audioEnable?e=8:s.audioEnable?e=9:s.isMaster&&s.videoEnable?e=10:s.isManager&&s.videoEnable?e=11:s.videoEnable?e=12:s.isMaster?e=13:s.isManager?e=14:s.isCommonUser?e=16:s.isSignal?e=17:e=15,e}var rr="undefined";var _e="function";var Ei=typeof window!==rr?window:void 0;var io=typeof global!==rr?global:Ei;var so=Object.freeze({}),oo=Object.freeze([]),Ct="";function vt(s){return typeof s===_e}function Mi(s,e,t){return s.indexOf(e,t!==void 0?t:0)}function sr(s,e){return Mi(s,e)>=0}function or(s,e){return s!=null&&s.toString?s.toString():e!==void 0?e:Ct}function At(s){return vt(s)&&sr(or(s),"[native code]")}var Rt;typeof setImmediate===_e&&At(setImmediate)&&(Rt=setImmediate);typeof MessageChannel===_e&&At(MessageChannel)?Rt=function(s){let e=new MessageChannel;e.port1.onmessage=s,e.port2.postMessage(1)}:Rt=setTimeout;var ar=5*60*1e3;function Ut(s){let e=new Date(s),t=new Date,r=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,i=e.getDate()<10?"0"+e.getDate():e.getDate(),o=e.getHours()<10?"0"+e.getHours():e.getHours(),a=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes();return t.setHours(0,0,0,0)==e.setHours(0,0,0,0)?o+":"+a:r+"\u6708"+i+"\u65E5 "+o+":"+a}function He(s){return s.sort((e,t)=>e.sortNum===19&&t.sortNum===19?e.raiseHandTime-t.raiseHandTime:e.sortNum===t.sortNum?e.nickName.localeCompare(t.nickName):e.sortNum-t.sortNum)}function nr(s){return s.sort((e,t)=>e.sortNum!==t.sortNum?t.sortNum-e.sortNum:e.sortNum===t.sortNum?e.getUser().nickName.localeCompare(t.getUser().nickName):Number(e.getUser().isCommonUser)-Number(t.getUser().isCommonUser))}function We(s){return!Ge(s,"s")}function ot(s){return Ge(s,"a")}function Pt(s){return Ge(s,"v")}function at(s){return Ge(s,"m")}function nt(s){return Ge(s,"o")}function Ge(s,e){return s.toLowerCase().includes(e)}function Q(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|MicroMessenger/i.test(navigator.userAgent)}var ae=class{constructor(e,t=!1){this.audienceEnableSpeaking=!1;this.streamModels=new Map;this.sortNum=100;this.raiseVideoHands=!1;this.raiseAudioHands=!1;this.raiseHand=!1;this.isAudience=!1;this.isCommonUser=!1;this.inBackground=!1;this.isCalling=!1;this.raiseHandTime=0;this.signals=[];var i;this.userId=e.userId,this.userInfo=e.userInfo,this.nickName=e.nickname,this.isMaster=!!e.isMaster,this.isManager=!!e.isManager,this.isToupingma=!!e.isToupingma,this.isLocal=t,this.hasMultiple=!!e.hasMultiple,this.isCreate=!!e.isCreate,this.hasShare=!!e.hasShare,this.avatar=(i=e.userInfo)==null?void 0:i.avatar,this.permission=e.permission,this.raiseAudioHands=!!e.raiseAudioHands,this.raiseVideoHands=!!e.raiseVideoHands,this.raiseHand=!!e.raiseHand,this.isAudience=!!e.isAudience,this.isCommonUser=!!e.isCommonUser,this.inBackground=!!e.inBackground,this.isCalling=!!e.isCalling,this.signals=e.signals,e.permission&&(this.audienceEnableSpeaking=ot(e.permission.permission)),this.raiseHandTime=e.raiseHandTime||0;let r={operation:"none",user:this};this.watcher=new vi(r),this.updateSortNum(!1),this.customInfo=e.customInfo}get isWeb(){return!!(this.userInfo.pos&&(this.userInfo.pos.includes("web")||this.userInfo.pos.includes("pc")))}get isMobile(){return!!(this.userInfo.pos&&this.userInfo.pos.includes("web"))}setup(e,t,r,i){this.isLocal=!0,this.userId=e,this.userInfo=t,r?this.nickName=r:this.nickName=t.nickname,this.avatar=t.avatar,i&&i.signals&&(this.signals=i.signals),this.customInfo=i}getMainStreamModel(){return this.streamModels.get(this.userId)}get nickname(){return this.nickName}getShareStreamModel(){return this.streamModels.get(`${this.userId}${T}`)}get audioEnable(){let e=this.getMainStreamModel();return e?e._audio_enable:!1}get isMixer(){return this.userId.includes("-mixer-")}get videoEnable(){let e=this.getMainStreamModel();return e?e._video_enable:!1}get isSharing(){let e=!1;for(let t of this.streamModels.values())if(t.isShare){e=!0;break}return e}get isSignal(){var e;return!!((e=this.userId)!=null&&e.startsWith(it))}checkLocalHasMaster(){return this.isMaster||this.isManager}addStream(e,t){this.streamModels.set(e,t),this.watcher.next({operation:"changeShare",user:this})}removeStream(e){this.streamModels.delete(e),e.includes(T)&&(d("\u5220\u9664\u7684\u662F\u5171\u4EAB\u5C4F\u5E55\u7684\u6D41:","","",["streamId =>",e]),setTimeout(()=>{this.watcher.next({operation:"changeShare",user:this})},400))}getID(){return this.userId}getNickName(){return this.nickName}getUserInfo(){return this.userInfo}getStreams(){return this.streamModels}updateUserInfo(e,t={},r){var u,m;let i=(u=t==null?void 0:t.params)==null?void 0:u.customInfo,o=(i==null?void 0:i.updateKeys)||[];this.customInfo=i;let a=!1,n="none";if(d("updateUserInfo =>","updateUser",e.userId,["updateKeys",o.toString(),"permission",(m=e.permission)==null?void 0:m.permission,"isMaster =>",this.isMaster,"isManager =>",this.isManager]),this.nickName!==e.nickname&&(n="changeNickName"),!this.isMaster&&this.isManager&&!e.permission.getManage()&&(n="removeManager",this.isManager=!1),!this.isMaster&&!this.isManager&&e.permission.getManage()&&o.indexOf("changeMaster")==-1&&(n="getManager",this.isManager=!0),e.userinfo.pos)this.userInfo=e.userinfo;else{let h=this.userInfo.pos;this.userInfo=e.userinfo,this.userInfo.pos=h}(o.includes("changeMaster")||o.includes("permission"))&&(e.permission=t.getPermission()),o.includes("raiseHandsAudio")&&(this.raiseAudioHands=i.raiseHandsAudio,n="raiseHandsAudio",y.emitter.emit(O,{status:"raiseHandsAudio",user:this}),a=!0),o.includes("raiseHandsVideo")&&(this.raiseVideoHands=i.raiseHandsVideo,n="raiseHandsVideo",y.emitter.emit(O,{status:"raiseHandsVideo",user:this}),a=!0),o.includes("raiseHand")&&(this.raiseHand=i.raiseHand,this.raiseHandTime=i.raiseHandTime,n="raiseHand",y.emitter.emit(O,{status:"raiseHand",user:this}),a=!0),r.conferenceMode!==1&&this.isAudience&&o.includes("permission")&&((i==null?void 0:i.permission.indexOf("A"))!==-1&&(r.enableAudienceSpeakingWatcher.next(!0),this.audienceEnableSpeaking=!0,n="audienceEnableSpeaking",this.isLocal&&r.bmLiveVM.handleAudienceEnable()),(i==null?void 0:i.permission.indexOf("A"))===-1&&(r.enableAudienceSpeakingWatcher.next(!1),this.audienceEnableSpeaking=!1,n="audienceEnableSpeaking",this.isLocal&&r.bmLiveVM.handleAudienceDisable())),o.includes("inBackground")&&(n="inBackground",this.inBackground=i.inBackground),o.includes("isCalling")&&(n="isCalling",this.isCalling=i.isCalling),this.nickName=e.nickname,this.permission=e.permission;let l=!this.isCommonUser;this.isCommonUser=!e.permission.getSubscribe(),l!==!this.isCommonUser&&(d(`\u8EAB\u4EFD\u6709\u53D1\u751F\u8FC7\u53D8\u5316\uFF0C\u4ECE${l?"\u5609\u5BBE":"\u666E\u901A\u53C2\u4F1A\u8005"} => ${this.isCommonUser?"\u666E\u901A\u53C2\u4F1A\u8005":"\u5609\u5BBE"}`),y.emitter.emit(Se,{user:this,isGuest:!this.isCommonUser,preIsGuest:l})),n&&this.watcher.next({operation:n,user:this}),(!a||a&&!this.isLocal)&&this.updateSortNum(!0)}hasManager(){return this.isManager||this.isMaster}getNicknameSuffix(){let e="";return this.isLocal&&this.isMaster?e="(\u6211\u3001\u4E3B\u6301\u4EBA)":this.isLocal&&this.isManager?e="(\u6211\u3001\u8054\u5E2D\u4E3B\u6301\u4EBA)":this.isLocal?e="(\u6211)":this.isMaster?e="(\u4E3B\u6301\u4EBA)":this.isManager?e="(\u8054\u5E2D\u4E3B\u6301\u4EBA)":this.isSharing&&!this.isToupingma?e="\u7684\u5171\u4EAB\u5C4F\u5E55":this.isSharing&&this.isToupingma&&(e="(\u4EC5\u5171\u4EAB\u5C4F\u5E55)"),e}updateSortNum(e=!0,t=!1){let r=tr(this);this.setSortNum(r,e,t)}setSortNum(e,t,r){this.sortNum===e&&!t||(this.sortNum=e,t&&y.emitter.emit(he,{isCommon:this.isCommonUser,isAudience:this.isAudience,shouldDelay:r}))}};import{BehaviorSubject as Ce}from"rxjs";function H(s){return new Promise(e=>setTimeout(e,s))}import{debounce as lt}from"lodash-es";var Be=["-mixer-","-rtmpmixer-","record#","robot_","stt_"],ve=500,ct="RWPSAVMO,RWPSAVM,RWPSAV,RWPSA",je=class s{constructor(e,t,r){this.userList=new Map;this.audiencesList=new Map;this.signalList=new Map;this.commonUserList=new Map;this.userListWatcher=new Ce(Array.from(this.userList.values()));this.audiencesListWatcher=new Ce(Array.from(this.audiencesList.values()));this.commonUserListWatcher=new Ce(Array.from(this.commonUserList.values()));this.signalListWatcher=new Ce(Array.from(this.signalList.values()));this.masterUserWatcher=new Ce(null);this.getForceUserWatcher=new Ce(!1);this.commTimer=200;this.addBCUser=(e,t=!1,r=!1)=>{var a;let i=this.addUser(e);if(this.room.isWorkShop&&!ot(e.permission.permission)){console.log("\u7814\u8BA8\u4F1A, \u89C2\u4F17\u5148\u4E0D\u521B\u5EFA\u7A97\u53E3");return}this.room.bmStreamVm.streamModels.get(e.userId)||this.room.bmStreamVm.createStreamModel(i);{let n=this.room.bmStreamVm.streamModels.get(e.userId);n&&(e.stream.size?e.stream.forEach(l=>c(this,null,function*(){var f,S,b;let{video_enable:u,audio_enable:m,customInfo:h}=l;if(l.screen){i.hasShare=!0,this.room.bmStreamVm.shareBloudStateMap.set(e.userId,{audio:m,video:u,customInfo:h,userId:e.userId,streamId:l.getID(),isScreen:!0});let M={id:n.userId,isScreen:!0,isWeb:n.isWeb};t?yield(f=this.room)==null?void 0:f.processUser(M):(S=this.room)==null||S.addUser2Queue(M)}else if(n&&(n.updateBloudStream({video:u,audio:m,isScreen:l.screen,customInfo:h},this.room.bmStreamVm),t)){let M={id:n.userId,isScreen:!1,isWeb:n.isWeb};(b=this.room)==null||b.processUser(M)}})):(n.bloudStream&&n.updateBloudStream(void 0,this.room.bmStreamVm),(a=this.room)==null||a.bmStreamVm.removeShareStreamModelByUId(e.userId)))}return i&&i.isMaster&&this.masterUserWatcher.next(i),i==null||i.updateSortNum(r),i};this.updateAllSort=()=>{this.updateUserSort(),this.updateCommonUserSort(),this.updateAudienceUserSort(),this.updateSignalUserSort()};this.updateSortByType=e=>{var t,r;(t=this.room)!=null&&t.isSingleColumns||e.isCommon?(r=this.room)!=null&&r.isBig&&e.shouldDelay?this.updateDelayCommonUserSort():this.updateCommonUserSort():(e.isAudience?this.updateAudienceUserSort():this.updateUserSort(),this.updateSignalUserSort())};this.updateUserSort=lt(()=>{let e=this.sortUsers();this.userListWatcher.next(s.filterUsers(e))},200,{maxWait:1e3});this.updateCommonUserSort=lt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},this.commTimer,{maxWait:12*1e3});this.updateDelayCommonUserSort=lt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},120*1e3,{maxWait:120*1e3});this.updateAudienceUserSort=lt(()=>{let e=this.sortAudiences();this.audiencesListWatcher.next(e)},200,{maxWait:1e3});this.updateSignalUserSort=()=>{let e=this.sortSignalUsers();this.signalListWatcher.next(e)};this.transBloudUsers=(e,t="",r=!1,i=0)=>c(this,null,function*(){let o=new Map;yield this.getAllUsers(e,o,t,r).catch(()=>{if(i<3){p("get bloud user error, retry"),i+=1,this.transBloudUsers(e,t,r,i);return}else{p("get current page of bloud users after 10 times final failed","","",[" page ",e," permission ",t]);return}}),yield this.initUserList(o),o.clear();let a=[];for(let n of this.userList.values())(n.raiseVideoHands||n.raiseAudioHands||n.raiseHand)&&a.push(n);for(let n of this.commonUserList.values())(n.raiseVideoHands||n.raiseAudioHands||n.raiseHand)&&a.push(n);for(let n of this.commonUserList.values())(n.raiseVideoHands||n.raiseAudioHands)&&a.push(n);this.room.roomInfo.setRaiseHandsList(a),this.updateAllSort(),this.room.bmStreamVm.updateModelSort()});this.boomCore=e,this.localUser=t,this.room=r,y.emitter||p("init boom emitter error"),y.emitter.on(Se,this.handleUserRoleChange.bind(this)),y.emitter.on(he,this.updateSortByType)}handleUserRoleChange(e){return c(this,null,function*(){var n,l,u;let{user:t,isGuest:r,preIsGuest:i}=e,o=(n=this.room)==null?void 0:n.roomInfo.isBigRoom;if(d("handleUserRoleChange","",t.userId,["isGuest =>",r,"preIsGuest =>",i,"isBigRoom =>",o]),((l=this.room)==null?void 0:l.userListColumns)===1||(i?this.userList.delete(t.userId):this.commonUserList.delete(t.userId),r?this.userList.set(t.userId,t):this.commonUserList.set(t.userId,t)),o)if(r)t.isLocal&&(yield this.initUsers());else{let m=(u=this.room)==null?void 0:u.getLocalParticipant().isCommonUser;if(t.isLocal&&(this.handleUnSubCommonUser(),this.handleCommonUserChange(),this.commonUserList.set(t.userId,t)),m){let h=t.getMainStreamModel();h&&h.unSubscribeStream(),t.isLocal||this.commonUserList.delete(t.userId)}}this.updateAllSort()})}addUser(e){var i;let t=this.getUser(e.userId);if(t)return d("\u8BE5\u7528\u6237\u5DF2\u7ECF\u52A0\u5165\u623F\u95F4",N,e.userId),this.updateUser(t,e),t;let r;return this.boomCore.userId==e.userId?(this.updateUser(this.localUser,e),r=this.localUser):r=this.toBMUser(e),((i=this.room)==null?void 0:i.userListColumns)===1?this.commonUserList.set(r.userId,r):r.isAudience?this.audiencesList.set(r.userId,r):r.isSignal?this.signalList.set(r.userId,r):r.isCommonUser?this.commonUserList.set(r.userId,r):this.userList.set(r.userId,r),r}removeUser(e){let t=this.userList.delete(e);return t||(t=this.signalList.delete(e)),t||(t=this.audiencesList.delete(e)),t||(t=this.commonUserList.delete(e)),t||I("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, \u79FB\u9664\u65E0\u6548",N,e),t}videoEnable(e){let t=this.getUser(e);if(t)return t.videoEnable;throw new R(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}audioEnable(e){let t=this.getUser(e);if(t)return t.audioEnable;throw new R(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}checkIsMaster(e){if(!e)return!1;let t=this.boomCore.getMaster();return t?t===e:!1}checkLocalHasMaster(){return this.localUser.isMaster||this.localUser.isManager}checkUserHasMaster(e){let t=this.userList.get(e);return t?t.permission.getManage():!1}getUser(e){let t;return e!=null&&e.startsWith(it)?t=this.signalList.get(e):t=this.userList.get(e),t||(t=this.commonUserList.get(e)),t||(t=this.audiencesList.get(e)),t}getAllUsers(e,t,r="",i=!1){return c(this,null,function*(){let o;if(i){let{users:a,total:n}=yield this.boomCore.getUsersList(e,r,ve);o=a}else{let{users:a,total:n}=yield this.boomCore.getUsers(e,r,ve);o=a}o.forEach(a=>{t.set(a.userId,a)})})}initUserList(e){return c(this,null,function*(){var r,i;let t=e.get(this.localUser.userId);if(t){let o=this.addUser(t);if(!((r=this.room)!=null&&r.bmStreamVm.getStreamModelByUId(t.userId))){let a=this.getUser(t.userId);a?(i=this.room)==null||i.bmStreamVm.createStreamModel(a):p("there is no local streamModel exits, and create failed!!!")}o!=null&&o.isMaster&&this.masterUserWatcher.next(o)}e.delete(this.localUser.userId),e&&e.size>0&&this.addBcUsersMap(e)})}addBcUsersMap(e,t=!1,r=!1){e.forEach(i=>{this.addBCUser(i,t,r)})}updateMaster(e,t,r){let i=this.getUser(e);i&&(i.isManager&&(i.isManager=!1),i.isMaster=!0,i.updateSortNum());let o=this.getUser(t);return o&&(o.isMaster=!1,r&&(o.isManager=!0),o.updateSortNum()),!i&&!o&&p("\u672A\u627E\u5230\u8BE5\u7528\u6237, updateMaster\u672A\u751F\u6548",N,e,["masterId => ",e,"oldMasterId => ",t]),{master:i,oldMaster:o}}managerChangeToGuest(e){let t=this.getUser(e);return t?t.isManager?(t.permission.setManage(!1),t.permission.setSubscribe(!0),this.boomCore.updateUser(e,{customInfo:{permission:t.permission.get()}}),t.watcher.next({operation:"getGuest",user:t}),this.updateAllSort()):p("\u8BE5\u7528\u6237\u4E0D\u662F\u7BA1\u7406\u5458\uFF0C\u65E0\u6CD5\u8BBE\u7F6E\u4E3A\u5609\u5BBE",N,e):p("\u672A\u627E\u5230\u8BE5\u7528\u6237, managerChangeToGuest\u672A\u751F\u6548",N,e),t}updateManager(e,t,r=!0){let i=this.getUser(e);return i?(i.permission.setManage(t),r?i.permission.setSubscribe(!0):i.permission.setSubscribe(t),this.boomCore.updateUser(e,{customInfo:{permission:i.permission.get()}}),i.watcher.next({operation:t?"getManager":"removeManager",user:i}),this.updateAllSort()):p("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, updateManager\u672A\u751F\u6548",N,e),i}getLocalUser(){return this.localUser}updateUser(e,t){var C,E,L,W,G,j,F,$;let r=this.checkIsMaster(t.userId),i=(((C=t.permission)==null?void 0:C.getManage())||at((E=t.permission)==null?void 0:E.permission))&&!((L=t.permission)!=null&&L.getOwn()||nt((W=t.permission)==null?void 0:W.permission)),o="none",a=e.isMaster;e.isManager!==i&&(i?o="getManager":o="removeManager"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},10),a!==r&&(r?o="getMaster":o="removeMaster"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},100);let l=e.raiseHand,u=t.customInfo.raiseHand;l!==u&&(!u&&l&&this.room.roomInfo.removeSimpleRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHand",user:e})},300));let m=e.raiseVideoHands,h=t.customInfo.raiseHandsVideo;m!==h&&(!h&&m&&this.room.roomInfo.removeVideoRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsVideo",user:e})},300));let f=e.raiseAudioHands,S=t.customInfo.raiseHandsAudio;f!==S&&(!S&&f&&this.room.roomInfo.removeRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsAudio",user:e})},300));let b=e.nickname,M=t.nickname;if(b!==M&&setTimeout(()=>{e.watcher.next({operation:"changeNickName",user:e})},300),e.isAudience){let ee=e.audienceEnableSpeaking,te=t.permission.getAudio();ee!==te&&setTimeout(()=>{e.watcher.next({operation:"audienceEnableSpeaking",user:e})},300)}e.userInfo=t.userinfo,e.nickName=t.nickname,e.userId=t.userId,e.permission=t.permission,e.avatar=t.userinfo.avatar,e.isToupingma=t.userinfo.pos.includes("_toupingma"),e.raiseHand=u,e.isMaster=r,e.isCreate=this.boomCore.getCreator()===t.userId,e.isAudience=!t.permission.getVideo(),e.isCommonUser=!t.permission.getSubscribe(),e.isManager=i,e.inBackground=!!((G=t==null?void 0:t.customInfo)!=null&&G.inBackground),e.isCalling=!!((j=t==null?void 0:t.customInfo)!=null&&j.isCalling),(F=t.customInfo)!=null&&F.signals&&(e.signals=($=t==null?void 0:t.customInfo)==null?void 0:$.signals),e.isAudience&&(e.audienceEnableSpeaking=t.permission.getAudio()),e.updateSortNum()}updateLocalUserPermission(e){let t=this.getLocalUser();t.isMaster=nt(e),t.isManager=!nt(e)&&at(e),t.isCommonUser=We(e),t.isAudience=!Pt(e),t.watcher.next({operation:"none",user:t})}toBMUser(e){var i,o;let t={};t.userInfo=e.userinfo,t.nickname=e.nickname,t.userId=e.userId,t.streamModels=[],t.permission=e.permission,t.stream=e.stream,t.isToupingma=!!(e.userinfo.pos&&e.userinfo.pos.includes("_toupingma")),t.isMaster=this.checkIsMaster(t.userId),t.isCommonUser=!e.permission.getSubscribe()||We(e.permission.permission),t.isAudience=!Pt(e.permission.permission),t.raiseAudioHands=e.customInfo.raiseHandsAudio,t.raiseVideoHands=e.customInfo.raiseHandsVideo,t.raiseHand=e.customInfo.raiseHand,t.raiseHandTime=e.customInfo.raiseHandTime,t.inBackground=e.customInfo.inBackground,t.isCalling=e.customInfo.isCalling,t.customInfo=e.customInfo,t.isCreate=this.boomCore.getCreator()===e.userId,t.signals=e.customInfo.signals;let r=this.boomCore.getLocalParticipant();if(!r)throw new R(1001,"BCUserVM addUser\u65F6\u672A\u627E\u5230\u672C\u5730\u7528\u6237");return r.getID()==t.userId&&(t.isLocal=!0),((i=t.permission)!=null&&i.getManage()||at((o=t.permission)==null?void 0:o.permission))&&!t.isMaster&&(t.isManager=!0),new ae(t,t.isLocal)}sortUsers(){return He(Array.from(this.userList.values()))}sortAudiences(){return He(Array.from(this.audiencesList.values()))}sortCommonUsers(){return He(Array.from(this.commonUserList.values()))}sortSignalUsers(){return He(Array.from(this.signalList.values()))}static filterUsers(e){return e.filter(t=>!s.filterUser(t.userId))}static filterUser(e){return Be.some(t=>e.includes(t))}initUsers(){return c(this,null,function*(){var l;let e=yield this.getTotalUserNumber();d(`initUsers total users num: ${e}`);let t=Math.ceil(e/ve),r=0,i=this.localUser.isCommonUser,o=[],a=u=>c(this,null,function*(){u<t&&(yield this.transBloudUsers(u-1))}),n=u=>c(this,null,function*(){for(let m of u)yield m(),yield H(50)});if(i&&((l=this.room)!=null&&l.isBig))this.commonUserList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ct,!0);else if(this.room.conferenceMode===2)this.room.localIsAudience&&this.audiencesList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ct,!0);else{for(;r<t;)o.push(a.bind(null,r)),r+=1;n(o)}})}handleUnSubCommonUser(){this.commonUserList.forEach(e=>{let t=e.getMainStreamModel();t!=null&&t.hasPulled&&t.unSubscribeStream()})}handleCommonUserChange(){let e=new Map;this.room.bmStreamVm.streamModels.forEach(t=>{(!t.getUser().isCommonUser||t.isLocal)&&e.set(t.userId,t)}),this.room.bmStreamVm.streamModels=e,this.commonUserList.clear()}getUsers(e,t,r="RWPAV",i="array"){return c(this,null,function*(){let{users:o,total:a}=yield this.boomCore.getUsers(e,r,t);if(i==="map"){let n=new Map;return o.forEach(l=>{if(s.filterUser(l.userId))return;let u=this.toBMUser(l);n.set(u.userId,u),u.isAudience&&this.audiencesList.set(u.userId,u)}),{userList:n,total:a}}else{let n=[];return o.forEach(l=>{if(s.filterUser(l.userId))return;let u=this.toBMUser(l);n.push(u),u.isAudience&&this.audiencesList.set(u.userId,u)}),{userList:n,total:a}}})}getAudiencesList(e,t,r="array"){return c(this,null,function*(){let{users:i,total:o}=yield this.boomCore.getUsers(e,"RWPS",t,r),{users:a,total:n}=yield this.boomCore.getUsers(e,"RWPSA",t,r);if(e===-1&&this.audiencesList.clear(),r==="map"){let l=new Map;return a.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.set(m.userId,m),this.audiencesList.set(m.userId,m)}),i.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.set(m.userId,m),this.audiencesList.set(m.userId,m)}),this.updateAudienceUserSort(),{userList:l,total:o}}else{let l=[];return a.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.push(m),this.audiencesList.set(m.userId,m)}),i.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.push(m),this.audiencesList.set(m.userId,m)}),this.updateAudienceUserSort(),{userList:l,total:o+n}}})}getUsersList(e,t,r="",i=!1){return c(this,null,function*(){var u,m;let{users:o,total:a,pageIndex:n}=yield this.boomCore.getUsersList(e,r,t,i),l=[];return o.forEach(h=>{if(s.filterUser(h.userId))return;let f=this.toBMUser(h);l.push(f)}),i&&((u=this.room)==null?void 0:u.roomInfo.totalWaitRoomUserWatcher.value)!==a&&((m=this.room)==null||m.roomInfo.totalWaitRoomUserWatcher.next(a)),{userList:l,total:a,pageIndex:n}})}getTotalUserNumber(){return c(this,null,function*(){let e=()=>c(this,null,function*(){let{total:r}=yield this.boomCore.getUsers(0,"",1);return r}),t=r=>{e().then(i=>{r(i)}).catch(i=>{p("getTotalUserNumber error","","",[JSON.stringify(i)]),t(r)})};return new Promise((r,i)=>c(this,null,function*(){t(r)}))})}clearUsers(){this.userList.clear(),this.commonUserList.clear(),this.audiencesList.clear(),this.signalList.clear()}searchUsers(e,t){return c(this,null,function*(){try{let{users:r}=yield this.boomCore.searchUsers(e,t,!1),i=[],o=[],a=[];return r.forEach(n=>{let l=this.userList.get(n.userId);if(l){i.push(l);return}let u=this.commonUserList.get(n.userId);if(u){o.push(u);return}let m=this.audiencesList.get(n.userId);if(m)a.push(m);else{let h=this.toBMUser(n);a.push(h)}}),{userList:i,commonUserList:o,audienceList:a}}catch(r){return Promise.reject(new R(1e3,"boomCore.searchUsers\u53D1\u751F\u9519\u8BEF:"+(r==null?void 0:r.message)))}})}searchWaitRoomUsers(e,t){return c(this,null,function*(){try{let{users:r}=yield this.boomCore.searchUsers(e,t,!0),i=[];return r.forEach(o=>{let a=this.toBMUser(o);i.push(a)}),i}catch(r){return Promise.reject(new R(1e3,"search wait room users error"))}})}};var x=class{constructor(e){this.isMeetingNotice=!1;this.isEmoji=!1;this.userId=e.userId,this.message=e.message,this.role=e.role,this.isLocal=e.isLocal,this.avatar=e.avatar,this.nickName=e.nickName,this.to=e.to,this.isDanger=e.isDanger,this.seq=e.seq,this.failed=e.failed;let t=!1;e.isMeetingNotice&&(t=!0),this.isMeetingNotice=t,e.sendTime?(this.timeStamp=e.sendTime,this.time=Ut(this.timeStamp)):(this.timeStamp=new Date().getTime(),this.time=Ut(this.timeStamp));let r=this.message.match(/^\[(.*?)\]$/);this.isEmoji=r!==null&&r[0].length<=20&&r[0].length>=4}};import{debounce as Ti}from"lodash-es";function q(s){let e=s.getStreamId();return s.getUserId().toString().endsWith(T)||e.startsWith(rt)||s.getType&&s.getType()==="assist"}import{debounce as Ai}from"lodash-es";import{BMShareStreamReconnectFailed as Ri,BMShareStreamReconnectSuccess as Ui,BMStreamReconnectSuccess as Pi}from"@hysc/utils";import{BrtcEvents as cr,BloudEvents as Nt}from"@hysc/utils";function ur(s){var t,r;let e=s.getLocalStreamModel();if(e&&!(e!=null&&e.stream))s.bloudStream&&(d("brtc \u5DF2\u7ECF\u6CA1\u6709\u6D41\u4E86\uFF0Cbloud \u7684\u6D41\u8981\u53D6\u6D88\u6389"),s.bloudStream.unpublish(),e.updateBloudStream(void 0,s),s.bloudStream=null);else if(e&&e.stream){d("brtc \u6D41\u5DF2\u7ECF\u91CD\u63A8\u4E0A\u53BB\u4E86\uFF0Cbloud\u8981\u91CD\u65B0\u53D1\u63A8\u6D41\u7684\u903B\u8F91");let i=e.stream.getAudioOn(),o=e.stream.getVideoOn();s.publishBloudStream(i,o).then(()=>{var a;d("brtc stream repub success bloud repub success, notify reconnect success"),s.localStreamConnectErrorWatcher.next(Pi(i,o)),(a=e.player)==null||a.destroy(),e.player=null,e.isInBig&&e.playInBig()})}if(s.localIsShare){d("brtc has share stream, and bloud need to republish share stream");let i=(t=s.room)==null?void 0:t.boomCore.shareScreenStream;if(i){let o=i.getAudioOn(),a=i.getVideoOn();try{(r=s.room)==null||r.boomCore.createAndPubBloudShareStream(o,a)}catch(n){p("bloud \u5171\u4EAB\u5C4F\u5E55\u6D41\uFF0C\u65AD\u7F51\u91CD\u8FDE\u91CD\u63A8\u6D41\u5931\u8D25")}}}}var le=Ai(s=>{if(s.networkState.bloud&&s.networkState.brtc)try{s.streamQueue.restart()}catch(e){p("streamQueue restart error",JSON.stringify(e))}},300);function dr(s,e,t,r){let i=s.stream;if(d("\u672C\u5730\u63A8\u6D41","\u672C\u5730\u63A8\u6D41",i.getUserId()),i){let o=e.getLocalStreamModel();o&&e.updateStreamModel(o,i),r[cr.STREAM_PUBLISHED].next({published:!0,model:o}),t.conferenceMode===1&&t.getLocalParticipant().isAudience&&e.getStreamModels().forEach(n=>{n.sendMessage2Room()})}else r[cr.STREAM_PUBLISHED].next({published:!1})}function mr(s,e,t){d("bloud publish stream"),wt(s,e,!0),t[Nt.STREAM_PUBLISHED].next(s)}function wt(s,e,t=!1){var a,n,l;d("bloud stream update","","",[JSON.stringify(s)]);let r=s.userId,i=s.isScreen,o=e.streamModels.get(r);if(o)if(!i)o.updateBloudStream(s,e,t),o.getUser().updateSortNum();else{e.shareBloudStateMap.set(r,s);let u=(a=e.room)==null?void 0:a.userVM.getUser(r);u&&(u.hasShare=!0);let m={id:r,isWeb:o.isWeb,isScreen:i};(n=e.room)==null||n.addUser2Queue(m)}else{I("bloud stream update, but can not get streamModel","",r);let u=(l=e.room)==null?void 0:l.userVM.getUser(r);if(!u){p("bloud stream update, but can not get user","",r);return}e.createStreamModel(u).updateBloudStream({audio:s.audio,video:s.video,isScreen:s.isScreen},e)}}function hr(s,e,t){d("bloud unpublish stream","","",[JSON.stringify(s)]),Ni(s,e),t[Nt.STREAM_REMOVED].next(s)}function pr(s,e,t){d("bloud stream update","","",[JSON.stringify(s)]);let r=s.streamId,i=s.userId,o=s.params.customInfo,a;r.includes("_screen")?a=e.shareStreamModels.get(i):a=e.streamModels.get(i),a?a.updateBloudCustomInfo(o):p("bloud stream update, but can not get streamModel","",i,["streamId =>",r]),t[Nt.UPDATE_STREAM].next(s)}function Ni(s,e){var i,o,a,n;let t=s.userId;if(s.isScreen){let l=e.shareStreamModels.get(t),u=(a=e.room)==null?void 0:a.userVM.getUser(t);if(u&&(u.hasShare=!1),l){let m=l.stream;m?(m.destroy(),e.remoteStreamUnpublished(m)):e.removeShareStreamModelByUId(t);let h={id:t,isWeb:l.isWeb,isScreen:!0};(n=e.room)==null||n.streamQueue.removeUser(h)}else I("bloud user unpublish share stream but can not get streamModel","",t)}else{let l=e.streamModels.get(t);if(l){l.updateBloudStream(void 0,e);let u=l.stream;u&&((i=e.room.audioPlayer)==null||i.removeStream(u),e.remoteStreamUnpublished(u),u.destroy());let m={id:t,isWeb:l.isWeb,isScreen:!1};(o=e.room)==null||o.streamQueue.removeUser(m)}else I("bloud user unpublish stream but can not get streamModel","",t)}}function ut(s,e){setTimeout(()=>c(this,null,function*(){d("handle republish share stream");try{let t=s.boomCore.shareScreenStream;if(t){let r=t.getAudioOn(),i=t.getVideoOn();if(yield s.boomCore.shareBrtcClient.publish(t),yield s.boomCore.createAndPubBloudShareStream(r,i),Object.keys(e.localShareCustomStats).length){let o=e.localModel.userId;yield e.updateBloudStreamCustomStats(o,`${o}_screen`,e.localShareCustomStats)}d("handle republish share stream success"),e.localShareError.next(Ui())}else I("no share stream exist, unpublish share stream, to prevent share stream state error"),e.toggleShareScreen(!1,void 0)}catch(t){p("handle republish share stream failed , now unpublish"),e.localShareError.next(Ri()),yield e.toggleShareScreen(!1,void 0)}}),1e3)}import{BloudEvents as z,BrtcEvents as Sr}from"@hysc/utils";function br(s,e,t){let r=s.permission,i=s.total;r&&t.updateLocalUserPermission(r),e.isInWaitRoom=s.joinwait;let o=s.waitroom;e.roomInfo.isOpenWaitRoom.next(o),e.roomInfo.totalUserWatcher.next(i);let a=s.audiooff,n=s.selfopenaudio;(a!==e.roomInfo.audioOff||n!==e.roomInfo.selfopenaudio)&&a!=null&&n!=null&&e.roomInfo.setAudioOff(a,n)}function dt(s,e,t,r,i=!0){return c(this,null,function*(){var o;d("room-connected",e.getLocalParticipant().userId,"room-connected",["roomId =>",e.roomInfo.roomID," local permission => ",s.permission]),e.forceId=(o=s.customStats.forceOn)==null?void 0:o.user,yr(s,e),br(s,e,t),i&&r[z.ROOM_CONNECTED].next(s)})}function mt(s){return c(this,null,function*(){if(d("join ready init users"),!s.isInWaitRoom)if(s.forceId&&(yield s.getForceUser(s.forceId)),yield s.userVM.initUsers(),s.localUser.isAudience)s.queryBloudUsers([s.localUser.userId]);else{let{audioEnable:e,videoEnable:t}=s.roomInfo.originJoinRoomParams;if(s.localUser.userId.startsWith("robot_"))return;d(`join ready:audioEnable:${e}, videoEnable:${t}`),!e&&!t&&s.bmStreamVm.onlyBrtcPublish().catch(r=>{d("only-brtc-pub ","publish",s.localUser.userId,[r.message])})}})}function Ir(s,e){d("update-stats "," ","",["options => ",JSON.stringify(s.options)]),s.options&&s.options[0]=="audiooff"||s.options[1]=="selfopenaudio"?e.roomInfo.setAudioOff(s.room.audiooff,s.room.selfopenaudio):s.options&&s.options[0]=="lock"?e.roomInfo.setlock(s.room.lock):s.options&&s.options[0]=="waitroom"&&e.roomInfo.isOpenWaitRoom.next(s.stats.waitroom)}function yr(s,e){e.roomInfo.msgSeq=s.msgSeq,s.customStats&&e.roomInfo.initCustomStats(s.customStats)}function gr(s,e,t,r,i){var l;s.updateUser(e,t);let o=t.stream,a=r.streamModels.get(e.userId);if(a||p("bmUserVM\u4E2D\u5B58\u5728\u8BE5\u7528\u6237\uFF0C\u4F46\u662FbmStreamModelVM\u4E2D\u4E0D\u5B58\u5728\u8BE5\u7528\u6237\uFF0C\u4F5B\u4E86"),!o.size){a!=null&&a.bloudStream&&(a.updateBloudStream(void 0,r),i.streamQueue.removeUser({id:e.userId,isScreen:!1}),i.streamQueue.removeUser({id:e.userId,isScreen:!0}));let u=r.shareStreamModels.get(e.userId);if(u&&!u.isLocal){try{(l=u.stream)==null||l.destroy()}catch(m){}r.removeShareStreamModel(u)}}o.get(`${e.userId}_screen`)&&i.addUser2Queue({id:e.userId,isScreen:!0,isWeb:e.isWeb});let n=o.get(e.userId);n&&(a==null||a.updateBloudStream({audio:n.audio_enable,video:n.video_enable,isScreen:!1},r))}function fr(s,e,t,r){s.isSingleColumns?e.commonUserList.forEach(i=>{let o=t.get(i.userId);if(o){t.delete(i.userId),gr(e,i,o,r,s);return}e.commonUserList.delete(i.userId),r.streamModels.delete(i.userId),r.shareStreamModels.delete(i.userId)}):e.userList.forEach(i=>{let o=t.get(i.userId);if(o){gr(e,i,o,r,s),i.isCommonUser?e.userList.delete(i.userId):t.delete(i.userId);return}e.userList.delete(i.userId),r.streamModels.delete(i.userId),r.shareStreamModels.delete(i.userId)}),s.userVM.addBcUsersMap(t)}function wi(s,e,t,r){return c(this,null,function*(){let i=e.getLocalParticipant().userId,{users:o}=yield e.boomCore.queryUsers([i]),a=o.get(i);a&&t.updateUser(t.localUser,a);let n=e.getLocalParticipant().isCommonUser;if(e.isBig&&n){let{users:l}=yield e.boomCore.getUsersList(0,ct,500);fr(e,t,l,r)}else{let u=(yield e.userVM.getTotalUserNumber())/ve,m=new Map;for(let h=0;h<u;h++){let{users:f}=yield e.boomCore.getUsers(h-1,"",ve);f.forEach(S=>{m.set(S.userId,S)})}fr(e,t,m,r)}yr(s,e),e.userVM.updateAllSort(),e.bmStreamVm.updateModelSort()})}function Er(s,e,t){d("brtc room reconnecting"),e.networkState.brtc=!1,e.streamWSReconnectWatcher.next(!1),t[Sr.BRTC_ROOM_ROCONNECTING].next(s)}function Mr(s,e,t){d("brtc room reconnected"),e.networkState.brtc=!0,le(e),t[Sr.BRTC_ROOM_RECONNECTED].next(s)}function Cr(s,e,t){d("bloud room reconnecting"),e.networkState.bloud=!1,e.bloudWSReconnectWatcher.next(!1),t[z.RECONNECTING].next(s)}function ht(s,e,t){return c(this,null,function*(){e.hasSyncPermission?(d("bloud room reconnected"),e.bloudWSReconnectWatcher.next(!1),t[z.MOVE_USER_ROOM].next(null),yield e.syncRoom().then(()=>{e.hasSyncPermission=!0,t[z.ROOM_CONNECTED].next(s)}).catch(r=>{if(p("sync room error",JSON.stringify(r)),r.code===43){e.hasSyncPermission=!1,t[z.USER_REJOINED].next(r);return}else e.hasSyncPermission=!1,t[z.TIMEOUT].next(r)})):t[z.TIMEOUT].next(s)})}function vr(s,e,t,r,i){return c(this,null,function*(){d("bloud sync room completed"),br(s,t,e),yield wi(s,t,e,r),ur(r),t.networkState.bloud=!0,le(t),t.bloudWSReconnectWatcher.next(!0),i[z.ROOM_SYNCED].next(s)})}import{BloudEvents as xi}from"@hysc/utils";var{USER_REJOINED:Li,PARTICIPANT_JOINED:Oi,CHANGE_MASTER:Br,EVICTED:ki,UPDATE_USER:Di,PARTICIPANT_LEFT:Tt,CUSTOM_MESSAGE:_i,MOVE_USER_ROOM:Ar}=xi;function Rr(s,e,t,r,i,o){var f,S,b,M,C,E,L,W,G,j,F,$,ee,te,Te,xe,Le,re,ie,_,de,Oe;let a=(S=(f=s==null?void 0:s.participant)==null?void 0:f.params)==null?void 0:S.info.sync,n=s.mode,l=s.user.userId;d("\u7528\u6237\u5165\u4F1A","\u7528\u6237\u5165\u4F1A",s.user.userId,["sync => ",a,"mode =>",n]);let u=e.room.isBig&&t.streamModels.size>1e3,m=!1;if(a){let A=e.userList.get(s.user.userId);if(A||(A=e.commonUserList.get(s.user.userId)),A){A.inBackground!=!!((M=(b=s.user)==null?void 0:b.customInfo)!=null&&M.inBackground)&&(A.inBackground=!!((E=(C=s.user)==null?void 0:C.customInfo)!=null&&E.inBackground),A.watcher.next({operation:"inBackground",user:A})),A.isCalling!=!!((W=(L=s.user)==null?void 0:L.customInfo)!=null&&W.isCalling)&&(A.isCalling=!!((j=(G=s.user)==null?void 0:G.customInfo)!=null&&j.isCalling),A.watcher.next({operation:"isCalling",user:A}));return}}if((F=e.room)!=null&&F.isBig&&n===1&&(($=t.room)==null?void 0:$.conferenceMode)===1)if(We(s.user.permission.permission))e.userList.get(s.user.userId)&&(e.userList.delete(s.user.userId),t.streamModels.delete(s.user.userId),m=!0);else{let J=e.commonUserList.get(s.user.userId);(ee=e.room)!=null&&ee.isSingleColumns||J&&(e.commonUserList.delete(s.user.userId),t.streamModels.delete(s.user.userId),m=!0)}let h=e.addBCUser(s.user);if(h){h.inBackground!=!!((Te=(te=s.user)==null?void 0:te.customInfo)!=null&&Te.inBackground)&&(h.inBackground=!!((Le=(xe=s.user)==null?void 0:xe.customInfo)!=null&&Le.inBackground),h.watcher.next({operation:"inBackground",user:h})),h.isCalling!=!!((ie=(re=s.user)==null?void 0:re.customInfo)!=null&&ie.isCalling)&&(h.isCalling=!!((de=(_=s.user)==null?void 0:_.customInfo)!=null&&de.isCalling),h.watcher.next({operation:"inBackground",user:h}));let A=!1;if(Be.forEach(J=>{h!=null&&h.userId.includes(J)&&(A=!0)}),m?e.updateAllSort():(Oe=e.room)!=null&&Oe.isSingleColumns?e.updateCommonUserSort():h?h.isCommonUser?u?e.updateDelayCommonUserSort():e.updateCommonUserSort():h.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),!A){if(s.mode!==1){let J=new x({isMeetingNotice:!0,userId:h.userId,message:h.nickName+`\u52A0\u5165${r.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});i.addMessage(J,!0)}o[Oi].next({user:h,mode:n,data:s})}}}function Ur(s,e,t,r,i,o,a){var l;let n=s.userIds;d("bloud leave users","","",["userIds =>",n]),n.length&&(n.forEach(u=>{let m=xt(u,e,t,i);m&&Nr(m,o,a,r,!0,0)}),(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():e.updateAllSort(),i.updateModelSort())}function Pr(s,e,t,r,i,o,a){var m;d(`bloud participant left ===>${s.userId}, ${s.mode}`);let n=s.mode===1,l=s.userId,u=t.isBig&&i.streamModels.size>1e3;if(l){let h=xt(l,e,t,i);if((m=e.room)!=null&&m.isSingleColumns?e.updateCommonUserSort():h?h.isCommonUser?u?e.updateDelayCommonUserSort():e.updateCommonUserSort():h.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),i.updateModelSort(),n){r[Tt].next({user:h,mode:s.mode,data:s});return}h&&Nr(h,o,a,r,s.mode!==1,s.mode)}else I("participant-left\u89E6\u53D1=======>\u4F46\u662F\u8BE5\u7528\u6237\u4FE1\u606F\u4E0D\u5B58\u5728",N,null,[s.userId]),r[Tt].next({user:s.userId,mode:s.mode,data:s})}function Nr(s,e,t,r,i,o){let a=!1;if(Be.forEach(n=>{s!=null&&s.userId.includes(n)&&(a=!0)}),!a){if(i){let n=new x({isMeetingNotice:!0,userId:s.userId,message:(s==null?void 0:s.nickName)+`\u79BB\u5F00${e.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});t.addMessage(n,!0)}r[Tt].next({user:s,mode:o})}}function xt(s,e,t,r){let i=e.getUser(s);return e.removeUser(s),t.streamQueue.removeUser({id:s,isScreen:!1}),t.streamQueue.removeUser({id:s,isScreen:!0}),r.removeStreamModelByUId(s),r.removeShareStreamModelByUId(s),t.roomInfo.removeRaiseHandUser(s),t.roomInfo.removeVideoRaiseHandUser(s),t.roomInfo.removeSimpleRaiseHandUser(s),r.shareBloudStateMap.delete(s),i}function wr(s,e,t,r,i){d("changeMaster =>","changeMaster","",["master: => ",s.master,"oldMaster =>",s.oldMaster]);let o=s.master,a=s.oldMaster,n=s.isKeep;if(!o)I("change-master\u89E6\u53D1=======>\u4F46\u662F\u623F\u95F4\u5185\u627E\u4E0D\u5230master",N,null,o),r[Br].next(null);else{let l=e.updateMaster(o,a,n);l.master&&(l.master.watcher.next({operation:"getMaster",user:l.master}),t.userVM.masterUserWatcher.next(l.master)),l.oldMaster&&(l.oldMaster.watcher.next({operation:"removeMaster",user:l.oldMaster}),n&&l.oldMaster.watcher.next({operation:"getManager",user:l.oldMaster}));let u=i.getStreamModelByUId(a),m=i.getStreamModelByUId(o);u==null||u.updateSortNum(),m==null||m.updateSortNum(),r[Br].next({master:l.master,oldMaster:l.oldMaster,data:s})}}function Tr(s,e,t,r,i){var l;let o=s.userId,a=e.getUser(o);d("\u8E22\u51FA\u7528\u6237 => ","evict ",a==null?void 0:a.userId,["nickname => ",a==null?void 0:a.nickName]);let n=xt(o,e,r,t);(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():n?n.isCommonUser?e.updateCommonUserSort():n.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),i[ki].next(s)}function xr(s,e,t,r,i){var a;let o=(a=s.user)==null?void 0:a.userId;if(d("\u7528\u6237\u4FE1\u606F\u88AB\u6539\u53D8","",o),o){let n=e.getUser(o),l=r.getStreamModelByUId(o);n?n.updateUserInfo(s.user,s.participant,t):(console.warn("participant-update: bmUser is null"),t.queryBloudUsers([o],!0)),l&&l.updateSortNum(!0),i[Di].next({bmUser:n,params:s.participant.params})}}var Lt=Ti((s,e)=>{s[Li].next(e)},1e3);function Lr(s,e,t,r){return c(this,null,function*(){d("bloud move user room","","",[t]);let i=t.toWait;if(s.isInWaitRoom=i,i){s.handleResetOtherStreamStatus(),e.userList.clear(),e.userListWatcher.next([]),e.commonUserList.clear(),e.commonUserListWatcher.next([]),e.getForceUserWatcher.next(!1),s.bmStreamVm.streamModels.clear(),s.bmStreamVm.clearDetector(),s.bmStreamVm.speakerWatcher.next(null),r[_i].next(null),s.messageWatcher.next({type:"init",status:!1,isNotCancelRootReport:!1}),s.audioPlayer.destroy();let o=s.bmStreamVm.localModel;o&&s.bmStreamVm.streamModels.set(o.userId,o),s.bmStreamVm.streamModelsWatcher.next([]),s.bmStreamVm.shareStreamModels.clear(),s.bmStreamVm.shareStreamModelsWatcher.next([]),s.roomInfo.raiseHandsWatcher.next([]),s.roomInfo.raiseVideoHandsWatcher.next([]),s.roomInfo.raiseSimpleHandsWatcher.next([]),r[Ar].next(i),Object.values(s.observes).forEach(a=>{a.next(null)})}else{let{audiooff:o,selfopenaudio:a,lock:n}=t.info;n!==s.roomInfo.lock&&s.roomInfo.setlock(n),(o!==s.roomInfo.audioOff||a!==s.roomInfo.selfopenaudio)&&s.roomInfo.setAudioOff(o,a),yield dt(t.info,s,e,r,!0),yield mt(s),r[Ar].next(i)}})}import{BloudEvents as Ot}from"@hysc/utils";function kr(s,e,t,r){var o,a,n,l,u,m,h,f,S;let i=P({},s);if(i.message){if(i.message=typeof i.message=="string"?JSON.parse(i.message):i.message,d("new-message","","",[" method => ",i.message.method]),i.message.method==="send-talk"){let b=i.user===((o=e.getLocalUser())==null?void 0:o.userId),M=((n=(a=i.message)==null?void 0:a.params)==null?void 0:n.status)||"",C=(m=(u=(l=i.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.avatar,E=s.seq,L=new x({userId:i.user,message:M,isLocal:b,avatar:C,to:i.to,seq:E,nickName:(S=(f=(h=i.message)==null?void 0:h.params)==null?void 0:f.stream)==null?void 0:S.nickname,sendTime:new Date().getTime()});t.addMessage(L,!1)}r[Ot.SEND_MESSAGE].next(i)}}function Dr(s,e,t){var i,o,a,n,l,u,m,h,f,S,b,M,C;let r=P({},s);if(r.message)if(r.message=typeof r.message=="string"?JSON.parse(r.message):r.message,d("custom-message","","",[" method => ",r.message.method]),r.message.method=="video-force-change"){let E=r.message.params.status=="enabled";d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u6444\u50CF\u5934: ${E}`),e.messageWatcher.next({type:"video-force-change",status:E,fromUserId:r.user})}else if(r.message.method=="audio-force-change"){let E;r.message.params.status=="checkUserAudio"?E=r.message.params.status:E=r.message.params.status=="enabled",d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u9EA6\u514B\u98CE: ${E}`),e.messageWatcher.next({type:"audio-force-change",status:E,fromUserId:r.user,isNotCancelRootReport:(i=r.message.params)==null?void 0:i.isNotCancelRootReport})}else if(r.message.method==="raise-hands"){let E=r.message.params;Vi(E,e),e.raiseHandleRespWatcher.next(E)}else if(r.message.method==="give-like")(h=e.roomVM)==null||h.giveLikeList.push({userId:r.user,nickName:(n=(a=(o=r.message)==null?void 0:o.params)==null?void 0:a.stream)==null?void 0:n.nickname,time:new Date().getTime(),type:(m=(u=(l=r.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.type}),(S=e.roomVM)==null||S.giveLikeListWatcher.next((f=e.roomVM)==null?void 0:f.giveLikeList);else if(r.message.method==="resp-to-check-devices")(b=r.message)!=null&&b.params&&(r.message.params.fromUserId=r.user),t[Ot.CUSTOM_MESSAGE].next(r);else if(r.message.method==="usercount"){if(r.message.params){let E=(C=(M=r.message)==null?void 0:M.params)==null?void 0:C.total;E?(E=Number(E),E<0&&(I("\u670D\u52A1\u8FD4\u56DE\u7684usercount\u4E3A\u8D1F\u6570,"+E),E=0)):(I("\u670D\u52A1\u672A\u8FD4\u56DEusercount,"+E),E=0),e.roomInfo.totalUserWatcher.next(E)}}else if(r.message.method==="waitusercount"){if(r.message.params){let E=r.message.params.total;e.roomInfo.totalWaitRoomUserWatcher.next(E)}}else t[Ot.CUSTOM_MESSAGE].next(r)}function Vi(s,e){return c(this,null,function*(){let t=s.raiseInfo;if(s.raiseHandsType===4&&t){let r=e.userVM.getUser(t.userId);if(r||(d("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728,\u5F00\u59CB\u67E5\u8BE2",t.userId),yield e.queryBloudUsers([t.userId],!1,!1),r=e.userVM.audiencesList.get(t.userId)),!r){p("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728",t.userId);return}switch(t.type){case"raiseHandsAudio":r.raiseAudioHands=s.raiseHands;break;case"raiseHandsVideo":r.raiseVideoHands=s.raiseHands;break;case"raiseHand":r.raiseHand=s.raiseHands;break;default:break}y.emitter.emit(O,{status:t.type,user:r})}})}import{BloudEvents as Hi,BrtcEvents as kt}from"@hysc/utils";var pt=0;var gt=0,Fe=new Set;function Dt(s,e,t,r,i){return c(this,null,function*(){if(p("brtc error","brtc error","",[new Date().toLocaleTimeString(),JSON.stringify(s),s.getCode()]),s.getCode()===4002){e.BRTCConnectFailed=!0,e.networkState.brtc=!1,I("brtc \u4FE1\u4EE4\u901A\u9053\u9519\u8BEF\uFF0C\u9700\u8981\u91CD\u65B0\u8D70\u5165\u4F1A","brtc error",""),e.streamWSReconnectWatcher.next(!1);try{yield t.brtcClient.leave("room_close")}catch(a){p("brtc \u79BB\u4F1A\u5931\u8D25")}setTimeout(()=>c(this,null,function*(){e.handleResetOtherStreamStatus(),yield _r(t,e,i,s).catch(a=>{d("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25, \u5904\u7406\u4E00\u4E0B\u9000\u4F1A\u903B\u8F91","","",[JSON.stringify(a)]),i[kt.ERROR].next(s)})}),1e3)}else i[kt.ERROR].next(s)})}function _r(s,e,t,r){return c(this,null,function*(){return new Promise((i,o)=>{setTimeout(()=>{d("brtc\u91CD\u8FDE"),s.brtcClient.join(s.roomId,s.userId,s.brtcSig).then(()=>c(this,null,function*(){d("brtc\u65AD\u7F51\u91CD\u8FDE\u6210\u529F, \u91CD\u65B0\u5904\u7406\u62C9\u6D41\u548C\u63A8\u6D41"),e.networkState.brtc=!0,setTimeout(()=>{e.brtcNetEnableWatcher.next(!0)},2e3),le(e),e.BRTCConnectFailed=!1,pt=0,yield e.handleRePushSelf(),e.streamWSReconnectWatcher.next(!0),i(!0)})).catch(a=>{let n=a.getCode();d("\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[a,n]),pt<=10?(pt+=1,s.brtcClient.isJoinning=!1,setTimeout(()=>{_r(s,e,t,r)},2*1e3)):(p("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u9000\u4F1A"),pt=0,t[kt.ERROR].next(r),o(!1))})},7*1e3)})})}function _t(s){return c(this,null,function*(){return new Promise((e,t)=>{setTimeout(()=>{d("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE"),s.shareBrtcClient.join(s.roomId,s.userId,s.brtcSig).then(()=>{gt=0,e(!0)}).catch(r=>{let i=r.getCode();if(d("\u5171\u4EAB\u5C4F\u5E55\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[r,i]),gt<=3)gt+=1,_t(s);else throw p("\u5171\u4EAB\u5C4F\u5E55\u7528\u6237\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55"),gt=0,new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE\u5931\u8D25")})},7*1e3)})})}function Vr(s,e,t,r,i){return c(this,null,function*(){p("network-error","network-error","local-client",["\u672C\u5730\u94FE\u63A5\u51FA\u73B0\u95EE\u9898","netconnectiong => ",s.netConnecting]),s.netConnecting?yield ht(r,s,i):i[Hi.TIMEOUT].next(r)})}import{BloudEvents as Wi}from"@hysc/utils";function Hr(s,e,t){let r=s==null?void 0:s.updateKeys;d("update-custom-stats"," "," ",["updateKeys => ",JSON.stringify(r)]),(r!=null&&r.includes("chatNotice")||r!=null&&r.includes("chatNoticeRich")||r!=null&&r.includes("fileUpdateLook")||r!=null&&r.includes("fileUpdateDown")||r!=null&&r.includes("fileUpdateEdit")||r!=null&&r.includes("fileUpdateModel")||r!=null&&r.includes("screenShareModel")||r!=null&&r.includes("onlyOnePersonShare")||r!=null&&r.includes("chatEnable")||r!=null&&r.includes("giveLikeEnable")||r!=null&&r.includes("cloudRecord")||r!=null&&r.includes("joinAudioEnable")||r!=null&&r.includes("joinVideoEnable")||r!=null&&r.includes("userListEnable")||r!=null&&r.includes("audioEnable")||r!=null&&r.includes("videoEnable")||r!=null&&r.includes("modifyNameEnable")||r!=null&&r.includes("backgroundAIEnable")||r!=null&&r.includes("recordEnable")||r!=null&&r.includes("joinMicrophoneDisable")||r!=null&&r.includes("joinCameraDisable")||r!=null&&r.includes("raiseHandEnable")||r!=null&&r.includes("forceOpenUserMic")||r!=null&&r.includes("forceOpenUserCamera")||r!=null&&r.includes("joinCueVoice"))&&e.roomInfo.updateOperationPermission(s.customStats),(r!=null&&r.includes("chatNotice")||r!=null&&r.includes("chatNoticeRich"))&&e.roomInfo.chatNoticeWatcher.next(s),t[Wi.UPDATE_CUSTOM_STATS].next(s)}import Gi from"@hysc/p-queue";var ft=class{constructor(e,t=!0){this.queue=new Gi({concurrency:e,autoStart:t,carryoverConcurrencyCount:!0,timeout:3*1e3,completeAction:r=>{console.log("task complete",r)}}),this.queueArray=[],this.isTaskPending=t}addQueue(e,t,r=0,i=""){this.queue.isPaused&&this.queue.start();let o={};o.taskID=t,o.status="pending",this.queue.add(e,{priority:r,timeout:3*1e3},a=>{if(o.status=a,o.status==="resolve"||o.status==="resolve-paused"||o.status==="resolve-timeout"){let n=this.queueArray.findIndex(l=>o.taskID===l.taskID);n!==-1&&this.queueArray.splice(n,1)}}),this.queueArray.push(o)}clearQueue(){this.queue.clear(),this.queueArray=[],this.queue.onEmpty().then(e=>{}),this.queue.onIdle().then(e=>{console.log("clearQueue\u5168\u90E8\u5B8C\u4E8B")})}startQueue(){this.queue.start()}pauseQueue(){return this.queue.pause(),console.log(`size:${this.size()}`),this.isTaskPending=!1,this.queue.onEmpty().then(e=>{}),this.queue.onIdle().then(e=>{}),this.queueArray}size(){return this.queue.size}pending(){return this.queue.pending}checkTaskStatus(){return this.isTaskPending}setTaskStatus(e){this.isTaskPending=e}onIdle(){return this.queue.onIdle()}onEmpty(){return this.queue.onEmpty()}},k=new ft(4),v=new ft(10);import{BMShareStreamReconnectFailed as Fi}from"@hysc/utils";import{BloudEvents as g,BrtcEvents as U,CustomEvents as Ae}from"@hysc/utils";function Wr(s,e,t,r,i){d("attachEvents init");let o={};s.on("toggle-screen-share",()=>{p("share stream video track ended, now unpublish share stream"),t.localShareError.next(Fi()),t.localShareEndedError.next(!0)}),s.on("client-banned",()=>c(this,null,function*(){yield i.boomCore.leaveShare()})),s.on("share-brtc-error",n=>c(this,null,function*(){if(n.getCode()===4002)try{d("brtc share client disconnected, reconnecting"),yield s.shareBrtcClient.leave("room_close"),_t(s).then(()=>c(this,null,function*(){if(d("brtc share client reconnected, retry repub share stream"),yield H(1e3),s.shareScreenStream){let u=s.shareScreenStream.getAudioOn(),m=s.shareScreenStream.getVideoOn();s.shareBrtcClient.publish(s.shareScreenStream),s.createAndPubBloudShareStream(u,m)}})).catch(()=>{throw new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u65B0\u5165\u4F1A\u5931\u8D25")})}catch(u){t.toggleShareScreen(!1,void 0).then(()=>{}).catch(m=>{p("\u5171\u4EAB\u53D1\u751F\u9519\u8BEF\u9000\u4F1A\u5931\u8D25","","",[JSON.stringify(m)])})}}));let a=[];return a=a.concat(Object.values(g)),a=a.concat(Object.values(U)),a=a.concat(Object.values(Ae)),a.forEach(n=>{o[n]=new ji(null)}),a.forEach(n=>{switch(n){case U.STREAM_PUBLISHED:s.on(U.STREAM_PUBLISHED,l=>{v.addQueue(dr.bind(null,l,t,i,o),U.STREAM_PUBLISHED)});break;case U.BRTC_SYNC_ROOM_COMPLETED:s.on(U.BRTC_SYNC_ROOM_COMPLETED,()=>c(this,null,function*(){v.addQueue(i.handleResetOtherStreamStatus.bind(i),U.BRTC_SYNC_ROOM_COMPLETED)}));break;case Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED:s.on(Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED,()=>{d("brtc share client sync completed, retry publish share stream"),v.addQueue(ut.bind(null,i,t),Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED)});break;case U.BRTC_ROOM_ROCONNECTING:s.on(U.BRTC_ROOM_ROCONNECTING,l=>{v.addQueue(Er.bind(null,l,i,o),U.BRTC_ROOM_ROCONNECTING)});break;case U.BRTC_ROOM_RECONNECTED:s.on(U.BRTC_ROOM_RECONNECTED,l=>c(this,null,function*(){v.addQueue(Mr.bind(null,l,i,o),U.BRTC_ROOM_RECONNECTED)}));break;case U.CLIENT_BANNED:s.on(U.CLIENT_BANNED,l=>{d("brtc client banned"),Lt(o,l)});break;case U.ERROR:s.on(U.ERROR,l=>c(this,null,function*(){i.netConnecting?v.addQueue(Dt.bind(null,l,i,s,t,o),U.ERROR):Fe.add(Dt.bind(null,l,i,s,t,o))}));break;case g.SYNC_FAILED:s.on(g.SYNC_FAILED,l=>{p("bloud sync failed, leave room"),o[g.TIMEOUT].next(l)});break;case g.ROOM_CONNECTED:s.on(g.ROOM_CONNECTED,l=>c(this,null,function*(){return dt(l,i,e,o)}));break;case Ae.JOIN_READY:s.on(Ae.JOIN_READY,()=>mt(i));break;case g.PARTICIPANT_JOINED:s.on(g.PARTICIPANT_JOINED,l=>c(this,null,function*(){i.isInWaitRoom||v.addQueue(Rr.bind(null,l,e,t,s,r,o),g.PARTICIPANT_JOINED)}));break;case g.PARTICIPANT_LEFT:s.on(g.PARTICIPANT_LEFT,l=>{i.isInWaitRoom||v.addQueue(Pr.bind(null,l,e,i,o,t,s,r),g.PARTICIPANT_LEFT)});break;case g.LEAVE_USERS:s.on(g.LEAVE_USERS,l=>v.addQueue(Ur.bind(null,l,e,i,o,t,s,r),g.LEAVE_USERS));break;case g.CHANGE_MASTER:s.on(g.CHANGE_MASTER,l=>{v.addQueue(wr.bind(null,l,e,i,o,t),g.CHANGE_MASTER)});break;case g.SEND_MESSAGE:s.on(g.SEND_MESSAGE,l=>{v.addQueue(kr.bind(null,l,e,r,o),g.SEND_MESSAGE)});break;case g.CUSTOM_MESSAGE:s.on(g.CUSTOM_MESSAGE,l=>{v.addQueue(Dr.bind(null,l,i,o),g.CUSTOM_MESSAGE)});break;case g.EVICTED:s.on(g.EVICTED,l=>c(this,null,function*(){v.addQueue(Tr.bind(null,l,e,t,i,o),g.EVICTED)}));break;case g.UPDATE_USER:s.on(g.UPDATE_USER,l=>{v.addQueue(xr.bind(null,l,e,i,t,o),g.UPDATE_USER)});break;case g.UPDATE_STATS:s.on(g.UPDATE_STATS,l=>{v.addQueue(Ir.bind(null,l,i),g.UPDATE_STATS)});break;case g.UPDATE_CUSTOM_STATS:s.on(g.UPDATE_CUSTOM_STATS,l=>{v.addQueue(Hr.bind(null,l,i,o),g.UPDATE_CUSTOM_STATS)});break;case g.TIMEOUT:s.on(g.TIMEOUT,l=>{v.addQueue(Vr.bind(null,i,s,t,l,o),g.TIMEOUT)});break;case g.USER_REJOINED:s.on(g.USER_REJOINED,l=>{d("bloud user rejoined"),Lt(o,l)});break;case g.RECONNECTING:s.on(g.RECONNECTING,l=>{v.addQueue(Cr.bind(null,l,i,o),g.RECONNECTING)});break;case g.RECONNECTED:s.on(g.RECONNECTED,l=>c(this,null,function*(){v.addQueue(ht.bind(null,l,i,o),g.RECONNECTED)}));break;case g.ROOM_SYNCED:s.on(g.ROOM_SYNCED,l=>c(this,null,function*(){v.addQueue(vr.bind(null,l,e,i,t,o),g.ROOM_SYNCED)}));break;case g.STREAM_PUBLISHED:s.on(g.STREAM_PUBLISHED,l=>c(this,null,function*(){v.addQueue(mr.bind(null,l,t,o),g.STREAM_PUBLISHED)}));break;case g.STREAM_REMOVED:s.on(g.STREAM_REMOVED,l=>c(this,null,function*(){v.addQueue(hr.bind(null,l,t,o),g.STREAM_REMOVED)}));break;case g.UPDATE_STREAM:s.on(g.UPDATE_STREAM,l=>c(this,null,function*(){v.addQueue(pr.bind(null,l,t,o),g.UPDATE_STREAM)}));break;case g.STREAM_UPDATE:s.on(g.STREAM_UPDATE,l=>c(this,null,function*(){v.addQueue(wt.bind(null,l,t),g.STREAM_UPDATE)}));break;case g.MOVE_USER_ROOM:s.on(g.MOVE_USER_ROOM,l=>c(this,null,function*(){v.addQueue(Lr.bind(null,i,e,l,o),g.MOVE_USER_ROOM)}));break;default:s.on(n,l=>o[n].next(l));break}}),o}import{BmChangeAudioProfileError as Vt,BmChangeMasterError as Ht,BmChangeVideoProfileError as Wt,BmCheckDeviceError as Gt,BmEvictUserError as St,BmSetRemoteAudioEnable as $e,BmSetRemoteVideoEnable as $i,BmUpdateManagerError as Gr,BmUpdateUserError as jt,updateCustomStatsError as Ji}from"@hysc/utils";import{Subject as Qi}from"rxjs";var Je=class{constructor(e,t,r){this.room=null;this.tipQueueObj={};this.roomInfo=r,this.userVM=t,this.boomCore=e,this.giveLikeList=[],this.giveLikeListWatcher=new Qi}initWithRoom(e){this.room=e}evictUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(St("\u672A\u4F20\u9012\u7528\u6237id"));if(!this.userVM.checkLocalHasMaster())return Promise.reject(St("\u53EA\u6709\u4E3B\u6301\u4EBA\u6743\u9650\u624D\u80FD\u8E22\u51FA\u7528\u6237"));if(this.userVM.checkIsMaster(e))return Promise.reject(St("\u4E3B\u6301\u4EBA\u4E0D\u80FD\u88AB\u8E22\u51FA"));try{yield this.boomCore.evictUser(e,t)}catch(r){return Promise.reject(St(`\u8E22\u51FA\u7528\u6237\u5931\u8D25${JSON.stringify(r)}`))}})}updateUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(jt("\u672A\u4F20\u9012\u76EE\u6807\u7528\u6237id"));if(!t)return Promise.reject(jt("info\u4E3A\u7A7A,\u8BF7\u5199\u5165\u8981\u66F4\u65B0\u7684\u4FE1\u606F"));yield this.boomCore.updateUser(e,{customInfo:t}).catch(r=>Promise.reject(jt(`boomCore updateUser\u51FA\u9519 ${JSON.stringify(r)}`)))})}changeMaster(e,t){return c(this,null,function*(){var r;if(!e)return Promise.reject(Ht("\u672A\u4F20\u9012\u4E3B\u6301\u4EBAid"));if(this.userVM.checkLocalHasMaster()||(r=this.userVM.getUser(e))!=null&&r.isCreate)try{yield this.boomCore.changeMaster(e,t)}catch(i){return Promise.reject(Ht(`boomCore changeMaster error ${i}`))}else return console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA",N,e),Promise.reject(Ht("\u60A8\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))})}updateManager(e,t,r=!0){return c(this,null,function*(){return e?this.userVM.checkLocalHasMaster()?this.userVM.updateManager(e,t,r):(console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u8054\u5E2D\u4E3B\u6301\u4EBA",N,e),Promise.reject(Gr("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))):Promise.reject(Gr("\u672A\u4F20\u9012\u8054\u5E2D\u4E3B\u6301\u4EBAid"))})}changeNickName(e,t){return c(this,null,function*(){let r={nickname:t};yield this.updateUser(e,r)})}sendMessageWithMaster(e,t){return c(this,null,function*(){if(!this.userVM.checkLocalHasMaster())return Promise.reject($e("\u60A8\u4E0D\u662F\u4E3B\u6301\u4EBA\uFF0C\u6CA1\u6709\u8BE5\u6743\u9650"));if(t&&!this.userVM.getUser(t))return Promise.reject($e(`uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(e),t)}catch(r){return Promise.reject(r)}})}setRemoteAudioEnable(e,t,r){return c(this,null,function*(){let i=e?"enabled":"disabled";i=="enabled"&&r&&(i="checkUserAudio");let o={domain:"room-control",method:"audio-force-change",params:{status:i,isNotCancelRootReport:r,fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(o,t).catch(a=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${a}`)))})}setRemoteVideoEnable(e,t){return c(this,null,function*(){let r={domain:"room-control",method:"video-force-change",params:{status:e?"enabled":"disabled",fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject($i(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${i}`)))})}closeRemoteShare(e){return c(this,null,function*(){let t={domain:"room-control",method:"close-remote-share",params:{fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(t,e).catch(r=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${r}`)))})}tipUser(e,t,r,i){return c(this,null,function*(){let o={domain:"room-control",method:"tip-user",params:{fromUserId:this.boomCore.getLocalParticipant().getID(),message:t,richMsg:r}};i?this.tipQueueObj[e]=setTimeout(()=>{this.sendMessageWithMaster(o,e)},(i.minutes||0)*60*1e3+(i.seconds||0)*1e3):this.sendMessageWithMaster(o,e).catch(a=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${JSON.stringify(a)}`)))})}raiseHands(e,t){return c(this,null,function*(){var o,a;let r=(o=this.room)==null?void 0:o.getLocalParticipant().getID(),i={};e==="raiseHand"?(i.raiseHand=t,i.raiseHandTime=Math.floor(new Date().getTime()/1e3)):i[e==="audio"?"raiseHandsAudio":"raiseHandsVideo"]=t,yield this.updateUser(r,i),(a=this.room)!=null&&a.isBig&&(yield this.raiseHandsByCustomMessage(e,t,r))})}raiseHandsByCustomMessage(e,t,r){return c(this,null,function*(){var a;let i="raiseHand";e!="raiseHand"&&(i=e==="audio"?"raiseHandsAudio":"raiseHandsVideo");let o={domain:"user-control",method:"raise-hands",params:{raiseHandsType:4,raiseHands:t,raiseInfo:{userId:r,raiseHandTime:Math.floor(new Date().getTime()/1e3),type:i}}};return(a=this.room)==null||a.userVM.userList.forEach(n=>c(this,null,function*(){n.hasManager()&&(yield this.boomCore.customMessage(JSON.stringify(o),n.userId))})),!0})}handleRaiseHands(e,t,r){return c(this,null,function*(){var o,a,n;let i={domain:"user-control",method:"raise-hands",params:{raiseHandsType:e,raiseHands:t}};try{if(r)yield this.boomCore.customMessage(JSON.stringify(i),r);else{let l=(o=this.room)==null?void 0:o.roomInfo.raiseHandsWatcher.getValue(),u=(a=this.room)==null?void 0:a.roomInfo.raiseVideoHandsWatcher.getValue(),m=(n=this.room)==null?void 0:n.roomInfo.raiseSimpleHandsWatcher.getValue();e===0&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)}),u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===1&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===2&&(u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===3&&(m==null||m.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)}))}}catch(l){return Promise.reject(new R(1e3,"boomCore.sendMessage\u53D1\u751F\u9519\u8BEF"))}})}updateCustomStats(e,t=!1){return c(this,null,function*(){yield this.boomCore.updateCustomStats(e,t).catch(r=>Promise.reject(Ji(`${JSON.stringify(e)} - ${JSON.stringify(r)}`)))})}sendChatNotice(e,t,r){return c(this,null,function*(){yield this.updateCustomStats({chatNotice:e,chatNoticeRich:t,showTipNotice:r}).catch(i=>i)})}giveLikeEnable(e){return c(this,null,function*(){yield this.updateCustomStats({giveLikeEnable:e}).catch(t=>t)})}changeAutoMute(e){return c(this,null,function*(){return this.updateCustomStats({autoMute:e})})}allUserReceiveJoinLeaveMessages(e){return c(this,null,function*(){return this.updateCustomStats({allUserReceiveJoinLeaveMessages:e})})}userJoinMasterVoice(e){return c(this,null,function*(){return this.updateCustomStats({userJoinMasterVoice:e})})}userGiveLike(e){return c(this,null,function*(){var o,a;let t=new Date().getTime(),r={domain:"room-control",method:"give-like",params:{stream:{user:this.userVM.localUser.userId,avatar:this.userVM.localUser.avatar,sendTime:t,nickname:this.userVM.localUser.nickName,type:e||1}}},i=this.userVM.getLocalUser();try{yield this.boomCore.customMessage(JSON.stringify(r),void 0),this.giveLikeList.push({userId:(o=this.room)==null?void 0:o.getLocalParticipant().userId,nickName:(a=this.room)==null?void 0:a.getLocalParticipant().nickName,time:new Date().getTime(),type:e}),this.giveLikeListWatcher.next(this.giveLikeList)}catch(n){throw p(n,N,i==null?void 0:i.userId),new R(4005,"\u7528\u6237\u70B9\u8D5E==>sendMessage\u51FA\u9519")}})}chatEnable(e){return c(this,null,function*(){yield this.updateCustomStats({chatEnable:e}).catch(t=>t)})}joinAudioEnable(e){return c(this,null,function*(){yield this.updateCustomStats({joinAudioEnable:e}).catch(t=>t)})}joinVideoEnable(e){return c(this,null,function*(){yield this.updateCustomStats({joinVideoEnable:e}).catch(t=>t)})}userListEnable(e){return c(this,null,function*(){yield this.updateCustomStats({userListEnable:e}).catch(t=>t)})}audioEnable(e){return c(this,null,function*(){yield this.updateCustomStats({audioEnable:e}).catch(t=>t)})}videoEnable(e){return c(this,null,function*(){yield this.updateCustomStats({videoEnable:e}).catch(t=>t)})}modifyNameEnable(e){return c(this,null,function*(){yield this.updateCustomStats({modifyNameEnable:e}).catch(t=>t)})}backgroundAIEnable(e){return c(this,null,function*(){yield this.updateCustomStats({backgroundAIEnable:e}).catch(t=>t)})}forceOpenUserCamera(e){return c(this,null,function*(){yield this.updateCustomStats({forceOpenUserCamera:e}).catch(t=>t)})}forceOpenUserMic(e){return c(this,null,function*(){yield this.updateCustomStats({forceOpenUserMic:e}).catch(t=>t)})}joinCueVoice(e){return c(this,null,function*(){yield this.updateCustomStats({joinCueVoice:e}).catch(t=>t)})}recordEnable(e){return c(this,null,function*(){yield this.updateCustomStats({recordEnable:e}).catch(t=>t)})}raiseHandEnable(e){return c(this,null,function*(){yield this.updateCustomStats({raiseHandEnable:e}).catch(t=>t)})}joinMicrophoneDisable(e){return c(this,null,function*(){yield this.updateCustomStats({joinMicrophoneDisable:e}).catch(t=>t)})}joinCameraDisable(e){return c(this,null,function*(){yield this.updateCustomStats({joinCameraDisable:e}).catch(t=>t)})}changeFileUpdateModelPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateModel:e}).catch(t=>t)})}changeFileUpdateLookPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateLook:e}).catch(t=>t)})}changeFileUpdateDownPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateDown:e}).catch(t=>t)})}changeFileUpdateEditPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateEdit:e}).catch(t=>t)})}changeScreenShareModelPermission(e){return c(this,null,function*(){yield this.updateCustomStats({screenShareModel:e}).catch(t=>t)})}changeOnlyOnePersonSharePermission(e){return c(this,null,function*(){yield this.updateCustomStats({onlyOnePersonShare:e}).catch(t=>t)})}setForceOnUser(e){return c(this,null,function*(){yield this.updateCustomStats({forceOn:{user:e}}).catch(t=>t)})}updateCloudRecord(e){return c(this,null,function*(){return yield this.updateCustomStats({cloudRecord:{userId:e.userId,recordStatus:e.recordStatus}}).catch(t=>t)})}updateSafeHideSec(e){return c(this,null,function*(){return yield this.updateCustomStats({safeHideSec:e}).catch(t=>t)})}updateHostLayout(e,t=!1){return c(this,null,function*(){if(!this.userVM.checkLocalHasMaster())d("\u60A8\u4E0D\u662F\u4E3B\u6301\u4EBA\uFF0C\u6CA1\u6709\u8BE5\u4E0A\u62A5\u6743\u9650",N);else return this.updateCustomStats({from:{fromTag:"masterId"},hostLayout:e},t)})}checkDevices(e){return c(this,null,function*(){let t={domain:"user-control",method:"check-devices",params:{fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(t,e).catch(r=>Promise.reject(Gt(`\u68C0\u6D4B\u5BF9\u65B9\u8BBE\u5907send-message\u53D1\u751F\u9519\u8BEF: ${r}`)))})}resp2CheckDevices(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-check-devices",params:ke(P({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};if(!t)return Promise.reject(Gt(`\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4B: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(i){return Promise.reject(Gt(`\u54CD\u5E94\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4Bsend-message\u53D1\u751F\u9519\u8BEF ${i}`))}})}changeRemoteVideoProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"change-video-profile",params:ke(P({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject(Wt(`\u8C03\u8282\u5BF9\u65B9\u7684\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF: ${i}`)))})}resp2ChangeRemoteVideoProfile(e,t,r){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-change-video-profile",params:{status:e,profile:r,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Wt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(o){return Promise.reject(Wt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF ${o}`))}})}changeRemoteAudioProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"change-audio-profile",params:{microphoneDevice:e.microphoneDevice,speakerDevice:e.speakerDevice,echoCancellation:e.echoCancellation,noiseSuppression:e.noiseSuppression,autoGainControl:e.autoGainControl,speakerVolume:e.speakerVolume,microVolume:e.microVolume,fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject(Vt(`\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${JSON.stringify(i)}`)))})}resp2ChangeRemoteAudioProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-change-audio-profile",params:{status:e,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Vt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(i){return Promise.reject(Vt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${i}`))}})}};import{BehaviorSubject as qi,Subject as zi}from"rxjs";import{throttle as Xi}from"lodash-es";var Qe=class{constructor(e,t,r){this.messageList=[];this.hasDangerMessageWatcher=new zi;this.notificationMessageList=Xi(()=>{this.messageListWatcher.next(this.messageList)},200);this.boomCore=e,this.userVM=t,this.bmRoom=r,this.messageListWatcher=new qi(this.messageList)}sendMessage(e,t,r){return c(this,null,function*(){let i=e.replace(/(^\s*)|(\s*$)/g,""),o=new Date().getTime(),a={domain:"room-control",method:"send-talk",params:{stream:{user:this.userVM.localUser.userId,avatar:this.userVM.localUser.avatar,sendTime:o,nickname:this.userVM.localUser.nickName},status:i}},n=this.userVM.getLocalUser();try{let l=!1,u,m=r;m||(yield this.boomCore.sendMessage(JSON.stringify(a),t).then(f=>{u=f.seq}).catch(f=>{I("sendmessage \u51FA\u9519","",n==null?void 0:n.userId,[f]),f&&f.code===39&&(l=!0,this.hasDangerMessageWatcher.next(!0))}));let h=new x({userId:n==null?void 0:n.userId,message:i,isLocal:n==null?void 0:n.isLocal,avatar:n==null?void 0:n.avatar,nickName:n==null?void 0:n.nickName,sendTime:o,to:t,isDanger:l,seq:u,failed:m});return this.addMessage(h,!1),m?Promise.reject(h):Promise.resolve()}catch(l){throw p(l,N,n==null?void 0:n.userId),new R(4005,"\u53D1\u9001\u804A\u5929\u6D88\u606F==>sendMessage\u51FA\u9519")}})}addMessage(e,t){if(!(t&&!this.bmRoom.participantNotice)){if(this.messageList.length==0||e.timeStamp-this.messageList[this.messageList.length-1].timeStamp>=ar){let r=new x({isMeetingNotice:!0,message:""});this.messageList.push(r)}this.messageList.push(e),this.notificationMessageList()}}updateMessageListWatcher(e){this.messageList=e,this.messageListWatcher.next(this.messageList)}getHistoryMessage(){return c(this,null,function*(){let e=yield this.boomCore.getMessages(0,this.boomCore.getMsgSeq()),t=[];return e.items.forEach(r=>{if(r.private||r.to||r.msg.length==0||r.msg.indexOf("{")==-1)return!1;let i=JSON.parse(r.msg);if(i.method!="send-talk")return!1;let o=r.seq,a=i.params,n=a.stream.user?a.stream.user:r.userId,l={nickName:a.stream.nickname,content:a.status,timeStamp:new Date().getTime(),userId:n},u=new x({userId:n,message:a.status,nickName:a.stream.nickname,isLocal:n==this.userVM.localUser.userId,avatar:a.stream.avatar,sendTime:a.stream.sendTime,seq:o});t.push(u)}),Promise.resolve(t)})}generateInfo(e){return new x(e)}};import{BehaviorSubject as qr,Subject as X}from"rxjs";import{Player as Zi}from"@hysc/core";var Re=class{constructor(e,t){this.user=e,this.stream=t}getID(){return this.stream.getStreamId()}getUser(){return this.user}};import{debounce as qe}from"lodash-es";function jr(s,e){return 16|~~s<<1|~~e}function Fr(s,e){return 12|~~s<<1|~~e}function $r(s,e){return 8|~~s<<1|~~e}function Jr(s,e){return 4|~~s<<1|~~e}function Qr(){return Date.now()}function bt(){let s=Qr();return function(){return Qr()-s}}import{detect as Ki}from"detect-browser";var Ue=Ki(),es=(Ue==null?void 0:Ue.name)==="safari"||(Ue==null?void 0:Ue.name)==="ios";var ce=`.streammodel${Math.random()}`,Pe=class{constructor(e,t,r=!1){this.streamType=3;this.pullFailedNum=0;this._video_enable=!1;this._audio_enable=!1;this.videoEnableWatcher=new qr(this._video_enable);this.audioEnableWatcher=new qr(this._audio_enable);this.streamUpdateWatcher=new X;this.isSubScribedWatcher=new X;this.playStateChangeWatcher=new X;this.noContainerWatcher=new X;this.noBigContainerWatcher=new X;this.audioLevelWatcher=new X;this.isCurrentDisplay=!1;this.isDisplay=!1;this.isDisplayObserve=new X;this.isInBig=!1;this.isInBigObserve=new X;this._hasPulled=!1;this.shouldPull=!1;this.smallPlayFailed=0;this._pulledStreamType="small";this.pulledStreamGoal="small";this.bigPlayerId="";this.isPlayingBig=!1;this.muted=!1;this.checkVideoTimer=null;this.checkCount=0;this.sortNum=-1;this.isWhiteboard=!1;this.handleDisplayChange=e=>{this.isDisplay!==e&&(this.isDisplay=e,this.isDisplay||(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0,this.pulledStreamType="small"),this.sendMessage2Room())};this.onPlayerStateChange=e=>{var t,r;e.type==="error"&&e.reason&&e.reason.name==="NotAllowedError"&&(d("\u64AD\u653E\u5931\u8D25, \u9700\u8981\u8C03\u7528 resume \u65B9\u6CD5"),this.playStateChangeWatcher.next(this)),(e.state==="PAUSED"||e.reason==="pause")&&(this.player&&((t=this.player)==null||t.resume()),(r=this.stream)==null||r.resume())};this.handleStreamConnectError=()=>{d("\u6D41\u51FA\u73B0\u7684connect-error userId","",this.userId,["streamId ==>",this.streamId,"nickname =>",this.nickname,"isLocal => ",this.isLocal]),this.isLocal?y.emitter.emit(se,{stream:this,isLocal:!0}):y.emitter.emit(se,{stream:this,isLocal:!1})};this.bindElement=e=>{!this.isLocal&&(!this.stream||!this.stream.isSubscribed())||this.emitBindElement()};this.bindBigElement=e=>{this.bigPlayerId=e,!(!this.isLocal&&(!this.stream||!this.stream.isSubscribed()))&&this.emitBindBigElement()};this.sendMessage2Room=qe(()=>{y.emitter.emit(me,{stream:this})},100);this.emitBindElement=qe(()=>{y.emitter.emit(pe,{stream:this})},50);this.emitBindBigElement=qe(()=>{y.emitter.emit(be,{stream:this})},50);this.currentIsPlaying=(e,t=!0)=>{var l;let r=document.getElementById(e);if(!r)return 0;let i,o,a=0,n=Array.from(r.children);return i=n.length>0,o=n.length,n.forEach(u=>{u.children.length===0&&(a+=1)}),a>0&&(I(`check stream current is playing failed, ${e}`),t?this.stop():((l=this.player)==null||l.destroy(),this.player=null)),i&&o>a?2:1};this.play=(e=!1)=>c(this,null,function*(){var r,i;if(!this.playerId){I(`no playerId, do not play :${this.nickname} - ${this.userId} - ${this.streamId}`);return}let t=this.stream;if(t){if(!this.isLocal&&!t.isSubscribed())return;let o=bt();if(this.isDisplay&&this.videoEnable){if(e){this.stop(),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!ze}),(r=y.emitter)==null||r.emit(V,{uid:this.userId}),d(`\u64AD\u653E\u8017\u65F6: ${o()}`,"",this.userId);return}let a=this.currentIsPlaying(this.playerId);if(a===0)I("\u627E\u4E0D\u5230\u64AD\u653E\u5668\u5BB9\u5668","stream play",this.userId,["\u6D41 id =>",this.streamId,"nickname =>",this.nickname,"playerId =>",this.playerId]),this.playerId||y.emitter.emit(oe,{type:this.isShare?"share":"normal",id:this.userId,container:"small"});else if(a===1)try{d("\u8FDC\u7AEF\u6D41\u5F00\u59CB\u64AD\u653E","",this.userId),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!ze}),(i=y.emitter)==null||i.emit(V,{uid:this.userId}),d("\u8FDC\u7AEF\u6D41\u64AD\u653E\u7ED3\u675F",this.userId,this.streamId,[this.nickname]),d(`\u64AD\u653E\u8017\u65F6: ${o()}`,"",this.userId),this.smallPlayFailed=0,this.checkSmallVideo()}catch(n){this.stop(),setTimeout(()=>{p("\u64AD\u653E\u5C0F\u6D41\u5931\u8D25, \u5C1D\u8BD5\u91CD\u65B0\u64AD\u653E","\u64AD\u653E",this.userId,[this.streamId,this.stream,"error => ",JSON.stringify(n)]),this.play()},2*1e3)}}else this.stop()}});this.playInBig=(e=!1)=>c(this,null,function*(){var r,i,o,a;if(!this.bigPlayerId){I(`no bigPlayerId, do not play in big :${this.nickname} - ${this.userId} - ${this.streamId}`);return}let t=this.stream;if(t){if(!this.isLocal&&!t.isSubscribed())return;if(this.isInBig&&this.videoEnable&&this.bigPlayerId){let n=bt();if(e){this.initBigPlayer(),yield(r=this.player)==null?void 0:r.play(t),(i=y.emitter)==null||i.emit(V,{uid:this.userId}),d(`\u5927\u6D41\u64AD\u653E\u8017\u65F6: ${n()}`,"",this.userId);return}let l=this.currentIsPlaying(this.bigPlayerId,!1);l===0?(I("\u627E\u4E0D\u5230 bigPlayerId","\u5927\u6D41\u64AD\u653E",this.userId,["\u6D41 id =>",this.streamId]),this.bigPlayerId||y.emitter.emit(oe,{type:this.isShare?"share":"normal",id:this.userId,container:"big"})):l===1&&(d("\u8FDC\u7AEF\u6D41\u5927\u6D41\u5F00\u59CB\u64AD\u653E","",this.userId),this.initBigPlayer(),this.player&&(yield this.player.play(t),(o=y.emitter)==null||o.emit(V,{uid:this.userId}),this.isPlayingBig=!0,this.checkBigVideo()),d("\u8FDC\u7AEF\u6D41\u5927\u6D41\u64AD\u653E\u7ED3\u675F",this.userId,this.streamId,[this.nickname]),d(`\u5927\u6D41\u64AD\u653E\u8017\u65F6: ${n()}`,"",this.userId))}else(a=this.player)==null||a.destroy(),this.player=null,this.isPlayingBig=!1}});this.collectAudioLevel=()=>{this.stream?(this.stream.off("audio-level"+ce,this.handleAudioLevel),this.stream.on("audio-level"+ce,this.handleAudioLevel)):I("collection audio level but not have brtc stream")};this.handleAudioLevel=e=>{this.audioLevelWatcher.next(e)};this.checkSmallVideo=()=>c(this,null,function*(){if(this.videoEnable&&this.stream&&!this.isShare&&!!document.getElementById(this.playerId)){let t=`video_${this.stream.getStreamId()}`;if(!!document.getElementById(t)){this.checkVideoDecodeFrame(t);return}else p(`stream is display, but no video element, should replay now: ${this.smallPlayFailed}`),this.smallPlayFailed<3&&(this.smallPlayFailed+=1,yield H(1e3),this.stop(),yield this.play())}});this.checkBigVideo=qe(()=>{var e;if(this.videoEnable&&this.stream){let t=`video_${this.stream.getStreamId()}_big`;if(!this.isShare&&this.isDisplay&&this.playerId){let r=!!document.getElementById(t);if(this.isInBig)if(r){this.checkVideoDecodeFrame(t);return}else p("stream is playing in big, but no video element, replay now"),(e=this.player)==null||e.destroy(),this.player=null,this.playInBig()}this.isShare&&this.isInBig&&this.bigPlayerId&&this.checkVideoDecodeFrame(t)}},2e3);this.checkStreamIsPlaying=qe(()=>{if(this.isDisplay&&this.videoEnable){if(!this.stream||!document.getElementById(this.playerId))return;this.currentIsPlaying(this.playerId)===2||(p(`${this.userId} - ${this.nickname}: current is ${this.isDisplay}, but there is no player, try play again`),this.play())}},1e3);this.user=e,this.updateUser(e),this._stream=t,this.isDisplayObserve.subscribe(i=>{this.handleDisplayChange(i)}),this.isInBigObserve.subscribe(i=>{this.handleIsInBig(i)}),this.updateSortNum(!1),this.isWhiteboard=r}get hasPulled(){return this._hasPulled}set hasPulled(e){this._hasPulled=e}get pulledStreamType(){return this._pulledStreamType}set pulledStreamType(e){this._pulledStreamType=e}get uuid(){return this.isShare?`${this.userId}_share`:this.isWhiteboard?`${this.userId}_whiteboard`:this.userId}get playerId(){return this.isDisplay?"v_"+this.uuid:""}get isAudience(){return this.user.isAudience}get canShow(){return this.isAudience?this.user.audienceEnableSpeaking:!0}changeMute(e){this.muted!==e&&(this.muted=e,this.handleSpeakerChange())}handleSpeakerChange(){var e,t;this.isLocal||(this.muted?(e=this.stream)==null||e.setAudioVolume(0):(t=this.stream)==null||t.setAudioVolume(1))}get isToupingma(){return this.user.isToupingma}get isMixer(){return this.user.isMixer}get isSignal(){return this.user.isSignal}genReceiveSubMsg(){let e;return this.isDisplay?e={audio:!0,video:!0,streamType:"small"}:e={audio:!0,video:!1,streamType:"small"},e}handleIsInBig(e){this.isInBig!==e&&(this.isInBig=e,d("isInBig change","",this.userId,["streamId =>",this.streamId,"isInBig => ",e]),this.isInBig?this.pulledStreamGoal="big":this.pulledStreamGoal="small",this.sendMessage2Room(),this.isShare&&(this.isInBig||(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0)))}setVideoEnable(e){this._video_enable!==e&&(this._video_enable=e,this.videoEnableWatcher.next(e))}setAudioEnable(e){this._audio_enable!==e&&(this._audio_enable=e,this.audioEnableWatcher.next(e))}updateStream(e,t=!0,r){this._stream&&this._stream.off(ce),this._stream=e,e?(this.audioEnable&&(this.isShare||r.addToDetector(new Re(this.user,e)),this.collectAudioLevel()),e.on("player-state-changed"+ce,this.onPlayerStateChange),e.on("connect-error"+ce,this.handleStreamConnectError),e.on("stream-connection-error"+ce,this.handleStreamConnectError),!this.isLocal&&t&&this.sendMessage2Room()):(this.hasPulled=!1,this.pulledStreamType="small",this.streamType=3)}updateBloudStream(e,t,r=!1){var a,n,l,u,m;let i=!1,o=!1;e?(this.bloudStream={audio:e.audio,video:e.video,isScreen:e.isScreen},e.customInfo&&((!this.bloudStream.customInfo||((a=this.bloudStream.customInfo)==null?void 0:a.volume)!==e.customInfo.volume)&&(Number.isNaN(e.customInfo.volume)||this.setRemoteAudioLevel(e.customInfo.volume)),this.bloudStream.customInfo=e.customInfo),this.stream&&(this.bloudStream.audio?this.isShare||(t.addToDetector(new Re(this.user,this.stream)),this.collectAudioLevel()):t.removeFromDetector(this.stream.getStreamId())),this.bloudStream.video!==this._video_enable&&(i=!0),this.bloudStream.audio!=this._audio_enable&&(o=!0),this.setVideoEnable(this.bloudStream.video),this.setAudioEnable(this.bloudStream.audio),this.isLocal&&(this.isDisplay&&this.play(),this.isInBig&&this.playInBig()),r&&(this.destroyBrtcStream(),(n=this.player)==null||n.destroy(),this.stream&&((l=t.room.audioPlayer)==null||l.removeStream(this.stream)),this._stream=void 0),o&&!this.audioEnable&&this.stream&&((u=t.room.audioPlayer)==null||u.removeStream(this.stream)),(this.bloudStream.audio||this.bloudStream&&this.isDisplay)&&(!this.stream||r?y.emitter.emit(ye,{id:this.userId,isWeb:this.isWeb,isScreen:this.isShare}):(this.isLocal||(!this.hasPulled||!this.stream.isSubscribed())&&this.sendMessage2Room(),i&&(this.isDisplay&&this.playerId&&this.emitBindElement(),this.isInBig&&this.bigPlayerId&&this.emitBindBigElement()),!this.isLocal&&o&&this.audioEnable&&this.stream.isSubscribed()&&y.getInstance().emit(Me,{stream:this})))):(this.bloudStream=void 0,this.setVideoEnable(!1),this.setAudioEnable(!1),(m=this.player)==null||m.destroy(),this.stream&&t.removeFromDetector(this.stream.getStreamId())),this.updateSortNum(!0),this.streamUpdateWatcher.next(!0)}updateBloudCustomInfo(e){var t;this.bloudStream?((!this.bloudStream.customInfo||((t=this.bloudStream.customInfo)==null?void 0:t.volume)!==e.volume)&&(Number.isNaN(e.volume)||this.setRemoteAudioLevel(e.volume)),this.bloudStream.customInfo=e):p("updateBloudCustomInfo, but bloudStream is undefined","","",["userId =>",this.userId])}get streamId(){return this._stream?this._stream.getStreamId():this.userId}get bStreamId(){return this.isShare?`${this.userId}_screen`:this.userId}get userId(){return this.user.userId}get stream(){return this._stream}get isLocal(){return this.user.isLocal}get isShare(){var e,t,r;return this.stream?this.user.isWeb?(t=(e=this.stream)==null?void 0:e.getUserId().toString())==null?void 0:t.endsWith(T):this.stream&&this.stream.getType&&this.stream.getType()==="assist":!!((r=this.bloudStream)!=null&&r.isScreen)}get isWeb(){return this.user.isWeb}get isMobile(){return this.user.isMobile}get audioEnable(){return this._audio_enable}get videoEnable(){return this._video_enable}get brtcPlayerId(){return`player_${this.stream.getStreamId()}`}get selfPlayerId(){return`player_${this.stream.getStreamId()}_big_container`}get nickname(){var e;return this.user.isToupingma?`${this.user.nickName}(\u7684\u6295\u5C4F)`:(e=this.streamId)!=null&&e.includes(T)?`${this.user.nickName}(\u7684\u5C4F\u5E55\u5171\u4EAB)`:this.user.nickName}get audioLevel(){var e;return((e=this._stream)==null?void 0:e.getAudioLevel())||0}getUser(){return this.user}setRemoteAudioLevel(e){if(this.isLocal)throw new Error("\u4E0D\u80FD\u8BBE\u7F6E\u672C\u5730\u6D41\u7684\u97F3\u91CF");y.emitter.emit(Ee,{streamId:this.streamId,volume:e})}getStats(){var e;return(e=this._stream)==null?void 0:e.getStats()}initBigPlayer(){try{if(this.bigPlayerId){let e=document.querySelector(`#${this.bigPlayerId}`);if(!e){console.error("\u64AD\u653E\u5927\u6D41\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u5927\u6D41\u5BB9\u5668",this.userId,this.streamId,this.bigPlayerId);return}this.player&&this.player.destroy(),this.player=null,this.player=new Zi(e,{fit:"contain"}),this.player.on("player-state-changed",t=>{var r;this.stream&&(d("big player state change","","",[JSON.stringify(t)]),t.type==="error"&&t.reason&&t.reason.name==="NotAllowedError"&&this.playStateChangeWatcher.next(this),t.state==="PAUSED"&&((r=this.player)==null||r.resume()))})}}catch(e){p("\u521D\u59CB\u5316\u5927\u7A97\u53E3\u7684\u64AD\u653E\u5668\u5931\u8D25",this.userId,this.streamId,[e.message])}}stop(){var e;try{(e=this._stream)==null||e.stop()}catch(t){}}destroyBrtcStream(){var e;try{(e=this._stream)==null||e.destroy()}catch(t){}}isPlaying(){var e;return(e=this._stream)==null?void 0:e.isPlaying()}replay(){var e;return(e=this._stream)==null?void 0:e.replay()}resume(){var e,t;(e=this._stream)==null||e.resume(),(t=this.player)==null||t.resume()}hasAudio(){var e;return((e=this._stream)==null?void 0:e.hasAudio())||!1}hasVideo(){var e;return((e=this._stream)==null?void 0:e.hasVideo())||!1}updateUser(e){this.user=e;let t=this.user.userInfo.pos;if(this.isWhiteboard){this.streamType=3;return}if(!t){this.streamType=1;return}t.includes("web")||t.includes("pc")?this.streamType=0:t.includes("_toupingma")?this.streamType=2:this.streamType=1}updateSortNum(e=!0){let t=this.getSortNum();this.setSortNum(t,e)}setSortNum(e,t){this.sortNum!==e&&(this.sortNum=e,t&&(y.emitter.emit(Ie,null),this.user.updateSortNum(!0)))}getSortNum(){return this.user.isMaster?jr(this.audioEnable,this.videoEnable):this.user.isLocal?Fr(this.audioEnable,this.videoEnable):this.user.isManager?$r(this.audioEnable,this.videoEnable):Jr(this.audioEnable,this.videoEnable)}checkVideoDecodeFrame(e){if(this.isLocal||es)return;let t=document.getElementById(e);if(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),!t){d("\u9ED1\u5E27\u68C0\u6D4B\u6CA1\u6709\u64AD\u653E\u5BB9\u5668",this.userId,"",["streamId =>",this.streamId,"isShare =>",this.isShare,"playerId =>",this.playerId,"bigPlayerId =>",this.bigPlayerId,"isDisplay => ",this.isDisplay,"isInbig =>",this.isInBig]),this.isShare&&this.isInBig&&this.bigPlayerId&&(I("share stream has no video player, retry play"),this.playInBig(!0));return}this.checkVideoTimer=setTimeout(()=>{var i,o,a;let r=(t==null?void 0:t.getVideoPlaybackQuality)&&((i=t==null?void 0:t.getVideoPlaybackQuality())==null?void 0:i.totalVideoFrames)||0;if(t&&!t.getVideoPlaybackQuality){this.checkVideoTimer&&clearTimeout(this.checkVideoTimer);return}if(r>0){clearTimeout(this.checkVideoTimer);return}else{if(this.checkCount>10){p("\u68C0\u6D4B\u8D85\u8FC7\u4E86\u5341\u6B21\uFF0C\u8FD8\u6CA1\u6709\u89C6\u9891\u6D41\uFF0C\u9700\u8981\u91CD\u65B0\u62C9\u53D6","\u9ED1\u5E27\u68C0\u6D4B",this.userId,["streamId =>",this.streamId,"nickname =>",this.nickname,"videoContainer => ",e]),this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0,this.hasPulled=!1,this.pulledStreamType="small",(o=this._stream)==null||o.off(ce),this.destroyBrtcStream(),(a=this.player)==null||a.destroy(),this.player=null,this._stream=void 0,this.sendMessage2Room();return}this.checkCount+=1,this.checkVideoDecodeFrame(e)}},200)}subscribeStream(){this.shouldPull=!0,y.emitter.emit(ge,{stream:this})}unSubscribeStream(){this.shouldPull=!1,y.emitter.emit(fe,{stream:this})}unAttach(e){var t,r;e==="all"?(this.stop(),(t=this.player)==null||t.destroy(),this.bigPlayerId=""):e==="big"?((r=this.player)==null||r.destroy(),this.bigPlayerId=""):e==="small"&&this.stop()}};import{BehaviorSubject as ue,Subject as Y}from"rxjs";import{BoomError as Yr}from"@hysc/utils";import{debounce as ts}from"lodash-es";import{BMCameraNotAuthError as rs,BMMicNotAuthError as is,BMOpenCameraError as Zr,BMOpenMicroError as $t,BmSetLocalAudioEnable as ss,BmSetLocalSpeakerEnable as os,BmSetLocalVideoEnable as as,BMStreamDisconnectedError as Kr,BmSyncStreamFailError as Jt,getStreamError as ns}from"@hysc/utils";function zr(s){let e=null,t=s.videoElement,r=t.offsetWidth,i=t.offsetHeight;if(t.captureStream?e=t.captureStream():t.mozCaptureStream&&(e=t.mozCaptureStream()),e){let o=e.getVideoTracks()[0],a=e.getAudioTracks()[0];return{video:!!o,audio:!!a,videoSource:o,audioSource:a,width:r,height:i}}return null}function Xr(s,e){try{let t=s.getVideoTracks()[0],r=s.getAudioTracks()[0];return{video:!!t,audio:!!r,videoSource:t,audioSource:r,width:e.width,height:e.height}}catch(t){return console.log("\u83B7\u53D6\u5171\u4EAB\u97F3\u9891\u53C2\u6570\u6709\u8BEF",t),null}}function Ne(s){return s.split("_")[0]}var Z=`.streammuteevent${Math.random()}`,Xe=class s{constructor(){this.streamModels=new Map;this.streamModelsWatcher=new ue(s.filterStreamModels(this.sortStreamModels()));this.shareStreamModels=new Map;this.shareStreamModelsWatcher=new ue(Array.from(this.shareStreamModels.values()));this.localStreamErrorWatcher=new Y;this.localModel=null;this.room=null;this.bloudStream=null;this.whiteboard=null;this.whiteboardWatcher=new ue(this.whiteboard);this.brtcStream=null;this.videoStream=null;this.audioStream=null;this.localIsShare=!1;this.isShareWatcher=new Y;this.localShareCustomStats={};this._speaker_enable=!0;this.speakerEnableWatcher=new ue(this._speaker_enable);this.mixStreamUid=null;this.mixStreamModelWatcher=new ue(null);this.canvasTimer=null;this._recorder=void 0;this._isRecording=!1;this._slicingRecord=!1;this.isRecordingWatcher=new ue(this._isRecording);this._speaker=null;this._speakers=new Map;this.speakerWatcher=new ue(this._speaker);this.rtcPublishing=!1;this.noContainerWatcher=new Y;this.noBigContainerWatcher=new Y;this.localStreamConnectErrorWatcher=new Y;this.localShareError=new Y;this.localShareEndedError=new Y;this.shareBloudStateMap=new Map;this.streamPlayWatcher=new Y;this.handleStreamPlay=e=>{this.streamPlayWatcher.next(e)};this.updateModelSort=ts(()=>{let e=this.sortStreamModels();this.streamModelsWatcher.next(s.filterStreamModels(e))},200,{maxWait:500});this.handleNoContainer=e=>{let{type:t,container:r,id:i}=e,o;t==="share"?o=this.shareStreamModels.get(i):o=this.streamModels.get(i),o&&(r==="small"?this.noContainerWatcher.next(o):this.noBigContainerWatcher.next(o))};this.getHTMLMediaStream=zr;this.getMediaStream=Xr;setTimeout(()=>{this.createCanvas(),this.canvasDisplay()},100),y.emitter.on(Ie,this.updateModelSort),y.emitter.on(oe,this.handleNoContainer),y.emitter.on(V,this.handleStreamPlay),this.muteHandlerVideo=this.muteHandler.bind(this,"video"),this.muteHandlerAudio=this.muteHandler.bind(this,"audio")}get mixStreamModel(){return this.mixStreamUid?this.streamModels.get(this.mixStreamUid):null}static filterStreamModels(e){return e.filter(t=>!t.isToupingma).filter(t=>!Be.some(r=>t.userId.includes(r))).filter(t=>t.canShow)}initWithRoom(e){return this.room=e,this}setSpeakerEnable(e){var t;this._speaker_enable!==e&&((t=this.room.audioPlayer)==null||t.mute(!e),this._speaker_enable=e,this.speakerEnableWatcher.next(e))}getStreamModels(){return Array.from(this.streamModels.values())}getStreamModelByUId(e){return this.streamModels.get(e)}getShareStreamModelByUId(e){return this.shareStreamModels.get(e)}getLocalStreamModel(){return this.localModel}createWhiteBoard(e){var r;let t=(r=this.room)==null?void 0:r.userVM.getUser(e);if(!t){p("\u521B\u5EFA\u767D\u677F\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u7528\u6237","\u521B\u5EFA\u767D\u677F",e);return}return this.whiteboard=new Pe(t,void 0,!0),this.whiteboardWatcher.next(this.whiteboard),this.whiteboard}removeWhiteBoard(){this.whiteboard=null,this.whiteboardWatcher.next(this.whiteboard)}createStreamModel(e,t){let r=new Pe(e,void 0);return t&&r.updateStream(t,!0,this),r.isShare?(e.addStream(`${e.userId}${T}`,r),this.addShareStreamModel(r)):(e.addStream(e.userId,r),this.addStreamModel(r)),r.isMixer&&(this.mixStreamUid=r.userId,this.mixStreamModel&&this.mixStreamModelWatcher.next(this.mixStreamModel)),r}addStreamModel(e){e&&(e.isLocal?this.localModel||(this.localModel=e,this.localModel.audioEnableWatcher.subscribe(t=>{this._recorder&&this._recorder.muteAudio(!t)}),this.streamModels.set(this.localModel.userId,this.localModel)):this.streamModels.set(e.userId,e))}addShareStreamModel(e){if(e){if(e.isLocal){e.audioEnable&&e.stream&&this.addToRecorder(e.stream);return}this.shareStreamModels.set(e.userId,e),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}}removeStreamModel(e){if(!e)return;e.isShare&&e.isLocal&&this.removeFromRecorder(e.stream);let t=e.getUser();this.streamModels.delete(e.userId),t.removeStream(e.userId)}removeShareStreamModelByUId(e){var r,i,o;let t=this.shareStreamModels.get(e);if(t){try{(r=t.stream)==null||r.destroy()}catch(a){}t.audioEnable&&t.stream&&((o=(i=this.room)==null?void 0:i.audioPlayer)==null||o.removeStream(t.stream)),this.removeShareStreamModel(t)}}removeShareStreamModel(e){if(!e)return;let t=e.getUser();this.shareStreamModels.delete(e.userId),t.removeStream(`${e.userId}${T}`),t.updateSortNum(!0),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}removeStreamModelByUId(e){var r,i,o;let t=this.getStreamModelByUId(e);if(t){if(t.stream){this.removeFromDetector(t.streamId);try{t.stream.destroy()}catch(a){}}t.audioEnable&&(t.stream?(i=(r=this.room)==null?void 0:r.audioPlayer)==null||i.removeStream(t.stream):(o=this.room)==null||o.audioPlayer.removeStreamByUid(e)),this.removeStreamModel(t)}return t}remoteStreamPublished(e){var a;let t=e.getStreamId(),r=e.getUserId().toString(),i=this.getStreamModelByUId(r),o;if(i||(o=Ne(String(r)),i=this.getStreamModelByUId(o)),i){if(q(e)){let n;if(o){let l=(a=this.room)==null?void 0:a.userVM.getUser(o);if(l&&!l.hasShare){I("share stream published, but user has no share","",o);return}n=this.shareStreamModels.get(o)}if(n){if(n.isLocal)return;n.hasPulled=!1,n.pulledStreamType="small",n.updateStream(e,!0,this),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}else{let l=this.createStreamModel(i.getUser(),e),u=e.getVideoOn(),m=e.getAudioOn(),h=this.shareBloudStateMap.get(i.userId);h?l.updateBloudStream({audio:h.audio,video:h.video,isScreen:!0,customInfo:h.customInfo},this):l.updateBloudStream({audio:m,video:u,isScreen:!0},this),l.streamType=2}}else i.hasPulled=!1,i.pulledStreamType="small",this.updateStreamModel(i,e);this.changeSingleStreamSpeaker(i).catch(n=>{p("\u8BBE\u7F6E\u5355\u80A1\u6D41\u7684\u626C\u58F0\u5668\u7684\u64AD\u653E\u51FA\u73B0\u4E86\u95EE\u9898","\u8BBE\u7F6E\u64AD\u653E\u97F3\u91CF",i==null?void 0:i.userId)})}else p("brtc\u6709\u4EBA\u63A8\u6D41\u4E86\uFF0C\u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel, \u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u7528\u6237","",r,["streamId => ",t,"types =>",e.getType&&e.getType()])}remoteStreamUnpublished(e){var n,l,u;let t,r=e.getUserId().toString(),i=e.getStreamId(),o=!1;if(r.includes(T)){let m=Ne(String(r));if(m==((l=(n=this.room)==null?void 0:n.getLocalParticipant())==null?void 0:l.userId)){d("\u672C\u5730\u7528\u6237\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55","\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55",r),this.localModel.getUser().removeStream(r);return}t=this.getShareStreamModelByUId(m),o=!0}else i.startsWith(rt)||e.getType&&e.getType()==="assist"?(t=this.getShareStreamModelByUId(r),o=!0):t=this.getStreamModelByUId(r);if(this.removeFromDetector(i),this.removeFromRecorder(e),!t){p("brtc\u6709\u4EBA\u53D6\u6D88\u63A8\u6D41 \u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel","\u53D6\u6D88\u63A8\u6D41",r,[i]);return}let a=(u=t.stream)==null?void 0:u.getStreamId();if(a!==i){p("\u5F53\u524D\u53D6\u6D88\u63A8\u6D41\u7684\u548C\u5F53\u524D\u7ED1\u5B9A\u7684\u4E0D\u662F\u540C\u4E00\u80A1\u6D41","",r,["streamId =>",i,"streamModel.streamId",a]);return}if(t.hasPulled=!1,t.pulledStreamType="small",o||t.streamType===2){t.updateStream(void 0,!0,this),this.removeShareStreamModel(t);return}return t.updateStream(void 0,!0,this),t}sortStreamModels(){return nr(Array.from(this.streamModels.values()))}updateStreamModel(e,t){e.updateStream(t,!0,this)}updateShareStreamModel(e,t){e.updateStream(t,!0,this)}setLocalVideoEnable(e,t){return c(this,null,function*(){var i,o,a,n,l,u,m;if(!((i=this.room)!=null&&i.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u6444\u50CF\u5934\uFF0C\u4E0D\u4E0E\u54CD\u5E94");return}if(!this.room.mediaPermission.camera)return Promise.reject(rs());let r=this.getLocalStreamModel();if(d(`\u5F00\u5173\u672C\u5730\u6444\u50CF\u5934\uFF0C \u72B6\u6001 => ${e}`,"publish",r==null?void 0:r.userId),r)if(e)if(r!=null&&r.stream){if(t)yield r.stream.replaceTrack(t).catch(f=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","",r.userId,[JSON.stringify(f)])});else{let f=(o=r==null?void 0:r.stream)==null?void 0:o.getVideoTrack(),S=r==null?void 0:r.stream.hasVideo();if(!f||(f==null?void 0:f.constructor.name)==="CanvasCaptureMediaStreamTrack"||S==!1){let b=yield this.createVideoStreamTrack().catch(M=>Promise.reject(M));yield r.stream.replaceTrack(b).then(()=>{r.stream.setVideoProfile(this.room.videoProfile),d("replace video track success")}).catch(M=>(p(`\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u89C6\u9891\u6D41\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001 => ${r==null?void 0:r.audioEnable}`,"publish",r==null?void 0:r.userId,[JSON.stringify(M)]),r!=null&&r.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(Zr())))}else{let b=f==null?void 0:f.constructor.name;if(I(`setLocalVideoEnable: no videoTrack, trackName:${b}`,"publish",r==null?void 0:r.userId),Q()){let M=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C));yield r.stream.replaceTrack(M)}}}if(yield r.stream.unmuteVideo())d("brtc unmute video success");else return p(`brtc unmuteVideo\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001=> ${r==null?void 0:r.audioEnable} hasVideo=>${r.stream.hasVideo()}`,"publish",r==null?void 0:r.userId),r!=null&&r.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(Zr());if(!this.bloudStream.published){r.isInBig&&r.playInBig(!0),yield this.publishBloudStream(!1,!0);return}yield this.bloudStream.setVideoEnabled(!0).then(()=>{r.updateStream(r.stream,!0,this),r.updateBloudStream({video:!0,audio:r.audioEnable,isScreen:!1},this),r.playInBig(!0)}).catch(f=>{p("bloud unmuteVideo\u5931\u8D25","publish","",[JSON.stringify(f)]),this.handleStreamUpdateFailed()})}else try{yield this.createStreamAndPublish(!1,!0,r,t),r.playInBig(!0)}catch(h){return this.rtcPublishing=!1,p("\u5F00\u542F\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[JSON.stringify(h)]),(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(h)}else r.stream&&(yield this.muteOrUnpublishStream("video",!0,r).catch(f=>(p("\u5173\u95ED\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[f]),Promise.reject(as(f)))))})}handleStreamUpdateFailed(e=!1){return c(this,null,function*(){var t;p("brtc unmute stream failed, now unpublish","publish",(t=this.localModel)==null?void 0:t.userId),yield this.unpublishStream(e)})}setLocalAudioEnable(e,t=!1){return c(this,null,function*(){var i;let r=this.getLocalStreamModel();if(!((i=this.room)!=null&&i.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u9EA6\u514B\u98CE\uFF0C\u4E0D\u4E0E\u54CD\u5E94","publish",r==null?void 0:r.userId);return}if(!this.room.mediaPermission.microphone)return Promise.reject(is());if(d(`\u5F00\u5173\u672C\u5730\u9EA6\u514B\u98CE\uFF0C \u72B6\u6001 => ${e}`,"publish",r==null?void 0:r.userId),r)if(e)if(r!=null&&r.stream){if(!r.stream.hasAudio()){let a=yield this.createLocalAudioStream();if(!a)return Promise.reject($t());let n=a.getAudioTrack();yield r.stream.replaceTrack(n).then(()=>{d("replace audio track success","publish",r.userId)}).catch(l=>(p("\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u97F3\u9891\u6D41\u5931\u8D25","publish",r.userId,[JSON.stringify(l)]),this.handleStreamUpdateFailed(!0),Promise.reject($t())))}if(yield r.stream.unmuteAudio().catch(a=>{var n;d("brtc unmuteAudio:err, hasAudio="+((n=r.stream)==null?void 0:n.hasAudio()),"publish","",[a])}))d("unmute audio success","publish",r.userId);else return p(`unmute local stream audio res\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${r==null?void 0:r.videoEnable} hasAudio=>${r.stream.hasAudio()}`,"publish",r==null?void 0:r.userId),r!=null&&r.videoEnable||(yield this.handleStreamUpdateFailed(!0)),Promise.reject($t());if(!this.bloudStream.published){yield this.publishBloudStream(!0,!1);return}yield this.bloudStream.setAudioEnabled(!0).then(()=>{d("bloud stream set audio enable","publish",r.userId),r.updateStream(r.stream,!1,this),r.updateBloudStream({audio:!0,video:r.videoEnable,isScreen:!1},this)}).catch(a=>{p(`bloud unmuteAudio\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${r==null?void 0:r.videoEnable}`,"publish",r==null?void 0:r.userId,[JSON.stringify(a)]),r!=null&&r.videoEnable||this.handleStreamUpdateFailed(!0)});return}else yield this.createStreamAndPublish(!0,!1,r).catch(o=>{var a,n,l,u,m;return p("\u5F00\u542F\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",r==null?void 0:r.userId,[o]),this.rtcPublishing=!1,(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(o)});else{let o=r.stream;if(o){this.removeFromDetector(o.getStreamId());try{yield this.muteOrUnpublishStream("audio",!0,r,t)}catch(a){return p("\u5173\u95ED\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",r.userId,[JSON.stringify(a)]),Promise.reject(ss(a))}}return}})}joinWithAudioAndAudio(e,t){return c(this,null,function*(){d("join with audio and video","publish","",[e,t]);let r=this.getLocalStreamModel();if(this.brtcStream){e&&(yield this.brtcStream.unmuteAudio()),t&&(yield this.brtcStream.unmuteVideo()),yield this.publishBloudStream(e,t);return}return yield this.createStreamAndPublish(e,t,r).catch(i=>{var o,a,n,l,u,m;return p("join create and publish failed","publish",(o=this.localModel)==null?void 0:o.userId,[JSON.stringify(i)]),this.rtcPublishing=!1,(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(i)})})}changeSpeaker(e,t=!1){return c(this,null,function*(){var r;if(d("change speaker","device","",[JSON.stringify(e)]),!(e!=null&&e.deviceId))throw new Yr(1e3,"\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25\uFF01,\u539F\u56E0: \u9009\u62E9\u7684\u8BBE\u5907\u6CA1\u6709deviceId"+(e==null?void 0:e.name));try{this.room.setSelectSpeakerDevice(e),(r=this.room.audioPlayer)==null||r.setDevice(e.deviceId,t)}catch(i){throw p("\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25","device","",["error",i==null?void 0:i.message,JSON.stringify(i)]),new Yr(1e3,"\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25")}})}changeSingleStreamSpeaker(e){return c(this,null,function*(){let t=this.room.selectAudioOutputDevice;t&&(e.isLocal||e.stream&&(yield e.stream.setAudioOutput(t.deviceId)))})}changeAudioInput(e){return c(this,null,function*(){var r,i,o,a,n;d("change audio input device","device","",[JSON.stringify(e)]),e||I("changeAudioInput, device is null","device");let t=(r=this.localModel)==null?void 0:r.stream;if((i=this.room)==null||i.setSelectAudioDevice(e),t)return((o=t.getAudioTrack())==null?void 0:o.readyState)==="ended"&&!((a=this.room)!=null&&a.deviceChanging)?(p("try to change audio input device but audio track is ended","device"),!1):(yield t.switchDevice("audio",e.deviceId).catch(u=>{d("switchDevice:error","device","",[JSON.stringify(u)])}),(n=this._recorder)==null||n.setMicDevice(e.deviceId),!0)})}changeVideoInput(e){return c(this,null,function*(){var r,i,o,a;d("change video input device","device","",[JSON.stringify(e)]);let t=(r=this.localModel)==null?void 0:r.stream;if((i=this.room)==null||i.setSelectVideoDevice(e),t)return((o=t.getVideoTrack())==null?void 0:o.readyState)==="ended"?(p("try to change video input device but video track is ended","device"),!1):(yield t.switchDevice("video",e.deviceId).catch(l=>{d("switchDevice:error","device","",[l])}),(a=this.localModel)!=null&&a.isDisplay&&this.localModel.isInBig&&this.localModel.playInBig(!0),!0)})}muteSpeaker(e){return c(this,null,function*(){d("\u9759\u97F3\u626C\u58F0\u5668 \u72B6\u6001 =>","device","",["status =>",e]);try{this.setSpeakerEnable(e)}catch(t){return Promise.reject(os(`\u5F00\u5173\u626C\u58F0\u5668\u5931\u8D25 ${e} error: ${JSON.stringify(t)}`))}})}createLocalAudioStream(){return c(this,null,function*(){return this.audioStream?this.audioStream:(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId).catch(e=>(p("create brtc stream error","publish","",[JSON.stringify(e)]),Promise.reject(e))),this.audioStream)})}onlyBrtcPublish(){return c(this,null,function*(){let e=this.localModel,t=!!Q();return this.audioStream=yield this.room.createSingleLocalStream({video:t,audio:!0},e.userId).catch(r=>(p("create brtc stream error","publish","",[JSON.stringify(r)]),Promise.reject(r))),this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:!1,video_enable:!1},e.userId),d("onlyBrtcPublish","publish",e.userId),this.createStreamAndPublish(!1,!1,e).catch(r=>(this.rtcPublishing=!1,Promise.reject(r)))})}createStreamAndPublish(e,t,r,i){return c(this,null,function*(){var o,a,n,l,u,m,h,f,S;if(this.rtcPublishing)return I(`createStreamAndPublish(audio:${e},video:${t}), rtcPublishing ignore`,"publish",r.userId),!1;if(this.rtcPublishing=!0,d(`createStreamAndPublish(audio:${e},video:${t})`,"publish",r.userId),(o=this.brtcStream)!=null&&o.published&&(yield(a=this.room)==null?void 0:a.unpublish(this.brtcStream)),t)if((u=this.brtcStream)==null||u.destroy(),this.brtcStream=null,(m=this.room)!=null&&m.audioDevices.length||(p("\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709\u97F3\u9891\u8F93\u5165\u8BBE\u5907\uFF0C\u91CD\u65B0\u83B7\u53D6","publish"),yield(h=this.room)==null?void 0:h.initDevices()),(f=this.room)!=null&&f.videoDevices.length||(p("\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709\u89C6\u9891\u8F93\u5165\u8BBE\u5907, \u91CD\u65B0\u83B7\u53D6","publish"),yield(S=this.room)==null?void 0:S.initDevices()),this.room.audioDevices.length>0)try{this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:this.room.mediaPermission.microphone},r.userId).catch(b=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)))}catch(b){d("create brtc audio and video stream failed, recreate brtc stream with audio close and video open"),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!1},r.userId).catch(M=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(M)]),Promise.reject(M)))}else I("\u6CA1\u6709\u97F3\u9891\u8F93\u5165\u8BBE\u5907\uFF0C\u53EA\u80FD\u521B\u5EFA\u89C6\u9891\u6D41","publish"),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!1},r.userId).catch(b=>(p("create brtc video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)));else{let M=s.getCanvasStream().getVideoTracks()[0];this.audioStream||(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},r.userId).catch(E=>(p("create brtc stream error","publish","",[JSON.stringify(E)]),Promise.reject(E))));let C=(n=this.audioStream)==null?void 0:n.getAudioTrack();if(!C||C&&C.muted)throw(l=this.audioStream)==null||l.destroy(),this.audioStream=null,this.localStreamErrorWatcher.next("audio"),p("\u9EA6\u514B\u98CE\u8BBE\u5907\u4E0D\u53EF\u7528","publish","",["muted => ?",C==null?void 0:C.muted]),ns("\u9EA6\u514B\u98CE");this.brtcStream=null,this.room.videoDevices.length==0?(I("\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709\u89C6\u9891\u8F93\u5165\u8BBE\u5907, createSingleLocalStream video:false","publish",r.userId),this.brtcStream=this.audioStream):Q()?this.brtcStream=this.audioStream:this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:M,audioSource:C},r.userId).catch(E=>Promise.reject(E))}return this.brtcStream&&(t||(yield this.brtcStream.muteVideo()),e||(yield this.brtcStream.muteAudio()),i&&(yield this.brtcStream.replaceTrack(i).catch(b=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","publish","",JSON.stringify(b))})),yield this.room.publish(this.brtcStream).catch(b=>{var M,C;return(M=this.brtcStream)==null||M.destroy(),this.brtcStream=null,(C=this.localModel)==null||C.updateBloudStream(void 0,this),Promise.reject(b)}),this.brtcStreamAddEvent(),(e||t)&&(yield this.publishBloudStream(e,t))),this.rtcPublishing=!1,!0})}brtcStreamAddEvent(){var e,t,r,i;(e=this.brtcStream)==null||e.on("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.on("video-track-ended"+Z,this.muteHandlerVideo),(r=this.brtcStream)==null||r.on("audio-track-mute"+Z,this.muteHandlerAudio),(i=this.brtcStream)==null||i.on("audio-track-ended"+Z,this.muteHandlerAudio)}brtcStreamRemoveEvent(){var e,t,r,i;(e=this.brtcStream)==null||e.off("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.off("video-track-ended"+Z,this.muteHandlerVideo),(r=this.brtcStream)==null||r.off("audio-track-mute"+Z,this.muteHandlerAudio),(i=this.brtcStream)==null||i.off("audio-track-ended"+Z,this.muteHandlerAudio)}publishBloudStream(e,t){return c(this,null,function*(){var i;let r=this.localModel.userId;this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:e,video_enable:t},r),yield this.bloudStream.publish({video_enable:t,audio_enable:e}),(i=this.localModel)==null||i.updateBloudStream({video:t,audio:e,isScreen:!1},this)})}muteHandler(e){var a,n,l;let t=()=>c(this,null,function*(){var u,m,h,f,S,b,M,C,E;(u=this.localModel)!=null&&u.stream&&(yield(m=this.room)==null?void 0:m.unpublish(this.localModel.stream).catch(L=>{p("brtc local stream has problem and unpublish failed","publish","",[String(L)])})),(f=(h=this.localModel)==null?void 0:h.stream)==null||f.destroy(),(S=this.audioStream)==null||S.destroy(),(b=this.videoStream)==null||b.destroy(),(M=this.brtcStream)==null||M.destroy(),this.brtcStream=null,this.audioStream=null,this.videoStream=null,(C=this.localModel)==null||C.updateStream(void 0,!0,this),yield this.bloudStream.unpublish(),(E=this.localModel)==null||E.updateBloudStream(void 0,this)}),r=(a=this.localModel)==null?void 0:a.videoEnable,i=(n=this.localModel)==null?void 0:n.audioEnable,o=(l=this.brtcStream)==null?void 0:l.getAudioDeviceId();if(!r&&!i){d("muteHandler:\u97F3\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}setTimeout(()=>c(this,null,function*(){var u,m,h,f,S,b,M,C,E,L,W,G,j,F,$,ee,te,Te,xe,Le;if((u=this.localModel)!=null&&u.stream){let re=(m=this.localModel)==null?void 0:m.videoEnable,ie=(h=this.localModel)==null?void 0:h.audioEnable;if(o!=((f=this.localModel)==null?void 0:f.stream.getAudioDeviceId())){d("muteHandler:\u8BBE\u5907\u5DF2\u7ECF\u5207\u6362\u65E0\u9700\u5904\u7406","publish");return}if((S=this.room)!=null&&S.deviceChanging){d("muteHandler:\u8BBE\u5907\u6B63\u5728\u5207\u6362\u4E2D","publish");return}if(e==="video"){if(!re){d("muteHandler:\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}let _=(b=this.localModel.stream.getVideoTrack())==null?void 0:b.muted,de=(M=this.localModel.stream.getVideoTrack())==null?void 0:M.label,Oe=(C=this.localModel.stream.getVideoTrack())==null?void 0:C.enabled,A=(E=this.localModel.stream.getVideoTrack())==null?void 0:E.readyState,J=A==="ended";if(d(`muteHandler:brtc video track status:${_},enabled:${Oe},readyState:${A},label:${de} `,"publish",""),!J&&!_&&Oe)return;d("video track has problem, now try recreate and publish","publish"),p("brtc\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38\uFF0C\u9700\u8981\u91CD\u65B0\u63A8\u6D41\u5904\u7406","publish","",["videoEnable:",re,"audioEnable:",ie,"type:",e]),this.localStreamConnectErrorWatcher.next(Kr("\u6444\u50CF\u5934")),(L=this.localModel)!=null&&L.stream&&(yield(W=this.room)==null?void 0:W.unpublish(this.localModel.stream).catch(Et=>{p("brtc local stream has problem and unpublish failed","publish","",[String(Et)])}),(G=this.localModel)==null||G.updateStream(void 0,!0,this),(F=(j=this.localModel)==null?void 0:j.stream)==null||F.destroy(),($=this.localModel.player)==null||$.destroy(),(ee=this.brtcStream)==null||ee.destroy(),this.brtcStream=null,(te=this.videoStream)==null||te.destroy(),this.videoStream=null);try{yield this.createStreamAndPublish(ie,re,this.localModel),this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}catch(Et){this.rtcPublishing=!1,p("brtc video stream has problem and republish stream failed","publish","",[JSON.stringify(Et)]),yield t(),this.localStreamConnectErrorWatcher.next(Jt())}}else{if(!ie){console.log("muteHandler:\u97F3\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}p("brtc\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38\uFF0C\u9700\u8981\u91CD\u65B0\u63A8\u6D41\u5904\u7406","publish","",["videoEnable",re,"audioEnable",ie,"type",e]),this.localStreamConnectErrorWatcher.next(Kr("\u9EA6\u514B\u98CE")),(Te=this.audioStream)==null||Te.destroy(),(xe=this.localModel.player)==null||xe.destroy(),this.audioStream=null,this.audioStream=yield this.room.createPBSingleLocalStream({video:!1,audio:!0});let _=(Le=this.audioStream)==null?void 0:Le.getAudioTrack();_&&!_.muted?this.localModel.stream&&(yield this.localModel.stream.replaceTrack(_).then(()=>{this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}).catch(de=>{p("\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38, \u91CD\u65B0\u521B\u5EFAaudio stream replace \u5931\u8D25","publish","",[JSON.stringify(de)]),this.localStreamConnectErrorWatcher.next(Jt()),t()})):(p("recreate audio stream failed, now unpublish","publish"),this.localStreamConnectErrorWatcher.next(Jt()),t())}}this.localStreamErrorWatcher.next(e)}),1e3)}unpublishStream(e=!1){return c(this,null,function*(){var r,i,o,a,n,l,u;d("unpublish stream","publish",(r=this.localModel)==null?void 0:r.userId);let t=this.getLocalStreamModel();if(t){let m=t.stream;m&&e===!0&&(yield(i=this.room)==null?void 0:i.unpublish(m).catch(h=>{p("brtc \u53D6\u6D88\u53D1\u5E03\u5931\u8D25","publish",t.userId,[JSON.stringify(h)])}),m==null||m.destroy(),(o=this.localModel)==null||o.updateStream(void 0,!0,this),(a=this.audioStream)==null||a.destroy(),(n=this.brtcStream)==null||n.destroy(),this.brtcStream=null,this.audioStream=null);try{this.removeFromRecorder(m),(l=this.videoStream)==null||l.destroy(),this.videoStream=null,(u=this.bloudStream)!=null&&u.published&&(yield this.bloudStream.unpublish().catch(h=>{p("bloud unpublish stream failed","publish",t.userId,[JSON.stringify(h),h==null?void 0:h.code,h==null?void 0:h.message])})),t.updateBloudStream(void 0,this)}catch(h){p("stream destroy failed","publish",t.userId,[JSON.stringify(h)])}}})}muteOrUnpublishStream(e,t,r,i=!1){return c(this,null,function*(){let o=r.stream,a=!0;e==="audio"?a=r.videoEnable:e==="video"&&(a=r.audioEnable),a?e==="audio"?((yield o.muteAudio())||p("brtc muteAudio\u5931\u8D25","publish","\u672C\u5730",["muteAudio\u5931\u8D25"]),yield this.bloudStream.setAudioEnabled(!1).catch(l=>{p("bloud setAudioEnabled \u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(l)])}),r.updateBloudStream({audio:!1,video:!0,isScreen:!1},this)):e==="video"&&(yield this.justReplaceVideoTrack(o),yield this.bloudStream.setVideoEnabled(!1).catch(n=>{p("bloud setVideoEnabled \u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(n)])}),r.updateBloudStream({video:!1,audio:!0,isScreen:!1},this)):(e=="video"?this.justReplaceVideoTrack(o):e=="audio"&&((yield o.muteAudio())||p("brtc muteAudio\u5931\u8D25","publish","\u672C\u5730")),yield this.unpublishStream(i))})}justReplaceVideoTrack(e){return c(this,null,function*(){var i;let r=s.getCanvasStream().getVideoTracks()[0];try{yield e.replaceTrack(r),yield e.muteVideo()}catch(o){p("\u5173\u95ED\u672C\u5730\u89C6\u9891\u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(o)])}try{(i=this.videoStream)==null||i.destroy(),this.videoStream=null}catch(o){p("this.videoStream destroy failed","publish")}})}toggleShareScreen(i){return c(this,arguments,function*(e,t={},r){var a,n,l,u,m;d("\u5F00\u5173\u5171\u4EAB\u5C4F\u5E55","publish","\u5F00\u5173\u5171\u4EAB\u5C4F\u5E55",["stats => ",e]),!e&&((a=this.room)!=null&&a.boomCore.shareScreenStream)&&this.removeFromRecorder((n=this.room)==null?void 0:n.boomCore.shareScreenStream),e||(this.localShareCustomStats={});let o=(l=this.room)==null?void 0:l.voiceMode;return t.audioHint=o,yield this.room.boomCore.toggleShareScreen(e,t,r).then(()=>{if(this.localModel.getUser().hasShare=!0,d("bmStreamVm toggleShareScreen success","\u5207\u6362\u5171\u4EAB\u5C4F\u5E55","",["enable =>",e]),e){let h=this.room.boomCore.shareScreenStream;h&&this.remoteStreamPublished(h)}else this.localModel.getUser().hasShare=!1,this.localModel.getUser().removeStream(`${this.localModel.userId}_screen`),this.localModel.getUser().updateSortNum(!0)}).catch(h=>(p("bmStreamVm toggleShareScreen error","\u5207\u6362\u5171\u4EAB\u5C4F\u5E55","",["enable =>",e]),Promise.reject(h))),e&&((u=this.room)!=null&&u.boomCore.shareScreenStream)&&this.addToRecorder((m=this.room)==null?void 0:m.boomCore.shareScreenStream),this.localIsShare=e,this.isShareWatcher.next(e),Promise.resolve(!0)})}setShareScreenContentHint(e){var t;(t=this.room)==null||t.boomCore.setShareScreenContentHint(e)}createCanvas(){let e=document.createElement("canvas");e.id="tarCanvas",e.style.width="1px",e.style.height="1px",e.style.position="absolute",e.style.bottom="0",document.body.appendChild(e)}canvasDisplay(){let e=document.getElementById("tarCanvas");if(e){e.width=640,e.height=360;let t=e.getContext("2d");t.fill(),t.beginPath(),t.fillStyle="rgb(0,0,0)",t.fillRect(0,0,e.width,e.height),this.canvasTimer&&clearTimeout(this.canvasTimer),this.canvasTimer=setTimeout(()=>{this.canvasDisplay()},1e3)}}static getCanvasStream(){return document.getElementById("tarCanvas").captureStream()}createVideoStreamTrack(){return c(this,null,function*(){var e;return(e=this.videoStream)==null||e.destroy(),this.videoStream=null,this.videoStream=yield this.room.createPBSingleLocalStream({video:!0,audio:!1},this.localModel.userId).catch(t=>(p("createPBSingleLocalStream error","publish","",[JSON.stringify(t)]),Promise.reject(t))),this.videoStream.getVideoTrack()})}startRecord(e){return c(this,null,function*(){var r;if(this._recorder)return;this._recorder=(r=this.room)==null?void 0:r.boomCore.createRecorder(e),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record: ended","record")}),this._recorder.on("started",()=>{var i;d("record: started.","record"),this._recorder.muteAudio(!((i=this.localModel)!=null&&i.audioEnable))});let t=!0;try{yield this._recorder.start(),this._isRecording=!0,this.isRecordingWatcher.next(!0),this.shareStreamModels.forEach(i=>{i.stream&&!i.stream.isLocalStream()&&i.stream.isSubscribed()&&this.addToRecorder(i.stream)}),this.streamModels.forEach(i=>{i.stream&&!i.stream.isLocalStream()&&i.stream.isSubscribed()&&this.addToRecorder(i.stream)})}catch(i){I("record: error","record","",[JSON.stringify(i)]);let o=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),t=!1,yield o==null?void 0:o.stop()}return t})}addToRecorder(e){var t;e.isLocalStream()&&!e.isScreenStream()||this._isRecording&&!this._slicingRecord&&(e.on("audio-track-ended",()=>{this.removeFromRecorder(e)}),(t=this._recorder)==null||t.addStream(e))}removeFromRecorder(e){var t;this._isRecording&&!this._slicingRecord&&((t=this._recorder)==null||t.removeStream(e))}stopRecord(){return c(this,null,function*(){if(d("record:stopRecord","record"),!this._recorder){I("stopRecord recorder is null","record","");return}this._isRecording=!1,this.isRecordingWatcher.next(!1),yield this._recorder.stop(),this._recorder=void 0})}sliceRecord(e,t,r){return c(this,null,function*(){var a,n,l;if(!this._isRecording)return;let i=(a=this._recorder)==null?void 0:a._opts;this._slicingRecord=!0;try{yield(n=this._recorder)==null?void 0:n.stop()}catch(u){p("record:stop record exception","","",[JSON.stringify(u)])}i.filename=e,this._recorder=(l=this.room)==null?void 0:l.boomCore.createRecorder(i),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record:record ended.")}),this._recorder.on("started",()=>{var u;d("record:record started."),this._recorder.muteAudio(!((u=this.localModel)!=null&&u.audioEnable))});let o=!0;try{yield this._recorder.start(t,r),this._slicingRecord=!1,this.shareStreamModels.forEach(u=>{u.stream&&!u.stream.isLocalStream()&&u.stream.isSubscribed()&&this.addToRecorder(u.stream)}),this.streamModels.forEach(u=>{u.stream&&!u.stream.isLocalStream()&&u.stream.isSubscribed()&&this.addToRecorder(u.stream)})}catch(u){let m=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),this._slicingRecord=!1,o=!1,console.log("record:stopRecord.error",u),yield m==null?void 0:m.stop()}return o})}startSpeakerDetector(){var e;this._speaker=null,this._speakerDetector=(e=this.room)==null?void 0:e.boomCore.createSpeakerDetector(),this._speakerDetector.on("speaker",t=>{var i,o,a;let r=!0;t?(((i=this._speaker)==null?void 0:i.getUserInfo().userId)===t.getUser().userId&&(r=!1),this._speaker=t.getUser()):(this._speaker||(r=!1),this._speaker=null),r&&(d("\u5F53\u524D\u8BB2\u8BDD\u4EBA","\u8BED\u97F3\u6FC0\u52B1",(o=this._speaker)==null?void 0:o.userId,["nickname => ",(a=this._speaker)==null?void 0:a.nickname]),this.speakerWatcher.next(this._speaker))})}addToDetector(e){this._speakers.set(e.getID(),e),this._speakerDetector&&this._speakerDetector.addStream(e)}removeFromDetector(e){let t=this._speakers.get(e);this._speakerDetector&&t&&(this._speakers.delete(e),this._speakerDetector.removeStream(t))}clearDetector(){let e=[];this._speakers.forEach((t,r)=>{e.push(r)}),e.forEach(t=>{this.removeFromDetector(t)})}shareCustomMedia(e,t){return c(this,null,function*(){var r;return(r=this.room)==null?void 0:r.boomCore.shareHTMLMedia(e,t)})}updateBloudStreamCustomStats(e,t,r){return c(this,null,function*(){var o,a;d("update bloud stream custom stats","",e,[t,JSON.stringify(r)]);let i=yield(o=this.room)==null?void 0:o.boomCore.updateStream(e,t,r);((a=this.localModel)==null?void 0:a.userId)===e&&t.startsWith(e)&&t.endsWith("_screen")&&i.customInfo&&(this.localShareCustomStats=i.customInfo)})}checkStreamStats(e){d("check stream stats","","",[e]),this.streamModels.size<100&&this.streamModels.forEach(t=>{t.checkStreamIsPlaying()})}clearCache(){var e,t,r,i,o;try{(t=(e=this.localModel)==null?void 0:e.stream)==null||t.destroy(),(r=this.videoStream)==null||r.destroy(),(i=this.audioStream)==null||i.destroy()}catch(a){}this.canvasTimer&&clearTimeout(this.canvasTimer),this.canvasTimer=null,this.streamModels.clear(),this.shareStreamModels.clear(),(o=this.room)==null||o.userVM.clearUsers(),this.shareBloudStateMap.clear()}};import{BehaviorSubject as K,Subject as It}from"rxjs";import{debounce as Qt}from"lodash-es";var Ye=class{constructor(e){this._roomName="";this.msgSeq="";this.roomID="";this.audioOff=!1;this.selfopenaudio=!1;this.lock=!1;this.leaveNotice=!1;this.openSelf=!1;this.chatNotice="";this.chatNoticeRich="";this.raiseHandsList=new Map;this.raiseHandsWatcher=new K(Array.from(this.raiseHandsList.values()));this.raiseVideoHandsList=new Map;this.raiseVideoHandsWatcher=new K(Array.from(this.raiseVideoHandsList.values()));this.raiseSimpleHandsList=new Map;this.raiseSimpleHandsWatcher=new K(Array.from(this.raiseSimpleHandsList.values()));this.operationPermissionWatcher=new It;this.chatNoticeWatcher=new It;this.totalUserWatcher=new K(0);this.totalWaitRoomUserWatcher=new K(0);this.isOpenWaitRoom=new It;this.originJoinRoomParams={};this.originRespInfo={};this.audioOffWatcher=new It;this.lockWatcher=new K(this.lock);this.leaveNoticeWatcher=new K(this.leaveNotice);this.openSelfWatcher=new K(this.openSelf);this.setRaiseHandsWatcherValue=Qt(()=>{this.raiseHandsWatcher.next(Array.from(this.raiseHandsList.values()))},1e3);this.setVideoRaiseHandsWatcherValue=Qt(()=>{this.raiseVideoHandsWatcher.next(Array.from(this.raiseVideoHandsList.values()))},1e3);this.setSimpleRaiseHandsWatcherValue=Qt(()=>{this.raiseSimpleHandsWatcher.next(Array.from(this.raiseSimpleHandsList.values()))},1e3);this.room=e,y.emitter.on(O,t=>{t.status==="raiseHandsAudio"?t.user.raiseAudioHands?this.addRaiseHandUser(t.user):this.removeRaiseHandUser(t.user.userId):t.status==="raiseHandsVideo"?t.user.raiseVideoHands?this.addVideoRaiseHandUser(t.user):this.removeVideoRaiseHandUser(t.user.userId):t.status==="raiseHand"&&(t.user.raiseHand?this.addSimpleRaiseHandUser(t.user):this.removeSimpleRaiseHandUser(t.user.userId))})}get roomName(){return this._roomName?this._roomName:(this._roomName=this.room.getName(),this._roomName)}get isBigRoom(){return this.room.isBig}get startup(){var e;return(e=this.room.boomCore.client)==null?void 0:e.startup}setup(e){this.roomID=e.room,this.handleInitParams(),this.originRespInfo=e}initCustomStats(e){this.operationPermission=e,e.chatNotice!==void 0&&(this.chatNotice=e.chatNotice),e.chatNoticeRich!==void 0&&(this.chatNoticeRich=e.chatNoticeRich),this.operationPermissionWatcher.next(this.operationPermission)}updateOperationPermission(e){this.operationPermission=P(P({},this.operationPermission),e),e.chatNotice!==void 0&&(this.chatNotice=e.chatNotice),e.chatNoticeRich!==void 0&&(this.chatNoticeRich=e.chatNoticeRich),this.operationPermissionWatcher.next(this.operationPermission)}handleInitParams(){let e=this.room.boomCore.getAudioOff(),t=this.room.boomCore.getSelfOpenAudio();this.setAudioOff(e,t)}setAudioOff(e,t){this.audioOff=e,this.selfopenaudio=t,this.audioOffWatcher.next({audioOff:e,selfopenaudio:t})}setlock(e){this.lock=e,this.lockWatcher.next(e)}setLeaveNotice(e){this.leaveNotice=e,this.leaveNoticeWatcher.next(e)}setRaiseHandsList(e){e.forEach(t=>{t.raiseAudioHands&&this.raiseHandsList.set(t.getID(),t),t.raiseVideoHands&&this.raiseVideoHandsList.set(t.getID(),t),t.raiseHand&&this.raiseSimpleHandsList.set(t.getID(),t)}),this.setRaiseHandsWatcherValue(),this.setVideoRaiseHandsWatcherValue(),this.setSimpleRaiseHandsWatcherValue()}addRaiseHandUser(e){this.raiseHandsList.set(e.getID(),e),this.setRaiseHandsWatcherValue()}removeRaiseHandUser(e){this.raiseHandsList.delete(e),this.setRaiseHandsWatcherValue()}addVideoRaiseHandUser(e){this.raiseVideoHandsList.set(e.getID(),e),this.setVideoRaiseHandsWatcherValue()}removeVideoRaiseHandUser(e){this.raiseVideoHandsList.delete(e),this.setVideoRaiseHandsWatcherValue()}addSimpleRaiseHandUser(e){this.raiseSimpleHandsList.set(e.getID(),e),this.setSimpleRaiseHandsWatcherValue()}removeSimpleRaiseHandUser(e){this.raiseSimpleHandsList.delete(e),this.setSimpleRaiseHandsWatcherValue()}};import{BehaviorSubject as yt,Subject as D}from"rxjs";var qt={name:"@hysc/meeting",version:"10.7.1",description:"boom meeting",private:!1,main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",files:["dist","umd"],scripts:{build:"tsup ./src/index.ts --format cjs,esm --dts --minify",dev:"tsup ./src/index.ts --format esm,cjs --watch --dts"},author:"yangliye",license:"MIT",dependencies:{"@hysc/bloud":"workspace:*","@hysc/core":"workspace:*","@hysc/p-queue":"6.3.0","@hysc/utils":"workspace:*","detect-browser":"^5.3.0",immutable:"5.0.0-beta.4","lodash-es":"^4.17.21",mitt:"^3.0.0",rxjs:"^7.5.5",typescript:"^4.6.3"},peerDependencies:{"@hysc/core":"workspace:*"},devDependencies:{"@hysc/brtc":"workspace:*","@types/lodash-es":"^4.17.6"}};import{Logger as si,LOGLEVEL as bs}from"@hysc/utils";var Ze=class{constructor(e){this.pullMap=new Map;this.room=e}addUser(e){let t=e.id;e.isScreen&&(t=`${t}_screen`),this.pullMap.set(t,e)}removeUser(e){let t=e.id;e.isScreen&&(t=`${t}_screen`),this.pullMap.delete(t)}restart(){this.room.restartPullUsers(this.pullMap)}};import{BMCameraNotAuthError as Is,BMCameraOccupyError as ys,BMCreateStreamError as Es,BmLeaveError as Ms,BMMicNotAuthError as Cs,BMMicOccupyError as vs,BmSetAudioOffError as Bs,BmSetMsgOffError as As,BmSetVideoOffError as Rs,BMShareStreamConnectError as Us,BMStreamConnectError as Ps,BMStreamReconnectFailed as Ns,BMStreamReconnectSuccess as ws,BmUpdateCustomStatsError as Ts,getStreamError as xs,RepeatJoinError as Ls}from"@hysc/utils";var zt=class{constructor(e){this.room=e}get localBMUser(){return this.room.getLocalParticipant()}get localIsAudience(){return this.room.getLocalParticipant().isAudience}handlePull(e){return c(this,null,function*(){if(this.localIsAudience){if(e.isMixer){if(this.room.ignoreMixer){d(" \u914D\u7F6E\u4E86\u4F7F\u7528 CDN\u6D41\uFF0C\u4E0D\u62C9\u6DF7\u6D41 handlePull ignore mixer");return}yield this.room.handlePull(e);return}if(this.localBMUser.audienceEnableSpeaking&&e.audioEnable){yield this.room.handlePull(e);return}}else e.isMixer||(yield this.room.handlePull(e))})}handleChangeStreamType(e){return c(this,null,function*(){yield this.room.handleChangeStreamType(e)})}handlePlay(e,t){return c(this,null,function*(){this.localIsAudience&&!this.localBMUser.audienceEnableSpeaking?e.isMixer&&(yield this.room.handlePlay(e)):yield this.room.handlePlay(e)})}handleAudienceDisable(e){return c(this,null,function*(){this.room.bmStreamVm.getStreamModels().forEach(t=>{var r;t.isMixer||!t.isLocal&&t.stream&&((r=t.stream)!=null&&r.isSubscribed())&&t.hasPulled&&(t.hasPulled=!1,t.pulledStreamType="small",this.room.unsubscribe(t.stream).then(()=>{console.log("\u89C2\u4F17\u53D6\u6D88\u8BA2\u9605\u8FD9\u80A1\u6D41",t.userId,t.nickname,t.isDisplay,t.isCurrentDisplay)}))}),this.handleMixStream(!1,e)})}handleAudienceEnable(e){return c(this,null,function*(){this.handleMixStream(!0,e),this.room.bmStreamVm.getStreamModels().forEach(t=>{t.isMixer||k.addQueue(this.room.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)})})}handleMixStream(e,t){return c(this,null,function*(){var i,o;let r=this.room.bmStreamVm.mixStreamUid;if(r){let a=this.room.bmStreamVm.streamModels.get(r);e?(i=a==null?void 0:a.stream)==null||i.muteAudio().then(()=>{d(`play:\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${r}`)}):this.room.ignoreMixer||(o=a==null?void 0:a.stream)==null||o.unmuteAudio().then(()=>{d(`play:\u53D6\u6D88\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${r}`)})}t==null||t(e)})}},ei=zt;import{debounce as oi,isNumber as Os,toNumber as ai,delay as ks}from"lodash-es";import{BrtcEvents as ti}from"@hysc/utils";function ri(s){var r,i;let e=()=>s.fire(ti.BRTC_ROOM_ROCONNECTING),t=()=>s.fire(ti.BRTC_ROOM_RECONNECTED);(r=s.brtcClient.client)==null||r.signal.channel.on("reconnecting",e),(i=s.brtcClient.client)==null||i.signal.channel.on("reconnected",t)}import{AudioPlayer as cs}from"@hysc/core";import{Subject as us}from"rxjs";var Ke=class{constructor(e,t){this.playMap=new WeakSet;this.playerMap=new Map;this.muted=!1;this.playStateChangeWatcher=new us;var i;let r=document.getElementById(e);if(r)this.container=r;else throw new Error("no container found, play failed");this.room=t,this.deviceId=(i=t.selectAudioOutputDevice)==null?void 0:i.deviceId}addStream(e,t=!1){let r=this.room.localUser,i=r.audienceEnableSpeaking;if(r.isAudience)if(i){if(!(e.getUserId().toString()+"".includes("-mixer-"))){d("audienceEnableSpeaking is true, only play mixer stream","",e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}}else{I("audienceEnableSpeaking is false, not play audio","",e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}this.room.shouldPlayAudio&&this.room.autoPlayAudio&&e.isSubscribed()&&(t||!this.playMap.has(e))&&(d("add stream to player","",e.getUserId(),["streamId ",e.getStreamId()]),this.playMap.add(e),this.play(e))}removeStream(e){let t=e.getStreamId(),r=this.playerMap.get(t);r&&r.destroy(),d("remove audio player","","",["streamId =>",t]),this.playerMap.delete(t),this.playMap.delete(e)}removeStreamByUid(e){let t=new Map;this.playerMap.forEach(r=>{q(r.stream)||r.stream.getUserId()===e&&t.set(r.stream.getStreamId(),r)}),t.forEach((r,i)=>{r.off(),r.destroy(),this.playerMap.delete(i),this.playMap.delete(r.stream)}),t.clear()}play(e){return c(this,null,function*(){var t;if(e.hasAudio()&&this.container){let r=new cs(this.container,{});this.addPlayerEvent(r),yield r.play(e);let i=Ne(e.getUserId().toString());if(this.deviceId?yield r.setSinkId(this.deviceId):(I("audioPlayer play() this.deviceId is null ","",i,["streamId =>",e.getStreamId()]),Q()&&(yield r.setSinkId("default"))),this.muted)r.setVolume(0);else{let o;if(q(e)?o=this.room.bmStreamVm.shareStreamModels.get(i):o=this.room.bmStreamVm.streamModels.get(i),o){let a=(t=o.bloudStream)==null?void 0:t.customInfo;a&&a.volume&&(r.audioLevel=a.volume,r.setVolume(a.volume))}}this.playerMap.set(e.getStreamId(),r)}})}mute(e){this.muted=e,e?this.playerMap.forEach(t=>t.setVolume(0)):this.playerMap.forEach(t=>{t.audioLevel>0?t.setVolume(t.audioLevel):t.setVolume(1)})}setVolume(e,t){let r=this.playerMap.get(e);if(r){if(r.audioLevel=t,this.muted)return;r.setVolume(t)}else p("\u8BBE\u7F6E\u4E86\u6D41\u7684\u97F3\u91CF\uFF0C\u4F46\u662F\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u64AD\u653E\u5668",e)}setDevice(e,t=!1){return c(this,null,function*(){d("setDevice:","","",[e]),e&&(this.deviceId=e,this.playerMap.forEach(r=>r.setSinkId(e)))})}addPlayerEvent(e){e.on("player-state-changed",t=>{e.stream&&(d("audio player state change","","",[JSON.stringify(t)]),t.type==="error"&&t.reason&&t.reason.name==="NotAllowedError"&&this.playStateChangeWatcher.next(e),t.state==="PAUSED"&&e.resume())})}clear(){d("audio play clear"),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}destroy(){d("audio play destroy"),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}};var Mt=1,Ds={audio:!0,video:!0,streamType:"small",videoEnable:!0,audioEnable:!0},ze=!0,we=class{constructor({initDevices:e,ignoreMixer:t}={initDevices:!0,ignoreMixer:!1}){this.roomVM=null;this.videoDevices=[];this.audioDevices=[];this.audioOutputDevices=[];this.selectVideoDevice=null;this.selectAudioDevice=null;this.selectAudioOutputDevice=null;this.streamQueue=new Ze(this);this.userListColumns=1;this.sortType=1;this.BRTCConnectFailed=!1;this.pubFailedNum=0;this.streamConnectedErrorQueue=[];this.conferenceMode=1;this.isBig=!1;this.selectVideoDeviceWatcher=new yt(this.selectVideoDevice);this.selectAudioDeviceWatcher=new yt(this.selectAudioDevice);this.selectAudioOutputDeviceWatcher=new yt(this.selectAudioOutputDevice);this.audioDevicesWatcher=new D;this.videoDevicesWatcher=new D;this.audioOutputDevicesWatcher=new D;this.raiseHandleRespWatcher=new D;this.enableAudienceSpeakingWatcher=new D;this.deviceChangeWatcher=new D;this.mediaPermission={microphone:!0,camera:!0,screen:!0};this.videoProfile="360p";this.audioProfile=null;this.voiceMode="";this.videoEncodeConfig=null;this.streamWSReconnectWatcher=new D;this.bloudWSReconnectWatcher=new D;this.netConnecting=!0;this.netConnectingWatcher=new D;this.hasSyncPermission=!0;this.meetingControlOptions={cancelAutoPull:!1};this.forceId="";this.networkState={bloud:!0,brtc:!0};this.brtcNetEnableWatcher=new D;this.autoPlayAudio=!0;this.pubFailedTimer=null;this.messageWatcher=new yt({type:"init",status:!1,isNotCancelRootReport:!1});this.isInWaitRoom=!1;this.shouldPlayAudio=!0;this.deviceChanging=!1;this.ignoreMixer=!1;this.handleReprocessStreamError=()=>{this.netConnecting&&this.networkState.brtc&&this.networkState.bloud&&this.streamConnectedErrorQueue.length&&(d("brtc \u7F51\u7EDC\u6062\u590D\u6B63\u5E38\uFF0C\u5904\u7406\u91CD\u63A8\u903B\u8F91","","",this.streamConnectedErrorQueue),this.streamConnectedErrorQueue.forEach(e=>{this.handleStreamConnectError(e)}),this.streamConnectedErrorQueue=[])};this.handleMediaDevicesChange=e=>c(this,null,function*(){d("media devices change"),this.deviceChanging=!0,ks(()=>{this.deviceChanging=!1},1200);let{changed:t,selectAudioDevice:r,selectAudioOutputDevice:i,selectVideoDevice:o}=yield this.initDevices(!0),a=r,n=i;t&&(this.deviceChangeWatcher.next(!0),a=this.selectAudioDevice,n=this.selectAudioOutputDevice),o&&(yield this.bmStreamVm.changeVideoInput(o)),yield this.bmStreamVm.changeAudioInput(a),yield this.bmStreamVm.changeSpeaker(n).catch(l=>{})});this.enumVideoDevices=()=>fs().then(e=>{if(!Q())return e;let t=[];return e.forEach((r,i)=>{r.name.includes("front")||r.name.includes("\u524D\u7F6E")?r.name=`\u524D\u7F6E${i.toString().padStart(2,"0")}`:(r.name.includes("back")||r.name.includes("\u540E\u7F6E"))&&(r.name=`\u540E\u7F6E${i.toString().padStart(2,"0")}`),t.push(r)}),t});this.enumAudioInputDevices=()=>ps().then(e=>{let t=e,r=e.find(i=>i.default);if(r){let i=Object.assign({},r);i.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${r==null?void 0:r.name}\uFF09`,t.unshift(i)}return t});this.enumAudioOutputDevices=()=>gs().then(e=>{let t=e,r=e.find(i=>i.default);if(r){let i=Object.assign({},r);i.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${r==null?void 0:r.name}\uFF09`,t.unshift(i)}return t});this.getPermissions=Ss;this.checkSystemSupport=ms;this.createStream=hs;this.participantNotice=!1;this.handleQueueTask=(e,t=!1)=>c(this,null,function*(){if(!this.BRTCConnectFailed&&!(!e.isLocal&&this.meetingControlOptions.cancelAutoPull&&!e.shouldPull)){if(!this.streamModelExits(e)){I(`streamModel is not exits, userId: ${e.userId}, isShare: ${e.isShare}, ignore`);return}yield this.handleStreamTask(e,t)}});this.republishLocalStream=oi(e=>c(this,null,function*(){let t=e.getAudioOn()||this.localUser.audioEnable||!1,r=e.getVideoOn()||this.localUser.videoEnable||!1;d("republish local stream ","","",[t,r]),yield this.publish(e).then(()=>c(this,null,function*(){this.bmStreamVm.bloudStream=null,yield this.bmStreamVm.publishBloudStream(t,r),d("local stream connect error, and republish success, bloud stream republish success","","",["audio =>",t," video => ",r]),this.bmStreamVm.localStreamConnectErrorWatcher.next(ws(t,r))})).catch(()=>{d("local stream connect error, and republish failed","","",["audio =>",t," video => ",r]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Ns())})}),1e3);this.processUser=(e,t=0)=>c(this,null,function*(){let r="";if(e.isScreen){let i=this.bmStreamVm.getShareStreamModelByUId(e.id);(!i||!i.stream&&!i.isLocal)&&(e.isWeb?r=`${e.id}_screen`:r=e.id)}else{let i=this.bmStreamVm.streamModels.get(e.id);i&&!i.stream&&!i.isLocal&&(r=e.id)}if(r){d("brtc query streams","","",["queryId => ",r]);try{let i=yield this.queryBrtcStreams([r]);if(i&&i.length){let o=i.map(a=>[a.getUserId(),a.getStreamId()]);d("brtc query streams result ","","",["streamInfo =>",JSON.stringify(o)]),i&&this.handleAddStreams(i)}else t<10?(t+=1,yield H(1e3),this.processUser(e,t)):I(`query stream error: uId:${e}`)}catch(i){p("query stream error","","",[JSON.stringify(i),t]),t<10&&(t+=1,yield H(1e3),this.processUser(e,t))}}});si.setLogLevel(bs.INFO),d(`
1
+ var ni=Object.defineProperty,li=Object.defineProperties;var ci=Object.getOwnPropertyDescriptors;var Xt=Object.getOwnPropertySymbols;var ui=Object.prototype.hasOwnProperty,di=Object.prototype.propertyIsEnumerable;var Yt=(s,e,t)=>e in s?ni(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,P=(s,e)=>{for(var t in e||(e={}))ui.call(e,t)&&Yt(s,t,e[t]);if(Xt)for(var t of Xt(e))di.call(e,t)&&Yt(s,t,e[t]);return s},ke=(s,e)=>li(s,ci(e));var c=(s,e,t)=>new Promise((r,i)=>{var o=l=>{try{n(t.next(l))}catch(u){i(u)}},a=l=>{try{n(t.throw(l))}catch(u){i(u)}},n=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,a);n((t=t.apply(s,e)).next())});import ds,{checkSystemSupport as ms,createStream as hs,enumAudioInputDevices as ps,enumAudioOutputDevices as gs,enumVideoDevices as fs,getPermissions as Ss}from"@hysc/core";var R=class extends Error{constructor(t,r,i,o){super();this.code=t,this.error=i,this.BoomErrorFlag=!0,this.eName=o,this.message=r}static instanceOf(t){return!!(t&&t.BoomErrorFlag)}getCode(){return this.code}};var Zt=1,mi=2,Kt=3,hi=4;var pi=function(){},js=/BRTC/.test(pi.toString())?Zt:Kt;function et(s,e,t,r){let i=[];return t&&i.push(t),r&&i.push(r),`[${new Date().toLocaleTimeString("chinese",{hour12:!1})}] <${s}> [${i.join("|")}] ${e}`}function gi(s,e,t,r=[]){r.unshift(et("DEBUG",s,e,t)),console.log(...r)}function d(s,e,t,r=[]){Array.isArray(r)||(r=[r]),r.unshift(et("INFO",s,e,t)),console.log(...r)}function I(s,e,t,r=[]){Array.isArray(r)||(r=[r]),r.unshift(et("WARN",s,e,t)),console.log(...r)}function p(s,e,t,r=[]){typeof r=="string"?r=[r]:Array.isArray(r)||(r=[JSON.stringify(r)]),r.unshift(et("ERROR",s,e,t)),console.log(...r)}var Fs={[Zt]:gi,[mi]:d,[Kt]:I,[hi]:p};import{BehaviorSubject as ji}from"rxjs";var er="undefined";var fi=typeof window!==er?window:void 0;var $s=typeof global!==er?global:fi;var Js=Object.freeze({}),Qs=Object.freeze([]);var N="c";import{BehaviorSubject as vi}from"rxjs";var T="_screen",rt="screen-",it="xinhao_";var me="sub-message",he="user-sort-num-change",pe="bind-element",se="stream-connect-error",O="raise-hand",ge="manual-subscription",fe="unsubscribe-stream",Se="change-is-guest",be="bind-big-element",oe="no-container",Ie="model-sort-num-change",ye="add-pull-user",Ee="set-volume",Me="add-audio-play",V="stream-play";import Si from"mitt";var B=class B{static getInstance(){return B.emitter||(B.emitter=Si()),B.emitter}};B.emitter=void 0,B.removeEmitter=()=>{var e,t,r,i,o,a,n,l,u,m,h,f,S,b,M;(e=B.emitter)==null||e.off(me),(t=B.emitter)==null||t.off(he),(r=B.emitter)==null||r.off(se),(i=B.emitter)==null||i.off(O),(o=B.emitter)==null||o.off(fe),(a=B.emitter)==null||a.off(ge),(n=B.emitter)==null||n.off(Se),(l=B.emitter)==null||l.off(pe),(u=B.emitter)==null||u.off(be),(m=B.emitter)==null||m.off(oe),(h=B.emitter)==null||h.off(Ie),(f=B.emitter)==null||f.off(ye),(S=B.emitter)==null||S.off(Ee),(b=B.emitter)==null||b.off(Me),(M=B.emitter)==null||M.off(V),B.emitter=void 0};var y=B;function tr(s){return Mt===2?yi(s):Ii(s)}function Ii(s){let e=30;return s.isSharing?(s.isMaster?e=0:s.isManager&&s.audioEnable&&s.videoEnable?e=1:s.isManager&&s.audioEnable?e=2:s.isManager&&s.videoEnable?e=3:s.isManager?e=4:s.isCommonUser?s.audioEnable&&s.videoEnable?e=9:s.audioEnable?e=10:s.videoEnable?e=11:e=12:s.audioEnable&&s.videoEnable?e=5:s.audioEnable?e=6:s.videoEnable?e=7:e=8,e):(s.isMaster?e=13:s.isLocal?e=14:s.isManager?s.audioEnable&&s.videoEnable?e=15:s.audioEnable?e=16:s.videoEnable?e=17:e=18:s.raiseHand?e=19:s.isCommonUser?s.isSignal?e=26:s.isCommonUser&&(s.audioEnable&&s.videoEnable?e=27:s.audioEnable?e=28:s.videoEnable?e=29:e=30):s.audioEnable&&s.videoEnable?e=22:s.audioEnable?e=23:s.videoEnable?e=24:e=25,e)}function yi(s){let e;return s.isToupingma?e=0:s.raiseHand?e=19:s.raiseAudioHands?e=1:s.raiseVideoHands?e=2:s.isLocal?e=3:s.isMaster&&s.audioEnable&&s.videoEnable?e=4:s.isManager&&s.audioEnable&&s.videoEnable?e=5:s.audioEnable&&s.videoEnable?e=6:s.isMaster&&s.audioEnable?e=7:s.isManager&&s.audioEnable?e=8:s.audioEnable?e=9:s.isMaster&&s.videoEnable?e=10:s.isManager&&s.videoEnable?e=11:s.videoEnable?e=12:s.isMaster?e=13:s.isManager?e=14:s.isCommonUser?e=16:s.isSignal?e=17:e=15,e}var rr="undefined";var _e="function";var Ei=typeof window!==rr?window:void 0;var io=typeof global!==rr?global:Ei;var so=Object.freeze({}),oo=Object.freeze([]),Ct="";function vt(s){return typeof s===_e}function Mi(s,e,t){return s.indexOf(e,t!==void 0?t:0)}function sr(s,e){return Mi(s,e)>=0}function or(s,e){return s!=null&&s.toString?s.toString():e!==void 0?e:Ct}function At(s){return vt(s)&&sr(or(s),"[native code]")}var Rt;typeof setImmediate===_e&&At(setImmediate)&&(Rt=setImmediate);typeof MessageChannel===_e&&At(MessageChannel)?Rt=function(s){let e=new MessageChannel;e.port1.onmessage=s,e.port2.postMessage(1)}:Rt=setTimeout;var ar=5*60*1e3;function Ut(s){let e=new Date(s),t=new Date,r=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,i=e.getDate()<10?"0"+e.getDate():e.getDate(),o=e.getHours()<10?"0"+e.getHours():e.getHours(),a=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes();return t.setHours(0,0,0,0)==e.setHours(0,0,0,0)?o+":"+a:r+"\u6708"+i+"\u65E5 "+o+":"+a}function He(s){return s.sort((e,t)=>e.sortNum===19&&t.sortNum===19?e.raiseHandTime-t.raiseHandTime:e.sortNum===t.sortNum?e.nickName.localeCompare(t.nickName):e.sortNum-t.sortNum)}function nr(s){return s.sort((e,t)=>e.sortNum!==t.sortNum?t.sortNum-e.sortNum:e.sortNum===t.sortNum?e.getUser().nickName.localeCompare(t.getUser().nickName):Number(e.getUser().isCommonUser)-Number(t.getUser().isCommonUser))}function We(s){return!Ge(s,"s")}function ot(s){return Ge(s,"a")}function Pt(s){return Ge(s,"v")}function at(s){return Ge(s,"m")}function nt(s){return Ge(s,"o")}function Ge(s,e){return s.toLowerCase().includes(e)}function Q(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|MicroMessenger/i.test(navigator.userAgent)}var ae=class{constructor(e,t=!1){this.audienceEnableSpeaking=!1;this.streamModels=new Map;this.sortNum=100;this.raiseVideoHands=!1;this.raiseAudioHands=!1;this.raiseHand=!1;this.isAudience=!1;this.isCommonUser=!1;this.inBackground=!1;this.isCalling=!1;this.raiseHandTime=0;this.signals=[];var i;this.userId=e.userId,this.userInfo=e.userInfo,this.nickName=e.nickname,this.isMaster=!!e.isMaster,this.isManager=!!e.isManager,this.isToupingma=!!e.isToupingma,this.isLocal=t,this.hasMultiple=!!e.hasMultiple,this.isCreate=!!e.isCreate,this.hasShare=!!e.hasShare,this.avatar=(i=e.userInfo)==null?void 0:i.avatar,this.permission=e.permission,this.raiseAudioHands=!!e.raiseAudioHands,this.raiseVideoHands=!!e.raiseVideoHands,this.raiseHand=!!e.raiseHand,this.isAudience=!!e.isAudience,this.isCommonUser=!!e.isCommonUser,this.inBackground=!!e.inBackground,this.isCalling=!!e.isCalling,this.signals=e.signals,e.permission&&(this.audienceEnableSpeaking=ot(e.permission.permission)),this.raiseHandTime=e.raiseHandTime||0;let r={operation:"none",user:this};this.watcher=new vi(r),this.updateSortNum(!1),this.customInfo=e.customInfo}get isWeb(){return!!(this.userInfo.pos&&(this.userInfo.pos.includes("web")||this.userInfo.pos.includes("pc")))}get isMobile(){return!!(this.userInfo.pos&&this.userInfo.pos.includes("web"))}setup(e,t,r,i){this.isLocal=!0,this.userId=e,this.userInfo=t,r?this.nickName=r:this.nickName=t.nickname,this.avatar=t.avatar,i&&i.signals&&(this.signals=i.signals),this.customInfo=i}getMainStreamModel(){return this.streamModels.get(this.userId)}get nickname(){return this.nickName}getShareStreamModel(){return this.streamModels.get(`${this.userId}${T}`)}get audioEnable(){let e=this.getMainStreamModel();return e?e._audio_enable:!1}get isMixer(){return this.userId.includes("-mixer-")}get videoEnable(){let e=this.getMainStreamModel();return e?e._video_enable:!1}get isSharing(){let e=!1;for(let t of this.streamModels.values())if(t.isShare){e=!0;break}return e}get isSignal(){var e;return!!((e=this.userId)!=null&&e.startsWith(it))}checkLocalHasMaster(){return this.isMaster||this.isManager}addStream(e,t){this.streamModels.set(e,t),this.watcher.next({operation:"changeShare",user:this})}removeStream(e){this.streamModels.delete(e),e.includes(T)&&(d("\u5220\u9664\u7684\u662F\u5171\u4EAB\u5C4F\u5E55\u7684\u6D41:","","",["streamId =>",e]),setTimeout(()=>{this.watcher.next({operation:"changeShare",user:this})},400))}getID(){return this.userId}getNickName(){return this.nickName}getUserInfo(){return this.userInfo}getStreams(){return this.streamModels}updateUserInfo(e,t={},r){var u,m;let i=(u=t==null?void 0:t.params)==null?void 0:u.customInfo,o=(i==null?void 0:i.updateKeys)||[];this.customInfo=i;let a=!1,n="none";if(d("updateUserInfo =>","updateUser",e.userId,["updateKeys",o.toString(),"permission",(m=e.permission)==null?void 0:m.permission,"isMaster =>",this.isMaster,"isManager =>",this.isManager]),this.nickName!==e.nickname&&(n="changeNickName"),!this.isMaster&&this.isManager&&!e.permission.getManage()&&(n="removeManager",this.isManager=!1),!this.isMaster&&!this.isManager&&e.permission.getManage()&&o.indexOf("changeMaster")==-1&&(n="getManager",this.isManager=!0),e.userinfo.pos)this.userInfo=e.userinfo;else{let h=this.userInfo.pos;this.userInfo=e.userinfo,this.userInfo.pos=h}(o.includes("changeMaster")||o.includes("permission"))&&(e.permission=t.getPermission()),o.includes("raiseHandsAudio")&&(this.raiseAudioHands=i.raiseHandsAudio,n="raiseHandsAudio",y.emitter.emit(O,{status:"raiseHandsAudio",user:this}),a=!0),o.includes("raiseHandsVideo")&&(this.raiseVideoHands=i.raiseHandsVideo,n="raiseHandsVideo",y.emitter.emit(O,{status:"raiseHandsVideo",user:this}),a=!0),o.includes("raiseHand")&&(this.raiseHand=i.raiseHand,this.raiseHandTime=i.raiseHandTime,n="raiseHand",y.emitter.emit(O,{status:"raiseHand",user:this}),a=!0),r.conferenceMode!==1&&this.isAudience&&o.includes("permission")&&((i==null?void 0:i.permission.indexOf("A"))!==-1&&(r.enableAudienceSpeakingWatcher.next(!0),this.audienceEnableSpeaking=!0,n="audienceEnableSpeaking",this.isLocal&&r.bmLiveVM.handleAudienceEnable()),(i==null?void 0:i.permission.indexOf("A"))===-1&&(r.enableAudienceSpeakingWatcher.next(!1),this.audienceEnableSpeaking=!1,n="audienceEnableSpeaking",this.isLocal&&r.bmLiveVM.handleAudienceDisable())),o.includes("inBackground")&&(n="inBackground",this.inBackground=i.inBackground),o.includes("isCalling")&&(n="isCalling",this.isCalling=i.isCalling),this.nickName=e.nickname,this.permission=e.permission;let l=!this.isCommonUser;this.isCommonUser=!e.permission.getSubscribe(),l!==!this.isCommonUser&&(d(`\u8EAB\u4EFD\u6709\u53D1\u751F\u8FC7\u53D8\u5316\uFF0C\u4ECE${l?"\u5609\u5BBE":"\u666E\u901A\u53C2\u4F1A\u8005"} => ${this.isCommonUser?"\u666E\u901A\u53C2\u4F1A\u8005":"\u5609\u5BBE"}`),y.emitter.emit(Se,{user:this,isGuest:!this.isCommonUser,preIsGuest:l})),n&&this.watcher.next({operation:n,user:this}),(!a||a&&!this.isLocal)&&this.updateSortNum(!0)}hasManager(){return this.isManager||this.isMaster}getNicknameSuffix(){let e="";return this.isLocal&&this.isMaster?e="(\u6211\u3001\u4E3B\u6301\u4EBA)":this.isLocal&&this.isManager?e="(\u6211\u3001\u8054\u5E2D\u4E3B\u6301\u4EBA)":this.isLocal?e="(\u6211)":this.isMaster?e="(\u4E3B\u6301\u4EBA)":this.isManager?e="(\u8054\u5E2D\u4E3B\u6301\u4EBA)":this.isSharing&&!this.isToupingma?e="\u7684\u5171\u4EAB\u5C4F\u5E55":this.isSharing&&this.isToupingma&&(e="(\u4EC5\u5171\u4EAB\u5C4F\u5E55)"),e}updateSortNum(e=!0,t=!1){let r=tr(this);this.setSortNum(r,e,t)}setSortNum(e,t,r){this.sortNum===e&&!t||(this.sortNum=e,t&&y.emitter.emit(he,{isCommon:this.isCommonUser,isAudience:this.isAudience,shouldDelay:r}))}};import{BehaviorSubject as Ce}from"rxjs";function H(s){return new Promise(e=>setTimeout(e,s))}import{debounce as lt}from"lodash-es";var Be=["-mixer-","-rtmpmixer-","record#","robot_","stt_"],ve=500,ct="RWPSAVMO,RWPSAVM,RWPSAV,RWPSA",je=class s{constructor(e,t,r){this.userList=new Map;this.audiencesList=new Map;this.signalList=new Map;this.commonUserList=new Map;this.userListWatcher=new Ce(Array.from(this.userList.values()));this.audiencesListWatcher=new Ce(Array.from(this.audiencesList.values()));this.commonUserListWatcher=new Ce(Array.from(this.commonUserList.values()));this.signalListWatcher=new Ce(Array.from(this.signalList.values()));this.masterUserWatcher=new Ce(null);this.getForceUserWatcher=new Ce(!1);this.commTimer=200;this.addBCUser=(e,t=!1,r=!1)=>{var a;let i=this.addUser(e);if(this.room.isWorkShop&&!ot(e.permission.permission)){console.log("\u7814\u8BA8\u4F1A, \u89C2\u4F17\u5148\u4E0D\u521B\u5EFA\u7A97\u53E3");return}this.room.bmStreamVm.streamModels.get(e.userId)||this.room.bmStreamVm.createStreamModel(i);{let n=this.room.bmStreamVm.streamModels.get(e.userId);n&&(e.stream.size?e.stream.forEach(l=>c(this,null,function*(){var f,S,b;let{video_enable:u,audio_enable:m,customInfo:h}=l;if(l.screen){i.hasShare=!0,this.room.bmStreamVm.shareBloudStateMap.set(e.userId,{audio:m,video:u,customInfo:h,userId:e.userId,streamId:l.getID(),isScreen:!0});let M={id:n.userId,isScreen:!0,isWeb:n.isWeb};t?yield(f=this.room)==null?void 0:f.processUser(M):(S=this.room)==null||S.addUser2Queue(M)}else if(n&&(n.updateBloudStream({video:u,audio:m,isScreen:l.screen,customInfo:h},this.room.bmStreamVm),t)){let M={id:n.userId,isScreen:!1,isWeb:n.isWeb};(b=this.room)==null||b.processUser(M)}})):(n.bloudStream&&n.updateBloudStream(void 0,this.room.bmStreamVm),(a=this.room)==null||a.bmStreamVm.removeShareStreamModelByUId(e.userId)))}return i&&i.isMaster&&this.masterUserWatcher.next(i),i==null||i.updateSortNum(r),i};this.updateAllSort=()=>{this.updateUserSort(),this.updateCommonUserSort(),this.updateAudienceUserSort(),this.updateSignalUserSort()};this.updateSortByType=e=>{var t,r;(t=this.room)!=null&&t.isSingleColumns||e.isCommon?(r=this.room)!=null&&r.isBig&&e.shouldDelay?this.updateDelayCommonUserSort():this.updateCommonUserSort():(e.isAudience?this.updateAudienceUserSort():this.updateUserSort(),this.updateSignalUserSort())};this.updateUserSort=lt(()=>{let e=this.sortUsers();this.userListWatcher.next(s.filterUsers(e))},200,{maxWait:1e3});this.updateCommonUserSort=lt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},this.commTimer,{maxWait:12*1e3});this.updateDelayCommonUserSort=lt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},120*1e3,{maxWait:120*1e3});this.updateAudienceUserSort=lt(()=>{let e=this.sortAudiences();this.audiencesListWatcher.next(e)},200,{maxWait:1e3});this.updateSignalUserSort=()=>{let e=this.sortSignalUsers();this.signalListWatcher.next(e)};this.transBloudUsers=(e,t="",r=!1,i=0)=>c(this,null,function*(){let o=new Map;yield this.getAllUsers(e,o,t,r).catch(()=>{if(i<3){p("get bloud user error, retry"),i+=1,this.transBloudUsers(e,t,r,i);return}else{p("get current page of bloud users after 10 times final failed","","",[" page ",e," permission ",t]);return}}),yield this.initUserList(o),o.clear();let a=[];for(let n of this.userList.values())(n.raiseVideoHands||n.raiseAudioHands||n.raiseHand)&&a.push(n);for(let n of this.commonUserList.values())(n.raiseVideoHands||n.raiseAudioHands||n.raiseHand)&&a.push(n);for(let n of this.commonUserList.values())(n.raiseVideoHands||n.raiseAudioHands)&&a.push(n);this.room.roomInfo.setRaiseHandsList(a),this.updateAllSort(),this.room.bmStreamVm.updateModelSort()});this.boomCore=e,this.localUser=t,this.room=r,y.emitter||p("init boom emitter error"),y.emitter.on(Se,this.handleUserRoleChange.bind(this)),y.emitter.on(he,this.updateSortByType)}handleUserRoleChange(e){return c(this,null,function*(){var n,l,u;let{user:t,isGuest:r,preIsGuest:i}=e,o=(n=this.room)==null?void 0:n.roomInfo.isBigRoom;if(d("handleUserRoleChange","",t.userId,["isGuest =>",r,"preIsGuest =>",i,"isBigRoom =>",o]),((l=this.room)==null?void 0:l.userListColumns)===1||(i?this.userList.delete(t.userId):this.commonUserList.delete(t.userId),r?this.userList.set(t.userId,t):this.commonUserList.set(t.userId,t)),o)if(r)t.isLocal&&(yield this.initUsers());else{let m=(u=this.room)==null?void 0:u.getLocalParticipant().isCommonUser;if(t.isLocal&&(this.handleUnSubCommonUser(),this.handleCommonUserChange(),this.commonUserList.set(t.userId,t)),m){let h=t.getMainStreamModel();h&&h.unSubscribeStream(),t.isLocal||this.commonUserList.delete(t.userId)}}this.updateAllSort()})}addUser(e){var i;let t=this.getUser(e.userId);if(t)return d("\u8BE5\u7528\u6237\u5DF2\u7ECF\u52A0\u5165\u623F\u95F4",N,e.userId),this.updateUser(t,e),t;let r;return this.boomCore.userId==e.userId?(this.updateUser(this.localUser,e),r=this.localUser):r=this.toBMUser(e),((i=this.room)==null?void 0:i.userListColumns)===1?this.commonUserList.set(r.userId,r):r.isAudience?this.audiencesList.set(r.userId,r):r.isSignal?this.signalList.set(r.userId,r):r.isCommonUser?this.commonUserList.set(r.userId,r):this.userList.set(r.userId,r),r}removeUser(e){let t=this.userList.delete(e);return t||(t=this.signalList.delete(e)),t||(t=this.audiencesList.delete(e)),t||(t=this.commonUserList.delete(e)),t||I("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, \u79FB\u9664\u65E0\u6548",N,e),t}videoEnable(e){let t=this.getUser(e);if(t)return t.videoEnable;throw new R(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}audioEnable(e){let t=this.getUser(e);if(t)return t.audioEnable;throw new R(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}checkIsMaster(e){if(!e)return!1;let t=this.boomCore.getMaster();return t?t===e:!1}checkLocalHasMaster(){return this.localUser.isMaster||this.localUser.isManager}checkUserHasMaster(e){let t=this.userList.get(e);return t?t.permission.getManage():!1}getUser(e){let t;return e!=null&&e.startsWith(it)?t=this.signalList.get(e):t=this.userList.get(e),t||(t=this.commonUserList.get(e)),t||(t=this.audiencesList.get(e)),t}getAllUsers(e,t,r="",i=!1){return c(this,null,function*(){let o;if(i){let{users:a,total:n}=yield this.boomCore.getUsersList(e,r,ve);o=a}else{let{users:a,total:n}=yield this.boomCore.getUsers(e,r,ve);o=a}o.forEach(a=>{t.set(a.userId,a)})})}initUserList(e){return c(this,null,function*(){var r,i;let t=e.get(this.localUser.userId);if(t){let o=this.addUser(t);if(!((r=this.room)!=null&&r.bmStreamVm.getStreamModelByUId(t.userId))){let a=this.getUser(t.userId);a?(i=this.room)==null||i.bmStreamVm.createStreamModel(a):p("there is no local streamModel exits, and create failed!!!")}o!=null&&o.isMaster&&this.masterUserWatcher.next(o)}e.delete(this.localUser.userId),e&&e.size>0&&this.addBcUsersMap(e)})}addBcUsersMap(e,t=!1,r=!1){e.forEach(i=>{this.addBCUser(i,t,r)})}updateMaster(e,t,r){let i=this.getUser(e);i&&(i.isManager&&(i.isManager=!1),i.isMaster=!0,i.updateSortNum());let o=this.getUser(t);return o&&(o.isMaster=!1,r&&(o.isManager=!0),o.updateSortNum()),!i&&!o&&p("\u672A\u627E\u5230\u8BE5\u7528\u6237, updateMaster\u672A\u751F\u6548",N,e,["masterId => ",e,"oldMasterId => ",t]),{master:i,oldMaster:o}}managerChangeToGuest(e){let t=this.getUser(e);return t?t.isManager?(t.permission.setManage(!1),t.permission.setSubscribe(!0),this.boomCore.updateUser(e,{customInfo:{permission:t.permission.get()}}),t.watcher.next({operation:"getGuest",user:t}),this.updateAllSort()):p("\u8BE5\u7528\u6237\u4E0D\u662F\u7BA1\u7406\u5458\uFF0C\u65E0\u6CD5\u8BBE\u7F6E\u4E3A\u5609\u5BBE",N,e):p("\u672A\u627E\u5230\u8BE5\u7528\u6237, managerChangeToGuest\u672A\u751F\u6548",N,e),t}updateManager(e,t,r=!0){let i=this.getUser(e);return i?(i.permission.setManage(t),r?i.permission.setSubscribe(!0):i.permission.setSubscribe(t),this.boomCore.updateUser(e,{customInfo:{permission:i.permission.get()}}),i.watcher.next({operation:t?"getManager":"removeManager",user:i}),this.updateAllSort()):p("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, updateManager\u672A\u751F\u6548",N,e),i}getLocalUser(){return this.localUser}updateUser(e,t){var C,E,L,W,G,j,F,$;let r=this.checkIsMaster(t.userId),i=(((C=t.permission)==null?void 0:C.getManage())||at((E=t.permission)==null?void 0:E.permission))&&!((L=t.permission)!=null&&L.getOwn()||nt((W=t.permission)==null?void 0:W.permission)),o="none",a=e.isMaster;e.isManager!==i&&(i?o="getManager":o="removeManager"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},10),a!==r&&(r?o="getMaster":o="removeMaster"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},100);let l=e.raiseHand,u=t.customInfo.raiseHand;l!==u&&(!u&&l&&this.room.roomInfo.removeSimpleRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHand",user:e})},300));let m=e.raiseVideoHands,h=t.customInfo.raiseHandsVideo;m!==h&&(!h&&m&&this.room.roomInfo.removeVideoRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsVideo",user:e})},300));let f=e.raiseAudioHands,S=t.customInfo.raiseHandsAudio;f!==S&&(!S&&f&&this.room.roomInfo.removeRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsAudio",user:e})},300));let b=e.nickname,M=t.nickname;if(b!==M&&setTimeout(()=>{e.watcher.next({operation:"changeNickName",user:e})},300),e.isAudience){let ee=e.audienceEnableSpeaking,te=t.permission.getAudio();ee!==te&&setTimeout(()=>{e.watcher.next({operation:"audienceEnableSpeaking",user:e})},300)}e.userInfo=t.userinfo,e.nickName=t.nickname,e.userId=t.userId,e.permission=t.permission,e.avatar=t.userinfo.avatar,e.isToupingma=t.userinfo.pos.includes("_toupingma"),e.raiseHand=u,e.isMaster=r,e.isCreate=this.boomCore.getCreator()===t.userId,e.isAudience=!t.permission.getVideo(),e.isCommonUser=!t.permission.getSubscribe(),e.isManager=i,e.inBackground=!!((G=t==null?void 0:t.customInfo)!=null&&G.inBackground),e.isCalling=!!((j=t==null?void 0:t.customInfo)!=null&&j.isCalling),(F=t.customInfo)!=null&&F.signals&&(e.signals=($=t==null?void 0:t.customInfo)==null?void 0:$.signals),e.isAudience&&(e.audienceEnableSpeaking=t.permission.getAudio()),e.updateSortNum()}updateLocalUserPermission(e){let t=this.getLocalUser();t.isMaster=nt(e),t.isManager=!nt(e)&&at(e),t.isCommonUser=We(e),t.isAudience=!Pt(e),t.watcher.next({operation:"none",user:t})}toBMUser(e){var i,o;let t={};t.userInfo=e.userinfo,t.nickname=e.nickname,t.userId=e.userId,t.streamModels=[],t.permission=e.permission,t.stream=e.stream,t.isToupingma=!!(e.userinfo.pos&&e.userinfo.pos.includes("_toupingma")),t.isMaster=this.checkIsMaster(t.userId),t.isCommonUser=!e.permission.getSubscribe()||We(e.permission.permission),t.isAudience=!Pt(e.permission.permission),t.raiseAudioHands=e.customInfo.raiseHandsAudio,t.raiseVideoHands=e.customInfo.raiseHandsVideo,t.raiseHand=e.customInfo.raiseHand,t.raiseHandTime=e.customInfo.raiseHandTime,t.inBackground=e.customInfo.inBackground,t.isCalling=e.customInfo.isCalling,t.customInfo=e.customInfo,t.isCreate=this.boomCore.getCreator()===e.userId,t.signals=e.customInfo.signals;let r=this.boomCore.getLocalParticipant();if(!r)throw new R(1001,"BCUserVM addUser\u65F6\u672A\u627E\u5230\u672C\u5730\u7528\u6237");return r.getID()==t.userId&&(t.isLocal=!0),((i=t.permission)!=null&&i.getManage()||at((o=t.permission)==null?void 0:o.permission))&&!t.isMaster&&(t.isManager=!0),new ae(t,t.isLocal)}sortUsers(){return He(Array.from(this.userList.values()))}sortAudiences(){return He(Array.from(this.audiencesList.values()))}sortCommonUsers(){return He(Array.from(this.commonUserList.values()))}sortSignalUsers(){return He(Array.from(this.signalList.values()))}static filterUsers(e){return e.filter(t=>!s.filterUser(t.userId))}static filterUser(e){return Be.some(t=>e.includes(t))}initUsers(){return c(this,null,function*(){var l;let e=yield this.getTotalUserNumber();d(`initUsers total users num: ${e}`);let t=Math.ceil(e/ve),r=0,i=this.localUser.isCommonUser,o=[],a=u=>c(this,null,function*(){u<t&&(yield this.transBloudUsers(u-1))}),n=u=>c(this,null,function*(){for(let m of u)yield m(),yield H(50)});if(i&&((l=this.room)!=null&&l.isBig))this.commonUserList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ct,!0);else if(this.room.conferenceMode===2)this.room.localIsAudience&&this.audiencesList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ct,!0);else{for(;r<t;)o.push(a.bind(null,r)),r+=1;n(o)}})}handleUnSubCommonUser(){this.commonUserList.forEach(e=>{let t=e.getMainStreamModel();t!=null&&t.hasPulled&&t.unSubscribeStream()})}handleCommonUserChange(){let e=new Map;this.room.bmStreamVm.streamModels.forEach(t=>{(!t.getUser().isCommonUser||t.isLocal)&&e.set(t.userId,t)}),this.room.bmStreamVm.streamModels=e,this.commonUserList.clear()}getUsers(e,t,r="RWPAV",i="array"){return c(this,null,function*(){let{users:o,total:a}=yield this.boomCore.getUsers(e,r,t);if(i==="map"){let n=new Map;return o.forEach(l=>{if(s.filterUser(l.userId))return;let u=this.toBMUser(l);n.set(u.userId,u),u.isAudience&&this.audiencesList.set(u.userId,u)}),{userList:n,total:a}}else{let n=[];return o.forEach(l=>{if(s.filterUser(l.userId))return;let u=this.toBMUser(l);n.push(u),u.isAudience&&this.audiencesList.set(u.userId,u)}),{userList:n,total:a}}})}getAudiencesList(e,t,r="array"){return c(this,null,function*(){let{users:i,total:o}=yield this.boomCore.getUsers(e,"RWPS",t,r),{users:a,total:n}=yield this.boomCore.getUsers(e,"RWPSA",t,r);if(e===-1&&this.audiencesList.clear(),r==="map"){let l=new Map;return a.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.set(m.userId,m),this.audiencesList.set(m.userId,m)}),i.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.set(m.userId,m),this.audiencesList.set(m.userId,m)}),this.updateAudienceUserSort(),{userList:l,total:o}}else{let l=[];return a.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.push(m),this.audiencesList.set(m.userId,m)}),i.forEach(u=>{if(s.filterUser(u.userId))return;let m=this.toBMUser(u);l.push(m),this.audiencesList.set(m.userId,m)}),this.updateAudienceUserSort(),{userList:l,total:o+n}}})}getUsersList(e,t,r="",i=!1){return c(this,null,function*(){var u,m;let{users:o,total:a,pageIndex:n}=yield this.boomCore.getUsersList(e,r,t,i),l=[];return o.forEach(h=>{if(s.filterUser(h.userId))return;let f=this.toBMUser(h);l.push(f)}),i&&((u=this.room)==null?void 0:u.roomInfo.totalWaitRoomUserWatcher.value)!==a&&((m=this.room)==null||m.roomInfo.totalWaitRoomUserWatcher.next(a)),{userList:l,total:a,pageIndex:n}})}getTotalUserNumber(){return c(this,null,function*(){let e=()=>c(this,null,function*(){let{total:r}=yield this.boomCore.getUsers(0,"",1);return r}),t=r=>{e().then(i=>{r(i)}).catch(i=>{p("getTotalUserNumber error","","",[JSON.stringify(i)]),t(r)})};return new Promise((r,i)=>c(this,null,function*(){t(r)}))})}clearUsers(){this.userList.clear(),this.commonUserList.clear(),this.audiencesList.clear(),this.signalList.clear()}searchUsers(e,t){return c(this,null,function*(){try{let{users:r}=yield this.boomCore.searchUsers(e,t,!1),i=[],o=[],a=[];return r.forEach(n=>{let l=this.userList.get(n.userId);if(l){i.push(l);return}let u=this.commonUserList.get(n.userId);if(u){o.push(u);return}let m=this.audiencesList.get(n.userId);if(m)a.push(m);else{let h=this.toBMUser(n);a.push(h)}}),{userList:i,commonUserList:o,audienceList:a}}catch(r){return Promise.reject(new R(1e3,"boomCore.searchUsers\u53D1\u751F\u9519\u8BEF:"+(r==null?void 0:r.message)))}})}searchWaitRoomUsers(e,t){return c(this,null,function*(){try{let{users:r}=yield this.boomCore.searchUsers(e,t,!0),i=[];return r.forEach(o=>{let a=this.toBMUser(o);i.push(a)}),i}catch(r){return Promise.reject(new R(1e3,"search wait room users error"))}})}};var x=class{constructor(e){this.isMeetingNotice=!1;this.isEmoji=!1;this.userId=e.userId,this.message=e.message,this.role=e.role,this.isLocal=e.isLocal,this.avatar=e.avatar,this.nickName=e.nickName,this.to=e.to,this.isDanger=e.isDanger,this.seq=e.seq,this.failed=e.failed;let t=!1;e.isMeetingNotice&&(t=!0),this.isMeetingNotice=t,e.sendTime?(this.timeStamp=e.sendTime,this.time=Ut(this.timeStamp)):(this.timeStamp=new Date().getTime(),this.time=Ut(this.timeStamp));let r=this.message.match(/^\[(.*?)\]$/);this.isEmoji=r!==null&&r[0].length<=20&&r[0].length>=4}};import{debounce as Ti}from"lodash-es";function q(s){let e=s.getStreamId();return s.getUserId().toString().endsWith(T)||e.startsWith(rt)||s.getType&&s.getType()==="assist"}import{debounce as Ai}from"lodash-es";import{BMShareStreamReconnectFailed as Ri,BMShareStreamReconnectSuccess as Ui,BMStreamReconnectSuccess as Pi}from"@hysc/utils";import{BrtcEvents as cr,BloudEvents as Nt}from"@hysc/utils";function ur(s){var t,r;let e=s.getLocalStreamModel();if(e&&!(e!=null&&e.stream))s.bloudStream&&(d("brtc \u5DF2\u7ECF\u6CA1\u6709\u6D41\u4E86\uFF0Cbloud \u7684\u6D41\u8981\u53D6\u6D88\u6389"),s.bloudStream.unpublish(),e.updateBloudStream(void 0,s),s.bloudStream=null);else if(e&&e.stream){d("brtc \u6D41\u5DF2\u7ECF\u91CD\u63A8\u4E0A\u53BB\u4E86\uFF0Cbloud\u8981\u91CD\u65B0\u53D1\u63A8\u6D41\u7684\u903B\u8F91");let i=e.stream.getAudioOn(),o=e.stream.getVideoOn();s.publishBloudStream(i,o).then(()=>{var a;d("brtc stream repub success bloud repub success, notify reconnect success"),s.localStreamConnectErrorWatcher.next(Pi(i,o)),(a=e.player)==null||a.destroy(),e.player=null,e.isInBig&&e.playInBig()})}if(s.localIsShare){d("brtc has share stream, and bloud need to republish share stream");let i=(t=s.room)==null?void 0:t.boomCore.shareScreenStream;if(i){let o=i.getAudioOn(),a=i.getVideoOn();try{(r=s.room)==null||r.boomCore.createAndPubBloudShareStream(o,a)}catch(n){p("bloud \u5171\u4EAB\u5C4F\u5E55\u6D41\uFF0C\u65AD\u7F51\u91CD\u8FDE\u91CD\u63A8\u6D41\u5931\u8D25")}}}}var le=Ai(s=>{if(s.networkState.bloud&&s.networkState.brtc)try{s.streamQueue.restart()}catch(e){p("streamQueue restart error",JSON.stringify(e))}},300);function dr(s,e,t,r){let i=s.stream;if(d("\u672C\u5730\u63A8\u6D41","\u672C\u5730\u63A8\u6D41",i.getUserId()),i){let o=e.getLocalStreamModel();o&&e.updateStreamModel(o,i),r[cr.STREAM_PUBLISHED].next({published:!0,model:o}),t.conferenceMode===1&&t.getLocalParticipant().isAudience&&e.getStreamModels().forEach(n=>{n.sendMessage2Room()})}else r[cr.STREAM_PUBLISHED].next({published:!1})}function mr(s,e,t){d("bloud publish stream"),wt(s,e,!0),t[Nt.STREAM_PUBLISHED].next(s)}function wt(s,e,t=!1){var a,n,l;d("bloud stream update","","",[JSON.stringify(s)]);let r=s.userId,i=s.isScreen,o=e.streamModels.get(r);if(o)if(!i)o.updateBloudStream(s,e,t),o.getUser().updateSortNum();else{e.shareBloudStateMap.set(r,s);let u=(a=e.room)==null?void 0:a.userVM.getUser(r);u&&(u.hasShare=!0);let m={id:r,isWeb:o.isWeb,isScreen:i};(n=e.room)==null||n.addUser2Queue(m)}else{I("bloud stream update, but can not get streamModel","",r);let u=(l=e.room)==null?void 0:l.userVM.getUser(r);if(!u){p("bloud stream update, but can not get user","",r);return}e.createStreamModel(u).updateBloudStream({audio:s.audio,video:s.video,isScreen:s.isScreen},e)}}function hr(s,e,t){d("bloud unpublish stream","","",[JSON.stringify(s)]),Ni(s,e),t[Nt.STREAM_REMOVED].next(s)}function pr(s,e,t){d("bloud stream update","","",[JSON.stringify(s)]);let r=s.streamId,i=s.userId,o=s.params.customInfo,a;r.includes("_screen")?a=e.shareStreamModels.get(i):a=e.streamModels.get(i),a?a.updateBloudCustomInfo(o):p("bloud stream update, but can not get streamModel","",i,["streamId =>",r]),t[Nt.UPDATE_STREAM].next(s)}function Ni(s,e){var i,o,a,n;let t=s.userId;if(s.isScreen){let l=e.shareStreamModels.get(t),u=(a=e.room)==null?void 0:a.userVM.getUser(t);if(u&&(u.hasShare=!1),l){let m=l.stream;m?(m.destroy(),e.remoteStreamUnpublished(m)):e.removeShareStreamModelByUId(t);let h={id:t,isWeb:l.isWeb,isScreen:!0};(n=e.room)==null||n.streamQueue.removeUser(h)}else I("bloud user unpublish share stream but can not get streamModel","",t)}else{let l=e.streamModels.get(t);if(l){l.updateBloudStream(void 0,e);let u=l.stream;u&&((i=e.room.audioPlayer)==null||i.removeStream(u),e.remoteStreamUnpublished(u),u.destroy());let m={id:t,isWeb:l.isWeb,isScreen:!1};(o=e.room)==null||o.streamQueue.removeUser(m)}else I("bloud user unpublish stream but can not get streamModel","",t)}}function ut(s,e){setTimeout(()=>c(this,null,function*(){d("handle republish share stream");try{let t=s.boomCore.shareScreenStream;if(t){let r=t.getAudioOn(),i=t.getVideoOn();if(yield s.boomCore.shareBrtcClient.publish(t),yield s.boomCore.createAndPubBloudShareStream(r,i),Object.keys(e.localShareCustomStats).length){let o=e.localModel.userId;yield e.updateBloudStreamCustomStats(o,`${o}_screen`,e.localShareCustomStats)}d("handle republish share stream success"),e.localShareError.next(Ui())}else I("no share stream exist, unpublish share stream, to prevent share stream state error"),e.toggleShareScreen(!1,void 0)}catch(t){p("handle republish share stream failed , now unpublish"),e.localShareError.next(Ri()),yield e.toggleShareScreen(!1,void 0)}}),1e3)}import{BloudEvents as z,BrtcEvents as Sr}from"@hysc/utils";function br(s,e,t){let r=s.permission,i=s.total;r&&t.updateLocalUserPermission(r),e.isInWaitRoom=s.joinwait;let o=s.waitroom;e.roomInfo.isOpenWaitRoom.next(o),e.roomInfo.totalUserWatcher.next(i);let a=s.audiooff,n=s.selfopenaudio;(a!==e.roomInfo.audioOff||n!==e.roomInfo.selfopenaudio)&&a!=null&&n!=null&&e.roomInfo.setAudioOff(a,n)}function dt(s,e,t,r,i=!0){return c(this,null,function*(){var o;d("room-connected",e.getLocalParticipant().userId,"room-connected",["roomId =>",e.roomInfo.roomID," local permission => ",s.permission]),e.forceId=(o=s.customStats.forceOn)==null?void 0:o.user,yr(s,e),br(s,e,t),i&&r[z.ROOM_CONNECTED].next(s)})}function mt(s){return c(this,null,function*(){if(d("join ready init users"),!s.isInWaitRoom)if(s.forceId&&(yield s.getForceUser(s.forceId)),yield s.userVM.initUsers(),s.localUser.isAudience)s.queryBloudUsers([s.localUser.userId]);else{let{audioEnable:e,videoEnable:t}=s.roomInfo.originJoinRoomParams;if(s.localUser.userId.startsWith("robot_"))return;d(`join ready:audioEnable:${e}, videoEnable:${t}`),!e&&!t&&s.bmStreamVm.onlyBrtcPublish().catch(r=>{d("only-brtc-pub ","publish",s.localUser.userId,[r.message])})}})}function Ir(s,e){d("update-stats "," ","",["options => ",JSON.stringify(s.options)]),s.options&&s.options[0]=="audiooff"||s.options[1]=="selfopenaudio"?e.roomInfo.setAudioOff(s.room.audiooff,s.room.selfopenaudio):s.options&&s.options[0]=="lock"?e.roomInfo.setlock(s.room.lock):s.options&&s.options[0]=="waitroom"&&e.roomInfo.isOpenWaitRoom.next(s.stats.waitroom)}function yr(s,e){e.roomInfo.msgSeq=s.msgSeq,s.customStats&&e.roomInfo.initCustomStats(s.customStats)}function gr(s,e,t,r,i){var l;s.updateUser(e,t);let o=t.stream,a=r.streamModels.get(e.userId);if(a||p("bmUserVM\u4E2D\u5B58\u5728\u8BE5\u7528\u6237\uFF0C\u4F46\u662FbmStreamModelVM\u4E2D\u4E0D\u5B58\u5728\u8BE5\u7528\u6237\uFF0C\u4F5B\u4E86"),!o.size){a!=null&&a.bloudStream&&(a.updateBloudStream(void 0,r),i.streamQueue.removeUser({id:e.userId,isScreen:!1}),i.streamQueue.removeUser({id:e.userId,isScreen:!0}));let u=r.shareStreamModels.get(e.userId);if(u&&!u.isLocal){try{(l=u.stream)==null||l.destroy()}catch(m){}r.removeShareStreamModel(u)}}o.get(`${e.userId}_screen`)&&i.addUser2Queue({id:e.userId,isScreen:!0,isWeb:e.isWeb});let n=o.get(e.userId);n&&(a==null||a.updateBloudStream({audio:n.audio_enable,video:n.video_enable,isScreen:!1},r))}function fr(s,e,t,r){s.isSingleColumns?e.commonUserList.forEach(i=>{let o=t.get(i.userId);if(o){t.delete(i.userId),gr(e,i,o,r,s);return}e.commonUserList.delete(i.userId),r.streamModels.delete(i.userId),r.shareStreamModels.delete(i.userId)}):e.userList.forEach(i=>{let o=t.get(i.userId);if(o){gr(e,i,o,r,s),i.isCommonUser?e.userList.delete(i.userId):t.delete(i.userId);return}e.userList.delete(i.userId),r.streamModels.delete(i.userId),r.shareStreamModels.delete(i.userId)}),s.userVM.addBcUsersMap(t)}function wi(s,e,t,r){return c(this,null,function*(){let i=e.getLocalParticipant().userId,{users:o}=yield e.boomCore.queryUsers([i]),a=o.get(i);a&&t.updateUser(t.localUser,a);let n=e.getLocalParticipant().isCommonUser;if(e.isBig&&n){let{users:l}=yield e.boomCore.getUsersList(0,ct,500);fr(e,t,l,r)}else{let u=(yield e.userVM.getTotalUserNumber())/ve,m=new Map;for(let h=0;h<u;h++){let{users:f}=yield e.boomCore.getUsers(h-1,"",ve);f.forEach(S=>{m.set(S.userId,S)})}fr(e,t,m,r)}yr(s,e),e.userVM.updateAllSort(),e.bmStreamVm.updateModelSort()})}function Er(s,e,t){d("brtc room reconnecting"),e.networkState.brtc=!1,e.streamWSReconnectWatcher.next(!1),t[Sr.BRTC_ROOM_ROCONNECTING].next(s)}function Mr(s,e,t){d("brtc room reconnected"),e.networkState.brtc=!0,le(e),t[Sr.BRTC_ROOM_RECONNECTED].next(s)}function Cr(s,e,t){d("bloud room reconnecting"),e.networkState.bloud=!1,e.bloudWSReconnectWatcher.next(!1),t[z.RECONNECTING].next(s)}function ht(s,e,t){return c(this,null,function*(){e.hasSyncPermission?(d("bloud room reconnected"),e.bloudWSReconnectWatcher.next(!1),t[z.MOVE_USER_ROOM].next(null),yield e.syncRoom().then(()=>{e.hasSyncPermission=!0,t[z.ROOM_CONNECTED].next(s)}).catch(r=>{if(p("sync room error",JSON.stringify(r)),r.code===43){e.hasSyncPermission=!1,t[z.USER_REJOINED].next(r);return}else e.hasSyncPermission=!1,t[z.TIMEOUT].next(r)})):t[z.TIMEOUT].next(s)})}function vr(s,e,t,r,i){return c(this,null,function*(){d("bloud sync room completed"),br(s,t,e),yield wi(s,t,e,r),ur(r),t.networkState.bloud=!0,le(t),t.bloudWSReconnectWatcher.next(!0),i[z.ROOM_SYNCED].next(s)})}import{BloudEvents as xi}from"@hysc/utils";var{USER_REJOINED:Li,PARTICIPANT_JOINED:Oi,CHANGE_MASTER:Br,EVICTED:ki,UPDATE_USER:Di,PARTICIPANT_LEFT:Tt,CUSTOM_MESSAGE:_i,MOVE_USER_ROOM:Ar}=xi;function Rr(s,e,t,r,i,o){var f,S,b,M,C,E,L,W,G,j,F,$,ee,te,Te,xe,Le,re,ie,_,de,Oe;let a=(S=(f=s==null?void 0:s.participant)==null?void 0:f.params)==null?void 0:S.info.sync,n=s.mode,l=s.user.userId;d("\u7528\u6237\u5165\u4F1A","\u7528\u6237\u5165\u4F1A",s.user.userId,["sync => ",a,"mode =>",n]);let u=e.room.isBig&&t.streamModels.size>1e3,m=!1;if(a){let A=e.userList.get(s.user.userId);if(A||(A=e.commonUserList.get(s.user.userId)),A){A.inBackground!=!!((M=(b=s.user)==null?void 0:b.customInfo)!=null&&M.inBackground)&&(A.inBackground=!!((E=(C=s.user)==null?void 0:C.customInfo)!=null&&E.inBackground),A.watcher.next({operation:"inBackground",user:A})),A.isCalling!=!!((W=(L=s.user)==null?void 0:L.customInfo)!=null&&W.isCalling)&&(A.isCalling=!!((j=(G=s.user)==null?void 0:G.customInfo)!=null&&j.isCalling),A.watcher.next({operation:"isCalling",user:A}));return}}if((F=e.room)!=null&&F.isBig&&n===1&&(($=t.room)==null?void 0:$.conferenceMode)===1)if(We(s.user.permission.permission))e.userList.get(s.user.userId)&&(e.userList.delete(s.user.userId),t.streamModels.delete(s.user.userId),m=!0);else{let J=e.commonUserList.get(s.user.userId);(ee=e.room)!=null&&ee.isSingleColumns||J&&(e.commonUserList.delete(s.user.userId),t.streamModels.delete(s.user.userId),m=!0)}let h=e.addBCUser(s.user);if(h){h.inBackground!=!!((Te=(te=s.user)==null?void 0:te.customInfo)!=null&&Te.inBackground)&&(h.inBackground=!!((Le=(xe=s.user)==null?void 0:xe.customInfo)!=null&&Le.inBackground),h.watcher.next({operation:"inBackground",user:h})),h.isCalling!=!!((ie=(re=s.user)==null?void 0:re.customInfo)!=null&&ie.isCalling)&&(h.isCalling=!!((de=(_=s.user)==null?void 0:_.customInfo)!=null&&de.isCalling),h.watcher.next({operation:"inBackground",user:h}));let A=!1;if(Be.forEach(J=>{h!=null&&h.userId.includes(J)&&(A=!0)}),m?e.updateAllSort():(Oe=e.room)!=null&&Oe.isSingleColumns?e.updateCommonUserSort():h?h.isCommonUser?u?e.updateDelayCommonUserSort():e.updateCommonUserSort():h.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),!A){if(s.mode!==1){let J=new x({isMeetingNotice:!0,userId:h.userId,message:h.nickName+`\u52A0\u5165${r.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});i.addMessage(J,!0)}o[Oi].next({user:h,mode:n,data:s})}}}function Ur(s,e,t,r,i,o,a){var l;let n=s.userIds;d("bloud leave users","","",["userIds =>",n]),n.length&&(n.forEach(u=>{let m=xt(u,e,t,i);m&&Nr(m,o,a,r,!0,0)}),(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():e.updateAllSort(),i.updateModelSort())}function Pr(s,e,t,r,i,o,a){var m;d(`bloud participant left ===>${s.userId}, ${s.mode}`);let n=s.mode===1,l=s.userId,u=t.isBig&&i.streamModels.size>1e3;if(l){let h=xt(l,e,t,i);if((m=e.room)!=null&&m.isSingleColumns?e.updateCommonUserSort():h?h.isCommonUser?u?e.updateDelayCommonUserSort():e.updateCommonUserSort():h.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),i.updateModelSort(),n){r[Tt].next({user:h,mode:s.mode,data:s});return}h&&Nr(h,o,a,r,s.mode!==1,s.mode)}else I("participant-left\u89E6\u53D1=======>\u4F46\u662F\u8BE5\u7528\u6237\u4FE1\u606F\u4E0D\u5B58\u5728",N,null,[s.userId]),r[Tt].next({user:s.userId,mode:s.mode,data:s})}function Nr(s,e,t,r,i,o){let a=!1;if(Be.forEach(n=>{s!=null&&s.userId.includes(n)&&(a=!0)}),!a){if(i){let n=new x({isMeetingNotice:!0,userId:s.userId,message:(s==null?void 0:s.nickName)+`\u79BB\u5F00${e.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});t.addMessage(n,!0)}r[Tt].next({user:s,mode:o})}}function xt(s,e,t,r){let i=e.getUser(s);return e.removeUser(s),t.streamQueue.removeUser({id:s,isScreen:!1}),t.streamQueue.removeUser({id:s,isScreen:!0}),r.removeStreamModelByUId(s),r.removeShareStreamModelByUId(s),t.roomInfo.removeRaiseHandUser(s),t.roomInfo.removeVideoRaiseHandUser(s),t.roomInfo.removeSimpleRaiseHandUser(s),r.shareBloudStateMap.delete(s),i}function wr(s,e,t,r,i){d("changeMaster =>","changeMaster","",["master: => ",s.master,"oldMaster =>",s.oldMaster]);let o=s.master,a=s.oldMaster,n=s.isKeep;if(!o)I("change-master\u89E6\u53D1=======>\u4F46\u662F\u623F\u95F4\u5185\u627E\u4E0D\u5230master",N,null,o),r[Br].next(null);else{let l=e.updateMaster(o,a,n);l.master&&(l.master.watcher.next({operation:"getMaster",user:l.master}),t.userVM.masterUserWatcher.next(l.master)),l.oldMaster&&(l.oldMaster.watcher.next({operation:"removeMaster",user:l.oldMaster}),n&&l.oldMaster.watcher.next({operation:"getManager",user:l.oldMaster}));let u=i.getStreamModelByUId(a),m=i.getStreamModelByUId(o);u==null||u.updateSortNum(),m==null||m.updateSortNum(),r[Br].next({master:l.master,oldMaster:l.oldMaster,data:s})}}function Tr(s,e,t,r,i){var l;let o=s.userId,a=e.getUser(o);d("\u8E22\u51FA\u7528\u6237 => ","evict ",a==null?void 0:a.userId,["nickname => ",a==null?void 0:a.nickName]);let n=xt(o,e,r,t);(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():n?n.isCommonUser?e.updateCommonUserSort():n.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),i[ki].next(s)}function xr(s,e,t,r,i){var a;let o=(a=s.user)==null?void 0:a.userId;if(d("\u7528\u6237\u4FE1\u606F\u88AB\u6539\u53D8","",o),o){let n=e.getUser(o),l=r.getStreamModelByUId(o);n?n.updateUserInfo(s.user,s.participant,t):(console.warn("participant-update: bmUser is null"),t.queryBloudUsers([o],!0)),l&&l.updateSortNum(!0),i[Di].next({bmUser:n,params:s.participant.params})}}var Lt=Ti((s,e)=>{s[Li].next(e)},1e3);function Lr(s,e,t,r){return c(this,null,function*(){d("bloud move user room","","",[t]);let i=t.toWait;if(s.isInWaitRoom=i,i){s.handleResetOtherStreamStatus(),e.userList.clear(),e.userListWatcher.next([]),e.commonUserList.clear(),e.commonUserListWatcher.next([]),e.getForceUserWatcher.next(!1),s.bmStreamVm.streamModels.clear(),s.bmStreamVm.clearDetector(),s.bmStreamVm.speakerWatcher.next(null),r[_i].next(null),s.messageWatcher.next({type:"init",status:!1,isNotCancelRootReport:!1}),s.audioPlayer.destroy();let o=s.bmStreamVm.localModel;o&&s.bmStreamVm.streamModels.set(o.userId,o),s.bmStreamVm.streamModelsWatcher.next([]),s.bmStreamVm.shareStreamModels.clear(),s.bmStreamVm.shareStreamModelsWatcher.next([]),s.roomInfo.raiseHandsWatcher.next([]),s.roomInfo.raiseVideoHandsWatcher.next([]),s.roomInfo.raiseSimpleHandsWatcher.next([]),r[Ar].next(i),Object.values(s.observes).forEach(a=>{a.next(null)})}else{let{audiooff:o,selfopenaudio:a,lock:n}=t.info;n!==s.roomInfo.lock&&s.roomInfo.setlock(n),(o!==s.roomInfo.audioOff||a!==s.roomInfo.selfopenaudio)&&s.roomInfo.setAudioOff(o,a),yield dt(t.info,s,e,r,!0),yield mt(s),r[Ar].next(i)}})}import{BloudEvents as Ot}from"@hysc/utils";function kr(s,e,t,r){var o,a,n,l,u,m,h,f,S;let i=P({},s);if(i.message){if(i.message=typeof i.message=="string"?JSON.parse(i.message):i.message,d("new-message","","",[" method => ",i.message.method]),i.message.method==="send-talk"){let b=i.user===((o=e.getLocalUser())==null?void 0:o.userId),M=((n=(a=i.message)==null?void 0:a.params)==null?void 0:n.status)||"",C=(m=(u=(l=i.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.avatar,E=s.seq,L=new x({userId:i.user,message:M,isLocal:b,avatar:C,to:i.to,seq:E,nickName:(S=(f=(h=i.message)==null?void 0:h.params)==null?void 0:f.stream)==null?void 0:S.nickname,sendTime:new Date().getTime()});t.addMessage(L,!1)}r[Ot.SEND_MESSAGE].next(i)}}function Dr(s,e,t){var i,o,a,n,l,u,m,h,f,S,b,M,C;let r=P({},s);if(r.message)if(r.message=typeof r.message=="string"?JSON.parse(r.message):r.message,d("custom-message","","",[" method => ",r.message.method]),r.message.method=="video-force-change"){let E=r.message.params.status=="enabled";d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u6444\u50CF\u5934: ${E}`),e.messageWatcher.next({type:"video-force-change",status:E,fromUserId:r.user})}else if(r.message.method=="audio-force-change"){let E;r.message.params.status=="checkUserAudio"?E=r.message.params.status:E=r.message.params.status=="enabled",d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u9EA6\u514B\u98CE: ${E}`),e.messageWatcher.next({type:"audio-force-change",status:E,fromUserId:r.user,isNotCancelRootReport:(i=r.message.params)==null?void 0:i.isNotCancelRootReport})}else if(r.message.method==="raise-hands"){let E=r.message.params;Vi(E,e),e.raiseHandleRespWatcher.next(E)}else if(r.message.method==="give-like")(h=e.roomVM)==null||h.giveLikeList.push({userId:r.user,nickName:(n=(a=(o=r.message)==null?void 0:o.params)==null?void 0:a.stream)==null?void 0:n.nickname,time:new Date().getTime(),type:(m=(u=(l=r.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.type}),(S=e.roomVM)==null||S.giveLikeListWatcher.next((f=e.roomVM)==null?void 0:f.giveLikeList);else if(r.message.method==="resp-to-check-devices")(b=r.message)!=null&&b.params&&(r.message.params.fromUserId=r.user),t[Ot.CUSTOM_MESSAGE].next(r);else if(r.message.method==="usercount"){if(r.message.params){let E=(C=(M=r.message)==null?void 0:M.params)==null?void 0:C.total;E?(E=Number(E),E<0&&(I("\u670D\u52A1\u8FD4\u56DE\u7684usercount\u4E3A\u8D1F\u6570,"+E),E=0)):(I("\u670D\u52A1\u672A\u8FD4\u56DEusercount,"+E),E=0),e.roomInfo.totalUserWatcher.next(E)}}else if(r.message.method==="waitusercount"){if(r.message.params){let E=r.message.params.total;e.roomInfo.totalWaitRoomUserWatcher.next(E)}}else t[Ot.CUSTOM_MESSAGE].next(r)}function Vi(s,e){return c(this,null,function*(){let t=s.raiseInfo;if(s.raiseHandsType===4&&t){let r=e.userVM.getUser(t.userId);if(r||(d("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728,\u5F00\u59CB\u67E5\u8BE2",t.userId),yield e.queryBloudUsers([t.userId],!1,!1),r=e.userVM.audiencesList.get(t.userId)),!r){p("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728",t.userId);return}switch(t.type){case"raiseHandsAudio":r.raiseAudioHands=s.raiseHands;break;case"raiseHandsVideo":r.raiseVideoHands=s.raiseHands;break;case"raiseHand":r.raiseHand=s.raiseHands;break;default:break}y.emitter.emit(O,{status:t.type,user:r})}})}import{BloudEvents as Hi,BrtcEvents as kt}from"@hysc/utils";var pt=0;var gt=0,Fe=new Set;function Dt(s,e,t,r,i){return c(this,null,function*(){if(p("brtc error","brtc error","",[new Date().toLocaleTimeString(),JSON.stringify(s),s.getCode()]),s.getCode()===4002){e.BRTCConnectFailed=!0,e.networkState.brtc=!1,I("brtc \u4FE1\u4EE4\u901A\u9053\u9519\u8BEF\uFF0C\u9700\u8981\u91CD\u65B0\u8D70\u5165\u4F1A","brtc error",""),e.streamWSReconnectWatcher.next(!1);try{yield t.brtcClient.leave("room_close")}catch(a){p("brtc \u79BB\u4F1A\u5931\u8D25")}setTimeout(()=>c(this,null,function*(){e.handleResetOtherStreamStatus(),yield _r(t,e,i,s).catch(a=>{d("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25, \u5904\u7406\u4E00\u4E0B\u9000\u4F1A\u903B\u8F91","","",[JSON.stringify(a)]),i[kt.ERROR].next(s)})}),1e3)}else i[kt.ERROR].next(s)})}function _r(s,e,t,r){return c(this,null,function*(){return new Promise((i,o)=>{setTimeout(()=>{d("brtc\u91CD\u8FDE"),s.brtcClient.join(s.roomId,s.userId,s.brtcSig).then(()=>c(this,null,function*(){d("brtc\u65AD\u7F51\u91CD\u8FDE\u6210\u529F, \u91CD\u65B0\u5904\u7406\u62C9\u6D41\u548C\u63A8\u6D41"),e.networkState.brtc=!0,setTimeout(()=>{e.brtcNetEnableWatcher.next(!0)},2e3),le(e),e.BRTCConnectFailed=!1,pt=0,yield e.handleRePushSelf(),e.streamWSReconnectWatcher.next(!0),i(!0)})).catch(a=>{let n=a.getCode();d("\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[a,n]),pt<=10?(pt+=1,s.brtcClient.isJoinning=!1,setTimeout(()=>{_r(s,e,t,r)},2*1e3)):(p("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u9000\u4F1A"),pt=0,t[kt.ERROR].next(r),o(!1))})},7*1e3)})})}function _t(s){return c(this,null,function*(){return new Promise((e,t)=>{setTimeout(()=>{d("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE"),s.shareBrtcClient.join(s.roomId,s.userId,s.brtcSig).then(()=>{gt=0,e(!0)}).catch(r=>{let i=r.getCode();if(d("\u5171\u4EAB\u5C4F\u5E55\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[r,i]),gt<=3)gt+=1,_t(s);else throw p("\u5171\u4EAB\u5C4F\u5E55\u7528\u6237\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55"),gt=0,new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE\u5931\u8D25")})},7*1e3)})})}function Vr(s,e,t,r,i){return c(this,null,function*(){p("network-error","network-error","local-client",["\u672C\u5730\u94FE\u63A5\u51FA\u73B0\u95EE\u9898","netconnectiong => ",s.netConnecting]),s.netConnecting?yield ht(r,s,i):i[Hi.TIMEOUT].next(r)})}import{BloudEvents as Wi}from"@hysc/utils";function Hr(s,e,t){let r=s==null?void 0:s.updateKeys;d("update-custom-stats"," "," ",["updateKeys => ",JSON.stringify(r)]),(r!=null&&r.includes("chatNotice")||r!=null&&r.includes("chatNoticeRich")||r!=null&&r.includes("fileUpdateLook")||r!=null&&r.includes("fileUpdateDown")||r!=null&&r.includes("fileUpdateEdit")||r!=null&&r.includes("fileUpdateModel")||r!=null&&r.includes("screenShareModel")||r!=null&&r.includes("onlyOnePersonShare")||r!=null&&r.includes("chatEnable")||r!=null&&r.includes("giveLikeEnable")||r!=null&&r.includes("cloudRecord")||r!=null&&r.includes("joinAudioEnable")||r!=null&&r.includes("joinVideoEnable")||r!=null&&r.includes("userListEnable")||r!=null&&r.includes("audioEnable")||r!=null&&r.includes("videoEnable")||r!=null&&r.includes("modifyNameEnable")||r!=null&&r.includes("backgroundAIEnable")||r!=null&&r.includes("recordEnable")||r!=null&&r.includes("joinMicrophoneDisable")||r!=null&&r.includes("joinCameraDisable")||r!=null&&r.includes("raiseHandEnable")||r!=null&&r.includes("forceOpenUserMic")||r!=null&&r.includes("forceOpenUserCamera")||r!=null&&r.includes("joinCueVoice"))&&e.roomInfo.updateOperationPermission(s.customStats),(r!=null&&r.includes("chatNotice")||r!=null&&r.includes("chatNoticeRich"))&&e.roomInfo.chatNoticeWatcher.next(s),t[Wi.UPDATE_CUSTOM_STATS].next(s)}import Gi from"@hysc/p-queue";var ft=class{constructor(e,t=!0){this.queue=new Gi({concurrency:e,autoStart:t,carryoverConcurrencyCount:!0,timeout:3*1e3,completeAction:r=>{console.log("task complete",r)}}),this.queueArray=[],this.isTaskPending=t}addQueue(e,t,r=0,i=""){this.queue.isPaused&&this.queue.start();let o={};o.taskID=t,o.status="pending",this.queue.add(e,{priority:r,timeout:3*1e3},a=>{if(o.status=a,o.status==="resolve"||o.status==="resolve-paused"||o.status==="resolve-timeout"){let n=this.queueArray.findIndex(l=>o.taskID===l.taskID);n!==-1&&this.queueArray.splice(n,1)}}),this.queueArray.push(o)}clearQueue(){this.queue.clear(),this.queueArray=[],this.queue.onEmpty().then(e=>{}),this.queue.onIdle().then(e=>{console.log("clearQueue\u5168\u90E8\u5B8C\u4E8B")})}startQueue(){this.queue.start()}pauseQueue(){return this.queue.pause(),console.log(`size:${this.size()}`),this.isTaskPending=!1,this.queue.onEmpty().then(e=>{}),this.queue.onIdle().then(e=>{}),this.queueArray}size(){return this.queue.size}pending(){return this.queue.pending}checkTaskStatus(){return this.isTaskPending}setTaskStatus(e){this.isTaskPending=e}onIdle(){return this.queue.onIdle()}onEmpty(){return this.queue.onEmpty()}},k=new ft(4),v=new ft(10);import{BMShareStreamReconnectFailed as Fi}from"@hysc/utils";import{BloudEvents as g,BrtcEvents as U,CustomEvents as Ae}from"@hysc/utils";function Wr(s,e,t,r,i){d("attachEvents init");let o={};s.on("toggle-screen-share",()=>{p("share stream video track ended, now unpublish share stream"),t.localShareError.next(Fi()),t.localShareEndedError.next(!0)}),s.on("client-banned",()=>c(this,null,function*(){yield i.boomCore.leaveShare()})),s.on("share-brtc-error",n=>c(this,null,function*(){if(n.getCode()===4002)try{d("brtc share client disconnected, reconnecting"),yield s.shareBrtcClient.leave("room_close"),_t(s).then(()=>c(this,null,function*(){if(d("brtc share client reconnected, retry repub share stream"),yield H(1e3),s.shareScreenStream){let u=s.shareScreenStream.getAudioOn(),m=s.shareScreenStream.getVideoOn();s.shareBrtcClient.publish(s.shareScreenStream),s.createAndPubBloudShareStream(u,m)}})).catch(()=>{throw new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u65B0\u5165\u4F1A\u5931\u8D25")})}catch(u){t.toggleShareScreen(!1,void 0).then(()=>{}).catch(m=>{p("\u5171\u4EAB\u53D1\u751F\u9519\u8BEF\u9000\u4F1A\u5931\u8D25","","",[JSON.stringify(m)])})}}));let a=[];return a=a.concat(Object.values(g)),a=a.concat(Object.values(U)),a=a.concat(Object.values(Ae)),a.forEach(n=>{o[n]=new ji(null)}),a.forEach(n=>{switch(n){case U.STREAM_PUBLISHED:s.on(U.STREAM_PUBLISHED,l=>{v.addQueue(dr.bind(null,l,t,i,o),U.STREAM_PUBLISHED)});break;case U.BRTC_SYNC_ROOM_COMPLETED:s.on(U.BRTC_SYNC_ROOM_COMPLETED,()=>c(this,null,function*(){v.addQueue(i.handleResetOtherStreamStatus.bind(i),U.BRTC_SYNC_ROOM_COMPLETED)}));break;case Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED:s.on(Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED,()=>{d("brtc share client sync completed, retry publish share stream"),v.addQueue(ut.bind(null,i,t),Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED)});break;case U.BRTC_ROOM_ROCONNECTING:s.on(U.BRTC_ROOM_ROCONNECTING,l=>{v.addQueue(Er.bind(null,l,i,o),U.BRTC_ROOM_ROCONNECTING)});break;case U.BRTC_ROOM_RECONNECTED:s.on(U.BRTC_ROOM_RECONNECTED,l=>c(this,null,function*(){v.addQueue(Mr.bind(null,l,i,o),U.BRTC_ROOM_RECONNECTED)}));break;case U.CLIENT_BANNED:s.on(U.CLIENT_BANNED,l=>{d("brtc client banned"),Lt(o,l)});break;case U.ERROR:s.on(U.ERROR,l=>c(this,null,function*(){i.netConnecting?v.addQueue(Dt.bind(null,l,i,s,t,o),U.ERROR):Fe.add(Dt.bind(null,l,i,s,t,o))}));break;case g.SYNC_FAILED:s.on(g.SYNC_FAILED,l=>{p("bloud sync failed, leave room"),o[g.TIMEOUT].next(l)});break;case g.ROOM_CONNECTED:s.on(g.ROOM_CONNECTED,l=>c(this,null,function*(){return dt(l,i,e,o)}));break;case Ae.JOIN_READY:s.on(Ae.JOIN_READY,()=>mt(i));break;case g.PARTICIPANT_JOINED:s.on(g.PARTICIPANT_JOINED,l=>c(this,null,function*(){i.isInWaitRoom||v.addQueue(Rr.bind(null,l,e,t,s,r,o),g.PARTICIPANT_JOINED)}));break;case g.PARTICIPANT_LEFT:s.on(g.PARTICIPANT_LEFT,l=>{i.isInWaitRoom||v.addQueue(Pr.bind(null,l,e,i,o,t,s,r),g.PARTICIPANT_LEFT)});break;case g.LEAVE_USERS:s.on(g.LEAVE_USERS,l=>v.addQueue(Ur.bind(null,l,e,i,o,t,s,r),g.LEAVE_USERS));break;case g.CHANGE_MASTER:s.on(g.CHANGE_MASTER,l=>{v.addQueue(wr.bind(null,l,e,i,o,t),g.CHANGE_MASTER)});break;case g.SEND_MESSAGE:s.on(g.SEND_MESSAGE,l=>{v.addQueue(kr.bind(null,l,e,r,o),g.SEND_MESSAGE)});break;case g.CUSTOM_MESSAGE:s.on(g.CUSTOM_MESSAGE,l=>{v.addQueue(Dr.bind(null,l,i,o),g.CUSTOM_MESSAGE)});break;case g.EVICTED:s.on(g.EVICTED,l=>c(this,null,function*(){v.addQueue(Tr.bind(null,l,e,t,i,o),g.EVICTED)}));break;case g.UPDATE_USER:s.on(g.UPDATE_USER,l=>{v.addQueue(xr.bind(null,l,e,i,t,o),g.UPDATE_USER)});break;case g.UPDATE_STATS:s.on(g.UPDATE_STATS,l=>{v.addQueue(Ir.bind(null,l,i),g.UPDATE_STATS)});break;case g.UPDATE_CUSTOM_STATS:s.on(g.UPDATE_CUSTOM_STATS,l=>{v.addQueue(Hr.bind(null,l,i,o),g.UPDATE_CUSTOM_STATS)});break;case g.TIMEOUT:s.on(g.TIMEOUT,l=>{v.addQueue(Vr.bind(null,i,s,t,l,o),g.TIMEOUT)});break;case g.USER_REJOINED:s.on(g.USER_REJOINED,l=>{d("bloud user rejoined"),Lt(o,l)});break;case g.RECONNECTING:s.on(g.RECONNECTING,l=>{v.addQueue(Cr.bind(null,l,i,o),g.RECONNECTING)});break;case g.RECONNECTED:s.on(g.RECONNECTED,l=>c(this,null,function*(){v.addQueue(ht.bind(null,l,i,o),g.RECONNECTED)}));break;case g.ROOM_SYNCED:s.on(g.ROOM_SYNCED,l=>c(this,null,function*(){v.addQueue(vr.bind(null,l,e,i,t,o),g.ROOM_SYNCED)}));break;case g.STREAM_PUBLISHED:s.on(g.STREAM_PUBLISHED,l=>c(this,null,function*(){v.addQueue(mr.bind(null,l,t,o),g.STREAM_PUBLISHED)}));break;case g.STREAM_REMOVED:s.on(g.STREAM_REMOVED,l=>c(this,null,function*(){v.addQueue(hr.bind(null,l,t,o),g.STREAM_REMOVED)}));break;case g.UPDATE_STREAM:s.on(g.UPDATE_STREAM,l=>c(this,null,function*(){v.addQueue(pr.bind(null,l,t,o),g.UPDATE_STREAM)}));break;case g.STREAM_UPDATE:s.on(g.STREAM_UPDATE,l=>c(this,null,function*(){v.addQueue(wt.bind(null,l,t),g.STREAM_UPDATE)}));break;case g.MOVE_USER_ROOM:s.on(g.MOVE_USER_ROOM,l=>c(this,null,function*(){v.addQueue(Lr.bind(null,i,e,l,o),g.MOVE_USER_ROOM)}));break;default:s.on(n,l=>o[n].next(l));break}}),o}import{BmChangeAudioProfileError as Vt,BmChangeMasterError as Ht,BmChangeVideoProfileError as Wt,BmCheckDeviceError as Gt,BmEvictUserError as St,BmSetRemoteAudioEnable as $e,BmSetRemoteVideoEnable as $i,BmUpdateManagerError as Gr,BmUpdateUserError as jt,updateCustomStatsError as Ji}from"@hysc/utils";import{Subject as Qi}from"rxjs";var Je=class{constructor(e,t,r){this.room=null;this.tipQueueObj={};this.roomInfo=r,this.userVM=t,this.boomCore=e,this.giveLikeList=[],this.giveLikeListWatcher=new Qi}initWithRoom(e){this.room=e}evictUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(St("\u672A\u4F20\u9012\u7528\u6237id"));if(!this.userVM.checkLocalHasMaster())return Promise.reject(St("\u53EA\u6709\u4E3B\u6301\u4EBA\u6743\u9650\u624D\u80FD\u8E22\u51FA\u7528\u6237"));if(this.userVM.checkIsMaster(e))return Promise.reject(St("\u4E3B\u6301\u4EBA\u4E0D\u80FD\u88AB\u8E22\u51FA"));try{yield this.boomCore.evictUser(e,t)}catch(r){return Promise.reject(St(`\u8E22\u51FA\u7528\u6237\u5931\u8D25${JSON.stringify(r)}`))}})}updateUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(jt("\u672A\u4F20\u9012\u76EE\u6807\u7528\u6237id"));if(!t)return Promise.reject(jt("info\u4E3A\u7A7A,\u8BF7\u5199\u5165\u8981\u66F4\u65B0\u7684\u4FE1\u606F"));yield this.boomCore.updateUser(e,{customInfo:t}).catch(r=>Promise.reject(jt(`boomCore updateUser\u51FA\u9519 ${JSON.stringify(r)}`)))})}changeMaster(e,t){return c(this,null,function*(){var r;if(!e)return Promise.reject(Ht("\u672A\u4F20\u9012\u4E3B\u6301\u4EBAid"));if(this.userVM.checkLocalHasMaster()||(r=this.userVM.getUser(e))!=null&&r.isCreate)try{yield this.boomCore.changeMaster(e,t)}catch(i){return Promise.reject(Ht(`boomCore changeMaster error ${i}`))}else return console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA",N,e),Promise.reject(Ht("\u60A8\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))})}updateManager(e,t,r=!0){return c(this,null,function*(){return e?this.userVM.checkLocalHasMaster()?this.userVM.updateManager(e,t,r):(console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u8054\u5E2D\u4E3B\u6301\u4EBA",N,e),Promise.reject(Gr("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))):Promise.reject(Gr("\u672A\u4F20\u9012\u8054\u5E2D\u4E3B\u6301\u4EBAid"))})}changeNickName(e,t){return c(this,null,function*(){let r={nickname:t};yield this.updateUser(e,r)})}sendMessageWithMaster(e,t){return c(this,null,function*(){if(!this.userVM.checkLocalHasMaster())return Promise.reject($e("\u60A8\u4E0D\u662F\u4E3B\u6301\u4EBA\uFF0C\u6CA1\u6709\u8BE5\u6743\u9650"));if(t&&!this.userVM.getUser(t))return Promise.reject($e(`uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(e),t)}catch(r){return Promise.reject(r)}})}setRemoteAudioEnable(e,t,r){return c(this,null,function*(){let i=e?"enabled":"disabled";i=="enabled"&&r&&(i="checkUserAudio");let o={domain:"room-control",method:"audio-force-change",params:{status:i,isNotCancelRootReport:r,fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(o,t).catch(a=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${a}`)))})}setRemoteVideoEnable(e,t){return c(this,null,function*(){let r={domain:"room-control",method:"video-force-change",params:{status:e?"enabled":"disabled",fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject($i(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${i}`)))})}closeRemoteShare(e){return c(this,null,function*(){let t={domain:"room-control",method:"close-remote-share",params:{fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(t,e).catch(r=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${r}`)))})}tipUser(e,t,r,i){return c(this,null,function*(){let o={domain:"room-control",method:"tip-user",params:{fromUserId:this.boomCore.getLocalParticipant().getID(),message:t,richMsg:r}};i?this.tipQueueObj[e]=setTimeout(()=>{this.sendMessageWithMaster(o,e)},(i.minutes||0)*60*1e3+(i.seconds||0)*1e3):this.sendMessageWithMaster(o,e).catch(a=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${JSON.stringify(a)}`)))})}raiseHands(e,t){return c(this,null,function*(){var o,a;let r=(o=this.room)==null?void 0:o.getLocalParticipant().getID(),i={};e==="raiseHand"?(i.raiseHand=t,i.raiseHandTime=Math.floor(new Date().getTime()/1e3)):i[e==="audio"?"raiseHandsAudio":"raiseHandsVideo"]=t,yield this.updateUser(r,i),(a=this.room)!=null&&a.isBig&&(yield this.raiseHandsByCustomMessage(e,t,r))})}raiseHandsByCustomMessage(e,t,r){return c(this,null,function*(){var a;let i="raiseHand";e!="raiseHand"&&(i=e==="audio"?"raiseHandsAudio":"raiseHandsVideo");let o={domain:"user-control",method:"raise-hands",params:{raiseHandsType:4,raiseHands:t,raiseInfo:{userId:r,raiseHandTime:Math.floor(new Date().getTime()/1e3),type:i}}};return(a=this.room)==null||a.userVM.userList.forEach(n=>c(this,null,function*(){n.hasManager()&&(yield this.boomCore.customMessage(JSON.stringify(o),n.userId))})),!0})}handleRaiseHands(e,t,r){return c(this,null,function*(){var o,a,n;let i={domain:"user-control",method:"raise-hands",params:{raiseHandsType:e,raiseHands:t}};try{if(r)yield this.boomCore.customMessage(JSON.stringify(i),r);else{let l=(o=this.room)==null?void 0:o.roomInfo.raiseHandsWatcher.getValue(),u=(a=this.room)==null?void 0:a.roomInfo.raiseVideoHandsWatcher.getValue(),m=(n=this.room)==null?void 0:n.roomInfo.raiseSimpleHandsWatcher.getValue();e===0&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)}),u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===1&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===2&&(u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)})),e===3&&(m==null||m.forEach(h=>{this.boomCore.customMessage(JSON.stringify(i),h.userId)}))}}catch(l){return Promise.reject(new R(1e3,"boomCore.sendMessage\u53D1\u751F\u9519\u8BEF"))}})}updateCustomStats(e,t=!1){return c(this,null,function*(){yield this.boomCore.updateCustomStats(e,t).catch(r=>Promise.reject(Ji(`${JSON.stringify(e)} - ${JSON.stringify(r)}`)))})}sendChatNotice(e,t,r){return c(this,null,function*(){yield this.updateCustomStats({chatNotice:e,chatNoticeRich:t,showTipNotice:r}).catch(i=>i)})}giveLikeEnable(e){return c(this,null,function*(){yield this.updateCustomStats({giveLikeEnable:e}).catch(t=>t)})}changeAutoMute(e){return c(this,null,function*(){return this.updateCustomStats({autoMute:e})})}allUserReceiveJoinLeaveMessages(e){return c(this,null,function*(){return this.updateCustomStats({allUserReceiveJoinLeaveMessages:e})})}userJoinMasterVoice(e){return c(this,null,function*(){return this.updateCustomStats({userJoinMasterVoice:e})})}userGiveLike(e){return c(this,null,function*(){var o,a;let t=new Date().getTime(),r={domain:"room-control",method:"give-like",params:{stream:{user:this.userVM.localUser.userId,avatar:this.userVM.localUser.avatar,sendTime:t,nickname:this.userVM.localUser.nickName,type:e||1}}},i=this.userVM.getLocalUser();try{yield this.boomCore.customMessage(JSON.stringify(r),void 0),this.giveLikeList.push({userId:(o=this.room)==null?void 0:o.getLocalParticipant().userId,nickName:(a=this.room)==null?void 0:a.getLocalParticipant().nickName,time:new Date().getTime(),type:e}),this.giveLikeListWatcher.next(this.giveLikeList)}catch(n){throw p(n,N,i==null?void 0:i.userId),new R(4005,"\u7528\u6237\u70B9\u8D5E==>sendMessage\u51FA\u9519")}})}chatEnable(e){return c(this,null,function*(){yield this.updateCustomStats({chatEnable:e}).catch(t=>t)})}joinAudioEnable(e){return c(this,null,function*(){yield this.updateCustomStats({joinAudioEnable:e}).catch(t=>t)})}joinVideoEnable(e){return c(this,null,function*(){yield this.updateCustomStats({joinVideoEnable:e}).catch(t=>t)})}userListEnable(e){return c(this,null,function*(){yield this.updateCustomStats({userListEnable:e}).catch(t=>t)})}audioEnable(e){return c(this,null,function*(){yield this.updateCustomStats({audioEnable:e}).catch(t=>t)})}videoEnable(e){return c(this,null,function*(){yield this.updateCustomStats({videoEnable:e}).catch(t=>t)})}modifyNameEnable(e){return c(this,null,function*(){yield this.updateCustomStats({modifyNameEnable:e}).catch(t=>t)})}backgroundAIEnable(e){return c(this,null,function*(){yield this.updateCustomStats({backgroundAIEnable:e}).catch(t=>t)})}forceOpenUserCamera(e){return c(this,null,function*(){yield this.updateCustomStats({forceOpenUserCamera:e}).catch(t=>t)})}forceOpenUserMic(e){return c(this,null,function*(){yield this.updateCustomStats({forceOpenUserMic:e}).catch(t=>t)})}joinCueVoice(e){return c(this,null,function*(){yield this.updateCustomStats({joinCueVoice:e}).catch(t=>t)})}recordEnable(e){return c(this,null,function*(){yield this.updateCustomStats({recordEnable:e}).catch(t=>t)})}raiseHandEnable(e){return c(this,null,function*(){yield this.updateCustomStats({raiseHandEnable:e}).catch(t=>t)})}joinMicrophoneDisable(e){return c(this,null,function*(){yield this.updateCustomStats({joinMicrophoneDisable:e}).catch(t=>t)})}joinCameraDisable(e){return c(this,null,function*(){yield this.updateCustomStats({joinCameraDisable:e}).catch(t=>t)})}changeFileUpdateModelPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateModel:e}).catch(t=>t)})}changeFileUpdateLookPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateLook:e}).catch(t=>t)})}changeFileUpdateDownPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateDown:e}).catch(t=>t)})}changeFileUpdateEditPermission(e){return c(this,null,function*(){yield this.updateCustomStats({fileUpdateEdit:e}).catch(t=>t)})}changeScreenShareModelPermission(e){return c(this,null,function*(){yield this.updateCustomStats({screenShareModel:e}).catch(t=>t)})}changeOnlyOnePersonSharePermission(e){return c(this,null,function*(){yield this.updateCustomStats({onlyOnePersonShare:e}).catch(t=>t)})}setForceOnUser(e){return c(this,null,function*(){yield this.updateCustomStats({forceOn:{user:e}}).catch(t=>t)})}updateCloudRecord(e){return c(this,null,function*(){return yield this.updateCustomStats({cloudRecord:{userId:e.userId,recordStatus:e.recordStatus}}).catch(t=>t)})}updateSafeHideSec(e){return c(this,null,function*(){return yield this.updateCustomStats({safeHideSec:e}).catch(t=>t)})}updateHostLayout(e,t=!1){return c(this,null,function*(){if(!this.userVM.checkLocalHasMaster())d("\u60A8\u4E0D\u662F\u4E3B\u6301\u4EBA\uFF0C\u6CA1\u6709\u8BE5\u4E0A\u62A5\u6743\u9650",N);else return this.updateCustomStats({from:{fromTag:"masterId"},hostLayout:e},t)})}checkDevices(e){return c(this,null,function*(){let t={domain:"user-control",method:"check-devices",params:{fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(t,e).catch(r=>Promise.reject(Gt(`\u68C0\u6D4B\u5BF9\u65B9\u8BBE\u5907send-message\u53D1\u751F\u9519\u8BEF: ${r}`)))})}resp2CheckDevices(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-check-devices",params:ke(P({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};if(!t)return Promise.reject(Gt(`\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4B: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(i){return Promise.reject(Gt(`\u54CD\u5E94\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4Bsend-message\u53D1\u751F\u9519\u8BEF ${i}`))}})}changeRemoteVideoProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"change-video-profile",params:ke(P({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject(Wt(`\u8C03\u8282\u5BF9\u65B9\u7684\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF: ${i}`)))})}resp2ChangeRemoteVideoProfile(e,t,r){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-change-video-profile",params:{status:e,profile:r,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Wt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(o){return Promise.reject(Wt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF ${o}`))}})}changeRemoteAudioProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"change-audio-profile",params:{microphoneDevice:e.microphoneDevice,speakerDevice:e.speakerDevice,echoCancellation:e.echoCancellation,noiseSuppression:e.noiseSuppression,autoGainControl:e.autoGainControl,speakerVolume:e.speakerVolume,microVolume:e.microVolume,fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(r,t).catch(i=>Promise.reject(Vt(`\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${JSON.stringify(i)}`)))})}resp2ChangeRemoteAudioProfile(e,t){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-change-audio-profile",params:{status:e,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Vt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(i){return Promise.reject(Vt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${i}`))}})}};import{BehaviorSubject as qi,Subject as zi}from"rxjs";import{throttle as Xi}from"lodash-es";var Qe=class{constructor(e,t,r){this.messageList=[];this.hasDangerMessageWatcher=new zi;this.notificationMessageList=Xi(()=>{this.messageListWatcher.next(this.messageList)},200);this.boomCore=e,this.userVM=t,this.bmRoom=r,this.messageListWatcher=new qi(this.messageList)}sendMessage(e,t,r){return c(this,null,function*(){let i=e.replace(/(^\s*)|(\s*$)/g,""),o=new Date().getTime(),a={domain:"room-control",method:"send-talk",params:{stream:{user:this.userVM.localUser.userId,avatar:this.userVM.localUser.avatar,sendTime:o,nickname:this.userVM.localUser.nickName},status:i}},n=this.userVM.getLocalUser();try{let l=!1,u,m=r;m||(yield this.boomCore.sendMessage(JSON.stringify(a),t).then(f=>{u=f.seq}).catch(f=>{I("sendmessage \u51FA\u9519","",n==null?void 0:n.userId,[f]),f&&f.code===39&&(l=!0,this.hasDangerMessageWatcher.next(!0))}));let h=new x({userId:n==null?void 0:n.userId,message:i,isLocal:n==null?void 0:n.isLocal,avatar:n==null?void 0:n.avatar,nickName:n==null?void 0:n.nickName,sendTime:o,to:t,isDanger:l,seq:u,failed:m});return this.addMessage(h,!1),m?Promise.reject(h):Promise.resolve()}catch(l){throw p(l,N,n==null?void 0:n.userId),new R(4005,"\u53D1\u9001\u804A\u5929\u6D88\u606F==>sendMessage\u51FA\u9519")}})}addMessage(e,t){if(!(t&&!this.bmRoom.participantNotice)){if(this.messageList.length==0||e.timeStamp-this.messageList[this.messageList.length-1].timeStamp>=ar){let r=new x({isMeetingNotice:!0,message:""});this.messageList.push(r)}this.messageList.push(e),this.notificationMessageList()}}updateMessageListWatcher(e){this.messageList=e,this.messageListWatcher.next(this.messageList)}getHistoryMessage(){return c(this,null,function*(){let e=yield this.boomCore.getMessages(0,this.boomCore.getMsgSeq()),t=[];return e.items.forEach(r=>{if(r.private||r.to||r.msg.length==0||r.msg.indexOf("{")==-1)return!1;let i=JSON.parse(r.msg);if(i.method!="send-talk")return!1;let o=r.seq,a=i.params,n=a.stream.user?a.stream.user:r.userId,l={nickName:a.stream.nickname,content:a.status,timeStamp:new Date().getTime(),userId:n},u=new x({userId:n,message:a.status,nickName:a.stream.nickname,isLocal:n==this.userVM.localUser.userId,avatar:a.stream.avatar,sendTime:a.stream.sendTime,seq:o});t.push(u)}),Promise.resolve(t)})}generateInfo(e){return new x(e)}};import{BehaviorSubject as qr,Subject as X}from"rxjs";import{Player as Zi}from"@hysc/core";var Re=class{constructor(e,t){this.user=e,this.stream=t}getID(){return this.stream.getStreamId()}getUser(){return this.user}};import{debounce as qe}from"lodash-es";function jr(s,e){return 16|~~s<<1|~~e}function Fr(s,e){return 12|~~s<<1|~~e}function $r(s,e){return 8|~~s<<1|~~e}function Jr(s,e){return 4|~~s<<1|~~e}function Qr(){return Date.now()}function bt(){let s=Qr();return function(){return Qr()-s}}import{detect as Ki}from"detect-browser";var Ue=Ki(),es=(Ue==null?void 0:Ue.name)==="safari"||(Ue==null?void 0:Ue.name)==="ios";var ce=`.streammodel${Math.random()}`,Pe=class{constructor(e,t,r=!1){this.streamType=3;this.pullFailedNum=0;this._video_enable=!1;this._audio_enable=!1;this.videoEnableWatcher=new qr(this._video_enable);this.audioEnableWatcher=new qr(this._audio_enable);this.streamUpdateWatcher=new X;this.isSubScribedWatcher=new X;this.playStateChangeWatcher=new X;this.noContainerWatcher=new X;this.noBigContainerWatcher=new X;this.audioLevelWatcher=new X;this.isCurrentDisplay=!1;this.isDisplay=!1;this.isDisplayObserve=new X;this.isInBig=!1;this.isInBigObserve=new X;this._hasPulled=!1;this.shouldPull=!1;this.smallPlayFailed=0;this._pulledStreamType="small";this.pulledStreamGoal="small";this.bigPlayerId="";this.isPlayingBig=!1;this.muted=!1;this.checkVideoTimer=null;this.checkCount=0;this.sortNum=-1;this.isWhiteboard=!1;this.handleDisplayChange=e=>{this.isDisplay!==e&&(this.isDisplay=e,this.isDisplay||(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0,this.pulledStreamType="small"),this.sendMessage2Room())};this.onPlayerStateChange=e=>{var t,r;e.type==="error"&&e.reason&&e.reason.name==="NotAllowedError"&&d("\u64AD\u653E\u5931\u8D25, \u9700\u8981\u8C03\u7528 resume \u65B9\u6CD5"),(e.state==="PAUSED"||e.reason==="pause")&&(this.player&&((t=this.player)==null||t.resume()),(r=this.stream)==null||r.resume())};this.handleStreamConnectError=()=>{d("\u6D41\u51FA\u73B0\u7684connect-error userId","",this.userId,["streamId ==>",this.streamId,"nickname =>",this.nickname,"isLocal => ",this.isLocal]),this.isLocal?y.emitter.emit(se,{stream:this,isLocal:!0}):y.emitter.emit(se,{stream:this,isLocal:!1})};this.bindElement=e=>{!this.isLocal&&(!this.stream||!this.stream.isSubscribed())||this.emitBindElement()};this.bindBigElement=e=>{this.bigPlayerId=e,!(!this.isLocal&&(!this.stream||!this.stream.isSubscribed()))&&this.emitBindBigElement()};this.sendMessage2Room=qe(()=>{y.emitter.emit(me,{stream:this})},100);this.emitBindElement=qe(()=>{y.emitter.emit(pe,{stream:this})},50);this.emitBindBigElement=qe(()=>{y.emitter.emit(be,{stream:this})},50);this.currentIsPlaying=(e,t=!0)=>{var l;let r=document.getElementById(e);if(!r)return 0;let i,o,a=0,n=Array.from(r.children);return i=n.length>0,o=n.length,n.forEach(u=>{u.children.length===0&&(a+=1)}),a>0&&(I(`check stream current is playing failed, ${e}`),t?this.stop():((l=this.player)==null||l.destroy(),this.player=null)),i&&o>a?2:1};this.play=(e=!1)=>c(this,null,function*(){var r,i;if(!this.playerId){I(`no playerId, do not play :${this.nickname} - ${this.userId} - ${this.streamId}`);return}let t=this.stream;if(t){if(!this.isLocal&&!t.isSubscribed())return;let o=bt();if(this.isDisplay&&this.videoEnable){if(e){this.stop(),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!ze}),(r=y.emitter)==null||r.emit(V,{uid:this.userId}),d(`\u64AD\u653E\u8017\u65F6: ${o()}`,"",this.userId);return}let a=this.currentIsPlaying(this.playerId);if(a===0)I("\u627E\u4E0D\u5230\u64AD\u653E\u5668\u5BB9\u5668","stream play",this.userId,["\u6D41 id =>",this.streamId,"nickname =>",this.nickname,"playerId =>",this.playerId]),this.playerId||y.emitter.emit(oe,{type:this.isShare?"share":"normal",id:this.userId,container:"small"});else if(a===1)try{d("\u8FDC\u7AEF\u6D41\u5F00\u59CB\u64AD\u653E","",this.userId),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!ze}),(i=y.emitter)==null||i.emit(V,{uid:this.userId}),d("\u8FDC\u7AEF\u6D41\u64AD\u653E\u7ED3\u675F",this.userId,this.streamId,[this.nickname]),d(`\u64AD\u653E\u8017\u65F6: ${o()}`,"",this.userId),this.smallPlayFailed=0,this.checkSmallVideo()}catch(n){this.stop(),setTimeout(()=>{p("\u64AD\u653E\u5C0F\u6D41\u5931\u8D25, \u5C1D\u8BD5\u91CD\u65B0\u64AD\u653E","\u64AD\u653E",this.userId,[this.streamId,this.stream,"error => ",JSON.stringify(n)]),this.play()},2*1e3)}}else this.stop()}});this.playInBig=(e=!1)=>c(this,null,function*(){var r,i,o,a;if(!this.bigPlayerId){I(`no bigPlayerId, do not play in big :${this.nickname} - ${this.userId} - ${this.streamId}`);return}let t=this.stream;if(t){if(!this.isLocal&&!t.isSubscribed())return;if(this.isInBig&&this.videoEnable&&this.bigPlayerId){let n=bt();if(e){this.initBigPlayer(),yield(r=this.player)==null?void 0:r.play(t),(i=y.emitter)==null||i.emit(V,{uid:this.userId}),d(`\u5927\u6D41\u64AD\u653E\u8017\u65F6: ${n()}`,"",this.userId);return}let l=this.currentIsPlaying(this.bigPlayerId,!1);l===0?(I("\u627E\u4E0D\u5230 bigPlayerId","\u5927\u6D41\u64AD\u653E",this.userId,["\u6D41 id =>",this.streamId]),this.bigPlayerId||y.emitter.emit(oe,{type:this.isShare?"share":"normal",id:this.userId,container:"big"})):l===1&&(d("\u8FDC\u7AEF\u6D41\u5927\u6D41\u5F00\u59CB\u64AD\u653E","",this.userId),this.initBigPlayer(),this.player&&(yield this.player.play(t),(o=y.emitter)==null||o.emit(V,{uid:this.userId}),this.isPlayingBig=!0,this.checkBigVideo()),d("\u8FDC\u7AEF\u6D41\u5927\u6D41\u64AD\u653E\u7ED3\u675F",this.userId,this.streamId,[this.nickname]),d(`\u5927\u6D41\u64AD\u653E\u8017\u65F6: ${n()}`,"",this.userId))}else(a=this.player)==null||a.destroy(),this.player=null,this.isPlayingBig=!1}});this.collectAudioLevel=()=>{this.stream?(this.stream.off("audio-level"+ce,this.handleAudioLevel),this.stream.on("audio-level"+ce,this.handleAudioLevel)):I("collection audio level but not have brtc stream")};this.handleAudioLevel=e=>{this.audioLevelWatcher.next(e)};this.checkSmallVideo=()=>c(this,null,function*(){if(this.videoEnable&&this.stream&&!this.isShare&&!!document.getElementById(this.playerId)){let t=`video_${this.stream.getStreamId()}`;if(!!document.getElementById(t)){this.checkVideoDecodeFrame(t);return}else p(`stream is display, but no video element, should replay now: ${this.smallPlayFailed}`),this.smallPlayFailed<3&&(this.smallPlayFailed+=1,yield H(1e3),this.stop(),yield this.play())}});this.checkBigVideo=qe(()=>{var e;if(this.videoEnable&&this.stream){let t=`video_${this.stream.getStreamId()}_big`;if(!this.isShare&&this.isDisplay&&this.playerId){let r=!!document.getElementById(t);if(this.isInBig)if(r){this.checkVideoDecodeFrame(t);return}else p("stream is playing in big, but no video element, replay now"),(e=this.player)==null||e.destroy(),this.player=null,this.playInBig()}this.isShare&&this.isInBig&&this.bigPlayerId&&this.checkVideoDecodeFrame(t)}},2e3);this.checkStreamIsPlaying=qe(()=>{if(this.isDisplay&&this.videoEnable){if(!this.stream||!document.getElementById(this.playerId))return;this.currentIsPlaying(this.playerId)===2||(p(`${this.userId} - ${this.nickname}: current is ${this.isDisplay}, but there is no player, try play again`),this.play())}},1e3);this.user=e,this.updateUser(e),this._stream=t,this.isDisplayObserve.subscribe(i=>{this.handleDisplayChange(i)}),this.isInBigObserve.subscribe(i=>{this.handleIsInBig(i)}),this.updateSortNum(!1),this.isWhiteboard=r}get hasPulled(){return this._hasPulled}set hasPulled(e){this._hasPulled=e}get pulledStreamType(){return this._pulledStreamType}set pulledStreamType(e){this._pulledStreamType=e}get uuid(){return this.isShare?`${this.userId}_share`:this.isWhiteboard?`${this.userId}_whiteboard`:this.userId}get playerId(){return this.isDisplay?"v_"+this.uuid:""}get isAudience(){return this.user.isAudience}get canShow(){return this.isAudience?this.user.audienceEnableSpeaking:!0}changeMute(e){this.muted!==e&&(this.muted=e,this.handleSpeakerChange())}handleSpeakerChange(){var e,t;this.isLocal||(this.muted?(e=this.stream)==null||e.setAudioVolume(0):(t=this.stream)==null||t.setAudioVolume(1))}get isToupingma(){return this.user.isToupingma}get isMixer(){return this.user.isMixer}get isSignal(){return this.user.isSignal}genReceiveSubMsg(){let e;return this.isDisplay?e={audio:!0,video:!0,streamType:"small"}:e={audio:!0,video:!1,streamType:"small"},e}handleIsInBig(e){this.isInBig!==e&&(this.isInBig=e,d("isInBig change","",this.userId,["streamId =>",this.streamId,"isInBig => ",e]),this.isInBig?this.pulledStreamGoal="big":this.pulledStreamGoal="small",this.sendMessage2Room(),this.isShare&&(this.isInBig||(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0)))}setVideoEnable(e){this._video_enable!==e&&(this._video_enable=e,this.videoEnableWatcher.next(e))}setAudioEnable(e){this._audio_enable!==e&&(this._audio_enable=e,this.audioEnableWatcher.next(e))}updateStream(e,t=!0,r){this._stream&&this._stream.off(ce),this._stream=e,e?(this.audioEnable&&(this.isShare||r.addToDetector(new Re(this.user,e)),this.collectAudioLevel()),e.on("player-state-changed"+ce,this.onPlayerStateChange),e.on("connect-error"+ce,this.handleStreamConnectError),e.on("stream-connection-error"+ce,this.handleStreamConnectError),!this.isLocal&&t&&this.sendMessage2Room()):(this.hasPulled=!1,this.pulledStreamType="small",this.streamType=3)}updateBloudStream(e,t,r=!1){var a,n,l,u,m;let i=!1,o=!1;e?(this.bloudStream={audio:e.audio,video:e.video,isScreen:e.isScreen},e.customInfo&&((!this.bloudStream.customInfo||((a=this.bloudStream.customInfo)==null?void 0:a.volume)!==e.customInfo.volume)&&(Number.isNaN(e.customInfo.volume)||this.setRemoteAudioLevel(e.customInfo.volume)),this.bloudStream.customInfo=e.customInfo),this.stream&&(this.bloudStream.audio?this.isShare||(t.addToDetector(new Re(this.user,this.stream)),this.collectAudioLevel()):t.removeFromDetector(this.stream.getStreamId())),this.bloudStream.video!==this._video_enable&&(i=!0),this.bloudStream.audio!=this._audio_enable&&(o=!0),this.setVideoEnable(this.bloudStream.video),this.setAudioEnable(this.bloudStream.audio),this.isLocal&&(this.isDisplay&&this.play(),this.isInBig&&this.playInBig()),r&&(this.destroyBrtcStream(),(n=this.player)==null||n.destroy(),this.stream&&((l=t.room.audioPlayer)==null||l.removeStream(this.stream)),this._stream=void 0),o&&!this.audioEnable&&this.stream&&((u=t.room.audioPlayer)==null||u.removeStream(this.stream)),(this.bloudStream.audio||this.bloudStream&&this.isDisplay)&&(!this.stream||r?y.emitter.emit(ye,{id:this.userId,isWeb:this.isWeb,isScreen:this.isShare}):(this.isLocal||(!this.hasPulled||!this.stream.isSubscribed())&&this.sendMessage2Room(),i&&(this.isDisplay&&this.playerId&&this.emitBindElement(),this.isInBig&&this.bigPlayerId&&this.emitBindBigElement()),!this.isLocal&&o&&this.audioEnable&&this.stream.isSubscribed()&&y.getInstance().emit(Me,{stream:this})))):(this.bloudStream=void 0,this.setVideoEnable(!1),this.setAudioEnable(!1),(m=this.player)==null||m.destroy(),this.stream&&t.removeFromDetector(this.stream.getStreamId())),this.updateSortNum(!0),this.streamUpdateWatcher.next(!0)}updateBloudCustomInfo(e){var t;this.bloudStream?((!this.bloudStream.customInfo||((t=this.bloudStream.customInfo)==null?void 0:t.volume)!==e.volume)&&(Number.isNaN(e.volume)||this.setRemoteAudioLevel(e.volume)),this.bloudStream.customInfo=e):p("updateBloudCustomInfo, but bloudStream is undefined","","",["userId =>",this.userId])}get streamId(){return this._stream?this._stream.getStreamId():this.userId}get bStreamId(){return this.isShare?`${this.userId}_screen`:this.userId}get userId(){return this.user.userId}get stream(){return this._stream}get isLocal(){return this.user.isLocal}get isShare(){var e,t,r;return this.stream?this.user.isWeb?(t=(e=this.stream)==null?void 0:e.getUserId().toString())==null?void 0:t.endsWith(T):this.stream&&this.stream.getType&&this.stream.getType()==="assist":!!((r=this.bloudStream)!=null&&r.isScreen)}get isWeb(){return this.user.isWeb}get isMobile(){return this.user.isMobile}get audioEnable(){return this._audio_enable}get videoEnable(){return this._video_enable}get brtcPlayerId(){return`player_${this.stream.getStreamId()}`}get selfPlayerId(){return`player_${this.stream.getStreamId()}_big_container`}get nickname(){var e;return this.user.isToupingma?`${this.user.nickName}(\u7684\u6295\u5C4F)`:(e=this.streamId)!=null&&e.includes(T)?`${this.user.nickName}(\u7684\u5C4F\u5E55\u5171\u4EAB)`:this.user.nickName}get audioLevel(){var e;return((e=this._stream)==null?void 0:e.getAudioLevel())||0}getUser(){return this.user}setRemoteAudioLevel(e){if(this.isLocal)throw new Error("\u4E0D\u80FD\u8BBE\u7F6E\u672C\u5730\u6D41\u7684\u97F3\u91CF");y.emitter.emit(Ee,{streamId:this.streamId,volume:e})}getStats(){var e;return(e=this._stream)==null?void 0:e.getStats()}initBigPlayer(){try{if(this.bigPlayerId){let e=document.querySelector(`#${this.bigPlayerId}`);if(!e){console.error("\u64AD\u653E\u5927\u6D41\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u5927\u6D41\u5BB9\u5668",this.userId,this.streamId,this.bigPlayerId);return}this.player&&this.player.destroy(),this.player=null,this.player=new Zi(e,{fit:"contain"}),this.player.on("player-state-changed",t=>{var r;this.stream&&(d("big player state change","","",[JSON.stringify(t)]),t.type==="error"&&t.reason&&t.reason.name==="NotAllowedError"&&I("big player state change video need resume?","","",[JSON.stringify(t)]),t.state==="PAUSED"&&((r=this.player)==null||r.resume()))})}}catch(e){p("\u521D\u59CB\u5316\u5927\u7A97\u53E3\u7684\u64AD\u653E\u5668\u5931\u8D25",this.userId,this.streamId,[e.message])}}stop(){var e;try{(e=this._stream)==null||e.stop()}catch(t){}}destroyBrtcStream(){var e;try{(e=this._stream)==null||e.destroy()}catch(t){}}isPlaying(){var e;return(e=this._stream)==null?void 0:e.isPlaying()}replay(){var e;return(e=this._stream)==null?void 0:e.replay()}resume(){var e,t;(e=this._stream)==null||e.resume(),(t=this.player)==null||t.resume()}hasAudio(){var e;return((e=this._stream)==null?void 0:e.hasAudio())||!1}hasVideo(){var e;return((e=this._stream)==null?void 0:e.hasVideo())||!1}updateUser(e){this.user=e;let t=this.user.userInfo.pos;if(this.isWhiteboard){this.streamType=3;return}if(!t){this.streamType=1;return}t.includes("web")||t.includes("pc")?this.streamType=0:t.includes("_toupingma")?this.streamType=2:this.streamType=1}updateSortNum(e=!0){let t=this.getSortNum();this.setSortNum(t,e)}setSortNum(e,t){this.sortNum!==e&&(this.sortNum=e,t&&(y.emitter.emit(Ie,null),this.user.updateSortNum(!0)))}getSortNum(){return this.user.isMaster?jr(this.audioEnable,this.videoEnable):this.user.isLocal?Fr(this.audioEnable,this.videoEnable):this.user.isManager?$r(this.audioEnable,this.videoEnable):Jr(this.audioEnable,this.videoEnable)}checkVideoDecodeFrame(e){if(this.isLocal||es)return;let t=document.getElementById(e);if(this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),!t){d("\u9ED1\u5E27\u68C0\u6D4B\u6CA1\u6709\u64AD\u653E\u5BB9\u5668",this.userId,"",["streamId =>",this.streamId,"isShare =>",this.isShare,"playerId =>",this.playerId,"bigPlayerId =>",this.bigPlayerId,"isDisplay => ",this.isDisplay,"isInbig =>",this.isInBig]),this.isShare&&this.isInBig&&this.bigPlayerId&&(I("share stream has no video player, retry play"),this.playInBig(!0));return}this.checkVideoTimer=setTimeout(()=>{var i,o,a;let r=(t==null?void 0:t.getVideoPlaybackQuality)&&((i=t==null?void 0:t.getVideoPlaybackQuality())==null?void 0:i.totalVideoFrames)||0;if(t&&!t.getVideoPlaybackQuality){this.checkVideoTimer&&clearTimeout(this.checkVideoTimer);return}if(r>0){clearTimeout(this.checkVideoTimer);return}else{if(this.checkCount>10){p("\u68C0\u6D4B\u8D85\u8FC7\u4E86\u5341\u6B21\uFF0C\u8FD8\u6CA1\u6709\u89C6\u9891\u6D41\uFF0C\u9700\u8981\u91CD\u65B0\u62C9\u53D6","\u9ED1\u5E27\u68C0\u6D4B",this.userId,["streamId =>",this.streamId,"nickname =>",this.nickname,"videoContainer => ",e]),this.checkVideoTimer&&clearTimeout(this.checkVideoTimer),this.checkVideoTimer=null,this.checkCount=0,this.hasPulled=!1,this.pulledStreamType="small",(o=this._stream)==null||o.off(ce),this.destroyBrtcStream(),(a=this.player)==null||a.destroy(),this.player=null,this._stream=void 0,this.sendMessage2Room();return}this.checkCount+=1,this.checkVideoDecodeFrame(e)}},200)}subscribeStream(){this.shouldPull=!0,y.emitter.emit(ge,{stream:this})}unSubscribeStream(){this.shouldPull=!1,y.emitter.emit(fe,{stream:this})}unAttach(e){var t,r;e==="all"?(this.stop(),(t=this.player)==null||t.destroy(),this.bigPlayerId=""):e==="big"?((r=this.player)==null||r.destroy(),this.bigPlayerId=""):e==="small"&&this.stop()}};import{BehaviorSubject as ue,Subject as Y}from"rxjs";import{BoomError as Yr}from"@hysc/utils";import{debounce as ts}from"lodash-es";import{BMCameraNotAuthError as rs,BMMicNotAuthError as is,BMOpenCameraError as Zr,BMOpenMicroError as $t,BmSetLocalAudioEnable as ss,BmSetLocalSpeakerEnable as os,BmSetLocalVideoEnable as as,BMStreamDisconnectedError as Kr,BmSyncStreamFailError as Jt,getStreamError as ns}from"@hysc/utils";function zr(s){let e=null,t=s.videoElement,r=t.offsetWidth,i=t.offsetHeight;if(t.captureStream?e=t.captureStream():t.mozCaptureStream&&(e=t.mozCaptureStream()),e){let o=e.getVideoTracks()[0],a=e.getAudioTracks()[0];return{video:!!o,audio:!!a,videoSource:o,audioSource:a,width:r,height:i}}return null}function Xr(s,e){try{let t=s.getVideoTracks()[0],r=s.getAudioTracks()[0];return{video:!!t,audio:!!r,videoSource:t,audioSource:r,width:e.width,height:e.height}}catch(t){return console.log("\u83B7\u53D6\u5171\u4EAB\u97F3\u9891\u53C2\u6570\u6709\u8BEF",t),null}}function Ne(s){return s.split("_")[0]}var Z=`.streammuteevent${Math.random()}`,Xe=class s{constructor(){this.streamModels=new Map;this.streamModelsWatcher=new ue(s.filterStreamModels(this.sortStreamModels()));this.shareStreamModels=new Map;this.shareStreamModelsWatcher=new ue(Array.from(this.shareStreamModels.values()));this.localStreamErrorWatcher=new Y;this.localModel=null;this.room=null;this.bloudStream=null;this.whiteboard=null;this.whiteboardWatcher=new ue(this.whiteboard);this.brtcStream=null;this.videoStream=null;this.audioStream=null;this.localIsShare=!1;this.isShareWatcher=new Y;this.localShareCustomStats={};this._speaker_enable=!0;this.speakerEnableWatcher=new ue(this._speaker_enable);this.mixStreamUid=null;this.mixStreamModelWatcher=new ue(null);this.canvasTimer=null;this._recorder=void 0;this._isRecording=!1;this._slicingRecord=!1;this.isRecordingWatcher=new ue(this._isRecording);this._speaker=null;this._speakers=new Map;this.speakerWatcher=new ue(this._speaker);this.rtcPublishing=!1;this.noContainerWatcher=new Y;this.noBigContainerWatcher=new Y;this.localStreamConnectErrorWatcher=new Y;this.localShareError=new Y;this.localShareEndedError=new Y;this.shareBloudStateMap=new Map;this.streamPlayWatcher=new Y;this.handleStreamPlay=e=>{this.streamPlayWatcher.next(e)};this.updateModelSort=ts(()=>{let e=this.sortStreamModels();this.streamModelsWatcher.next(s.filterStreamModels(e))},200,{maxWait:500});this.handleNoContainer=e=>{let{type:t,container:r,id:i}=e,o;t==="share"?o=this.shareStreamModels.get(i):o=this.streamModels.get(i),o&&(r==="small"?this.noContainerWatcher.next(o):this.noBigContainerWatcher.next(o))};this.getHTMLMediaStream=zr;this.getMediaStream=Xr;setTimeout(()=>{this.createCanvas(),this.canvasDisplay()},100),y.emitter.on(Ie,this.updateModelSort),y.emitter.on(oe,this.handleNoContainer),y.emitter.on(V,this.handleStreamPlay),this.muteHandlerVideo=this.muteHandler.bind(this,"video"),this.muteHandlerAudio=this.muteHandler.bind(this,"audio")}get mixStreamModel(){return this.mixStreamUid?this.streamModels.get(this.mixStreamUid):null}static filterStreamModels(e){return e.filter(t=>!t.isToupingma).filter(t=>!Be.some(r=>t.userId.includes(r))).filter(t=>t.canShow)}initWithRoom(e){return this.room=e,this}setSpeakerEnable(e){var t;this._speaker_enable!==e&&((t=this.room.audioPlayer)==null||t.mute(!e),this._speaker_enable=e,this.speakerEnableWatcher.next(e))}getStreamModels(){return Array.from(this.streamModels.values())}getStreamModelByUId(e){return this.streamModels.get(e)}getShareStreamModelByUId(e){return this.shareStreamModels.get(e)}getLocalStreamModel(){return this.localModel}createWhiteBoard(e){var r;let t=(r=this.room)==null?void 0:r.userVM.getUser(e);if(!t){p("\u521B\u5EFA\u767D\u677F\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u7528\u6237","\u521B\u5EFA\u767D\u677F",e);return}return this.whiteboard=new Pe(t,void 0,!0),this.whiteboardWatcher.next(this.whiteboard),this.whiteboard}removeWhiteBoard(){this.whiteboard=null,this.whiteboardWatcher.next(this.whiteboard)}createStreamModel(e,t){let r=new Pe(e,void 0);return t&&r.updateStream(t,!0,this),r.isShare?(e.addStream(`${e.userId}${T}`,r),this.addShareStreamModel(r)):(e.addStream(e.userId,r),this.addStreamModel(r)),r.isMixer&&(this.mixStreamUid=r.userId,this.mixStreamModel&&this.mixStreamModelWatcher.next(this.mixStreamModel)),r}addStreamModel(e){e&&(e.isLocal?this.localModel||(this.localModel=e,this.localModel.audioEnableWatcher.subscribe(t=>{this._recorder&&this._recorder.muteAudio(!t)}),this.streamModels.set(this.localModel.userId,this.localModel)):this.streamModels.set(e.userId,e))}addShareStreamModel(e){if(e){if(e.isLocal){e.audioEnable&&e.stream&&this.addToRecorder(e.stream);return}this.shareStreamModels.set(e.userId,e),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}}removeStreamModel(e){if(!e)return;e.isShare&&e.isLocal&&this.removeFromRecorder(e.stream);let t=e.getUser();this.streamModels.delete(e.userId),t.removeStream(e.userId)}removeShareStreamModelByUId(e){var r,i,o;let t=this.shareStreamModels.get(e);if(t){try{(r=t.stream)==null||r.destroy()}catch(a){}t.audioEnable&&t.stream&&((o=(i=this.room)==null?void 0:i.audioPlayer)==null||o.removeStream(t.stream)),this.removeShareStreamModel(t)}}removeShareStreamModel(e){if(!e)return;let t=e.getUser();this.shareStreamModels.delete(e.userId),t.removeStream(`${e.userId}${T}`),t.updateSortNum(!0),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}removeStreamModelByUId(e){var r,i,o;let t=this.getStreamModelByUId(e);if(t){if(t.stream){this.removeFromDetector(t.streamId);try{t.stream.destroy()}catch(a){}}t.audioEnable&&(t.stream?(i=(r=this.room)==null?void 0:r.audioPlayer)==null||i.removeStream(t.stream):(o=this.room)==null||o.audioPlayer.removeStreamByUid(e)),this.removeStreamModel(t)}return t}remoteStreamPublished(e){var a;let t=e.getStreamId(),r=e.getUserId().toString(),i=this.getStreamModelByUId(r),o;if(i||(o=Ne(String(r)),i=this.getStreamModelByUId(o)),i){if(q(e)){let n;if(o){let l=(a=this.room)==null?void 0:a.userVM.getUser(o);if(l&&!l.hasShare){I("share stream published, but user has no share","",o);return}n=this.shareStreamModels.get(o)}if(n){if(n.isLocal)return;n.hasPulled=!1,n.pulledStreamType="small",n.updateStream(e,!0,this),this.shareStreamModelsWatcher.next(Array.from(this.shareStreamModels.values()))}else{let l=this.createStreamModel(i.getUser(),e),u=e.getVideoOn(),m=e.getAudioOn(),h=this.shareBloudStateMap.get(i.userId);h?l.updateBloudStream({audio:h.audio,video:h.video,isScreen:!0,customInfo:h.customInfo},this):l.updateBloudStream({audio:m,video:u,isScreen:!0},this),l.streamType=2}}else i.hasPulled=!1,i.pulledStreamType="small",this.updateStreamModel(i,e);this.changeSingleStreamSpeaker(i).catch(n=>{p("\u8BBE\u7F6E\u5355\u80A1\u6D41\u7684\u626C\u58F0\u5668\u7684\u64AD\u653E\u51FA\u73B0\u4E86\u95EE\u9898","\u8BBE\u7F6E\u64AD\u653E\u97F3\u91CF",i==null?void 0:i.userId)})}else p("brtc\u6709\u4EBA\u63A8\u6D41\u4E86\uFF0C\u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel, \u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u7528\u6237","",r,["streamId => ",t,"types =>",e.getType&&e.getType()])}remoteStreamUnpublished(e){var n,l,u;let t,r=e.getUserId().toString(),i=e.getStreamId(),o=!1;if(r.includes(T)){let m=Ne(String(r));if(m==((l=(n=this.room)==null?void 0:n.getLocalParticipant())==null?void 0:l.userId)){d("\u672C\u5730\u7528\u6237\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55","\u53D6\u6D88\u5171\u4EAB\u5C4F\u5E55",r),this.localModel.getUser().removeStream(r);return}t=this.getShareStreamModelByUId(m),o=!0}else i.startsWith(rt)||e.getType&&e.getType()==="assist"?(t=this.getShareStreamModelByUId(r),o=!0):t=this.getStreamModelByUId(r);if(this.removeFromDetector(i),this.removeFromRecorder(e),!t){p("brtc\u6709\u4EBA\u53D6\u6D88\u63A8\u6D41 \u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel","\u53D6\u6D88\u63A8\u6D41",r,[i]);return}let a=(u=t.stream)==null?void 0:u.getStreamId();if(a!==i){p("\u5F53\u524D\u53D6\u6D88\u63A8\u6D41\u7684\u548C\u5F53\u524D\u7ED1\u5B9A\u7684\u4E0D\u662F\u540C\u4E00\u80A1\u6D41","",r,["streamId =>",i,"streamModel.streamId",a]);return}if(t.hasPulled=!1,t.pulledStreamType="small",o||t.streamType===2){t.updateStream(void 0,!0,this),this.removeShareStreamModel(t);return}return t.updateStream(void 0,!0,this),t}sortStreamModels(){return nr(Array.from(this.streamModels.values()))}updateStreamModel(e,t){e.updateStream(t,!0,this)}updateShareStreamModel(e,t){e.updateStream(t,!0,this)}setLocalVideoEnable(e,t){return c(this,null,function*(){var i,o,a,n,l,u,m;if(!((i=this.room)!=null&&i.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u6444\u50CF\u5934\uFF0C\u4E0D\u4E0E\u54CD\u5E94");return}if(!this.room.mediaPermission.camera)return Promise.reject(rs());let r=this.getLocalStreamModel();if(d(`\u5F00\u5173\u672C\u5730\u6444\u50CF\u5934\uFF0C \u72B6\u6001 => ${e}`,"publish",r==null?void 0:r.userId),r)if(e)if(r!=null&&r.stream){if(t)yield r.stream.replaceTrack(t).catch(f=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","",r.userId,[JSON.stringify(f)])});else{let f=(o=r==null?void 0:r.stream)==null?void 0:o.getVideoTrack(),S=r==null?void 0:r.stream.hasVideo();if(!f||(f==null?void 0:f.constructor.name)==="CanvasCaptureMediaStreamTrack"||S==!1){let b=yield this.createVideoStreamTrack().catch(M=>Promise.reject(M));yield r.stream.replaceTrack(b).then(()=>{r.stream.setVideoProfile(this.room.videoProfile),d("replace video track success")}).catch(M=>(p(`\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u89C6\u9891\u6D41\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001 => ${r==null?void 0:r.audioEnable}`,"publish",r==null?void 0:r.userId,[JSON.stringify(M)]),r!=null&&r.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(Zr())))}else{let b=f==null?void 0:f.constructor.name;if(I(`setLocalVideoEnable: no videoTrack, trackName:${b}`,"publish",r==null?void 0:r.userId),Q()){let M=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C));yield r.stream.replaceTrack(M)}}}if(yield r.stream.unmuteVideo())d("brtc unmute video success");else return p(`brtc unmuteVideo\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001=> ${r==null?void 0:r.audioEnable} hasVideo=>${r.stream.hasVideo()}`,"publish",r==null?void 0:r.userId),r!=null&&r.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(Zr());if(!this.bloudStream.published){r.isInBig&&r.playInBig(!0),yield this.publishBloudStream(!1,!0);return}yield this.bloudStream.setVideoEnabled(!0).then(()=>{r.updateStream(r.stream,!0,this),r.updateBloudStream({video:!0,audio:r.audioEnable,isScreen:!1},this),r.playInBig(!0)}).catch(f=>{p("bloud unmuteVideo\u5931\u8D25","publish","",[JSON.stringify(f)]),this.handleStreamUpdateFailed()})}else try{yield this.createStreamAndPublish(!1,!0,r,t),r.playInBig(!0)}catch(h){return this.rtcPublishing=!1,p("\u5F00\u542F\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[JSON.stringify(h)]),(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(h)}else r.stream&&(yield this.muteOrUnpublishStream("video",!0,r).catch(f=>(p("\u5173\u95ED\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[f]),Promise.reject(as(f)))))})}handleStreamUpdateFailed(e=!1){return c(this,null,function*(){var t;p("brtc unmute stream failed, now unpublish","publish",(t=this.localModel)==null?void 0:t.userId),yield this.unpublishStream(e)})}setLocalAudioEnable(e,t=!1){return c(this,null,function*(){var i;let r=this.getLocalStreamModel();if(!((i=this.room)!=null&&i.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u9EA6\u514B\u98CE\uFF0C\u4E0D\u4E0E\u54CD\u5E94","publish",r==null?void 0:r.userId);return}if(!this.room.mediaPermission.microphone)return Promise.reject(is());if(d(`\u5F00\u5173\u672C\u5730\u9EA6\u514B\u98CE\uFF0C \u72B6\u6001 => ${e}`,"publish",r==null?void 0:r.userId),r)if(e)if(r!=null&&r.stream){if(!r.stream.hasAudio()){let a=yield this.createLocalAudioStream();if(!a)return Promise.reject($t());let n=a.getAudioTrack();yield r.stream.replaceTrack(n).then(()=>{d("replace audio track success","publish",r.userId)}).catch(l=>(p("\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u97F3\u9891\u6D41\u5931\u8D25","publish",r.userId,[JSON.stringify(l)]),this.handleStreamUpdateFailed(!0),Promise.reject($t())))}if(yield r.stream.unmuteAudio().catch(a=>{var n;d("brtc unmuteAudio:err, hasAudio="+((n=r.stream)==null?void 0:n.hasAudio()),"publish","",[a])}))d("unmute audio success","publish",r.userId);else return p(`unmute local stream audio res\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${r==null?void 0:r.videoEnable} hasAudio=>${r.stream.hasAudio()}`,"publish",r==null?void 0:r.userId),r!=null&&r.videoEnable||(yield this.handleStreamUpdateFailed(!0)),Promise.reject($t());if(!this.bloudStream.published){yield this.publishBloudStream(!0,!1);return}yield this.bloudStream.setAudioEnabled(!0).then(()=>{d("bloud stream set audio enable","publish",r.userId),r.updateStream(r.stream,!1,this),r.updateBloudStream({audio:!0,video:r.videoEnable,isScreen:!1},this)}).catch(a=>{p(`bloud unmuteAudio\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${r==null?void 0:r.videoEnable}`,"publish",r==null?void 0:r.userId,[JSON.stringify(a)]),r!=null&&r.videoEnable||this.handleStreamUpdateFailed(!0)});return}else yield this.createStreamAndPublish(!0,!1,r).catch(o=>{var a,n,l,u,m;return p("\u5F00\u542F\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",r==null?void 0:r.userId,[o]),this.rtcPublishing=!1,(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(o)});else{let o=r.stream;if(o){this.removeFromDetector(o.getStreamId());try{yield this.muteOrUnpublishStream("audio",!0,r,t)}catch(a){return p("\u5173\u95ED\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",r.userId,[JSON.stringify(a)]),Promise.reject(ss(a))}}return}})}joinWithAudioAndAudio(e,t){return c(this,null,function*(){d("join with audio and video","publish","",[e,t]);let r=this.getLocalStreamModel();if(this.brtcStream){e&&(yield this.brtcStream.unmuteAudio()),t&&(yield this.brtcStream.unmuteVideo()),yield this.publishBloudStream(e,t);return}return yield this.createStreamAndPublish(e,t,r).catch(i=>{var o,a,n,l,u,m;return p("join create and publish failed","publish",(o=this.localModel)==null?void 0:o.userId,[JSON.stringify(i)]),this.rtcPublishing=!1,(n=(a=this.localModel)==null?void 0:a.stream)==null||n.destroy(),(l=this.bloudStream)!=null&&l.published&&this.bloudStream.unpublish(),(u=this.localModel)==null||u.updateStream(void 0,!0,this),(m=this.localModel)==null||m.updateBloudStream(void 0,this),Promise.reject(i)})})}changeSpeaker(e,t=!1){return c(this,null,function*(){var r;if(d("change speaker","device","",[JSON.stringify(e)]),!(e!=null&&e.deviceId))throw new Yr(1e3,"\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25\uFF01,\u539F\u56E0: \u9009\u62E9\u7684\u8BBE\u5907\u6CA1\u6709deviceId"+(e==null?void 0:e.name));try{this.room.setSelectSpeakerDevice(e),(r=this.room.audioPlayer)==null||r.setDevice(e.deviceId,t)}catch(i){throw p("\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25","device","",["error",i==null?void 0:i.message,JSON.stringify(i)]),new Yr(1e3,"\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25")}})}changeSingleStreamSpeaker(e){return c(this,null,function*(){let t=this.room.selectAudioOutputDevice;t&&(e.isLocal||e.stream&&(yield e.stream.setAudioOutput(t.deviceId)))})}changeAudioInput(e){return c(this,null,function*(){var r,i,o,a,n;d("change audio input device","device","",[JSON.stringify(e)]),e||I("changeAudioInput, device is null","device");let t=(r=this.localModel)==null?void 0:r.stream;if((i=this.room)==null||i.setSelectAudioDevice(e),t)return((o=t.getAudioTrack())==null?void 0:o.readyState)==="ended"&&!((a=this.room)!=null&&a.deviceChanging)?(p("try to change audio input device but audio track is ended","device"),!1):(yield t.switchDevice("audio",e.deviceId).catch(u=>{d("switchDevice:error","device","",[JSON.stringify(u)])}),(n=this._recorder)==null||n.setMicDevice(e.deviceId),!0)})}changeVideoInput(e){return c(this,null,function*(){var r,i,o,a;d("change video input device","device","",[JSON.stringify(e)]);let t=(r=this.localModel)==null?void 0:r.stream;if((i=this.room)==null||i.setSelectVideoDevice(e),t)return((o=t.getVideoTrack())==null?void 0:o.readyState)==="ended"?(p("try to change video input device but video track is ended","device"),!1):(yield t.switchDevice("video",e.deviceId).catch(l=>{d("switchDevice:error","device","",[l])}),(a=this.localModel)!=null&&a.isDisplay&&this.localModel.isInBig&&this.localModel.playInBig(!0),!0)})}muteSpeaker(e){return c(this,null,function*(){d("\u9759\u97F3\u626C\u58F0\u5668 \u72B6\u6001 =>","device","",["status =>",e]);try{this.setSpeakerEnable(e)}catch(t){return Promise.reject(os(`\u5F00\u5173\u626C\u58F0\u5668\u5931\u8D25 ${e} error: ${JSON.stringify(t)}`))}})}createLocalAudioStream(){return c(this,null,function*(){return this.audioStream?this.audioStream:(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId).catch(e=>(p("create brtc stream error","publish","",[JSON.stringify(e)]),Promise.reject(e))),this.audioStream)})}onlyBrtcPublish(){return c(this,null,function*(){let e=this.localModel,t=!!Q();return this.audioStream=yield this.room.createSingleLocalStream({video:t,audio:!0},e.userId).catch(r=>(p("create brtc stream error","publish","",[JSON.stringify(r)]),Promise.reject(r))),this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:!1,video_enable:!1},e.userId),d("onlyBrtcPublish","publish",e.userId),this.createStreamAndPublish(!1,!1,e).catch(r=>(this.rtcPublishing=!1,Promise.reject(r)))})}createStreamAndPublish(e,t,r,i){return c(this,null,function*(){var o,a,n,l,u,m,h,f,S;if(this.rtcPublishing)return I(`createStreamAndPublish(audio:${e},video:${t}), rtcPublishing ignore`,"publish",r.userId),!1;if(this.rtcPublishing=!0,d(`createStreamAndPublish(audio:${e},video:${t})`,"publish",r.userId),(o=this.brtcStream)!=null&&o.published&&(yield(a=this.room)==null?void 0:a.unpublish(this.brtcStream)),t){if((u=this.brtcStream)==null||u.destroy(),this.brtcStream=null,!((m=this.room)!=null&&m.audioDevices.length)||!((h=this.room)!=null&&h.videoDevices.length)){let b=(f=this.room)!=null&&f.audioDevices.length?"\u6CA1\u6709\u89C6\u9891\u8F93\u5165\u8BBE\u5907":"\u6CA1\u6709\u97F3\u9891\u8F93\u5165\u8BBE\u5907";p(`\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709${b}, \u91CD\u65B0\u83B7\u53D6`,"publish",r.userId),yield(S=this.room)==null?void 0:S.initDevices()}if(this.room.audioDevices.length>0)try{this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:this.room.mediaPermission.microphone},r.userId).catch(b=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)))}catch(b){d("create brtc audio and video stream failed, recreate brtc stream with audio close and video open"),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!1},r.userId).catch(M=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(M)]),Promise.reject(M)))}else I("\u6CA1\u6709\u97F3\u9891\u8F93\u5165\u8BBE\u5907\uFF0C\u53EA\u80FD\u521B\u5EFA\u89C6\u9891\u6D41","publish"),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!1},r.userId).catch(b=>(p("create brtc video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)))}else{let M=s.getCanvasStream().getVideoTracks()[0];this.audioStream||(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},r.userId).catch(E=>(p("create brtc stream error","publish","",[JSON.stringify(E)]),Promise.reject(E))));let C=(n=this.audioStream)==null?void 0:n.getAudioTrack();if(!C||C&&C.muted)throw(l=this.audioStream)==null||l.destroy(),this.audioStream=null,this.localStreamErrorWatcher.next("audio"),p("\u9EA6\u514B\u98CE\u8BBE\u5907\u4E0D\u53EF\u7528","publish","",["muted => ?",C==null?void 0:C.muted]),ns("\u9EA6\u514B\u98CE");this.brtcStream=null,this.room.videoDevices.length==0?(I("\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709\u89C6\u9891\u8F93\u5165\u8BBE\u5907, createSingleLocalStream video:false","publish",r.userId),this.brtcStream=this.audioStream):Q()?this.brtcStream=this.audioStream:this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:M,audioSource:C},r.userId).catch(E=>Promise.reject(E))}return this.brtcStream&&(t||(yield this.brtcStream.muteVideo()),e||(yield this.brtcStream.muteAudio()),i&&(yield this.brtcStream.replaceTrack(i).catch(b=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","publish","",JSON.stringify(b))})),yield this.room.publish(this.brtcStream).catch(b=>{var M,C;return(M=this.brtcStream)==null||M.destroy(),this.brtcStream=null,(C=this.localModel)==null||C.updateBloudStream(void 0,this),Promise.reject(b)}),this.brtcStreamAddEvent(),(e||t)&&(yield this.publishBloudStream(e,t))),this.rtcPublishing=!1,!0})}brtcStreamAddEvent(){var e,t,r,i;(e=this.brtcStream)==null||e.on("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.on("video-track-ended"+Z,this.muteHandlerVideo),(r=this.brtcStream)==null||r.on("audio-track-mute"+Z,this.muteHandlerAudio),(i=this.brtcStream)==null||i.on("audio-track-ended"+Z,this.muteHandlerAudio)}brtcStreamRemoveEvent(){var e,t,r,i;(e=this.brtcStream)==null||e.off("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.off("video-track-ended"+Z,this.muteHandlerVideo),(r=this.brtcStream)==null||r.off("audio-track-mute"+Z,this.muteHandlerAudio),(i=this.brtcStream)==null||i.off("audio-track-ended"+Z,this.muteHandlerAudio)}publishBloudStream(e,t){return c(this,null,function*(){var i;let r=this.localModel.userId;this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:e,video_enable:t},r),yield this.bloudStream.publish({video_enable:t,audio_enable:e}),(i=this.localModel)==null||i.updateBloudStream({video:t,audio:e,isScreen:!1},this)})}muteHandler(e){var a,n,l;let t=()=>c(this,null,function*(){var u,m,h,f,S,b,M,C,E;(u=this.localModel)!=null&&u.stream&&(yield(m=this.room)==null?void 0:m.unpublish(this.localModel.stream).catch(L=>{p("brtc local stream has problem and unpublish failed","publish","",[String(L)])})),(f=(h=this.localModel)==null?void 0:h.stream)==null||f.destroy(),(S=this.audioStream)==null||S.destroy(),(b=this.videoStream)==null||b.destroy(),(M=this.brtcStream)==null||M.destroy(),this.brtcStream=null,this.audioStream=null,this.videoStream=null,(C=this.localModel)==null||C.updateStream(void 0,!0,this),yield this.bloudStream.unpublish(),(E=this.localModel)==null||E.updateBloudStream(void 0,this)}),r=(a=this.localModel)==null?void 0:a.videoEnable,i=(n=this.localModel)==null?void 0:n.audioEnable,o=(l=this.brtcStream)==null?void 0:l.getAudioDeviceId();if(!r&&!i){d("muteHandler:\u97F3\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}setTimeout(()=>c(this,null,function*(){var u,m,h,f,S,b,M,C,E,L,W,G,j,F,$,ee,te,Te,xe,Le;if((u=this.localModel)!=null&&u.stream){let re=(m=this.localModel)==null?void 0:m.videoEnable,ie=(h=this.localModel)==null?void 0:h.audioEnable;if(o!=((f=this.localModel)==null?void 0:f.stream.getAudioDeviceId())){d("muteHandler:\u8BBE\u5907\u5DF2\u7ECF\u5207\u6362\u65E0\u9700\u5904\u7406","publish");return}if((S=this.room)!=null&&S.deviceChanging){d("muteHandler:\u8BBE\u5907\u6B63\u5728\u5207\u6362\u4E2D","publish");return}if(e==="video"){if(!re){d("muteHandler:\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}let _=(b=this.localModel.stream.getVideoTrack())==null?void 0:b.muted,de=(M=this.localModel.stream.getVideoTrack())==null?void 0:M.label,Oe=(C=this.localModel.stream.getVideoTrack())==null?void 0:C.enabled,A=(E=this.localModel.stream.getVideoTrack())==null?void 0:E.readyState,J=A==="ended";if(d(`muteHandler:brtc video track status:${_},enabled:${Oe},readyState:${A},label:${de} `,"publish",""),!J&&!_&&Oe)return;d("video track has problem, now try recreate and publish","publish"),p("brtc\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38\uFF0C\u9700\u8981\u91CD\u65B0\u63A8\u6D41\u5904\u7406","publish","",["videoEnable:",re,"audioEnable:",ie,"type:",e]),this.localStreamConnectErrorWatcher.next(Kr("\u6444\u50CF\u5934")),(L=this.localModel)!=null&&L.stream&&(yield(W=this.room)==null?void 0:W.unpublish(this.localModel.stream).catch(Et=>{p("brtc local stream has problem and unpublish failed","publish","",[String(Et)])}),(G=this.localModel)==null||G.updateStream(void 0,!0,this),(F=(j=this.localModel)==null?void 0:j.stream)==null||F.destroy(),($=this.localModel.player)==null||$.destroy(),(ee=this.brtcStream)==null||ee.destroy(),this.brtcStream=null,(te=this.videoStream)==null||te.destroy(),this.videoStream=null);try{yield this.createStreamAndPublish(ie,re,this.localModel),this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}catch(Et){this.rtcPublishing=!1,p("brtc video stream has problem and republish stream failed","publish","",[JSON.stringify(Et)]),yield t(),this.localStreamConnectErrorWatcher.next(Jt())}}else{if(!ie){console.log("muteHandler:\u97F3\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}p("brtc\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38\uFF0C\u9700\u8981\u91CD\u65B0\u63A8\u6D41\u5904\u7406","publish","",["videoEnable",re,"audioEnable",ie,"type",e]),this.localStreamConnectErrorWatcher.next(Kr("\u9EA6\u514B\u98CE")),(Te=this.audioStream)==null||Te.destroy(),(xe=this.localModel.player)==null||xe.destroy(),this.audioStream=null,this.audioStream=yield this.room.createPBSingleLocalStream({video:!1,audio:!0});let _=(Le=this.audioStream)==null?void 0:Le.getAudioTrack();_&&!_.muted?this.localModel.stream&&(yield this.localModel.stream.replaceTrack(_).then(()=>{this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}).catch(de=>{p("\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38, \u91CD\u65B0\u521B\u5EFAaudio stream replace \u5931\u8D25","publish","",[JSON.stringify(de)]),this.localStreamConnectErrorWatcher.next(Jt()),t()})):(p("recreate audio stream failed, now unpublish","publish"),this.localStreamConnectErrorWatcher.next(Jt()),t())}}this.localStreamErrorWatcher.next(e)}),1e3)}unpublishStream(e=!1){return c(this,null,function*(){var r,i,o,a,n,l,u;d("unpublish stream","publish",(r=this.localModel)==null?void 0:r.userId);let t=this.getLocalStreamModel();if(t){let m=t.stream;m&&e===!0&&(yield(i=this.room)==null?void 0:i.unpublish(m).catch(h=>{p("brtc \u53D6\u6D88\u53D1\u5E03\u5931\u8D25","publish",t.userId,[JSON.stringify(h)])}),m==null||m.destroy(),(o=this.localModel)==null||o.updateStream(void 0,!0,this),(a=this.audioStream)==null||a.destroy(),(n=this.brtcStream)==null||n.destroy(),this.brtcStream=null,this.audioStream=null);try{this.removeFromRecorder(m),(l=this.videoStream)==null||l.destroy(),this.videoStream=null,(u=this.bloudStream)!=null&&u.published&&(yield this.bloudStream.unpublish().catch(h=>{p("bloud unpublish stream failed","publish",t.userId,[JSON.stringify(h),h==null?void 0:h.code,h==null?void 0:h.message])})),t.updateBloudStream(void 0,this)}catch(h){p("stream destroy failed","publish",t.userId,[JSON.stringify(h)])}}})}muteOrUnpublishStream(e,t,r,i=!1){return c(this,null,function*(){let o=r.stream,a=!0;e==="audio"?a=r.videoEnable:e==="video"&&(a=r.audioEnable),a?e==="audio"?((yield o.muteAudio())||p("brtc muteAudio\u5931\u8D25","publish","\u672C\u5730",["muteAudio\u5931\u8D25"]),yield this.bloudStream.setAudioEnabled(!1).catch(l=>{p("bloud setAudioEnabled \u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(l)])}),r.updateBloudStream({audio:!1,video:!0,isScreen:!1},this)):e==="video"&&(yield this.justReplaceVideoTrack(o),yield this.bloudStream.setVideoEnabled(!1).catch(n=>{p("bloud setVideoEnabled \u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(n)])}),r.updateBloudStream({video:!1,audio:!0,isScreen:!1},this)):(e=="video"?this.justReplaceVideoTrack(o):e=="audio"&&((yield o.muteAudio())||p("brtc muteAudio\u5931\u8D25","publish","\u672C\u5730")),yield this.unpublishStream(i))})}justReplaceVideoTrack(e){return c(this,null,function*(){var i;let r=s.getCanvasStream().getVideoTracks()[0];try{yield e.replaceTrack(r),yield e.muteVideo()}catch(o){p("\u5173\u95ED\u672C\u5730\u89C6\u9891\u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(o)])}try{(i=this.videoStream)==null||i.destroy(),this.videoStream=null}catch(o){p("this.videoStream destroy failed","publish")}})}toggleShareScreen(i){return c(this,arguments,function*(e,t={},r){var a,n,l,u,m;d("\u5F00\u5173\u5171\u4EAB\u5C4F\u5E55","publish","\u5F00\u5173\u5171\u4EAB\u5C4F\u5E55",["stats => ",e]),!e&&((a=this.room)!=null&&a.boomCore.shareScreenStream)&&this.removeFromRecorder((n=this.room)==null?void 0:n.boomCore.shareScreenStream),e||(this.localShareCustomStats={});let o=(l=this.room)==null?void 0:l.voiceMode;return t.audioHint=o,yield this.room.boomCore.toggleShareScreen(e,t,r).then(()=>{if(this.localModel.getUser().hasShare=!0,d("bmStreamVm toggleShareScreen success","\u5207\u6362\u5171\u4EAB\u5C4F\u5E55","",["enable =>",e]),e){let h=this.room.boomCore.shareScreenStream;h&&this.remoteStreamPublished(h)}else this.localModel.getUser().hasShare=!1,this.localModel.getUser().removeStream(`${this.localModel.userId}_screen`),this.localModel.getUser().updateSortNum(!0)}).catch(h=>(p("bmStreamVm toggleShareScreen error","\u5207\u6362\u5171\u4EAB\u5C4F\u5E55","",["enable =>",e]),Promise.reject(h))),e&&((u=this.room)!=null&&u.boomCore.shareScreenStream)&&this.addToRecorder((m=this.room)==null?void 0:m.boomCore.shareScreenStream),this.localIsShare=e,this.isShareWatcher.next(e),Promise.resolve(!0)})}setShareScreenContentHint(e){var t;(t=this.room)==null||t.boomCore.setShareScreenContentHint(e)}createCanvas(){let e=document.createElement("canvas");e.id="tarCanvas",e.style.width="1px",e.style.height="1px",e.style.position="absolute",e.style.bottom="0",document.body.appendChild(e)}canvasDisplay(){let e=document.getElementById("tarCanvas");if(e){e.width=640,e.height=360;let t=e.getContext("2d");t.fill(),t.beginPath(),t.fillStyle="rgb(0,0,0)",t.fillRect(0,0,e.width,e.height),this.canvasTimer&&clearTimeout(this.canvasTimer),this.canvasTimer=setTimeout(()=>{this.canvasDisplay()},1e3)}}static getCanvasStream(){return document.getElementById("tarCanvas").captureStream()}createVideoStreamTrack(){return c(this,null,function*(){var e,t,r;return((e=this.room)==null?void 0:e.videoDevices.length)==0&&(I("\u5F53\u524D\u7535\u8111\u4E2D\u6CA1\u6709\u89C6\u9891\u8F93\u5165\u8BBE\u5907, \u91CD\u65B0\u83B7\u53D6","publish"),yield(t=this.room)==null?void 0:t.initDevices()),(r=this.videoStream)==null||r.destroy(),this.videoStream=null,this.videoStream=yield this.room.createPBSingleLocalStream({video:!0,audio:!1},this.localModel.userId).catch(i=>(p("createPBSingleLocalStream error","publish","",[JSON.stringify(i)]),Promise.reject(i))),this.videoStream.getVideoTrack()})}startRecord(e){return c(this,null,function*(){var r;if(this._recorder)return;this._recorder=(r=this.room)==null?void 0:r.boomCore.createRecorder(e),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record: ended","record")}),this._recorder.on("started",()=>{var i;d("record: started.","record"),this._recorder.muteAudio(!((i=this.localModel)!=null&&i.audioEnable))});let t=!0;try{yield this._recorder.start(),this._isRecording=!0,this.isRecordingWatcher.next(!0),this.shareStreamModels.forEach(i=>{i.stream&&!i.stream.isLocalStream()&&i.stream.isSubscribed()&&this.addToRecorder(i.stream)}),this.streamModels.forEach(i=>{i.stream&&!i.stream.isLocalStream()&&i.stream.isSubscribed()&&this.addToRecorder(i.stream)})}catch(i){I("record: error","record","",[JSON.stringify(i)]);let o=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),t=!1,yield o==null?void 0:o.stop()}return t})}addToRecorder(e){var t;e.isLocalStream()&&!e.isScreenStream()||this._isRecording&&!this._slicingRecord&&(e.on("audio-track-ended",()=>{this.removeFromRecorder(e)}),(t=this._recorder)==null||t.addStream(e))}removeFromRecorder(e){var t;this._isRecording&&!this._slicingRecord&&((t=this._recorder)==null||t.removeStream(e))}stopRecord(){return c(this,null,function*(){if(d("record:stopRecord","record"),!this._recorder){I("stopRecord recorder is null","record","");return}this._isRecording=!1,this.isRecordingWatcher.next(!1),yield this._recorder.stop(),this._recorder=void 0})}sliceRecord(e,t,r){return c(this,null,function*(){var a,n,l;if(!this._isRecording)return;let i=(a=this._recorder)==null?void 0:a._opts;this._slicingRecord=!0;try{yield(n=this._recorder)==null?void 0:n.stop()}catch(u){p("record:stop record exception","","",[JSON.stringify(u)])}i.filename=e,this._recorder=(l=this.room)==null?void 0:l.boomCore.createRecorder(i),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record:record ended.")}),this._recorder.on("started",()=>{var u;d("record:record started."),this._recorder.muteAudio(!((u=this.localModel)!=null&&u.audioEnable))});let o=!0;try{yield this._recorder.start(t,r),this._slicingRecord=!1,this.shareStreamModels.forEach(u=>{u.stream&&!u.stream.isLocalStream()&&u.stream.isSubscribed()&&this.addToRecorder(u.stream)}),this.streamModels.forEach(u=>{u.stream&&!u.stream.isLocalStream()&&u.stream.isSubscribed()&&this.addToRecorder(u.stream)})}catch(u){let m=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),this._slicingRecord=!1,o=!1,console.log("record:stopRecord.error",u),yield m==null?void 0:m.stop()}return o})}startSpeakerDetector(){var e;this._speaker=null,this._speakerDetector=(e=this.room)==null?void 0:e.boomCore.createSpeakerDetector(),this._speakerDetector.on("speaker",t=>{var i,o,a;let r=!0;t?(((i=this._speaker)==null?void 0:i.getUserInfo().userId)===t.getUser().userId&&(r=!1),this._speaker=t.getUser()):(this._speaker||(r=!1),this._speaker=null),r&&(d("\u5F53\u524D\u8BB2\u8BDD\u4EBA","\u8BED\u97F3\u6FC0\u52B1",(o=this._speaker)==null?void 0:o.userId,["nickname => ",(a=this._speaker)==null?void 0:a.nickname]),this.speakerWatcher.next(this._speaker))})}addToDetector(e){this._speakers.set(e.getID(),e),this._speakerDetector&&this._speakerDetector.addStream(e)}removeFromDetector(e){let t=this._speakers.get(e);this._speakerDetector&&t&&(this._speakers.delete(e),this._speakerDetector.removeStream(t))}clearDetector(){let e=[];this._speakers.forEach((t,r)=>{e.push(r)}),e.forEach(t=>{this.removeFromDetector(t)})}shareCustomMedia(e,t){return c(this,null,function*(){var r;return(r=this.room)==null?void 0:r.boomCore.shareHTMLMedia(e,t)})}updateBloudStreamCustomStats(e,t,r){return c(this,null,function*(){var o,a;d("update bloud stream custom stats","",e,[t,JSON.stringify(r)]);let i=yield(o=this.room)==null?void 0:o.boomCore.updateStream(e,t,r);((a=this.localModel)==null?void 0:a.userId)===e&&t.startsWith(e)&&t.endsWith("_screen")&&i.customInfo&&(this.localShareCustomStats=i.customInfo)})}checkStreamStats(e){d("check stream stats","","",[e]),this.streamModels.size<100&&this.streamModels.forEach(t=>{t.checkStreamIsPlaying()})}clearCache(){var e,t,r,i,o;try{(t=(e=this.localModel)==null?void 0:e.stream)==null||t.destroy(),(r=this.videoStream)==null||r.destroy(),(i=this.audioStream)==null||i.destroy()}catch(a){}this.canvasTimer&&clearTimeout(this.canvasTimer),this.canvasTimer=null,this.streamModels.clear(),this.shareStreamModels.clear(),(o=this.room)==null||o.userVM.clearUsers(),this.shareBloudStateMap.clear()}};import{BehaviorSubject as K,Subject as It}from"rxjs";import{debounce as Qt}from"lodash-es";var Ye=class{constructor(e){this._roomName="";this.msgSeq="";this.roomID="";this.audioOff=!1;this.selfopenaudio=!1;this.lock=!1;this.leaveNotice=!1;this.openSelf=!1;this.chatNotice="";this.chatNoticeRich="";this.raiseHandsList=new Map;this.raiseHandsWatcher=new K(Array.from(this.raiseHandsList.values()));this.raiseVideoHandsList=new Map;this.raiseVideoHandsWatcher=new K(Array.from(this.raiseVideoHandsList.values()));this.raiseSimpleHandsList=new Map;this.raiseSimpleHandsWatcher=new K(Array.from(this.raiseSimpleHandsList.values()));this.operationPermissionWatcher=new It;this.chatNoticeWatcher=new It;this.totalUserWatcher=new K(0);this.totalWaitRoomUserWatcher=new K(0);this.isOpenWaitRoom=new It;this.originJoinRoomParams={};this.originRespInfo={};this.audioOffWatcher=new It;this.lockWatcher=new K(this.lock);this.leaveNoticeWatcher=new K(this.leaveNotice);this.openSelfWatcher=new K(this.openSelf);this.setRaiseHandsWatcherValue=Qt(()=>{this.raiseHandsWatcher.next(Array.from(this.raiseHandsList.values()))},1e3);this.setVideoRaiseHandsWatcherValue=Qt(()=>{this.raiseVideoHandsWatcher.next(Array.from(this.raiseVideoHandsList.values()))},1e3);this.setSimpleRaiseHandsWatcherValue=Qt(()=>{this.raiseSimpleHandsWatcher.next(Array.from(this.raiseSimpleHandsList.values()))},1e3);this.room=e,y.emitter.on(O,t=>{t.status==="raiseHandsAudio"?t.user.raiseAudioHands?this.addRaiseHandUser(t.user):this.removeRaiseHandUser(t.user.userId):t.status==="raiseHandsVideo"?t.user.raiseVideoHands?this.addVideoRaiseHandUser(t.user):this.removeVideoRaiseHandUser(t.user.userId):t.status==="raiseHand"&&(t.user.raiseHand?this.addSimpleRaiseHandUser(t.user):this.removeSimpleRaiseHandUser(t.user.userId))})}get roomName(){return this._roomName?this._roomName:(this._roomName=this.room.getName(),this._roomName)}get isBigRoom(){return this.room.isBig}get startup(){var e;return(e=this.room.boomCore.client)==null?void 0:e.startup}setup(e){this.roomID=e.room,this.handleInitParams(),this.originRespInfo=e}initCustomStats(e){this.operationPermission=e,e.chatNotice!==void 0&&(this.chatNotice=e.chatNotice),e.chatNoticeRich!==void 0&&(this.chatNoticeRich=e.chatNoticeRich),this.operationPermissionWatcher.next(this.operationPermission)}updateOperationPermission(e){this.operationPermission=P(P({},this.operationPermission),e),e.chatNotice!==void 0&&(this.chatNotice=e.chatNotice),e.chatNoticeRich!==void 0&&(this.chatNoticeRich=e.chatNoticeRich),this.operationPermissionWatcher.next(this.operationPermission)}handleInitParams(){let e=this.room.boomCore.getAudioOff(),t=this.room.boomCore.getSelfOpenAudio();this.setAudioOff(e,t)}setAudioOff(e,t){this.audioOff=e,this.selfopenaudio=t,this.audioOffWatcher.next({audioOff:e,selfopenaudio:t})}setlock(e){this.lock=e,this.lockWatcher.next(e)}setLeaveNotice(e){this.leaveNotice=e,this.leaveNoticeWatcher.next(e)}setRaiseHandsList(e){e.forEach(t=>{t.raiseAudioHands&&this.raiseHandsList.set(t.getID(),t),t.raiseVideoHands&&this.raiseVideoHandsList.set(t.getID(),t),t.raiseHand&&this.raiseSimpleHandsList.set(t.getID(),t)}),this.setRaiseHandsWatcherValue(),this.setVideoRaiseHandsWatcherValue(),this.setSimpleRaiseHandsWatcherValue()}addRaiseHandUser(e){this.raiseHandsList.set(e.getID(),e),this.setRaiseHandsWatcherValue()}removeRaiseHandUser(e){this.raiseHandsList.delete(e),this.setRaiseHandsWatcherValue()}addVideoRaiseHandUser(e){this.raiseVideoHandsList.set(e.getID(),e),this.setVideoRaiseHandsWatcherValue()}removeVideoRaiseHandUser(e){this.raiseVideoHandsList.delete(e),this.setVideoRaiseHandsWatcherValue()}addSimpleRaiseHandUser(e){this.raiseSimpleHandsList.set(e.getID(),e),this.setSimpleRaiseHandsWatcherValue()}removeSimpleRaiseHandUser(e){this.raiseSimpleHandsList.delete(e),this.setSimpleRaiseHandsWatcherValue()}};import{BehaviorSubject as yt,Subject as D}from"rxjs";var qt={name:"@hysc/meeting",version:"10.7.3",description:"boom meeting",private:!1,main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",files:["dist","umd"],scripts:{build:"tsup ./src/index.ts --format cjs,esm --dts --minify",dev:"tsup ./src/index.ts --format esm,cjs --watch --dts"},author:"yangliye",license:"MIT",dependencies:{"@hysc/bloud":"workspace:*","@hysc/core":"workspace:*","@hysc/p-queue":"6.3.0","@hysc/utils":"workspace:*","detect-browser":"^5.3.0",immutable:"5.0.0-beta.4","lodash-es":"^4.17.21",mitt:"^3.0.0",rxjs:"^7.5.5",typescript:"^4.6.3"},peerDependencies:{"@hysc/core":"workspace:*"},devDependencies:{"@hysc/brtc":"workspace:*","@types/lodash-es":"^4.17.6"}};import{Logger as si,LOGLEVEL as bs}from"@hysc/utils";var Ze=class{constructor(e){this.pullMap=new Map;this.room=e}addUser(e){let t=e.id;e.isScreen&&(t=`${t}_screen`),this.pullMap.set(t,e)}removeUser(e){let t=e.id;e.isScreen&&(t=`${t}_screen`),this.pullMap.delete(t)}restart(){this.room.restartPullUsers(this.pullMap)}};import{BMCameraNotAuthError as Is,BMCameraOccupyError as ys,BMCreateStreamError as Es,BmLeaveError as Ms,BMMicNotAuthError as Cs,BMMicOccupyError as vs,BmSetAudioOffError as Bs,BmSetMsgOffError as As,BmSetVideoOffError as Rs,BMShareStreamConnectError as Us,BMStreamConnectError as Ps,BMStreamReconnectFailed as Ns,BMStreamReconnectSuccess as ws,BmUpdateCustomStatsError as Ts,getStreamError as xs,RepeatJoinError as Ls}from"@hysc/utils";var zt=class{constructor(e){this.room=e}get localBMUser(){return this.room.getLocalParticipant()}get localIsAudience(){return this.room.getLocalParticipant().isAudience}handlePull(e){return c(this,null,function*(){if(this.localIsAudience){if(e.isMixer){if(this.room.ignoreMixer){d(" \u914D\u7F6E\u4E86\u4F7F\u7528 CDN\u6D41\uFF0C\u4E0D\u62C9\u6DF7\u6D41 handlePull ignore mixer");return}yield this.room.handlePull(e);return}if(this.localBMUser.audienceEnableSpeaking&&e.audioEnable){yield this.room.handlePull(e);return}}else e.isMixer||(yield this.room.handlePull(e))})}handleChangeStreamType(e){return c(this,null,function*(){yield this.room.handleChangeStreamType(e)})}handlePlay(e,t){return c(this,null,function*(){this.localIsAudience&&!this.localBMUser.audienceEnableSpeaking?e.isMixer&&(yield this.room.handlePlay(e)):yield this.room.handlePlay(e)})}handleAudienceDisable(e){return c(this,null,function*(){this.room.bmStreamVm.getStreamModels().forEach(t=>{var r;t.isMixer||!t.isLocal&&t.stream&&((r=t.stream)!=null&&r.isSubscribed())&&t.hasPulled&&(t.hasPulled=!1,t.pulledStreamType="small",this.room.unsubscribe(t.stream).then(()=>{console.log("\u89C2\u4F17\u53D6\u6D88\u8BA2\u9605\u8FD9\u80A1\u6D41",t.userId,t.nickname,t.isDisplay,t.isCurrentDisplay)}))}),this.handleMixStream(!1,e)})}handleAudienceEnable(e){return c(this,null,function*(){this.handleMixStream(!0,e),this.room.bmStreamVm.getStreamModels().forEach(t=>{t.isMixer||k.addQueue(this.room.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)})})}handleMixStream(e,t){return c(this,null,function*(){var i,o;let r=this.room.bmStreamVm.mixStreamUid;if(r){let a=this.room.bmStreamVm.streamModels.get(r);e?(i=a==null?void 0:a.stream)==null||i.muteAudio().then(()=>{d(`play:\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${r}`)}):this.room.ignoreMixer||(o=a==null?void 0:a.stream)==null||o.unmuteAudio().then(()=>{d(`play:\u53D6\u6D88\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${r}`)})}t==null||t(e)})}},ei=zt;import{debounce as oi,isNumber as Os,toNumber as ai,delay as ks}from"lodash-es";import{BrtcEvents as ti}from"@hysc/utils";function ri(s){var r,i;let e=()=>s.fire(ti.BRTC_ROOM_ROCONNECTING),t=()=>s.fire(ti.BRTC_ROOM_RECONNECTED);(r=s.brtcClient.client)==null||r.signal.channel.on("reconnecting",e),(i=s.brtcClient.client)==null||i.signal.channel.on("reconnected",t)}import{AudioPlayer as cs}from"@hysc/core";import{Subject as us}from"rxjs";var Ke=class{constructor(e,t){this.playMap=new WeakSet;this.playerMap=new Map;this.muted=!1;this.playStateChangeWatcher=new us;var i;let r=document.getElementById(e);if(r)this.container=r;else throw new Error("no container found, play failed");this.room=t,this.deviceId=(i=t.selectAudioOutputDevice)==null?void 0:i.deviceId}addStream(e,t=!1){let r=this.room.localUser,i=r.audienceEnableSpeaking;if(r.isAudience)if(i){if(!(e.getUserId().toString()+"".includes("-mixer-"))){d("audienceEnableSpeaking is true, only play mixer stream","",e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}}else{I("audienceEnableSpeaking is false, not play audio","",e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}this.room.shouldPlayAudio&&this.room.autoPlayAudio&&e.isSubscribed()&&(t||!this.playMap.has(e))&&(d("add stream to player","",e.getUserId(),["streamId ",e.getStreamId()]),this.playMap.add(e),this.play(e))}removeStream(e){let t=e.getStreamId(),r=this.playerMap.get(t);r&&r.destroy(),d("remove audio player","","",["streamId =>",t]),this.playerMap.delete(t),this.playMap.delete(e)}removeStreamByUid(e){let t=new Map;this.playerMap.forEach(r=>{q(r.stream)||r.stream.getUserId()===e&&t.set(r.stream.getStreamId(),r)}),t.forEach((r,i)=>{r.off(),r.destroy(),this.playerMap.delete(i),this.playMap.delete(r.stream)}),t.clear()}play(e){return c(this,null,function*(){var t;if(e.hasAudio()&&this.container){let r=new cs(this.container,{});this.addPlayerEvent(r),yield r.play(e);let i=Ne(e.getUserId().toString());if(this.deviceId?yield r.setSinkId(this.deviceId):(I("audioPlayer play() this.deviceId is null ","",i,["streamId =>",e.getStreamId()]),Q()&&(yield r.setSinkId("default"))),this.muted)r.setVolume(0);else{let o;if(q(e)?o=this.room.bmStreamVm.shareStreamModels.get(i):o=this.room.bmStreamVm.streamModels.get(i),o){let a=(t=o.bloudStream)==null?void 0:t.customInfo;a&&a.volume&&(r.audioLevel=a.volume,r.setVolume(a.volume))}}this.playerMap.set(e.getStreamId(),r)}})}mute(e){this.muted=e,e?this.playerMap.forEach(t=>t.setVolume(0)):this.playerMap.forEach(t=>{t.audioLevel>0?t.setVolume(t.audioLevel):t.setVolume(1)})}setVolume(e,t){let r=this.playerMap.get(e);if(r){if(r.audioLevel=t,this.muted)return;r.setVolume(t)}else p("\u8BBE\u7F6E\u4E86\u6D41\u7684\u97F3\u91CF\uFF0C\u4F46\u662F\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u64AD\u653E\u5668",e)}setDevice(e,t=!1){return c(this,null,function*(){d("setDevice:","","",[e]),e&&(this.deviceId=e,this.playerMap.forEach(r=>r.setSinkId(e)))})}addPlayerEvent(e){e.on("player-state-changed",t=>{e.stream&&(d("audio player state change","","",[JSON.stringify(t)]),t.type==="error"&&t.reason&&t.reason.name==="NotAllowedError"&&this.playStateChangeWatcher.next(e),t.state==="PAUSED"&&e.resume())})}clear(){d("audio play clear"),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}destroy(){d("audio play destroy"),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}};var Mt=1,Ds={audio:!0,video:!0,streamType:"small",videoEnable:!0,audioEnable:!0},ze=!0,we=class{constructor({initDevices:e,ignoreMixer:t}={initDevices:!0,ignoreMixer:!1}){this.roomVM=null;this.videoDevices=[];this.audioDevices=[];this.audioOutputDevices=[];this.selectVideoDevice=null;this.selectAudioDevice=null;this.selectAudioOutputDevice=null;this.streamQueue=new Ze(this);this.userListColumns=1;this.sortType=1;this.BRTCConnectFailed=!1;this.pubFailedNum=0;this.streamConnectedErrorQueue=[];this.conferenceMode=1;this.isBig=!1;this.selectVideoDeviceWatcher=new yt(this.selectVideoDevice);this.selectAudioDeviceWatcher=new yt(this.selectAudioDevice);this.selectAudioOutputDeviceWatcher=new yt(this.selectAudioOutputDevice);this.audioDevicesWatcher=new D;this.videoDevicesWatcher=new D;this.audioOutputDevicesWatcher=new D;this.raiseHandleRespWatcher=new D;this.enableAudienceSpeakingWatcher=new D;this.deviceChangeWatcher=new D;this.mediaPermission={microphone:!0,camera:!0,screen:!0};this.videoProfile="360p";this.audioProfile=null;this.voiceMode="";this.videoEncodeConfig=null;this.streamWSReconnectWatcher=new D;this.bloudWSReconnectWatcher=new D;this.netConnecting=!0;this.netConnectingWatcher=new D;this.hasSyncPermission=!0;this.meetingControlOptions={cancelAutoPull:!1};this.forceId="";this.networkState={bloud:!0,brtc:!0};this.brtcNetEnableWatcher=new D;this.autoPlayAudio=!0;this.pubFailedTimer=null;this.messageWatcher=new yt({type:"init",status:!1,isNotCancelRootReport:!1});this.isInWaitRoom=!1;this.shouldPlayAudio=!0;this.deviceChanging=!1;this.ignoreMixer=!1;this.handleReprocessStreamError=()=>{this.netConnecting&&this.networkState.brtc&&this.networkState.bloud&&this.streamConnectedErrorQueue.length&&(d("brtc \u7F51\u7EDC\u6062\u590D\u6B63\u5E38\uFF0C\u5904\u7406\u91CD\u63A8\u903B\u8F91","","",this.streamConnectedErrorQueue),this.streamConnectedErrorQueue.forEach(e=>{this.handleStreamConnectError(e)}),this.streamConnectedErrorQueue=[])};this.handleMediaDevicesChange=e=>c(this,null,function*(){d("media devices change"),this.deviceChanging=!0,ks(()=>{this.deviceChanging=!1},1200);let{changed:t,selectAudioDevice:r,selectAudioOutputDevice:i,selectVideoDevice:o}=yield this.initDevices(!0),a=r,n=i;t&&(this.deviceChangeWatcher.next(!0),a=this.selectAudioDevice,n=this.selectAudioOutputDevice),o&&(yield this.bmStreamVm.changeVideoInput(o)),yield this.bmStreamVm.changeAudioInput(a),yield this.bmStreamVm.changeSpeaker(n).catch(l=>{})});this.enumVideoDevices=()=>fs().then(e=>{if(!Q())return e;let t=[];return e.forEach((r,i)=>{r.name.includes("front")||r.name.includes("\u524D\u7F6E")?r.name=`\u524D\u7F6E${i.toString().padStart(2,"0")}`:(r.name.includes("back")||r.name.includes("\u540E\u7F6E"))&&(r.name=`\u540E\u7F6E${i.toString().padStart(2,"0")}`),t.push(r)}),t});this.enumAudioInputDevices=()=>ps().then(e=>{let t=e,r=e.find(i=>i.default);if(r){let i=Object.assign({},r);i.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${r==null?void 0:r.name}\uFF09`,t.unshift(i)}return t});this.enumAudioOutputDevices=()=>gs().then(e=>{let t=e,r=e.find(i=>i.default);if(r){let i=Object.assign({},r);i.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${r==null?void 0:r.name}\uFF09`,t.unshift(i)}return t});this.getPermissions=Ss;this.checkSystemSupport=ms;this.createStream=hs;this.participantNotice=!1;this.handleQueueTask=(e,t=!1)=>c(this,null,function*(){if(!this.BRTCConnectFailed&&!(!e.isLocal&&this.meetingControlOptions.cancelAutoPull&&!e.shouldPull)){if(!this.streamModelExits(e)){I(`streamModel is not exits, userId: ${e.userId}, isShare: ${e.isShare}, ignore`);return}yield this.handleStreamTask(e,t)}});this.republishLocalStream=oi(e=>c(this,null,function*(){let t=e.getAudioOn()||this.localUser.audioEnable||!1,r=e.getVideoOn()||this.localUser.videoEnable||!1;d("republish local stream ","","",[t,r]),yield this.publish(e).then(()=>c(this,null,function*(){this.bmStreamVm.bloudStream=null,yield this.bmStreamVm.publishBloudStream(t,r),d("local stream connect error, and republish success, bloud stream republish success","","",["audio =>",t," video => ",r]),this.bmStreamVm.localStreamConnectErrorWatcher.next(ws(t,r))})).catch(()=>{d("local stream connect error, and republish failed","","",["audio =>",t," video => ",r]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Ns())})}),1e3);this.processUser=(e,t=0)=>c(this,null,function*(){let r="";if(e.isScreen){let i=this.bmStreamVm.getShareStreamModelByUId(e.id);(!i||!i.stream&&!i.isLocal)&&(e.isWeb?r=`${e.id}_screen`:r=e.id)}else{let i=this.bmStreamVm.streamModels.get(e.id);i&&!i.stream&&!i.isLocal&&(r=e.id)}if(r){d("brtc query streams","","",["queryId => ",r]);try{let i=yield this.queryBrtcStreams([r]);if(i&&i.length){let o=i.map(a=>[a.getUserId(),a.getStreamId()]);d("brtc query streams result ","","",["streamInfo =>",JSON.stringify(o)]),i&&this.handleAddStreams(i)}else t<10?(t+=1,yield H(1e3),this.processUser(e,t)):I(`query stream error: uId:${e}`)}catch(i){p("query stream error","","",[JSON.stringify(i),t]),t<10&&(t+=1,yield H(1e3),this.processUser(e,t))}}});si.setLogLevel(bs.INFO),d(`
2
2
  ******************************************************************************
3
3
  * \u6B22\u8FCE\u4F7F\u7528 BoomCore(${qt.version})
4
4
  ******************************************************************************