sip-connector 6.22.3 → 6.24.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.
@@ -0,0 +1 @@
1
+ "use strict";var Rt=Object.defineProperty;var It=(r,e,t)=>e in r?Rt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(It(r,typeof e!="symbol"?e+"":e,t),t);const S=require("@krivega/cancelable-promise"),Pe=require("events-constructor"),B=require("debug"),mt="Connection Error",He="Request Timeout",ft="SIP Failure Code",Ot="Internal Error",Dt="Busy",V="Rejected",Mt="Redirected",Pt="Unavailable",qe="Not Found",pt="Address Incomplete",vt="Incompatible SDP",bt="Missing SDP",wt="Authentication Error",ke="Terminated",yt="WebRTC Error",We="Canceled",Ut="No Answer",Lt="Expires",Ht="No ACK",qt="Dialog Error",kt="User Denied Media Access",Fe="Bad Media Description",Wt="RTP Timeout",Ft=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:pt,AUTHENTICATION_ERROR:wt,BAD_MEDIA_DESCRIPTION:Fe,BUSY:Dt,BYE:ke,CANCELED:We,CONNECTION_ERROR:mt,DIALOG_ERROR:qt,EXPIRES:Lt,INCOMPATIBLE_SDP:vt,INTERNAL_ERROR:Ot,MISSING_SDP:bt,NOT_FOUND:qe,NO_ACK:Ht,NO_ANSWER:Ut,REDIRECTED:Mt,REJECTED:V,REQUEST_TIMEOUT:He,RTP_TIMEOUT:Wt,SIP_FAILURE_CODE:ft,UNAVAILABLE:Pt,USER_DENIED_MEDIA_ACCESS:kt,WEBRTC_ERROR:yt},Symbol.toStringTag,{value:"Module"})),Y="incomingCall",x="declinedIncomingCall",G="failedIncomingCall",$="terminatedIncomingCall",H="connecting",I="connected",T="disconnected",M="newRTCSession",m="registered",X="unregistered",f="registrationFailed",Be="newMessage",J="sipEvent",z="availableSecondRemoteStream",Q="notAvailableSecondRemoteStream",K="mustStopPresentation",P="shareState",j="enterRoom",Z="useLicense",ee="peerconnection:confirmed",te="peerconnection:ontrack",p="channels",ne="channels:notify",se="ended:fromserver",ie="main-cam-control",re="admin-stop-main-cam",oe="admin-start-main-cam",ae="admin-stop-mic",ce="admin-start-mic",v="admin-force-sync-media-state",Ee="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",he="participant:move-request-to-stream",de="participation:accepting-word-request",le="participation:cancelling-word-request",ue="webcast:started",Te="webcast:stopped",Se="account:changed",Ne="account:deleted",ge="conference:participant-token-issued",O="ended",Ve="sending",Ye="reinvite",xe="replaces",Ge="refer",$e="progress",Xe="accepted",b="confirmed",w="peerconnection",C="failed",Je="muted",ze="unmuted",Ce="newDTMF",Ae="newInfo",Qe="hold",Ke="unhold",je="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",Re="presentation:ended",y="presentation:failed",Bt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Xe,ACCOUNT_CHANGED:Se,ACCOUNT_DELETED:Ne,ADMIN_FORCE_SYNC_MEDIA_STATE:v,ADMIN_START_MAIN_CAM:oe,ADMIN_START_MIC:ce,ADMIN_STOP_MAIN_CAM:re,ADMIN_STOP_MIC:ae,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:z,CHANNELS:p,CHANNELS_NOTIFY:ne,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:ge,CONFIRMED:b,CONNECTED:I,CONNECTING:H,DECLINED_INCOMING_CALL:x,DISCONNECTED:T,ENDED:O,ENDED_FROM_SERVER:se,ENTER_ROOM:j,FAILED:C,FAILED_INCOMING_CALL:G,GET_USER_MEDIA_FAILED:tt,HOLD:Qe,ICE_CANDIDATE:et,INCOMING_CALL:Y,MAIN_CAM_CONTROL:ie,MUST_STOP_PRESENTATION_EVENT:K,MUTED:Je,NEW_DTMF:Ce,NEW_INFO:Ae,NEW_MESSAGE:Be,NEW_RTC_SESSION:M,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Q,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Ee,PARTICIPANT_MOVE_REQUEST_TO_STREAM:he,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:_e,PARTICIPATION_ACCEPTING_WORD_REQUEST:de,PARTICIPATION_CANCELLING_WORD_REQUEST:le,PEER_CONNECTION:w,PEER_CONNECTION_CONFIRMED:ee,PEER_CONNECTION_CREATE_ANSWER_FAILED:st,PEER_CONNECTION_CREATE_OFFER_FAILED:nt,PEER_CONNECTION_ONTRACK:te,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:it,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:rt,PRESENTATION_END:ct,PRESENTATION_ENDED:Re,PRESENTATION_FAILED:y,PRESENTATION_START:ot,PRESENTATION_STARTED:at,PROGRESS:$e,REFER:Ge,REGISTERED:m,REGISTRATION_FAILED:f,REINVITE:Ye,REPLACES:xe,SDP:Ze,SENDING:Ve,SHARE_STATE:P,SIP_EVENT:J,TERMINATED_INCOMING_CALL:$,UNHOLD:Ke,UNMUTED:ze,UNREGISTERED:X,UPDATE:je,USE_LICENSE:Z,WEBCAST_STARTED:ue,WEBCAST_STOPPED:Te},Symbol.toStringTag,{value:"Module"})),Et=[Y,x,$,G,de,le,he,ne,ge,Se,Ne,ue,Te,Ee,_e],Ie=[H,I,T,M,m,X,f,Be,J],_t=[z,Q,K,P,j,Z,ee,te,p,se,ie,oe,re,ae,ce,v],me=[O,H,Ve,Ye,xe,Ge,$e,Xe,b,w,C,Je,ze,Ce,Ae,Qe,Ke,je,Ze,et,tt,nt,st,it,rt,ot,at,ct,Re,y],fe=[...Ie,...Et],Oe=[...me,..._t],Vt=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Oe,SESSION_JSSIP_EVENT_NAMES:me,SESSION_SYNTHETICS_EVENT_NAMES:_t,UA_EVENT_NAMES:fe,UA_JSSIP_EVENT_NAMES:Ie,UA_SYNTHETICS_EVENT_NAMES:Et},Symbol.toStringTag,{value:"Module"})),Yt=r=>{const e=[];return r&&e.push(`X-Vinteo-Remote: ${r}`),e},xt="content-type",Gt="x-webrtc-enter-room",q="application/vinteo.webrtc.sharedesktop",$t="application/vinteo.webrtc.roomname",Xt="application/vinteo.webrtc.channels",Jt="application/vinteo.webrtc.mediastate",zt="application/vinteo.webrtc.refusal",pe="application/vinteo.webrtc.maincam",Qt="application/vinteo.webrtc.mic",Kt="application/vinteo.webrtc.uselic",jt="X-WEBRTC-USE-LICENSE",ve="X-WEBRTC-INPUT-CHANNELS",be="X-WEBRTC-OUTPUT-CHANNELS",Zt="X-WEBRTC-MAINCAM",en="X-WEBRTC-MIC",we="X-WEBRTC-SYNC",tn="X-WEBRTC-MAINCAM-RESOLUTION",nn="X-WEBRTC-MEDIA-STATE",sn="X-Vinteo-Media-Type",rn="X-Vinteo-MainCam-State",on="X-Vinteo-Mic-State",an="application/vinteo.webrtc.notify",cn="X-VINTEO-NOTIFY",D="x-webrtc-share-state",En=`${D}: LETMESTARTPRESENTATION`,_n=`${D}: STOPPRESENTATION`,ht="YOUCANRECEIVECONTENT",dt="CONTENTEND",hn="YOUMUSTSTOPSENDCONTENT",dn=`${D}: ${ht}`,ln=`${D}: ${dt}`,un="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Tn=`${un}: LETMESTARTMAINCAM`,De="sip-connector",W=B(De),Sn=()=>{B.enable(De)},Nn=()=>{B.enable(`-${De}`)};var A=(r=>(r.PAUSE_MAIN_CAM="PAUSEMAINCAM",r.RESUME_MAIN_CAM="RESUMEMAINCAM",r.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",r.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",r.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",r))(A||{}),U=(r=>(r.ADMIN_STOP_MIC="ADMINSTOPMIC",r.ADMIN_START_MIC="ADMINSTARTMIC",r))(U||{}),L=(r=>(r.ADMIN_SYNC_FORCED="1",r.ADMIN_SYNC_NOT_FORCED="0",r))(L||{}),lt=(r=>(r.AUDIO="AUDIO",r.VIDEO="VIDEO",r.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",r))(lt||{});function ye(r){return e=>`sip:${e}@${r}`}const gn=(r,e)=>()=>Math.floor(Math.random()*(e-r))+r,Ue=r=>r.trim().replaceAll(" ","_"),Cn=gn(1e5,99999999),k=(r,{videoMode:e,audioMode:t}={})=>{if(!r||e==="recvonly"&&t==="recvonly")return;const n=t==="recvonly"?[]:r.getAudioTracks(),s=e==="recvonly"?[]:r.getVideoTracks(),o=[...n,...s],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],a},An=r=>r.some(t=>{const{kind:n}=t;return n==="video"}),Rn="Error decline with 603",In=r=>r.message===Rn,mn=(r,e)=>r.find(t=>t.track&&e.getTracks().includes(t.track)),ut=1,Tt=r=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==r,fn=Tt(ut),On=(r,e)=>{const t=r===void 0?void 0:Math.max(r,ut);if(t!==void 0&&fn(t,e))return t},Dn=Tt(),Mn=(r,e)=>{if(Dn(r,e))return r},St=async(r,e,t)=>{const n=r.getParameters();(n.encodings===void 0||n.encodings.length===0)&&(n.encodings=[{}]);const[s]=n.encodings,o=s.scaleResolutionDownBy,a=On(e.scaleResolutionDownBy,o);let c=!1;a!==void 0&&(n.encodings[0].scaleResolutionDownBy=a,c=!0);const E=s.maxBitrate,h=Mn(e.maxBitrate,E);return h!==void 0&&(n.encodings[0].maxBitrate=h,c=!0),c?(t&&t(n),r.setParameters(n).then(()=>({parameters:n,isChanged:c}))):{parameters:n,isChanged:c}},Pn=async(r,e,t)=>{const n=mn(r,e);if(n)return St(n,{maxBitrate:t})},pn=486,vn=487,F="local",Le="remote",bn=(r=new Error)=>{const{originator:e,cause:t}=r;return S.isCanceledError(r)?!0:typeof t=="string"?t===He||t===V||e===F&&(t===We||t===ke):!1},N="SipConnector",wn="channels",yn="WebcastStarted",Un="WebcastStopped",Ln="accountChanged",Hn="accountDeleted",qn="addedToListModerators",kn="removedFromListModerators",Wn="ParticipationRequestAccepted",Fn="ParticipationRequestRejected",Bn="ParticipantMovedToWebcast",Vn="ConferenceParticipantTokenIssued";class Yn{constructor({JsSIP:e}){i(this,"_isRegisterConfig",!1);i(this,"_connectionConfiguration",{});i(this,"_remoteStreams",{});i(this,"JsSIP");i(this,"_sessionEvents");i(this,"_uaEvents");i(this,"_cancelableConnect");i(this,"_cancelableInitUa");i(this,"_cancelableDisconnect");i(this,"_cancelableSet");i(this,"_cancelableCall");i(this,"_cancelableAnswer");i(this,"_cancelableSendDTMF");i(this,"getSipServerUrl",e=>e);i(this,"promisePendingStartPresentation");i(this,"promisePendingStopPresentation");i(this,"ua");i(this,"session");i(this,"incomingSession");i(this,"_streamPresentationCurrent");i(this,"socket");i(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));i(this,"initUa",async e=>this._cancelableInitUa.request(e));i(this,"set",async e=>this._cancelableSet.request(e));i(this,"call",async e=>this._cancelableCall.request(e));i(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));i(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));i(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));i(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));i(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(H,void 0);try{await this.unregister()}catch(e){W("tryRegister",e)}return this.register()});i(this,"declineToIncomingCall",async({statusCode:e=vn}={})=>new Promise((t,n)=>{if(!this.isAvailableIncomingCall){n(new Error("no incomingSession"));return}const s=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(x,o),t(s.terminate({status_code:e}))}));i(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:pn}));i(this,"removeIncomingSession",()=>{delete this.incomingSession});i(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===Le){this.incomingSession=t;const n=this.remoteCallerData;t.on(C,s=>{this.removeIncomingSession(),s.originator===F?this._uaEvents.trigger($,n):this._uaEvents.trigger(G,n)}),this._uaEvents.trigger(Y,n)}});i(this,"_connect",async e=>this.initUa(e).then(async()=>this._start()));i(this,"_initUa",async({user:e,password:t,sipServerUrl:n,sipWebSocketServerURL:s,remoteAddress:o,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:h,connectionRecoveryMaxInterval:_,userAgent:u,displayName:l="",register:d=!1,extraHeaders:g=[]})=>{if(!n)throw new Error("sipServerUrl is required");if(!s)throw new Error("sipWebSocketServerURL is required");if(d&&!e)throw new Error("user is required for authorized connection");if(d&&!t)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:n,displayName:l,register:d,user:e,password:t},this.getSipServerUrl=ye(n),this.socket=new this.JsSIP.WebSocketInterface(s),this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!d;const{socket:R}=this;this.ua=this._createUa({user:e,password:t,socket:R,displayName:l,register:d,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:h,connectionRecoveryMaxInterval:_,userAgent:u,getSipServerUrl:this.getSipServerUrl}),this._uaEvents.eachTriggers((gt,Ct)=>{const Me=Ie.find(At=>At===Ct);Me&&this.ua&&this.ua.on(Me,gt)});const Nt=[...Yt(o),...g];return this.ua.registrator().setExtraHeaders(Nt),this.ua});i(this,"_createUa",({user:e,password:t,socket:n,displayName:s,getSipServerUrl:o,register:a=!1,sdpSemantics:c="plan-b",sessionTimers:E=!1,registerExpires:h=60*5,connectionRecoveryMinInterval:_=2,connectionRecoveryMaxInterval:u=6,userAgent:l})=>{if(a&&!t)throw new Error("password is required for authorized connection");const d=a&&e?e.trim():`${Cn()}`,g=o(d),R={password:t,register:a,uri:g,display_name:Ue(s),user_agent:l,sdp_semantics:c,sockets:[n],session_timers:E,register_expires:h,connection_recovery_min_interval:_,connection_recovery_max_interval:u};return new this.JsSIP.UA(R)});i(this,"_start",async()=>new Promise((e,t)=>{const{ua:n}=this;if(!n){t(new Error("this.ua is not initialized"));return}const s=()=>{c(),e(n)},o=E=>{c(),t(E)},a=()=>{this.isRegisterConfig?(this.on(m,s),this.on(f,o)):this.on(I,s),this.on(T,o)},c=()=>{this.off(m,s),this.off(f,o),this.off(I,s),this.off(T,o)};a(),this.on(M,this.handleNewRTCSession),n.start()}));i(this,"_set",async({displayName:e,password:t})=>new Promise((n,s)=>{const{ua:o}=this;if(!o){s(new Error("this.ua is not initialized"));return}let a=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(a=o.set("display_name",Ue(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const E=a||c;c&&this.isRegisterConfig?this.register().then(()=>{n(E)}).catch(s):E?n(E):s(new Error("nothing changed"))}));i(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());i(this,"_disconnect",async()=>{this.off(M,this.handleNewRTCSession);const e=new Promise(t=>{this.once(T,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(T,void 0)):this._uaEvents.trigger(T,void 0),e});i(this,"_call",async({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:o,videoMode:a,audioMode:c,degradationPreference:E,offerToReceiveAudio:h=!0,offerToReceiveVideo:_=!0})=>new Promise((u,l)=>{const{ua:d}=this;if(!d){l(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(u).catch(l),this.session=d.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:k(t,{videoMode:a,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:a,audioMode:c,degradationPreference:E,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:h,offerToReceiveVideo:_}})}));i(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:o,audioMode:a,degradationPreference:c})=>new Promise((E,h)=>{if(!this.isAvailableIncomingCall){h(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:_}=this;if(!_){h(new Error("No session established"));return}this._sessionEvents.eachTriggers((l,d)=>{const g=me.find(R=>R===d);g&&_.on(g,l)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=_.remote_identity.uri.user,this._handleCall({ontrack:t}).then(E).catch(h);const u=k(e,{videoMode:o,audioMode:a});_.answer({extraHeaders:n,videoMode:o,audioMode:a,degradationPreference:c,mediaStream:u,pcConfig:{iceServers:s}})}));i(this,"_handleCall",async({ontrack:e})=>new Promise((t,n)=>{const s=()=>{this.onSession(w,_),this.onSession(b,u)},o=()=>{this.offSession(w,_),this.offSession(b,u)},a=()=>{this.onSession(C,E),this.onSession(O,E)},c=()=>{this.offSession(C,E),this.offSession(O,E)},E=l=>{o(),c(),n(l)};let h;const _=({peerconnection:l})=>{h=l,h.ontrack=d=>{this._sessionEvents.trigger(te,h),e&&e(d)}},u=()=>{h&&this._sessionEvents.trigger(ee,h),o(),c(),t(h)};s(),a()}));i(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});i(this,"_sendDTMF",async e=>new Promise((t,n)=>{const{session:s}=this;if(!s){n(new Error("No session established"));return}this.onceSession(Ce,({originator:o})=>{o===F&&t()}),s.sendDTMF(e,{duration:120,interToneGap:600})}));i(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),e.isEnded()||e.terminate()}});i(this,"_handleShareState",e=>{switch(e){case ht:{this._sessionEvents.trigger(z,void 0);break}case dt:{this._sessionEvents.trigger(Q,void 0);break}case hn:{this._sessionEvents.trigger(K,void 0);break}}});i(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(ve),n=e.getHeader(be);if(t&&n){const s={inputChannels:t,outputChannels:n};this._sessionEvents.trigger(p,s)}});i(this,"_handleNotify",e=>{switch(e.cmd){case wn:{const t=e;this._triggerChannelsNotify(t);break}case yn:{const t=e;this._triggerWebcastStartedNotify(t);break}case Un:{const t=e;this._triggerWebcastStoppedNotify(t);break}case qn:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case kn:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case Wn:{const t=e;this._triggerParticipationAcceptingWordRequest(t);break}case Fn:{const t=e;this._triggerParticipationCancellingWordRequest(t);break}case Bn:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case Ln:{this._triggerAccountChangedNotify();break}case Hn:{this._triggerAccountDeletedNotify();break}case Vn:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:W("unknown cmd",e.cmd)}});i(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(_e,t)});i(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Ee,t)});i(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(ue,n)});i(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(Te,n)});i(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(Se,void 0)});i(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(Ne,void 0)});i(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger(ge,s)});i(this,"_triggerChannelsNotify",e=>{const t=e.input,n=e.output,s={inputChannels:t,outputChannels:n};this._uaEvents.trigger(ne,s)});i(this,"_triggerParticipationAcceptingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(de,t)});i(this,"_triggerParticipationCancellingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(le,t)});i(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(he,t)});i(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Gt);this._sessionEvents.trigger(j,t)});i(this,"_triggerShareState",e=>{const t=e.getHeader(D);this._sessionEvents.trigger(P,t)});i(this,"_triggerMainCamControl",e=>{const t=e.getHeader(Zt),n=e.getHeader(we),s=n===L.ADMIN_SYNC_FORCED;if(t===A.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(oe,{isSyncForced:s});else if(t===A.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(re,{isSyncForced:s});else if((t===A.RESUME_MAIN_CAM||t===A.PAUSE_MAIN_CAM)&&n)this._sessionEvents.trigger(v,{isSyncForced:s});else{const o=e.getHeader(tn);this._sessionEvents.trigger(ie,{mainCam:t,resolutionMainCam:o})}});i(this,"_triggerMicControl",e=>{const t=e.getHeader(en),s=e.getHeader(we)===L.ADMIN_SYNC_FORCED;t===U.ADMIN_START_MIC?this._sessionEvents.trigger(ce,{isSyncForced:s}):t===U.ADMIN_STOP_MIC&&this._sessionEvents.trigger(ae,{isSyncForced:s})});i(this,"_triggerUseLicense",e=>{const t=e.getHeader(jt);this._sessionEvents.trigger(Z,t)});i(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:n}=e,s=n.getHeader(xt);if(s)switch(s){case $t:{this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break}case an:{this._maybeHandleNotify(n);break}case q:{this._triggerShareState(n);break}case pe:{this._triggerMainCamControl(n);break}case Qt:{this._triggerMicControl(n);break}case Kt:{this._triggerUseLicense(n);break}}});i(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});i(this,"_maybeHandleNotify",e=>{const t=e.getHeader(cn);if(t){const n=JSON.parse(t);this._handleNotify(n)}});i(this,"_handleEnded",e=>{const{originator:t}=e;t===Le&&this._sessionEvents.trigger(se,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new Pe(Oe),this._uaEvents=new Pe(fe),this._cancelableConnect=new S.CancelableRequest(this._connect,{moduleName:N,afterCancelRequest:()=>{this._cancelableInitUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableInitUa=new S.CancelableRequest(this._initUa,{moduleName:N}),this._cancelableDisconnect=new S.CancelableRequest(this._disconnect,{moduleName:N}),this._cancelableSet=new S.CancelableRequest(this._set,{moduleName:N}),this._cancelableCall=new S.CancelableRequest(this._call,{moduleName:N}),this._cancelableAnswer=new S.CancelableRequest(this._answer,{moduleName:N}),this._cancelableSendDTMF=new S.CancelableRequest(this._sendDTMF,{moduleName:N}),this.onSession(P,this._handleShareState),this.onSession(Ae,this._handleNewInfo),this.on(J,this._handleSipEvent),this.onSession(C,this._handleEnded),this.onSession(O,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(m,e),this.ua.on(f,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(X,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,n){if(!this.ua)throw new Error("is not connected");return new Promise((s,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:o}})}catch(a){o(a)}})}async ping(e,t){var s;if(!((s=this.ua)!=null&&s.configuration.uri))throw new Error("is not connected");const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}async checkTelephony({userAgent:e,displayName:t,sipServerUrl:n,sipWebSocketServerURL:s,sdpSemantics:o}){return new Promise((a,c)=>{const E=ye(n),h=new this.JsSIP.WebSocketInterface(s),_=this._createUa({socket:h,displayName:t,sdpSemantics:o,userAgent:e,getSipServerUrl:E}),u=()=>{const d=new Error("Telephony is not available");c(d)};_.once(T,u);const l=()=>{_.removeAllListeners(),_.once(T,a),_.stop()};_.once(I,l),_.start()})}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=[Tn];return this.session.sendInfo(pe,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(n=>{if(In(n))throw n})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:o=!0,isP2P:a=!1}){const c=k(t);this._streamPresentationCurrent=c;const E=a?[dn]:[En],h=e.sendInfo(q,void 0,{extraHeaders:E}).then(async()=>e.startPresentation(c,o,s)).then(async()=>{const{connection:_}=this;if(!_||n===void 0)return;const u=_.getSenders();await Pn(u,t,n)}).then(()=>t).catch(_=>{throw this._sessionEvents.trigger(y,_),_});return this.promisePendingStartPresentation=h,h.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:o}={}){const a=this.establishedSession;if(!a)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return this._sendPresentation(a,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:o})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation??Promise.resolve();const s=e?[ln]:[_n],o=this.establishedSession;return o&&t&&(n=n.then(async()=>o.sendInfo(q,void 0,{extraHeaders:s})).then(async()=>o.stopPresentation(t)).catch(a=>{throw this._sessionEvents.trigger(y,a),a})),!o&&t&&this._sessionEvents.trigger(Re,t),this.promisePendingStopPresentation=n,n.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:n,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,e,{isP2P:t,maxBitrate:n,degradationPreference:s,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:n})=>n);return An(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,n,s,o,a;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(s=(n=this.incomingSession)==null?void 0:n.remote_identity)==null?void 0:s.uri.host,incomingNumber:(a=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:a.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableInitUa.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}_generateStream(e,t){const{id:n}=e,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const{id:t}=e,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach((n,s)=>{if(n.kind==="audio")return;const o=n,a=e[s-1];let c;a&&a.kind==="audio"&&(c=a);const E=this._generateStream(o,c);t.push(E)}),t}_generateAudioStreams(e){return e.map(n=>this._generateAudioStream(n))}_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(p)}async waitSyncMediaState(){return this.waitSession(v)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=`${ve}: ${e}`,s=`${be}: ${t}`,o=[n,s];return this.session.sendInfo(Xt,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},n={}){if(!this.session)throw new Error("No session established");const s=`${nn}: currentstate`,o=`${rn}: ${Number(e)}`,a=`${on}: ${Number(t)}`,c=[s,o,a];return this.session.sendInfo(Jt,void 0,{noTerminateWhenError:!0,...n,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${sn}: ${e==="mic"?0:1}`];return this.session.sendInfo(zt,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})}}exports.BAD_MEDIA_DESCRIPTION=Fe;exports.EEventsMainCAM=A;exports.EEventsMic=U;exports.EEventsSyncMediaState=L;exports.EUseLicense=lt;exports.NOT_FOUND=qe;exports.REJECTED=V;exports.SESSION_EVENT_NAMES=Oe;exports.SipConnector=Yn;exports.UA_EVENT_NAMES=fe;exports.causes=Ft;exports.constants=Bt;exports.disableDebug=Nn;exports.enableDebug=Sn;exports.eventNames=Vt;exports.hasCanceledCallError=bn;exports.logger=W;exports.setEncodingsToSender=St;
@@ -74,6 +74,7 @@ type TOptionsExtraHeaders = {
74
74
  extraHeaders?: string[];
75
75
  };
76
76
  type TOntrack = (track: RTCTrackEvent) => void;
77
+ type TGetServerUrl = (id: string) => string;
77
78
  type TParametersConnection = TOptionsExtraHeaders & {
78
79
  displayName?: string;
79
80
  user?: string;
@@ -89,8 +90,30 @@ type TParametersConnection = TOptionsExtraHeaders & {
89
90
  connectionRecoveryMaxInterval?: number;
90
91
  userAgent?: string;
91
92
  };
93
+ type TParametersCreateUa = {
94
+ socket: WebSocketInterface;
95
+ displayName: string;
96
+ getSipServerUrl: TGetServerUrl;
97
+ user?: string;
98
+ register?: boolean;
99
+ password?: string;
100
+ sdpSemantics?: 'plan-b' | 'unified-plan';
101
+ sessionTimers?: boolean;
102
+ registerExpires?: number;
103
+ connectionRecoveryMinInterval?: number;
104
+ connectionRecoveryMaxInterval?: number;
105
+ userAgent?: string;
106
+ };
107
+ type TParametersCheckTelephony = {
108
+ displayName: string;
109
+ sipServerUrl: string;
110
+ sipWebSocketServerURL: string;
111
+ sdpSemantics?: 'plan-b' | 'unified-plan';
112
+ userAgent?: string;
113
+ };
92
114
  type TConnect = (parameters: TParametersConnection) => Promise<UA>;
93
- type TCreateUa = (parameters: TParametersConnection) => Promise<UA>;
115
+ type TInitUa = (parameters: TParametersConnection) => Promise<UA>;
116
+ type TCreateUa = (parameters: TParametersCreateUa) => UA;
94
117
  type TStart = () => Promise<UA>;
95
118
  type TSet = ({ displayName, password, }: {
96
119
  displayName?: string;
@@ -130,7 +153,7 @@ export default class SipConnector {
130
153
  private readonly _sessionEvents;
131
154
  private readonly _uaEvents;
132
155
  private readonly _cancelableConnect;
133
- private readonly _cancelableCreateUa;
156
+ private readonly _cancelableInitUa;
134
157
  private readonly _cancelableDisconnect;
135
158
  private readonly _cancelableSet;
136
159
  private readonly _cancelableCall;
@@ -148,7 +171,7 @@ export default class SipConnector {
148
171
  JsSIP: TJsSIP;
149
172
  });
150
173
  connect: TConnect;
151
- createUa: TCreateUa;
174
+ initUa: TInitUa;
152
175
  set: TSet;
153
176
  call: TCall;
154
177
  disconnect: TDisconnect;
@@ -160,6 +183,7 @@ export default class SipConnector {
160
183
  tryRegister: () => Promise<RegisteredEvent>;
161
184
  sendOptions(target: URI | string, body?: string, extraHeaders?: string[]): Promise<void>;
162
185
  ping(body?: string, extraHeaders?: string[]): Promise<void>;
186
+ checkTelephony({ userAgent, displayName, sipServerUrl, sipWebSocketServerURL, sdpSemantics, }: TParametersCheckTelephony): Promise<void>;
163
187
  replaceMediaStream(mediaStream: MediaStream, options?: {
164
188
  deleteExisting: boolean;
165
189
  addMissing: boolean;
@@ -225,11 +249,8 @@ export default class SipConnector {
225
249
  get isCallActive(): boolean;
226
250
  get isAvailableIncomingCall(): boolean;
227
251
  _connect: TConnect;
252
+ _initUa: TInitUa;
228
253
  _createUa: TCreateUa;
229
- _init({ sipServerUrl, sipWebSocketServerURL, }: {
230
- sipServerUrl: string;
231
- sipWebSocketServerURL: string;
232
- }): void;
233
254
  _start: TStart;
234
255
  _set: TSet;
235
256
  _disconnectWithoutCancelRequests: TDisconnect;
@@ -9,6 +9,9 @@ export declare const PASSWORD_CORRECT = "PASSWORD_CORRECT";
9
9
  export declare const PASSWORD_CORRECT_2 = "PASSWORD_CORRECT_2";
10
10
  export declare const NAME_INCORRECT = "NAME_INCORRECT";
11
11
  declare class UA implements IUA {
12
+ private static isAvailableTelephony;
13
+ static setAvailableTelephony(): void;
14
+ static setNotAvailableTelephony(): void;
12
15
  _events: Events<typeof UA_EVENT_NAMES>;
13
16
  _startedTimeout?: ReturnType<typeof setTimeout>;
14
17
  _stopedTimeout?: ReturnType<typeof setTimeout>;
@@ -32,6 +35,9 @@ declare class UA implements IUA {
32
35
  stop(): void;
33
36
  call: jest.Mock<Session, [url: string, parameters: any], any>;
34
37
  on(eventName: TEventUA, handler: any): this;
38
+ once(eventName: TEventUA, handler: any): this;
39
+ off(eventName: TEventUA, handler: any): this;
40
+ removeAllListeners(): this;
35
41
  trigger(eventName: TEventUA, data?: any): void;
36
42
  /**
37
43
  * terminateSessions
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var W=Object.defineProperty;var b=(i,e,t)=>e in i?W(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var n=(i,e,t)=>(b(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("./SipConnector-4TW1xlov.cjs"),D=require("@krivega/jssip/lib/NameAddrHeader"),k=require("@krivega/jssip/lib/URI"),L=require("node:events"),P=require("@krivega/jssip/lib/SIPMessage"),f=require("events-constructor");require("@krivega/cancelable-promise");require("debug");class R extends P.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var x=Object.defineProperty,F=(i,e,t)=>e in i?x(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,s=(i,e,t)=>(F(i,typeof e!="symbol"?e+"":e,t),t);const m="ended",U="mute",V="isolationchange",z="overconstrained",q="unmute",H=[m,U,q,V,z];class S{constructor(e,{id:t="identifier",constraints:r={}}={}){s(this,"events"),s(this,"id"),s(this,"kind"),s(this,"constraints"),s(this,"enabled"),s(this,"contentHint",""),s(this,"readyState","live"),s(this,"isolated",!1),s(this,"label",""),s(this,"muted",!1),s(this,"onended",null),s(this,"onisolationchange",null),s(this,"onmute",null),s(this,"onunmute",null),s(this,"getConstraints",()=>this.constraints),s(this,"stop",()=>{const o={...new Event(m)};this.events.trigger(m,o),this.readyState=m,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,a)=>{this.events.on(o,a)}),s(this,"removeEventListener",(o,a)=>{this.events.off(o,a)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...r},this.events=new f(H)}clone(){return{...this}}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){let e=0,t=0;return typeof this.constraints.width=="object"&&this.constraints.width.ideal!==void 0?e=this.constraints.width.ideal:typeof this.constraints.width=="object"&&this.constraints.width.exact!==void 0?e=this.constraints.width.exact:typeof this.constraints.width=="number"&&this.constraints.width&&(e=this.constraints.width),typeof this.constraints.height=="object"&&this.constraints.height.ideal!==void 0?t=this.constraints.height.ideal:typeof this.constraints.height=="object"&&this.constraints.height.exact!==void 0?t=this.constraints.height.exact:typeof this.constraints.height=="number"&&this.constraints.height&&(t=this.constraints.height),{width:e,height:t}}async applyConstraints(e){this.constraints={...e}}dispatchEvent(e){const t=e.type;return this.events.trigger(t,e),!0}}const j=i=>new S("audio",i),$=i=>new S("video",i);class B{constructor({originator:e="local",eventHandlers:t}){n(this,"originator");n(this,"_connection");n(this,"_events");n(this,"_remote_identity");n(this,"_mutedOptions",{audio:!1,video:!1});this.originator=e,this._events=new f(u.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 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(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 K{constructor(e,t){n(this,"_senders",[]);n(this,"_receivers",[]);n(this,"canTrickleIceCandidates");n(this,"connectionState");n(this,"currentLocalDescription");n(this,"currentRemoteDescription");n(this,"iceConnectionState");n(this,"iceGatheringState");n(this,"idpErrorInfo");n(this,"idpLoginUrl");n(this,"localDescription");n(this,"onconnectionstatechange");n(this,"ondatachannel");n(this,"onicecandidate");n(this,"onicecandidateerror",null);n(this,"oniceconnectionstatechange");n(this,"onicegatheringstatechange");n(this,"onnegotiationneeded");n(this,"onsignalingstatechange");n(this,"ontrack");n(this,"peerIdentity");n(this,"pendingLocalDescription");n(this,"pendingRemoteDescription");n(this,"remoteDescription");n(this,"sctp",null);n(this,"signalingState");n(this,"getReceivers",()=>this._receivers);n(this,"getSenders",()=>this._senders);n(this,"addTrack",e=>{const t={track:e};return this._senders.push(t),t});this._receivers=t.map(r=>({track:r}))}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.")}}function Y(i){const e=i.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const p=400,T="777",J=i=>i.getVideoTracks().length>0;class y extends B{constructor({url:t="",mediaStream:r,eventHandlers:o,originator:a}){super({originator:a,eventHandlers:o});n(this,"url");n(this,"status_code");n(this,"_isEnded",!1);n(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},p)}));this.url=t,this.initPeerconnection(r)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const r=j();r.id="mainaudio1";const o=[r];if(J(t)){const C=$();C.id="mainvideo1",o.push(C)}this._connection=new K(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},p)}connect(t){const r=Y(t);setTimeout(()=>{this.url.includes(T)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:u.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",r)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},p)}terminate({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t}),this._isEnded=!1,this}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}_addStream(t,r="getTracks"){t[r]().forEach(o=>this.connection.addTrack(o))}_forEachSenders(t){const r=this.connection.getSenders();for(const o of r)t(o);return r}_toggleMuteAudio(t){this._forEachSenders(({track:r})=>{r&&r.kind==="audio"&&(r.enabled=!t)})}_toggleMuteVideo(t){this._forEachSenders(({track:r})=>{r&&r.kind==="video"&&(r.enabled=!t)})}mute(t){t.audio&&(this._mutedOptions.audio=!0,this._toggleMuteAudio(this._mutedOptions.audio)),t.video&&(this._mutedOptions.video=!0,this._toggleMuteVideo(this._mutedOptions.video)),this._onmute(t)}unmute(t){t.audio&&(this._mutedOptions.audio=!1),t.video&&(this._mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this._mutedOptions}async replaceMediaStream(t){return t}_onmute({audio:t,video:r}){this.trigger("muted",{audio:t,video:r})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(t){this.trigger("newInfo",t)}}class G{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",w="PASSWORD_CORRECT_2",A="NAME_INCORRECT",c=400;class X{constructor(e){n(this,"_events");n(this,"_startedTimeout");n(this,"_stopedTimeout");n(this,"session");n(this,"_isRegistered");n(this,"_isConnected");n(this,"configuration");n(this,"_registrator");n(this,"call",jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:o}=t;return this.session=new y({url:e,mediaStream:r,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new f(u.UA_EVENT_NAMES),this.configuration=e,this._registrator=new G}start(){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")})},c):this.trigger("disconnected",{error:new Error("stoped")})}on(e,t){return this._events.on(e,t),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.includes(A)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},c)):!this._isRegistered&&t&&(e===d||e===w)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},c)):t&&e!==d&&e!==w&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},c)),this.trigger("connected"),this._isConnected=!0}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(e){this.trigger("sipEvent",e)}}class Q{constructor(e){n(this,"url");this.url=e}}class Z extends L.EventEmitter{constructor(t,r){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=r}}const E="remote",ee=(i,e)=>{const t=new R(e),r={originator:E,request:t,info:new Z("","")};i.newInfo(r)},te=(i,e)=>{const r={request:new R(e)};i.newSipEvent(r)},ne=(i,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new y({originator:E}),a=new k("sip",e,r);o._remote_identity=new D(a,t),i.trigger("newRTCSession",{originator:E,session:o})},re=(i,e)=>{e?i.trigger("failed",e):i.trigger("failed",i)},I={triggerNewInfo:ee,triggerNewSipEvent:te,triggerIncomingSession:ne,triggerFailIncomingSession:re,WebSocketInterface:Q,UA:X,C:{INVITE:"INVITE"}},l="user",h="displayName",g="SIP_SERVER_URL",M="SIP_WEB_SOCKET_SERVER_URL",ie=new I.WebSocketInterface(M),v={userAgent:"Chrome",sipServerUrl:g,sipWebSocketServerURL:M},oe={...v},O={...v,user:l,password:d,register:!0},se={...O,displayName:h},ae={...v,displayName:h,register:!1},_={session_timers:!1,sockets:[ie],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},de={..._,password:d,uri:`sip:${l}@${g}`,display_name:"",register:!0},he={..._,password:d,uri:`sip:${l}@${g}`,display_name:h,register:!0},ce={..._,display_name:h,register:!1},me={..._,display_name:"",register:!1},N="10.10.10.10",ue=[`X-Vinteo-Remote: ${N}`],le=()=>new u.SipConnector({JsSIP:I});exports.FAILED_CONFERENCE_NUMBER=T;exports.NAME_INCORRECT=A;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=w;exports.SIP_SERVER_URL=g;exports.SIP_WEB_SOCKET_SERVER_URL=M;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=se;exports.dataForConnectionWithoutAuthorization=ae;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=oe;exports.default=le;exports.displayName=h;exports.extraHeadersRemoteAddress=ue;exports.remoteAddress=N;exports.uaConfigurationWithAuthorization=de;exports.uaConfigurationWithAuthorizationWithDisplayName=he;exports.uaConfigurationWithoutAuthorization=ce;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=me;exports.user=l;
1
+ "use strict";var D=Object.defineProperty;var k=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(k(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./SipConnector-eRr2JbY9.cjs"),L=require("@krivega/jssip/lib/NameAddrHeader"),P=require("@krivega/jssip/lib/URI"),x=require("node:events"),F=require("@krivega/jssip/lib/SIPMessage"),M=require("events-constructor");class T extends F.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var V=Object.defineProperty,z=(r,e,t)=>e in r?V(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>(z(r,typeof e!="symbol"?e+"":e,t),t);const m="ended",U="mute",H="isolationchange",q="overconstrained",j="unmute",$=[m,U,j,H,q];class y{constructor(e,{id:t="identifier",constraints:i={}}={}){s(this,"events"),s(this,"id"),s(this,"kind"),s(this,"constraints"),s(this,"enabled"),s(this,"contentHint",""),s(this,"readyState","live"),s(this,"isolated",!1),s(this,"label",""),s(this,"muted",!1),s(this,"onended",null),s(this,"onisolationchange",null),s(this,"onmute",null),s(this,"onunmute",null),s(this,"getConstraints",()=>this.constraints),s(this,"stop",()=>{const o={...new Event(m)};this.events.trigger(m,o),this.readyState=m,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,a)=>{this.events.on(o,a)}),s(this,"removeEventListener",(o,a)=>{this.events.off(o,a)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...i},this.events=new M($)}clone(){return{...this}}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){let e=0,t=0;return typeof this.constraints.width=="object"&&this.constraints.width.ideal!==void 0?e=this.constraints.width.ideal:typeof this.constraints.width=="object"&&this.constraints.width.exact!==void 0?e=this.constraints.width.exact:typeof this.constraints.width=="number"&&this.constraints.width&&(e=this.constraints.width),typeof this.constraints.height=="object"&&this.constraints.height.ideal!==void 0?t=this.constraints.height.ideal:typeof this.constraints.height=="object"&&this.constraints.height.exact!==void 0?t=this.constraints.height.exact:typeof this.constraints.height=="number"&&this.constraints.height&&(t=this.constraints.height),{width:e,height:t}}async applyConstraints(e){this.constraints={...e}}dispatchEvent(e){const t=e.type;return this.events.trigger(t,e),!0}}const B=r=>new y("audio",r),K=r=>new y("video",r);class Y{constructor({originator:e="local",eventHandlers:t}){n(this,"originator");n(this,"_connection");n(this,"_events");n(this,"_remote_identity");n(this,"_mutedOptions",{audio:!1,video:!1});this.originator=e,this._events=new M(l.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 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(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,i){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,i])=>this.on(t,i))}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 J{constructor(e,t){n(this,"_senders",[]);n(this,"_receivers",[]);n(this,"canTrickleIceCandidates");n(this,"connectionState");n(this,"currentLocalDescription");n(this,"currentRemoteDescription");n(this,"iceConnectionState");n(this,"iceGatheringState");n(this,"idpErrorInfo");n(this,"idpLoginUrl");n(this,"localDescription");n(this,"onconnectionstatechange");n(this,"ondatachannel");n(this,"onicecandidate");n(this,"onicecandidateerror",null);n(this,"oniceconnectionstatechange");n(this,"onicegatheringstatechange");n(this,"onnegotiationneeded");n(this,"onsignalingstatechange");n(this,"ontrack");n(this,"peerIdentity");n(this,"pendingLocalDescription");n(this,"pendingRemoteDescription");n(this,"remoteDescription");n(this,"sctp",null);n(this,"signalingState");n(this,"getReceivers",()=>this._receivers);n(this,"getSenders",()=>this._senders);n(this,"addTrack",e=>{const t={track:e};return this._senders.push(t),t});this._receivers=t.map(i=>({track:i}))}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,i){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,i){throw new Error("Method not implemented.")}removeEventListener(e,t,i){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function G(r){const e=r.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const w=400,A="777",X=r=>r.getVideoTracks().length>0;class b extends Y{constructor({url:t="",mediaStream:i,eventHandlers:o,originator:a}){super({originator:a,eventHandlers:o});n(this,"url");n(this,"status_code");n(this,"_isEnded",!1);n(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},w)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=B();i.id="mainaudio1";const o=[i];if(X(t)){const S=K();S.id="mainvideo1",o.push(S)}this._connection=new J(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(t){const i=G(t);setTimeout(()=>{this.url.includes(A)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:l.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",i)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},w)}terminate({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t}),this._isEnded=!1,this}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}_addStream(t,i="getTracks"){t[i]().forEach(o=>this.connection.addTrack(o))}_forEachSenders(t){const i=this.connection.getSenders();for(const o of i)t(o);return i}_toggleMuteAudio(t){this._forEachSenders(({track:i})=>{i&&i.kind==="audio"&&(i.enabled=!t)})}_toggleMuteVideo(t){this._forEachSenders(({track:i})=>{i&&i.kind==="video"&&(i.enabled=!t)})}mute(t){t.audio&&(this._mutedOptions.audio=!0,this._toggleMuteAudio(this._mutedOptions.audio)),t.video&&(this._mutedOptions.video=!0,this._toggleMuteVideo(this._mutedOptions.video)),this._onmute(t)}unmute(t){t.audio&&(this._mutedOptions.audio=!1),t.video&&(this._mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this._mutedOptions}async replaceMediaStream(t){return t}_onmute({audio:t,video:i}){this.trigger("muted",{audio:t,video:i})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(t){this.trigger("newInfo",t)}}class Q{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",E="PASSWORD_CORRECT_2",I="NAME_INCORRECT",c=400,u=class u{constructor(e){n(this,"_events");n(this,"_startedTimeout");n(this,"_stopedTimeout");n(this,"session");n(this,"_isRegistered");n(this,"_isConnected");n(this,"configuration");n(this,"_registrator");n(this,"call",jest.fn((e,t)=>{const{mediaStream:i,eventHandlers:o}=t;return this.session=new b({url:e,mediaStream:i,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new M(l.UA_EVENT_NAMES),this.configuration=e,this._registrator=new Q}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){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")})},c):this.trigger("disconnected",{error:new Error("stoped")})}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:i}=this.configuration;t&&i.includes(I)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},c)):!this._isRegistered&&t&&(e===d||e===E)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},c)):t&&e!==d&&e!==E&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},c)),u.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(e){this.trigger("sipEvent",e)}};n(u,"isAvailableTelephony",!0);let f=u;class Z{constructor(e){n(this,"url");this.url=e}}class ee extends x.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const v="remote",te=(r,e)=>{const t=new T(e),i={originator:v,request:t,info:new ee("","")};r.newInfo(i)},ne=(r,e)=>{const i={request:new T(e)};r.newSipEvent(i)},ie=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:v}),a=new P("sip",e,i);o._remote_identity=new L(a,t),r.trigger("newRTCSession",{originator:v,session:o})},re=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},O={triggerNewInfo:te,triggerNewSipEvent:ne,triggerIncomingSession:ie,triggerFailIncomingSession:re,WebSocketInterface:Z,UA:f,C:{INVITE:"INVITE"}},g="user",h="displayName",_="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",oe=new O.WebSocketInterface(C),R={userAgent:"Chrome",sipServerUrl:_,sipWebSocketServerURL:C},se={...R},N={...R,user:g,password:d,register:!0},ae={...N,displayName:h},de={...R,displayName:h,register:!1},p={session_timers:!1,sockets:[oe],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},he={...p,password:d,uri:`sip:${g}@${_}`,display_name:"",register:!0},ce={...p,password:d,uri:`sip:${g}@${_}`,display_name:h,register:!0},me={...p,display_name:h,register:!1},ue={...p,display_name:"",register:!1},W="10.10.10.10",le=[`X-Vinteo-Remote: ${W}`],ge=()=>new l.SipConnector({JsSIP:O});exports.FAILED_CONFERENCE_NUMBER=A;exports.NAME_INCORRECT=I;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=E;exports.SIP_SERVER_URL=_;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=N;exports.dataForConnectionWithAuthorizationWithDisplayName=ae;exports.dataForConnectionWithoutAuthorization=de;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=se;exports.default=ge;exports.displayName=h;exports.extraHeadersRemoteAddress=le;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=he;exports.uaConfigurationWithAuthorizationWithDisplayName=ce;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ue;exports.user=g;
package/dist/doMock.js CHANGED
@@ -1,15 +1,13 @@
1
- var y = Object.defineProperty;
2
- var I = (i, e, t) => e in i ? y(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var n = (i, e, t) => (I(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { j as b, R as O, U as k, S as A } from "./SipConnector-Hg44qtgr.js";
5
- import N from "@krivega/jssip/lib/NameAddrHeader";
6
- import L from "@krivega/jssip/lib/URI";
7
- import { EventEmitter as D } from "node:events";
8
- import { IncomingRequest as W } from "@krivega/jssip/lib/SIPMessage";
9
- import _ from "events-constructor";
10
- import "@krivega/cancelable-promise";
11
- import "debug";
12
- class M extends W {
1
+ var I = Object.defineProperty;
2
+ var A = (i, e, t) => e in i ? I(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var n = (i, e, t) => (A(i, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { j as O, R as k, U as N, S as L } from "./SipConnector-1HoiCnsj.js";
5
+ import D from "@krivega/jssip/lib/NameAddrHeader";
6
+ import W from "@krivega/jssip/lib/URI";
7
+ import { EventEmitter as P } from "node:events";
8
+ import { IncomingRequest as x } from "@krivega/jssip/lib/SIPMessage";
9
+ import w from "events-constructor";
10
+ class y extends x {
13
11
  constructor(t) {
14
12
  super();
15
13
  n(this, "headers");
@@ -19,8 +17,8 @@ class M extends W {
19
17
  return this.headers.get(t) || "";
20
18
  }
21
19
  }
22
- var P = Object.defineProperty, x = (i, e, t) => e in i ? P(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, s = (i, e, t) => (x(i, typeof e != "symbol" ? e + "" : e, t), t);
23
- const c = "ended", U = "mute", V = "isolationchange", F = "overconstrained", j = "unmute", H = [c, U, j, V, F];
20
+ var V = Object.defineProperty, F = (i, e, t) => e in i ? V(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, s = (i, e, t) => (F(i, typeof e != "symbol" ? e + "" : e, t), t);
21
+ const c = "ended", H = "mute", U = "isolationchange", j = "overconstrained", z = "unmute", $ = [c, H, z, U, j];
24
22
  class R {
25
23
  constructor(e, { id: t = "identifier", constraints: r = {} } = {}) {
26
24
  s(this, "events"), s(this, "id"), s(this, "kind"), s(this, "constraints"), s(this, "enabled"), s(this, "contentHint", ""), s(this, "readyState", "live"), s(this, "isolated", !1), s(this, "label", ""), s(this, "muted", !1), s(this, "onended", null), s(this, "onisolationchange", null), s(this, "onmute", null), s(this, "onunmute", null), s(this, "getConstraints", () => this.constraints), s(this, "stop", () => {
@@ -30,7 +28,7 @@ class R {
30
28
  this.events.on(o, a);
31
29
  }), s(this, "removeEventListener", (o, a) => {
32
30
  this.events.off(o, a);
33
- }), this.id = `${t}-${e}-track`, this.kind = e, this.enabled = !0, this.constraints = { ...r }, this.events = new _(H);
31
+ }), this.id = `${t}-${e}-track`, this.kind = e, this.enabled = !0, this.constraints = { ...r }, this.events = new w($);
34
32
  }
35
33
  clone() {
36
34
  return { ...this };
@@ -56,8 +54,8 @@ class R {
56
54
  return this.events.trigger(t, e), !0;
57
55
  }
58
56
  }
59
- const z = (i) => new R("audio", i), $ = (i) => new R("video", i);
60
- class q {
57
+ const q = (i) => new R("audio", i), B = (i) => new R("video", i);
58
+ class K {
61
59
  // @ts-expect-error
62
60
  constructor({ originator: e = "local", eventHandlers: t }) {
63
61
  n(this, "originator");
@@ -65,7 +63,7 @@ class q {
65
63
  n(this, "_events");
66
64
  n(this, "_remote_identity");
67
65
  n(this, "_mutedOptions", { audio: !1, video: !1 });
68
- this.originator = e, this._events = new _(b), this.initEvents(t);
66
+ this.originator = e, this._events = new w(O), this.initEvents(t);
69
67
  }
70
68
  // @ts-expect-error
71
69
  get C() {
@@ -238,7 +236,7 @@ class q {
238
236
  return !0;
239
237
  }
240
238
  }
241
- class B {
239
+ class Y {
242
240
  constructor(e, t) {
243
241
  n(this, "_senders", []);
244
242
  n(this, "_receivers", []);
@@ -332,14 +330,14 @@ class B {
332
330
  throw new Error("Method not implemented.");
333
331
  }
334
332
  }
335
- function K(i) {
333
+ function J(i) {
336
334
  const e = i.match(/[\d.]+/g);
337
335
  if (!e)
338
336
  throw new Error("wrong sip url");
339
337
  return e[0];
340
338
  }
341
- const u = 400, Y = "777", J = (i) => i.getVideoTracks().length > 0;
342
- class T extends q {
339
+ const g = 400, G = "777", X = (i) => i.getVideoTracks().length > 0;
340
+ class S extends K {
343
341
  constructor({
344
342
  url: t = "",
345
343
  mediaStream: r,
@@ -368,7 +366,7 @@ class T extends q {
368
366
  }, 100), setTimeout(() => {
369
367
  this.trigger("confirmed");
370
368
  }, 200);
371
- }, u);
369
+ }, g);
372
370
  }));
373
371
  this.url = t, this.initPeerconnection(r);
374
372
  }
@@ -376,24 +374,24 @@ class T extends q {
376
374
  return t ? (this.createPeerconnection(t), !0) : !1;
377
375
  }
378
376
  createPeerconnection(t) {
379
- const r = z();
377
+ const r = q();
380
378
  r.id = "mainaudio1";
381
379
  const o = [r];
382
- if (J(t)) {
383
- const f = $();
384
- f.id = "mainvideo1", o.push(f);
380
+ if (X(t)) {
381
+ const M = B();
382
+ M.id = "mainvideo1", o.push(M);
385
383
  }
386
- this._connection = new B(void 0, o), this._addStream(t), setTimeout(() => {
384
+ this._connection = new Y(void 0, o), this._addStream(t), setTimeout(() => {
387
385
  this.trigger("peerconnection", { peerconnection: this.connection });
388
- }, u);
386
+ }, g);
389
387
  }
390
388
  connect(t) {
391
- const r = K(t);
389
+ const r = J(t);
392
390
  setTimeout(() => {
393
- this.url.includes(Y) ? this.trigger("failed", {
391
+ this.url.includes(G) ? this.trigger("failed", {
394
392
  originator: "remote",
395
393
  message: "IncomingResponse",
396
- cause: O
394
+ cause: k
397
395
  }) : (this.trigger("connecting"), setTimeout(() => {
398
396
  this.trigger("enterRoom", r);
399
397
  }, 100), setTimeout(() => {
@@ -401,7 +399,7 @@ class T extends q {
401
399
  }, 200), setTimeout(() => {
402
400
  this.trigger("confirmed");
403
401
  }, 300));
404
- }, u);
402
+ }, g);
405
403
  }
406
404
  terminate({ status_code: t } = {}) {
407
405
  return this.status_code = t, this.trigger("ended", { status_code: t }), this._isEnded = !1, this;
@@ -459,7 +457,7 @@ class T extends q {
459
457
  }
460
458
  /* eslint-enable no-param-reassign */
461
459
  }
462
- class G {
460
+ class Q {
463
461
  constructor() {
464
462
  n(this, "extraHeaders");
465
463
  }
@@ -469,8 +467,7 @@ class G {
469
467
  setExtraContactParams() {
470
468
  }
471
469
  }
472
- const d = "PASSWORD_CORRECT", v = "PASSWORD_CORRECT_2", X = "NAME_INCORRECT", h = 400;
473
- class Q {
470
+ const d = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", Z = "NAME_INCORRECT", h = 400, m = class m {
474
471
  constructor(e) {
475
472
  n(this, "_events");
476
473
  n(this, "_startedTimeout");
@@ -483,9 +480,15 @@ class Q {
483
480
  // @ts-expect-error
484
481
  n(this, "call", jest.fn((e, t) => {
485
482
  const { mediaStream: r, eventHandlers: o } = t;
486
- return this.session = new T({ url: e, mediaStream: r, eventHandlers: o, originator: "local" }), this.session.connect(e), this.session;
483
+ return this.session = new S({ url: e, mediaStream: r, eventHandlers: o, originator: "local" }), this.session.connect(e), this.session;
487
484
  }));
488
- this._events = new _(k), this.configuration = e, this._registrator = new G();
485
+ this._events = new w(N), this.configuration = e, this._registrator = new Q();
486
+ }
487
+ static setAvailableTelephony() {
488
+ this.isAvailableTelephony = !0;
489
+ }
490
+ static setNotAvailableTelephony() {
491
+ this.isAvailableTelephony = !1;
489
492
  }
490
493
  /**
491
494
  * start
@@ -509,6 +512,17 @@ class Q {
509
512
  on(e, t) {
510
513
  return this._events.on(e, t), this;
511
514
  }
515
+ // @ts-expect-error
516
+ once(e, t) {
517
+ return this._events.once(e, t), this;
518
+ }
519
+ // @ts-expect-error
520
+ off(e, t) {
521
+ return this._events.off(e, t), this;
522
+ }
523
+ removeAllListeners() {
524
+ return this._events.removeEventHandlers(), this;
525
+ }
512
526
  trigger(e, t) {
513
527
  this._events.trigger(e, t);
514
528
  }
@@ -539,13 +553,13 @@ class Q {
539
553
  register() {
540
554
  this._startedTimeout && clearTimeout(this._startedTimeout);
541
555
  const { password: e, register: t, uri: r } = this.configuration;
542
- t && r.includes(X) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
556
+ t && r.includes(Z) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
543
557
  this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
544
- }, h)) : !this._isRegistered && t && (e === d || e === v) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
558
+ }, h)) : !this._isRegistered && t && (e === d || e === T) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
545
559
  this.trigger("registered");
546
- }, h)) : t && e !== d && e !== v && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
560
+ }, h)) : t && e !== d && e !== T && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
547
561
  this.trigger("registrationFailed", { response: null, cause: "Wrong credentials" });
548
- }, h)), this.trigger("connected"), this._isConnected = !0;
562
+ }, h)), m.isAvailableTelephony ? (this.trigger("connected"), this._isConnected = !0) : this.stop();
549
563
  }
550
564
  /**
551
565
  * unregister
@@ -577,14 +591,16 @@ class Q {
577
591
  newSipEvent(e) {
578
592
  this.trigger("sipEvent", e);
579
593
  }
580
- }
581
- class Z {
594
+ };
595
+ n(m, "isAvailableTelephony", !0);
596
+ let p = m;
597
+ class ee {
582
598
  constructor(e) {
583
599
  n(this, "url");
584
600
  this.url = e;
585
601
  }
586
602
  }
587
- class ee extends D {
603
+ class te extends P {
588
604
  constructor(t, r) {
589
605
  super();
590
606
  n(this, "contentType");
@@ -592,102 +608,102 @@ class ee extends D {
592
608
  this.contentType = t, this.body = r;
593
609
  }
594
610
  }
595
- const g = "remote", te = (i, e) => {
596
- const t = new M(e), r = {
597
- originator: g,
611
+ const _ = "remote", ne = (i, e) => {
612
+ const t = new y(e), r = {
613
+ originator: _,
598
614
  request: t,
599
- info: new ee("", "")
615
+ info: new te("", "")
600
616
  };
601
617
  i.newInfo(r);
602
- }, ne = (i, e) => {
603
- const r = { request: new M(e) };
618
+ }, re = (i, e) => {
619
+ const r = { request: new y(e) };
604
620
  i.newSipEvent(r);
605
- }, re = (i, {
621
+ }, ie = (i, {
606
622
  incomingNumber: e = "1234",
607
623
  displayName: t,
608
624
  host: r
609
625
  }) => {
610
- const o = new T({ originator: g }), a = new L("sip", e, r);
611
- o._remote_identity = new N(a, t), i.trigger("newRTCSession", { originator: g, session: o });
612
- }, ie = (i, e) => {
626
+ const o = new S({ originator: _ }), a = new W("sip", e, r);
627
+ o._remote_identity = new D(a, t), i.trigger("newRTCSession", { originator: _, session: o });
628
+ }, oe = (i, e) => {
613
629
  e ? i.trigger("failed", e) : i.trigger("failed", i);
614
- }, S = {
615
- triggerNewInfo: te,
616
- triggerNewSipEvent: ne,
617
- triggerIncomingSession: re,
618
- triggerFailIncomingSession: ie,
619
- WebSocketInterface: Z,
620
- UA: Q,
630
+ }, C = {
631
+ triggerNewInfo: ne,
632
+ triggerNewSipEvent: re,
633
+ triggerIncomingSession: ie,
634
+ triggerFailIncomingSession: oe,
635
+ WebSocketInterface: ee,
636
+ UA: p,
621
637
  C: {
622
638
  INVITE: "INVITE"
623
639
  }
624
- }, p = "user", m = "displayName", w = "SIP_SERVER_URL", C = "SIP_WEB_SOCKET_SERVER_URL", oe = new S.WebSocketInterface(C), E = {
640
+ }, E = "user", l = "displayName", f = "SIP_SERVER_URL", b = "SIP_WEB_SOCKET_SERVER_URL", se = new C.WebSocketInterface(b), v = {
625
641
  userAgent: "Chrome",
626
- sipServerUrl: w,
627
- sipWebSocketServerURL: C
628
- }, we = {
629
- ...E
630
- }, se = {
631
- ...E,
632
- user: p,
642
+ sipServerUrl: f,
643
+ sipWebSocketServerURL: b
644
+ }, _e = {
645
+ ...v
646
+ }, ae = {
647
+ ...v,
648
+ user: E,
633
649
  password: d,
634
650
  register: !0
651
+ }, we = {
652
+ ...ae,
653
+ displayName: l
635
654
  }, Ee = {
636
- ...se,
637
- displayName: m
638
- }, fe = {
639
- ...E,
640
- displayName: m,
655
+ ...v,
656
+ displayName: l,
641
657
  register: !1
642
- }, l = {
658
+ }, u = {
643
659
  session_timers: !1,
644
- sockets: [oe],
660
+ sockets: [se],
645
661
  user_agent: "Chrome",
646
662
  sdp_semantics: "plan-b",
647
663
  register_expires: 300,
648
664
  connection_recovery_max_interval: 6,
649
665
  connection_recovery_min_interval: 2
650
- }, ve = {
651
- ...l,
666
+ }, fe = {
667
+ ...u,
652
668
  password: d,
653
- uri: `sip:${p}@${w}`,
669
+ uri: `sip:${E}@${f}`,
654
670
  display_name: "",
655
671
  register: !0
656
- }, Me = {
657
- ...l,
672
+ }, ve = {
673
+ ...u,
658
674
  password: d,
659
- uri: `sip:${p}@${w}`,
660
- display_name: m,
675
+ uri: `sip:${E}@${f}`,
676
+ display_name: l,
661
677
  register: !0
662
- }, Re = {
663
- ...l,
664
- display_name: m,
678
+ }, Me = {
679
+ ...u,
680
+ display_name: l,
665
681
  register: !1
666
682
  }, Te = {
667
- ...l,
683
+ ...u,
668
684
  display_name: "",
669
685
  register: !1
670
- }, ae = "10.10.10.10", Se = [`X-Vinteo-Remote: ${ae}`], Ce = () => new A({
671
- JsSIP: S
686
+ }, de = "10.10.10.10", ye = [`X-Vinteo-Remote: ${de}`], Re = () => new L({
687
+ JsSIP: C
672
688
  });
673
689
  export {
674
- Y as FAILED_CONFERENCE_NUMBER,
675
- X as NAME_INCORRECT,
690
+ G as FAILED_CONFERENCE_NUMBER,
691
+ Z as NAME_INCORRECT,
676
692
  d as PASSWORD_CORRECT,
677
- v as PASSWORD_CORRECT_2,
678
- w as SIP_SERVER_URL,
679
- C as SIP_WEB_SOCKET_SERVER_URL,
680
- se as dataForConnectionWithAuthorization,
681
- Ee as dataForConnectionWithAuthorizationWithDisplayName,
682
- fe as dataForConnectionWithoutAuthorization,
683
- we as dataForConnectionWithoutAuthorizationWithoutDisplayName,
684
- Ce as default,
685
- m as displayName,
686
- Se as extraHeadersRemoteAddress,
687
- ae as remoteAddress,
688
- ve as uaConfigurationWithAuthorization,
689
- Me as uaConfigurationWithAuthorizationWithDisplayName,
690
- Re as uaConfigurationWithoutAuthorization,
693
+ T as PASSWORD_CORRECT_2,
694
+ f as SIP_SERVER_URL,
695
+ b as SIP_WEB_SOCKET_SERVER_URL,
696
+ ae as dataForConnectionWithAuthorization,
697
+ we as dataForConnectionWithAuthorizationWithDisplayName,
698
+ Ee as dataForConnectionWithoutAuthorization,
699
+ _e as dataForConnectionWithoutAuthorizationWithoutDisplayName,
700
+ Re as default,
701
+ l as displayName,
702
+ ye as extraHeadersRemoteAddress,
703
+ de as remoteAddress,
704
+ fe as uaConfigurationWithAuthorization,
705
+ ve as uaConfigurationWithAuthorizationWithDisplayName,
706
+ Me as uaConfigurationWithoutAuthorization,
691
707
  Te as uaConfigurationWithoutAuthorizationWithoutDisplayName,
692
- p as user
708
+ E as user
693
709
  };