tjc-sdk
Version:
TIANJI IM SDK
1 lines • 114 kB
JavaScript
import*as e from"../../dist/av/config.js";import"../../dist/av/platform.js";import*as t from"../../messages/messageContentType.js";import*as o from"../../model/conversation.js";import*as i from"../../model/conversationType.js";import*as r from"../../model/nullUserInfo.js";import*as n from"../../util/longUtil.js";import*as l from"../engine/avenginekit.js";import*as d from"../engine/avenginekitproxy.js";import*as u from"../engine/callEndReason.js";import*as a from"../engine/callSession.js";import*as c from"../engine/callState.js";import*as h from"../engine/participantProfile.js";import*as m from"../engine/rcEndReason.js";import*as j from"../engine/rcState.js";import*as f from"../engine/subscriber.js";import*as _ from"../engine/videoProfile.js";import*as b from"../engine/videoType.js";import*as y from"../messages/addParticipantsMessageContent.js";import*as v from"../messages/callAnswerMessageContent.js";import*as p from"../messages/callByeMessageContent.js";import*as g from"../messages/callModifyMessageContent.js";import*as w from"../messages/callStartMessageContent.js";import*as S from"../messages/conferenceChangeModeContent.js";import*as k from"../messages/muteVideoMessageContent.js";import*as M from"../messages/rcAcceptInviteMessageContent.js";import*as C from"../messages/rcEndMessageContent.js";import*as T from"../messages/rcInviteMessageContent.js";import*as I from"../messages/rcRequestMessageContent.js";var O={"./av/internal/avenginekitImpl.js":(e,s,t)=>{t.r(s),t.d(s,{TjcAVEngineKitImpl:()=>S,default:()=>M});var o=t("./node_modules/babel-runtime/core-js/json/stringify.js"),i=t.n(o),r=t("./node_modules/babel-runtime/helpers/extends.js"),n=t("./node_modules/babel-runtime/core-js/map.js"),l=t.n(n),d=t("../../messages/messageContentType"),u=t("../messages/callByeMessageContent"),a=t("../messages/callAnswerMessageContent"),c=t("../messages/callStartMessageContent"),h=t("../messages/callModifyMessageContent"),m=t("../../model/conversationType"),j=t("../engine/callEndReason"),f=t("../engine/avenginekitproxy"),_=t("../engine/callState"),b=t("./av/internal/callSessionImpl.js"),y=t("../messages/addParticipantsMessageContent"),v=t("../engine/avenginekit"),p=t("../../../config.js"),g=t("../messages/rcRequestMessageContent"),w=t("../engine/rcState");class S extends v.default{constructor(){super(),this.sendMessageId=0,this.sendConferenceRequestId=0,this.t=e=>("string"!=typeof e||"string"==typeof(e=JSON.parse(e))&&(e=JSON.parse(e)),e),this.onSendMessageResult=(e,s)=>{s=this.t(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)=>{s=this.t(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.t(s),this.currentSession&&this.currentSession.onConferenceEvent(s)},this.onReceiveMessage=(e,s)=>{if(!((s=this.t(s)).conversation.type!==m.default.Single&&s.conversation.type!==m.default.Group||1!==s.direction&&s.messageContent.type!==d.default.VOIP_CONTENT_TYPE_ACCEPT&&s.messageContent.type!==d.default.VOIP_CONTENT_TYPE_END)){let e=s.messageContent;if(s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_INPUT_EVENT){if(!k.currentSession||k.currentSession.status===_.default.STATUS_IDLE)return;if(k.currentSession.conversation.type!=s.conversation.type||k.currentSession.conversation.targetId!=s.conversation.targetId)return;let e=s.messageContent;!k.currentSession||k.currentSession.status!==_.default.STATUS_CONNECTING&&k.currentSession.status!==_.default.STATUS_CONNECTED&&k.currentSession.status!==_.default.STATUS_OUTGOING||k.onReceiveRCData(e.data)}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_SIGNAL){if(!k.currentSession||k.currentSession.status===_.default.STATUS_IDLE)return;let t=s.messageContent;t.callId!==k.currentSession.callId?k.rejectOtherCall(s.conversation,e.callId,null,s.messageUid):!k.currentSession||k.currentSession.status!==_.default.STATUS_CONNECTING&&k.currentSession.status!==_.default.STATUS_CONNECTED&&k.currentSession.status!==_.default.STATUS_OUTGOING||k.onReceiveData(s.from,t.payload)}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_START||s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_REQUEST){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),k.currentSession&&k.currentSession.status!==_.default.STATUS_IDLE?k.rejectOtherCall(s.conversation,e.callId,t,s.messageUid):(k.currentSession=b.default.newSession(s.conversation,s.from,e.callId,e.audioOnly,k.sessionCallback),k.currentSession.startMsgUid=s.messageUid,k.currentSession.pin=e.pin,k.currentSession.joinTime=s.timestamp,k.currentSession.callExtra=e.extra,s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_REQUEST&&(k.currentSession.rcStatus=w.default.STATUS_INCOMING_REQUEST,k.currentSession.videoMuted=!0),k.currentSession.initSession(!1,s.selfUserInfo,s.participantUserInfos,s.groupMemberUserInfos),k.currentSession.setUserJoinTime(s.from,s.timestamp),s.participantUserInfos.forEach((e=>{k.currentSession.setUserJoinTime(e.uid,s.timestamp)})),k.currentSession.setUserAcceptTime(s.from,s.timestamp),k.currentSession.setState(_.default.STATUS_INCOMING))}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_ACCEPT||s.messageContent.type===d.default.VOIP_CONTENT_TYPE_ACCEPT_T){if(k.currentSession&&k.currentSession.status!==_.default.STATUS_IDLE){if(e.callId!==k.currentSession.callId)return void(1===s.direction&&k.rejectOtherCall(s.conversation,e.callId,[s.selfUserInfo.uid]));if(0===s.direction&&k.currentSession.status===_.default.STATUS_INCOMING)return void k.currentSession.endCall(j.default.REASON_AcceptByOtherClient);k.currentSession.status===_.default.STATUS_OUTGOING&&k.currentSession.setState(_.default.STATUS_CONNECTING),!k.currentSession.audioOnly&&e.audioOnly&&k.currentSession.setAudioOnly(!0),k.currentSession.setUserAcceptTime(s.from,s.timestamp);let t=k.queueOfferMessageMap.get(s.from);t&&t.forEach((e=>{k.processSignalingMessage(s.from,e)})),k.queueOfferMessageMap.delete(s.from)}}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_END){if(k.currentSession&&k.currentSession.status!==_.default.STATUS_IDLE&&k.currentSession.callId===e.callId){let t=e.reason;if(1===s.direction){switch(e.reason){case j.default.REASON_Unknown:t=j.default.REASON_Unknown;break;case j.default.REASON_Busy:t=j.default.RemoteBusy;break;case j.default.REASON_SignalError:t=j.default.RemoteNetworkError;break;case j.default.REASON_Hangup:t=j.default.REASON_RemoteHangup;break;case j.default.REASON_MediaError:t=j.default.RemoteNetworkError;break;case j.default.REASON_RemoteHangup:t=j.default.REASON_Hangup;break;case j.default.REASON_OpenCameraFailure:t=j.default.RemoteNetworkError;break;case j.default.REASON_Timeout:t=j.default.RemoteTimeout;break;case j.default.REASON_AcceptByOtherClient:t=j.default.REASON_AcceptByOtherClient;break;case j.default.REASON_AllLeft:t=j.default.REASON_AllLeft;break;case j.default.RemoteBusy:t=j.default.REASON_Busy;break;case j.default.RemoteTimeout:t=j.default.REASON_Timeout;break;case j.default.RemoteNetworkError:t=j.default.REASON_SignalError;break;case j.default.RoomDestroyed:t=j.default.RoomDestroyed;break;case j.default.RoomNotExist:t=j.default.RoomNotExist;break;case j.default.RoomParticipantsFull:t=j.default.RoomParticipantsFull;break;case j.default.Interrupted:t=j.default.RemoteInterrupted;break;default:t=j.default.RemoteNetworkError}k.currentSession.endUserCall(s.from,t)}}}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_MODIFY)k.currentSession&&k.currentSession.status===_.default.STATUS_CONNECTED&&k.currentSession.callId===e.callId&&e.audioOnly&&(k.currentSession.audioOnly=!0,k.currentSession.downgrade2Voice(!0));else if(s.messageContent.type===d.default.VOIP_Join_Call_Request)k.currentSession&&k.currentSession.status===_.default.STATUS_CONNECTED&&s.messageContent.callId===k.currentSession.callId&&k.currentSession.initiatorId===k.currentSession.selfUserInfo.uid&&k.currentSession.inviteNewParticipants([s.from],s.messageContent.clientId,!0);else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_ADD_PARTICIPANT)if(e.participants.indexOf(s.selfUserInfo.uid)>-1){if(k.currentSession&&k.currentSession.status!==_.default.STATUS_IDLE){if(k.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 k.rejectOtherCall(s.conversation,e.callId,t)}k.currentSession=b.default.newSession(s.conversation,s.from,e.callId,e.audioOnly,k.sessionCallback),k.currentSession.pin=e.pin,k.currentSession.startMsgUid=s.messageUid;let t=s.participantUserInfos.filter((e=>e.uid!==s.selfUserInfo.uid));k.currentSession.joinTime=s.timestamp,k.currentSession.callExtra=s.messageContent.extra,k.currentSession.initSession(!1,s.selfUserInfo,t,s.groupMemberUserInfos),t.forEach((e=>{k.currentSession.setUserJoinTime(e.uid,s.timestamp)})),k.currentSession.updateExistParticipant(e.existParticipants,s.timestamp),k.currentSession.setState(_.default.STATUS_INCOMING),p.default.ENABLE_MULTI_CALL_AUTO_JOIN&&e.autoAnswer&&k.currentSession.answer(e.audioOnly)}else if(k.currentSession&&k.currentSession.status!==_.default.STATUS_IDLE&&k.currentSession.callId===e.callId){let t=s.participantUserInfos.filter((s=>e.participants.indexOf(s.uid)>-1));k.currentSession.didAddNewParticipants(e.participants,t),t.forEach((e=>{k.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)),k.rejectOtherCall(s.conversation,e.callId,t)}else if(s.messageContent.type===d.default.VOIP_CONTENT_TYPE_MUTE_VIDEO){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.status!==_.default.STATUS_IDLE&&k.currentSession.updateVideoMute(s.from,e.videoMuted)}else if(s.messageContent.type===d.default.CONFERENCE_CONTENT_TYPE_CHANGE_MODE){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.onRequestChangeMode(e.audience)}else if(s.messageContent.type===d.default.CONFERENCE_CONTENT_TYPE_KICKOFF_MEMBER){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.onKickoff()}else if(s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_INVITE){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.l()}else if(s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_ACCEPT_INVITE){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.u()}else if(s.messageContent.type===d.default.VOIP_REMOTE_CONTROL_END){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.h(e.reason)}}},this.startCall=(e,s)=>{let t,o=(s=this.t(s)).conversation,i=s.audioOnly;if(!this.currentSession){this.currentSession=b.default.newSession(o,s.selfUserInfo.uid,s.callId,i,k.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(_.default.STATUS_OUTGOING),s.remoteControl?(t=new g.default,this.currentSession.videoMuted=!0,this.currentSession.rcStatus=w.default.STATUS_OUTGOING_REQUEST):(t=new c.default,t.audioOnly=i,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)=>{k.currentSession&&(0!==e?this.currentSession.endCall(j.default.REASON_SignalError):(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(j.default.REASON_SignalError)}))}},this.startConference=(e,s)=>{let t=(s=this.t(s)).audioOnly;this.currentSession||(this.currentSession=b.default.newSession(null,s.selfUserInfo.uid,s.callId,t,k.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(_.default.STATUS_OUTGOING),this.currentSession.createRoom((e=>{0!==e&&this.currentSession.endCall(j.default.REASON_SignalError)})))},this.m=(e,s)=>{this.joinConference(s)},this.joinConference=e=>{e=this.t(e),this.currentSession||(this.currentSession=b.default.newSession(null,e.selfUserInfo.uid,e.callId,e.audioOnly,k.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(_.default.STATUS_CONNECTING))},this.onConnectionStatusChange=(e,s)=>{k.currentSession&&k.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,f.default.listenVoipEvent("message",this.onReceiveMessage),f.default.listenVoipEvent("conferenceEvent",this.onConferenceEvent),f.default.listenVoipEvent("sendMessageResult",this.onSendMessageResult),f.default.listenVoipEvent("sendConferenceRequestResult",this.onSendConferenceRequestResult),f.default.listenVoipEvent("startCall",this.startCall),f.default.listenVoipEvent("startConference",this.startConference),f.default.listenVoipEvent("joinConference",this.m),f.default.listenVoipEvent("connectionStatus",this.onConnectionStatusChange),this.sendMessageCallbackMap=new(l()),this.sendConferenceRequestCallbackMap=new(l()),this.queueOfferMessageMap=new(l()),this.sessionCallback=e}getCurrentSession(){return k.currentSession}inviteNewParticipants(e,s,t,o){let i=k.currentSession;if(!i)return;let r=new y.default;r.callId=i.callId,r.initiator=i.selfUserInfo.uid,r.audioOnly=i.audioOnly,r.pin=s,r.participants=e,r.existParticipants=i.getExistParticipantsStatus(),r.autoAnswer=o,r.clientId=t;let n=[...i.getParticipantIds()];n.push(...e),this.sendSignalMessage(r,n,!0,!1,((s,t,o)=>{if(0!==s)return;let r=i.groupMemberUserInfos.filter((s=>e.findIndex((e=>e===s.uid))>-1));i.didAddNewParticipants(e,r),e.forEach((e=>{i.setUserJoinTime(e,o)}))}))}updateCallStartMessageContent(e,s){let t={messageUid:(0,r.default)({},e),content:s};f.default.emitToMain("update-call-start-message",t)}clearInviteUnreadStatus(e){}sendSignalMessage(e,s,t,o,i){k.currentSession.conversation&&this.sendSignalMessageEx(k.currentSession.conversation,e,s,t,o,i)}sendSignalMessageEx(e,s,t,o,r,n){t&&r&&t.push(this.currentSession.selfUserInfo.uid);let l={conversation:JSON.parse(i()(e)),content:s.encode(),toUsers:t};n&&(this.sendMessageId++,l.sendMessageId=this.sendMessageId,this.sendMessageCallbackMap.set(this.sendMessageId,n)),f.default.emitToMain("voip-message",l)}sendConferenceRequest(e,s,t,o,i){this.sendConferenceRequestEx(e,s,t,o,this.currentSession.advance,i)}sendConferenceRequestEx(e,s,t,o,i,r){let n={sessionId:e,roomId:s,request:t,data:o,advance:i};r&&(this.sendConferenceRequestId++,n.sendConferenceRequestId=this.sendConferenceRequestId,this.sendConferenceRequestCallbackMap.set(this.sendConferenceRequestId,r)),f.default.emitToMain("conference-request",n)}rejectOtherCall(e,s,t,o){let i=new u.default;i.callId=s,i.inviteMsgUid=o,i.reason=j.default.REASON_Busy,this.sendSignalMessageEx(e,i,t,!1,!0)}onReceiveRCData(e){f.default.emitToMain("rc_receive_input_event",e)}onReceiveData(e,s){let t=JSON.parse(s);if(k.currentSession.getPeerConnection(e))k.processSignalingMessage(e,t);else{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){}answerCurrentCall(){let e=new a.default;e.audioOnly=k.currentSession.audioOnly,e.callId=k.currentSession.callId,e.inviteMessageUid=k.currentSession.startMsgUid,this.sendSignalMessage(e,this.currentSession.getParticipantIds(),!0,!0,((e,s,t)=>{0===e?this.currentSession.setAcceptTime(t):this.currentSession.endCall(j.default.REASON_SignalError)}))}downgrade2VoiceCall(){let e=new h.default;k.currentSession.audioOnly=!0,e.audioOnly=k.currentSession.audioOnly,e.callId=k.currentSession.callId,this.sendSignalMessage(e,this.currentSession.getParticipantIds(),!0,!1)}}const k=new S,M=k},"./av/internal/callSessionImpl.js":(e,s,t)=>{t.r(s),t.d(s,{default:()=>L});var o=t("./node_modules/babel-runtime/core-js/object/keys.js"),i=t.n(o),r=t("./node_modules/babel-runtime/helpers/extends.js"),n=t("./node_modules/babel-runtime/helpers/asyncToGenerator.js"),l=t("./node_modules/babel-runtime/core-js/map.js"),d=t.n(l),u=t("./node_modules/babel-runtime/core-js/json/stringify.js"),a=t.n(u),c=t("../../../config.js"),h=t("../engine/callState"),m=t("./av/internal/avenginekitImpl.js"),j=t("../engine/callEndReason"),f=t("../messages/callByeMessageContent"),_=t("./av/internal/subscriberImpl.js"),b=t("../../../platform.js"),y=t("../engine/callSession"),v=t("../../util/longUtil.js"),p=t("../engine/avenginekit"),g=t("../../model/conversationType"),w=t("../messages/conferenceChangeModeContent"),S=t("../../model/conversation"),k=t("./av/internal/roomErrorCode.js"),M=t("./av/internal/soundMeter.js"),C=t("../engine/avenginekitproxy"),T=t("../messages/muteVideoMessageContent"),I=t("../engine/videoProfile"),O=t("./av/internal/publisherImpl.js"),P=t("./av/internal/screenSharingPublisherImpl.js"),R=t("../../model/nullUserInfo"),x=t("../engine/participantProfile"),E=t("../messages/rcInviteMessageContent"),A=t("../messages/rcAcceptInviteMessageContent"),V=t("../messages/rcEndMessageContent"),N=t("../engine/rcEndReason"),D=t("../engine/rcState");class L extends y.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.j=!1,this._=!1,this.clipboardInterval=0,this.M=0,this.onVoipWindowClose=e=>{this.endCall(j.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,v.numberValue)(this.joinTime);if(0!==s){if(this.status===h.default.STATUS_INCOMING){if(e-s>6e4)return void this.endCall(j.default.REASON_Timeout)}else if(this.status!==h.default.STATUS_CONNECTED&&e-s>6e4)return void this.endCall(j.default.RemoteTimeout);this.subscriberMap.forEach(((s,t)=>{let o=(0,v.gt)(s.acceptTime,s.joinTime)?s.acceptTime:s.joinTime;s.status!==h.default.STATUS_CONNECTED&&(0,v.gt)(o,0)&&e-(0,v.numberValue)(o)>6e4&&this.endUserCall(t,j.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=>{this.sessionCallback&&this.sessionCallback.didRemoveRemoteVideoTrack(e)};let o=this.getSubscriber(e);if(t.getAudioTracks().length>0){let e=new M.SoundMeter(window.audioContext);e.connectToSource(t,(e=>{})),o.soundMeter=e}o.stream=s.streams[0]},this.onIceCandidate=(e,s,t)=>{if(!t.candidate)return;if(p.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 i={};i.candidate=t.candidate.candidate,i.sdpMLineIndex=t.candidate.sdpMLineIndex,i.sdpMid=t.candidate.sdpMid,i.pin=this.pin,o.candidate=i,m.default.sendConferenceRequest(this.sessionId,this.callId,"trickle",a()(o),((e,s)=>{}))},this.onIceStateChange=(e,s,t)=>{if(s){if("connected"===s.iceConnectionState){if(this.selfUserInfo.uid===e)return this.connectedTime||(this.connectedTime=(new Date).getTime()),void this.setState(h.default.STATUS_CONNECTED);{let s=this.getSubscriber(e);if(this.audience&&this.setState(h.default.STATUS_CONNECTED),s.status=h.default.STATUS_CONNECTED,this.sessionCallback){let s=this.getScreenSharingUserId(e);this.sessionCallback.didParticipantConnected(s||e,null!==s)}}}"disconnected"===s.iceConnectionState||s.iceConnectionState}},this.bytesPrev=0,this.timestampPrev=0,this.requestArray=[],this.C=[],this.T=[],this.I=()=>{b.clipboard||this.T&&navigator.clipboard.writeText(this.T).then((e=>{this.T=""})).catch((e=>{}))},s}static newSession(e,s,t,o,i){let r=new L;return r.conversation=e,r.initiatorId=s,r.callId=t,r.audioOnly=o,r.sessionCallback=i,window.__callSession=r,r}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){let t=this.getSubscriber(e);t&&(t.acceptTime=s)}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 x.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 x.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.O(e,s)}acceptRemoteControlRequest(){this.O(!1,"")}O(e,s){this.status===h.default.STATUS_INCOMING&&(this.setState(h.default.STATUS_CONNECTING),this.audioOnly&&!e&&(e=!0),this.audioOnly=e,this.callExtra=s,m.default.answerCurrentCall())}setState(e){if(this.status!==e&&(this.status!==h.default.STATUS_CONNECTED||e!==h.default.STATUS_CONNECTING)){if(this.status=e,e===h.default.STATUS_IDLE||e===h.default.STATUS_CONNECTED){if(this.startMsgUid){let s={audioOnly:this.audioOnly};s.status=this.endReason?this.endReason:0,e===h.default.STATUS_CONNECTED?(s.connectTime=(new Date).getTime(),this.startTime=s.connectTime):s.endTime=(new Date).getTime(),m.default.updateCallStartMessageContent(this.startMsgUid,s)}e===h.default.STATUS_CONNECTED?(this.conference?this.notifyMuteState():!this.audioOnly&&this.videoMuted&&this.sendMuteVideoMessage(),this.rcStatus!==D.default.STATUS_INCOMING_REQUEST&&this.rcStatus!==D.default.STATUS_OUTGOING_REQUEST||(this.rcStatus=D.default.STATUS_CONNECTED,this.A(),this.I())):this.rcStatus=D.default.STATUS_IDLE,e===h.default.STATUS_IDLE&&clearInterval(this.clipboardInterval)}else e===h.default.STATUS_CONNECTING&&this.joinAndPublish();this.sessionCallback&&this.sessionCallback.didChangeState(e)}}initSession(e,s,t=[],o=[],i=!1){this.moCall=e,this.selfUserInfo=s,this.participantUserInfos=t,this.singleCall=t&&1===t.length,this.groupMemberUserInfos=o;let r=s;!e&&t&&t.length>0&&(r=t.filter((e=>e.uid===this.initiatorId))[0]),this.sessionCallback.onInitial(this,s,r,t,o);let n=[];t&&t.length>0&&t.forEach((e=>{n.push(e.uid)})),this.initSubscriberMap(n),i||(e?(this.setState(h.default.STATUS_OUTGOING),this.startPreview(this.audioOnly)):(this.setState(h.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){this.subscriberMap||(this.subscriberMap=new(d())),!e||e.length<1||e.forEach((e=>{let s=new _.default(e,this);s.status=h.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,m.default.inviteNewParticipants(e,this.pin,s,t))}getExistParticipantsStatus(){let e=[];return e.push({userId:this.selfUserInfo.uid,acceptTime:this.acceptTime?(0,v.numberValue)(this.acceptTime):0,joinTime:this.joinTime?(0,v.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,v.numberValue)(t.acceptTime):0,joinTime:t.joinTime?(0,v.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 R.default(e))})),e.forEach((e=>{let s=new _.default(e,this);s.status=h.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=h.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=I.default.getVideoProfile(p.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),s}createLocalCameraVideoStream(e,s=!0){var t=this;return(0,n.default)((function*(){try{const o=yield navigator.mediaDevices.getUserMedia(t.defaultVideoConstraints(e));s&&t.sessionCallback&&!t.videoMuted&&t.sessionCallback.didCreateLocalVideoTrack(o,!1);const i=o.getVideoTracks();return e?i&&i.length>0&&i.forEach((function(e){return e.stop()})):i&&i.length,o.getAudioTracks().length,o}catch(e){}return null}))()}startPreview(e){var s=this;return(0,n.default)((function*(){s.conference&&s.audience||(s.previewStream=yield s.createLocalCameraVideoStream(e),s.previewStream||(s.previewStream=yield s.createDummyVideoStream()),s.previewStream||s.endCall(j.default.REASON_MediaError),s.status===h.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(b.currentWindow)s.screenShareStream=yield navigator.mediaDevices.getUserMedia({audio:!1,video:{mandatory:(0,r.default)({chromeMediaSource:"desktop"},e)}});else{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})}if(s.screenSharing=!0,s.sessionCallback&&s.sessionCallback.didCreateLocalVideoTrack(s.screenShareStream,!0),s.screenShareStream.getVideoTracks()[0].addEventListener("ended",(function(){s.stopScreenShare()})),p.default.SCREEN_SHARING_REPLACE_MODE){if(s.cameraPublisher.videoSender){if(yield s.cameraPublisher.videoSender.replaceTrack(s.screenShareStream.getVideoTracks()[0]),!p.default.DISABLE_DUAL_STREAM){let e=s.screenShareStream.getVideoTracks()[0].clone();yield s.cameraPublisher.smallVideoSender.replaceTrack(e)}s.cameraPublisher.stopVideoTrack(s.cameraPublisher.cameraVideoStream)}s.notifyMuteState()}else s.screenSharingPublisher=new P.default(s),s.screenSharingPublisher.attachAndPublishScreenSharing()}}))()}isScreenSharing(){return!!this.screenShareStream}stopScreenShare(){var e=this;p.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,j.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(c.default.ICE_SERVERS&&c.default.ICE_SERVERS.length){t.iceServers=[];for(const e of c.default.ICE_SERVERS)t.iceServers.push({credential:e[2],credentialType:"password",urls:e[0],username:e[1]})}let o=p.default.FORCE_RELAY;void 0===o&&(o=p.default.FORCE_REPLAY),o&&(t.iceTransportPolicy="relay");let i=new RTCPeerConnection(t);if(e!==this.selfUserInfo.uid){let t=this.getSubscriber(e);t.peerConnection=i,t.isInitiator=s}return i.addEventListener("icecandidate",(s=>this.onIceCandidate(e,i,s))),i.addEventListener("iceconnectionstatechange",(s=>this.onIceStateChange(e,i,s))),i.addEventListener("track",(s=>this.gotRemoteStream(e,s))),i.addEventListener("connectionstatechange",(s=>this.onConnectionStateChange(e,i,s))),i}getSelectedSdpSemantics(){return{bundlePolicy:"max-bundle"}}onConnectionStateChange(e,s,t){s.connectionState}hangup(){this.endCall(j.default.REASON_Hangup)}setAudioOnly(e){this.audioOnly=e,this.conference||this.sessionCallback&&this.sessionCallback.didChangeMode(e)}downgrade2Voice(e=!1){this.status===h.default.STATUS_CONNECTED&&(this.cameraPublisher.stopVideoTrack(this.cameraPublisher.cameraVideoStream),e||m.default.downgrade2VoiceCall(),this.setAudioOnly(!0))}downToVoice(){if(this.stopIncomingRing(),this.status===h.default.STATUS_INCOMING)return this.setAudioOnly(!0),void this.answerCall(!0);this.status===h.default.STATUS_CONNECTED&&(this.audioOnly||(this.setAudioOnly(!0),m.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===h.default.STATUS_CONNECTED&&s.videoMuted!==!e&&!(s.audioOnly||s.isScreenSharing()&&p.default.SCREEN_SHARING_REPLACE_MODE)&&!s.j&&(s.videoMuted=!e,s.audience||(s.j=!0,e?(s.cameraPublisher||(s.cameraPublisher=new O.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]),s.j=!1),!0)}))()}sendMuteVideoMessage(){let e=new T.default;e.callId=this.callId,e.videoMuted=this.videoMuted,e.existParticipants=this.getExistParticipantsStatus(),m.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===h.default.STATUS_CONNECTED&&s.audioMuted!==!e&&!s.j&&(s.audioMuted=!e,s.audience||(s.j=!0,e?s.cameraPublisher&&s.cameraPublisher.cameraVideoStream?s.cameraPublisher.cameraVideoStream.getTracks().forEach((function(e){"audio"===e.kind&&(e.enabled=!0)})):(s.cameraPublisher=new O.default(s),s.cameraPublisher.handleId=s.handleId,yield s.cameraPublisher.createMediaSenders()):s.cameraPublisher&&s.cameraPublisher.stopAudioTrack(s.cameraPublisher.cameraVideoStream),s.conference&&s.status===h.default.STATUS_CONNECTED&&(s.notifyMuteState(),s.sessionCallback&&s.sessionCallback.didMuteStateChanged([s.selfUserInfo.uid])),s.j=!1),!0)}))()}forceEndMedia(){this.endMedia()}endMedia(){if(this.setState(h.default.STATUS_IDLE),this.stopIncomingRing(),this.cameraPublisher&&this.cameraPublisher.endMedia(),this.screenSharingPublisher&&this.screenSharingPublisher.endMedia(),this.previewStream){const e=this.previewStream;this.previewStream=null,void 0===e.getTracks?e.stop():e.getTracks().forEach((e=>{e.stop()}))}}endUserCall(e,s){if(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(o.acceptTime&&(0,v.gt)(o.acceptTime,0)&&e!==s){t=!0;break}if(t=t||this.acceptTime&&this.acceptTime&&(0,v.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&&(t.peerConnection&&(t.peerConnection.getSenders().forEach((e=>t.peerConnection.removeTrack(e))),t.peerConnection.close(),t.peerConnection=null),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===j.default.RemoteBusy,this.conference||0!==this.subscriberMap.size||(0===this.conversation.type||this.singleCall?this.endCall(s):this.endCall(this.isAllBusy?j.default.RemoteBusy:j.default.REASON_AllLeft))}leaveConference(e){this.conference?this.endCall(j.default.REASON_Hangup,e):this.endCall(j.default.REASON_Hangup)}endCall(e,s){if(this.endReason=e,this.status!==h.default.STATUS_IDLE){if(this.setState(h.default.STATUS_IDLE),!this.conference&&e!==j.default.REASON_AcceptByOtherClient&&e!==j.default.REASON_AllLeft&&e!==j.default.REASON_RemoteHangup&&this.getParticipantIds().length>0){let s=new f.default;s.callId=this.callId,s.inviteMsgUid=this.startMsgUid,s.reason=e,m.default.sendSignalMessage(s,this.getParticipantIds(),!1,!0)}if(e!==j.default.REASON_AcceptByOtherClient){let t={};t.handle_id=this.handleId,(s||e===j.default.REASON_AllLeft||this.conversation&&this.conversation.type===g.default.Single&&[j.default.RemoteBusy,j.default.REASON_RemoteHangup,j.default.RemoteTimeout].indexOf(e)>-1)&&(t.destroy=!0),m.default.sendConferenceRequest(this.sessionId,this.callId,"leave",a()(t),((e,s)=>{}))}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);m.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?p.default.MAX_AUDIO_PARTICIPANT_COUNT:p.default.MAX_VIDEO_PARTICIPANT_COUNT,this.conference||(s.is_private=!0),this.record&&(s.record=!0),m.default.sendConferenceRequest(this.sessionId,this.callId,"create_room",a()(s),((s,t)=>{if(0!==s)return void e(s);let o=JSON.parse(t);this.sessionId=o.session_id,this.handleId=o.handle_id;let i=o.data;this.callId,i.room,this.keepAlive(!0),e(0),this.conference&&this.setState(h.default.STATUS_CONNECTING)}))}onConferenceEvent(e){let s;if(s="string"==typeof e?JSON.parse(e):e,this.sessionId!==s.session_id)return;let t=s.sender;if(t>0&&this.screenSharingPublisher&&this.screenSharingPublisher.handleId===t)return;let o=s.data,i=o?o.videoroom:null;if("event"===i){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 i=o.kicked;i&&this.onLeave(i);let r=o.joining;r&&this.onJoining([r]);let n=o.attendees;this.onJoining(n)}else if("destroyed"===i)this.endCall(j.default.RoomDestroyed);else if("participants"===i){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"===i){let e=o.mute;this.onMute(e)}else if("slowlink"===i){let e=s.handle_id;this.onSlowLink(this.sessionId,e,o)}else s.janus}keepAlive(e){if(e){if(this.keepAliveTimer)return;this.lastActiveTime=(new Date).getTime(),this.keepAliveTimer=setInterval((()=>{m.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 void this.endCall(j.default.REASON_SignalError);this.lastActiveTime>0&&t-this.lastActiveTime>6e4&&this.endCall(j.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),m.default.sendConferenceRequest(this.sessionId,this.callId,"join_pub",a()(e),((e,s)=>{if(0!==e)return void this.endCall(j.default.REASON_SignalError);let t=JSON.parse(s),o=t.data,i=o.error_code;if(i>0)return void(i===k.default.JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM?this.endCall(j.default.RoomNotExist):i===k.default.JANUS_VIDEOROOM_ERROR_ID_EXISTS&&setTimeout((()=>{this.status!==h.default.STATUS_IDLE&&this.joinAndPublish()}),500));this.sessionId=t.session_id,this.handleId=t.handle_id;let r=o.publishers;this.onPublish(r),o.id,o.videoroom,this.privateId=o.private_id,o.description,o.room;let n=o.attendees;this.onJoining(n),this.audience?this.setState(h.default.STATUS_CONNECTED):(this.cameraPublisher=new O.default(this),this.cameraPublisher.handleId=this.handleId,this.cameraPublisher.publishMedia()),this.keepAlive(!0)}))}updateInitiator(){let e,s=(new Date).getTime()+864e5;(0,v.gt)(this.acceptTime,0)&&(s=this.acceptTime,e=this.selfUserInfo.uid),this.subscriberMap.forEach((t=>{(0,v.gt)(t.acceptTime,0)&&(0,v.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,i=e.streams;for(const[e,r]of this.subscriberMap)if(e===s){r.streams(i),r.callExtra=t,r.subscribe(),r.audience=!1,o=!1;break}if(o){let e=new _.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=h.default.STATUS_CONNECTED,e.audience=!1,e.callExtra=t,e.streams(i),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 r=this.subscriberMap.get(s);(r.videoMuted||r.audioMuted)&&this.sessionCallback&&this.sessionCallback.didMuteStateChanged([s])}onPublish(e){if(e)for(const s of e)this.onParticipantPublish(s)}onJoining(e){if(e)for(const s of e){let e=s.id;if(this.isSelfScreenSharing(e))continue;let t=!0,o=s.display;for(const[s,i]of this.subscriberMap)if(s===e){i.audience=!0,i.callExtra=o,t=!1;break}if(t){let s=new _.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=h.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,i=t.uplink,r=t.lost;if(this.handleId===s)this.sessionCallback.didMediaLostPacket(o,r,!1);else if(this.screenSharingPublisher&&this.screenSharingPublisher.handleId===s)this.sessionCallback.didMediaLostPacket(o,r,!0);else for(const[e,t]of this.subscriberMap)if(t.handleId===s){if(e.startsWith("screen_sharing_")){let s=e.substr(15);this.sessionCallback.didUserMediaLostPacket(s,o,r,i,!0)}else this.sessionCallback.didUserMediaLostPacket(e,o,r,i,!1);break}}onLeave(e){this.getSubscriber(e)?this.endUserCall(e,j.default.REASON_RemoteHangup):e===this.selfUserInfo.uid&&this.endCall(j.default.REASON_Hangup,!1)}mediaStream(){return this.screenShareStream?this.screenShareStream:this.cameraVideoStream}requestChangeMode(e,s){let t=new w.default(this.callId,s),o=new S.default(g.default.Single,e,0);m.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*(){s.conference&&(s._||e===s.audience||(s._=!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 O.default(s),s.cameraPublisher.handleId=s.handleId),yield s.cameraPublisher.publishMedia(),s.reportAudienceChanged(s.selfUserInfo.uid,!1),s.notifyMuteState(),s.audience=!1),s._=!1))}))()}onMute(e){let s=[];this.subscriberMap.forEach(((t,o)=>{let i=e[o],r=!1,n=!1;i&&(r=!!i.hasOwnProperty("a")&&i.a,n=!!i.hasOwnProperty("v")&&i.v),t.videoMuted===n&&t.audioMuted===r||(t.videoMuted=n,t.audioMuted=r,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===h.default.STATUS_IDLE)return;let e={handle_id:this.handleId,a:this.audioMuted};p.default.SCREEN_SHARING_REPLACE_MODE?e.v=this.videoMuted&&!this.isScreenSharing():e.v=this.videoMuted,m.default.sendConferenceRequest(this.sessionId,this.callId,"mute",a()(e),((e,s)=>{}))}kickoffParticipant(e,s,t){if(this.status===h.default.STATUS_IDLE&&t&&t(-1),this.getSubscriber(e)){let o={handle_id:this.handleId,user:e};m.default.sendConferenceRequest(this.sessionId,this.callId,"kick",a()(o),((e,o)=>{0===e?s&&s():t&&t(e)}))}}closeVoipWindow(){localStorage.getItem("enable_voip_debug")||(b.currentWindow?b.currentWindow.close():C.default.emitToMain("close-voip-div"))}setAudioInputDeviceId(e){e="null"===e?null:e,this.audioInputDeviceId=e,this.cameraPublisher&&(this.cameraPublisher.stopVideoStream(this.cameraPublisher.cameraVideoStream),this.cameraPublisher.cameraVideoStream=null,this.cameraPublisher.createMediaSenders())}setVideoInputDeviceId(e){e="null"===e?null:e,this.videoInputDeviceId=e,this.cameraPublisher&&(this.cameraPublisher.stopVideoStream(this.cameraPublisher.cameraVideoStream),this.cameraPublisher.cameraVideoStream=null,this.cameraPublisher.createMediaSenders())}setInputStream(e){this.externalStream=e,this.cameraPublisher&&(this.cameraPublisher.stopVideoStream(this.cameraPublisher.cameraVideoStream),this.cameraPublisher.cameraVideoStream=null,this.cameraPublisher.createMediaSenders())}switchCamera(){return!!navigator.mediaDevices.getSupportedConstraints().facingMode&&("user"===this.videoCamera?this.videoCamera="environment":this.videoCamera="user",this.cameraPublisher.stopVideoStream(this.cameraPublisher.cameraVideoStream),this.cameraPublisher.createMediaSenders(),!0)}rotate(e){this.cameraPublisher&&this.cameraPublisher.rotate(e)}screenSharingId(){return"screen_sharing_"+this.selfUserInfo.uid}getScreenSharingUserId(e=""){return e.startsWith("screen_sharing_")?e.substring(15):null}isSelfScreenSharing(e=""){return this.screenSharingId()===e}setVideoMaxBitrate(e){this.cameraPublisher&&this.cameraPublisher.setVideoMaxBitrate(e)}scaleVideoResolutionDownBy(e){this.cameraPublisher&&this.cameraPublisher.scaleVideoResolutionDownBy(e)}dumpStats(e){let s="";return e.forEach((e=>{s+="<h3>Report type=",s+=e.type,s+="</h3>\n",s+=`id ${e.id}<br>`,s+=`time ${e.timestamp}<br>`,i()(e).forEach((t=>{"timestamp"!==t&&"type"!==t&&"id"!==t&&("object"==typeof e[t]?s+=`${t}: ${a()(e[t])}<br>`:s+=`${t}: ${e[t]}<br>`)}))})),s}showRemoteStats(e,s){this.dumpStats(s),localStorage.getItem("enable_voip_debug.stats"),s.forEach((e=>{const s=e.timestamp;let t;if("inbound-rtp"===e.type&&"video"===e.mediaType){const o=e.bytesReceived;this.timestampPrev&&(t=8*(o-this.bytesPrev)/(s-this.timestampPrev),t=Math.floor(t)),this.bytesPrev=o,this.timestampPrev=s}t&&(t+=" kbits/sec")}))}setParticipantVideoType(e,s,t){s&&(e="screen_sharing_"+e);for(const[s,o]of this.subscriberMap)if(e===s){o.setVideoType(t);break}}onIMConnectionStatusChange(e){1===e&&(this.status===h.default.STATUS_CONNECTED&&this.queryParticipantStatus(),this.cameraPublisher&&this.cameraPublisher.restartICE(),this.screenSharingPublisher&&this.screenSharingPublisher.restartICE(),this.subscriberMap&&this.subscriberMap.forEach(((e,s)=>{e.restartICE()})))}queryParticipantStatus(){let e={handle_id:this.handleId,pin:this.pin};m.default.sendConferenceRequest(this.sessionId,this.callId,"query_participants",a()(e),((e,s)=>{if(0!==e)return;let t=JSON.parse(s).data;if(t){let e=t.publishers,s=t.attendees;this.onJoining(s),this.onPublish(e)}}))}createDummyVideoStream(){return(0,n.default)((function*(){const e=document.createElement("video");e.autoplay=!0,e.loop=!0,e.volume=.5,e.src=p.default.DUMMY_VIDEO_URI,e.load();try{yield e.play()}catch(e){}let s=null;return s=e.captureStream?e.captureStream():e.mozCaptureStream?e.mozCaptureStream():document.createElement("canvas").captureStream(60),s}))()}inviteRemoteControl(){if(this.conversation.type!==g.default.Single&&!this.audioOnly)return;this.rcStatus=D.default.STATUS_OUTGOING_INVITE;let e=new E.default(this.callId);m.default.sendSignalMessageEx(this.conversation,e,[],!1),setTimeout((()=>{this.rcStatus!==D.default.STATUS_CONNECTED&&(this.rcStatus=D.default.STATUS_IDLE,this.sessionCallback&&this.sessionCallback.didRemoteControlEnd(N.default.REASON_TIME_OUT))}),6e4)}onDataChannelMessage(e,s){if(this.rcStatus===D.default.STATUS_CONNECTED)if("string"==typeof s){let e=JSON.parse(s);"rce"===e.type?this.sessionCallback&&this.sessionCallback.didRemoteControlInputError(e.code):"cs"===e.type&&this.V(e.data)}else if(this.sessionCallback){let e=this.sessionCallback.didReceiveRemoteControlEvent(s);0!==e&&this.M!==e?(this.M=e,this.cameraPublisher.dataChannel.send(a()({type:"rce",code:e}))):this.M=e}}acceptRemoteControlInvite(){if(this.conversation.type!==g.default.Single&&!this.audioOnly)return;this.rcStatus=D.default.STATUS_CONNECTED,this.A(),this.I();let e=new A.default(this.callId);m.default.sendSignalMessageEx(this.conversation,e,[],!1)}rejectRemoteControlInvite(){if(this.conversation.type!==g.default.Single&&!this.audioOnly)return;let e=new V.default(this.callId);e.reason=N.default.REASON_REJECT,m.default.sendSignalMessageEx(this.conversation,e,[],!1)}endRemoteControl(e){if(this.conversation.type!==g.default.Single&&!this.audioOnly)return;let s=new V.default(this.callId);s.reason=N.default.REASON_HANGUP,this.rcStatus=D.default.STATUS_IDLE,m.default.sendSignalMessageEx(this.conversation,s,[],!1)}l(){this.rcStatus=D.default.STATUS_INCOMING_INVITE,this.sessionCallback.onReceiveRemoteControlInvite(),setTimeout((()=>{this.rcStatus!==D.default.STATUS_CONNECTED&&(this.rcStatus=D.default.STATUS_IDLE,this.sess