UNPKG

wildfire-im-sdk

Version:
1 lines 124 kB
import*as e from"../../../config.js";import*as s from"../../../platform.js";import*as t from"../../messages/messageContentType";import*as o from"../../model/conversation";import*as r from"../../model/conversationType";import*as i from"../../model/nullUserInfo";import*as n from"../../util/longUtil.js";import*as a from"../engine/avenginekit";import*as l from"../engine/avenginekitproxy";import*as d from"../engine/callEndReason";import*as c from"../engine/callSession";import*as u from"../engine/callState";import*as m from"../engine/participantProfile";import*as h from"../engine/rcEndReason";import*as f from"../engine/rcState";import*as _ from"../engine/subscriber";import*as p from"../engine/videoProfile";import*as S from"../engine/videoType";import*as b from"../messages/addParticipantsMessageContent";import*as g from"../messages/callAnswerMessageContent";import*as j from"../messages/callByeMessageContent";import*as v from"../messages/callModifyMessageContent";import*as y from"../messages/callStartMessageContent";import*as C from"../messages/conferenceChangeModeContent";import*as T from"../messages/muteVideoMessageContent";import*as I from"../messages/rcAcceptInviteMessageContent";import*as E from"../messages/rcEndMessageContent";import*as M from"../messages/rcInviteMessageContent";import*as O from"../messages/rcRequestMessageContent";var R={"./av/internal/avenginekitImpl.js":(e,s,t)=>{t.r(s),t.d(s,{WfcAVEngineKitImpl:()=>C,default:()=>I});var o=t("./node_modules/babel-runtime/core-js/json/stringify.js"),r=t.n(o),i=t("./node_modules/babel-runtime/helpers/extends.js"),n=t("./node_modules/babel-runtime/core-js/map.js"),a=t.n(n),l=t("../../messages/messageContentType"),d=t("../messages/callByeMessageContent"),c=t("../messages/callAnswerMessageContent"),u=t("../messages/callStartMessageContent"),m=t("../messages/callModifyMessageContent"),h=t("../../model/conversationType"),f=t("../engine/callEndReason"),_=t("../engine/avenginekitproxy"),p=t("../engine/callState"),S=t("./av/internal/callSessionImpl.js"),b=t("../messages/addParticipantsMessageContent"),g=t("../engine/avenginekit"),j=t("../../../config.js"),v=t("../messages/rcRequestMessageContent"),y=t("../engine/rcState");class C extends g.default{constructor(){super(),this.sendMessageId=0,this.sendConferenceRequestId=0,this._fixLongSerializedIssue=e=>("string"!=typeof e||"string"==typeof(e=JSON.parse(e))&&(e=JSON.parse(e)),e),this.onSendMessageResult=(e,s)=>{s=this._fixLongSerializedIssue(s);let t=this.sendMessageCallbackMap.get(s.sendMessageId);t&&t(s.error,s.messageUid,s.timestamp),this.sendMessageCallbackMap.delete(s.sendMessageId)},this.onSendConferenceRequestResult=(e,s)=>{console.log("av-c","sendConferenceRequestResult",e,s),s=this._fixLongSerializedIssue(s);let t=this.sendConferenceRequestCallbackMap.get(s.sendConferenceRequestId);t&&(t(s.error,s.response),this.sendConferenceRequestCallbackMap.delete(s.sendConferenceRequestId))},this.onConferenceEvent=(e,s)=>{s=this._fixLongSerializedIssue(s),this.currentSession&&this.currentSession.onConferenceEvent(s)},this.onReceiveMessage=(e,s)=>{if(s=this._fixLongSerializedIssue(s),console.log("av-c","receive voip message ",s),!(s.conversation.type!==h.default.Single&&s.conversation.type!==h.default.Group||1!==s.direction&&s.messageContent.type!==l.default.VOIP_CONTENT_TYPE_ACCEPT&&s.messageContent.type!==l.default.VOIP_CONTENT_TYPE_END)){let e=s.messageContent;if(s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_INPUT_EVENT){if(!T.currentSession||T.currentSession.status===p.default.STATUS_IDLE)return;if(T.currentSession.conversation.type!=s.conversation.type||T.currentSession.conversation.targetId!=s.conversation.targetId)return;let e=s.messageContent;!T.currentSession||T.currentSession.status!==p.default.STATUS_CONNECTING&&T.currentSession.status!==p.default.STATUS_CONNECTED&&T.currentSession.status!==p.default.STATUS_OUTGOING||T.onReceiveRCData(e.data)}else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_SIGNAL){if(!T.currentSession||T.currentSession.status===p.default.STATUS_IDLE)return;let t=s.messageContent;t.callId!==T.currentSession.callId?T.rejectOtherCall(s.conversation,e.callId,null,s.messageUid):!T.currentSession||T.currentSession.status!==p.default.STATUS_CONNECTING&&T.currentSession.status!==p.default.STATUS_CONNECTED&&T.currentSession.status!==p.default.STATUS_OUTGOING||T.onReceiveData(s.from,t.payload)}else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_START||s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_REQUEST){console.log("av-c","callstart",s);let t=s.messageContent.targetIds;if(t.findIndex(e=>e===s.selfUserInfo.uid)<0)return;t=t.filter(e=>e!==s.selfUserInfo.uid),t.push(s.from),T.currentSession&&T.currentSession.status!==p.default.STATUS_IDLE?T.rejectOtherCall(s.conversation,e.callId,t,s.messageUid):(T.currentSession=S.default.newSession(s.conversation,s.from,e.callId,e.audioOnly,T.sessionCallback),T.currentSession.startMsgUid=s.messageUid,T.currentSession.pin=e.pin,T.currentSession.joinTime=s.timestamp,T.currentSession.callExtra=e.extra,s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_REQUEST&&(T.currentSession.rcStatus=y.default.STATUS_INCOMING_REQUEST,T.currentSession.videoMuted=!0),T.currentSession.initSession(!1,s.selfUserInfo,s.participantUserInfos,s.groupMemberUserInfos),T.currentSession.setUserJoinTime(s.from,s.timestamp),s.participantUserInfos.forEach(e=>{T.currentSession.setUserJoinTime(e.uid,s.timestamp)}),T.currentSession.setUserAcceptTime(s.from,s.timestamp),T.currentSession.setState(p.default.STATUS_INCOMING))}else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_ACCEPT||s.messageContent.type===l.default.VOIP_CONTENT_TYPE_ACCEPT_T){if(T.currentSession&&T.currentSession.status!==p.default.STATUS_IDLE){if(e.callId!==T.currentSession.callId)return void(1===s.direction&&T.rejectOtherCall(s.conversation,e.callId,[s.selfUserInfo.uid]));if(0===s.direction&&T.currentSession.status===p.default.STATUS_INCOMING)return void T.currentSession.endCall(f.default.REASON_AcceptByOtherClient);T.currentSession.status===p.default.STATUS_OUTGOING&&T.currentSession.setState(p.default.STATUS_CONNECTING),!T.currentSession.audioOnly&&e.audioOnly&&T.currentSession.setAudioOnly(!0),T.currentSession.setUserAcceptTime(s.from,s.timestamp);let t=T.queueOfferMessageMap.get(s.from);t&&t.forEach(e=>{T.processSignalingMessage(s.from,e)}),T.queueOfferMessageMap.delete(s.from)}}else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_END)if(T.currentSession&&T.currentSession.status!==p.default.STATUS_IDLE&&T.currentSession.callId===e.callId){let t=e.reason;if(1===s.direction){switch(e.reason){case f.default.REASON_Unknown:t=f.default.REASON_Unknown;break;case f.default.REASON_Busy:t=f.default.RemoteBusy;break;case f.default.REASON_SignalError:t=f.default.RemoteNetworkError;break;case f.default.REASON_Hangup:t=f.default.REASON_RemoteHangup;break;case f.default.REASON_MediaError:t=f.default.RemoteNetworkError;break;case f.default.REASON_RemoteHangup:t=f.default.REASON_Hangup;break;case f.default.REASON_OpenCameraFailure:t=f.default.RemoteNetworkError;break;case f.default.REASON_Timeout:t=f.default.RemoteTimeout;break;case f.default.REASON_AcceptByOtherClient:t=f.default.REASON_AcceptByOtherClient;break;case f.default.REASON_AllLeft:t=f.default.REASON_AllLeft;break;case f.default.RemoteBusy:t=f.default.REASON_Busy;break;case f.default.RemoteTimeout:t=f.default.REASON_Timeout;break;case f.default.RemoteNetworkError:t=f.default.REASON_SignalError;break;case f.default.RoomDestroyed:t=f.default.RoomDestroyed;break;case f.default.RoomNotExist:t=f.default.RoomNotExist;break;case f.default.RoomParticipantsFull:t=f.default.RoomParticipantsFull;break;case f.default.Interrupted:t=f.default.RemoteInterrupted;break;default:t=f.default.RemoteNetworkError}T.currentSession.endUserCall(s.from,t)}}else console.log("av-c","invalid bye message, ignore it",T.currentSession,e);else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_MODIFY)T.currentSession&&T.currentSession.status===p.default.STATUS_CONNECTED&&T.currentSession.callId===e.callId&&(e.audioOnly?(T.currentSession.audioOnly=!0,T.currentSession.downgrade2Voice(!0)):console.log("av-c","cannot modify voice call to video call"));else if(s.messageContent.type===l.default.VOIP_Join_Call_Request)T.currentSession&&T.currentSession.status===p.default.STATUS_CONNECTED&&s.messageContent.callId===T.currentSession.callId&&T.currentSession.initiatorId===T.currentSession.selfUserInfo.uid&&T.currentSession.inviteNewParticipants([s.from],s.messageContent.clientId,!0);else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_ADD_PARTICIPANT)if(e.participants.indexOf(s.selfUserInfo.uid)>-1){if(T.currentSession&&T.currentSession.status!==p.default.STATUS_IDLE){if(T.currentSession.callId===s.messageContent.callId)return;let t=[];return t.push(...s.messageContent.participants),s.messageContent.existParticipants&&t.push(...s.messageContent.existParticipants),t.push(s.from),t=t.filter(e=>e!==s.selfUserInfo.uid),void T.rejectOtherCall(s.conversation,e.callId,t)}T.currentSession=S.default.newSession(s.conversation,s.from,e.callId,e.audioOnly,T.sessionCallback),T.currentSession.pin=e.pin,T.currentSession.startMsgUid=s.messageUid;let t=s.participantUserInfos.filter(e=>e.uid!==s.selfUserInfo.uid);T.currentSession.joinTime=s.timestamp,T.currentSession.callExtra=s.messageContent.extra,T.currentSession.initSession(!1,s.selfUserInfo,t,s.groupMemberUserInfos),t.forEach(e=>{T.currentSession.setUserJoinTime(e.uid,s.timestamp)}),T.currentSession.updateExistParticipant(e.existParticipants,s.timestamp),T.currentSession.setState(p.default.STATUS_INCOMING),j.default.ENABLE_MULTI_CALL_AUTO_JOIN&&e.autoAnswer&&T.currentSession.answer(e.audioOnly)}else if(T.currentSession&&T.currentSession.status!==p.default.STATUS_IDLE&&T.currentSession.callId===e.callId){let t=s.participantUserInfos.filter(s=>e.participants.indexOf(s.uid)>-1);T.currentSession.didAddNewParticipants(e.participants,t),t.forEach(e=>{T.currentSession.setUserJoinTime(e.uid,s.timestamp)})}else{let t=[];t.push(...s.messageContent.participants),s.messageContent.existParticipants&&t.push(...s.messageContent.existParticipants),t.push(s.from),t=t.filter(e=>e!==s.selfUserInfo.uid),T.rejectOtherCall(s.conversation,e.callId,t)}else if(s.messageContent.type===l.default.VOIP_CONTENT_TYPE_MUTE_VIDEO){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession.status!==p.default.STATUS_IDLE&&T.currentSession.updateVideoMute(s.from,e.videoMuted)}else if(s.messageContent.type===l.default.CONFERENCE_CONTENT_TYPE_CHANGE_MODE){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession.onRequestChangeMode(e.audience)}else if(s.messageContent.type===l.default.CONFERENCE_CONTENT_TYPE_KICKOFF_MEMBER){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession.onKickoff()}else if(s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_INVITE){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession._onReceiveRemoteControlInvite()}else if(s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_ACCEPT_INVITE){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession._didAcceptRemoteControlInvite()}else if(s.messageContent.type===l.default.VOIP_REMOTE_CONTROL_END){let e=s.messageContent;T.currentSession&&T.currentSession.callId===e.callId&&T.currentSession._didRemoteControlEnd(e.reason)}}},this.startCall=(e,s)=>{let t,o=(s=this._fixLongSerializedIssue(s)).conversation,r=s.audioOnly;if(!this.currentSession){this.currentSession=S.default.newSession(o,s.selfUserInfo.uid,s.callId,r,T.sessionCallback),this.currentSession.pin="";for(let e=0;e<6;e++)this.currentSession.pin+=Math.floor(10*Math.random());this.currentSession.callExtra=s.callExtra,this.currentSession.initSession(!0,s.selfUserInfo,s.participantUserInfos,s.groupMemberUserInfos),this.currentSession.setState(p.default.STATUS_OUTGOING),s.remoteControl?(t=new v.default,this.currentSession.videoMuted=!0,this.currentSession.rcStatus=y.default.STATUS_OUTGOING_REQUEST):(t=new u.default,t.audioOnly=r,t.extra=s.callExtra,t.sdkType=2),t.targetIds=this.currentSession.getParticipantIds(),t.callId=s.callId,t.pin=this.currentSession.pin,this.currentSession.createRoom(e=>{0===e?this.sendSignalMessage(t,this.currentSession.getParticipantIds(),!0,!1,(e,s,o)=>{T.currentSession&&(0!==e?this.currentSession.endCall(f.default.REASON_SignalError):(this.currentSession.startMsgUid=s,console.log("av-c","startMsgUid",this.currentSession.startMsgUid,s),this.currentSession.joinTime=o,this.currentSession.setAcceptTime(o),t.targetIds.forEach(e=>{this.currentSession.setUserJoinTime(e,o)},this)))}):this.currentSession.endCall(f.default.REASON_SignalError)})}},this.startConference=(e,s)=>{let t=(s=this._fixLongSerializedIssue(s)).audioOnly;this.currentSession||(this.currentSession=S.default.newSession(null,s.selfUserInfo.uid,s.callId,t,T.sessionCallback),this.currentSession.pin=s.pin,this.currentSession.host=s.host,this.currentSession.title=s.title,this.currentSession.desc=s.desc,this.currentSession.conference=!0,this.currentSession.defaultAudience=s.audience,this.currentSession.advance=s.advance,this.currentSession.record=s.record,this.currentSession.extra=s.extra,this.currentSession.callExtra=s.callExtra,this.currentSession.videoMuted=s.muteVideo,this.currentSession.audioMuted=s.muteAudio,this.currentSession.initSession(!0,s.selfUserInfo,null,null,!0),this.currentSession.setState(p.default.STATUS_OUTGOING),this.currentSession.createRoom(e=>{0!==e&&this.currentSession.endCall(f.default.REASON_SignalError)}))},this._joinConference=(e,s)=>{this.joinConference(s)},this.joinConference=e=>{e=this._fixLongSerializedIssue(e),this.currentSession||(console.log("av-c","joinConference",e),this.currentSession=S.default.newSession(null,e.selfUserInfo.uid,e.callId,e.audioOnly,T.sessionCallback),this.currentSession.pin=e.pin,this.currentSession.host=e.host,this.currentSession.title=e.title,this.currentSession.desc=e.desc,this.currentSession.defaultAudience=e.audience,this.currentSession.audience=e.audience,this.currentSession.conference=!0,this.currentSession.advance=e.advance,this.currentSession.audioMuted=e.muteAudio,this.currentSession.videoMuted=e.muteVideo,this.currentSession.extra=e.extra,this.currentSession.callExtra=e.callExtra,this.currentSession.initSession(!1,e.selfUserInfo,null,null,!0),this.currentSession.setState(p.default.STATUS_CONNECTING))},this.onConnectionStatusChange=(e,s)=>{T.currentSession&&T.currentSession.onIMConnectionStatusChange(Number(s))}}setup(e){window&&!window._log&&localStorage.getItem("enable_voip_log_with_date")&&(window._log=console.log,console.log=(e,...s)=>{window._log((new Date).toLocaleString(),e,...s)}),this.sendMessageCallbackMap&&console.log("av-c","wfc avengine-conference, setup multi times"),console.log("av-c","wfc avengine-conference"),_.default.listenVoipEvent("message",this.onReceiveMessage),_.default.listenVoipEvent("conferenceEvent",this.onConferenceEvent),_.default.listenVoipEvent("sendMessageResult",this.onSendMessageResult),_.default.listenVoipEvent("sendConferenceRequestResult",this.onSendConferenceRequestResult),_.default.listenVoipEvent("startCall",this.startCall),_.default.listenVoipEvent("startConference",this.startConference),_.default.listenVoipEvent("joinConference",this._joinConference),_.default.listenVoipEvent("connectionStatus",this.onConnectionStatusChange),this.sendMessageCallbackMap=new(a()),this.sendConferenceRequestCallbackMap=new(a()),this.queueOfferMessageMap=new(a()),this.sessionCallback=e}getCurrentSession(){return T.currentSession}inviteNewParticipants(e,s,t,o){let r=T.currentSession;if(!r)return;let i=new b.default;i.callId=r.callId,i.initiator=r.selfUserInfo.uid,console.log("av-c","inviteNewParticipants","initiator "+r.selfUserInfo),i.audioOnly=r.audioOnly,i.pin=s,i.participants=e,i.existParticipants=r.getExistParticipantsStatus(),i.autoAnswer=o,i.clientId=t;let n=[...r.getParticipantIds()];n.push(...e),this.sendSignalMessage(i,n,!0,!1,(s,t,o)=>{if(console.log("av-c","send invite message success"),0!==s)return void console.log("av-c","send invite message error",s);let i=r.groupMemberUserInfos.filter(s=>e.findIndex(e=>e===s.uid)>-1);console.log("av-c","didAddNewParticipants av",e,i),r.didAddNewParticipants(e,i),e.forEach(e=>{r.setUserJoinTime(e,o)})})}updateCallStartMessageContent(e,s){let t={messageUid:(0,i.default)({},e),content:s};_.default.emitToMain("update-call-start-message",t)}clearInviteUnreadStatus(e){}sendSignalMessage(e,s,t,o,r){T.currentSession.conversation&&this.sendSignalMessageEx(T.currentSession.conversation,e,s,t,o,r)}sendSignalMessageEx(e,s,t,o,i,n){t&&i&&t.push(this.currentSession.selfUserInfo.uid);let a={conversation:JSON.parse(r()(e)),content:s.encode(),toUsers:t};console.log("av-c","send signal message",s),n&&(this.sendMessageId++,a.sendMessageId=this.sendMessageId,this.sendMessageCallbackMap.set(this.sendMessageId,n)),_.default.emitToMain("voip-message",a)}sendConferenceRequest(e,s,t,o,r){this.sendConferenceRequestEx(e,s,t,o,this.currentSession.advance,r)}sendConferenceRequestEx(e,s,t,o,r,i){let n={sessionId:e,roomId:s,request:t,data:o,advance:r};i&&(this.sendConferenceRequestId++,n.sendConferenceRequestId=this.sendConferenceRequestId,this.sendConferenceRequestCallbackMap.set(this.sendConferenceRequestId,i)),console.log("av-c","sendConferenceRequest",n),_.default.emitToMain("conference-request",n)}rejectOtherCall(e,s,t,o){let r=new d.default;r.callId=s,r.inviteMsgUid=o,r.reason=f.default.REASON_Busy,console.log("av-c","reject other call",r,t),this.sendSignalMessageEx(e,r,t,!1,!0)}onReceiveRCData(e){console.log("av-c","receive remote control:",e),_.default.emitToMain("rc_receive_input_event",e)}onReceiveData(e,s){let t=JSON.parse(s);if(T.currentSession.getPeerConnection(e))T.processSignalingMessage(e,t);else{console.log("av-c","queue signal",e,t);let s=this.queueOfferMessageMap.get(e);s||(s=[],this.queueOfferMessageMap.set(e,s)),"answer"===t.type||"offer"===t.type?s.unshift(t):s.push(t)}}processSignalingMessage(e,s){console.log("av-c","process remote signal:"+s)}answerCurrentCall(){let e=new c.default;e.audioOnly=T.currentSession.audioOnly,e.callId=T.currentSession.callId,e.inviteMessageUid=T.currentSession.startMsgUid,this.sendSignalMessage(e,this.currentSession.getParticipantIds(),!0,!0,(e,s,t)=>{0===e?this.currentSession.setAcceptTime(t):this.currentSession.endCall(f.default.REASON_SignalError)})}downgrade2VoiceCall(){let e=new m.default;T.currentSession.audioOnly=!0,e.audioOnly=T.currentSession.audioOnly,e.callId=T.currentSession.callId,this.sendSignalMessage(e,this.currentSession.getParticipantIds(),!0,!1)}}const T=new C,I=T},"./av/internal/callSessionImpl.js":(e,s,t)=>{t.r(s),t.d(s,{default:()=>D});var o=t("./node_modules/babel-runtime/core-js/object/keys.js"),r=t.n(o),i=t("./node_modules/babel-runtime/helpers/extends.js"),n=t("./node_modules/babel-runtime/helpers/asyncToGenerator.js"),a=t("./node_modules/babel-runtime/core-js/map.js"),l=t.n(a),d=t("./node_modules/babel-runtime/core-js/json/stringify.js"),c=t.n(d),u=t("../../../config.js"),m=t("../engine/callState"),h=t("./av/internal/avenginekitImpl.js"),f=t("../engine/callEndReason"),_=t("../messages/callByeMessageContent"),p=t("./av/internal/subscriberImpl.js"),S=t("../../../platform.js"),b=t("../engine/callSession"),g=t("../../util/longUtil.js"),j=t("../engine/avenginekit"),v=t("../../model/conversationType"),y=t("../messages/conferenceChangeModeContent"),C=t("../../model/conversation"),T=t("./av/internal/roomErrorCode.js"),I=t("./av/internal/soundMeter.js"),E=t("../engine/avenginekitproxy"),M=t("../messages/muteVideoMessageContent"),O=t("../engine/videoProfile"),R=t("./av/internal/publisherImpl.js"),A=t("./av/internal/screenSharingPublisherImpl.js"),k=t("../../model/nullUserInfo"),N=t("../engine/participantProfile"),V=t("../messages/rcInviteMessageContent"),P=t("../messages/rcAcceptInviteMessageContent"),x=t("../messages/rcEndMessageContent"),w=t("../engine/rcEndReason"),U=t("../engine/rcState");class D extends b.default{constructor(...e){var s;return s=super(...e),this.audience=!1,this.lastActiveTime=0,this.joinTime=0,this.acceptTime=0,this.status=0,this.isAllBusy=!0,this.videoCamera="user",this.rotateAng=0,this._isMuting=!1,this._isSwitchAudience=!1,this.clipboardInterval=0,this._lastRCInputError=0,this.onVoipWindowClose=e=>{this.endCall(f.default.RemoteNetworkError),window.removeEventListener("beforeunload",this.onVoipWindowClose)},this.callTimeout=()=>{let e=(new Date).valueOf();this.callTimer||(this.callTimer=setInterval(this.callTimeout,1e3));let s=(0,g.numberValue)(this.joinTime);if(0!==s){if(this.status===m.default.STATUS_INCOMING){if(e-s>6e4)return void this.endCall(f.default.REASON_Timeout)}else if(this.status!==m.default.STATUS_CONNECTED&&e-s>6e4)return void this.endCall(f.default.RemoteTimeout);this.subscriberMap.forEach((s,t)=>{let o=(0,g.gt)(s.acceptTime,s.joinTime)?s.acceptTime:s.joinTime;s.status!==m.default.STATUS_CONNECTED&&(0,g.gt)(o,0)&&e-(0,g.numberValue)(o)>6e4&&(console.log("av-c","subscriber timeout",e,(0,g.numberValue)(s.acceptTime),(0,g.numberValue)(s.joinTime)),this.endUserCall(t,f.default.RemoteTimeout))})}},this.gotRemoteStream=(e,s)=>{if(this.sessionCallback){let t=this.getScreenSharingUserId(e);this.sessionCallback.didReceiveRemoteVideoTrack(t||e,s.streams[0],null!==t)}let t=s.streams[0];t.onremovetrack=s=>{console.log("av-c","pc remove remote stream",s),this.sessionCallback&&this.sessionCallback.didRemoveRemoteVideoTrack(e)};let o=this.getSubscriber(e);if(t.getAudioTracks().length>0){let e=new I.SoundMeter(window.audioContext);e.connectToSource(t,e=>{console.log("av-c","connect to soundMeter",e)}),o.soundMeter=e}o.stream=s.streams[0],console.log("av-c","pc received remote stream",e,s.streams[0],s.streams[0].getVideoTracks().length,s.streams[0].getAudioTracks().length)},this.onIceCandidate=(e,s,t)=>{if(!t.candidate)return;if(j.default.FORCE_MEDIA_OVER_TCP)return;let o={};if(o.session_id=this.sessionId,e===this.selfUserInfo.uid)o.handle_id=this.handleId;else{let s=this.getSubscriber(e);o.handle_id=s.handleId}let r={};r.candidate=t.candidate.candidate,r.sdpMLineIndex=t.candidate.sdpMLineIndex,r.sdpMid=t.candidate.sdpMid,r.pin=this.pin,o.candidate=r,h.default.sendConferenceRequest(this.sessionId,this.callId,"trickle",c()(o),(e,s)=>{0!==e&&console.log("av-c","conference request, trickle error",e)})},this.onIceStateChange=(e,s,t)=>{if(s){if(console.log("av-c","ICE state change event: ",e,s.iceConnectionState,t),"connected"===s.iceConnectionState){if(this.selfUserInfo.uid===e)return this.connectedTime||(this.connectedTime=(new Date).getTime()),void this.setState(m.default.STATUS_CONNECTED);{let s=this.getSubscriber(e);if(this.audience&&this.setState(m.default.STATUS_CONNECTED),s.status=m.default.STATUS_CONNECTED,this.sessionCallback){let s=this.getScreenSharingUserId(e);this.sessionCallback.didParticipantConnected(s||e,null!==s)}}}"disconnected"===s.iceConnectionState||"failed"===s.iceConnectionState&&console.log("av-c","iceConnectionState failed, endCall")}},this.bytesPrev=0,this.timestampPrev=0,this.requestArray=[],this._lastLocalClipboardData=[],this._lastRemoteClipboardData=[],this._listenDocumentOnFocus=()=>{S.clipboard||this._lastRemoteClipboardData&&navigator.clipboard.writeText(this._lastRemoteClipboardData).then(e=>{this._lastRemoteClipboardData=""}).catch(e=>{})},s}static newSession(e,s,t,o,r){console.log("av-c","newSession");let i=new D;return i.conversation=e,i.initiatorId=s,i.callId=t,i.audioOnly=o,i.sessionCallback=r,window.__callSession=i,i}getParticipantIds(){let e=[];for(const[s,t]of this.subscriberMap)e.push(s);return e}setAcceptTime(e){this.acceptTime||(this.acceptTime=e),this.updateInitiator()}setUserAcceptTime(e,s){console.log("av-c","setUserAcceptTime",e,s);let t=this.getSubscriber(e);t?t.acceptTime=s:console.error("av-c","setUserAcceptTime undefined",e,this.status,this.subscriberMap)}setUserJoinTime(e,s){this.getSubscriber(e).joinTime=s}getSubscriber(e,s){return s&&(e="screen_sharing_"+e),this.subscriberMap.get(e)}getParticipantProfiles(){let e=[];for(const s of this.subscriberMap.values()){let t=new N.default;t.userId=s.userId,t.status=s.status,t.joinTime=s.joinTime,t.acceptTime=s.acceptTime,t.audioMuted=s.audioMuted,t.videoMuted=s.videoMuted,t.audience=s.audience,e.push(t)}return e}getSelfProfile(){let e=new N.default;return e.userId=this.userId,e.status=this.status,e.joinTime=this.joinTime,e.acceptTime=this.acceptTime,e.audioMuted=this.audioMuted,e.videoMuted=this.videoMuted,e.audience=this.audience,e}getPeerConnection(e){return this.subscriberMap.get(e).peerConnection}answer(e,s){this._answer(e,s)}acceptRemoteControlRequest(){this._answer(!1,"")}_answer(e,s){this.status===m.default.STATUS_INCOMING&&(this.setState(m.default.STATUS_CONNECTING),this.audioOnly&&!e&&(e=!0),this.audioOnly=e,this.callExtra=s,h.default.answerCurrentCall())}setState(e){if(this.status!==e&&(this.status!==m.default.STATUS_CONNECTED||e!==m.default.STATUS_CONNECTING)){if(this.status=e,console.log("av-c","set status",e,this.startMsgUid),e===m.default.STATUS_IDLE||e===m.default.STATUS_CONNECTED){if(this.startMsgUid){let s={audioOnly:this.audioOnly};s.status=this.endReason?this.endReason:0,e===m.default.STATUS_CONNECTED?(s.connectTime=(new Date).getTime(),this.startTime=s.connectTime):s.endTime=(new Date).getTime(),h.default.updateCallStartMessageContent(this.startMsgUid,s)}e===m.default.STATUS_CONNECTED?(this.conference?this.notifyMuteState():!this.audioOnly&&this.videoMuted&&this.sendMuteVideoMessage(),this.rcStatus!==U.default.STATUS_INCOMING_REQUEST&&this.rcStatus!==U.default.STATUS_OUTGOING_REQUEST||(this.rcStatus=U.default.STATUS_CONNECTED,this._readClipboard(),this._listenDocumentOnFocus())):this.rcStatus=U.default.STATUS_IDLE,e===m.default.STATUS_IDLE&&clearInterval(this.clipboardInterval)}else e===m.default.STATUS_CONNECTING&&this.joinAndPublish();this.sessionCallback&&this.sessionCallback.didChangeState(e)}}initSession(e,s,t=[],o=[],r=!1){this.moCall=e,this.selfUserInfo=s,this.participantUserInfos=t,this.singleCall=t&&1===t.length,this.groupMemberUserInfos=o;let i=s;!e&&t&&t.length>0&&(i=t.filter(e=>e.uid===this.initiatorId)[0]),this.sessionCallback.onInitial(this,s,i,t,o);let n=[];t&&t.length>0&&t.forEach(e=>{n.push(e.uid)}),this.initSubscriberMap(n),r||(e?(this.setState(m.default.STATUS_OUTGOING),this.startPreview(this.audioOnly)):(this.setState(m.default.STATUS_INCOMING),this.playIncomingRing())),this.callTimeout(),window.AudioContext=window.AudioContext||window.webkitAudioContext,window.audioContext=new AudioContext,setTimeout(()=>{window.addEventListener("beforeunload",this.onVoipWindowClose)},500),this.soundMeterTimer=setInterval(()=>{if(!this.sessionCallback)return;let e=this.cameraPublisher&&this.cameraPublisher.soundMeter;if(e){let s=e.instant.toFixed(2);e.slow.toFixed(2),e.clip;this.sessionCallback.didReportAudioVolume(this.selfUserInfo.uid,Number(s))}this.subscriberMap.forEach((e,s)=>{if(!e.soundMeter)return;let t=e.soundMeter.instant.toFixed(2);e.soundMeter.slow.toFixed(2),e.soundMeter.clip;this.sessionCallback.didReportAudioVolume(s,Number(t))})},100),localStorage.getItem("enable_voip_debug")&&(this.pcStatsTimer=setInterval(()=>{this.subscriberMap.forEach((e,s)=>{let t=e.peerConnection;t&&t.getStats().then(e=>{this.showRemoteStats(s,e)})})},1e3))}initSubscriberMap(e){console.log("av-c","initParticipantClientMap",e),this.subscriberMap||(this.subscriberMap=new(l())),!e||e.length<1||e.forEach(e=>{let s=new p.default(e,this);s.status=m.default.STATUS_INCOMING,this.subscriberMap.set(e,s)},this)}inviteNewParticipants(e,s,t){e.length&&(e=e.filter(e=>e!==this.selfUserInfo.uid&&this.participantUserInfos.findIndex(s=>s.uid===e)<0)).length&&(this.singleCall=!1,h.default.inviteNewParticipants(e,this.pin,s,t))}getExistParticipantsStatus(){let e=[];return e.push({userId:this.selfUserInfo.uid,acceptTime:this.acceptTime?(0,g.numberValue)(this.acceptTime):0,joinTime:this.joinTime?(0,g.numberValue)(this.joinTime):0,videoMuted:this.videoMuted}),this.participantUserInfos.forEach(s=>{let t=this.getSubscriber(s.uid);e.push({userId:t.userId,acceptTime:t.acceptTime?(0,g.numberValue)(t.acceptTime):0,joinTime:t.joinTime?(0,g.numberValue)(t.joinTime):0,videoMuted:t.videoMuted})},this),e}didAddNewParticipants(e,s){e.forEach(e=>{-1===s.findIndex(s=>s.uid===e)&&s.push(new k.default(e))}),console.log("av-c","didAddNewParticipants",e,s),e.forEach(e=>{let s=new p.default(e,this);s.status=m.default.STATUS_INCOMING,this.subscriberMap.set(e,s)},this),s.forEach(e=>{this.participantUserInfos.push(e),this.sessionCallback&&this.sessionCallback.didParticipantJoined(e.uid,!1)},this)}updateExistParticipant(e,s){e.forEach(e=>{let t=this.getSubscriber(e.userId);t.status=m.default.STATUS_INCOMING,t.joinTime=s,t.videoMuted=e.videoMuted,t.acceptTime=e.acceptTime})}updateVideoMute(e,s){let t=this.getSubscriber(e);t&&t.videoMuted!==s&&(t.videoMuted=s,this.sessionCallback&&this.sessionCallback.didVideoMuted(e,s))}defaultVideoConstraints(e){let s;if(e)s={audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1};else{let e=O.default.getVideoProfile(j.default.VIDEO_PROFILE);s={audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:{width:{ideal:e.width},height:{ideal:e.height},frameRate:{ideal:e.fps}}}}return this.audioInputDeviceId&&(s.audio.deviceId=this.audioInputDeviceId),e||(this.videoInputDeviceId?s.video.deviceId=this.videoInputDeviceId:s.video.facingMode=this.videoCamera),console.log("av-c","camera stream constraints",c()(s)),s}createLocalCameraVideoStream(e,s=!0){var t=this;return(0,n.default)((function*(){try{console.log("av-c","createLocalCameraVideoStream",e);const o=yield navigator.mediaDevices.getUserMedia(t.defaultVideoConstraints(e));console.log("av-c","Received local stream",o,o.getVideoTracks().length,e),s&&t.sessionCallback&&!t.videoMuted&&t.sessionCallback.didCreateLocalVideoTrack(o,!1);const r=o.getVideoTracks();e?r&&r.length>0&&(console.log("av-c","audioOnly, stop video track"),r.forEach((function(e){return e.stop()}))):r&&r.length>0&&console.log("av-c",`Using video device: ${r[0].label}`);const i=o.getAudioTracks();return i.length>0&&console.log("av-c",`Using audio device: ${i[0].label}`),o}catch(e){console.error("av-c","getUserMedia error",e)}return console.log("av-c","createLocalCameraVideoStream failed"),null}))()}startPreview(e){var s=this;return(0,n.default)((function*(){console.log("av-c","start preview"),s.conference&&s.audience||(s.previewStream=yield s.createLocalCameraVideoStream(e),s.previewStream||(s.previewStream=yield s.createDummyVideoStream()),s.previewStream||s.endCall(f.default.REASON_MediaError),s.status===m.default.STATUS_IDLE&&s.endMedia())}))()}getDesktopSources(e){return null}startScreenShare(e){var s=this;return(0,n.default)((function*(){if(!s.isScreenSharing()&&!s.audioOnly){if(console.log("av-c","start screen share"),S.currentWindow)s.screenShareStream=yield navigator.mediaDevices.getUserMedia({audio:!1,video:{mandatory:(0,i.default)({chromeMediaSource:"desktop"},e)}}),console.log("av-c","screen share stream",s.screenShareStream);else{console.log("av-c","await screenShareStream");let t={};e&&(t={height:{max:e.maxHeight,min:e.minHeight,ideal:e.idealHeight},width:{max:e.maxWidth,min:e.minWidth,ideal:e.idealWidth},frameRate:e.frameRate}),s.screenShareStream=yield navigator.mediaDevices.getDisplayMedia({audio:!1,video:t}),console.log("av-c","screenShareStream",s.screenShareStream)}if(s.screenSharing=!0,s.sessionCallback&&s.sessionCallback.didCreateLocalVideoTrack(s.screenShareStream,!0),s.screenShareStream.getVideoTracks()[0].addEventListener("ended",(function(){s.stopScreenShare()})),j.default.SCREEN_SHARING_REPLACE_MODE){if(s.cameraPublisher.videoSender){if(yield s.cameraPublisher.videoSender.replaceTrack(s.screenShareStream.getVideoTracks()[0]),!j.default.DISABLE_DUAL_STREAM){let e=s.screenShareStream.getVideoTracks()[0].clone();yield s.cameraPublisher.smallVideoSender.replaceTrack(e)}s.cameraPublisher.stopVideoTrack(s.cameraPublisher.cameraVideoStream)}else console.error("av-c","screen share error, publisher.videoSender is null");s.notifyMuteState()}else s.screenSharingPublisher=new A.default(s),s.screenSharingPublisher.attachAndPublishScreenSharing()}}))()}isScreenSharing(){return!!this.screenShareStream}stopScreenShare(){var e=this;console.log("av-c","stopScreenShare"),j.default.SCREEN_SHARING_REPLACE_MODE?(this.cameraPublisher.stopVideoStream(this.screenShareStream),this.screenShareStream=null,this.screenSharing=!1,this.videoMuted?this.notifyMuteState():(0,n.default)((function*(){e.cameraPublisher.cameraVideoStream=null,yield e.cameraPublisher.createMediaSenders(),e.sessionCallback&&e.sessionCallback.didCreateLocalVideoTrack(e.cameraPublisher.cameraVideoStream,!1)}))()):(this.screenSharingPublisher&&(this.screenSharingPublisher.stopVideoStream(this.screenShareStream),this.screenSharingPublisher.unPublishMedia(),this.screenSharingPublisher.deattach(),this.screenSharingPublisher=null,this.sessionCallback&&(this.sessionCallback.didParticipantLeft(this.selfUserInfo.uid,f.default.REASON_Hangup,!0),this.cameraPublisher&&this.cameraPublisher.cameraVideoStream&&!this.videoMuted&&!this.audioMuted&&this.sessionCallback.didCreateLocalVideoTrack(this.cameraPublisher.cameraVideoStream,!1))),this.screenShareStream=null,this.screenSharing=!1),this.sessionCallback&&this.sessionCallback.didScreenShareEnded()}createPeerConnection(e,s){let t=this.getSelectedSdpSemantics();if(console.log("xxxxx av-c","RTCPeerConnection configuration:",e,t),u.default.ICE_SERVERS&&u.default.ICE_SERVERS.length){t.iceServers=[];for(const e of u.default.ICE_SERVERS)t.iceServers.push({credential:e[2],credentialType:"password",urls:e[0],username:e[1]})}let o=j.default.FORCE_RELAY;void 0===o&&(o=j.default.FORCE_REPLAY),o&&(console.log("av-c","force relay",t.iceServers.length),t.iceTransportPolicy="relay");let r=new RTCPeerConnection(t);if(e!==this.selfUserInfo.uid){let t=this.getSubscriber(e);t.peerConnection=r,t.isInitiator=s}return console.log("av-c","Created local peer connection object pc"),r.addEventListener("icecandidate",s=>this.onIceCandidate(e,r,s)),r.addEventListener("iceconnectionstatechange",s=>this.onIceStateChange(e,r,s)),r.addEventListener("track",s=>this.gotRemoteStream(e,s)),r.addEventListener("connectionstatechange",s=>this.onConnectionStateChange(e,r,s)),console.log("av-c","createPeerConnection",e,this.getSubscriber(e)),r}getSelectedSdpSemantics(){return{bundlePolicy:"max-bundle"}}onConnectionStateChange(e,s,t){console.log("av-c","onConnectionStateChange",e,s,t),s.connectionState}hangup(){console.log("av-c","Ending call"),this.endCall(f.default.REASON_Hangup)}setAudioOnly(e){this.audioOnly=e,this.conference||this.sessionCallback&&this.sessionCallback.didChangeMode(e)}downgrade2Voice(e=!1){this.status===m.default.STATUS_CONNECTED&&(this.cameraPublisher.stopVideoTrack(this.cameraPublisher.cameraVideoStream),e||h.default.downgrade2VoiceCall(),this.setAudioOnly(!0))}downToVoice(){if(console.log("av-c","down to voice"),this.stopIncomingRing(),this.status===m.default.STATUS_INCOMING)return this.setAudioOnly(!0),void this.answerCall(!0);this.status===m.default.STATUS_CONNECTED&&(this.audioOnly||(this.setAudioOnly(!0),h.default.downgrade2VoiceCall()))}muteVideo(e){var s=this;return(0,n.default)((function*(){return yield s.setVideoEnabled(!e)}))()}setVideoEnabled(e){var s=this;return(0,n.default)((function*(){return s.status!==m.default.STATUS_CONNECTED?(console.error("av-c","connecting, can not muteVideo"),!1):s.videoMuted===!e?(console.log("av-c","setVideoEnabled error",s.videoMuted,e),!1):s.audioOnly||s.isScreenSharing()&&j.default.SCREEN_SHARING_REPLACE_MODE?(console.log("av-c","setVideoEnabled error audioOnly, or (isScreenSharing and replace mode)"),!1):s._isMuting?(console.log("av-c","mute operation is still in progress"),!1):(s.videoMuted=!e,console.log("av-c",`setVideoEnabled ${e}, audience ${s.audience}`),s.audience||(s._isMuting=!0,e?(s.cameraPublisher||(s.cameraPublisher=new R.default(s),s.cameraPublisher.handleId=s.handleId),s.cameraPublisher.stopVideoStream(s.cameraPublisher.cameraVideoStream),s.cameraPublisher.cameraVideoStream=null,yield s.cameraPublisher.createMediaSenders()):s.cameraPublisher&&s.cameraPublisher.stopVideoTrack(s.cameraPublisher.cameraVideoStream),s.conference?s.notifyMuteState():s.sendMuteVideoMessage(),s.sessionCallback&&s.sessionCallback.didMuteStateChanged([s.selfUserInfo.uid]),console.log("av-c","mute video end"),s._isMuting=!1),!0)}))()}sendMuteVideoMessage(){let e=new M.default;e.callId=this.callId,e.videoMuted=this.videoMuted,e.existParticipants=this.getExistParticipantsStatus(),h.default.sendSignalMessage(e,this.getParticipantIds(),!0,!1)}muteAudio(e){var s=this;return(0,n.default)((function*(){return yield s.setAudioEnabled(!e)}))()}setAudioEnabled(e){var s=this;return(0,n.default)((function*(){return s.status!==m.default.STATUS_CONNECTED?(console.error("av-c","connecting, can not muteAudio"),!1):s.audioMuted!==!e&&(s._isMuting?(console.log("av-c","mute operation is still in progress"),!1):(s.audioMuted=!e,s.audience||(s._isMuting=!0,console.log("av-c","setAudioEnabled",e),e?s.cameraPublisher&&s.cameraPublisher.cameraVideoStream?s.cameraPublisher.cameraVideoStream.getTracks().forEach((function(e){"audio"===e.kind&&(e.enabled=!0)})):(s.cameraPublisher=new R.default(s),s.cameraPublisher.handleId=s.handleId,yield s.cameraPublisher.createMediaSenders()):s.cameraPublisher&&s.cameraPublisher.stopAudioTrack(s.cameraPublisher.cameraVideoStream),s.conference&&s.status===m.default.STATUS_CONNECTED&&(s.notifyMuteState(),s.sessionCallback&&s.sessionCallback.didMuteStateChanged([s.selfUserInfo.uid])),console.log("av-c","mute audio end"),s._isMuting=!1),!0))}))()}forceEndMedia(){this.endMedia()}endMedia(){if(console.log("av-c","Ending media"),this.setState(m.default.STATUS_IDLE),this.stopIncomingRing(),this.cameraPublisher&&this.cameraPublisher.endMedia(),this.screenSharingPublisher&&this.screenSharingPublisher.endMedia(),this.previewStream){console.log("av-c","stop previewStream");const e=this.previewStream;this.previewStream=null,void 0===e.getTracks?e.stop():e.getTracks().forEach(e=>{console.log("av-c","stop preview track",e.kind,e.id),e.stop()})}}endUserCall(e,s){if(console.log("av-c","endUserCall",e,s),e===this.selfUserInfo.uid)return void this.endCall(s);if(!this.conference&&e===this.initiatorId){let t=!1;for(const[s,o]of this.subscriberMap)if(console.log("av-c","endUserCall acceptTime",o.acceptTime),o.acceptTime&&(0,g.gt)(o.acceptTime,0)&&e!==s){t=!0;break}if(t=t||this.acceptTime&&this.acceptTime&&(0,g.gt)(this.acceptTime,0),!t)return void this.endCall(s)}let t=this.getSubscriber(e);if(this.subscriberMap.delete(e),this.participantUserInfos&&(this.participantUserInfos=this.participantUserInfos.filter(s=>s.uid!==e)),t){if(t.peerConnection){t.peerConnection.getSenders().forEach(e=>t.peerConnection.removeTrack(e)),t.peerConnection.close(),t.peerConnection=null}if(e===this.initiatorId&&this.updateInitiator(),this.sessionCallback){let t=this.getScreenSharingUserId(e);this.sessionCallback.didParticipantLeft(t||e,s,null!==t)}}this.isAllBusy=this.isAllBusy&&s===f.default.RemoteBusy,this.conference||0!==this.subscriberMap.size||(0===this.conversation.type||this.singleCall?this.endCall(s):this.endCall(this.isAllBusy?f.default.RemoteBusy:f.default.REASON_AllLeft))}leaveConference(e){this.conference?this.endCall(f.default.REASON_Hangup,e):this.endCall(f.default.REASON_Hangup)}endCall(e,s){if(console.log("av-c","endCall ---- ",e,(new Error).stack),this.endReason=e,this.status===m.default.STATUS_IDLE)return;if(this.setState(m.default.STATUS_IDLE),!this.conference&&e!==f.default.REASON_AcceptByOtherClient&&e!==f.default.REASON_AllLeft&&e!==f.default.REASON_RemoteHangup&&this.getParticipantIds().length>0){let s=new _.default;s.callId=this.callId,s.inviteMsgUid=this.startMsgUid,s.reason=e,h.default.sendSignalMessage(s,this.getParticipantIds(),!1,!0)}if(e!==f.default.REASON_AcceptByOtherClient){let t={};t.handle_id=this.handleId,(s||e===f.default.REASON_AllLeft||this.conversation&&this.conversation.type===v.default.Single&&[f.default.RemoteBusy,f.default.REASON_RemoteHangup,f.default.RemoteTimeout].indexOf(e)>-1)&&(t.destroy=!0),console.log("av-c","leave",c()(t)),h.default.sendConferenceRequest(this.sessionId,this.callId,"leave",c()(t),(e,s)=>{0!==e&&console.log("av-c","conference request, leave error",e)})}this.callId,this.audioOnly,this.pin,this.host,this.title,this.desc,this.audience,this.advance;this.keepAlive(!1),this.endTime=(new Date).valueOf();for(const[e,s]of this.subscriberMap)s.peerConnection&&(s.peerConnection.close(),s.peerConnection=null);h.default.currentSession=null,clearInterval(this.callTimer),clearInterval(this.soundMeterTimer),this.pcStatsTimer&&clearInterval(this.pcStatsTimer),this.endMedia(),this.sessionCallback&&this.sessionCallback.didCallEndWithReason(e)}defaultPublishMediaConstraints(){return{offerToReceiveAudio:!1,offerToReceiveVideo:!1}}defaultSubscribeMediaConstraints(){return{offerToReceiveAudio:!0,offerToReceiveVideo:!0}}restartPublishConstrains(){return{iceRestart:!0,offerToReceiveAudio:!1,offerToReceiveVideo:!1}}createRoom(e){let s={participants:9};s.pin=this.pin,s.publishers=this.audioOnly?j.default.MAX_AUDIO_PARTICIPANT_COUNT:j.default.MAX_VIDEO_PARTICIPANT_COUNT,this.conference||(s.is_private=!0),this.record&&(s.record=!0),console.log("av-c","create room"),h.default.sendConferenceRequest(this.sessionId,this.callId,"create_room",c()(s),(s,t)=>{if(console.log("av-c","create_room res",s,t),0!==s)return void e(s);let o=JSON.parse(t);this.sessionId=o.session_id,this.handleId=o.handle_id;let r=o.data;this.callId,r.room,this.keepAlive(!0),e(0),this.conference&&this.setState(m.default.STATUS_CONNECTING)})}onConferenceEvent(e){let s;if(s="string"==typeof e?JSON.parse(e):e,console.log("av-c","onConferenceEvent",c()(e)),this.sessionId!==s.session_id)return void console.log("av-c","on conference event, unknown sessionId",this.sessionId,s.session_id);let t=s.sender;if(t>0&&this.screenSharingPublisher&&this.screenSharingPublisher.handleId===t)return;let o=s.data,r=o?o.videoroom:null;if("event"===r){let e=o.publishers;this.onPublish(e);let s=o.unpublished;s&&this.onUnpublish(s);let t=o.leaving;t&&("ok"===t&&"kicked"===o.reason?this.onLeave(this.selfUserInfo.uid):this.onLeave(t));let r=o.kicked;r&&this.onLeave(r);let i=o.joining;i&&this.onJoining([i]);let n=o.attendees;this.onJoining(n)}else if("destroyed"===r)this.endCall(f.default.RoomDestroyed);else if("participants"===r){let e=o.attendees;if(e&&e.length>0){let s=e.map(e=>({id:e}));this.onJoining(s)}let s=o.leavings;s&&s.length>0&&s.forEach(e=>{this.onLeave(e)})}else if("mute"===r){let e=o.mute;this.onMute(e)}else if("slowlink"===r){let e=s.handle_id;this.onSlowLink(this.sessionId,e,o)}else{"hangup"===s.janus||console.log("av-c","unknown event")}}keepAlive(e){if(e){if(this.keepAliveTimer)return;this.lastActiveTime=(new Date).getTime(),this.keepAliveTimer=setInterval(()=>{h.default.sendConferenceRequest(this.sessionId,this.callId,"keepalive","",(e,s)=>{let t=(new Date).getTime();if(0===e)this.lastActiveTime=t;else{if(253===e||61===e)return console.error("av-c","keepalive error",e),void this.endCall(f.default.REASON_SignalError);this.lastActiveTime>0&&t-this.lastActiveTime>6e4&&(console.error("av-c","keepalive not response",t-this.lastActiveTime),this.endCall(f.default.REASON_SignalError))}})},2e4)}else this.keepAliveTimer&&(clearInterval(this.keepAliveTimer),this.keepAliveTimer=0)}joinAndPublish(){let e={};e.handle_id=this.handleId,e.user_id=this.selfUserInfo.uid,e.pin=this.pin,this.callExtra&&(e.extra=this.callExtra),h.default.sendConferenceRequest(this.sessionId,this.callId,"join_pub",c()(e),(e,s)=>{if(console.log("av-c","join_pub",e,s),0!==e)return void this.endCall(f.default.REASON_SignalError);let t=JSON.parse(s),o=t.data,r=o.error_code;if(r>0)return console.log("av-c","conference request, join_pub error",r),void(r===T.default.JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM?this.endCall(f.default.RoomNotExist):r===T.default.JANUS_VIDEOROOM_ERROR_ID_EXISTS&&setTimeout(()=>{this.status!==m.default.STATUS_IDLE&&(console.log("av-c","rejoin"),this.joinAndPublish())},500));this.sessionId=t.session_id,this.handleId=t.handle_id;let i=o.publishers;this.onPublish(i);o.id,o.videoroom;this.privateId=o.private_id;o.description,o.room;let n=o.attendees;this.onJoining(n),this.audience?this.setState(m.default.STATUS_CONNECTED):(this.cameraPublisher=new R.default(this),this.cameraPublisher.handleId=this.handleId,this.cameraPublisher.publishMedia()),this.keepAlive(!0)})}updateInitiator(){let e,s=(new Date).getTime()+864e5;(0,g.gt)(this.acceptTime,0)&&(s=this.acceptTime,e=this.selfUserInfo.uid),this.subscriberMap.forEach(t=>{(0,g.gt)(t.acceptTime,0)&&(0,g.gt)(s,t.acceptTime)&&(s=t.acceptTime,e=t.userId)});let t=this.initiatorId;this.initiatorId=e,this.subscriberMap.forEach(e=>{e.isInitiator=this.initiatorId===e.userId}),t!==e&&e!==this.selfUserInfo.uid&&this.sessionCallback&&this.sessionCallback.didChangeInitiator(this.initiatorId)}onParticipantPublish(e){e.talking;let s=e.id;if(this.isSelfScreenSharing(s))return;let t=e.display,o=!0,r=e.streams;for(const[e,i]of this.subscriberMap)if(e===s){i.streams(r),i.callExtra=t,i.subscribe(),i.audience=!1,o=!1;break}if(o){let e=new p.default(s,this);this.subscriberMap.set(e.userId,e);let o=(new Date).valueOf();if(this.setUserAcceptTime(e.userId,o),this.setUserJoinTime(e.userId,o),e.status=m.default.STATUS_CONNECTED,e.audience=!1,e.callExtra=t,e.streams(r),e.subscribe(),this.sessionCallback){let s=this.getScreenSharingUserId(e.userId);this.sessionCallback.didParticipantJoined(s||e.userId,null!==s),this.reportAudienceChanged(e.userId,!1)}}else this.reportAudienceChanged(s,!1);let i=this.subscriberMap.get(s);(i.videoMuted||i.audioMuted)&&this.sessionCallback&&this.sessionCallback.didMuteStateChanged([s])}onPublish(e){if(console.log("av-c","onPublish",e),e)for(const s of e)this.onParticipantPublish(s)}onJoining(e){if(e){console.log("av-c","onJoining",e);for(const s of e){let e=s.id;if(this.isSelfScreenSharing(e))continue;let t=!0,o=s.display;for(const[s,r]of this.subscriberMap)if(s===e){r.audience=!0,r.callExtra=o,t=!1;break}if(t){let s=new p.default(e,this);this.subscriberMap.set(s.userId,s);let t=(new Date).valueOf();if(this.setUserAcceptTime(s.userId,t),this.setUserJoinTime(s.userId,t),s.status=m.default.STATUS_CONNECTED,s.audience=!0,s.callExtra=o,this.sessionCallback){let e=this.getScreenSharingUserId(s.userId);this.sessionCallback.didParticipantJoined(e||s.userId,null!==e)}}}}}onUnpublish(e){for(const[s,t]of this.subscriberMap)if(s===e){t.audience=!0,t.videoMuted=!1,t.audioMuted=!1,t.peerConnection&&(t.peerConnection.close(),t.peerConnection=null),t.handleId=0;break}this.conference&&e!==this.selfUserInfo.uid&&this.reportAudienceChanged(e,!0)}reportAudienceChanged(e,s){let t=this.getScreenSharingUserId(e);this.sessionCallback&&this.sessionCallback.didChangeType(t||e,s,null!==t)}onSlowLink(e,s,t){if(!this.sessionCallback)return;let o=t.media,r=t.uplink,i=t.lost;if(this.handleId===s)this.sessionCallback.didMediaLostPacket(o,i,!1);else if(this.screenSharingPublisher&&this.screenSharingPublisher.handleId===s)this.sessionCallback.didMediaLostPacket(o,i,!0);else for(const[e,t]of this.subscriberMap)if(t.handleId===s){if(e.startsWith("screen_sharing_")){let s=e.substr("screen_sharing_".length);this.sessionCallback.didUserMediaLostPacket(s,o,i,r,!0)}else this.sessionCallback.didUserMediaLostPacket(e,o,i,r,!1);break}}onLeave(e){this.getSubscriber(e)?this.endUserCall(e,f.default.REASON_RemoteHangup):e===this.selfUserInfo.uid&&this.endCall(f.default.REASON_Hangup,!1)}mediaStream(){return this.screenShareStream?this.screenShareStream:this.cameraVideoStream}requestChangeMode(e,s){let t=new y.default(this.callId,s),o=new C.default(v.default.Single,e,0);h.default.sendSignalMessageEx(o,t,this.getParticipantIds(),!1,!1)}onRequestChangeMode(e){this.switchAudience(e)}onKickoff(){this.leaveConference(!1)}switchAudience(e){var s=this;return(0,n.default)((function*(){console.log("av-c","switchAudience",e),s.conference&&(s._isSwitchAudience||e===s.audience?console.log("av-c",`switchAudience isSwitching ${s._isSwitchAudience}`):(s._isSwitchAudience=!0,e?s.audience||(s.screenSharingPublisher&&(yield s.screenSharingPublisher.unPublishMedia(),s.screenSharingPublisher.screenShareStream=null),s.cameraPublisher&&(yield s.cameraPublisher.unPublishMedia(),s.cameraPublisher.cameraVideoStream=null),s.reportAudienceChanged(s.selfUserInfo.uid,!0),s.audience=!0):(s.cameraPublisher||(s.cameraPublisher=new R.default(s),s.cameraPublisher.handleId=s.handleId),yield s.cameraPublisher.publishMedia(),s.reportAudienceChanged(s.selfUserInfo.uid,!1),s.notifyMuteState(),s.audience=!1),s._isSwitchAudience=!1))}))()}onMute(e){let s=[];this.subscriberMap.forEach((t,o)=>{let r=e[o],i=!1,n=!1;r&&(i=!!r.hasOwnProperty("a")&&r.a,n=!!r.hasOwnProperty("v")&&r.v),t.videoMuted===n&&t.audioMuted===i||(t.videoMuted=n,t.audioMuted=i,t.audience||s.push(o))}),s=s.filter(e=>e!==this.selfUserInfo.uid),s.length>0&&this.sessionCallback&&this.sessionCallback.didMuteStateChanged(s)}notifyMuteState(){if(!this.conference||this.status===m.default.STATUS_IDLE)return;let e={handle_id:this.handleId,a:this.audioMuted};j.default.SCREEN_SHARING_REPLACE_MODE?e.v=this.videoMuted&&!this.isScreenSharing():e.v=this.videoMuted,h.default.sendConferenceRequest(this.sessionId,this.callId,"mute",c()(e),(e,s)=>{console.log("av-c","mute res",e,s)})}kickoffParticipant(e,s,t){if(this.status===m.default.STATUS_IDLE&&t&&t(-1),this.getSubscriber(e)){let o={handle_id:this.handleId,user:e};h.default.sendConferenceRequest(this.sessionId,this.callId,"kick",c()(o),(e,o)=>{console.log("av-c