sip-connector 6.25.0 → 7.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.
@@ -4,7 +4,7 @@ var i = (r, e, t) => (Rt(r, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import { CancelableRequest as N, isCanceledError as It } from "@krivega/cancelable-promise";
5
5
  import Oe from "events-constructor";
6
6
  import F from "debug";
7
- const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code", Ot = "Internal Error", Pt = "Busy", Le = "Rejected", Mt = "Redirected", Dt = "Unavailable", pt = "Not Found", vt = "Address Incomplete", wt = "Incompatible SDP", yt = "Missing SDP", bt = "Authentication Error", He = "Terminated", Ut = "WebRTC Error", ke = "Canceled", Lt = "No Answer", Ht = "Expires", kt = "No ACK", qt = "Dialog Error", Wt = "User Denied Media Access", Ft = "Bad Media Description", Bt = "RTP Timeout", Xs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
7
+ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code", Ot = "Internal Error", Pt = "Busy", Le = "Rejected", Mt = "Redirected", pt = "Unavailable", Dt = "Not Found", vt = "Address Incomplete", wt = "Incompatible SDP", yt = "Missing SDP", bt = "Authentication Error", He = "Terminated", Ut = "WebRTC Error", ke = "Canceled", Lt = "No Answer", Ht = "Expires", kt = "No ACK", qt = "Dialog Error", Wt = "User Denied Media Access", Ft = "Bad Media Description", Bt = "RTP Timeout", Js = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8
8
  __proto__: null,
9
9
  ADDRESS_INCOMPLETE: vt,
10
10
  AUTHENTICATION_ERROR: bt,
@@ -18,7 +18,7 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
18
18
  INCOMPATIBLE_SDP: wt,
19
19
  INTERNAL_ERROR: Ot,
20
20
  MISSING_SDP: yt,
21
- NOT_FOUND: pt,
21
+ NOT_FOUND: Dt,
22
22
  NO_ACK: kt,
23
23
  NO_ANSWER: Lt,
24
24
  REDIRECTED: Mt,
@@ -26,10 +26,10 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
26
26
  REQUEST_TIMEOUT: Ue,
27
27
  RTP_TIMEOUT: Bt,
28
28
  SIP_FAILURE_CODE: ft,
29
- UNAVAILABLE: Dt,
29
+ UNAVAILABLE: pt,
30
30
  USER_DENIED_MEDIA_ACCESS: Wt,
31
31
  WEBRTC_ERROR: Ut
32
- }, Symbol.toStringTag, { value: "Module" })), B = "incomingCall", V = "declinedIncomingCall", Y = "failedIncomingCall", x = "terminatedIncomingCall", L = "connecting", m = "connected", u = "disconnected", D = "newRTCSession", f = "registered", $ = "unregistered", O = "registrationFailed", qe = "newMessage", G = "sipEvent", X = "availableSecondRemoteStream", J = "notAvailableSecondRemoteStream", z = "mustStopPresentation", p = "shareState", Q = "enterRoom", K = "useLicense", j = "peerconnection:confirmed", Z = "peerconnection:ontrack", v = "channels", ee = "channels:notify", te = "ended:fromserver", se = "main-cam-control", ne = "admin-stop-main-cam", ie = "admin-start-main-cam", re = "admin-stop-mic", oe = "admin-start-mic", w = "admin-force-sync-media-state", ae = "participant:added-to-list-moderators", ce = "participant:removed-from-list-moderators", Ee = "participant:move-request-to-stream", _e = "participant:move-request-to-spectators", he = "participation:accepting-word-request", de = "participation:cancelling-word-request", le = "webcast:started", Te = "webcast:stopped", ue = "account:changed", Se = "account:deleted", Ne = "conference:participant-token-issued", P = "ended", We = "sending", Fe = "reinvite", Be = "replaces", Ve = "refer", Ye = "progress", xe = "accepted", y = "confirmed", b = "peerconnection", C = "failed", $e = "muted", Ge = "unmuted", ge = "newDTMF", Ce = "newInfo", Xe = "hold", Je = "unhold", ze = "update", Qe = "sdp", Ke = "icecandidate", je = "getusermediafailed", Ze = "peerconnection:createofferfailed", et = "peerconnection:createanswerfailed", tt = "peerconnection:setlocaldescriptionfailed", st = "peerconnection:setremotedescriptionfailed", nt = "presentation:start", it = "presentation:started", rt = "presentation:end", Ae = "presentation:ended", U = "presentation:failed", ot = "SPECTATOR", Js = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
32
+ }, Symbol.toStringTag, { value: "Module" })), B = "incomingCall", V = "declinedIncomingCall", Y = "failedIncomingCall", x = "terminatedIncomingCall", L = "connecting", m = "connected", u = "disconnected", p = "newRTCSession", f = "registered", $ = "unregistered", O = "registrationFailed", qe = "newMessage", G = "sipEvent", X = "availableSecondRemoteStream", J = "notAvailableSecondRemoteStream", z = "mustStopPresentation", D = "shareState", Q = "enterRoom", K = "useLicense", j = "peerconnection:confirmed", Z = "peerconnection:ontrack", v = "channels", ee = "channels:notify", te = "ended:fromserver", se = "main-cam-control", ne = "admin-stop-main-cam", ie = "admin-start-main-cam", re = "admin-stop-mic", oe = "admin-start-mic", w = "admin-force-sync-media-state", ae = "participant:added-to-list-moderators", ce = "participant:removed-from-list-moderators", Ee = "participant:move-request-to-stream", _e = "participant:move-request-to-spectators", he = "participation:accepting-word-request", de = "participation:cancelling-word-request", Te = "webcast:started", le = "webcast:stopped", ue = "account:changed", Se = "account:deleted", Ne = "conference:participant-token-issued", P = "ended", We = "sending", Fe = "reinvite", Be = "replaces", Ve = "refer", Ye = "progress", xe = "accepted", y = "confirmed", b = "peerconnection", C = "failed", $e = "muted", Ge = "unmuted", ge = "newDTMF", Ce = "newInfo", Xe = "hold", Je = "unhold", ze = "update", Qe = "sdp", Ke = "icecandidate", je = "getusermediafailed", Ze = "peerconnection:createofferfailed", et = "peerconnection:createanswerfailed", tt = "peerconnection:setlocaldescriptionfailed", st = "peerconnection:setremotedescriptionfailed", nt = "presentation:start", it = "presentation:started", rt = "presentation:end", Ae = "presentation:ended", U = "presentation:failed", ot = "SPECTATOR", zs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
33
33
  __proto__: null,
34
34
  ACCEPTED: xe,
35
35
  ACCOUNT_CHANGED: ue,
@@ -63,7 +63,7 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
63
63
  NEW_DTMF: ge,
64
64
  NEW_INFO: Ce,
65
65
  NEW_MESSAGE: qe,
66
- NEW_RTC_SESSION: D,
66
+ NEW_RTC_SESSION: p,
67
67
  NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT: J,
68
68
  PARTICIPANT_ADDED_TO_LIST_MODERATORS: ae,
69
69
  PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS: _e,
@@ -91,7 +91,7 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
91
91
  REPLACES: Be,
92
92
  SDP: Qe,
93
93
  SENDING: We,
94
- SHARE_STATE: p,
94
+ SHARE_STATE: D,
95
95
  SIP_EVENT: G,
96
96
  SPECTATOR: ot,
97
97
  TERMINATED_INCOMING_CALL: x,
@@ -100,8 +100,8 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
100
100
  UNREGISTERED: $,
101
101
  UPDATE: ze,
102
102
  USE_LICENSE: K,
103
- WEBCAST_STARTED: le,
104
- WEBCAST_STOPPED: Te
103
+ WEBCAST_STARTED: Te,
104
+ WEBCAST_STOPPED: le
105
105
  }, Symbol.toStringTag, { value: "Module" })), at = [
106
106
  B,
107
107
  V,
@@ -114,15 +114,15 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
114
114
  Ne,
115
115
  ue,
116
116
  Se,
117
- le,
118
117
  Te,
118
+ le,
119
119
  ae,
120
120
  ce
121
121
  ], Re = [
122
122
  L,
123
123
  m,
124
124
  u,
125
- D,
125
+ p,
126
126
  f,
127
127
  $,
128
128
  O,
@@ -132,7 +132,7 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
132
132
  X,
133
133
  J,
134
134
  z,
135
- p,
135
+ D,
136
136
  Q,
137
137
  K,
138
138
  j,
@@ -180,7 +180,7 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
180
180
  ], Et = [...Re, ...at], _t = [
181
181
  ...Ie,
182
182
  ...ct
183
- ], zs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
183
+ ], Qs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
184
184
  __proto__: null,
185
185
  SESSION_EVENT_NAMES: _t,
186
186
  SESSION_JSSIP_EVENT_NAMES: Ie,
@@ -191,16 +191,16 @@ const mt = "Connection Error", Ue = "Request Timeout", ft = "SIP Failure Code",
191
191
  }, Symbol.toStringTag, { value: "Module" })), Vt = (r) => {
192
192
  const e = [];
193
193
  return r && e.push(`X-Vinteo-Remote: ${r}`), e;
194
- }, Yt = "content-type", xt = "x-webrtc-enter-room", M = "application/vinteo.webrtc.sharedesktop", $t = "application/vinteo.webrtc.roomname", Gt = "application/vinteo.webrtc.channels", Xt = "application/vinteo.webrtc.mediastate", Jt = "application/vinteo.webrtc.refusal", Pe = "application/vinteo.webrtc.maincam", zt = "application/vinteo.webrtc.mic", Qt = "application/vinteo.webrtc.uselic", Kt = "X-WEBRTC-USE-LICENSE", Me = "X-WEBRTC-INPUT-CHANNELS", De = "X-WEBRTC-OUTPUT-CHANNELS", jt = "X-WEBRTC-MAINCAM", Zt = "X-WEBRTC-MIC", pe = "X-WEBRTC-SYNC", es = "X-WEBRTC-MAINCAM-RESOLUTION", ts = "X-WEBRTC-MEDIA-STATE", ss = "X-Vinteo-Media-Type", ns = "X-Vinteo-MainCam-State", is = "X-Vinteo-Mic-State", rs = "application/vinteo.webrtc.partstate", os = "X-WEBRTC-PARTSTATE", as = "application/vinteo.webrtc.notify", cs = "X-VINTEO-NOTIFY", A = "x-webrtc-share-state", Es = `${A}: LETMESTARTPRESENTATION`, _s = `${A}: STOPPRESENTATION`, ht = "YOUCANRECEIVECONTENT", dt = "CONTENTEND", lt = "YOUMUSTSTOPSENDCONTENT", hs = `${A}: ${lt}`, ds = `${A}: ${ht}`, ls = `${A}: ${dt}`, Ts = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", us = `${Ts}: LETMESTARTMAINCAM`, me = "sip-connector", ve = F(me), Qs = () => {
194
+ }, Yt = "content-type", xt = "x-webrtc-enter-room", M = "application/vinteo.webrtc.sharedesktop", $t = "application/vinteo.webrtc.roomname", Gt = "application/vinteo.webrtc.channels", Xt = "application/vinteo.webrtc.mediastate", Jt = "application/vinteo.webrtc.refusal", Pe = "application/vinteo.webrtc.maincam", zt = "application/vinteo.webrtc.mic", Qt = "application/vinteo.webrtc.uselic", Kt = "X-WEBRTC-USE-LICENSE", jt = "X-WEBRTC-PARTICIPANT-NAME", Me = "X-WEBRTC-INPUT-CHANNELS", pe = "X-WEBRTC-OUTPUT-CHANNELS", Zt = "X-WEBRTC-MAINCAM", es = "X-WEBRTC-MIC", De = "X-WEBRTC-SYNC", ts = "X-WEBRTC-MAINCAM-RESOLUTION", ss = "X-WEBRTC-MEDIA-STATE", ns = "X-Vinteo-Media-Type", is = "X-Vinteo-MainCam-State", rs = "X-Vinteo-Mic-State", os = "application/vinteo.webrtc.partstate", as = "X-WEBRTC-PARTSTATE", cs = "application/vinteo.webrtc.notify", Es = "X-VINTEO-NOTIFY", A = "x-webrtc-share-state", _s = `${A}: LETMESTARTPRESENTATION`, hs = `${A}: STOPPRESENTATION`, ht = "YOUCANRECEIVECONTENT", dt = "CONTENTEND", Tt = "YOUMUSTSTOPSENDCONTENT", ds = `${A}: ${Tt}`, Ts = `${A}: ${ht}`, ls = `${A}: ${dt}`, us = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", Ss = `${us}: LETMESTARTMAINCAM`, me = "sip-connector", ve = F(me), Ks = () => {
195
195
  F.enable(me);
196
- }, Ks = () => {
196
+ }, js = () => {
197
197
  F.enable(`-${me}`);
198
198
  };
199
- var I = /* @__PURE__ */ ((r) => (r.PAUSE_MAIN_CAM = "PAUSEMAINCAM", r.RESUME_MAIN_CAM = "RESUMEMAINCAM", r.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", r.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", r.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", r))(I || {}), k = /* @__PURE__ */ ((r) => (r.ADMIN_STOP_MIC = "ADMINSTOPMIC", r.ADMIN_START_MIC = "ADMINSTARTMIC", r))(k || {}), q = /* @__PURE__ */ ((r) => (r.ADMIN_SYNC_FORCED = "1", r.ADMIN_SYNC_NOT_FORCED = "0", r))(q || {}), Ss = /* @__PURE__ */ ((r) => (r.AUDIO = "AUDIO", r.VIDEO = "VIDEO", r.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", r))(Ss || {});
199
+ var I = /* @__PURE__ */ ((r) => (r.PAUSE_MAIN_CAM = "PAUSEMAINCAM", r.RESUME_MAIN_CAM = "RESUMEMAINCAM", r.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", r.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", r.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", r))(I || {}), k = /* @__PURE__ */ ((r) => (r.ADMIN_STOP_MIC = "ADMINSTOPMIC", r.ADMIN_START_MIC = "ADMINSTARTMIC", r))(k || {}), q = /* @__PURE__ */ ((r) => (r.ADMIN_SYNC_FORCED = "1", r.ADMIN_SYNC_NOT_FORCED = "0", r))(q || {}), Ns = /* @__PURE__ */ ((r) => (r.AUDIO = "AUDIO", r.VIDEO = "VIDEO", r.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", r))(Ns || {});
200
200
  function we(r) {
201
201
  return (e) => `sip:${e}@${r}`;
202
202
  }
203
- const Ns = (r, e) => () => Math.floor(Math.random() * (e - r)) + r, ye = (r) => r.trim().replaceAll(" ", "_"), gs = Ns(1e5, 99999999), H = (r, {
203
+ const gs = (r, e) => () => Math.floor(Math.random() * (e - r)) + r, ye = (r) => r.trim().replaceAll(" ", "_"), Cs = gs(1e5, 99999999), H = (r, {
204
204
  videoMode: e,
205
205
  audioMode: t
206
206
  } = {}) => {
@@ -208,41 +208,41 @@ const Ns = (r, e) => () => Math.floor(Math.random() * (e - r)) + r, ye = (r) =>
208
208
  return;
209
209
  const s = t === "recvonly" ? [] : r.getAudioTracks(), n = e === "recvonly" ? [] : r.getVideoTracks(), o = [...s, ...n], a = new MediaStream(o);
210
210
  return a.getTracks = () => [...a.getAudioTracks(), ...a.getVideoTracks()], a;
211
- }, Cs = (r) => r.some((t) => {
211
+ }, As = (r) => r.some((t) => {
212
212
  const { kind: s } = t;
213
213
  return s === "video";
214
- }), As = "Error decline with 603", Rs = (r) => r.message === As, Is = (r, e) => r.find((t) => t.track && e.getTracks().includes(t.track)), Tt = 1, ut = (r) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== r, ms = ut(
215
- Tt
216
- ), fs = (r, e) => {
217
- const t = r === void 0 ? void 0 : Math.max(r, Tt);
218
- if (t !== void 0 && ms(
214
+ }), Rs = "Error decline with 603", Is = (r) => r.message === Rs, ms = (r, e) => r.find((t) => t.track && e.getTracks().includes(t.track)), lt = 1, ut = (r) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== r, fs = ut(
215
+ lt
216
+ ), Os = (r, e) => {
217
+ const t = r === void 0 ? void 0 : Math.max(r, lt);
218
+ if (t !== void 0 && fs(
219
219
  t,
220
220
  e
221
221
  ))
222
222
  return t;
223
- }, Os = ut(), Ps = (r, e) => {
224
- if (Os(r, e))
223
+ }, Ps = ut(), Ms = (r, e) => {
224
+ if (Ps(r, e))
225
225
  return r;
226
- }, Ms = async (r, e, t) => {
226
+ }, ps = async (r, e, t) => {
227
227
  const s = r.getParameters();
228
228
  (s.encodings === void 0 || s.encodings.length === 0) && (s.encodings = [{}]);
229
- const [n] = s.encodings, o = n.scaleResolutionDownBy, a = fs(
229
+ const [n] = s.encodings, o = n.scaleResolutionDownBy, a = Os(
230
230
  e.scaleResolutionDownBy,
231
231
  o
232
232
  );
233
233
  let c = !1;
234
234
  a !== void 0 && (s.encodings[0].scaleResolutionDownBy = a, c = !0);
235
- const E = n.maxBitrate, _ = Ps(e.maxBitrate, E);
235
+ const E = n.maxBitrate, _ = Ms(e.maxBitrate, E);
236
236
  return _ !== void 0 && (s.encodings[0].maxBitrate = _, c = !0), c ? (t && t(s), r.setParameters(s).then(() => ({ parameters: s, isChanged: c }))) : { parameters: s, isChanged: c };
237
237
  }, Ds = async (r, e, t) => {
238
- const s = Is(r, e);
238
+ const s = ms(r, e);
239
239
  if (s)
240
- return Ms(s, { maxBitrate: t });
241
- }, ps = 486, vs = 487, W = "local", be = "remote", js = (r = new Error()) => {
240
+ return ps(s, { maxBitrate: t });
241
+ }, vs = 486, ws = 487, W = "local", be = "remote", Zs = (r = new Error()) => {
242
242
  const { originator: e, cause: t } = r;
243
243
  return It(r) ? !0 : typeof t == "string" ? t === Ue || t === Le || e === W && (t === ke || t === He) : !1;
244
- }, g = "SipConnector", ws = "channels", ys = "WebcastStarted", bs = "WebcastStopped", Us = "accountChanged", Ls = "accountDeleted", Hs = "addedToListModerators", ks = "removedFromListModerators", qs = "ParticipationRequestAccepted", Ws = "ParticipationRequestRejected", Fs = "ParticipantMovedToWebcast", Bs = "ConferenceParticipantTokenIssued";
245
- class Zs {
244
+ }, g = "SipConnector", ys = "channels", bs = "WebcastStarted", Us = "WebcastStopped", Ls = "accountChanged", Hs = "accountDeleted", ks = "addedToListModerators", qs = "removedFromListModerators", Ws = "ParticipationRequestAccepted", Fs = "ParticipationRequestRejected", Bs = "ParticipantMovedToWebcast", Vs = "ConferenceParticipantTokenIssued";
245
+ class en {
246
246
  constructor({ JsSIP: e }) {
247
247
  i(this, "_isRegisterConfig", !1);
248
248
  i(this, "_connectionConfiguration", {});
@@ -284,7 +284,7 @@ class Zs {
284
284
  }
285
285
  return this.register();
286
286
  });
287
- i(this, "declineToIncomingCall", async ({ statusCode: e = vs } = {}) => new Promise((t, s) => {
287
+ i(this, "declineToIncomingCall", async ({ statusCode: e = ws } = {}) => new Promise((t, s) => {
288
288
  if (!this.isAvailableIncomingCall) {
289
289
  s(new Error("no incomingSession"));
290
290
  return;
@@ -292,7 +292,7 @@ class Zs {
292
292
  const n = this.incomingSession, o = this.remoteCallerData;
293
293
  this._cancelableCall.cancelRequest(), this._cancelableAnswer.cancelRequest(), this.removeIncomingSession(), this._uaEvents.trigger(V, o), t(n.terminate({ status_code: e }));
294
294
  }));
295
- i(this, "busyIncomingCall", async () => this.declineToIncomingCall({ statusCode: ps }));
295
+ i(this, "busyIncomingCall", async () => this.declineToIncomingCall({ statusCode: vs }));
296
296
  i(this, "removeIncomingSession", () => {
297
297
  delete this.incomingSession;
298
298
  });
@@ -317,39 +317,39 @@ class Zs {
317
317
  registerExpires: E,
318
318
  connectionRecoveryMinInterval: _,
319
319
  connectionRecoveryMaxInterval: h,
320
- userAgent: T,
320
+ userAgent: l,
321
321
  displayName: d = "",
322
- register: l = !1,
322
+ register: T = !1,
323
323
  extraHeaders: S = []
324
324
  }) => {
325
325
  if (!s)
326
326
  throw new Error("sipServerUrl is required");
327
327
  if (!n)
328
328
  throw new Error("sipWebSocketServerURL is required");
329
- if (l && !e)
329
+ if (T && !e)
330
330
  throw new Error("user is required for authorized connection");
331
- if (l && !t)
331
+ if (T && !t)
332
332
  throw new Error("password is required for authorized connection");
333
333
  this._connectionConfiguration = {
334
334
  sipServerUrl: s,
335
335
  displayName: d,
336
- register: l,
336
+ register: T,
337
337
  user: e,
338
338
  password: t
339
- }, this.getSipServerUrl = we(s), this.socket = new this.JsSIP.WebSocketInterface(n), this.ua && await this._disconnectWithoutCancelRequests(), this._isRegisterConfig = !!l;
339
+ }, this.getSipServerUrl = we(s), this.socket = new this.JsSIP.WebSocketInterface(n), this.ua && await this._disconnectWithoutCancelRequests(), this._isRegisterConfig = !!T;
340
340
  const { socket: R } = this;
341
341
  this.ua = this._createUa({
342
342
  user: e,
343
343
  password: t,
344
344
  socket: R,
345
345
  displayName: d,
346
- register: l,
346
+ register: T,
347
347
  sdpSemantics: a,
348
348
  sessionTimers: c,
349
349
  registerExpires: E,
350
350
  connectionRecoveryMinInterval: _,
351
351
  connectionRecoveryMaxInterval: h,
352
- userAgent: T,
352
+ userAgent: l,
353
353
  getSipServerUrl: this.getSipServerUrl
354
354
  }), this._uaEvents.eachTriggers((Nt, gt) => {
355
355
  const fe = Re.find((Ct) => Ct === gt);
@@ -370,12 +370,12 @@ class Zs {
370
370
  registerExpires: _ = 60 * 5,
371
371
  // 5 minutes in sec
372
372
  connectionRecoveryMinInterval: h = 2,
373
- connectionRecoveryMaxInterval: T = 6,
373
+ connectionRecoveryMaxInterval: l = 6,
374
374
  userAgent: d
375
375
  }) => {
376
376
  if (a && !t)
377
377
  throw new Error("password is required for authorized connection");
378
- const l = a && e ? e.trim() : `${gs()}`, S = o(l), R = {
378
+ const T = a && e ? e.trim() : `${Cs()}`, S = o(T), R = {
379
379
  password: t,
380
380
  register: a,
381
381
  uri: S,
@@ -386,7 +386,7 @@ class Zs {
386
386
  session_timers: E,
387
387
  register_expires: _,
388
388
  connection_recovery_min_interval: h,
389
- connection_recovery_max_interval: T
389
+ connection_recovery_max_interval: l
390
390
  };
391
391
  return new this.JsSIP.UA(R);
392
392
  });
@@ -405,7 +405,7 @@ class Zs {
405
405
  }, c = () => {
406
406
  this.off(f, n), this.off(O, o), this.off(m, n), this.off(u, o);
407
407
  };
408
- a(), this.on(D, this.handleNewRTCSession), s.start();
408
+ a(), this.on(p, this.handleNewRTCSession), s.start();
409
409
  }));
410
410
  i(this, "_set", async ({ displayName: e, password: t }) => new Promise((s, n) => {
411
411
  const { ua: o } = this;
@@ -424,7 +424,7 @@ class Zs {
424
424
  }));
425
425
  i(this, "_disconnectWithoutCancelRequests", async () => this._cancelableDisconnect.request());
426
426
  i(this, "_disconnect", async () => {
427
- this.off(D, this.handleNewRTCSession);
427
+ this.off(p, this.handleNewRTCSession);
428
428
  const e = new Promise((t) => {
429
429
  this.once(u, () => {
430
430
  delete this.ua, t();
@@ -443,15 +443,15 @@ class Zs {
443
443
  degradationPreference: E,
444
444
  offerToReceiveAudio: _ = !0,
445
445
  offerToReceiveVideo: h = !0
446
- }) => new Promise((T, d) => {
447
- const { ua: l } = this;
448
- if (!l) {
446
+ }) => new Promise((l, d) => {
447
+ const { ua: T } = this;
448
+ if (!T) {
449
449
  d(new Error("this.ua is not initialized"));
450
450
  return;
451
451
  }
452
- this._connectionConfiguration.number = e, this._connectionConfiguration.answer = !1, this._handleCall({ ontrack: n }).then(T).catch((S) => {
452
+ this._connectionConfiguration.number = e, this._connectionConfiguration.answer = !1, this._handleCall({ ontrack: n }).then(l).catch((S) => {
453
453
  d(S);
454
- }), this.session = l.call(this.getSipServerUrl(e), {
454
+ }), this.session = T.call(this.getSipServerUrl(e), {
455
455
  extraHeaders: s,
456
456
  mediaStream: H(t, {
457
457
  videoMode: a,
@@ -489,13 +489,13 @@ class Zs {
489
489
  _(new Error("No session established"));
490
490
  return;
491
491
  }
492
- this._sessionEvents.eachTriggers((d, l) => {
493
- const S = Ie.find((R) => R === l);
492
+ this._sessionEvents.eachTriggers((d, T) => {
493
+ const S = Ie.find((R) => R === T);
494
494
  S && h.on(S, d);
495
495
  }), this._connectionConfiguration.answer = !0, this._connectionConfiguration.number = h.remote_identity.uri.user, this._handleCall({ ontrack: t }).then(E).catch((d) => {
496
496
  _(d);
497
497
  });
498
- const T = H(e, {
498
+ const l = H(e, {
499
499
  videoMode: o,
500
500
  audioMode: a
501
501
  });
@@ -504,7 +504,7 @@ class Zs {
504
504
  videoMode: o,
505
505
  audioMode: a,
506
506
  degradationPreference: c,
507
- mediaStream: T,
507
+ mediaStream: l,
508
508
  pcConfig: {
509
509
  iceServers: n
510
510
  }
@@ -512,9 +512,9 @@ class Zs {
512
512
  }));
513
513
  i(this, "_handleCall", async ({ ontrack: e }) => new Promise((t, s) => {
514
514
  const n = () => {
515
- this.onSession(b, h), this.onSession(y, T);
515
+ this.onSession(b, h), this.onSession(y, l);
516
516
  }, o = () => {
517
- this.offSession(b, h), this.offSession(y, T);
517
+ this.offSession(b, h), this.offSession(y, l);
518
518
  }, a = () => {
519
519
  this.onSession(C, E), this.onSession(P, E);
520
520
  }, c = () => {
@@ -524,10 +524,10 @@ class Zs {
524
524
  };
525
525
  let _;
526
526
  const h = ({ peerconnection: d }) => {
527
- _ = d, _.ontrack = (l) => {
528
- this._sessionEvents.trigger(Z, _), e && e(l);
527
+ _ = d, _.ontrack = (T) => {
528
+ this._sessionEvents.trigger(Z, _), e && e(T);
529
529
  };
530
- }, T = () => {
530
+ }, l = () => {
531
531
  _ && this._sessionEvents.trigger(j, _), o(), c(), t(_);
532
532
  };
533
533
  n(), a();
@@ -564,14 +564,14 @@ class Zs {
564
564
  this._sessionEvents.trigger(J, void 0);
565
565
  break;
566
566
  }
567
- case lt: {
567
+ case Tt: {
568
568
  this._sessionEvents.trigger(z, void 0);
569
569
  break;
570
570
  }
571
571
  }
572
572
  });
573
573
  i(this, "_maybeTriggerChannels", (e) => {
574
- const t = e.getHeader(Me), s = e.getHeader(De);
574
+ const t = e.getHeader(Me), s = e.getHeader(pe);
575
575
  if (t && s) {
576
576
  const n = {
577
577
  inputChannels: t,
@@ -582,55 +582,55 @@ class Zs {
582
582
  });
583
583
  i(this, "_handleNotify", (e) => {
584
584
  switch (e.cmd) {
585
- case ws: {
585
+ case ys: {
586
586
  const t = e;
587
587
  this._triggerChannelsNotify(t);
588
588
  break;
589
589
  }
590
- case ys: {
590
+ case bs: {
591
591
  const t = e;
592
592
  this._triggerWebcastStartedNotify(t);
593
593
  break;
594
594
  }
595
- case bs: {
595
+ case Us: {
596
596
  const t = e;
597
597
  this._triggerWebcastStoppedNotify(t);
598
598
  break;
599
599
  }
600
- case Hs: {
600
+ case ks: {
601
601
  const t = e;
602
602
  this._triggerAddedToListModeratorsNotify(t);
603
603
  break;
604
604
  }
605
- case ks: {
605
+ case qs: {
606
606
  const t = e;
607
607
  this._triggerRemovedFromListModeratorsNotify(t);
608
608
  break;
609
609
  }
610
- case qs: {
610
+ case Ws: {
611
611
  const t = e;
612
612
  this._triggerParticipationAcceptingWordRequest(t);
613
613
  break;
614
614
  }
615
- case Ws: {
615
+ case Fs: {
616
616
  const t = e;
617
617
  this._triggerParticipationCancellingWordRequest(t);
618
618
  break;
619
619
  }
620
- case Fs: {
620
+ case Bs: {
621
621
  const t = e;
622
622
  this._triggerParticipantMoveRequestToStream(t);
623
623
  break;
624
624
  }
625
- case Us: {
625
+ case Ls: {
626
626
  this._triggerAccountChangedNotify();
627
627
  break;
628
628
  }
629
- case Ls: {
629
+ case Hs: {
630
630
  this._triggerAccountDeletedNotify();
631
631
  break;
632
632
  }
633
- case Bs: {
633
+ case Vs: {
634
634
  const t = e;
635
635
  this._triggerConferenceParticipantTokenIssued(t);
636
636
  break;
@@ -661,14 +661,14 @@ class Zs {
661
661
  conference: e,
662
662
  type: t
663
663
  };
664
- this._uaEvents.trigger(le, s);
664
+ this._uaEvents.trigger(Te, s);
665
665
  });
666
666
  i(this, "_triggerWebcastStoppedNotify", ({ body: { conference: e, type: t } }) => {
667
667
  const s = {
668
668
  conference: e,
669
669
  type: t
670
670
  };
671
- this._uaEvents.trigger(Te, s);
671
+ this._uaEvents.trigger(le, s);
672
672
  });
673
673
  i(this, "_triggerAccountChangedNotify", () => {
674
674
  this._uaEvents.trigger(ue, void 0);
@@ -721,18 +721,18 @@ class Zs {
721
721
  this._uaEvents.trigger(Ee, t);
722
722
  });
723
723
  i(this, "_triggerEnterRoom", (e) => {
724
- const t = e.getHeader(xt);
725
- this._sessionEvents.trigger(Q, t);
724
+ const t = e.getHeader(xt), s = e.getHeader(jt);
725
+ this._sessionEvents.trigger(Q, { room: t, participantName: s });
726
726
  });
727
727
  i(this, "_triggerShareState", (e) => {
728
728
  const t = e.getHeader(A);
729
- this._sessionEvents.trigger(p, t);
729
+ this._sessionEvents.trigger(D, t);
730
730
  });
731
731
  i(this, "_maybeTriggerParticipantMoveRequestToSpectators", (e) => {
732
- e.getHeader(os) === ot && this._sessionEvents.trigger(_e, void 0);
732
+ e.getHeader(as) === ot && this._sessionEvents.trigger(_e, void 0);
733
733
  });
734
734
  i(this, "_triggerMainCamControl", (e) => {
735
- const t = e.getHeader(jt), s = e.getHeader(pe), n = s === q.ADMIN_SYNC_FORCED;
735
+ const t = e.getHeader(Zt), s = e.getHeader(De), n = s === q.ADMIN_SYNC_FORCED;
736
736
  if (t === I.ADMIN_START_MAIN_CAM)
737
737
  this._sessionEvents.trigger(ie, { isSyncForced: n });
738
738
  else if (t === I.ADMIN_STOP_MAIN_CAM)
@@ -740,7 +740,7 @@ class Zs {
740
740
  else if ((t === I.RESUME_MAIN_CAM || t === I.PAUSE_MAIN_CAM) && s)
741
741
  this._sessionEvents.trigger(w, { isSyncForced: n });
742
742
  else {
743
- const o = e.getHeader(es);
743
+ const o = e.getHeader(ts);
744
744
  this._sessionEvents.trigger(se, {
745
745
  mainCam: t,
746
746
  resolutionMainCam: o
@@ -748,7 +748,7 @@ class Zs {
748
748
  }
749
749
  });
750
750
  i(this, "_triggerMicControl", (e) => {
751
- const t = e.getHeader(Zt), n = e.getHeader(pe) === q.ADMIN_SYNC_FORCED;
751
+ const t = e.getHeader(es), n = e.getHeader(De) === q.ADMIN_SYNC_FORCED;
752
752
  t === k.ADMIN_START_MIC ? this._sessionEvents.trigger(oe, { isSyncForced: n }) : t === k.ADMIN_STOP_MIC && this._sessionEvents.trigger(re, { isSyncForced: n });
753
753
  });
754
754
  i(this, "_triggerUseLicense", (e) => {
@@ -766,7 +766,7 @@ class Zs {
766
766
  this._triggerEnterRoom(s), this._maybeTriggerChannels(s);
767
767
  break;
768
768
  }
769
- case as: {
769
+ case cs: {
770
770
  this._maybeHandleNotify(s);
771
771
  break;
772
772
  }
@@ -786,7 +786,7 @@ class Zs {
786
786
  this._triggerUseLicense(s);
787
787
  break;
788
788
  }
789
- case rs: {
789
+ case os: {
790
790
  this._maybeTriggerParticipantMoveRequestToSpectators(s);
791
791
  break;
792
792
  }
@@ -796,7 +796,7 @@ class Zs {
796
796
  this._maybeHandleNotify(e);
797
797
  });
798
798
  i(this, "_maybeHandleNotify", (e) => {
799
- const t = e.getHeader(cs);
799
+ const t = e.getHeader(Es);
800
800
  if (t) {
801
801
  const s = JSON.parse(t);
802
802
  this._handleNotify(s);
@@ -825,7 +825,7 @@ class Zs {
825
825
  }), this._cancelableCall = new N(
826
826
  this._call,
827
827
  { moduleName: g }
828
- ), this._cancelableAnswer = new N(this._answer, { moduleName: g }), this._cancelableSendDTMF = new N(this._sendDTMF, { moduleName: g }), this.onSession(p, this._handleShareState), this.onSession(Ce, this._handleNewInfo), this.on(G, this._handleSipEvent), this.onSession(C, this._handleEnded), this.onSession(P, this._handleEnded);
828
+ ), this._cancelableAnswer = new N(this._answer, { moduleName: g }), this._cancelableSendDTMF = new N(this._sendDTMF, { moduleName: g }), this.onSession(D, this._handleShareState), this.onSession(Ce, this._handleNewInfo), this.on(G, this._handleSipEvent), this.onSession(C, this._handleEnded), this.onSession(P, this._handleEnded);
829
829
  }
830
830
  async register() {
831
831
  return new Promise((e, t) => {
@@ -877,11 +877,11 @@ class Zs {
877
877
  sdpSemantics: o,
878
878
  userAgent: e,
879
879
  getSipServerUrl: E
880
- }), T = () => {
881
- const l = new Error("Telephony is not available");
882
- c(l);
880
+ }), l = () => {
881
+ const T = new Error("Telephony is not available");
882
+ c(T);
883
883
  };
884
- h.once(u, T);
884
+ h.once(u, l);
885
885
  const d = () => {
886
886
  h.removeAllListeners(), h.once(u, a), h.stop();
887
887
  };
@@ -896,13 +896,13 @@ class Zs {
896
896
  async askPermissionToEnableCam(e = {}) {
897
897
  if (!this.session)
898
898
  throw new Error("No session established");
899
- const t = [us];
899
+ const t = [Ss];
900
900
  return this.session.sendInfo(Pe, void 0, {
901
901
  noTerminateWhenError: !0,
902
902
  ...e,
903
903
  extraHeaders: t
904
904
  }).catch((s) => {
905
- if (Rs(s))
905
+ if (Is(s))
906
906
  throw s;
907
907
  });
908
908
  }
@@ -917,7 +917,7 @@ class Zs {
917
917
  }) {
918
918
  const c = H(t);
919
919
  this._streamPresentationCurrent = c;
920
- const E = a ? [ds] : [Es], _ = e.sendInfo(M, void 0, {
920
+ const E = a ? [Ts] : [_s], _ = e.sendInfo(M, void 0, {
921
921
  extraHeaders: E
922
922
  }).then(async () => e.startPresentation(
923
923
  c,
@@ -927,8 +927,8 @@ class Zs {
927
927
  const { connection: h } = this;
928
928
  if (!h || s === void 0)
929
929
  return;
930
- const T = h.getSenders();
931
- await Ds(T, t, s);
930
+ const l = h.getSenders();
931
+ await Ds(l, t, s);
932
932
  }).then(() => t).catch((h) => {
933
933
  throw this._sessionEvents.trigger(U, h), h;
934
934
  });
@@ -956,7 +956,7 @@ class Zs {
956
956
  }
957
957
  async sendMustStopPresentation(e) {
958
958
  await e.sendInfo(M, void 0, {
959
- extraHeaders: [hs]
959
+ extraHeaders: [ds]
960
960
  });
961
961
  }
962
962
  async stopPresentation({
@@ -964,7 +964,7 @@ class Zs {
964
964
  } = {}) {
965
965
  const t = this._streamPresentationCurrent;
966
966
  let s = this.promisePendingStartPresentation ?? Promise.resolve();
967
- const n = e ? [ls] : [_s], o = this.establishedSession;
967
+ const n = e ? [ls] : [hs], o = this.establishedSession;
968
968
  return o && t && (s = s.then(async () => o.sendInfo(M, void 0, {
969
969
  extraHeaders: n
970
970
  })).then(async () => o.stopPresentation(t)).catch((a) => {
@@ -1033,7 +1033,7 @@ class Zs {
1033
1033
  if (!this.connection)
1034
1034
  return;
1035
1035
  const t = this.connection.getReceivers().map(({ track: s }) => s);
1036
- return Cs(t) ? this._generateStreams(t) : this._generateAudioStreams(t);
1036
+ return As(t) ? this._generateStreams(t) : this._generateAudioStreams(t);
1037
1037
  }
1038
1038
  get connection() {
1039
1039
  var t;
@@ -1111,7 +1111,7 @@ class Zs {
1111
1111
  async sendChannels({ inputChannels: e, outputChannels: t }) {
1112
1112
  if (!this.session)
1113
1113
  throw new Error("No session established");
1114
- const s = `${Me}: ${e}`, n = `${De}: ${t}`, o = [
1114
+ const s = `${Me}: ${e}`, n = `${pe}: ${t}`, o = [
1115
1115
  s,
1116
1116
  n
1117
1117
  ];
@@ -1120,7 +1120,7 @@ class Zs {
1120
1120
  async sendMediaState({ cam: e, mic: t }, s = {}) {
1121
1121
  if (!this.session)
1122
1122
  throw new Error("No session established");
1123
- const n = `${ts}: currentstate`, o = `${ns}: ${Number(e)}`, a = `${is}: ${Number(t)}`, c = [
1123
+ const n = `${ss}: currentstate`, o = `${is}: ${Number(e)}`, a = `${rs}: ${Number(t)}`, c = [
1124
1124
  n,
1125
1125
  o,
1126
1126
  a
@@ -1134,7 +1134,7 @@ class Zs {
1134
1134
  async _sendRefusalToTurnOn(e, t = {}) {
1135
1135
  if (!this.session)
1136
1136
  throw new Error("No session established");
1137
- const c = [`${ss}: ${e === "mic" ? 0 : 1}`];
1137
+ const c = [`${ns}: ${e === "mic" ? 0 : 1}`];
1138
1138
  return this.session.sendInfo(Jt, void 0, {
1139
1139
  noTerminateWhenError: !0,
1140
1140
  ...t,
@@ -1155,20 +1155,20 @@ class Zs {
1155
1155
  export {
1156
1156
  Ft as B,
1157
1157
  I as E,
1158
- pt as N,
1158
+ Dt as N,
1159
1159
  Le as R,
1160
- Zs as S,
1160
+ en as S,
1161
1161
  Et as U,
1162
- Js as a,
1163
- Qs as b,
1164
- Xs as c,
1165
- Ks as d,
1166
- zs as e,
1162
+ zs as a,
1163
+ Ks as b,
1164
+ Js as c,
1165
+ js as d,
1166
+ Qs as e,
1167
1167
  k as f,
1168
1168
  q as g,
1169
- js as h,
1170
- Ss as i,
1169
+ Zs as h,
1170
+ Ns as i,
1171
1171
  _t as j,
1172
1172
  ve as l,
1173
- Ms as s
1173
+ ps as s
1174
1174
  };
@@ -0,0 +1 @@
1
+ "use strict";var ft=Object.defineProperty;var Ot=(r,e,t)=>e in r?ft(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(Ot(r,typeof e!="symbol"?e+"":e,t),t);const N=require("@krivega/cancelable-promise"),pe=require("events-constructor"),B=require("debug"),Mt="Connection Error",qe="Request Timeout",Pt="SIP Failure Code",Dt="Internal Error",pt="Busy",V="Rejected",vt="Redirected",bt="Unavailable",ke="Not Found",wt="Address Incomplete",yt="Incompatible SDP",Ut="Missing SDP",Lt="Authentication Error",We="Terminated",Ht="WebRTC Error",Fe="Canceled",qt="No Answer",kt="Expires",Wt="No ACK",Ft="Dialog Error",Bt="User Denied Media Access",Be="Bad Media Description",Vt="RTP Timeout",Yt=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:wt,AUTHENTICATION_ERROR:Lt,BAD_MEDIA_DESCRIPTION:Be,BUSY:pt,BYE:We,CANCELED:Fe,CONNECTION_ERROR:Mt,DIALOG_ERROR:Ft,EXPIRES:kt,INCOMPATIBLE_SDP:yt,INTERNAL_ERROR:Dt,MISSING_SDP:Ut,NOT_FOUND:ke,NO_ACK:Wt,NO_ANSWER:qt,REDIRECTED:vt,REJECTED:V,REQUEST_TIMEOUT:qe,RTP_TIMEOUT:Vt,SIP_FAILURE_CODE:Pt,UNAVAILABLE:bt,USER_DENIED_MEDIA_ACCESS:Bt,WEBRTC_ERROR:Ht},Symbol.toStringTag,{value:"Module"})),Y="incomingCall",x="declinedIncomingCall",$="failedIncomingCall",G="terminatedIncomingCall",q="connecting",m="connected",u="disconnected",D="newRTCSession",f="registered",X="unregistered",O="registrationFailed",Ve="newMessage",J="sipEvent",z="availableSecondRemoteStream",Q="notAvailableSecondRemoteStream",K="mustStopPresentation",p="shareState",j="enterRoom",Z="useLicense",ee="peerconnection:confirmed",te="peerconnection:ontrack",v="channels",ne="channels:notify",se="ended:fromserver",ie="main-cam-control",re="admin-stop-main-cam",oe="admin-start-main-cam",ae="admin-stop-mic",ce="admin-start-mic",b="admin-force-sync-media-state",Ee="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",he="participant:move-request-to-stream",de="participant:move-request-to-spectators",le="participation:accepting-word-request",Te="participation:cancelling-word-request",ue="webcast:started",Se="webcast:stopped",Ne="account:changed",Ce="account:deleted",ge="conference:participant-token-issued",M="ended",Ye="sending",xe="reinvite",$e="replaces",Ge="refer",Xe="progress",Je="accepted",w="confirmed",y="peerconnection",g="failed",ze="muted",Qe="unmuted",Ae="newDTMF",Re="newInfo",Ke="hold",je="unhold",Ze="update",et="sdp",tt="icecandidate",nt="getusermediafailed",st="peerconnection:createofferfailed",it="peerconnection:createanswerfailed",rt="peerconnection:setlocaldescriptionfailed",ot="peerconnection:setremotedescriptionfailed",at="presentation:start",ct="presentation:started",Et="presentation:end",Ie="presentation:ended",U="presentation:failed",_t="SPECTATOR",xt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Je,ACCOUNT_CHANGED:Ne,ACCOUNT_DELETED:Ce,ADMIN_FORCE_SYNC_MEDIA_STATE:b,ADMIN_START_MAIN_CAM:oe,ADMIN_START_MIC:ce,ADMIN_STOP_MAIN_CAM:re,ADMIN_STOP_MIC:ae,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:z,CHANNELS:v,CHANNELS_NOTIFY:ne,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:ge,CONFIRMED:w,CONNECTED:m,CONNECTING:q,DECLINED_INCOMING_CALL:x,DISCONNECTED:u,ENDED:M,ENDED_FROM_SERVER:se,ENTER_ROOM:j,FAILED:g,FAILED_INCOMING_CALL:$,GET_USER_MEDIA_FAILED:nt,HOLD:Ke,ICE_CANDIDATE:tt,INCOMING_CALL:Y,MAIN_CAM_CONTROL:ie,MUST_STOP_PRESENTATION_EVENT:K,MUTED:ze,NEW_DTMF:Ae,NEW_INFO:Re,NEW_MESSAGE:Ve,NEW_RTC_SESSION:D,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Q,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Ee,PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS:de,PARTICIPANT_MOVE_REQUEST_TO_STREAM:he,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:_e,PARTICIPATION_ACCEPTING_WORD_REQUEST:le,PARTICIPATION_CANCELLING_WORD_REQUEST:Te,PEER_CONNECTION:y,PEER_CONNECTION_CONFIRMED:ee,PEER_CONNECTION_CREATE_ANSWER_FAILED:it,PEER_CONNECTION_CREATE_OFFER_FAILED:st,PEER_CONNECTION_ONTRACK:te,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:rt,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:ot,PRESENTATION_END:Et,PRESENTATION_ENDED:Ie,PRESENTATION_FAILED:U,PRESENTATION_START:at,PRESENTATION_STARTED:ct,PROGRESS:Xe,REFER:Ge,REGISTERED:f,REGISTRATION_FAILED:O,REINVITE:xe,REPLACES:$e,SDP:et,SENDING:Ye,SHARE_STATE:p,SIP_EVENT:J,SPECTATOR:_t,TERMINATED_INCOMING_CALL:G,UNHOLD:je,UNMUTED:Qe,UNREGISTERED:X,UPDATE:Ze,USE_LICENSE:Z,WEBCAST_STARTED:ue,WEBCAST_STOPPED:Se},Symbol.toStringTag,{value:"Module"})),ht=[Y,x,G,$,le,Te,he,ne,ge,Ne,Ce,ue,Se,Ee,_e],me=[q,m,u,D,f,X,O,Ve,J],dt=[z,Q,K,p,j,Z,ee,te,v,se,ie,oe,re,ae,ce,b,de],fe=[M,q,Ye,xe,$e,Ge,Xe,Je,w,y,g,ze,Qe,Ae,Re,Ke,je,Ze,et,tt,nt,st,it,rt,ot,at,ct,Et,Ie,U],Oe=[...me,...ht],Me=[...fe,...dt],$t=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Me,SESSION_JSSIP_EVENT_NAMES:fe,SESSION_SYNTHETICS_EVENT_NAMES:dt,UA_EVENT_NAMES:Oe,UA_JSSIP_EVENT_NAMES:me,UA_SYNTHETICS_EVENT_NAMES:ht},Symbol.toStringTag,{value:"Module"})),Gt=r=>{const e=[];return r&&e.push(`X-Vinteo-Remote: ${r}`),e},Xt="content-type",Jt="x-webrtc-enter-room",P="application/vinteo.webrtc.sharedesktop",zt="application/vinteo.webrtc.roomname",Qt="application/vinteo.webrtc.channels",Kt="application/vinteo.webrtc.mediastate",jt="application/vinteo.webrtc.refusal",ve="application/vinteo.webrtc.maincam",Zt="application/vinteo.webrtc.mic",en="application/vinteo.webrtc.uselic",tn="X-WEBRTC-USE-LICENSE",nn="X-WEBRTC-PARTICIPANT-NAME",be="X-WEBRTC-INPUT-CHANNELS",we="X-WEBRTC-OUTPUT-CHANNELS",sn="X-WEBRTC-MAINCAM",rn="X-WEBRTC-MIC",ye="X-WEBRTC-SYNC",on="X-WEBRTC-MAINCAM-RESOLUTION",an="X-WEBRTC-MEDIA-STATE",cn="X-Vinteo-Media-Type",En="X-Vinteo-MainCam-State",_n="X-Vinteo-Mic-State",hn="application/vinteo.webrtc.partstate",dn="X-WEBRTC-PARTSTATE",ln="application/vinteo.webrtc.notify",Tn="X-VINTEO-NOTIFY",R="x-webrtc-share-state",un=`${R}: LETMESTARTPRESENTATION`,Sn=`${R}: STOPPRESENTATION`,lt="YOUCANRECEIVECONTENT",Tt="CONTENTEND",ut="YOUMUSTSTOPSENDCONTENT",Nn=`${R}: ${ut}`,Cn=`${R}: ${lt}`,gn=`${R}: ${Tt}`,An="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Rn=`${An}: LETMESTARTMAINCAM`,Pe="sip-connector",W=B(Pe),In=()=>{B.enable(Pe)},mn=()=>{B.enable(`-${Pe}`)};var A=(r=>(r.PAUSE_MAIN_CAM="PAUSEMAINCAM",r.RESUME_MAIN_CAM="RESUMEMAINCAM",r.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",r.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",r.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",r))(A||{}),L=(r=>(r.ADMIN_STOP_MIC="ADMINSTOPMIC",r.ADMIN_START_MIC="ADMINSTARTMIC",r))(L||{}),H=(r=>(r.ADMIN_SYNC_FORCED="1",r.ADMIN_SYNC_NOT_FORCED="0",r))(H||{}),St=(r=>(r.AUDIO="AUDIO",r.VIDEO="VIDEO",r.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",r))(St||{});function Ue(r){return e=>`sip:${e}@${r}`}const fn=(r,e)=>()=>Math.floor(Math.random()*(e-r))+r,Le=r=>r.trim().replaceAll(" ","_"),On=fn(1e5,99999999),k=(r,{videoMode:e,audioMode:t}={})=>{if(!r||e==="recvonly"&&t==="recvonly")return;const n=t==="recvonly"?[]:r.getAudioTracks(),s=e==="recvonly"?[]:r.getVideoTracks(),o=[...n,...s],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],a},Mn=r=>r.some(t=>{const{kind:n}=t;return n==="video"}),Pn="Error decline with 603",Dn=r=>r.message===Pn,pn=(r,e)=>r.find(t=>t.track&&e.getTracks().includes(t.track)),Nt=1,Ct=r=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==r,vn=Ct(Nt),bn=(r,e)=>{const t=r===void 0?void 0:Math.max(r,Nt);if(t!==void 0&&vn(t,e))return t},wn=Ct(),yn=(r,e)=>{if(wn(r,e))return r},gt=async(r,e,t)=>{const n=r.getParameters();(n.encodings===void 0||n.encodings.length===0)&&(n.encodings=[{}]);const[s]=n.encodings,o=s.scaleResolutionDownBy,a=bn(e.scaleResolutionDownBy,o);let c=!1;a!==void 0&&(n.encodings[0].scaleResolutionDownBy=a,c=!0);const E=s.maxBitrate,_=yn(e.maxBitrate,E);return _!==void 0&&(n.encodings[0].maxBitrate=_,c=!0),c?(t&&t(n),r.setParameters(n).then(()=>({parameters:n,isChanged:c}))):{parameters:n,isChanged:c}},Un=async(r,e,t)=>{const n=pn(r,e);if(n)return gt(n,{maxBitrate:t})},Ln=486,Hn=487,F="local",He="remote",qn=(r=new Error)=>{const{originator:e,cause:t}=r;return N.isCanceledError(r)?!0:typeof t=="string"?t===qe||t===V||e===F&&(t===Fe||t===We):!1},C="SipConnector",kn="channels",Wn="WebcastStarted",Fn="WebcastStopped",Bn="accountChanged",Vn="accountDeleted",Yn="addedToListModerators",xn="removedFromListModerators",$n="ParticipationRequestAccepted",Gn="ParticipationRequestRejected",Xn="ParticipantMovedToWebcast",Jn="ConferenceParticipantTokenIssued";class zn{constructor({JsSIP:e}){i(this,"_isRegisterConfig",!1);i(this,"_connectionConfiguration",{});i(this,"_remoteStreams",{});i(this,"JsSIP");i(this,"_sessionEvents");i(this,"_uaEvents");i(this,"_cancelableConnect");i(this,"_cancelableInitUa");i(this,"_cancelableDisconnect");i(this,"_cancelableSet");i(this,"_cancelableCall");i(this,"_cancelableAnswer");i(this,"_cancelableSendDTMF");i(this,"getSipServerUrl",e=>e);i(this,"promisePendingStartPresentation");i(this,"promisePendingStopPresentation");i(this,"ua");i(this,"session");i(this,"incomingSession");i(this,"_streamPresentationCurrent");i(this,"socket");i(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));i(this,"initUa",async e=>this._cancelableInitUa.request(e));i(this,"set",async e=>this._cancelableSet.request(e));i(this,"call",async e=>this._cancelableCall.request(e));i(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));i(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));i(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));i(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));i(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(q,void 0);try{await this.unregister()}catch(e){W("tryRegister",e)}return this.register()});i(this,"declineToIncomingCall",async({statusCode:e=Hn}={})=>new Promise((t,n)=>{if(!this.isAvailableIncomingCall){n(new Error("no incomingSession"));return}const s=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(x,o),t(s.terminate({status_code:e}))}));i(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:Ln}));i(this,"removeIncomingSession",()=>{delete this.incomingSession});i(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===He){this.incomingSession=t;const n=this.remoteCallerData;t.on(g,s=>{this.removeIncomingSession(),s.originator===F?this._uaEvents.trigger(G,n):this._uaEvents.trigger($,n)}),this._uaEvents.trigger(Y,n)}});i(this,"_connect",async e=>this.initUa(e).then(async()=>this._start()));i(this,"_initUa",async({user:e,password:t,sipServerUrl:n,sipWebSocketServerURL:s,remoteAddress:o,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,displayName:d="",register:l=!1,extraHeaders:S=[]})=>{if(!n)throw new Error("sipServerUrl is required");if(!s)throw new Error("sipWebSocketServerURL is required");if(l&&!e)throw new Error("user is required for authorized connection");if(l&&!t)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:n,displayName:d,register:l,user:e,password:t},this.getSipServerUrl=Ue(n),this.socket=new this.JsSIP.WebSocketInterface(s),this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!l;const{socket:I}=this;this.ua=this._createUa({user:e,password:t,socket:I,displayName:d,register:l,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,getSipServerUrl:this.getSipServerUrl}),this._uaEvents.eachTriggers((Rt,It)=>{const De=me.find(mt=>mt===It);De&&this.ua&&this.ua.on(De,Rt)});const At=[...Gt(o),...S];return this.ua.registrator().setExtraHeaders(At),this.ua});i(this,"_createUa",({user:e,password:t,socket:n,displayName:s,getSipServerUrl:o,register:a=!1,sdpSemantics:c="plan-b",sessionTimers:E=!1,registerExpires:_=60*5,connectionRecoveryMinInterval:h=2,connectionRecoveryMaxInterval:T=6,userAgent:d})=>{if(a&&!t)throw new Error("password is required for authorized connection");const l=a&&e?e.trim():`${On()}`,S=o(l),I={password:t,register:a,uri:S,display_name:Le(s),user_agent:d,sdp_semantics:c,sockets:[n],session_timers:E,register_expires:_,connection_recovery_min_interval:h,connection_recovery_max_interval:T};return new this.JsSIP.UA(I)});i(this,"_start",async()=>new Promise((e,t)=>{const{ua:n}=this;if(!n){t(new Error("this.ua is not initialized"));return}const s=()=>{c(),e(n)},o=E=>{c(),t(E)},a=()=>{this.isRegisterConfig?(this.on(f,s),this.on(O,o)):this.on(m,s),this.on(u,o)},c=()=>{this.off(f,s),this.off(O,o),this.off(m,s),this.off(u,o)};a(),this.on(D,this.handleNewRTCSession),n.start()}));i(this,"_set",async({displayName:e,password:t})=>new Promise((n,s)=>{const{ua:o}=this;if(!o){s(new Error("this.ua is not initialized"));return}let a=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(a=o.set("display_name",Le(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const E=a||c;c&&this.isRegisterConfig?this.register().then(()=>{n(E)}).catch(_=>{s(_)}):E?n(E):s(new Error("nothing changed"))}));i(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());i(this,"_disconnect",async()=>{this.off(D,this.handleNewRTCSession);const e=new Promise(t=>{this.once(u,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(u,void 0)):this._uaEvents.trigger(u,void 0),e});i(this,"_call",async({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:o,videoMode:a,audioMode:c,degradationPreference:E,offerToReceiveAudio:_=!0,offerToReceiveVideo:h=!0})=>new Promise((T,d)=>{const{ua:l}=this;if(!l){d(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(T).catch(S=>{d(S)}),this.session=l.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:k(t,{videoMode:a,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:a,audioMode:c,degradationPreference:E,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:_,offerToReceiveVideo:h}})}));i(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:o,audioMode:a,degradationPreference:c})=>new Promise((E,_)=>{if(!this.isAvailableIncomingCall){_(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:h}=this;if(!h){_(new Error("No session established"));return}this._sessionEvents.eachTriggers((d,l)=>{const S=fe.find(I=>I===l);S&&h.on(S,d)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=h.remote_identity.uri.user,this._handleCall({ontrack:t}).then(E).catch(d=>{_(d)});const T=k(e,{videoMode:o,audioMode:a});h.answer({extraHeaders:n,videoMode:o,audioMode:a,degradationPreference:c,mediaStream:T,pcConfig:{iceServers:s}})}));i(this,"_handleCall",async({ontrack:e})=>new Promise((t,n)=>{const s=()=>{this.onSession(y,h),this.onSession(w,T)},o=()=>{this.offSession(y,h),this.offSession(w,T)},a=()=>{this.onSession(g,E),this.onSession(M,E)},c=()=>{this.offSession(g,E),this.offSession(M,E)},E=d=>{o(),c(),n(d)};let _;const h=({peerconnection:d})=>{_=d,_.ontrack=l=>{this._sessionEvents.trigger(te,_),e&&e(l)}},T=()=>{_&&this._sessionEvents.trigger(ee,_),o(),c(),t(_)};s(),a()}));i(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});i(this,"_sendDTMF",async e=>new Promise((t,n)=>{const{session:s}=this;if(!s){n(new Error("No session established"));return}this.onceSession(Ae,({originator:o})=>{o===F&&t()}),s.sendDTMF(e,{duration:120,interToneGap:600})}));i(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),e.isEnded()||e.terminate()}});i(this,"_handleShareState",e=>{switch(e){case lt:{this._sessionEvents.trigger(z,void 0);break}case Tt:{this._sessionEvents.trigger(Q,void 0);break}case ut:{this._sessionEvents.trigger(K,void 0);break}}});i(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(be),n=e.getHeader(we);if(t&&n){const s={inputChannels:t,outputChannels:n};this._sessionEvents.trigger(v,s)}});i(this,"_handleNotify",e=>{switch(e.cmd){case kn:{const t=e;this._triggerChannelsNotify(t);break}case Wn:{const t=e;this._triggerWebcastStartedNotify(t);break}case Fn:{const t=e;this._triggerWebcastStoppedNotify(t);break}case Yn:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case xn:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case $n:{const t=e;this._triggerParticipationAcceptingWordRequest(t);break}case Gn:{const t=e;this._triggerParticipationCancellingWordRequest(t);break}case Xn:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case Bn:{this._triggerAccountChangedNotify();break}case Vn:{this._triggerAccountDeletedNotify();break}case Jn:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:W("unknown cmd",e.cmd)}});i(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(_e,t)});i(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Ee,t)});i(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(ue,n)});i(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(Se,n)});i(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(Ne,void 0)});i(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(Ce,void 0)});i(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger(ge,s)});i(this,"_triggerChannelsNotify",e=>{const t=e.input,n=e.output,s={inputChannels:t,outputChannels:n};this._uaEvents.trigger(ne,s)});i(this,"_triggerParticipationAcceptingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(le,t)});i(this,"_triggerParticipationCancellingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(Te,t)});i(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(he,t)});i(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Jt),n=e.getHeader(nn);this._sessionEvents.trigger(j,{room:t,participantName:n})});i(this,"_triggerShareState",e=>{const t=e.getHeader(R);this._sessionEvents.trigger(p,t)});i(this,"_maybeTriggerParticipantMoveRequestToSpectators",e=>{e.getHeader(dn)===_t&&this._sessionEvents.trigger(de,void 0)});i(this,"_triggerMainCamControl",e=>{const t=e.getHeader(sn),n=e.getHeader(ye),s=n===H.ADMIN_SYNC_FORCED;if(t===A.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(oe,{isSyncForced:s});else if(t===A.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(re,{isSyncForced:s});else if((t===A.RESUME_MAIN_CAM||t===A.PAUSE_MAIN_CAM)&&n)this._sessionEvents.trigger(b,{isSyncForced:s});else{const o=e.getHeader(on);this._sessionEvents.trigger(ie,{mainCam:t,resolutionMainCam:o})}});i(this,"_triggerMicControl",e=>{const t=e.getHeader(rn),s=e.getHeader(ye)===H.ADMIN_SYNC_FORCED;t===L.ADMIN_START_MIC?this._sessionEvents.trigger(ce,{isSyncForced:s}):t===L.ADMIN_STOP_MIC&&this._sessionEvents.trigger(ae,{isSyncForced:s})});i(this,"_triggerUseLicense",e=>{const t=e.getHeader(tn);this._sessionEvents.trigger(Z,t)});i(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:n}=e,s=n.getHeader(Xt);if(s)switch(s){case zt:{this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break}case ln:{this._maybeHandleNotify(n);break}case P:{this._triggerShareState(n);break}case ve:{this._triggerMainCamControl(n);break}case Zt:{this._triggerMicControl(n);break}case en:{this._triggerUseLicense(n);break}case hn:{this._maybeTriggerParticipantMoveRequestToSpectators(n);break}}});i(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});i(this,"_maybeHandleNotify",e=>{const t=e.getHeader(Tn);if(t){const n=JSON.parse(t);this._handleNotify(n)}});i(this,"_handleEnded",e=>{const{originator:t}=e;t===He&&this._sessionEvents.trigger(se,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new pe(Me),this._uaEvents=new pe(Oe),this._cancelableConnect=new N.CancelableRequest(this._connect,{moduleName:C,afterCancelRequest:()=>{this._cancelableInitUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableInitUa=new N.CancelableRequest(this._initUa,{moduleName:C}),this._cancelableDisconnect=new N.CancelableRequest(this._disconnect,{moduleName:C}),this._cancelableSet=new N.CancelableRequest(this._set,{moduleName:C}),this._cancelableCall=new N.CancelableRequest(this._call,{moduleName:C}),this._cancelableAnswer=new N.CancelableRequest(this._answer,{moduleName:C}),this._cancelableSendDTMF=new N.CancelableRequest(this._sendDTMF,{moduleName:C}),this.onSession(p,this._handleShareState),this.onSession(Re,this._handleNewInfo),this.on(J,this._handleSipEvent),this.onSession(g,this._handleEnded),this.onSession(M,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(f,e),this.ua.on(O,t),this.ua.register()):t(new Error("Config is not registered"))})}async unregister(){return new Promise((e,t)=>{this.isRegistered&&this.ua?(this.ua.on(X,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,n){if(!this.ua)throw new Error("is not connected");return new Promise((s,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:o}})}catch(a){o(a)}})}async ping(e,t){var s;if(!((s=this.ua)!=null&&s.configuration.uri))throw new Error("is not connected");const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}async checkTelephony({userAgent:e,displayName:t,sipServerUrl:n,sipWebSocketServerURL:s,sdpSemantics:o}){return new Promise((a,c)=>{const E=Ue(n),_=new this.JsSIP.WebSocketInterface(s),h=this._createUa({socket:_,displayName:t,sdpSemantics:o,userAgent:e,getSipServerUrl:E}),T=()=>{const l=new Error("Telephony is not available");c(l)};h.once(u,T);const d=()=>{h.removeAllListeners(),h.once(u,a),h.stop()};h.once(m,d),h.start()})}async replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}async askPermissionToEnableCam(e={}){if(!this.session)throw new Error("No session established");const t=[Rn];return this.session.sendInfo(ve,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(n=>{if(Dn(n))throw n})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:o=!0,isP2P:a=!1}){const c=k(t);this._streamPresentationCurrent=c;const E=a?[Cn]:[un],_=e.sendInfo(P,void 0,{extraHeaders:E}).then(async()=>e.startPresentation(c,o,s)).then(async()=>{const{connection:h}=this;if(!h||n===void 0)return;const T=h.getSenders();await Un(T,t,n)}).then(()=>t).catch(h=>{throw this._sessionEvents.trigger(U,h),h});return this.promisePendingStartPresentation=_,_.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:o}={}){const a=this.establishedSession;if(!a)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return n&&await this.sendMustStopPresentation(a),this._sendPresentation(a,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:o})}async sendMustStopPresentation(e){await e.sendInfo(P,void 0,{extraHeaders:[Nn]})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation??Promise.resolve();const s=e?[gn]:[Sn],o=this.establishedSession;return o&&t&&(n=n.then(async()=>o.sendInfo(P,void 0,{extraHeaders:s})).then(async()=>o.stopPresentation(t)).catch(a=>{throw this._sessionEvents.trigger(U,a),a})),!o&&t&&this._sessionEvents.trigger(Ie,t),this.promisePendingStopPresentation=n,n.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:n,degradationPreference:s}={}){const o=this.establishedSession;if(!o)throw new Error("No session established");if(!this._streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this._sendPresentation(o,e,{isP2P:t,maxBitrate:n,degradationPreference:s,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}async wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}async waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:n})=>n);return Mn(t)?this._generateStreams(t):this._generateAudioStreams(t)}get connection(){var t;return(t=this.session)==null?void 0:t.connection}get remoteCallerData(){var e,t,n,s,o,a;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(s=(n=this.incomingSession)==null?void 0:n.remote_identity)==null?void 0:s.uri.host,incomingNumber:(a=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:a.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableInitUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){var e;return(e=this.session)!=null&&e.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!!(this.ua&&this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_generateStream(e,t){const{id:n}=e,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const{id:t}=e,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach((n,s)=>{if(n.kind==="audio")return;const o=n,a=e[s-1];let c;a&&a.kind==="audio"&&(c=a);const E=this._generateStream(o,c);t.push(E)}),t}_generateAudioStreams(e){return e.map(n=>this._generateAudioStream(n))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}async waitChannels(){return this.waitSession(v)}async waitSyncMediaState(){return this.waitSession(b)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=`${be}: ${e}`,s=`${we}: ${t}`,o=[n,s];return this.session.sendInfo(Qt,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},n={}){if(!this.session)throw new Error("No session established");const s=`${an}: currentstate`,o=`${En}: ${Number(e)}`,a=`${_n}: ${Number(t)}`,c=[s,o,a];return this.session.sendInfo(Kt,void 0,{noTerminateWhenError:!0,...n,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${cn}: ${e==="mic"?0:1}`];return this.session.sendInfo(jt,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}}exports.BAD_MEDIA_DESCRIPTION=Be;exports.EEventsMainCAM=A;exports.EEventsMic=L;exports.EEventsSyncMediaState=H;exports.EUseLicense=St;exports.NOT_FOUND=ke;exports.REJECTED=V;exports.SESSION_EVENT_NAMES=Me;exports.SipConnector=zn;exports.UA_EVENT_NAMES=Oe;exports.causes=Yt;exports.constants=xt;exports.disableDebug=mn;exports.enableDebug=In;exports.eventNames=$t;exports.hasCanceledCallError=qn;exports.logger=W;exports.setEncodingsToSender=gt;
@@ -0,0 +1,5 @@
1
+ export declare const enterRoomData: {
2
+ room: string;
3
+ participantName: string;
4
+ };
5
+ export declare const enterRoomHeaders: [string, string][];
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var L=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(L(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-BrUmibLH.cjs"),P=require("@krivega/jssip/lib/NameAddrHeader"),x=require("@krivega/jssip/lib/URI"),F=require("node:events"),U=require("@krivega/jssip/lib/SIPMessage"),R=require("events-constructor"),C=require("@krivega/jssip");class y extends U.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",H="isolationchange",j="overconstrained",B="unmute",$=[m,q,B,H,j];class A{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 R($)}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 K=r=>new A("audio",r),Y=r=>new A("video",r);class J{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 R(g.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 G{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 X(r){const e=r.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const E=400,I="777",Q=r=>r.getVideoTracks().length>0;class b extends J{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)},E)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=K();i.id="mainaudio1";const o=[i];if(Q(t)){const c=Y();c.id="mainvideo1",o.push(c)}this._connection=new G(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},E)}connect(t){const i=X(t);setTimeout(()=>{this.url.includes(I)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",i)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},E)}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 Z{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",O="NAME_INCORRECT",u=400,l=class l{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 R(g.UA_EVENT_NAMES);const[t,i]=e.uri.split(":"),[o,a]=i.split("@"),c={...e,uri:new C.URI(t,o,a)};this.configuration=c,this._registrator=new Z}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")})},u):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.user.includes(O)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},u)):!this._isRegistered&&t&&(e===d||e===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},u)):t&&e!==d&&e!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},u)),l.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(l,"isAvailableTelephony",!0);let v=l;class ee{constructor(e){n(this,"url");this.url=e}}class te extends F.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const M="remote",ne=(r,e)=>{const t=new y(e),i={originator:M,request:t,info:new te("","")};r.newInfo(i)},ie=(r,e)=>{const i={request:new y(e)};r.newSipEvent(i)},re=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:M}),a=new x("sip",e,i);o._remote_identity=new P(a,t),r.trigger("newRTCSession",{originator:M,session:o})},oe=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},N={triggerNewInfo:ne,triggerNewSipEvent:ie,triggerIncomingSession:re,triggerFailIncomingSession:oe,WebSocketInterface:ee,UA:v,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",S="SIP_WEB_SOCKET_SERVER_URL",se=new N.WebSocketInterface(S),T={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:S},ae={...T},W={...T,user:_,password:d,register:!0},de={...W,displayName:h},he={...T,displayName:h,register:!1},w={session_timers:!1,sockets:[se],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},ce={...w,password:d,uri:new C.URI("sip",_,p),display_name:"",register:!0},ue={...w,password:d,uri:new C.URI("sip",_,p),display_name:h,register:!0},me={...w,display_name:h,register:!1},le={...w,display_name:"",register:!1},D="10.10.10.10",ge=[`X-Vinteo-Remote: ${D}`],_e=()=>new g.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=I;exports.NAME_INCORRECT=O;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=p;exports.SIP_WEB_SOCKET_SERVER_URL=S;exports.dataForConnectionWithAuthorization=W;exports.dataForConnectionWithAuthorizationWithDisplayName=de;exports.dataForConnectionWithoutAuthorization=he;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=ae;exports.default=_e;exports.displayName=h;exports.extraHeadersRemoteAddress=ge;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=ce;exports.uaConfigurationWithAuthorizationWithDisplayName=ue;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=le;exports.user=_;
1
+ "use strict";var k=Object.defineProperty;var L=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(L(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-BSuVfStn.cjs"),P=require("@krivega/jssip/lib/NameAddrHeader"),x=require("@krivega/jssip/lib/URI"),F=require("node:events"),U=require("@krivega/jssip/lib/SIPMessage"),R=require("events-constructor"),C=require("@krivega/jssip");class y extends U.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",H="isolationchange",j="overconstrained",B="unmute",$=[m,q,B,H,j];class A{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 R($)}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 K=r=>new A("audio",r),Y=r=>new A("video",r);class J{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 R(g.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 G{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 X(r){const e=r.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const E=400,I="777",Q=r=>r.getVideoTracks().length>0;class b extends J{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)},E)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=K();i.id="mainaudio1";const o=[i];if(Q(t)){const c=Y();c.id="mainvideo1",o.push(c)}this._connection=new G(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},E)}connect(t){const i=X(t);setTimeout(()=>{this.url.includes(I)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:i})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},E)}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 Z{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",O="NAME_INCORRECT",u=400,l=class l{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 R(g.UA_EVENT_NAMES);const[t,i]=e.uri.split(":"),[o,a]=i.split("@"),c={...e,uri:new C.URI(t,o,a)};this.configuration=c,this._registrator=new Z}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")})},u):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.user.includes(O)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},u)):!this._isRegistered&&t&&(e===d||e===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},u)):t&&e!==d&&e!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},u)),l.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(l,"isAvailableTelephony",!0);let v=l;class ee{constructor(e){n(this,"url");this.url=e}}class te extends F.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const M="remote",ne=(r,e)=>{const t=new y(e),i={originator:M,request:t,info:new te("","")};r.newInfo(i)},ie=(r,e)=>{const i={request:new y(e)};r.newSipEvent(i)},re=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:M}),a=new x("sip",e,i);o._remote_identity=new P(a,t),r.trigger("newRTCSession",{originator:M,session:o})},oe=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},N={triggerNewInfo:ne,triggerNewSipEvent:ie,triggerIncomingSession:re,triggerFailIncomingSession:oe,WebSocketInterface:ee,UA:v,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",S="SIP_WEB_SOCKET_SERVER_URL",se=new N.WebSocketInterface(S),T={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:S},ae={...T},W={...T,user:_,password:d,register:!0},de={...W,displayName:h},he={...T,displayName:h,register:!1},w={session_timers:!1,sockets:[se],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},ce={...w,password:d,uri:new C.URI("sip",_,p),display_name:"",register:!0},ue={...w,password:d,uri:new C.URI("sip",_,p),display_name:h,register:!0},me={...w,display_name:h,register:!1},le={...w,display_name:"",register:!1},D="10.10.10.10",ge=[`X-Vinteo-Remote: ${D}`],_e=()=>new g.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=I;exports.NAME_INCORRECT=O;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=p;exports.SIP_WEB_SOCKET_SERVER_URL=S;exports.dataForConnectionWithAuthorization=W;exports.dataForConnectionWithAuthorizationWithDisplayName=de;exports.dataForConnectionWithoutAuthorization=he;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=ae;exports.default=_e;exports.displayName=h;exports.extraHeadersRemoteAddress=ge;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=ce;exports.uaConfigurationWithAuthorizationWithDisplayName=ue;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=le;exports.user=_;
package/dist/doMock.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var A = Object.defineProperty;
2
2
  var O = (i, e, t) => e in i ? A(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
3
  var n = (i, e, t) => (O(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { j as k, R as N, U as L, S as D } from "./SipConnector-Dq76GLMy.js";
4
+ import { j as k, R as N, U as L, S as D } from "./SipConnector-B87yL77o.js";
5
5
  import W from "@krivega/jssip/lib/NameAddrHeader";
6
6
  import P from "@krivega/jssip/lib/URI";
7
7
  import { EventEmitter as x } from "node:events";
@@ -332,7 +332,7 @@ class J {
332
332
  }
333
333
  }
334
334
  function G(i) {
335
- const e = i.match(/[\d.]+/g);
335
+ const e = i.match(/(purgatory)|[\d.]+/g);
336
336
  if (!e)
337
337
  throw new Error("wrong sip url");
338
338
  return e[0];
@@ -394,7 +394,7 @@ class C extends Y {
394
394
  message: "IncomingResponse",
395
395
  cause: N
396
396
  }) : (this.trigger("connecting"), setTimeout(() => {
397
- this.trigger("enterRoom", r);
397
+ this.trigger("enterRoom", { room: r });
398
398
  }, 100), setTimeout(() => {
399
399
  this.trigger("accepted");
400
400
  }, 200), setTimeout(() => {
package/dist/headers.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare const CONTENT_TYPE_MAIN_CAM = "application/vinteo.webrtc.maincam"
9
9
  export declare const CONTENT_TYPE_MIC = "application/vinteo.webrtc.mic";
10
10
  export declare const CONTENT_TYPE_USE_LICENSE = "application/vinteo.webrtc.uselic";
11
11
  export declare const HEADER_CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE";
12
+ export declare const HEADER_PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME";
12
13
  export declare const HEADER_INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS";
13
14
  export declare const HEADER_OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS";
14
15
  export declare const HEADER_MAIN_CAM = "X-WEBRTC-MAINCAM";
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-BrUmibLH.cjs"),H=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug"),x="purgatory",p=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>H.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:C,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:T,onFinishProgressCall:E,onEndedCall:h}=t,R=D({setRemoteStreams:u,getRemoteStreams:B(e)}),y=V(R);s.logger("answerIncomingCall",t);const N=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:y}),A=()=>{const{remoteCallerData:l}=e;return l.incomingNumber};let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,R(),C&&C({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),h&&h()}),l),b=l=>{throw s.logger("onFail"),T&&T(),g(),l},O=()=>{s.logger("onFinish"),E&&E()};if(s.logger("onBeforeProgressCall"),d){const l=A();d(l)}return N().then(M).catch(l=>b(l)).finally(O)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:C,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:T,onFailProgressCall:E,onFinishProgressCall:h,onEndedCall:R}=t,y=D({setRemoteStreams:d,getRemoteStreams:B(e)}),N=V(y);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:N}));let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",T),m??T?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?m&&m():T&&T({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,y(),f&&f({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),R&&R()}),l),b=l=>{throw s.logger("onFail"),E&&E(),g(),l},O=()=>{s.logger("onFinish"),h&&h()};return s.logger("onBeforeProgressCall"),C&&C(r),A().then(M).catch(l=>b(l)).finally(O)},P=e=>{if(!Y.isCanceledError(e))throw e;return{isSuccessful:!1}},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:C,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:T}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:C,user:d,register:f}).then(E=>(s.logger("connectToServer then"),{ua:E,isSuccessful:!0})).catch(async E=>(s.logger("connectToServer catch: error",E),T===!0?e.disconnect().then(()=>P(E)).catch(()=>P(E)):P(E)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(s.logger("disconnectFromServer: catch",n),{isSuccessful:!1}))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",t)),ge=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),Se=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},me=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},fe=1e6,Ee=({maxBitrate:e=fe,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ce=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(r=>{s.logger(r)})),Re=1e6,Me=({sipConnector:e,maxBitrate:n=Re})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Te=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Te(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),_e=e=>n=>[...n].map(r=>async()=>e(r)),be=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=_e(n)(e);return ye(o,t)},ve=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),Oe=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Ae=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),pe=({sipConnector:e})=>{const n=(h,R)=>({isSyncForced:y=!1})=>{if(y){h();return}R()},t=ve(e),r=Ne(e),o=Oe(e),c=Ae(e);let a=()=>{},u=()=>{},d=()=>{},C=()=>{};const f=({onStartMainCamForced:h,onStartMainCamNotForced:R,onStopMainCamForced:y,onStopMainCamNotForced:N,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:S})=>{const g=n(h,R);a=t(g);const M=n(y,N);u=r(M);const b=n(A,_);d=o(b);const O=n(i,S);C=c(O)},m=()=>{a(),u(),d(),C()};return{start:h=>{f(h)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:pe,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:p,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMoveToSpectators:le,resolveOnMustStopPresentation:ue,resolveOnUseLicense:ge,resolveSendMediaState:Se,resolveSendRefusalToTurnOnCam:de,resolveSendRefusalToTurnOnMic:me,resolveStartPresentation:Ee,resolveStopShareSipConnector:Ce,resolveUpdatePresentation:Me,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:be},Symbol.toStringTag,{value:"Module"})),Ie=e=>[...e.keys()].map(n=>e.get(n)),we=(e,n)=>Ie(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=we(n,"codec");return t==null?void 0:t.mimeType}),Be=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),De="ERROR_NOT_RUNNING",ke=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=De,n.name="Not running",n},Fe=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(ke(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Ue=new Error("Stack is empty"),I=e=>e[e.length-1],Le=new Error("Promise is not actual"),xe=new Error("stackPromises only works with functions that returns a Promise"),Ve=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:S})=>{r.push({task:i,index:S})},c=(i,{task:S,index:g})=>{const M=r.find(({task:b,index:O})=>S===b&&g===O);if(!M)throw new Error("Task not found");if(M.promise)throw new Error("Task is already running");M.promise=i},a=({task:i,index:S})=>{const g=r.find(({task:M,index:b})=>i===M&&S===b);if(g)return g.promise},u=({task:i})=>{const S=I(r);return(S==null?void 0:S.task)===i},d=({task:i,index:S})=>(o({task:i,index:S}),async()=>{let g=a({task:i,index:S});const M=u({task:i});return!g&&n&&!M?Promise.resolve():(g||(g=i({isActual:M}),c(g,{task:i,index:S})),g)}),C=({resolve:i,reject:S})=>({results:g,isSuccessful:M})=>{const b=g.length,O=t.length;if(b===O){const l=I(g);if(M){i(l);return}S(l);return}if(e){const l=I(g);i(l);return}S(Le)};let f=!1;const m=()=>{f=!0},T=()=>{f=!1},E=()=>f,h=async()=>(m(),Fe(t,E)),R=async()=>{if(t.length===0)throw Ue;return new Promise((i,S)=>{const g=C({resolve:i,reject:S});h().then(g).catch(g)})},y=i=>{if(typeof i!="function")throw xe;const S=t.length;return t.push(d({task:i,index:S})),R},N=async i=>(y(i),R()),A=()=>{t.length=0,r.length=0},_=()=>{T(),A()};return R.add=y,R.run=N,R.stop=_,R},$e=1e6,v=e=>e*$e,X=v(.06),je=v(4),Ge=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):je,Xe="av1",Ke=e=>G(e,Xe),We=.6,K=(e,n)=>Ke(n)?e*We:e,qe=e=>K(X,e),W=(e,n)=>{const t=Ge(e);return K(t,n)},q=Ve(),He=async()=>q().catch(e=>{s.logger("videoSendingBalancer: error",e)}),Ye=async e=>(q.add(e),He()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>Ye(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),ze=async({sender:e,codec:n},t)=>{const o=qe(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},Je=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,C]=t.split("x"),f=a/Number(d),m=u/Number(C),E=Math.max(f,m,1),h=W(Number(d),r);return F({sender:e,maxBitrate:h,onSetParameters:o,scaleResolutionDownBy:E})},Qe=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return ze({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?Je({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=Be(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Qe({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Ze=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:C,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:C,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Ze;exports.tools=Pe;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-BSuVfStn.cjs"),H=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug"),x="purgatory",p=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>H.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:C,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:T,onFinishProgressCall:E,onEndedCall:h}=t,R=D({setRemoteStreams:u,getRemoteStreams:B(e)}),y=V(R);s.logger("answerIncomingCall",t);const N=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:y}),A=()=>{const{remoteCallerData:l}=e;return l.incomingNumber};let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,R(),C&&C({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),h&&h()}),l),b=l=>{throw s.logger("onFail"),T&&T(),g(),l},O=()=>{s.logger("onFinish"),E&&E()};if(s.logger("onBeforeProgressCall"),d){const l=A();d(l)}return N().then(M).catch(l=>b(l)).finally(O)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:C,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:T,onFailProgressCall:E,onFinishProgressCall:h,onEndedCall:R}=t,y=D({setRemoteStreams:d,getRemoteStreams:B(e)}),N=V(y);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:N}));let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",T),m??T?e.onSession("enterRoom",({room:l})=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?m&&m():T&&T({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,y(),f&&f({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),R&&R()}),l),b=l=>{throw s.logger("onFail"),E&&E(),g(),l},O=()=>{s.logger("onFinish"),h&&h()};return s.logger("onBeforeProgressCall"),C&&C(r),A().then(M).catch(l=>b(l)).finally(O)},P=e=>{if(!Y.isCanceledError(e))throw e;return{isSuccessful:!1}},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:C,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:T}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:C,user:d,register:f}).then(E=>(s.logger("connectToServer then"),{ua:E,isSuccessful:!0})).catch(async E=>(s.logger("connectToServer catch: error",E),T===!0?e.disconnect().then(()=>P(E)).catch(()=>P(E)):P(E)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(s.logger("disconnectFromServer: catch",n),{isSuccessful:!1}))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",t)),ge=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),Se=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},me=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},fe=1e6,Ee=({maxBitrate:e=fe,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ce=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(r=>{s.logger(r)})),Re=1e6,Me=({sipConnector:e,maxBitrate:n=Re})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Te=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Te(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),_e=e=>n=>[...n].map(r=>async()=>e(r)),be=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=_e(n)(e);return ye(o,t)},ve=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),Oe=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Ae=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),pe=({sipConnector:e})=>{const n=(h,R)=>({isSyncForced:y=!1})=>{if(y){h();return}R()},t=ve(e),r=Ne(e),o=Oe(e),c=Ae(e);let a=()=>{},u=()=>{},d=()=>{},C=()=>{};const f=({onStartMainCamForced:h,onStartMainCamNotForced:R,onStopMainCamForced:y,onStopMainCamNotForced:N,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:S})=>{const g=n(h,R);a=t(g);const M=n(y,N);u=r(M);const b=n(A,_);d=o(b);const O=n(i,S);C=c(O)},m=()=>{a(),u(),d(),C()};return{start:h=>{f(h)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:pe,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:p,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMoveToSpectators:le,resolveOnMustStopPresentation:ue,resolveOnUseLicense:ge,resolveSendMediaState:Se,resolveSendRefusalToTurnOnCam:de,resolveSendRefusalToTurnOnMic:me,resolveStartPresentation:Ee,resolveStopShareSipConnector:Ce,resolveUpdatePresentation:Me,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:be},Symbol.toStringTag,{value:"Module"})),Ie=e=>[...e.keys()].map(n=>e.get(n)),we=(e,n)=>Ie(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=we(n,"codec");return t==null?void 0:t.mimeType}),Be=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),De="ERROR_NOT_RUNNING",ke=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=De,n.name="Not running",n},Fe=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(ke(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Ue=new Error("Stack is empty"),I=e=>e[e.length-1],Le=new Error("Promise is not actual"),xe=new Error("stackPromises only works with functions that returns a Promise"),Ve=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:S})=>{r.push({task:i,index:S})},c=(i,{task:S,index:g})=>{const M=r.find(({task:b,index:O})=>S===b&&g===O);if(!M)throw new Error("Task not found");if(M.promise)throw new Error("Task is already running");M.promise=i},a=({task:i,index:S})=>{const g=r.find(({task:M,index:b})=>i===M&&S===b);if(g)return g.promise},u=({task:i})=>{const S=I(r);return(S==null?void 0:S.task)===i},d=({task:i,index:S})=>(o({task:i,index:S}),async()=>{let g=a({task:i,index:S});const M=u({task:i});return!g&&n&&!M?Promise.resolve():(g||(g=i({isActual:M}),c(g,{task:i,index:S})),g)}),C=({resolve:i,reject:S})=>({results:g,isSuccessful:M})=>{const b=g.length,O=t.length;if(b===O){const l=I(g);if(M){i(l);return}S(l);return}if(e){const l=I(g);i(l);return}S(Le)};let f=!1;const m=()=>{f=!0},T=()=>{f=!1},E=()=>f,h=async()=>(m(),Fe(t,E)),R=async()=>{if(t.length===0)throw Ue;return new Promise((i,S)=>{const g=C({resolve:i,reject:S});h().then(g).catch(g)})},y=i=>{if(typeof i!="function")throw xe;const S=t.length;return t.push(d({task:i,index:S})),R},N=async i=>(y(i),R()),A=()=>{t.length=0,r.length=0},_=()=>{T(),A()};return R.add=y,R.run=N,R.stop=_,R},$e=1e6,v=e=>e*$e,X=v(.06),je=v(4),Ge=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):je,Xe="av1",Ke=e=>G(e,Xe),We=.6,K=(e,n)=>Ke(n)?e*We:e,qe=e=>K(X,e),W=(e,n)=>{const t=Ge(e);return K(t,n)},q=Ve(),He=async()=>q().catch(e=>{s.logger("videoSendingBalancer: error",e)}),Ye=async e=>(q.add(e),He()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>Ye(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),ze=async({sender:e,codec:n},t)=>{const o=qe(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},Je=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,C]=t.split("x"),f=a/Number(d),m=u/Number(C),E=Math.max(f,m,1),h=W(Number(d),r);return F({sender:e,maxBitrate:h,onSetParameters:o,scaleResolutionDownBy:E})},Qe=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return ze({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?Je({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=Be(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Qe({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Ze=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:C,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:C,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Ze;exports.tools=Pe;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { l as o, B as V, N as $, E as P, s as q, S as tn } from "./SipConnector-Dq76GLMy.js";
2
- import { f as ln, g as Sn, i as dn, c as mn, a as fn, d as Cn, b as En, e as gn, h as Rn } from "./SipConnector-Dq76GLMy.js";
1
+ import { l as o, B as V, N as $, E as P, s as q, S as tn } from "./SipConnector-B87yL77o.js";
2
+ import { f as ln, g as Sn, i as dn, c as mn, a as fn, d as Cn, b as En, e as gn, h as Rn } from "./SipConnector-B87yL77o.js";
3
3
  import { debounce as J } from "ts-debounce";
4
4
  import { isCanceledError as Q } from "@krivega/cancelable-promise";
5
5
  import { default as Tn } from "debug";
@@ -85,7 +85,7 @@ const G = "purgatory", A = (e) => e === G, k = (e) => () => (o("getRemoteStreams
85
85
  ontrack: O
86
86
  }));
87
87
  let _ = !1, i;
88
- const S = (o("subscribeEnterConference: onEnterConference", y), f ?? y ? e.onSession("enterRoom", (l) => {
88
+ const S = (o("subscribeEnterConference: onEnterConference", y), f ?? y ? e.onSession("enterRoom", ({ room: l }) => {
89
89
  o("enterRoom", { _room: l, isSuccessProgressCall: _ }), i = l, A(i) ? f && f() : y && y({ isSuccessProgressCall: _ });
90
90
  }) : () => {
91
91
  }), h = (l) => (o("onSuccess"), _ = !0, M(), C && C({ isPurgatory: A(i) }), e.onceRaceSession(["ended", "failed"], () => {
@@ -1,10 +1,22 @@
1
1
  import { default as RTCPeerConnectionMock } from '../../__fixtures__/RTCPeerConnectionMock';
2
2
 
3
+ export declare const onEnterPurgatory: jest.Mock<any, any, any>;
4
+ export declare const onEnterConference: jest.Mock<any, any, any>;
3
5
  declare const data: {
6
+ onEnterPurgatory: jest.Mock<any, any, any>;
7
+ onEnterConference: jest.Mock<any, any, any>;
4
8
  mediaStream: import('webrtc-mock').MediaStreamMock;
5
9
  conference: string;
6
10
  setOutgoingCall: jest.Mock<any, any, any>;
7
11
  setRemoteStreams: jest.Mock<any, any, any>;
8
12
  };
9
13
  export default data;
14
+ export declare const dataCallPurgatory: {
15
+ onEnterPurgatory: jest.Mock<any, any, any>;
16
+ onEnterConference: jest.Mock<any, any, any>;
17
+ conference: string;
18
+ mediaStream: import('webrtc-mock').MediaStreamMock;
19
+ setOutgoingCall: jest.Mock<any, any, any>;
20
+ setRemoteStreams: jest.Mock<any, any, any>;
21
+ };
10
22
  export declare const peerConnectionFromData: RTCPeerConnectionMock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-connector",
3
- "version": "6.25.0",
3
+ "version": "7.0.1",
4
4
  "description": "Module for connect to Vinteo server",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -73,13 +73,13 @@
73
73
  },
74
74
  "devDependencies": {
75
75
  "@babel/preset-typescript": "^7.24.1",
76
- "@commitlint/cli": "^19.2.1",
77
- "@commitlint/config-conventional": "^19.1.0",
78
- "@nabla/vite-plugin-eslint": "^2.0.2",
76
+ "@commitlint/cli": "^19.3.0",
77
+ "@commitlint/config-conventional": "^19.2.2",
78
+ "@nabla/vite-plugin-eslint": "^2.0.4",
79
79
  "@types/debug": "^4.1.12",
80
80
  "@types/jest": "^29.5.12",
81
- "@typescript-eslint/eslint-plugin": "^7.6.0",
82
- "@typescript-eslint/parser": "^7.6.0",
81
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
82
+ "@typescript-eslint/parser": "^7.7.1",
83
83
  "cross-env": "^7.0.3",
84
84
  "eslint": "^8.57.0",
85
85
  "eslint-config-airbnb-base": "^15.0.0",
@@ -102,9 +102,9 @@
102
102
  "ts-jest": "^29.1.2",
103
103
  "ts-node": "^10.9.2",
104
104
  "tsc-files": "^1.1.4",
105
- "typescript": "^5.4.4",
106
- "vite": "^5.2.8",
107
- "vite-plugin-dts": "^3.8.1",
105
+ "typescript": "^5.4.5",
106
+ "vite": "^5.2.10",
107
+ "vite-plugin-dts": "^3.9.0",
108
108
  "vite-tsconfig-paths": "^4.3.2"
109
109
  },
110
110
  "peerDependencies": {
@@ -1 +0,0 @@
1
- "use strict";var ft=Object.defineProperty;var Ot=(r,e,t)=>e in r?ft(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(Ot(r,typeof e!="symbol"?e+"":e,t),t);const N=require("@krivega/cancelable-promise"),pe=require("events-constructor"),B=require("debug"),Mt="Connection Error",qe="Request Timeout",Dt="SIP Failure Code",Pt="Internal Error",pt="Busy",V="Rejected",vt="Redirected",bt="Unavailable",ke="Not Found",wt="Address Incomplete",yt="Incompatible SDP",Ut="Missing SDP",Lt="Authentication Error",We="Terminated",Ht="WebRTC Error",Fe="Canceled",qt="No Answer",kt="Expires",Wt="No ACK",Ft="Dialog Error",Bt="User Denied Media Access",Be="Bad Media Description",Vt="RTP Timeout",Yt=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:wt,AUTHENTICATION_ERROR:Lt,BAD_MEDIA_DESCRIPTION:Be,BUSY:pt,BYE:We,CANCELED:Fe,CONNECTION_ERROR:Mt,DIALOG_ERROR:Ft,EXPIRES:kt,INCOMPATIBLE_SDP:yt,INTERNAL_ERROR:Pt,MISSING_SDP:Ut,NOT_FOUND:ke,NO_ACK:Wt,NO_ANSWER:qt,REDIRECTED:vt,REJECTED:V,REQUEST_TIMEOUT:qe,RTP_TIMEOUT:Vt,SIP_FAILURE_CODE:Dt,UNAVAILABLE:bt,USER_DENIED_MEDIA_ACCESS:Bt,WEBRTC_ERROR:Ht},Symbol.toStringTag,{value:"Module"})),Y="incomingCall",x="declinedIncomingCall",$="failedIncomingCall",G="terminatedIncomingCall",q="connecting",m="connected",u="disconnected",P="newRTCSession",f="registered",X="unregistered",O="registrationFailed",Ve="newMessage",J="sipEvent",z="availableSecondRemoteStream",Q="notAvailableSecondRemoteStream",K="mustStopPresentation",p="shareState",j="enterRoom",Z="useLicense",ee="peerconnection:confirmed",te="peerconnection:ontrack",v="channels",ne="channels:notify",se="ended:fromserver",ie="main-cam-control",re="admin-stop-main-cam",oe="admin-start-main-cam",ae="admin-stop-mic",ce="admin-start-mic",b="admin-force-sync-media-state",Ee="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",he="participant:move-request-to-stream",de="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",M="ended",Ye="sending",xe="reinvite",$e="replaces",Ge="refer",Xe="progress",Je="accepted",w="confirmed",y="peerconnection",C="failed",ze="muted",Qe="unmuted",Ae="newDTMF",Re="newInfo",Ke="hold",je="unhold",Ze="update",et="sdp",tt="icecandidate",nt="getusermediafailed",st="peerconnection:createofferfailed",it="peerconnection:createanswerfailed",rt="peerconnection:setlocaldescriptionfailed",ot="peerconnection:setremotedescriptionfailed",at="presentation:start",ct="presentation:started",Et="presentation:end",Ie="presentation:ended",U="presentation:failed",_t="SPECTATOR",xt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Je,ACCOUNT_CHANGED:Ne,ACCOUNT_DELETED:ge,ADMIN_FORCE_SYNC_MEDIA_STATE:b,ADMIN_START_MAIN_CAM:oe,ADMIN_START_MIC:ce,ADMIN_STOP_MAIN_CAM:re,ADMIN_STOP_MIC:ae,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:z,CHANNELS:v,CHANNELS_NOTIFY:ne,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:Ce,CONFIRMED:w,CONNECTED:m,CONNECTING:q,DECLINED_INCOMING_CALL:x,DISCONNECTED:u,ENDED:M,ENDED_FROM_SERVER:se,ENTER_ROOM:j,FAILED:C,FAILED_INCOMING_CALL:$,GET_USER_MEDIA_FAILED:nt,HOLD:Ke,ICE_CANDIDATE:tt,INCOMING_CALL:Y,MAIN_CAM_CONTROL:ie,MUST_STOP_PRESENTATION_EVENT:K,MUTED:ze,NEW_DTMF:Ae,NEW_INFO:Re,NEW_MESSAGE:Ve,NEW_RTC_SESSION:P,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Q,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Ee,PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS:de,PARTICIPANT_MOVE_REQUEST_TO_STREAM:he,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:_e,PARTICIPATION_ACCEPTING_WORD_REQUEST:le,PARTICIPATION_CANCELLING_WORD_REQUEST:Te,PEER_CONNECTION:y,PEER_CONNECTION_CONFIRMED:ee,PEER_CONNECTION_CREATE_ANSWER_FAILED:it,PEER_CONNECTION_CREATE_OFFER_FAILED:st,PEER_CONNECTION_ONTRACK:te,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:rt,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:ot,PRESENTATION_END:Et,PRESENTATION_ENDED:Ie,PRESENTATION_FAILED:U,PRESENTATION_START:at,PRESENTATION_STARTED:ct,PROGRESS:Xe,REFER:Ge,REGISTERED:f,REGISTRATION_FAILED:O,REINVITE:xe,REPLACES:$e,SDP:et,SENDING:Ye,SHARE_STATE:p,SIP_EVENT:J,SPECTATOR:_t,TERMINATED_INCOMING_CALL:G,UNHOLD:je,UNMUTED:Qe,UNREGISTERED:X,UPDATE:Ze,USE_LICENSE:Z,WEBCAST_STARTED:ue,WEBCAST_STOPPED:Se},Symbol.toStringTag,{value:"Module"})),ht=[Y,x,G,$,le,Te,he,ne,Ce,Ne,ge,ue,Se,Ee,_e],me=[q,m,u,P,f,X,O,Ve,J],dt=[z,Q,K,p,j,Z,ee,te,v,se,ie,oe,re,ae,ce,b,de],fe=[M,q,Ye,xe,$e,Ge,Xe,Je,w,y,C,ze,Qe,Ae,Re,Ke,je,Ze,et,tt,nt,st,it,rt,ot,at,ct,Et,Ie,U],Oe=[...me,...ht],Me=[...fe,...dt],$t=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Me,SESSION_JSSIP_EVENT_NAMES:fe,SESSION_SYNTHETICS_EVENT_NAMES:dt,UA_EVENT_NAMES:Oe,UA_JSSIP_EVENT_NAMES:me,UA_SYNTHETICS_EVENT_NAMES:ht},Symbol.toStringTag,{value:"Module"})),Gt=r=>{const e=[];return r&&e.push(`X-Vinteo-Remote: ${r}`),e},Xt="content-type",Jt="x-webrtc-enter-room",D="application/vinteo.webrtc.sharedesktop",zt="application/vinteo.webrtc.roomname",Qt="application/vinteo.webrtc.channels",Kt="application/vinteo.webrtc.mediastate",jt="application/vinteo.webrtc.refusal",ve="application/vinteo.webrtc.maincam",Zt="application/vinteo.webrtc.mic",en="application/vinteo.webrtc.uselic",tn="X-WEBRTC-USE-LICENSE",be="X-WEBRTC-INPUT-CHANNELS",we="X-WEBRTC-OUTPUT-CHANNELS",nn="X-WEBRTC-MAINCAM",sn="X-WEBRTC-MIC",ye="X-WEBRTC-SYNC",rn="X-WEBRTC-MAINCAM-RESOLUTION",on="X-WEBRTC-MEDIA-STATE",an="X-Vinteo-Media-Type",cn="X-Vinteo-MainCam-State",En="X-Vinteo-Mic-State",_n="application/vinteo.webrtc.partstate",hn="X-WEBRTC-PARTSTATE",dn="application/vinteo.webrtc.notify",ln="X-VINTEO-NOTIFY",R="x-webrtc-share-state",Tn=`${R}: LETMESTARTPRESENTATION`,un=`${R}: STOPPRESENTATION`,lt="YOUCANRECEIVECONTENT",Tt="CONTENTEND",ut="YOUMUSTSTOPSENDCONTENT",Sn=`${R}: ${ut}`,Nn=`${R}: ${lt}`,gn=`${R}: ${Tt}`,Cn="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",An=`${Cn}: LETMESTARTMAINCAM`,De="sip-connector",W=B(De),Rn=()=>{B.enable(De)},In=()=>{B.enable(`-${De}`)};var A=(r=>(r.PAUSE_MAIN_CAM="PAUSEMAINCAM",r.RESUME_MAIN_CAM="RESUMEMAINCAM",r.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",r.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",r.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",r))(A||{}),L=(r=>(r.ADMIN_STOP_MIC="ADMINSTOPMIC",r.ADMIN_START_MIC="ADMINSTARTMIC",r))(L||{}),H=(r=>(r.ADMIN_SYNC_FORCED="1",r.ADMIN_SYNC_NOT_FORCED="0",r))(H||{}),St=(r=>(r.AUDIO="AUDIO",r.VIDEO="VIDEO",r.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",r))(St||{});function Ue(r){return e=>`sip:${e}@${r}`}const mn=(r,e)=>()=>Math.floor(Math.random()*(e-r))+r,Le=r=>r.trim().replaceAll(" ","_"),fn=mn(1e5,99999999),k=(r,{videoMode:e,audioMode:t}={})=>{if(!r||e==="recvonly"&&t==="recvonly")return;const n=t==="recvonly"?[]:r.getAudioTracks(),s=e==="recvonly"?[]:r.getVideoTracks(),o=[...n,...s],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],a},On=r=>r.some(t=>{const{kind:n}=t;return n==="video"}),Mn="Error decline with 603",Dn=r=>r.message===Mn,Pn=(r,e)=>r.find(t=>t.track&&e.getTracks().includes(t.track)),Nt=1,gt=r=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==r,pn=gt(Nt),vn=(r,e)=>{const t=r===void 0?void 0:Math.max(r,Nt);if(t!==void 0&&pn(t,e))return t},bn=gt(),wn=(r,e)=>{if(bn(r,e))return r},Ct=async(r,e,t)=>{const n=r.getParameters();(n.encodings===void 0||n.encodings.length===0)&&(n.encodings=[{}]);const[s]=n.encodings,o=s.scaleResolutionDownBy,a=vn(e.scaleResolutionDownBy,o);let c=!1;a!==void 0&&(n.encodings[0].scaleResolutionDownBy=a,c=!0);const E=s.maxBitrate,_=wn(e.maxBitrate,E);return _!==void 0&&(n.encodings[0].maxBitrate=_,c=!0),c?(t&&t(n),r.setParameters(n).then(()=>({parameters:n,isChanged:c}))):{parameters:n,isChanged:c}},yn=async(r,e,t)=>{const n=Pn(r,e);if(n)return Ct(n,{maxBitrate:t})},Un=486,Ln=487,F="local",He="remote",Hn=(r=new Error)=>{const{originator:e,cause:t}=r;return N.isCanceledError(r)?!0:typeof t=="string"?t===qe||t===V||e===F&&(t===Fe||t===We):!1},g="SipConnector",qn="channels",kn="WebcastStarted",Wn="WebcastStopped",Fn="accountChanged",Bn="accountDeleted",Vn="addedToListModerators",Yn="removedFromListModerators",xn="ParticipationRequestAccepted",$n="ParticipationRequestRejected",Gn="ParticipantMovedToWebcast",Xn="ConferenceParticipantTokenIssued";class Jn{constructor({JsSIP:e}){i(this,"_isRegisterConfig",!1);i(this,"_connectionConfiguration",{});i(this,"_remoteStreams",{});i(this,"JsSIP");i(this,"_sessionEvents");i(this,"_uaEvents");i(this,"_cancelableConnect");i(this,"_cancelableInitUa");i(this,"_cancelableDisconnect");i(this,"_cancelableSet");i(this,"_cancelableCall");i(this,"_cancelableAnswer");i(this,"_cancelableSendDTMF");i(this,"getSipServerUrl",e=>e);i(this,"promisePendingStartPresentation");i(this,"promisePendingStopPresentation");i(this,"ua");i(this,"session");i(this,"incomingSession");i(this,"_streamPresentationCurrent");i(this,"socket");i(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));i(this,"initUa",async e=>this._cancelableInitUa.request(e));i(this,"set",async e=>this._cancelableSet.request(e));i(this,"call",async e=>this._cancelableCall.request(e));i(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));i(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));i(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));i(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));i(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(q,void 0);try{await this.unregister()}catch(e){W("tryRegister",e)}return this.register()});i(this,"declineToIncomingCall",async({statusCode:e=Ln}={})=>new Promise((t,n)=>{if(!this.isAvailableIncomingCall){n(new Error("no incomingSession"));return}const s=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(x,o),t(s.terminate({status_code:e}))}));i(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:Un}));i(this,"removeIncomingSession",()=>{delete this.incomingSession});i(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===He){this.incomingSession=t;const n=this.remoteCallerData;t.on(C,s=>{this.removeIncomingSession(),s.originator===F?this._uaEvents.trigger(G,n):this._uaEvents.trigger($,n)}),this._uaEvents.trigger(Y,n)}});i(this,"_connect",async e=>this.initUa(e).then(async()=>this._start()));i(this,"_initUa",async({user:e,password:t,sipServerUrl:n,sipWebSocketServerURL:s,remoteAddress:o,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,displayName:d="",register:l=!1,extraHeaders:S=[]})=>{if(!n)throw new Error("sipServerUrl is required");if(!s)throw new Error("sipWebSocketServerURL is required");if(l&&!e)throw new Error("user is required for authorized connection");if(l&&!t)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:n,displayName:d,register:l,user:e,password:t},this.getSipServerUrl=Ue(n),this.socket=new this.JsSIP.WebSocketInterface(s),this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!l;const{socket:I}=this;this.ua=this._createUa({user:e,password:t,socket:I,displayName:d,register:l,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,getSipServerUrl:this.getSipServerUrl}),this._uaEvents.eachTriggers((Rt,It)=>{const Pe=me.find(mt=>mt===It);Pe&&this.ua&&this.ua.on(Pe,Rt)});const At=[...Gt(o),...S];return this.ua.registrator().setExtraHeaders(At),this.ua});i(this,"_createUa",({user:e,password:t,socket:n,displayName:s,getSipServerUrl:o,register:a=!1,sdpSemantics:c="plan-b",sessionTimers:E=!1,registerExpires:_=60*5,connectionRecoveryMinInterval:h=2,connectionRecoveryMaxInterval:T=6,userAgent:d})=>{if(a&&!t)throw new Error("password is required for authorized connection");const l=a&&e?e.trim():`${fn()}`,S=o(l),I={password:t,register:a,uri:S,display_name:Le(s),user_agent:d,sdp_semantics:c,sockets:[n],session_timers:E,register_expires:_,connection_recovery_min_interval:h,connection_recovery_max_interval:T};return new this.JsSIP.UA(I)});i(this,"_start",async()=>new Promise((e,t)=>{const{ua:n}=this;if(!n){t(new Error("this.ua is not initialized"));return}const s=()=>{c(),e(n)},o=E=>{c(),t(E)},a=()=>{this.isRegisterConfig?(this.on(f,s),this.on(O,o)):this.on(m,s),this.on(u,o)},c=()=>{this.off(f,s),this.off(O,o),this.off(m,s),this.off(u,o)};a(),this.on(P,this.handleNewRTCSession),n.start()}));i(this,"_set",async({displayName:e,password:t})=>new Promise((n,s)=>{const{ua:o}=this;if(!o){s(new Error("this.ua is not initialized"));return}let a=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(a=o.set("display_name",Le(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const E=a||c;c&&this.isRegisterConfig?this.register().then(()=>{n(E)}).catch(_=>{s(_)}):E?n(E):s(new Error("nothing changed"))}));i(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());i(this,"_disconnect",async()=>{this.off(P,this.handleNewRTCSession);const e=new Promise(t=>{this.once(u,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(u,void 0)):this._uaEvents.trigger(u,void 0),e});i(this,"_call",async({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:o,videoMode:a,audioMode:c,degradationPreference:E,offerToReceiveAudio:_=!0,offerToReceiveVideo:h=!0})=>new Promise((T,d)=>{const{ua:l}=this;if(!l){d(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(T).catch(S=>{d(S)}),this.session=l.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:k(t,{videoMode:a,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:a,audioMode:c,degradationPreference:E,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:_,offerToReceiveVideo:h}})}));i(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:o,audioMode:a,degradationPreference:c})=>new Promise((E,_)=>{if(!this.isAvailableIncomingCall){_(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:h}=this;if(!h){_(new Error("No session established"));return}this._sessionEvents.eachTriggers((d,l)=>{const S=fe.find(I=>I===l);S&&h.on(S,d)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=h.remote_identity.uri.user,this._handleCall({ontrack:t}).then(E).catch(d=>{_(d)});const T=k(e,{videoMode:o,audioMode:a});h.answer({extraHeaders:n,videoMode:o,audioMode:a,degradationPreference:c,mediaStream:T,pcConfig:{iceServers:s}})}));i(this,"_handleCall",async({ontrack:e})=>new Promise((t,n)=>{const s=()=>{this.onSession(y,h),this.onSession(w,T)},o=()=>{this.offSession(y,h),this.offSession(w,T)},a=()=>{this.onSession(C,E),this.onSession(M,E)},c=()=>{this.offSession(C,E),this.offSession(M,E)},E=d=>{o(),c(),n(d)};let _;const h=({peerconnection:d})=>{_=d,_.ontrack=l=>{this._sessionEvents.trigger(te,_),e&&e(l)}},T=()=>{_&&this._sessionEvents.trigger(ee,_),o(),c(),t(_)};s(),a()}));i(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});i(this,"_sendDTMF",async e=>new Promise((t,n)=>{const{session:s}=this;if(!s){n(new Error("No session established"));return}this.onceSession(Ae,({originator:o})=>{o===F&&t()}),s.sendDTMF(e,{duration:120,interToneGap:600})}));i(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),e.isEnded()||e.terminate()}});i(this,"_handleShareState",e=>{switch(e){case lt:{this._sessionEvents.trigger(z,void 0);break}case Tt:{this._sessionEvents.trigger(Q,void 0);break}case ut:{this._sessionEvents.trigger(K,void 0);break}}});i(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(be),n=e.getHeader(we);if(t&&n){const s={inputChannels:t,outputChannels:n};this._sessionEvents.trigger(v,s)}});i(this,"_handleNotify",e=>{switch(e.cmd){case qn:{const t=e;this._triggerChannelsNotify(t);break}case kn:{const t=e;this._triggerWebcastStartedNotify(t);break}case Wn:{const t=e;this._triggerWebcastStoppedNotify(t);break}case Vn:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case Yn:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case xn:{const t=e;this._triggerParticipationAcceptingWordRequest(t);break}case $n:{const t=e;this._triggerParticipationCancellingWordRequest(t);break}case Gn:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case Fn:{this._triggerAccountChangedNotify();break}case Bn:{this._triggerAccountDeletedNotify();break}case Xn:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:W("unknown cmd",e.cmd)}});i(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(_e,t)});i(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Ee,t)});i(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(ue,n)});i(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(Se,n)});i(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(Ne,void 0)});i(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(ge,void 0)});i(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger(Ce,s)});i(this,"_triggerChannelsNotify",e=>{const t=e.input,n=e.output,s={inputChannels:t,outputChannels:n};this._uaEvents.trigger(ne,s)});i(this,"_triggerParticipationAcceptingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(le,t)});i(this,"_triggerParticipationCancellingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(Te,t)});i(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(he,t)});i(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Jt);this._sessionEvents.trigger(j,t)});i(this,"_triggerShareState",e=>{const t=e.getHeader(R);this._sessionEvents.trigger(p,t)});i(this,"_maybeTriggerParticipantMoveRequestToSpectators",e=>{e.getHeader(hn)===_t&&this._sessionEvents.trigger(de,void 0)});i(this,"_triggerMainCamControl",e=>{const t=e.getHeader(nn),n=e.getHeader(ye),s=n===H.ADMIN_SYNC_FORCED;if(t===A.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(oe,{isSyncForced:s});else if(t===A.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(re,{isSyncForced:s});else if((t===A.RESUME_MAIN_CAM||t===A.PAUSE_MAIN_CAM)&&n)this._sessionEvents.trigger(b,{isSyncForced:s});else{const o=e.getHeader(rn);this._sessionEvents.trigger(ie,{mainCam:t,resolutionMainCam:o})}});i(this,"_triggerMicControl",e=>{const t=e.getHeader(sn),s=e.getHeader(ye)===H.ADMIN_SYNC_FORCED;t===L.ADMIN_START_MIC?this._sessionEvents.trigger(ce,{isSyncForced:s}):t===L.ADMIN_STOP_MIC&&this._sessionEvents.trigger(ae,{isSyncForced:s})});i(this,"_triggerUseLicense",e=>{const t=e.getHeader(tn);this._sessionEvents.trigger(Z,t)});i(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:n}=e,s=n.getHeader(Xt);if(s)switch(s){case zt:{this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break}case dn:{this._maybeHandleNotify(n);break}case D:{this._triggerShareState(n);break}case ve:{this._triggerMainCamControl(n);break}case Zt:{this._triggerMicControl(n);break}case en:{this._triggerUseLicense(n);break}case _n:{this._maybeTriggerParticipantMoveRequestToSpectators(n);break}}});i(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});i(this,"_maybeHandleNotify",e=>{const t=e.getHeader(ln);if(t){const n=JSON.parse(t);this._handleNotify(n)}});i(this,"_handleEnded",e=>{const{originator:t}=e;t===He&&this._sessionEvents.trigger(se,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new pe(Me),this._uaEvents=new pe(Oe),this._cancelableConnect=new N.CancelableRequest(this._connect,{moduleName:g,afterCancelRequest:()=>{this._cancelableInitUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableInitUa=new N.CancelableRequest(this._initUa,{moduleName:g}),this._cancelableDisconnect=new N.CancelableRequest(this._disconnect,{moduleName:g}),this._cancelableSet=new N.CancelableRequest(this._set,{moduleName:g}),this._cancelableCall=new N.CancelableRequest(this._call,{moduleName:g}),this._cancelableAnswer=new N.CancelableRequest(this._answer,{moduleName:g}),this._cancelableSendDTMF=new N.CancelableRequest(this._sendDTMF,{moduleName:g}),this.onSession(p,this._handleShareState),this.onSession(Re,this._handleNewInfo),this.on(J,this._handleSipEvent),this.onSession(C,this._handleEnded),this.onSession(M,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(f,e),this.ua.on(O,t),this.ua.register()):t(new Error("Config is not registered"))})}async unregister(){return new Promise((e,t)=>{this.isRegistered&&this.ua?(this.ua.on(X,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,n){if(!this.ua)throw new Error("is not connected");return new Promise((s,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:o}})}catch(a){o(a)}})}async ping(e,t){var s;if(!((s=this.ua)!=null&&s.configuration.uri))throw new Error("is not connected");const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}async checkTelephony({userAgent:e,displayName:t,sipServerUrl:n,sipWebSocketServerURL:s,sdpSemantics:o}){return new Promise((a,c)=>{const E=Ue(n),_=new this.JsSIP.WebSocketInterface(s),h=this._createUa({socket:_,displayName:t,sdpSemantics:o,userAgent:e,getSipServerUrl:E}),T=()=>{const l=new Error("Telephony is not available");c(l)};h.once(u,T);const d=()=>{h.removeAllListeners(),h.once(u,a),h.stop()};h.once(m,d),h.start()})}async replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}async askPermissionToEnableCam(e={}){if(!this.session)throw new Error("No session established");const t=[An];return this.session.sendInfo(ve,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(n=>{if(Dn(n))throw n})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:o=!0,isP2P:a=!1}){const c=k(t);this._streamPresentationCurrent=c;const E=a?[Nn]:[Tn],_=e.sendInfo(D,void 0,{extraHeaders:E}).then(async()=>e.startPresentation(c,o,s)).then(async()=>{const{connection:h}=this;if(!h||n===void 0)return;const T=h.getSenders();await yn(T,t,n)}).then(()=>t).catch(h=>{throw this._sessionEvents.trigger(U,h),h});return this.promisePendingStartPresentation=_,_.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:o}={}){const a=this.establishedSession;if(!a)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return n&&await this.sendMustStopPresentation(a),this._sendPresentation(a,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:o})}async sendMustStopPresentation(e){await e.sendInfo(D,void 0,{extraHeaders:[Sn]})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation??Promise.resolve();const s=e?[gn]:[un],o=this.establishedSession;return o&&t&&(n=n.then(async()=>o.sendInfo(D,void 0,{extraHeaders:s})).then(async()=>o.stopPresentation(t)).catch(a=>{throw this._sessionEvents.trigger(U,a),a})),!o&&t&&this._sessionEvents.trigger(Ie,t),this.promisePendingStopPresentation=n,n.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:n,degradationPreference:s}={}){const o=this.establishedSession;if(!o)throw new Error("No session established");if(!this._streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this._sendPresentation(o,e,{isP2P:t,maxBitrate:n,degradationPreference:s,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}async wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}async waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:n})=>n);return On(t)?this._generateStreams(t):this._generateAudioStreams(t)}get connection(){var t;return(t=this.session)==null?void 0:t.connection}get remoteCallerData(){var e,t,n,s,o,a;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(s=(n=this.incomingSession)==null?void 0:n.remote_identity)==null?void 0:s.uri.host,incomingNumber:(a=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:a.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableInitUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){var e;return(e=this.session)!=null&&e.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!!(this.ua&&this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_generateStream(e,t){const{id:n}=e,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const{id:t}=e,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach((n,s)=>{if(n.kind==="audio")return;const o=n,a=e[s-1];let c;a&&a.kind==="audio"&&(c=a);const E=this._generateStream(o,c);t.push(E)}),t}_generateAudioStreams(e){return e.map(n=>this._generateAudioStream(n))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}async waitChannels(){return this.waitSession(v)}async waitSyncMediaState(){return this.waitSession(b)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=`${be}: ${e}`,s=`${we}: ${t}`,o=[n,s];return this.session.sendInfo(Qt,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},n={}){if(!this.session)throw new Error("No session established");const s=`${on}: currentstate`,o=`${cn}: ${Number(e)}`,a=`${En}: ${Number(t)}`,c=[s,o,a];return this.session.sendInfo(Kt,void 0,{noTerminateWhenError:!0,...n,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${an}: ${e==="mic"?0:1}`];return this.session.sendInfo(jt,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}}exports.BAD_MEDIA_DESCRIPTION=Be;exports.EEventsMainCAM=A;exports.EEventsMic=L;exports.EEventsSyncMediaState=H;exports.EUseLicense=St;exports.NOT_FOUND=ke;exports.REJECTED=V;exports.SESSION_EVENT_NAMES=Me;exports.SipConnector=Jn;exports.UA_EVENT_NAMES=Oe;exports.causes=Yt;exports.constants=xt;exports.disableDebug=In;exports.enableDebug=Rn;exports.eventNames=$t;exports.hasCanceledCallError=Hn;exports.logger=W;exports.setEncodingsToSender=Ct;