sip-connector 9.2.1 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1309 @@
1
+ var At = Object.defineProperty;
2
+ var Rt = (s, e, t) => e in s ? At(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var o = (s, e, t) => Rt(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { CancelableRequest as g, isCanceledError as It } from "@krivega/cancelable-promise";
5
+ import De from "events-constructor";
6
+ import { repeatedCallsAsync as pe } from "repeated-calls";
7
+ import x from "debug";
8
+ const ft = "Connection Error", Le = "Request Timeout", mt = "SIP Failure Code", Pt = "Internal Error", Ot = "Busy", He = "Rejected", Dt = "Redirected", pt = "Unavailable", Mt = "Not Found", vt = "Address Incomplete", yt = "Incompatible SDP", wt = "Missing SDP", bt = "Authentication Error", We = "Terminated", Ut = "WebRTC Error", ke = "Canceled", Lt = "No Answer", Ht = "Expires", Wt = "No ACK", kt = "Dialog Error", Bt = "User Denied Media Access", qt = "Bad Media Description", Ft = "RTP Timeout", cs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
+ __proto__: null,
10
+ ADDRESS_INCOMPLETE: vt,
11
+ AUTHENTICATION_ERROR: bt,
12
+ BAD_MEDIA_DESCRIPTION: qt,
13
+ BUSY: Ot,
14
+ BYE: We,
15
+ CANCELED: ke,
16
+ CONNECTION_ERROR: ft,
17
+ DIALOG_ERROR: kt,
18
+ EXPIRES: Ht,
19
+ INCOMPATIBLE_SDP: yt,
20
+ INTERNAL_ERROR: Pt,
21
+ MISSING_SDP: wt,
22
+ NOT_FOUND: Mt,
23
+ NO_ACK: Wt,
24
+ NO_ANSWER: Lt,
25
+ REDIRECTED: Dt,
26
+ REJECTED: He,
27
+ REQUEST_TIMEOUT: Le,
28
+ RTP_TIMEOUT: Ft,
29
+ SIP_FAILURE_CODE: mt,
30
+ UNAVAILABLE: pt,
31
+ USER_DENIED_MEDIA_ACCESS: Bt,
32
+ WEBRTC_ERROR: Ut
33
+ }, Symbol.toStringTag, { value: "Module" })), V = "incomingCall", Y = "declinedIncomingCall", G = "failedIncomingCall", $ = "terminatedIncomingCall", H = "connecting", f = "connected", S = "disconnected", M = "newRTCSession", m = "registered", J = "unregistered", P = "registrationFailed", Be = "newMessage", X = "sipEvent", z = "availableSecondRemoteStream", Q = "notAvailableSecondRemoteStream", j = "mustStopPresentation", v = "shareState", K = "enterRoom", Z = "useLicense", ee = "peerconnection:confirmed", te = "peerconnection:ontrack", y = "channels", ne = "channels:notify", se = "ended:fromserver", ie = "main-cam-control", oe = "admin-stop-main-cam", re = "admin-start-main-cam", ae = "admin-stop-mic", ce = "admin-start-mic", w = "admin-force-sync-media-state", _e = "participant:added-to-list-moderators", Ee = "participant:removed-from-list-moderators", de = "participant:move-request-to-stream", he = "participant:move-request-to-spectators", le = "participation:accepting-word-request", Te = "participation:cancelling-word-request", ue = "webcast:started", Se = "webcast:stopped", Ne = "account:changed", ge = "account:deleted", Ce = "conference:participant-token-issued", O = "ended", qe = "sending", Fe = "reinvite", xe = "replaces", Ve = "refer", Ye = "progress", Ge = "accepted", b = "confirmed", U = "peerconnection", A = "failed", $e = "muted", Je = "unmuted", Ae = "newDTMF", Re = "newInfo", Xe = "hold", ze = "unhold", Qe = "update", je = "sdp", Ke = "icecandidate", Ze = "getusermediafailed", et = "peerconnection:createofferfailed", tt = "peerconnection:createanswerfailed", nt = "peerconnection:setlocaldescriptionfailed", st = "peerconnection:setremotedescriptionfailed", it = "presentation:start", ot = "presentation:started", rt = "presentation:end", Ie = "presentation:ended", L = "presentation:failed", at = "SPECTATOR", ct = 1e6, _s = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
34
+ __proto__: null,
35
+ ACCEPTED: Ge,
36
+ ACCOUNT_CHANGED: Ne,
37
+ ACCOUNT_DELETED: ge,
38
+ ADMIN_FORCE_SYNC_MEDIA_STATE: w,
39
+ ADMIN_START_MAIN_CAM: re,
40
+ ADMIN_START_MIC: ce,
41
+ ADMIN_STOP_MAIN_CAM: oe,
42
+ ADMIN_STOP_MIC: ae,
43
+ AVAILABLE_SECOND_REMOTE_STREAM_EVENT: z,
44
+ CHANNELS: y,
45
+ CHANNELS_NOTIFY: ne,
46
+ CONFERENCE_PARTICIPANT_TOKEN_ISSUED: Ce,
47
+ CONFIRMED: b,
48
+ CONNECTED: f,
49
+ CONNECTING: H,
50
+ DECLINED_INCOMING_CALL: Y,
51
+ DISCONNECTED: S,
52
+ ENDED: O,
53
+ ENDED_FROM_SERVER: se,
54
+ ENTER_ROOM: K,
55
+ FAILED: A,
56
+ FAILED_INCOMING_CALL: G,
57
+ GET_USER_MEDIA_FAILED: Ze,
58
+ HOLD: Xe,
59
+ ICE_CANDIDATE: Ke,
60
+ INCOMING_CALL: V,
61
+ MAIN_CAM_CONTROL: ie,
62
+ MUST_STOP_PRESENTATION_EVENT: j,
63
+ MUTED: $e,
64
+ NEW_DTMF: Ae,
65
+ NEW_INFO: Re,
66
+ NEW_MESSAGE: Be,
67
+ NEW_RTC_SESSION: M,
68
+ NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT: Q,
69
+ ONE_MEGABIT_IN_BITS: ct,
70
+ PARTICIPANT_ADDED_TO_LIST_MODERATORS: _e,
71
+ PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS: he,
72
+ PARTICIPANT_MOVE_REQUEST_TO_STREAM: de,
73
+ PARTICIPANT_REMOVED_FROM_LIST_MODERATORS: Ee,
74
+ PARTICIPATION_ACCEPTING_WORD_REQUEST: le,
75
+ PARTICIPATION_CANCELLING_WORD_REQUEST: Te,
76
+ PEER_CONNECTION: U,
77
+ PEER_CONNECTION_CONFIRMED: ee,
78
+ PEER_CONNECTION_CREATE_ANSWER_FAILED: tt,
79
+ PEER_CONNECTION_CREATE_OFFER_FAILED: et,
80
+ PEER_CONNECTION_ONTRACK: te,
81
+ PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED: nt,
82
+ PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED: st,
83
+ PRESENTATION_END: rt,
84
+ PRESENTATION_ENDED: Ie,
85
+ PRESENTATION_FAILED: L,
86
+ PRESENTATION_START: it,
87
+ PRESENTATION_STARTED: ot,
88
+ PROGRESS: Ye,
89
+ REFER: Ve,
90
+ REGISTERED: m,
91
+ REGISTRATION_FAILED: P,
92
+ REINVITE: Fe,
93
+ REPLACES: xe,
94
+ SDP: je,
95
+ SENDING: qe,
96
+ SHARE_STATE: v,
97
+ SIP_EVENT: X,
98
+ SPECTATOR: at,
99
+ TERMINATED_INCOMING_CALL: $,
100
+ UNHOLD: ze,
101
+ UNMUTED: Je,
102
+ UNREGISTERED: J,
103
+ UPDATE: Qe,
104
+ USE_LICENSE: Z,
105
+ WEBCAST_STARTED: ue,
106
+ WEBCAST_STOPPED: Se
107
+ }, Symbol.toStringTag, { value: "Module" })), _t = [
108
+ V,
109
+ Y,
110
+ $,
111
+ G,
112
+ le,
113
+ Te,
114
+ de,
115
+ ne,
116
+ Ce,
117
+ Ne,
118
+ ge,
119
+ ue,
120
+ Se,
121
+ _e,
122
+ Ee
123
+ ], fe = [
124
+ H,
125
+ f,
126
+ S,
127
+ M,
128
+ m,
129
+ J,
130
+ P,
131
+ Be,
132
+ X
133
+ ], Et = [
134
+ z,
135
+ Q,
136
+ j,
137
+ v,
138
+ K,
139
+ Z,
140
+ ee,
141
+ te,
142
+ y,
143
+ se,
144
+ ie,
145
+ re,
146
+ oe,
147
+ ae,
148
+ ce,
149
+ w,
150
+ he
151
+ ], me = [
152
+ O,
153
+ H,
154
+ qe,
155
+ Fe,
156
+ xe,
157
+ Ve,
158
+ Ye,
159
+ Ge,
160
+ b,
161
+ U,
162
+ A,
163
+ $e,
164
+ Je,
165
+ Ae,
166
+ Re,
167
+ Xe,
168
+ ze,
169
+ Qe,
170
+ je,
171
+ Ke,
172
+ Ze,
173
+ et,
174
+ tt,
175
+ nt,
176
+ st,
177
+ it,
178
+ ot,
179
+ rt,
180
+ Ie,
181
+ L
182
+ ], dt = [...fe, ..._t], ht = [
183
+ ...me,
184
+ ...Et
185
+ ], Es = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
186
+ __proto__: null,
187
+ SESSION_EVENT_NAMES: ht,
188
+ SESSION_JSSIP_EVENT_NAMES: me,
189
+ SESSION_SYNTHETICS_EVENT_NAMES: Et,
190
+ UA_EVENT_NAMES: dt,
191
+ UA_JSSIP_EVENT_NAMES: fe,
192
+ UA_SYNTHETICS_EVENT_NAMES: _t
193
+ }, Symbol.toStringTag, { value: "Module" })), xt = (s) => {
194
+ const e = [];
195
+ return s && e.push(`X-Vinteo-Remote: ${s}`), e;
196
+ }, Vt = "content-type", Yt = "x-webrtc-enter-room", D = "application/vinteo.webrtc.sharedesktop", Gt = "application/vinteo.webrtc.roomname", $t = "application/vinteo.webrtc.channels", Jt = "application/vinteo.webrtc.mediastate", Xt = "application/vinteo.webrtc.refusal", Me = "application/vinteo.webrtc.maincam", zt = "application/vinteo.webrtc.mic", Qt = "application/vinteo.webrtc.uselic", jt = "X-WEBRTC-USE-LICENSE", Kt = "X-WEBRTC-PARTICIPANT-NAME", ve = "X-WEBRTC-INPUT-CHANNELS", ye = "X-WEBRTC-OUTPUT-CHANNELS", Zt = "X-WEBRTC-MAINCAM", en = "X-WEBRTC-MIC", we = "X-WEBRTC-SYNC", tn = "X-WEBRTC-MAINCAM-RESOLUTION", nn = "X-WEBRTC-MEDIA-STATE", sn = "X-Vinteo-Media-Type", on = "X-Vinteo-MainCam-State", rn = "X-Vinteo-Mic-State", an = "application/vinteo.webrtc.partstate", cn = "X-WEBRTC-PARTSTATE", _n = "application/vinteo.webrtc.notify", En = "X-VINTEO-NOTIFY", R = "x-webrtc-share-state", dn = `${R}: LETMESTARTPRESENTATION`, hn = `${R}: STOPPRESENTATION`, lt = "YOUCANRECEIVECONTENT", Tt = "CONTENTEND", ut = "YOUMUSTSTOPSENDCONTENT", ln = `${R}: ${ut}`, Tn = `${R}: ${lt}`, un = `${R}: ${Tt}`, Sn = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", Nn = `${Sn}: LETMESTARTMAINCAM`, Pe = "sip-connector", k = x(Pe), ds = () => {
197
+ x.enable(Pe);
198
+ }, hs = () => {
199
+ x.enable(`-${Pe}`);
200
+ }, gn = (s, e) => {
201
+ s.getVideoTracks().forEach((n) => {
202
+ "contentHint" in n && n.contentHint !== e && (n.contentHint = e);
203
+ });
204
+ }, p = (s, {
205
+ videoMode: e,
206
+ audioMode: t,
207
+ contentHint: n
208
+ } = {}) => {
209
+ if (!s || e === "recvonly" && t === "recvonly")
210
+ return;
211
+ const i = t === "recvonly" ? [] : s.getAudioTracks(), r = e === "recvonly" ? [] : s.getVideoTracks(), a = [...i, ...r], c = new MediaStream(a);
212
+ return c.getTracks = () => [...c.getAudioTracks(), ...c.getVideoTracks()], n && n !== "none" && gn(c, n), c;
213
+ };
214
+ var I = /* @__PURE__ */ ((s) => (s.PAUSE_MAIN_CAM = "PAUSEMAINCAM", s.RESUME_MAIN_CAM = "RESUMEMAINCAM", s.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", s.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", s.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", s))(I || {}), B = /* @__PURE__ */ ((s) => (s.ADMIN_STOP_MIC = "ADMINSTOPMIC", s.ADMIN_START_MIC = "ADMINSTARTMIC", s))(B || {}), q = /* @__PURE__ */ ((s) => (s.ADMIN_SYNC_FORCED = "1", s.ADMIN_SYNC_NOT_FORCED = "0", s))(q || {}), Cn = /* @__PURE__ */ ((s) => (s.AUDIO = "AUDIO", s.VIDEO = "VIDEO", s.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", s))(Cn || {});
215
+ function An(s) {
216
+ return (e) => `sip:${e}@${s}`;
217
+ }
218
+ const Rn = (s, e) => () => Math.floor(Math.random() * (e - s)) + s, be = (s) => s.trim().replaceAll(" ", "_"), In = Rn(1e5, 99999999), fn = (s) => s.some((t) => {
219
+ const { kind: n } = t;
220
+ return n === "video";
221
+ }), mn = "Error decline with 603", Pn = 1006, On = (s) => typeof s == "object" && s !== null && "code" in s && s.code === Pn, Dn = (s) => s.message === mn, pn = (s, e) => s.find((t) => t.track && e.getTracks().includes(t.track)), Mn = (s, e) => (s.degradationPreference = e.degradationPreference, s), vn = (s, e) => {
222
+ s.encodings === void 0 && (s.encodings = []);
223
+ for (let t = s.encodings.length; t < e; t += 1)
224
+ s.encodings.push({});
225
+ return s;
226
+ }, St = (s) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== s, yn = St(), wn = (s, e) => {
227
+ if (yn(s, e))
228
+ return s;
229
+ }, bn = (s, e) => {
230
+ const t = s.maxBitrate, n = wn(e, t);
231
+ return n !== void 0 && (s.maxBitrate = n), s;
232
+ }, Nt = 1, Un = St(
233
+ Nt
234
+ ), Ln = (s, e) => {
235
+ const t = s === void 0 ? void 0 : Math.max(s, Nt);
236
+ if (t !== void 0 && Un(
237
+ t,
238
+ e
239
+ ))
240
+ return t;
241
+ }, Hn = (s, e) => {
242
+ const t = s.scaleResolutionDownBy, n = Ln(
243
+ e,
244
+ t
245
+ );
246
+ return n !== void 0 && (s.scaleResolutionDownBy = n), s;
247
+ }, Wn = (s, e) => {
248
+ var n;
249
+ const t = ((n = e.encodings) == null ? void 0 : n.length) ?? 0;
250
+ return vn(s, t), s.encodings.forEach((i, r) => {
251
+ const a = ((e == null ? void 0 : e.encodings) ?? [])[r], c = a == null ? void 0 : a.maxBitrate, E = a == null ? void 0 : a.scaleResolutionDownBy;
252
+ bn(i, c), Hn(i, E);
253
+ }), s;
254
+ }, kn = (s, e) => {
255
+ var t, n, i, r, a, c, E, d;
256
+ if (((t = s.codecs) == null ? void 0 : t.length) !== ((n = e.codecs) == null ? void 0 : n.length))
257
+ return !0;
258
+ for (let _ = 0; _ < (((i = s.codecs) == null ? void 0 : i.length) ?? 0); _++)
259
+ if (JSON.stringify(s.codecs[_]) !== JSON.stringify(e.codecs[_]))
260
+ return !0;
261
+ if (((r = s.headerExtensions) == null ? void 0 : r.length) !== ((a = e.headerExtensions) == null ? void 0 : a.length))
262
+ return !0;
263
+ for (let _ = 0; _ < (((c = s.headerExtensions) == null ? void 0 : c.length) ?? 0); _++)
264
+ if (JSON.stringify(s.headerExtensions[_]) !== JSON.stringify(e.headerExtensions[_]))
265
+ return !0;
266
+ if (((E = s.encodings) == null ? void 0 : E.length) !== ((d = e.encodings) == null ? void 0 : d.length))
267
+ return !0;
268
+ for (let _ = 0; _ < (s.encodings.length ?? 0); _++)
269
+ if (JSON.stringify(s.encodings[_]) !== JSON.stringify(e.encodings[_]))
270
+ return !0;
271
+ return s.rtcp.cname !== e.rtcp.cname || s.rtcp.reducedSize !== e.rtcp.reducedSize || s.degradationPreference !== e.degradationPreference;
272
+ }, Bn = async (s, e) => {
273
+ const t = s.getParameters(), n = JSON.parse(JSON.stringify(t));
274
+ Wn(t, e), Mn(t, e);
275
+ const i = kn(n, t);
276
+ return i && await s.setParameters(t), { parameters: t, isChanged: i };
277
+ }, qn = async (s, e, t) => {
278
+ const { isChanged: n, parameters: i } = await Bn(s, {
279
+ encodings: [
280
+ {
281
+ scaleResolutionDownBy: e.scaleResolutionDownBy,
282
+ maxBitrate: e.maxBitrate
283
+ }
284
+ ]
285
+ });
286
+ return n && t && t(i), { isChanged: n, parameters: i };
287
+ }, Fn = async (s, e, t) => {
288
+ const n = pn(s, e);
289
+ if (n)
290
+ return qn(n, { maxBitrate: t });
291
+ }, xn = 486, Vn = 487, F = "local", Ue = "remote", Yn = 3, Gn = 1, ls = (s = new Error()) => {
292
+ const { originator: e, cause: t } = s;
293
+ return It(s) ? !0 : typeof t == "string" ? t === Le || t === He || e === F && (t === ke || t === We) : !1;
294
+ }, C = "SipConnector", $n = "channels", Jn = "WebcastStarted", Xn = "WebcastStopped", zn = "accountChanged", Qn = "accountDeleted", jn = "addedToListModerators", Kn = "removedFromListModerators", Zn = "ParticipationRequestAccepted", es = "ParticipationRequestRejected", ts = "ParticipantMovedToWebcast", ns = "ConferenceParticipantTokenIssued";
295
+ class Ts {
296
+ constructor({ JsSIP: e }) {
297
+ o(this, "_isRegisterConfig", !1);
298
+ o(this, "_connectionConfiguration", {});
299
+ o(this, "_remoteStreams", {});
300
+ o(this, "JsSIP");
301
+ o(this, "_sessionEvents");
302
+ o(this, "_uaEvents");
303
+ o(this, "_cancelableConnect");
304
+ o(this, "_cancelableConnectWithRepeatedCalls");
305
+ o(this, "_cancelableSendPresentationWithRepeatedCalls");
306
+ o(this, "_cancelableInitUa");
307
+ o(this, "_cancelableDisconnect");
308
+ o(this, "_cancelableSet");
309
+ o(this, "_cancelableCall");
310
+ o(this, "_cancelableAnswer");
311
+ o(this, "_cancelableSendDTMF");
312
+ o(this, "getSipServerUrl", (e) => e);
313
+ o(this, "promisePendingStartPresentation");
314
+ o(this, "promisePendingStopPresentation");
315
+ o(this, "ua");
316
+ o(this, "session");
317
+ o(this, "incomingSession");
318
+ o(this, "_streamPresentationCurrent");
319
+ o(this, "socket");
320
+ o(this, "connect", async (e, t) => (this._cancelRequests(), this._connectWithDuplicatedCalls(e, t)));
321
+ o(this, "initUa", async (e) => this._cancelableInitUa.request(e));
322
+ o(this, "set", async (e) => this._cancelableSet.request(e));
323
+ o(this, "call", async (e) => this._cancelableCall.request(e));
324
+ o(this, "disconnect", async () => (this._cancelRequests(), this._disconnectWithoutCancelRequests()));
325
+ o(this, "answerToIncomingCall", async (e) => this._cancelableAnswer.request(e));
326
+ o(this, "sendDTMF", async (e) => this._cancelableSendDTMF.request(e));
327
+ o(this, "hangUp", async () => (this._cancelRequests(), this._hangUpWithoutCancelRequests()));
328
+ o(this, "tryRegister", async () => {
329
+ if (!this.isRegisterConfig)
330
+ throw new Error("Config is not registered");
331
+ this._uaEvents.trigger(H, void 0);
332
+ try {
333
+ await this.unregister();
334
+ } catch (e) {
335
+ k("tryRegister", e);
336
+ }
337
+ return this.register();
338
+ });
339
+ o(this, "declineToIncomingCall", async ({ statusCode: e = Vn } = {}) => new Promise((t, n) => {
340
+ if (!this.isAvailableIncomingCall) {
341
+ n(new Error("no incomingSession"));
342
+ return;
343
+ }
344
+ const i = this.incomingSession, r = this.remoteCallerData;
345
+ this._cancelableCall.cancelRequest(), this._cancelableAnswer.cancelRequest(), this.removeIncomingSession(), this._uaEvents.trigger(Y, r), t(i.terminate({ status_code: e }));
346
+ }));
347
+ o(this, "busyIncomingCall", async () => this.declineToIncomingCall({ statusCode: xn }));
348
+ o(this, "removeIncomingSession", () => {
349
+ delete this.incomingSession;
350
+ });
351
+ o(this, "_connectWithDuplicatedCalls", async (e, { callLimit: t = Yn } = {}) => {
352
+ const n = async () => this._cancelableConnect.request(e), i = (r) => {
353
+ var d;
354
+ const c = !!((d = this.ua) != null && d.isConnected()) && this.hasEqualConnectionConfiguration(e), E = !!r && !On(r);
355
+ return c || E;
356
+ };
357
+ return this._cancelableConnectWithRepeatedCalls = pe({
358
+ targetFunction: n,
359
+ isComplete: i,
360
+ callLimit: t,
361
+ isRejectAsValid: !0,
362
+ isCheckBeforeCall: !1,
363
+ onAfterCancel: () => {
364
+ this._cancelableConnect.cancelRequest();
365
+ }
366
+ }), this._cancelableConnectWithRepeatedCalls.then((r) => {
367
+ if (r instanceof this.JsSIP.UA)
368
+ return r;
369
+ throw r;
370
+ });
371
+ });
372
+ o(this, "handleNewRTCSession", ({ originator: e, session: t }) => {
373
+ if (e === Ue) {
374
+ this.incomingSession = t;
375
+ const n = this.remoteCallerData;
376
+ t.on(A, (i) => {
377
+ this.removeIncomingSession(), i.originator === F ? this._uaEvents.trigger($, n) : this._uaEvents.trigger(G, n);
378
+ }), this._uaEvents.trigger(V, n);
379
+ }
380
+ });
381
+ o(this, "_connect", async (e) => this.initUa(e).then(async () => this._start()));
382
+ o(this, "_initUa", async ({
383
+ user: e,
384
+ password: t,
385
+ sipServerUrl: n,
386
+ sipWebSocketServerURL: i,
387
+ remoteAddress: r,
388
+ sessionTimers: a,
389
+ registerExpires: c,
390
+ connectionRecoveryMinInterval: E,
391
+ connectionRecoveryMaxInterval: d,
392
+ userAgent: _,
393
+ displayName: h = "",
394
+ register: l = !1,
395
+ extraHeaders: T = []
396
+ }) => {
397
+ if (!n)
398
+ throw new Error("sipServerUrl is required");
399
+ if (!i)
400
+ throw new Error("sipWebSocketServerURL is required");
401
+ if (l && !e)
402
+ throw new Error("user is required for authorized connection");
403
+ if (l && !t)
404
+ throw new Error("password is required for authorized connection");
405
+ this._connectionConfiguration = {
406
+ sipServerUrl: n,
407
+ displayName: h,
408
+ register: l,
409
+ user: e,
410
+ password: t
411
+ };
412
+ const { configuration: N, helpers: u } = this.createUaConfiguration({
413
+ user: e,
414
+ sipServerUrl: n,
415
+ sipWebSocketServerURL: i,
416
+ password: t,
417
+ displayName: h,
418
+ register: l,
419
+ sessionTimers: a,
420
+ registerExpires: c,
421
+ connectionRecoveryMinInterval: E,
422
+ connectionRecoveryMaxInterval: d,
423
+ userAgent: _
424
+ });
425
+ return this.getSipServerUrl = u.getSipServerUrl, this.socket = u.socket, this.ua && await this._disconnectWithoutCancelRequests(), this._isRegisterConfig = !!l, this.ua = this._createUa({ ...N, remoteAddress: r, extraHeaders: T }), this._uaEvents.eachTriggers((W, gt) => {
426
+ const Oe = fe.find((Ct) => Ct === gt);
427
+ Oe && this.ua && this.ua.on(Oe, W);
428
+ }), this.ua;
429
+ });
430
+ o(this, "_createUa", ({
431
+ remoteAddress: e,
432
+ extraHeaders: t = [],
433
+ ...n
434
+ }) => {
435
+ const i = new this.JsSIP.UA(n), a = [...e ? xt(e) : [], ...t];
436
+ return a.length > 0 && i.registrator().setExtraHeaders(a), i;
437
+ });
438
+ o(this, "_start", async () => new Promise((e, t) => {
439
+ const { ua: n } = this;
440
+ if (!n) {
441
+ t(new Error("this.ua is not initialized"));
442
+ return;
443
+ }
444
+ const i = () => {
445
+ c(), e(n);
446
+ }, r = (E) => {
447
+ c(), t(E);
448
+ }, a = () => {
449
+ this.isRegisterConfig ? (this.on(m, i), this.on(P, r)) : this.on(f, i), this.on(S, r);
450
+ }, c = () => {
451
+ this.off(m, i), this.off(P, r), this.off(f, i), this.off(S, r);
452
+ };
453
+ a(), this.on(M, this.handleNewRTCSession), n.start();
454
+ }));
455
+ o(this, "_set", async ({ displayName: e, password: t }) => new Promise((n, i) => {
456
+ const { ua: r } = this;
457
+ if (!r) {
458
+ i(new Error("this.ua is not initialized"));
459
+ return;
460
+ }
461
+ let a = !1, c = !1;
462
+ e !== void 0 && e !== this._connectionConfiguration.displayName && (a = r.set("display_name", be(e)), this._connectionConfiguration.displayName = e), t !== void 0 && t !== this._connectionConfiguration.password && (c = r.set("password", t), this._connectionConfiguration.password = t);
463
+ const E = a || c;
464
+ c && this.isRegisterConfig ? this.register().then(() => {
465
+ n(E);
466
+ }).catch((d) => {
467
+ i(d);
468
+ }) : E ? n(E) : i(new Error("nothing changed"));
469
+ }));
470
+ o(this, "_disconnectWithoutCancelRequests", async () => this._cancelableDisconnect.request());
471
+ o(this, "_disconnect", async () => {
472
+ this.off(M, this.handleNewRTCSession);
473
+ const e = new Promise((t) => {
474
+ this.once(S, () => {
475
+ delete this.ua, t();
476
+ });
477
+ });
478
+ return this.ua ? (await this._hangUpWithoutCancelRequests(), this.ua ? this.ua.stop() : this._uaEvents.trigger(S, void 0)) : this._uaEvents.trigger(S, void 0), e;
479
+ });
480
+ o(this, "_call", async ({
481
+ number: e,
482
+ mediaStream: t,
483
+ extraHeaders: n = [],
484
+ ontrack: i,
485
+ iceServers: r,
486
+ videoMode: a,
487
+ audioMode: c,
488
+ onAddedSender: E,
489
+ contentHint: d,
490
+ offerToReceiveAudio: _ = !0,
491
+ offerToReceiveVideo: h = !0
492
+ }) => new Promise((l, T) => {
493
+ const { ua: N } = this;
494
+ if (!N) {
495
+ T(new Error("this.ua is not initialized"));
496
+ return;
497
+ }
498
+ this._connectionConfiguration.number = e, this._connectionConfiguration.answer = !1, this._handleCall({ ontrack: i }).then(l).catch((u) => {
499
+ T(u);
500
+ }), this.session = N.call(this.getSipServerUrl(e), {
501
+ extraHeaders: n,
502
+ mediaStream: p(t, {
503
+ videoMode: a,
504
+ audioMode: c,
505
+ contentHint: d
506
+ }),
507
+ eventHandlers: this._sessionEvents.triggers,
508
+ videoMode: a,
509
+ audioMode: c,
510
+ onAddedSender: E,
511
+ pcConfig: {
512
+ iceServers: r
513
+ },
514
+ rtcOfferConstraints: {
515
+ offerToReceiveAudio: _,
516
+ offerToReceiveVideo: h
517
+ }
518
+ });
519
+ }));
520
+ o(this, "_answer", async ({
521
+ mediaStream: e,
522
+ ontrack: t,
523
+ extraHeaders: n = [],
524
+ iceServers: i,
525
+ videoMode: r,
526
+ audioMode: a,
527
+ onAddedSender: c,
528
+ contentHint: E
529
+ }) => new Promise((d, _) => {
530
+ if (!this.isAvailableIncomingCall) {
531
+ _(new Error("no incomingSession"));
532
+ return;
533
+ }
534
+ this.session = this.incomingSession, this.removeIncomingSession();
535
+ const { session: h } = this;
536
+ if (!h) {
537
+ _(new Error("No session established"));
538
+ return;
539
+ }
540
+ this._sessionEvents.eachTriggers((T, N) => {
541
+ const u = me.find((W) => W === N);
542
+ u && h.on(u, T);
543
+ }), this._connectionConfiguration.answer = !0, this._connectionConfiguration.number = h.remote_identity.uri.user, this._handleCall({ ontrack: t }).then(d).catch((T) => {
544
+ _(T);
545
+ });
546
+ const l = p(e, {
547
+ videoMode: r,
548
+ audioMode: a,
549
+ contentHint: E
550
+ });
551
+ h.answer({
552
+ extraHeaders: n,
553
+ videoMode: r,
554
+ audioMode: a,
555
+ onAddedSender: c,
556
+ mediaStream: l,
557
+ pcConfig: {
558
+ iceServers: i
559
+ }
560
+ });
561
+ }));
562
+ o(this, "_handleCall", async ({ ontrack: e }) => new Promise((t, n) => {
563
+ const i = () => {
564
+ this.onSession(U, _), this.onSession(b, h);
565
+ }, r = () => {
566
+ this.offSession(U, _), this.offSession(b, h);
567
+ }, a = () => {
568
+ this.onSession(A, E), this.onSession(O, E);
569
+ }, c = () => {
570
+ this.offSession(A, E), this.offSession(O, E);
571
+ }, E = (l) => {
572
+ r(), c(), n(l);
573
+ };
574
+ let d;
575
+ const _ = ({ peerconnection: l }) => {
576
+ d = l, d.ontrack = (T) => {
577
+ this._sessionEvents.trigger(te, d), e && e(T);
578
+ };
579
+ }, h = () => {
580
+ d && this._sessionEvents.trigger(ee, d), r(), c(), t(d);
581
+ };
582
+ i(), a();
583
+ }));
584
+ o(this, "_restoreSession", () => {
585
+ this._cancelRequestsAndResetPresentation(), delete this._connectionConfiguration.number, delete this.session, this._remoteStreams = {};
586
+ });
587
+ o(this, "_sendDTMF", async (e) => new Promise((t, n) => {
588
+ const { session: i } = this;
589
+ if (!i) {
590
+ n(new Error("No session established"));
591
+ return;
592
+ }
593
+ this.onceSession(Ae, ({ originator: r }) => {
594
+ r === F && t();
595
+ }), i.sendDTMF(e, {
596
+ duration: 120,
597
+ interToneGap: 600
598
+ });
599
+ }));
600
+ o(this, "_hangUpWithoutCancelRequests", async () => {
601
+ if (this.ua && this.session) {
602
+ const { session: e } = this;
603
+ if (this._streamPresentationCurrent)
604
+ try {
605
+ await this.stopPresentation();
606
+ } catch (t) {
607
+ k("error stop presentation: ", t);
608
+ }
609
+ if (this._restoreSession(), !e.isEnded())
610
+ return e.terminateAsync();
611
+ }
612
+ });
613
+ o(this, "_handleShareState", (e) => {
614
+ switch (e) {
615
+ case lt: {
616
+ this._sessionEvents.trigger(z, void 0);
617
+ break;
618
+ }
619
+ case Tt: {
620
+ this._sessionEvents.trigger(Q, void 0);
621
+ break;
622
+ }
623
+ case ut: {
624
+ this._sessionEvents.trigger(j, void 0);
625
+ break;
626
+ }
627
+ }
628
+ });
629
+ o(this, "_maybeTriggerChannels", (e) => {
630
+ const t = e.getHeader(ve), n = e.getHeader(ye);
631
+ if (t && n) {
632
+ const i = {
633
+ inputChannels: t,
634
+ outputChannels: n
635
+ };
636
+ this._sessionEvents.trigger(y, i);
637
+ }
638
+ });
639
+ o(this, "_handleNotify", (e) => {
640
+ switch (e.cmd) {
641
+ case $n: {
642
+ const t = e;
643
+ this._triggerChannelsNotify(t);
644
+ break;
645
+ }
646
+ case Jn: {
647
+ const t = e;
648
+ this._triggerWebcastStartedNotify(t);
649
+ break;
650
+ }
651
+ case Xn: {
652
+ const t = e;
653
+ this._triggerWebcastStoppedNotify(t);
654
+ break;
655
+ }
656
+ case jn: {
657
+ const t = e;
658
+ this._triggerAddedToListModeratorsNotify(t);
659
+ break;
660
+ }
661
+ case Kn: {
662
+ const t = e;
663
+ this._triggerRemovedFromListModeratorsNotify(t);
664
+ break;
665
+ }
666
+ case Zn: {
667
+ const t = e;
668
+ this._triggerParticipationAcceptingWordRequest(t);
669
+ break;
670
+ }
671
+ case es: {
672
+ const t = e;
673
+ this._triggerParticipationCancellingWordRequest(t);
674
+ break;
675
+ }
676
+ case ts: {
677
+ const t = e;
678
+ this._triggerParticipantMoveRequestToStream(t);
679
+ break;
680
+ }
681
+ case zn: {
682
+ this._triggerAccountChangedNotify();
683
+ break;
684
+ }
685
+ case Qn: {
686
+ this._triggerAccountDeletedNotify();
687
+ break;
688
+ }
689
+ case ns: {
690
+ const t = e;
691
+ this._triggerConferenceParticipantTokenIssued(t);
692
+ break;
693
+ }
694
+ default:
695
+ k("unknown cmd", e.cmd);
696
+ }
697
+ });
698
+ o(this, "_triggerRemovedFromListModeratorsNotify", ({
699
+ conference: e
700
+ }) => {
701
+ const t = {
702
+ conference: e
703
+ };
704
+ this._uaEvents.trigger(
705
+ Ee,
706
+ t
707
+ );
708
+ });
709
+ o(this, "_triggerAddedToListModeratorsNotify", ({ conference: e }) => {
710
+ const t = {
711
+ conference: e
712
+ };
713
+ this._uaEvents.trigger(_e, t);
714
+ });
715
+ o(this, "_triggerWebcastStartedNotify", ({ body: { conference: e, type: t } }) => {
716
+ const n = {
717
+ conference: e,
718
+ type: t
719
+ };
720
+ this._uaEvents.trigger(ue, n);
721
+ });
722
+ o(this, "_triggerWebcastStoppedNotify", ({ body: { conference: e, type: t } }) => {
723
+ const n = {
724
+ conference: e,
725
+ type: t
726
+ };
727
+ this._uaEvents.trigger(Se, n);
728
+ });
729
+ o(this, "_triggerAccountChangedNotify", () => {
730
+ this._uaEvents.trigger(Ne, void 0);
731
+ });
732
+ o(this, "_triggerAccountDeletedNotify", () => {
733
+ this._uaEvents.trigger(ge, void 0);
734
+ });
735
+ o(this, "_triggerConferenceParticipantTokenIssued", ({
736
+ body: { conference: e, participant: t, jwt: n }
737
+ }) => {
738
+ const i = {
739
+ conference: e,
740
+ participant: t,
741
+ jwt: n
742
+ };
743
+ this._uaEvents.trigger(
744
+ Ce,
745
+ i
746
+ );
747
+ });
748
+ o(this, "_triggerChannelsNotify", (e) => {
749
+ const t = e.input, n = e.output, i = {
750
+ inputChannels: t,
751
+ outputChannels: n
752
+ };
753
+ this._uaEvents.trigger(ne, i);
754
+ });
755
+ o(this, "_triggerParticipationAcceptingWordRequest", ({
756
+ body: { conference: e }
757
+ }) => {
758
+ const t = {
759
+ conference: e
760
+ };
761
+ this._uaEvents.trigger(le, t);
762
+ });
763
+ o(this, "_triggerParticipationCancellingWordRequest", ({
764
+ body: { conference: e }
765
+ }) => {
766
+ const t = {
767
+ conference: e
768
+ };
769
+ this._uaEvents.trigger(Te, t);
770
+ });
771
+ o(this, "_triggerParticipantMoveRequestToStream", ({
772
+ body: { conference: e }
773
+ }) => {
774
+ const t = {
775
+ conference: e
776
+ };
777
+ this._uaEvents.trigger(de, t);
778
+ });
779
+ o(this, "_triggerEnterRoom", (e) => {
780
+ const t = e.getHeader(Yt), n = e.getHeader(Kt);
781
+ this._sessionEvents.trigger(K, { room: t, participantName: n });
782
+ });
783
+ o(this, "_triggerShareState", (e) => {
784
+ const t = e.getHeader(R);
785
+ this._sessionEvents.trigger(v, t);
786
+ });
787
+ o(this, "_maybeTriggerParticipantMoveRequestToSpectators", (e) => {
788
+ e.getHeader(cn) === at && this._sessionEvents.trigger(he, void 0);
789
+ });
790
+ o(this, "_triggerMainCamControl", (e) => {
791
+ const t = e.getHeader(Zt), n = e.getHeader(we), i = n === q.ADMIN_SYNC_FORCED;
792
+ if (t === I.ADMIN_START_MAIN_CAM) {
793
+ this._sessionEvents.trigger(re, { isSyncForced: i });
794
+ return;
795
+ }
796
+ if (t === I.ADMIN_STOP_MAIN_CAM) {
797
+ this._sessionEvents.trigger(oe, { isSyncForced: i });
798
+ return;
799
+ }
800
+ (t === I.RESUME_MAIN_CAM || t === I.PAUSE_MAIN_CAM) && n && this._sessionEvents.trigger(w, { isSyncForced: i });
801
+ const r = e.getHeader(tn);
802
+ this._sessionEvents.trigger(ie, {
803
+ mainCam: t,
804
+ resolutionMainCam: r
805
+ });
806
+ });
807
+ o(this, "_triggerMicControl", (e) => {
808
+ const t = e.getHeader(en), i = e.getHeader(we) === q.ADMIN_SYNC_FORCED;
809
+ t === B.ADMIN_START_MIC ? this._sessionEvents.trigger(ce, { isSyncForced: i }) : t === B.ADMIN_STOP_MIC && this._sessionEvents.trigger(ae, { isSyncForced: i });
810
+ });
811
+ o(this, "_triggerUseLicense", (e) => {
812
+ const t = e.getHeader(jt);
813
+ this._sessionEvents.trigger(Z, t);
814
+ });
815
+ o(this, "_handleNewInfo", (e) => {
816
+ const { originator: t } = e;
817
+ if (t !== "remote")
818
+ return;
819
+ const { request: n } = e, i = n.getHeader(Vt);
820
+ if (i)
821
+ switch (i) {
822
+ case Gt: {
823
+ this._triggerEnterRoom(n), this._maybeTriggerChannels(n);
824
+ break;
825
+ }
826
+ case _n: {
827
+ this._maybeHandleNotify(n);
828
+ break;
829
+ }
830
+ case D: {
831
+ this._triggerShareState(n);
832
+ break;
833
+ }
834
+ case Me: {
835
+ this._triggerMainCamControl(n);
836
+ break;
837
+ }
838
+ case zt: {
839
+ this._triggerMicControl(n);
840
+ break;
841
+ }
842
+ case Qt: {
843
+ this._triggerUseLicense(n);
844
+ break;
845
+ }
846
+ case an: {
847
+ this._maybeTriggerParticipantMoveRequestToSpectators(n);
848
+ break;
849
+ }
850
+ }
851
+ });
852
+ o(this, "_handleSipEvent", ({ request: e }) => {
853
+ this._maybeHandleNotify(e);
854
+ });
855
+ o(this, "_maybeHandleNotify", (e) => {
856
+ const t = e.getHeader(En);
857
+ if (t) {
858
+ const n = JSON.parse(t);
859
+ this._handleNotify(n);
860
+ }
861
+ });
862
+ o(this, "_handleEnded", (e) => {
863
+ const { originator: t } = e;
864
+ t === Ue && this._sessionEvents.trigger(se, e), this._restoreSession();
865
+ });
866
+ this.JsSIP = e, this._sessionEvents = new De(ht), this._uaEvents = new De(dt), this._cancelableConnect = new g(
867
+ this._connect,
868
+ {
869
+ moduleName: C,
870
+ afterCancelRequest: () => {
871
+ this._cancelableInitUa.cancelRequest(), this._cancelableDisconnect.cancelRequest();
872
+ }
873
+ }
874
+ ), this._cancelableInitUa = new g(
875
+ this._initUa,
876
+ { moduleName: C }
877
+ ), this._cancelableDisconnect = new g(
878
+ this._disconnect,
879
+ { moduleName: C }
880
+ ), this._cancelableSet = new g(this._set, {
881
+ moduleName: C
882
+ }), this._cancelableCall = new g(
883
+ this._call,
884
+ { moduleName: C }
885
+ ), this._cancelableAnswer = new g(this._answer, { moduleName: C }), this._cancelableSendDTMF = new g(this._sendDTMF, { moduleName: C }), this.onSession(v, this._handleShareState), this.onSession(Re, this._handleNewInfo), this.on(X, this._handleSipEvent), this.onSession(A, this._handleEnded), this.onSession(O, this._handleEnded);
886
+ }
887
+ async register() {
888
+ return new Promise((e, t) => {
889
+ this.isRegisterConfig && this.ua ? (this.ua.on(m, e), this.ua.on(P, t), this.ua.register()) : t(new Error("Config is not registered"));
890
+ });
891
+ }
892
+ async unregister() {
893
+ return new Promise((e, t) => {
894
+ this.isRegistered && this.ua ? (this.ua.on(J, e), this.ua.unregister()) : t(new Error("ua is not registered"));
895
+ });
896
+ }
897
+ async sendOptions(e, t, n) {
898
+ if (!this.ua)
899
+ throw new Error("is not connected");
900
+ return new Promise((i, r) => {
901
+ try {
902
+ this.ua.sendOptions(e, t, {
903
+ extraHeaders: n,
904
+ eventHandlers: {
905
+ succeeded: () => {
906
+ i();
907
+ },
908
+ failed: r
909
+ }
910
+ });
911
+ } catch (a) {
912
+ r(a);
913
+ }
914
+ });
915
+ }
916
+ async ping(e, t) {
917
+ var i;
918
+ if (!((i = this.ua) != null && i.configuration.uri))
919
+ throw new Error("is not connected");
920
+ const n = this.ua.configuration.uri;
921
+ return this.sendOptions(n, e, t);
922
+ }
923
+ async checkTelephony({
924
+ userAgent: e,
925
+ displayName: t,
926
+ sipServerUrl: n,
927
+ sipWebSocketServerURL: i,
928
+ remoteAddress: r,
929
+ extraHeaders: a
930
+ }) {
931
+ return new Promise((c, E) => {
932
+ const { configuration: d } = this.createUaConfiguration({
933
+ sipWebSocketServerURL: i,
934
+ displayName: t,
935
+ userAgent: e,
936
+ sipServerUrl: n
937
+ }), _ = this._createUa({ ...d, remoteAddress: r, extraHeaders: a }), h = () => {
938
+ const T = new Error("Telephony is not available");
939
+ E(T);
940
+ };
941
+ _.once(S, h);
942
+ const l = () => {
943
+ _.removeAllListeners(), _.once(S, c), _.stop();
944
+ };
945
+ _.once(f, l), _.start();
946
+ });
947
+ }
948
+ async replaceMediaStream(e, t) {
949
+ if (!this.session)
950
+ throw new Error("No session established");
951
+ const { contentHint: n } = t || {}, i = p(e, { contentHint: n });
952
+ return this.session.replaceMediaStream(i, t);
953
+ }
954
+ async askPermissionToEnableCam(e = {}) {
955
+ if (!this.session)
956
+ throw new Error("No session established");
957
+ const t = [Nn];
958
+ return this.session.sendInfo(Me, void 0, {
959
+ noTerminateWhenError: !0,
960
+ ...e,
961
+ extraHeaders: t
962
+ }).catch((n) => {
963
+ if (Dn(n))
964
+ throw n;
965
+ });
966
+ }
967
+ get isPendingPresentation() {
968
+ return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
969
+ }
970
+ async _sendPresentationWithDuplicatedCalls({
971
+ session: e,
972
+ stream: t,
973
+ presentationOptions: n,
974
+ options: i = {
975
+ callLimit: Gn
976
+ }
977
+ }) {
978
+ const r = async () => this._sendPresentation(e, t, n), a = () => !!this._streamPresentationCurrent;
979
+ return this._cancelableSendPresentationWithRepeatedCalls = pe({
980
+ targetFunction: r,
981
+ isComplete: a,
982
+ isRejectAsValid: !0,
983
+ ...i
984
+ }), this._cancelableSendPresentationWithRepeatedCalls.then((c) => c);
985
+ }
986
+ hasEqualConnectionConfiguration(e) {
987
+ var i;
988
+ const { configuration: t } = this.createUaConfiguration(e), n = (i = this.ua) == null ? void 0 : i.configuration;
989
+ return (n == null ? void 0 : n.password) === t.password && (n == null ? void 0 : n.register) === t.register && (n == null ? void 0 : n.uri.toString()) === t.uri && (n == null ? void 0 : n.display_name) === t.display_name && (n == null ? void 0 : n.user_agent) === t.user_agent && (n == null ? void 0 : n.sockets) === t.sockets && (n == null ? void 0 : n.session_timers) === t.session_timers && (n == null ? void 0 : n.register_expires) === t.register_expires && (n == null ? void 0 : n.connection_recovery_min_interval) === t.connection_recovery_min_interval && (n == null ? void 0 : n.connection_recovery_max_interval) === t.connection_recovery_max_interval;
990
+ }
991
+ createUaConfiguration({
992
+ user: e,
993
+ password: t,
994
+ sipWebSocketServerURL: n,
995
+ displayName: i = "",
996
+ sipServerUrl: r,
997
+ register: a = !1,
998
+ sessionTimers: c = !1,
999
+ registerExpires: E = 60 * 5,
1000
+ // 5 minutes in sec
1001
+ connectionRecoveryMinInterval: d = 2,
1002
+ connectionRecoveryMaxInterval: _ = 6,
1003
+ userAgent: h
1004
+ }) {
1005
+ if (a && !t)
1006
+ throw new Error("password is required for authorized connection");
1007
+ const l = a && e ? e.trim() : `${In()}`, T = An(r), N = T(l), u = new this.JsSIP.WebSocketInterface(n);
1008
+ return {
1009
+ configuration: {
1010
+ password: t,
1011
+ register: a,
1012
+ uri: N,
1013
+ display_name: be(i),
1014
+ user_agent: h,
1015
+ sdp_semantics: "unified-plan",
1016
+ sockets: [u],
1017
+ session_timers: c,
1018
+ register_expires: E,
1019
+ connection_recovery_min_interval: d,
1020
+ connection_recovery_max_interval: _
1021
+ },
1022
+ helpers: {
1023
+ socket: u,
1024
+ getSipServerUrl: T
1025
+ }
1026
+ };
1027
+ }
1028
+ async _sendPresentation(e, t, {
1029
+ maxBitrate: n = ct,
1030
+ onAddedSender: i,
1031
+ isNeedReinvite: r = !0,
1032
+ isP2P: a = !1,
1033
+ contentHint: c = "detail"
1034
+ }) {
1035
+ const E = p(t, { contentHint: c });
1036
+ this._streamPresentationCurrent = E;
1037
+ const d = a ? [Tn] : [dn], _ = e.sendInfo(D, void 0, {
1038
+ extraHeaders: d
1039
+ }).then(async () => e.startPresentation(E, r, i)).then(async () => {
1040
+ const { connection: h } = this;
1041
+ if (!h || n === void 0)
1042
+ return;
1043
+ const l = h.getSenders();
1044
+ await Fn(l, t, n);
1045
+ }).then(() => t).catch((h) => {
1046
+ throw this._removeStreamPresentationCurrent(), this._sessionEvents.trigger(L, h), h;
1047
+ });
1048
+ return this.promisePendingStartPresentation = _, _.finally(() => {
1049
+ this.promisePendingStartPresentation = void 0;
1050
+ });
1051
+ }
1052
+ async startPresentation(e, {
1053
+ isNeedReinvite: t,
1054
+ isP2P: n,
1055
+ maxBitrate: i,
1056
+ onAddedSender: r,
1057
+ contentHint: a
1058
+ } = {}, c) {
1059
+ const E = this.establishedSession;
1060
+ if (!E)
1061
+ throw new Error("No session established");
1062
+ if (this._streamPresentationCurrent)
1063
+ throw new Error("Presentation is already started");
1064
+ return n && await this.sendMustStopPresentation(E), this._sendPresentationWithDuplicatedCalls({
1065
+ session: E,
1066
+ stream: e,
1067
+ presentationOptions: {
1068
+ isNeedReinvite: t,
1069
+ isP2P: n,
1070
+ maxBitrate: i,
1071
+ onAddedSender: r,
1072
+ contentHint: a
1073
+ },
1074
+ options: c
1075
+ });
1076
+ }
1077
+ async sendMustStopPresentation(e) {
1078
+ await e.sendInfo(D, void 0, {
1079
+ extraHeaders: [ln]
1080
+ });
1081
+ }
1082
+ async stopPresentation({
1083
+ isP2P: e = !1
1084
+ } = {}) {
1085
+ this._cancelSendPresentationWithRepeatedCalls();
1086
+ const t = this._streamPresentationCurrent;
1087
+ let n = this.promisePendingStartPresentation ?? Promise.resolve();
1088
+ const i = e ? [un] : [hn], r = this.establishedSession;
1089
+ return r && t && (n = n.then(async () => r.sendInfo(D, void 0, {
1090
+ extraHeaders: i
1091
+ })).then(async () => r.stopPresentation(t)).catch((a) => {
1092
+ throw this._sessionEvents.trigger(L, a), a;
1093
+ })), !r && t && this._sessionEvents.trigger(Ie, t), this.promisePendingStopPresentation = n, n.finally(() => {
1094
+ this._resetPresentation();
1095
+ });
1096
+ }
1097
+ async updatePresentation(e, {
1098
+ isP2P: t,
1099
+ maxBitrate: n,
1100
+ onAddedSender: i,
1101
+ contentHint: r
1102
+ } = {}) {
1103
+ const a = this.establishedSession;
1104
+ if (!a)
1105
+ throw new Error("No session established");
1106
+ if (!this._streamPresentationCurrent)
1107
+ throw new Error("Presentation has not started yet");
1108
+ return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this._sendPresentation(a, e, {
1109
+ isP2P: t,
1110
+ maxBitrate: n,
1111
+ onAddedSender: i,
1112
+ contentHint: r,
1113
+ isNeedReinvite: !1
1114
+ });
1115
+ }
1116
+ _removeStreamPresentationCurrent() {
1117
+ delete this._streamPresentationCurrent;
1118
+ }
1119
+ _resetPresentation() {
1120
+ this._removeStreamPresentationCurrent(), this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
1121
+ }
1122
+ _cancelRequestsAndResetPresentation() {
1123
+ this._cancelSendPresentationWithRepeatedCalls(), this._resetPresentation();
1124
+ }
1125
+ on(e, t) {
1126
+ return this._uaEvents.on(e, t);
1127
+ }
1128
+ once(e, t) {
1129
+ return this._uaEvents.once(e, t);
1130
+ }
1131
+ onceRace(e, t) {
1132
+ return this._uaEvents.onceRace(e, t);
1133
+ }
1134
+ async wait(e) {
1135
+ return this._uaEvents.wait(e);
1136
+ }
1137
+ off(e, t) {
1138
+ this._uaEvents.off(e, t);
1139
+ }
1140
+ onSession(e, t) {
1141
+ return this._sessionEvents.on(e, t);
1142
+ }
1143
+ onceSession(e, t) {
1144
+ return this._sessionEvents.once(e, t);
1145
+ }
1146
+ onceRaceSession(e, t) {
1147
+ return this._sessionEvents.onceRace(e, t);
1148
+ }
1149
+ async waitSession(e) {
1150
+ return this._sessionEvents.wait(e);
1151
+ }
1152
+ offSession(e, t) {
1153
+ this._sessionEvents.off(e, t);
1154
+ }
1155
+ isConfigured() {
1156
+ return !!this.ua;
1157
+ }
1158
+ getConnectionConfiguration() {
1159
+ return { ...this._connectionConfiguration };
1160
+ }
1161
+ getRemoteStreams() {
1162
+ if (!this.connection)
1163
+ return;
1164
+ const t = this.connection.getReceivers().map(({ track: n }) => n);
1165
+ return fn(t) ? this._generateStreams(t) : this._generateAudioStreams(t);
1166
+ }
1167
+ get connection() {
1168
+ var t;
1169
+ return (t = this.session) == null ? void 0 : t.connection;
1170
+ }
1171
+ get remoteCallerData() {
1172
+ var e, t, n, i, r, a;
1173
+ return {
1174
+ displayName: (t = (e = this.incomingSession) == null ? void 0 : e.remote_identity) == null ? void 0 : t.display_name,
1175
+ host: (i = (n = this.incomingSession) == null ? void 0 : n.remote_identity) == null ? void 0 : i.uri.host,
1176
+ incomingNumber: (a = (r = this.incomingSession) == null ? void 0 : r.remote_identity) == null ? void 0 : a.uri.user,
1177
+ session: this.incomingSession
1178
+ };
1179
+ }
1180
+ get requested() {
1181
+ return this._cancelableConnect.requested || this._cancelableInitUa.requested || this._cancelableCall.requested || this._cancelableAnswer.requested;
1182
+ }
1183
+ get establishedSession() {
1184
+ var e;
1185
+ return (e = this.session) != null && e.isEstablished() ? this.session : void 0;
1186
+ }
1187
+ get isRegistered() {
1188
+ return !!this.ua && this.ua.isRegistered();
1189
+ }
1190
+ get isRegisterConfig() {
1191
+ return !!this.ua && this._isRegisterConfig;
1192
+ }
1193
+ get isCallActive() {
1194
+ return !!(this.ua && this.session);
1195
+ }
1196
+ get isAvailableIncomingCall() {
1197
+ return !!this.incomingSession;
1198
+ }
1199
+ _generateStream(e, t) {
1200
+ const { id: n } = e, i = this._remoteStreams[n] || new MediaStream();
1201
+ return t && i.addTrack(t), i.addTrack(e), this._remoteStreams[n] = i, i;
1202
+ }
1203
+ _generateAudioStream(e) {
1204
+ const { id: t } = e, n = this._remoteStreams[t] || new MediaStream();
1205
+ return n.addTrack(e), this._remoteStreams[t] = n, n;
1206
+ }
1207
+ _generateStreams(e) {
1208
+ const t = [];
1209
+ return e.forEach((n, i) => {
1210
+ if (n.kind === "audio")
1211
+ return;
1212
+ const r = n, a = e[i - 1];
1213
+ let c;
1214
+ a && a.kind === "audio" && (c = a);
1215
+ const E = this._generateStream(r, c);
1216
+ t.push(E);
1217
+ }), t;
1218
+ }
1219
+ _generateAudioStreams(e) {
1220
+ return e.map((n) => this._generateAudioStream(n));
1221
+ }
1222
+ _cancelRequests() {
1223
+ this._cancelActionsRequests(), this._cancelCallRequests(), this._cancelConnectWithRepeatedCalls();
1224
+ }
1225
+ _cancelConnectWithRepeatedCalls() {
1226
+ var e;
1227
+ (e = this._cancelableConnectWithRepeatedCalls) == null || e.cancel();
1228
+ }
1229
+ _cancelSendPresentationWithRepeatedCalls() {
1230
+ var e;
1231
+ (e = this._cancelableSendPresentationWithRepeatedCalls) == null || e.cancel();
1232
+ }
1233
+ _cancelCallRequests() {
1234
+ this._cancelableCall.cancelRequest(), this._cancelableAnswer.cancelRequest();
1235
+ }
1236
+ _cancelActionsRequests() {
1237
+ this._cancelableAnswer.cancelRequest(), this._cancelableSendDTMF.cancelRequest();
1238
+ }
1239
+ async waitChannels() {
1240
+ return this.waitSession(y);
1241
+ }
1242
+ async waitSyncMediaState() {
1243
+ return this.waitSession(w);
1244
+ }
1245
+ async sendChannels({ inputChannels: e, outputChannels: t }) {
1246
+ if (!this.session)
1247
+ throw new Error("No session established");
1248
+ const n = `${ve}: ${e}`, i = `${ye}: ${t}`, r = [
1249
+ n,
1250
+ i
1251
+ ];
1252
+ return this.session.sendInfo($t, void 0, { extraHeaders: r });
1253
+ }
1254
+ async sendMediaState({ cam: e, mic: t }, n = {}) {
1255
+ if (!this.session)
1256
+ throw new Error("No session established");
1257
+ const i = `${nn}: currentstate`, r = `${on}: ${Number(e)}`, a = `${rn}: ${Number(t)}`, c = [
1258
+ i,
1259
+ r,
1260
+ a
1261
+ ];
1262
+ return this.session.sendInfo(Jt, void 0, {
1263
+ noTerminateWhenError: !0,
1264
+ ...n,
1265
+ extraHeaders: c
1266
+ });
1267
+ }
1268
+ async _sendRefusalToTurnOn(e, t = {}) {
1269
+ if (!this.session)
1270
+ throw new Error("No session established");
1271
+ const c = [`${sn}: ${e === "mic" ? 0 : 1}`];
1272
+ return this.session.sendInfo(Xt, void 0, {
1273
+ noTerminateWhenError: !0,
1274
+ ...t,
1275
+ extraHeaders: c
1276
+ });
1277
+ }
1278
+ async sendRefusalToTurnOnMic(e = {}) {
1279
+ if (!this.session)
1280
+ throw new Error("No session established");
1281
+ return this._sendRefusalToTurnOn("mic", { noTerminateWhenError: !0, ...e });
1282
+ }
1283
+ async sendRefusalToTurnOnCam(e = {}) {
1284
+ if (!this.session)
1285
+ throw new Error("No session established");
1286
+ return this._sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
1287
+ }
1288
+ }
1289
+ export {
1290
+ qt as B,
1291
+ I as E,
1292
+ Mt as N,
1293
+ He as R,
1294
+ Ts as S,
1295
+ dt as U,
1296
+ qn as a,
1297
+ _s as b,
1298
+ cs as c,
1299
+ hs as d,
1300
+ Es as e,
1301
+ ds as f,
1302
+ B as g,
1303
+ ls as h,
1304
+ q as i,
1305
+ Cn as j,
1306
+ ht as k,
1307
+ k as l,
1308
+ Bn as s
1309
+ };