sip-connector 6.22.2 → 6.23.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.
@@ -74,6 +74,7 @@ type TOptionsExtraHeaders = {
74
74
  extraHeaders?: string[];
75
75
  };
76
76
  type TOntrack = (track: RTCTrackEvent) => void;
77
+ type TGetServerUrl = (id: string) => string;
77
78
  type TParametersConnection = TOptionsExtraHeaders & {
78
79
  displayName?: string;
79
80
  user?: string;
@@ -89,8 +90,30 @@ type TParametersConnection = TOptionsExtraHeaders & {
89
90
  connectionRecoveryMaxInterval?: number;
90
91
  userAgent?: string;
91
92
  };
93
+ type TParametersCreateUa = {
94
+ socket: WebSocketInterface;
95
+ displayName: string;
96
+ getSipServerUrl: TGetServerUrl;
97
+ user?: string;
98
+ register?: boolean;
99
+ password?: string;
100
+ sdpSemantics?: 'plan-b' | 'unified-plan';
101
+ sessionTimers?: boolean;
102
+ registerExpires?: number;
103
+ connectionRecoveryMinInterval?: number;
104
+ connectionRecoveryMaxInterval?: number;
105
+ userAgent?: string;
106
+ };
107
+ type TParametersCheckTelephony = {
108
+ displayName: string;
109
+ sipServerUrl: string;
110
+ sipWebSocketServerURL: string;
111
+ sdpSemantics?: 'plan-b' | 'unified-plan';
112
+ userAgent?: string;
113
+ };
92
114
  type TConnect = (parameters: TParametersConnection) => Promise<UA>;
93
- type TCreateUa = (parameters: TParametersConnection) => Promise<UA>;
115
+ type TInitUa = (parameters: TParametersConnection) => Promise<UA>;
116
+ type TCreateUa = (parameters: TParametersCreateUa) => UA;
94
117
  type TStart = () => Promise<UA>;
95
118
  type TSet = ({ displayName, password, }: {
96
119
  displayName?: string;
@@ -130,7 +153,7 @@ export default class SipConnector {
130
153
  private readonly _sessionEvents;
131
154
  private readonly _uaEvents;
132
155
  private readonly _cancelableConnect;
133
- private readonly _cancelableCreateUa;
156
+ private readonly _cancelableInitUa;
134
157
  private readonly _cancelableDisconnect;
135
158
  private readonly _cancelableSet;
136
159
  private readonly _cancelableCall;
@@ -148,7 +171,7 @@ export default class SipConnector {
148
171
  JsSIP: TJsSIP;
149
172
  });
150
173
  connect: TConnect;
151
- createUa: TCreateUa;
174
+ initUa: TInitUa;
152
175
  set: TSet;
153
176
  call: TCall;
154
177
  disconnect: TDisconnect;
@@ -160,6 +183,7 @@ export default class SipConnector {
160
183
  tryRegister: () => Promise<RegisteredEvent>;
161
184
  sendOptions(target: URI | string, body?: string, extraHeaders?: string[]): Promise<void>;
162
185
  ping(body?: string, extraHeaders?: string[]): Promise<void>;
186
+ checkTelephony({ userAgent, displayName, sipServerUrl, sipWebSocketServerURL, sdpSemantics, }: TParametersCheckTelephony): Promise<void>;
163
187
  replaceMediaStream(mediaStream: MediaStream, options?: {
164
188
  deleteExisting: boolean;
165
189
  addMissing: boolean;
@@ -225,11 +249,8 @@ export default class SipConnector {
225
249
  get isCallActive(): boolean;
226
250
  get isAvailableIncomingCall(): boolean;
227
251
  _connect: TConnect;
252
+ _initUa: TInitUa;
228
253
  _createUa: TCreateUa;
229
- _init({ sipServerUrl, sipWebSocketServerURL, }: {
230
- sipServerUrl: string;
231
- sipWebSocketServerURL: string;
232
- }): void;
233
254
  _start: TStart;
234
255
  _set: TSet;
235
256
  _disconnectWithoutCancelRequests: TDisconnect;
@@ -9,6 +9,9 @@ export declare const PASSWORD_CORRECT = "PASSWORD_CORRECT";
9
9
  export declare const PASSWORD_CORRECT_2 = "PASSWORD_CORRECT_2";
10
10
  export declare const NAME_INCORRECT = "NAME_INCORRECT";
11
11
  declare class UA implements IUA {
12
+ private static isAvailableTelephony;
13
+ static setAvailableTelephony(): void;
14
+ static setNotAvailableTelephony(): void;
12
15
  _events: Events<typeof UA_EVENT_NAMES>;
13
16
  _startedTimeout?: ReturnType<typeof setTimeout>;
14
17
  _stopedTimeout?: ReturnType<typeof setTimeout>;
@@ -32,6 +35,9 @@ declare class UA implements IUA {
32
35
  stop(): void;
33
36
  call: jest.Mock<Session, [url: string, parameters: any], any>;
34
37
  on(eventName: TEventUA, handler: any): this;
38
+ once(eventName: TEventUA, handler: any): this;
39
+ off(eventName: TEventUA, handler: any): this;
40
+ removeAllListeners(): this;
35
41
  trigger(eventName: TEventUA, data?: any): void;
36
42
  /**
37
43
  * terminateSessions
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var O=(o,t,e)=>t in o?N(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(O(o,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("./SipConnector-4TW1xlov.cjs"),W=require("@krivega/jssip/lib/NameAddrHeader"),k=require("@krivega/jssip/lib/URI"),D=require("node:events"),L=require("@krivega/jssip/lib/SIPMessage"),M=require("webrtc-mock"),R=require("events-constructor");require("@krivega/cancelable-promise");require("debug");class C extends L.IncomingRequest{constructor(e){super();r(this,"headers");this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)||""}}class P{constructor({originator:t="local",eventHandlers:e}){r(this,"originator");r(this,"_connection");r(this,"_events");r(this,"_remote_identity");r(this,"_mutedOptions",{audio:!1,video:!1});this.originator=t,this._events=new R(h.SESSION_EVENT_NAMES),this.initEvents(e)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(t){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get remote_identity(){return this._remote_identity}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(t){throw new Error("Method not implemented.")}terminate(t){throw new Error("Method not implemented.")}async sendInfo(t,e,n){throw new Error("Method not implemented.")}hold(t,e){throw new Error("Method not implemented.")}unhold(t,e){throw new Error("Method not implemented.")}async renegotiate(t,e){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(t){throw new Error("Method not implemented.")}unmute(t){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(t,e){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(t,e){throw new Error("Method not implemented.")}addListener(t,e){throw new Error("Method not implemented.")}once(t,e){throw new Error("Method not implemented.")}removeListener(t,e){throw new Error("Method not implemented.")}off(t,e){throw new Error("Method not implemented.")}removeAllListeners(t){throw new Error("Method not implemented.")}setMaxListeners(t){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(t){throw new Error("Method not implemented.")}rawListeners(t){throw new Error("Method not implemented.")}emit(t,...e){throw new Error("Method not implemented.")}listenerCount(t){throw new Error("Method not implemented.")}prependListener(t,e){throw new Error("Method not implemented.")}prependOnceListener(t,e){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(t=[]){Object.entries(t).forEach(([e,n])=>this.on(e,n))}on(t,e){return this._events.on(t,e),this}trigger(t,e){this._events.trigger(t,e)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(t){return t}async updatePresentation(t){return t}async stopPresentation(t){return t}isEstablished(){return!0}}class b{constructor(t,e){r(this,"_senders",[]);r(this,"_receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this._receivers);r(this,"getSenders",()=>this._senders);r(this,"addTrack",t=>{const e={track:t};return this._senders.push(e),e});this._receivers=e.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(t){throw new Error("Method not implemented.")}addTransceiver(t,e){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(t,e){throw new Error("Method not implemented.")}createDataChannel(t,e){throw new Error("Method not implemented.")}async createOffer(t,e,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(t){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(t){throw new Error("Method not implemented.")}setConfiguration(t){throw new Error("Method not implemented.")}async setLocalDescription(t){throw new Error("Method not implemented.")}async setRemoteDescription(t){throw new Error("Method not implemented.")}addEventListener(t,e,n){throw new Error("Method not implemented.")}removeEventListener(t,e,n){throw new Error("Method not implemented.")}dispatchEvent(t){throw new Error("Method not implemented.")}}function F(o){const t=o.match(/[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const g=400,S="777",V=o=>o.getVideoTracks().length>0;class T extends P{constructor({url:e="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"_isEnded",!1);r(this,"answer",jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},g)}));this.url=e,this.initPeerconnection(n)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const n=M.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(V(e)){const f=M.createVideoMediaStreamTrackMock();f.id="mainvideo1",i.push(f)}this._connection=new b(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},g)}connect(e){const n=F(e);setTimeout(()=>{this.url.includes(S)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:h.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",n)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},g)}terminate({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e}),this._isEnded=!1,this}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}_addStream(e,n="getTracks"){e[n]().forEach(i=>this.connection.addTrack(i))}_forEachSenders(e){const n=this.connection.getSenders();for(const i of n)e(i);return n}_toggleMuteAudio(e){this._forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!e)})}_toggleMuteVideo(e){this._forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!e)})}mute(e){e.audio&&(this._mutedOptions.audio=!0,this._toggleMuteAudio(this._mutedOptions.audio)),e.video&&(this._mutedOptions.video=!0,this._toggleMuteVideo(this._mutedOptions.video)),this._onmute(e)}unmute(e){e.audio&&(this._mutedOptions.audio=!1),e.video&&(this._mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this._mutedOptions}async replaceMediaStream(e){return e}_onmute({audio:e,video:n}){this.trigger("muted",{audio:e,video:n})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(e){this.trigger("newInfo",e)}}class U{constructor(){r(this,"extraHeaders")}setExtraHeaders(t){this.extraHeaders=t}setExtraContactParams(){}}const s="PASSWORD_CORRECT",_="PASSWORD_CORRECT_2",v="NAME_INCORRECT",c=400;class z{constructor(t){r(this,"_events");r(this,"_startedTimeout");r(this,"_stopedTimeout");r(this,"session");r(this,"_isRegistered");r(this,"_isConnected");r(this,"configuration");r(this,"_registrator");r(this,"call",jest.fn((t,e)=>{const{mediaStream:n,eventHandlers:i}=e;return this.session=new T({url:t,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(t),this.session}));this._events=new R(h.UA_EVENT_NAMES),this.configuration=t,this._registrator=new U}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(t,e){return this._events.on(t,e),this}trigger(t,e){this._events.trigger(t,e)}terminateSessions(){this.session.terminate()}set(t,e){return this.configuration[t]=e,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:t,register:e,uri:n}=this.configuration;e&&n.includes(v)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},c)):!this._isRegistered&&e&&(t===s||t===_)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},c)):e&&t!==s&&t!==_&&(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(t){this.trigger("sipEvent",t)}}class q{constructor(t){r(this,"url");this.url=t}}class x extends D.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const p="remote",H=(o,t)=>{const e=new C(t),n={originator:p,request:e,info:new x("","")};o.newInfo(n)},B=(o,t)=>{const n={request:new C(t)};o.newSipEvent(n)},$=(o,{incomingNumber:t="1234",displayName:e,host:n})=>{const i=new T({originator:p}),d=new k("sip",t,n);i._remote_identity=new W(d,e),o.trigger("newRTCSession",{originator:p,session:i})},j=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},y={triggerNewInfo:H,triggerNewSipEvent:B,triggerIncomingSession:$,triggerFailIncomingSession:j,WebSocketInterface:q,UA:z,C:{INVITE:"INVITE"}},m="user",a="displayName",u="SIP_SERVER_URL",w="SIP_WEB_SOCKET_SERVER_URL",K=new y.WebSocketInterface(w),E={userAgent:"Chrome",sipServerUrl:u,sipWebSocketServerURL:w},J={...E},A={...E,user:m,password:s,register:!0},Y={...A,displayName:a},G={...E,displayName:a,register:!1},l={session_timers:!1,sockets:[K],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},X={...l,password:s,uri:`sip:${m}@${u}`,display_name:"",register:!0},Q={...l,password:s,uri:`sip:${m}@${u}`,display_name:a,register:!0},Z={...l,display_name:a,register:!1},ee={...l,display_name:"",register:!1},I="10.10.10.10",te=[`X-Vinteo-Remote: ${I}`],re=()=>new h.SipConnector({JsSIP:y});exports.FAILED_CONFERENCE_NUMBER=S;exports.NAME_INCORRECT=v;exports.PASSWORD_CORRECT=s;exports.PASSWORD_CORRECT_2=_;exports.SIP_SERVER_URL=u;exports.SIP_WEB_SOCKET_SERVER_URL=w;exports.dataForConnectionWithAuthorization=A;exports.dataForConnectionWithAuthorizationWithDisplayName=Y;exports.dataForConnectionWithoutAuthorization=G;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=J;exports.default=re;exports.displayName=a;exports.extraHeadersRemoteAddress=te;exports.remoteAddress=I;exports.uaConfigurationWithAuthorization=X;exports.uaConfigurationWithAuthorizationWithDisplayName=Q;exports.uaConfigurationWithoutAuthorization=Z;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ee;exports.user=m;
1
+ "use strict";var D=Object.defineProperty;var k=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(k(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./SipConnector-Q7QLgdlo.cjs"),L=require("@krivega/jssip/lib/NameAddrHeader"),P=require("@krivega/jssip/lib/URI"),x=require("node:events"),F=require("@krivega/jssip/lib/SIPMessage"),M=require("events-constructor");require("@krivega/cancelable-promise");require("debug");class T extends F.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var V=Object.defineProperty,z=(r,e,t)=>e in r?V(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>(z(r,typeof e!="symbol"?e+"":e,t),t);const m="ended",q="mute",U="isolationchange",H="overconstrained",j="unmute",$=[m,q,j,U,H];class y{constructor(e,{id:t="identifier",constraints:i={}}={}){s(this,"events"),s(this,"id"),s(this,"kind"),s(this,"constraints"),s(this,"enabled"),s(this,"contentHint",""),s(this,"readyState","live"),s(this,"isolated",!1),s(this,"label",""),s(this,"muted",!1),s(this,"onended",null),s(this,"onisolationchange",null),s(this,"onmute",null),s(this,"onunmute",null),s(this,"getConstraints",()=>this.constraints),s(this,"stop",()=>{const o={...new Event(m)};this.events.trigger(m,o),this.readyState=m,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,a)=>{this.events.on(o,a)}),s(this,"removeEventListener",(o,a)=>{this.events.off(o,a)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...i},this.events=new M($)}clone(){return{...this}}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){let e=0,t=0;return typeof this.constraints.width=="object"&&this.constraints.width.ideal!==void 0?e=this.constraints.width.ideal:typeof this.constraints.width=="object"&&this.constraints.width.exact!==void 0?e=this.constraints.width.exact:typeof this.constraints.width=="number"&&this.constraints.width&&(e=this.constraints.width),typeof this.constraints.height=="object"&&this.constraints.height.ideal!==void 0?t=this.constraints.height.ideal:typeof this.constraints.height=="object"&&this.constraints.height.exact!==void 0?t=this.constraints.height.exact:typeof this.constraints.height=="number"&&this.constraints.height&&(t=this.constraints.height),{width:e,height:t}}async applyConstraints(e){this.constraints={...e}}dispatchEvent(e){const t=e.type;return this.events.trigger(t,e),!0}}const B=r=>new y("audio",r),K=r=>new y("video",r);class Y{constructor({originator:e="local",eventHandlers:t}){n(this,"originator");n(this,"_connection");n(this,"_events");n(this,"_remote_identity");n(this,"_mutedOptions",{audio:!1,video:!1});this.originator=e,this._events=new M(l.SESSION_EVENT_NAMES),this.initEvents(t)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get remote_identity(){return this._remote_identity}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,i){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e=[]){Object.entries(e).forEach(([t,i])=>this.on(t,i))}on(e,t){return this._events.on(e,t),this}trigger(e,t){this._events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class J{constructor(e,t){n(this,"_senders",[]);n(this,"_receivers",[]);n(this,"canTrickleIceCandidates");n(this,"connectionState");n(this,"currentLocalDescription");n(this,"currentRemoteDescription");n(this,"iceConnectionState");n(this,"iceGatheringState");n(this,"idpErrorInfo");n(this,"idpLoginUrl");n(this,"localDescription");n(this,"onconnectionstatechange");n(this,"ondatachannel");n(this,"onicecandidate");n(this,"onicecandidateerror",null);n(this,"oniceconnectionstatechange");n(this,"onicegatheringstatechange");n(this,"onnegotiationneeded");n(this,"onsignalingstatechange");n(this,"ontrack");n(this,"peerIdentity");n(this,"pendingLocalDescription");n(this,"pendingRemoteDescription");n(this,"remoteDescription");n(this,"sctp",null);n(this,"signalingState");n(this,"getReceivers",()=>this._receivers);n(this,"getSenders",()=>this._senders);n(this,"addTrack",e=>{const t={track:e};return this._senders.push(t),t});this._receivers=t.map(i=>({track:i}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,i){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,i){throw new Error("Method not implemented.")}removeEventListener(e,t,i){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function G(r){const e=r.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const w=400,A="777",X=r=>r.getVideoTracks().length>0;class b extends Y{constructor({url:t="",mediaStream:i,eventHandlers:o,originator:a}){super({originator:a,eventHandlers:o});n(this,"url");n(this,"status_code");n(this,"_isEnded",!1);n(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},w)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=B();i.id="mainaudio1";const o=[i];if(X(t)){const S=K();S.id="mainvideo1",o.push(S)}this._connection=new J(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(t){const i=G(t);setTimeout(()=>{this.url.includes(A)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:l.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",i)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},w)}terminate({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t}),this._isEnded=!1,this}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}_addStream(t,i="getTracks"){t[i]().forEach(o=>this.connection.addTrack(o))}_forEachSenders(t){const i=this.connection.getSenders();for(const o of i)t(o);return i}_toggleMuteAudio(t){this._forEachSenders(({track:i})=>{i&&i.kind==="audio"&&(i.enabled=!t)})}_toggleMuteVideo(t){this._forEachSenders(({track:i})=>{i&&i.kind==="video"&&(i.enabled=!t)})}mute(t){t.audio&&(this._mutedOptions.audio=!0,this._toggleMuteAudio(this._mutedOptions.audio)),t.video&&(this._mutedOptions.video=!0,this._toggleMuteVideo(this._mutedOptions.video)),this._onmute(t)}unmute(t){t.audio&&(this._mutedOptions.audio=!1),t.video&&(this._mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this._mutedOptions}async replaceMediaStream(t){return t}_onmute({audio:t,video:i}){this.trigger("muted",{audio:t,video:i})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(t){this.trigger("newInfo",t)}}class Q{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",E="PASSWORD_CORRECT_2",I="NAME_INCORRECT",c=400,u=class u{constructor(e){n(this,"_events");n(this,"_startedTimeout");n(this,"_stopedTimeout");n(this,"session");n(this,"_isRegistered");n(this,"_isConnected");n(this,"configuration");n(this,"_registrator");n(this,"call",jest.fn((e,t)=>{const{mediaStream:i,eventHandlers:o}=t;return this.session=new b({url:e,mediaStream:i,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new M(l.UA_EVENT_NAMES),this.configuration=e,this._registrator=new Q}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},c):this.trigger("disconnected",{error:new Error("stoped")})}on(e,t){return this._events.on(e,t),this}once(e,t){return this._events.once(e,t),this}off(e,t){return this._events.off(e,t),this}removeAllListeners(){return this._events.removeEventHandlers(),this}trigger(e,t){this._events.trigger(e,t)}terminateSessions(){this.session.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:e,register:t,uri:i}=this.configuration;t&&i.includes(I)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},c)):!this._isRegistered&&t&&(e===d||e===E)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},c)):t&&e!==d&&e!==E&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},c)),u.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(e){this.trigger("sipEvent",e)}};n(u,"isAvailableTelephony",!0);let f=u;class Z{constructor(e){n(this,"url");this.url=e}}class ee extends x.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const v="remote",te=(r,e)=>{const t=new T(e),i={originator:v,request:t,info:new ee("","")};r.newInfo(i)},ne=(r,e)=>{const i={request:new T(e)};r.newSipEvent(i)},ie=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:v}),a=new P("sip",e,i);o._remote_identity=new L(a,t),r.trigger("newRTCSession",{originator:v,session:o})},re=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},O={triggerNewInfo:te,triggerNewSipEvent:ne,triggerIncomingSession:ie,triggerFailIncomingSession:re,WebSocketInterface:Z,UA:f,C:{INVITE:"INVITE"}},g="user",h="displayName",_="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",oe=new O.WebSocketInterface(C),R={userAgent:"Chrome",sipServerUrl:_,sipWebSocketServerURL:C},se={...R},N={...R,user:g,password:d,register:!0},ae={...N,displayName:h},de={...R,displayName:h,register:!1},p={session_timers:!1,sockets:[oe],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},he={...p,password:d,uri:`sip:${g}@${_}`,display_name:"",register:!0},ce={...p,password:d,uri:`sip:${g}@${_}`,display_name:h,register:!0},me={...p,display_name:h,register:!1},ue={...p,display_name:"",register:!1},W="10.10.10.10",le=[`X-Vinteo-Remote: ${W}`],ge=()=>new l.SipConnector({JsSIP:O});exports.FAILED_CONFERENCE_NUMBER=A;exports.NAME_INCORRECT=I;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=E;exports.SIP_SERVER_URL=_;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=N;exports.dataForConnectionWithAuthorizationWithDisplayName=ae;exports.dataForConnectionWithoutAuthorization=de;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=se;exports.default=ge;exports.displayName=h;exports.extraHeadersRemoteAddress=le;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=he;exports.uaConfigurationWithAuthorizationWithDisplayName=ce;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ue;exports.user=g;