sip-connector 19.8.3 → 19.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("node:events"),U=require("@krivega/jssip/lib/NameAddrHeader"),H=require("@krivega/jssip/lib/URI"),q=require("@krivega/jssip/lib/SIPMessage"),a=require("@krivega/jssip"),f=require("webrtc-mock"),S=require("events-constructor"),D=require("./@SipConnector-BHakZWEK.cjs");class N extends q.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const G="incomingCall",x="declinedIncomingCall",z="failedIncomingCall",Y="terminatedIncomingCall",y="connecting",j="connected",B="disconnected",K="newRTCSession",J="registered",$="unregistered",Q="registrationFailed",X="newMessage",Z="sipEvent",ee="availableSecondRemoteStream",te="notAvailableSecondRemoteStream",re="mustStopPresentation",ne="shareState",oe="enterRoom",ie="useLicense",se="peerconnection:confirmed",ae="peerconnection:ontrack",ce="channels",de="channels:notify",Ee="ended:fromserver",he="main-cam-control",ue="admin-stop-main-cam",me="admin-start-main-cam",le="admin-stop-mic",pe="admin-start-mic",ge="admin-force-sync-media-state",_e="participant:added-to-list-moderators",Te="participant:removed-from-list-moderators",Ie="participant:move-request-to-stream",Se="participant:move-request-to-spectators",Ne="participant:move-request-to-participants",we="participation:accepting-word-request",Ce="participation:cancelling-word-request",Re="webcast:started",fe="webcast:stopped",Ae="account:changed",Me="account:deleted",Oe="conference:participant-token-issued",Pe="ended",ve="sending",De="reinvite",ye="replaces",Le="refer",Fe="progress",We="accepted",be="confirmed",ke="peerconnection",Ve="failed",Ue="muted",He="unmuted",qe="newDTMF",Ge="newInfo",xe="hold",ze="unhold",Ye="update",je="sdp",Be="icecandidate",Ke="getusermediafailed",Je="peerconnection:createofferfailed",$e="peerconnection:createanswerfailed",Qe="peerconnection:setlocaldescriptionfailed",Xe="peerconnection:setremotedescriptionfailed",Ze="presentation:start",et="presentation:started",tt="presentation:end",rt="presentation:ended",nt="presentation:failed",ot=[G,x,Y,z,we,Ce,Ie,de,Oe,Ae,Me,Re,fe,_e,Te],L=[y,j,B,K,J,$,Q,X,Z],it=[ee,te,re,ne,oe,ie,se,ae,ce,Ee,he,me,ue,le,pe,ge,Se,Ne],_=[Pe,y,ve,De,ye,Le,Fe,We,be,ke,Ve,Ue,He,qe,Ge,xe,ze,Ye,je,Be,Ke,Je,$e,Qe,Xe,Ze,et,tt,rt,nt];[...L,...ot];[..._,...it];class st{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new S.Events(_),this.initEvents(t),this.remote_identity=r}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.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){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){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}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){e&&Object.entries(e).forEach(([t,r])=>{this.on(t,r)})}on(e,t){return _.includes(e)&&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 this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class A{stats=new Map().set("codec",{mimeType:"video/h264"});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(){return this.stats}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 M{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}const at=["track"];class ct{senders=[];receivers=[];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;events;constructor(e,t){this.events=new S.Events(at),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){this.events.on(e,t)}removeEventListener(e,t,r){this.events.off(e,t)}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new A({track:e}),n=new M(r);return n.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r};addTrackWithMid=(e,t)=>{const r=new A({track:e}),n=new M(r);return t===void 0?n.mid=e.kind==="audio"?"0":"1":n.mid=t,this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r}}function dt(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const O=400,F="777",Et=o=>o.getVideoTracks().length>0;class s extends st{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;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)},O)});replaceMediaStream=jest.fn(async e=>{});_isReadyToReOffer=jest.fn(()=>!0);addTransceiver=jest.fn((e,t)=>({}));restartIce=jest.fn(async e=>!0);isEndedInner=!1;delayStartPresentation=0;timeoutStartPresentation;timeoutConnect;timeoutNewInfo;timeoutAccepted;timeoutConfirmed;constructor({eventHandlers:e,originator:t,remoteIdentity:r=new a.NameAddrHeader(new a.URI("sip","caller1","test1.com",5060),"Test Caller 1"),delayStartPresentation:n=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=n}static get C(){return a.SessionStatus}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}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}startPresentation=async e=>(s.countStartsPresentation+=1,new Promise((t,r)=>{this.timeoutStartPresentation=setTimeout(()=>{if(s.presentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.presentationError);return}if(s.startPresentationError&&s.countStartsPresentation<s.countStartPresentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.startPresentationError);return}t(super.startPresentation(e))},this.delayStartPresentation)}));stopPresentation=async e=>{if(s.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),s.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=f.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(Et(e)){const c=f.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new ct(void 0,r),this.addStream(e),this.trigger("peerconnection",{peerconnection:this.connection})}connect(e,{mediaStream:t}={}){const r=dt(e);return this.initPeerconnection(t),this.timeoutConnect=setTimeout(()=>{e.includes(F)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),this.timeoutNewInfo=setTimeout(()=>{this.newInfo({originator:D.Originator.REMOTE,request:{getHeader:n=>n==="content-type"?"application/vinteo.webrtc.roomname":n==="x-webrtc-enter-room"?r:n==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},O),this.connection}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?.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track: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}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}clear(){clearTimeout(this.timeoutStartPresentation),clearTimeout(this.timeoutConnect),clearTimeout(this.timeoutNewInfo),clearTimeout(this.timeoutAccepted),clearTimeout(this.timeoutConfirmed)}}class ht{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",T="PASSWORD_CORRECT_2",W="NAME_INCORRECT",h=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},P={status_code:200,reason_phrase:"OK"},v={status_code:401,reason_phrase:"Unauthorized"};class i{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:n}=t;return this.session=new s({eventHandlers:n,originator:"local"}),this.session.connect(e,{mediaStream:r}),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(i.countStarts+=1,i.startError&&i.countStarts<i.countStartError){this.trigger("disconnected",i.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:g})},h):this.trigger("disconnected",{error:!0,socket:g})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;constructor(e){this.events=new S.Events(L);const[t,r]=e.uri.split(":"),[n,c]=r.split("@"),p={...e,uri:new a.URI(t,n,c)};this.configuration=p,this.registratorInner=new ht}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){i.startError=e,i.countStartError=t}static resetStartError(){i.startError=void 0,i.countStartError=Number.POSITIVE_INFINITY,i.countStarts=0}static setAvailableTelephony(){i.isAvailableTelephony=!0}static setNotAvailableTelephony(){i.isAvailableTelephony=!1}static reset(){i.resetStartError(),i.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}off(e,t){return this.events.off(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===!0&&r.user.includes(W)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:v,cause:a.C.causes.REJECTED})},h)):!this.isRegistered()&&t===!0&&(e===d||e===T)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:P})},h)):t===!0&&e!==d&&e!==T&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:v,cause:a.C.causes.REJECTED})},h)),i.isAvailableTelephony?(this.trigger("connected",{socket:g}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:P})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}}class ut{url;constructor(e){this.url=e}}class mt extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const I="remote",lt=(o,e)=>{const t=new N(e),r={originator:I,request:t,info:new mt("","")};o.newInfo(r)},pt=(o,e)=>{const r={event:"sipEvent",request:new N(e)};o.newSipEvent(r)},gt=(o,{incomingNumber:e="1234",displayName:t,host:r})=>{const n=new s({originator:I,eventHandlers:{}}),c=new H("sip",e,r);n.remote_identity=new U(c,t);const p=new N([]);o.trigger("newRTCSession",{originator:I,session:n,request:p})},_t=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},w={triggerNewInfo:lt,triggerNewSipEvent:pt,triggerIncomingSession:gt,triggerFailIncomingSession:_t,WebSocketInterface:ut,UA:i,C:{INVITE:"INVITE"}},u="user",E="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",Tt=new w.WebSocketInterface(C),R={displayName:"DISPLAY_NAME",userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:C},It={...R,displayName:"DISPLAY_NAME",register:!1},b={...R,user:u,password:d,register:!0},St={...b,displayName:E},Nt={...R,displayName:E,register:!1},l={session_timers:!1,sockets:[Tt],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},wt={...l,password:d,uri:new a.URI("sip",u,m),display_name:"DISPLAY_NAME",register:!0},Ct={...l,password:d,uri:new a.URI("sip",u,m),display_name:E,register:!0},Rt={...l,display_name:E,register:!1},ft={...l,display_name:"DISPLAY_NAME",register:!1},k="10.10.10.10",At=[`X-Vinteo-Remote: ${k}`],Mt=()=>new D.SipConnector({JsSIP:w});exports.FAILED_CONFERENCE_NUMBER=F;exports.JsSIP=w;exports.NAME_INCORRECT=W;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=T;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=St;exports.dataForConnectionWithoutAuthorization=Nt;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=It;exports.displayName=E;exports.doMockSipConnector=Mt;exports.extraHeadersRemoteAddress=At;exports.remoteAddress=k;exports.uaConfigurationWithAuthorization=wt;exports.uaConfigurationWithAuthorizationWithDisplayName=Ct;exports.uaConfigurationWithoutAuthorization=Rt;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ft;exports.user=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("node:events"),U=require("@krivega/jssip/lib/NameAddrHeader"),j=require("@krivega/jssip/lib/URI"),H=require("@krivega/jssip/lib/SIPMessage"),a=require("@krivega/jssip"),_=require("webrtc-mock"),v=require("events-constructor"),D=require("./@SipConnector-CR3DyIpB.cjs");class N extends H.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const q="incomingCall",G="declinedIncomingCall",x="failedIncomingCall",z="terminatedIncomingCall",y="connecting",Y="connected",B="disconnected",K="newRTCSession",J="registered",Q="unregistered",$="registrationFailed",X="newMessage",Z="sipEvent",ee="availableSecondRemoteStream",te="notAvailableSecondRemoteStream",re="mustStopPresentation",ne="shareState",oe="enterRoom",ie="useLicense",se="peerconnection:confirmed",ae="peerconnection:ontrack",ce="channels",de="channels:notify",Ee="ended:fromserver",he="main-cam-control",ue="admin-stop-main-cam",me="admin-start-main-cam",le="admin-stop-mic",pe="admin-start-mic",ge="admin-force-sync-media-state",_e="participant:added-to-list-moderators",Te="participant:removed-from-list-moderators",Ie="participant:move-request-to-stream",Se="participant:move-request-to-spectators",Ne="participant:move-request-to-participants",we="participation:accepting-word-request",Ce="participation:cancelling-word-request",fe="webcast:started",Re="webcast:stopped",Ae="account:changed",Me="account:deleted",Oe="conference:participant-token-issued",Pe="ended",ve="sending",De="reinvite",ye="replaces",Le="refer",Fe="progress",ke="accepted",We="confirmed",be="peerconnection",Ve="failed",Ue="muted",je="unmuted",He="newDTMF",qe="newInfo",Ge="hold",xe="unhold",ze="update",Ye="sdp",Be="icecandidate",Ke="getusermediafailed",Je="peerconnection:createofferfailed",Qe="peerconnection:createanswerfailed",$e="peerconnection:setlocaldescriptionfailed",Xe="peerconnection:setremotedescriptionfailed",Ze="presentation:start",et="presentation:started",tt="presentation:end",rt="presentation:ended",nt="presentation:failed",ot=[q,G,z,x,we,Ce,Ie,de,Oe,Ae,Me,fe,Re,_e,Te],L=[y,Y,B,K,J,Q,$,X,Z],it=[ee,te,re,ne,oe,ie,se,ae,ce,Ee,he,me,ue,le,pe,ge,Se,Ne],T=[Pe,y,ve,De,ye,Le,Fe,ke,We,be,Ve,Ue,je,He,qe,Ge,xe,ze,Ye,Be,Ke,Je,Qe,$e,Xe,Ze,et,tt,rt,nt];[...L,...ot];[...T,...it];class st{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new v.Events(T),this.initEvents(t),this.remote_identity=r}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.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){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){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}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){e&&Object.entries(e).forEach(([t,r])=>{this.on(t,r)})}on(e,t){return T.includes(e)&&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 this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class R{stats=new Map().set("codec",{mimeType:"video/h264"});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(){return this.stats}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 A{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}class at extends EventTarget{senders=[];receivers=[];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;close=jest.fn();setLocalDescription=jest.fn(async e=>{});setRemoteDescription=jest.fn(async e=>{});addTransceiver=jest.fn((e,t)=>({}));createOffer=jest.fn(async(e,t,r)=>({type:"offer",sdp:"offer-sdp"}));constructor(e,t){super(),this.receivers=t?.map(r=>({track:r}))??[]}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){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.")}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.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new R({track:e}),o=new A(r);return o.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.dispatchTrackInternal(e),r};addTrackWithMid=(e,t)=>{const r=new R({track:e}),o=new A(r);return t===void 0?o.mid=e.kind==="audio"?"0":"1":o.mid=t,this.senders.push(r),this.dispatchTrackInternal(e),r};dispatchTrack(e){this.dispatchTrackInternal(new _.MediaStreamTrackMock(e))}dispatchTrackInternal(e){const t=new Event("track");Object.defineProperty(t,"track",{value:e}),this.dispatchEvent(t)}}function ct(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const M=400,F="777",dt=n=>n.getVideoTracks().length>0;class s extends st{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;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)},M)});replaceMediaStream=jest.fn(async e=>{});_isReadyToReOffer=jest.fn(()=>!0);addTransceiver=jest.fn((e,t)=>({}));restartIce=jest.fn(async e=>!0);isEndedInner=!1;delayStartPresentation=0;timeoutStartPresentation;timeoutConnect;timeoutNewInfo;timeoutAccepted;timeoutConfirmed;constructor({eventHandlers:e,originator:t,remoteIdentity:r=new a.NameAddrHeader(new a.URI("sip","caller1","test1.com",5060),"Test Caller 1"),delayStartPresentation:o=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=o}static get C(){return a.SessionStatus}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}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}startPresentation=async e=>(s.countStartsPresentation+=1,new Promise((t,r)=>{this.timeoutStartPresentation=setTimeout(()=>{if(s.presentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.presentationError);return}if(s.startPresentationError&&s.countStartsPresentation<s.countStartPresentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.startPresentationError);return}t(super.startPresentation(e))},this.delayStartPresentation)}));stopPresentation=async e=>{if(s.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),s.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=_.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(dt(e)){const c=_.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new at(void 0,r),this.addStream(e),this.trigger("peerconnection",{peerconnection:this.connection})}connect(e,{mediaStream:t}={}){const r=ct(e);return this.initPeerconnection(t),this.timeoutConnect=setTimeout(()=>{e.includes(F)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),this.timeoutNewInfo=setTimeout(()=>{this.newInfo({originator:D.Originator.REMOTE,request:{getHeader:o=>o==="content-type"?"application/vinteo.webrtc.roomname":o==="x-webrtc-enter-room"?r:o==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},M),this.connection}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?.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track: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}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}clear(){clearTimeout(this.timeoutStartPresentation),clearTimeout(this.timeoutConnect),clearTimeout(this.timeoutNewInfo),clearTimeout(this.timeoutAccepted),clearTimeout(this.timeoutConfirmed)}}class Et{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",k="NAME_INCORRECT",h=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},O={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"};class i{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:o}=t;return this.session=new s({eventHandlers:o,originator:"local"}),this.session.connect(e,{mediaStream:r}),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(i.countStarts+=1,i.startError&&i.countStarts<i.countStartError){this.trigger("disconnected",i.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:g})},h):this.trigger("disconnected",{error:!0,socket:g})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;constructor(e){this.events=new v.Events(L);const[t,r]=e.uri.split(":"),[o,c]=r.split("@"),p={...e,uri:new a.URI(t,o,c)};this.configuration=p,this.registratorInner=new Et}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){i.startError=e,i.countStartError=t}static resetStartError(){i.startError=void 0,i.countStartError=Number.POSITIVE_INFINITY,i.countStarts=0}static setAvailableTelephony(){i.isAvailableTelephony=!0}static setNotAvailableTelephony(){i.isAvailableTelephony=!1}static reset(){i.resetStartError(),i.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}off(e,t){return this.events.off(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===!0&&r.user.includes(k)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},h)):!this.isRegistered()&&t===!0&&(e===d||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:O})},h)):t===!0&&e!==d&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},h)),i.isAvailableTelephony?(this.trigger("connected",{socket:g}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:O})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}}class ht{url;constructor(e){this.url=e}}class ut extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const S="remote",mt=(n,e)=>{const t=new N(e),r={originator:S,request:t,info:new ut("","")};n.newInfo(r)},lt=(n,e)=>{const r={event:"sipEvent",request:new N(e)};n.newSipEvent(r)},pt=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new s({originator:S,eventHandlers:{}}),c=new j("sip",e,r);o.remote_identity=new U(c,t);const p=new N([]);n.trigger("newRTCSession",{originator:S,session:o,request:p})},gt=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},w={triggerNewInfo:mt,triggerNewSipEvent:lt,triggerIncomingSession:pt,triggerFailIncomingSession:gt,WebSocketInterface:ht,UA:i,C:{INVITE:"INVITE"}},u="user",E="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",_t=new w.WebSocketInterface(C),f={displayName:"DISPLAY_NAME",userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:C},Tt={...f,displayName:"DISPLAY_NAME",register:!1},W={...f,user:u,password:d,register:!0},It={...W,displayName:E},St={...f,displayName:E,register:!1},l={session_timers:!1,sockets:[_t],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Nt={...l,password:d,uri:new a.URI("sip",u,m),display_name:"DISPLAY_NAME",register:!0},wt={...l,password:d,uri:new a.URI("sip",u,m),display_name:E,register:!0},Ct={...l,display_name:E,register:!1},ft={...l,display_name:"DISPLAY_NAME",register:!1},b="10.10.10.10",Rt=[`X-Vinteo-Remote: ${b}`],At=()=>new D.SipConnector({JsSIP:w});exports.FAILED_CONFERENCE_NUMBER=F;exports.JsSIP=w;exports.NAME_INCORRECT=k;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=W;exports.dataForConnectionWithAuthorizationWithDisplayName=It;exports.dataForConnectionWithoutAuthorization=St;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Tt;exports.displayName=E;exports.doMockSipConnector=At;exports.extraHeadersRemoteAddress=Rt;exports.remoteAddress=b;exports.uaConfigurationWithAuthorization=Nt;exports.uaConfigurationWithAuthorizationWithDisplayName=wt;exports.uaConfigurationWithoutAuthorization=Ct;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ft;exports.user=u;
package/dist/doMock.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { EventEmitter as L } from "node:events";
2
- import F from "@krivega/jssip/lib/NameAddrHeader";
3
- import b from "@krivega/jssip/lib/URI";
4
- import { IncomingRequest as k } from "@krivega/jssip/lib/SIPMessage";
2
+ import k from "@krivega/jssip/lib/NameAddrHeader";
3
+ import F from "@krivega/jssip/lib/URI";
4
+ import { IncomingRequest as b } from "@krivega/jssip/lib/SIPMessage";
5
5
  import { NameAddrHeader as V, URI as E, SessionStatus as W, C as N } from "@krivega/jssip";
6
- import { createAudioMediaStreamTrackMock as U, createVideoMediaStreamTrackMock as G } from "webrtc-mock";
7
- import { Events as _ } from "events-constructor";
8
- import { O as H, S as x } from "./@SipConnector-BmkeKEDD.js";
9
- class T extends k {
6
+ import { MediaStreamTrackMock as U, createAudioMediaStreamTrackMock as G, createVideoMediaStreamTrackMock as H } from "webrtc-mock";
7
+ import { Events as O } from "events-constructor";
8
+ import { O as j, S as x } from "./@SipConnector-BpypVXj0.js";
9
+ class T extends b {
10
10
  headers;
11
11
  constructor(e) {
12
12
  super(), this.headers = new Headers(e);
@@ -15,34 +15,33 @@ class T extends k {
15
15
  return this.headers.get(e) ?? "";
16
16
  }
17
17
  }
18
- const Y = "incomingCall", j = "declinedIncomingCall", q = "failedIncomingCall", z = "terminatedIncomingCall", P = "connecting", B = "connected", K = "disconnected", $ = "newRTCSession", J = "registered", Q = "unregistered", X = "registrationFailed", Z = "newMessage", ee = "sipEvent", te = "availableSecondRemoteStream", re = "notAvailableSecondRemoteStream", ne = "mustStopPresentation", oe = "shareState", se = "enterRoom", ie = "useLicense", ae = "peerconnection:confirmed", ce = "peerconnection:ontrack", de = "channels", Ee = "channels:notify", he = "ended:fromserver", me = "main-cam-control", ue = "admin-stop-main-cam", le = "admin-start-main-cam", pe = "admin-stop-mic", ge = "admin-start-mic", _e = "admin-force-sync-media-state", Te = "participant:added-to-list-moderators", Ie = "participant:removed-from-list-moderators", Se = "participant:move-request-to-stream", we = "participant:move-request-to-spectators", Ne = "participant:move-request-to-participants", fe = "participation:accepting-word-request", Ce = "participation:cancelling-word-request", Re = "webcast:started", Ae = "webcast:stopped", Me = "account:changed", Oe = "account:deleted", Pe = "conference:participant-token-issued", ve = "ended", De = "sending", ye = "reinvite", Le = "replaces", Fe = "refer", be = "progress", ke = "accepted", Ve = "confirmed", We = "peerconnection", Ue = "failed", Ge = "muted", He = "unmuted", xe = "newDTMF", Ye = "newInfo", je = "hold", qe = "unhold", ze = "update", Be = "sdp", Ke = "icecandidate", $e = "getusermediafailed", Je = "peerconnection:createofferfailed", Qe = "peerconnection:createanswerfailed", Xe = "peerconnection:setlocaldescriptionfailed", Ze = "peerconnection:setremotedescriptionfailed", et = "presentation:start", tt = "presentation:started", rt = "presentation:end", nt = "presentation:ended", ot = "presentation:failed", st = [
18
+ const Y = "incomingCall", q = "declinedIncomingCall", z = "failedIncomingCall", B = "terminatedIncomingCall", P = "connecting", K = "connected", J = "disconnected", $ = "newRTCSession", Q = "registered", X = "unregistered", Z = "registrationFailed", ee = "newMessage", te = "sipEvent", re = "availableSecondRemoteStream", ne = "notAvailableSecondRemoteStream", oe = "mustStopPresentation", se = "shareState", ie = "enterRoom", ae = "useLicense", ce = "peerconnection:confirmed", de = "peerconnection:ontrack", Ee = "channels", he = "channels:notify", me = "ended:fromserver", ue = "main-cam-control", le = "admin-stop-main-cam", pe = "admin-start-main-cam", ge = "admin-stop-mic", Te = "admin-start-mic", _e = "admin-force-sync-media-state", Ie = "participant:added-to-list-moderators", Se = "participant:removed-from-list-moderators", Ne = "participant:move-request-to-stream", we = "participant:move-request-to-spectators", fe = "participant:move-request-to-participants", Ce = "participation:accepting-word-request", Re = "participation:cancelling-word-request", Ae = "webcast:started", Me = "webcast:stopped", Oe = "account:changed", Pe = "account:deleted", ve = "conference:participant-token-issued", De = "ended", ye = "sending", Le = "reinvite", ke = "replaces", Fe = "refer", be = "progress", Ve = "accepted", We = "confirmed", Ue = "peerconnection", Ge = "failed", He = "muted", je = "unmuted", xe = "newDTMF", Ye = "newInfo", qe = "hold", ze = "unhold", Be = "update", Ke = "sdp", Je = "icecandidate", $e = "getusermediafailed", Qe = "peerconnection:createofferfailed", Xe = "peerconnection:createanswerfailed", Ze = "peerconnection:setlocaldescriptionfailed", et = "peerconnection:setremotedescriptionfailed", tt = "presentation:start", rt = "presentation:started", nt = "presentation:end", ot = "presentation:ended", st = "presentation:failed", it = [
19
19
  Y,
20
- j,
21
- z,
22
20
  q,
23
- fe,
21
+ B,
22
+ z,
24
23
  Ce,
25
- Se,
26
- Ee,
27
- Pe,
28
- Me,
29
- Oe,
30
24
  Re,
25
+ Ne,
26
+ he,
27
+ ve,
28
+ Oe,
29
+ Pe,
31
30
  Ae,
32
- Te,
33
- Ie
31
+ Me,
32
+ Ie,
33
+ Se
34
34
  ], v = [
35
35
  P,
36
- B,
37
36
  K,
38
- $,
39
37
  J,
38
+ $,
40
39
  Q,
41
40
  X,
42
41
  Z,
43
- ee
44
- ], it = [
45
- te,
42
+ ee,
43
+ te
44
+ ], at = [
46
45
  re,
47
46
  ne,
48
47
  oe,
@@ -51,38 +50,38 @@ const Y = "incomingCall", j = "declinedIncomingCall", q = "failedIncomingCall",
51
50
  ae,
52
51
  ce,
53
52
  de,
54
- he,
53
+ Ee,
55
54
  me,
56
- le,
57
55
  ue,
58
56
  pe,
57
+ le,
59
58
  ge,
59
+ Te,
60
60
  _e,
61
61
  we,
62
- Ne
62
+ fe
63
63
  ], p = [
64
- ve,
65
- P,
66
64
  De,
65
+ P,
67
66
  ye,
68
67
  Le,
68
+ ke,
69
69
  Fe,
70
70
  be,
71
- ke,
72
71
  Ve,
73
72
  We,
74
73
  Ue,
75
74
  Ge,
76
75
  He,
76
+ je,
77
77
  xe,
78
78
  Ye,
79
- je,
80
79
  qe,
81
80
  ze,
82
81
  Be,
83
82
  Ke,
84
- $e,
85
83
  Je,
84
+ $e,
86
85
  Qe,
87
86
  Xe,
88
87
  Ze,
@@ -90,14 +89,15 @@ const Y = "incomingCall", j = "declinedIncomingCall", q = "failedIncomingCall",
90
89
  tt,
91
90
  rt,
92
91
  nt,
93
- ot
92
+ ot,
93
+ st
94
94
  ];
95
- [...v, ...st];
95
+ [...v, ...it];
96
96
  [
97
97
  ...p,
98
- ...it
98
+ ...at
99
99
  ];
100
- class at {
100
+ class ct {
101
101
  originator;
102
102
  connection;
103
103
  events;
@@ -108,7 +108,7 @@ class at {
108
108
  eventHandlers: t,
109
109
  remoteIdentity: r
110
110
  }) {
111
- this.originator = e, this.events = new _(p), this.initEvents(t), this.remote_identity = r;
111
+ this.originator = e, this.events = new O(p), this.initEvents(t), this.remote_identity = r;
112
112
  }
113
113
  get contact() {
114
114
  throw new Error("Method not implemented.");
@@ -268,7 +268,7 @@ class at {
268
268
  return !0;
269
269
  }
270
270
  }
271
- class f {
271
+ class w {
272
272
  stats = (/* @__PURE__ */ new Map()).set("codec", { mimeType: "video/h264" });
273
273
  dtmf = null;
274
274
  track = null;
@@ -311,7 +311,7 @@ class f {
311
311
  throw new Error("Method not implemented.");
312
312
  }
313
313
  }
314
- class C {
314
+ class f {
315
315
  currentDirection = "sendrecv";
316
316
  direction = "sendrecv";
317
317
  // eslint-disable-next-line unicorn/no-null
@@ -329,8 +329,7 @@ class C {
329
329
  stop() {
330
330
  }
331
331
  }
332
- const ct = ["track"];
333
- class dt {
332
+ class dt extends EventTarget {
334
333
  senders = [];
335
334
  receivers = [];
336
335
  canTrickleIceCandidates;
@@ -359,9 +358,23 @@ class dt {
359
358
  // eslint-disable-next-line unicorn/no-null
360
359
  sctp = null;
361
360
  signalingState;
362
- events;
361
+ close = jest.fn();
362
+ setLocalDescription = jest.fn(
363
+ async (e) => {
364
+ }
365
+ );
366
+ setRemoteDescription = jest.fn(
367
+ async (e) => {
368
+ }
369
+ );
370
+ addTransceiver = jest.fn(
371
+ (e, t) => ({})
372
+ );
373
+ createOffer = jest.fn(
374
+ async (e, t, r) => ({ type: "offer", sdp: "offer-sdp" })
375
+ );
363
376
  constructor(e, t) {
364
- this.events = new _(ct), this.receivers = t.map((r) => ({ track: r }));
377
+ super(), this.receivers = t?.map((r) => ({ track: r })) ?? [];
365
378
  }
366
379
  getRemoteStreams() {
367
380
  throw new Error("Method not implemented.");
@@ -369,12 +382,6 @@ class dt {
369
382
  async addIceCandidate(e) {
370
383
  throw new Error("Method not implemented.");
371
384
  }
372
- addTransceiver(e, t) {
373
- throw new Error("Method not implemented.");
374
- }
375
- close() {
376
- throw new Error("Method not implemented.");
377
- }
378
385
  restartIce() {
379
386
  throw new Error("Method not implemented.");
380
387
  }
@@ -384,9 +391,6 @@ class dt {
384
391
  createDataChannel(e, t) {
385
392
  throw new Error("Method not implemented.");
386
393
  }
387
- async createOffer(e, t, r) {
388
- throw new Error("Method not implemented.");
389
- }
390
394
  getConfiguration() {
391
395
  throw new Error("Method not implemented.");
392
396
  }
@@ -405,41 +409,38 @@ class dt {
405
409
  setConfiguration(e) {
406
410
  throw new Error("Method not implemented.");
407
411
  }
408
- async setLocalDescription(e) {
409
- throw new Error("Method not implemented.");
410
- }
411
- async setRemoteDescription(e) {
412
- throw new Error("Method not implemented.");
413
- }
414
- addEventListener(e, t, r) {
415
- this.events.on(e, t);
416
- }
417
- removeEventListener(e, t, r) {
418
- this.events.off(e, t);
419
- }
420
- dispatchEvent(e) {
421
- throw new Error("Method not implemented.");
422
- }
423
412
  getReceivers = () => this.receivers;
424
413
  getSenders = () => this.senders;
425
414
  addTrack = (e, ...t) => {
426
- const r = new f({ track: e }), n = new C(r);
427
- return n.mid = e.kind === "audio" ? "0" : "1", this.senders.push(r), this.events.trigger("track", { track: e, transceiver: n }), r;
415
+ const r = new w({ track: e }), o = new f(r);
416
+ return o.mid = e.kind === "audio" ? "0" : "1", this.senders.push(r), this.dispatchTrackInternal(e), r;
428
417
  };
429
418
  // Дополнительный метод для тестов с возможностью установки mid
430
419
  addTrackWithMid = (e, t) => {
431
- const r = new f({ track: e }), n = new C(r);
432
- return t === void 0 ? n.mid = e.kind === "audio" ? "0" : "1" : n.mid = t, this.senders.push(r), this.events.trigger("track", { track: e, transceiver: n }), r;
420
+ const r = new w({ track: e }), o = new f(r);
421
+ return t === void 0 ? o.mid = e.kind === "audio" ? "0" : "1" : o.mid = t, this.senders.push(r), this.dispatchTrackInternal(e), r;
433
422
  };
423
+ dispatchTrack(e) {
424
+ this.dispatchTrackInternal(new U(e));
425
+ }
426
+ dispatchTrackInternal(e) {
427
+ const t = new Event(
428
+ "track"
429
+ /* TRACK */
430
+ );
431
+ Object.defineProperty(t, "track", {
432
+ value: e
433
+ }), this.dispatchEvent(t);
434
+ }
434
435
  }
435
- function Et(o) {
436
- const e = o.match(/(purgatory)|[\d.]+/g);
436
+ function Et(n) {
437
+ const e = n.match(/(purgatory)|[\d.]+/g);
437
438
  if (!e)
438
439
  throw new Error("wrong sip url");
439
440
  return e[0];
440
441
  }
441
- const R = 400, ht = "777", mt = (o) => o.getVideoTracks().length > 0;
442
- class i extends at {
442
+ const C = 400, ht = "777", mt = (n) => n.getVideoTracks().length > 0;
443
+ class i extends ct {
443
444
  static presentationError;
444
445
  static startPresentationError;
445
446
  static countStartPresentationError = Number.POSITIVE_INFINITY;
@@ -464,7 +465,7 @@ class i extends at {
464
465
  }, 100), setTimeout(() => {
465
466
  this.trigger("confirmed");
466
467
  }, 200);
467
- }, R);
468
+ }, C);
468
469
  });
469
470
  replaceMediaStream = jest.fn(async (e) => {
470
471
  });
@@ -489,9 +490,9 @@ class i extends at {
489
490
  new E("sip", "caller1", "test1.com", 5060),
490
491
  "Test Caller 1"
491
492
  ),
492
- delayStartPresentation: n = 0
493
+ delayStartPresentation: o = 0
493
494
  }) {
494
- super({ originator: t, eventHandlers: e, remoteIdentity: r }), this.delayStartPresentation = n;
495
+ super({ originator: t, eventHandlers: e, remoteIdentity: r }), this.delayStartPresentation = o;
495
496
  }
496
497
  static get C() {
497
498
  return W;
@@ -530,11 +531,11 @@ class i extends at {
530
531
  return e ? (this.createPeerconnection(e), !0) : !1;
531
532
  }
532
533
  createPeerconnection(e) {
533
- const t = U();
534
+ const t = G();
534
535
  t.id = "mainaudio1";
535
536
  const r = [t];
536
537
  if (mt(e)) {
537
- const a = G();
538
+ const a = H();
538
539
  a.id = "mainvideo1", r.push(a);
539
540
  }
540
541
  this.connection = new dt(void 0, r), this.addStream(e), this.trigger("peerconnection", { peerconnection: this.connection });
@@ -548,10 +549,10 @@ class i extends at {
548
549
  cause: "Rejected"
549
550
  }) : (this.trigger("connecting"), this.timeoutNewInfo = setTimeout(() => {
550
551
  this.newInfo({
551
- originator: H.REMOTE,
552
+ originator: j.REMOTE,
552
553
  // @ts-expect-error
553
554
  request: {
554
- getHeader: (n) => n === "content-type" ? "application/vinteo.webrtc.roomname" : n === "x-webrtc-enter-room" ? r : n === "x-webrtc-participant-name" ? "Test Caller 1" : ""
555
+ getHeader: (o) => o === "content-type" ? "application/vinteo.webrtc.roomname" : o === "x-webrtc-enter-room" ? r : o === "x-webrtc-participant-name" ? "Test Caller 1" : ""
555
556
  }
556
557
  });
557
558
  }, 100), this.timeoutAccepted = setTimeout(() => {
@@ -559,7 +560,7 @@ class i extends at {
559
560
  }, 200), this.timeoutConfirmed = setTimeout(() => {
560
561
  this.trigger("confirmed");
561
562
  }, 300));
562
- }, R), this.connection;
563
+ }, C), this.connection;
563
564
  }
564
565
  terminate({ status_code: e, cause: t } = {}) {
565
566
  return this.status_code = e, this.trigger("ended", { status_code: e, cause: t, originator: "local" }), this.isEndedInner = !1, this;
@@ -629,14 +630,14 @@ class ut {
629
630
  setExtraContactParams() {
630
631
  }
631
632
  }
632
- const c = "PASSWORD_CORRECT", A = "PASSWORD_CORRECT_2", lt = "NAME_INCORRECT", d = 400, l = {
633
+ const c = "PASSWORD_CORRECT", R = "PASSWORD_CORRECT_2", lt = "NAME_INCORRECT", d = 400, l = {
633
634
  url: "wss://sipServerUrl/webrtc/wss/",
634
635
  sip_uri: "sip:sipServerUrl;transport=ws",
635
636
  via_transport: "WSS"
636
- }, M = {
637
+ }, A = {
637
638
  status_code: 200,
638
639
  reason_phrase: "OK"
639
- }, O = {
640
+ }, M = {
640
641
  status_code: 401,
641
642
  reason_phrase: "Unauthorized"
642
643
  };
@@ -650,8 +651,8 @@ class s {
650
651
  // @ts-expect-error – Jest создаёт функцию-замок.
651
652
  call = jest.fn(
652
653
  (e, t) => {
653
- const { mediaStream: r, eventHandlers: n } = t;
654
- return this.session = new i({ eventHandlers: n, originator: "local" }), this.session.connect(e, { mediaStream: r }), this.session;
654
+ const { mediaStream: r, eventHandlers: o } = t;
655
+ return this.session = new i({ eventHandlers: o, originator: "local" }), this.session.connect(e, { mediaStream: r }), this.session;
655
656
  }
656
657
  );
657
658
  sendOptions = jest.fn(
@@ -686,10 +687,10 @@ class s {
686
687
  isConnectedInner;
687
688
  configuration;
688
689
  constructor(e) {
689
- this.events = new _(v);
690
- const [t, r] = e.uri.split(":"), [n, a] = r.split("@"), u = {
690
+ this.events = new O(v);
691
+ const [t, r] = e.uri.split(":"), [o, a] = r.split("@"), u = {
691
692
  ...e,
692
- uri: new E(t, n, a)
693
+ uri: new E(t, o, a)
693
694
  };
694
695
  this.configuration = u, this.registratorInner = new ut();
695
696
  }
@@ -737,11 +738,11 @@ class s {
737
738
  this.startedTimeout && clearTimeout(this.startedTimeout);
738
739
  const { password: e, register: t, uri: r } = this.configuration;
739
740
  t === !0 && r.user.includes(lt) ? (this.isRegisteredInner = !1, this.isConnectedInner = !1, this.startedTimeout = setTimeout(() => {
740
- this.trigger("registrationFailed", { response: O, cause: N.causes.REJECTED });
741
- }, d)) : !this.isRegistered() && t === !0 && (e === c || e === A) ? (this.isRegisteredInner = !0, this.startedTimeout = setTimeout(() => {
742
- this.trigger("registered", { response: M });
743
- }, d)) : t === !0 && e !== c && e !== A && (this.isRegisteredInner = !1, this.isConnectedInner = !1, this.startedTimeout = setTimeout(() => {
744
- this.trigger("registrationFailed", { response: O, cause: N.causes.REJECTED });
741
+ this.trigger("registrationFailed", { response: M, cause: N.causes.REJECTED });
742
+ }, d)) : !this.isRegistered() && t === !0 && (e === c || e === R) ? (this.isRegisteredInner = !0, this.startedTimeout = setTimeout(() => {
743
+ this.trigger("registered", { response: A });
744
+ }, d)) : t === !0 && e !== c && e !== R && (this.isRegisteredInner = !1, this.isConnectedInner = !1, this.startedTimeout = setTimeout(() => {
745
+ this.trigger("registrationFailed", { response: M, cause: N.causes.REJECTED });
745
746
  }, d)), s.isAvailableTelephony ? (this.trigger("connected", { socket: l }), this.isConnectedInner = !0) : this.stop();
746
747
  }
747
748
  /**
@@ -750,7 +751,7 @@ class s {
750
751
  * @returns {undefined}
751
752
  */
752
753
  unregister() {
753
- this.isRegisteredInner = !1, this.isConnectedInner = !1, this.trigger("unregistered", { response: M });
754
+ this.isRegisteredInner = !1, this.isConnectedInner = !1, this.trigger("unregistered", { response: A });
754
755
  }
755
756
  isRegistered() {
756
757
  return this.isRegisteredInner === !0;
@@ -786,34 +787,34 @@ class gt extends L {
786
787
  super(), this.contentType = e, this.body = t;
787
788
  }
788
789
  }
789
- const g = "remote", _t = (o, e) => {
790
+ const g = "remote", Tt = (n, e) => {
790
791
  const t = new T(e), r = {
791
792
  originator: g,
792
793
  request: t,
793
794
  info: new gt("", "")
794
795
  };
795
- o.newInfo(r);
796
- }, Tt = (o, e) => {
796
+ n.newInfo(r);
797
+ }, _t = (n, e) => {
797
798
  const r = { event: "sipEvent", request: new T(e) };
798
- o.newSipEvent(r);
799
- }, It = (o, {
799
+ n.newSipEvent(r);
800
+ }, It = (n, {
800
801
  incomingNumber: e = "1234",
801
802
  displayName: t,
802
803
  host: r
803
804
  }) => {
804
- const n = new i({ originator: g, eventHandlers: {} }), a = new b("sip", e, r);
805
- n.remote_identity = new F(a, t);
805
+ const o = new i({ originator: g, eventHandlers: {} }), a = new F("sip", e, r);
806
+ o.remote_identity = new k(a, t);
806
807
  const u = new T([]);
807
- o.trigger("newRTCSession", {
808
+ n.trigger("newRTCSession", {
808
809
  originator: g,
809
- session: n,
810
+ session: o,
810
811
  request: u
811
812
  });
812
- }, St = (o, e) => {
813
- e ? o.trigger("failed", e) : o.trigger("failed", o);
813
+ }, St = (n, e) => {
814
+ e ? n.trigger("failed", e) : n.trigger("failed", n);
814
815
  }, D = {
815
- triggerNewInfo: _t,
816
- triggerNewSipEvent: Tt,
816
+ triggerNewInfo: Tt,
817
+ triggerNewSipEvent: _t,
817
818
  triggerIncomingSession: It,
818
819
  triggerFailIncomingSession: St,
819
820
  WebSocketInterface: pt,
@@ -821,45 +822,45 @@ const g = "remote", _t = (o, e) => {
821
822
  C: {
822
823
  INVITE: "INVITE"
823
824
  }
824
- }, I = "user", h = "displayName", S = "SIP_SERVER_URL", y = "SIP_WEB_SOCKET_SERVER_URL", wt = new D.WebSocketInterface(y), w = {
825
+ }, _ = "user", h = "displayName", I = "SIP_SERVER_URL", y = "SIP_WEB_SOCKET_SERVER_URL", Nt = new D.WebSocketInterface(y), S = {
825
826
  displayName: "DISPLAY_NAME",
826
827
  userAgent: "Chrome",
827
- sipServerUrl: S,
828
+ sipServerUrl: I,
828
829
  sipWebSocketServerURL: y
829
830
  }, yt = {
830
- ...w,
831
+ ...S,
831
832
  displayName: "DISPLAY_NAME",
832
833
  register: !1
833
- }, Nt = {
834
- ...w,
835
- user: I,
834
+ }, wt = {
835
+ ...S,
836
+ user: _,
836
837
  password: c,
837
838
  register: !0
838
839
  }, Lt = {
839
- ...Nt,
840
+ ...wt,
840
841
  displayName: h
841
- }, Ft = {
842
- ...w,
842
+ }, kt = {
843
+ ...S,
843
844
  displayName: h,
844
845
  register: !1
845
846
  }, m = {
846
847
  session_timers: !1,
847
- sockets: [wt],
848
+ sockets: [Nt],
848
849
  user_agent: "Chrome",
849
850
  sdpSemantics: "unified-plan",
850
851
  register_expires: 300,
851
852
  connection_recovery_max_interval: 6,
852
853
  connection_recovery_min_interval: 2
853
- }, bt = {
854
+ }, Ft = {
854
855
  ...m,
855
856
  password: c,
856
- uri: new E("sip", I, S),
857
+ uri: new E("sip", _, I),
857
858
  display_name: "DISPLAY_NAME",
858
859
  register: !0
859
- }, kt = {
860
+ }, bt = {
860
861
  ...m,
861
862
  password: c,
862
- uri: new E("sip", I, S),
863
+ uri: new E("sip", _, I),
863
864
  display_name: h,
864
865
  register: !0
865
866
  }, Vt = {
@@ -878,20 +879,20 @@ export {
878
879
  D as JsSIP,
879
880
  lt as NAME_INCORRECT,
880
881
  c as PASSWORD_CORRECT,
881
- A as PASSWORD_CORRECT_2,
882
- S as SIP_SERVER_URL,
882
+ R as PASSWORD_CORRECT_2,
883
+ I as SIP_SERVER_URL,
883
884
  y as SIP_WEB_SOCKET_SERVER_URL,
884
- Nt as dataForConnectionWithAuthorization,
885
+ wt as dataForConnectionWithAuthorization,
885
886
  Lt as dataForConnectionWithAuthorizationWithDisplayName,
886
- Ft as dataForConnectionWithoutAuthorization,
887
+ kt as dataForConnectionWithoutAuthorization,
887
888
  yt as dataForConnectionWithoutAuthorizationWithoutDisplayName,
888
889
  h as displayName,
889
890
  Gt as doMockSipConnector,
890
891
  Ut as extraHeadersRemoteAddress,
891
892
  ft as remoteAddress,
892
- bt as uaConfigurationWithAuthorization,
893
- kt as uaConfigurationWithAuthorizationWithDisplayName,
893
+ Ft as uaConfigurationWithAuthorization,
894
+ bt as uaConfigurationWithAuthorizationWithDisplayName,
894
895
  Vt as uaConfigurationWithoutAuthorization,
895
896
  Wt as uaConfigurationWithoutAuthorizationWithoutDisplayName,
896
- I as user
897
+ _ as user
897
898
  };