@hysc/meeting 10.9.0 → 10.9.2
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.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var hr=Object.defineProperty,pr=Object.defineProperties;var fr=Object.getOwnPropertyDescriptors;var ti=Object.getOwnPropertySymbols;var gr=Object.prototype.hasOwnProperty,Sr=Object.prototype.propertyIsEnumerable;var ii=(s,e,t)=>e in s?hr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,N=(s,e)=>{for(var t in e||(e={}))gr.call(e,t)&&ii(s,t,e[t]);if(ti)for(var t of ti(e))Sr.call(e,t)&&ii(s,t,e[t]);return s},Oe=(s,e)=>pr(s,fr(e));var c=(s,e,t)=>new Promise((i,r)=>{var o=l=>{try{n(t.next(l))}catch(u){r(u)}},a=l=>{try{n(t.throw(l))}catch(u){r(u)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(o,a);n((t=t.apply(s,e)).next())});import ys,{checkSystemSupport as Ms,createStream as Es,enumAudioInputDevices as Cs,enumAudioOutputDevices as vs,enumVideoDevices as Bs,getPermissions as As}from"@hysc/core";var U=class extends Error{constructor(t,i,r,o){super();this.code=t,this.error=r,this.BoomErrorFlag=!0,this.eName=o,this.message=i}static instanceOf(t){return!!(t&&t.BoomErrorFlag)}getCode(){return this.code}};var ri=1,br=2,si=3,Ir=4;var yr=function(){},Zs=/BRTC/.test(yr.toString())?ri:si;function tt(s,e,t,i){let r=[];return t&&r.push(t),i&&r.push(i),`[${new Date().toLocaleTimeString("chinese",{hour12:!1})}] <${s}> [${r.join("|")}] ${e}`}function Mr(s,e,t,i=[]){i.unshift(tt("DEBUG",s,e,t)),console.log(...i)}function d(s,e,t,i=[]){Array.isArray(i)||(i=[i]),i.unshift(tt("INFO",s,e,t)),console.log(...i)}function I(s,e,t,i=[]){Array.isArray(i)||(i=[i]),i.unshift(tt("WARN",s,e,t)),console.log(...i)}function p(s,e,t,i=[]){typeof i=="string"?i=[i]:Array.isArray(i)||(i=[JSON.stringify(i)]),i.unshift(tt("ERROR",s,e,t)),console.log(...i)}var Ks={[ri]:Mr,[br]:d,[si]:I,[Ir]:p};import{BehaviorSubject as zr}from"rxjs";var oi="undefined";var Er=typeof window!==oi?window:void 0;var eo=typeof global!==oi?global:Er;var to=Object.freeze({}),io=Object.freeze([]);var P="c";import{BehaviorSubject as Pr}from"rxjs";var T="_screen",rt="screen-",st="xinhao_";var me="sub-message",he="user-sort-num-change",pe="bind-element",se="stream-connect-error",k="raise-hand",fe="manual-subscription",ge="unsubscribe-stream",Se="change-is-guest",be="bind-big-element",oe="no-container",Ie="model-sort-num-change",ye="add-pull-user",Me="set-volume",Ee="add-audio-play",V="stream-play",ot="share-file";import Cr from"mitt";var B=class B{static getInstance(){return B.emitter||(B.emitter=Cr()),B.emitter}};B.emitter=void 0,B.removeEmitter=()=>{var e,t,i,r,o,a,n,l,u,m,h,g,S,b,E;(e=B.emitter)==null||e.off(me),(t=B.emitter)==null||t.off(he),(i=B.emitter)==null||i.off(se),(r=B.emitter)==null||r.off(k),(o=B.emitter)==null||o.off(ge),(a=B.emitter)==null||a.off(fe),(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),(g=B.emitter)==null||g.off(ye),(S=B.emitter)==null||S.off(Me),(b=B.emitter)==null||b.off(Ee),(E=B.emitter)==null||E.off(V),B.emitter=void 0};var M=B;function ai(s){return Bt===2?Ar(s):Br(s)}function Br(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 Ar(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 ni="undefined";var _e="function";var Ur=typeof window!==ni?window:void 0;var po=typeof global!==ni?global:Ur;var fo=Object.freeze({}),go=Object.freeze([]),At="";function Ut(s){return typeof s===_e}function Rr(s,e,t){return s.indexOf(e,t!==void 0?t:0)}function ci(s,e){return Rr(s,e)>=0}function ui(s,e){return s!=null&&s.toString?s.toString():e!==void 0?e:At}function Nt(s){return Ut(s)&&ci(ui(s),"[native code]")}var Pt;typeof setImmediate===_e&&Nt(setImmediate)&&(Pt=setImmediate);typeof MessageChannel===_e&&Nt(MessageChannel)?Pt=function(s){let e=new MessageChannel;e.port1.onmessage=s,e.port2.postMessage(1)}:Pt=setTimeout;var di=5*60*1e3;function wt(s){let e=new Date(s),t=new Date,i=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,r=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:i+"\u6708"+r+"\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 mi(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 nt(s){return Ge(s,"a")}function Tt(s){return Ge(s,"v")}function lt(s){return Ge(s,"m")}function ct(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 r;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=(r=e.userInfo)==null?void 0:r.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=nt(e.permission.permission)),this.raiseHandTime=e.raiseHandTime||0;let i={operation:"none",user:this};this.watcher=new Pr(i),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,i,r){this.isLocal=!0,this.userId=e,this.userInfo=t,i?this.nickName=i:this.nickName=t.nickname,this.avatar=t.avatar,r&&r.signals&&(this.signals=r.signals),this.customInfo=r}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(st))}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={},i){var u,m;let r=(u=t==null?void 0:t.params)==null?void 0:u.customInfo,o=(r==null?void 0:r.updateKeys)||[];this.customInfo=r;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=r.raiseHandsAudio,n="raiseHandsAudio",M.emitter.emit(k,{status:"raiseHandsAudio",user:this}),a=!0),o.includes("raiseHandsVideo")&&(this.raiseVideoHands=r.raiseHandsVideo,n="raiseHandsVideo",M.emitter.emit(k,{status:"raiseHandsVideo",user:this}),a=!0),o.includes("raiseHand")&&(this.raiseHand=r.raiseHand,this.raiseHandTime=r.raiseHandTime,n="raiseHand",M.emitter.emit(k,{status:"raiseHand",user:this}),a=!0),i.conferenceMode!==1&&this.isAudience&&o.includes("permission")&&((r==null?void 0:r.permission.indexOf("A"))!==-1&&(i.enableAudienceSpeakingWatcher.next(!0),this.audienceEnableSpeaking=!0,n="audienceEnableSpeaking",this.isLocal&&i.bmLiveVM.handleAudienceEnable()),(r==null?void 0:r.permission.indexOf("A"))===-1&&(i.enableAudienceSpeakingWatcher.next(!1),this.audienceEnableSpeaking=!1,n="audienceEnableSpeaking",this.isLocal&&i.bmLiveVM.handleAudienceDisable())),o.includes("inBackground")&&(n="inBackground",this.inBackground=r.inBackground),o.includes("isCalling")&&(n="isCalling",this.isCalling=r.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"}`),M.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 i=ai(this);this.setSortNum(i,e,t)}setSortNum(e,t,i){this.sortNum===e&&!t||(this.sortNum=e,t&&M.emitter.emit(he,{isCommon:this.isCommonUser,isAudience:this.isAudience,shouldDelay:i}))}};import{BehaviorSubject as Ce}from"rxjs";function H(s){return new Promise(e=>setTimeout(e,s))}import{debounce as ut}from"lodash-es";var Be=["-mixer-","-rtmpmixer-","record#","robot_","stt_"],ve=500,dt="RWPSAVMO,RWPSAVM,RWPSAV,RWPSA",Fe=class s{constructor(e,t,i){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,i=!1)=>{var a;let r=this.addUser(e);if(this.room.isWorkShop&&!nt(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(r);{let n=this.room.bmStreamVm.streamModels.get(e.userId);n&&(e.stream.size?e.stream.forEach(l=>c(this,null,function*(){var g,S,b;let{video_enable:u,audio_enable:m,customInfo:h}=l;if(l.screen){r.hasShare=!0,this.room.bmStreamVm.shareBloudStateMap.set(e.userId,{audio:m,video:u,customInfo:h,userId:e.userId,streamId:l.getID(),isScreen:!0});let E={id:n.userId,isScreen:!0,isWeb:n.isWeb};t?yield(g=this.room)==null?void 0:g.processUser(E):(S=this.room)==null||S.addUser2Queue(E)}else if(n&&(n.updateBloudStream({video:u,audio:m,isScreen:l.screen,customInfo:h},this.room.bmStreamVm),t)){let E={id:n.userId,isScreen:!1,isWeb:n.isWeb};(b=this.room)==null||b.processUser(E)}})):(n.bloudStream&&n.updateBloudStream(void 0,this.room.bmStreamVm),(a=this.room)==null||a.bmStreamVm.removeShareStreamModelByUId(e.userId)))}return r&&r.isMaster&&this.masterUserWatcher.next(r),r==null||r.updateSortNum(i),r};this.updateAllSort=()=>{this.updateUserSort(),this.updateCommonUserSort(),this.updateAudienceUserSort(),this.updateSignalUserSort()};this.updateSortByType=e=>{var t,i;(t=this.room)!=null&&t.isSingleColumns||e.isCommon?(i=this.room)!=null&&i.isBig&&e.shouldDelay?this.updateDelayCommonUserSort():this.updateCommonUserSort():(e.isAudience?this.updateAudienceUserSort():this.updateUserSort(),this.updateSignalUserSort())};this.updateUserSort=ut(()=>{let e=this.sortUsers();this.userListWatcher.next(s.filterUsers(e))},200,{maxWait:1e3});this.updateCommonUserSort=ut(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},this.commTimer,{maxWait:12*1e3});this.updateDelayCommonUserSort=ut(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},120*1e3,{maxWait:120*1e3});this.updateAudienceUserSort=ut(()=>{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="",i=!1,r=0)=>c(this,null,function*(){let o=new Map;yield this.getAllUsers(e,o,t,i).catch(()=>{if(r<3){p("get bloud user error, retry"),r+=1,this.transBloudUsers(e,t,i,r);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=i,M.emitter||p("init boom emitter error"),M.emitter.on(Se,this.handleUserRoleChange.bind(this)),M.emitter.on(he,this.updateSortByType)}handleUserRoleChange(e){return c(this,null,function*(){var n,l,u;let{user:t,isGuest:i,preIsGuest:r}=e,o=(n=this.room)==null?void 0:n.roomInfo.isBigRoom;if(d("handleUserRoleChange","",t.userId,["isGuest =>",i,"preIsGuest =>",r,"isBigRoom =>",o]),((l=this.room)==null?void 0:l.userListColumns)===1||(r?this.userList.delete(t.userId):this.commonUserList.delete(t.userId),i?this.userList.set(t.userId,t):this.commonUserList.set(t.userId,t)),o)if(i)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 r;let t=this.getUser(e.userId);if(t)return d("\u8BE5\u7528\u6237\u5DF2\u7ECF\u52A0\u5165\u623F\u95F4",P,e.userId),this.updateUser(t,e),t;let i;return this.boomCore.userId==e.userId?(this.updateUser(this.localUser,e),i=this.localUser):i=this.toBMUser(e),((r=this.room)==null?void 0:r.userListColumns)===1?this.commonUserList.set(i.userId,i):i.isAudience?this.audiencesList.set(i.userId,i):i.isSignal?this.signalList.set(i.userId,i):i.isCommonUser?this.commonUserList.set(i.userId,i):this.userList.set(i.userId,i),i}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",P,e),t}videoEnable(e){let t=this.getUser(e);if(t)return t.videoEnable;throw new U(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}audioEnable(e){let t=this.getUser(e);if(t)return t.audioEnable;throw new U(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(st)?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,i="",r=!1){return c(this,null,function*(){let o;if(r){let{users:a,total:n}=yield this.boomCore.getUsersList(e,i,ve);o=a}else{let{users:a,total:n}=yield this.boomCore.getUsers(e,i,ve);o=a}o.forEach(a=>{t.set(a.userId,a)})})}initUserList(e){return c(this,null,function*(){var i,r;let t=e.get(this.localUser.userId);if(t){let o=this.addUser(t);if(!((i=this.room)!=null&&i.bmStreamVm.getStreamModelByUId(t.userId))){let a=this.getUser(t.userId);a?(r=this.room)==null||r.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,i=!1){e.forEach(r=>{this.addBCUser(r,t,i)})}updateMaster(e,t,i){let r=this.getUser(e);r&&(r.isManager&&(r.isManager=!1),r.isMaster=!0,r.updateSortNum());let o=this.getUser(t);return o&&(o.isMaster=!1,i&&(o.isManager=!0),o.updateSortNum()),!r&&!o&&p("\u672A\u627E\u5230\u8BE5\u7528\u6237, updateMaster\u672A\u751F\u6548",P,e,["masterId => ",e,"oldMasterId => ",t]),{master:r,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",P,e):p("\u672A\u627E\u5230\u8BE5\u7528\u6237, managerChangeToGuest\u672A\u751F\u6548",P,e),t}updateManager(e,t,i=!0){let r=this.getUser(e);return r?(r.permission.setManage(t),i?r.permission.setSubscribe(!0):r.permission.setSubscribe(t),this.boomCore.updateUser(e,{customInfo:{permission:r.permission.get()}}),r.watcher.next({operation:t?"getManager":"removeManager",user:r}),this.updateAllSort()):p("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, updateManager\u672A\u751F\u6548",P,e),r}getLocalUser(){return this.localUser}updateUser(e,t){var C,y,L,W,G,F,j,$;let i=this.checkIsMaster(t.userId),r=(((C=t.permission)==null?void 0:C.getManage())||lt((y=t.permission)==null?void 0:y.permission))&&!((L=t.permission)!=null&&L.getOwn()||ct((W=t.permission)==null?void 0:W.permission)),o="none",a=e.isMaster;e.isManager!==r&&(r?o="getManager":o="removeManager"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},10),a!==i&&(i?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 g=e.raiseAudioHands,S=t.customInfo.raiseHandsAudio;g!==S&&(!S&&g&&this.room.roomInfo.removeRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsAudio",user:e})},300));let b=e.nickname,E=t.nickname;if(b!==E&&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=i,e.isCreate=this.boomCore.getCreator()===t.userId,e.isAudience=!t.permission.getVideo(),e.isCommonUser=!t.permission.getSubscribe(),e.isManager=r,e.inBackground=!!((G=t==null?void 0:t.customInfo)!=null&&G.inBackground),e.isCalling=!!((F=t==null?void 0:t.customInfo)!=null&&F.isCalling),(j=t.customInfo)!=null&&j.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=ct(e),t.isManager=!ct(e)&<(e),t.isCommonUser=We(e),t.isAudience=!Tt(e),t.watcher.next({operation:"none",user:t})}toBMUser(e){var r,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=!Tt(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 i=this.boomCore.getLocalParticipant();if(!i)throw new U(1001,"BCUserVM addUser\u65F6\u672A\u627E\u5230\u672C\u5730\u7528\u6237");return i.getID()==t.userId&&(t.isLocal=!0),((r=t.permission)!=null&&r.getManage()||lt((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),i=0,r=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(r&&((l=this.room)!=null&&l.isBig))this.commonUserList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,dt,!0);else if(this.room.conferenceMode===2)this.room.localIsAudience&&this.audiencesList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,dt,!0);else{for(;i<t;)o.push(a.bind(null,i)),i+=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,i="RWPAV",r="array"){return c(this,null,function*(){let{users:o,total:a}=yield this.boomCore.getUsers(e,i,t);if(r==="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,i="array"){return c(this,null,function*(){let{users:r,total:o}=yield this.boomCore.getUsers(e,"RWPS",t,i),{users:a,total:n}=yield this.boomCore.getUsers(e,"RWPSA",t,i);if(e===-1&&this.audiencesList.clear(),i==="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)}),r.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)}),r.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,i="",r=!1){return c(this,null,function*(){var u,m;let{users:o,total:a,pageIndex:n}=yield this.boomCore.getUsersList(e,i,t,r),l=[];return o.forEach(h=>{if(s.filterUser(h.userId))return;let g=this.toBMUser(h);l.push(g)}),r&&((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:i}=yield this.boomCore.getUsers(0,"",1);return i}),t=i=>{e().then(r=>{i(r)}).catch(r=>{p("getTotalUserNumber error","","",[JSON.stringify(r)]),t(i)})};return new Promise((i,r)=>c(this,null,function*(){t(i)}))})}clearUsers(){this.userList.clear(),this.commonUserList.clear(),this.audiencesList.clear(),this.signalList.clear()}searchUsers(e,t){return c(this,null,function*(){try{let{users:i}=yield this.boomCore.searchUsers(e,t,!1),r=[],o=[],a=[];return i.forEach(n=>{let l=this.userList.get(n.userId);if(l){r.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:r,commonUserList:o,audienceList:a}}catch(i){return Promise.reject(new U(1e3,"boomCore.searchUsers\u53D1\u751F\u9519\u8BEF:"+(i==null?void 0:i.message)))}})}searchWaitRoomUsers(e,t){return c(this,null,function*(){try{let{users:i}=yield this.boomCore.searchUsers(e,t,!0),r=[];return i.forEach(o=>{let a=this.toBMUser(o);r.push(a)}),r}catch(i){return Promise.reject(new U(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=wt(this.timeStamp)):(this.timeStamp=new Date().getTime(),this.time=wt(this.timeStamp));let i=this.message.match(/^\[(.*?)\]$/);this.isEmoji=i!==null&&i[0].length<=20&&i[0].length>=4}};import{debounce as _r}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 Tr}from"lodash-es";import{BMShareStreamReconnectFailed as xr,BMShareStreamReconnectSuccess as Lr,BMStreamReconnectSuccess as kr}from"@hysc/utils";import{BrtcEvents as pi,BloudEvents as xt}from"@hysc/utils";function fi(s){var t,i;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 r=e.stream.getAudioOn(),o=e.stream.getVideoOn();s.publishBloudStream(r,o).then(()=>{var a;d("brtc stream repub success bloud repub success, notify reconnect success"),s.localStreamConnectErrorWatcher.next(kr(r,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 r=(t=s.room)==null?void 0:t.boomCore.shareScreenStream;if(r){let o=r.getAudioOn(),a=r.getVideoOn();try{(i=s.room)==null||i.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=Tr(s=>{if(s.networkState.bloud&&s.networkState.brtc)try{s.streamQueue.restart()}catch(e){p("streamQueue restart error",JSON.stringify(e))}},300);function gi(s,e,t,i){let r=s.stream;if(d("\u672C\u5730\u63A8\u6D41","\u672C\u5730\u63A8\u6D41",r.getUserId()),r){let o=e.getLocalStreamModel();o&&e.updateStreamModel(o,r),i[pi.STREAM_PUBLISHED].next({published:!0,model:o}),t.conferenceMode===1&&t.getLocalParticipant().isAudience&&e.getStreamModels().forEach(n=>{n.sendMessage2Room()})}else i[pi.STREAM_PUBLISHED].next({published:!1})}function Si(s,e,t){d("bloud publish stream"),Lt(s,e,!0),t[xt.STREAM_PUBLISHED].next(s)}function Lt(s,e,t=!1){var a,n,l;d("bloud stream update","","",[JSON.stringify(s)]);let i=s.userId,r=s.isScreen,o=e.streamModels.get(i);if(o)if(!r)o.updateBloudStream(s,e,t),o.getUser().updateSortNum();else{e.shareBloudStateMap.set(i,s);let u=(a=e.room)==null?void 0:a.userVM.getUser(i);u&&(u.hasShare=!0);let m={id:i,isWeb:o.isWeb,isScreen:r};(n=e.room)==null||n.addUser2Queue(m)}else{I("bloud stream update, but can not get streamModel","",i);let u=(l=e.room)==null?void 0:l.userVM.getUser(i);if(!u){p("bloud stream update, but can not get user","",i);return}e.createStreamModel(u).updateBloudStream({audio:s.audio,video:s.video,isScreen:s.isScreen},e)}}function bi(s,e,t,i){d("bloud unpublish stream","","",[JSON.stringify(s)]),Or(s,e,t),i[xt.STREAM_REMOVED].next(s)}function Ii(s,e,t){d("bloud stream update","","",[JSON.stringify(s)]);let i=s.streamId,r=s.userId,o=s.params.customInfo,a;i.includes("_screen")?a=e.shareStreamModels.get(r):a=e.streamModels.get(r),a?a.updateBloudCustomInfo(o):p("bloud stream update, but can not get streamModel","",r,["streamId =>",i]),t[xt.UPDATE_STREAM].next(s)}function Or(s,e,t){var o,a,n,l;let i=s.userId;if(s.isScreen){let u=e.shareStreamModels.get(i),m=(n=e.room)==null?void 0:n.userVM.getUser(i);if(m&&(m.hasShare=!1),u){let h=u.stream;h?(h.destroy(),e.remoteStreamUnpublished(h)):e.removeShareStreamModelByUId(i);let g=t.shareFileWatcher.getValue();g!=null&&g.streamId==i+"_screen"&&t.shareFileWatcher.next(null);let S={id:i,isWeb:u.isWeb,isScreen:!0};(l=e.room)==null||l.streamQueue.removeUser(S)}else I("bloud user unpublish share stream but can not get streamModel","",i)}else{let u=e.streamModels.get(i);if(u){u.updateBloudStream(void 0,e);let m=u.stream;m&&((o=e.room.audioPlayer)==null||o.removeStream(m),e.remoteStreamUnpublished(m),m.destroy());let h={id:i,isWeb:u.isWeb,isScreen:!1};(a=e.room)==null||a.streamQueue.removeUser(h)}else I("bloud user unpublish stream but can not get streamModel","",i)}}function mt(s,e){setTimeout(()=>c(this,null,function*(){d("handle republish share stream");try{let t=s.boomCore.shareScreenStream;if(t){let i=t.getAudioOn(),r=t.getVideoOn();if(yield s.boomCore.shareBrtcClient.publish(t),yield s.boomCore.createAndPubBloudShareStream(i,r),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(Lr())}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(xr()),yield e.toggleShareScreen(!1,void 0)}}),1e3)}import{BloudEvents as z,BrtcEvents as Ei}from"@hysc/utils";function Ci(s,e,t){let i=s.permission,r=s.total;i&&t.updateLocalUserPermission(i),e.isInWaitRoom=s.joinwait;let o=s.waitroom;e.roomInfo.isOpenWaitRoom.next(o),e.roomInfo.totalUserWatcher.next(r);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 ht(s,e,t,i,r=!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,Bi(s,e),Ci(s,e,t),r&&i[z.ROOM_CONNECTED].next(s)})}function pt(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(i=>{d("only-brtc-pub ","publish",s.localUser.userId,[i.message])})}})}function vi(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 Bi(s,e){e.roomInfo.msgSeq=s.msgSeq,s.customStats&&e.roomInfo.initCustomStats(s.customStats)}function yi(s,e,t,i,r){var l;s.updateUser(e,t);let o=t.stream,a=i.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,i),r.streamQueue.removeUser({id:e.userId,isScreen:!1}),r.streamQueue.removeUser({id:e.userId,isScreen:!0}));let u=i.shareStreamModels.get(e.userId);if(u&&!u.isLocal){try{(l=u.stream)==null||l.destroy()}catch(m){}i.removeShareStreamModel(u)}}o.get(`${e.userId}_screen`)&&r.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},i))}function Mi(s,e,t,i){s.isSingleColumns?e.commonUserList.forEach(r=>{let o=t.get(r.userId);if(o){t.delete(r.userId),yi(e,r,o,i,s);return}e.commonUserList.delete(r.userId),i.streamModels.delete(r.userId),i.shareStreamModels.delete(r.userId)}):e.userList.forEach(r=>{let o=t.get(r.userId);if(o){yi(e,r,o,i,s),r.isCommonUser?e.userList.delete(r.userId):t.delete(r.userId);return}e.userList.delete(r.userId),i.streamModels.delete(r.userId),i.shareStreamModels.delete(r.userId)}),s.userVM.addBcUsersMap(t)}function Dr(s,e,t,i){return c(this,null,function*(){let r=e.getLocalParticipant().userId,{users:o}=yield e.boomCore.queryUsers([r]),a=o.get(r);a&&t.updateUser(t.localUser,a);let n=e.getLocalParticipant().isCommonUser;if(e.isBig&&n){let{users:l}=yield e.boomCore.getUsersList(0,dt,500);Mi(e,t,l,i)}else{let u=(yield e.userVM.getTotalUserNumber())/ve,m=new Map;for(let h=0;h<u;h++){let{users:g}=yield e.boomCore.getUsers(h-1,"",ve);g.forEach(S=>{m.set(S.userId,S)})}Mi(e,t,m,i)}Bi(s,e),e.userVM.updateAllSort(),e.bmStreamVm.updateModelSort()})}function Ai(s,e,t){d("brtc room reconnecting"),e.networkState.brtc=!1,e.streamWSReconnectWatcher.next(!1),t[Ei.BRTC_ROOM_ROCONNECTING].next(s)}function Ui(s,e,t){d("brtc room reconnected"),e.networkState.brtc=!0,le(e),t[Ei.BRTC_ROOM_RECONNECTED].next(s)}function Ri(s,e,t){d("bloud room reconnecting"),e.networkState.bloud=!1,e.bloudWSReconnectWatcher.next(!1),t[z.RECONNECTING].next(s)}function ft(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(i=>{if(p("sync room error",JSON.stringify(i)),i.code===43){e.hasSyncPermission=!1,t[z.USER_REJOINED].next(i);return}else e.hasSyncPermission=!1,t[z.TIMEOUT].next(i)})):t[z.TIMEOUT].next(s)})}function Ni(s,e,t,i,r){return c(this,null,function*(){d("bloud sync room completed"),Ci(s,t,e),yield Dr(s,t,e,i),fi(i),t.networkState.bloud=!0,le(t),t.bloudWSReconnectWatcher.next(!0),r[z.ROOM_SYNCED].next(s)})}import{BloudEvents as Vr}from"@hysc/utils";var{USER_REJOINED:Hr,PARTICIPANT_JOINED:Wr,CHANGE_MASTER:Pi,EVICTED:Gr,UPDATE_USER:Fr,PARTICIPANT_LEFT:kt,CUSTOM_MESSAGE:jr,MOVE_USER_ROOM:wi}=Vr;function Ti(s,e,t,i,r,o){var g,S,b,E,C,y,L,W,G,F,j,$,ee,te,Te,xe,Le,ie,re,_,de,ke;let a=(S=(g=s==null?void 0:s.participant)==null?void 0:g.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!=!!((E=(b=s.user)==null?void 0:b.customInfo)!=null&&E.inBackground)&&(A.inBackground=!!((y=(C=s.user)==null?void 0:C.customInfo)!=null&&y.inBackground),A.watcher.next({operation:"inBackground",user:A})),A.isCalling!=!!((W=(L=s.user)==null?void 0:L.customInfo)!=null&&W.isCalling)&&(A.isCalling=!!((F=(G=s.user)==null?void 0:G.customInfo)!=null&&F.isCalling),A.watcher.next({operation:"isCalling",user:A}));return}}if((j=e.room)!=null&&j.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!=!!((re=(ie=s.user)==null?void 0:ie.customInfo)!=null&&re.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():(ke=e.room)!=null&&ke.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${i.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});r.addMessage(J,!0)}o[Wr].next({user:h,mode:n,data:s})}}}function xi(s,e,t,i,r,o,a){var l;let n=s.userIds;d("bloud leave users","","",["userIds =>",n]),n.length&&(n.forEach(u=>{let m=Ot(u,e,t,r);m&&ki(m,o,a,i,!0,0)}),(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():e.updateAllSort(),r.updateModelSort())}function Li(s,e,t,i,r,o,a){var m;d(`bloud participant left ===>${s.userId}, ${s.mode}`);let n=s.mode===1,l=s.userId,u=t.isBig&&r.streamModels.size>1e3;if(l){let h=Ot(l,e,t,r);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(),r.updateModelSort(),n){i[kt].next({user:h,mode:s.mode,data:s});return}h&&ki(h,o,a,i,s.mode!==1,s.mode)}else I("participant-left\u89E6\u53D1=======>\u4F46\u662F\u8BE5\u7528\u6237\u4FE1\u606F\u4E0D\u5B58\u5728",P,null,[s.userId]),i[kt].next({user:s.userId,mode:s.mode,data:s})}function ki(s,e,t,i,r,o){let a=!1;if(Be.forEach(n=>{s!=null&&s.userId.includes(n)&&(a=!0)}),!a){if(r){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)}i[kt].next({user:s,mode:o})}}function Ot(s,e,t,i){let r=e.getUser(s);return e.removeUser(s),t.streamQueue.removeUser({id:s,isScreen:!1}),t.streamQueue.removeUser({id:s,isScreen:!0}),i.removeStreamModelByUId(s),i.removeShareStreamModelByUId(s),t.roomInfo.removeRaiseHandUser(s),t.roomInfo.removeVideoRaiseHandUser(s),t.roomInfo.removeSimpleRaiseHandUser(s),i.shareBloudStateMap.delete(s),r}function Oi(s,e,t,i,r){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",P,null,o),i[Pi].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=r.getStreamModelByUId(a),m=r.getStreamModelByUId(o);u==null||u.updateSortNum(),m==null||m.updateSortNum(),i[Pi].next({master:l.master,oldMaster:l.oldMaster,data:s})}}function Di(s,e,t,i,r){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=Ot(o,e,i,t);(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():n?n.isCommonUser?e.updateCommonUserSort():n.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),r[Gr].next(s)}function _i(s,e,t,i,r){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=i.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),r[Fr].next({bmUser:n,params:s.participant.params})}}var Dt=_r((s,e)=>{s[Hr].next(e)},1e3);function Vi(s,e,t,i){return c(this,null,function*(){d("bloud move user room","","",[t]);let r=t.toWait;if(s.isInWaitRoom=r,r){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),i[jr].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([]),i[wi].next(r),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 ht(t.info,s,e,i,!0),yield pt(s),i[wi].next(r)}})}import{BloudEvents as _t}from"@hysc/utils";function Wi(s,e,t,i){var o,a,n,l,u,m,h,g,S;let r=N({},s);if(r.message){if(r.message=typeof r.message=="string"?JSON.parse(r.message):r.message,d("new-message","","",[" method => ",r.message.method]),r.message.method==="send-talk"){let b=r.user===((o=e.getLocalUser())==null?void 0:o.userId),E=((n=(a=r.message)==null?void 0:a.params)==null?void 0:n.status)||"",C=(m=(u=(l=r.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.avatar,y=s.seq,L=new x({userId:r.user,message:E,isLocal:b,avatar:C,to:r.to,seq:y,nickName:(S=(g=(h=r.message)==null?void 0:h.params)==null?void 0:g.stream)==null?void 0:S.nickname,sendTime:new Date().getTime()});t.addMessage(L,!1)}i[_t.SEND_MESSAGE].next(r)}}function Gi(s,e,t){var r,o,a,n,l,u,m,h,g,S,b,E,C;let i=N({},s);if(i.message)if(i.message=typeof i.message=="string"?JSON.parse(i.message):i.message,d("custom-message","","",[" method => ",i.message.method]),i.message.method=="video-force-change"){let y=i.message.params.status=="enabled";d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u6444\u50CF\u5934: ${y}`),e.messageWatcher.next({type:"video-force-change",status:y,fromUserId:i.user})}else if(i.message.method=="audio-force-change"){let y;i.message.params.status=="checkUserAudio"?y=i.message.params.status:y=i.message.params.status=="enabled",d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u9EA6\u514B\u98CE: ${y}`),e.messageWatcher.next({type:"audio-force-change",status:y,fromUserId:i.user,isNotCancelRootReport:(r=i.message.params)==null?void 0:r.isNotCancelRootReport})}else if(i.message.method==="raise-hands"){let y=i.message.params;$r(y,e),e.raiseHandleRespWatcher.next(y)}else if(i.message.method==="give-like")(h=e.roomVM)==null||h.giveLikeList.push({userId:i.user,nickName:(n=(a=(o=i.message)==null?void 0:o.params)==null?void 0:a.stream)==null?void 0:n.nickname,time:new Date().getTime(),type:(m=(u=(l=i.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.type}),(S=e.roomVM)==null||S.giveLikeListWatcher.next((g=e.roomVM)==null?void 0:g.giveLikeList);else if(i.message.method==="resp-to-check-devices")(b=i.message)!=null&&b.params&&(i.message.params.fromUserId=i.user),t[_t.CUSTOM_MESSAGE].next(i);else if(i.message.method==="usercount"){if(i.message.params){let y=(C=(E=i.message)==null?void 0:E.params)==null?void 0:C.total;y?(y=Number(y),y<0&&(I("\u670D\u52A1\u8FD4\u56DE\u7684usercount\u4E3A\u8D1F\u6570,"+y),y=0)):(I("\u670D\u52A1\u672A\u8FD4\u56DEusercount,"+y),y=0),e.roomInfo.totalUserWatcher.next(y)}}else if(i.message.method==="waitusercount"){if(i.message.params){let y=i.message.params.total;e.roomInfo.totalWaitRoomUserWatcher.next(y)}}else t[_t.CUSTOM_MESSAGE].next(i)}function $r(s,e){return c(this,null,function*(){let t=s.raiseInfo;if(s.raiseHandsType===4&&t){let i=e.userVM.getUser(t.userId);if(i||(d("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728,\u5F00\u59CB\u67E5\u8BE2",t.userId),yield e.queryBloudUsers([t.userId],!1,!1),i=e.userVM.audiencesList.get(t.userId)),!i){p("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728",t.userId);return}switch(t.type){case"raiseHandsAudio":i.raiseAudioHands=s.raiseHands;break;case"raiseHandsVideo":i.raiseVideoHands=s.raiseHands;break;case"raiseHand":i.raiseHand=s.raiseHands;break;default:break}M.emitter.emit(k,{status:t.type,user:i})}})}import{BloudEvents as Jr,BrtcEvents as Vt}from"@hysc/utils";var gt=0;var St=0,je=new Set;function Ht(s,e,t,i,r){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 Fi(t,e,r,s).catch(a=>{d("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25, \u5904\u7406\u4E00\u4E0B\u9000\u4F1A\u903B\u8F91","","",[JSON.stringify(a)]),r[Vt.ERROR].next(s)})}),1e3)}else r[Vt.ERROR].next(s)})}function Fi(s,e,t,i){return c(this,null,function*(){return new Promise((r,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,gt=0,yield e.handleRePushSelf(),e.streamWSReconnectWatcher.next(!0),r(!0)})).catch(a=>{let n=a.getCode();d("\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[a,n]),gt<=10?(gt+=1,s.brtcClient.isJoinning=!1,setTimeout(()=>{Fi(s,e,t,i)},2*1e3)):(p("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u9000\u4F1A"),gt=0,t[Vt.ERROR].next(i),o(!1))})},7*1e3)})})}function Wt(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(()=>{St=0,e(!0)}).catch(i=>{let r=i.getCode();if(d("\u5171\u4EAB\u5C4F\u5E55\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[i,r]),St<=3)St+=1,Wt(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"),St=0,new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE\u5931\u8D25")})},7*1e3)})})}function ji(s,e,t,i,r){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 ft(i,s,r):r[Jr.TIMEOUT].next(i)})}import{BloudEvents as Qr}from"@hysc/utils";function $i(s,e,t){let i=s==null?void 0:s.updateKeys;d("update-custom-stats"," "," ",["updateKeys => ",JSON.stringify(i)]),(i!=null&&i.includes("chatNotice")||i!=null&&i.includes("chatNoticeRich")||i!=null&&i.includes("fileUpdateLook")||i!=null&&i.includes("fileUpdateDown")||i!=null&&i.includes("fileUpdateEdit")||i!=null&&i.includes("fileUpdateModel")||i!=null&&i.includes("screenShareModel")||i!=null&&i.includes("onlyOnePersonShare")||i!=null&&i.includes("chatEnable")||i!=null&&i.includes("giveLikeEnable")||i!=null&&i.includes("cloudRecord")||i!=null&&i.includes("joinAudioEnable")||i!=null&&i.includes("joinVideoEnable")||i!=null&&i.includes("userListEnable")||i!=null&&i.includes("audioEnable")||i!=null&&i.includes("videoEnable")||i!=null&&i.includes("modifyNameEnable")||i!=null&&i.includes("backgroundAIEnable")||i!=null&&i.includes("recordEnable")||i!=null&&i.includes("joinMicrophoneDisable")||i!=null&&i.includes("joinCameraDisable")||i!=null&&i.includes("raiseHandEnable")||i!=null&&i.includes("forceOpenUserMic")||i!=null&&i.includes("forceOpenUserCamera")||i!=null&&i.includes("joinCueVoice"))&&e.roomInfo.updateOperationPermission(s.customStats),(i!=null&&i.includes("chatNotice")||i!=null&&i.includes("chatNoticeRich"))&&e.roomInfo.chatNoticeWatcher.next(s),t[Qr.UPDATE_CUSTOM_STATS].next(s)}import qr from"@hysc/p-queue";var bt=class{constructor(e,t=!0){this.queue=new qr({concurrency:e,autoStart:t,carryoverConcurrencyCount:!0,timeout:3*1e3,completeAction:i=>{console.log("task complete",i)}}),this.queueArray=[],this.isTaskPending=t}addQueue(e,t,i=0,r=""){this.queue.isPaused&&this.queue.start();let o={};o.taskID=t,o.status="pending",this.queue.add(e,{priority:i,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()}},O=new bt(4),v=new bt(10);import{BMShareStreamReconnectFailed as Xr}from"@hysc/utils";import{BloudEvents as f,BrtcEvents as R,CustomEvents as Ae}from"@hysc/utils";function Ji(s,e,t,i,r){d("attachEvents init");let o={};s.on("toggle-screen-share",()=>{p("share stream video track ended, now unpublish share stream"),t.localShareError.next(Xr()),t.localShareEndedError.next(!0)}),s.on("client-banned",()=>c(this,null,function*(){yield r.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"),Wt(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(f)),a=a.concat(Object.values(R)),a=a.concat(Object.values(Ae)),a.forEach(n=>{o[n]=new zr(null)}),a.forEach(n=>{switch(n){case R.STREAM_PUBLISHED:s.on(R.STREAM_PUBLISHED,l=>{v.addQueue(gi.bind(null,l,t,r,o),R.STREAM_PUBLISHED)});break;case R.BRTC_SYNC_ROOM_COMPLETED:s.on(R.BRTC_SYNC_ROOM_COMPLETED,()=>c(this,null,function*(){v.addQueue(r.handleResetOtherStreamStatus.bind(r),R.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(mt.bind(null,r,t),Ae.BRTC_SHARE_SYNC_ROOM_COMPLETED)});break;case R.BRTC_ROOM_ROCONNECTING:s.on(R.BRTC_ROOM_ROCONNECTING,l=>{v.addQueue(Ai.bind(null,l,r,o),R.BRTC_ROOM_ROCONNECTING)});break;case R.BRTC_ROOM_RECONNECTED:s.on(R.BRTC_ROOM_RECONNECTED,l=>c(this,null,function*(){v.addQueue(Ui.bind(null,l,r,o),R.BRTC_ROOM_RECONNECTED)}));break;case R.CLIENT_BANNED:s.on(R.CLIENT_BANNED,l=>{d("brtc client banned"),Dt(o,l)});break;case R.ERROR:s.on(R.ERROR,l=>c(this,null,function*(){r.netConnecting?v.addQueue(Ht.bind(null,l,r,s,t,o),R.ERROR):je.add(Ht.bind(null,l,r,s,t,o))}));break;case f.SYNC_FAILED:s.on(f.SYNC_FAILED,l=>{p("bloud sync failed, leave room"),o[f.TIMEOUT].next(l)});break;case f.ROOM_CONNECTED:s.on(f.ROOM_CONNECTED,l=>c(this,null,function*(){return ht(l,r,e,o)}));break;case Ae.JOIN_READY:s.on(Ae.JOIN_READY,()=>pt(r));break;case f.PARTICIPANT_JOINED:s.on(f.PARTICIPANT_JOINED,l=>c(this,null,function*(){r.isInWaitRoom||v.addQueue(Ti.bind(null,l,e,t,s,i,o),f.PARTICIPANT_JOINED)}));break;case f.PARTICIPANT_LEFT:s.on(f.PARTICIPANT_LEFT,l=>{r.isInWaitRoom||v.addQueue(Li.bind(null,l,e,r,o,t,s,i),f.PARTICIPANT_LEFT)});break;case f.LEAVE_USERS:s.on(f.LEAVE_USERS,l=>v.addQueue(xi.bind(null,l,e,r,o,t,s,i),f.LEAVE_USERS));break;case f.CHANGE_MASTER:s.on(f.CHANGE_MASTER,l=>{v.addQueue(Oi.bind(null,l,e,r,o,t),f.CHANGE_MASTER)});break;case f.SEND_MESSAGE:s.on(f.SEND_MESSAGE,l=>{v.addQueue(Wi.bind(null,l,e,i,o),f.SEND_MESSAGE)});break;case f.CUSTOM_MESSAGE:s.on(f.CUSTOM_MESSAGE,l=>{v.addQueue(Gi.bind(null,l,r,o),f.CUSTOM_MESSAGE)});break;case f.EVICTED:s.on(f.EVICTED,l=>c(this,null,function*(){v.addQueue(Di.bind(null,l,e,t,r,o),f.EVICTED)}));break;case f.UPDATE_USER:s.on(f.UPDATE_USER,l=>{v.addQueue(_i.bind(null,l,e,r,t,o),f.UPDATE_USER)});break;case f.UPDATE_STATS:s.on(f.UPDATE_STATS,l=>{v.addQueue(vi.bind(null,l,r),f.UPDATE_STATS)});break;case f.UPDATE_CUSTOM_STATS:s.on(f.UPDATE_CUSTOM_STATS,l=>{v.addQueue($i.bind(null,l,r,o),f.UPDATE_CUSTOM_STATS)});break;case f.TIMEOUT:s.on(f.TIMEOUT,l=>{v.addQueue(ji.bind(null,r,s,t,l,o),f.TIMEOUT)});break;case f.USER_REJOINED:s.on(f.USER_REJOINED,l=>{d("bloud user rejoined"),Dt(o,l)});break;case f.RECONNECTING:s.on(f.RECONNECTING,l=>{v.addQueue(Ri.bind(null,l,r,o),f.RECONNECTING)});break;case f.RECONNECTED:s.on(f.RECONNECTED,l=>c(this,null,function*(){v.addQueue(ft.bind(null,l,r,o),f.RECONNECTED)}));break;case f.ROOM_SYNCED:s.on(f.ROOM_SYNCED,l=>c(this,null,function*(){v.addQueue(Ni.bind(null,l,e,r,t,o),f.ROOM_SYNCED)}));break;case f.STREAM_PUBLISHED:s.on(f.STREAM_PUBLISHED,l=>c(this,null,function*(){v.addQueue(Si.bind(null,l,t,o),f.STREAM_PUBLISHED)}));break;case f.STREAM_REMOVED:s.on(f.STREAM_REMOVED,l=>c(this,null,function*(){v.addQueue(bi.bind(null,l,t,r,o),f.STREAM_REMOVED)}));break;case f.UPDATE_STREAM:s.on(f.UPDATE_STREAM,l=>c(this,null,function*(){v.addQueue(Ii.bind(null,l,t,o),f.UPDATE_STREAM)}));break;case f.STREAM_UPDATE:s.on(f.STREAM_UPDATE,l=>c(this,null,function*(){v.addQueue(Lt.bind(null,l,t),f.STREAM_UPDATE)}));break;case f.MOVE_USER_ROOM:s.on(f.MOVE_USER_ROOM,l=>c(this,null,function*(){v.addQueue(Vi.bind(null,r,e,l,o),f.MOVE_USER_ROOM)}));break;default:s.on(n,l=>o[n].next(l));break}}),o}import{BmChangeAudioProfileError as Gt,BmChangeMasterError as Ft,BmChangeVideoProfileError as jt,BmCheckDeviceError as $t,BmEvictUserError as It,BmSetRemoteAudioEnable as $e,BmSetRemoteVideoEnable as Yr,BmUpdateManagerError as Qi,BmUpdateUserError as Jt,updateCustomStatsError as Zr}from"@hysc/utils";import{Subject as Kr}from"rxjs";var Je=class{constructor(e,t,i){this.room=null;this.tipQueueObj={};this.roomInfo=i,this.userVM=t,this.boomCore=e,this.giveLikeList=[],this.giveLikeListWatcher=new Kr}initWithRoom(e){this.room=e}evictUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(It("\u672A\u4F20\u9012\u7528\u6237id"));if(!this.userVM.checkLocalHasMaster())return Promise.reject(It("\u53EA\u6709\u4E3B\u6301\u4EBA\u6743\u9650\u624D\u80FD\u8E22\u51FA\u7528\u6237"));if(this.userVM.checkIsMaster(e))return Promise.reject(It("\u4E3B\u6301\u4EBA\u4E0D\u80FD\u88AB\u8E22\u51FA"));try{yield this.boomCore.evictUser(e,t)}catch(i){return Promise.reject(It(`\u8E22\u51FA\u7528\u6237\u5931\u8D25${JSON.stringify(i)}`))}})}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(i=>Promise.reject(Jt(`boomCore updateUser\u51FA\u9519 ${JSON.stringify(i)}`)))})}changeMaster(e,t){return c(this,null,function*(){var i;if(!e)return Promise.reject(Ft("\u672A\u4F20\u9012\u4E3B\u6301\u4EBAid"));if(this.userVM.checkLocalHasMaster()||(i=this.userVM.getUser(e))!=null&&i.isCreate)try{yield this.boomCore.changeMaster(e,t)}catch(r){return Promise.reject(Ft(`boomCore changeMaster error ${r}`))}else return console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA",P,e),Promise.reject(Ft("\u60A8\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))})}updateManager(e,t,i=!0){return c(this,null,function*(){return e?this.userVM.checkLocalHasMaster()?this.userVM.updateManager(e,t,i):(console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u8054\u5E2D\u4E3B\u6301\u4EBA",P,e),Promise.reject(Qi("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))):Promise.reject(Qi("\u672A\u4F20\u9012\u8054\u5E2D\u4E3B\u6301\u4EBAid"))})}changeNickName(e,t){return c(this,null,function*(){let i={nickname:t};yield this.updateUser(e,i)})}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(i){return Promise.reject(i)}})}setRemoteAudioEnable(e,t,i){return c(this,null,function*(){let r=e?"enabled":"disabled";r=="enabled"&&i&&(r="checkUserAudio");let o={domain:"room-control",method:"audio-force-change",params:{status:r,isNotCancelRootReport:i,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 i={domain:"room-control",method:"video-force-change",params:{status:e?"enabled":"disabled",fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(i,t).catch(r=>Promise.reject(Yr(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${r}`)))})}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(i=>Promise.reject($e(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${i}`)))})}tipUser(e,t,i,r){return c(this,null,function*(){let o={domain:"room-control",method:"tip-user",params:{fromUserId:this.boomCore.getLocalParticipant().getID(),message:t,richMsg:i}};r?this.tipQueueObj[e]=setTimeout(()=>{this.sendMessageWithMaster(o,e)},(r.minutes||0)*60*1e3+(r.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 i=(o=this.room)==null?void 0:o.getLocalParticipant().getID(),r={};e==="raiseHand"?(r.raiseHand=t,r.raiseHandTime=Math.floor(new Date().getTime()/1e3)):r[e==="audio"?"raiseHandsAudio":"raiseHandsVideo"]=t,yield this.updateUser(i,r),(a=this.room)!=null&&a.isBig&&(yield this.raiseHandsByCustomMessage(e,t,i))})}raiseHandsByCustomMessage(e,t,i){return c(this,null,function*(){var a;let r="raiseHand";e!="raiseHand"&&(r=e==="audio"?"raiseHandsAudio":"raiseHandsVideo");let o={domain:"user-control",method:"raise-hands",params:{raiseHandsType:4,raiseHands:t,raiseInfo:{userId:i,raiseHandTime:Math.floor(new Date().getTime()/1e3),type:r}}};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,i){return c(this,null,function*(){var o,a,n;let r={domain:"user-control",method:"raise-hands",params:{raiseHandsType:e,raiseHands:t}};try{if(i)yield this.boomCore.customMessage(JSON.stringify(r),i);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(r),h.userId)}),u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===1&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===2&&(u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===3&&(m==null||m.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)}))}}catch(l){return Promise.reject(new U(1e3,"boomCore.sendMessage\u53D1\u751F\u9519\u8BEF"))}})}updateCustomStats(e,t=!1){return c(this,null,function*(){yield this.boomCore.updateCustomStats(e,t).catch(i=>Promise.reject(Zr(`${JSON.stringify(e)} - ${JSON.stringify(i)}`)))})}sendChatNotice(e,t,i){return c(this,null,function*(){yield this.updateCustomStats({chatNotice:e,chatNoticeRich:t,showTipNotice:i}).catch(r=>r)})}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(),i={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}}},r=this.userVM.getLocalUser();try{yield this.boomCore.customMessage(JSON.stringify(i),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,P,r==null?void 0:r.userId),new U(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",P);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(i=>Promise.reject($t(`\u68C0\u6D4B\u5BF9\u65B9\u8BBE\u5907send-message\u53D1\u751F\u9519\u8BEF: ${i}`)))})}resp2CheckDevices(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-check-devices",params:Oe(N({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};if(!t)return Promise.reject($t(`\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4B: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(r){return Promise.reject($t(`\u54CD\u5E94\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4Bsend-message\u53D1\u751F\u9519\u8BEF ${r}`))}})}changeRemoteVideoProfile(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"change-video-profile",params:Oe(N({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};this.sendMessageWithMaster(i,t).catch(r=>Promise.reject(jt(`\u8C03\u8282\u5BF9\u65B9\u7684\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF: ${r}`)))})}resp2ChangeRemoteVideoProfile(e,t,i){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-change-video-profile",params:{status:e,profile:i,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(jt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(o){return Promise.reject(jt(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF ${o}`))}})}changeRemoteAudioProfile(e,t){return c(this,null,function*(){let i={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(i,t).catch(r=>Promise.reject(Gt(`\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${JSON.stringify(r)}`)))})}resp2ChangeRemoteAudioProfile(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-change-audio-profile",params:{status:e,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Gt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(r){return Promise.reject(Gt(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${r}`))}})}};import{BehaviorSubject as es,Subject as ts}from"rxjs";import{throttle as is}from"lodash-es";var Qe=class{constructor(e,t,i){this.messageList=[];this.hasDangerMessageWatcher=new ts;this.notificationMessageList=is(()=>{this.messageListWatcher.next(this.messageList)},200);this.boomCore=e,this.userVM=t,this.bmRoom=i,this.messageListWatcher=new es(this.messageList)}sendMessage(e,t,i){return c(this,null,function*(){let r=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:r}},n=this.userVM.getLocalUser();try{let l=!1,u,m=i;m||(yield this.boomCore.sendMessage(JSON.stringify(a),t).then(g=>{u=g.seq}).catch(g=>{I("sendmessage \u51FA\u9519","",n==null?void 0:n.userId,[g]),g&&g.code===39&&(l=!0,this.hasDangerMessageWatcher.next(!0))}));let h=new x({userId:n==null?void 0:n.userId,message:r,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,P,n==null?void 0:n.userId),new U(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>=di){let i=new x({isMeetingNotice:!0,message:""});this.messageList.push(i)}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(i=>{if(i.private||i.to||i.msg.length==0||i.msg.indexOf("{")==-1)return!1;let r=JSON.parse(i.msg);if(r.method!="send-talk")return!1;let o=i.seq,a=r.params,n=a.stream.user?a.stream.user:i.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 er,Subject as X}from"rxjs";import{Player as ss}from"@hysc/core";var Ue=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 qi(s,e){return 16|~~s<<1|~~e}function zi(s,e){return 12|~~s<<1|~~e}function Xi(s,e){return 8|~~s<<1|~~e}function Yi(s,e){return 4|~~s<<1|~~e}function Zi(s,e){return 20|~~s<<1|~~e}function Ki(){return Date.now()}function yt(){let s=Ki();return function(){return Ki()-s}}import{detect as os}from"detect-browser";var Re=os(),as=(Re==null?void 0:Re.name)==="safari"||(Re==null?void 0:Re.name)==="ios";var ce=`.streammodel${Math.random()}`,Ne=class{constructor(e,t,i,r=!1){this.streamType=3;this.pullFailedNum=0;this._video_enable=!1;this._audio_enable=!1;this.videoEnableWatcher=new er(this._video_enable);this.audioEnableWatcher=new er(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,i;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()),(i=this.stream)==null||i.resume())};this.handleStreamConnectError=()=>{d("\u6D41\u51FA\u73B0\u7684connect-error userId","",this.userId,["streamId ==>",this.streamId,"nickname =>",this.nickname,"isLocal => ",this.isLocal]),this.isLocal?M.emitter.emit(se,{stream:this,isLocal:!0}):M.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(()=>{M.emitter.emit(me,{stream:this})},100);this.emitBindElement=qe(()=>{M.emitter.emit(pe,{stream:this})},50);this.emitBindBigElement=qe(()=>{M.emitter.emit(be,{stream:this})},50);this.currentIsPlaying=(e,t=!0)=>{var l;let i=document.getElementById(e);if(!i)return 0;let r,o,a=0,n=Array.from(i.children);return r=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)),r&&o>a?2:1};this.play=(e=!1)=>c(this,null,function*(){var i,r;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=yt();if(this.isDisplay&&this.videoEnable){if(e){this.stop(),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!ze}),(i=M.emitter)==null||i.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||M.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}),(r=M.emitter)==null||r.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 i,r,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=yt();if(e){this.initBigPlayer(),yield(i=this.player)==null?void 0:i.play(t),(r=M.emitter)==null||r.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||M.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=M.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 i=!!document.getElementById(t);if(this.isInBig)if(i){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.room=t,this.updateUser(e),this._stream=i,this.isDisplayObserve.subscribe(o=>{this.handleDisplayChange(o)}),this.isInBigObserve.subscribe(o=>{this.handleIsInBig(o)}),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,"isShare =>",this.isShare]),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,i){this._stream&&this._stream.off(ce),this._stream=e,e?(this.audioEnable&&(this.isShare||i.addToDetector(new Ue(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,i=!1){var a,n,l,u,m;let r=!1,o=!1;if(e){if(this.bloudStream={audio:e.audio,video:e.video,isScreen:e.isScreen},e.customInfo){if(!this.bloudStream.customInfo||((a=this.bloudStream.customInfo)==null?void 0:a.volume)!==e.customInfo.volume){let h=e.customInfo.volume;typeof h=="number"&&this.setRemoteAudioLevel(h)}this.bloudStream.customInfo=e.customInfo}this.stream&&(this.bloudStream.audio?this.isShare||(t.addToDetector(new Ue(this.user,this.stream)),this.collectAudioLevel()):t.removeFromDetector(this.stream.getStreamId())),this.bloudStream.video!==this._video_enable&&(r=!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()),i&&(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||i?M.emitter.emit(ye,{id:this.userId,isWeb:this.isWeb,isScreen:this.isShare}):(this.isLocal||(!this.hasPulled||!this.stream.isSubscribed())&&this.sendMessage2Room(),r&&(this.isDisplay&&this.playerId&&this.emitBindElement(),this.isInBig&&this.bigPlayerId&&this.emitBindBigElement()),!this.isLocal&&o&&this.audioEnable&&this.stream.isSubscribed()&&M.getInstance().emit(Ee,{stream:this})))}else 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,i,r,o;this.bloudStream?(e&&(((i=(t=this.bloudStream)==null?void 0:t.customInfo)==null?void 0:i.volume)!==e.volume?typeof e.volume=="number"&&this.setRemoteAudioLevel(e.volume):((o=(r=this.bloudStream)==null?void 0:r.customInfo)==null?void 0:o.share_file)!==e.share_file&&e.share_file&&this.setShareFile(e.share_file)),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,i;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":!!((i=this.bloudStream)!=null&&i.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");M.emitter.emit(Me,{streamId:this.streamId,volume:e})}setShareFile(e){M.emitter.emit(ot,{streamId:this.bStreamId,fileId: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 ss(e,{fit:"contain"}),this.player.on("player-state-changed",t=>{var i;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"&&((i=this.player)==null||i.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&&(M.emitter.emit(Ie,null),this.user.updateSortNum(!0)))}getSortNum(){var e;return this.user.isMaster?qi(this.audioEnable,this.videoEnable):this.user.isLocal?zi(this.audioEnable,this.videoEnable):this.user.isManager?Xi(this.audioEnable,this.videoEnable):this.user.isCommonUser&&((e=this.room)==null?void 0:e.template_name)==="mention"&&(this.room.userVM.localUser.isMaster||this.room.userVM.localUser.isManager)?Zi(this.audioEnable,this.videoEnable):Yi(this.audioEnable,this.videoEnable)}checkVideoDecodeFrame(e){if(this.isLocal||as)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 r,o,a;let i=(t==null?void 0:t.getVideoPlaybackQuality)&&((r=t==null?void 0:t.getVideoPlaybackQuality())==null?void 0:r.totalVideoFrames)||0;if(t&&!t.getVideoPlaybackQuality){this.checkVideoTimer&&clearTimeout(this.checkVideoTimer);return}if(i>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,M.emitter.emit(fe,{stream:this})}unSubscribeStream(){this.shouldPull=!1,M.emitter.emit(ge,{stream:this})}unAttach(e){var t,i;e==="all"?(this.stop(),(t=this.player)==null||t.destroy(),this.bigPlayerId=""):e==="big"?((i=this.player)==null||i.destroy(),this.bigPlayerId=""):e==="small"&&this.stop()}};import{BehaviorSubject as ue,Subject as Y}from"rxjs";import{BoomError as rr}from"@hysc/utils";import{debounce as us}from"lodash-es";import{BMCameraNotAuthError as ds,BMMicNotAuthError as ms,BMOpenCameraError as sr,BMOpenMicroError as Xt,BmSetLocalAudioEnable as hs,BmSetLocalSpeakerEnable as ps,BmSetLocalVideoEnable as fs,BMStreamDisconnectedError as or,BmSyncStreamFailError as Yt,getStreamError as gs}from"@hysc/utils";function tr(s){let e=null,t=s.videoElement,i=t.offsetWidth,r=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:i,height:r}}return null}function ir(s,e){try{let t=s.getVideoTracks()[0],i=s.getAudioTracks()[0];return{video:!!t,audio:!!i,videoSource:t,audioSource:i,width:e.width,height:e.height}}catch(t){return console.log("\u83B7\u53D6\u5171\u4EAB\u97F3\u9891\u53C2\u6570\u6709\u8BEF",t),null}}import{Logger as ns}from"@hysc/utils";var ls="NoiseSuppressorWorklet",Mt=null,qt=null;function zt(s){return Mt||(Mt=new AudioContext({sampleRate:48e3})),qt||(s?qt=Mt.audioWorklet.addModule(s):console.error("Please provide workletPublicUrl or restore workletCode")),qt}function cs(s){return c(this,null,function*(){yield zt();let e=Mt;e.state==="suspended"&&(yield e.resume());let t=yield navigator.mediaDevices.getUserMedia({audio:{sampleRate:48e3,channelCount:1,deviceId:s,echoCancellation:!0,noiseSuppression:!1,autoGainControl:!0}}),i=new AudioWorkletNode(e,ls),r=e.createMediaStreamSource(t);r.connect(i);let o=e.createMediaStreamDestination();return i.connect(o),ns.info("rnnoise MediaStream:","rnnoise","",[]),t.getTracks()[0].onended=()=>{i.disconnect(),r.disconnect()},o.stream})}var Et=cs;function Pe(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._enableNoiseFilter=!1;this._canUseNoiseFilter=!1;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=us(()=>{let e=this.sortStreamModels();this.streamModelsWatcher.next(s.filterStreamModels(e))},200,{maxWait:500});this.handleNoContainer=e=>{let{type:t,container:i,id:r}=e,o;t==="share"?o=this.shareStreamModels.get(r):o=this.streamModels.get(r),o&&(i==="small"?this.noContainerWatcher.next(o):this.noBigContainerWatcher.next(o))};this.getHTMLMediaStream=tr;this.getMediaStream=ir;setTimeout(()=>{this.createCanvas(),this.canvasDisplay()},100),M.emitter.on(Ie,this.updateModelSort),M.emitter.on(oe,this.handleNoContainer),M.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(i=>t.userId.includes(i))).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 i;let t=(i=this.room)==null?void 0:i.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 Ne(t,this.room,void 0,!0),this.whiteboardWatcher.next(this.whiteboard),this.whiteboard}removeWhiteBoard(){this.whiteboard=null,this.whiteboardWatcher.next(this.whiteboard)}createStreamModel(e,t){let i=new Ne(e,this.room,void 0);return t&&i.updateStream(t,!0,this),i.isShare?(e.addStream(`${e.userId}${T}`,i),this.addShareStreamModel(i)):(e.addStream(e.userId,i),this.addStreamModel(i)),i.isMixer&&(this.mixStreamUid=i.userId,this.mixStreamModel&&this.mixStreamModelWatcher.next(this.mixStreamModel)),i}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 i,r,o;let t=this.shareStreamModels.get(e);if(t){try{(i=t.stream)==null||i.destroy()}catch(a){}t.audioEnable&&t.stream&&((o=(r=this.room)==null?void 0:r.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 i,r,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?(r=(i=this.room)==null?void 0:i.audioPlayer)==null||r.removeStream(t.stream):(o=this.room)==null||o.audioPlayer.removeStreamByUid(e)),this.removeStreamModel(t)}return t}remoteStreamPublished(e){var a;let t=e.getStreamId(),i=e.getUserId().toString(),r=this.getStreamModelByUId(i),o;if(r||(o=Pe(String(i)),r=this.getStreamModelByUId(o)),r){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(r.getUser(),e),u=e.getVideoOn(),m=e.getAudioOn(),h=this.shareBloudStateMap.get(r.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 r.hasPulled=!1,r.pulledStreamType="small",this.updateStreamModel(r,e);this.changeSingleStreamSpeaker(r).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",r==null?void 0:r.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","",i,["streamId => ",t,"types =>",e.getType&&e.getType()])}remoteStreamUnpublished(e){var n,l,u;let t,i=e.getUserId().toString(),r=e.getStreamId(),o=!1;if(i.includes(T)){let m=Pe(String(i));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",i),this.localModel.getUser().removeStream(i);return}t=this.getShareStreamModelByUId(m),o=!0}else r.startsWith(rt)||e.getType&&e.getType()==="assist"?(t=this.getShareStreamModelByUId(i),o=!0):t=this.getStreamModelByUId(i);if(this.removeFromDetector(r),this.removeFromRecorder(e),!t){p("brtc\u6709\u4EBA\u53D6\u6D88\u63A8\u6D41 \u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel","\u53D6\u6D88\u63A8\u6D41",i,[r]);return}let a=(u=t.stream)==null?void 0:u.getStreamId();if(a!==r){p("\u5F53\u524D\u53D6\u6D88\u63A8\u6D41\u7684\u548C\u5F53\u524D\u7ED1\u5B9A\u7684\u4E0D\u662F\u540C\u4E00\u80A1\u6D41","",i,["streamId =>",r,"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 mi(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 r,o,a,n,l,u,m;if(!((r=this.room)!=null&&r.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(ds());let i=this.getLocalStreamModel();if(d(`\u5F00\u5173\u672C\u5730\u6444\u50CF\u5934\uFF0C \u72B6\u6001 => ${e}`,"publish",i==null?void 0:i.userId),i)if(e)if(i!=null&&i.stream){if(t)yield i.stream.replaceTrack(t).catch(g=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","",i.userId,[JSON.stringify(g)])});else{let g=(o=i==null?void 0:i.stream)==null?void 0:o.getVideoTrack(),S=i==null?void 0:i.stream.hasVideo();if(!g||(g==null?void 0:g.constructor.name)==="CanvasCaptureMediaStreamTrack"||S==!1){let b=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C)),E=i.stream;yield E.replaceTrack(b).then(()=>{E.setVideoProfile(this.room.videoProfile),d("replace video track success")}).catch(C=>(p(`\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u89C6\u9891\u6D41\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001 => ${i==null?void 0:i.audioEnable}`,"publish",i==null?void 0:i.userId,[JSON.stringify(C)]),i!=null&&i.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(sr())))}else{let b=g==null?void 0:g.constructor.name;if(I(`setLocalVideoEnable: no videoTrack, trackName:${b}`,"publish",i==null?void 0:i.userId),Q()){let E=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C));yield i.stream.replaceTrack(E)}}}if(yield i.stream.unmuteVideo())d("brtc unmute video success");else return p(`brtc unmuteVideo\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001=> ${i==null?void 0:i.audioEnable} hasVideo=>${i.stream.hasVideo()}`,"publish",i==null?void 0:i.userId),i!=null&&i.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(sr());if(!this.bloudStream||this.bloudStream.published==!1){i.isInBig&&i.playInBig(!0),yield this.publishBloudStream(!1,!0);return}yield this.bloudStream.setVideoEnabled(!0).then(()=>{i.updateStream(i.stream,!0,this),i.updateBloudStream({video:!0,audio:i.audioEnable,isScreen:!1},this),i.playInBig(!0)}).catch(g=>{p("bloud unmuteVideo\u5931\u8D25","publish","",[JSON.stringify(g)]),this.handleStreamUpdateFailed()})}else try{yield this.createStreamAndPublish(!1,!0,i,t),i.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 i.stream&&(yield this.muteOrUnpublishStream("video",!0,i).catch(g=>(p("\u5173\u95ED\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[g]),Promise.reject(fs(g)))))})}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 r;let i=this.getLocalStreamModel();if(!((r=this.room)!=null&&r.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u9EA6\u514B\u98CE\uFF0C\u4E0D\u4E0E\u54CD\u5E94","publish",i==null?void 0:i.userId);return}if(!this.room.mediaPermission.microphone)return Promise.reject(ms());if(d(`\u5F00\u5173\u672C\u5730\u9EA6\u514B\u98CE\uFF0C \u72B6\u6001 => ${e}`,"publish",i==null?void 0:i.userId),i)if(e)if(i!=null&&i.stream){if(!i.stream.hasAudio()){let a=yield this.createLocalAudioStream();if(!a)return Promise.reject(Xt());let n=a.getAudioTrack();yield i.stream.replaceTrack(n).then(()=>{d("replace audio track success","publish",i.userId)}).catch(l=>(p("\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u97F3\u9891\u6D41\u5931\u8D25","publish",i.userId,[JSON.stringify(l)]),this.handleStreamUpdateFailed(!0),Promise.reject(Xt())))}if(yield i.stream.unmuteAudio().catch(a=>{var n;d("brtc unmuteAudio:err, hasAudio="+((n=i.stream)==null?void 0:n.hasAudio()),"publish","",[a])}))d("unmute audio success","publish",i.userId);else return p(`unmute local stream audio res\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${i==null?void 0:i.videoEnable} hasAudio=>${i.stream.hasAudio()}`,"publish",i==null?void 0:i.userId),i!=null&&i.videoEnable||(yield this.handleStreamUpdateFailed(!0)),Promise.reject(Xt());if(!this.bloudStream||this.bloudStream.published==!1){yield this.publishBloudStream(!0,!1);return}yield this.bloudStream.setAudioEnabled(!0).then(()=>{d("bloud stream set audio enable","publish",i.userId),i.updateStream(i.stream,!1,this),i.updateBloudStream({audio:!0,video:i.videoEnable,isScreen:!1},this)}).catch(a=>{p(`bloud unmuteAudio\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${i==null?void 0:i.videoEnable}`,"publish",i==null?void 0:i.userId,[JSON.stringify(a)]),i!=null&&i.videoEnable||this.handleStreamUpdateFailed(!0)});return}else yield this.createStreamAndPublish(!0,!1,i).catch(o=>{var a,n,l,u,m;return p("\u5F00\u542F\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",i==null?void 0:i.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=i.stream;if(o){this.removeFromDetector(o.getStreamId());try{yield this.muteOrUnpublishStream("audio",!0,i,t)}catch(a){return p("\u5173\u95ED\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",i.userId,[JSON.stringify(a)]),Promise.reject(hs(a))}}return}})}joinWithAudioAndAudio(e,t){return c(this,null,function*(){d("join with audio and video","publish","",[e,t]);let i=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,i).catch(r=>{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(r)]),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(r)})})}changeSpeaker(e,t=!1){return c(this,null,function*(){var i;if(d("change speaker","device","",[JSON.stringify(e)]),!(e!=null&&e.deviceId))throw new rr(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),(i=this.room.audioPlayer)==null||i.setDevice(e.deviceId,t)}catch(r){throw p("\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25","device","",["error",r==null?void 0:r.message,JSON.stringify(r)]),new rr(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 i,r,o,a,n;d("change audio input device","device","",[JSON.stringify(e)]),e||I("changeAudioInput, device is null","device");let t=(i=this.localModel)==null?void 0:i.stream;if((r=this.room)==null||r.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,t=!1){return c(this,null,function*(){var r,o,a,n;d("change video input device","device","",[JSON.stringify(e)]);let i=(r=this.localModel)==null?void 0:r.stream;if((o=this.room)==null||o.setSelectVideoDevice(e),t)return!0;if(i)return((a=i.getVideoTrack())==null?void 0:a.readyState)==="ended"?(p("try to change video input device but video track is ended","device"),!1):(yield i.switchDevice("video",e.deviceId).catch(u=>{d("switchDevice:error","device","",[u])}),(n=this.localModel)!=null&&n.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(ps(`\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,this._canUseNoiseFilter).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,this._canUseNoiseFilter).catch(i=>(p("create brtc stream error","publish","",[JSON.stringify(i)]),Promise.reject(i))),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(i=>(this.rtcPublishing=!1,Promise.reject(i)))})}createStreamAndPublish(e,t,i,r){return c(this,null,function*(){var o,a,n,l,u,m,h,g,S;if(this.rtcPublishing)return I(`createStreamAndPublish(audio:${e},video:${t}), rtcPublishing ignore`,"publish",i.userId),!1;if(this.rtcPublishing=!0,d(`createStreamAndPublish(audio:${e},video:${t})`,"publish",i.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=(g=this.room)!=null&&g.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",i.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},i.userId,this._canUseNoiseFilter).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},i.userId,this._canUseNoiseFilter).catch(E=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(E)]),Promise.reject(E)))}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},i.userId,this._canUseNoiseFilter).catch(b=>(p("create brtc video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)))}else{let E=s.getCanvasStream().getVideoTracks()[0];this.audioStream||(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},i.userId,this._canUseNoiseFilter).catch(y=>(p("create brtc stream error","publish","",[JSON.stringify(y)]),Promise.reject(y))));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]),gs("\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",i.userId),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:E,audioSource:C},i.userId,this._canUseNoiseFilter).catch(y=>Promise.reject(y))):Q()?this.brtcStream=this.audioStream:this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:E,audioSource:C},i.userId,this._canUseNoiseFilter).catch(y=>Promise.reject(y))}return this.brtcStream&&(t||(yield this.brtcStream.muteVideo()),e||(yield this.brtcStream.muteAudio()),r&&(yield this.brtcStream.replaceTrack(r).catch(b=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","publish","",JSON.stringify(b))})),yield this.room.publish(this.brtcStream).catch(b=>{var E,C;return(E=this.brtcStream)==null||E.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,i,r;(e=this.brtcStream)==null||e.on("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.on("video-track-ended"+Z,this.muteHandlerVideo),(i=this.brtcStream)==null||i.on("audio-track-mute"+Z,this.muteHandlerAudio),(r=this.brtcStream)==null||r.on("audio-track-ended"+Z,this.muteHandlerAudio)}brtcStreamRemoveEvent(){var e,t,i,r;(e=this.brtcStream)==null||e.off("video-track-mute"+Z,this.muteHandlerVideo),(t=this.brtcStream)==null||t.off("video-track-ended"+Z,this.muteHandlerVideo),(i=this.brtcStream)==null||i.off("audio-track-mute"+Z,this.muteHandlerAudio),(r=this.brtcStream)==null||r.off("audio-track-ended"+Z,this.muteHandlerAudio)}publishBloudStream(e,t){return c(this,null,function*(){var r;let i=this.localModel.userId;this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:e,video_enable:t},i),yield this.bloudStream.publish({video_enable:t,audio_enable:e}),(r=this.localModel)==null||r.updateBloudStream({video:t,audio:e,isScreen:!1},this)})}muteHandler(e){var a,n,l;let t=()=>c(this,null,function*(){var u,m,h,g,S,b,E,C,y;(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)])})),(g=(h=this.localModel)==null?void 0:h.stream)==null||g.destroy(),(S=this.audioStream)==null||S.destroy(),(b=this.videoStream)==null||b.destroy(),(E=this.brtcStream)==null||E.destroy(),this.brtcStream=null,this.audioStream=null,this.videoStream=null,(C=this.localModel)==null||C.updateStream(void 0,!0,this),yield this.bloudStream.unpublish(),(y=this.localModel)==null||y.updateBloudStream(void 0,this)}),i=(a=this.localModel)==null?void 0:a.videoEnable,r=(n=this.localModel)==null?void 0:n.audioEnable,o=(l=this.brtcStream)==null?void 0:l.getAudioDeviceId();if(!i&&!r){d("muteHandler:\u97F3\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}setTimeout(()=>c(this,null,function*(){var u,m,h,g,S,b,E,C,y,L,W,G,F,j,$,ee,te,Te,xe,Le;if((u=this.localModel)!=null&&u.stream){let ie=(m=this.localModel)==null?void 0:m.videoEnable,re=(h=this.localModel)==null?void 0:h.audioEnable;if(o!=((g=this.localModel)==null?void 0:g.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(!ie){d("muteHandler:\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}let _=(b=this.localModel.stream.getVideoTrack())==null?void 0:b.muted,de=(E=this.localModel.stream.getVideoTrack())==null?void 0:E.label,ke=(C=this.localModel.stream.getVideoTrack())==null?void 0:C.enabled,A=(y=this.localModel.stream.getVideoTrack())==null?void 0:y.readyState,J=A==="ended";if(d(`muteHandler:brtc video track status:${_},enabled:${ke},readyState:${A},label:${de} `,"publish",""),!J&&!_&&ke)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:",ie,"audioEnable:",re,"type:",e]),this.localStreamConnectErrorWatcher.next(or("\u6444\u50CF\u5934")),(L=this.localModel)!=null&&L.stream&&(yield(W=this.room)==null?void 0:W.unpublish(this.localModel.stream).catch(vt=>{p("brtc local stream has problem and unpublish failed","publish","",[String(vt)])}),(G=this.localModel)==null||G.updateStream(void 0,!0,this),(j=(F=this.localModel)==null?void 0:F.stream)==null||j.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(re,ie,this.localModel),this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}catch(vt){this.rtcPublishing=!1,p("brtc video stream has problem and republish stream failed","publish","",[JSON.stringify(vt)]),yield t(),this.localStreamConnectErrorWatcher.next(Yt())}}else{if(!re){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",ie,"audioEnable",re,"type",e]),this.localStreamConnectErrorWatcher.next(or("\u9EA6\u514B\u98CE")),(Te=this.audioStream)==null||Te.destroy(),(xe=this.localModel.player)==null||xe.destroy(),this.audioStream=null,this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId);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(Yt()),t()})):(p("recreate audio stream failed, now unpublish","publish"),this.localStreamConnectErrorWatcher.next(Yt()),t())}}this.localStreamErrorWatcher.next(e)}),1e3)}unpublishStream(e=!1){return c(this,null,function*(){var i,r,o,a,n,l,u;d("unpublish stream","publish",(i=this.localModel)==null?void 0:i.userId);let t=this.getLocalStreamModel();if(t){let m=t.stream;m&&e===!0&&(yield(r=this.room)==null?void 0:r.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,i,r=!1){return c(this,null,function*(){let o=i.stream,a=!0;e==="audio"?a=i.videoEnable:e==="video"&&(a=i.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)])}),i.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)])}),i.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(r))})}justReplaceVideoTrack(e){return c(this,null,function*(){var r;let i=s.getCanvasStream().getVideoTracks()[0];try{yield e.replaceTrack(i),yield e.muteVideo()}catch(o){p("\u5173\u95ED\u672C\u5730\u89C6\u9891\u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(o)])}try{(r=this.videoStream)==null||r.destroy(),this.videoStream=null}catch(o){p("this.videoStream destroy failed","publish")}})}toggleShareScreen(r){return c(this,arguments,function*(e,t={},i){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,i).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,i;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()),(i=this.videoStream)==null||i.destroy(),this.videoStream=null,this.videoStream=yield this.room.createPBSingleLocalStream({video:!0,audio:!1},this.localModel.userId).catch(r=>(p("createPBSingleLocalStream error","publish","",[JSON.stringify(r)]),Promise.reject(r))),this.videoStream.getVideoTrack()})}startRecord(e){return c(this,null,function*(){var i,r,o,a;if(this._recorder)return;this._recorder=(i=this.room)==null?void 0:i.boomCore.createRecorder(e),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record: ended","record")}),this._recorder.on("started",()=>{var n;d("record: started.","record"),this._recorder.muteAudio(!((n=this.localModel)!=null&&n.audioEnable))});let t=!0;try{yield this._recorder.start(void 0,void 0,{roomId:(r=this.room)==null?void 0:r.roomInfo.roomID,userName:(o=this.localModel)==null?void 0:o.getUser().nickname,title:(a=this.room)==null?void 0:a.roomInfo.roomName}),this._isRecording=!0,this.isRecordingWatcher.next(!0),this.shareStreamModels.forEach(n=>{n.stream&&!n.stream.isLocalStream()&&n.stream.isSubscribed()&&this.addToRecorder(n.stream)}),this.streamModels.forEach(n=>{n.stream&&!n.stream.isLocalStream()&&n.stream.isSubscribed()&&this.addToRecorder(n.stream)})}catch(n){I("record: error","record","",[JSON.stringify(n)]);let l=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),t=!1,yield l==null?void 0:l.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,i){return c(this,null,function*(){var a,n,l,u;if((a=this._recorder)!=null&&a.supportAutoSave())return!0;if(!this._isRecording)return;let r=(n=this._recorder)==null?void 0:n._opts;this._slicingRecord=!0;try{yield(l=this._recorder)==null?void 0:l.stop()}catch(m){p("record:stop record exception","","",[JSON.stringify(m)])}r.filename=e,this._recorder=(u=this.room)==null?void 0:u.boomCore.createRecorder(r),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record:record ended.")}),this._recorder.on("started",()=>{var m;d("record:record started."),this._recorder.muteAudio(!((m=this.localModel)!=null&&m.audioEnable))});let o=!0;try{yield this._recorder.start(t,i),this._slicingRecord=!1,this.shareStreamModels.forEach(m=>{m.stream&&!m.stream.isLocalStream()&&m.stream.isSubscribed()&&this.addToRecorder(m.stream)}),this.streamModels.forEach(m=>{m.stream&&!m.stream.isLocalStream()&&m.stream.isSubscribed()&&this.addToRecorder(m.stream)})}catch(m){let h=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),this._slicingRecord=!1,o=!1,console.log("record:stopRecord.error",m),yield h==null?void 0:h.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 r,o,a;let i=!0;t?(((r=this._speaker)==null?void 0:r.getUserInfo().userId)===t.getUser().userId&&(i=!1),this._speaker=t.getUser()):(this._speaker||(i=!1),this._speaker=null),i&&(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,i)=>{e.push(i)}),e.forEach(t=>{this.removeFromDetector(t)})}shareCustomMedia(e,t){return c(this,null,function*(){var i;return(i=this.room)==null?void 0:i.boomCore.shareHTMLMedia(e,t)})}updateBloudStreamCustomStats(e,t,i){return c(this,null,function*(){var o,a;d("update bloud stream custom stats","",e,[t,JSON.stringify(i)]);let r=yield(o=this.room)==null?void 0:o.boomCore.updateStream(e,t,i);((a=this.localModel)==null?void 0:a.userId)===e&&t.startsWith(e)&&t.endsWith("_screen")&&r.customInfo&&(this.localShareCustomStats=r.customInfo)})}checkStreamStats(e){d("check stream stats","","",[e]),this.streamModels.size<100&&this.streamModels.forEach(t=>{t.checkStreamIsPlaying()})}setEnableNoiseFilter(e,t){return c(this,null,function*(){var i,r,o;if(this._enableNoiseFilter=e,e)try{yield zt(t),this._canUseNoiseFilter=!0}catch(a){throw p("init noise filter error","publish","",[JSON.stringify(a)]),this._canUseNoiseFilter=!1,a}else this._canUseNoiseFilter=!1;if((i=this.localModel)!=null&&i.stream&&this.localModel.audioEnable){let a;this._canUseNoiseFilter?a=(yield Et((o=(r=this.room)==null?void 0:r.selectAudioDevice)==null?void 0:o.deviceId)).getTracks()[0]:(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId),a=this.audioStream.getMediaStream().getTracks()[0]),this.localModel.stream.replaceTrack(a).then(()=>{d(`noise filter replace track ${this._canUseNoiseFilter?"noise":"audio"}`,"publish","",[])}).catch(n=>{throw p(`noise filter replace track ${this._canUseNoiseFilter?"noise":"audio"} error`,"publish","",[JSON.stringify(n)]),n})}return!0})}clearCache(){var e,t,i,r,o;try{(t=(e=this.localModel)==null?void 0:e.stream)==null||t.destroy(),(i=this.videoStream)==null||i.destroy(),(r=this.audioStream)==null||r.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 Ct}from"rxjs";import{debounce as Zt}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 Ct;this.chatNoticeWatcher=new Ct;this.totalUserWatcher=new K(0);this.totalWaitRoomUserWatcher=new K(0);this.isOpenWaitRoom=new Ct;this.originJoinRoomParams={};this.originRespInfo={};this.audioOffWatcher=new Ct;this.lockWatcher=new K(this.lock);this.leaveNoticeWatcher=new K(this.leaveNotice);this.openSelfWatcher=new K(this.openSelf);this.setRaiseHandsWatcherValue=Zt(()=>{this.raiseHandsWatcher.next(Array.from(this.raiseHandsList.values()))},1e3);this.setVideoRaiseHandsWatcherValue=Zt(()=>{this.raiseVideoHandsWatcher.next(Array.from(this.raiseVideoHandsList.values()))},1e3);this.setSimpleRaiseHandsWatcherValue=Zt(()=>{this.raiseSimpleHandsWatcher.next(Array.from(this.raiseSimpleHandsList.values()))},1e3);this.room=e,M.emitter.on(k,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=N(N({},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 et,Subject as D}from"rxjs";var Kt={name:"@hysc/meeting",version:"10.9.0",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:*","@timephy/rnnoise-wasm":"^1.0.0","detect-browser":"^5.3.0",immutable:"5.0.0-beta.4","lodash-es":"^4.17.21",mitt:"^3.0.0",rxjs:"^7.5.5"},peerDependencies:{"@hysc/core":"workspace:*"},devDependencies:{"@hysc/brtc":"workspace:*","@types/lodash-es":"^4.17.6",typescript:"6.0.0-dev.20260118"}};import{Logger as ur,LOGLEVEL as Us}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 Rs,BMCameraOccupyError as Ns,BMCreateStreamError as Ps,BmLeaveError as ws,BMMicNotAuthError as Ts,BMMicOccupyError as xs,BmSetAudioOffError as Ls,BmSetMsgOffError as ks,BmSetVideoOffError as Os,BMShareStreamConnectError as Ds,BMStreamConnectError as _s,BMStreamReconnectFailed as Vs,BMStreamReconnectSuccess as Hs,BmUpdateCustomStatsError as Ws,getStreamError as Gs,RepeatJoinError as Fs}from"@hysc/utils";var ei=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 i;t.isMixer||!t.isLocal&&t.stream&&((i=t.stream)!=null&&i.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||O.addQueue(this.room.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)})})}handleMixStream(e,t){return c(this,null,function*(){var r,o;let i=this.room.bmStreamVm.mixStreamUid;if(i){let a=this.room.bmStreamVm.streamModels.get(i);e?(r=a==null?void 0:a.stream)==null||r.muteAudio().then(()=>{d(`play:\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${i}`)}):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:${i}`)})}t==null||t(e)})}},ar=ei;import{debounce as dr,isNumber as js,toNumber as mr,delay as $s}from"lodash-es";import{BrtcEvents as nr}from"@hysc/utils";function lr(s){var i,r;let e=()=>s.fire(nr.BRTC_ROOM_ROCONNECTING),t=()=>s.fire(nr.BRTC_ROOM_RECONNECTED);(i=s.brtcClient.client)==null||i.signal.channel.on("reconnecting",e),(r=s.brtcClient.client)==null||r.signal.channel.on("reconnected",t)}import{AudioPlayer as bs}from"@hysc/core";import{Subject as Is}from"rxjs";var Ke=class{constructor(e,t){this.playMap=new WeakSet;this.playerMap=new Map;this.muted=!1;this.playStateChangeWatcher=new Is;var r;let i=document.getElementById(e);if(i)this.container=i;else throw new Error("no container found, play failed");this.room=t,this.deviceId=(r=t.selectAudioOutputDevice)==null?void 0:r.deviceId}addStream(e,t=!1){let i=this.room.localUser,r=i.audienceEnableSpeaking;if(i.isAudience)if(r){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(),i=this.playerMap.get(t);i&&i.destroy(),d("remove audio player","","",["streamId =>",t]),this.playerMap.delete(t),this.playMap.delete(e)}removeStreamByUid(e){let t=new Map;this.playerMap.forEach(i=>{q(i.stream)||i.stream.getUserId()===e&&t.set(i.stream.getStreamId(),i)}),t.forEach((i,r)=>{i.off(),i.destroy(),this.playerMap.delete(r),this.playMap.delete(i.stream)}),t.clear()}play(e){return c(this,null,function*(){var t;if(e.hasAudio()&&this.container){let i=new bs(this.container,{});this.addPlayerEvent(i),yield i.play(e);let r=Pe(e.getUserId().toString());if(this.deviceId?yield i.setSinkId(this.deviceId):(I("audioPlayer play() this.deviceId is null ","",r,["streamId =>",e.getStreamId()]),Q()&&(yield i.setSinkId("default"))),this.muted)i.setVolume(0);else{let o;if(q(e)?o=this.room.bmStreamVm.shareStreamModels.get(r):o=this.room.bmStreamVm.streamModels.get(r),o){let a=(t=o.bloudStream)==null?void 0:t.customInfo;a&&a.volume&&(i.audioLevel=a.volume,i.setVolume(a.volume))}}this.playerMap.set(e.getStreamId(),i)}})}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 i=this.playerMap.get(e);if(i){if(i.audioLevel=t,this.muted)return;i.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(i=>i.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 Bt=1,Js={audio:!0,video:!0,streamType:"small",videoEnable:!0,audioEnable:!0},ze=!0,we=class{constructor({initDevices:e,ignoreMixer:t,template_name:i}={initDevices:!0,ignoreMixer:!1,template_name:""}){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 et(this.selectVideoDevice);this.selectAudioDeviceWatcher=new et(this.selectAudioDevice);this.selectAudioOutputDeviceWatcher=new et(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.shareFileWatcher=new et(null);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 et({type:"init",status:!1,isNotCancelRootReport:!1});this.isInWaitRoom=!1;this.shouldPlayAudio=!0;this.deviceChanging=!1;this.ignoreMixer=!1;this.template_name="";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,$s(()=>{this.deviceChanging=!1},1200);let{changed:t,selectAudioDevice:i,selectAudioOutputDevice:r,selectVideoDevice:o}=yield this.initDevices(!0),a=i,n=r;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=()=>Bs().then(e=>{if(!Q())return e;let t=[];return e.forEach((i,r)=>{i.name.includes("front")||i.name.includes("\u524D\u7F6E")?i.name=`\u524D\u7F6E${r.toString().padStart(2,"0")}`:(i.name.includes("back")||i.name.includes("\u540E\u7F6E"))&&(i.name=`\u540E\u7F6E${r.toString().padStart(2,"0")}`),t.push(i)}),t});this.enumAudioInputDevices=()=>Cs().then(e=>{let t=e,i=e.find(r=>r.default);if(i){let r=Object.assign({},i);r.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${i==null?void 0:i.name}\uFF09`,t.unshift(r)}return t});this.enumAudioOutputDevices=()=>vs().then(e=>{let t=e,i=e.find(r=>r.default);if(i){let r=Object.assign({},i);r.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${i==null?void 0:i.name}\uFF09`,t.unshift(r)}return t});this.getPermissions=As;this.checkSystemSupport=Ms;this.createStream=Es;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=dr(e=>c(this,null,function*(){let t=e.getAudioOn()||this.localUser.audioEnable||!1,i=e.getVideoOn()||this.localUser.videoEnable||!1;d("republish local stream ","","",[t,i]),yield this.publish(e).then(()=>c(this,null,function*(){this.bmStreamVm.bloudStream=null,yield this.bmStreamVm.publishBloudStream(t,i),d("local stream connect error, and republish success, bloud stream republish success","","",["audio =>",t," video => ",i]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Hs(t,i))})).catch(()=>{d("local stream connect error, and republish failed","","",["audio =>",t," video => ",i]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Vs())})}),1e3);this.processUser=(e,t=0)=>c(this,null,function*(){let i="";if(e.isScreen){let r=this.bmStreamVm.getShareStreamModelByUId(e.id);(!r||!r.stream&&!r.isLocal)&&(e.isWeb?i=`${e.id}_screen`:i=e.id)}else{let r=this.bmStreamVm.streamModels.get(e.id);r&&!r.stream&&!r.isLocal&&(i=e.id)}if(i){d("brtc query streams","","",["queryId => ",i]);try{let r=yield this.queryBrtcStreams([i]);if(r&&r.length){let o=r.map(a=>[a.getUserId(),a.getStreamId()]);d("brtc query streams result ","","",["streamInfo =>",JSON.stringify(o)]),r&&this.handleAddStreams(r)}else t<10?(t+=1,yield H(1e3),this.processUser(e,t)):I(`query stream error: uId:${e}`)}catch(r){p("query stream error","","",[JSON.stringify(r),t]),t<10&&(t+=1,yield H(1e3),this.processUser(e,t))}}});ur.setLogLevel(Us.INFO),d(`
|
|
1
|
+
var pr=Object.defineProperty,fr=Object.defineProperties;var gr=Object.getOwnPropertyDescriptors;var ii=Object.getOwnPropertySymbols;var Sr=Object.prototype.hasOwnProperty,br=Object.prototype.propertyIsEnumerable;var ri=(s,e,t)=>e in s?pr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,N=(s,e)=>{for(var t in e||(e={}))Sr.call(e,t)&&ri(s,t,e[t]);if(ii)for(var t of ii(e))br.call(e,t)&&ri(s,t,e[t]);return s},_e=(s,e)=>fr(s,gr(e));var c=(s,e,t)=>new Promise((i,r)=>{var o=l=>{try{n(t.next(l))}catch(u){r(u)}},a=l=>{try{n(t.throw(l))}catch(u){r(u)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(o,a);n((t=t.apply(s,e)).next())});import Ms,{checkSystemSupport as Es,createStream as Cs,enumAudioInputDevices as vs,enumAudioOutputDevices as Bs,enumVideoDevices as As,getPermissions as Us}from"@hysc/core";var U=class extends Error{constructor(t,i,r,o){super();this.code=t,this.error=r,this.BoomErrorFlag=!0,this.eName=o,this.message=i}static instanceOf(t){return!!(t&&t.BoomErrorFlag)}getCode(){return this.code}};var si=1,Ir=2,oi=3,yr=4;var Mr=function(){},Ks=/BRTC/.test(Mr.toString())?si:oi;function rt(s,e,t,i){let r=[];return t&&r.push(t),i&&r.push(i),`[${new Date().toLocaleTimeString("chinese",{hour12:!1})}] <${s}> [${r.join("|")}] ${e}`}function Er(s,e,t,i=[]){i.unshift(rt("DEBUG",s,e,t)),console.log(...i)}function d(s,e,t,i=[]){Array.isArray(i)||(i=[i]),i.unshift(rt("INFO",s,e,t)),console.log(...i)}function I(s,e,t,i=[]){Array.isArray(i)||(i=[i]),i.unshift(rt("WARN",s,e,t)),console.log(...i)}function p(s,e,t,i=[]){typeof i=="string"?i=[i]:Array.isArray(i)||(i=[JSON.stringify(i)]),i.unshift(rt("ERROR",s,e,t)),console.log(...i)}var eo={[si]:Er,[Ir]:d,[oi]:I,[yr]:p};import{BehaviorSubject as Xr}from"rxjs";var ai="undefined";var Cr=typeof window!==ai?window:void 0;var to=typeof global!==ai?global:Cr;var io=Object.freeze({}),ro=Object.freeze([]);var P="c";import{BehaviorSubject as wr}from"rxjs";var T="_screen",ot="screen-",at="xinhao_";var he="sub-message",pe="user-sort-num-change",fe="bind-element",oe="stream-connect-error",O="raise-hand",ge="manual-subscription",Se="unsubscribe-stream",be="change-is-guest",Ie="bind-big-element",ae="no-container",ye="model-sort-num-change",Me="add-pull-user",Ee="set-volume",Ce="add-audio-play",H="stream-play",nt="share-file";import vr from"mitt";var B=class B{static getInstance(){return B.emitter||(B.emitter=vr()),B.emitter}};B.emitter=void 0,B.removeEmitter=()=>{var e,t,i,r,o,a,n,l,u,m,h,g,S,b,E;(e=B.emitter)==null||e.off(he),(t=B.emitter)==null||t.off(pe),(i=B.emitter)==null||i.off(oe),(r=B.emitter)==null||r.off(O),(o=B.emitter)==null||o.off(Se),(a=B.emitter)==null||a.off(ge),(n=B.emitter)==null||n.off(be),(l=B.emitter)==null||l.off(fe),(u=B.emitter)==null||u.off(Ie),(m=B.emitter)==null||m.off(ae),(h=B.emitter)==null||h.off(ye),(g=B.emitter)==null||g.off(Me),(S=B.emitter)==null||S.off(Ee),(b=B.emitter)==null||b.off(Ce),(E=B.emitter)==null||E.off(H),B.emitter=void 0};var M=B;function ni(s){return At===2?Ur(s):Ar(s)}function Ar(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 Ur(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 li="undefined";var Ve="function";var Rr=typeof window!==li?window:void 0;var fo=typeof global!==li?global:Rr;var go=Object.freeze({}),So=Object.freeze([]),Ut="";function Rt(s){return typeof s===Ve}function Nr(s,e,t){return s.indexOf(e,t!==void 0?t:0)}function ui(s,e){return Nr(s,e)>=0}function di(s,e){return s!=null&&s.toString?s.toString():e!==void 0?e:Ut}function Pt(s){return Rt(s)&&ui(di(s),"[native code]")}var wt;typeof setImmediate===Ve&&Pt(setImmediate)&&(wt=setImmediate);typeof MessageChannel===Ve&&Pt(MessageChannel)?wt=function(s){let e=new MessageChannel;e.port1.onmessage=s,e.port2.postMessage(1)}:wt=setTimeout;var mi=5*60*1e3;function Tt(s){let e=new Date(s),t=new Date,i=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,r=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:i+"\u6708"+r+"\u65E5 "+o+":"+a}function We(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 hi(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 Ge(s){return!Fe(s,"s")}function ct(s){return Fe(s,"a")}function xt(s){return Fe(s,"v")}function ut(s){return Fe(s,"m")}function dt(s){return Fe(s,"o")}function Fe(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 ne=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 r;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=(r=e.userInfo)==null?void 0:r.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=ct(e.permission.permission)),this.raiseHandTime=e.raiseHandTime||0;let i={operation:"none",user:this};this.watcher=new wr(i),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,i,r){this.isLocal=!0,this.userId=e,this.userInfo=t,i?this.nickName=i:this.nickName=t.nickname,this.avatar=t.avatar,r&&r.signals&&(this.signals=r.signals),this.customInfo=r}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(at))}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={},i){var u,m;let r=(u=t==null?void 0:t.params)==null?void 0:u.customInfo,o=(r==null?void 0:r.updateKeys)||[];this.customInfo=r;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=r.raiseHandsAudio,n="raiseHandsAudio",M.emitter.emit(O,{status:"raiseHandsAudio",user:this}),a=!0),o.includes("raiseHandsVideo")&&(this.raiseVideoHands=r.raiseHandsVideo,n="raiseHandsVideo",M.emitter.emit(O,{status:"raiseHandsVideo",user:this}),a=!0),o.includes("raiseHand")&&(this.raiseHand=r.raiseHand,this.raiseHandTime=r.raiseHandTime,n="raiseHand",M.emitter.emit(O,{status:"raiseHand",user:this}),a=!0),i.conferenceMode!==1&&this.isAudience&&o.includes("permission")&&((r==null?void 0:r.permission.indexOf("A"))!==-1&&(i.enableAudienceSpeakingWatcher.next(!0),this.audienceEnableSpeaking=!0,n="audienceEnableSpeaking",this.isLocal&&i.bmLiveVM.handleAudienceEnable()),(r==null?void 0:r.permission.indexOf("A"))===-1&&(i.enableAudienceSpeakingWatcher.next(!1),this.audienceEnableSpeaking=!1,n="audienceEnableSpeaking",this.isLocal&&i.bmLiveVM.handleAudienceDisable())),o.includes("inBackground")&&(n="inBackground",this.inBackground=r.inBackground),o.includes("isCalling")&&(n="isCalling",this.isCalling=r.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"}`),M.emitter.emit(be,{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 i=ni(this);this.setSortNum(i,e,t)}setSortNum(e,t,i){this.sortNum===e&&!t||(this.sortNum=e,t&&M.emitter.emit(pe,{isCommon:this.isCommonUser,isAudience:this.isAudience,shouldDelay:i}))}};import{BehaviorSubject as ve}from"rxjs";function W(s){return new Promise(e=>setTimeout(e,s))}import{debounce as mt}from"lodash-es";var Ae=["-mixer-","-rtmpmixer-","record#","robot_","stt_"],Be=500,ht="RWPSAVMO,RWPSAVM,RWPSAV,RWPSA",je=class s{constructor(e,t,i){this.userList=new Map;this.audiencesList=new Map;this.signalList=new Map;this.commonUserList=new Map;this.userListWatcher=new ve(Array.from(this.userList.values()));this.audiencesListWatcher=new ve(Array.from(this.audiencesList.values()));this.commonUserListWatcher=new ve(Array.from(this.commonUserList.values()));this.signalListWatcher=new ve(Array.from(this.signalList.values()));this.masterUserWatcher=new ve(null);this.getForceUserWatcher=new ve(!1);this.commTimer=200;this.addBCUser=(e,t=!1,i=!1)=>{var a;let r=this.addUser(e);if(this.room.isWorkShop&&!ct(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(r);{let n=this.room.bmStreamVm.streamModels.get(e.userId);n&&(e.stream.size?e.stream.forEach(l=>c(this,null,function*(){var g,S,b;let{video_enable:u,audio_enable:m,customInfo:h}=l;if(l.screen){r.hasShare=!0,this.room.bmStreamVm.shareBloudStateMap.set(e.userId,{audio:m,video:u,customInfo:h,userId:e.userId,streamId:l.getID(),isScreen:!0});let E={id:n.userId,isScreen:!0,isWeb:n.isWeb};t?yield(g=this.room)==null?void 0:g.processUser(E):(S=this.room)==null||S.addUser2Queue(E)}else if(n&&(n.updateBloudStream({video:u,audio:m,isScreen:l.screen,customInfo:h},this.room.bmStreamVm),t)){let E={id:n.userId,isScreen:!1,isWeb:n.isWeb};(b=this.room)==null||b.processUser(E)}})):(n.bloudStream&&n.updateBloudStream(void 0,this.room.bmStreamVm),(a=this.room)==null||a.bmStreamVm.removeShareStreamModelByUId(e.userId)))}return r&&r.isMaster&&this.masterUserWatcher.next(r),r==null||r.updateSortNum(i),r};this.updateAllSort=()=>{this.updateUserSort(),this.updateCommonUserSort(),this.updateAudienceUserSort(),this.updateSignalUserSort()};this.updateSortByType=e=>{var t,i;(t=this.room)!=null&&t.isSingleColumns||e.isCommon?(i=this.room)!=null&&i.isBig&&e.shouldDelay?this.updateDelayCommonUserSort():this.updateCommonUserSort():(e.isAudience?this.updateAudienceUserSort():this.updateUserSort(),this.updateSignalUserSort())};this.updateUserSort=mt(()=>{let e=this.sortUsers();this.userListWatcher.next(s.filterUsers(e))},200,{maxWait:1e3});this.updateCommonUserSort=mt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},this.commTimer,{maxWait:12*1e3});this.updateDelayCommonUserSort=mt(()=>{let e=this.sortCommonUsers();this.commonUserListWatcher.next(s.filterUsers(e))},120*1e3,{maxWait:120*1e3});this.updateAudienceUserSort=mt(()=>{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="",i=!1,r=0)=>c(this,null,function*(){let o=new Map;yield this.getAllUsers(e,o,t,i).catch(()=>{if(r<3){p("get bloud user error, retry"),r+=1,this.transBloudUsers(e,t,i,r);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=i,M.emitter||p("init boom emitter error"),M.emitter.on(be,this.handleUserRoleChange.bind(this)),M.emitter.on(pe,this.updateSortByType)}handleUserRoleChange(e){return c(this,null,function*(){var n,l,u;let{user:t,isGuest:i,preIsGuest:r}=e,o=(n=this.room)==null?void 0:n.roomInfo.isBigRoom;if(d("handleUserRoleChange","",t.userId,["isGuest =>",i,"preIsGuest =>",r,"isBigRoom =>",o]),((l=this.room)==null?void 0:l.userListColumns)===1||(r?this.userList.delete(t.userId):this.commonUserList.delete(t.userId),i?this.userList.set(t.userId,t):this.commonUserList.set(t.userId,t)),o)if(i)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 r;let t=this.getUser(e.userId);if(t)return d("\u8BE5\u7528\u6237\u5DF2\u7ECF\u52A0\u5165\u623F\u95F4",P,e.userId),this.updateUser(t,e),t;let i;return this.boomCore.userId==e.userId?(this.updateUser(this.localUser,e),i=this.localUser):i=this.toBMUser(e),((r=this.room)==null?void 0:r.userListColumns)===1?this.commonUserList.set(i.userId,i):i.isAudience?this.audiencesList.set(i.userId,i):i.isSignal?this.signalList.set(i.userId,i):i.isCommonUser?this.commonUserList.set(i.userId,i):this.userList.set(i.userId,i),i}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",P,e),t}videoEnable(e){let t=this.getUser(e);if(t)return t.videoEnable;throw new U(9001,"\u7528\u6237\u4E0D\u5B58\u5728")}audioEnable(e){let t=this.getUser(e);if(t)return t.audioEnable;throw new U(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(at)?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,i="",r=!1){return c(this,null,function*(){let o;if(r){let{users:a,total:n}=yield this.boomCore.getUsersList(e,i,Be);o=a}else{let{users:a,total:n}=yield this.boomCore.getUsers(e,i,Be);o=a}o.forEach(a=>{t.set(a.userId,a)})})}initUserList(e){return c(this,null,function*(){var i,r;let t=e.get(this.localUser.userId);if(t){let o=this.addUser(t);if(!((i=this.room)!=null&&i.bmStreamVm.getStreamModelByUId(t.userId))){let a=this.getUser(t.userId);a?(r=this.room)==null||r.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,i=!1){e.forEach(r=>{this.addBCUser(r,t,i)})}updateMaster(e,t,i){let r=this.getUser(e);r&&(r.isManager&&(r.isManager=!1),r.isMaster=!0,r.updateSortNum());let o=this.getUser(t);return o&&(o.isMaster=!1,i&&(o.isManager=!0),o.updateSortNum()),!r&&!o&&p("\u672A\u627E\u5230\u8BE5\u7528\u6237, updateMaster\u672A\u751F\u6548",P,e,["masterId => ",e,"oldMasterId => ",t]),{master:r,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",P,e):p("\u672A\u627E\u5230\u8BE5\u7528\u6237, managerChangeToGuest\u672A\u751F\u6548",P,e),t}updateManager(e,t,i=!0){let r=this.getUser(e);return r?(r.permission.setManage(t),i?r.permission.setSubscribe(!0):r.permission.setSubscribe(t),this.boomCore.updateUser(e,{customInfo:{permission:r.permission.get()}}),r.watcher.next({operation:t?"getManager":"removeManager",user:r}),this.updateAllSort()):p("userList\u4E2D\u672A\u627E\u5230\u8BE5\u7528\u6237, updateManager\u672A\u751F\u6548",P,e),r}getLocalUser(){return this.localUser}updateUser(e,t){var C,y,L,G,F,j,$,J;let i=this.checkIsMaster(t.userId),r=(((C=t.permission)==null?void 0:C.getManage())||ut((y=t.permission)==null?void 0:y.permission))&&!((L=t.permission)!=null&&L.getOwn()||dt((G=t.permission)==null?void 0:G.permission)),o="none",a=e.isMaster;e.isManager!==r&&(r?o="getManager":o="removeManager"),o!=="none"&&setTimeout(()=>{e.watcher.next({operation:o,user:e})},10),a!==i&&(i?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 g=e.raiseAudioHands,S=t.customInfo.raiseHandsAudio;g!==S&&(!S&&g&&this.room.roomInfo.removeRaiseHandUser(e.userId),setTimeout(()=>{e.watcher.next({operation:"raiseHandsAudio",user:e})},300));let b=e.nickname,E=t.nickname;if(b!==E&&setTimeout(()=>{e.watcher.next({operation:"changeNickName",user:e})},300),e.isAudience){let te=e.audienceEnableSpeaking,ie=t.permission.getAudio();te!==ie&&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=i,e.isCreate=this.boomCore.getCreator()===t.userId,e.isAudience=!t.permission.getVideo(),e.isCommonUser=!t.permission.getSubscribe(),e.isManager=r,e.inBackground=!!((F=t==null?void 0:t.customInfo)!=null&&F.inBackground),e.isCalling=!!((j=t==null?void 0:t.customInfo)!=null&&j.isCalling),($=t.customInfo)!=null&&$.signals&&(e.signals=(J=t==null?void 0:t.customInfo)==null?void 0:J.signals),e.isAudience&&(e.audienceEnableSpeaking=t.permission.getAudio()),e.updateSortNum()}updateLocalUserPermission(e){let t=this.getLocalUser();t.isMaster=dt(e),t.isManager=!dt(e)&&ut(e),t.isCommonUser=Ge(e),t.isAudience=!xt(e),t.watcher.next({operation:"none",user:t})}toBMUser(e){var r,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()||Ge(e.permission.permission),t.isAudience=!xt(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 i=this.boomCore.getLocalParticipant();if(!i)throw new U(1001,"BCUserVM addUser\u65F6\u672A\u627E\u5230\u672C\u5730\u7528\u6237");return i.getID()==t.userId&&(t.isLocal=!0),((r=t.permission)!=null&&r.getManage()||ut((o=t.permission)==null?void 0:o.permission))&&!t.isMaster&&(t.isManager=!0),new ne(t,t.isLocal)}sortUsers(){return We(Array.from(this.userList.values()))}sortAudiences(){return We(Array.from(this.audiencesList.values()))}sortCommonUsers(){return We(Array.from(this.commonUserList.values()))}sortSignalUsers(){return We(Array.from(this.signalList.values()))}static filterUsers(e){return e.filter(t=>!s.filterUser(t.userId))}static filterUser(e){return Ae.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/Be),i=0,r=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 W(50)});if(r&&((l=this.room)!=null&&l.isBig))this.commonUserList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ht,!0);else if(this.room.conferenceMode===2)this.room.localIsAudience&&this.audiencesList.set(this.localUser.userId,this.localUser),yield this.transBloudUsers(-1,ht,!0);else{for(;i<t;)o.push(a.bind(null,i)),i+=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,i="RWPAV",r="array"){return c(this,null,function*(){let{users:o,total:a}=yield this.boomCore.getUsers(e,i,t);if(r==="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,i="array"){return c(this,null,function*(){let{users:r,total:o}=yield this.boomCore.getUsers(e,"RWPS",t,i),{users:a,total:n}=yield this.boomCore.getUsers(e,"RWPSA",t,i);if(e===-1&&this.audiencesList.clear(),i==="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)}),r.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)}),r.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,i="",r=!1){return c(this,null,function*(){var u,m;let{users:o,total:a,pageIndex:n}=yield this.boomCore.getUsersList(e,i,t,r),l=[];return o.forEach(h=>{if(s.filterUser(h.userId))return;let g=this.toBMUser(h);l.push(g)}),r&&((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:i}=yield this.boomCore.getUsers(0,"",1);return i}),t=i=>{e().then(r=>{i(r)}).catch(r=>{p("getTotalUserNumber error","","",[JSON.stringify(r)]),t(i)})};return new Promise((i,r)=>c(this,null,function*(){t(i)}))})}clearUsers(){this.userList.clear(),this.commonUserList.clear(),this.audiencesList.clear(),this.signalList.clear()}searchUsers(e,t){return c(this,null,function*(){try{let{users:i}=yield this.boomCore.searchUsers(e,t,!1),r=[],o=[],a=[];return i.forEach(n=>{let l=this.userList.get(n.userId);if(l){r.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:r,commonUserList:o,audienceList:a}}catch(i){return Promise.reject(new U(1e3,"boomCore.searchUsers\u53D1\u751F\u9519\u8BEF:"+(i==null?void 0:i.message)))}})}searchWaitRoomUsers(e,t){return c(this,null,function*(){try{let{users:i}=yield this.boomCore.searchUsers(e,t,!0),r=[];return i.forEach(o=>{let a=this.toBMUser(o);r.push(a)}),r}catch(i){return Promise.reject(new U(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=Tt(this.timeStamp)):(this.timeStamp=new Date().getTime(),this.time=Tt(this.timeStamp));let i=this.message.match(/^\[(.*?)\]$/);this.isEmoji=i!==null&&i[0].length<=20&&i[0].length>=4}};import{debounce as Vr}from"lodash-es";function z(s){let e=s.getStreamId();return s.getUserId().toString().endsWith(T)||e.startsWith(ot)||s.getType&&s.getType()==="assist"}import{debounce as xr}from"lodash-es";import{BMShareStreamReconnectFailed as Lr,BMShareStreamReconnectSuccess as kr,BMStreamReconnectSuccess as Or}from"@hysc/utils";import{BrtcEvents as fi,BloudEvents as Lt}from"@hysc/utils";function gi(s){var t,i;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 r=e.stream.getAudioOn(),o=e.stream.getVideoOn();s.publishBloudStream(r,o).then(()=>{var a;d("brtc stream repub success bloud repub success, notify reconnect success"),s.localStreamConnectErrorWatcher.next(Or(r,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 r=(t=s.room)==null?void 0:t.boomCore.shareScreenStream;if(r){let o=r.getAudioOn(),a=r.getVideoOn();try{(i=s.room)==null||i.boomCore.createAndPubBloudShareStream(o,a)}catch(n){p("bloud \u5171\u4EAB\u5C4F\u5E55\u6D41\uFF0C\u65AD\u7F51\u91CD\u8FDE\u91CD\u63A8\u6D41\u5931\u8D25")}}}}var ce=xr(s=>{if(s.networkState.bloud&&s.networkState.brtc)try{s.streamQueue.restart()}catch(e){p("streamQueue restart error",JSON.stringify(e))}},300);function Si(s,e,t,i){let r=s.stream;if(d("\u672C\u5730\u63A8\u6D41","\u672C\u5730\u63A8\u6D41",r.getUserId()),r){let o=e.getLocalStreamModel();o&&e.updateStreamModel(o,r),i[fi.STREAM_PUBLISHED].next({published:!0,model:o}),t.conferenceMode===1&&t.getLocalParticipant().isAudience&&e.getStreamModels().forEach(n=>{n.sendMessage2Room()})}else i[fi.STREAM_PUBLISHED].next({published:!1})}function bi(s,e,t){d("bloud publish stream"),kt(s,e,!0),t[Lt.STREAM_PUBLISHED].next(s)}function kt(s,e,t=!1){var a,n,l;d("bloud stream update","","",[JSON.stringify(s)]);let i=s.userId,r=s.isScreen,o=e.streamModels.get(i);if(o)if(!r)o.updateBloudStream(s,e,t),o.getUser().updateSortNum();else{e.shareBloudStateMap.set(i,s);let u=(a=e.room)==null?void 0:a.userVM.getUser(i);u&&(u.hasShare=!0);let m={id:i,isWeb:o.isWeb,isScreen:r};(n=e.room)==null||n.addUser2Queue(m)}else{I("bloud stream update, but can not get streamModel","",i);let u=(l=e.room)==null?void 0:l.userVM.getUser(i);if(!u){p("bloud stream update, but can not get user","",i);return}e.createStreamModel(u).updateBloudStream({audio:s.audio,video:s.video,isScreen:s.isScreen},e)}}function Ii(s,e,t,i){d("bloud unpublish stream","","",[JSON.stringify(s)]),_r(s,e,t),i[Lt.STREAM_REMOVED].next(s)}function yi(s,e,t){d("bloud stream update","","",[JSON.stringify(s)]);let i=s.streamId,r=s.userId,o=s.params.customInfo,a;i.includes("_screen")?a=e.shareStreamModels.get(r):a=e.streamModels.get(r),a?a.updateBloudCustomInfo(o):p("bloud stream update, but can not get streamModel","",r,["streamId =>",i]),t[Lt.UPDATE_STREAM].next(s)}function _r(s,e,t){var o,a,n,l;let i=s.userId;if(s.isScreen){let u=e.shareStreamModels.get(i),m=(n=e.room)==null?void 0:n.userVM.getUser(i);if(m&&(m.hasShare=!1),u){let h=u.stream;h?(h.destroy(),e.remoteStreamUnpublished(h)):e.removeShareStreamModelByUId(i);let g=t.shareFileWatcher.getValue();g!=null&&g.streamId==i+"_screen"&&t.shareFileWatcher.next(null);let S={id:i,isWeb:u.isWeb,isScreen:!0};(l=e.room)==null||l.streamQueue.removeUser(S)}else I("bloud user unpublish share stream but can not get streamModel","",i)}else{let u=e.streamModels.get(i);if(u){u.updateBloudStream(void 0,e);let m=u.stream;m&&((o=e.room.audioPlayer)==null||o.removeStream(m),e.remoteStreamUnpublished(m),m.destroy());let h={id:i,isWeb:u.isWeb,isScreen:!1};(a=e.room)==null||a.streamQueue.removeUser(h)}else I("bloud user unpublish stream but can not get streamModel","",i)}}function pt(s,e){setTimeout(()=>c(this,null,function*(){d("handle republish share stream");try{let t=s.boomCore.shareScreenStream;if(t){let i=t.getAudioOn(),r=t.getVideoOn();if(yield s.boomCore.shareBrtcClient.publish(t),yield s.boomCore.createAndPubBloudShareStream(i,r),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(kr())}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(Lr()),yield e.toggleShareScreen(!1,void 0)}}),1e3)}import{BloudEvents as X,BrtcEvents as Ci}from"@hysc/utils";function vi(s,e,t){let i=s.permission,r=s.total;i&&t.updateLocalUserPermission(i),e.isInWaitRoom=s.joinwait;let o=s.waitroom;e.roomInfo.isOpenWaitRoom.next(o),e.roomInfo.totalUserWatcher.next(r);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 ft(s,e,t,i,r=!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,Ai(s,e),vi(s,e,t),r&&i[X.ROOM_CONNECTED].next(s)})}function gt(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(i=>{d("only-brtc-pub ","publish",s.localUser.userId,[i.message])})}})}function Bi(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 Ai(s,e){e.roomInfo.msgSeq=s.msgSeq,s.customStats&&e.roomInfo.initCustomStats(s.customStats)}function Mi(s,e,t,i,r){var l;s.updateUser(e,t);let o=t.stream,a=i.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,i),r.streamQueue.removeUser({id:e.userId,isScreen:!1}),r.streamQueue.removeUser({id:e.userId,isScreen:!0}));let u=i.shareStreamModels.get(e.userId);if(u&&!u.isLocal){try{(l=u.stream)==null||l.destroy()}catch(m){}i.removeShareStreamModel(u)}}o.get(`${e.userId}_screen`)&&r.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},i))}function Ei(s,e,t,i){s.isSingleColumns?e.commonUserList.forEach(r=>{let o=t.get(r.userId);if(o){t.delete(r.userId),Mi(e,r,o,i,s);return}e.commonUserList.delete(r.userId),i.streamModels.delete(r.userId),i.shareStreamModels.delete(r.userId)}):e.userList.forEach(r=>{let o=t.get(r.userId);if(o){Mi(e,r,o,i,s),r.isCommonUser?e.userList.delete(r.userId):t.delete(r.userId);return}e.userList.delete(r.userId),i.streamModels.delete(r.userId),i.shareStreamModels.delete(r.userId)}),s.userVM.addBcUsersMap(t)}function Dr(s,e,t,i){return c(this,null,function*(){let r=e.getLocalParticipant().userId,{users:o}=yield e.boomCore.queryUsers([r]),a=o.get(r);a&&t.updateUser(t.localUser,a);let n=e.getLocalParticipant().isCommonUser;if(e.isBig&&n){let{users:l}=yield e.boomCore.getUsersList(0,ht,500);Ei(e,t,l,i)}else{let u=(yield e.userVM.getTotalUserNumber())/Be,m=new Map;for(let h=0;h<u;h++){let{users:g}=yield e.boomCore.getUsers(h-1,"",Be);g.forEach(S=>{m.set(S.userId,S)})}Ei(e,t,m,i)}Ai(s,e),e.userVM.updateAllSort(),e.bmStreamVm.updateModelSort()})}function Ui(s,e,t){d("brtc room reconnecting"),e.networkState.brtc=!1,e.streamWSReconnectWatcher.next(!1),t[Ci.BRTC_ROOM_ROCONNECTING].next(s)}function Ri(s,e,t){d("brtc room reconnected"),e.networkState.brtc=!0,ce(e),t[Ci.BRTC_ROOM_RECONNECTED].next(s)}function Ni(s,e,t){d("bloud room reconnecting"),e.networkState.bloud=!1,e.bloudWSReconnectWatcher.next(!1),t[X.RECONNECTING].next(s)}function St(s,e,t){return c(this,null,function*(){e.hasSyncPermission?(d("bloud room reconnected"),e.bloudWSReconnectWatcher.next(!1),t[X.MOVE_USER_ROOM].next(null),yield e.syncRoom().then(()=>{e.hasSyncPermission=!0,t[X.ROOM_CONNECTED].next(s)}).catch(i=>{if(p("sync room error",JSON.stringify(i)),i.code===43){e.hasSyncPermission=!1,t[X.USER_REJOINED].next(i);return}else e.hasSyncPermission=!1,t[X.TIMEOUT].next(i)})):t[X.TIMEOUT].next(s)})}function Pi(s,e,t,i,r){return c(this,null,function*(){d("bloud sync room completed"),vi(s,t,e),yield Dr(s,t,e,i),gi(i),t.networkState.bloud=!0,ce(t),t.bloudWSReconnectWatcher.next(!0),r[X.ROOM_SYNCED].next(s)})}import{BloudEvents as Hr}from"@hysc/utils";var{USER_REJOINED:Wr,PARTICIPANT_JOINED:Gr,CHANGE_MASTER:wi,EVICTED:Fr,UPDATE_USER:jr,PARTICIPANT_LEFT:Ot,CUSTOM_MESSAGE:$r,MOVE_USER_ROOM:Ti}=Hr;function xi(s,e,t,i,r,o){var g,S,b,E,C,y,L,G,F,j,$,J,te,ie,xe,Le,ke,re,se,V,me,Oe;let a=(S=(g=s==null?void 0:s.participant)==null?void 0:g.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!=!!((E=(b=s.user)==null?void 0:b.customInfo)!=null&&E.inBackground)&&(A.inBackground=!!((y=(C=s.user)==null?void 0:C.customInfo)!=null&&y.inBackground),A.watcher.next({operation:"inBackground",user:A})),A.isCalling!=!!((G=(L=s.user)==null?void 0:L.customInfo)!=null&&G.isCalling)&&(A.isCalling=!!((j=(F=s.user)==null?void 0:F.customInfo)!=null&&j.isCalling),A.watcher.next({operation:"isCalling",user:A}));return}}if(($=e.room)!=null&&$.isBig&&n===1&&((J=t.room)==null?void 0:J.conferenceMode)===1)if(Ge(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 Q=e.commonUserList.get(s.user.userId);(te=e.room)!=null&&te.isSingleColumns||Q&&(e.commonUserList.delete(s.user.userId),t.streamModels.delete(s.user.userId),m=!0)}let h=e.addBCUser(s.user);if(h){h.inBackground!=!!((xe=(ie=s.user)==null?void 0:ie.customInfo)!=null&&xe.inBackground)&&(h.inBackground=!!((ke=(Le=s.user)==null?void 0:Le.customInfo)!=null&&ke.inBackground),h.watcher.next({operation:"inBackground",user:h})),h.isCalling!=!!((se=(re=s.user)==null?void 0:re.customInfo)!=null&&se.isCalling)&&(h.isCalling=!!((me=(V=s.user)==null?void 0:V.customInfo)!=null&&me.isCalling),h.watcher.next({operation:"inBackground",user:h}));let A=!1;if(Ae.forEach(Q=>{h!=null&&h.userId.includes(Q)&&(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 Q=new x({isMeetingNotice:!0,userId:h.userId,message:h.nickName+`\u52A0\u5165${i.roomType==2?"\u76F4\u64AD":"\u4F1A\u8BAE"}`});r.addMessage(Q,!0)}o[Gr].next({user:h,mode:n,data:s})}}}function Li(s,e,t,i,r,o,a){var l;let n=s.userIds;d("bloud leave users","","",["userIds =>",n]),n.length&&(n.forEach(u=>{let m=_t(u,e,t,r);m&&Oi(m,o,a,i,!0,0)}),(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():e.updateAllSort(),r.updateModelSort())}function ki(s,e,t,i,r,o,a){var m;d(`bloud participant left ===>${s.userId}, ${s.mode}`);let n=s.mode===1,l=s.userId,u=t.isBig&&r.streamModels.size>1e3;if(l){let h=_t(l,e,t,r);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(),r.updateModelSort(),n){i[Ot].next({user:h,mode:s.mode,data:s});return}h&&Oi(h,o,a,i,s.mode!==1,s.mode)}else I("participant-left\u89E6\u53D1=======>\u4F46\u662F\u8BE5\u7528\u6237\u4FE1\u606F\u4E0D\u5B58\u5728",P,null,[s.userId]),i[Ot].next({user:s.userId,mode:s.mode,data:s})}function Oi(s,e,t,i,r,o){let a=!1;if(Ae.forEach(n=>{s!=null&&s.userId.includes(n)&&(a=!0)}),!a){if(r){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)}i[Ot].next({user:s,mode:o})}}function _t(s,e,t,i){let r=e.getUser(s);return e.removeUser(s),t.streamQueue.removeUser({id:s,isScreen:!1}),t.streamQueue.removeUser({id:s,isScreen:!0}),i.removeStreamModelByUId(s),i.removeShareStreamModelByUId(s),t.roomInfo.removeRaiseHandUser(s),t.roomInfo.removeVideoRaiseHandUser(s),t.roomInfo.removeSimpleRaiseHandUser(s),i.shareBloudStateMap.delete(s),r}function _i(s,e,t,i,r){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",P,null,o),i[wi].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=r.getStreamModelByUId(a),m=r.getStreamModelByUId(o);u==null||u.updateSortNum(),m==null||m.updateSortNum(),i[wi].next({master:l.master,oldMaster:l.oldMaster,data:s})}}function Di(s,e,t,i,r){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=_t(o,e,i,t);(l=e.room)!=null&&l.isSingleColumns?e.updateCommonUserSort():n?n.isCommonUser?e.updateCommonUserSort():n.isAudience?e.updateAudienceUserSort():e.updateUserSort():e.updateAllSort(),t.updateModelSort(),r[Fr].next(s)}function Vi(s,e,t,i,r){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=i.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),r[jr].next({bmUser:n,params:s.participant.params})}}var Dt=Vr((s,e)=>{s[Wr].next(e)},1e3);function Hi(s,e,t,i){return c(this,null,function*(){d("bloud move user room","","",[t]);let r=t.toWait;if(s.isInWaitRoom=r,r){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),i[$r].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([]),i[Ti].next(r),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 ft(t.info,s,e,i,!0),yield gt(s),i[Ti].next(r)}})}import{BloudEvents as Vt}from"@hysc/utils";function Gi(s,e,t,i){var o,a,n,l,u,m,h,g,S;let r=N({},s);if(r.message){if(r.message=typeof r.message=="string"?JSON.parse(r.message):r.message,d("new-message","","",[" method => ",r.message.method]),r.message.method==="send-talk"){let b=r.user===((o=e.getLocalUser())==null?void 0:o.userId),E=((n=(a=r.message)==null?void 0:a.params)==null?void 0:n.status)||"",C=(m=(u=(l=r.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.avatar,y=s.seq,L=new x({userId:r.user,message:E,isLocal:b,avatar:C,to:r.to,seq:y,nickName:(S=(g=(h=r.message)==null?void 0:h.params)==null?void 0:g.stream)==null?void 0:S.nickname,sendTime:new Date().getTime()});t.addMessage(L,!1)}i[Vt.SEND_MESSAGE].next(r)}}function Fi(s,e,t){var r,o,a,n,l,u,m,h,g,S,b,E,C;let i=N({},s);if(i.message)if(i.message=typeof i.message=="string"?JSON.parse(i.message):i.message,d("custom-message","","",[" method => ",i.message.method]),i.message.method=="video-force-change"){let y=i.message.params.status=="enabled";d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u6444\u50CF\u5934: ${y}`),e.messageWatcher.next({type:"video-force-change",status:y,fromUserId:i.user})}else if(i.message.method=="audio-force-change"){let y;i.message.params.status=="checkUserAudio"?y=i.message.params.status:y=i.message.params.status=="enabled",d(`\u8FDC\u7AEF\u63A7\u5236\u672C\u5730\u9EA6\u514B\u98CE: ${y}`),e.messageWatcher.next({type:"audio-force-change",status:y,fromUserId:i.user,isNotCancelRootReport:(r=i.message.params)==null?void 0:r.isNotCancelRootReport})}else if(i.message.method==="raise-hands"){let y=i.message.params;Jr(y,e),e.raiseHandleRespWatcher.next(y)}else if(i.message.method==="give-like")(h=e.roomVM)==null||h.giveLikeList.push({userId:i.user,nickName:(n=(a=(o=i.message)==null?void 0:o.params)==null?void 0:a.stream)==null?void 0:n.nickname,time:new Date().getTime(),type:(m=(u=(l=i.message)==null?void 0:l.params)==null?void 0:u.stream)==null?void 0:m.type}),(S=e.roomVM)==null||S.giveLikeListWatcher.next((g=e.roomVM)==null?void 0:g.giveLikeList);else if(i.message.method==="resp-to-check-devices")(b=i.message)!=null&&b.params&&(i.message.params.fromUserId=i.user),t[Vt.CUSTOM_MESSAGE].next(i);else if(i.message.method==="usercount"){if(i.message.params){let y=(C=(E=i.message)==null?void 0:E.params)==null?void 0:C.total;y?(y=Number(y),y<0&&(I("\u670D\u52A1\u8FD4\u56DE\u7684usercount\u4E3A\u8D1F\u6570,"+y),y=0)):(I("\u670D\u52A1\u672A\u8FD4\u56DEusercount,"+y),y=0),e.roomInfo.totalUserWatcher.next(y)}}else if(i.message.method==="waitusercount"){if(i.message.params){let y=i.message.params.total;e.roomInfo.totalWaitRoomUserWatcher.next(y)}}else t[Vt.CUSTOM_MESSAGE].next(i)}function Jr(s,e){return c(this,null,function*(){let t=s.raiseInfo;if(s.raiseHandsType===4&&t){let i=e.userVM.getUser(t.userId);if(i||(d("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728,\u5F00\u59CB\u67E5\u8BE2",t.userId),yield e.queryBloudUsers([t.userId],!1,!1),i=e.userVM.audiencesList.get(t.userId)),!i){p("handleRaiseHands:\u7528\u6237\u4E0D\u5B58\u5728",t.userId);return}switch(t.type){case"raiseHandsAudio":i.raiseAudioHands=s.raiseHands;break;case"raiseHandsVideo":i.raiseVideoHands=s.raiseHands;break;case"raiseHand":i.raiseHand=s.raiseHands;break;default:break}M.emitter.emit(O,{status:t.type,user:i})}})}import{BloudEvents as Qr,BrtcEvents as Ht}from"@hysc/utils";var bt=0;var It=0,$e=new Set;function Wt(s,e,t,i,r){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 ji(t,e,r,s).catch(a=>{d("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25, \u5904\u7406\u4E00\u4E0B\u9000\u4F1A\u903B\u8F91","","",[JSON.stringify(a)]),r[Ht.ERROR].next(s)})}),1e3)}else r[Ht.ERROR].next(s)})}function ji(s,e,t,i){return c(this,null,function*(){return new Promise((r,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),ce(e),e.BRTCConnectFailed=!1,bt=0,yield e.handleRePushSelf(),e.streamWSReconnectWatcher.next(!0),r(!0)})).catch(a=>{let n=a.getCode();d("\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[a,n]),bt<=10?(bt+=1,s.brtcClient.isJoinning=!1,setTimeout(()=>{ji(s,e,t,i)},2*1e3)):(p("brtc\u65AD\u7F51\u91CD\u8FDE\u5931\u8D25\uFF0C\u5904\u7406\u4E00\u4E0B\u9000\u4F1A"),bt=0,t[Ht.ERROR].next(i),o(!1))})},7*1e3)})})}function Gt(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(()=>{It=0,e(!0)}).catch(i=>{let r=i.getCode();if(d("\u5171\u4EAB\u5C4F\u5E55\u65AD\u7F51\u91CD\u8FDE\u5165\u4F1A\u5931\u8D25","","",[i,r]),It<=3)It+=1,Gt(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"),It=0,new Error("\u5171\u4EAB\u5C4F\u5E55\u91CD\u8FDE\u5931\u8D25")})},7*1e3)})})}function $i(s,e,t,i,r){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 St(i,s,r):r[Qr.TIMEOUT].next(i)})}import{BloudEvents as qr}from"@hysc/utils";function Ji(s,e,t){let i=s==null?void 0:s.updateKeys;d("update-custom-stats"," "," ",["updateKeys => ",JSON.stringify(i)]),(i!=null&&i.includes("chatNotice")||i!=null&&i.includes("chatNoticeRich")||i!=null&&i.includes("fileUpdateLook")||i!=null&&i.includes("fileUpdateDown")||i!=null&&i.includes("fileUpdateEdit")||i!=null&&i.includes("fileUpdateModel")||i!=null&&i.includes("screenShareModel")||i!=null&&i.includes("onlyOnePersonShare")||i!=null&&i.includes("chatEnable")||i!=null&&i.includes("giveLikeEnable")||i!=null&&i.includes("cloudRecord")||i!=null&&i.includes("joinAudioEnable")||i!=null&&i.includes("joinVideoEnable")||i!=null&&i.includes("userListEnable")||i!=null&&i.includes("audioEnable")||i!=null&&i.includes("videoEnable")||i!=null&&i.includes("modifyNameEnable")||i!=null&&i.includes("backgroundAIEnable")||i!=null&&i.includes("recordEnable")||i!=null&&i.includes("joinMicrophoneDisable")||i!=null&&i.includes("joinCameraDisable")||i!=null&&i.includes("raiseHandEnable")||i!=null&&i.includes("forceOpenUserMic")||i!=null&&i.includes("forceOpenUserCamera")||i!=null&&i.includes("joinCueVoice"))&&e.roomInfo.updateOperationPermission(s.customStats),(i!=null&&i.includes("chatNotice")||i!=null&&i.includes("chatNoticeRich"))&&e.roomInfo.chatNoticeWatcher.next(s),t[qr.UPDATE_CUSTOM_STATS].next(s)}import zr from"@hysc/p-queue";var yt=class{constructor(e,t=!0){this.queue=new zr({concurrency:e,autoStart:t,carryoverConcurrencyCount:!0,timeout:3*1e3,completeAction:i=>{console.log("task complete",i)}}),this.queueArray=[],this.isTaskPending=t}addQueue(e,t,i=0,r=""){this.queue.isPaused&&this.queue.start();let o={};o.taskID=t,o.status="pending",this.queue.add(e,{priority:i,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()}},_=new yt(4),v=new yt(10);import{BMShareStreamReconnectFailed as Yr}from"@hysc/utils";import{BloudEvents as f,BrtcEvents as R,CustomEvents as Ue}from"@hysc/utils";function Qi(s,e,t,i,r){d("attachEvents init");let o={};s.on("toggle-screen-share",()=>{p("share stream video track ended, now unpublish share stream"),t.localShareError.next(Yr()),t.localShareEndedError.next(!0)}),s.on("client-banned",()=>c(this,null,function*(){yield r.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"),Gt(s).then(()=>c(this,null,function*(){if(d("brtc share client reconnected, retry repub share stream"),yield W(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(f)),a=a.concat(Object.values(R)),a=a.concat(Object.values(Ue)),a.forEach(n=>{o[n]=new Xr(null)}),a.forEach(n=>{switch(n){case R.STREAM_PUBLISHED:s.on(R.STREAM_PUBLISHED,l=>{v.addQueue(Si.bind(null,l,t,r,o),R.STREAM_PUBLISHED)});break;case R.BRTC_SYNC_ROOM_COMPLETED:s.on(R.BRTC_SYNC_ROOM_COMPLETED,()=>c(this,null,function*(){v.addQueue(r.handleResetOtherStreamStatus.bind(r),R.BRTC_SYNC_ROOM_COMPLETED)}));break;case Ue.BRTC_SHARE_SYNC_ROOM_COMPLETED:s.on(Ue.BRTC_SHARE_SYNC_ROOM_COMPLETED,()=>{d("brtc share client sync completed, retry publish share stream"),v.addQueue(pt.bind(null,r,t),Ue.BRTC_SHARE_SYNC_ROOM_COMPLETED)});break;case R.BRTC_ROOM_ROCONNECTING:s.on(R.BRTC_ROOM_ROCONNECTING,l=>{v.addQueue(Ui.bind(null,l,r,o),R.BRTC_ROOM_ROCONNECTING)});break;case R.BRTC_ROOM_RECONNECTED:s.on(R.BRTC_ROOM_RECONNECTED,l=>c(this,null,function*(){v.addQueue(Ri.bind(null,l,r,o),R.BRTC_ROOM_RECONNECTED)}));break;case R.CLIENT_BANNED:s.on(R.CLIENT_BANNED,l=>{d("brtc client banned"),Dt(o,l)});break;case R.ERROR:s.on(R.ERROR,l=>c(this,null,function*(){r.netConnecting?v.addQueue(Wt.bind(null,l,r,s,t,o),R.ERROR):$e.add(Wt.bind(null,l,r,s,t,o))}));break;case f.SYNC_FAILED:s.on(f.SYNC_FAILED,l=>{p("bloud sync failed, leave room"),o[f.TIMEOUT].next(l)});break;case f.ROOM_CONNECTED:s.on(f.ROOM_CONNECTED,l=>c(this,null,function*(){return ft(l,r,e,o)}));break;case Ue.JOIN_READY:s.on(Ue.JOIN_READY,()=>gt(r));break;case f.PARTICIPANT_JOINED:s.on(f.PARTICIPANT_JOINED,l=>c(this,null,function*(){r.isInWaitRoom||v.addQueue(xi.bind(null,l,e,t,s,i,o),f.PARTICIPANT_JOINED)}));break;case f.PARTICIPANT_LEFT:s.on(f.PARTICIPANT_LEFT,l=>{r.isInWaitRoom||v.addQueue(ki.bind(null,l,e,r,o,t,s,i),f.PARTICIPANT_LEFT)});break;case f.LEAVE_USERS:s.on(f.LEAVE_USERS,l=>v.addQueue(Li.bind(null,l,e,r,o,t,s,i),f.LEAVE_USERS));break;case f.CHANGE_MASTER:s.on(f.CHANGE_MASTER,l=>{v.addQueue(_i.bind(null,l,e,r,o,t),f.CHANGE_MASTER)});break;case f.SEND_MESSAGE:s.on(f.SEND_MESSAGE,l=>{v.addQueue(Gi.bind(null,l,e,i,o),f.SEND_MESSAGE)});break;case f.CUSTOM_MESSAGE:s.on(f.CUSTOM_MESSAGE,l=>{v.addQueue(Fi.bind(null,l,r,o),f.CUSTOM_MESSAGE)});break;case f.EVICTED:s.on(f.EVICTED,l=>c(this,null,function*(){v.addQueue(Di.bind(null,l,e,t,r,o),f.EVICTED)}));break;case f.UPDATE_USER:s.on(f.UPDATE_USER,l=>{v.addQueue(Vi.bind(null,l,e,r,t,o),f.UPDATE_USER)});break;case f.UPDATE_STATS:s.on(f.UPDATE_STATS,l=>{v.addQueue(Bi.bind(null,l,r),f.UPDATE_STATS)});break;case f.UPDATE_CUSTOM_STATS:s.on(f.UPDATE_CUSTOM_STATS,l=>{v.addQueue(Ji.bind(null,l,r,o),f.UPDATE_CUSTOM_STATS)});break;case f.TIMEOUT:s.on(f.TIMEOUT,l=>{v.addQueue($i.bind(null,r,s,t,l,o),f.TIMEOUT)});break;case f.USER_REJOINED:s.on(f.USER_REJOINED,l=>{d("bloud user rejoined"),Dt(o,l)});break;case f.RECONNECTING:s.on(f.RECONNECTING,l=>{v.addQueue(Ni.bind(null,l,r,o),f.RECONNECTING)});break;case f.RECONNECTED:s.on(f.RECONNECTED,l=>c(this,null,function*(){v.addQueue(St.bind(null,l,r,o),f.RECONNECTED)}));break;case f.ROOM_SYNCED:s.on(f.ROOM_SYNCED,l=>c(this,null,function*(){v.addQueue(Pi.bind(null,l,e,r,t,o),f.ROOM_SYNCED)}));break;case f.STREAM_PUBLISHED:s.on(f.STREAM_PUBLISHED,l=>c(this,null,function*(){v.addQueue(bi.bind(null,l,t,o),f.STREAM_PUBLISHED)}));break;case f.STREAM_REMOVED:s.on(f.STREAM_REMOVED,l=>c(this,null,function*(){v.addQueue(Ii.bind(null,l,t,r,o),f.STREAM_REMOVED)}));break;case f.UPDATE_STREAM:s.on(f.UPDATE_STREAM,l=>c(this,null,function*(){v.addQueue(yi.bind(null,l,t,o),f.UPDATE_STREAM)}));break;case f.STREAM_UPDATE:s.on(f.STREAM_UPDATE,l=>c(this,null,function*(){v.addQueue(kt.bind(null,l,t),f.STREAM_UPDATE)}));break;case f.MOVE_USER_ROOM:s.on(f.MOVE_USER_ROOM,l=>c(this,null,function*(){v.addQueue(Hi.bind(null,r,e,l,o),f.MOVE_USER_ROOM)}));break;default:s.on(n,l=>o[n].next(l));break}}),o}import{BmChangeAudioProfileError as Ft,BmChangeMasterError as jt,BmChangeVideoProfileError as $t,BmCheckDeviceError as Jt,BmEvictUserError as Mt,BmSetRemoteAudioEnable as Je,BmSetRemoteVideoEnable as Zr,BmUpdateManagerError as qi,BmUpdateUserError as Qt,updateCustomStatsError as Kr}from"@hysc/utils";import{Subject as es}from"rxjs";var Qe=class{constructor(e,t,i){this.room=null;this.tipQueueObj={};this.roomInfo=i,this.userVM=t,this.boomCore=e,this.giveLikeList=[],this.giveLikeListWatcher=new es}initWithRoom(e){this.room=e}evictUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(Mt("\u672A\u4F20\u9012\u7528\u6237id"));if(!this.userVM.checkLocalHasMaster())return Promise.reject(Mt("\u53EA\u6709\u4E3B\u6301\u4EBA\u6743\u9650\u624D\u80FD\u8E22\u51FA\u7528\u6237"));if(this.userVM.checkIsMaster(e))return Promise.reject(Mt("\u4E3B\u6301\u4EBA\u4E0D\u80FD\u88AB\u8E22\u51FA"));try{yield this.boomCore.evictUser(e,t)}catch(i){return Promise.reject(Mt(`\u8E22\u51FA\u7528\u6237\u5931\u8D25${JSON.stringify(i)}`))}})}updateUser(e,t){return c(this,null,function*(){if(!e)return Promise.reject(Qt("\u672A\u4F20\u9012\u76EE\u6807\u7528\u6237id"));if(!t)return Promise.reject(Qt("info\u4E3A\u7A7A,\u8BF7\u5199\u5165\u8981\u66F4\u65B0\u7684\u4FE1\u606F"));yield this.boomCore.updateUser(e,{customInfo:t}).catch(i=>Promise.reject(Qt(`boomCore updateUser\u51FA\u9519 ${JSON.stringify(i)}`)))})}changeMaster(e,t){return c(this,null,function*(){var i;if(!e)return Promise.reject(jt("\u672A\u4F20\u9012\u4E3B\u6301\u4EBAid"));if(this.userVM.checkLocalHasMaster()||(i=this.userVM.getUser(e))!=null&&i.isCreate)try{yield this.boomCore.changeMaster(e,t)}catch(r){return Promise.reject(jt(`boomCore changeMaster error ${r}`))}else return console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA",P,e),Promise.reject(jt("\u60A8\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))})}updateManager(e,t,i=!0){return c(this,null,function*(){return e?this.userVM.checkLocalHasMaster()?this.userVM.updateManager(e,t,i):(console.error("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u8054\u5E2D\u4E3B\u6301\u4EBA",P,e),Promise.reject(qi("\u8BE5\u7528\u6237\u6CA1\u6709\u7BA1\u7406\u5458\u6743\u9650, \u65E0\u6CD5\u6539\u53D8\u4E3B\u6301\u4EBA"))):Promise.reject(qi("\u672A\u4F20\u9012\u8054\u5E2D\u4E3B\u6301\u4EBAid"))})}changeNickName(e,t){return c(this,null,function*(){let i={nickname:t};yield this.updateUser(e,i)})}sendMessageWithMaster(e,t){return c(this,null,function*(){if(!this.userVM.checkLocalHasMaster())return Promise.reject(Je("\u60A8\u4E0D\u662F\u4E3B\u6301\u4EBA\uFF0C\u6CA1\u6709\u8BE5\u6743\u9650"));if(t&&!this.userVM.getUser(t))return Promise.reject(Je(`uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(e),t)}catch(i){return Promise.reject(i)}})}setRemoteAudioEnable(e,t,i){return c(this,null,function*(){let r=e?"enabled":"disabled";r=="enabled"&&i&&(r="checkUserAudio");let o={domain:"room-control",method:"audio-force-change",params:{status:r,isNotCancelRootReport:i,fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(o,t).catch(a=>Promise.reject(Je(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${a}`)))})}setRemoteVideoEnable(e,t){return c(this,null,function*(){let i={domain:"room-control",method:"video-force-change",params:{status:e?"enabled":"disabled",fromUserId:this.boomCore.getLocalParticipant().getID()}};this.sendMessageWithMaster(i,t).catch(r=>Promise.reject(Zr(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${r}`)))})}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(i=>Promise.reject(Je(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${i}`)))})}tipUser(e,t,i,r){return c(this,null,function*(){let o={domain:"room-control",method:"tip-user",params:{fromUserId:this.boomCore.getLocalParticipant().getID(),message:t,richMsg:i}};r?this.tipQueueObj[e]=setTimeout(()=>{this.sendMessageWithMaster(o,e)},(r.minutes||0)*60*1e3+(r.seconds||0)*1e3):this.sendMessageWithMaster(o,e).catch(a=>Promise.reject(Je(`boomCore.sendMessage\u53D1\u751F\u9519\u8BEF ${JSON.stringify(a)}`)))})}raiseHands(e,t){return c(this,null,function*(){var o,a;let i=(o=this.room)==null?void 0:o.getLocalParticipant().getID(),r={};e==="raiseHand"?(r.raiseHand=t,r.raiseHandTime=Math.floor(new Date().getTime()/1e3)):r[e==="audio"?"raiseHandsAudio":"raiseHandsVideo"]=t,yield this.updateUser(i,r),(a=this.room)!=null&&a.isBig&&(yield this.raiseHandsByCustomMessage(e,t,i))})}raiseHandsByCustomMessage(e,t,i){return c(this,null,function*(){var a;let r="raiseHand";e!="raiseHand"&&(r=e==="audio"?"raiseHandsAudio":"raiseHandsVideo");let o={domain:"user-control",method:"raise-hands",params:{raiseHandsType:4,raiseHands:t,raiseInfo:{userId:i,raiseHandTime:Math.floor(new Date().getTime()/1e3),type:r}}};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,i){return c(this,null,function*(){var o,a,n;let r={domain:"user-control",method:"raise-hands",params:{raiseHandsType:e,raiseHands:t}};try{if(i)yield this.boomCore.customMessage(JSON.stringify(r),i);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(r),h.userId)}),u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===1&&(l==null||l.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===2&&(u==null||u.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)})),e===3&&(m==null||m.forEach(h=>{this.boomCore.customMessage(JSON.stringify(r),h.userId)}))}}catch(l){return Promise.reject(new U(1e3,"boomCore.sendMessage\u53D1\u751F\u9519\u8BEF"))}})}updateCustomStats(e,t=!1){return c(this,null,function*(){yield this.boomCore.updateCustomStats(e,t).catch(i=>Promise.reject(Kr(`${JSON.stringify(e)} - ${JSON.stringify(i)}`)))})}sendChatNotice(e,t,i){return c(this,null,function*(){yield this.updateCustomStats({chatNotice:e,chatNoticeRich:t,showTipNotice:i}).catch(r=>r)})}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(),i={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}}},r=this.userVM.getLocalUser();try{yield this.boomCore.customMessage(JSON.stringify(i),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,P,r==null?void 0:r.userId),new U(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",P);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(i=>Promise.reject(Jt(`\u68C0\u6D4B\u5BF9\u65B9\u8BBE\u5907send-message\u53D1\u751F\u9519\u8BEF: ${i}`)))})}resp2CheckDevices(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-check-devices",params:_e(N({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};if(!t)return Promise.reject(Jt(`\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4B: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(r){return Promise.reject(Jt(`\u54CD\u5E94\u54CD\u5E94\u8BBE\u5907\u68C0\u6D4Bsend-message\u53D1\u751F\u9519\u8BEF ${r}`))}})}changeRemoteVideoProfile(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"change-video-profile",params:_e(N({},e),{fromUserId:this.boomCore.getLocalParticipant().getID()})};this.sendMessageWithMaster(i,t).catch(r=>Promise.reject($t(`\u8C03\u8282\u5BF9\u65B9\u7684\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF: ${r}`)))})}resp2ChangeRemoteVideoProfile(e,t,i){return c(this,null,function*(){let r={domain:"user-control",method:"resp-to-change-video-profile",params:{status:e,profile:i,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject($t(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(r),t)}catch(o){return Promise.reject($t(`\u54CD\u5E94\u8C03\u8282\u89C6\u9891\u5206\u8FA8\u7387send-message\u53D1\u751F\u9519\u8BEF ${o}`))}})}changeRemoteAudioProfile(e,t){return c(this,null,function*(){let i={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(i,t).catch(r=>Promise.reject(Ft(`\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${JSON.stringify(r)}`)))})}resp2ChangeRemoteAudioProfile(e,t){return c(this,null,function*(){let i={domain:"user-control",method:"resp-to-change-audio-profile",params:{status:e,fromUserId:this.boomCore.getLocalParticipant().getID()}};if(!t)return Promise.reject(Ft(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891: uid: ${t} \u672A\u627E\u5230\u7528\u6237`));try{yield this.boomCore.customMessage(JSON.stringify(i),t)}catch(r){return Promise.reject(Ft(`\u54CD\u5E94\u8C03\u8282\u97F3\u9891send-message\u53D1\u751F\u9519\u8BEF ${r}`))}})}};import{BehaviorSubject as ts,Subject as is}from"rxjs";import{throttle as rs}from"lodash-es";var qe=class{constructor(e,t,i){this.messageList=[];this.hasDangerMessageWatcher=new is;this.notificationMessageList=rs(()=>{this.messageListWatcher.next(this.messageList)},200);this.boomCore=e,this.userVM=t,this.bmRoom=i,this.messageListWatcher=new ts(this.messageList)}sendMessage(e,t,i){return c(this,null,function*(){let r=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:r}},n=this.userVM.getLocalUser();try{let l=!1,u,m=i;m||(yield this.boomCore.sendMessage(JSON.stringify(a),t).then(g=>{u=g.seq}).catch(g=>{I("sendmessage \u51FA\u9519","",n==null?void 0:n.userId,[g]),g&&g.code===39&&(l=!0,this.hasDangerMessageWatcher.next(!0))}));let h=new x({userId:n==null?void 0:n.userId,message:r,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,P,n==null?void 0:n.userId),new U(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>=mi){let i=new x({isMeetingNotice:!0,message:""});this.messageList.push(i)}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(i=>{if(i.private||i.to||i.msg.length==0||i.msg.indexOf("{")==-1)return!1;let r=JSON.parse(i.msg);if(r.method!="send-talk")return!1;let o=i.seq,a=r.params,n=a.stream.user?a.stream.user:i.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 tr,Subject as Y}from"rxjs";import{Player as os}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 ze}from"lodash-es";function zi(s,e){return 16|~~s<<1|~~e}function Xi(s,e){return 12|~~s<<1|~~e}function Yi(s,e){return 8|~~s<<1|~~e}function Zi(s,e){return 4|~~s<<1|~~e}function Ki(s,e){return 20|~~s<<1|~~e}function er(){return Date.now()}function Et(){let s=er();return function(){return er()-s}}import{detect as as}from"detect-browser";var Ne=as(),ns=(Ne==null?void 0:Ne.name)==="safari"||(Ne==null?void 0:Ne.name)==="ios";var ue=`.streammodel${Math.random()}`,Pe=class{constructor(e,t,i,r=!1){this.streamType=3;this.pullFailedNum=0;this._video_enable=!1;this._audio_enable=!1;this.videoEnableWatcher=new tr(this._video_enable);this.audioEnableWatcher=new tr(this._audio_enable);this.streamUpdateWatcher=new Y;this.isSubScribedWatcher=new Y;this.playStateChangeWatcher=new Y;this.noContainerWatcher=new Y;this.noBigContainerWatcher=new Y;this.audioLevelWatcher=new Y;this.isCurrentDisplay=!1;this.isDisplay=!1;this.isDisplayObserve=new Y;this.isInBig=!1;this.isInBigObserve=new Y;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,i;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()),(i=this.stream)==null||i.resume())};this.handleStreamConnectError=()=>{d("\u6D41\u51FA\u73B0\u7684connect-error userId","",this.userId,["streamId ==>",this.streamId,"nickname =>",this.nickname,"isLocal => ",this.isLocal]),this.isLocal?M.emitter.emit(oe,{stream:this,isLocal:!0}):M.emitter.emit(oe,{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=ze(()=>{M.emitter.emit(he,{stream:this})},100);this.emitBindElement=ze(()=>{M.emitter.emit(fe,{stream:this})},50);this.emitBindBigElement=ze(()=>{M.emitter.emit(Ie,{stream:this})},50);this.currentIsPlaying=(e,t=!0)=>{var l;let i=document.getElementById(e);if(!i)return 0;let r,o,a=0,n=Array.from(i.children);return r=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)),r&&o>a?2:1};this.play=(e=!1)=>c(this,null,function*(){var i,r;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=Et();if(this.isDisplay&&this.videoEnable){if(e){this.stop(),yield t.play(this.playerId,{backgroundColor:"#202020",fit:"contain",audio:!Xe}),(i=M.emitter)==null||i.emit(H,{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||M.emitter.emit(ae,{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:!Xe}),(r=M.emitter)==null||r.emit(H,{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 i,r,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=Et();if(e){this.initBigPlayer(),yield(i=this.player)==null?void 0:i.play(t),(r=M.emitter)==null||r.emit(H,{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||M.emitter.emit(ae,{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=M.emitter)==null||o.emit(H,{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"+ue,this.handleAudioLevel),this.stream.on("audio-level"+ue,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 W(1e3),this.stop(),yield this.play())}});this.checkBigVideo=ze(()=>{var e;if(this.videoEnable&&this.stream){let t=`video_${this.stream.getStreamId()}_big`;if(!this.isShare&&this.isDisplay&&this.playerId){let i=!!document.getElementById(t);if(this.isInBig)if(i){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=ze(()=>{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.room=t,this.updateUser(e),this._stream=i,this.isDisplayObserve.subscribe(o=>{this.handleDisplayChange(o)}),this.isInBigObserve.subscribe(o=>{this.handleIsInBig(o)}),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,"isShare =>",this.isShare]),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,i){this._stream&&this._stream.off(ue),this._stream=e,e?(this.audioEnable&&(this.isShare||i.addToDetector(new Re(this.user,e)),this.collectAudioLevel()),e.on("player-state-changed"+ue,this.onPlayerStateChange),e.on("connect-error"+ue,this.handleStreamConnectError),e.on("stream-connection-error"+ue,this.handleStreamConnectError),!this.isLocal&&t&&this.sendMessage2Room()):(this.hasPulled=!1,this.pulledStreamType="small",this.streamType=3)}updateBloudStream(e,t,i=!1){var a,n,l,u,m;let r=!1,o=!1;if(e){if(this.bloudStream={audio:e.audio,video:e.video,isScreen:e.isScreen},e.customInfo){if(!this.bloudStream.customInfo||((a=this.bloudStream.customInfo)==null?void 0:a.volume)!==e.customInfo.volume){let h=e.customInfo.volume;typeof h=="number"&&this.setRemoteAudioLevel(h)}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&&(r=!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()),i&&(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||i?M.emitter.emit(Me,{id:this.userId,isWeb:this.isWeb,isScreen:this.isShare}):(this.isLocal||(!this.hasPulled||!this.stream.isSubscribed())&&this.sendMessage2Room(),r&&(this.isDisplay&&this.playerId&&this.emitBindElement(),this.isInBig&&this.bigPlayerId&&this.emitBindBigElement()),!this.isLocal&&o&&this.audioEnable&&this.stream.isSubscribed()&&M.getInstance().emit(Ce,{stream:this})))}else 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,i,r,o;this.bloudStream?(e&&(((i=(t=this.bloudStream)==null?void 0:t.customInfo)==null?void 0:i.volume)!==e.volume?typeof e.volume=="number"&&this.setRemoteAudioLevel(e.volume):((o=(r=this.bloudStream)==null?void 0:r.customInfo)==null?void 0:o.share_file)!==e.share_file&&e.share_file&&this.setShareFile(e.share_file)),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,i;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":!!((i=this.bloudStream)!=null&&i.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");M.emitter.emit(Ee,{streamId:this.streamId,volume:e})}setShareFile(e){M.emitter.emit(nt,{streamId:this.bStreamId,fileId: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 os(e,{fit:"contain"}),this.player.on("player-state-changed",t=>{var i;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"&&((i=this.player)==null||i.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&&(M.emitter.emit(ye,null),this.user.updateSortNum(!0)))}getSortNum(){var e;return this.user.isMaster?zi(this.audioEnable,this.videoEnable):this.user.isLocal?Xi(this.audioEnable,this.videoEnable):this.user.isManager?Yi(this.audioEnable,this.videoEnable):this.user.isCommonUser&&((e=this.room)==null?void 0:e.template_name)==="mention"&&(this.room.userVM.localUser.isMaster||this.room.userVM.localUser.isManager)?Ki(this.audioEnable,this.videoEnable):Zi(this.audioEnable,this.videoEnable)}checkVideoDecodeFrame(e){if(this.isLocal||ns)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 r,o,a;let i=(t==null?void 0:t.getVideoPlaybackQuality)&&((r=t==null?void 0:t.getVideoPlaybackQuality())==null?void 0:r.totalVideoFrames)||0;if(t&&!t.getVideoPlaybackQuality){this.checkVideoTimer&&clearTimeout(this.checkVideoTimer);return}if(i>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(ue),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,M.emitter.emit(ge,{stream:this})}unSubscribeStream(){this.shouldPull=!1,M.emitter.emit(Se,{stream:this})}unAttach(e){var t,i;e==="all"?(this.stop(),(t=this.player)==null||t.destroy(),this.bigPlayerId=""):e==="big"?((i=this.player)==null||i.destroy(),this.bigPlayerId=""):e==="small"&&this.stop()}};import{BehaviorSubject as de,Subject as Z}from"rxjs";import{BoomError as sr}from"@hysc/utils";import{debounce as ds}from"lodash-es";import{BMCameraNotAuthError as ms,BMMicNotAuthError as hs,BMOpenCameraError as or,BMOpenMicroError as Yt,BmSetLocalAudioEnable as ps,BmSetLocalSpeakerEnable as fs,BmSetLocalVideoEnable as gs,BMStreamDisconnectedError as ar,BmSyncStreamFailError as Zt,getStreamError as Ss}from"@hysc/utils";function ir(s){let e=null,t=s.videoElement,i=t.offsetWidth,r=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:i,height:r}}return null}function rr(s,e){try{let t=s.getVideoTracks()[0],i=s.getAudioTracks()[0];return{video:!!t,audio:!!i,videoSource:t,audioSource:i,width:e.width,height:e.height}}catch(t){return console.log("\u83B7\u53D6\u5171\u4EAB\u97F3\u9891\u53C2\u6570\u6709\u8BEF",t),null}}import{Logger as ls}from"@hysc/utils";var cs="NoiseSuppressorWorklet",Ct=null,zt=null;function Xt(s){return Ct||(Ct=new AudioContext({sampleRate:48e3})),zt||(s?zt=Ct.audioWorklet.addModule(s):console.error("Please provide workletPublicUrl or restore workletCode")),zt}function us(s){return c(this,null,function*(){yield Xt();let e=Ct;e.state==="suspended"&&(yield e.resume());let t=yield navigator.mediaDevices.getUserMedia({audio:{sampleRate:48e3,channelCount:1,deviceId:s,echoCancellation:!0,noiseSuppression:!1,autoGainControl:!0}}),i=new AudioWorkletNode(e,cs),r=e.createMediaStreamSource(t);r.connect(i);let o=e.createMediaStreamDestination();return i.connect(o),ls.info("rnnoise MediaStream:","rnnoise","",[]),t.getTracks()[0].onended=()=>{i.disconnect(),r.disconnect()},o.stream})}var Ye=us;function we(s){return s.split("_")[0]}var K=`.streammuteevent${Math.random()}`,Ze=class s{constructor(){this.streamModels=new Map;this.streamModelsWatcher=new de(s.filterStreamModels(this.sortStreamModels()));this.shareStreamModels=new Map;this.shareStreamModelsWatcher=new de(Array.from(this.shareStreamModels.values()));this.localStreamErrorWatcher=new Z;this.localModel=null;this.room=null;this.bloudStream=null;this.whiteboard=null;this.whiteboardWatcher=new de(this.whiteboard);this.brtcStream=null;this.videoStream=null;this.audioStream=null;this.localIsShare=!1;this.isShareWatcher=new Z;this.localShareCustomStats={};this._speaker_enable=!0;this.speakerEnableWatcher=new de(this._speaker_enable);this.mixStreamUid=null;this.mixStreamModelWatcher=new de(null);this.canvasTimer=null;this._recorder=void 0;this._isRecording=!1;this._slicingRecord=!1;this.isRecordingWatcher=new de(this._isRecording);this._speaker=null;this._speakers=new Map;this.speakerWatcher=new de(this._speaker);this._enableNoiseFilter=!1;this._canUseNoiseFilter=!1;this.rtcPublishing=!1;this.noContainerWatcher=new Z;this.noBigContainerWatcher=new Z;this.localStreamConnectErrorWatcher=new Z;this.localShareError=new Z;this.localShareEndedError=new Z;this.shareBloudStateMap=new Map;this.streamPlayWatcher=new Z;this.handleStreamPlay=e=>{this.streamPlayWatcher.next(e)};this.updateModelSort=ds(()=>{let e=this.sortStreamModels();this.streamModelsWatcher.next(s.filterStreamModels(e))},200,{maxWait:500});this.handleNoContainer=e=>{let{type:t,container:i,id:r}=e,o;t==="share"?o=this.shareStreamModels.get(r):o=this.streamModels.get(r),o&&(i==="small"?this.noContainerWatcher.next(o):this.noBigContainerWatcher.next(o))};this.getHTMLMediaStream=ir;this.getMediaStream=rr;setTimeout(()=>{this.createCanvas(),this.canvasDisplay()},100),M.emitter.on(ye,this.updateModelSort),M.emitter.on(ae,this.handleNoContainer),M.emitter.on(H,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=>!Ae.some(i=>t.userId.includes(i))).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 i;let t=(i=this.room)==null?void 0:i.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,this.room,void 0,!0),this.whiteboardWatcher.next(this.whiteboard),this.whiteboard}removeWhiteBoard(){this.whiteboard=null,this.whiteboardWatcher.next(this.whiteboard)}createStreamModel(e,t){let i=new Pe(e,this.room,void 0);return t&&i.updateStream(t,!0,this),i.isShare?(e.addStream(`${e.userId}${T}`,i),this.addShareStreamModel(i)):(e.addStream(e.userId,i),this.addStreamModel(i)),i.isMixer&&(this.mixStreamUid=i.userId,this.mixStreamModel&&this.mixStreamModelWatcher.next(this.mixStreamModel)),i}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 i,r,o;let t=this.shareStreamModels.get(e);if(t){try{(i=t.stream)==null||i.destroy()}catch(a){}t.audioEnable&&t.stream&&((o=(r=this.room)==null?void 0:r.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 i,r,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?(r=(i=this.room)==null?void 0:i.audioPlayer)==null||r.removeStream(t.stream):(o=this.room)==null||o.audioPlayer.removeStreamByUid(e)),this.removeStreamModel(t)}return t}remoteStreamPublished(e){var a;let t=e.getStreamId(),i=e.getUserId().toString(),r=this.getStreamModelByUId(i),o;if(r||(o=we(String(i)),r=this.getStreamModelByUId(o)),r){if(z(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(r.getUser(),e),u=e.getVideoOn(),m=e.getAudioOn(),h=this.shareBloudStateMap.get(r.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 r.hasPulled=!1,r.pulledStreamType="small",this.updateStreamModel(r,e);this.changeSingleStreamSpeaker(r).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",r==null?void 0:r.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","",i,["streamId => ",t,"types =>",e.getType&&e.getType()])}remoteStreamUnpublished(e){var n,l,u;let t,i=e.getUserId().toString(),r=e.getStreamId(),o=!1;if(i.includes(T)){let m=we(String(i));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",i),this.localModel.getUser().removeStream(i);return}t=this.getShareStreamModelByUId(m),o=!0}else r.startsWith(ot)||e.getType&&e.getType()==="assist"?(t=this.getShareStreamModelByUId(i),o=!0):t=this.getStreamModelByUId(i);if(this.removeFromDetector(r),this.removeFromRecorder(e),!t){p("brtc\u6709\u4EBA\u53D6\u6D88\u63A8\u6D41 \u4F46\u662F\u627E\u4E0D\u5230\u5BF9\u5E94\u7684streamModel","\u53D6\u6D88\u63A8\u6D41",i,[r]);return}let a=(u=t.stream)==null?void 0:u.getStreamId();if(a!==r){p("\u5F53\u524D\u53D6\u6D88\u63A8\u6D41\u7684\u548C\u5F53\u524D\u7ED1\u5B9A\u7684\u4E0D\u662F\u540C\u4E00\u80A1\u6D41","",i,["streamId =>",r,"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 hi(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 r,o,a,n,l,u,m;if(!((r=this.room)!=null&&r.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(ms());let i=this.getLocalStreamModel();if(d(`\u5F00\u5173\u672C\u5730\u6444\u50CF\u5934\uFF0C \u72B6\u6001 => ${e}`,"publish",i==null?void 0:i.userId),i)if(e)if(i!=null&&i.stream){if(t)yield i.stream.replaceTrack(t).catch(g=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","",i.userId,[JSON.stringify(g)])});else{let g=(o=i==null?void 0:i.stream)==null?void 0:o.getVideoTrack(),S=i==null?void 0:i.stream.hasVideo();if(!g||(g==null?void 0:g.constructor.name)==="CanvasCaptureMediaStreamTrack"||S==!1){let b=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C)),E=i.stream;yield E.replaceTrack(b).then(()=>{E.setVideoProfile(this.room.videoProfile),d("replace video track success")}).catch(C=>(p(`\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u89C6\u9891\u6D41\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001 => ${i==null?void 0:i.audioEnable}`,"publish",i==null?void 0:i.userId,[JSON.stringify(C)]),i!=null&&i.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(or())))}else{let b=g==null?void 0:g.constructor.name;if(I(`setLocalVideoEnable: no videoTrack, trackName:${b}`,"publish",i==null?void 0:i.userId),q()){let E=yield this.createVideoStreamTrack().catch(C=>Promise.reject(C));yield i.stream.replaceTrack(E)}}}if(yield i.stream.unmuteVideo())d("brtc unmute video success");else return p(`brtc unmuteVideo\u5931\u8D25\uFF0C\u5F53\u524D\u9EA6\u514B\u98CE\u72B6\u6001=> ${i==null?void 0:i.audioEnable} hasVideo=>${i.stream.hasVideo()}`,"publish",i==null?void 0:i.userId),i!=null&&i.audioEnable||this.handleStreamUpdateFailed(),Promise.reject(or());if(!this.bloudStream||this.bloudStream.published==!1){i.isInBig&&i.playInBig(!0),yield this.publishBloudStream(!1,!0);return}yield this.bloudStream.setVideoEnabled(!0).then(()=>{i.updateStream(i.stream,!0,this),i.updateBloudStream({video:!0,audio:i.audioEnable,isScreen:!1},this),i.playInBig(!0)}).catch(g=>{p("bloud unmuteVideo\u5931\u8D25","publish","",[JSON.stringify(g)]),this.handleStreamUpdateFailed()})}else try{yield this.createStreamAndPublish(!1,!0,i,t),i.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 i.stream&&(yield this.muteOrUnpublishStream("video",!0,i).catch(g=>(p("\u5173\u95ED\u672C\u5730\u6444\u50CF\u5934\u5931\u8D25","","",[g]),Promise.reject(gs(g)))))})}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 r;let i=this.getLocalStreamModel();if(!((r=this.room)!=null&&r.networkState.brtc)||!this.room.netConnecting){p("\u65AD\u7F51\u671F\u95F4\u5F00\u672C\u5730\u9EA6\u514B\u98CE\uFF0C\u4E0D\u4E0E\u54CD\u5E94","publish",i==null?void 0:i.userId);return}if(!this.room.mediaPermission.microphone)return Promise.reject(hs());if(d(`\u5F00\u5173\u672C\u5730\u9EA6\u514B\u98CE\uFF0C \u72B6\u6001 => ${e}`,"publish",i==null?void 0:i.userId),i)if(e)if(i!=null&&i.stream){if(!i.stream.hasAudio()){let a=yield this.createLocalAudioStream();if(!a)return Promise.reject(Yt());let n=a.getAudioTrack();yield i.stream.replaceTrack(n).then(()=>{d("replace audio track success","publish",i.userId)}).catch(l=>(p("\u672C\u5730\u89C6\u9891\u6D41\u66F4\u6362\u97F3\u9891\u6D41\u5931\u8D25","publish",i.userId,[JSON.stringify(l)]),this.handleStreamUpdateFailed(!0),Promise.reject(Yt())))}if(yield i.stream.unmuteAudio().catch(a=>{var n;d("brtc unmuteAudio:err, hasAudio="+((n=i.stream)==null?void 0:n.hasAudio()),"publish","",[a])}))d("unmute audio success","publish",i.userId);else return p(`unmute local stream audio res\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${i==null?void 0:i.videoEnable} hasAudio=>${i.stream.hasAudio()}`,"publish",i==null?void 0:i.userId),i!=null&&i.videoEnable||(yield this.handleStreamUpdateFailed(!0)),Promise.reject(Yt());if(!this.bloudStream||this.bloudStream.published==!1){yield this.publishBloudStream(!0,!1);return}yield this.bloudStream.setAudioEnabled(!0).then(()=>{d("bloud stream set audio enable","publish",i.userId),i.updateStream(i.stream,!1,this),i.updateBloudStream({audio:!0,video:i.videoEnable,isScreen:!1},this)}).catch(a=>{p(`bloud unmuteAudio\u5931\u8D25\uFF0C\u5F53\u524D\u6444\u50CF\u5934\u72B6\u6001 => ${i==null?void 0:i.videoEnable}`,"publish",i==null?void 0:i.userId,[JSON.stringify(a)]),i!=null&&i.videoEnable||this.handleStreamUpdateFailed(!0)});return}else yield this.createStreamAndPublish(!0,!1,i).catch(o=>{var a,n,l,u,m;return p("\u5F00\u542F\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",i==null?void 0:i.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=i.stream;if(o){this.removeFromDetector(o.getStreamId());try{yield this.muteOrUnpublishStream("audio",!0,i,t)}catch(a){return p("\u5173\u95ED\u672C\u5730\u9EA6\u514B\u98CE\u5931\u8D25","publish",i.userId,[JSON.stringify(a)]),Promise.reject(ps(a))}}return}})}joinWithAudioAndAudio(e,t){return c(this,null,function*(){d("join with audio and video","publish","",[e,t]);let i=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,i).catch(r=>{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(r)]),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(r)})})}changeSpeaker(e,t=!1){return c(this,null,function*(){var i;if(d("change speaker","device","",[JSON.stringify(e)]),!(e!=null&&e.deviceId))throw new sr(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),(i=this.room.audioPlayer)==null||i.setDevice(e.deviceId,t)}catch(r){throw p("\u5207\u6362\u626C\u58F0\u5668\u5931\u8D25","device","",["error",r==null?void 0:r.message,JSON.stringify(r)]),new sr(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 i,r,o,a,n;d("change audio input device","device","",[JSON.stringify(e)]),e||I("changeAudioInput, device is null","device");let t=(i=this.localModel)==null?void 0:i.stream;if((r=this.room)==null||r.setSelectAudioDevice(e),t){if(((o=t.getAudioTrack())==null?void 0:o.readyState)==="ended"&&!((a=this.room)!=null&&a.deviceChanging))return p("try to change audio input device but audio track is ended","device"),!1;if(this._canUseNoiseFilter){let u=yield Ye(e.deviceId);yield t.replaceTrack(u.getAudioTracks()[0])}else yield t.switchDevice("audio",e.deviceId).catch(u=>{d("switchDevice:error","device","",[JSON.stringify(u)])});return(n=this._recorder)==null||n.setMicDevice(e.deviceId),!0}})}changeVideoInput(e,t=!1){return c(this,null,function*(){var r,o,a,n;d("change video input device","device","",[JSON.stringify(e)]);let i=(r=this.localModel)==null?void 0:r.stream;if((o=this.room)==null||o.setSelectVideoDevice(e),t)return!0;if(i)return((a=i.getVideoTrack())==null?void 0:a.readyState)==="ended"?(p("try to change video input device but video track is ended","device"),!1):(yield i.switchDevice("video",e.deviceId).catch(u=>{d("switchDevice:error","device","",[u])}),(n=this.localModel)!=null&&n.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(fs(`\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,this._canUseNoiseFilter).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,this._canUseNoiseFilter).catch(i=>(p("create brtc stream error","publish","",[JSON.stringify(i)]),Promise.reject(i))),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(i=>(this.rtcPublishing=!1,Promise.reject(i)))})}createStreamAndPublish(e,t,i,r){return c(this,null,function*(){var o,a,n,l,u,m,h,g,S;if(this.rtcPublishing)return I(`createStreamAndPublish(audio:${e},video:${t}), rtcPublishing ignore`,"publish",i.userId),!1;if(this.rtcPublishing=!0,d(`createStreamAndPublish(audio:${e},video:${t})`,"publish",i.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=(g=this.room)!=null&&g.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",i.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},i.userId,this._canUseNoiseFilter).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},i.userId,this._canUseNoiseFilter).catch(E=>(p("create brtc audio and video stream failed","publish","",[JSON.stringify(E)]),Promise.reject(E)))}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},i.userId,this._canUseNoiseFilter).catch(b=>(p("create brtc video stream failed","publish","",[JSON.stringify(b)]),Promise.reject(b)))}else{let E=s.getCanvasStream().getVideoTracks()[0];this.audioStream||(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},i.userId,this._canUseNoiseFilter).catch(y=>(p("create brtc stream error","publish","",[JSON.stringify(y)]),Promise.reject(y))));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]),Ss("\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",i.userId),this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:E,audioSource:C},i.userId,this._canUseNoiseFilter).catch(y=>Promise.reject(y))):q()?this.brtcStream=this.audioStream:this.brtcStream=yield this.room.createSingleLocalStream({video:!0,audio:!0,videoSource:E,audioSource:C},i.userId,this._canUseNoiseFilter).catch(y=>Promise.reject(y))}return this.brtcStream&&(t||(yield this.brtcStream.muteVideo()),e||(yield this.brtcStream.muteAudio()),r&&(yield this.brtcStream.replaceTrack(r).catch(b=>{p("\u7F8E\u989C videoTrack replace \u5931\u8D25","publish","",JSON.stringify(b))})),yield this.room.publish(this.brtcStream).catch(b=>{var E,C;return(E=this.brtcStream)==null||E.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,i,r;(e=this.brtcStream)==null||e.on("video-track-mute"+K,this.muteHandlerVideo),(t=this.brtcStream)==null||t.on("video-track-ended"+K,this.muteHandlerVideo),(i=this.brtcStream)==null||i.on("audio-track-mute"+K,this.muteHandlerAudio),(r=this.brtcStream)==null||r.on("audio-track-ended"+K,this.muteHandlerAudio)}brtcStreamRemoveEvent(){var e,t,i,r;(e=this.brtcStream)==null||e.off("video-track-mute"+K,this.muteHandlerVideo),(t=this.brtcStream)==null||t.off("video-track-ended"+K,this.muteHandlerVideo),(i=this.brtcStream)==null||i.off("audio-track-mute"+K,this.muteHandlerAudio),(r=this.brtcStream)==null||r.off("audio-track-ended"+K,this.muteHandlerAudio)}publishBloudStream(e,t){return c(this,null,function*(){var r;let i=this.localModel.userId;this.bloudStream=this.room.boomCore.creteBloudLocalStream({audio_enable:e,video_enable:t},i),yield this.bloudStream.publish({video_enable:t,audio_enable:e}),(r=this.localModel)==null||r.updateBloudStream({video:t,audio:e,isScreen:!1},this)})}muteHandler(e){var a,n,l;let t=()=>c(this,null,function*(){var u,m,h,g,S,b,E,C,y;(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)])})),(g=(h=this.localModel)==null?void 0:h.stream)==null||g.destroy(),(S=this.audioStream)==null||S.destroy(),(b=this.videoStream)==null||b.destroy(),(E=this.brtcStream)==null||E.destroy(),this.brtcStream=null,this.audioStream=null,this.videoStream=null,(C=this.localModel)==null||C.updateStream(void 0,!0,this),yield this.bloudStream.unpublish(),(y=this.localModel)==null||y.updateBloudStream(void 0,this)}),i=(a=this.localModel)==null?void 0:a.videoEnable,r=(n=this.localModel)==null?void 0:n.audioEnable,o=(l=this.brtcStream)==null?void 0:l.getAudioDeviceId();if(!i&&!r){d("muteHandler:\u97F3\u89C6\u9891\u5DF2\u5173,\u65E0\u9700\u5904\u7406","publish");return}setTimeout(()=>c(this,null,function*(){var u,m,h,g,S,b,E,C,y,L,G,F,j,$,J,te,ie,xe,Le,ke;if((u=this.localModel)!=null&&u.stream){let re=(m=this.localModel)==null?void 0:m.videoEnable,se=(h=this.localModel)==null?void 0:h.audioEnable;if(o!=((g=this.localModel)==null?void 0:g.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 V=(b=this.localModel.stream.getVideoTrack())==null?void 0:b.muted,me=(E=this.localModel.stream.getVideoTrack())==null?void 0:E.label,Oe=(C=this.localModel.stream.getVideoTrack())==null?void 0:C.enabled,A=(y=this.localModel.stream.getVideoTrack())==null?void 0:y.readyState,Q=A==="ended";if(d(`muteHandler:brtc video track status:${V},enabled:${Oe},readyState:${A},label:${me} `,"publish",""),!Q&&!V&&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:",se,"type:",e]),this.localStreamConnectErrorWatcher.next(ar("\u6444\u50CF\u5934")),(L=this.localModel)!=null&&L.stream&&(yield(G=this.room)==null?void 0:G.unpublish(this.localModel.stream).catch(Bt=>{p("brtc local stream has problem and unpublish failed","publish","",[String(Bt)])}),(F=this.localModel)==null||F.updateStream(void 0,!0,this),($=(j=this.localModel)==null?void 0:j.stream)==null||$.destroy(),(J=this.localModel.player)==null||J.destroy(),(te=this.brtcStream)==null||te.destroy(),this.brtcStream=null,(ie=this.videoStream)==null||ie.destroy(),this.videoStream=null);try{yield this.createStreamAndPublish(se,re,this.localModel),this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}catch(Bt){this.rtcPublishing=!1,p("brtc video stream has problem and republish stream failed","publish","",[JSON.stringify(Bt)]),yield t(),this.localStreamConnectErrorWatcher.next(Zt())}}else{if(!se){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",se,"type",e]),this.localStreamConnectErrorWatcher.next(ar("\u9EA6\u514B\u98CE")),(xe=this.audioStream)==null||xe.destroy(),(Le=this.localModel.player)==null||Le.destroy(),this.audioStream=null,this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId);let V=(ke=this.audioStream)==null?void 0:ke.getAudioTrack();V&&!V.muted?this.localModel.stream&&(yield this.localModel.stream.replaceTrack(V).then(()=>{this.localModel.isInBig&&this.localModel.bigPlayerId&&this.localModel.playInBig(!0)}).catch(me=>{p("\u672C\u5730\u6D41\u51FA\u73B0\u5F02\u5E38, \u91CD\u65B0\u521B\u5EFAaudio stream replace \u5931\u8D25","publish","",[JSON.stringify(me)]),this.localStreamConnectErrorWatcher.next(Zt()),t()})):(p("recreate audio stream failed, now unpublish","publish"),this.localStreamConnectErrorWatcher.next(Zt()),t())}}this.localStreamErrorWatcher.next(e)}),1e3)}unpublishStream(e=!1){return c(this,null,function*(){var i,r,o,a,n,l,u;d("unpublish stream","publish",(i=this.localModel)==null?void 0:i.userId);let t=this.getLocalStreamModel();if(t){let m=t.stream;m&&e===!0&&(yield(r=this.room)==null?void 0:r.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,i,r=!1){return c(this,null,function*(){let o=i.stream,a=!0;e==="audio"?a=i.videoEnable:e==="video"&&(a=i.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)])}),i.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)])}),i.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(r))})}justReplaceVideoTrack(e){return c(this,null,function*(){var r;let i=s.getCanvasStream().getVideoTracks()[0];try{yield e.replaceTrack(i),yield e.muteVideo()}catch(o){p("\u5173\u95ED\u672C\u5730\u89C6\u9891\u5931\u8D25","publish","\u672C\u5730",[JSON.stringify(o)])}try{(r=this.videoStream)==null||r.destroy(),this.videoStream=null}catch(o){p("this.videoStream destroy failed","publish")}})}toggleShareScreen(r){return c(this,arguments,function*(e,t={},i){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,i).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,i;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()),(i=this.videoStream)==null||i.destroy(),this.videoStream=null,this.videoStream=yield this.room.createPBSingleLocalStream({video:!0,audio:!1},this.localModel.userId).catch(r=>(p("createPBSingleLocalStream error","publish","",[JSON.stringify(r)]),Promise.reject(r))),this.videoStream.getVideoTrack()})}startRecord(e){return c(this,null,function*(){var i,r,o,a;if(this._recorder)return;this._recorder=(i=this.room)==null?void 0:i.boomCore.createRecorder(e),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record: ended","record")}),this._recorder.on("started",()=>{var n;d("record: started.","record"),this._recorder.muteAudio(!((n=this.localModel)!=null&&n.audioEnable))});let t=!0;try{yield this._recorder.start(void 0,void 0,{roomId:(r=this.room)==null?void 0:r.roomInfo.roomID,userName:(o=this.localModel)==null?void 0:o.getUser().nickname,title:(a=this.room)==null?void 0:a.roomInfo.roomName}),this._isRecording=!0,this.isRecordingWatcher.next(!0),this.shareStreamModels.forEach(n=>{n.stream&&!n.stream.isLocalStream()&&n.stream.isSubscribed()&&this.addToRecorder(n.stream)}),this.streamModels.forEach(n=>{n.stream&&!n.stream.isLocalStream()&&n.stream.isSubscribed()&&this.addToRecorder(n.stream)})}catch(n){I("record: error","record","",[JSON.stringify(n)]);let l=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),t=!1,yield l==null?void 0:l.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,i){return c(this,null,function*(){var a,n,l,u;if((a=this._recorder)!=null&&a.supportAutoSave())return!0;if(!this._isRecording)return;let r=(n=this._recorder)==null?void 0:n._opts;this._slicingRecord=!0;try{yield(l=this._recorder)==null?void 0:l.stop()}catch(m){p("record:stop record exception","","",[JSON.stringify(m)])}r.filename=e,this._recorder=(u=this.room)==null?void 0:u.boomCore.createRecorder(r),this._recorder.on("track-ended",()=>{this.stopRecord(),d("record:record ended.")}),this._recorder.on("started",()=>{var m;d("record:record started."),this._recorder.muteAudio(!((m=this.localModel)!=null&&m.audioEnable))});let o=!0;try{yield this._recorder.start(t,i),this._slicingRecord=!1,this.shareStreamModels.forEach(m=>{m.stream&&!m.stream.isLocalStream()&&m.stream.isSubscribed()&&this.addToRecorder(m.stream)}),this.streamModels.forEach(m=>{m.stream&&!m.stream.isLocalStream()&&m.stream.isSubscribed()&&this.addToRecorder(m.stream)})}catch(m){let h=this._recorder;this._recorder=void 0,this._isRecording=!1,this.isRecordingWatcher.next(!1),this._slicingRecord=!1,o=!1,console.log("record:stopRecord.error",m),yield h==null?void 0:h.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 r,o,a;let i=!0;t?(((r=this._speaker)==null?void 0:r.getUserInfo().userId)===t.getUser().userId&&(i=!1),this._speaker=t.getUser()):(this._speaker||(i=!1),this._speaker=null),i&&(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,i)=>{e.push(i)}),e.forEach(t=>{this.removeFromDetector(t)})}shareCustomMedia(e,t){return c(this,null,function*(){var i;return(i=this.room)==null?void 0:i.boomCore.shareHTMLMedia(e,t)})}updateBloudStreamCustomStats(e,t,i){return c(this,null,function*(){var o,a;d("update bloud stream custom stats","",e,[t,JSON.stringify(i)]);let r=yield(o=this.room)==null?void 0:o.boomCore.updateStream(e,t,i);((a=this.localModel)==null?void 0:a.userId)===e&&t.startsWith(e)&&t.endsWith("_screen")&&r.customInfo&&(this.localShareCustomStats=r.customInfo)})}checkStreamStats(e){d("check stream stats","","",[e]),this.streamModels.size<100&&this.streamModels.forEach(t=>{t.checkStreamIsPlaying()})}setEnableNoiseFilter(e,t){return c(this,null,function*(){var i,r,o;if(this._enableNoiseFilter=e,e)try{yield Xt(t),this._canUseNoiseFilter=!0}catch(a){throw p("init noise filter error","publish","",[JSON.stringify(a)]),this._canUseNoiseFilter=!1,a}else this._canUseNoiseFilter=!1;if((i=this.localModel)!=null&&i.stream&&this.localModel.audioEnable){let a;this._canUseNoiseFilter?a=(yield Ye((o=(r=this.room)==null?void 0:r.selectAudioDevice)==null?void 0:o.deviceId)).getTracks()[0]:(this.audioStream=yield this.room.createSingleLocalStream({video:!1,audio:!0},this.localModel.userId),a=this.audioStream.getMediaStream().getTracks()[0]),this.localModel.stream.replaceTrack(a).then(()=>{d(`noise filter replace track ${this._canUseNoiseFilter?"noise":"audio"}`,"publish","",[])}).catch(n=>{throw p(`noise filter replace track ${this._canUseNoiseFilter?"noise":"audio"} error`,"publish","",[JSON.stringify(n)]),n})}return!0})}clearCache(){var e,t,i,r,o;try{(t=(e=this.localModel)==null?void 0:e.stream)==null||t.destroy(),(i=this.videoStream)==null||i.destroy(),(r=this.audioStream)==null||r.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 ee,Subject as vt}from"rxjs";import{debounce as Kt}from"lodash-es";var Ke=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 ee(Array.from(this.raiseHandsList.values()));this.raiseVideoHandsList=new Map;this.raiseVideoHandsWatcher=new ee(Array.from(this.raiseVideoHandsList.values()));this.raiseSimpleHandsList=new Map;this.raiseSimpleHandsWatcher=new ee(Array.from(this.raiseSimpleHandsList.values()));this.operationPermissionWatcher=new vt;this.chatNoticeWatcher=new vt;this.totalUserWatcher=new ee(0);this.totalWaitRoomUserWatcher=new ee(0);this.isOpenWaitRoom=new vt;this.originJoinRoomParams={};this.originRespInfo={};this.audioOffWatcher=new vt;this.lockWatcher=new ee(this.lock);this.leaveNoticeWatcher=new ee(this.leaveNotice);this.openSelfWatcher=new ee(this.openSelf);this.setRaiseHandsWatcherValue=Kt(()=>{this.raiseHandsWatcher.next(Array.from(this.raiseHandsList.values()))},1e3);this.setVideoRaiseHandsWatcherValue=Kt(()=>{this.raiseVideoHandsWatcher.next(Array.from(this.raiseVideoHandsList.values()))},1e3);this.setSimpleRaiseHandsWatcherValue=Kt(()=>{this.raiseSimpleHandsWatcher.next(Array.from(this.raiseSimpleHandsList.values()))},1e3);this.room=e,M.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=N(N({},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 it,Subject as D}from"rxjs";var ei={name:"@hysc/meeting",version:"10.9.2",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:*","@timephy/rnnoise-wasm":"^1.0.0","detect-browser":"^5.3.0",immutable:"5.0.0-beta.4","lodash-es":"^4.17.21",mitt:"^3.0.0",rxjs:"^7.5.5"},peerDependencies:{"@hysc/core":"workspace:*"},devDependencies:{"@hysc/brtc":"workspace:*","@types/lodash-es":"^4.17.6",typescript:"6.0.0-dev.20260118"}};import{Logger as dr,LOGLEVEL as Rs}from"@hysc/utils";var et=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 Ns,BMCameraOccupyError as Ps,BMCreateStreamError as ws,BmLeaveError as Ts,BMMicNotAuthError as xs,BMMicOccupyError as Ls,BmSetAudioOffError as ks,BmSetMsgOffError as Os,BmSetVideoOffError as _s,BMShareStreamConnectError as Ds,BMStreamConnectError as Vs,BMStreamReconnectFailed as Hs,BMStreamReconnectSuccess as Ws,BmUpdateCustomStatsError as Gs,getStreamError as Fs,RepeatJoinError as js}from"@hysc/utils";var ti=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 i;t.isMixer||!t.isLocal&&t.stream&&((i=t.stream)!=null&&i.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||_.addQueue(this.room.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)})})}handleMixStream(e,t){return c(this,null,function*(){var r,o;let i=this.room.bmStreamVm.mixStreamUid;if(i){let a=this.room.bmStreamVm.streamModels.get(i);e?(r=a==null?void 0:a.stream)==null||r.muteAudio().then(()=>{d(`play:\u9759\u97F3\u6DF7\u6D41\u6210\u529F streamId:${i}`)}):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:${i}`)})}t==null||t(e)})}},nr=ti;import{debounce as mr,isNumber as $s,toNumber as hr,delay as Js}from"lodash-es";import{BrtcEvents as lr}from"@hysc/utils";function cr(s){var i,r;let e=()=>s.fire(lr.BRTC_ROOM_ROCONNECTING),t=()=>s.fire(lr.BRTC_ROOM_RECONNECTED);(i=s.brtcClient.client)==null||i.signal.channel.on("reconnecting",e),(r=s.brtcClient.client)==null||r.signal.channel.on("reconnected",t)}import{AudioPlayer as Is}from"@hysc/core";import{Subject as ys}from"rxjs";var k="AudioPlay",tt=class{constructor(e,t){this.playMap=new WeakSet;this.playerMap=new Map;this.muted=!1;this.playStateChangeWatcher=new ys;var r;let i=document.getElementById(e);if(i)this.container=i;else throw new Error("no container found, play failed");this.room=t,this.deviceId=(r=t.selectAudioOutputDevice)==null?void 0:r.deviceId}addStream(e,t=!1){let i=this.room.localUser,r=i.audienceEnableSpeaking;if(i.isAudience)if(r){if(!(e.getUserId().toString()+"".includes("-mixer-"))){d("audienceEnableSpeaking is true, only play mixer stream",k,e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}}else{I("audienceEnableSpeaking is false, not play audio",k,e.getUserId()+"-",["streamId =>",e.getStreamId()]);return}this.room.shouldPlayAudio&&this.room.autoPlayAudio&&e.isSubscribed()&&(t||!this.playMap.has(e))&&(d("add stream to player",k,e.getUserId(),["streamId ",e.getStreamId()]),this.playMap.add(e),this.play(e))}removeStream(e){let t=e.getStreamId(),i=this.playerMap.get(t);i&&i.destroy(),d("remove audio player",k,"",["streamId =>",t]),this.playerMap.delete(t),this.playMap.delete(e)}removeStreamByUid(e){let t=new Map;this.playerMap.forEach(i=>{z(i.stream)||i.stream.getUserId()===e&&t.set(i.stream.getStreamId(),i)}),t.forEach((i,r)=>{i.off(),i.destroy(),this.playerMap.delete(r),this.playMap.delete(i.stream)}),t.clear()}play(e){return c(this,null,function*(){var t;if(e.hasAudio()&&this.container){let i=new Is(this.container,{});this.addPlayerEvent(i),yield i.play(e);let r=we(e.getUserId().toString());if(this.deviceId?yield i.setSinkId(this.deviceId):(I("audioPlayer play() this.deviceId is null ",k,r,["streamId =>",e.getStreamId()]),q()&&(yield i.setSinkId("default"))),this.muted)i.setVolume(0);else{let o;if(z(e)?o=this.room.bmStreamVm.shareStreamModels.get(r):o=this.room.bmStreamVm.streamModels.get(r),o){let a=(t=o.bloudStream)==null?void 0:t.customInfo;a&&a.volume&&(i.audioLevel=a.volume,i.setVolume(a.volume))}}this.playerMap.set(e.getStreamId(),i)}})}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 i=this.playerMap.get(e);if(i){if(i.audioLevel=t,this.muted)return;i.setVolume(t)}else{let r=i==null?void 0:i.stream,o=r&&r.getUserId();p("\u8BBE\u7F6E\u4E86\u6D41\u7684\u97F3\u91CF\uFF0C\u4F46\u662F\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u64AD\u653E\u5668:"+e,k,o)}}setDevice(e,t=!1){return c(this,null,function*(){d("setDevice:",k,"",[e]),e&&(this.deviceId=e,this.playerMap.forEach(i=>i.setSinkId(e)))})}addPlayerEvent(e){e.on("player-state-changed",t=>{e.stream&&(d("audio player state change",k,"",[JSON.stringify(t)]),t.type==="error"&&t.reason&&t.reason.name==="NotAllowedError"&&this.playStateChangeWatcher.next(e),t.state==="PAUSED"&&e.resume().catch(()=>{let i=e.stream.getUserId();d("audio player resume failed, resubscribe stream",k,i,[]);let r=this.room.bmStreamVm.getStreamModelByUId(i+"");r==null||r.subscribeStream()}))})}clear(){d("audio play clear",k),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}destroy(){d("audio play destroy",k),this.playerMap.forEach(e=>e.destroy()),this.playerMap.clear(),this.playMap=new WeakSet}};var At=1,Qs={audio:!0,video:!0,streamType:"small",videoEnable:!0,audioEnable:!0},Xe=!0,Te=class{constructor({initDevices:e,ignoreMixer:t,template_name:i}={initDevices:!0,ignoreMixer:!1,template_name:""}){this.roomVM=null;this.videoDevices=[];this.audioDevices=[];this.audioOutputDevices=[];this.selectVideoDevice=null;this.selectAudioDevice=null;this.selectAudioOutputDevice=null;this.streamQueue=new et(this);this.userListColumns=1;this.sortType=1;this.BRTCConnectFailed=!1;this.pubFailedNum=0;this.streamConnectedErrorQueue=[];this.conferenceMode=1;this.isBig=!1;this.selectVideoDeviceWatcher=new it(this.selectVideoDevice);this.selectAudioDeviceWatcher=new it(this.selectAudioDevice);this.selectAudioOutputDeviceWatcher=new it(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.shareFileWatcher=new it(null);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 it({type:"init",status:!1,isNotCancelRootReport:!1});this.isInWaitRoom=!1;this.shouldPlayAudio=!0;this.deviceChanging=!1;this.ignoreMixer=!1;this.template_name="";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,Js(()=>{this.deviceChanging=!1},1200);let{changed:t,selectAudioDevice:i,selectAudioOutputDevice:r,selectVideoDevice:o}=yield this.initDevices(!0),a=i,n=r;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=()=>As().then(e=>{if(!q())return e;let t=[];return e.forEach((i,r)=>{i.name.includes("front")||i.name.includes("\u524D\u7F6E")?i.name=`\u524D\u7F6E${r.toString().padStart(2,"0")}`:(i.name.includes("back")||i.name.includes("\u540E\u7F6E"))&&(i.name=`\u540E\u7F6E${r.toString().padStart(2,"0")}`),t.push(i)}),t});this.enumAudioInputDevices=()=>vs().then(e=>{let t=e,i=e.find(r=>r.default);if(i){let r=Object.assign({},i);r.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${i==null?void 0:i.name}\uFF09`,t.unshift(r)}return t});this.enumAudioOutputDevices=()=>Bs().then(e=>{let t=e,i=e.find(r=>r.default);if(i){let r=Object.assign({},i);r.name=`\u7CFB\u7EDF\u9ED8\u8BA4\uFF08${i==null?void 0:i.name}\uFF09`,t.unshift(r)}return t});this.getPermissions=Us;this.checkSystemSupport=Es;this.createStream=Cs;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=mr(e=>c(this,null,function*(){let t=e.getAudioOn()||this.localUser.audioEnable||!1,i=e.getVideoOn()||this.localUser.videoEnable||!1;d("republish local stream ","","",[t,i]),yield this.publish(e).then(()=>c(this,null,function*(){this.bmStreamVm.bloudStream=null,yield this.bmStreamVm.publishBloudStream(t,i),d("local stream connect error, and republish success, bloud stream republish success","","",["audio =>",t," video => ",i]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Ws(t,i))})).catch(()=>{d("local stream connect error, and republish failed","","",["audio =>",t," video => ",i]),this.bmStreamVm.localStreamConnectErrorWatcher.next(Hs())})}),1e3);this.processUser=(e,t=0)=>c(this,null,function*(){let i="";if(e.isScreen){let r=this.bmStreamVm.getShareStreamModelByUId(e.id);(!r||!r.stream&&!r.isLocal)&&(e.isWeb?i=`${e.id}_screen`:i=e.id)}else{let r=this.bmStreamVm.streamModels.get(e.id);r&&!r.stream&&!r.isLocal&&(i=e.id)}if(i){d("brtc query streams","","",["queryId => ",i]);try{let r=yield this.queryBrtcStreams([i]);if(r&&r.length){let o=r.map(a=>[a.getUserId(),a.getStreamId()]);d("brtc query streams result ","","",["streamInfo =>",JSON.stringify(o)]),r&&this.handleAddStreams(r)}else t<10?(t+=1,yield W(1e3),this.processUser(e,t)):I(`query stream error: uId:${e}`)}catch(r){p("query stream error","","",[JSON.stringify(r),t]),t<10&&(t+=1,yield W(1e3),this.processUser(e,t))}}});dr.setLogLevel(Rs.INFO),d(`
|
|
2
2
|
******************************************************************************
|
|
3
|
-
* \u6B22\u8FCE\u4F7F\u7528 BoomCore(${
|
|
3
|
+
* \u6B22\u8FCE\u4F7F\u7528 BoomCore(${ei.version})
|
|
4
4
|
******************************************************************************
|
|
5
|
-
`),ur.info("this is formatted by hysc/logger module");let r=M.getInstance();this.ignoreMixer=t,this.template_name=i,this.localUser=new ae({},!0),this.roomInfo=new Ye(this),this.bmLiveVM=new ar(this),this.bmStreamVm=new Xe().initWithRoom(this),this.boomCore=new ys({}),r.on(me,o=>{this.handleSubMessage(o)}),r.on(se,o=>{this.handleStreamConnectError(o)}),r.on(ye,o=>{this.addUser2Queue(o)}),r.on(fe,o=>{this.manualSubscribeStreamModel(o.stream)}),r.on(ge,o=>{this.handleUnsubscribe(o.stream)}),r.on(pe,o=>{this.handleStreamBindElement(o.stream)}),r.on(be,o=>{this.handleStreamBindBigElement(o.stream)}),r.on(Me,o=>{var a;(a=this.audioPlayer)==null||a.setVolume(o.streamId,o.volume)}),r.on(ot,o=>{var a;(a=this.shareFileWatcher)==null||a.next({fileId:o.fileId,streamId:o.streamId})}),r.on(Ee,o=>{let a=o.stream.stream;a&&!a.isLocalStream()&&(this.audioPlayer.playMap.has(a)||this.audioPlayer.addStream(a))}),window.addEventListener("offline",()=>{this.netConnecting=!1,this.netConnectingWatcher.next(!1)}),window.addEventListener("online",()=>{var o,a;this.netConnecting=!0,this.netConnectingWatcher.next(!0),je.forEach(n=>{n()}),je.clear(),this.boomCore.client.reconnect(),(a=(o=this.boomCore.brtcClient)==null?void 0:o.client)==null||a.signal.channel.transport.reconnect(),this.handleReprocessStreamError()}),window.navigator.mediaDevices&&e&&(window.navigator.mediaDevices.addEventListener("devicechange",dr(this.handleMediaDevicesChange,100)),this.initDevices()),this.brtcNetEnableWatcher.subscribe(o=>{o&&this.handleReprocessStreamError()}),this.bloudWSReconnectWatcher.subscribe(o=>{o&&this.handleReprocessStreamError()})}setVoiceMode(e){this.voiceMode=e}get isSingleColumns(){return this.userListColumns===1}get localIsAudience(){var e;return(e=this.getLocalParticipant())==null?void 0:e.isAudience}get shouldIgnoreStream(){return this.conferenceMode===2&&this.isBig&&this.localIsAudience&&!this.localUser.audioEnable}get isWorkShop(){return this.conferenceMode===2}setAutoPlayAudio(e){this.autoPlayAudio=e,ze=e}setMediaPermission(e){this.mediaPermission=N(N({},this.mediaPermission),e),d("current media permission is ","","",[JSON.stringify(this.mediaPermission)])}setShouldPlayAudio(e){this.shouldPlayAudio=e}initAudioPlayer(e){d("init audio player"),this.audioPlayer=new Ke(e,this)}setupMeetingControlOptions(e){e&&(this.meetingControlOptions=N(N({},this.meetingControlOptions),e))}handleSubMessage(e){O.addQueue(this.handleQueueTask.bind(this,e.stream),`${e.stream.streamId} - \u8BA2\u9605\u6D41 - display ${e.stream.isDisplay} - currentDisplay - ${e.stream.isCurrentDisplay}`,0,e.stream.nickname)}configSM(e){e&&this.boomCore.configSM(e)}setVideoProfile(e){e&&(d(`set video profile ${e} `),this.videoProfile=e)}setCustomVideoEncodeConfig(e){this.videoEncodeConfig=e}setUserListColumns(e){let t=mr(e);if(js(t))this.userListColumns=t;else throw new Error("\u53C2\u6570\u5FC5\u987B\u662F\u6570\u5B57")}setSortType(e){let t=mr(e);if(t>2||t<1)throw new Error("\u6392\u5E8F\u6620\u5C04\u53EA\u80FD\u4E3A 2 \u6216\u8005 1");this.sortType=t,Bt=this.sortType}setAudioProfile(e){this.audioProfile=e}setSig(e){this.boomCore.setShareSig(e)}benchmark(){let e=Date.now();return function(){return Date.now()-e}}initDevices(e=!1){return c(this,null,function*(){var g;let t=this.benchmark(),i=!1,r=yield this.enumVideoDevices();d("videoDevices:"+JSON.stringify(r)),this.videoDevices.length!==r.length&&(i=!0);let o=r.filter(S=>{var b;return S.name==((b=this.selectVideoDevice)==null?void 0:b.name)})[0];this.videoDevices=r,this.videoDevicesWatcher.next(r);let a=o||this.filterDevice(this.videoDevices),n=(a==null?void 0:a.deviceId)!=((g=this.selectVideoDevice)==null?void 0:g.deviceId);a&&this.setSelectVideoDevice(a);let l=yield this.enumAudioInputDevices();this.audioDevices.length!==l.length&&(i=!0);let u=this.selectAudioDevice;if(!u||u.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=this.filterDevice(l,!0);S&&(u=S)}else if(!u.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=l.slice().reverse().find(b=>b.deviceId==u.deviceId);S?u=S:u=this.filterDevice(l)}this.audioDevices=l.filter(S=>S.deviceId!=="default"&&S.deviceId!=="communications"),this.audioDevicesWatcher.next(l),u||(u=this.filterDevice(l),this.audioDevices=l),u&&this.setSelectAudioDevice(u);let m=yield this.enumAudioOutputDevices();this.audioOutputDevices.length!==m.length&&(i=!0);let h=this.selectAudioOutputDevice;if(!h||h.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=this.filterDevice(m,!0);S&&(h=S)}else if(!h.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=m.slice().reverse().find(b=>b.deviceId==h.deviceId);S?h=S:h=this.filterDevice(m)}return this.audioOutputDevices=m.filter(S=>S.deviceId!=="default"&&S.deviceId!=="communications"),this.audioOutputDevicesWatcher.next(m),h||(h=this.filterDevice(m),this.audioOutputDevices=m),h!=this.selectAudioOutputDevice&&this.setSelectSpeakerDevice(h),d(`initDevices\u8017\u65F6 : ${t()}`),{videoDevices:this.videoDevices,audioDevices:this.audioDevices,audioOutputDevices:this.audioOutputDevices,selectVideoDevice:n?a:null,selectAudioDevice:u,selectAudioOutputDevice:h,changed:i}})}filterDevice(e,t=!1){if(t)return e.filter(o=>o.default)[0];let i=e.filter(r=>r.default)[0];return i||e[0]}setSelectAudioDevice(e){var t;(((t=this.selectAudioDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectAudioDevice.default!==e.default||this.selectAudioDevice.name!==e.name)&&(d("setSelectAudioDevice","","",["deviceId =>",e.deviceId,"name =>",e.name]),this.selectAudioDevice=e,this.selectAudioDeviceWatcher.next(e))}setSelectVideoDevice(e){var t;(((t=this.selectVideoDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectVideoDevice.default!==e.default)&&(d("setSelectVideoDevice","","",["deviceId =>",e==null?void 0:e.deviceId,"name =>",e==null?void 0:e.name]),this.selectVideoDevice=e,this.selectVideoDeviceWatcher.next(e))}setSelectSpeakerDevice(e){var t,i,r;(((t=this.selectAudioOutputDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectAudioOutputDevice.default!==e.default||((i=this.selectAudioOutputDevice)==null?void 0:i.name)!=e.name)&&((r=this.audioPlayer)==null||r.setDevice(e.deviceId),d("setSelectSpeakerDevice","","",["deviceId =>",e.deviceId,"name =>",e==null?void 0:e.name]),this.selectAudioOutputDevice=e,this.selectAudioOutputDeviceWatcher.next(e))}observe(e,t){var i;return!this.observes||!this.observes[e]?null:(i=this.observes[e])==null?void 0:i.subscribe(t)}join(e){return c(this,null,function*(){let t=e.brtc_host;t&&this.setCustomUrl(t),e.ignoreMixer&&(this.ignoreMixer=e.ignoreMixer),this.template_name=e.template_name;try{if(this.boomCore.client)return p("\u91CD\u590D join\uFF0C\u8BF7\u5148\u8C03\u7528 destroy"),Promise.reject(Fs);this.conferenceMode=e.roomType,this.isBig=e.is_big,d("========================","join info",e.userId,["roomId: ",e.room," roomType: ",e.roomType," roomName: ",e.name]),this.localUser.setup(e.userId,e.userinfo,e.nickname,e.customInfo),this.bmStreamVm.createStreamModel(this.localUser),this.userVM=new Fe(this.boomCore,this.localUser,this),this.isBig&&(this.userVM.commTimer=1e3),this.roomInfo.originJoinRoomParams=N({},e),this.roomVM=new Je(this.boomCore,this.userVM,this.roomInfo),this.roomVM.initWithRoom(this),this.chatVM=new Qe(this.boomCore,this.userVM,this),this._attachEvents(),yield this.boomCore.join(e).catch(i=>Promise.reject(i)),this.roomInfo.setup(this.boomCore.getRoomInfo());for(let i in this.observes)this.observe(i,()=>{});this.bmStreamVm.startSpeakerDetector(),this.roomInfo.setlock(this.boomCore.client.lock),lr(this.boomCore)}catch(i){return p("join room error","","",[JSON.stringify(i)]),Promise.reject(i)}})}leave(){return c(this,null,function*(){var e,t,i;try{this.bmStreamVm.brtcStream&&((e=this.bmStreamVm.brtcStream)!=null&&e.published)&&(yield this.unpublish(this.bmStreamVm.brtcStream).catch(o=>{p("leave brtc unpublish fail:"+o.message,"unpublish")})),this.pubFailedTimer&&clearTimeout(this.pubFailedTimer),this.pubFailedNum=0,M.removeEmitter(),ze=!0,(t=this.audioPlayer)==null||t.destroy(),this.bmStreamVm.clearCache(),this.bmStreamVm.canvasTimer&&clearTimeout(this.bmStreamVm.canvasTimer);let r=yield this.boomCore.leave().catch(()=>{p("bloud\u79BB\u4F1A\u5931\u8D25")});for(let o in this.observes)(i=this.observes[o])==null||i.unsubscribe();return this.observes={},r}catch(r){return p("leave room error","","",[JSON.stringify(r)]),Promise.reject(ws(JSON.stringify(r)))}})}releaseRoom(){return c(this,null,function*(){yield this.boomCore.releaseRoom()})}startRecord(e){return c(this,null,function*(){return yield this.bmStreamVm.startRecord(e)})}stopRecord(){return c(this,null,function*(){return yield this.bmStreamVm.stopRecord()})}sliceRecord(e,t,i){return c(this,null,function*(){return yield this.bmStreamVm.sliceRecord(e,t,i)})}close(){this.bmStreamVm.clearCache(),this.boomCore.close()}setRemoteVideoEnable(e,t){return c(this,null,function*(){yield this.roomVM.setRemoteVideoEnable(e,t).catch(i=>Promise.reject(i))})}setRemoteAudioEnable(e,t,i){return c(this,null,function*(){yield this.roomVM.setRemoteAudioEnable(e,t,i).catch(r=>Promise.reject(r))})}setLocalVideoEnable(e,t){return c(this,null,function*(){yield this.bmStreamVm.setLocalVideoEnable(e,t).catch(i=>Promise.reject(i))})}setLocalAudioEnable(e,t=!1){return c(this,null,function*(){return yield this.bmStreamVm.setLocalAudioEnable(e,t).catch(i=>Promise.reject(i))})}setLocalSpeakerEnable(e){return c(this,null,function*(){yield this.bmStreamVm.muteSpeaker(e).catch(t=>Promise.reject(t))})}_attachEvents(){this.observes=Ji(this.boomCore,this.userVM,this.bmStreamVm,this.chatVM,this)}createSingleLocalStream(){return c(this,arguments,function*(e={video:!0,audio:!0},t,i=!1){var a,n,l,u;let r={video:e.video,audio:e.audio,cameraId:(a=this.selectVideoDevice)==null?void 0:a.deviceId,microphoneId:(n=this.selectAudioDevice)==null?void 0:n.deviceId,sourceType:"camera"};if(e.videoSource&&(r.videoSource=e.videoSource),e.audioSource&&(r.audioSource=e.audioSource),r.echoCancellation=!0,r.noiseSuppression=(l=e.noiseSuppression)!=null?l:!0,r.autoGainControl=!0,this.voiceMode&&(r.audioHint=this.voiceMode,r.noiseSuppression=!1),i){let m=yield Et((u=this.selectAudioDevice)==null?void 0:u.deviceId);r.audioSource=m.getAudioTracks()[0]}let o=yield this.boomCore.createLocalStream(r,t).catch(m=>(p("create brtc stream error","publish","",[JSON.stringify(m),m==null?void 0:m.message]),Promise.reject(Gs(e.video?"\u6444\u50CF\u5934":"\u9EA6\u514B\u98CE"))));return e.video&&(this.videoEncodeConfig?o.setVideoEncoderConfiguration(this.videoEncodeConfig):this.videoProfile==="720p"?o.setVideoEncoderConfiguration({width:1280,height:720,bitrate:1500,frameRate:25}):o.setVideoProfile(this.videoProfile)),yield this.handleStreamInit(e,o),o})}createPBSingleLocalStream(){return c(this,arguments,function*(e={video:!0,audio:!0},t){var o,a;let i={video:e.video,audio:e.audio,cameraId:(o=this.selectVideoDevice)==null?void 0:o.deviceId,microphoneId:(a=this.selectAudioDevice)==null?void 0:a.deviceId,sourceType:"camera"};i.echoCancellation=!0,i.noiseSuppression=!0,i.autoGainControl=!0,this.voiceMode&&(i.audioHint=this.voiceMode,i.noiseSuppression=!1);let r=yield this.boomCore.createPBLocalStream(i,t).catch(n=>Promise.reject(n));return this.videoProfile==="720p"?r.setVideoEncoderConfiguration({width:1280,height:720,bitrate:1500,frameRate:25}):r.setVideoProfile(this.videoProfile),yield this.handleStreamInit(e,r),r})}handleStreamInit(){return c(this,arguments,function*(e={video:!0,audio:!0},t){try{yield t.init()}catch(i){if(p("brtc init stream failed","publish","",[i==null?void 0:i.message]),String(i).includes("Permission denied")){if(e.video)return Promise.reject(Rs());if(e.audio)return Promise.reject(Ts())}else{if(String(i).includes("Could not start video source"))return Promise.reject(Ns());if(String(i).includes("Could not start audio source"))return Promise.reject(xs())}let r=e.video?"\u6444\u50CF\u5934":"\u9EA6\u514B\u98CE";return Promise.reject(Ps(r,i==null?void 0:i.message))}})}subscribe(e,t){return c(this,null,function*(){return this.boomCore.subscribe(e,t)})}unsubscribe(e){return this.boomCore.unsubscribe(e).catch(t=>Promise.reject(t))}publish(e){return new Promise((t,i)=>{this.boomCore.publish(e).then(()=>{d("publish:brtc stream publish success"),this.pubFailedNum=0,t(!0)}).catch(r=>c(this,null,function*(){this.pubFailedNum<=3?(this.pubFailedNum+=1,this.pubFailedTimer&&clearTimeout(this.pubFailedTimer),this.pubFailedTimer=setTimeout(()=>{var o;return p(`publish:local publish stream failed, retry failed num: ${this.pubFailedNum}, msg: ${r.message}`,"publish",(o=this.localUser)==null?void 0:o.userId),this.publish(e).then(t).catch(i)},3e3)):(p("publish:retry publish local stream failed, ubpublish now"),yield this.bmStreamVm.unpublishStream(!0),i(!1))}))})}unpublish(e){return this.boomCore.unpublish(e).catch(t=>Promise.reject(t))}getUser(e){return this.userVM.getUser(e)}changeMaster(e,t=!1){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.changeMaster(e,t).catch(r=>r)})}updateManager(e,t,i=!0){return c(this,null,function*(){return this.roomVM.updateManager(e,t,i).catch(r=>r)})}getMaster(){return this.boomCore.getMaster()}getCreator(){return this.boomCore.getCreator()}getName(){return this.boomCore.getName()}evictUser(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.evictUser(e,t)})}updateUser(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.updateUser(e,t)})}getMsgSeq(){return this.boomCore.getMsgSeq()}getLimits(){return this.boomCore.getLimits()}getSwitch(){return this.boomCore.getSwitch()}syncRoom(){return this.boomCore.syncRoom()}update(e){return this.boomCore.update(e)}getUsers(){return this.userVM.userList}getTotalUsers(){return this.userVM.userList.size}sendMessage(e,t){return this.boomCore.sendMessage(e,t)}customMessage(e,t,i=!1){return this.boomCore.customMessage(e,t,i)}getMessages(e,t){return this.boomCore.getMessages(e,t)}getLocalParticipant(){var t;let e=(t=this.userVM)==null?void 0:t.getLocalUser();return e||(e=this.localUser),e}getAudioOff(){return this.boomCore.getAudioOff()}getSelfOpenAudio(){return this.boomCore.getSelfOpenAudio()}getVideoOff(){return this.boomCore.getVideoOff()}getMsgOff(){return this.boomCore.getMsgOff()}getLock(){return this.boomCore.getLock()}getRoomInfo(){return this.roomInfo}setAudioOff(e,t){return c(this,null,function*(){return yield this.boomCore.setAudioOff(e,t).catch(i=>Promise.reject(Ls(`boomCore.setAudioOff error ${JSON.stringify(i)}`)))})}updateRoom(e){return c(this,null,function*(){return this.boomCore.client.update(e)})}setVideoOff(e){return this.boomCore.setVideoOff(e).catch(t=>Promise.reject(Os(`boomCore.setVideoOff error ${JSON.stringify(t)}`)))}setMsgOff(e){return this.boomCore.setMsgOff(e).catch(t=>Promise.reject(ks(`boomCore.setMsgOff error ${JSON.stringify(t)}`)))}setSwitch(e){return this.boomCore.setSwitch(e)}setLock(e){return c(this,null,function*(){return yield this.boomCore.setLock(e),this.boomCore.getLock()})}sendChatMessage(e,t,i){if(!this.chatVM)throw new U(1002,"\u672A\u521D\u59CB\u5316chatVM, \u65E0\u6CD5\u53D1\u9001\u804A\u5929\u4FE1\u606F");return this.chatVM.sendMessage(e,t,i)}getChatMessage(){if(!this.chatVM)throw new U(1002,"\u672A\u521D\u59CB\u5316chatVM, \u65E0\u6CD5\u83B7\u53D6\u804A\u5929\u5BA4\u6D88\u606F");return this.chatVM.messageList}getHistoryMessage(){return c(this,null,function*(){return this.chatVM.getHistoryMessage()})}updateCustomStats(e,t){return this.boomCore.updateCustomStats(Oe(N({},e),{pos:"web"}),t).catch(i=>Promise.reject(Ws(`.boomCore.updateCustomStats ${JSON.stringify(i)}`)))}getCustomStats(){return this.boomCore.getCustomStats()}getDuration(){return this.boomCore.getDuration()}checkUserHasMaster(e){return this.userVM.checkUserHasMaster(e)}changeNickName(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.changeNickName(e,t)})}streamModelExits(e){let t=e.userId;return e.isShare?this.bmStreamVm.shareStreamModels.has(t):this.bmStreamVm.streamModels.has(t)}handleStreamTask(e,t=!1){return c(this,null,function*(){if(!this.streamModelExits(e)){I(`streamModel is not exits, userId: ${e.userId}, isShare: ${e.isShare}, ignore`);return}e.stream?this.conferenceMode===1?(yield this.handlePull(e),yield this.handleChangeStreamType(e)):(yield this.bmLiveVM.handlePull(e),yield this.bmLiveVM.handleChangeStreamType(e)):((e.isDisplay||e.isInBig)&&e.bloudStream||e.audioEnable)&&(yield this.addUser2Queue({id:e.userId,isScreen:e.isShare,isWeb:e.isWeb}))})}handlePull(e){return c(this,null,function*(){var t;e.isLocal||(e.isMixer&&(yield this.handleSubscribeSteam(e)),(e.isDisplay!==e.isCurrentDisplay||e.isInBig&&e.pulledStreamType!==e.pulledStreamGoal||!e.hasPulled)&&(e.isCurrentDisplay=e.isDisplay,e.checkCount=0,e.isDisplay||e.isInBig||!e.isDisplay&&(e.audioEnable||(t=e.stream)!=null&&t.getAudioOn())?yield this.handleSubscribeSteam(e):yield this.handleUnsubscribeStream(e)))})}manualSubscribeStreamModel(e){O.addQueue(this.handleStreamTask.bind(this,e),e.streamId,0,e.nickname)}handleUnsubscribe(e){O.addQueue(this.handleUnsubscribeStream.bind(this,e),e.streamId,0,e.nickname)}handleStreamBindElement(e){O.addQueue(this.handlePlaySmall.bind(this,e,!1,!1),`bindElement-${e.userId}-${e.nickname}`,0,e.nickname)}handleStreamBindBigElement(e){O.addQueue(this.handlePlayInBIg.bind(this,e),`bindElement-${e.userId}-${e.nickname}`,0,e.nickname)}handleUnsubscribeStream(e){return c(this,null,function*(){var t,i;e.stream&&((i=(t=e.stream)==null?void 0:t.isSubscribed)!=null&&i.call(t)||e.hasPulled)&&(e.hasPulled=!1,e.pulledStreamType="small",e.isInBig=!1,e.stop(),yield this.unsubscribe(e.stream).then(()=>{var r,o;e.stream&&((r=this.audioPlayer)==null||r.removeStream(e.stream)),e.isSubScribedWatcher.next(!1),d("\u53D6\u6D88\u8BA2\u9605\u6D41\u6210\u529F","",e.userId,[e.nickname,e.isDisplay,e.isCurrentDisplay,(o=e.stream)==null?void 0:o.getStreamId()])}).catch(()=>{p("unsubscribe error")}))})}handleSubscribeSteam(e){return c(this,null,function*(){var t,i;try{e.hasPulled&&e.stream.isSubscribed()?e.isDisplay?(t=e.stream)==null||t.unmuteVideo().then(()=>{d("stream unmute video success ","unmute-video",e.userId,["streamId => ",e.streamId])}):(i=e.stream)==null||i.muteVideo().then(()=>{d("stream mute video success ","mute-video",e.userId,["streamId => ",e.streamId])}):(d("\u5F00\u59CB\u8BA2\u9605","subscribe",e.userId,[e.streamId]),e.hasPulled=!0,yield this.subscribe(e.stream,Js).then(()=>{var r,o;d("\u8BA2\u9605\u6D41\u7ED3\u675F","subscribe",e.userId,[" nickname =>",e.nickname,"streamId =>",e.streamId,"display =>",e.isDisplay]),e.isDisplay||(r=e.stream)==null||r.muteVideo(),e.stream&&e.audioEnable&&((o=this.audioPlayer)==null||o.addStream(e.stream,!0)),e.pullFailedNum=0,e.isSubScribedWatcher.next(!0),this.bmStreamVm.addToRecorder(e.stream),e.isDisplay&&e.videoEnable&&this.handlePlay(e,!0)}).catch(r=>{var o,a;if(p("\u8BA2\u9605\u6D41\u5931\u8D25","subscribe",e.userId,[" nickname =>",e.nickname,"streamId =>",e.streamId," error => ",JSON.stringify(r)]),e.hasPulled=!1,e.pulledStreamType="small",e.pullFailedNum+=1,(o=e.player)==null||o.destroy(),e.pullFailedNum<=3)this.handlePulledFailed(e);else{e.pullFailedNum=0;let n=e.isShare;try{(a=e.stream)==null||a.destroy()}catch(l){}e.updateStream(void 0,!1,this.bmStreamVm),d("subscribe stream failed, need to reQuery stream","",e.userId,["streamId =>",e.streamId,"hasStream => ",!!e.stream,"isWeb => ",e.isWeb,"isScreen => ",n,"bloudStreamState =>",JSON.stringify(e.bloudStream)]),e.bloudStream&&this.addUser2Queue({id:e.userId,isWeb:e.isWeb,isScreen:n})}}))}catch(r){e.hasPulled=!1,e.pulledStreamType="small",console.error("\u8BA2\u9605\u6D41\u5931\u8D25","",e.userId,e.nickname,"\u9519\u8BEF =>",r)}})}handleChangeStreamType(e){return c(this,null,function*(){var t,i;e.isLocal||e.pulledStreamType!==e.pulledStreamGoal&&((t=e.stream)!=null&&t.isSubscribed())&&((i=e.stream)!=null&&i.isSubscribed()||e.hasPulled)&&(e.pulledStreamType=e.pulledStreamGoal,yield this.boomCore.brtcClient.setRemoteVideoStreamType(e.stream,e.pulledStreamGoal).catch(r=>{p("\u5927\u5C0F\u6D41\u5207\u6362\u5931\u8D25","",e.userId,["error => ",JSON.stringify(r)])}),d("\u5927\u5C0F\u6D41\u5207\u6362\u7ED3\u675F","",e.userId,["nickname =>",e.nickname," isInBig => ",e.isInBig," pulledStreamGoal => ",e.pulledStreamGoal,"pulledStreamType => ",e.pulledStreamType]))})}handlePlay(e,t=!1){return c(this,null,function*(){this.streamModelExits(e)&&(e.stream&&e.isLocal&&!e.isShare||!e.isLocal&&e.stream.isSubscribed())&&(e.isDisplay&&e.playerId&&e.play(t),e.isInBig&&e.bigPlayerId&&e.playInBig(t))})}handlePlaySmall(e,...t){this.streamModelExits(e)&&e.play()}handlePlayInBIg(e){this.streamModelExits(e)&&e.playInBig()}handlePulledFailed(e){let t=e.userId;(e.isShare?this.bmStreamVm.shareStreamModels.has(t):this.bmStreamVm.streamModels.has(t))&&O.addQueue(this.handleQueueTask.bind(this,e),e.streamId,0,e.nickname)}handleStreamConnectError(e){return c(this,null,function*(){var r,o;let{stream:t,isLocal:i}=e;t&&(d("handleStreamConnectError","","",["nickname =>",t.nickname,"streamId => ",t.streamId,"isShare =>",t.isShare,"isLocal => ",i]),t.stream&&(t.stop(),(r=this.audioPlayer)==null||r.removeStream(t.stream)),(o=t.player)==null||o.destroy(),i?t.stream&&(t.isShare?this.bmStreamVm.localShareError.next(Ds()):this.bmStreamVm.localStreamConnectErrorWatcher.next(_s()),this.netConnecting&&this.networkState.brtc&&this.networkState.bloud?t.isShare?(d("Local share stream has problem, now ,republish"),mt(this,this.bmStreamVm)):(d("brtc \u7F51\u7EDC\u6B63\u5E38\uFF0C\u91CD\u65B0\u63A8\u6D41"),t.stream&&(yield this.republishLocalStream(t.stream))):(p("brtc \u7F51\u7EDC\u8FD8\u6CA1\u6062\u590D\uFF0C\u7B49\u6062\u590D\u4E86\u5728\u91CD\u65B0\u63A8\u6D41 ","",t.userId,["nickname =>",t.nickname,"streamId => ",t.streamId,"isShare =>",t.isShare]),this.streamConnectedErrorQueue.push(e))):this.netConnecting&&this.networkState.brtc?(t.hasPulled=!1,t.pulledStreamType="small",O.addQueue(this.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)):(p("brtc \u7F51\u7EDC\u8FD8\u6CA1\u6062\u590D\uFF0C\u7B49\u6062\u590D\u4E86\u5728\u91CD\u65B0\u62C9\u6D41 ","",t.userId,["nickname =>",t.nickname]),this.streamConnectedErrorQueue.push(e)))})}toggleAudienceSpeaking(e,t){e.permission.setAudio(t);let i={};return e.raiseHand&&(e.raiseHand=!1,i.raiseHand=!1),e.raiseAudioHands&&(e.raiseAudioHands=!1,i.raiseHandsAudio=!1),this.updateUser(e.userId,N({permission:e.permission.get()},i))}updateUserIsGuest(e,t){return c(this,null,function*(){return e.permission.setSubscribe(t),this.updateUser(e.userId,{permission:e.permission.get()})})}managerChangeToGuest(e){this.userVM.managerChangeToGuest(e)}moveUserRoom(e,t=!1,i=!1){return this.boomCore.client.moveUserRoom(e,t,i)}getParticipantNotice(e){this.participantNotice=e}setCustomUrl(e){this.boomCore.setCustomUrl(e)}handleRePushSelf(){return c(this,null,function*(){var t,i;let e=(i=(t=this.getLocalParticipant())==null?void 0:t.getMainStreamModel())==null?void 0:i.stream;e&&(yield this.republishLocalStream(e))})}handleResetOtherStreamStatus(){d("brtc sync-room-completed"),this.audioPlayer.clear(),this.bmStreamVm.streamModels.forEach(e=>{var t;if(!e.isLocal){e.hasPulled=!1,e.pulledStreamType="small";try{(t=e.stream)==null||t.destroy()}catch(i){}e.updateStream(void 0,!1,this.bmStreamVm)}}),this.bmStreamVm.shareStreamModels.forEach(e=>{var t;if(!e.isLocal){e.hasPulled=!1,e.pulledStreamType="small";let i=e.getUser();try{(t=e.stream)==null||t.destroy()}catch(r){}i.removeStream(`${e.userId}${T}`)}}),this.bmStreamVm.shareStreamModels.clear(),this.bmStreamVm.shareStreamModelsWatcher.next(Array.from(this.bmStreamVm.shareStreamModels.values())),this.networkState.brtc=!0,setTimeout(()=>{this.brtcNetEnableWatcher.next(!0),this.streamWSReconnectWatcher.next(!0)},2e3),le(this)}restartPullUsers(e){e.forEach((t,i)=>{this.addUser2Queue(t)})}addUser2Queue(e){return c(this,null,function*(){var t;if(this.streamQueue.addUser(e),e.force||e.isScreen)this.processUser(e);else{let i=this.bmStreamVm.streamModels.get(e.id);i&&!i.isLocal&&(i.stream||i&&((t=i.bloudStream)!=null&&t.audio||i.bloudStream&&i.isDisplay)&&this.processUser(e))}})}queryBrtcStreams(e){return c(this,null,function*(){return this.boomCore.brtcClient.queryUsers(e)})}handleAddStreams(e){if(this.isInWaitRoom){I("handleAddStreams isInWaitRoom true return");return}e.forEach(t=>{if(q(t)){let i=this.bmStreamVm.shareStreamModels.get(Pe(t.getUserId().toString()));(!i||i&&!i.stream)&&(i!=null&&i.player&&i.player.destroy(),this.bmStreamVm.remoteStreamPublished(t))}else{let i=this.bmStreamVm.streamModels.get(t.getUserId().toString());i&&!i.stream&&(i!=null&&i.player&&i.player.destroy(),this.bmStreamVm.remoteStreamPublished(t))}})}getForceUser(e){return c(this,null,function*(){yield this.queryBloudUsers([e]),this.userVM.getForceUserWatcher.next(!0)})}queryBloudUsers(e,t=!1,i=!0){return c(this,null,function*(){let{users:r}=yield this.boomCore.queryUsers(e);return this.userVM.addBcUsersMap(r,i,t),r})}getVersion(){return Kt.version}};import{BoomError as Qs,Logger as qs}from"@hysc/utils";var Kl=we;window.BoomMeeting=we;window.BoomError=Qs;window.BOOMLogger=qs;export{qs as Logger,Kl as default};
|
|
5
|
+
`),dr.info("this is formatted by hysc/logger module");let r=M.getInstance();this.ignoreMixer=t,this.template_name=i,this.localUser=new ne({},!0),this.roomInfo=new Ke(this),this.bmLiveVM=new nr(this),this.bmStreamVm=new Ze().initWithRoom(this),this.boomCore=new Ms({}),r.on(he,o=>{this.handleSubMessage(o)}),r.on(oe,o=>{this.handleStreamConnectError(o)}),r.on(Me,o=>{this.addUser2Queue(o)}),r.on(ge,o=>{this.manualSubscribeStreamModel(o.stream)}),r.on(Se,o=>{this.handleUnsubscribe(o.stream)}),r.on(fe,o=>{this.handleStreamBindElement(o.stream)}),r.on(Ie,o=>{this.handleStreamBindBigElement(o.stream)}),r.on(Ee,o=>{var a;(a=this.audioPlayer)==null||a.setVolume(o.streamId,o.volume)}),r.on(nt,o=>{var a;(a=this.shareFileWatcher)==null||a.next({fileId:o.fileId,streamId:o.streamId})}),r.on(Ce,o=>{let a=o.stream.stream;a&&!a.isLocalStream()&&(this.audioPlayer.playMap.has(a)||this.audioPlayer.addStream(a))}),window.addEventListener("offline",()=>{this.netConnecting=!1,this.netConnectingWatcher.next(!1)}),window.addEventListener("online",()=>{var o,a;this.netConnecting=!0,this.netConnectingWatcher.next(!0),$e.forEach(n=>{n()}),$e.clear(),this.boomCore.client.reconnect(),(a=(o=this.boomCore.brtcClient)==null?void 0:o.client)==null||a.signal.channel.transport.reconnect(),this.handleReprocessStreamError()}),window.navigator.mediaDevices&&e&&(window.navigator.mediaDevices.addEventListener("devicechange",mr(this.handleMediaDevicesChange,100)),this.initDevices()),this.brtcNetEnableWatcher.subscribe(o=>{o&&this.handleReprocessStreamError()}),this.bloudWSReconnectWatcher.subscribe(o=>{o&&this.handleReprocessStreamError()})}setVoiceMode(e){this.voiceMode=e}get isSingleColumns(){return this.userListColumns===1}get localIsAudience(){var e;return(e=this.getLocalParticipant())==null?void 0:e.isAudience}get shouldIgnoreStream(){return this.conferenceMode===2&&this.isBig&&this.localIsAudience&&!this.localUser.audioEnable}get isWorkShop(){return this.conferenceMode===2}setAutoPlayAudio(e){this.autoPlayAudio=e,Xe=e}setMediaPermission(e){this.mediaPermission=N(N({},this.mediaPermission),e),d("current media permission is ","","",[JSON.stringify(this.mediaPermission)])}setShouldPlayAudio(e){this.shouldPlayAudio=e}initAudioPlayer(e){d("init audio player"),this.audioPlayer=new tt(e,this)}setupMeetingControlOptions(e){e&&(this.meetingControlOptions=N(N({},this.meetingControlOptions),e))}handleSubMessage(e){_.addQueue(this.handleQueueTask.bind(this,e.stream),`${e.stream.streamId} - \u8BA2\u9605\u6D41 - display ${e.stream.isDisplay} - currentDisplay - ${e.stream.isCurrentDisplay}`,0,e.stream.nickname)}configSM(e){e&&this.boomCore.configSM(e)}setVideoProfile(e){e&&(d(`set video profile ${e} `),this.videoProfile=e)}setCustomVideoEncodeConfig(e){this.videoEncodeConfig=e}setUserListColumns(e){let t=hr(e);if($s(t))this.userListColumns=t;else throw new Error("\u53C2\u6570\u5FC5\u987B\u662F\u6570\u5B57")}setSortType(e){let t=hr(e);if(t>2||t<1)throw new Error("\u6392\u5E8F\u6620\u5C04\u53EA\u80FD\u4E3A 2 \u6216\u8005 1");this.sortType=t,At=this.sortType}setAudioProfile(e){this.audioProfile=e}setSig(e){this.boomCore.setShareSig(e)}benchmark(){let e=Date.now();return function(){return Date.now()-e}}initDevices(e=!1){return c(this,null,function*(){var g;let t=this.benchmark(),i=!1,r=yield this.enumVideoDevices();d("videoDevices:"+JSON.stringify(r)),this.videoDevices.length!==r.length&&(i=!0);let o=r.filter(S=>{var b;return S.name==((b=this.selectVideoDevice)==null?void 0:b.name)})[0];this.videoDevices=r,this.videoDevicesWatcher.next(r);let a=o||this.filterDevice(this.videoDevices),n=(a==null?void 0:a.deviceId)!=((g=this.selectVideoDevice)==null?void 0:g.deviceId);a&&this.setSelectVideoDevice(a);let l=yield this.enumAudioInputDevices();this.audioDevices.length!==l.length&&(i=!0);let u=this.selectAudioDevice;if(!u||u.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=this.filterDevice(l,!0);S&&(u=S)}else if(!u.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=l.slice().reverse().find(b=>b.deviceId==u.deviceId);S?u=S:u=this.filterDevice(l)}this.audioDevices=l.filter(S=>S.deviceId!=="default"&&S.deviceId!=="communications"),this.audioDevicesWatcher.next(l),u||(u=this.filterDevice(l),this.audioDevices=l),u&&this.setSelectAudioDevice(u);let m=yield this.enumAudioOutputDevices();this.audioOutputDevices.length!==m.length&&(i=!0);let h=this.selectAudioOutputDevice;if(!h||h.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=this.filterDevice(m,!0);S&&(h=S)}else if(!h.name.startsWith("\u7CFB\u7EDF\u9ED8\u8BA4\uFF08")){let S=m.slice().reverse().find(b=>b.deviceId==h.deviceId);S?h=S:h=this.filterDevice(m)}return this.audioOutputDevices=m.filter(S=>S.deviceId!=="default"&&S.deviceId!=="communications"),this.audioOutputDevicesWatcher.next(m),h||(h=this.filterDevice(m),this.audioOutputDevices=m),h!=this.selectAudioOutputDevice&&this.setSelectSpeakerDevice(h),d(`initDevices\u8017\u65F6 : ${t()}`),{videoDevices:this.videoDevices,audioDevices:this.audioDevices,audioOutputDevices:this.audioOutputDevices,selectVideoDevice:n?a:null,selectAudioDevice:u,selectAudioOutputDevice:h,changed:i}})}filterDevice(e,t=!1){if(t)return e.filter(o=>o.default)[0];let i=e.filter(r=>r.default)[0];return i||e[0]}setSelectAudioDevice(e){var t;(((t=this.selectAudioDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectAudioDevice.default!==e.default||this.selectAudioDevice.name!==e.name)&&(d("setSelectAudioDevice","","",["deviceId =>",e.deviceId,"name =>",e.name]),this.selectAudioDevice=e,this.selectAudioDeviceWatcher.next(e))}setSelectVideoDevice(e){var t;(((t=this.selectVideoDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectVideoDevice.default!==e.default)&&(d("setSelectVideoDevice","","",["deviceId =>",e==null?void 0:e.deviceId,"name =>",e==null?void 0:e.name]),this.selectVideoDevice=e,this.selectVideoDeviceWatcher.next(e))}setSelectSpeakerDevice(e){var t,i,r;(((t=this.selectAudioOutputDevice)==null?void 0:t.deviceId)!==e.deviceId||this.selectAudioOutputDevice.default!==e.default||((i=this.selectAudioOutputDevice)==null?void 0:i.name)!=e.name)&&((r=this.audioPlayer)==null||r.setDevice(e.deviceId),d("setSelectSpeakerDevice","","",["deviceId =>",e.deviceId,"name =>",e==null?void 0:e.name]),this.selectAudioOutputDevice=e,this.selectAudioOutputDeviceWatcher.next(e))}observe(e,t){var i;return!this.observes||!this.observes[e]?null:(i=this.observes[e])==null?void 0:i.subscribe(t)}join(e){return c(this,null,function*(){let t=e.brtc_host;t&&this.setCustomUrl(t),e.ignoreMixer&&(this.ignoreMixer=e.ignoreMixer),this.template_name=e.template_name;try{if(this.boomCore.client)return p("\u91CD\u590D join\uFF0C\u8BF7\u5148\u8C03\u7528 destroy"),Promise.reject(js);this.conferenceMode=e.roomType,this.isBig=e.is_big,d("========================","join info",e.userId,["roomId: ",e.room," roomType: ",e.roomType," roomName: ",e.name]),this.localUser.setup(e.userId,e.userinfo,e.nickname,e.customInfo),this.bmStreamVm.createStreamModel(this.localUser),this.userVM=new je(this.boomCore,this.localUser,this),this.isBig&&(this.userVM.commTimer=1e3),this.roomInfo.originJoinRoomParams=N({},e),this.roomVM=new Qe(this.boomCore,this.userVM,this.roomInfo),this.roomVM.initWithRoom(this),this.chatVM=new qe(this.boomCore,this.userVM,this),this._attachEvents(),yield this.boomCore.join(e).catch(i=>Promise.reject(i)),this.roomInfo.setup(this.boomCore.getRoomInfo());for(let i in this.observes)this.observe(i,()=>{});this.bmStreamVm.startSpeakerDetector(),this.roomInfo.setlock(this.boomCore.client.lock),cr(this.boomCore)}catch(i){return p("join room error","","",[JSON.stringify(i)]),Promise.reject(i)}})}leave(){return c(this,null,function*(){var e,t,i;try{this.bmStreamVm.brtcStream&&((e=this.bmStreamVm.brtcStream)!=null&&e.published)&&(yield this.unpublish(this.bmStreamVm.brtcStream).catch(o=>{p("leave brtc unpublish fail:"+o.message,"unpublish")})),this.pubFailedTimer&&clearTimeout(this.pubFailedTimer),this.pubFailedNum=0,M.removeEmitter(),Xe=!0,(t=this.audioPlayer)==null||t.destroy(),this.bmStreamVm.clearCache(),this.bmStreamVm.canvasTimer&&clearTimeout(this.bmStreamVm.canvasTimer);let r=yield this.boomCore.leave().catch(()=>{p("bloud\u79BB\u4F1A\u5931\u8D25")});for(let o in this.observes)(i=this.observes[o])==null||i.unsubscribe();return this.observes={},r}catch(r){return p("leave room error","","",[JSON.stringify(r)]),Promise.reject(Ts(JSON.stringify(r)))}})}releaseRoom(){return c(this,null,function*(){yield this.boomCore.releaseRoom()})}startRecord(e){return c(this,null,function*(){return yield this.bmStreamVm.startRecord(e)})}stopRecord(){return c(this,null,function*(){return yield this.bmStreamVm.stopRecord()})}sliceRecord(e,t,i){return c(this,null,function*(){return yield this.bmStreamVm.sliceRecord(e,t,i)})}close(){this.bmStreamVm.clearCache(),this.boomCore.close()}setRemoteVideoEnable(e,t){return c(this,null,function*(){yield this.roomVM.setRemoteVideoEnable(e,t).catch(i=>Promise.reject(i))})}setRemoteAudioEnable(e,t,i){return c(this,null,function*(){yield this.roomVM.setRemoteAudioEnable(e,t,i).catch(r=>Promise.reject(r))})}setLocalVideoEnable(e,t){return c(this,null,function*(){yield this.bmStreamVm.setLocalVideoEnable(e,t).catch(i=>Promise.reject(i))})}setLocalAudioEnable(e,t=!1){return c(this,null,function*(){return yield this.bmStreamVm.setLocalAudioEnable(e,t).catch(i=>Promise.reject(i))})}setLocalSpeakerEnable(e){return c(this,null,function*(){yield this.bmStreamVm.muteSpeaker(e).catch(t=>Promise.reject(t))})}_attachEvents(){this.observes=Qi(this.boomCore,this.userVM,this.bmStreamVm,this.chatVM,this)}createSingleLocalStream(){return c(this,arguments,function*(e={video:!0,audio:!0},t,i=!1){var a,n,l,u;let r={video:e.video,audio:e.audio,cameraId:(a=this.selectVideoDevice)==null?void 0:a.deviceId,microphoneId:(n=this.selectAudioDevice)==null?void 0:n.deviceId,sourceType:"camera"};if(e.videoSource&&(r.videoSource=e.videoSource),e.audioSource&&(r.audioSource=e.audioSource),r.echoCancellation=!0,r.noiseSuppression=(l=e.noiseSuppression)!=null?l:!0,r.autoGainControl=!0,this.voiceMode&&(r.audioHint=this.voiceMode,r.noiseSuppression=!1),i){let m=yield Ye((u=this.selectAudioDevice)==null?void 0:u.deviceId);r.audioSource=m.getAudioTracks()[0]}let o=yield this.boomCore.createLocalStream(r,t).catch(m=>(p("create brtc stream error","publish","",[JSON.stringify(m),m==null?void 0:m.message]),Promise.reject(Fs(e.video?"\u6444\u50CF\u5934":"\u9EA6\u514B\u98CE"))));return e.video&&(this.videoEncodeConfig?o.setVideoEncoderConfiguration(this.videoEncodeConfig):this.videoProfile==="720p"?o.setVideoEncoderConfiguration({width:1280,height:720,bitrate:1500,frameRate:25}):o.setVideoProfile(this.videoProfile)),yield this.handleStreamInit(e,o),o})}createPBSingleLocalStream(){return c(this,arguments,function*(e={video:!0,audio:!0},t){var o,a;let i={video:e.video,audio:e.audio,cameraId:(o=this.selectVideoDevice)==null?void 0:o.deviceId,microphoneId:(a=this.selectAudioDevice)==null?void 0:a.deviceId,sourceType:"camera"};i.echoCancellation=!0,i.noiseSuppression=!0,i.autoGainControl=!0,this.voiceMode&&(i.audioHint=this.voiceMode,i.noiseSuppression=!1);let r=yield this.boomCore.createPBLocalStream(i,t).catch(n=>Promise.reject(n));return this.videoProfile==="720p"?r.setVideoEncoderConfiguration({width:1280,height:720,bitrate:1500,frameRate:25}):r.setVideoProfile(this.videoProfile),yield this.handleStreamInit(e,r),r})}handleStreamInit(){return c(this,arguments,function*(e={video:!0,audio:!0},t){try{yield t.init()}catch(i){if(p("brtc init stream failed","publish","",[i==null?void 0:i.message]),String(i).includes("Permission denied")){if(e.video)return Promise.reject(Ns());if(e.audio)return Promise.reject(xs())}else{if(String(i).includes("Could not start video source"))return Promise.reject(Ps());if(String(i).includes("Could not start audio source"))return Promise.reject(Ls())}let r=e.video?"\u6444\u50CF\u5934":"\u9EA6\u514B\u98CE";return Promise.reject(ws(r,i==null?void 0:i.message))}})}subscribe(e,t){return c(this,null,function*(){return this.boomCore.subscribe(e,t)})}unsubscribe(e){return this.boomCore.unsubscribe(e).catch(t=>Promise.reject(t))}publish(e){return new Promise((t,i)=>{this.boomCore.publish(e).then(()=>{d("publish:brtc stream publish success"),this.pubFailedNum=0,t(!0)}).catch(r=>c(this,null,function*(){this.pubFailedNum<=3?(this.pubFailedNum+=1,this.pubFailedTimer&&clearTimeout(this.pubFailedTimer),this.pubFailedTimer=setTimeout(()=>{var o;return p(`publish:local publish stream failed, retry failed num: ${this.pubFailedNum}, msg: ${r.message}`,"publish",(o=this.localUser)==null?void 0:o.userId),this.publish(e).then(t).catch(i)},3e3)):(p("publish:retry publish local stream failed, ubpublish now"),yield this.bmStreamVm.unpublishStream(!0),i(!1))}))})}unpublish(e){return this.boomCore.unpublish(e).catch(t=>Promise.reject(t))}getUser(e){return this.userVM.getUser(e)}changeMaster(e,t=!1){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.changeMaster(e,t).catch(r=>r)})}updateManager(e,t,i=!0){return c(this,null,function*(){return this.roomVM.updateManager(e,t,i).catch(r=>r)})}getMaster(){return this.boomCore.getMaster()}getCreator(){return this.boomCore.getCreator()}getName(){return this.boomCore.getName()}evictUser(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.evictUser(e,t)})}updateUser(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.updateUser(e,t)})}getMsgSeq(){return this.boomCore.getMsgSeq()}getLimits(){return this.boomCore.getLimits()}getSwitch(){return this.boomCore.getSwitch()}syncRoom(){return this.boomCore.syncRoom()}update(e){return this.boomCore.update(e)}getUsers(){return this.userVM.userList}getTotalUsers(){return this.userVM.userList.size}sendMessage(e,t){return this.boomCore.sendMessage(e,t)}customMessage(e,t,i=!1){return this.boomCore.customMessage(e,t,i)}getMessages(e,t){return this.boomCore.getMessages(e,t)}getLocalParticipant(){var t;let e=(t=this.userVM)==null?void 0:t.getLocalUser();return e||(e=this.localUser),e}getAudioOff(){return this.boomCore.getAudioOff()}getSelfOpenAudio(){return this.boomCore.getSelfOpenAudio()}getVideoOff(){return this.boomCore.getVideoOff()}getMsgOff(){return this.boomCore.getMsgOff()}getLock(){return this.boomCore.getLock()}getRoomInfo(){return this.roomInfo}setAudioOff(e,t){return c(this,null,function*(){return yield this.boomCore.setAudioOff(e,t).catch(i=>Promise.reject(ks(`boomCore.setAudioOff error ${JSON.stringify(i)}`)))})}updateRoom(e){return c(this,null,function*(){return this.boomCore.client.update(e)})}setVideoOff(e){return this.boomCore.setVideoOff(e).catch(t=>Promise.reject(_s(`boomCore.setVideoOff error ${JSON.stringify(t)}`)))}setMsgOff(e){return this.boomCore.setMsgOff(e).catch(t=>Promise.reject(Os(`boomCore.setMsgOff error ${JSON.stringify(t)}`)))}setSwitch(e){return this.boomCore.setSwitch(e)}setLock(e){return c(this,null,function*(){return yield this.boomCore.setLock(e),this.boomCore.getLock()})}sendChatMessage(e,t,i){if(!this.chatVM)throw new U(1002,"\u672A\u521D\u59CB\u5316chatVM, \u65E0\u6CD5\u53D1\u9001\u804A\u5929\u4FE1\u606F");return this.chatVM.sendMessage(e,t,i)}getChatMessage(){if(!this.chatVM)throw new U(1002,"\u672A\u521D\u59CB\u5316chatVM, \u65E0\u6CD5\u83B7\u53D6\u804A\u5929\u5BA4\u6D88\u606F");return this.chatVM.messageList}getHistoryMessage(){return c(this,null,function*(){return this.chatVM.getHistoryMessage()})}updateCustomStats(e,t){return this.boomCore.updateCustomStats(_e(N({},e),{pos:"web"}),t).catch(i=>Promise.reject(Gs(`.boomCore.updateCustomStats ${JSON.stringify(i)}`)))}getCustomStats(){return this.boomCore.getCustomStats()}getDuration(){return this.boomCore.getDuration()}checkUserHasMaster(e){return this.userVM.checkUserHasMaster(e)}changeNickName(e,t){return c(this,null,function*(){var i;return(i=this.roomVM)==null?void 0:i.changeNickName(e,t)})}streamModelExits(e){let t=e.userId;return e.isShare?this.bmStreamVm.shareStreamModels.has(t):this.bmStreamVm.streamModels.has(t)}handleStreamTask(e,t=!1){return c(this,null,function*(){if(!this.streamModelExits(e)){I(`streamModel is not exits, userId: ${e.userId}, isShare: ${e.isShare}, ignore`);return}e.stream?this.conferenceMode===1?(yield this.handlePull(e),yield this.handleChangeStreamType(e)):(yield this.bmLiveVM.handlePull(e),yield this.bmLiveVM.handleChangeStreamType(e)):((e.isDisplay||e.isInBig)&&e.bloudStream||e.audioEnable)&&(yield this.addUser2Queue({id:e.userId,isScreen:e.isShare,isWeb:e.isWeb}))})}handlePull(e){return c(this,null,function*(){var t;e.isLocal||(e.isMixer&&(yield this.handleSubscribeSteam(e)),(e.isDisplay!==e.isCurrentDisplay||e.isInBig&&e.pulledStreamType!==e.pulledStreamGoal||!e.hasPulled)&&(e.isCurrentDisplay=e.isDisplay,e.checkCount=0,e.isDisplay||e.isInBig||!e.isDisplay&&(e.audioEnable||(t=e.stream)!=null&&t.getAudioOn())?yield this.handleSubscribeSteam(e):yield this.handleUnsubscribeStream(e)))})}manualSubscribeStreamModel(e){_.addQueue(this.handleStreamTask.bind(this,e),e.streamId,0,e.nickname)}handleUnsubscribe(e){_.addQueue(this.handleUnsubscribeStream.bind(this,e),e.streamId,0,e.nickname)}handleStreamBindElement(e){_.addQueue(this.handlePlaySmall.bind(this,e,!1,!1),`bindElement-${e.userId}-${e.nickname}`,0,e.nickname)}handleStreamBindBigElement(e){_.addQueue(this.handlePlayInBIg.bind(this,e),`bindElement-${e.userId}-${e.nickname}`,0,e.nickname)}handleUnsubscribeStream(e){return c(this,null,function*(){var t,i;e.stream&&((i=(t=e.stream)==null?void 0:t.isSubscribed)!=null&&i.call(t)||e.hasPulled)&&(e.hasPulled=!1,e.pulledStreamType="small",e.isInBig=!1,e.stop(),yield this.unsubscribe(e.stream).then(()=>{var r,o;e.stream&&((r=this.audioPlayer)==null||r.removeStream(e.stream)),e.isSubScribedWatcher.next(!1),d("\u53D6\u6D88\u8BA2\u9605\u6D41\u6210\u529F","",e.userId,[e.nickname,e.isDisplay,e.isCurrentDisplay,(o=e.stream)==null?void 0:o.getStreamId()])}).catch(()=>{p("unsubscribe error")}))})}handleSubscribeSteam(e){return c(this,null,function*(){var t,i;try{e.hasPulled&&e.stream.isSubscribed()?e.isDisplay?(t=e.stream)==null||t.unmuteVideo().then(()=>{d("stream unmute video success ","unmute-video",e.userId,["streamId => ",e.streamId])}):(i=e.stream)==null||i.muteVideo().then(()=>{d("stream mute video success ","mute-video",e.userId,["streamId => ",e.streamId])}):(d("\u5F00\u59CB\u8BA2\u9605","subscribe",e.userId,[e.streamId]),e.hasPulled=!0,yield this.subscribe(e.stream,Qs).then(()=>{var r,o;d("\u8BA2\u9605\u6D41\u7ED3\u675F","subscribe",e.userId,[" nickname =>",e.nickname,"streamId =>",e.streamId,"display =>",e.isDisplay]),e.isDisplay||(r=e.stream)==null||r.muteVideo(),e.stream&&e.audioEnable&&((o=this.audioPlayer)==null||o.addStream(e.stream,!0)),e.pullFailedNum=0,e.isSubScribedWatcher.next(!0),this.bmStreamVm.addToRecorder(e.stream),e.isDisplay&&e.videoEnable&&this.handlePlay(e,!0)}).catch(r=>{var o,a;if(p("\u8BA2\u9605\u6D41\u5931\u8D25","subscribe",e.userId,[" nickname =>",e.nickname,"streamId =>",e.streamId," error => ",JSON.stringify(r)]),e.hasPulled=!1,e.pulledStreamType="small",e.pullFailedNum+=1,(o=e.player)==null||o.destroy(),e.pullFailedNum<=3)this.handlePulledFailed(e);else{e.pullFailedNum=0;let n=e.isShare;try{(a=e.stream)==null||a.destroy()}catch(l){}e.updateStream(void 0,!1,this.bmStreamVm),d("subscribe stream failed, need to reQuery stream","",e.userId,["streamId =>",e.streamId,"hasStream => ",!!e.stream,"isWeb => ",e.isWeb,"isScreen => ",n,"bloudStreamState =>",JSON.stringify(e.bloudStream)]),e.bloudStream&&this.addUser2Queue({id:e.userId,isWeb:e.isWeb,isScreen:n})}}))}catch(r){e.hasPulled=!1,e.pulledStreamType="small",console.error("\u8BA2\u9605\u6D41\u5931\u8D25","",e.userId,e.nickname,"\u9519\u8BEF =>",r)}})}handleChangeStreamType(e){return c(this,null,function*(){var t,i;e.isLocal||e.pulledStreamType!==e.pulledStreamGoal&&((t=e.stream)!=null&&t.isSubscribed())&&((i=e.stream)!=null&&i.isSubscribed()||e.hasPulled)&&(e.pulledStreamType=e.pulledStreamGoal,yield this.boomCore.brtcClient.setRemoteVideoStreamType(e.stream,e.pulledStreamGoal).catch(r=>{p("\u5927\u5C0F\u6D41\u5207\u6362\u5931\u8D25","",e.userId,["error => ",JSON.stringify(r)])}),d("\u5927\u5C0F\u6D41\u5207\u6362\u7ED3\u675F","",e.userId,["nickname =>",e.nickname," isInBig => ",e.isInBig," pulledStreamGoal => ",e.pulledStreamGoal,"pulledStreamType => ",e.pulledStreamType]))})}handlePlay(e,t=!1){return c(this,null,function*(){this.streamModelExits(e)&&(e.stream&&e.isLocal&&!e.isShare||!e.isLocal&&e.stream.isSubscribed())&&(e.isDisplay&&e.playerId&&e.play(t),e.isInBig&&e.bigPlayerId&&e.playInBig(t))})}handlePlaySmall(e,...t){this.streamModelExits(e)&&e.play()}handlePlayInBIg(e){this.streamModelExits(e)&&e.playInBig()}handlePulledFailed(e){let t=e.userId;(e.isShare?this.bmStreamVm.shareStreamModels.has(t):this.bmStreamVm.streamModels.has(t))&&_.addQueue(this.handleQueueTask.bind(this,e),e.streamId,0,e.nickname)}handleStreamConnectError(e){return c(this,null,function*(){var r,o;let{stream:t,isLocal:i}=e;t&&(d("handleStreamConnectError","","",["nickname =>",t.nickname,"streamId => ",t.streamId,"isShare =>",t.isShare,"isLocal => ",i]),t.stream&&(t.stop(),(r=this.audioPlayer)==null||r.removeStream(t.stream)),(o=t.player)==null||o.destroy(),i?t.stream&&(t.isShare?this.bmStreamVm.localShareError.next(Ds()):this.bmStreamVm.localStreamConnectErrorWatcher.next(Vs()),this.netConnecting&&this.networkState.brtc&&this.networkState.bloud?t.isShare?(d("Local share stream has problem, now ,republish"),pt(this,this.bmStreamVm)):(d("brtc \u7F51\u7EDC\u6B63\u5E38\uFF0C\u91CD\u65B0\u63A8\u6D41"),t.stream&&(yield this.republishLocalStream(t.stream))):(p("brtc \u7F51\u7EDC\u8FD8\u6CA1\u6062\u590D\uFF0C\u7B49\u6062\u590D\u4E86\u5728\u91CD\u65B0\u63A8\u6D41 ","",t.userId,["nickname =>",t.nickname,"streamId => ",t.streamId,"isShare =>",t.isShare]),this.streamConnectedErrorQueue.push(e))):this.netConnecting&&this.networkState.brtc?(t.hasPulled=!1,t.pulledStreamType="small",_.addQueue(this.handleQueueTask.bind(this,t),t.streamId,0,t.nickname)):(p("brtc \u7F51\u7EDC\u8FD8\u6CA1\u6062\u590D\uFF0C\u7B49\u6062\u590D\u4E86\u5728\u91CD\u65B0\u62C9\u6D41 ","",t.userId,["nickname =>",t.nickname]),this.streamConnectedErrorQueue.push(e)))})}toggleAudienceSpeaking(e,t){e.permission.setAudio(t);let i={};return e.raiseHand&&(e.raiseHand=!1,i.raiseHand=!1),e.raiseAudioHands&&(e.raiseAudioHands=!1,i.raiseHandsAudio=!1),this.updateUser(e.userId,N({permission:e.permission.get()},i))}updateUserIsGuest(e,t){return c(this,null,function*(){return e.permission.setSubscribe(t),this.updateUser(e.userId,{permission:e.permission.get()})})}managerChangeToGuest(e){this.userVM.managerChangeToGuest(e)}moveUserRoom(e,t=!1,i=!1){return this.boomCore.client.moveUserRoom(e,t,i)}getParticipantNotice(e){this.participantNotice=e}setCustomUrl(e){this.boomCore.setCustomUrl(e)}handleRePushSelf(){return c(this,null,function*(){var t,i;let e=(i=(t=this.getLocalParticipant())==null?void 0:t.getMainStreamModel())==null?void 0:i.stream;e&&(yield this.republishLocalStream(e))})}handleResetOtherStreamStatus(){d("brtc sync-room-completed"),this.audioPlayer.clear(),this.bmStreamVm.streamModels.forEach(e=>{var t;if(!e.isLocal){e.hasPulled=!1,e.pulledStreamType="small";try{(t=e.stream)==null||t.destroy()}catch(i){}e.updateStream(void 0,!1,this.bmStreamVm)}}),this.bmStreamVm.shareStreamModels.forEach(e=>{var t;if(!e.isLocal){e.hasPulled=!1,e.pulledStreamType="small";let i=e.getUser();try{(t=e.stream)==null||t.destroy()}catch(r){}i.removeStream(`${e.userId}${T}`)}}),this.bmStreamVm.shareStreamModels.clear(),this.bmStreamVm.shareStreamModelsWatcher.next(Array.from(this.bmStreamVm.shareStreamModels.values())),this.networkState.brtc=!0,setTimeout(()=>{this.brtcNetEnableWatcher.next(!0),this.streamWSReconnectWatcher.next(!0)},2e3),ce(this)}restartPullUsers(e){e.forEach((t,i)=>{this.addUser2Queue(t)})}addUser2Queue(e){return c(this,null,function*(){var t;if(this.streamQueue.addUser(e),e.force||e.isScreen)this.processUser(e);else{let i=this.bmStreamVm.streamModels.get(e.id);i&&!i.isLocal&&(i.stream||i&&((t=i.bloudStream)!=null&&t.audio||i.bloudStream&&i.isDisplay)&&this.processUser(e))}})}queryBrtcStreams(e){return c(this,null,function*(){return this.boomCore.brtcClient.queryUsers(e)})}handleAddStreams(e){if(this.isInWaitRoom){I("handleAddStreams isInWaitRoom true return");return}e.forEach(t=>{if(z(t)){let i=this.bmStreamVm.shareStreamModels.get(we(t.getUserId().toString()));(!i||i&&!i.stream)&&(i!=null&&i.player&&i.player.destroy(),this.bmStreamVm.remoteStreamPublished(t))}else{let i=this.bmStreamVm.streamModels.get(t.getUserId().toString());i&&!i.stream&&(i!=null&&i.player&&i.player.destroy(),this.bmStreamVm.remoteStreamPublished(t))}})}getForceUser(e){return c(this,null,function*(){yield this.queryBloudUsers([e]),this.userVM.getForceUserWatcher.next(!0)})}queryBloudUsers(e,t=!1,i=!0){return c(this,null,function*(){let{users:r}=yield this.boomCore.queryUsers(e);return this.userVM.addBcUsersMap(r,i,t),r})}getVersion(){return ei.version}};import{BoomError as qs,Logger as zs}from"@hysc/utils";var ec=Te;window.BoomMeeting=Te;window.BoomError=qs;window.BOOMLogger=zs;export{zs as Logger,ec as default};
|