sip-connector 6.21.2 → 6.21.4

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";var M=Object.defineProperty;var v=(i,e,t)=>e in i?M(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var n=(i,e,t)=>(v(i,typeof e!="symbol"?e+"":e,t),t);const c=require("./SipConnector-3317ff75.cjs"),T=require("@krivega/jssip/lib/NameAddrHeader"),S=require("@krivega/jssip/lib/URI"),C=require("node:events"),R=require("@krivega/jssip/lib/SIPMessage"),g=require("events-constructor");require("@krivega/cancelable-promise");require("debug");class p extends R.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var y=Object.defineProperty,I=(i,e,t)=>e in i?y(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,s=(i,e,t)=>(I(i,typeof e!="symbol"?e+"":e,t),t);const a="ended",O="mute",b="isolationchange",k="overconstrained",N="unmute",L=[a,O,N,b,k];class E{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(a)};this.events.trigger(a,o),this.readyState=a,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,d)=>{this.events.on(o,d)}),s(this,"removeEventListener",(o,d)=>{this.events.off(o,d)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...r},this.events=new g(L)}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 A=i=>new E("audio",i),D=i=>new E("video",i);class P{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 g(c.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 x{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 q(i){const e=i.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const m=400,j="777",H=i=>i.getVideoTracks().length>0;class f extends P{constructor({url:t="",mediaStream:r,eventHandlers:o,originator:d}){super({originator:d,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)},m)}));this.url=t,this.initPeerconnection(r)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const r=A();r.id="mainaudio1";const o=[r];if(H(t)){const u=D();u.id="mainvideo1",o.push(u)}this._connection=new x(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},m)}connect(t){const r=q(t);setTimeout(()=>{this.url.includes(j)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:c.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",r)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},m)}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 V{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const w="PASSWORD_CORRECT",_="PASSWORD_CORRECT_2",F="NAME_INCORRECT",h=400;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:r,eventHandlers:o}=t;return this.session=new f({url:e,mediaStream:r,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new g(c.UA_EVENT_NAMES),this.configuration=e,this._registrator=new V}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")})},h):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(F)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},h)):!this._isRegistered&&t&&(e===w||e===_)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},h)):t&&e!==w&&e!==_&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},h)),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 W{constructor(e){n(this,"url");this.url=e}}class Y extends C.EventEmitter{constructor(t,r){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=r}}const l="remote",$=(i,e)=>{const t=new p(e),r={originator:l,request:t,info:new Y("","")};i.newInfo(r)},B=(i,e)=>{const r={request:new p(e)};i.newSipEvent(r)},J=(i,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new f({originator:l}),d=new S("sip",e,r);o._remote_identity=new T(d,t),i.trigger("newRTCSession",{originator:l,session:o})},G=(i,e)=>{e?i.trigger("failed",e):i.trigger("failed",i)},K={triggerNewInfo:$,triggerNewSipEvent:B,triggerIncomingSession:J,triggerFailIncomingSession:G,WebSocketInterface:W,UA:U,C:{INVITE:"INVITE"}},z=()=>new c.SipConnector({JsSIP:K});module.exports=z;
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-3317ff75.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;
package/dist/doMock.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import SIPconnector from './SipConnector';
2
2
  declare const doMock: () => SIPconnector;
3
3
  export default doMock;
4
+ export { FAILED_CONFERENCE_NUMBER } from './__fixtures__/Session.mock';
5
+ export { NAME_INCORRECT, PASSWORD_CORRECT, PASSWORD_CORRECT_2 } from './__fixtures__/UA.mock';
6
+ export * from './__fixtures__/index';
package/dist/doMock.js CHANGED
@@ -1,15 +1,15 @@
1
- var f = Object.defineProperty;
2
- var M = (i, e, t) => e in i ? f(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var n = (i, e, t) => (M(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { j as v, R as T, U as R, S } from "./SipConnector-abcad4a1.js";
5
- import C from "@krivega/jssip/lib/NameAddrHeader";
6
- import y from "@krivega/jssip/lib/URI";
7
- import { EventEmitter as I } from "node:events";
8
- import { IncomingRequest as O } from "@krivega/jssip/lib/SIPMessage";
9
- import l from "events-constructor";
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-abcad4a1.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
10
  import "@krivega/cancelable-promise";
11
11
  import "debug";
12
- class p extends O {
12
+ class M extends W {
13
13
  constructor(t) {
14
14
  super();
15
15
  n(this, "headers");
@@ -19,18 +19,18 @@ class p extends O {
19
19
  return this.headers.get(t) || "";
20
20
  }
21
21
  }
22
- var b = Object.defineProperty, k = (i, e, t) => e in i ? b(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, s = (i, e, t) => (k(i, typeof e != "symbol" ? e + "" : e, t), t);
23
- const a = "ended", N = "mute", L = "isolationchange", A = "overconstrained", D = "unmute", P = [a, N, D, L, A];
24
- class _ {
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];
24
+ class R {
25
25
  constructor(e, { id: t = "identifier", constraints: r = {} } = {}) {
26
26
  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", () => {
27
- const o = { ...new Event(a) };
28
- this.events.trigger(a, o), this.readyState = a, this.onended && this.onended(o);
29
- }), s(this, "addEventListener", (o, d) => {
30
- this.events.on(o, d);
31
- }), s(this, "removeEventListener", (o, d) => {
32
- this.events.off(o, d);
33
- }), this.id = `${t}-${e}-track`, this.kind = e, this.enabled = !0, this.constraints = { ...r }, this.events = new l(P);
27
+ const o = { ...new Event(c) };
28
+ this.events.trigger(c, o), this.readyState = c, this.onended && this.onended(o);
29
+ }), s(this, "addEventListener", (o, a) => {
30
+ this.events.on(o, a);
31
+ }), s(this, "removeEventListener", (o, a) => {
32
+ this.events.off(o, a);
33
+ }), this.id = `${t}-${e}-track`, this.kind = e, this.enabled = !0, this.constraints = { ...r }, this.events = new _(H);
34
34
  }
35
35
  clone() {
36
36
  return { ...this };
@@ -56,8 +56,8 @@ class _ {
56
56
  return this.events.trigger(t, e), !0;
57
57
  }
58
58
  }
59
- const x = (i) => new _("audio", i), j = (i) => new _("video", i);
60
- class H {
59
+ const z = (i) => new R("audio", i), $ = (i) => new R("video", i);
60
+ class q {
61
61
  // @ts-expect-error
62
62
  constructor({ originator: e = "local", eventHandlers: t }) {
63
63
  n(this, "originator");
@@ -65,7 +65,7 @@ class H {
65
65
  n(this, "_events");
66
66
  n(this, "_remote_identity");
67
67
  n(this, "_mutedOptions", { audio: !1, video: !1 });
68
- this.originator = e, this._events = new l(v), this.initEvents(t);
68
+ this.originator = e, this._events = new _(b), this.initEvents(t);
69
69
  }
70
70
  // @ts-expect-error
71
71
  get C() {
@@ -238,7 +238,7 @@ class H {
238
238
  return !0;
239
239
  }
240
240
  }
241
- class V {
241
+ class B {
242
242
  constructor(e, t) {
243
243
  n(this, "_senders", []);
244
244
  n(this, "_receivers", []);
@@ -332,21 +332,21 @@ class V {
332
332
  throw new Error("Method not implemented.");
333
333
  }
334
334
  }
335
- function F(i) {
335
+ function K(i) {
336
336
  const e = i.match(/[\d.]+/g);
337
337
  if (!e)
338
338
  throw new Error("wrong sip url");
339
339
  return e[0];
340
340
  }
341
- const c = 400, U = "777", W = (i) => i.getVideoTracks().length > 0;
342
- class E extends H {
341
+ const u = 400, Y = "777", J = (i) => i.getVideoTracks().length > 0;
342
+ class T extends q {
343
343
  constructor({
344
344
  url: t = "",
345
345
  mediaStream: r,
346
346
  eventHandlers: o,
347
- originator: d
347
+ originator: a
348
348
  }) {
349
- super({ originator: d, eventHandlers: o });
349
+ super({ originator: a, eventHandlers: o });
350
350
  n(this, "url");
351
351
  n(this, "status_code");
352
352
  n(this, "_isEnded", !1);
@@ -368,7 +368,7 @@ class E extends H {
368
368
  }, 100), setTimeout(() => {
369
369
  this.trigger("confirmed");
370
370
  }, 200);
371
- }, c);
371
+ }, u);
372
372
  }));
373
373
  this.url = t, this.initPeerconnection(r);
374
374
  }
@@ -376,24 +376,24 @@ class E extends H {
376
376
  return t ? (this.createPeerconnection(t), !0) : !1;
377
377
  }
378
378
  createPeerconnection(t) {
379
- const r = x();
379
+ const r = z();
380
380
  r.id = "mainaudio1";
381
381
  const o = [r];
382
- if (W(t)) {
383
- const g = j();
384
- g.id = "mainvideo1", o.push(g);
382
+ if (J(t)) {
383
+ const f = $();
384
+ f.id = "mainvideo1", o.push(f);
385
385
  }
386
- this._connection = new V(void 0, o), this._addStream(t), setTimeout(() => {
386
+ this._connection = new B(void 0, o), this._addStream(t), setTimeout(() => {
387
387
  this.trigger("peerconnection", { peerconnection: this.connection });
388
- }, c);
388
+ }, u);
389
389
  }
390
390
  connect(t) {
391
- const r = F(t);
391
+ const r = K(t);
392
392
  setTimeout(() => {
393
- this.url.includes(U) ? this.trigger("failed", {
393
+ this.url.includes(Y) ? this.trigger("failed", {
394
394
  originator: "remote",
395
395
  message: "IncomingResponse",
396
- cause: T
396
+ cause: O
397
397
  }) : (this.trigger("connecting"), setTimeout(() => {
398
398
  this.trigger("enterRoom", r);
399
399
  }, 100), setTimeout(() => {
@@ -401,7 +401,7 @@ class E extends H {
401
401
  }, 200), setTimeout(() => {
402
402
  this.trigger("confirmed");
403
403
  }, 300));
404
- }, c);
404
+ }, u);
405
405
  }
406
406
  terminate({ status_code: t } = {}) {
407
407
  return this.status_code = t, this.trigger("ended", { status_code: t }), this._isEnded = !1, this;
@@ -459,7 +459,7 @@ class E extends H {
459
459
  }
460
460
  /* eslint-enable no-param-reassign */
461
461
  }
462
- class q {
462
+ class G {
463
463
  constructor() {
464
464
  n(this, "extraHeaders");
465
465
  }
@@ -469,8 +469,8 @@ class q {
469
469
  setExtraContactParams() {
470
470
  }
471
471
  }
472
- const u = "PASSWORD_CORRECT", w = "PASSWORD_CORRECT_2", Y = "NAME_INCORRECT", h = 400;
473
- class $ {
472
+ const d = "PASSWORD_CORRECT", v = "PASSWORD_CORRECT_2", X = "NAME_INCORRECT", h = 400;
473
+ class Q {
474
474
  constructor(e) {
475
475
  n(this, "_events");
476
476
  n(this, "_startedTimeout");
@@ -483,9 +483,9 @@ class $ {
483
483
  // @ts-expect-error
484
484
  n(this, "call", jest.fn((e, t) => {
485
485
  const { mediaStream: r, eventHandlers: o } = t;
486
- return this.session = new E({ url: e, mediaStream: r, eventHandlers: o, originator: "local" }), this.session.connect(e), this.session;
486
+ return this.session = new T({ url: e, mediaStream: r, eventHandlers: o, originator: "local" }), this.session.connect(e), this.session;
487
487
  }));
488
- this._events = new l(R), this.configuration = e, this._registrator = new q();
488
+ this._events = new _(k), this.configuration = e, this._registrator = new G();
489
489
  }
490
490
  /**
491
491
  * start
@@ -539,11 +539,11 @@ class $ {
539
539
  register() {
540
540
  this._startedTimeout && clearTimeout(this._startedTimeout);
541
541
  const { password: e, register: t, uri: r } = this.configuration;
542
- t && r.includes(Y) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
542
+ t && r.includes(X) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
543
543
  this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
544
- }, h)) : !this._isRegistered && t && (e === u || e === w) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
544
+ }, h)) : !this._isRegistered && t && (e === d || e === v) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
545
545
  this.trigger("registered");
546
- }, h)) : t && e !== u && e !== w && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
546
+ }, h)) : t && e !== d && e !== v && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
547
547
  this.trigger("registrationFailed", { response: null, cause: "Wrong credentials" });
548
548
  }, h)), this.trigger("connected"), this._isConnected = !0;
549
549
  }
@@ -578,13 +578,13 @@ class $ {
578
578
  this.trigger("sipEvent", e);
579
579
  }
580
580
  }
581
- class B {
581
+ class Z {
582
582
  constructor(e) {
583
583
  n(this, "url");
584
584
  this.url = e;
585
585
  }
586
586
  }
587
- class J extends I {
587
+ class ee extends D {
588
588
  constructor(t, r) {
589
589
  super();
590
590
  n(this, "contentType");
@@ -592,38 +592,102 @@ class J extends I {
592
592
  this.contentType = t, this.body = r;
593
593
  }
594
594
  }
595
- const m = "remote", G = (i, e) => {
596
- const t = new p(e), r = {
597
- originator: m,
595
+ const g = "remote", te = (i, e) => {
596
+ const t = new M(e), r = {
597
+ originator: g,
598
598
  request: t,
599
- info: new J("", "")
599
+ info: new ee("", "")
600
600
  };
601
601
  i.newInfo(r);
602
- }, K = (i, e) => {
603
- const r = { request: new p(e) };
602
+ }, ne = (i, e) => {
603
+ const r = { request: new M(e) };
604
604
  i.newSipEvent(r);
605
- }, z = (i, {
605
+ }, re = (i, {
606
606
  incomingNumber: e = "1234",
607
607
  displayName: t,
608
608
  host: r
609
609
  }) => {
610
- const o = new E({ originator: m }), d = new y("sip", e, r);
611
- o._remote_identity = new C(d, t), i.trigger("newRTCSession", { originator: m, session: o });
612
- }, Q = (i, e) => {
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) => {
613
613
  e ? i.trigger("failed", e) : i.trigger("failed", i);
614
- }, X = {
615
- triggerNewInfo: G,
616
- triggerNewSipEvent: K,
617
- triggerIncomingSession: z,
618
- triggerFailIncomingSession: Q,
619
- WebSocketInterface: B,
620
- UA: $,
614
+ }, S = {
615
+ triggerNewInfo: te,
616
+ triggerNewSipEvent: ne,
617
+ triggerIncomingSession: re,
618
+ triggerFailIncomingSession: ie,
619
+ WebSocketInterface: Z,
620
+ UA: Q,
621
621
  C: {
622
622
  INVITE: "INVITE"
623
623
  }
624
- }, he = () => new S({
625
- JsSIP: X
624
+ }, p = "user", m = "displayName", w = "SIP_SERVER_URL", C = "SIP_WEB_SOCKET_SERVER_URL", oe = new S.WebSocketInterface(C), E = {
625
+ userAgent: "Chrome",
626
+ sipServerUrl: w,
627
+ sipWebSocketServerURL: C
628
+ }, we = {
629
+ ...E
630
+ }, se = {
631
+ ...E,
632
+ user: p,
633
+ password: d,
634
+ register: !0
635
+ }, Ee = {
636
+ ...se,
637
+ displayName: m
638
+ }, fe = {
639
+ ...E,
640
+ displayName: m,
641
+ register: !1
642
+ }, l = {
643
+ session_timers: !1,
644
+ sockets: [oe],
645
+ user_agent: "Chrome",
646
+ sdp_semantics: "plan-b",
647
+ register_expires: 300,
648
+ connection_recovery_max_interval: 6,
649
+ connection_recovery_min_interval: 2
650
+ }, ve = {
651
+ ...l,
652
+ password: d,
653
+ uri: `sip:${p}@${w}`,
654
+ display_name: "",
655
+ register: !0
656
+ }, Me = {
657
+ ...l,
658
+ password: d,
659
+ uri: `sip:${p}@${w}`,
660
+ display_name: m,
661
+ register: !0
662
+ }, Re = {
663
+ ...l,
664
+ display_name: m,
665
+ register: !1
666
+ }, Te = {
667
+ ...l,
668
+ display_name: "",
669
+ register: !1
670
+ }, ae = "10.10.10.10", Se = [`X-Vinteo-Remote: ${ae}`], Ce = () => new A({
671
+ JsSIP: S
626
672
  });
627
673
  export {
628
- he as default
674
+ Y as FAILED_CONFERENCE_NUMBER,
675
+ X as NAME_INCORRECT,
676
+ 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,
691
+ Te as uaConfigurationWithoutAuthorizationWithoutDisplayName,
692
+ p as user
629
693
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-connector",
3
- "version": "6.21.2",
3
+ "version": "6.21.4",
4
4
  "description": "Module for connect to Vinteo server",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -53,9 +53,9 @@
53
53
  "prepare": "husky install",
54
54
  "prepublishOnly": "yarn build",
55
55
  "preview": "vite preview",
56
- "release": "standard-version && yarn release:publish",
57
- "release:major": "standard-version --release-as major && yarn release:publish",
58
- "release:pre": "standard-version --prerelease && yarn release:publish",
56
+ "release": "standard-version && npm release:publish",
57
+ "release:major": "standard-version --release-as major && npm release:publish",
58
+ "release:pre": "standard-version --prerelease && npm release:publish",
59
59
  "release:publish": "git push --follow-tags origin master && npm publish --access=public",
60
60
  "test": "jest --watch",
61
61
  "test:ci": "cross-env CI=true jest --passWithNoTests",