sip-connector 13.3.1 → 14.0.1-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.
Files changed (97) hide show
  1. package/dist/SipConnector-CJN8qKAC.js +1316 -0
  2. package/dist/SipConnector-DO0YvSq6.cjs +1 -0
  3. package/dist/doMock.cjs +1 -1
  4. package/dist/doMock.js +376 -387
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +513 -517
  7. package/dist/{SipConnector.d.ts → src/SipConnector.d.ts} +69 -82
  8. package/dist/{__fixtures__ → src/__fixtures__}/BaseSession.mock.d.ts +19 -31
  9. package/dist/{__fixtures__ → src/__fixtures__}/RTCPeerConnectionMock.d.ts +14 -14
  10. package/dist/{__fixtures__ → src/__fixtures__}/RTCRtpSenderMock.d.ts +2 -2
  11. package/dist/{__fixtures__/Session.mock.d.ts → src/__fixtures__/RTCSessionMock.d.ts} +25 -29
  12. package/dist/{__fixtures__ → src/__fixtures__}/UA.mock.d.ts +25 -44
  13. package/dist/{__fixtures__ → src/__fixtures__}/channelsNotify.d.ts +2 -2
  14. package/dist/{__fixtures__ → src/__fixtures__}/jssip.mock.d.ts +3 -3
  15. package/dist/{__fixtures__ → src/__fixtures__}/participantNotify.d.ts +2 -2
  16. package/dist/{constants.d.ts → src/constants.d.ts} +5 -0
  17. package/dist/src/doMock.d.ts +5 -0
  18. package/dist/{index.d.ts → src/index.d.ts} +1 -3
  19. package/dist/{types.d.ts → src/types.d.ts} +2 -1
  20. package/package.json +39 -39
  21. package/dist/SipConnector-B4xLnl6L.js +0 -1334
  22. package/dist/SipConnector-CE4F15z6.cjs +0 -1
  23. package/dist/doMock.d.ts +0 -6
  24. package/dist/utils.d.ts +0 -4
  25. /package/dist/{SipConnectorFacade → src/SipConnectorFacade}/SipConnectorFacade.d.ts +0 -0
  26. /package/dist/{SipConnectorFacade → src/SipConnectorFacade}/index.d.ts +0 -0
  27. /package/dist/{__fixtures__ → src/__fixtures__}/Registrator.mock.d.ts +0 -0
  28. /package/dist/{__fixtures__ → src/__fixtures__}/Request.mock.d.ts +0 -0
  29. /package/dist/{__fixtures__ → src/__fixtures__}/WebSocketInterface.mock.d.ts +0 -0
  30. /package/dist/{__fixtures__ → src/__fixtures__}/accountNotify.d.ts +0 -0
  31. /package/dist/{__fixtures__ → src/__fixtures__}/channels.d.ts +0 -0
  32. /package/dist/{__fixtures__ → src/__fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
  33. /package/dist/{__fixtures__ → src/__fixtures__}/delayPromise.d.ts +0 -0
  34. /package/dist/{__fixtures__ → src/__fixtures__}/enterRoom.d.ts +0 -0
  35. /package/dist/{__fixtures__ → src/__fixtures__}/index.d.ts +0 -0
  36. /package/dist/{__fixtures__ → src/__fixtures__}/mediaState.d.ts +0 -0
  37. /package/dist/{__fixtures__ → src/__fixtures__}/participantMoveRequests.d.ts +0 -0
  38. /package/dist/{__fixtures__ → src/__fixtures__}/remoteCallerData.d.ts +0 -0
  39. /package/dist/{__fixtures__ → src/__fixtures__}/utils.d.ts +0 -0
  40. /package/dist/{__fixtures__ → src/__fixtures__}/webcastNotify.d.ts +0 -0
  41. /package/dist/{causes.d.ts → src/causes.d.ts} +0 -0
  42. /package/dist/{eventNames.d.ts → src/eventNames.d.ts} +0 -0
  43. /package/dist/{getExtraHeadersRemoteAddress.d.ts → src/getExtraHeadersRemoteAddress.d.ts} +0 -0
  44. /package/dist/{headers.d.ts → src/headers.d.ts} +0 -0
  45. /package/dist/{logger.d.ts → src/logger.d.ts} +0 -0
  46. /package/dist/{setParametersToSender → src/setParametersToSender}/configureDegradationPreference.d.ts +0 -0
  47. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
  48. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEncodings.d.ts +0 -0
  49. /package/dist/{setParametersToSender → src/setParametersToSender}/configureMaxBitrate.d.ts +0 -0
  50. /package/dist/{setParametersToSender → src/setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
  51. /package/dist/{setParametersToSender → src/setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
  52. /package/dist/{setParametersToSender → src/setParametersToSender}/index.d.ts +0 -0
  53. /package/dist/{setParametersToSender → src/setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
  54. /package/dist/{setParametersToSender → src/setParametersToSender}/setParametersToSender.d.ts +0 -0
  55. /package/dist/{tools → src/tools}/__fixtures__/call.d.ts +0 -0
  56. /package/dist/{tools → src/tools}/__fixtures__/connectToServer.d.ts +0 -0
  57. /package/dist/{tools → src/tools}/__fixtures__/hasValidUri.d.ts +0 -0
  58. /package/dist/{tools → src/tools}/__fixtures__/permissions.d.ts +0 -0
  59. /package/dist/{tools → src/tools}/__fixtures__/processRequest.d.ts +0 -0
  60. /package/dist/{tools → src/tools}/__tests-utils__/parseObject.d.ts +0 -0
  61. /package/dist/{tools → src/tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
  62. /package/dist/{tools → src/tools}/error/getLinkError.d.ts +0 -0
  63. /package/dist/{tools → src/tools}/error/getTypeFromError.d.ts +0 -0
  64. /package/dist/{tools → src/tools}/error/getValuesFromError.d.ts +0 -0
  65. /package/dist/{tools → src/tools}/error/index.d.ts +0 -0
  66. /package/dist/{tools → src/tools}/error/stringifyMessage.d.ts +0 -0
  67. /package/dist/{tools → src/tools}/generateSimulcastEncodings.d.ts +0 -0
  68. /package/dist/{tools → src/tools}/getExtraHeaders.d.ts +0 -0
  69. /package/dist/{tools → src/tools}/getUserAgent.d.ts +0 -0
  70. /package/dist/{tools → src/tools}/hasPurgatory.d.ts +0 -0
  71. /package/dist/{tools → src/tools}/index.d.ts +0 -0
  72. /package/dist/{tools → src/tools}/prepareMediaStream.d.ts +0 -0
  73. /package/dist/{tools → src/tools}/resolveUpdateTransceiver.d.ts +0 -0
  74. /package/dist/{tools → src/tools}/sendDTMFAccumulated.d.ts +0 -0
  75. /package/dist/{tools → src/tools}/setVideoTrackContentHints.d.ts +0 -0
  76. /package/dist/{tools → src/tools}/syncMediaState/index.d.ts +0 -0
  77. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMainCam.d.ts +0 -0
  78. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMic.d.ts +0 -0
  79. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMainCam.d.ts +0 -0
  80. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMic.d.ts +0 -0
  81. /package/dist/{utils → src/utils}/errors.d.ts +0 -0
  82. /package/dist/{utils → src/utils}/findSenderByStream.d.ts +0 -0
  83. /package/dist/{utils → src/utils}/findVideoSender.d.ts +0 -0
  84. /package/dist/{utils → src/utils}/findVideoTrack.d.ts +0 -0
  85. /package/dist/{utils → src/utils}/getCodecFromSender.d.ts +0 -0
  86. /package/dist/{utils → src/utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
  87. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/balance.d.ts +0 -0
  88. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidth.d.ts +0 -0
  89. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +0 -0
  90. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
  91. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasIncludesString.d.ts +0 -0
  92. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/index.d.ts +0 -0
  93. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/processSender.d.ts +0 -0
  94. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrate.d.ts +0 -0
  95. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
  96. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
  97. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
@@ -0,0 +1 @@
1
+ "use strict";const Pt=require("@krivega/cancelable-promise"),ve=require("events-constructor"),ye=require("repeated-calls"),$=require("debug"),Ot="Connection Error",We="Request Timeout",mt="SIP Failure Code",Mt="Internal Error",Dt="Busy",G="Rejected",pt="Redirected",vt="Unavailable",ke="Not Found",yt="Address Incomplete",wt="Incompatible SDP",bt="Missing SDP",Ut="Authentication Error",Be="Terminated",Lt="WebRTC Error",J="Canceled",Ht="No Answer",Wt="Expires",kt="No ACK",Bt="Dialog Error",Ft="User Denied Media Access",Fe="Bad Media Description",xt="RTP Timeout",Vt=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:yt,AUTHENTICATION_ERROR:Ut,BAD_MEDIA_DESCRIPTION:Fe,BUSY:Dt,BYE:Be,CANCELED:J,CONNECTION_ERROR:Ot,DIALOG_ERROR:Bt,EXPIRES:Wt,INCOMPATIBLE_SDP:wt,INTERNAL_ERROR:Mt,MISSING_SDP:bt,NOT_FOUND:ke,NO_ACK:kt,NO_ANSWER:Ht,REDIRECTED:pt,REJECTED:G,REQUEST_TIMEOUT:We,RTP_TIMEOUT:xt,SIP_FAILURE_CODE:mt,UNAVAILABLE:vt,USER_DENIED_MEDIA_ACCESS:Ft,WEBRTC_ERROR:Lt},Symbol.toStringTag,{value:"Module"})),X="incomingCall",Q="declinedIncomingCall",z="failedIncomingCall",j="terminatedIncomingCall",B="connecting",I="connected",g="disconnected",v="newRTCSession",P="registered",K="unregistered",O="registrationFailed",xe="newMessage",Z="sipEvent",ee="availableSecondRemoteStream",te="notAvailableSecondRemoteStream",ne="mustStopPresentation",y="shareState",se="enterRoom",ie="useLicense",re="peerconnection:confirmed",oe="peerconnection:ontrack",w="channels",ae="channels:notify",ce="ended:fromserver",Ee="main-cam-control",de="admin-stop-main-cam",he="admin-start-main-cam",Te="admin-stop-mic",Se="admin-start-mic",b="admin-force-sync-media-state",le="participant:added-to-list-moderators",ue="participant:removed-from-list-moderators",ge="participant:move-request-to-stream",F="participant:move-request-to-spectators",x="participant:move-request-to-participants",Ce="participation:accepting-word-request",_e="participation:cancelling-word-request",Ne="webcast:started",Ae="webcast:stopped",Re="account:changed",fe="account:deleted",Ie="conference:participant-token-issued",m="ended",Ve="sending",Ye="reinvite",qe="replaces",$e="refer",Ge="progress",Je="accepted",U="confirmed",L="peerconnection",N="failed",Xe="muted",Qe="unmuted",Pe="newDTMF",Oe="newInfo",ze="hold",je="unhold",Ke="update",Ze="sdp",et="icecandidate",tt="getusermediafailed",nt="peerconnection:createofferfailed",st="peerconnection:createanswerfailed",it="peerconnection:setlocaldescriptionfailed",rt="peerconnection:setremotedescriptionfailed",ot="presentation:start",at="presentation:started",ct="presentation:end",me="presentation:ended",H="presentation:failed",Et="SPECTATOR",dt="PARTICIPANT",ht=1e6;var C=(s=>(s.LOCAL="local",s.REMOTE="remote",s.SYSTEM="system",s))(C||{});const Yt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Je,ACCOUNT_CHANGED:Re,ACCOUNT_DELETED:fe,ADMIN_FORCE_SYNC_MEDIA_STATE:b,ADMIN_START_MAIN_CAM:he,ADMIN_START_MIC:Se,ADMIN_STOP_MAIN_CAM:de,ADMIN_STOP_MIC:Te,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:ee,CHANNELS:w,CHANNELS_NOTIFY:ae,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:Ie,CONFIRMED:U,CONNECTED:I,CONNECTING:B,DECLINED_INCOMING_CALL:Q,DISCONNECTED:g,ENDED:m,ENDED_FROM_SERVER:ce,ENTER_ROOM:se,FAILED:N,FAILED_INCOMING_CALL:z,GET_USER_MEDIA_FAILED:tt,HOLD:ze,ICE_CANDIDATE:et,INCOMING_CALL:X,MAIN_CAM_CONTROL:Ee,MUST_STOP_PRESENTATION_EVENT:ne,MUTED:Xe,NEW_DTMF:Pe,NEW_INFO:Oe,NEW_MESSAGE:xe,NEW_RTC_SESSION:v,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:te,ONE_MEGABIT_IN_BITS:ht,Originator:C,PARTICIPANT:dt,PARTICIPANT_ADDED_TO_LIST_MODERATORS:le,PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS:x,PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS:F,PARTICIPANT_MOVE_REQUEST_TO_STREAM:ge,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:ue,PARTICIPATION_ACCEPTING_WORD_REQUEST:Ce,PARTICIPATION_CANCELLING_WORD_REQUEST:_e,PEER_CONNECTION:L,PEER_CONNECTION_CONFIRMED:re,PEER_CONNECTION_CREATE_ANSWER_FAILED:st,PEER_CONNECTION_CREATE_OFFER_FAILED:nt,PEER_CONNECTION_ONTRACK:oe,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:it,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:rt,PRESENTATION_END:ct,PRESENTATION_ENDED:me,PRESENTATION_FAILED:H,PRESENTATION_START:ot,PRESENTATION_STARTED:at,PROGRESS:Ge,REFER:$e,REGISTERED:P,REGISTRATION_FAILED:O,REINVITE:Ye,REPLACES:qe,SDP:Ze,SENDING:Ve,SHARE_STATE:y,SIP_EVENT:Z,SPECTATOR:Et,TERMINATED_INCOMING_CALL:j,UNHOLD:je,UNMUTED:Qe,UNREGISTERED:K,UPDATE:Ke,USE_LICENSE:ie,WEBCAST_STARTED:Ne,WEBCAST_STOPPED:Ae},Symbol.toStringTag,{value:"Module"})),Tt=[X,Q,j,z,Ce,_e,ge,ae,Ie,Re,fe,Ne,Ae,le,ue],V=[B,I,g,v,P,K,O,xe,Z],St=[ee,te,ne,y,se,ie,re,oe,w,ce,Ee,he,de,Te,Se,b,F,x],Me=[m,B,Ve,Ye,qe,$e,Ge,Je,U,L,N,Xe,Qe,Pe,Oe,ze,je,Ke,Ze,et,tt,nt,st,it,rt,ot,at,ct,me,H],lt=[...V,...Tt],De=[...Me,...St],qt=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:De,SESSION_JSSIP_EVENT_NAMES:Me,SESSION_SYNTHETICS_EVENT_NAMES:St,UA_EVENT_NAMES:lt,UA_JSSIP_EVENT_NAMES:V,UA_SYNTHETICS_EVENT_NAMES:Tt},Symbol.toStringTag,{value:"Module"})),pe="sip-connector",p=$(pe),$t=()=>{$.enable(pe)},Gt=()=>{$.enable(`-${pe}`)},Jt=(s,t)=>(s.degradationPreference=t.degradationPreference,s),Xt=(s,t)=>{s.encodings??=[];for(let e=s.encodings.length;e<t;e+=1)s.encodings.push({});return s},ut=s=>(t,e)=>e!==void 0&&t!==e||e===void 0&&t!==s,Qt=ut(),zt=(s,t)=>{if(Qt(s,t))return s},jt=(s,t)=>{const e=s.maxBitrate,n=zt(t,e);return n!==void 0&&(s.maxBitrate=n),s},gt=1,Kt=ut(gt),Zt=(s,t)=>{const e=s===void 0?void 0:Math.max(s,gt);if(e!==void 0&&Kt(e,t))return e},en=(s,t)=>{const e=s.scaleResolutionDownBy,n=Zt(t,e);return n!==void 0&&(s.scaleResolutionDownBy=n),s},tn=(s,t)=>{const e=t.encodings?.length??0;return Xt(s,e),s.encodings.forEach((n,i)=>{const r=(t?.encodings??[])[i],o=r?.maxBitrate,a=r?.scaleResolutionDownBy;jt(n,o),en(n,a)}),s},nn=(s,t)=>{if(s.codecs?.length!==t.codecs?.length)return!0;for(let e=0;e<(s.codecs?.length??0);e++)if(JSON.stringify(s.codecs[e])!==JSON.stringify(t.codecs[e]))return!0;if(s.headerExtensions?.length!==t.headerExtensions?.length)return!0;for(let e=0;e<(s.headerExtensions?.length??0);e++)if(JSON.stringify(s.headerExtensions[e])!==JSON.stringify(t.headerExtensions[e]))return!0;if(s.encodings?.length!==t.encodings?.length)return!0;for(let e=0;e<(s.encodings.length??0);e++)if(JSON.stringify(s.encodings[e])!==JSON.stringify(t.encodings[e]))return!0;return s.rtcp?.cname!==t.rtcp?.cname||s.rtcp?.reducedSize!==t.rtcp?.reducedSize||s.degradationPreference!==t.degradationPreference},Ct=async(s,t)=>{const e=s.getParameters(),n=JSON.parse(JSON.stringify(e));tn(e,t),Jt(e,t);const i=nn(n,e);return i&&await s.setParameters(e),{parameters:e,isChanged:i}};var A=(s=>(s.PAUSE_MAIN_CAM="PAUSEMAINCAM",s.RESUME_MAIN_CAM="RESUMEMAINCAM",s.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",s.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",s.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",s))(A||{}),W=(s=>(s.ADMIN_STOP_MIC="ADMINSTOPMIC",s.ADMIN_START_MIC="ADMINSTARTMIC",s))(W||{}),k=(s=>(s.ADMIN_SYNC_FORCED="1",s.ADMIN_SYNC_NOT_FORCED="0",s))(k||{}),_t=(s=>(s.AUDIO="AUDIO",s.VIDEO="VIDEO",s.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",s))(_t||{}),Nt=(s=>(s.VP8="video/VP8",s.VP9="video/VP9",s.H264="video/H264",s.AV1="video/AV1",s.rtx="video/rtx",s.red="video/red",s.flexfec03="video/flexfec-03",s))(Nt||{});const At=async(s,t,e)=>{const{isChanged:n,parameters:i}=await Ct(s,{encodings:[{scaleResolutionDownBy:t.scaleResolutionDownBy,maxBitrate:t.maxBitrate}]});return n&&e&&e(i),{isChanged:n,parameters:i}};function sn(s){return t=>`sip:${t}@${s}`}const rn=(s,t)=>()=>Math.floor(Math.random()*(t-s))+s,we=s=>s.trim().replaceAll(" ","_"),on=rn(1e5,99999999),an=s=>s.some(e=>{const{kind:n}=e;return n==="video"}),cn=s=>{const t=[];return s&&t.push(`X-Vinteo-Remote: ${s}`),t},En="content-type",dn="x-webrtc-enter-room",M="application/vinteo.webrtc.sharedesktop",hn="application/vinteo.webrtc.roomname",Tn="application/vinteo.webrtc.channels",Sn="application/vinteo.webrtc.mediastate",ln="application/vinteo.webrtc.refusal",be="application/vinteo.webrtc.maincam",un="application/vinteo.webrtc.mic",gn="application/vinteo.webrtc.uselic",Cn="X-WEBRTC-USE-LICENSE",_n="X-WEBRTC-PARTICIPANT-NAME",Ue="X-WEBRTC-INPUT-CHANNELS",Le="X-WEBRTC-OUTPUT-CHANNELS",Nn="X-WEBRTC-MAINCAM",An="X-WEBRTC-MIC",He="X-WEBRTC-SYNC",Rn="X-WEBRTC-MAINCAM-RESOLUTION",fn="X-WEBRTC-MEDIA-STATE",In="X-Vinteo-Media-Type",Pn="X-Vinteo-MainCam-State",On="X-Vinteo-Mic-State",mn="application/vinteo.webrtc.partstate",Mn="X-WEBRTC-PARTSTATE",Dn="application/vinteo.webrtc.notify",pn="X-VINTEO-NOTIFY",R="x-webrtc-share-state",vn=`${R}: LETMESTARTPRESENTATION`,yn=`${R}: STOPPRESENTATION`,Rt="YOUCANRECEIVECONTENT",ft="CONTENTEND",It="YOUMUSTSTOPSENDCONTENT",wn=`${R}: ${It}`,bn=`${R}: ${Rt}`,Un=`${R}: ${ft}`,Ln="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Hn=`${Ln}: LETMESTARTMAINCAM`,Wn=(s,t)=>{s.getVideoTracks().forEach(n=>{"contentHint"in n&&n.contentHint!==t&&(n.contentHint=t)})},D=(s,{directionVideo:t,directionAudio:e,contentHint:n}={})=>{if(!s||t==="recvonly"&&e==="recvonly")return;const i=e==="recvonly"?[]:s.getAudioTracks(),r=t==="recvonly"?[]:s.getVideoTracks(),o=[...i,...r],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],n&&n!=="none"&&Wn(a,n),a},kn="Error decline with 603",Bn=1006,Fn=s=>typeof s=="object"&&s!==null&&"code"in s&&s.code===Bn,xn=s=>s.message===kn,Vn=(s,t)=>s.find(e=>e.track&&t.getTracks().includes(e.track)),Yn=async(s,t,e)=>{const n=Vn(s,t);if(n)return At(n,{maxBitrate:e})},qn=486,$n=487,Gn=3,Jn=1,Xn=s=>s instanceof Object&&("originator"in s||"cause"in s),Qn=s=>{if(Pt.isCanceledError(s))return!0;if(!Xn(s))return!1;const{originator:t,cause:e}=s;return typeof e=="string"?e===We||e===G||t===C.LOCAL&&(e===J||e===Be):!1},zn="channels",jn="WebcastStarted",Kn="WebcastStopped",Zn="accountChanged",es="accountDeleted",ts="addedToListModerators",ns="removedFromListModerators",ss="ParticipationRequestAccepted",is="ParticipationRequestRejected",rs="ParticipantMovedToWebcast",os="ConferenceParticipantTokenIssued";class as{isRegisterConfigInner=!1;connectionConfiguration={};remoteStreams={};JsSIP;sessionEvents;uaEvents;getSipServerUrl=t=>t;cancelableConnectWithRepeatedCalls;cancelableSendPresentationWithRepeatedCalls;isPendingConnect=!1;isPendingInitUa=!1;isPendingCall=!1;isPendingAnswer=!1;promisePendingStartPresentation;promisePendingStopPresentation;ua;rtcSession;incomingRTCSession;streamPresentationCurrent;socket;constructor({JsSIP:t}){this.JsSIP=t,this.sessionEvents=new ve(De),this.uaEvents=new ve(lt),this.onSession(y,this.handleShareState),this.onSession(Oe,this.handleNewInfo),this.on(Z,this.handleSipEvent),this.onSession(N,this.handleEnded),this.onSession(m,this.handleEnded)}connect=async(t,e)=>(this.cancelRequests(),this.connectWithDuplicatedCalls(t,e));hangUp=async()=>(this.cancelRequests(),this.hangUpWithoutCancelRequests());async register(){return new Promise((t,e)=>{this.isRegisterConfig&&this.ua?(this.ua.on(P,t),this.ua.on(O,e),this.ua.register()):e(new Error("Config is not registered"))})}async unregister(){return new Promise((t,e)=>{this.isRegistered&&this.ua?(this.ua.on(K,t),this.ua.unregister()):e(new Error("ua is not registered"))})}tryRegister=async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this.uaEvents.trigger(B,void 0);try{await this.unregister()}catch(t){p("tryRegister",t)}return this.register()};async sendOptions(t,e,n){if(!this.ua)throw new Error("is not connected");return new Promise((i,r)=>{try{this.ua.sendOptions(t,e,{extraHeaders:n,eventHandlers:{succeeded:()=>{i()},failed:r}})}catch(o){r(o)}})}async ping(t,e){if(!this.ua?.configuration.uri)throw new Error("is not connected");const n=this.ua.configuration.uri;return this.sendOptions(n,t,e)}async checkTelephony({userAgent:t,displayName:e,sipServerUrl:n,sipWebSocketServerURL:i,remoteAddress:r,extraHeaders:o}){return new Promise((a,c)=>{const{configuration:E}=this.createUaConfiguration({sipWebSocketServerURL:i,displayName:e,userAgent:t,sipServerUrl:n}),h=this.createUa({...E,remoteAddress:r,extraHeaders:o}),T=()=>{const S=new Error("Telephony is not available");c(S)};h.once(g,T);const d=()=>{h.removeAllListeners(),h.once(g,a),h.stop()};h.once(I,d),h.start()})}async replaceMediaStream(t,e){if(!this.rtcSession)throw new Error("No rtcSession established");const{contentHint:n}=e??{},i=D(t,{contentHint:n});return this.rtcSession.replaceMediaStream(i,e)}declineToIncomingCall=async({statusCode:t=$n}={})=>new Promise((e,n)=>{if(!this.isAvailableIncomingCall){n(new Error("no incomingRTCSession"));return}const i=this.incomingRTCSession,r=this.remoteCallerData;this.removeIncomingSession(),this.uaEvents.trigger(Q,r),e(i.terminate({status_code:t}))});busyIncomingCall=async()=>this.declineToIncomingCall({statusCode:qn});removeIncomingSession=()=>{delete this.incomingRTCSession};async askPermissionToEnableCam(t={}){if(!this.rtcSession)throw new Error("No rtcSession established");const e=[Hn];return this.rtcSession.sendInfo(be,void 0,{noTerminateWhenError:!0,...t,extraHeaders:e}).catch(n=>{if(xn(n))throw n})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}connectWithDuplicatedCalls=async(t,{callLimit:e=Gn}={})=>{const n=async()=>this.connectInner(t),i=r=>{const a=!!this.ua?.isConnected()&&this.hasEqualConnectionConfiguration(t),c=!!r&&!Fn(r);return a||c};return this.isPendingConnect=!0,this.cancelableConnectWithRepeatedCalls=ye.repeatedCallsAsync({targetFunction:n,isComplete:i,callLimit:e,isRejectAsValid:!0,isCheckBeforeCall:!1}),this.cancelableConnectWithRepeatedCalls.then(r=>{if(r instanceof this.JsSIP.UA)return r;throw r}).finally(()=>{this.isPendingConnect=!1})};async sendPresentationWithDuplicatedCalls({rtcSession:t,stream:e,presentationOptions:n,options:i={callLimit:Jn}}){const r=async()=>this.sendPresentation(t,e,n),o=()=>!!this.streamPresentationCurrent;return this.cancelableSendPresentationWithRepeatedCalls=ye.repeatedCallsAsync({targetFunction:r,isComplete:o,isRejectAsValid:!0,...i}),this.cancelableSendPresentationWithRepeatedCalls.then(a=>a)}hasEqualConnectionConfiguration(t){const{configuration:e}=this.createUaConfiguration(t),n=this.ua?.configuration;return n?.password===e.password&&n?.register===e.register&&n?.uri.toString()===e.uri&&n?.display_name===e.display_name&&n?.user_agent===e.user_agent&&n?.sockets===e.sockets&&n?.session_timers===e.session_timers&&n?.register_expires===e.register_expires&&n?.connection_recovery_min_interval===e.connection_recovery_min_interval&&n?.connection_recovery_max_interval===e.connection_recovery_max_interval}createUaConfiguration({user:t,password:e,sipWebSocketServerURL:n,displayName:i="",sipServerUrl:r,register:o=!1,sessionTimers:a=!1,registerExpires:c=60*5,connectionRecoveryMinInterval:E=2,connectionRecoveryMaxInterval:h=6,userAgent:T}){if(o&&!e)throw new Error("password is required for authorized connection");const d=o&&t?t.trim():`${on()}`,S=sn(r),l=S(d),u=new this.JsSIP.WebSocketInterface(n);return{configuration:{password:e,register:o,uri:l,display_name:we(i),user_agent:T,sdp_semantics:"unified-plan",sockets:[u],session_timers:a,register_expires:c,connection_recovery_min_interval:E,connection_recovery_max_interval:h},helpers:{socket:u,getSipServerUrl:S}}}async sendPresentation(t,e,{maxBitrate:n=ht,isNeedReinvite:i=!0,isP2P:r=!1,contentHint:o="detail",sendEncodings:a,onAddedTransceiver:c}){const E=D(e,{contentHint:o});this.streamPresentationCurrent=E;const h=r?[bn]:[vn],T=t.sendInfo(M,void 0,{extraHeaders:h}).then(async()=>t.startPresentation(E,i,{sendEncodings:a,onAddedTransceiver:c})).then(async()=>{const{connection:d}=this;if(!d||n===void 0)return;const S=d.getSenders();await Yn(S,e,n)}).then(()=>e).catch(d=>{throw this.removeStreamPresentationCurrent(),this.sessionEvents.trigger(H,d),d});return this.promisePendingStartPresentation=T,T.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(t,{isNeedReinvite:e,isP2P:n,maxBitrate:i,contentHint:r,sendEncodings:o,onAddedTransceiver:a}={},c){const E=this.establishedRTCSession;if(!E)throw new Error("No rtcSession established");if(this.streamPresentationCurrent)throw new Error("Presentation is already started");return n&&await this.sendMustStopPresentation(E),this.sendPresentationWithDuplicatedCalls({rtcSession:E,stream:t,presentationOptions:{isNeedReinvite:e,isP2P:n,maxBitrate:i,contentHint:r,sendEncodings:o,onAddedTransceiver:a},options:c})}async sendMustStopPresentation(t){await t.sendInfo(M,void 0,{extraHeaders:[wn]})}async stopPresentation({isP2P:t=!1}={}){this.cancelSendPresentationWithRepeatedCalls();const e=this.streamPresentationCurrent;let n=this.promisePendingStartPresentation??Promise.resolve();const i=t?[Un]:[yn],r=this.establishedRTCSession;return r&&e&&(n=n.then(async()=>r.sendInfo(M,void 0,{extraHeaders:i})).then(async()=>r.stopPresentation(e)).catch(o=>{throw this.sessionEvents.trigger(H,o),o})),!r&&e&&this.sessionEvents.trigger(me,e),this.promisePendingStopPresentation=n,n.finally(()=>{this.resetPresentation()})}async updatePresentation(t,{isP2P:e,maxBitrate:n,contentHint:i,sendEncodings:r,onAddedTransceiver:o}={}){const a=this.establishedRTCSession;if(!a)throw new Error("No rtcSession established");if(!this.streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this.sendPresentation(a,t,{isP2P:e,maxBitrate:n,contentHint:i,isNeedReinvite:!1,sendEncodings:r,onAddedTransceiver:o})}removeStreamPresentationCurrent(){delete this.streamPresentationCurrent}resetPresentation(){this.removeStreamPresentationCurrent(),this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}cancelRequestsAndResetPresentation(){this.cancelSendPresentationWithRepeatedCalls(),this.resetPresentation()}handleNewRTCSession=({originator:t,session:e})=>{if(t===C.REMOTE){this.incomingRTCSession=e;const n=this.remoteCallerData;e.on(N,i=>{this.removeIncomingSession(),i.originator===C.LOCAL?this.uaEvents.trigger(j,n):this.uaEvents.trigger(z,n)}),this.uaEvents.trigger(X,n)}};on(t,e){return this.uaEvents.on(t,e)}once(t,e){return this.uaEvents.once(t,e)}onceRace(t,e){return this.uaEvents.onceRace(t,e)}async wait(t){return this.uaEvents.wait(t)}off(t,e){this.uaEvents.off(t,e)}onSession(t,e){return this.sessionEvents.on(t,e)}onceSession(t,e){return this.sessionEvents.once(t,e)}onceRaceSession(t,e){return this.sessionEvents.onceRace(t,e)}async waitSession(t){return this.sessionEvents.wait(t)}offSession(t,e){this.sessionEvents.off(t,e)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this.connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const e=this.connection.getReceivers().map(({track:n})=>n);return an(e)?this.generateStreams(e):this.generateAudioStreams(e)}get connection(){return this.rtcSession?.connection}get remoteCallerData(){return{displayName:this.incomingRTCSession?.remote_identity?.display_name,host:this.incomingRTCSession?.remote_identity?.uri.host,incomingNumber:this.incomingRTCSession?.remote_identity?.uri.user,rtcSession:this.incomingRTCSession}}get requested(){return this.isPendingInitUa||this.isPendingConnect||this.isPendingCall||this.isPendingAnswer}get establishedRTCSession(){return this.rtcSession?.isEstablished()?this.rtcSession:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this.isRegisterConfigInner}get isCallActive(){return!!(this.ua&&this.rtcSession)}get isAvailableIncomingCall(){return!!this.incomingRTCSession}connectInner=async t=>this.initUa(t).then(async()=>this.start());initUa=async({user:t,password:e,sipServerUrl:n,sipWebSocketServerURL:i,remoteAddress:r,sessionTimers:o,registerExpires:a,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:E,userAgent:h,displayName:T="",register:d=!1,extraHeaders:S=[]})=>{if(!n)throw new Error("sipServerUrl is required");if(!i)throw new Error("sipWebSocketServerURL is required");if(d&&!t)throw new Error("user is required for authorized connection");if(d&&!e)throw new Error("password is required for authorized connection");this.isPendingInitUa=!0;try{this.connectionConfiguration={sipServerUrl:n,displayName:T,register:d,user:t,password:e};const{configuration:l,helpers:u}=this.createUaConfiguration({user:t,sipServerUrl:n,sipWebSocketServerURL:i,password:e,displayName:T,register:d,sessionTimers:o,registerExpires:a,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:E,userAgent:h});return this.getSipServerUrl=u.getSipServerUrl,this.socket=u.socket,this.ua&&await this.disconnect(),this.isRegisterConfigInner=!!d,this.ua=this.createUa({...l,remoteAddress:r,extraHeaders:S}),this.uaEvents.eachTriggers((_,Y)=>{const f=V.find(q=>q===Y);f&&this.ua&&this.ua.on(f,_)}),this.ua}finally{this.isPendingInitUa=!1}};createUa=({remoteAddress:t,extraHeaders:e=[],...n})=>{const i=new this.JsSIP.UA(n),o=[...t?cn(t):[],...e];return o.length>0&&i.registrator().setExtraHeaders(o),i};start=async()=>new Promise((t,e)=>{const{ua:n}=this;if(!n){e(new Error("this.ua is not initialized"));return}const i=()=>{a(),t(n)},r=c=>{a(),e(c)},o=()=>{this.isRegisterConfig?(this.on(P,i),this.on(O,r)):this.on(I,i),this.on(g,r)},a=()=>{this.off(P,i),this.off(O,r),this.off(I,i),this.off(g,r)};o(),this.on(v,this.handleNewRTCSession),n.start()});set=async({displayName:t,password:e})=>new Promise((n,i)=>{const{ua:r}=this;if(!r){i(new Error("this.ua is not initialized"));return}let o=!1,a=!1;t!==void 0&&t!==this.connectionConfiguration.displayName&&(o=r.set("display_name",we(t)),this.connectionConfiguration.displayName=t),e!==void 0&&e!==this.connectionConfiguration.password&&(a=r.set("password",e),this.connectionConfiguration.password=e);const c=o||a;a&&this.isRegisterConfig?this.register().then(()=>{n(c)}).catch(E=>{i(E)}):c?n(c):i(new Error("nothing changed"))});disconnect=async()=>{this.off(v,this.handleNewRTCSession);const t=new Promise(e=>{this.once(g,()=>{e()})});return this.ua?(await this.hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this.uaEvents.trigger(g,void 0)):this.uaEvents.trigger(g,void 0),t.finally(()=>{delete this.ua})};call=async({number:t,mediaStream:e,extraHeaders:n=[],ontrack:i,iceServers:r,directionVideo:o,directionAudio:a,contentHint:c,offerToReceiveAudio:E=!0,offerToReceiveVideo:h=!0,sendEncodings:T,onAddedTransceiver:d})=>(this.isPendingCall=!0,new Promise((S,l)=>{const{ua:u}=this;if(!u){l(new Error("this.ua is not initialized"));return}this.connectionConfiguration.number=t,this.connectionConfiguration.answer=!1,this.handleCall({ontrack:i}).then(S).catch(_=>{l(_)}),this.rtcSession=u.call(this.getSipServerUrl(t),{extraHeaders:n,mediaStream:D(e,{directionVideo:o,directionAudio:a,contentHint:c}),eventHandlers:this.sessionEvents.triggers,directionVideo:o,directionAudio:a,pcConfig:{iceServers:r},rtcOfferConstraints:{offerToReceiveAudio:E,offerToReceiveVideo:h},sendEncodings:T,onAddedTransceiver:d})}).finally(()=>{this.isPendingCall=!1}));answerToIncomingCall=async({mediaStream:t,ontrack:e,extraHeaders:n=[],iceServers:i,directionVideo:r,directionAudio:o,offerToReceiveAudio:a,offerToReceiveVideo:c,contentHint:E,sendEncodings:h,onAddedTransceiver:T})=>(this.isPendingAnswer=!0,new Promise((d,S)=>{if(!this.isAvailableIncomingCall){S(new Error("no incomingRTCSession"));return}this.rtcSession=this.incomingRTCSession,this.removeIncomingSession();const{rtcSession:l}=this;if(!l){S(new Error("No rtcSession established"));return}this.sessionEvents.eachTriggers((_,Y)=>{const f=Me.find(q=>q===Y);f&&l.on(f,_)}),this.connectionConfiguration.answer=!0,this.connectionConfiguration.number=l.remote_identity.uri.user,this.handleCall({ontrack:e}).then(d).catch(_=>{S(_)});const u=D(t,{directionVideo:r,directionAudio:o,contentHint:E});l.answer({extraHeaders:n,directionVideo:r,directionAudio:o,mediaStream:u,pcConfig:{iceServers:i},rtcOfferConstraints:{offerToReceiveAudio:a,offerToReceiveVideo:c},sendEncodings:h,onAddedTransceiver:T})}).finally(()=>{this.isPendingAnswer=!1}));handleCall=async({ontrack:t})=>new Promise((e,n)=>{const i=()=>{this.onSession(L,h),this.onSession(U,T)},r=()=>{this.offSession(L,h),this.offSession(U,T)},o=()=>{this.onSession(N,c),this.onSession(m,c)},a=()=>{this.offSession(N,c),this.offSession(m,c)},c=d=>{r(),a(),n(d)};let E;const h=({peerconnection:d})=>{E=d,E.ontrack=S=>{this.sessionEvents.trigger(oe,E),t&&t(S)}},T=()=>{E&&this.sessionEvents.trigger(re,E),r(),a(),e(E)};i(),o()});restoreSession=()=>{this.cancelRequestsAndResetPresentation(),delete this.connectionConfiguration.number,delete this.rtcSession,this.remoteStreams={}};sendDTMF=async t=>new Promise((e,n)=>{const{rtcSession:i}=this;if(!i){n(new Error("No rtcSession established"));return}this.onceSession(Pe,({originator:r})=>{r===C.LOCAL&&e()}),i.sendDTMF(t,{duration:120,interToneGap:600})});generateStream(t,e){const{id:n}=t,i=this.remoteStreams[n]||new MediaStream;return e&&i.addTrack(e),i.addTrack(t),this.remoteStreams[n]=i,i}generateAudioStream(t){const{id:e}=t,n=this.remoteStreams[e]||new MediaStream;return n.addTrack(t),this.remoteStreams[e]=n,n}generateStreams(t){const e=[];return t.forEach((n,i)=>{if(n.kind==="audio")return;const r=n,o=t[i-1];let a;o&&o.kind==="audio"&&(a=o);const c=this.generateStream(r,a);e.push(c)}),e}generateAudioStreams(t){return t.map(n=>this.generateAudioStream(n))}hangUpWithoutCancelRequests=async()=>{if(this.ua&&this.rtcSession){const{rtcSession:t}=this;if(this.streamPresentationCurrent)try{await this.stopPresentation()}catch(e){p("error stop presentation: ",e)}if(this.restoreSession(),!t.isEnded())return t.terminateAsync({cause:J})}};cancelRequests(){this.cancelConnectWithRepeatedCalls()}cancelConnectWithRepeatedCalls(){this.cancelableConnectWithRepeatedCalls?.cancel()}cancelSendPresentationWithRepeatedCalls(){this.cancelableSendPresentationWithRepeatedCalls?.cancel()}handleShareState=t=>{switch(t){case Rt:{this.sessionEvents.trigger(ee,void 0);break}case ft:{this.sessionEvents.trigger(te,void 0);break}case It:{this.sessionEvents.trigger(ne,void 0);break}}};maybeTriggerChannels=t=>{const e=t.getHeader(Ue),n=t.getHeader(Le);if(e&&n){const i={inputChannels:e,outputChannels:n};this.sessionEvents.trigger(w,i)}};handleNotify=t=>{switch(t.cmd){case zn:{const e=t;this.triggerChannelsNotify(e);break}case jn:{const e=t;this.triggerWebcastStartedNotify(e);break}case Kn:{const e=t;this.triggerWebcastStoppedNotify(e);break}case ts:{const e=t;this.triggerAddedToListModeratorsNotify(e);break}case ns:{const e=t;this.triggerRemovedFromListModeratorsNotify(e);break}case ss:{const e=t;this.triggerParticipationAcceptingWordRequest(e);break}case is:{const e=t;this.triggerParticipationCancellingWordRequest(e);break}case rs:{const e=t;this.triggerParticipantMoveRequestToStream(e);break}case Zn:{this.triggerAccountChangedNotify();break}case es:{this.triggerAccountDeletedNotify();break}case os:{const e=t;this.triggerConferenceParticipantTokenIssued(e);break}default:p("unknown cmd",t.cmd)}};triggerRemovedFromListModeratorsNotify=({conference:t})=>{const e={conference:t};this.uaEvents.trigger(ue,e)};triggerAddedToListModeratorsNotify=({conference:t})=>{const e={conference:t};this.uaEvents.trigger(le,e)};triggerWebcastStartedNotify=({body:{conference:t,type:e}})=>{const n={conference:t,type:e};this.uaEvents.trigger(Ne,n)};triggerWebcastStoppedNotify=({body:{conference:t,type:e}})=>{const n={conference:t,type:e};this.uaEvents.trigger(Ae,n)};triggerAccountChangedNotify=()=>{this.uaEvents.trigger(Re,void 0)};triggerAccountDeletedNotify=()=>{this.uaEvents.trigger(fe,void 0)};triggerConferenceParticipantTokenIssued=({body:{conference:t,participant:e,jwt:n}})=>{const i={conference:t,participant:e,jwt:n};this.uaEvents.trigger(Ie,i)};triggerChannelsNotify=t=>{const e=t.input,n=t.output,i={inputChannels:e,outputChannels:n};this.uaEvents.trigger(ae,i)};triggerParticipationAcceptingWordRequest=({body:{conference:t}})=>{const e={conference:t};this.uaEvents.trigger(Ce,e)};triggerParticipationCancellingWordRequest=({body:{conference:t}})=>{const e={conference:t};this.uaEvents.trigger(_e,e)};triggerParticipantMoveRequestToStream=({body:{conference:t}})=>{const e={conference:t};this.uaEvents.trigger(ge,e)};triggerEnterRoom=t=>{const e=t.getHeader(dn),n=t.getHeader(_n);this.sessionEvents.trigger(se,{room:e,participantName:n})};triggerShareState=t=>{const e=t.getHeader(R);this.sessionEvents.trigger(y,e)};maybeTriggerParticipantMoveRequest=t=>{const e=t.getHeader(Mn);e===Et&&this.sessionEvents.trigger(F,void 0),e===dt&&this.sessionEvents.trigger(x,void 0)};triggerMainCamControl=t=>{const e=t.getHeader(Nn),n=t.getHeader(He),i=n===k.ADMIN_SYNC_FORCED;if(e===A.ADMIN_START_MAIN_CAM){this.sessionEvents.trigger(he,{isSyncForced:i});return}if(e===A.ADMIN_STOP_MAIN_CAM){this.sessionEvents.trigger(de,{isSyncForced:i});return}(e===A.RESUME_MAIN_CAM||e===A.PAUSE_MAIN_CAM)&&n&&this.sessionEvents.trigger(b,{isSyncForced:i});const r=t.getHeader(Rn);this.sessionEvents.trigger(Ee,{mainCam:e,resolutionMainCam:r})};triggerMicControl=t=>{const e=t.getHeader(An),i=t.getHeader(He)===k.ADMIN_SYNC_FORCED;e===W.ADMIN_START_MIC?this.sessionEvents.trigger(Se,{isSyncForced:i}):e===W.ADMIN_STOP_MIC&&this.sessionEvents.trigger(Te,{isSyncForced:i})};triggerUseLicense=t=>{const e=t.getHeader(Cn);this.sessionEvents.trigger(ie,e)};handleNewInfo=t=>{const{originator:e}=t;if(e!==C.REMOTE)return;const{request:n}=t,i=n.getHeader(En);if(i)switch(i){case hn:{this.triggerEnterRoom(n),this.maybeTriggerChannels(n);break}case Dn:{this.maybeHandleNotify(n);break}case M:{this.triggerShareState(n);break}case be:{this.triggerMainCamControl(n);break}case un:{this.triggerMicControl(n);break}case gn:{this.triggerUseLicense(n);break}case mn:{this.maybeTriggerParticipantMoveRequest(n);break}}};handleSipEvent=({request:t})=>{this.maybeHandleNotify(t)};maybeHandleNotify=t=>{const e=t.getHeader(pn);if(e){const n=JSON.parse(e);this.handleNotify(n)}};async waitChannels(){return this.waitSession(w)}async waitSyncMediaState(){return this.waitSession(b)}async sendChannels({inputChannels:t,outputChannels:e}){if(!this.rtcSession)throw new Error("No rtcSession established");const n=`${Ue}: ${t}`,i=`${Le}: ${e}`,r=[n,i];return this.rtcSession.sendInfo(Tn,void 0,{extraHeaders:r})}async sendMediaState({cam:t,mic:e},n={}){if(!this.rtcSession)throw new Error("No rtcSession established");const i=`${fn}: currentstate`,r=`${Pn}: ${Number(t)}`,o=`${On}: ${Number(e)}`,a=[i,r,o];return this.rtcSession.sendInfo(Sn,void 0,{noTerminateWhenError:!0,...n,extraHeaders:a})}async sendRefusalToTurnOn(t,e={}){if(!this.rtcSession)throw new Error("No rtcSession established");const a=[`${In}: ${t==="mic"?0:1}`];return this.rtcSession.sendInfo(ln,void 0,{noTerminateWhenError:!0,...e,extraHeaders:a})}async sendRefusalToTurnOnMic(t={}){if(!this.rtcSession)throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...t})}async sendRefusalToTurnOnCam(t={}){if(!this.rtcSession)throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...t})}handleEnded=t=>{const{originator:e}=t;e===C.REMOTE&&this.sessionEvents.trigger(ce,t),this.restoreSession()}}exports.BAD_MEDIA_DESCRIPTION=Fe;exports.EEventsMainCAM=A;exports.EEventsMic=W;exports.EEventsSyncMediaState=k;exports.EMimeTypesVideoCodecs=Nt;exports.EUseLicense=_t;exports.NOT_FOUND=ke;exports.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS=x;exports.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS=F;exports.REJECTED=G;exports.SESSION_EVENT_NAMES=De;exports.SipConnector=as;exports.UA_JSSIP_EVENT_NAMES=V;exports.causes=Vt;exports.constants=Yt;exports.disableDebug=Gt;exports.enableDebug=$t;exports.eventNames=qt;exports.hasCanceledCallError=Qn;exports.logger=p;exports.setEncodingsToSender=At;exports.setParametersToSender=Ct;
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var b=(o,t,e)=>t in o?k(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>b(o,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-CE4F15z6.cjs"),D=require("@krivega/jssip/lib/NameAddrHeader"),L=require("@krivega/jssip/lib/URI"),F=require("node:events"),V=require("@krivega/jssip/lib/SIPMessage"),C=require("webrtc-mock"),I=require("events-constructor"),T=require("@krivega/jssip");class y extends V.IncomingRequest{constructor(e){super();r(this,"headers");this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)||""}}class z{constructor({originator:t="local",eventHandlers:e}){r(this,"originator");r(this,"_connection");r(this,"_events");r(this,"_remote_identity");r(this,"_mutedOptions",{audio:!1,video:!1});this.originator=t,this._events=new I(g.SESSION_EVENT_NAMES),this.initEvents(e)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(t){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get remote_identity(){return this._remote_identity}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(t){throw new Error("Method not implemented.")}terminate(t){throw new Error("Method not implemented.")}async sendInfo(t,e,n){throw new Error("Method not implemented.")}hold(t,e){throw new Error("Method not implemented.")}unhold(t,e){throw new Error("Method not implemented.")}async renegotiate(t,e){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(t){throw new Error("Method not implemented.")}unmute(t){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(t,e){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(t,e){throw new Error("Method not implemented.")}addListener(t,e){throw new Error("Method not implemented.")}once(t,e){throw new Error("Method not implemented.")}removeListener(t,e){throw new Error("Method not implemented.")}off(t,e){throw new Error("Method not implemented.")}removeAllListeners(t){throw new Error("Method not implemented.")}setMaxListeners(t){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(t){throw new Error("Method not implemented.")}rawListeners(t){throw new Error("Method not implemented.")}emit(t,...e){throw new Error("Method not implemented.")}listenerCount(t){throw new Error("Method not implemented.")}prependListener(t,e){throw new Error("Method not implemented.")}prependOnceListener(t,e){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(t=[]){Object.entries(t).forEach(([e,n])=>this.on(e,n))}on(t,e){return this._events.on(t,e),this}trigger(t,e){this._events.trigger(t,e)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(t){return t}async updatePresentation(t){return t}async stopPresentation(t){return t}isEstablished(){return!0}}class x{constructor({track:t}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"_parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"_parametersGets");this.track=t??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(t){this.track=t??null}async setParameters(t){if(t!==this._parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:e}=this._parameters;this._parameters={...this._parameters,...t,transactionId:`${Number(e)+1}`}}getParameters(){return this._parametersGets={...this._parameters},this._parametersGets}setStreams(){throw new Error("Method not implemented.")}}class U{constructor(t,e){r(this,"_senders",[]);r(this,"_receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this._receivers);r(this,"getSenders",()=>this._senders);r(this,"addTrack",t=>{const e=new x({track:t});return this._senders.push(e),e});this._receivers=e.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(t){throw new Error("Method not implemented.")}addTransceiver(t,e){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(t,e){throw new Error("Method not implemented.")}createDataChannel(t,e){throw new Error("Method not implemented.")}async createOffer(t,e,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(t){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(t){throw new Error("Method not implemented.")}setConfiguration(t){throw new Error("Method not implemented.")}async setLocalDescription(t){throw new Error("Method not implemented.")}async setRemoteDescription(t){throw new Error("Method not implemented.")}addEventListener(t,e,n){throw new Error("Method not implemented.")}removeEventListener(t,e,n){throw new Error("Method not implemented.")}dispatchEvent(t){throw new Error("Method not implemented.")}}function q(o){const t=o.match(/(purgatory)|[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const w=400,N="777",H=o=>o.getVideoTracks().length>0,a=class a extends z{constructor({url:e="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"_isEnded",!1);r(this,"answer",jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},w)}));this.url=e,this.initPeerconnection(n)}static setStartPresentationError(e,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(e){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(e)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const n=C.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(H(e)){const u=C.createVideoMediaStreamTrackMock();u.id="mainvideo1",i.push(u)}this._connection=new U(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(e){const n=q(e);setTimeout(()=>{this.url.includes(N)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},w)}terminate({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e}),this._isEnded=!1,this}async terminateAsync({status_code:e}={}){this.terminate({status_code:e})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}_addStream(e,n="getTracks"){e[n]().forEach(i=>this.connection.addTrack(i))}_forEachSenders(e){const n=this.connection.getSenders();for(const i of n)e(i);return n}_toggleMuteAudio(e){this._forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!e)})}_toggleMuteVideo(e){this._forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!e)})}mute(e){e.audio&&(this._mutedOptions.audio=!0,this._toggleMuteAudio(this._mutedOptions.audio)),e.video&&(this._mutedOptions.video=!0,this._toggleMuteVideo(this._mutedOptions.video)),this._onmute(e)}unmute(e){e.audio&&(this._mutedOptions.audio=!1),e.video&&(this._mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this._mutedOptions}async replaceMediaStream(e){return e}_onmute({audio:e,video:n}){this.trigger("muted",{audio:e,video:n})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(e){this.trigger("newInfo",e)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let l=a;class Y{constructor(){r(this,"extraHeaders",[])}setExtraHeaders(t){this.extraHeaders=t}setExtraContactParams(){}}const c="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",P="NAME_INCORRECT",m=400,s=class s{constructor(t){r(this,"_events");r(this,"_startedTimeout");r(this,"_stopedTimeout");r(this,"session");r(this,"_isRegistered");r(this,"_isConnected");r(this,"configuration");r(this,"_registrator");r(this,"call",jest.fn((t,e)=>{const{mediaStream:n,eventHandlers:i}=e;return this.session=new l({url:t,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(t),this.session}));this._events=new I(g.UA_EVENT_NAMES);const[e,n]=t.uri.split(":"),[i,d]=n.split("@"),u={...t,uri:new T.URI(e,i,d)};this.configuration=u,this._registrator=new Y}static setStartError(t,{count:e=Number.POSITIVE_INFINITY}={}){this.startError=t,this.countStartError=e}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}isConnected(){return!!this._isConnected}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",s.startError);return}this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},m):this.trigger("disconnected",{error:new Error("stoped")})}on(t,e){return this._events.on(t,e),this}once(t,e){return this._events.once(t,e),this}off(t,e){return this._events.off(t,e),this}removeAllListeners(){return this._events.removeEventHandlers(),this}trigger(t,e){this._events.trigger(t,e)}terminateSessions(){this.session.terminate()}set(t,e){return this.configuration[t]=e,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:t,register:e,uri:n}=this.configuration;e&&n.user.includes(P)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},m)):!this._isRegistered&&e&&(t===c||t===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},m)):e&&t!==c&&t!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},m)),s.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(t){this.trigger("sipEvent",t)}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let M=s;class j{constructor(t){r(this,"url");this.url=t}}class B extends F.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const S="remote",G=(o,t)=>{const e=new y(t),n={originator:S,request:e,info:new B("","")};o.newInfo(n)},K=(o,t)=>{const n={request:new y(t)};o.newSipEvent(n)},$=(o,{incomingNumber:t="1234",displayName:e,host:n})=>{const i=new l({originator:S}),d=new L("sip",t,n);i._remote_identity=new D(d,e),o.trigger("newRTCSession",{originator:S,session:i})},J=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},A={triggerNewInfo:G,triggerNewSipEvent:K,triggerIncomingSession:$,triggerFailIncomingSession:J,WebSocketInterface:j,UA:M,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",X=new A.WebSocketInterface(R),v={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:R},Q={...v},O={...v,user:_,password:c,register:!0},Z={...O,displayName:h},ee={...v,displayName:h,register:!1},E={session_timers:!1,sockets:[X],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},te={...E,password:c,uri:new T.URI("sip",_,p),display_name:"",register:!0},re={...E,password:c,uri:new T.URI("sip",_,p),display_name:h,register:!0},ne={...E,display_name:h,register:!1},oe={...E,display_name:"",register:!1},W="10.10.10.10",ie=[`X-Vinteo-Remote: ${W}`],se=()=>new g.SipConnector({JsSIP:A});exports.FAILED_CONFERENCE_NUMBER=N;exports.NAME_INCORRECT=P;exports.PASSWORD_CORRECT=c;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=p;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=Z;exports.dataForConnectionWithoutAuthorization=ee;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Q;exports.default=se;exports.displayName=h;exports.extraHeadersRemoteAddress=ie;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=te;exports.uaConfigurationWithAuthorizationWithDisplayName=re;exports.uaConfigurationWithoutAuthorization=ne;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=oe;exports.user=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./SipConnector-DO0YvSq6.cjs"),W=require("@krivega/jssip/lib/NameAddrHeader"),b=require("@krivega/jssip/lib/URI"),D=require("node:events"),F=require("@krivega/jssip/lib/SIPMessage"),v=require("webrtc-mock"),y=require("events-constructor"),c=require("@krivega/jssip");class I extends F.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}class L{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t}){this.originator=e,this.events=new y(m.SESSION_EVENT_NAMES),this.initEvents(t)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,r){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){Object.entries(e).forEach(([t,r])=>this.on(t,r))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class V{dtmf=null;track=null;transport=null;transform=null;parameters={encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}};parametersGets;constructor({track:e}={}){this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class U{senders=[];receivers=[];constructor(e,t){this.receivers=t.map(r=>({track:r}))}canTrickleIceCandidates;connectionState;currentLocalDescription;currentRemoteDescription;iceConnectionState;iceGatheringState;idpErrorInfo;idpLoginUrl;localDescription;onconnectionstatechange;ondatachannel;onicecandidate;onicecandidateerror=null;oniceconnectionstatechange;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;peerIdentity=void 0;pendingLocalDescription;pendingRemoteDescription;remoteDescription;sctp=null;signalingState;getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,r){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,r){throw new Error("Method not implemented.")}removeEventListener(e,t,r){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=e=>{const t=new V({track:e});return this.senders.push(t),t}}function z(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const w=400,N="777",x=n=>n.getVideoTracks().length>0;class s extends L{url;status_code;isEndedInner=!1;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;constructor({url:e="",mediaStream:t,eventHandlers:r,originator:o}){super({originator:o,eventHandlers:r}),this.url=e,this.initPeerconnection(t)}static setStartPresentationError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=t}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(e){if(s.countStartsPresentation+=1,s.startPresentationError&&s.countStartsPresentation<s.countStartPresentationError)throw s.startPresentationError;return super.startPresentation(e)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=v.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(x(e)){const a=v.createVideoMediaStreamTrackMock();a.id="mainvideo1",r.push(a)}this.connection=new U(void 0,r),this.addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(e){const t=z(e);setTimeout(()=>{this.url.includes(N)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:m.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:t})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},w)}answer=jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},w)});terminate({status_code:e,cause:t}={}){return this.status_code=e,this.trigger("ended",{status_code:e,cause:t,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:e,cause:t}={}){this.terminate({status_code:e,cause:t})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}addStream(e,t="getTracks"){e[t]().forEach(r=>this.connection.addTrack(r))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t&&t.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{t&&t.kind==="video"&&(t.enabled=!e)})}mute(e){e.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),e.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(e)}unmute(e){e.audio&&(this.mutedOptions.audio=!1),e.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this.mutedOptions}async replaceMediaStream(e){}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}}class q{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",P="NAME_INCORRECT",u=400,_={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},R={status_code:200,reason_phrase:"OK"},C={status_code:401,reason_phrase:"Unauthorized"};class i{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startError=e,this.countStartError=t}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}events;startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;registratorInner;constructor(e){this.events=new y(m.UA_JSSIP_EVENT_NAMES);const[t,r]=e.uri.split(":"),[o,a]=r.split("@"),E={...e,uri:new c.URI(t,o,a)};this.configuration=E,this.registratorInner=new q}start(){if(i.countStarts+=1,i.startError&&i.countStarts<i.countStartError){this.trigger("disconnected",i.startError);return}this.register()}stop(){this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:_})},u):this.trigger("disconnected",{error:!0,socket:_})}call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:o}=t;return this.session=new s({url:e,mediaStream:r,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session});on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}off(e,t){return this.events.off(e,t),this}removeAllListeners(){return this.events.removeEventHandlers(),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){this.session.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:r}=this.configuration;t&&r.user.includes(P)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:C,cause:c.C.causes.REJECTED})},u)):!this.isRegistered()&&t&&(e===d||e===f)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:R})},u)):t&&e!==d&&e!==f&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:C,cause:c.C.causes.REJECTED})},u)),i.isAvailableTelephony?(this.trigger("connected",{socket:_}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:R})}isRegistered(){return!!this.isRegisteredInner}isConnected(){return!!this.isConnectedInner}isStarted(){return this.configuration&&((this.configuration.register&&!!this.isRegisteredInner)??(!this.configuration.register&&!!this.isConnectedInner))}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}}class H{url;constructor(e){this.url=e}}class Y extends D.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const S="remote",j=(n,e)=>{const t=new I(e),r={originator:S,request:t,info:new Y("","")};n.newInfo(r)},B=(n,e)=>{const r={event:"sipEvent",request:new I(e)};n.newSipEvent(r)},G=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new s({originator:S,eventHandlers:{}}),a=new b("sip",e,r);o.remote_identity=new W(a,t);const E=new I([]);n.trigger("newRTCSession",{originator:S,session:o,request:E})},J=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},A={triggerNewInfo:j,triggerNewSipEvent:B,triggerIncomingSession:G,triggerFailIncomingSession:J,WebSocketInterface:H,UA:i,C:{INVITE:"INVITE"}},l="user",h="displayName",g="SIP_SERVER_URL",M="SIP_WEB_SOCKET_SERVER_URL",K=new A.WebSocketInterface(M),T={userAgent:"Chrome",sipServerUrl:g,sipWebSocketServerURL:M},$={...T},O={...T,user:l,password:d,register:!0},X={...O,displayName:h},Q={...T,displayName:h,register:!1},p={session_timers:!1,sockets:[K],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Z={...p,password:d,uri:new c.URI("sip",l,g),display_name:"",register:!0},ee={...p,password:d,uri:new c.URI("sip",l,g),display_name:h,register:!0},te={...p,display_name:h,register:!1},re={...p,display_name:"",register:!1},k="10.10.10.10",ne=[`X-Vinteo-Remote: ${k}`],oe=()=>new m.SipConnector({JsSIP:A});exports.FAILED_CONFERENCE_NUMBER=N;exports.NAME_INCORRECT=P;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=g;exports.SIP_WEB_SOCKET_SERVER_URL=M;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=X;exports.dataForConnectionWithoutAuthorization=Q;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=$;exports.displayName=h;exports.doMockSipConnector=oe;exports.extraHeadersRemoteAddress=ne;exports.remoteAddress=k;exports.uaConfigurationWithAuthorization=Z;exports.uaConfigurationWithAuthorizationWithDisplayName=ee;exports.uaConfigurationWithoutAuthorization=te;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=re;exports.user=l;