sip-connector 6.20.0 → 6.21.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.
@@ -1,8 +1,4 @@
1
- import type { UA, URI, WebSocketInterface } from '@krivega/jssip';
2
- import type RTCSession from '@krivega/jssip/lib/RTCSession';
3
- import type { IncomingInfoEvent, OutgoingInfoEvent } from '@krivega/jssip/lib/RTCSession';
4
- import type { IncomingRequest } from '@krivega/jssip/lib/SIPMessage';
5
- import type { IncomingRTCSessionEvent, RegisteredEvent, UnRegisteredEvent } from '@krivega/jssip/lib/UA';
1
+ import type { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
6
2
  import type { TEventSession, TEventUA } from './eventNames';
7
3
  import type { TCustomError, TJsSIP } from './types';
8
4
  export declare const hasCanceledCallError: (error?: TCustomError) => boolean;
@@ -0,0 +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;
@@ -0,0 +1,3 @@
1
+ import SIPconnector from './SipConnector';
2
+ declare const doMock: () => SIPconnector;
3
+ export default doMock;
package/dist/doMock.js ADDED
@@ -0,0 +1,629 @@
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";
10
+ import "@krivega/cancelable-promise";
11
+ import "debug";
12
+ class p extends O {
13
+ constructor(t) {
14
+ super();
15
+ n(this, "headers");
16
+ this.headers = new Headers(t);
17
+ }
18
+ getHeader(t) {
19
+ return this.headers.get(t) || "";
20
+ }
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 _ {
25
+ constructor(e, { id: t = "identifier", constraints: r = {} } = {}) {
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);
34
+ }
35
+ clone() {
36
+ return { ...this };
37
+ }
38
+ getCapabilities() {
39
+ return {
40
+ width: { min: 352, max: 4096 },
41
+ height: { min: 288, max: 2160 }
42
+ };
43
+ }
44
+ getSettings() {
45
+ let e = 0, t = 0;
46
+ 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), {
47
+ width: e,
48
+ height: t
49
+ };
50
+ }
51
+ async applyConstraints(e) {
52
+ this.constraints = { ...e };
53
+ }
54
+ dispatchEvent(e) {
55
+ const t = e.type;
56
+ return this.events.trigger(t, e), !0;
57
+ }
58
+ }
59
+ const x = (i) => new _("audio", i), j = (i) => new _("video", i);
60
+ class H {
61
+ // @ts-expect-error
62
+ constructor({ originator: e = "local", eventHandlers: t }) {
63
+ n(this, "originator");
64
+ n(this, "_connection");
65
+ n(this, "_events");
66
+ n(this, "_remote_identity");
67
+ n(this, "_mutedOptions", { audio: !1, video: !1 });
68
+ this.originator = e, this._events = new l(v), this.initEvents(t);
69
+ }
70
+ // @ts-expect-error
71
+ get C() {
72
+ throw new Error("Method not implemented.");
73
+ }
74
+ // @ts-expect-error
75
+ get causes() {
76
+ throw new Error("Method not implemented.");
77
+ }
78
+ get id() {
79
+ throw new Error("Method not implemented.");
80
+ }
81
+ set data(e) {
82
+ throw new Error("Method not implemented.");
83
+ }
84
+ get data() {
85
+ throw new Error("Method not implemented.");
86
+ }
87
+ get connection() {
88
+ return this._connection;
89
+ }
90
+ get contact() {
91
+ throw new Error("Method not implemented.");
92
+ }
93
+ get direction() {
94
+ throw new Error("Method not implemented.");
95
+ }
96
+ get local_identity() {
97
+ throw new Error("Method not implemented.");
98
+ }
99
+ get remote_identity() {
100
+ return this._remote_identity;
101
+ }
102
+ get start_time() {
103
+ throw new Error("Method not implemented.");
104
+ }
105
+ get end_time() {
106
+ throw new Error("Method not implemented.");
107
+ }
108
+ get status() {
109
+ throw new Error("Method not implemented.");
110
+ }
111
+ isInProgress() {
112
+ throw new Error("Method not implemented.");
113
+ }
114
+ isEnded() {
115
+ throw new Error("Method not implemented.");
116
+ }
117
+ isReadyToReOffer() {
118
+ throw new Error("Method not implemented.");
119
+ }
120
+ answer(e) {
121
+ throw new Error("Method not implemented.");
122
+ }
123
+ terminate(e) {
124
+ throw new Error("Method not implemented.");
125
+ }
126
+ async sendInfo(e, t, r) {
127
+ throw new Error("Method not implemented.");
128
+ }
129
+ hold(e, t) {
130
+ throw new Error("Method not implemented.");
131
+ }
132
+ unhold(e, t) {
133
+ throw new Error("Method not implemented.");
134
+ }
135
+ async renegotiate(e, t) {
136
+ throw new Error("Method not implemented.");
137
+ }
138
+ isOnHold() {
139
+ throw new Error("Method not implemented.");
140
+ }
141
+ mute(e) {
142
+ throw new Error("Method not implemented.");
143
+ }
144
+ unmute(e) {
145
+ throw new Error("Method not implemented.");
146
+ }
147
+ isMuted() {
148
+ throw new Error("Method not implemented.");
149
+ }
150
+ refer(e, t) {
151
+ throw new Error("Method not implemented.");
152
+ }
153
+ resetLocalMedia() {
154
+ throw new Error("Method not implemented.");
155
+ }
156
+ async replaceMediaStream(e, t) {
157
+ throw new Error("Method not implemented.");
158
+ }
159
+ addListener(e, t) {
160
+ throw new Error("Method not implemented.");
161
+ }
162
+ once(e, t) {
163
+ throw new Error("Method not implemented.");
164
+ }
165
+ removeListener(e, t) {
166
+ throw new Error("Method not implemented.");
167
+ }
168
+ off(e, t) {
169
+ throw new Error("Method not implemented.");
170
+ }
171
+ removeAllListeners(e) {
172
+ throw new Error("Method not implemented.");
173
+ }
174
+ setMaxListeners(e) {
175
+ throw new Error("Method not implemented.");
176
+ }
177
+ getMaxListeners() {
178
+ throw new Error("Method not implemented.");
179
+ }
180
+ listeners(e) {
181
+ throw new Error("Method not implemented.");
182
+ }
183
+ rawListeners(e) {
184
+ throw new Error("Method not implemented.");
185
+ }
186
+ emit(e, ...t) {
187
+ throw new Error("Method not implemented.");
188
+ }
189
+ listenerCount(e) {
190
+ throw new Error("Method not implemented.");
191
+ }
192
+ prependListener(e, t) {
193
+ throw new Error("Method not implemented.");
194
+ }
195
+ prependOnceListener(e, t) {
196
+ throw new Error("Method not implemented.");
197
+ }
198
+ eventNames() {
199
+ throw new Error("Method not implemented.");
200
+ }
201
+ /**
202
+ * initEvents
203
+ *
204
+ * @param {Array} [eventHandlers=[] - ] The event handlers
205
+ *
206
+ * @returns {undefined}
207
+ */
208
+ initEvents(e = []) {
209
+ Object.entries(e).forEach(([t, r]) => this.on(t, r));
210
+ }
211
+ // @ts-expect-error
212
+ on(e, t) {
213
+ return this._events.on(e, t), this;
214
+ }
215
+ trigger(e, t) {
216
+ this._events.trigger(e, t);
217
+ }
218
+ /**
219
+ * sendDTMF
220
+ *
221
+ * @param {object} options - options
222
+ *
223
+ * @returns {undefined}
224
+ */
225
+ sendDTMF() {
226
+ this.trigger("newDTMF", { originator: this.originator });
227
+ }
228
+ async startPresentation(e) {
229
+ return e;
230
+ }
231
+ async updatePresentation(e) {
232
+ return e;
233
+ }
234
+ async stopPresentation(e) {
235
+ return e;
236
+ }
237
+ isEstablished() {
238
+ return !0;
239
+ }
240
+ }
241
+ class V {
242
+ constructor(e, t) {
243
+ n(this, "_senders", []);
244
+ n(this, "_receivers", []);
245
+ n(this, "canTrickleIceCandidates");
246
+ n(this, "connectionState");
247
+ n(this, "currentLocalDescription");
248
+ n(this, "currentRemoteDescription");
249
+ n(this, "iceConnectionState");
250
+ n(this, "iceGatheringState");
251
+ n(this, "idpErrorInfo");
252
+ n(this, "idpLoginUrl");
253
+ n(this, "localDescription");
254
+ n(this, "onconnectionstatechange");
255
+ n(this, "ondatachannel");
256
+ n(this, "onicecandidate");
257
+ n(this, "onicecandidateerror", null);
258
+ n(this, "oniceconnectionstatechange");
259
+ n(this, "onicegatheringstatechange");
260
+ n(this, "onnegotiationneeded");
261
+ n(this, "onsignalingstatechange");
262
+ n(this, "ontrack");
263
+ n(this, "peerIdentity");
264
+ n(this, "pendingLocalDescription");
265
+ n(this, "pendingRemoteDescription");
266
+ n(this, "remoteDescription");
267
+ n(this, "sctp", null);
268
+ n(this, "signalingState");
269
+ n(this, "getReceivers", () => this._receivers);
270
+ n(this, "getSenders", () => this._senders);
271
+ n(this, "addTrack", (e) => {
272
+ const t = { track: e };
273
+ return this._senders.push(t), t;
274
+ });
275
+ this._receivers = t.map((r) => ({ track: r }));
276
+ }
277
+ getRemoteStreams() {
278
+ throw new Error("Method not implemented.");
279
+ }
280
+ async addIceCandidate(e) {
281
+ throw new Error("Method not implemented.");
282
+ }
283
+ addTransceiver(e, t) {
284
+ throw new Error("Method not implemented.");
285
+ }
286
+ close() {
287
+ throw new Error("Method not implemented.");
288
+ }
289
+ restartIce() {
290
+ throw new Error("Method not implemented.");
291
+ }
292
+ async createAnswer(e, t) {
293
+ throw new Error("Method not implemented.");
294
+ }
295
+ createDataChannel(e, t) {
296
+ throw new Error("Method not implemented.");
297
+ }
298
+ async createOffer(e, t, r) {
299
+ throw new Error("Method not implemented.");
300
+ }
301
+ getConfiguration() {
302
+ throw new Error("Method not implemented.");
303
+ }
304
+ async getIdentityAssertion() {
305
+ throw new Error("Method not implemented.");
306
+ }
307
+ async getStats(e) {
308
+ throw new Error("Method not implemented.");
309
+ }
310
+ getTransceivers() {
311
+ throw new Error("Method not implemented.");
312
+ }
313
+ removeTrack(e) {
314
+ throw new Error("Method not implemented.");
315
+ }
316
+ setConfiguration(e) {
317
+ throw new Error("Method not implemented.");
318
+ }
319
+ async setLocalDescription(e) {
320
+ throw new Error("Method not implemented.");
321
+ }
322
+ async setRemoteDescription(e) {
323
+ throw new Error("Method not implemented.");
324
+ }
325
+ addEventListener(e, t, r) {
326
+ throw new Error("Method not implemented.");
327
+ }
328
+ removeEventListener(e, t, r) {
329
+ throw new Error("Method not implemented.");
330
+ }
331
+ dispatchEvent(e) {
332
+ throw new Error("Method not implemented.");
333
+ }
334
+ }
335
+ function F(i) {
336
+ const e = i.match(/[\d.]+/g);
337
+ if (!e)
338
+ throw new Error("wrong sip url");
339
+ return e[0];
340
+ }
341
+ const c = 400, U = "777", W = (i) => i.getVideoTracks().length > 0;
342
+ class E extends H {
343
+ constructor({
344
+ url: t = "",
345
+ mediaStream: r,
346
+ eventHandlers: o,
347
+ originator: d
348
+ }) {
349
+ super({ originator: d, eventHandlers: o });
350
+ n(this, "url");
351
+ n(this, "status_code");
352
+ n(this, "_isEnded", !1);
353
+ /**
354
+ * answer
355
+ *
356
+ * @param {Object} arg1 - The argument 1
357
+ * @param {Object} arg1.mediaStream - The media stream
358
+ * @param {Array} arg1.eventHandlers - The event handlers
359
+
360
+ * @returns {undefined}
361
+ */
362
+ n(this, "answer", jest.fn(({ mediaStream: t }) => {
363
+ if (this.originator !== "remote")
364
+ throw new Error("answer available only for remote sessions");
365
+ this.initPeerconnection(t), setTimeout(() => {
366
+ this.trigger("connecting"), setTimeout(() => {
367
+ this.trigger("accepted");
368
+ }, 100), setTimeout(() => {
369
+ this.trigger("confirmed");
370
+ }, 200);
371
+ }, c);
372
+ }));
373
+ this.url = t, this.initPeerconnection(r);
374
+ }
375
+ initPeerconnection(t) {
376
+ return t ? (this.createPeerconnection(t), !0) : !1;
377
+ }
378
+ createPeerconnection(t) {
379
+ const r = x();
380
+ r.id = "mainaudio1";
381
+ const o = [r];
382
+ if (W(t)) {
383
+ const g = j();
384
+ g.id = "mainvideo1", o.push(g);
385
+ }
386
+ this._connection = new V(void 0, o), this._addStream(t), setTimeout(() => {
387
+ this.trigger("peerconnection", { peerconnection: this.connection });
388
+ }, c);
389
+ }
390
+ connect(t) {
391
+ const r = F(t);
392
+ setTimeout(() => {
393
+ this.url.includes(U) ? this.trigger("failed", {
394
+ originator: "remote",
395
+ message: "IncomingResponse",
396
+ cause: T
397
+ }) : (this.trigger("connecting"), setTimeout(() => {
398
+ this.trigger("enterRoom", r);
399
+ }, 100), setTimeout(() => {
400
+ this.trigger("accepted");
401
+ }, 200), setTimeout(() => {
402
+ this.trigger("confirmed");
403
+ }, 300));
404
+ }, c);
405
+ }
406
+ terminate({ status_code: t } = {}) {
407
+ return this.status_code = t, this.trigger("ended", { status_code: t }), this._isEnded = !1, this;
408
+ }
409
+ terminateRemote({ status_code: t } = {}) {
410
+ return this.status_code = t, this.trigger("ended", { status_code: t, originator: "remote" }), this;
411
+ }
412
+ _addStream(t, r = "getTracks") {
413
+ t[r]().forEach((o) => this.connection.addTrack(o));
414
+ }
415
+ _forEachSenders(t) {
416
+ const r = this.connection.getSenders();
417
+ for (const o of r)
418
+ t(o);
419
+ return r;
420
+ }
421
+ /* eslint-disable no-param-reassign */
422
+ _toggleMuteAudio(t) {
423
+ this._forEachSenders(({ track: r }) => {
424
+ r && r.kind === "audio" && (r.enabled = !t);
425
+ });
426
+ }
427
+ /* eslint-enable no-param-reassign */
428
+ /* eslint-disable no-param-reassign */
429
+ _toggleMuteVideo(t) {
430
+ this._forEachSenders(({ track: r }) => {
431
+ r && r.kind === "video" && (r.enabled = !t);
432
+ });
433
+ }
434
+ mute(t) {
435
+ 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);
436
+ }
437
+ unmute(t) {
438
+ t.audio && (this._mutedOptions.audio = !1), t.video && (this._mutedOptions.video = !1), this.trigger("unmuted", t);
439
+ }
440
+ isMuted() {
441
+ return this._mutedOptions;
442
+ }
443
+ async replaceMediaStream(t) {
444
+ return t;
445
+ }
446
+ _onmute({ audio: t, video: r }) {
447
+ this.trigger("muted", {
448
+ audio: t,
449
+ video: r
450
+ });
451
+ }
452
+ async sendInfo() {
453
+ }
454
+ isEnded() {
455
+ return this._isEnded;
456
+ }
457
+ newInfo(t) {
458
+ this.trigger("newInfo", t);
459
+ }
460
+ /* eslint-enable no-param-reassign */
461
+ }
462
+ class q {
463
+ constructor() {
464
+ n(this, "extraHeaders");
465
+ }
466
+ setExtraHeaders(e) {
467
+ this.extraHeaders = e;
468
+ }
469
+ setExtraContactParams() {
470
+ }
471
+ }
472
+ const u = "PASSWORD_CORRECT", w = "PASSWORD_CORRECT_2", Y = "NAME_INCORRECT", h = 400;
473
+ class $ {
474
+ constructor(e) {
475
+ n(this, "_events");
476
+ n(this, "_startedTimeout");
477
+ n(this, "_stopedTimeout");
478
+ n(this, "session");
479
+ n(this, "_isRegistered");
480
+ n(this, "_isConnected");
481
+ n(this, "configuration");
482
+ n(this, "_registrator");
483
+ // @ts-expect-error
484
+ n(this, "call", jest.fn((e, t) => {
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;
487
+ }));
488
+ this._events = new l(R), this.configuration = e, this._registrator = new q();
489
+ }
490
+ /**
491
+ * start
492
+ *
493
+ * @returns {undefined}
494
+ */
495
+ start() {
496
+ this.register();
497
+ }
498
+ /**
499
+ * stop
500
+ *
501
+ * @returns {undefined}
502
+ */
503
+ stop() {
504
+ this._startedTimeout && clearTimeout(this._startedTimeout), this._stopedTimeout && clearTimeout(this._stopedTimeout), this.unregister(), this.isStarted() ? this._stopedTimeout = setTimeout(() => {
505
+ this.trigger("disconnected", { error: new Error("stoped") });
506
+ }, h) : this.trigger("disconnected", { error: new Error("stoped") });
507
+ }
508
+ // @ts-expect-error
509
+ on(e, t) {
510
+ return this._events.on(e, t), this;
511
+ }
512
+ trigger(e, t) {
513
+ this._events.trigger(e, t);
514
+ }
515
+ /**
516
+ * terminateSessions
517
+ *
518
+ * @returns {undefined}
519
+ */
520
+ terminateSessions() {
521
+ this.session.terminate();
522
+ }
523
+ /**
524
+ * set
525
+ *
526
+ * @param {string} key - key
527
+ * @param {string} value - value
528
+ *
529
+ * @returns {boolean} true
530
+ */
531
+ set(e, t) {
532
+ return this.configuration[e] = t, !0;
533
+ }
534
+ /**
535
+ * register
536
+ *
537
+ * @returns {undefined}
538
+ */
539
+ register() {
540
+ this._startedTimeout && clearTimeout(this._startedTimeout);
541
+ const { password: e, register: t, uri: r } = this.configuration;
542
+ t && r.includes(Y) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
543
+ this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
544
+ }, h)) : !this._isRegistered && t && (e === u || e === w) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
545
+ this.trigger("registered");
546
+ }, h)) : t && e !== u && e !== w && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
547
+ this.trigger("registrationFailed", { response: null, cause: "Wrong credentials" });
548
+ }, h)), this.trigger("connected"), this._isConnected = !0;
549
+ }
550
+ /**
551
+ * unregister
552
+ *
553
+ * @returns {undefined}
554
+ */
555
+ unregister() {
556
+ this._isRegistered = !1, this._isConnected = !1, this.trigger("unregistered");
557
+ }
558
+ /**
559
+ * isRegistered
560
+ *
561
+ * @returns {boolean} isRegistered
562
+ */
563
+ isRegistered() {
564
+ return !!this._isRegistered;
565
+ }
566
+ /**
567
+ * isStarted
568
+ *
569
+ * @returns {boolean} isStarted
570
+ */
571
+ isStarted() {
572
+ return this.configuration && (this.configuration.register && !!this._isRegistered || !this.configuration.register && !!this._isConnected);
573
+ }
574
+ registrator() {
575
+ return this._registrator;
576
+ }
577
+ newSipEvent(e) {
578
+ this.trigger("sipEvent", e);
579
+ }
580
+ }
581
+ class B {
582
+ constructor(e) {
583
+ n(this, "url");
584
+ this.url = e;
585
+ }
586
+ }
587
+ class J extends I {
588
+ constructor(t, r) {
589
+ super();
590
+ n(this, "contentType");
591
+ n(this, "body");
592
+ this.contentType = t, this.body = r;
593
+ }
594
+ }
595
+ const m = "remote", G = (i, e) => {
596
+ const t = new p(e), r = {
597
+ originator: m,
598
+ request: t,
599
+ info: new J("", "")
600
+ };
601
+ i.newInfo(r);
602
+ }, K = (i, e) => {
603
+ const r = { request: new p(e) };
604
+ i.newSipEvent(r);
605
+ }, z = (i, {
606
+ incomingNumber: e = "1234",
607
+ displayName: t,
608
+ host: r
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) => {
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: $,
621
+ C: {
622
+ INVITE: "INVITE"
623
+ }
624
+ }, he = () => new S({
625
+ JsSIP: X
626
+ });
627
+ export {
628
+ he as default
629
+ };