sip-connector 16.0.3 → 16.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
- import { Events as D, TypedEvents as j } from "events-constructor";
2
- import { CancelableRequest as Ae } from "@krivega/cancelable-promise";
1
+ import { Events as D, TypedEvents as K } from "events-constructor";
2
+ import { CancelableRequest as Re } from "@krivega/cancelable-promise";
3
3
  import q from "debug";
4
- import { hasCanceledError as Re, repeatedCallsAsync as K } from "repeated-calls";
5
- import { setup as Ie, createActor as _e } from "xstate";
6
- import { SetTimeoutRequest as Z } from "@krivega/timeout-requester";
4
+ import { hasCanceledError as Ie, repeatedCallsAsync as j } from "repeated-calls";
5
+ import { setup as _e, createActor as Me } from "xstate";
6
+ import { createStackPromises as Z } from "stack-promises";
7
+ import { SetTimeoutRequest as ee } from "@krivega/timeout-requester";
7
8
  import "ua-parser-js";
8
9
  import "sequent-promises";
9
- import { createStackPromises as Me } from "stack-promises";
10
- var C = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(C || {}), $ = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))($ || {});
11
- const ee = [
10
+ var E = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(E || {}), $ = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))($ || {});
11
+ const te = [
12
12
  "peerconnection",
13
13
  "connecting",
14
14
  "sending",
@@ -39,8 +39,8 @@ const ee = [
39
39
  "peerconnection:confirmed",
40
40
  "peerconnection:ontrack",
41
41
  "ended:fromserver"
42
- ], te = [
43
- ...ee,
42
+ ], ne = [
43
+ ...te,
44
44
  ...me
45
45
  ], pe = (n, e) => {
46
46
  n.getVideoTracks().forEach((s) => {
@@ -53,13 +53,13 @@ const ee = [
53
53
  } = {}) => {
54
54
  if (!n || e === "recvonly" && t === "recvonly")
55
55
  return;
56
- const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
56
+ const r = t === "recvonly" ? [] : n.getAudioTracks(), i = e === "recvonly" ? [] : n.getVideoTracks(), a = [...r, ...i], o = new MediaStream(a);
57
57
  return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && pe(o, s), o;
58
58
  };
59
59
  function Pe(n) {
60
60
  return (e) => `sip:${e}@${n}`;
61
61
  }
62
- const fe = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, ne = (n) => n.trim().replaceAll(" ", "_"), Oe = fe(1e5, 99999999), ve = (n) => n.some((t) => {
62
+ const fe = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, se = (n) => n.trim().replaceAll(" ", "_"), Oe = fe(1e5, 99999999), ve = (n) => n.some((t) => {
63
63
  const { kind: s } = t;
64
64
  return s === "video";
65
65
  });
@@ -74,15 +74,15 @@ class De {
74
74
  this.events = e;
75
75
  }
76
76
  }
77
- var se = /* @__PURE__ */ ((n) => (n.BYE = "Terminated", n.WEBRTC_ERROR = "WebRTC Error", n.CANCELED = "Canceled", n.REQUEST_TIMEOUT = "Request Timeout", n.REJECTED = "Rejected", n.REDIRECTED = "Redirected", n.UNAVAILABLE = "Unavailable", n.NOT_FOUND = "Not Found", n.ADDRESS_INCOMPLETE = "Address Incomplete", n.INCOMPATIBLE_SDP = "Incompatible SDP", n.BAD_MEDIA_DESCRIPTION = "Bad Media Description", n))(se || {});
77
+ var re = /* @__PURE__ */ ((n) => (n.BYE = "Terminated", n.WEBRTC_ERROR = "WebRTC Error", n.CANCELED = "Canceled", n.REQUEST_TIMEOUT = "Request Timeout", n.REJECTED = "Rejected", n.REDIRECTED = "Redirected", n.UNAVAILABLE = "Unavailable", n.NOT_FOUND = "Not Found", n.ADDRESS_INCOMPLETE = "Address Incomplete", n.INCOMPATIBLE_SDP = "Incompatible SDP", n.BAD_MEDIA_DESCRIPTION = "Bad Media Description", n))(re || {});
78
78
  class ye {
79
79
  remoteStreams = {};
80
80
  reset() {
81
81
  this.remoteStreams = {};
82
82
  }
83
83
  generateStream(e, t) {
84
- const { id: s } = e, i = this.remoteStreams[s] ?? new MediaStream();
85
- return t && i.addTrack(t), i.addTrack(e), this.remoteStreams[s] = i, i;
84
+ const { id: s } = e, r = this.remoteStreams[s] ?? new MediaStream();
85
+ return t && r.addTrack(t), r.addTrack(e), this.remoteStreams[s] = r, r;
86
86
  }
87
87
  generateAudioStream(e) {
88
88
  const { id: t } = e, s = this.remoteStreams[t] ?? new MediaStream();
@@ -90,13 +90,13 @@ class ye {
90
90
  }
91
91
  generateStreams(e) {
92
92
  const t = [];
93
- return e.forEach((s, i) => {
93
+ return e.forEach((s, r) => {
94
94
  if (s.kind === "audio")
95
95
  return;
96
- const r = s, a = e[i - 1];
96
+ const i = s, a = e[r - 1];
97
97
  let o;
98
98
  a?.kind === "audio" && (o = a);
99
- const c = this.generateStream(r, o);
99
+ const c = this.generateStream(i, o);
100
100
  t.push(c);
101
101
  }), t;
102
102
  }
@@ -108,7 +108,7 @@ class be extends De {
108
108
  remoteStreamsManager = new ye();
109
109
  disposers = /* @__PURE__ */ new Set();
110
110
  constructor(e) {
111
- super(e), e.on(C.FAILED, this.handleEnded), e.on(C.ENDED, this.handleEnded);
111
+ super(e), e.on(E.FAILED, this.handleEnded), e.on(E.ENDED, this.handleEnded);
112
112
  }
113
113
  get requested() {
114
114
  return this.isPendingCall || this.isPendingAnswer;
@@ -124,24 +124,24 @@ class be extends De {
124
124
  }
125
125
  startCall = async (e, t, {
126
126
  number: s,
127
- mediaStream: i,
128
- extraHeaders: r = [],
127
+ mediaStream: r,
128
+ extraHeaders: i = [],
129
129
  ontrack: a,
130
130
  iceServers: o,
131
131
  directionVideo: c,
132
132
  directionAudio: d,
133
133
  contentHint: u,
134
134
  offerToReceiveAudio: T = !0,
135
- offerToReceiveVideo: h = !0,
135
+ offerToReceiveVideo: g = !0,
136
136
  degradationPreference: S,
137
137
  sendEncodings: m,
138
138
  onAddedTransceiver: I
139
- }) => (this.isPendingCall = !0, new Promise((A, y) => {
140
- this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(A).catch((b) => {
139
+ }) => (this.isPendingCall = !0, new Promise((R, y) => {
140
+ this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(R).catch((b) => {
141
141
  y(b);
142
142
  }), this.rtcSession = e.call(t(s), {
143
- extraHeaders: r,
144
- mediaStream: B(i, {
143
+ extraHeaders: i,
144
+ mediaStream: B(r, {
145
145
  directionVideo: c,
146
146
  directionAudio: d,
147
147
  contentHint: u
@@ -157,7 +157,7 @@ class be extends De {
157
157
  },
158
158
  rtcOfferConstraints: {
159
159
  offerToReceiveAudio: T,
160
- offerToReceiveVideo: h
160
+ offerToReceiveVideo: g
161
161
  },
162
162
  degradationPreference: S,
163
163
  sendEncodings: m,
@@ -170,7 +170,7 @@ class be extends De {
170
170
  const { rtcSession: e } = this;
171
171
  if (e && !e.isEnded())
172
172
  return e.terminateAsync({
173
- cause: se.CANCELED
173
+ cause: re.CANCELED
174
174
  }).finally(() => {
175
175
  this.reset();
176
176
  });
@@ -179,20 +179,20 @@ class be extends De {
179
179
  answerToIncomingCall = async (e, {
180
180
  mediaStream: t,
181
181
  ontrack: s,
182
- extraHeaders: i = [],
183
- iceServers: r,
182
+ extraHeaders: r = [],
183
+ iceServers: i,
184
184
  directionVideo: a,
185
185
  directionAudio: o,
186
186
  offerToReceiveAudio: c,
187
187
  offerToReceiveVideo: d,
188
188
  contentHint: u,
189
189
  degradationPreference: T,
190
- sendEncodings: h,
190
+ sendEncodings: g,
191
191
  onAddedTransceiver: S
192
192
  }) => (this.isPendingAnswer = !0, new Promise((m, I) => {
193
193
  try {
194
- const A = e();
195
- this.rtcSession = A, this.subscribeToSessionEvents(A), this.callConfiguration.answer = !0, this.callConfiguration.number = A.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(m).catch((b) => {
194
+ const R = e();
195
+ this.rtcSession = R, this.subscribeToSessionEvents(R), this.callConfiguration.answer = !0, this.callConfiguration.number = R.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(m).catch((b) => {
196
196
  I(b);
197
197
  });
198
198
  const y = B(t, {
@@ -200,24 +200,24 @@ class be extends De {
200
200
  directionAudio: o,
201
201
  contentHint: u
202
202
  });
203
- A.answer({
204
- extraHeaders: i,
203
+ R.answer({
204
+ extraHeaders: r,
205
205
  directionVideo: a,
206
206
  directionAudio: o,
207
207
  mediaStream: y,
208
208
  pcConfig: {
209
- iceServers: r
209
+ iceServers: i
210
210
  },
211
211
  rtcOfferConstraints: {
212
212
  offerToReceiveAudio: c,
213
213
  offerToReceiveVideo: d
214
214
  },
215
215
  degradationPreference: T,
216
- sendEncodings: h,
216
+ sendEncodings: g,
217
217
  onAddedTransceiver: S
218
218
  });
219
- } catch (A) {
220
- I(A);
219
+ } catch (R) {
220
+ I(R);
221
221
  }
222
222
  }).finally(() => {
223
223
  this.isPendingAnswer = !1;
@@ -237,44 +237,49 @@ class be extends De {
237
237
  async replaceMediaStream(e, t) {
238
238
  if (!this.rtcSession)
239
239
  throw new Error("No rtcSession established");
240
- const { contentHint: s } = t ?? {}, i = B(e, { contentHint: s });
241
- if (i === void 0)
240
+ const { contentHint: s } = t ?? {}, r = B(e, { contentHint: s });
241
+ if (r === void 0)
242
242
  throw new Error("No preparedMediaStream");
243
- return this.rtcSession.replaceMediaStream(i, t);
243
+ return this.rtcSession.replaceMediaStream(r, t);
244
+ }
245
+ async restartIce(e) {
246
+ if (!this.rtcSession)
247
+ throw new Error("No rtcSession established");
248
+ return this.rtcSession.restartIce(e);
244
249
  }
245
250
  handleCall = async ({
246
251
  ontrack: e
247
252
  }) => new Promise((t, s) => {
248
- const i = () => {
249
- this.events.on(C.PEER_CONNECTION, u), this.events.on(C.CONFIRMED, T);
250
- }, r = () => {
251
- this.events.off(C.PEER_CONNECTION, u), this.events.off(C.CONFIRMED, T);
253
+ const r = () => {
254
+ this.events.on(E.PEER_CONNECTION, u), this.events.on(E.CONFIRMED, T);
255
+ }, i = () => {
256
+ this.events.off(E.PEER_CONNECTION, u), this.events.off(E.CONFIRMED, T);
252
257
  }, a = () => {
253
- this.events.on(C.FAILED, c), this.events.on(C.ENDED, c);
258
+ this.events.on(E.FAILED, c), this.events.on(E.ENDED, c);
254
259
  }, o = () => {
255
- this.events.off(C.FAILED, c), this.events.off(C.ENDED, c);
256
- }, c = (h) => {
257
- r(), o(), s(h);
260
+ this.events.off(E.FAILED, c), this.events.off(E.ENDED, c);
261
+ }, c = (g) => {
262
+ i(), o(), s(g);
258
263
  };
259
264
  let d;
260
- const u = ({ peerconnection: h }) => {
261
- d = h;
265
+ const u = ({ peerconnection: g }) => {
266
+ d = g;
262
267
  const S = (m) => {
263
- this.events.trigger(C.PEER_CONNECTION_ONTRACK, h), e && e(m);
268
+ this.events.trigger(E.PEER_CONNECTION_ONTRACK, g), e && e(m);
264
269
  };
265
- h.addEventListener("track", S), this.disposers.add(() => {
266
- h.removeEventListener("track", S);
270
+ g.addEventListener("track", S), this.disposers.add(() => {
271
+ g.removeEventListener("track", S);
267
272
  });
268
273
  }, T = () => {
269
- d !== void 0 && this.events.trigger(C.PEER_CONNECTION_CONFIRMED, d), r(), o(), t(d);
274
+ d !== void 0 && this.events.trigger(E.PEER_CONNECTION_CONFIRMED, d), i(), o(), t(d);
270
275
  };
271
- i(), a();
276
+ r(), a();
272
277
  });
273
278
  subscribeToSessionEvents(e) {
274
279
  this.events.eachTriggers((t, s) => {
275
- const i = ee.find((r) => r === s);
276
- i && (e.on(i, t), this.disposers.add(() => {
277
- e.off(i, t);
280
+ const r = te.find((i) => i === s);
281
+ r && (e.on(r, t), this.disposers.add(() => {
282
+ e.off(r, t);
278
283
  }));
279
284
  });
280
285
  }
@@ -285,17 +290,17 @@ class be extends De {
285
290
  }
286
291
  handleEnded = (e) => {
287
292
  const { originator: t } = e;
288
- t === $.REMOTE && this.events.trigger(C.ENDED_FROM_SERVER, e), this.reset();
293
+ t === $.REMOTE && this.events.trigger(E.ENDED_FROM_SERVER, e), this.reset();
289
294
  };
290
295
  reset = () => {
291
296
  delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
292
297
  };
293
298
  }
294
- class we {
299
+ class Ue {
295
300
  events;
296
301
  strategy;
297
302
  constructor(e) {
298
- this.events = new D(te), this.strategy = e ?? new be(this.events);
303
+ this.events = new D(ne), this.strategy = e ?? new be(this.events);
299
304
  }
300
305
  get requested() {
301
306
  return this.strategy.requested;
@@ -338,13 +343,14 @@ class we {
338
343
  getCallConfiguration = () => this.strategy.getCallConfiguration();
339
344
  getRemoteStreams = () => this.strategy.getRemoteStreams();
340
345
  replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
346
+ restartIce = async (e) => this.strategy.restartIce(e);
341
347
  }
342
- const G = "sip-connector", R = q(G), un = () => {
348
+ const G = "sip-connector", A = q(G), Tn = () => {
343
349
  q.enable(G);
344
- }, Tn = () => {
350
+ }, Sn = () => {
345
351
  q.enable(`-${G}`);
346
- }, Ue = "Error decline with 603", Le = 1006, Be = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Le, ke = (n) => n.message === Ue;
347
- var l = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n))(l || {}), k = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(k || {}), F = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n.SPECTATOR_OVER_SFU = "SPECTATOROVERSFU", n))(F || {}), O = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(O || {}), M = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.STATS = "application/vinteo.webrtc.stats", n))(M || {}), P = /* @__PURE__ */ ((n) => (n.PAUSE_MAIN_CAM = "PAUSEMAINCAM", n.RESUME_MAIN_CAM = "RESUMEMAINCAM", n.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", n.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", n.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", n))(P || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(W || {}), H = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(H || {}), Fe = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Fe || {}), g = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU = "participant:move-request-to-spectators-over-sfu", n.PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request", n.PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request", n.WEBCAST_STARTED = "webcast:started", n.WEBCAST_STOPPED = "webcast:stopped", n.ACCOUNT_CHANGED = "account:changed", n.ACCOUNT_DELETED = "account:deleted", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n))(g || {});
352
+ }, we = "Error decline with 603", Le = 1006, Be = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Le, ke = (n) => n.message === we;
353
+ var h = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n.AUDIO_TRACK_COUNT = "X-WEBRTC-AUDIO-TRACK-COUNT", n.VIDEO_TRACK_COUNT = "X-WEBRTC-VIDEO-TRACK-COUNT", n.TRACKS_DIRECTION = "X-WEBRTC-TRACKS-DIRECTION", n))(h || {}), k = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(k || {}), F = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n.SPECTATOR_OVER_SFU = "SPECTATOROVERSFU", n))(F || {}), f = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.RESTART = "application/vinteo.webrtc.restart", n))(f || {}), M = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.STATS = "application/vinteo.webrtc.stats", n))(M || {}), P = /* @__PURE__ */ ((n) => (n.PAUSE_MAIN_CAM = "PAUSEMAINCAM", n.RESUME_MAIN_CAM = "RESUMEMAINCAM", n.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", n.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", n.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", n))(P || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(W || {}), H = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(H || {}), Fe = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Fe || {}), l = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU = "participant:move-request-to-spectators-over-sfu", n.PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request", n.PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request", n.WEBCAST_STARTED = "webcast:started", n.WEBCAST_STOPPED = "webcast:stopped", n.ACCOUNT_CHANGED = "account:changed", n.ACCOUNT_DELETED = "account:deleted", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n.RESTART = "restart", n))(l || {});
348
354
  const ie = [
349
355
  "participation:accepting-word-request",
350
356
  "participation:cancelling-word-request",
@@ -373,7 +379,8 @@ const ie = [
373
379
  "availableSecondRemoteStream",
374
380
  "notAvailableSecondRemoteStream",
375
381
  "mustStopPresentation",
376
- "newDTMF"
382
+ "newDTMF",
383
+ "restart"
377
384
  ];
378
385
  var _ = /* @__PURE__ */ ((n) => (n.CHANNELS = "channels", n.WEBCAST_STARTED = "WebcastStarted", n.WEBCAST_STOPPED = "WebcastStopped", n.ACCOUNT_CHANGED = "accountChanged", n.ACCOUNT_DELETED = "accountDeleted", n.ADDED_TO_LIST_MODERATORS = "addedToListModerators", n.REMOVED_FROM_LIST_MODERATORS = "removedFromListModerators", n.ACCEPTING_WORD_REQUEST = "ParticipationRequestAccepted", n.CANCELLING_WORD_REQUEST = "ParticipationRequestRejected", n.MOVE_REQUEST_TO_STREAM = "ParticipantMovedToWebcast", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "ConferenceParticipantTokenIssued", n))(_ || {});
379
386
  class $e {
@@ -387,41 +394,41 @@ class $e {
387
394
  this.connectionManager = e, this.callManager = t, this.events = new D(ie), this.subscribe();
388
395
  }
389
396
  async waitChannels() {
390
- return this.wait(g.CHANNELS);
397
+ return this.wait(l.CHANNELS);
391
398
  }
392
399
  async waitSyncMediaState() {
393
- return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
400
+ return this.wait(l.ADMIN_FORCE_SYNC_MEDIA_STATE);
394
401
  }
395
402
  async sendDTMF(e) {
396
403
  return new Promise((t, s) => {
397
- let i;
404
+ let r;
398
405
  try {
399
- i = this.getEstablishedRTCSessionProtected();
400
- } catch (r) {
401
- s(r);
406
+ r = this.getEstablishedRTCSessionProtected();
407
+ } catch (i) {
408
+ s(i);
402
409
  }
403
- i && (this.callManager.once("newDTMF", ({ originator: r }) => {
404
- r === $.LOCAL && t();
405
- }), i.sendDTMF(e, {
410
+ r && (this.callManager.once("newDTMF", ({ originator: i }) => {
411
+ i === $.LOCAL && t();
412
+ }), r.sendDTMF(e, {
406
413
  duration: 120,
407
414
  interToneGap: 600
408
415
  }));
409
416
  });
410
417
  }
411
418
  async sendChannels({ inputChannels: e, outputChannels: t }) {
412
- const s = this.getEstablishedRTCSessionProtected(), i = `${l.INPUT_CHANNELS}: ${e}`, r = `${l.OUTPUT_CHANNELS}: ${t}`, a = [
413
- i,
414
- r
419
+ const s = this.getEstablishedRTCSessionProtected(), r = `${h.INPUT_CHANNELS}: ${e}`, i = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
420
+ r,
421
+ i
415
422
  ];
416
423
  return s.sendInfo(M.CHANNELS, void 0, { extraHeaders: a });
417
424
  }
418
425
  async sendMediaState({ cam: e, mic: t }, s = {}) {
419
- const i = this.getEstablishedRTCSessionProtected(), r = `${l.MEDIA_STATE}: currentstate`, a = `${l.MAIN_CAM_STATE}: ${Number(e)}`, o = `${l.MIC_STATE}: ${Number(t)}`, c = [
420
- r,
426
+ const r = this.getEstablishedRTCSessionProtected(), i = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
427
+ i,
421
428
  a,
422
429
  o
423
430
  ];
424
- return i.sendInfo(M.MEDIA_STATE, void 0, {
431
+ return r.sendInfo(M.MEDIA_STATE, void 0, {
425
432
  noTerminateWhenError: !0,
426
433
  ...s,
427
434
  extraHeaders: c
@@ -430,14 +437,14 @@ class $e {
430
437
  async sendStats({
431
438
  availableIncomingBitrate: e
432
439
  }) {
433
- const t = this.getEstablishedRTCSessionProtected(), i = [`${l.AVAILABLE_INCOMING_BITRATE}: ${e}`];
440
+ const t = this.getEstablishedRTCSessionProtected(), r = [`${h.AVAILABLE_INCOMING_BITRATE}: ${e}`];
434
441
  return t.sendInfo(M.STATS, void 0, {
435
442
  noTerminateWhenError: !0,
436
- extraHeaders: i
443
+ extraHeaders: r
437
444
  });
438
445
  }
439
446
  async sendRefusalToTurnOn(e, t = {}) {
440
- const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${l.MEDIA_TYPE}: ${a}`];
447
+ const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${h.MEDIA_TYPE}: ${a}`];
441
448
  return s.sendInfo(M.REFUSAL, void 0, {
442
449
  noTerminateWhenError: !0,
443
450
  ...t,
@@ -452,38 +459,38 @@ class $e {
452
459
  }
453
460
  async sendMustStopPresentationP2P() {
454
461
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
455
- extraHeaders: [l.MUST_STOP_PRESENTATION_P2P]
462
+ extraHeaders: [h.MUST_STOP_PRESENTATION_P2P]
456
463
  });
457
464
  }
458
465
  async sendStoppedPresentationP2P() {
459
466
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
460
- extraHeaders: [l.STOP_PRESENTATION_P2P]
467
+ extraHeaders: [h.STOP_PRESENTATION_P2P]
461
468
  });
462
469
  }
463
470
  async sendStoppedPresentation() {
464
471
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
465
- extraHeaders: [l.STOP_PRESENTATION]
472
+ extraHeaders: [h.STOP_PRESENTATION]
466
473
  });
467
474
  }
468
475
  async askPermissionToStartPresentationP2P() {
469
476
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
470
- extraHeaders: [l.START_PRESENTATION_P2P]
477
+ extraHeaders: [h.START_PRESENTATION_P2P]
471
478
  });
472
479
  }
473
480
  async askPermissionToStartPresentation() {
474
481
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
475
- extraHeaders: [l.START_PRESENTATION]
482
+ extraHeaders: [h.START_PRESENTATION]
476
483
  });
477
484
  }
478
485
  async askPermissionToEnableCam(e = {}) {
479
- const t = this.getEstablishedRTCSessionProtected(), s = [l.ENABLE_MAIN_CAM];
486
+ const t = this.getEstablishedRTCSessionProtected(), s = [h.ENABLE_MAIN_CAM];
480
487
  return t.sendInfo(M.MAIN_CAM, void 0, {
481
488
  noTerminateWhenError: !0,
482
489
  ...e,
483
490
  extraHeaders: s
484
- }).catch((i) => {
485
- if (ke(i))
486
- throw i;
491
+ }).catch((r) => {
492
+ if (ke(r))
493
+ throw r;
487
494
  });
488
495
  }
489
496
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
@@ -521,13 +528,13 @@ class $e {
521
528
  };
522
529
  maybeHandleNotify = (e) => {
523
530
  try {
524
- const t = e.getHeader(l.NOTIFY);
531
+ const t = e.getHeader(h.NOTIFY);
525
532
  if (t) {
526
533
  const s = JSON.parse(t);
527
534
  this.handleNotify(s);
528
535
  }
529
536
  } catch (t) {
530
- R("error parse notify", t);
537
+ A("error parse notify", t);
531
538
  }
532
539
  };
533
540
  handleNotify = (e) => {
@@ -586,52 +593,56 @@ class $e {
586
593
  break;
587
594
  }
588
595
  default:
589
- R("unknown cmd", e);
596
+ A("unknown cmd", e);
590
597
  }
591
598
  };
592
599
  handleNewInfo = (e) => {
593
600
  const { originator: t } = e;
594
601
  if (t !== $.REMOTE)
595
602
  return;
596
- const { request: s } = e, i = s.getHeader(l.CONTENT_TYPE);
597
- if (i !== void 0)
598
- switch (i) {
599
- case O.ENTER_ROOM: {
603
+ const { request: s } = e, r = s.getHeader(h.CONTENT_TYPE);
604
+ if (r !== void 0)
605
+ switch (r) {
606
+ case f.ENTER_ROOM: {
600
607
  this.triggerEnterRoom(s), this.maybeTriggerChannels(s);
601
608
  break;
602
609
  }
603
- case O.NOTIFY: {
610
+ case f.NOTIFY: {
604
611
  this.maybeHandleNotify(s);
605
612
  break;
606
613
  }
607
- case O.SHARE_STATE: {
614
+ case f.SHARE_STATE: {
608
615
  this.triggerShareState(s);
609
616
  break;
610
617
  }
611
- case O.MAIN_CAM: {
618
+ case f.MAIN_CAM: {
612
619
  this.triggerMainCamControl(s);
613
620
  break;
614
621
  }
615
- case O.MIC: {
622
+ case f.MIC: {
616
623
  this.triggerMicControl(s);
617
624
  break;
618
625
  }
619
- case O.USE_LICENSE: {
626
+ case f.USE_LICENSE: {
620
627
  this.triggerUseLicense(s);
621
628
  break;
622
629
  }
623
- case O.PARTICIPANT_STATE: {
630
+ case f.PARTICIPANT_STATE: {
624
631
  this.maybeTriggerParticipantMoveRequest(s);
625
632
  break;
626
633
  }
634
+ case f.RESTART: {
635
+ this.triggerRestart(s);
636
+ break;
637
+ }
627
638
  }
628
639
  };
629
640
  triggerChannelsNotify = (e) => {
630
- const t = e.input, s = e.output, i = {
641
+ const t = e.input, s = e.output, r = {
631
642
  inputChannels: t,
632
643
  outputChannels: s
633
644
  };
634
- this.events.trigger(g.CHANNELS_NOTIFY, i);
645
+ this.events.trigger(l.CHANNELS_NOTIFY, r);
635
646
  };
636
647
  triggerWebcastStartedNotify = ({
637
648
  body: { conference: e, type: t }
@@ -640,7 +651,7 @@ class $e {
640
651
  conference: e,
641
652
  type: t
642
653
  };
643
- this.events.trigger(g.WEBCAST_STARTED, s);
654
+ this.events.trigger(l.WEBCAST_STARTED, s);
644
655
  };
645
656
  triggerWebcastStoppedNotify = ({
646
657
  body: { conference: e, type: t }
@@ -649,7 +660,7 @@ class $e {
649
660
  conference: e,
650
661
  type: t
651
662
  };
652
- this.events.trigger(g.WEBCAST_STOPPED, s);
663
+ this.events.trigger(l.WEBCAST_STOPPED, s);
653
664
  };
654
665
  triggerAddedToListModeratorsNotify = ({
655
666
  conference: e
@@ -658,7 +669,7 @@ class $e {
658
669
  conference: e
659
670
  };
660
671
  this.events.trigger(
661
- g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
672
+ l.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
662
673
  t
663
674
  );
664
675
  };
@@ -669,7 +680,7 @@ class $e {
669
680
  conference: e
670
681
  };
671
682
  this.events.trigger(
672
- g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
683
+ l.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
673
684
  t
674
685
  );
675
686
  };
@@ -679,7 +690,7 @@ class $e {
679
690
  const t = {
680
691
  conference: e
681
692
  };
682
- this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
693
+ this.events.trigger(l.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
683
694
  };
684
695
  triggerParticipationCancellingWordRequest = ({
685
696
  body: { conference: e }
@@ -687,7 +698,7 @@ class $e {
687
698
  const t = {
688
699
  conference: e
689
700
  };
690
- this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
701
+ this.events.trigger(l.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
691
702
  };
692
703
  triggerParticipantMoveRequestToStream = ({
693
704
  body: { conference: e }
@@ -695,87 +706,97 @@ class $e {
695
706
  const t = {
696
707
  conference: e
697
708
  };
698
- this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
709
+ this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
699
710
  };
700
711
  triggerAccountChangedNotify = () => {
701
- this.events.trigger(g.ACCOUNT_CHANGED, void 0);
712
+ this.events.trigger(l.ACCOUNT_CHANGED, void 0);
702
713
  };
703
714
  triggerAccountDeletedNotify = () => {
704
- this.events.trigger(g.ACCOUNT_DELETED, void 0);
715
+ this.events.trigger(l.ACCOUNT_DELETED, void 0);
705
716
  };
706
717
  triggerConferenceParticipantTokenIssued = ({
707
718
  body: { conference: e, participant: t, jwt: s }
708
719
  }) => {
709
- const i = {
720
+ const r = {
710
721
  conference: e,
711
722
  participant: t,
712
723
  jwt: s
713
724
  };
714
725
  this.events.trigger(
715
- g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
716
- i
726
+ l.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
727
+ r
717
728
  );
718
729
  };
719
730
  maybeTriggerChannels = (e) => {
720
- const t = e.getHeader(l.INPUT_CHANNELS), s = e.getHeader(l.OUTPUT_CHANNELS);
731
+ const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
721
732
  if (t && s) {
722
- const i = {
733
+ const r = {
723
734
  inputChannels: t,
724
735
  outputChannels: s
725
736
  };
726
- this.events.trigger(g.CHANNELS, i);
737
+ this.events.trigger(l.CHANNELS, r);
727
738
  }
728
739
  };
729
740
  triggerEnterRoom = (e) => {
730
- const t = e.getHeader(l.CONTENT_ENTER_ROOM), s = e.getHeader(l.PARTICIPANT_NAME);
731
- this.events.trigger(g.ENTER_ROOM, { room: t, participantName: s });
741
+ const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
742
+ this.events.trigger(l.ENTER_ROOM, { room: t, participantName: s });
732
743
  };
733
744
  triggerShareState = (e) => {
734
- const t = e.getHeader(l.CONTENT_SHARE_STATE);
745
+ const t = e.getHeader(h.CONTENT_SHARE_STATE);
735
746
  if (t !== void 0)
736
747
  switch (t) {
737
748
  case k.AVAILABLE_SECOND_REMOTE_STREAM: {
738
- this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
749
+ this.events.trigger(l.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
739
750
  break;
740
751
  }
741
752
  case k.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
742
- this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
753
+ this.events.trigger(l.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
743
754
  break;
744
755
  }
745
756
  case k.MUST_STOP_PRESENTATION: {
746
- this.events.trigger(g.MUST_STOP_PRESENTATION, void 0);
757
+ this.events.trigger(l.MUST_STOP_PRESENTATION, void 0);
747
758
  break;
748
759
  }
749
760
  }
750
761
  };
751
762
  maybeTriggerParticipantMoveRequest = (e) => {
752
- const t = e.getHeader(l.CONTENT_PARTICIPANT_STATE);
753
- t === F.SPECTATOR && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === F.PARTICIPANT && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0), t === F.SPECTATOR_OVER_SFU && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU, void 0);
763
+ const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
764
+ t === F.SPECTATOR && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === F.PARTICIPANT && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0), t === F.SPECTATOR_OVER_SFU && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU, void 0);
754
765
  };
755
766
  triggerMainCamControl = (e) => {
756
- const t = e.getHeader(l.MAIN_CAM), s = e.getHeader(l.MEDIA_SYNC), i = s === H.ADMIN_SYNC_FORCED;
767
+ const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), r = s === H.ADMIN_SYNC_FORCED;
757
768
  if (t === P.ADMIN_START_MAIN_CAM) {
758
- this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: i });
769
+ this.events.trigger(l.ADMIN_START_MAIN_CAM, { isSyncForced: r });
759
770
  return;
760
771
  }
761
772
  if (t === P.ADMIN_STOP_MAIN_CAM) {
762
- this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
773
+ this.events.trigger(l.ADMIN_STOP_MAIN_CAM, { isSyncForced: r });
763
774
  return;
764
775
  }
765
- (t === P.RESUME_MAIN_CAM || t === P.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(g.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
766
- const r = e.getHeader(l.MAIN_CAM_RESOLUTION);
767
- this.events.trigger(g.MAIN_CAM_CONTROL, {
776
+ (t === P.RESUME_MAIN_CAM || t === P.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(l.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: r });
777
+ const i = e.getHeader(h.MAIN_CAM_RESOLUTION);
778
+ this.events.trigger(l.MAIN_CAM_CONTROL, {
768
779
  mainCam: t,
769
- resolutionMainCam: r
780
+ resolutionMainCam: i
770
781
  });
771
782
  };
772
783
  triggerMicControl = (e) => {
773
- const t = e.getHeader(l.MIC), i = e.getHeader(l.MEDIA_SYNC) === H.ADMIN_SYNC_FORCED;
774
- t === W.ADMIN_START_MIC ? this.events.trigger(g.ADMIN_START_MIC, { isSyncForced: i }) : t === W.ADMIN_STOP_MIC && this.events.trigger(g.ADMIN_STOP_MIC, { isSyncForced: i });
784
+ const t = e.getHeader(h.MIC), r = e.getHeader(h.MEDIA_SYNC) === H.ADMIN_SYNC_FORCED;
785
+ t === W.ADMIN_START_MIC ? this.events.trigger(l.ADMIN_START_MIC, { isSyncForced: r }) : t === W.ADMIN_STOP_MIC && this.events.trigger(l.ADMIN_STOP_MIC, { isSyncForced: r });
775
786
  };
776
787
  triggerUseLicense = (e) => {
777
- const t = e.getHeader(l.CONTENT_USE_LICENSE);
778
- this.events.trigger(g.USE_LICENSE, t);
788
+ const t = e.getHeader(h.CONTENT_USE_LICENSE);
789
+ this.events.trigger(l.USE_LICENSE, t);
790
+ };
791
+ triggerRestart = (e) => {
792
+ const t = e.getHeader(
793
+ h.TRACKS_DIRECTION
794
+ ), s = Number(
795
+ e.getHeader(h.AUDIO_TRACK_COUNT)
796
+ ), r = Number(
797
+ e.getHeader(h.VIDEO_TRACK_COUNT)
798
+ ), i = { tracksDirection: t, audioTrackCount: s, videoTrackCount: r };
799
+ this.events.trigger(l.RESTART, i);
779
800
  };
780
801
  }
781
802
  const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We = (n, e) => {
@@ -783,16 +804,16 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
783
804
  for (let t = n.encodings.length; t < e; t += 1)
784
805
  n.encodings.push({});
785
806
  return n;
786
- }, re = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, He = re(), xe = (n, e) => {
807
+ }, ae = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, He = ae(), xe = (n, e) => {
787
808
  if (He(n, e))
788
809
  return n;
789
810
  }, qe = (n, e) => {
790
811
  const t = n.maxBitrate, s = xe(e, t);
791
812
  return s !== void 0 && (n.maxBitrate = s), n;
792
- }, ae = 1, Ge = re(
793
- ae
813
+ }, oe = 1, Ge = ae(
814
+ oe
794
815
  ), Qe = (n, e) => {
795
- const t = n === void 0 ? void 0 : Math.max(n, ae);
816
+ const t = n === void 0 ? void 0 : Math.max(n, oe);
796
817
  if (t !== void 0 && Ge(
797
818
  t,
798
819
  e
@@ -806,11 +827,11 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
806
827
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
807
828
  }, ze = (n, e) => {
808
829
  const t = e.encodings?.length ?? 0;
809
- return We(n, t), n.encodings.forEach((s, i) => {
810
- const r = (e?.encodings ?? [])[i], a = r?.maxBitrate, o = r?.scaleResolutionDownBy;
830
+ return We(n, t), n.encodings.forEach((s, r) => {
831
+ const i = (e?.encodings ?? [])[r], a = i?.maxBitrate, o = i?.scaleResolutionDownBy;
811
832
  qe(s, a), Ye(s, o);
812
833
  }), n;
813
- }, Je = (n, e) => {
834
+ }, Xe = (n, e) => {
814
835
  if (n.codecs?.length !== e.codecs?.length)
815
836
  return !0;
816
837
  for (let t = 0; t < (n.codecs?.length ?? 0); t++)
@@ -827,15 +848,15 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
827
848
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
828
849
  return !0;
829
850
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
830
- }, Xe = async (n, e) => {
851
+ }, Je = async (n, e) => {
831
852
  const t = n.getParameters(), s = JSON.parse(
832
853
  JSON.stringify(t)
833
854
  );
834
855
  ze(t, e), Ve(t, e);
835
- const i = Je(s, t);
836
- return i && await n.setParameters(t), { parameters: t, isChanged: i };
837
- }, oe = async (n, e, t) => {
838
- const { isChanged: s, parameters: i } = await Xe(n, {
856
+ const r = Xe(s, t);
857
+ return r && await n.setParameters(t), { parameters: t, isChanged: r };
858
+ }, ce = async (n, e, t) => {
859
+ const { isChanged: s, parameters: r } = await Je(n, {
839
860
  encodings: [
840
861
  {
841
862
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -843,20 +864,20 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
843
864
  }
844
865
  ]
845
866
  });
846
- return s && t && t(i), { isChanged: s, parameters: i };
847
- }, je = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ke = async (n, e, t) => {
848
- const s = je(n, e);
867
+ return s && t && t(r), { isChanged: s, parameters: r };
868
+ }, Ke = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), je = async (n, e, t) => {
869
+ const s = Ke(n, e);
849
870
  if (s)
850
- return oe(s, { maxBitrate: t });
871
+ return ce(s, { maxBitrate: t });
851
872
  };
852
- var f = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(f || {});
853
- const ce = [
873
+ var O = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(O || {});
874
+ const de = [
854
875
  "presentation:start",
855
876
  "presentation:started",
856
877
  "presentation:end",
857
878
  "presentation:ended",
858
879
  "presentation:failed"
859
- ], Ze = 1, Sn = (n) => Re(n);
880
+ ], Ze = 1, Cn = (n) => Ie(n);
860
881
  class et {
861
882
  events;
862
883
  promisePendingStartPresentation;
@@ -869,7 +890,7 @@ class et {
869
890
  callManager: e,
870
891
  maxBitrate: t
871
892
  }) {
872
- this.callManager = e, this.maxBitrate = t, this.events = new D(ce), this.subscribe();
893
+ this.callManager = e, this.maxBitrate = t, this.events = new D(de), this.subscribe();
873
894
  }
874
895
  get isPendingPresentation() {
875
896
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
@@ -877,8 +898,8 @@ class et {
877
898
  // eslint-disable-next-line @typescript-eslint/max-params
878
899
  async startPresentation(e, t, {
879
900
  isNeedReinvite: s,
880
- contentHint: i,
881
- sendEncodings: r,
901
+ contentHint: r,
902
+ sendEncodings: i,
882
903
  onAddedTransceiver: a
883
904
  } = {}, o) {
884
905
  const c = this.getRtcSessionProtected();
@@ -889,8 +910,8 @@ class et {
889
910
  stream: t,
890
911
  presentationOptions: {
891
912
  isNeedReinvite: s,
892
- contentHint: i,
893
- sendEncodings: r,
913
+ contentHint: r,
914
+ sendEncodings: i,
894
915
  onAddedTransceiver: a
895
916
  },
896
917
  options: o
@@ -902,17 +923,17 @@ class et {
902
923
  let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
903
924
  this.promisePendingStartPresentation && await this.promisePendingStartPresentation.catch(() => {
904
925
  });
905
- const i = this.callManager.getEstablishedRTCSession();
906
- return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
907
- throw this.events.trigger(f.FAILED_PRESENTATION, r), r;
908
- }) : t && this.events.trigger(f.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
926
+ const r = this.callManager.getEstablishedRTCSession();
927
+ return r && t ? s = e().then(async () => r.stopPresentation(t)).catch((i) => {
928
+ throw this.events.trigger(O.FAILED_PRESENTATION, i), i;
929
+ }) : t && this.events.trigger(O.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
909
930
  this.resetPresentation();
910
931
  });
911
932
  }
912
933
  async updatePresentation(e, t, {
913
934
  contentHint: s,
914
- sendEncodings: i,
915
- onAddedTransceiver: r
935
+ sendEncodings: r,
936
+ onAddedTransceiver: i
916
937
  } = {}) {
917
938
  const a = this.getRtcSessionProtected();
918
939
  if (!this.streamPresentationCurrent)
@@ -920,8 +941,8 @@ class et {
920
941
  return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
921
942
  contentHint: s,
922
943
  isNeedReinvite: !1,
923
- sendEncodings: i,
924
- onAddedTransceiver: r
944
+ sendEncodings: r,
945
+ onAddedTransceiver: i
925
946
  }).then(async (o) => (await this.setMaxBitrate(), o));
926
947
  }
927
948
  cancelSendPresentationWithRepeatedCalls() {
@@ -948,22 +969,22 @@ class et {
948
969
  }
949
970
  subscribe() {
950
971
  this.callManager.on("presentation:start", (e) => {
951
- this.events.trigger(f.START_PRESENTATION, e);
972
+ this.events.trigger(O.START_PRESENTATION, e);
952
973
  }), this.callManager.on("presentation:started", (e) => {
953
- this.events.trigger(f.STARTED_PRESENTATION, e);
974
+ this.events.trigger(O.STARTED_PRESENTATION, e);
954
975
  }), this.callManager.on("presentation:end", (e) => {
955
- this.events.trigger(f.END_PRESENTATION, e);
976
+ this.events.trigger(O.END_PRESENTATION, e);
956
977
  }), this.callManager.on("presentation:ended", (e) => {
957
- this.events.trigger(f.ENDED_PRESENTATION, e);
978
+ this.events.trigger(O.ENDED_PRESENTATION, e);
958
979
  }), this.callManager.on("presentation:failed", (e) => {
959
- this.events.trigger(f.FAILED_PRESENTATION, e);
980
+ this.events.trigger(O.FAILED_PRESENTATION, e);
960
981
  }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
961
982
  }
962
983
  async sendPresentationWithDuplicatedCalls(e, {
963
984
  rtcSession: t,
964
985
  stream: s,
965
- presentationOptions: i,
966
- options: r = {
986
+ presentationOptions: r,
987
+ options: i = {
967
988
  callLimit: Ze
968
989
  }
969
990
  }) {
@@ -971,33 +992,33 @@ class et {
971
992
  e,
972
993
  t,
973
994
  s,
974
- i
995
+ r
975
996
  ), o = () => !!this.streamPresentationCurrent;
976
- return this.cancelableSendPresentationWithRepeatedCalls = K({
997
+ return this.cancelableSendPresentationWithRepeatedCalls = j({
977
998
  targetFunction: a,
978
999
  isComplete: o,
979
1000
  isRejectAsValid: !0,
980
- ...r
1001
+ ...i
981
1002
  }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
982
1003
  }
983
1004
  // eslint-disable-next-line @typescript-eslint/max-params
984
1005
  async sendPresentation(e, t, s, {
985
- isNeedReinvite: i = !0,
986
- contentHint: r = "detail",
1006
+ isNeedReinvite: r = !0,
1007
+ contentHint: i = "detail",
987
1008
  degradationPreference: a,
988
1009
  sendEncodings: o,
989
1010
  onAddedTransceiver: c
990
1011
  }) {
991
- const d = B(s, { contentHint: r });
1012
+ const d = B(s, { contentHint: i });
992
1013
  if (d === void 0)
993
1014
  throw new Error("No streamPresentationTarget");
994
1015
  this.streamPresentationCurrent = d;
995
- const u = e().then(async () => t.startPresentation(d, i, {
1016
+ const u = e().then(async () => t.startPresentation(d, r, {
996
1017
  degradationPreference: a,
997
1018
  sendEncodings: o,
998
1019
  onAddedTransceiver: c
999
1020
  })).then(this.setMaxBitrate).then(() => s).catch((T) => {
1000
- throw this.removeStreamPresentationCurrent(), this.events.trigger(f.FAILED_PRESENTATION, T), T;
1021
+ throw this.removeStreamPresentationCurrent(), this.events.trigger(O.FAILED_PRESENTATION, T), T;
1001
1022
  });
1002
1023
  return this.promisePendingStartPresentation = u, u.finally(() => {
1003
1024
  this.promisePendingStartPresentation = void 0;
@@ -1007,8 +1028,8 @@ class et {
1007
1028
  const { connection: e } = this.callManager, { streamPresentationCurrent: t } = this, { maxBitrate: s } = this;
1008
1029
  if (!e || !t || s === void 0)
1009
1030
  return;
1010
- const i = e.getSenders();
1011
- await Ke(i, t, s);
1031
+ const r = e.getSenders();
1032
+ await je(r, t, s);
1012
1033
  };
1013
1034
  getRtcSessionProtected = () => {
1014
1035
  const e = this.callManager.getEstablishedRTCSession();
@@ -1103,7 +1124,7 @@ class tt {
1103
1124
  }
1104
1125
  }
1105
1126
  var N = /* @__PURE__ */ ((n) => (n.CONNECTING = "connecting", n.CONNECTED = "connected", n.DISCONNECTED = "disconnected", n.NEW_RTC_SESSION = "newRTCSession", n.REGISTERED = "registered", n.UNREGISTERED = "unregistered", n.REGISTRATION_FAILED = "registrationFailed", n.NEW_MESSAGE = "newMessage", n.SIP_EVENT = "sipEvent", n))(N || {});
1106
- const de = [
1127
+ const he = [
1107
1128
  "connecting",
1108
1129
  "connected",
1109
1130
  "disconnected",
@@ -1113,7 +1134,7 @@ const de = [
1113
1134
  "registrationFailed",
1114
1135
  "newMessage",
1115
1136
  "sipEvent"
1116
- ], he = [...de], nt = 3;
1137
+ ], ge = [...he], nt = 3;
1117
1138
  class st {
1118
1139
  cancelableConnectWithRepeatedCalls;
1119
1140
  JsSIP;
@@ -1133,15 +1154,15 @@ class st {
1133
1154
  }
1134
1155
  connect = async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t));
1135
1156
  set = async ({ displayName: e }) => new Promise((t, s) => {
1136
- const i = this.getUa();
1137
- if (!i) {
1157
+ const r = this.getUa();
1158
+ if (!r) {
1138
1159
  s(new Error("this.ua is not initialized"));
1139
1160
  return;
1140
1161
  }
1141
- let r = !1;
1162
+ let i = !1;
1142
1163
  const a = this.getConnectionConfiguration();
1143
- e !== void 0 && e !== a.displayName && (r = i.set("display_name", ne(e)), this.updateConnectionConfiguration("displayName", e));
1144
- const o = r;
1164
+ e !== void 0 && e !== a.displayName && (i = r.set("display_name", se(e)), this.updateConnectionConfiguration("displayName", e));
1165
+ const o = i;
1145
1166
  o ? t(o) : s(new Error("nothing changed"));
1146
1167
  });
1147
1168
  disconnect = async () => {
@@ -1158,68 +1179,68 @@ class st {
1158
1179
  this.cancelConnectWithRepeatedCalls();
1159
1180
  }
1160
1181
  connectWithDuplicatedCalls = async (e, { callLimit: t = nt } = {}) => {
1161
- const s = async () => this.connectInner(e), i = (r) => {
1162
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !Be(r);
1182
+ const s = async () => this.connectInner(e), r = (i) => {
1183
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = i != null && !Be(i);
1163
1184
  return c || d;
1164
1185
  };
1165
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = K({
1186
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = j({
1166
1187
  targetFunction: s,
1167
- isComplete: i,
1188
+ isComplete: r,
1168
1189
  callLimit: t,
1169
1190
  isRejectAsValid: !0,
1170
1191
  isCheckBeforeCall: !1
1171
- }), this.cancelableConnectWithRepeatedCalls.then((r) => {
1172
- if (r instanceof this.JsSIP.UA)
1173
- return r;
1174
- throw r;
1192
+ }), this.cancelableConnectWithRepeatedCalls.then((i) => {
1193
+ if (i instanceof this.JsSIP.UA)
1194
+ return i;
1195
+ throw i;
1175
1196
  });
1176
1197
  };
1177
1198
  hasEqualConnectionConfiguration(e) {
1178
- const { configuration: t } = this.uaFactory.createConfiguration(e), i = this.getUa()?.configuration;
1179
- return i ? i.password === t.password && i.register === t.register && i.uri.toString() === t.uri && i.display_name === t.display_name && i.user_agent === t.user_agent && i.sockets === t.sockets && i.session_timers === t.session_timers && i.register_expires === t.register_expires && i.connection_recovery_min_interval === t.connection_recovery_min_interval && i.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1199
+ const { configuration: t } = this.uaFactory.createConfiguration(e), r = this.getUa()?.configuration;
1200
+ return r ? r.password === t.password && r.register === t.register && r.uri.toString() === t.uri && r.display_name === t.display_name && r.user_agent === t.user_agent && r.sockets === t.sockets && r.session_timers === t.session_timers && r.register_expires === t.register_expires && r.connection_recovery_min_interval === t.connection_recovery_min_interval && r.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1180
1201
  }
1181
1202
  connectInner = async (e) => this.initUa(e).then(async () => this.start());
1182
1203
  initUa = async ({
1183
1204
  user: e,
1184
1205
  password: t,
1185
1206
  sipServerUrl: s,
1186
- sipWebSocketServerURL: i,
1187
- remoteAddress: r,
1207
+ sipWebSocketServerURL: r,
1208
+ remoteAddress: i,
1188
1209
  sessionTimers: a,
1189
1210
  registerExpires: o,
1190
1211
  connectionRecoveryMinInterval: c,
1191
1212
  connectionRecoveryMaxInterval: d,
1192
1213
  userAgent: u,
1193
1214
  displayName: T = "",
1194
- register: h = !1,
1215
+ register: g = !1,
1195
1216
  extraHeaders: S = []
1196
1217
  }) => {
1197
1218
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1198
1219
  sipServerUrl: s,
1199
1220
  displayName: T,
1200
- register: h,
1221
+ register: g,
1201
1222
  user: e,
1202
1223
  password: t
1203
1224
  }), this.getUa() && await this.disconnect();
1204
- const { ua: I, helpers: A } = this.uaFactory.createUAWithConfiguration(
1225
+ const { ua: I, helpers: R } = this.uaFactory.createUAWithConfiguration(
1205
1226
  {
1206
1227
  user: e,
1207
1228
  password: t,
1208
1229
  sipServerUrl: s,
1209
- sipWebSocketServerURL: i,
1230
+ sipWebSocketServerURL: r,
1210
1231
  displayName: T,
1211
- register: h,
1232
+ register: g,
1212
1233
  sessionTimers: a,
1213
1234
  registerExpires: o,
1214
1235
  connectionRecoveryMinInterval: c,
1215
1236
  connectionRecoveryMaxInterval: d,
1216
1237
  userAgent: u,
1217
- remoteAddress: r,
1238
+ remoteAddress: i,
1218
1239
  extraHeaders: S
1219
1240
  },
1220
1241
  this.events
1221
1242
  );
1222
- return this.setUa(I), this.setSipServerUrl(A.getSipServerUrl), this.setSocket(A.socket), I;
1243
+ return this.setUa(I), this.setSipServerUrl(R.getSipServerUrl), this.setSocket(R.socket), I;
1223
1244
  };
1224
1245
  start = async () => new Promise((e, t) => {
1225
1246
  const s = this.getUa();
@@ -1227,40 +1248,40 @@ class st {
1227
1248
  t(new Error("this.ua is not initialized"));
1228
1249
  return;
1229
1250
  }
1230
- let i;
1231
- i = ((c, d) => {
1251
+ let r;
1252
+ r = ((c, d) => {
1232
1253
  if (this.getConnectionConfiguration().register === !0)
1233
1254
  return this.registrationManager.subscribeToStartEvents(c, d);
1234
- const T = N.CONNECTED, h = [N.DISCONNECTED];
1235
- return this.events.on(T, c), h.forEach((S) => {
1255
+ const T = N.CONNECTED, g = [N.DISCONNECTED];
1256
+ return this.events.on(T, c), g.forEach((S) => {
1236
1257
  this.events.on(S, d);
1237
1258
  }), () => {
1238
- this.events.off(T, c), h.forEach((S) => {
1259
+ this.events.off(T, c), g.forEach((S) => {
1239
1260
  this.events.off(S, d);
1240
1261
  });
1241
1262
  };
1242
1263
  })(() => {
1243
- i?.(), e(s);
1264
+ r?.(), e(s);
1244
1265
  }, (c) => {
1245
- i?.(), t(c);
1266
+ r?.(), t(c);
1246
1267
  }), s.start();
1247
1268
  });
1248
1269
  cancelConnectWithRepeatedCalls() {
1249
1270
  this.cancelableConnectWithRepeatedCalls?.cancel();
1250
1271
  }
1251
1272
  }
1252
- var ge = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(ge || {});
1253
- const it = Ie({
1273
+ var le = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(le || {});
1274
+ const rt = _e({
1254
1275
  types: {
1255
1276
  context: {},
1256
1277
  events: {}
1257
1278
  },
1258
1279
  actions: {
1259
1280
  logTransition: (n, e) => {
1260
- R(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1281
+ A(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1261
1282
  },
1262
1283
  logStateChange: (n, e) => {
1263
- R("ConnectionStateMachine state changed", e.state);
1284
+ A("ConnectionStateMachine state changed", e.state);
1264
1285
  }
1265
1286
  }
1266
1287
  }).createMachine({
@@ -1564,17 +1585,17 @@ const it = Ie({
1564
1585
  }
1565
1586
  }
1566
1587
  });
1567
- class rt {
1588
+ class it {
1568
1589
  actor;
1569
1590
  stateChangeListeners = /* @__PURE__ */ new Set();
1570
1591
  events;
1571
1592
  unsubscribeFromEvents;
1572
1593
  actorSubscription;
1573
1594
  constructor(e) {
1574
- this.events = e, this.actor = _e(it), this.actorSubscription = this.actor.subscribe((t) => {
1595
+ this.events = e, this.actor = Me(rt), this.actorSubscription = this.actor.subscribe((t) => {
1575
1596
  const s = t.value;
1576
- this.stateChangeListeners.forEach((i) => {
1577
- i(s);
1597
+ this.stateChangeListeners.forEach((r) => {
1598
+ r(s);
1578
1599
  });
1579
1600
  }), this.actor.start(), this.subscribeToEvents();
1580
1601
  }
@@ -1657,7 +1678,7 @@ class rt {
1657
1678
  return this.actor.getSnapshot().can({ type: e });
1658
1679
  }
1659
1680
  getValidEvents() {
1660
- return Object.values(ge).filter((e) => this.canTransition(e));
1681
+ return Object.values(le).filter((e) => this.canTransition(e));
1661
1682
  }
1662
1683
  hasState(e) {
1663
1684
  return this.actor.getSnapshot().matches(e);
@@ -1665,7 +1686,7 @@ class rt {
1665
1686
  sendEvent(e) {
1666
1687
  const t = this.actor.getSnapshot(), s = { type: e };
1667
1688
  if (!t.can(s)) {
1668
- R(
1689
+ A(
1669
1690
  `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
1670
1691
  );
1671
1692
  return;
@@ -1748,17 +1769,17 @@ class at {
1748
1769
  try {
1749
1770
  await this.unregister();
1750
1771
  } catch (e) {
1751
- R("tryRegister", e);
1772
+ A("tryRegister", e);
1752
1773
  }
1753
1774
  return this.register();
1754
1775
  }
1755
1776
  subscribeToStartEvents(e, t) {
1756
- const s = N.REGISTERED, i = [N.REGISTRATION_FAILED, N.DISCONNECTED];
1757
- return this.events.on(s, e), i.forEach((r) => {
1758
- this.events.on(r, t);
1777
+ const s = N.REGISTERED, r = [N.REGISTRATION_FAILED, N.DISCONNECTED];
1778
+ return this.events.on(s, e), r.forEach((i) => {
1779
+ this.events.on(i, t);
1759
1780
  }), () => {
1760
- this.events.off(s, e), i.forEach((r) => {
1761
- this.events.off(r, t);
1781
+ this.events.off(s, e), r.forEach((i) => {
1782
+ this.events.off(i, t);
1762
1783
  });
1763
1784
  };
1764
1785
  }
@@ -1773,14 +1794,14 @@ class ot {
1773
1794
  * Отправляет SIP OPTIONS запрос к указанному адресу
1774
1795
  */
1775
1796
  async sendOptions(e, t, s) {
1776
- const i = this.getUaProtected();
1777
- return new Promise((r, a) => {
1797
+ const r = this.getUaProtected();
1798
+ return new Promise((i, a) => {
1778
1799
  try {
1779
- i.sendOptions(e, t, {
1800
+ r.sendOptions(e, t, {
1780
1801
  extraHeaders: s,
1781
1802
  eventHandlers: {
1782
1803
  succeeded: () => {
1783
- r();
1804
+ i();
1784
1805
  },
1785
1806
  failed: a
1786
1807
  }
@@ -1794,8 +1815,8 @@ class ot {
1794
1815
  * Отправляет SIP OPTIONS запрос к собственному URI (ping)
1795
1816
  */
1796
1817
  async ping(e, t) {
1797
- const i = this.getUaProtected().configuration.uri;
1798
- return this.sendOptions(i, e, t);
1818
+ const r = this.getUaProtected().configuration.uri;
1819
+ return this.sendOptions(r, e, t);
1799
1820
  }
1800
1821
  /**
1801
1822
  * Проверяет доступность телефонии, создавая временное соединение
@@ -1804,27 +1825,27 @@ class ot {
1804
1825
  userAgent: e,
1805
1826
  displayName: t,
1806
1827
  sipServerUrl: s,
1807
- sipWebSocketServerURL: i,
1808
- remoteAddress: r,
1828
+ sipWebSocketServerURL: r,
1829
+ remoteAddress: i,
1809
1830
  extraHeaders: a
1810
1831
  }) {
1811
1832
  return new Promise((o, c) => {
1812
1833
  const { configuration: d } = this.uaFactory.createConfiguration({
1813
- sipWebSocketServerURL: i,
1834
+ sipWebSocketServerURL: r,
1814
1835
  displayName: t,
1815
1836
  userAgent: e,
1816
1837
  sipServerUrl: s
1817
- }), u = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), T = () => {
1838
+ }), u = this.uaFactory.createUA({ ...d, remoteAddress: i, extraHeaders: a }), T = () => {
1818
1839
  const S = new Error("Telephony is not available");
1819
1840
  c(S);
1820
1841
  };
1821
1842
  u.once(N.DISCONNECTED, T);
1822
- const h = () => {
1843
+ const g = () => {
1823
1844
  u.removeAllListeners(), u.once(N.DISCONNECTED, () => {
1824
1845
  o();
1825
1846
  }), u.stop();
1826
1847
  };
1827
- u.once(N.CONNECTED, h), u.start();
1848
+ u.once(N.CONNECTED, g), u.start();
1828
1849
  });
1829
1850
  }
1830
1851
  }
@@ -1844,12 +1865,12 @@ class v {
1844
1865
  register: e,
1845
1866
  password: t,
1846
1867
  user: s,
1847
- sipServerUrl: i,
1848
- sipWebSocketServerURL: r
1868
+ sipServerUrl: r,
1869
+ sipWebSocketServerURL: i
1849
1870
  }) {
1850
- if (!i)
1851
- throw new Error("sipServerUrl is required");
1852
1871
  if (!r)
1872
+ throw new Error("sipServerUrl is required");
1873
+ if (!i)
1853
1874
  throw new Error("sipWebSocketServerURL is required");
1854
1875
  if (e && (t === void 0 || t === ""))
1855
1876
  throw new Error("password is required for authorized connection");
@@ -1867,8 +1888,8 @@ class v {
1867
1888
  user: e,
1868
1889
  password: t,
1869
1890
  sipWebSocketServerURL: s,
1870
- displayName: i = "",
1871
- sipServerUrl: r,
1891
+ displayName: r = "",
1892
+ sipServerUrl: i,
1872
1893
  register: a = !1,
1873
1894
  sessionTimers: o = !1,
1874
1895
  registerExpires: c = 300,
@@ -1881,16 +1902,16 @@ class v {
1881
1902
  register: a,
1882
1903
  password: t,
1883
1904
  user: e,
1884
- sipServerUrl: r,
1905
+ sipServerUrl: i,
1885
1906
  sipWebSocketServerURL: s
1886
1907
  });
1887
- const h = v.resolveAuthorizationUser(a, e), S = Pe(r), m = S(h), I = new this.JsSIP.WebSocketInterface(s);
1908
+ const g = v.resolveAuthorizationUser(a, e), S = Pe(i), m = S(g), I = new this.JsSIP.WebSocketInterface(s);
1888
1909
  return {
1889
1910
  configuration: {
1890
1911
  password: t,
1891
1912
  register: a,
1892
1913
  uri: m,
1893
- display_name: ne(i),
1914
+ display_name: se(r),
1894
1915
  user_agent: T,
1895
1916
  sdpSemantics: "unified-plan",
1896
1917
  sockets: [I],
@@ -1906,22 +1927,22 @@ class v {
1906
1927
  };
1907
1928
  }
1908
1929
  createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
1909
- const i = new this.JsSIP.UA(s), r = v.buildExtraHeaders(e, t);
1910
- return r.length > 0 && i.registrator().setExtraHeaders(r), i;
1930
+ const r = new this.JsSIP.UA(s), i = v.buildExtraHeaders(e, t);
1931
+ return i.length > 0 && r.registrator().setExtraHeaders(i), r;
1911
1932
  }
1912
1933
  /**
1913
1934
  * Создает UA с полным жизненным циклом - конфигурация + создание + настройка событий
1914
1935
  */
1915
1936
  createUAWithConfiguration(e, t) {
1916
- const { configuration: s, helpers: i } = this.createConfiguration(e), r = this.createUA({
1937
+ const { configuration: s, helpers: r } = this.createConfiguration(e), i = this.createUA({
1917
1938
  ...s,
1918
1939
  remoteAddress: e.remoteAddress,
1919
1940
  extraHeaders: e.extraHeaders
1920
1941
  });
1921
1942
  return t.eachTriggers((a, o) => {
1922
- const c = de.find((d) => d === o);
1923
- c && r.on(c, a);
1924
- }), { ua: r, helpers: i };
1943
+ const c = he.find((d) => d === o);
1944
+ c && i.on(c, a);
1945
+ }), { ua: i, helpers: r };
1925
1946
  }
1926
1947
  }
1927
1948
  class dt {
@@ -1936,10 +1957,10 @@ class dt {
1936
1957
  configurationManager;
1937
1958
  JsSIP;
1938
1959
  constructor({ JsSIP: e }) {
1939
- this.JsSIP = e, this.events = new D(he), this.uaFactory = new v(e), this.registrationManager = new at({
1960
+ this.JsSIP = e, this.events = new D(ge), this.uaFactory = new v(e), this.registrationManager = new at({
1940
1961
  events: this.events,
1941
1962
  getUaProtected: this.getUaProtected
1942
- }), this.stateMachine = new rt(this.events), this.configurationManager = new tt({
1963
+ }), this.stateMachine = new it(this.events), this.configurationManager = new tt({
1943
1964
  getUa: this.getUa
1944
1965
  }), this.sipOperations = new ot({
1945
1966
  uaFactory: this.uaFactory,
@@ -2035,19 +2056,37 @@ class dt {
2035
2056
  };
2036
2057
  getUa = () => this.ua;
2037
2058
  }
2038
- var U = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(U || {}), x = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(x || {});
2039
- const le = [
2059
+ class ht {
2060
+ connectionManager;
2061
+ stackPromises = Z({
2062
+ noRunIsNotActual: !0
2063
+ });
2064
+ constructor({ connectionManager: e }) {
2065
+ this.connectionManager = e;
2066
+ }
2067
+ connect = async (...e) => this.stackPromises.run(async () => this.connectionManager.connect(...e));
2068
+ disconnect = async () => this.stackPromises.run(async () => this.connectionManager.disconnect());
2069
+ register = async () => this.stackPromises.run(async () => this.connectionManager.register());
2070
+ unregister = async () => this.stackPromises.run(async () => this.connectionManager.unregister());
2071
+ tryRegister = async () => this.stackPromises.run(async () => this.connectionManager.tryRegister());
2072
+ checkTelephony = async (...e) => this.stackPromises.run(async () => this.connectionManager.checkTelephony(...e));
2073
+ sendOptions = async (...e) => this.stackPromises.run(async () => this.connectionManager.sendOptions(...e));
2074
+ ping = async (...e) => this.stackPromises.run(async () => this.connectionManager.ping(...e));
2075
+ set = async (...e) => this.stackPromises.run(async () => this.connectionManager.set(...e));
2076
+ }
2077
+ var w = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(w || {}), x = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(x || {});
2078
+ const ue = [
2040
2079
  "incomingCall",
2041
2080
  "declinedIncomingCall",
2042
2081
  "terminatedIncomingCall",
2043
2082
  "failedIncomingCall"
2044
- ], ht = 486, gt = 487;
2045
- class lt {
2083
+ ], gt = 486, lt = 487;
2084
+ class ut {
2046
2085
  events;
2047
2086
  incomingRTCSession;
2048
2087
  connectionManager;
2049
2088
  constructor(e) {
2050
- this.connectionManager = e, this.events = new D(le), this.start();
2089
+ this.connectionManager = e, this.events = new D(ue), this.start();
2051
2090
  }
2052
2091
  get remoteCallerData() {
2053
2092
  return {
@@ -2077,19 +2116,19 @@ class lt {
2077
2116
  return this.removeIncomingSession(), e;
2078
2117
  };
2079
2118
  async declineToIncomingCall({
2080
- statusCode: e = gt
2119
+ statusCode: e = lt
2081
2120
  } = {}) {
2082
2121
  return new Promise((t, s) => {
2083
2122
  try {
2084
- const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
2085
- this.removeIncomingSession(), this.events.trigger(U.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2086
- } catch (i) {
2087
- s(i);
2123
+ const r = this.getIncomingRTCSession(), i = this.remoteCallerData;
2124
+ this.removeIncomingSession(), this.events.trigger(w.DECLINED_INCOMING_CALL, i), r.terminate({ status_code: e }), t();
2125
+ } catch (r) {
2126
+ s(r);
2088
2127
  }
2089
2128
  });
2090
2129
  }
2091
2130
  async busyIncomingCall() {
2092
- return this.declineToIncomingCall({ statusCode: ht });
2131
+ return this.declineToIncomingCall({ statusCode: gt });
2093
2132
  }
2094
2133
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2095
2134
  on(e, t) {
@@ -2126,19 +2165,19 @@ class lt {
2126
2165
  this.incomingRTCSession = e;
2127
2166
  const t = this.remoteCallerData;
2128
2167
  e.on("failed", (s) => {
2129
- this.removeIncomingSession(), s.originator === x.LOCAL ? this.events.trigger(U.TERMINATED_INCOMING_CALL, t) : this.events.trigger(U.FAILED_INCOMING_CALL, t);
2130
- }), this.events.trigger(U.INCOMING_CALL, t);
2168
+ this.removeIncomingSession(), s.originator === x.LOCAL ? this.events.trigger(w.TERMINATED_INCOMING_CALL, t) : this.events.trigger(w.FAILED_INCOMING_CALL, t);
2169
+ }), this.events.trigger(w.INCOMING_CALL, t);
2131
2170
  }
2132
2171
  removeIncomingSession() {
2133
2172
  delete this.incomingRTCSession;
2134
2173
  }
2135
2174
  }
2136
- const w = 1e3;
2137
- var E = /* @__PURE__ */ ((n) => (n.INBOUND_RTP = "inbound-rtp", n.REMOTE_OUTBOUND_RTP = "remote-outbound-rtp", n.MEDIA_SOURCE = "media-source", n.OUTBOUND_RTP = "outbound-rtp", n.REMOTE_INBOUND_RTP = "remote-inbound-rtp", n.CODEC = "codec", n.CANDIDATE_PAIR = "candidate-pair", n.CERTIFICATE = "certificate", n.TRANSPORT = "transport", n.LOCAL_CANDIDATE = "local-candidate", n.REMOTE_CANDIDATE = "remote-candidate", n))(E || {});
2138
- const ue = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
2175
+ const U = 1e3;
2176
+ var C = /* @__PURE__ */ ((n) => (n.INBOUND_RTP = "inbound-rtp", n.REMOTE_OUTBOUND_RTP = "remote-outbound-rtp", n.MEDIA_SOURCE = "media-source", n.OUTBOUND_RTP = "outbound-rtp", n.REMOTE_INBOUND_RTP = "remote-inbound-rtp", n.CODEC = "codec", n.CANDIDATE_PAIR = "candidate-pair", n.CERTIFICATE = "certificate", n.TRANSPORT = "transport", n.LOCAL_CANDIDATE = "local-candidate", n.REMOTE_CANDIDATE = "remote-candidate", n))(C || {});
2177
+ const Te = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
2139
2178
  const s = n.get(t);
2140
2179
  return s === void 0 ? e : { ...e, [s.type]: s };
2141
- }, {}), ut = (n) => {
2180
+ }, {}), Tt = (n) => {
2142
2181
  if (!n)
2143
2182
  return {
2144
2183
  outboundRtp: void 0,
@@ -2148,10 +2187,10 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2148
2187
  };
2149
2188
  const e = L(n);
2150
2189
  return {
2151
- outboundRtp: e[E.OUTBOUND_RTP],
2152
- codec: e[E.CODEC],
2153
- mediaSource: e[E.MEDIA_SOURCE],
2154
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2190
+ outboundRtp: e[C.OUTBOUND_RTP],
2191
+ codec: e[C.CODEC],
2192
+ mediaSource: e[C.MEDIA_SOURCE],
2193
+ remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2155
2194
  };
2156
2195
  }, z = (n) => {
2157
2196
  if (!n)
@@ -2163,12 +2202,12 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2163
2202
  };
2164
2203
  const e = L(n);
2165
2204
  return {
2166
- outboundRtp: e[E.OUTBOUND_RTP],
2167
- codec: e[E.CODEC],
2168
- mediaSource: e[E.MEDIA_SOURCE],
2169
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2205
+ outboundRtp: e[C.OUTBOUND_RTP],
2206
+ codec: e[C.CODEC],
2207
+ mediaSource: e[C.MEDIA_SOURCE],
2208
+ remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2170
2209
  };
2171
- }, J = ({
2210
+ }, X = ({
2172
2211
  videoReceiversStats: n,
2173
2212
  synchronizationSourcesVideo: e
2174
2213
  }) => {
@@ -2180,11 +2219,11 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2180
2219
  };
2181
2220
  const t = L(n);
2182
2221
  return {
2183
- inboundRtp: t[E.INBOUND_RTP],
2184
- codec: t[E.CODEC],
2222
+ inboundRtp: t[C.INBOUND_RTP],
2223
+ codec: t[C.CODEC],
2185
2224
  synchronizationSources: e
2186
2225
  };
2187
- }, Tt = ({
2226
+ }, St = ({
2188
2227
  audioReceiverStats: n,
2189
2228
  synchronizationSourcesAudio: e
2190
2229
  }) => {
@@ -2197,12 +2236,12 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2197
2236
  };
2198
2237
  const t = L(n);
2199
2238
  return {
2200
- inboundRtp: t[E.INBOUND_RTP],
2201
- codec: t[E.CODEC],
2202
- remoteOutboundRtp: t[E.REMOTE_OUTBOUND_RTP],
2239
+ inboundRtp: t[C.INBOUND_RTP],
2240
+ codec: t[C.CODEC],
2241
+ remoteOutboundRtp: t[C.REMOTE_OUTBOUND_RTP],
2203
2242
  synchronizationSources: e
2204
2243
  };
2205
- }, Te = (n) => {
2244
+ }, Se = (n) => {
2206
2245
  if (!n)
2207
2246
  return {
2208
2247
  candidatePair: void 0,
@@ -2213,21 +2252,21 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2213
2252
  };
2214
2253
  const e = L(n);
2215
2254
  return {
2216
- candidatePair: e[E.CANDIDATE_PAIR],
2217
- certificate: e[E.CERTIFICATE],
2218
- localCandidate: e[E.LOCAL_CANDIDATE],
2219
- remoteCandidate: e[E.REMOTE_CANDIDATE],
2220
- transport: e[E.TRANSPORT]
2255
+ candidatePair: e[C.CANDIDATE_PAIR],
2256
+ certificate: e[C.CERTIFICATE],
2257
+ localCandidate: e[C.LOCAL_CANDIDATE],
2258
+ remoteCandidate: e[C.REMOTE_CANDIDATE],
2259
+ transport: e[C.TRANSPORT]
2221
2260
  };
2222
- }, St = ({
2261
+ }, Ct = ({
2223
2262
  audioSenderStats: n,
2224
2263
  videoSenderFirstStats: e,
2225
2264
  videoSenderSecondStats: t
2226
2265
  }) => ({
2227
2266
  video: z(e),
2228
2267
  secondVideo: z(t),
2229
- audio: ut(n),
2230
- additional: Te(
2268
+ audio: Tt(n),
2269
+ additional: Se(
2231
2270
  n ?? e ?? t
2232
2271
  )
2233
2272
  }), Et = ({
@@ -2236,46 +2275,46 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2236
2275
  videoReceiverSecondStats: t,
2237
2276
  synchronizationSources: s
2238
2277
  }) => ({
2239
- video: J({
2278
+ video: X({
2240
2279
  videoReceiversStats: e,
2241
2280
  synchronizationSourcesVideo: s.video
2242
2281
  }),
2243
- secondVideo: J({
2282
+ secondVideo: X({
2244
2283
  videoReceiversStats: t,
2245
2284
  synchronizationSourcesVideo: s.video
2246
2285
  }),
2247
- audio: Tt({
2286
+ audio: St({
2248
2287
  audioReceiverStats: n,
2249
2288
  synchronizationSourcesAudio: s.audio
2250
2289
  }),
2251
- additional: Te(
2290
+ additional: Se(
2252
2291
  n ?? e ?? t
2253
2292
  )
2254
- }), Ct = ({
2293
+ }), Nt = ({
2255
2294
  audioSenderStats: n,
2256
2295
  videoSenderFirstStats: e,
2257
2296
  videoSenderSecondStats: t,
2258
2297
  audioReceiverStats: s,
2259
- videoReceiverFirstStats: i,
2260
- videoReceiverSecondStats: r,
2298
+ videoReceiverFirstStats: r,
2299
+ videoReceiverSecondStats: i,
2261
2300
  synchronizationSources: a
2262
2301
  }) => {
2263
- const o = St({
2302
+ const o = Ct({
2264
2303
  audioSenderStats: n,
2265
2304
  videoSenderFirstStats: e,
2266
2305
  videoSenderSecondStats: t
2267
2306
  }), c = Et({
2268
2307
  audioReceiverStats: s,
2269
- videoReceiverFirstStats: i,
2270
- videoReceiverSecondStats: r,
2308
+ videoReceiverFirstStats: r,
2309
+ videoReceiverSecondStats: i,
2271
2310
  synchronizationSources: a
2272
2311
  });
2273
2312
  return {
2274
2313
  outbound: o,
2275
2314
  inbound: c
2276
2315
  };
2277
- }, Nt = async (n) => {
2278
- const e = "audio", t = "video", s = n.getSenders(), i = s.find((h) => h.track?.kind === e), r = s.filter((h) => h.track?.kind === t), a = n.getReceivers(), o = a.find((h) => h.track.kind === e), c = a.filter((h) => h.track.kind === t), d = {
2316
+ }, At = async (n) => {
2317
+ const e = "audio", t = "video", s = n.getSenders(), r = s.find((g) => g.track?.kind === e), i = s.filter((g) => g.track?.kind === t), a = n.getReceivers(), o = a.find((g) => g.track.kind === e), c = a.filter((g) => g.track.kind === t), d = {
2279
2318
  trackIdentifier: o?.track.id,
2280
2319
  item: o?.getSynchronizationSources()[0]
2281
2320
  }, u = {
@@ -2286,47 +2325,47 @@ const ue = ["collected"], Y = () => "performance" in window ? performance.now()
2286
2325
  video: u
2287
2326
  };
2288
2327
  return Promise.all([
2289
- i?.getStats(),
2290
- r[0]?.getStats(),
2291
- r[1]?.getStats(),
2328
+ r?.getStats(),
2329
+ i[0]?.getStats(),
2330
+ i[1]?.getStats(),
2292
2331
  o?.getStats(),
2293
2332
  c[0]?.getStats(),
2294
2333
  c[1]?.getStats()
2295
- ]).then((h) => {
2334
+ ]).then((g) => {
2296
2335
  const [
2297
2336
  S,
2298
2337
  m,
2299
2338
  I,
2300
- A,
2339
+ R,
2301
2340
  y,
2302
2341
  b
2303
- ] = h;
2342
+ ] = g;
2304
2343
  return {
2305
2344
  synchronizationSources: T,
2306
2345
  audioSenderStats: S,
2307
2346
  videoSenderFirstStats: m,
2308
2347
  videoSenderSecondStats: I,
2309
- audioReceiverStats: A,
2348
+ audioReceiverStats: R,
2310
2349
  videoReceiverFirstStats: y,
2311
2350
  videoReceiverSecondStats: b
2312
2351
  };
2313
2352
  });
2314
- }, At = (n) => {
2315
- R(String(n));
2353
+ }, Rt = (n) => {
2354
+ A(String(n));
2316
2355
  };
2317
- class Rt {
2356
+ class It {
2318
2357
  events;
2319
2358
  setTimeoutRequest;
2320
- requesterAllStatistics = new Ae(Nt);
2359
+ requesterAllStatistics = new Re(At);
2321
2360
  constructor() {
2322
- this.events = new j(ue), this.setTimeoutRequest = new Z();
2361
+ this.events = new K(Te), this.setTimeoutRequest = new ee();
2323
2362
  }
2324
2363
  get requested() {
2325
2364
  return this.setTimeoutRequest.requested;
2326
2365
  }
2327
2366
  start(e, {
2328
- interval: t = w,
2329
- onError: s = At
2367
+ interval: t = U,
2368
+ onError: s = Rt
2330
2369
  } = {}) {
2331
2370
  this.stop(), this.setTimeoutRequest.request(() => {
2332
2371
  this.collectStatistics(e, {
@@ -2356,20 +2395,20 @@ class Rt {
2356
2395
  onError: t
2357
2396
  }) => {
2358
2397
  const s = Y();
2359
- this.requesterAllStatistics.request(e).then((i) => {
2360
- this.events.trigger("collected", Ct(i));
2398
+ this.requesterAllStatistics.request(e).then((r) => {
2399
+ this.events.trigger("collected", Nt(r));
2361
2400
  const a = Y() - s;
2362
- let o = w;
2363
- a > 48 ? o = w * 4 : a > 32 ? o = w * 3 : a > 16 && (o = w * 2), this.start(e, {
2401
+ let o = U;
2402
+ a > 48 ? o = U * 4 : a > 32 ? o = U * 3 : a > 16 && (o = U * 2), this.start(e, {
2364
2403
  onError: t,
2365
2404
  interval: o
2366
2405
  });
2367
- }).catch((i) => {
2368
- t && t(i);
2406
+ }).catch((r) => {
2407
+ t && t(r);
2369
2408
  });
2370
2409
  };
2371
2410
  }
2372
- class It {
2411
+ class _t {
2373
2412
  availableIncomingBitrate;
2374
2413
  statsPeerConnection;
2375
2414
  callManager;
@@ -2379,7 +2418,7 @@ class It {
2379
2418
  callManager: e,
2380
2419
  apiManager: t
2381
2420
  }) {
2382
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Rt(), this.subscribe();
2421
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new It(), this.subscribe();
2383
2422
  }
2384
2423
  get events() {
2385
2424
  return this.statsPeerConnection.events;
@@ -2417,37 +2456,37 @@ class It {
2417
2456
  };
2418
2457
  maybeSendStats() {
2419
2458
  this.availableIncomingBitrate !== void 0 && this.hasAvailableIncomingBitrateChangedQuarter() && this.apiManager.sendStats({ availableIncomingBitrate: this.availableIncomingBitrate }).catch((e) => {
2420
- R("Failed to send stats", e);
2459
+ A("Failed to send stats", e);
2421
2460
  });
2422
2461
  }
2423
2462
  }
2424
- const _t = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), Mt = (n) => {
2425
- const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
2426
- return _t(s, i);
2427
- }, mt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2428
- const i = e.indexOf(t.mimeType), r = e.indexOf(s.mimeType), a = i === -1 ? Number.MAX_VALUE : i, o = r === -1 ? Number.MAX_VALUE : r;
2463
+ const Mt = (n, e) => n.filter((s) => e.some((r) => r.clockRate === s.clockRate && r.mimeType === s.mimeType && r.channels === s.channels && r.sdpFmtpLine === s.sdpFmtpLine)), mt = (n) => {
2464
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, r = t === null ? [] : t.codecs;
2465
+ return Mt(s, r);
2466
+ }, pt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2467
+ const r = e.indexOf(t.mimeType), i = e.indexOf(s.mimeType), a = r === -1 ? Number.MAX_VALUE : r, o = i === -1 ? Number.MAX_VALUE : i;
2429
2468
  return a - o;
2430
- }), pt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Pt = (n, {
2469
+ }), Pt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), ft = (n, {
2431
2470
  preferredMimeTypesVideoCodecs: e,
2432
2471
  excludeMimeTypesVideoCodecs: t
2433
2472
  }) => {
2434
2473
  try {
2435
2474
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
2436
- const s = Mt("video"), i = pt(s, t), r = mt(i, e);
2437
- n.setCodecPreferences(r);
2475
+ const s = mt("video"), r = Pt(s, t), i = pt(r, e);
2476
+ n.setCodecPreferences(i);
2438
2477
  }
2439
2478
  } catch (s) {
2440
- R("setCodecPreferences error", s);
2479
+ A("setCodecPreferences error", s);
2441
2480
  }
2442
- }, ft = (n) => [...n.keys()].map((e) => n.get(e)), Ot = (n, e) => ft(n).find((t) => t?.type === e), vt = async (n) => n.getStats().then((e) => Ot(e, "codec")?.mimeType);
2443
- class Dt {
2481
+ }, Ot = (n) => [...n.keys()].map((e) => n.get(e)), vt = (n, e) => Ot(n).find((t) => t?.type === e), Dt = async (n) => n.getStats().then((e) => vt(e, "codec")?.mimeType);
2482
+ class yt {
2444
2483
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2445
2484
  async getCodecFromSender(e) {
2446
- return await vt(e) ?? "";
2485
+ return await Dt(e) ?? "";
2447
2486
  }
2448
2487
  }
2449
- class yt {
2450
- stackPromises = Me({
2488
+ class bt {
2489
+ stackPromises = Z({
2451
2490
  noRunIsNotActual: !0
2452
2491
  });
2453
2492
  /**
@@ -2467,34 +2506,34 @@ class yt {
2467
2506
  */
2468
2507
  async run() {
2469
2508
  return this.stackPromises().catch((e) => {
2470
- R("TaskQueue: error", e);
2509
+ A("TaskQueue: error", e);
2471
2510
  });
2472
2511
  }
2473
2512
  }
2474
- class bt {
2513
+ class Ut {
2475
2514
  taskQueue;
2476
2515
  onSetParameters;
2477
2516
  constructor(e) {
2478
- this.onSetParameters = e, this.taskQueue = new yt();
2517
+ this.onSetParameters = e, this.taskQueue = new bt();
2479
2518
  }
2480
2519
  async setEncodingsToSender(e, t) {
2481
- return this.taskQueue.add(async () => oe(e, t, this.onSetParameters));
2520
+ return this.taskQueue.add(async () => ce(e, t, this.onSetParameters));
2482
2521
  }
2483
2522
  stop() {
2484
2523
  this.taskQueue.stop();
2485
2524
  }
2486
2525
  }
2487
- const Se = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), wt = 1e6, p = (n) => n * wt, Ee = p(0.06), Ce = p(4), Ut = (n) => n <= 64 ? Ee : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ce, Lt = "av1", Bt = (n) => Se(n, Lt), kt = 0.6, Q = (n, e) => Bt(e) ? n * kt : n, Ft = (n) => Q(Ee, n), $t = (n) => Q(Ce, n), X = (n, e) => {
2488
- const t = Ut(n);
2526
+ const Ce = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), wt = 1e6, p = (n) => n * wt, Ee = p(0.06), Ne = p(4), Lt = (n) => n <= 64 ? Ee : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ne, Bt = "av1", kt = (n) => Ce(n, Bt), Ft = 0.6, Q = (n, e) => kt(e) ? n * Ft : n, $t = (n) => Q(Ee, n), Vt = (n) => Q(Ne, n), J = (n, e) => {
2527
+ const t = Lt(n);
2489
2528
  return Q(t, e);
2490
- }, V = 1, Vt = ({
2529
+ }, V = 1, Wt = ({
2491
2530
  videoTrack: n,
2492
2531
  targetSize: e
2493
2532
  }) => {
2494
- const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? V : s / e.width, a = i === void 0 ? V : i / e.height;
2495
- return Math.max(r, a, V);
2533
+ const t = n.getSettings(), s = t.width, r = t.height, i = s === void 0 ? V : s / e.width, a = r === void 0 ? V : r / e.height;
2534
+ return Math.max(i, a, V);
2496
2535
  };
2497
- class Wt {
2536
+ class Ht {
2498
2537
  ignoreForCodec;
2499
2538
  senderFinder;
2500
2539
  codecProvider;
@@ -2513,8 +2552,8 @@ class Wt {
2513
2552
  senderFinder: e,
2514
2553
  codecProvider: t,
2515
2554
  parametersSetter: s
2516
- }, i) {
2517
- this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = i.ignoreForCodec;
2555
+ }, r) {
2556
+ this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = r.ignoreForCodec;
2518
2557
  }
2519
2558
  /**
2520
2559
  * Выполняет балансировку на основе заголовков от сервера
@@ -2523,21 +2562,21 @@ class Wt {
2523
2562
  * @returns Promise с результатом балансировки
2524
2563
  */
2525
2564
  async balance(e, t) {
2526
- const s = e.getSenders(), i = this.senderFinder.findVideoSender(s);
2527
- if (!i?.track)
2528
- return { ...this.resultNoChanged, sender: i };
2529
- const r = await this.codecProvider.getCodecFromSender(i);
2530
- if (Se(r, this.ignoreForCodec))
2531
- return { ...this.resultNoChanged, sender: i };
2565
+ const s = e.getSenders(), r = this.senderFinder.findVideoSender(s);
2566
+ if (!r?.track)
2567
+ return { ...this.resultNoChanged, sender: r };
2568
+ const i = await this.codecProvider.getCodecFromSender(r);
2569
+ if (Ce(i, this.ignoreForCodec))
2570
+ return { ...this.resultNoChanged, sender: r };
2532
2571
  const { mainCam: a, resolutionMainCam: o } = t ?? {};
2533
2572
  return this.processSender(
2534
2573
  { mainCam: a, resolutionMainCam: o },
2535
2574
  {
2536
- sender: i,
2537
- codec: r,
2538
- videoTrack: i.track
2575
+ sender: r,
2576
+ codec: i,
2577
+ videoTrack: r.track
2539
2578
  }
2540
- ).then((c) => ({ ...c, sender: i }));
2579
+ ).then((c) => ({ ...c, sender: r }));
2541
2580
  }
2542
2581
  /**
2543
2582
  * Обрабатывает отправитель в зависимости от команды управления
@@ -2545,14 +2584,14 @@ class Wt {
2545
2584
  * @returns Promise с результатом обработки
2546
2585
  */
2547
2586
  async processSender(e, t) {
2548
- const { mainCam: s, resolutionMainCam: i } = e;
2587
+ const { mainCam: s, resolutionMainCam: r } = e;
2549
2588
  switch (s) {
2550
2589
  case P.PAUSE_MAIN_CAM:
2551
2590
  return this.downgradeResolutionSender(t);
2552
2591
  case P.RESUME_MAIN_CAM:
2553
2592
  return this.setBitrateByTrackResolution(t);
2554
2593
  case P.MAX_MAIN_CAM_RESOLUTION:
2555
- return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
2594
+ return r !== void 0 ? this.setResolutionSender(r, t) : this.setBitrateByTrackResolution(t);
2556
2595
  case P.ADMIN_STOP_MAIN_CAM:
2557
2596
  case P.ADMIN_START_MAIN_CAM:
2558
2597
  case void 0:
@@ -2567,11 +2606,11 @@ class Wt {
2567
2606
  * @returns Promise с результатом
2568
2607
  */
2569
2608
  async downgradeResolutionSender(e) {
2570
- const { sender: t, codec: s } = e, i = {
2609
+ const { sender: t, codec: s } = e, r = {
2571
2610
  scaleResolutionDownBy: 200,
2572
- maxBitrate: Ft(s)
2611
+ maxBitrate: $t(s)
2573
2612
  };
2574
- return this.parametersSetter.setEncodingsToSender(t, i);
2613
+ return this.parametersSetter.setEncodingsToSender(t, r);
2575
2614
  }
2576
2615
  /**
2577
2616
  * Устанавливает битрейт на основе разрешения трека
@@ -2579,7 +2618,7 @@ class Wt {
2579
2618
  * @returns Promise с результатом
2580
2619
  */
2581
2620
  async setBitrateByTrackResolution(e) {
2582
- const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? $t(i) : X(a, i);
2621
+ const { sender: t, videoTrack: s, codec: r } = e, a = s.getSettings().width, o = a === void 0 ? Vt(r) : J(a, r);
2583
2622
  return this.parametersSetter.setEncodingsToSender(t, {
2584
2623
  scaleResolutionDownBy: 1,
2585
2624
  maxBitrate: o
@@ -2592,27 +2631,27 @@ class Wt {
2592
2631
  * @returns Promise с результатом
2593
2632
  */
2594
2633
  async setResolutionSender(e, t) {
2595
- const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
2634
+ const [s, r] = e.split("x"), { sender: i, videoTrack: a, codec: o } = t, c = {
2596
2635
  width: Number(s),
2597
- height: Number(i)
2598
- }, d = Vt({
2636
+ height: Number(r)
2637
+ }, d = Wt({
2599
2638
  videoTrack: a,
2600
2639
  targetSize: c
2601
- }), u = X(c.width, o), T = {
2640
+ }), u = J(c.width, o), T = {
2602
2641
  scaleResolutionDownBy: d,
2603
2642
  maxBitrate: u
2604
2643
  };
2605
- return this.parametersSetter.setEncodingsToSender(r, T);
2644
+ return this.parametersSetter.setEncodingsToSender(i, T);
2606
2645
  }
2607
2646
  }
2608
- const Ht = (n) => n.find((e) => e.track?.kind === "video");
2609
- class xt {
2647
+ const xt = (n) => n.find((e) => e.track?.kind === "video");
2648
+ class qt {
2610
2649
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2611
2650
  findVideoSender(e) {
2612
- return Ht(e);
2651
+ return xt(e);
2613
2652
  }
2614
2653
  }
2615
- class qt {
2654
+ class Gt {
2616
2655
  currentSender;
2617
2656
  originalReplaceTrack;
2618
2657
  lastWidth;
@@ -2625,7 +2664,7 @@ class qt {
2625
2664
  pollIntervalMs: e = 1e3,
2626
2665
  maxPollIntervalMs: t
2627
2666
  }) {
2628
- this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new Z();
2667
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new ee();
2629
2668
  }
2630
2669
  /**
2631
2670
  * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
@@ -2644,8 +2683,8 @@ class qt {
2644
2683
  attachSender(e, t) {
2645
2684
  this.currentSender = e;
2646
2685
  const s = e.replaceTrack.bind(e);
2647
- this.originalReplaceTrack = s, e.replaceTrack = async (i) => {
2648
- await s(i), this.attachTrack(t, i ?? void 0), t();
2686
+ this.originalReplaceTrack = s, e.replaceTrack = async (r) => {
2687
+ await s(r), this.attachTrack(t, r ?? void 0), t();
2649
2688
  }, this.attachTrack(t, e.track);
2650
2689
  }
2651
2690
  detachSender() {
@@ -2654,8 +2693,8 @@ class qt {
2654
2693
  attachTrack(e, t) {
2655
2694
  if (this.detachTrack(), !t)
2656
2695
  return;
2657
- const { width: s, height: i } = t.getSettings();
2658
- this.lastWidth = s, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2696
+ const { width: s, height: r } = t.getSettings();
2697
+ this.lastWidth = s, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2659
2698
  }
2660
2699
  /**
2661
2700
  * Периодически опрашивает track с экспоненциальной адаптацией частоты.
@@ -2664,8 +2703,8 @@ class qt {
2664
2703
  */
2665
2704
  schedulePoll(e, t) {
2666
2705
  const s = () => {
2667
- const { width: i, height: r } = e.getSettings();
2668
- i !== this.lastWidth || r !== this.lastHeight ? (this.lastWidth = i, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2706
+ const { width: r, height: i } = e.getSettings();
2707
+ r !== this.lastWidth || i !== this.lastHeight ? (this.lastWidth = r, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2669
2708
  this.currentPollIntervalMs * 2,
2670
2709
  this.maxPollIntervalMs
2671
2710
  ), this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
@@ -2676,7 +2715,7 @@ class qt {
2676
2715
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
2677
2716
  }
2678
2717
  }
2679
- class Gt {
2718
+ class Qt {
2680
2719
  apiManager;
2681
2720
  currentHandler;
2682
2721
  constructor(e) {
@@ -2696,7 +2735,7 @@ class Gt {
2696
2735
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
2697
2736
  }
2698
2737
  }
2699
- class Qt {
2738
+ class Yt {
2700
2739
  eventHandler;
2701
2740
  senderBalancer;
2702
2741
  parametersSetterWithQueue;
@@ -2705,19 +2744,19 @@ class Qt {
2705
2744
  trackMonitor;
2706
2745
  constructor(e, t, {
2707
2746
  ignoreForCodec: s,
2708
- onSetParameters: i,
2709
- pollIntervalMs: r
2747
+ onSetParameters: r,
2748
+ pollIntervalMs: i
2710
2749
  } = {}) {
2711
- this.getConnection = t, this.eventHandler = new Gt(e), this.parametersSetterWithQueue = new bt(i), this.senderBalancer = new Wt(
2750
+ this.getConnection = t, this.eventHandler = new Qt(e), this.parametersSetterWithQueue = new Ut(r), this.senderBalancer = new Ht(
2712
2751
  {
2713
- senderFinder: new xt(),
2714
- codecProvider: new Dt(),
2752
+ senderFinder: new qt(),
2753
+ codecProvider: new yt(),
2715
2754
  parametersSetter: this.parametersSetterWithQueue
2716
2755
  },
2717
2756
  {
2718
2757
  ignoreForCodec: s
2719
2758
  }
2720
- ), this.trackMonitor = new qt({ pollIntervalMs: r });
2759
+ ), this.trackMonitor = new Gt({ pollIntervalMs: i });
2721
2760
  }
2722
2761
  /**
2723
2762
  * Подписывается на события управления главной камерой
@@ -2748,7 +2787,7 @@ class Qt {
2748
2787
  const t = await this.senderBalancer.balance(e, this.serverHeaders);
2749
2788
  return this.trackMonitor.subscribe(t.sender, () => {
2750
2789
  this.balance().catch((s) => {
2751
- R("balance on track change: error", s);
2790
+ A("balance on track change: error", s);
2752
2791
  });
2753
2792
  }), t;
2754
2793
  }
@@ -2758,17 +2797,17 @@ class Qt {
2758
2797
  */
2759
2798
  handleMainCamControl = (e) => {
2760
2799
  this.serverHeaders = e, this.balance().catch((t) => {
2761
- R("handleMainCamControl: error", t);
2800
+ A("handleMainCamControl: error", t);
2762
2801
  });
2763
2802
  };
2764
2803
  }
2765
- const Ne = [
2804
+ const Ae = [
2766
2805
  "balancing-scheduled",
2767
2806
  "balancing-started",
2768
2807
  "balancing-stopped",
2769
2808
  "parameters-updated"
2770
2809
  ];
2771
- class Yt {
2810
+ class zt {
2772
2811
  isBalancingActive = !1;
2773
2812
  events;
2774
2813
  callManager;
@@ -2776,13 +2815,13 @@ class Yt {
2776
2815
  videoSendingBalancer;
2777
2816
  startBalancingTimer;
2778
2817
  constructor(e, t, s = {}) {
2779
- this.events = new j(Ne), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Qt(
2818
+ this.events = new K(Ae), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Yt(
2780
2819
  t,
2781
2820
  () => e.connection,
2782
2821
  {
2783
2822
  ...s,
2784
- onSetParameters: (i) => {
2785
- this.events.trigger("parameters-updated", i), s.onSetParameters?.(i);
2823
+ onSetParameters: (r) => {
2824
+ this.events.trigger("parameters-updated", r), s.onSetParameters?.(r);
2786
2825
  }
2787
2826
  }
2788
2827
  ), this.subscribe();
@@ -2838,7 +2877,7 @@ class Yt {
2838
2877
  scheduleBalancingStart() {
2839
2878
  this.clearStartTimer(), this.startBalancingTimer = setTimeout(() => {
2840
2879
  this.startBalancingTimer = void 0, this.startBalancing().catch((e) => {
2841
- R("startBalancing: error", e);
2880
+ A("startBalancing: error", e);
2842
2881
  });
2843
2882
  }, this.balancingStartDelay), this.events.trigger("balancing-scheduled", { delay: this.balancingStartDelay });
2844
2883
  }
@@ -2846,18 +2885,19 @@ class Yt {
2846
2885
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
2847
2886
  }
2848
2887
  }
2849
- const zt = 1e6, Jt = he.map((n) => `connection:${n}`), Xt = te.map((n) => `call:${n}`), jt = ie.map((n) => `api:${n}`), Kt = le.map((n) => `incoming-call:${n}`), Zt = ce.map((n) => `presentation:${n}`), en = ue.map((n) => `stats:${n}`), tn = Ne.map((n) => `video-balancer:${n}`), nn = [
2888
+ const Xt = 1e6, Jt = ge.map((n) => `connection:${n}`), Kt = ne.map((n) => `call:${n}`), jt = ie.map((n) => `api:${n}`), Zt = ue.map((n) => `incoming-call:${n}`), en = de.map((n) => `presentation:${n}`), tn = Te.map((n) => `stats:${n}`), nn = Ae.map((n) => `video-balancer:${n}`), sn = [
2850
2889
  ...Jt,
2851
- ...Xt,
2852
- ...jt,
2853
2890
  ...Kt,
2891
+ ...jt,
2854
2892
  ...Zt,
2855
2893
  ...en,
2856
- ...tn
2894
+ ...tn,
2895
+ ...nn
2857
2896
  ];
2858
2897
  class En {
2859
2898
  events;
2860
2899
  connectionManager;
2900
+ connectionQueueManager;
2861
2901
  callManager;
2862
2902
  apiManager;
2863
2903
  incomingCallManager;
@@ -2869,21 +2909,23 @@ class En {
2869
2909
  constructor({ JsSIP: e }, {
2870
2910
  preferredMimeTypesVideoCodecs: t,
2871
2911
  excludeMimeTypesVideoCodecs: s,
2872
- videoBalancerOptions: i
2912
+ videoBalancerOptions: r
2873
2913
  } = {}) {
2874
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(nn), this.connectionManager = new dt({ JsSIP: e }), this.callManager = new we(), this.apiManager = new $e({
2914
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(sn), this.connectionManager = new dt({ JsSIP: e }), this.connectionQueueManager = new ht({
2915
+ connectionManager: this.connectionManager
2916
+ }), this.callManager = new Ue(), this.apiManager = new $e({
2875
2917
  connectionManager: this.connectionManager,
2876
2918
  callManager: this.callManager
2877
- }), this.incomingCallManager = new lt(this.connectionManager), this.presentationManager = new et({
2919
+ }), this.incomingCallManager = new ut(this.connectionManager), this.presentationManager = new et({
2878
2920
  callManager: this.callManager,
2879
- maxBitrate: zt
2880
- }), this.statsManager = new It({
2921
+ maxBitrate: Xt
2922
+ }), this.statsManager = new _t({
2881
2923
  callManager: this.callManager,
2882
2924
  apiManager: this.apiManager
2883
- }), this.videoSendingBalancerManager = new Yt(
2925
+ }), this.videoSendingBalancerManager = new zt(
2884
2926
  this.callManager,
2885
2927
  this.apiManager,
2886
- i
2928
+ r
2887
2929
  ), this.subscribe();
2888
2930
  }
2889
2931
  get requestedConnection() {
@@ -2944,15 +2986,15 @@ class En {
2944
2986
  off(e, t) {
2945
2987
  this.events.off(e, t);
2946
2988
  }
2947
- connect = async (...e) => this.connectionManager.connect(...e);
2948
- set = async (...e) => this.connectionManager.set(...e);
2949
- disconnect = async () => this.connectionManager.disconnect();
2950
- register = async () => this.connectionManager.register();
2951
- unregister = async () => this.connectionManager.unregister();
2952
- tryRegister = async () => this.connectionManager.tryRegister();
2953
- sendOptions = async (e, t, s) => this.connectionManager.sendOptions(e, t, s);
2954
- ping = async (e, t) => this.connectionManager.ping(e, t);
2955
- checkTelephony = async (e) => this.connectionManager.checkTelephony(e);
2989
+ connect = async (...e) => this.connectionQueueManager.connect(...e);
2990
+ set = async (...e) => this.connectionQueueManager.set(...e);
2991
+ disconnect = async () => this.connectionQueueManager.disconnect();
2992
+ register = async () => this.connectionQueueManager.register();
2993
+ unregister = async () => this.connectionQueueManager.unregister();
2994
+ tryRegister = async () => this.connectionQueueManager.tryRegister();
2995
+ sendOptions = async (e, t, s) => this.connectionQueueManager.sendOptions(e, t, s);
2996
+ ping = async (e, t) => this.connectionQueueManager.ping(e, t);
2997
+ checkTelephony = async (e) => this.connectionQueueManager.checkTelephony(e);
2956
2998
  isConfigured = () => this.connectionManager.isConfigured();
2957
2999
  getConnectionConfiguration = () => this.connectionManager.getConnectionConfiguration();
2958
3000
  getSipServerUrl = (e) => this.connectionManager.getSipServerUrl(e);
@@ -2963,8 +3005,8 @@ class En {
2963
3005
  this.getSipServerUrl,
2964
3006
  {
2965
3007
  ...s,
2966
- onAddedTransceiver: async (i, r, a) => {
2967
- this.setCodecPreferences(i), await t?.(i, r, a);
3008
+ onAddedTransceiver: async (r, i, a) => {
3009
+ this.setCodecPreferences(r), await t?.(r, i, a);
2968
3010
  }
2969
3011
  }
2970
3012
  );
@@ -2976,8 +3018,8 @@ class En {
2976
3018
  this.incomingCallManager.extractIncomingRTCSession,
2977
3019
  {
2978
3020
  ...s,
2979
- onAddedTransceiver: async (i, r, a) => {
2980
- this.setCodecPreferences(i), await t?.(i, r, a);
3021
+ onAddedTransceiver: async (r, i, a) => {
3022
+ this.setCodecPreferences(r), await t?.(r, i, a);
2981
3023
  }
2982
3024
  }
2983
3025
  );
@@ -2988,7 +3030,7 @@ class En {
2988
3030
  getRemoteStreams = () => this.callManager.getRemoteStreams();
2989
3031
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
2990
3032
  async startPresentation(e, t = {}) {
2991
- const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
3033
+ const { isP2P: s, callLimit: r, onAddedTransceiver: i, ...a } = t;
2992
3034
  return this.presentationManager.startPresentation(
2993
3035
  async () => {
2994
3036
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
@@ -2997,10 +3039,10 @@ class En {
2997
3039
  {
2998
3040
  ...a,
2999
3041
  onAddedTransceiver: async (o, c, d) => {
3000
- this.setCodecPreferences(o), await r?.(o, c, d);
3042
+ this.setCodecPreferences(o), await i?.(o, c, d);
3001
3043
  }
3002
3044
  },
3003
- i === void 0 ? void 0 : { callLimit: i }
3045
+ r === void 0 ? void 0 : { callLimit: r }
3004
3046
  );
3005
3047
  }
3006
3048
  async stopPresentation(e = {}) {
@@ -3010,16 +3052,16 @@ class En {
3010
3052
  });
3011
3053
  }
3012
3054
  async updatePresentation(e, t = {}) {
3013
- const { isP2P: s, onAddedTransceiver: i, ...r } = t;
3055
+ const { isP2P: s, onAddedTransceiver: r, ...i } = t;
3014
3056
  return this.presentationManager.updatePresentation(
3015
3057
  async () => {
3016
3058
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
3017
3059
  },
3018
3060
  e,
3019
3061
  {
3020
- ...r,
3062
+ ...i,
3021
3063
  onAddedTransceiver: async (a, o, c) => {
3022
- this.setCodecPreferences(a), await i?.(a, o, c);
3064
+ this.setCodecPreferences(a), await r?.(a, o, c);
3023
3065
  }
3024
3066
  }
3025
3067
  );
@@ -3067,7 +3109,7 @@ class En {
3067
3109
  return this.apiManager.askPermissionToEnableCam(...e);
3068
3110
  }
3069
3111
  setCodecPreferences(e) {
3070
- Pt(e, {
3112
+ ft(e, {
3071
3113
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
3072
3114
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
3073
3115
  });
@@ -3101,22 +3143,27 @@ class En {
3101
3143
  this.videoSendingBalancerManager.on(t, (s) => {
3102
3144
  this.events.trigger(`video-balancer:${t}`, s);
3103
3145
  });
3104
- });
3146
+ }), this.apiManager.on("restart", this.handleRestart);
3105
3147
  }
3148
+ handleRestart = () => {
3149
+ this.callManager.restartIce().catch((e) => {
3150
+ A("Failed to restart ICE", e);
3151
+ });
3152
+ };
3106
3153
  }
3107
3154
  export {
3108
- se as E,
3155
+ re as E,
3109
3156
  $ as O,
3110
3157
  En as S,
3111
- Xe as a,
3158
+ Je as a,
3112
3159
  Fe as b,
3113
- E as c,
3114
- Tn as d,
3115
- un as e,
3116
- Rt as f,
3117
- vt as g,
3118
- Sn as h,
3119
- R as l,
3160
+ C as c,
3161
+ Sn as d,
3162
+ Tn as e,
3163
+ It as f,
3164
+ Dt as g,
3165
+ Cn as h,
3166
+ A as l,
3120
3167
  B as p,
3121
- oe as s
3168
+ ce as s
3122
3169
  };