sip-connector 6.20.0 → 6.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SipConnector-3317ff75.cjs +1 -0
- package/dist/SipConnector-abcad4a1.js +1098 -0
- package/dist/SipConnector.d.ts +1 -5
- package/dist/doMock.cjs +1 -0
- package/dist/doMock.d.ts +3 -0
- package/dist/doMock.js +629 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +263 -1801
- package/dist/tools/__tests-utils__/parseObject.d.ts +3 -1
- package/dist/tools/__tests-utils__/resolveParseArray.d.ts +1 -1
- package/dist/tools/resolveUpdateRemoteStreams.d.ts +4 -1
- package/package.json +11 -8
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var nr=Object.defineProperty;var rr=(e,t,n)=>t in e?nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>(rr(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const I=require("@krivega/cancelable-promise"),dt=require("events-constructor"),se=require("debug"),sr=require("sequent-promises"),or=require("stack-promises"),ir="Connection Error",Vt="Request Timeout",ar="SIP Failure Code",cr="Internal Error",ur="Busy",Gt="Rejected",lr="Redirected",_r="Unavailable",me="Not Found",dr="Address Incomplete",Er="Incompatible SDP",hr="Missing SDP",fr="Authentication Error",Yt="Terminated",Sr="WebRTC Error",Xt="Canceled",gr="No Answer",Tr="Expires",Cr="No ACK",mr="Dialog Error",Rr="User Denied Media Access",Re="Bad Media Description",Nr="RTP Timeout",vr=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:dr,AUTHENTICATION_ERROR:fr,BAD_MEDIA_DESCRIPTION:Re,BUSY:ur,BYE:Yt,CANCELED:Xt,CONNECTION_ERROR:ir,DIALOG_ERROR:mr,EXPIRES:Tr,INCOMPATIBLE_SDP:Er,INTERNAL_ERROR:cr,MISSING_SDP:hr,NOT_FOUND:me,NO_ACK:Cr,NO_ANSWER:gr,REDIRECTED:lr,REJECTED:Gt,REQUEST_TIMEOUT:Vt,RTP_TIMEOUT:Nr,SIP_FAILURE_CODE:ar,UNAVAILABLE:_r,USER_DENIED_MEDIA_ACCESS:Rr,WEBRTC_ERROR:Sr},Symbol.toStringTag,{value:"Module"})),Ne="incomingCall",ve="declinedIncomingCall",Ae="failedIncomingCall",pe="terminatedIncomingCall",oe="connecting",j="connected",w="disconnected",V="newRTCSession",F="registered",be="unregistered",k="registrationFailed",zt="newMessage",ye="sipEvent",Oe="availableSecondRemoteStream",Ie="notAvailableSecondRemoteStream",Me="mustStopPresentation",G="shareState",Pe="enterRoom",De="useLicense",we="peerconnection:confirmed",$e="peerconnection:ontrack",Y="channels",Le="channels:notify",Ue="ended:fromserver",Fe="main-cam-control",ke="admin-stop-main-cam",Be="admin-start-main-cam",He="admin-stop-mic",xe="admin-start-mic",X="admin-force-sync-media-state",We="participant:added-to-list-moderators",qe="participant:removed-from-list-moderators",je="participant:move-request-to-conference",Ve="participant:move-request-to-stream",Ge="participant:canceling-word-request",Ye="webcast:started",Xe="webcast:stopped",ze="account:changed",Je="account:deleted",Ke="conference:participant-token-issued",B="ended",Jt="sending",Kt="reinvite",Qt="replaces",Zt="refer",en="progress",tn="accepted",z="confirmed",J="peerconnection",$="failed",nn="muted",rn="unmuted",Qe="newDTMF",Ze="newInfo",sn="hold",on="unhold",an="update",cn="sdp",un="icecandidate",ln="getusermediafailed",_n="peerconnection:createofferfailed",dn="peerconnection:createanswerfailed",En="peerconnection:setlocaldescriptionfailed",hn="peerconnection:setremotedescriptionfailed",fn="presentation:start",Sn="presentation:started",gn="presentation:end",et="presentation:ended",K="presentation:failed",Ar=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:tn,ACCOUNT_CHANGED:ze,ACCOUNT_DELETED:Je,ADMIN_FORCE_SYNC_MEDIA_STATE:X,ADMIN_START_MAIN_CAM:Be,ADMIN_START_MIC:xe,ADMIN_STOP_MAIN_CAM:ke,ADMIN_STOP_MIC:He,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Oe,CHANNELS:Y,CHANNELS_NOTIFY:Le,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:Ke,CONFIRMED:z,CONNECTED:j,CONNECTING:oe,DECLINED_INCOMING_CALL:ve,DISCONNECTED:w,ENDED:B,ENDED_FROM_SERVER:Ue,ENTER_ROOM:Pe,FAILED:$,FAILED_INCOMING_CALL:Ae,GET_USER_MEDIA_FAILED:ln,HOLD:sn,ICE_CANDIDATE:un,INCOMING_CALL:Ne,MAIN_CAM_CONTROL:Fe,MUST_STOP_PRESENTATION_EVENT:Me,MUTED:nn,NEW_DTMF:Qe,NEW_INFO:Ze,NEW_MESSAGE:zt,NEW_RTC_SESSION:V,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Ie,PARTICIPANT_ADDED_TO_LIST_MODERATORS:We,PARTICIPANT_CANCELLING_WORD_REQUEST:Ge,PARTICIPANT_MOVE_REQUEST_TO_CONFERENCE:je,PARTICIPANT_MOVE_REQUEST_TO_STREAM:Ve,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:qe,PEER_CONNECTION:J,PEER_CONNECTION_CONFIRMED:we,PEER_CONNECTION_CREATE_ANSWER_FAILED:dn,PEER_CONNECTION_CREATE_OFFER_FAILED:_n,PEER_CONNECTION_ONTRACK:$e,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:En,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:hn,PRESENTATION_END:gn,PRESENTATION_ENDED:et,PRESENTATION_FAILED:K,PRESENTATION_START:fn,PRESENTATION_STARTED:Sn,PROGRESS:en,REFER:Zt,REGISTERED:F,REGISTRATION_FAILED:k,REINVITE:Kt,REPLACES:Qt,SDP:cn,SENDING:Jt,SHARE_STATE:G,SIP_EVENT:ye,TERMINATED_INCOMING_CALL:pe,UNHOLD:on,UNMUTED:rn,UNREGISTERED:be,UPDATE:an,USE_LICENSE:De,WEBCAST_STARTED:Ye,WEBCAST_STOPPED:Xe},Symbol.toStringTag,{value:"Module"})),Tn=[Ne,ve,pe,Ae,Ge,Ve,je,Le,Ke,ze,Je,Ye,Xe,We,qe],tt=[oe,j,w,V,F,be,k,zt,ye],Cn=[Oe,Ie,Me,G,Pe,De,we,$e,Y,Ue,Fe,Be,ke,He,xe,X],nt=[B,oe,Jt,Kt,Qt,Zt,en,tn,z,J,$,nn,rn,Qe,Ze,sn,on,an,cn,un,ln,_n,dn,En,hn,fn,Sn,gn,et,K],mn=[...tt,...Tn],Rn=[...nt,...Cn],pr=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Rn,SESSION_JSSIP_EVENT_NAMES:nt,SESSION_SYNTHETICS_EVENT_NAMES:Cn,UA_EVENT_NAMES:mn,UA_JSSIP_EVENT_NAMES:tt,UA_SYNTHETICS_EVENT_NAMES:Tn},Symbol.toStringTag,{value:"Module"})),br=e=>{const t=[];return e&&t.push(`X-Vinteo-Remote: ${e}`),t},yr="content-type",Or="x-webrtc-enter-room",le="application/vinteo.webrtc.sharedesktop",Ir="application/vinteo.webrtc.roomname",Mr="application/vinteo.webrtc.channels",Pr="application/vinteo.webrtc.mediastate",Dr="application/vinteo.webrtc.refusal",Et="application/vinteo.webrtc.maincam",wr="application/vinteo.webrtc.mic",$r="application/vinteo.webrtc.uselic",Lr="X-WEBRTC-USE-LICENSE",ht="X-WEBRTC-INPUT-CHANNELS",ft="X-WEBRTC-OUTPUT-CHANNELS",Ur="X-WEBRTC-MAINCAM",Fr="X-WEBRTC-MIC",St="X-WEBRTC-SYNC",kr="X-WEBRTC-MAINCAM-RESOLUTION",Br="X-WEBRTC-MEDIA-STATE",Hr="X-Vinteo-Media-Type",xr="X-Vinteo-MainCam-State",Wr="X-Vinteo-Mic-State",qr="application/vinteo.webrtc.notify",jr="X-VINTEO-NOTIFY",x="x-webrtc-share-state",Vr=`${x}: LETMESTARTPRESENTATION`,Gr=`${x}: STOPPRESENTATION`,Nn="YOUCANRECEIVECONTENT",vn="CONTENTEND",Yr="YOUMUSTSTOPSENDCONTENT",Xr=`${x}: ${Nn}`,zr=`${x}: ${vn}`,Jr="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Kr=`${Jr}: LETMESTARTMAINCAM`,rt="sip-connector",_=se(rt),Qr=()=>{se.enable(`${rt}`)},Zr=()=>{se.enable(`-${rt}`)};var M=(e=>(e.PAUSE_MAIN_CAM="PAUSEMAINCAM",e.RESUME_MAIN_CAM="RESUMEMAINCAM",e.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",e.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",e.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",e))(M||{}),Q=(e=>(e.ADMIN_STOP_MIC="ADMINSTOPMIC",e.ADMIN_START_MIC="ADMINSTARTMIC",e))(Q||{}),Z=(e=>(e.ADMIN_SYNC_FORCED="1",e.ADMIN_SYNC_NOT_FORCED="0",e))(Z||{}),An=(e=>(e.AUDIO="AUDIO",e.VIDEO="VIDEO",e.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",e))(An||{});function es(e){return t=>`sip:${t}@${e}`}const ts=(e,t)=>()=>Math.floor(Math.random()*(t-e))+e,gt=e=>e.trim().replaceAll(" ","_"),ns=ts(1e5,99999999),_e=(e,{videoMode:t,audioMode:n}={})=>{if(!e||t==="recvonly"&&n==="recvonly")return;const r=n==="recvonly"?[]:e.getAudioTracks(),s=t==="recvonly"?[]:e.getVideoTracks(),o=[...r,...s],i=new MediaStream(o);return i.getTracks=()=>[...i.getAudioTracks(),...i.getVideoTracks()],i},rs=e=>e.some(n=>{const{kind:r}=n;return r==="video"}),ss="Error decline with 603",os=e=>e.message===ss,is=(e,t)=>e.find(n=>n.track&&t.getTracks().includes(n.track)),pn=1,bn=e=>(t,n)=>n!==void 0&&t!==n||n===void 0&&t!==e,as=bn(pn),cs=(e,t)=>{const n=e===void 0?void 0:Math.max(e,pn);if(n!==void 0&&as(n,t))return n},us=bn(),ls=(e,t)=>{if(us(e,t))return e},yn=async(e,t,n)=>{const r=e.getParameters();(r.encodings===void 0||r.encodings.length===0)&&(r.encodings=[{}]);const[s]=r.encodings,o=s.scaleResolutionDownBy,i=cs(t.scaleResolutionDownBy,o);let a=!1;i!==void 0&&(r.encodings[0].scaleResolutionDownBy=i,a=!0);const u=s.maxBitrate,l=ls(t.maxBitrate,u);return l!==void 0&&(r.encodings[0].maxBitrate=l,a=!0),a?(n&&n(r),e.setParameters(r).then(()=>({parameters:r,isChanged:a}))):{parameters:r,isChanged:a}},_s=async(e,t,n)=>{const r=is(e,t);if(r)return yn(r,{maxBitrate:n})},ds=486,Es=487,ge="local",Tt="remote",hs=(e=new Error)=>{const{originator:t,cause:n}=e;return I.isCanceledError(e)?!0:typeof n=="string"?n===Vt||n===Gt||t===ge&&(n===Xt||n===Yt):!1},D="SipConnector",fs="channels",Ss="WebcastStarted",gs="WebcastStopped",Ts="accountChanged",Cs="accountDeleted",ms="addedToListModerators",Rs="removedFromListModerators",Ns="WebcastParticipationAccepted",vs="WebcastParticipationRejected",As="ParticipantMovedToWebcast",ps="ConferenceParticipantTokenIssued";class bs{constructor({JsSIP:t}){c(this,"_isRegisterConfig",!1);c(this,"_connectionConfiguration",{});c(this,"_remoteStreams",{});c(this,"JsSIP");c(this,"_sessionEvents");c(this,"_uaEvents");c(this,"_cancelableConnect");c(this,"_cancelableCreateUa");c(this,"_cancelableDisconnect");c(this,"_cancelableSet");c(this,"_cancelableCall");c(this,"_cancelableAnswer");c(this,"_cancelableSendDTMF");c(this,"getSipServerUrl",t=>t);c(this,"promisePendingStartPresentation");c(this,"promisePendingStopPresentation");c(this,"ua");c(this,"session");c(this,"incomingSession");c(this,"_streamPresentationCurrent");c(this,"socket");c(this,"connect",async t=>(this._cancelRequests(),this._cancelableConnect.request(t)));c(this,"createUa",async t=>this._cancelableCreateUa.request(t));c(this,"set",async t=>this._cancelableSet.request(t));c(this,"call",async t=>this._cancelableCall.request(t));c(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));c(this,"answerToIncomingCall",async t=>this._cancelableAnswer.request(t));c(this,"sendDTMF",async t=>this._cancelableSendDTMF.request(t));c(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));c(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(oe,void 0);try{await this.unregister()}catch(t){_("tryRegister",t)}return this.register()});c(this,"declineToIncomingCall",async({statusCode:t=Es}={})=>new Promise((n,r)=>{if(!this.isAvailableIncomingCall){r(new Error("no incomingSession"));return}const s=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(ve,o),n(s.terminate({status_code:t}))}));c(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:ds}));c(this,"removeIncomingSession",()=>{delete this.incomingSession});c(this,"handleNewRTCSession",({originator:t,session:n})=>{if(t===Tt){this.incomingSession=n;const r=this.remoteCallerData;n.on($,s=>{this.removeIncomingSession(),s.originator===ge?this._uaEvents.trigger(pe,r):this._uaEvents.trigger(Ae,r)}),this._uaEvents.trigger(Ne,r)}});c(this,"_connect",async t=>this.createUa(t).then(async()=>this._start()));c(this,"_createUa",async({displayName:t="",user:n,password:r,register:s=!1,sipServerUrl:o,sipWebSocketServerURL:i,remoteAddress:a,extraHeaders:u=[],sdpSemantics:l="plan-b",sessionTimers:d=!1,registerExpires:E=60*5,connectionRecoveryMinInterval:h=2,connectionRecoveryMaxInterval:S=6,userAgent:g})=>{if(!o)throw new Error("sipServerUrl is required");if(!i)throw new Error("sipWebSocketServerURL is required");if(s&&!n)throw new Error("user is required for authorized connection");if(s&&!r)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:o,displayName:t,register:s,user:n,password:r},this._init({sipServerUrl:o,sipWebSocketServerURL:i});const C=s&&n?n.trim():`${ns()}`,m={password:r,register:s,display_name:gt(t),user_agent:g,sdp_semantics:l,sockets:[this.socket],uri:this.getSipServerUrl(C),session_timers:d,register_expires:E,connection_recovery_min_interval:h,connection_recovery_max_interval:S};this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!m.register,this.ua=new this.JsSIP.UA(m),this._uaEvents.eachTriggers((N,v)=>{const y=tt.find(f=>f===v);y&&this.ua&&this.ua.on(y,N)});const b=[...br(a),...u];return this.ua.registrator().setExtraHeaders(b),this.ua});c(this,"_start",async()=>new Promise((t,n)=>{const{ua:r}=this;if(!r){n(new Error("this.ua is not initialized"));return}const s=()=>{a(),t(r)},o=u=>{a(),n(u)},i=()=>{this.isRegisterConfig?(this.on(F,s),this.on(k,o)):this.on(j,s),this.on(w,o)},a=()=>{this.off(F,s),this.off(k,o),this.off(j,s),this.off(w,o)};i(),this.on(V,this.handleNewRTCSession),r.start()}));c(this,"_set",async({displayName:t,password:n})=>new Promise((r,s)=>{const{ua:o}=this;if(!o){s(new Error("this.ua is not initialized"));return}let i=!1,a=!1;t!==void 0&&t!==this._connectionConfiguration.displayName&&(i=o.set("display_name",gt(t)),this._connectionConfiguration.displayName=t),n!==void 0&&n!==this._connectionConfiguration.password&&(a=o.set("password",n),this._connectionConfiguration.password=n);const u=i||a;a&&this.isRegisterConfig?this.register().then(()=>{r(u)}).catch(s):u?r(u):s(u)}));c(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());c(this,"_disconnect",async()=>{this.off(V,this.handleNewRTCSession);const t=new Promise(n=>{this.once(w,()=>{delete this.ua,n()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(w,void 0)):this._uaEvents.trigger(w,void 0),t});c(this,"_call",async({number:t,mediaStream:n,extraHeaders:r=[],ontrack:s,iceServers:o,videoMode:i,audioMode:a,degradationPreference:u,offerToReceiveAudio:l=!0,offerToReceiveVideo:d=!0})=>new Promise((E,h)=>{const{ua:S}=this;if(!S){h(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=t,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(E).catch(h),this.session=S.call(this.getSipServerUrl(t),{extraHeaders:r,mediaStream:_e(n,{videoMode:i,audioMode:a}),eventHandlers:this._sessionEvents.triggers,videoMode:i,audioMode:a,degradationPreference:u,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:l,offerToReceiveVideo:d}})}));c(this,"_answer",async({mediaStream:t,ontrack:n,extraHeaders:r=[],iceServers:s,videoMode:o,audioMode:i,degradationPreference:a})=>new Promise((u,l)=>{if(!this.isAvailableIncomingCall){l(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:d}=this;if(!d){l(new Error("No session established"));return}this._sessionEvents.eachTriggers((h,S)=>{const g=nt.find(C=>C===S);g&&d.on(g,h)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=d.remote_identity.uri.user,this._handleCall({ontrack:n}).then(u).catch(l);const E=_e(t,{videoMode:o,audioMode:i});d.answer({extraHeaders:r,videoMode:o,audioMode:i,degradationPreference:a,mediaStream:E,pcConfig:{iceServers:s}})}));c(this,"_handleCall",async({ontrack:t})=>new Promise((n,r)=>{const s=()=>{this.onSession(J,d),this.onSession(z,E)},o=()=>{this.offSession(J,d),this.offSession(z,E)},i=()=>{this.onSession($,u),this.onSession(B,u)},a=()=>{this.offSession($,u),this.offSession(B,u)},u=h=>{o(),a(),r(h)};let l;const d=({peerconnection:h})=>{l=h,l.ontrack=S=>{this._sessionEvents.trigger($e,l),t&&t(S)}},E=()=>{l&&this._sessionEvents.trigger(we,l),o(),a(),n(l)};s(),i()}));c(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});c(this,"_sendDTMF",async t=>new Promise((n,r)=>{const{session:s}=this;if(!s){r(new Error("No session established"));return}this.onceSession(Qe,({originator:o})=>{o===ge&&n()}),s.sendDTMF(t,{duration:120,interToneGap:600})}));c(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:t}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),t.isEnded()||t.terminate()}});c(this,"_handleShareState",t=>{switch(t){case Nn:{this._sessionEvents.trigger(Oe,void 0);break}case vn:{this._sessionEvents.trigger(Ie,void 0);break}case Yr:{this._sessionEvents.trigger(Me,void 0);break}}});c(this,"_maybeTriggerChannels",t=>{const n=t.getHeader(ht),r=t.getHeader(ft);if(n&&r){const s={inputChannels:n,outputChannels:r};this._sessionEvents.trigger(Y,s)}});c(this,"_handleNotify",t=>{switch(t.cmd){case fs:{const n=t;this._triggerChannelsNotify(n);break}case Ss:{const n=t;this._triggerWebcastStartedNotify(n);break}case gs:{const n=t;this._triggerWebcastStoppedNotify(n);break}case ms:{const n=t;this._triggerAddedToListModeratorsNotify(n);break}case Rs:{const n=t;this._triggerRemovedFromListModeratorsNotify(n);break}case Ns:{const n=t;this._triggerParticipantMoveRequestToConference(n);break}case vs:{const n=t;this._triggerParticipantCancelingWordRequest(n);break}case As:{const n=t;this._triggerParticipantMoveRequestToStream(n);break}case Ts:{this._triggerAccountChangedNotify();break}case Cs:{this._triggerAccountDeletedNotify();break}case ps:{const n=t;this._triggerConferenceParticipantTokenIssued(n);break}default:_("unknown cmd",t.cmd)}});c(this,"_triggerRemovedFromListModeratorsNotify",({conference:t})=>{const n={conference:t};this._uaEvents.trigger(qe,n)});c(this,"_triggerAddedToListModeratorsNotify",({conference:t})=>{const n={conference:t};this._uaEvents.trigger(We,n)});c(this,"_triggerWebcastStartedNotify",({body:{conference:t,type:n}})=>{const r={conference:t,type:n};this._uaEvents.trigger(Ye,r)});c(this,"_triggerWebcastStoppedNotify",({body:{conference:t,type:n}})=>{const r={conference:t,type:n};this._uaEvents.trigger(Xe,r)});c(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(ze,void 0)});c(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(Je,void 0)});c(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:t,participant:n,jwt:r}})=>{const s={conference:t,participant:n,jwt:r};this._uaEvents.trigger(Ke,s)});c(this,"_triggerChannelsNotify",t=>{const n=t.input,r=t.output,s={inputChannels:n,outputChannels:r};this._uaEvents.trigger(Le,s)});c(this,"_triggerParticipantMoveRequestToConference",({body:{conference:t}})=>{const n={conference:t};this._uaEvents.trigger(je,n)});c(this,"_triggerParticipantCancelingWordRequest",({body:{conference:t}})=>{const n={conference:t};this._uaEvents.trigger(Ge,n)});c(this,"_triggerParticipantMoveRequestToStream",({body:{conference:t}})=>{const n={conference:t};this._uaEvents.trigger(Ve,n)});c(this,"_triggerEnterRoom",t=>{const n=t.getHeader(Or);this._sessionEvents.trigger(Pe,n)});c(this,"_triggerShareState",t=>{const n=t.getHeader(x);this._sessionEvents.trigger(G,n)});c(this,"_triggerMainCamControl",t=>{const n=t.getHeader(Ur),r=t.getHeader(St),s=r===Z.ADMIN_SYNC_FORCED;if(n===M.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(Be,{isSyncForced:s});else if(n===M.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(ke,{isSyncForced:s});else if((n===M.RESUME_MAIN_CAM||n===M.PAUSE_MAIN_CAM)&&r)this._sessionEvents.trigger(X,{isSyncForced:s});else{const o=t.getHeader(kr);this._sessionEvents.trigger(Fe,{mainCam:n,resolutionMainCam:o})}});c(this,"_triggerMicControl",t=>{const n=t.getHeader(Fr),s=t.getHeader(St)===Z.ADMIN_SYNC_FORCED;n===Q.ADMIN_START_MIC?this._sessionEvents.trigger(xe,{isSyncForced:s}):n===Q.ADMIN_STOP_MIC&&this._sessionEvents.trigger(He,{isSyncForced:s})});c(this,"_triggerUseLicense",t=>{const n=t.getHeader(Lr);this._sessionEvents.trigger(De,n)});c(this,"_handleNewInfo",t=>{const{originator:n}=t;if(n!=="remote")return;const{request:r}=t,s=r.getHeader(yr);if(s)switch(s){case Ir:{this._triggerEnterRoom(r),this._maybeTriggerChannels(r);break}case qr:{this._maybeHandleNotify(r);break}case le:{this._triggerShareState(r);break}case Et:{this._triggerMainCamControl(r);break}case wr:{this._triggerMicControl(r);break}case $r:{this._triggerUseLicense(r);break}}});c(this,"_handleSipEvent",({request:t})=>{this._maybeHandleNotify(t)});c(this,"_maybeHandleNotify",t=>{const n=t.getHeader(jr);if(n){const r=JSON.parse(n);this._handleNotify(r)}});c(this,"_handleEnded",t=>{const{originator:n}=t;n===Tt&&this._sessionEvents.trigger(Ue,t),this._restoreSession()});this.JsSIP=t,this._sessionEvents=new dt(Rn),this._uaEvents=new dt(mn),this._cancelableConnect=new I.CancelableRequest(this._connect,{moduleName:D,afterCancelRequest:()=>{this._cancelableCreateUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableCreateUa=new I.CancelableRequest(this._createUa,{moduleName:D}),this._cancelableDisconnect=new I.CancelableRequest(this._disconnect,{moduleName:D}),this._cancelableSet=new I.CancelableRequest(this._set,{moduleName:D}),this._cancelableCall=new I.CancelableRequest(this._call,{moduleName:D}),this._cancelableAnswer=new I.CancelableRequest(this._answer,{moduleName:D}),this._cancelableSendDTMF=new I.CancelableRequest(this._sendDTMF,{moduleName:D}),this.onSession(G,this._handleShareState),this.onSession(Ze,this._handleNewInfo),this.on(ye,this._handleSipEvent),this.onSession($,this._handleEnded),this.onSession(B,this._handleEnded)}async register(){return new Promise((t,n)=>{this.isRegisterConfig&&this.ua?(this.ua.on(F,t),this.ua.on(k,n),this.ua.register()):n(new Error("Config is not registered"))})}async unregister(){return new Promise((t,n)=>{this.isRegistered&&this.ua?(this.ua.on(be,t),this.ua.unregister()):n(new Error("ua is not registered"))})}async sendOptions(t,n,r){if(!this.ua)throw new Error("is not connected");return new Promise((s,o)=>{try{this.ua.sendOptions(t,n,{extraHeaders:r,eventHandlers:{succeeded:()=>{s()},failed:o}})}catch(i){o(i)}})}async ping(t,n){var s;if(!((s=this.ua)!=null&&s.configuration.uri))throw new Error("is not connected");const r=this.ua.configuration.uri;return this.sendOptions(r,t,n)}async replaceMediaStream(t,n){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(t,n)}async askPermissionToEnableCam(t={}){if(!this.session)throw new Error("No session established");const n=[Kr];return this.session.sendInfo(Et,void 0,{noTerminateWhenError:!0,...t,extraHeaders:n}).catch(r=>{if(os(r))throw r})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(t,n,{maxBitrate:r,degradationPreference:s,isNeedReinvite:o=!0,isP2P:i=!1}){const a=_e(n);this._streamPresentationCurrent=a;const u=i?[Xr]:[Vr],l=t.sendInfo(le,void 0,{extraHeaders:u}).then(async()=>t.startPresentation(a,o,s)).then(async()=>{const{connection:d}=this;if(!d||r===void 0)return;const E=d.getSenders();return _s(E,n,r)}).then(()=>n).catch(d=>{throw this._sessionEvents.trigger(K,d),d});return this.promisePendingStartPresentation=l,l.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(t,{isNeedReinvite:n=!0,isP2P:r=!1,maxBitrate:s,degradationPreference:o}={}){const i=this.establishedSession;if(!i)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return this._sendPresentation(i,t,{isNeedReinvite:n,isP2P:r,maxBitrate:s,degradationPreference:o})}async stopPresentation({isP2P:t=!1}={}){const n=this._streamPresentationCurrent;let r=this.promisePendingStartPresentation??Promise.resolve();const s=t?[zr]:[Gr],o=this.establishedSession;return o&&n&&(r=r.then(async()=>o.sendInfo(le,void 0,{extraHeaders:s})).then(async()=>o.stopPresentation(n)).catch(i=>{throw this._sessionEvents.trigger(K,i),i})),!o&&n&&this._sessionEvents.trigger(et,n),this.promisePendingStopPresentation=r,r.finally(()=>{this._resetPresentation()})}async updatePresentation(t,{isP2P:n=!1,maxBitrate:r,degradationPreference:s}={}){const o=this.establishedSession;if(!o)throw new Error("No session established");if(!this._streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this._sendPresentation(o,t,{isP2P:n,maxBitrate:r,degradationPreference:s,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(t,n){return this._uaEvents.on(t,n)}once(t,n){return this._uaEvents.once(t,n)}onceRace(t,n){return this._uaEvents.onceRace(t,n)}async wait(t){return this._uaEvents.wait(t)}off(t,n){this._uaEvents.off(t,n)}onSession(t,n){return this._sessionEvents.on(t,n)}onceSession(t,n){return this._sessionEvents.once(t,n)}onceRaceSession(t,n){return this._sessionEvents.onceRace(t,n)}async waitSession(t){return this._sessionEvents.wait(t)}offSession(t,n){this._sessionEvents.off(t,n)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const n=this.connection.getReceivers().map(({track:r})=>r);return rs(n)?this._generateStreams(n):this._generateAudioStreams(n)}get connection(){var n;return(n=this.session)==null?void 0:n.connection}get remoteCallerData(){var t,n,r,s,o,i;return{displayName:(n=(t=this.incomingSession)==null?void 0:t.remote_identity)==null?void 0:n.display_name,host:(s=(r=this.incomingSession)==null?void 0:r.remote_identity)==null?void 0:s.uri.host,incomingNumber:(i=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:i.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableCreateUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){return this.session&&this.session.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!!(this.ua&&this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_init({sipServerUrl:t,sipWebSocketServerURL:n}){this.getSipServerUrl=es(t),this.socket=new this.JsSIP.WebSocketInterface(n)}_generateStream(t,n){const{id:r}=t,s=this._remoteStreams[r]||new MediaStream;return n&&s.addTrack(n),s.addTrack(t),this._remoteStreams[r]=s,s}_generateAudioStream(t){const{id:n}=t,r=this._remoteStreams[n]||new MediaStream;return r.addTrack(t),this._remoteStreams[n]=r,r}_generateStreams(t){const n=[];return t.forEach((r,s)=>{if(r.kind==="audio")return;const o=r,i=t[s-1];let a;i&&i.kind==="audio"&&(a=i);const u=this._generateStream(o,a);n.push(u)}),n}_generateAudioStreams(t){return t.map(r=>this._generateAudioStream(r))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}async waitChannels(){return this.waitSession(Y)}async waitSyncMediaState(){return this.waitSession(X)}async sendChannels({inputChannels:t,outputChannels:n}){if(!this.session)throw new Error("No session established");const r=`${ht}: ${t}`,s=`${ft}: ${n}`,o=[r,s];return this.session.sendInfo(Mr,void 0,{extraHeaders:o})}async sendMediaState({cam:t,mic:n},r={}){if(!this.session)throw new Error("No session established");const s=`${Br}: currentstate`,o=`${xr}: ${Number(t)}`,i=`${Wr}: ${Number(n)}`,a=[s,o,i];return this.session.sendInfo(Pr,void 0,{noTerminateWhenError:!0,...r,extraHeaders:a})}async _sendRefusalToTurnOn(t,n={}){if(!this.session)throw new Error("No session established");const a=[`${Hr}: ${t==="mic"?0:1}`];return this.session.sendInfo(Dr,void 0,{noTerminateWhenError:!0,...n,extraHeaders:a})}async sendRefusalToTurnOnMic(t={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...t})}async sendRefusalToTurnOnCam(t={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...t})}}const On="purgatory",H=e=>e===On,st=e=>()=>(_("getRemoteStreams"),e.getRemoteStreams()),ys=({kind:e,readyState:t})=>e==="video"&&t==="live",In=e=>({track:t})=>{ys(t)&&e()};var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ot(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Os(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var L=Os,Is=typeof q=="object"&&q&&q.Object===Object&&q,Mn=Is,Ms=Mn,Ps=typeof self=="object"&&self&&self.Object===Object&&self,Ds=Ms||Ps||Function("return this")(),ie=Ds,ws=ie,$s=function(){return ws.Date.now()},Ls=$s,Us=/\s/;function Fs(e){for(var t=e.length;t--&&Us.test(e.charAt(t)););return t}var ks=Fs,Bs=ks,Hs=/^\s+/;function xs(e){return e&&e.slice(0,Bs(e)+1).replace(Hs,"")}var Ws=xs,qs=ie,js=qs.Symbol,ae=js,Ct=ae,Pn=Object.prototype,Vs=Pn.hasOwnProperty,Gs=Pn.toString,U=Ct?Ct.toStringTag:void 0;function Ys(e){var t=Vs.call(e,U),n=e[U];try{e[U]=void 0;var r=!0}catch{}var s=Gs.call(e);return r&&(t?e[U]=n:delete e[U]),s}var Xs=Ys,zs=Object.prototype,Js=zs.toString;function Ks(e){return Js.call(e)}var Qs=Ks,mt=ae,Zs=Xs,eo=Qs,to="[object Null]",no="[object Undefined]",Rt=mt?mt.toStringTag:void 0;function ro(e){return e==null?e===void 0?no:to:Rt&&Rt in Object(e)?Zs(e):eo(e)}var ce=ro;function so(e){return e!=null&&typeof e=="object"}var W=so,oo=ce,io=W,ao="[object Symbol]";function co(e){return typeof e=="symbol"||io(e)&&oo(e)==ao}var Dn=co,uo=Ws,Nt=L,lo=Dn,vt=0/0,_o=/^[-+]0x[0-9a-f]+$/i,Eo=/^0b[01]+$/i,ho=/^0o[0-7]+$/i,fo=parseInt;function So(e){if(typeof e=="number")return e;if(lo(e))return vt;if(Nt(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Nt(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=uo(e);var n=Eo.test(e);return n||ho.test(e)?fo(e.slice(2),n?2:8):_o.test(e)?vt:+e}var go=So,To=L,de=Ls,At=go,Co="Expected a function",mo=Math.max,Ro=Math.min;function No(e,t,n){var r,s,o,i,a,u,l=0,d=!1,E=!1,h=!0;if(typeof e!="function")throw new TypeError(Co);t=At(t)||0,To(n)&&(d=!!n.leading,E="maxWait"in n,o=E?mo(At(n.maxWait)||0,t):o,h="trailing"in n?!!n.trailing:h);function S(f){var R=r,p=s;return r=s=void 0,l=f,i=e.apply(p,R),i}function g(f){return l=f,a=setTimeout(A,t),d?S(f):i}function C(f){var R=f-u,p=f-l,P=t-R;return E?Ro(P,o-p):P}function m(f){var R=f-u,p=f-l;return u===void 0||R>=t||R<0||E&&p>=o}function A(){var f=de();if(m(f))return b(f);a=setTimeout(A,C(f))}function b(f){return a=void 0,h&&r?S(f):(r=s=void 0,i)}function N(){a!==void 0&&clearTimeout(a),l=0,r=u=s=a=void 0}function v(){return a===void 0?i:b(de())}function y(){var f=de(),R=m(f);if(r=arguments,s=this,u=f,R){if(a===void 0)return g(u);if(E)return clearTimeout(a),a=setTimeout(A,t),S(u)}return a===void 0&&(a=setTimeout(A,t)),i}return y.cancel=N,y.flush=v,y}var vo=No;const Ao=ot(vo),it=({getRemoteStreams:e,setRemoteStreams:t})=>Ao(()=>{const n=e();_("remoteStreams",n),n&&t(n)},200),po=e=>async n=>{const{mediaStream:r,extraHeaders:s,iceServers:o,degradationPreference:i,setRemoteStreams:a,onBeforeProgressCall:u,onSuccessProgressCall:l,onEnterPurgatory:d,onEnterConference:E,onFailProgressCall:h,onFinishProgressCall:S,onEndedCall:g}=n,C=it({setRemoteStreams:a,getRemoteStreams:st(e)}),m=In(C);_("answerIncomingCall",n);const A=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:s,iceServers:o,degradationPreference:i,ontrack:m}),b=()=>{const{remoteCallerData:T}=e;return T.incomingNumber};let N=!1,v;const f=(()=>(_("subscribeEnterConference: onEnterConference",E),d??E?e.onSession("enterRoom",T=>{_("enterRoom",{_room:T,isSuccessProgressCall:N}),v=T,H(v)?d&&d():E&&E({isSuccessProgressCall:N})}):()=>{}))(),R=T=>(_("onSuccess"),N=!0,C(),l&&l({isPurgatory:H(v)}),e.onceRaceSession(["ended","failed"],()=>{f(),g&&g()}),T),p=T=>{throw _("onFail"),h&&h(),f(),T},P=()=>{_("onFinish"),S&&S()};if(_("onBeforeProgressCall"),u){const T=b();u(T)}return A().then(R).catch(p).finally(P)},bo=e=>async n=>{const{conference:r,mediaStream:s,extraHeaders:o,iceServers:i,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:l,onSuccessProgressCall:d,onEnterPurgatory:E,onEnterConference:h,onFailProgressCall:S,onFinishProgressCall:g,onEndedCall:C}=n,m=it({setRemoteStreams:u,getRemoteStreams:st(e)}),A=In(m);_("callToServer",n);const b=async()=>(_("startCall"),e.call({mediaStream:s,extraHeaders:o,iceServers:i,degradationPreference:a,number:r,ontrack:A}));let N=!1,v;const f=(()=>(_("subscribeEnterConference: onEnterConference",h),E??h?e.onSession("enterRoom",T=>{_("enterRoom",{_room:T,isSuccessProgressCall:N}),v=T,H(v)?E&&E():h&&h({isSuccessProgressCall:N})}):()=>{}))(),R=T=>(_("onSuccess"),N=!0,m(),d&&d({isPurgatory:H(v)}),e.onceRaceSession(["ended","failed"],()=>{f(),C&&C()}),T),p=T=>{throw _("onFail"),S&&S(),f(),T},P=()=>{_("onFinish"),g&&g()};return _("onBeforeProgressCall"),l&&l(r),b().then(R).catch(p).finally(P)},Ee=e=>{if(!I.isCanceledError(e))throw e;return!1},yo=e=>async n=>{const{userAgent:r,sipWebSocketServerURL:s,sipServerUrl:o,remoteAddress:i,displayName:a,name:u,password:l,isRegisteredUser:d,sdpSemantics:E,isDisconnectOnFail:h}=n;return _("connectToServer",n),e.connect({userAgent:r,sdpSemantics:E,sipWebSocketServerURL:s,sipServerUrl:o,remoteAddress:i,displayName:a,password:l,user:u,register:d}).then(()=>(_("connectToServer then"),!0)).catch(async S=>(_("connectToServer catch: error",S),h===!0?e.disconnect().then(()=>Ee(S)).catch(()=>Ee(S)):Ee(S)))},Oo=e=>async()=>(_("disconnectFromServer"),e.disconnect().then(()=>(_("disconnectFromServer: then"),!1)).catch(t=>(_("disconnectFromServer: catch",t),!1))),at=e=>{const{url:t,cause:n}=e;let r=t;return(n===Re||n===me)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var wn=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))(wn||{});const Io=(e=new Error)=>{var s;const{cause:t,socket:n}=e;let r="CONNECT_SERVER_FAILED";switch(t){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case Re:{r="BAD_MEDIA_ERROR";break}case me:{r="NOT_FOUND_ERROR";break}default:n&&((s=n==null?void 0:n._ws)==null?void 0:s.readyState)===3?r="WS_CONNECTION_FAILED":at(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},Mo=(e=new Error)=>{const{code:t,cause:n,message:r}=e,s=at(e),o={};return r&&(o.message=r),s&&(o.link=s),t&&(o.code=t),n&&(o.cause=n),o},Po=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:wn,getLinkError:at,getTypeFromError:Io,getValuesFromError:Mo},Symbol.toStringTag,{value:"Module"})),Do=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:r,isRegistered:s,isPresentationCall:o})=>{const i=[],a=n?"0":"1",u=r?"0":"1";return i.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${u}`),s||i.push("X-Vinteo-Purgatory-Call: yes"),e&&i.push(`X-Vinteo-Session: ${e}`),o&&i.push("X-Vinteo-Presentation-Call: yes"),t&&i.push(`X-Vinteo-Remote: ${t}`),i},wo=({appName:e,appVersion:t,browserName:n,browserVersion:r})=>{const s=`${e} ${t}`;return`ChromeNew - ${n?`${n} ${r}, ${s}`:s}`},$o=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:r,appName:s})=>e?wo({appVersion:t,browserName:n,browserVersion:r,appName:s}):"Chrome",Lo=e=>async()=>{if(e.isCallActive)return _("askPermissionToEnableCam"),e.askPermissionToEnableCam()},Uo=e=>n=>(_("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Fo=e=>n=>(_("onUseLicense"),e.onSession("useLicense",n)),ko=e=>async({isEnabledCam:n,isEnabledMic:r})=>{if(e.isCallActive)return _("sendMediaState"),e.sendMediaState({cam:n,mic:r})},Bo=e=>async()=>{if(e.isCallActive)return _("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{_("sendRefusalToTurnOnCam: error",n)})},Ho=e=>async()=>{if(e.isCallActive)return _("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{_("sendRefusalToTurnOnMic: error",n)})},xo=1e6,Wo=({maxBitrate:e=xo,sipConnector:t})=>async({mediaStream:r,isP2P:s=!1})=>(_("startPresentation"),t.startPresentation(r,{isP2P:s,maxBitrate:e})),qo=({sipConnector:e})=>async({isP2P:n=!1}={})=>(_("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(_)),jo=1e6,Vo=({sipConnector:e,maxBitrate:t=jo})=>async({mediaStream:r,isP2P:s=!1})=>(_("updatePresentation"),e.updatePresentation(r,{isP2P:s,maxBitrate:t}));var Go=L,pt=Object.create,Yo=function(){function e(){}return function(t){if(!Go(t))return{};if(pt)return pt(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}(),$n=Yo;function Xo(){}var ct=Xo,zo=$n,Jo=ct;function ee(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=void 0}ee.prototype=zo(Jo.prototype);ee.prototype.constructor=ee;var ut=ee;function Ko(e,t){for(var n=-1,r=t.length,s=e.length;++n<r;)e[s+n]=t[n];return e}var Qo=Ko,Zo=ce,ei=W,ti="[object Arguments]";function ni(e){return ei(e)&&Zo(e)==ti}var ri=ni,bt=ri,si=W,Ln=Object.prototype,oi=Ln.hasOwnProperty,ii=Ln.propertyIsEnumerable,ai=bt(function(){return arguments}())?bt:function(e){return si(e)&&oi.call(e,"callee")&&!ii.call(e,"callee")},ci=ai,ui=Array.isArray,ue=ui,yt=ae,li=ci,_i=ue,Ot=yt?yt.isConcatSpreadable:void 0;function di(e){return _i(e)||li(e)||!!(Ot&&e&&e[Ot])}var Ei=di,hi=Qo,fi=Ei;function Un(e,t,n,r,s){var o=-1,i=e.length;for(n||(n=fi),s||(s=[]);++o<i;){var a=e[o];t>0&&n(a)?t>1?Un(a,t-1,n,r,s):hi(s,a):r||(s[s.length]=a)}return s}var Si=Un,gi=Si;function Ti(e){var t=e==null?0:e.length;return t?gi(e,1):[]}var Ci=Ti;function mi(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Ri=mi,Ni=Ri,It=Math.max;function vi(e,t,n){return t=It(t===void 0?e.length-1:t,0),function(){for(var r=arguments,s=-1,o=It(r.length-t,0),i=Array(o);++s<o;)i[s]=r[t+s];s=-1;for(var a=Array(t+1);++s<t;)a[s]=r[s];return a[t]=n(i),Ni(e,this,a)}}var Ai=vi;function pi(e){return function(){return e}}var bi=pi,yi=ce,Oi=L,Ii="[object AsyncFunction]",Mi="[object Function]",Pi="[object GeneratorFunction]",Di="[object Proxy]";function wi(e){if(!Oi(e))return!1;var t=yi(e);return t==Mi||t==Pi||t==Ii||t==Di}var Fn=wi,$i=ie,Li=$i["__core-js_shared__"],Ui=Li,he=Ui,Mt=function(){var e=/[^.]+$/.exec(he&&he.keys&&he.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Fi(e){return!!Mt&&Mt in e}var ki=Fi,Bi=Function.prototype,Hi=Bi.toString;function xi(e){if(e!=null){try{return Hi.call(e)}catch{}try{return e+""}catch{}}return""}var Wi=xi,qi=Fn,ji=ki,Vi=L,Gi=Wi,Yi=/[\\^$.*+?()[\]{}|]/g,Xi=/^\[object .+?Constructor\]$/,zi=Function.prototype,Ji=Object.prototype,Ki=zi.toString,Qi=Ji.hasOwnProperty,Zi=RegExp("^"+Ki.call(Qi).replace(Yi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(e){if(!Vi(e)||ji(e))return!1;var t=qi(e)?Zi:Xi;return t.test(Gi(e))}var ta=ea;function na(e,t){return e==null?void 0:e[t]}var ra=na,sa=ta,oa=ra;function ia(e,t){var n=oa(e,t);return sa(n)?n:void 0}var kn=ia,aa=kn,ca=function(){try{var e=aa(Object,"defineProperty");return e({},"",{}),e}catch{}}(),ua=ca;function la(e){return e}var _a=la,da=bi,Pt=ua,Ea=_a,ha=Pt?function(e,t){return Pt(e,"toString",{configurable:!0,enumerable:!1,value:da(t),writable:!0})}:Ea,fa=ha,Sa=800,ga=16,Ta=Date.now;function Ca(e){var t=0,n=0;return function(){var r=Ta(),s=ga-(r-n);if(n=r,s>0){if(++t>=Sa)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var ma=Ca,Ra=fa,Na=ma,va=Na(Ra),Aa=va,pa=Ci,ba=Ai,ya=Aa;function Oa(e){return ya(ba(e,void 0,pa),e+"")}var Ia=Oa,Ma=kn,Pa=ie,Da=Ma(Pa,"WeakMap"),wa=Da,Dt=wa,$a=Dt&&new Dt,La=$a;function Ua(){}var Fa=Ua,wt=La,ka=Fa,Ba=wt?function(e){return wt.get(e)}:ka,Bn=Ba,Ha={},xa=Ha,$t=xa,Wa=Object.prototype,qa=Wa.hasOwnProperty;function ja(e){for(var t=e.name+"",n=$t[t],r=qa.call($t,t)?n.length:0;r--;){var s=n[r],o=s.func;if(o==null||o==e)return s.name}return t}var Hn=ja,Va=$n,Ga=ct,Ya=4294967295;function te(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Ya,this.__views__=[]}te.prototype=Va(Ga.prototype);te.prototype.constructor=te;var lt=te;function Xa(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}var za=Xa,Ja=lt,Ka=ut,Qa=za;function Za(e){if(e instanceof Ja)return e.clone();var t=new Ka(e.__wrapped__,e.__chain__);return t.__actions__=Qa(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}var ec=Za,tc=lt,Lt=ut,nc=ct,rc=ue,sc=W,oc=ec,ic=Object.prototype,ac=ic.hasOwnProperty;function ne(e){if(sc(e)&&!rc(e)&&!(e instanceof tc)){if(e instanceof Lt)return e;if(ac.call(e,"__wrapped__"))return oc(e)}return new Lt(e)}ne.prototype=nc.prototype;ne.prototype.constructor=ne;var cc=ne,uc=lt,lc=Bn,_c=Hn,dc=cc;function Ec(e){var t=_c(e),n=dc[t];if(typeof n!="function"||!(t in uc.prototype))return!1;if(e===n)return!0;var r=lc(n);return!!r&&e===r[0]}var hc=Ec,Ut=ut,fc=Ia,Sc=Bn,fe=Hn,gc=ue,Ft=hc,Tc="Expected a function",Cc=8,mc=32,Rc=128,Nc=256;function vc(e){return fc(function(t){var n=t.length,r=n,s=Ut.prototype.thru;for(e&&t.reverse();r--;){var o=t[r];if(typeof o!="function")throw new TypeError(Tc);if(s&&!i&&fe(o)=="wrapper")var i=new Ut([],!0)}for(r=i?r:n;++r<n;){o=t[r];var a=fe(o),u=a=="wrapper"?Sc(o):void 0;u&&Ft(u[0])&&u[1]==(Rc|Cc|mc|Nc)&&!u[4].length&&u[9]==1?i=i[fe(u[0])].apply(i,u[3]):i=o.length==1&&Ft(o)?i[a]():i.thru(o)}return function(){var l=arguments,d=l[0];if(i&&l.length==1&&gc(d))return i.plant(d).value();for(var E=0,h=n?t[E].apply(this,l):d;++E<n;)h=t[E].call(this,h);return h}})}var Ac=vc,pc=Ac,bc=pc(),yc=bc;const Oc=ot(yc);function Ic(e,t){for(var n=-1,r=e==null?0:e.length,s=Array(r);++n<r;)s[n]=t(e[n],n,e);return s}var Mc=Ic,kt=ae,Pc=Mc,Dc=ue,wc=Dn,$c=1/0,Bt=kt?kt.prototype:void 0,Ht=Bt?Bt.toString:void 0;function xn(e){if(typeof e=="string")return e;if(Dc(e))return Pc(e,xn)+"";if(wc(e))return Ht?Ht.call(e):"";var t=e+"";return t=="0"&&1/e==-$c?"-0":t}var Wn=xn;function Lc(e,t,n){var r=-1,s=e.length;t<0&&(t=-t>s?0:s+t),n=n>s?s:n,n<0&&(n+=s),s=t>n?0:n-t>>>0,t>>>=0;for(var o=Array(s);++r<s;)o[r]=e[r+t];return o}var Uc=Lc,Fc=Uc;function kc(e,t,n){var r=e.length;return n=n===void 0?r:n,!t&&n>=r?e:Fc(e,t,n)}var Bc=kc,Hc="\\ud800-\\udfff",xc="\\u0300-\\u036f",Wc="\\ufe20-\\ufe2f",qc="\\u20d0-\\u20ff",jc=xc+Wc+qc,Vc="\\ufe0e\\ufe0f",Gc="\\u200d",Yc=RegExp("["+Gc+Hc+jc+Vc+"]");function Xc(e){return Yc.test(e)}var qn=Xc;function zc(e,t){return e===t||e!==e&&t!==t}var Jc=zc,Kc=9007199254740991;function Qc(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Kc}var Zc=Qc,eu=Fn,tu=Zc;function nu(e){return e!=null&&tu(e.length)&&!eu(e)}var ru=nu,su=9007199254740991,ou=/^(?:0|[1-9]\d*)$/;function iu(e,t){var n=typeof e;return t=t??su,!!t&&(n=="number"||n!="symbol"&&ou.test(e))&&e>-1&&e%1==0&&e<t}var au=iu,cu=Jc,uu=ru,lu=au,_u=L;function du(e,t,n){if(!_u(n))return!1;var r=typeof t;return(r=="number"?uu(n)&&lu(t,n.length):r=="string"&&t in n)?cu(n[t],e):!1}var Eu=du,hu=ce,fu=W,Su="[object RegExp]";function gu(e){return fu(e)&&hu(e)==Su}var Tu=gu;function Cu(e){return function(t){return e(t)}}var mu=Cu,re={exports:{}};re.exports;(function(e,t){var n=Mn,r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,o=s&&s.exports===r,i=o&&n.process,a=function(){try{var u=s&&s.require&&s.require("util").types;return u||i&&i.binding&&i.binding("util")}catch{}}();e.exports=a})(re,re.exports);var Ru=re.exports,Nu=Tu,vu=mu,xt=Ru,Wt=xt&&xt.isRegExp,Au=Wt?vu(Wt):Nu,pu=Au;function bu(e){return e.split("")}var yu=bu,jn="\\ud800-\\udfff",Ou="\\u0300-\\u036f",Iu="\\ufe20-\\ufe2f",Mu="\\u20d0-\\u20ff",Pu=Ou+Iu+Mu,Du="\\ufe0e\\ufe0f",wu="["+jn+"]",Te="["+Pu+"]",Ce="\\ud83c[\\udffb-\\udfff]",$u="(?:"+Te+"|"+Ce+")",Vn="[^"+jn+"]",Gn="(?:\\ud83c[\\udde6-\\uddff]){2}",Yn="[\\ud800-\\udbff][\\udc00-\\udfff]",Lu="\\u200d",Xn=$u+"?",zn="["+Du+"]?",Uu="(?:"+Lu+"(?:"+[Vn,Gn,Yn].join("|")+")"+zn+Xn+")*",Fu=zn+Xn+Uu,ku="(?:"+[Vn+Te+"?",Te,Gn,Yn,wu].join("|")+")",Bu=RegExp(Ce+"(?="+Ce+")|"+ku+Fu,"g");function Hu(e){return e.match(Bu)||[]}var xu=Hu,Wu=yu,qu=qn,ju=xu;function Vu(e){return qu(e)?ju(e):Wu(e)}var Gu=Vu,Yu=Wn;function Xu(e){return e==null?"":Yu(e)}var zu=Xu,Ju=Wn,Ku=Bc,Qu=qn,Zu=Eu,el=pu,tl=Gu,nl=zu,rl=4294967295;function sl(e,t,n){return n&&typeof n!="number"&&Zu(e,t,n)&&(t=n=void 0),n=n===void 0?rl:n>>>0,n?(e=nl(e),e&&(typeof t=="string"||t!=null&&!el(t))&&(t=Ju(t),!t&&Qu(e))?Ku(tl(e),0,n):e.split(t,n)):[]}var ol=sl;const il=ot(ol),al=e=>Oc(t=>il(t,""),t=>t.map(n=>async()=>e(n))),cl=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const s=al(t)(e);return sr(s,n)},ul=e=>n=>(_("onStartMainCam"),e.onSession("admin-start-main-cam",n)),ll=e=>n=>(_("onStartMic"),e.onSession("admin-start-mic",n)),_l=e=>n=>(_("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),dl=e=>n=>(_("onStopMic"),e.onSession("admin-stop-mic",n)),El=({sipConnector:e})=>{const t=(g,C)=>({isSyncForced:m=!1})=>{if(m){g();return}C()},n=ul(e),r=_l(e),s=ll(e),o=dl(e);let i=()=>{},a=()=>{},u=()=>{},l=()=>{};const d=({onStartMainCamForced:g,onStartMainCamNotForced:C,onStopMainCamForced:m,onStopMainCamNotForced:A,onStartMicForced:b,onStartMicNotForced:N,onStopMicForced:v,onStopMicNotForced:y})=>{const f=t(g,C);i=n(f);const R=t(m,A);a=r(R);const p=t(b,N);u=s(p);const P=t(v,y);l=o(P)},E=()=>{i(),a(),u(),l()};return{start:g=>{d(g)},stop:()=>{E()}}},hl=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:On,createSyncMediaState:El,error:Po,getExtraHeaders:Do,getUserAgent:$o,hasPurgatory:H,resolveAnswerIncomingCall:po,resolveAskPermissionToEnableCam:Lo,resolveCallToServer:bo,resolveConnectToServer:yo,resolveDisconnectFromServer:Oo,resolveGetRemoteStreams:st,resolveOnMustStopPresentation:Uo,resolveOnUseLicense:Fo,resolveSendMediaState:ko,resolveSendRefusalToTurnOnCam:Bo,resolveSendRefusalToTurnOnMic:Ho,resolveStartPresentation:Wo,resolveStopShareSipConnector:qo,resolveUpdatePresentation:Vo,resolveUpdateRemoteStreams:it,sendDTMFAccumulated:cl},Symbol.toStringTag,{value:"Module"})),fl=e=>[...e.keys()].map(t=>e.get(t)),Sl=(e,t)=>fl(e).find(n=>n.type===t),Jn=async e=>e.getStats().then(t=>{const n=Sl(t,"codec");return n==null?void 0:n.mimeType}),gl=e=>e.find(t=>{var n;return((n=t==null?void 0:t.track)==null?void 0:n.kind)==="video"}),Kn=(e,t)=>e!==void 0&&t!==void 0&&e.toLowerCase().includes(t.toLowerCase()),Tl=1e6,O=e=>e*Tl,Qn=O(.06),Cl=O(4),ml=e=>e<=64?Qn:e<=128?O(.12):e<=256?O(.25):e<=384?O(.32):e<=426?O(.38):e<=640?O(.5):e<=848?O(.7):e<=1280?O(1):e<=1920?O(2):Cl,Rl="av1",Nl=e=>Kn(e,Rl),vl=.6,Zn=(e,t)=>Nl(t)?e*vl:e,Al=e=>Zn(Qn,e),er=(e,t)=>{const n=ml(e);return Zn(n,t)},tr=or(),pl=async()=>tr().catch(e=>{_("videoSendingBalancer: error",e)}),bl=async e=>(tr.add(e),pl()),_t=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:r})=>bl(async()=>yn(e,{scaleResolutionDownBy:t,maxBitrate:n},r)),yl=async({sender:e,codec:t},n)=>{const s=Al(t);return _t({sender:e,maxBitrate:s,onSetParameters:n,scaleResolutionDownBy:200})},Se=async({sender:e,track:t,codec:n},r)=>{const i=t.getSettings().width,a=er(i,n);return _t({sender:e,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:1})},Ol=async({sender:e,track:t,resolution:n,codec:r},s)=>{const o=t.getSettings(),i=o.width,a=o.height,[u,l]=n.split("x"),d=i/Number(u),E=a/Number(l),S=Math.max(d,E,1),g=er(Number(u),r);return _t({sender:e,maxBitrate:g,onSetParameters:s,scaleResolutionDownBy:S})},Il=async({mainCam:e,resolutionMainCam:t,sender:n,track:r,codec:s},o)=>{switch(e){case M.PAUSE_MAIN_CAM:return yl({sender:n,codec:s},o);case M.RESUME_MAIN_CAM:return Se({sender:n,track:r,codec:s},o);case M.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?Ol({sender:n,track:r,codec:s,resolution:t},o):Se({sender:n,track:r,codec:s},o);default:return Se({sender:n,track:r,codec:s},o)}},qt={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},jt=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:r,ignoreForCodec:s})=>{const o=n.getSenders(),i=gl(o);if(!(i!=null&&i.track))return qt;const a=await Jn(i);return Kn(a,s)?qt:Il({mainCam:e,resolutionMainCam:t,sender:i,codec:a,track:i.track},r)},Ml=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const r=async()=>{const{connection:u}=e;if(!u)throw new Error("connection is not exist");return jt({connection:u,onSetParameters:n,ignoreForCodec:t})};let s=r;const o=async u=>(s=async()=>{const{mainCam:l,resolutionMainCam:d}=u,{connection:E}=e;if(!E)throw new Error("connection is not exist");return jt({mainCam:l,resolutionMainCam:d,connection:E,onSetParameters:n,ignoreForCodec:t})},s());return{subscribe:()=>{e.onSession("main-cam-control",o)},unsubscribe:()=>{e.offSession("main-cam-control",o)},balanceByTrack:r,resetMainCamControl(){s=r},async reBalance(){return s()}}};exports.debug=se;exports.EEventsMainCAM=M;exports.EEventsMic=Q;exports.EEventsSyncMediaState=Z;exports.EUseLicense=An;exports.causes=vr;exports.constants=Ar;exports.default=bs;exports.disableDebug=Zr;exports.enableDebug=Qr;exports.eventNames=pr;exports.getCodecFromSender=Jn;exports.hasCanceledCallError=hs;exports.resolveVideoSendingBalancer=Ml;exports.tools=hl;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-3317ff75.cjs"),j=require("ts-debounce"),H=require("@krivega/cancelable-promise"),Y=require("sequent-promises"),z=require("stack-promises"),J=require("debug");require("events-constructor");const L="purgatory",N=e=>e===L,P=e=>()=>(r.logger("getRemoteStreams"),e.getRemoteStreams()),Q=({kind:e,readyState:t})=>e==="video"&&t==="live",V=e=>({track:t})=>{Q(t)&&e()},D=({getRemoteStreams:e,setRemoteStreams:t})=>j.debounce(()=>{const n=e();r.logger("remoteStreams",n),n&&t(n)},200),Z=e=>async n=>{const{mediaStream:s,extraHeaders:o,iceServers:a,degradationPreference:c,setRemoteStreams:u,onBeforeProgressCall:i,onSuccessProgressCall:S,onEnterPurgatory:d,onEnterConference:l,onFailProgressCall:f,onFinishProgressCall:m,onEndedCall:C}=n,R=D({setRemoteStreams:u,getRemoteStreams:P(e)}),_=V(R);r.logger("answerIncomingCall",n);const y=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:a,degradationPreference:c,ontrack:_}),h=()=>{const{remoteCallerData:g}=e;return g.incomingNumber};let M=!1,T;const b=(()=>(r.logger("subscribeEnterConference: onEnterConference",l),d??l?e.onSession("enterRoom",g=>{r.logger("enterRoom",{_room:g,isSuccessProgressCall:M}),T=g,N(T)?d&&d():l&&l({isSuccessProgressCall:M})}):()=>{}))(),O=g=>(r.logger("onSuccess"),M=!0,R(),S&&S({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),C&&C()}),g),v=g=>{throw r.logger("onFail"),f&&f(),b(),g},A=()=>{r.logger("onFinish"),m&&m()};if(r.logger("onBeforeProgressCall"),i){const g=h();i(g)}return y().then(O).catch(v).finally(A)},ee=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:a,iceServers:c,degradationPreference:u,setRemoteStreams:i,onBeforeProgressCall:S,onSuccessProgressCall:d,onEnterPurgatory:l,onEnterConference:f,onFailProgressCall:m,onFinishProgressCall:C,onEndedCall:R}=n,_=D({setRemoteStreams:i,getRemoteStreams:P(e)}),y=V(_);r.logger("callToServer",n);const h=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:a,iceServers:c,degradationPreference:u,number:s,ontrack:y}));let M=!1,T;const b=(()=>(r.logger("subscribeEnterConference: onEnterConference",f),l??f?e.onSession("enterRoom",g=>{r.logger("enterRoom",{_room:g,isSuccessProgressCall:M}),T=g,N(T)?l&&l():f&&f({isSuccessProgressCall:M})}):()=>{}))(),O=g=>(r.logger("onSuccess"),M=!0,_(),d&&d({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),R&&R()}),g),v=g=>{throw r.logger("onFail"),m&&m(),b(),g},A=()=>{r.logger("onFinish"),C&&C()};return r.logger("onBeforeProgressCall"),S&&S(s),h().then(O).catch(v).finally(A)},I=e=>{if(!H.isCanceledError(e))throw e;return!1},ne=e=>async n=>{const{userAgent:s,sipWebSocketServerURL:o,sipServerUrl:a,remoteAddress:c,displayName:u,name:i,password:S,isRegisteredUser:d,sdpSemantics:l,isDisconnectOnFail:f}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sdpSemantics:l,sipWebSocketServerURL:o,sipServerUrl:a,remoteAddress:c,displayName:u,password:S,user:i,register:d}).then(()=>(r.logger("connectToServer then"),!0)).catch(async m=>(r.logger("connectToServer catch: error",m),f===!0?e.disconnect().then(()=>I(m)).catch(()=>I(m)):I(m)))},te=e=>async()=>(r.logger("disconnectFromServer"),e.disconnect().then(()=>(r.logger("disconnectFromServer: then"),!1)).catch(t=>(r.logger("disconnectFromServer: catch",t),!1))),w=e=>{const{url:t,cause:n}=e;let s=t;return(n===r.BAD_MEDIA_DESCRIPTION||n===r.NOT_FOUND)&&(s=`${e.message.to.uri.user}@${e.message.to.uri.host}`),s};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const re=(e=new Error)=>{var o;const{cause:t,socket:n}=e;let s="CONNECT_SERVER_FAILED";switch(t){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case r.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case r.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:n&&((o=n==null?void 0:n._ws)==null?void 0:o.readyState)===3?s="WS_CONNECTION_FAILED":w(e)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},se=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=w(e),a={};return s&&(a.message=s),o&&(a.link=o),t&&(a.code=t),n&&(a.cause=n),a},oe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:w,getTypeFromError:re,getValuesFromError:se},Symbol.toStringTag,{value:"Module"})),ae=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:a})=>{const c=[],u=n?"0":"1",i=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${i}`),o||c.push("X-Vinteo-Purgatory-Call: yes"),e&&c.push(`X-Vinteo-Session: ${e}`),a&&c.push("X-Vinteo-Presentation-Call: yes"),t&&c.push(`X-Vinteo-Remote: ${t}`),c},ce=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const o=`${e} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${o}`:o}`},ie=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?ce({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",ue=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},le=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),ge=e=>n=>(r.logger("onUseLicense"),e.onSession("useLicense",n)),Se=e=>async({isEnabledCam:n,isEnabledMic:s})=>{if(e.isCallActive)return r.logger("sendMediaState"),e.sendMediaState({cam:n,mic:s})},de=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},me=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},Ce=1e6,fe=({maxBitrate:e=Ce,sipConnector:t})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("startPresentation"),t.startPresentation(s,{isP2P:o,maxBitrate:e})),Ee=({sipConnector:e})=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(r.logger)),Re=1e6,Me=({sipConnector:e,maxBitrate:t=Re})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("updatePresentation"),e.updatePresentation(s,{isP2P:o,maxBitrate:t})),Te=e=>t=>[...t].map(s=>async()=>e(s)),_e=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=Te(t)(e);return Y(o,n)},be=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),ye=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),he=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Oe=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),ve=({sipConnector:e})=>{const t=(C,R)=>({isSyncForced:_=!1})=>{if(_){C();return}R()},n=be(e),s=he(e),o=ye(e),a=Oe(e);let c=()=>{},u=()=>{},i=()=>{},S=()=>{};const d=({onStartMainCamForced:C,onStartMainCamNotForced:R,onStopMainCamForced:_,onStopMainCamNotForced:y,onStartMicForced:h,onStartMicNotForced:M,onStopMicForced:T,onStopMicNotForced:B})=>{const b=t(C,R);c=n(b);const O=t(_,y);u=s(O);const v=t(h,M);i=o(v);const A=t(T,B);S=a(A)},l=()=>{c(),u(),i(),S()};return{start:C=>{d(C)},stop:()=>{l()}}},Ae=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:L,createSyncMediaState:ve,error:oe,getExtraHeaders:ae,getUserAgent:ie,hasPurgatory:N,resolveAnswerIncomingCall:Z,resolveAskPermissionToEnableCam:ue,resolveCallToServer:ee,resolveConnectToServer:ne,resolveDisconnectFromServer:te,resolveGetRemoteStreams:P,resolveOnMustStopPresentation:le,resolveOnUseLicense:ge,resolveSendMediaState:Se,resolveSendRefusalToTurnOnCam:de,resolveSendRefusalToTurnOnMic:me,resolveStartPresentation:fe,resolveStopShareSipConnector:Ee,resolveUpdatePresentation:Me,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:_e},Symbol.toStringTag,{value:"Module"})),Ne=e=>[...e.keys()].map(t=>e.get(t)),Be=(e,t)=>Ne(e).find(n=>n.type===t),x=async e=>e.getStats().then(t=>{const n=Be(t,"codec");return n==null?void 0:n.mimeType}),Ie=e=>e.find(t=>{var n;return((n=t==null?void 0:t.track)==null?void 0:n.kind)==="video"}),q=(e,t)=>e!==void 0&&t!==void 0&&e.toLowerCase().includes(t.toLowerCase()),pe=1e6,E=e=>e*pe,G=E(.06),Pe=E(4),De=e=>e<=64?G:e<=128?E(.12):e<=256?E(.25):e<=384?E(.32):e<=426?E(.38):e<=640?E(.5):e<=848?E(.7):e<=1280?E(1):e<=1920?E(2):Pe,we="av1",Fe=e=>q(e,we),ke=.6,X=(e,t)=>Fe(t)?e*ke:e,Ue=e=>X(G,e),K=(e,t)=>{const n=De(e);return X(n,t)},W=z(),Le=async()=>W().catch(e=>{r.logger("videoSendingBalancer: error",e)}),Ve=async e=>(W.add(e),Le()),F=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>Ve(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),$e=async({sender:e,codec:t},n)=>{const o=Ue(t);return F({sender:e,maxBitrate:o,onSetParameters:n,scaleResolutionDownBy:200})},p=async({sender:e,track:t,codec:n},s)=>{const c=t.getSettings().width,u=K(c,n);return F({sender:e,maxBitrate:u,onSetParameters:s,scaleResolutionDownBy:1})},xe=async({sender:e,track:t,resolution:n,codec:s},o)=>{const a=t.getSettings(),c=a.width,u=a.height,[i,S]=n.split("x"),d=c/Number(i),l=u/Number(S),m=Math.max(d,l,1),C=K(Number(i),s);return F({sender:e,maxBitrate:C,onSetParameters:o,scaleResolutionDownBy:m})},qe=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},a)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return $e({sender:n,codec:o},a);case r.EEventsMainCAM.RESUME_MAIN_CAM:return p({sender:n,track:s,codec:o},a);case r.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?xe({sender:n,track:s,codec:o,resolution:t},a):p({sender:n,track:s,codec:o},a);default:return p({sender:n,track:s,codec:o},a)}},k={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},U=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>{const a=n.getSenders(),c=Ie(a);if(!(c!=null&&c.track))return k;const u=await x(c);return q(u,o)?k:qe({mainCam:e,resolutionMainCam:t,sender:c,codec:u,track:c.track},s)},Ge=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:i}=e;if(!i)throw new Error("connection is not exist");return U({connection:i,onSetParameters:n,ignoreForCodec:t})};let o=s;const a=async i=>(o=async()=>{const{mainCam:S,resolutionMainCam:d}=i,{connection:l}=e;if(!l)throw new Error("connection is not exist");return U({mainCam:S,resolutionMainCam:d,connection:l,onSetParameters:n,ignoreForCodec:t})},o());return{subscribe:()=>{e.onSession("main-cam-control",a)},unsubscribe:()=>{e.offSession("main-cam-control",a)},balanceByTrack:s,resetMainCamControl(){o=s},async reBalance(){return o()}}};exports.EEventsMainCAM=r.EEventsMainCAM;exports.EEventsMic=r.EEventsMic;exports.EEventsSyncMediaState=r.EEventsSyncMediaState;exports.EUseLicense=r.EUseLicense;exports.causes=r.causes;exports.constants=r.constants;exports.default=r.SipConnector;exports.disableDebug=r.disableDebug;exports.enableDebug=r.enableDebug;exports.eventNames=r.eventNames;exports.hasCanceledCallError=r.hasCanceledCallError;exports.debug=J;exports.getCodecFromSender=x;exports.resolveVideoSendingBalancer=Ge;exports.tools=Ae;
|