sip-connector 6.20.0 → 6.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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";var Yt=Object.defineProperty;var Gt=(n,e,t)=>e in n?Yt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>(Gt(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const I=require("@krivega/cancelable-promise"),Ye=require("events-constructor"),J=require("debug"),Xt=require("ts-debounce"),zt=require("sequent-promises"),Kt=require("stack-promises"),Jt="Connection Error",et="Request Timeout",Qt="SIP Failure Code",jt="Internal Error",Zt="Busy",tt="Rejected",en="Redirected",tn="Unavailable",se="Not Found",nn="Address Incomplete",sn="Incompatible SDP",rn="Missing SDP",on="Authentication Error",nt="Terminated",an="WebRTC Error",st="Canceled",cn="No Answer",un="Expires",En="No ACK",ln="Dialog Error",_n="User Denied Media Access",re="Bad Media Description",dn="RTP Timeout",Sn=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:nn,AUTHENTICATION_ERROR:on,BAD_MEDIA_DESCRIPTION:re,BUSY:Zt,BYE:nt,CANCELED:st,CONNECTION_ERROR:Jt,DIALOG_ERROR:ln,EXPIRES:un,INCOMPATIBLE_SDP:sn,INTERNAL_ERROR:jt,MISSING_SDP:rn,NOT_FOUND:se,NO_ACK:En,NO_ANSWER:cn,REDIRECTED:en,REJECTED:tt,REQUEST_TIMEOUT:et,RTP_TIMEOUT:dn,SIP_FAILURE_CODE:Qt,UNAVAILABLE:tn,USER_DENIED_MEDIA_ACCESS:_n,WEBRTC_ERROR:an},Symbol.toStringTag,{value:"Module"})),oe="incomingCall",ie="declinedIncomingCall",ae="failedIncomingCall",ce="terminatedIncomingCall",Q="connecting",q="connected",P="disconnected",V="newRTCSession",L="registered",ue="unregistered",B="registrationFailed",rt="newMessage",Ee="sipEvent",le="availableSecondRemoteStream",_e="notAvailableSecondRemoteStream",de="mustStopPresentation",W="shareState",Se="enterRoom",he="useLicense",Te="peerconnection:confirmed",Ce="peerconnection:ontrack",$="channels",ge="channels:notify",Ne="ended:fromserver",Re="main-cam-control",me="admin-stop-main-cam",Ae="admin-start-main-cam",fe="admin-stop-mic",Ie="admin-start-mic",x="admin-force-sync-media-state",Me="participant:added-to-list-moderators",Oe="participant:removed-from-list-moderators",De="participant:move-request-to-conference",Pe="participant:move-request-to-stream",pe="participant:canceling-word-request",ve="webcast:started",be="webcast:stopped",ye="account:changed",we="account:deleted",Ue="conference:participant-token-issued",F="ended",ot="sending",it="reinvite",at="replaces",ct="refer",ut="progress",Et="accepted",Y="confirmed",G="peerconnection",b="failed",lt="muted",_t="unmuted",Le="newDTMF",Be="newInfo",dt="hold",St="unhold",ht="update",Tt="sdp",Ct="icecandidate",gt="getusermediafailed",Nt="peerconnection:createofferfailed",Rt="peerconnection:createanswerfailed",mt="peerconnection:setlocaldescriptionfailed",At="peerconnection:setremotedescriptionfailed",ft="presentation:start",It="presentation:started",Mt="presentation:end",Fe="presentation:ended",X="presentation:failed",hn=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Et,ACCOUNT_CHANGED:ye,ACCOUNT_DELETED:we,ADMIN_FORCE_SYNC_MEDIA_STATE:x,ADMIN_START_MAIN_CAM:Ae,ADMIN_START_MIC:Ie,ADMIN_STOP_MAIN_CAM:me,ADMIN_STOP_MIC:fe,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:le,CHANNELS:$,CHANNELS_NOTIFY:ge,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:Ue,CONFIRMED:Y,CONNECTED:q,CONNECTING:Q,DECLINED_INCOMING_CALL:ie,DISCONNECTED:P,ENDED:F,ENDED_FROM_SERVER:Ne,ENTER_ROOM:Se,FAILED:b,FAILED_INCOMING_CALL:ae,GET_USER_MEDIA_FAILED:gt,HOLD:dt,ICE_CANDIDATE:Ct,INCOMING_CALL:oe,MAIN_CAM_CONTROL:Re,MUST_STOP_PRESENTATION_EVENT:de,MUTED:lt,NEW_DTMF:Le,NEW_INFO:Be,NEW_MESSAGE:rt,NEW_RTC_SESSION:V,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:_e,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Me,PARTICIPANT_CANCELLING_WORD_REQUEST:pe,PARTICIPANT_MOVE_REQUEST_TO_CONFERENCE:De,PARTICIPANT_MOVE_REQUEST_TO_STREAM:Pe,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:Oe,PEER_CONNECTION:G,PEER_CONNECTION_CONFIRMED:Te,PEER_CONNECTION_CREATE_ANSWER_FAILED:Rt,PEER_CONNECTION_CREATE_OFFER_FAILED:Nt,PEER_CONNECTION_ONTRACK:Ce,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:mt,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:At,PRESENTATION_END:Mt,PRESENTATION_ENDED:Fe,PRESENTATION_FAILED:X,PRESENTATION_START:ft,PRESENTATION_STARTED:It,PROGRESS:ut,REFER:ct,REGISTERED:L,REGISTRATION_FAILED:B,REINVITE:it,REPLACES:at,SDP:Tt,SENDING:ot,SHARE_STATE:W,SIP_EVENT:Ee,TERMINATED_INCOMING_CALL:ce,UNHOLD:St,UNMUTED:_t,UNREGISTERED:ue,UPDATE:ht,USE_LICENSE:he,WEBCAST_STARTED:ve,WEBCAST_STOPPED:be},Symbol.toStringTag,{value:"Module"})),Ot=[oe,ie,ce,ae,pe,Pe,De,ge,Ue,ye,we,ve,be,Me,Oe],ke=[Q,q,P,V,L,ue,B,rt,Ee],Dt=[le,_e,de,W,Se,he,Te,Ce,$,Ne,Re,Ae,me,fe,Ie,x],He=[F,Q,ot,it,at,ct,ut,Et,Y,G,b,lt,_t,Le,Be,dt,St,ht,Tt,Ct,gt,Nt,Rt,mt,At,ft,It,Mt,Fe,X],Pt=[...ke,...Ot],pt=[...He,...Dt],Tn=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:pt,SESSION_JSSIP_EVENT_NAMES:He,SESSION_SYNTHETICS_EVENT_NAMES:Dt,UA_EVENT_NAMES:Pt,UA_JSSIP_EVENT_NAMES:ke,UA_SYNTHETICS_EVENT_NAMES:Ot},Symbol.toStringTag,{value:"Module"})),Cn=n=>{const e=[];return n&&e.push(`X-Vinteo-Remote: ${n}`),e},gn="content-type",Nn="x-webrtc-enter-room",j="application/vinteo.webrtc.sharedesktop",Rn="application/vinteo.webrtc.roomname",mn="application/vinteo.webrtc.channels",An="application/vinteo.webrtc.mediastate",fn="application/vinteo.webrtc.refusal",Ge="application/vinteo.webrtc.maincam",In="application/vinteo.webrtc.mic",Mn="application/vinteo.webrtc.uselic",On="X-WEBRTC-USE-LICENSE",Xe="X-WEBRTC-INPUT-CHANNELS",ze="X-WEBRTC-OUTPUT-CHANNELS",Dn="X-WEBRTC-MAINCAM",Pn="X-WEBRTC-MIC",Ke="X-WEBRTC-SYNC",pn="X-WEBRTC-MAINCAM-RESOLUTION",vn="X-WEBRTC-MEDIA-STATE",bn="X-Vinteo-Media-Type",yn="X-Vinteo-MainCam-State",wn="X-Vinteo-Mic-State",Un="application/vinteo.webrtc.notify",Ln="X-VINTEO-NOTIFY",H="x-webrtc-share-state",Bn=`${H}: LETMESTARTPRESENTATION`,Fn=`${H}: STOPPRESENTATION`,vt="YOUCANRECEIVECONTENT",bt="CONTENTEND",kn="YOUMUSTSTOPSENDCONTENT",Hn=`${H}: ${vt}`,qn=`${H}: ${bt}`,Vn="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Wn=`${Vn}: LETMESTARTMAINCAM`,qe="sip-connector",E=J(qe),$n=()=>{J.enable(`${qe}`)},xn=()=>{J.enable(`-${qe}`)};var M=(n=>(n.PAUSE_MAIN_CAM="PAUSEMAINCAM",n.RESUME_MAIN_CAM="RESUMEMAINCAM",n.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",n.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",n.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",n))(M||{}),z=(n=>(n.ADMIN_STOP_MIC="ADMINSTOPMIC",n.ADMIN_START_MIC="ADMINSTARTMIC",n))(z||{}),K=(n=>(n.ADMIN_SYNC_FORCED="1",n.ADMIN_SYNC_NOT_FORCED="0",n))(K||{}),yt=(n=>(n.AUDIO="AUDIO",n.VIDEO="VIDEO",n.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",n))(yt||{});function Yn(n){return e=>`sip:${e}@${n}`}const Gn=(n,e)=>()=>Math.floor(Math.random()*(e-n))+n,Je=n=>n.trim().replaceAll(" ","_"),Xn=Gn(1e5,99999999),Z=(n,{videoMode:e,audioMode:t}={})=>{if(!n||e==="recvonly"&&t==="recvonly")return;const s=t==="recvonly"?[]:n.getAudioTracks(),r=e==="recvonly"?[]:n.getVideoTracks(),o=[...s,...r],i=new MediaStream(o);return i.getTracks=()=>[...i.getAudioTracks(),...i.getVideoTracks()],i},zn=n=>n.some(t=>{const{kind:s}=t;return s==="video"}),Kn="Error decline with 603",Jn=n=>n.message===Kn,Qn=(n,e)=>n.find(t=>t.track&&e.getTracks().includes(t.track)),wt=1,Ut=n=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==n,jn=Ut(wt),Zn=(n,e)=>{const t=n===void 0?void 0:Math.max(n,wt);if(t!==void 0&&jn(t,e))return t},es=Ut(),ts=(n,e)=>{if(es(n,e))return n},Lt=async(n,e,t)=>{const s=n.getParameters();(s.encodings===void 0||s.encodings.length===0)&&(s.encodings=[{}]);const[r]=s.encodings,o=r.scaleResolutionDownBy,i=Zn(e.scaleResolutionDownBy,o);let c=!1;i!==void 0&&(s.encodings[0].scaleResolutionDownBy=i,c=!0);const u=r.maxBitrate,l=ts(e.maxBitrate,u);return l!==void 0&&(s.encodings[0].maxBitrate=l,c=!0),c?(t&&t(s),n.setParameters(s).then(()=>({parameters:s,isChanged:c}))):{parameters:s,isChanged:c}},ns=async(n,e,t)=>{const s=Qn(n,e);if(s)return Lt(s,{maxBitrate:t})},ss=486,rs=487,ne="local",Qe="remote",os=(n=new Error)=>{const{originator:e,cause:t}=n;return I.isCanceledError(n)?!0:typeof t=="string"?t===et||t===tt||e===ne&&(t===st||t===nt):!1},D="SipConnector",is="channels",as="WebcastStarted",cs="WebcastStopped",us="accountChanged",Es="accountDeleted",ls="addedToListModerators",_s="removedFromListModerators",ds="WebcastParticipationAccepted",Ss="WebcastParticipationRejected",hs="ParticipantMovedToWebcast",Ts="ConferenceParticipantTokenIssued";class Cs{constructor({JsSIP:e}){a(this,"_isRegisterConfig",!1);a(this,"_connectionConfiguration",{});a(this,"_remoteStreams",{});a(this,"JsSIP");a(this,"_sessionEvents");a(this,"_uaEvents");a(this,"_cancelableConnect");a(this,"_cancelableCreateUa");a(this,"_cancelableDisconnect");a(this,"_cancelableSet");a(this,"_cancelableCall");a(this,"_cancelableAnswer");a(this,"_cancelableSendDTMF");a(this,"getSipServerUrl",e=>e);a(this,"promisePendingStartPresentation");a(this,"promisePendingStopPresentation");a(this,"ua");a(this,"session");a(this,"incomingSession");a(this,"_streamPresentationCurrent");a(this,"socket");a(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));a(this,"createUa",async e=>this._cancelableCreateUa.request(e));a(this,"set",async e=>this._cancelableSet.request(e));a(this,"call",async e=>this._cancelableCall.request(e));a(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));a(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));a(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));a(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));a(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(Q,void 0);try{await this.unregister()}catch(e){E("tryRegister",e)}return this.register()});a(this,"declineToIncomingCall",async({statusCode:e=rs}={})=>new Promise((t,s)=>{if(!this.isAvailableIncomingCall){s(new Error("no incomingSession"));return}const r=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(ie,o),t(r.terminate({status_code:e}))}));a(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:ss}));a(this,"removeIncomingSession",()=>{delete this.incomingSession});a(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===Qe){this.incomingSession=t;const s=this.remoteCallerData;t.on(b,r=>{this.removeIncomingSession(),r.originator===ne?this._uaEvents.trigger(ce,s):this._uaEvents.trigger(ae,s)}),this._uaEvents.trigger(oe,s)}});a(this,"_connect",async e=>this.createUa(e).then(async()=>this._start()));a(this,"_createUa",async({displayName:e="",user:t,password:s,register:r=!1,sipServerUrl:o,sipWebSocketServerURL:i,remoteAddress:c,extraHeaders:u=[],sdpSemantics:l="plan-b",sessionTimers:_=!1,registerExpires:d=60*5,connectionRecoveryMinInterval:S=2,connectionRecoveryMaxInterval:h=6,userAgent:T})=>{if(!o)throw new Error("sipServerUrl is required");if(!i)throw new Error("sipWebSocketServerURL is required");if(r&&!t)throw new Error("user is required for authorized connection");if(r&&!s)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:o,displayName:e,register:r,user:t,password:s},this._init({sipServerUrl:o,sipWebSocketServerURL:i});const g=r&&t?t.trim():`${Xn()}`,N={password:s,register:r,display_name:Je(e),user_agent:T,sdp_semantics:l,sockets:[this.socket],uri:this.getSipServerUrl(g),session_timers:_,register_expires:d,connection_recovery_min_interval:S,connection_recovery_max_interval:h};this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!N.register,this.ua=new this.JsSIP.UA(N),this._uaEvents.eachTriggers((R,m)=>{const v=ke.find(f=>f===m);v&&this.ua&&this.ua.on(v,R)});const O=[...Cn(c),...u];return this.ua.registrator().setExtraHeaders(O),this.ua});a(this,"_start",async()=>new Promise((e,t)=>{const{ua:s}=this;if(!s){t(new Error("this.ua is not initialized"));return}const r=()=>{c(),e(s)},o=u=>{c(),t(u)},i=()=>{this.isRegisterConfig?(this.on(L,r),this.on(B,o)):this.on(q,r),this.on(P,o)},c=()=>{this.off(L,r),this.off(B,o),this.off(q,r),this.off(P,o)};i(),this.on(V,this.handleNewRTCSession),s.start()}));a(this,"_set",async({displayName:e,password:t})=>new Promise((s,r)=>{const{ua:o}=this;if(!o){r(new Error("this.ua is not initialized"));return}let i=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(i=o.set("display_name",Je(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const u=i||c;c&&this.isRegisterConfig?this.register().then(()=>{s(u)}).catch(r):u?s(u):r(u)}));a(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());a(this,"_disconnect",async()=>{this.off(V,this.handleNewRTCSession);const e=new Promise(t=>{this.once(P,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(P,void 0)):this._uaEvents.trigger(P,void 0),e});a(this,"_call",async({number:e,mediaStream:t,extraHeaders:s=[],ontrack:r,iceServers:o,videoMode:i,audioMode:c,degradationPreference:u,offerToReceiveAudio:l=!0,offerToReceiveVideo:_=!0})=>new Promise((d,S)=>{const{ua:h}=this;if(!h){S(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:r}).then(d).catch(S),this.session=h.call(this.getSipServerUrl(e),{extraHeaders:s,mediaStream:Z(t,{videoMode:i,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:i,audioMode:c,degradationPreference:u,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:l,offerToReceiveVideo:_}})}));a(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:s=[],iceServers:r,videoMode:o,audioMode:i,degradationPreference:c})=>new Promise((u,l)=>{if(!this.isAvailableIncomingCall){l(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:_}=this;if(!_){l(new Error("No session established"));return}this._sessionEvents.eachTriggers((S,h)=>{const T=He.find(g=>g===h);T&&_.on(T,S)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=_.remote_identity.uri.user,this._handleCall({ontrack:t}).then(u).catch(l);const d=Z(e,{videoMode:o,audioMode:i});_.answer({extraHeaders:s,videoMode:o,audioMode:i,degradationPreference:c,mediaStream:d,pcConfig:{iceServers:r}})}));a(this,"_handleCall",async({ontrack:e})=>new Promise((t,s)=>{const r=()=>{this.onSession(G,_),this.onSession(Y,d)},o=()=>{this.offSession(G,_),this.offSession(Y,d)},i=()=>{this.onSession(b,u),this.onSession(F,u)},c=()=>{this.offSession(b,u),this.offSession(F,u)},u=S=>{o(),c(),s(S)};let l;const _=({peerconnection:S})=>{l=S,l.ontrack=h=>{this._sessionEvents.trigger(Ce,l),e&&e(h)}},d=()=>{l&&this._sessionEvents.trigger(Te,l),o(),c(),t(l)};r(),i()}));a(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});a(this,"_sendDTMF",async e=>new Promise((t,s)=>{const{session:r}=this;if(!r){s(new Error("No session established"));return}this.onceSession(Le,({originator:o})=>{o===ne&&t()}),r.sendDTMF(e,{duration:120,interToneGap:600})}));a(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),e.isEnded()||e.terminate()}});a(this,"_handleShareState",e=>{switch(e){case vt:{this._sessionEvents.trigger(le,void 0);break}case bt:{this._sessionEvents.trigger(_e,void 0);break}case kn:{this._sessionEvents.trigger(de,void 0);break}}});a(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(Xe),s=e.getHeader(ze);if(t&&s){const r={inputChannels:t,outputChannels:s};this._sessionEvents.trigger($,r)}});a(this,"_handleNotify",e=>{switch(e.cmd){case is:{const t=e;this._triggerChannelsNotify(t);break}case as:{const t=e;this._triggerWebcastStartedNotify(t);break}case cs:{const t=e;this._triggerWebcastStoppedNotify(t);break}case ls:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case _s:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case ds:{const t=e;this._triggerParticipantMoveRequestToConference(t);break}case Ss:{const t=e;this._triggerParticipantCancelingWordRequest(t);break}case hs:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case us:{this._triggerAccountChangedNotify();break}case Es:{this._triggerAccountDeletedNotify();break}case Ts:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:E("unknown cmd",e.cmd)}});a(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Oe,t)});a(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Me,t)});a(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this._uaEvents.trigger(ve,s)});a(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this._uaEvents.trigger(be,s)});a(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(ye,void 0)});a(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(we,void 0)});a(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:s}})=>{const r={conference:e,participant:t,jwt:s};this._uaEvents.trigger(Ue,r)});a(this,"_triggerChannelsNotify",e=>{const t=e.input,s=e.output,r={inputChannels:t,outputChannels:s};this._uaEvents.trigger(ge,r)});a(this,"_triggerParticipantMoveRequestToConference",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(De,t)});a(this,"_triggerParticipantCancelingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(pe,t)});a(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(Pe,t)});a(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Nn);this._sessionEvents.trigger(Se,t)});a(this,"_triggerShareState",e=>{const t=e.getHeader(H);this._sessionEvents.trigger(W,t)});a(this,"_triggerMainCamControl",e=>{const t=e.getHeader(Dn),s=e.getHeader(Ke),r=s===K.ADMIN_SYNC_FORCED;if(t===M.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(Ae,{isSyncForced:r});else if(t===M.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(me,{isSyncForced:r});else if((t===M.RESUME_MAIN_CAM||t===M.PAUSE_MAIN_CAM)&&s)this._sessionEvents.trigger(x,{isSyncForced:r});else{const o=e.getHeader(pn);this._sessionEvents.trigger(Re,{mainCam:t,resolutionMainCam:o})}});a(this,"_triggerMicControl",e=>{const t=e.getHeader(Pn),r=e.getHeader(Ke)===K.ADMIN_SYNC_FORCED;t===z.ADMIN_START_MIC?this._sessionEvents.trigger(Ie,{isSyncForced:r}):t===z.ADMIN_STOP_MIC&&this._sessionEvents.trigger(fe,{isSyncForced:r})});a(this,"_triggerUseLicense",e=>{const t=e.getHeader(On);this._sessionEvents.trigger(he,t)});a(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:s}=e,r=s.getHeader(gn);if(r)switch(r){case Rn:{this._triggerEnterRoom(s),this._maybeTriggerChannels(s);break}case Un:{this._maybeHandleNotify(s);break}case j:{this._triggerShareState(s);break}case Ge:{this._triggerMainCamControl(s);break}case In:{this._triggerMicControl(s);break}case Mn:{this._triggerUseLicense(s);break}}});a(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});a(this,"_maybeHandleNotify",e=>{const t=e.getHeader(Ln);if(t){const s=JSON.parse(t);this._handleNotify(s)}});a(this,"_handleEnded",e=>{const{originator:t}=e;t===Qe&&this._sessionEvents.trigger(Ne,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new Ye(pt),this._uaEvents=new Ye(Pt),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(W,this._handleShareState),this.onSession(Be,this._handleNewInfo),this.on(Ee,this._handleSipEvent),this.onSession(b,this._handleEnded),this.onSession(F,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(L,e),this.ua.on(B,t),this.ua.register()):t(new Error("Config is not registered"))})}async unregister(){return new Promise((e,t)=>{this.isRegistered&&this.ua?(this.ua.on(ue,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,s){if(!this.ua)throw new Error("is not connected");return new Promise((r,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:s,eventHandlers:{succeeded:()=>{r()},failed:o}})}catch(i){o(i)}})}async ping(e,t){var r;if(!((r=this.ua)!=null&&r.configuration.uri))throw new Error("is not connected");const s=this.ua.configuration.uri;return this.sendOptions(s,e,t)}async replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}async askPermissionToEnableCam(e={}){if(!this.session)throw new Error("No session established");const t=[Wn];return this.session.sendInfo(Ge,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(s=>{if(Jn(s))throw s})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:s,degradationPreference:r,isNeedReinvite:o=!0,isP2P:i=!1}){const c=Z(t);this._streamPresentationCurrent=c;const u=i?[Hn]:[Bn],l=e.sendInfo(j,void 0,{extraHeaders:u}).then(async()=>e.startPresentation(c,o,r)).then(async()=>{const{connection:_}=this;if(!_||s===void 0)return;const d=_.getSenders();return ns(d,t,s)}).then(()=>t).catch(_=>{throw this._sessionEvents.trigger(X,_),_});return this.promisePendingStartPresentation=l,l.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:s=!1,maxBitrate:r,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,e,{isNeedReinvite:t,isP2P:s,maxBitrate:r,degradationPreference:o})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let s=this.promisePendingStartPresentation??Promise.resolve();const r=e?[qn]:[Fn],o=this.establishedSession;return o&&t&&(s=s.then(async()=>o.sendInfo(j,void 0,{extraHeaders:r})).then(async()=>o.stopPresentation(t)).catch(i=>{throw this._sessionEvents.trigger(X,i),i})),!o&&t&&this._sessionEvents.trigger(Fe,t),this.promisePendingStopPresentation=s,s.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:s,degradationPreference:r}={}){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,e,{isP2P:t,maxBitrate:s,degradationPreference:r,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}async wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}async waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:s})=>s);return zn(t)?this._generateStreams(t):this._generateAudioStreams(t)}get connection(){var t;return(t=this.session)==null?void 0:t.connection}get remoteCallerData(){var e,t,s,r,o,i;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(r=(s=this.incomingSession)==null?void 0:s.remote_identity)==null?void 0:r.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:e,sipWebSocketServerURL:t}){this.getSipServerUrl=Yn(e),this.socket=new this.JsSIP.WebSocketInterface(t)}_generateStream(e,t){const{id:s}=e,r=this._remoteStreams[s]||new MediaStream;return t&&r.addTrack(t),r.addTrack(e),this._remoteStreams[s]=r,r}_generateAudioStream(e){const{id:t}=e,s=this._remoteStreams[t]||new MediaStream;return s.addTrack(e),this._remoteStreams[t]=s,s}_generateStreams(e){const t=[];return e.forEach((s,r)=>{if(s.kind==="audio")return;const o=s,i=e[r-1];let c;i&&i.kind==="audio"&&(c=i);const u=this._generateStream(o,c);t.push(u)}),t}_generateAudioStreams(e){return e.map(s=>this._generateAudioStream(s))}_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($)}async waitSyncMediaState(){return this.waitSession(x)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const s=`${Xe}: ${e}`,r=`${ze}: ${t}`,o=[s,r];return this.session.sendInfo(mn,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},s={}){if(!this.session)throw new Error("No session established");const r=`${vn}: currentstate`,o=`${yn}: ${Number(e)}`,i=`${wn}: ${Number(t)}`,c=[r,o,i];return this.session.sendInfo(An,void 0,{noTerminateWhenError:!0,...s,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${bn}: ${e==="mic"?0:1}`];return this.session.sendInfo(fn,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}}const Bt="purgatory",k=n=>n===Bt,Ve=n=>()=>(E("getRemoteStreams"),n.getRemoteStreams()),gs=({kind:n,readyState:e})=>n==="video"&&e==="live",Ft=n=>({track:e})=>{gs(e)&&n()},We=({getRemoteStreams:n,setRemoteStreams:e})=>Xt.debounce(()=>{const t=n();E("remoteStreams",t),t&&e(t)},200),Ns=n=>async t=>{const{mediaStream:s,extraHeaders:r,iceServers:o,degradationPreference:i,setRemoteStreams:c,onBeforeProgressCall:u,onSuccessProgressCall:l,onEnterPurgatory:_,onEnterConference:d,onFailProgressCall:S,onFinishProgressCall:h,onEndedCall:T}=t,g=We({setRemoteStreams:c,getRemoteStreams:Ve(n)}),N=Ft(g);E("answerIncomingCall",t);const p=async()=>n.answerToIncomingCall({mediaStream:s,extraHeaders:r,iceServers:o,degradationPreference:i,ontrack:N}),O=()=>{const{remoteCallerData:C}=n;return C.incomingNumber};let R=!1,m;const f=(()=>(E("subscribeEnterConference: onEnterConference",d),_??d?n.onSession("enterRoom",C=>{E("enterRoom",{_room:C,isSuccessProgressCall:R}),m=C,k(m)?_&&_():d&&d({isSuccessProgressCall:R})}):()=>{}))(),y=C=>(E("onSuccess"),R=!0,g(),l&&l({isPurgatory:k(m)}),n.onceRaceSession(["ended","failed"],()=>{f(),T&&T()}),C),w=C=>{throw E("onFail"),S&&S(),f(),C},U=()=>{E("onFinish"),h&&h()};if(E("onBeforeProgressCall"),u){const C=O();u(C)}return p().then(y).catch(w).finally(U)},Rs=n=>async t=>{const{conference:s,mediaStream:r,extraHeaders:o,iceServers:i,degradationPreference:c,setRemoteStreams:u,onBeforeProgressCall:l,onSuccessProgressCall:_,onEnterPurgatory:d,onEnterConference:S,onFailProgressCall:h,onFinishProgressCall:T,onEndedCall:g}=t,N=We({setRemoteStreams:u,getRemoteStreams:Ve(n)}),p=Ft(N);E("callToServer",t);const O=async()=>(E("startCall"),n.call({mediaStream:r,extraHeaders:o,iceServers:i,degradationPreference:c,number:s,ontrack:p}));let R=!1,m;const f=(()=>(E("subscribeEnterConference: onEnterConference",S),d??S?n.onSession("enterRoom",C=>{E("enterRoom",{_room:C,isSuccessProgressCall:R}),m=C,k(m)?d&&d():S&&S({isSuccessProgressCall:R})}):()=>{}))(),y=C=>(E("onSuccess"),R=!0,N(),_&&_({isPurgatory:k(m)}),n.onceRaceSession(["ended","failed"],()=>{f(),g&&g()}),C),w=C=>{throw E("onFail"),h&&h(),f(),C},U=()=>{E("onFinish"),T&&T()};return E("onBeforeProgressCall"),l&&l(s),O().then(y).catch(w).finally(U)},ee=n=>{if(!I.isCanceledError(n))throw n;return!1},ms=n=>async t=>{const{userAgent:s,sipWebSocketServerURL:r,sipServerUrl:o,remoteAddress:i,displayName:c,name:u,password:l,isRegisteredUser:_,sdpSemantics:d,isDisconnectOnFail:S}=t;return E("connectToServer",t),n.connect({userAgent:s,sdpSemantics:d,sipWebSocketServerURL:r,sipServerUrl:o,remoteAddress:i,displayName:c,password:l,user:u,register:_}).then(()=>(E("connectToServer then"),!0)).catch(async h=>(E("connectToServer catch: error",h),S===!0?n.disconnect().then(()=>ee(h)).catch(()=>ee(h)):ee(h)))},As=n=>async()=>(E("disconnectFromServer"),n.disconnect().then(()=>(E("disconnectFromServer: then"),!1)).catch(e=>(E("disconnectFromServer: catch",e),!1))),$e=n=>{const{url:e,cause:t}=n;let s=e;return(t===re||t===se)&&(s=`${n.message.to.uri.user}@${n.message.to.uri.host}`),s};var kt=(n=>(n.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",n.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",n.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",n.NOT_FOUND_ERROR="NOT_FOUND_ERROR",n.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",n.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",n))(kt||{});const fs=(n=new Error)=>{var r;const{cause:e,socket:t}=n;let s="CONNECT_SERVER_FAILED";switch(e){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case re:{s="BAD_MEDIA_ERROR";break}case se:{s="NOT_FOUND_ERROR";break}default:t&&((r=t==null?void 0:t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":$e(n)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},Is=(n=new Error)=>{const{code:e,cause:t,message:s}=n,r=$e(n),o={};return s&&(o.message=s),r&&(o.link=r),e&&(o.code=e),t&&(o.cause=t),o},Ms=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:kt,getLinkError:$e,getTypeFromError:fs,getValuesFromError:Is},Symbol.toStringTag,{value:"Module"})),Os=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:o})=>{const i=[],c=t?"0":"1",u=s?"0":"1";return i.push(`X-Vinteo-Mic-State: ${c}`,`X-Vinteo-MainCam-State: ${u}`),r||i.push("X-Vinteo-Purgatory-Call: yes"),n&&i.push(`X-Vinteo-Session: ${n}`),o&&i.push("X-Vinteo-Presentation-Call: yes"),e&&i.push(`X-Vinteo-Remote: ${e}`),i},Ds=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const r=`${n} ${e}`;return`ChromeNew - ${t?`${t} ${s}, ${r}`:r}`},Ps=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?Ds({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",ps=n=>async()=>{if(n.isCallActive)return E("askPermissionToEnableCam"),n.askPermissionToEnableCam()},vs=n=>t=>(E("onMustStopPresentation"),n.onSession("mustStopPresentation",t)),bs=n=>t=>(E("onUseLicense"),n.onSession("useLicense",t)),ys=n=>async({isEnabledCam:t,isEnabledMic:s})=>{if(n.isCallActive)return E("sendMediaState"),n.sendMediaState({cam:t,mic:s})},ws=n=>async()=>{if(n.isCallActive)return E("sendRefusalToTurnOnCam"),n.sendRefusalToTurnOnCam().catch(t=>{E("sendRefusalToTurnOnCam: error",t)})},Us=n=>async()=>{if(n.isCallActive)return E("sendRefusalToTurnOnMic"),n.sendRefusalToTurnOnMic().catch(t=>{E("sendRefusalToTurnOnMic: error",t)})},Ls=1e6,Bs=({maxBitrate:n=Ls,sipConnector:e})=>async({mediaStream:s,isP2P:r=!1})=>(E("startPresentation"),e.startPresentation(s,{isP2P:r,maxBitrate:n})),Fs=({sipConnector:n})=>async({isP2P:t=!1}={})=>(E("stopShareSipConnector"),n.stopPresentation({isP2P:t}).catch(E)),ks=1e6,Hs=({sipConnector:n,maxBitrate:e=ks})=>async({mediaStream:s,isP2P:r=!1})=>(E("updatePresentation"),n.updatePresentation(s,{isP2P:r,maxBitrate:e})),qs=n=>e=>[...e].map(s=>async()=>n(s)),Vs=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=qs(e)(n);return zt(r,t)},Ws=n=>t=>(E("onStartMainCam"),n.onSession("admin-start-main-cam",t)),$s=n=>t=>(E("onStartMic"),n.onSession("admin-start-mic",t)),xs=n=>t=>(E("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),Ys=n=>t=>(E("onStopMic"),n.onSession("admin-stop-mic",t)),Gs=({sipConnector:n})=>{const e=(T,g)=>({isSyncForced:N=!1})=>{if(N){T();return}g()},t=Ws(n),s=xs(n),r=$s(n),o=Ys(n);let i=()=>{},c=()=>{},u=()=>{},l=()=>{};const _=({onStartMainCamForced:T,onStartMainCamNotForced:g,onStopMainCamForced:N,onStopMainCamNotForced:p,onStartMicForced:O,onStartMicNotForced:R,onStopMicForced:m,onStopMicNotForced:v})=>{const f=e(T,g);i=t(f);const y=e(N,p);c=s(y);const w=e(O,R);u=r(w);const U=e(m,v);l=o(U)},d=()=>{i(),c(),u(),l()};return{start:T=>{_(T)},stop:()=>{d()}}},Xs=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:Bt,createSyncMediaState:Gs,error:Ms,getExtraHeaders:Os,getUserAgent:Ps,hasPurgatory:k,resolveAnswerIncomingCall:Ns,resolveAskPermissionToEnableCam:ps,resolveCallToServer:Rs,resolveConnectToServer:ms,resolveDisconnectFromServer:As,resolveGetRemoteStreams:Ve,resolveOnMustStopPresentation:vs,resolveOnUseLicense:bs,resolveSendMediaState:ys,resolveSendRefusalToTurnOnCam:ws,resolveSendRefusalToTurnOnMic:Us,resolveStartPresentation:Bs,resolveStopShareSipConnector:Fs,resolveUpdatePresentation:Hs,resolveUpdateRemoteStreams:We,sendDTMFAccumulated:Vs},Symbol.toStringTag,{value:"Module"})),zs=n=>[...n.keys()].map(e=>n.get(e)),Ks=(n,e)=>zs(n).find(t=>t.type===e),Ht=async n=>n.getStats().then(e=>{const t=Ks(e,"codec");return t==null?void 0:t.mimeType}),Js=n=>n.find(e=>{var t;return((t=e==null?void 0:e.track)==null?void 0:t.kind)==="video"}),qt=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Qs=1e6,A=n=>n*Qs,Vt=A(.06),js=A(4),Zs=n=>n<=64?Vt:n<=128?A(.12):n<=256?A(.25):n<=384?A(.32):n<=426?A(.38):n<=640?A(.5):n<=848?A(.7):n<=1280?A(1):n<=1920?A(2):js,er="av1",tr=n=>qt(n,er),nr=.6,Wt=(n,e)=>tr(e)?n*nr:n,sr=n=>Wt(Vt,n),$t=(n,e)=>{const t=Zs(n);return Wt(t,e)},xt=Kt(),rr=async()=>xt().catch(n=>{E("videoSendingBalancer: error",n)}),or=async n=>(xt.add(n),rr()),xe=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>or(async()=>Lt(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),ir=async({sender:n,codec:e},t)=>{const r=sr(e);return xe({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},te=async({sender:n,track:e,codec:t},s)=>{const i=e.getSettings().width,c=$t(i,t);return xe({sender:n,maxBitrate:c,onSetParameters:s,scaleResolutionDownBy:1})},ar=async({sender:n,track:e,resolution:t,codec:s},r)=>{const o=e.getSettings(),i=o.width,c=o.height,[u,l]=t.split("x"),_=i/Number(u),d=c/Number(l),h=Math.max(_,d,1),T=$t(Number(u),s);return xe({sender:n,maxBitrate:T,onSetParameters:r,scaleResolutionDownBy:h})},cr=async({mainCam:n,resolutionMainCam:e,sender:t,track:s,codec:r},o)=>{switch(n){case M.PAUSE_MAIN_CAM:return ir({sender:t,codec:r},o);case M.RESUME_MAIN_CAM:return te({sender:t,track:s,codec:r},o);case M.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?ar({sender:t,track:s,codec:r,resolution:e},o):te({sender:t,track:s,codec:r},o);default:return te({sender:t,track:s,codec:r},o)}},je={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},Ze=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const o=t.getSenders(),i=Js(o);if(!(i!=null&&i.track))return je;const c=await Ht(i);return qt(c,r)?je:cr({mainCam:n,resolutionMainCam:e,sender:i,codec:c,track:i.track},s)},ur=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:u}=n;if(!u)throw new Error("connection is not exist");return Ze({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const o=async u=>(r=async()=>{const{mainCam:l,resolutionMainCam:_}=u,{connection:d}=n;if(!d)throw new Error("connection is not exist");return Ze({mainCam:l,resolutionMainCam:_,connection:d,onSetParameters:t,ignoreForCodec:e})},r());return{subscribe:()=>{n.onSession("main-cam-control",o)},unsubscribe:()=>{n.offSession("main-cam-control",o)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}};exports.debug=J;exports.EEventsMainCAM=M;exports.EEventsMic=z;exports.EEventsSyncMediaState=K;exports.EUseLicense=yt;exports.causes=Sn;exports.constants=hn;exports.default=Cs;exports.disableDebug=xn;exports.enableDebug=$n;exports.eventNames=Tn;exports.getCodecFromSender=Ht;exports.hasCanceledCallError=os;exports.resolveVideoSendingBalancer=ur;exports.tools=Xs;
|