!function(e,s){if("object"==typeof exports&&"object"==typeof module)module.exports=s(require("../../../config.js"),require("../../../platform.js"),require("../../messages/messageContentType"),require("../../model/conversation"),require("../../model/conversationType"),require("../../model/nullUserInfo"),require("../../util/longUtil.js"),require("../engine/avenginekit"),require("../engine/avenginekitproxy"),require("../engine/callEndReason"),require("../engine/callSession"),require("../engine/callState"),require("../engine/participantProfile"),require("../engine/subscriber"),require("../engine/videoProfile"),require("../engine/videoType"),require("../messages/addParticipantsMessageContent"),require("../messages/callAnswerMessageContent"),require("../messages/callByeMessageContent"),require("../messages/callModifyMessageContent"),require("../messages/callStartMessageContent"),require("../messages/conferenceChangeModeContent"),require("../messages/muteVideoMessageContent"));else if("function"==typeof define&&define.amd)define(["../../../config.js","../../../platform.js","../../messages/messageContentType","../../model/conversation","../../model/conversationType","../../model/nullUserInfo","../../util/longUtil.js","../engine/avenginekit","../engine/avenginekitproxy","../engine/callEndReason","../engine/callSession","../engine/callState","../engine/participantProfile","../engine/subscriber","../engine/videoProfile","../engine/videoType","../messages/addParticipantsMessageContent","../messages/callAnswerMessageContent","../messages/callByeMessageContent","../messages/callModifyMessageContent","../messages/callStartMessageContent","../messages/conferenceChangeModeContent","../messages/muteVideoMessageContent"],s);else{var o="object"==typeof exports?s(require("../../../config.js"),require("../../../platform.js"),require("../../messages/messageContentType"),require("../../model/conversation"),require("../../model/conversationType"),require("../../model/nullUserInfo"),require("../../util/longUtil.js"),require("../engine/avenginekit"),require("../engine/avenginekitproxy"),require("../engine/callEndReason"),require("../engine/callSession"),require("../engine/callState"),require("../engine/participantProfile"),require("../engine/subscriber"),require("../engine/videoProfile"),require("../engine/videoType"),require("../messages/addParticipantsMessageContent"),require("../messages/callAnswerMessageContent"),require("../messages/callByeMessageContent"),require("../messages/callModifyMessageContent"),require("../messages/callStartMessageContent"),require("../messages/conferenceChangeModeContent"),require("../messages/muteVideoMessageContent")):s(e["../../../config.js"],e["../../../platform.js"],e["../../messages/messageContentType"],e["../../model/conversation"],e["../../model/conversationType"],e["../../model/nullUserInfo"],e["../../util/longUtil.js"],e["../engine/avenginekit"],e["../engine/avenginekitproxy"],e["../engine/callEndReason"],e["../engine/callSession"],e["../engine/callState"],e["../engine/participantProfile"],e["../engine/subscriber"],e["../engine/videoProfile"],e["../engine/videoType"],e["../messages/addParticipantsMessageContent"],e["../messages/callAnswerMessageContent"],e["../messages/callByeMessageContent"],e["../messages/callModifyMessageContent"],e["../messages/callStartMessageContent"],e["../messages/conferenceChangeModeContent"],e["../messages/muteVideoMessageContent"]);for(var t in o)("object"==typeof exports?exports:e)[t]=o[t]}}(window,(function(e,s,o,t,r,i,n,a,l,c,d,u,m,h,f,_,p,S,b,g,j,v,y){return function(e){var s={};function o(t){if(s[t])return s[t].exports;var r=s[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=s,o.d=function(e,s,t){o.o(e,s)||Object.defineProperty(e,s,{enumerable:!0,get:t})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,s){if(1&s&&(e=o(e)),8&s)return e;if(4&s&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(o.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&s&&"string"!=typeof e)for(var r in e)o.d(t,r,function(s){return e[s]}.bind(null,r));return t},o.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(s,"a",s),s},o.o=function(e,s){return Object.prototype.hasOwnProperty.call(e,s)},o.p="",o(o.s="./av/internal/avenginekitImpl.js")}({"../../../config.js":function(s,o){s.exports=e},"../../../platform.js":function(e,o){e.exports=s},"../../messages/messageContentType":function(e,s){e.exports=o},"../../model/conversation":function(e,s){e.exports=t},"../../model/conversationType":function(e,s){e.exports=r},"../../model/nullUserInfo":function(e,s){e.exports=i},"../../util/longUtil.js":function(e,s){e.exports=n},"../engine/avenginekit":function(e,s){e.exports=a},"../engine/avenginekitproxy":function(e,s){e.exports=l},"../engine/callEndReason":function(e,s){e.exports=c},"../engine/callSession":function(e,s){e.exports=d},"../engine/callState":function(e,s){e.exports=u},"../engine/participantProfile":function(e,s){e.exports=m},"../engine/subscriber":function(e,s){e.exports=h},"../engine/videoProfile":function(e,s){e.exports=f},"../engine/videoType":function(e,s){e.exports=_},"../messages/addParticipantsMessageContent":function(e,s){e.exports=p},"../messages/callAnswerMessageContent":function(e,s){e.exports=S},"../messages/callByeMessageContent":function(e,s){e.exports=b},"../messages/callModifyMessageContent":function(e,s){e.exports=g},"../messages/callStartMessageContent":function(e,s){e.exports=j},"../messages/conferenceChangeModeContent":function(e,s){e.exports=v},"../messages/muteVideoMessageContent":function(e,s){e.exports=y},"./av/internal/avenginekitImpl.js":function(e,s,o){"use strict";o.r(s),o.d(s,"WfcAVEngineKitImpl",(function(){return A}));var t=o("./node_modules/babel-runtime/core-js/map.js"),r=o.n(t),i=o("../../messages/messageContentType"),n=o.n(i),a=o("../messages/callByeMessageContent"),l=o.n(a),c=o("../messages/callAnswerMessageContent"),d=o.n(c),u=o("../messages/callStartMessageContent"),m=o.n(u),h=o("../messages/callModifyMessageContent"),f=o.n(h),_=o("../../model/conversationType"),p=o.n(_),S=o("../engine/callEndReason"),b=o.n(S),g=o("../engine/avenginekitproxy"),j=o.n(g),v=o("../engine/callState"),y=o.n(v),C=o("./av/internal/callSessionImpl.js"),T=o("../messages/addParticipantsMessageContent"),I=o.n(T),M=o("../engine/avenginekit"),E=o.n(M),O=o("../../../config.js"),R=o.n(O);class A extends E.a{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 o=this.sendMessageCallbackMap.get(s.sendMessageId);o&&o(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 o=this.sendConferenceRequestCallbackMap.get(s.sendConferenceRequestId);o&&(o(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!==p.a.Single&&s.conversation.type!==p.a.Group||1!==s.direction&&s.messageContent.type!==n.a.VOIP_CONTENT_TYPE_ACCEPT&&s.messageContent.type!==n.a.VOIP_CONTENT_TYPE_END)){let e=s.messageContent;if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_SIGNAL){if(!k.currentSession||k.currentSession.status===y.a.STATUS_IDLE)return;let o=s.messageContent;o.callId!==k.currentSession.callId?k.rejectOtherCall(s.conversation,e.callId,null,s.messageUid):!k.currentSession||k.currentSession.status!==y.a.STATUS_CONNECTING&&k.currentSession.status!==y.a.STATUS_CONNECTED&&k.currentSession.status!==y.a.STATUS_OUTGOING||k.onReceiveData(s.from,o.payload)}else if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_START){console.log("av-c","callstart",s);let o=s.messageContent.targetIds;if(o.findIndex(e=>e===s.selfUserInfo.uid)<0)return;o=o.filter(e=>e!==s.selfUserInfo.uid),o.push(s.from),k.currentSession&&k.currentSession.status!==y.a.STATUS_IDLE?k.rejectOtherCall(s.conversation,e.callId,o,s.messageUid):(k.currentSession=C.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,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(y.a.STATUS_INCOMING))}else if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_ACCEPT||s.messageContent.type===n.a.VOIP_CONTENT_TYPE_ACCEPT_T){if(k.currentSession&&k.currentSession.status!==y.a.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===y.a.STATUS_INCOMING)return void k.currentSession.endCall(b.a.REASON_AcceptByOtherClient);k.currentSession.status===y.a.STATUS_OUTGOING&&k.currentSession.setState(y.a.STATUS_CONNECTING),!k.currentSession.audioOnly&&e.audioOnly&&k.currentSession.setAudioOnly(!0),k.currentSession.setUserAcceptTime(s.from,s.timestamp);let o=k.queueOfferMessageMap.get(s.from);o&&o.forEach(e=>{k.processSignalingMessage(s.from,e)}),k.queueOfferMessageMap.delete(s.from)}}else if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_END)if(k.currentSession&&k.currentSession.status!==y.a.STATUS_IDLE&&k.currentSession.callId===e.callId){let o=e.reason;if(1===s.direction){switch(e.reason){case b.a.REASON_Unknown:o=b.a.REASON_Unknown;break;case b.a.REASON_Busy:o=b.a.RemoteBusy;break;case b.a.REASON_SignalError:o=b.a.RemoteNetworkError;break;case b.a.REASON_Hangup:o=b.a.REASON_RemoteHangup;break;case b.a.REASON_MediaError:o=b.a.RemoteNetworkError;break;case b.a.REASON_RemoteHangup:o=b.a.REASON_Hangup;break;case b.a.REASON_OpenCameraFailure:o=b.a.RemoteNetworkError;break;case b.a.REASON_Timeout:o=b.a.RemoteTimeout;break;case b.a.REASON_AcceptByOtherClient:o=b.a.REASON_AcceptByOtherClient;break;case b.a.REASON_AllLeft:o=b.a.REASON_AllLeft;break;case b.a.RemoteBusy:o=b.a.REASON_Busy;break;case b.a.RemoteTimeout:o=b.a.REASON_Timeout;break;case b.a.RemoteNetworkError:o=b.a.REASON_SignalError;break;case b.a.RoomDestroyed:o=b.a.RoomDestroyed;break;case b.a.RoomNotExist:o=b.a.RoomNotExist;break;case b.a.RoomParticipantsFull:o=b.a.RoomParticipantsFull;break;case b.a.Interrupted:o=b.a.RemoteInterrupted;break;default:o=b.a.RemoteNetworkError}k.currentSession.endUserCall(s.from,o)}else k.currentSession.endCall(o)}else console.log("av-c","invalid bye message, ignore it",k.currentSession,e);else if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_MODIFY)k.currentSession&&k.currentSession.status===y.a.STATUS_CONNECTED&&k.currentSession.callId===e.callId&&(e.audioOnly?(k.currentSession.audioOnly=!0,k.currentSession.downgrade2Voice(!0)):console.log("av-c","cannot modify voice call to video call"));else if(s.messageContent.type===n.a.VOIP_Join_Call_Request)k.currentSession&&k.currentSession.status===y.a.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===n.a.VOIP_CONTENT_TYPE_ADD_PARTICIPANT)if(e.participants.indexOf(s.selfUserInfo.uid)>-1){if(k.currentSession&&k.currentSession.status!==y.a.STATUS_IDLE){if(k.currentSession.callId===s.messageContent.callId)return;let o=[];return o.push(...s.messageContent.participants),s.messageContent.existParticipants&&o.push(...s.messageContent.existParticipants),o.push(s.from),o=o.filter(e=>e!==s.selfUserInfo.uid),void k.rejectOtherCall(s.conversation,e.callId,o)}k.currentSession=C.default.newSession(s.conversation,s.from,e.callId,e.audioOnly,k.sessionCallback),k.currentSession.pin=e.pin,k.currentSession.startMsgUid=s.messageUid;let o=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,o,s.groupMemberUserInfos),o.forEach(e=>{k.currentSession.setUserJoinTime(e.uid,s.timestamp)}),k.currentSession.updateExistParticipant(e.existParticipants,s.timestamp),k.currentSession.setState(y.a.STATUS_INCOMING),R.a.ENABLE_MULTI_CALL_AUTO_JOIN&&e.autoAnswer&&k.currentSession.answer(e.audioOnly)}else if(k.currentSession&&k.currentSession.status!==y.a.STATUS_IDLE&&k.currentSession.callId===e.callId){let o=s.participantUserInfos.filter(s=>e.participants.indexOf(s.uid)>-1);k.currentSession.didAddNewParticipants(e.participants,o),o.forEach(e=>{k.currentSession.setUserJoinTime(e.uid,s.timestamp)})}else{let o=[];o.push(...s.messageContent.participants),s.messageContent.existParticipants&&o.push(...s.messageContent.existParticipants),o.push(s.from),o=o.filter(e=>e!==s.selfUserInfo.uid),k.rejectOtherCall(s.conversation,e.callId,o)}else if(s.messageContent.type===n.a.VOIP_CONTENT_TYPE_MUTE_VIDEO){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.status!==y.a.STATUS_IDLE&&k.currentSession.updateVideoMute(s.from,e.videoMuted)}else if(s.messageContent.type===n.a.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===n.a.CONFERENCE_CONTENT_TYPE_KICKOFF_MEMBER){let e=s.messageContent;k.currentSession&&k.currentSession.callId===e.callId&&k.currentSession.onKickoff()}}},this.startCall=(e,s)=>{let o=(s=this._fixLongSerializedIssue(s)).conversation,t=s.audioOnly;if(this.currentSession)return;this.currentSession=C.default.newSession(o,s.selfUserInfo.uid,s.callId,t,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(y.a.STATUS_OUTGOING);let r=new m.a;r.audioOnly=t,r.callId=s.callId,r.pin=this.currentSession.pin,r.targetIds=this.currentSession.getParticipantIds(),r.extra=s.callExtra,this.currentSession.createRoom(e=>{0===e?this.sendSignalMessage(r,this.currentSession.getParticipantIds(),!0,!1,(e,s,o)=>{k.currentSession&&(0!==e?this.currentSession.endCall(b.a.REASON_SignalError):(this.currentSession.startMsgUid=s,console.log("av-c","startMsgUid",this.currentSession.startMsgUid,s),this.currentSession.joinTime=o,this.currentSession.setAcceptTime(o),r.targetIds.forEach(e=>{this.currentSession.setUserJoinTime(e,o)},this)))}):this.currentSession.endCall(b.a.REASON_SignalError)})},this.startConference=(e,s)=>{let o=(s=this._fixLongSerializedIssue(s)).audioOnly;this.currentSession||(this.currentSession=C.default.newSession(null,s.selfUserInfo.uid,s.callId,o,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(y.a.STATUS_OUTGOING),this.currentSession.createRoom(e=>{0!==e&&this.currentSession.endCall(b.a.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=C.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(y.a.STATUS_CONNECTING))},this.onConnectionStatusChange=(e,s)=>{k.currentSession&&k.currentSession.onIMConnectionStatusChange(Number(s))}}setup(e){window&&!window._log&&(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"),j.a.listenVoipEvent("message",this.onReceiveMessage),j.a.listenVoipEvent("conferenceEvent",this.onConferenceEvent),j.a.listenVoipEvent("sendMessageResult",this.onSendMessageResult),j.a.listenVoipEvent("sendConferenceRequestResult",this.onSendConferenceRequestResult),j.a.listenVoipEvent("startCall",this.startCall),j.a.listenVoipEvent("startConference",this.startConference),j.a.listenVoipEvent("joinConference",this._joinConference),j.a.listenVoipEvent("connectionStatus",this.onConnectionStatusChange),this.sendMessageCallbackMap=new r.a,this.sendConferenceRequestCallbackMap=new r.a,this.queueOfferMessageMap=new r.a,this.sessionCallback=e}getCurrentSession(){return k.currentSession}inviteNewParticipants(e,s,o,t){let r=k.currentSession;if(!r)return;let i=new I.a;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=t,i.clientId=o;let n=[...r.getParticipantIds()];n.push(...e),this.sendSignalMessage(i,n,!0,!1,(s,o,t)=>{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,t)})})}updateCallStartMessageContent(e,s){let o={messageUid:e,content:s};j.a.emitToMain("update-call-start-message",o)}clearInviteUnreadStatus(e){}sendSignalMessage(e,s,o,t,r){k.currentSession.conversation&&this.sendSignalMessageEx(k.currentSession.conversation,e,s,o,t,r)}sendSignalMessageEx(e,s,o,t,r,i){o&&r&&o.push(this.currentSession.selfUserInfo.uid);let n={conversation:e,content:s.encode(),toUsers:o};console.log("av-c","send signal message",s),i&&(this.sendMessageId++,n.sendMessageId=this.sendMessageId,this.sendMessageCallbackMap.set(this.sendMessageId,i)),j.a.emitToMain("voip-message",n)}sendConferenceRequest(e,s,o,t,r){this.sendConferenceRequestEx(e,s,o,t,this.currentSession.advance,r)}sendConferenceRequestEx(e,s,o,t,r,i){let n={sessionId:e,roomId:s,request:o,data:t,advance:r};i&&(this.sendConferenceRequestId++,n.sendConferenceRequestId=this.sendConferenceRequestId,this.sendConferenceRequestCallbackMap.set(this.sendConferenceRequestId,i)),console.log("av-c","sendConferenceRequest",n),j.a.emitToMain("conference-request",n)}rejectOtherCall(e,s,o,t){let r=new l.a;r.callId=s,r.inviteMsgUid=t,r.reason=b.a.REASON_Busy,console.log("av-c","reject other call",r,o),this.sendSignalMessageEx(e,r,o,!1,!0)}onReceiveData(e,s){let o=JSON.parse(s);if(k.currentSession.getPeerConnection(e))k.processSignalingMessage(e,o);else{console.log("av-c","queue signal",e,o);let s=this.queueOfferMessageMap.get(e);s||(s=[],this.queueOfferMessageMap.set(e,s)),s.push(o)}}processSignalingMessage(e,s){console.log("av-c","process remote signal:"+s)}answerCurrentCall(){let e=new d.a;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,o)=>{0===e?this.currentSession.setAcceptTime(o):this.currentSession.endCall(b.a.REASON_SignalError)})}downgrade2VoiceCall(){let e=new f.a;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 A;s.default=k},"./av/internal/callSessionImpl.js":function(e,s,o){"use strict";o.r(s),o.d(s,"default",(function(){return K}));var t=o("./node_modules/babel-runtime/core-js/object/keys.js"),r=o.n(t),i=o("./node_modules/babel-runtime/helpers/extends.js"),n=o.n(i),a=o("./node_modules/babel-runtime/helpers/asyncToGenerator.js"),l=o.n(a),c=o("./node_modules/babel-runtime/core-js/map.js"),d=o.n(c),u=o("./node_modules/babel-runtime/core-js/json/stringify.js"),m=o.n(u),h=o("../../../config.js"),f=o.n(h),_=o("../engine/callState"),p=o.n(_),S=o("./av/internal/avenginekitImpl.js"),b=o("../engine/callEndReason"),g=o.n(b),j=o("../messages/callByeMessageContent"),v=o.n(j),y=o("./av/internal/subscriberImpl.js"),C=o("../../../platform.js"),T=o("../engine/callSession"),I=o.n(T),M=o("../../util/longUtil.js"),E=o("../engine/avenginekit"),O=o.n(E),R=o("../../model/conversationType"),A=o.n(R),k=o("../messages/conferenceChangeModeContent"),P=o.n(k),V=o("../../model/conversation"),x=o.n(V),w=o("./av/internal/roomErrorCode.js"),N=o("./av/internal/soundMeter.js"),U=o("../engine/avenginekitproxy"),D=o.n(U),L=o("../messages/muteVideoMessageContent"),q=o.n(L),B=o("../engine/videoProfile"),J=o.n(B),G=o("./av/internal/publisherImpl.js"),F=o("./av/internal/screenSharingPublisherImpl.js"),H=o("../../model/nullUserInfo"),W=o.n(H),Y=o("../engine/participantProfile"),z=o.n(Y);class K extends I.a{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.onVoipWindowClose=e=>{this.endCall(g.a.RemoteNetworkError),window.removeEventListener("beforeunload",this.onVoipWindowClose)},this.callTimeout=()=>{let e=(new Date).valueOf();this.callTimer||(this.callTimer=setInterval(this.callTimeout,1e3));let s=Object(M.numberValue)(this.joinTime);if(0!==s){if(this.status===p.a.STATUS_INCOMING){if(e-s>6e4)return void this.endCall(g.a.REASON_Timeout)}else if(this.status!==p.a.STATUS_CONNECTED&&e-s>6e4)return void this.endCall(g.a.RemoteTimeout);this.subscriberMap.forEach((s,o)=>{let t=Object(M.gt)(s.acceptTime,s.joinTime)?s.acceptTime:s.joinTime;s.status!==p.a.STATUS_CONNECTED&&Object(M.gt)(t,0)&&e-Object(M.numberValue)(t)>6e4&&(console.log("av-c","subscriber timeout",e,Object(M.numberValue)(s.acceptTime),Object(M.numberValue)(s.joinTime)),this.endUserCall(o,g.a.RemoteTimeout))})}},this.gotRemoteStream=(e,s)=>{if(this.sessionCallback){let o=this.getScreenSharingUserId(e);this.sessionCallback.didReceiveRemoteVideoTrack(o||e,s.streams[0],null!==o)}let o=s.streams[0];o.onremovetrack=s=>{console.log("av-c","pc remove remote stream",s),this.sessionCallback&&this.sessionCallback.didRemoveRemoteVideoTrack(e)};let t=this.getSubscriber(e);if(o.getAudioTracks().length>0){let e=new N.SoundMeter(window.audioContext);e.connectToSource(o,e=>{console.log("av-c","connect to soundMeter",e)}),t.soundMeter=e}t.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,o)=>{if(!o.candidate)return;if(O.a.FORCE_MEDIA_OVER_TCP)return;let t={};if(t.session_id=this.sessionId,e===this.selfUserInfo.uid)t.handle_id=this.handleId;else{let s=this.getSubscriber(e);t.handle_id=s.handleId}let r={};r.candidate=o.candidate.candidate,r.sdpMLineIndex=o.candidate.sdpMLineIndex,r.sdpMid=o.candidate.sdpMid,r.pin=this.pin,t.candidate=r,S.default.sendConferenceRequest(this.sessionId,this.callId,"trickle",m()(t),(e,s)=>{0!==e&&console.log("av-c","conference request, trickle error",e)})},this.onIceStateChange=(e,s,o)=>{if(s){if(console.log("av-c","ICE state change event: ",e,s.iceConnectionState,o),"connected"===s.iceConnectionState){if(this.selfUserInfo.uid===e)return this.connectedTime||(this.connectedTime=(new Date).getTime()),void this.setState(p.a.STATUS_CONNECTED);{let s=this.getSubscriber(e);if(this.audience&&this.setState(p.a.STATUS_CONNECTED),s.status=p.a.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,s}static newSession(e,s,o,t,r){console.log("av-c","newSession");let i=new K;return i.conversation=e,i.initiatorId=s,i.callId=o,i.audioOnly=t,i.sessionCallback=r,window.__callSession=i,i}getParticipantIds(){let e=[];for(const[s,o]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 o=this.getSubscriber(e);o?o.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 o=new z.a;o.userId=s.userId,o.status=s.status,o.joinTime=s.joinTime,o.acceptTime=s.acceptTime,o.audioMuted=s.audioMuted,o.videoMuted=s.videoMuted,o.audience=s.audience,e.push(o)}return e}getSelfProfile(){let e=new z.a;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.status===p.a.STATUS_INCOMING&&(this.setState(p.a.STATUS_CONNECTING),this.audioOnly&&!e&&(e=!0),this.audioOnly=e,this.callExtra=s,S.default.answerCurrentCall())}setState(e){if(this.status!==e&&(this.status!==p.a.STATUS_CONNECTED||e!==p.a.STATUS_CONNECTING)){if(this.status=e,console.log("av-c","set status",e,this.startMsgUid),e===p.a.STATUS_IDLE||e===p.a.STATUS_CONNECTED){if(this.startMsgUid){let s={audioOnly:this.audioOnly};s.status=this.endReason?this.endReason:0,e===p.a.STATUS_CONNECTED?(s.connectTime=(new Date).getTime(),this.startTime=s.connectTime):s.endTime=(new Date).getTime(),S.default.updateCallStartMessageContent(this.startMsgUid,s)}e===p.a.STATUS_CONNECTED&&(this.conference?this.notifyMuteState():!this.audioOnly&&this.videoMuted&&this.sendMuteVideoMessage())}else e===p.a.STATUS_CONNECTING&&this.joinAndPublish();this.sessionCallback&&this.sessionCallback.didChangeState(e)}}initSession(e,s,o=[],t=[],r=!1){this.moCall=e,this.selfUserInfo=s,this.participantUserInfos=o,this.singleCall=o&&1===o.length,this.groupMemberUserInfos=t;let i=s;!e&&o&&o.length>0&&(i=o.filter(e=>e.uid===this.initiatorId)[0]),this.sessionCallback.onInitial(this,s,i,o,t);let n=[];o&&o.length>0&&o.forEach(e=>{n.push(e.uid)}),this.initSubscriberMap(n),r||(e?(this.setState(p.a.STATUS_OUTGOING),this.startPreview(this.audioOnly)):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 o=e.soundMeter.instant.toFixed(2);e.soundMeter.slow.toFixed(2),e.soundMeter.clip;this.sessionCallback.didReportAudioVolume(s,Number(o))})},100),localStorage.getItem("enable_voip_debug")&&(this.pcStatsTimer=setInterval(()=>{this.subscriberMap.forEach((e,s)=>{let o=e.peerConnection;o&&o.getStats().then(e=>{this.showRemoteStats(s,e)})})},1e3))}initSubscriberMap(e){console.log("av-c","initParticipantClientMap",e),this.subscriberMap||(this.subscriberMap=new d.a),!e||e.length<1||e.forEach(e=>{let s=new y.default(e,this);s.status=p.a.STATUS_INCOMING,this.subscriberMap.set(e,s)},this)}inviteNewParticipants(e,s,o){e.length&&(e=e.filter(e=>e!==this.selfUserInfo.uid&&this.participantUserInfos.findIndex(s=>s.uid===e)<0)).length&&(this.singleCall=!1,S.default.inviteNewParticipants(e,this.pin,s,o))}getExistParticipantsStatus(){let e=[];return e.push({userId:this.selfUserInfo.uid,acceptTime:this.acceptTime?Object(M.numberValue)(this.acceptTime):0,joinTime:this.joinTime?Object(M.numberValue)(this.joinTime):0,videoMuted:this.videoMuted}),this.participantUserInfos.forEach(s=>{let o=this.getSubscriber(s.uid);e.push({userId:o.userId,acceptTime:o.acceptTime?Object(M.numberValue)(o.acceptTime):0,joinTime:o.joinTime?Object(M.numberValue)(o.joinTime):0,videoMuted:o.videoMuted})},this),e}didAddNewParticipants(e,s){e.forEach(e=>{-1===s.findIndex(s=>s.uid===e)&&s.push(new W.a(e))}),console.log("av-c","didAddNewParticipants",e,s),e.forEach(e=>{let s=new y.default(e,this);s.status=p.a.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 o=this.getSubscriber(e.userId);o.status=p.a.STATUS_INCOMING,o.joinTime=s,o.videoMuted=e.videoMuted,o.acceptTime=e.acceptTime})}updateVideoMute(e,s){let o=this.getSubscriber(e);o&&o.videoMuted!==s&&(o.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=J.a.getVideoProfile(O.a.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",m()(s)),s}createLocalCameraVideoStream(e){var s=this;return l()((function*(){try{console.log("av-c","createLocalCameraVideoStream",e);const o=yield navigator.mediaDevices.getUserMedia(s.defaultVideoConstraints(e));console.log("av-c","Received local stream",o,o.getVideoTracks().length,e),s.sessionCallback&&!s.videoMuted&&s.sessionCallback.didCreateLocalVideoTrack(o,!1);const t=o.getVideoTracks();e?t&&t.length>0&&(console.log("av-c","audioOnly, stop video track"),t.forEach((function(e){return e.stop()}))):t&&t.length>0&&console.log("av-c",`Using video device: ${t[0].label}`);const r=o.getAudioTracks();return r.length>0&&console.log("av-c",`Using audio device: ${r[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 l()((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(g.a.REASON_MediaError))}))()}getDesktopSources(e){return C.desktopCapturer?C.desktopCapturer.getSources({types:e}):null}startScreenShare(e){var s=this;return l()((function*(){if(!s.isScreenSharing()&&!s.audioOnly){if(console.log("av-c","start screen share"),console.log("av-c","desktopCapturer ",C.desktopCapturer),C.desktopCapturer)s.screenShareStream=yield navigator.mediaDevices.getUserMedia({audio:!1,video:{mandatory:n()({chromeMediaSource:"desktop"},e)}}),console.log("av-c","desktopCapturer screen share stream",s.screenShareStream);else{console.log("av-c","await screenShareStream");let o={};e&&(o={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:o}),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()})),O.a.SCREEN_SHARING_REPLACE_MODE){if(s.cameraPublisher.videoSender){if(s.cameraPublisher.videoSender.replaceTrack(s.screenShareStream.getVideoTracks()[0]),!O.a.DISABLE_DUAL_STREAM){let e=s.screenShareStream.getVideoTracks()[0].clone();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 F.default(s),s.screenSharingPublisher.attachAndPublishScreenSharing()}}))()}isScreenSharing(){return!!this.screenShareStream}stopScreenShare(){var e=this;console.log("av-c","stopScreenShare"),O.a.SCREEN_SHARING_REPLACE_MODE?(this.cameraPublisher.stopVideoStream(this.screenShareStream),this.screenShareStream=null,this.screenSharing=!1,this.videoMuted?this.notifyMuteState():l()((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,g.a.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 o=this.getSelectedSdpSemantics();if(console.log("av-c","RTCPeerConnection configuration:",o),f.a.ICE_SERVERS&&f.a.ICE_SERVERS.length){o.iceServers=[];for(const e of f.a.ICE_SERVERS)o.iceServers.push({credential:e[2],credentialType:"password",urls:e[0],username:e[1]})}let t=O.a.FORCE_RELAY;void 0===t&&(t=O.a.FORCE_REPLAY),t&&(console.log("av-c","force relay",o.iceServers.length),o.iceTransportPolicy="relay");let r=new RTCPeerConnection(o);if(e!==this.selfUserInfo.uid){let o=this.getSubscriber(e);o.peerConnection=r,o.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,o){console.log("av-c","onConnectionStateChange",e,s,o),s.connectionState}hangup(){console.log("av-c","Ending call"),this.endCall(g.a.REASON_Hangup)}setAudioOnly(e){this.audioOnly=e,this.conference||this.sessionCallback&&this.sessionCallback.didChangeMode(e)}downgrade2Voice(e=!1){this.status===p.a.STATUS_CONNECTED&&(this.cameraPublisher.stopVideoTrack(this.cameraPublisher.cameraVideoStream),e||S.default.downgrade2VoiceCall(),this.setAudioOnly(!0))}downToVoice(){if(console.log("av-c","down to voice"),this.stopIncomingRing(),this.status===p.a.STATUS_INCOMING)return this.setAudioOnly(!0),void this.answerCall(!0);this.status===p.a.STATUS_CONNECTED&&(this.audioOnly||(this.setAudioOnly(!0),S.default.downgrade2VoiceCall()))}muteVideo(e){var s=this;return l()((function*(){return yield s.setVideoEnabled(!e)}))()}setVideoEnabled(e){var s=this;return l()((function*(){return s.status!==p.a.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()&&O.a.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 G.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 q.a;e.callId=this.callId,e.videoMuted=this.videoMuted,e.existParticipants=this.getExistParticipantsStatus(),S.default.sendSignalMessage(e,this.getParticipantIds(),!0,!1)}muteAudio(e){var s=this;return l()((function*(){return yield s.setAudioEnabled(!e)}))()}setAudioEnabled(e){var s=this;return l()((function*(){return s.status!==p.a.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 G.default(s),s.cameraPublisher.handleId=s.handleId,yield s.cameraPublisher.createMediaSenders()):s.cameraPublisher&&s.cameraPublisher.stopAudioTrack(s.cameraPublisher.cameraVideoStream),s.conference&&s.status===p.a.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(e,s){if(console.log("av-c","Ending media"),this.setState(p.a.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 o=!1;for(const[s,t]of this.subscriberMap)if(console.log("av-c","endUserCall acceptTime",t.acceptTime),t.acceptTime&&Object(M.gt)(t.acceptTime,0)&&e!==s){o=!0;break}if(o=o||this.acceptTime&&this.acceptTime&&Object(M.gt)(this.acceptTime,0),!o)return void this.endCall(s)}let o=this.getSubscriber(e);if(this.subscriberMap.delete(e),this.participantUserInfos&&(this.participantUserInfos=this.participantUserInfos.filter(s=>s.uid!==e)),o){if(o.peerConnection){o.peerConnection.getSenders().forEach(e=>o.peerConnection.removeTrack(e)),o.peerConnection.close(),o.peerConnection=null}if(e===this.initiatorId&&this.updateInitiator(),this.sessionCallback){let o=this.getScreenSharingUserId(e);this.sessionCallback.didParticipantLeft(o||e,s,null!==o)}}this.isAllBusy=this.isAllBusy&&s===g.a.RemoteBusy,this.conference||0!==this.subscriberMap.size||(0===this.conversation.type||this.singleCall?this.endCall(s):this.endCall(this.isAllBusy?g.a.RemoteBusy:g.a.REASON_AllLeft))}leaveConference(e){this.conference?this.endCall(g.a.REASON_Hangup,e):this.endCall(g.a.REASON_Hangup)}endCall(e,s){if(console.log("av-c","endCall ---- ",e,(new Error).stack),this.endReason=e,this.status===p.a.STATUS_IDLE)return;if(this.setState(p.a.STATUS_IDLE),!this.conference&&e!==g.a.REASON_AcceptByOtherClient&&e!==g.a.REASON_AllLeft&&this.getParticipantIds().length>0){let s=new v.a;s.callId=this.callId,s.inviteMsgUid=this.startMsgUid,s.reason=e,S.default.sendSignalMessage(s,this.getParticipantIds(),!1,!0)}if(e!==g.a.REASON_AcceptByOtherClient){let o={};o.handle_id=this.handleId,(s||e===g.a.REASON_AllLeft||this.conversation&&this.conversation.type===A.a.Single&&[g.a.RemoteBusy,g.a.REASON_RemoteHangup,g.a.RemoteTimeout].indexOf(e)>-1)&&(o.destroy=!0),console.log("av-c","leave",m()(o)),S.default.sendConferenceRequest(this.sessionId,this.callId,"leave",m()(o),(e,s)=>{0!==e&&console.log("av-c","conference request, leave error",e)})}let o={callId:this.callId,audioOnly:this.audioOnly,pin:this.pin,host:this.host,title:this.title,desc:this.desc,audience:this.audience,advance: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);S.default.currentSession=null,clearInterval(this.callTimer),clearInterval(this.soundMeterTimer),this.pcStatsTimer&&clearInterval(this.pcStatsTimer),this.endMedia(e,o),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?O.a.MAX_AUDIO_PARTICIPANT_COUNT:O.a.MAX_VIDEO_PARTICIPANT_COUNT,this.conference||(s.is_private=!0),this.record&&(s.record=!0),console.log("av-c","create room"),S.default.sendConferenceRequest(this.sessionId,this.callId,"create_room",m()(s),(s,o)=>{if(console.log("av-c","create_room res",s,o),0!==s)return void e(s);let t=JSON.parse(o);this.sessionId=t.session_id,this.handleId=t.handle_id;let r=t.data;this.callId,r.room,this.keepAlive(!0),e(0),this.conference&&this.setState(p.a.STATUS_CONNECTING)})}onConferenceEvent(e){let s;if(s="string"==typeof e?JSON.parse(e):e,console.log("av-c","onConferenceEvent",m()(e)),this.sessionId!==s.session_id)return void console.log("av-c","on conference event, unknown sessionId",this.sessionId,s.session_id);let o=s.sender;if(o>0&&this.screenSharingPublisher&&this.screenSharingPublisher.handleId===o)return;let t=s.data,r=t?t.videoroom:null;if("event"===r){let e=t.publishers;this.onPublish(e);let s=t.unpublished;s&&this.onUnpublish(s);let o=t.leaving;o&&("ok"===o&&"kicked"===t.reason?this.onLeave(this.selfUserInfo.uid):this.onLeave(o));let r=t.kicked;r&&this.onLeave(r);let i=t.joining;i&&this.onJoining([i]);let n=t.attendees;this.onJoining(n)}else if("destroyed"===r)this.endCall(g.a.RoomDestroyed);else if("participants"===r){let e=t.attendees;if(e&&e.length>0){let s=e.map(e=>({id:e}));this.onJoining(s)}let s=t.leavings;s&&s.length>0&&s.forEach(e=>{this.onLeave(e)})}else if("mute"===r){let e=t.mute;this.onMute(e)}else if("slowlink"===r){let e=s.handle_id;this.onSlowLink(this.sessionId,e,t)}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(()=>{S.default.sendConferenceRequest(this.sessionId,this.callId,"keepalive","",(e,s)=>{let o=(new Date).getTime();if(0===e)this.lastActiveTime=o;else{if(253===e||61===e)return console.error("av-c","keepalive error",e),void this.endCall(g.a.REASON_SignalError);this.lastActiveTime>0&&o-this.lastActiveTime>6e4&&(console.error("av-c","keepalive not response",o-this.lastActiveTime),this.endCall(g.a.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),S.default.sendConferenceRequest(this.sessionId,this.callId,"join_pub",m()(e),(e,s)=>{if(console.log("av-c","join_pub",e,s),0!==e)return void this.endCall(g.a.REASON_SignalError);let o=JSON.parse(s),t=o.data,r=t.error_code;if(r>0)return console.log("av-c","conference request, join_pub error",r),void(r===w.default.JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM?this.endCall(g.a.RoomNotExist):r===w.default.JANUS_VIDEOROOM_ERROR_ID_EXISTS&&setTimeout(()=>{this.status!==p.a.STATUS_IDLE&&(console.log("av-c","rejoin"),this.joinAndPublish())},500));this.sessionId=o.session_id,this.handleId=o.handle_id;let i=t.publishers;this.onPublish(i);t.id,t.videoroom;this.privateId=t.private_id;t.description,t.room;let n=t.attendees;this.onJoining(n),this.audience?this.setState(p.a.STATUS_CONNECTED):(this.cameraPublisher=new G.default(this),this.cameraPublisher.handleId=this.handleId,this.cameraPublisher.publishMedia()),this.keepAlive(!0)})}updateInitiator(){let e,s=(new Date).getTime()+864e5;Object(M.gt)(this.acceptTime,0)&&(s=this.acceptTime,e=this.selfUserInfo.uid),this.subscriberMap.forEach(o=>{Object(M.gt)(o.acceptTime,0)&&Object(M.gt)(s,o.acceptTime)&&(s=o.acceptTime,e=o.userId)});let o=this.initiatorId;this.initiatorId=e,this.subscriberMap.forEach(e=>{e.isInitiator=this.initiatorId===e.userId}),o!==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 o=e.display,t=!0,r=e.streams;for(const[e,i]of this.subscriberMap)if(e===s){i.streams(r),i.callExtra=o,i.subscribe(),i.audience=!1,t=!1;break}if(t){let e=new y.default(s,this);this.subscriberMap.set(e.userId,e);let t=(new Date).valueOf();if(this.setUserAcceptTime(e.userId,t),this.setUserJoinTime(e.userId,t),e.status=p.a.STATUS_CONNECTED,e.audience=!1,e.callExtra=o,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 o=!0,t=s.display;for(const[s,r]of this.subscriberMap)if(s===e){r.audience=!0,r.callExtra=t,o=!1;break}if(o){let s=new y.default(e,this);this.subscriberMap.set(s.userId,s);let o=(new Date).valueOf();if(this.setUserAcceptTime(s.userId,o),this.setUserJoinTime(s.userId,o),s.status=p.a.STATUS_CONNECTED,s.audience=!0,s.callExtra=t,this.sessionCallback){let e=this.getScreenSharingUserId(s.userId);this.sessionCallback.didParticipantJoined(e||s.userId,null!==e)}}}}}onUnpublish(e){for(const[s,o]of this.subscriberMap)if(s===e){o.audience=!0,o.videoMuted=!1,o.audioMuted=!1,o.peerConnection&&(o.peerConnection.close(),o.peerConnection=null),o.handleId=0;break}this.conference&&e!==this.selfUserInfo.uid&&this.reportAudienceChanged(e,!0)}reportAudienceChanged(e,s){let o=this.getScreenSharingUserId(e);this.sessionCallback&&this.sessionCallback.didChangeType(o||e,s,null!==o)}onSlowLink(e,s,o){if(!this.sessionCallback)return;let t=o.media,r=o.uplink,i=o.lost;if(this.handleId===s)this.sessionCallback.didMediaLostPacket(t,i,!1);else if(this.screenSharingPublisher&&this.screenSharingPublisher.handleId===s)this.sessionCallback.didMediaLostPacket(t,i,!0);else for(const[e,o]of this.subscriberMap)if(o.handleId===s){if(e.startsWith("screen_sharing_")){let s=e.substr("screen_sharing_".length);this.sessionCallback.didUserMediaLostPacket(s,t,i,r,!0)}else this.sessionCallback.didUserMediaLostPacket(e,t,i,r,!1);break}}onLeave(e){this.getSubscriber(e)?this.endUserCall(e,g.a.REASON_RemoteHangup):e===this.selfUserInfo.uid&&this.endCall(g.a.REASON_Hangup,!1)}mediaStream(){return this.screenShareStream?this.screenShareStream:this.cameraVideoStream}requestChangeMode(e,s){let o=new P.a(this.callId,s),t=new x.a(A.a.Single,e,0);S.default.sendSignalMessageEx(t,o,this.getParticipantIds(),!1,!1)}onRequestChangeMode(e){this.switchAudience(e)}onKickoff(){this.leaveConference(!1)}switchAudience(e){var s=this;return l()((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 G.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((o,t)=>{let r=e[t],i=!1,n=!1;r&&(i=!!r.hasOwnProperty("a")&&r.a,n=!!r.hasOwnProperty("v")&&r.v),o.videoMuted===n&&o.audioMuted===i||(o.videoMuted=n,o.audioMuted=i,o.audience||s.push(t))}),s=s.filter(e=>e!==this.selfUserInfo.uid),s.length>0&&this.sessionCallback&&this.sessionCallback.didMuteStateChanged(s)}notifyMuteState(){if(!this.conference||this.status===p.a.STATUS_IDLE)return;let e={handle_id:this.handleId,a:this.audioMuted};O.a.SCREEN_SHARING_REPLACE_MODE?e.v=this.videoMuted&&!this.isScreenSharing():e.v=this.videoMuted,S.default.sendConferenceRequest(this.sessionId,this.callId,"mute",m()(e),(e,s)=>{console.log("av-c","mute res",e,s)})}kickoffParticipant(e,s,o){if(this.status===p.a.STATUS_IDLE&&o&&o(-1),this.getSubscriber(e)){let t={handle_id:this.handleId,user:e};S.default.sendConferenceRequest(this.sessionId,this.callId,"kick",m()(t),(e,t)=>{console.log("av-c","kick res",e,t),0===e?s&&s():o&&o(e)})}}closeVoipWindow(){localStorage.getItem("enable_voip_debug")||(C.currentWindow?C.currentWindow.close():D.a.emitToMain("close-voip-div"))}setAudioInputDeviceId(e){console.log("av-c","setInputAudioDeviceId",this.audioInputDeviceId,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){console.log("av-c","setVideoInputDeviceId",this.videoInputDeviceId,e),e="null"===e?null:e,this.videoInputDeviceId=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",console.log("av-c","switch camera",this.videoCamera),this.cameraPublisher.stopVideoStream(this.cameraPublisher.cameraVideoStream),this.cameraPublisher.createMediaSenders(),!0)}rotate(e){console.log("av-c","rotate",e),this.cameraPublisher&&this.cameraPublisher.rotate(e)}screenSharingId(){return"screen_sharing_"+this.selfUserInfo.uid}getScreenSharingUserId(e=""){return e.startsWith("screen_sharing_")?e.substring("screen_sharing_".length):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+="