sip-connector 16.1.0 → 17.0.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,13 +1,13 @@
1
- import { Events as D, TypedEvents as j } from "events-constructor";
1
+ import { Events as D, TypedEvents as K } from "events-constructor";
2
2
  import { CancelableRequest as Re } from "@krivega/cancelable-promise";
3
3
  import q from "debug";
4
- import { hasCanceledError as Ie, repeatedCallsAsync as K } from "repeated-calls";
5
- import { setup as _e, createActor as Me } from "xstate";
4
+ import { hasCanceledError as Ie, repeatedCallsAsync as j } from "repeated-calls";
5
+ import { setup as _e, createActor as me } from "xstate";
6
6
  import { createStackPromises as Z } from "stack-promises";
7
7
  import { SetTimeoutRequest as ee } from "@krivega/timeout-requester";
8
8
  import "ua-parser-js";
9
9
  import "sequent-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))($ || {});
10
+ var N = /* @__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))(N || {}), F = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(F || {});
11
11
  const te = [
12
12
  "peerconnection",
13
13
  "connecting",
@@ -35,31 +35,31 @@ const te = [
35
35
  "peerconnection:createanswerfailed",
36
36
  "peerconnection:setlocaldescriptionfailed",
37
37
  "peerconnection:setremotedescriptionfailed"
38
- ], me = [
38
+ ], Me = [
39
39
  "peerconnection:confirmed",
40
40
  "peerconnection:ontrack",
41
41
  "ended:fromserver"
42
42
  ], ne = [
43
43
  ...te,
44
- ...me
44
+ ...Me
45
45
  ], pe = (n, e) => {
46
46
  n.getVideoTracks().forEach((s) => {
47
47
  "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
48
48
  });
49
- }, B = (n, {
49
+ }, L = (n, {
50
50
  directionVideo: e,
51
51
  directionAudio: t,
52
52
  contentHint: s
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, se = (n) => n.trim().replaceAll(" ", "_"), Oe = fe(1e5, 99999999), ve = (n) => n.some((t) => {
62
+ const ve = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, se = (n) => n.trim().replaceAll(" ", "_"), fe = ve(1e5, 99999999), Oe = (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 ie = /* @__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))(ie || {});
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
  }
@@ -104,11 +104,82 @@ class ye {
104
104
  return e.map((t) => this.generateAudioStream(t));
105
105
  }
106
106
  }
107
- class be extends De {
107
+ class be {
108
+ /**
109
+ * Хранилище основных transceiver'ов
110
+ */
111
+ transceivers = {};
112
+ /**
113
+ * Сохраняет transceiver в соответствующем хранилище в зависимости от типа трека и mid
114
+ */
115
+ storeTransceiver(e, t) {
116
+ const { kind: s } = t;
117
+ if (s === "audio")
118
+ this.transceivers.mainAudio ??= e;
119
+ else {
120
+ const { mid: r } = e;
121
+ r === "2" ? this.transceivers.presentationVideo ??= e : this.transceivers.mainVideo ??= e;
122
+ }
123
+ }
124
+ /**
125
+ * Возвращает все сохраненные transceiver'ы
126
+ */
127
+ getTransceivers() {
128
+ return { ...this.transceivers };
129
+ }
130
+ /**
131
+ * Возвращает основной аудио transceiver
132
+ */
133
+ getMainAudioTransceiver() {
134
+ return this.transceivers.mainAudio;
135
+ }
136
+ /**
137
+ * Возвращает основной видео transceiver
138
+ */
139
+ getMainVideoTransceiver() {
140
+ return this.transceivers.mainVideo;
141
+ }
142
+ /**
143
+ * Возвращает презентационный видео transceiver
144
+ */
145
+ getPresentationVideoTransceiver() {
146
+ return this.transceivers.presentationVideo;
147
+ }
148
+ /**
149
+ * Проверяет, есть ли сохраненный transceiver для указанного типа
150
+ */
151
+ hasTransceiver(e) {
152
+ return this.transceivers[e] !== void 0;
153
+ }
154
+ /**
155
+ * Очищает все сохраненные transceiver'ы
156
+ */
157
+ clear() {
158
+ this.transceivers.mainVideo = void 0, this.transceivers.mainAudio = void 0, this.transceivers.presentationVideo = void 0;
159
+ }
160
+ /**
161
+ * Возвращает количество сохраненных transceiver'ов
162
+ */
163
+ getCount() {
164
+ let e = 0;
165
+ return this.transceivers.mainAudio && (e += 1), this.transceivers.mainVideo && (e += 1), this.transceivers.presentationVideo && (e += 1), e;
166
+ }
167
+ /**
168
+ * Проверяет, пустое ли хранилище
169
+ */
170
+ isEmpty() {
171
+ return this.getCount() === 0;
172
+ }
173
+ }
174
+ class Ue extends De {
108
175
  remoteStreamsManager = new ye();
109
176
  disposers = /* @__PURE__ */ new Set();
177
+ /**
178
+ * Менеджер для управления transceiver'ами
179
+ */
180
+ transceiverManager = new be();
110
181
  constructor(e) {
111
- super(e), e.on(C.FAILED, this.handleEnded), e.on(C.ENDED, this.handleEnded);
182
+ super(e), e.on(N.FAILED, this.handleEnded), e.on(N.ENDED, this.handleEnded);
112
183
  }
113
184
  get requested() {
114
185
  return this.isPendingCall || this.isPendingAnswer;
@@ -124,44 +195,44 @@ class be extends De {
124
195
  }
125
196
  startCall = async (e, t, {
126
197
  number: s,
127
- mediaStream: i,
128
- extraHeaders: r = [],
198
+ mediaStream: r,
199
+ extraHeaders: i = [],
129
200
  ontrack: a,
130
201
  iceServers: o,
131
202
  directionVideo: c,
132
203
  directionAudio: d,
133
204
  contentHint: u,
134
205
  offerToReceiveAudio: T = !0,
135
- offerToReceiveVideo: h = !0,
206
+ offerToReceiveVideo: g = !0,
136
207
  degradationPreference: S,
137
- sendEncodings: m,
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) => {
141
- y(b);
208
+ sendEncodings: I,
209
+ onAddedTransceiver: _
210
+ }) => (this.isPendingCall = !0, new Promise((R, y) => {
211
+ this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(R).catch(($) => {
212
+ y($);
142
213
  }), this.rtcSession = e.call(t(s), {
143
- extraHeaders: r,
144
- mediaStream: B(i, {
214
+ mediaStream: L(r, {
145
215
  directionVideo: c,
146
216
  directionAudio: d,
147
217
  contentHint: u
148
218
  }),
149
- // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
150
- // так как в методе call создается RTCSession
151
- // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
152
- eventHandlers: this.events.triggers,
153
- directionVideo: c,
154
- directionAudio: d,
155
219
  pcConfig: {
156
220
  iceServers: o
157
221
  },
158
222
  rtcOfferConstraints: {
159
223
  offerToReceiveAudio: T,
160
- offerToReceiveVideo: h
224
+ offerToReceiveVideo: g
161
225
  },
226
+ // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
227
+ // так как в методе call создается RTCSession
228
+ // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
229
+ eventHandlers: this.events.triggers,
230
+ extraHeaders: i,
231
+ directionVideo: c,
232
+ directionAudio: d,
162
233
  degradationPreference: S,
163
- sendEncodings: m,
164
- onAddedTransceiver: I
234
+ sendEncodings: I,
235
+ onAddedTransceiver: _
165
236
  });
166
237
  }).finally(() => {
167
238
  this.isPendingCall = !1;
@@ -170,7 +241,7 @@ class be extends De {
170
241
  const { rtcSession: e } = this;
171
242
  if (e && !e.isEnded())
172
243
  return e.terminateAsync({
173
- cause: ie.CANCELED
244
+ cause: re.CANCELED
174
245
  }).finally(() => {
175
246
  this.reset();
176
247
  });
@@ -179,45 +250,43 @@ class be extends De {
179
250
  answerToIncomingCall = async (e, {
180
251
  mediaStream: t,
181
252
  ontrack: s,
182
- extraHeaders: i = [],
183
- iceServers: r,
253
+ extraHeaders: r = [],
254
+ iceServers: i,
184
255
  directionVideo: a,
185
256
  directionAudio: o,
186
257
  offerToReceiveAudio: c,
187
258
  offerToReceiveVideo: d,
188
259
  contentHint: u,
189
260
  degradationPreference: T,
190
- sendEncodings: h,
261
+ sendEncodings: g,
191
262
  onAddedTransceiver: S
192
- }) => (this.isPendingAnswer = !0, new Promise((m, I) => {
263
+ }) => (this.isPendingAnswer = !0, new Promise((I, _) => {
193
264
  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) => {
196
- I(b);
197
- });
198
- const y = B(t, {
199
- directionVideo: a,
200
- directionAudio: o,
201
- contentHint: u
202
- });
203
- A.answer({
204
- extraHeaders: i,
205
- directionVideo: a,
206
- directionAudio: o,
207
- mediaStream: y,
265
+ const R = e();
266
+ this.rtcSession = R, this.subscribeToSessionEvents(R), this.callConfiguration.answer = !0, this.callConfiguration.number = R.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(I).catch((y) => {
267
+ _(y);
268
+ }), R.answer({
208
269
  pcConfig: {
209
- iceServers: r
270
+ iceServers: i
210
271
  },
211
272
  rtcOfferConstraints: {
212
273
  offerToReceiveAudio: c,
213
274
  offerToReceiveVideo: d
214
275
  },
276
+ mediaStream: L(t, {
277
+ directionVideo: a,
278
+ directionAudio: o,
279
+ contentHint: u
280
+ }),
281
+ extraHeaders: r,
282
+ directionVideo: a,
283
+ directionAudio: o,
215
284
  degradationPreference: T,
216
- sendEncodings: h,
285
+ sendEncodings: g,
217
286
  onAddedTransceiver: S
218
287
  });
219
- } catch (A) {
220
- I(A);
288
+ } catch (R) {
289
+ _(R);
221
290
  }
222
291
  }).finally(() => {
223
292
  this.isPendingAnswer = !1;
@@ -232,49 +301,65 @@ class be extends De {
232
301
  if (!this.connection)
233
302
  return;
234
303
  const t = this.connection.getReceivers().map(({ track: s }) => s);
235
- return ve(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
304
+ return Oe(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
236
305
  }
237
306
  async replaceMediaStream(e, t) {
238
307
  if (!this.rtcSession)
239
308
  throw new Error("No rtcSession established");
240
- const { contentHint: s } = t ?? {}, i = B(e, { contentHint: s });
241
- if (i === void 0)
309
+ const { contentHint: s } = t ?? {}, r = L(e, { contentHint: s });
310
+ if (r === void 0)
242
311
  throw new Error("No preparedMediaStream");
243
- return this.rtcSession.replaceMediaStream(i, t);
312
+ return this.rtcSession.replaceMediaStream(r, t);
313
+ }
314
+ async restartIce(e) {
315
+ if (!this.rtcSession)
316
+ throw new Error("No rtcSession established");
317
+ return this.rtcSession.restartIce(e);
318
+ }
319
+ async addTransceiver(e, t) {
320
+ if (!this.rtcSession)
321
+ throw new Error("No rtcSession established");
322
+ return this.rtcSession.addTransceiver(e, t);
323
+ }
324
+ /**
325
+ * Возвращает сохраненные transceiver'ы
326
+ */
327
+ getTransceivers() {
328
+ return this.transceiverManager.getTransceivers();
244
329
  }
245
330
  handleCall = async ({
246
331
  ontrack: e
247
332
  }) => 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);
333
+ const r = () => {
334
+ this.events.on(N.PEER_CONNECTION, u), this.events.on(N.CONFIRMED, T);
335
+ }, i = () => {
336
+ this.events.off(N.PEER_CONNECTION, u), this.events.off(N.CONFIRMED, T);
252
337
  }, a = () => {
253
- this.events.on(C.FAILED, c), this.events.on(C.ENDED, c);
338
+ this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
254
339
  }, o = () => {
255
- this.events.off(C.FAILED, c), this.events.off(C.ENDED, c);
256
- }, c = (h) => {
257
- r(), o(), s(h);
340
+ this.events.off(N.FAILED, c), this.events.off(N.ENDED, c);
341
+ }, c = (g) => {
342
+ i(), o(), s(g);
258
343
  };
259
344
  let d;
260
- const u = ({ peerconnection: h }) => {
261
- d = h;
262
- const S = (m) => {
263
- this.events.trigger(C.PEER_CONNECTION_ONTRACK, h), e && e(m);
345
+ const u = ({ peerconnection: g }) => {
346
+ d = g;
347
+ const S = (I) => {
348
+ this.events.trigger(N.PEER_CONNECTION_ONTRACK, g), this.transceiverManager.storeTransceiver(I.transceiver, I.track), e && e(I);
264
349
  };
265
- h.addEventListener("track", S), this.disposers.add(() => {
266
- h.removeEventListener("track", S);
350
+ g.addEventListener("track", S), this.disposers.add(() => {
351
+ g.removeEventListener("track", S);
267
352
  });
268
353
  }, T = () => {
269
- d !== void 0 && this.events.trigger(C.PEER_CONNECTION_CONFIRMED, d), r(), o(), t(d);
354
+ d !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, d), i(), o(), t(d);
270
355
  };
271
- i(), a();
356
+ r(), a();
272
357
  });
273
358
  subscribeToSessionEvents(e) {
274
359
  this.events.eachTriggers((t, s) => {
275
- const i = te.find((r) => r === s);
276
- i && (e.on(i, t), this.disposers.add(() => {
277
- e.off(i, t);
360
+ const r = te.find((i) => i === s);
361
+ r && (e.on(r, t), this.disposers.add(() => {
362
+ e.off(r, t);
278
363
  }));
279
364
  });
280
365
  }
@@ -285,17 +370,17 @@ class be extends De {
285
370
  }
286
371
  handleEnded = (e) => {
287
372
  const { originator: t } = e;
288
- t === $.REMOTE && this.events.trigger(C.ENDED_FROM_SERVER, e), this.reset();
373
+ t === F.REMOTE && this.events.trigger(N.ENDED_FROM_SERVER, e), this.reset();
289
374
  };
290
375
  reset = () => {
291
- delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
376
+ delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1, this.transceiverManager.clear();
292
377
  };
293
378
  }
294
379
  class we {
295
380
  events;
296
381
  strategy;
297
382
  constructor(e) {
298
- this.events = new D(ne), this.strategy = e ?? new be(this.events);
383
+ this.events = new D(ne), this.strategy = e ?? new Ue(this.events);
299
384
  }
300
385
  get requested() {
301
386
  return this.strategy.requested;
@@ -337,15 +422,18 @@ class we {
337
422
  getEstablishedRTCSession = () => this.strategy.getEstablishedRTCSession();
338
423
  getCallConfiguration = () => this.strategy.getCallConfiguration();
339
424
  getRemoteStreams = () => this.strategy.getRemoteStreams();
425
+ getTransceivers = () => this.strategy.getTransceivers();
426
+ addTransceiver = async (...e) => this.strategy.addTransceiver(...e);
340
427
  replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
428
+ restartIce = async (e) => this.strategy.restartIce(e);
341
429
  }
342
- const G = "sip-connector", R = q(G), Tn = () => {
430
+ const G = "sip-connector", E = q(G), Sn = () => {
343
431
  q.enable(G);
344
- }, Sn = () => {
432
+ }, Cn = () => {
345
433
  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 || {});
348
- const re = [
434
+ }, Le = "Error decline with 603", Be = 1006, ke = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Be, Fe = (n) => n.message === Le;
435
+ 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 || {}), B = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(B || {}), k = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n.SPECTATOR_OVER_SFU = "SPECTATOROVERSFU", n))(k || {}), v = /* @__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))(v || {}), 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 || {}), $e = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))($e || {}), 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 || {});
436
+ const ie = [
349
437
  "participation:accepting-word-request",
350
438
  "participation:cancelling-word-request",
351
439
  "participant:move-request-to-stream",
@@ -373,10 +461,11 @@ const re = [
373
461
  "availableSecondRemoteStream",
374
462
  "notAvailableSecondRemoteStream",
375
463
  "mustStopPresentation",
376
- "newDTMF"
464
+ "newDTMF",
465
+ "restart"
377
466
  ];
378
- 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
- class $e {
467
+ var m = /* @__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))(m || {});
468
+ class Ve {
380
469
  events;
381
470
  connectionManager;
382
471
  callManager;
@@ -384,44 +473,44 @@ class $e {
384
473
  connectionManager: e,
385
474
  callManager: t
386
475
  }) {
387
- this.connectionManager = e, this.callManager = t, this.events = new D(re), this.subscribe();
476
+ this.connectionManager = e, this.callManager = t, this.events = new D(ie), this.subscribe();
388
477
  }
389
478
  async waitChannels() {
390
- return this.wait(g.CHANNELS);
479
+ return this.wait(l.CHANNELS);
391
480
  }
392
481
  async waitSyncMediaState() {
393
- return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
482
+ return this.wait(l.ADMIN_FORCE_SYNC_MEDIA_STATE);
394
483
  }
395
484
  async sendDTMF(e) {
396
485
  return new Promise((t, s) => {
397
- let i;
486
+ let r;
398
487
  try {
399
- i = this.getEstablishedRTCSessionProtected();
400
- } catch (r) {
401
- s(r);
488
+ r = this.getEstablishedRTCSessionProtected();
489
+ } catch (i) {
490
+ s(i);
402
491
  }
403
- i && (this.callManager.once("newDTMF", ({ originator: r }) => {
404
- r === $.LOCAL && t();
405
- }), i.sendDTMF(e, {
492
+ r && (this.callManager.once("newDTMF", ({ originator: i }) => {
493
+ i === F.LOCAL && t();
494
+ }), r.sendDTMF(e, {
406
495
  duration: 120,
407
496
  interToneGap: 600
408
497
  }));
409
498
  });
410
499
  }
411
500
  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
501
+ const s = this.getEstablishedRTCSessionProtected(), r = `${h.INPUT_CHANNELS}: ${e}`, i = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
502
+ r,
503
+ i
415
504
  ];
416
505
  return s.sendInfo(M.CHANNELS, void 0, { extraHeaders: a });
417
506
  }
418
507
  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,
508
+ const r = this.getEstablishedRTCSessionProtected(), i = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
509
+ i,
421
510
  a,
422
511
  o
423
512
  ];
424
- return i.sendInfo(M.MEDIA_STATE, void 0, {
513
+ return r.sendInfo(M.MEDIA_STATE, void 0, {
425
514
  noTerminateWhenError: !0,
426
515
  ...s,
427
516
  extraHeaders: c
@@ -430,14 +519,14 @@ class $e {
430
519
  async sendStats({
431
520
  availableIncomingBitrate: e
432
521
  }) {
433
- const t = this.getEstablishedRTCSessionProtected(), i = [`${l.AVAILABLE_INCOMING_BITRATE}: ${e}`];
522
+ const t = this.getEstablishedRTCSessionProtected(), r = [`${h.AVAILABLE_INCOMING_BITRATE}: ${e}`];
434
523
  return t.sendInfo(M.STATS, void 0, {
435
524
  noTerminateWhenError: !0,
436
- extraHeaders: i
525
+ extraHeaders: r
437
526
  });
438
527
  }
439
528
  async sendRefusalToTurnOn(e, t = {}) {
440
- const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${l.MEDIA_TYPE}: ${a}`];
529
+ const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${h.MEDIA_TYPE}: ${a}`];
441
530
  return s.sendInfo(M.REFUSAL, void 0, {
442
531
  noTerminateWhenError: !0,
443
532
  ...t,
@@ -452,38 +541,38 @@ class $e {
452
541
  }
453
542
  async sendMustStopPresentationP2P() {
454
543
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
455
- extraHeaders: [l.MUST_STOP_PRESENTATION_P2P]
544
+ extraHeaders: [h.MUST_STOP_PRESENTATION_P2P]
456
545
  });
457
546
  }
458
547
  async sendStoppedPresentationP2P() {
459
548
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
460
- extraHeaders: [l.STOP_PRESENTATION_P2P]
549
+ extraHeaders: [h.STOP_PRESENTATION_P2P]
461
550
  });
462
551
  }
463
552
  async sendStoppedPresentation() {
464
553
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
465
- extraHeaders: [l.STOP_PRESENTATION]
554
+ extraHeaders: [h.STOP_PRESENTATION]
466
555
  });
467
556
  }
468
557
  async askPermissionToStartPresentationP2P() {
469
558
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
470
- extraHeaders: [l.START_PRESENTATION_P2P]
559
+ extraHeaders: [h.START_PRESENTATION_P2P]
471
560
  });
472
561
  }
473
562
  async askPermissionToStartPresentation() {
474
563
  await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
475
- extraHeaders: [l.START_PRESENTATION]
564
+ extraHeaders: [h.START_PRESENTATION]
476
565
  });
477
566
  }
478
567
  async askPermissionToEnableCam(e = {}) {
479
- const t = this.getEstablishedRTCSessionProtected(), s = [l.ENABLE_MAIN_CAM];
568
+ const t = this.getEstablishedRTCSessionProtected(), s = [h.ENABLE_MAIN_CAM];
480
569
  return t.sendInfo(M.MAIN_CAM, void 0, {
481
570
  noTerminateWhenError: !0,
482
571
  ...e,
483
572
  extraHeaders: s
484
- }).catch((i) => {
485
- if (ke(i))
486
- throw i;
573
+ }).catch((r) => {
574
+ if (Fe(r))
575
+ throw r;
487
576
  });
488
577
  }
489
578
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
@@ -521,117 +610,121 @@ class $e {
521
610
  };
522
611
  maybeHandleNotify = (e) => {
523
612
  try {
524
- const t = e.getHeader(l.NOTIFY);
613
+ const t = e.getHeader(h.NOTIFY);
525
614
  if (t) {
526
615
  const s = JSON.parse(t);
527
616
  this.handleNotify(s);
528
617
  }
529
618
  } catch (t) {
530
- R("error parse notify", t);
619
+ E("error parse notify", t);
531
620
  }
532
621
  };
533
622
  handleNotify = (e) => {
534
623
  switch (e.cmd) {
535
- case _.CHANNELS: {
624
+ case m.CHANNELS: {
536
625
  const t = e;
537
626
  this.triggerChannelsNotify(t);
538
627
  break;
539
628
  }
540
- case _.WEBCAST_STARTED: {
629
+ case m.WEBCAST_STARTED: {
541
630
  const t = e;
542
631
  this.triggerWebcastStartedNotify(t);
543
632
  break;
544
633
  }
545
- case _.WEBCAST_STOPPED: {
634
+ case m.WEBCAST_STOPPED: {
546
635
  const t = e;
547
636
  this.triggerWebcastStoppedNotify(t);
548
637
  break;
549
638
  }
550
- case _.ADDED_TO_LIST_MODERATORS: {
639
+ case m.ADDED_TO_LIST_MODERATORS: {
551
640
  const t = e;
552
641
  this.triggerAddedToListModeratorsNotify(t);
553
642
  break;
554
643
  }
555
- case _.REMOVED_FROM_LIST_MODERATORS: {
644
+ case m.REMOVED_FROM_LIST_MODERATORS: {
556
645
  const t = e;
557
646
  this.triggerRemovedFromListModeratorsNotify(t);
558
647
  break;
559
648
  }
560
- case _.ACCEPTING_WORD_REQUEST: {
649
+ case m.ACCEPTING_WORD_REQUEST: {
561
650
  const t = e;
562
651
  this.triggerParticipationAcceptingWordRequest(t);
563
652
  break;
564
653
  }
565
- case _.CANCELLING_WORD_REQUEST: {
654
+ case m.CANCELLING_WORD_REQUEST: {
566
655
  const t = e;
567
656
  this.triggerParticipationCancellingWordRequest(t);
568
657
  break;
569
658
  }
570
- case _.MOVE_REQUEST_TO_STREAM: {
659
+ case m.MOVE_REQUEST_TO_STREAM: {
571
660
  const t = e;
572
661
  this.triggerParticipantMoveRequestToStream(t);
573
662
  break;
574
663
  }
575
- case _.ACCOUNT_CHANGED: {
664
+ case m.ACCOUNT_CHANGED: {
576
665
  this.triggerAccountChangedNotify();
577
666
  break;
578
667
  }
579
- case _.ACCOUNT_DELETED: {
668
+ case m.ACCOUNT_DELETED: {
580
669
  this.triggerAccountDeletedNotify();
581
670
  break;
582
671
  }
583
- case _.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
672
+ case m.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
584
673
  const t = e;
585
674
  this.triggerConferenceParticipantTokenIssued(t);
586
675
  break;
587
676
  }
588
677
  default:
589
- R("unknown cmd", e);
678
+ E("unknown cmd", e);
590
679
  }
591
680
  };
592
681
  handleNewInfo = (e) => {
593
682
  const { originator: t } = e;
594
- if (t !== $.REMOTE)
683
+ if (t !== F.REMOTE)
595
684
  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: {
685
+ const { request: s } = e, r = s.getHeader(h.CONTENT_TYPE);
686
+ if (r !== void 0)
687
+ switch (r) {
688
+ case v.ENTER_ROOM: {
600
689
  this.triggerEnterRoom(s), this.maybeTriggerChannels(s);
601
690
  break;
602
691
  }
603
- case O.NOTIFY: {
692
+ case v.NOTIFY: {
604
693
  this.maybeHandleNotify(s);
605
694
  break;
606
695
  }
607
- case O.SHARE_STATE: {
696
+ case v.SHARE_STATE: {
608
697
  this.triggerShareState(s);
609
698
  break;
610
699
  }
611
- case O.MAIN_CAM: {
700
+ case v.MAIN_CAM: {
612
701
  this.triggerMainCamControl(s);
613
702
  break;
614
703
  }
615
- case O.MIC: {
704
+ case v.MIC: {
616
705
  this.triggerMicControl(s);
617
706
  break;
618
707
  }
619
- case O.USE_LICENSE: {
708
+ case v.USE_LICENSE: {
620
709
  this.triggerUseLicense(s);
621
710
  break;
622
711
  }
623
- case O.PARTICIPANT_STATE: {
712
+ case v.PARTICIPANT_STATE: {
624
713
  this.maybeTriggerParticipantMoveRequest(s);
625
714
  break;
626
715
  }
716
+ case v.RESTART: {
717
+ this.triggerRestart(s);
718
+ break;
719
+ }
627
720
  }
628
721
  };
629
722
  triggerChannelsNotify = (e) => {
630
- const t = e.input, s = e.output, i = {
723
+ const t = e.input, s = e.output, r = {
631
724
  inputChannels: t,
632
725
  outputChannels: s
633
726
  };
634
- this.events.trigger(g.CHANNELS_NOTIFY, i);
727
+ this.events.trigger(l.CHANNELS_NOTIFY, r);
635
728
  };
636
729
  triggerWebcastStartedNotify = ({
637
730
  body: { conference: e, type: t }
@@ -640,7 +733,7 @@ class $e {
640
733
  conference: e,
641
734
  type: t
642
735
  };
643
- this.events.trigger(g.WEBCAST_STARTED, s);
736
+ this.events.trigger(l.WEBCAST_STARTED, s);
644
737
  };
645
738
  triggerWebcastStoppedNotify = ({
646
739
  body: { conference: e, type: t }
@@ -649,7 +742,7 @@ class $e {
649
742
  conference: e,
650
743
  type: t
651
744
  };
652
- this.events.trigger(g.WEBCAST_STOPPED, s);
745
+ this.events.trigger(l.WEBCAST_STOPPED, s);
653
746
  };
654
747
  triggerAddedToListModeratorsNotify = ({
655
748
  conference: e
@@ -658,7 +751,7 @@ class $e {
658
751
  conference: e
659
752
  };
660
753
  this.events.trigger(
661
- g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
754
+ l.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
662
755
  t
663
756
  );
664
757
  };
@@ -669,7 +762,7 @@ class $e {
669
762
  conference: e
670
763
  };
671
764
  this.events.trigger(
672
- g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
765
+ l.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
673
766
  t
674
767
  );
675
768
  };
@@ -679,7 +772,7 @@ class $e {
679
772
  const t = {
680
773
  conference: e
681
774
  };
682
- this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
775
+ this.events.trigger(l.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
683
776
  };
684
777
  triggerParticipationCancellingWordRequest = ({
685
778
  body: { conference: e }
@@ -687,7 +780,7 @@ class $e {
687
780
  const t = {
688
781
  conference: e
689
782
  };
690
- this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
783
+ this.events.trigger(l.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
691
784
  };
692
785
  triggerParticipantMoveRequestToStream = ({
693
786
  body: { conference: e }
@@ -695,120 +788,130 @@ class $e {
695
788
  const t = {
696
789
  conference: e
697
790
  };
698
- this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
791
+ this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
699
792
  };
700
793
  triggerAccountChangedNotify = () => {
701
- this.events.trigger(g.ACCOUNT_CHANGED, void 0);
794
+ this.events.trigger(l.ACCOUNT_CHANGED, void 0);
702
795
  };
703
796
  triggerAccountDeletedNotify = () => {
704
- this.events.trigger(g.ACCOUNT_DELETED, void 0);
797
+ this.events.trigger(l.ACCOUNT_DELETED, void 0);
705
798
  };
706
799
  triggerConferenceParticipantTokenIssued = ({
707
800
  body: { conference: e, participant: t, jwt: s }
708
801
  }) => {
709
- const i = {
802
+ const r = {
710
803
  conference: e,
711
804
  participant: t,
712
805
  jwt: s
713
806
  };
714
807
  this.events.trigger(
715
- g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
716
- i
808
+ l.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
809
+ r
717
810
  );
718
811
  };
719
812
  maybeTriggerChannels = (e) => {
720
- const t = e.getHeader(l.INPUT_CHANNELS), s = e.getHeader(l.OUTPUT_CHANNELS);
813
+ const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
721
814
  if (t && s) {
722
- const i = {
815
+ const r = {
723
816
  inputChannels: t,
724
817
  outputChannels: s
725
818
  };
726
- this.events.trigger(g.CHANNELS, i);
819
+ this.events.trigger(l.CHANNELS, r);
727
820
  }
728
821
  };
729
822
  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 });
823
+ const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
824
+ this.events.trigger(l.ENTER_ROOM, { room: t, participantName: s });
732
825
  };
733
826
  triggerShareState = (e) => {
734
- const t = e.getHeader(l.CONTENT_SHARE_STATE);
827
+ const t = e.getHeader(h.CONTENT_SHARE_STATE);
735
828
  if (t !== void 0)
736
829
  switch (t) {
737
- case k.AVAILABLE_SECOND_REMOTE_STREAM: {
738
- this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
830
+ case B.AVAILABLE_SECOND_REMOTE_STREAM: {
831
+ this.events.trigger(l.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
739
832
  break;
740
833
  }
741
- case k.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
742
- this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
834
+ case B.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
835
+ this.events.trigger(l.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
743
836
  break;
744
837
  }
745
- case k.MUST_STOP_PRESENTATION: {
746
- this.events.trigger(g.MUST_STOP_PRESENTATION, void 0);
838
+ case B.MUST_STOP_PRESENTATION: {
839
+ this.events.trigger(l.MUST_STOP_PRESENTATION, void 0);
747
840
  break;
748
841
  }
749
842
  }
750
843
  };
751
844
  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);
845
+ const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
846
+ t === k.SPECTATOR && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === k.PARTICIPANT && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0), t === k.SPECTATOR_OVER_SFU && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU, void 0);
754
847
  };
755
848
  triggerMainCamControl = (e) => {
756
- const t = e.getHeader(l.MAIN_CAM), s = e.getHeader(l.MEDIA_SYNC), i = s === H.ADMIN_SYNC_FORCED;
849
+ const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), r = s === H.ADMIN_SYNC_FORCED;
757
850
  if (t === P.ADMIN_START_MAIN_CAM) {
758
- this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: i });
851
+ this.events.trigger(l.ADMIN_START_MAIN_CAM, { isSyncForced: r });
759
852
  return;
760
853
  }
761
854
  if (t === P.ADMIN_STOP_MAIN_CAM) {
762
- this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
855
+ this.events.trigger(l.ADMIN_STOP_MAIN_CAM, { isSyncForced: r });
763
856
  return;
764
857
  }
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, {
858
+ (t === P.RESUME_MAIN_CAM || t === P.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(l.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: r });
859
+ const i = e.getHeader(h.MAIN_CAM_RESOLUTION);
860
+ this.events.trigger(l.MAIN_CAM_CONTROL, {
768
861
  mainCam: t,
769
- resolutionMainCam: r
862
+ resolutionMainCam: i
770
863
  });
771
864
  };
772
865
  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 });
866
+ const t = e.getHeader(h.MIC), r = e.getHeader(h.MEDIA_SYNC) === H.ADMIN_SYNC_FORCED;
867
+ 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
868
  };
776
869
  triggerUseLicense = (e) => {
777
- const t = e.getHeader(l.CONTENT_USE_LICENSE);
778
- this.events.trigger(g.USE_LICENSE, t);
870
+ const t = e.getHeader(h.CONTENT_USE_LICENSE);
871
+ this.events.trigger(l.USE_LICENSE, t);
872
+ };
873
+ triggerRestart = (e) => {
874
+ const t = e.getHeader(
875
+ h.TRACKS_DIRECTION
876
+ ), s = Number(
877
+ e.getHeader(h.AUDIO_TRACK_COUNT)
878
+ ), r = Number(
879
+ e.getHeader(h.VIDEO_TRACK_COUNT)
880
+ ), i = { tracksDirection: t, audioTrackCount: s, videoTrackCount: r };
881
+ this.events.trigger(l.RESTART, i);
779
882
  };
780
883
  }
781
- const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We = (n, e) => {
884
+ const We = (n, e) => (n.degradationPreference = e.degradationPreference, n), He = (n, e) => {
782
885
  n.encodings ??= [];
783
886
  for (let t = n.encodings.length; t < e; t += 1)
784
887
  n.encodings.push({});
785
888
  return n;
786
- }, ae = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, He = ae(), xe = (n, e) => {
787
- if (He(n, e))
889
+ }, ae = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, xe = ae(), qe = (n, e) => {
890
+ if (xe(n, e))
788
891
  return n;
789
- }, qe = (n, e) => {
790
- const t = n.maxBitrate, s = xe(e, t);
892
+ }, Ge = (n, e) => {
893
+ const t = n.maxBitrate, s = qe(e, t);
791
894
  return s !== void 0 && (n.maxBitrate = s), n;
792
- }, oe = 1, Ge = ae(
895
+ }, oe = 1, Qe = ae(
793
896
  oe
794
- ), Qe = (n, e) => {
897
+ ), Ye = (n, e) => {
795
898
  const t = n === void 0 ? void 0 : Math.max(n, oe);
796
- if (t !== void 0 && Ge(
899
+ if (t !== void 0 && Qe(
797
900
  t,
798
901
  e
799
902
  ))
800
903
  return t;
801
- }, Ye = (n, e) => {
802
- const t = n.scaleResolutionDownBy, s = Qe(
904
+ }, ze = (n, e) => {
905
+ const t = n.scaleResolutionDownBy, s = Ye(
803
906
  e,
804
907
  t
805
908
  );
806
909
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
807
- }, ze = (n, e) => {
910
+ }, Xe = (n, e) => {
808
911
  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;
811
- qe(s, a), Ye(s, o);
912
+ return He(n, t), n.encodings.forEach((s, r) => {
913
+ const i = (e?.encodings ?? [])[r], a = i?.maxBitrate, o = i?.scaleResolutionDownBy;
914
+ Ge(s, a), ze(s, o);
812
915
  }), n;
813
916
  }, Je = (n, e) => {
814
917
  if (n.codecs?.length !== e.codecs?.length)
@@ -827,15 +930,15 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
827
930
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
828
931
  return !0;
829
932
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
830
- }, Xe = async (n, e) => {
933
+ }, Ke = async (n, e) => {
831
934
  const t = n.getParameters(), s = JSON.parse(
832
935
  JSON.stringify(t)
833
936
  );
834
- ze(t, e), Ve(t, e);
835
- const i = Je(s, t);
836
- return i && await n.setParameters(t), { parameters: t, isChanged: i };
937
+ Xe(t, e), We(t, e);
938
+ const r = Je(s, t);
939
+ return r && await n.setParameters(t), { parameters: t, isChanged: r };
837
940
  }, ce = async (n, e, t) => {
838
- const { isChanged: s, parameters: i } = await Xe(n, {
941
+ const { isChanged: s, parameters: r } = await Ke(n, {
839
942
  encodings: [
840
943
  {
841
944
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -843,8 +946,8 @@ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We
843
946
  }
844
947
  ]
845
948
  });
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) => {
949
+ return s && t && t(r), { isChanged: s, parameters: r };
950
+ }, je = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ze = async (n, e, t) => {
848
951
  const s = je(n, e);
849
952
  if (s)
850
953
  return ce(s, { maxBitrate: t });
@@ -856,8 +959,8 @@ const de = [
856
959
  "presentation:end",
857
960
  "presentation:ended",
858
961
  "presentation:failed"
859
- ], Ze = 1, En = (n) => Ie(n);
860
- class et {
962
+ ], et = 1, En = (n) => Ie(n);
963
+ class tt {
861
964
  events;
862
965
  promisePendingStartPresentation;
863
966
  promisePendingStopPresentation;
@@ -877,8 +980,8 @@ class et {
877
980
  // eslint-disable-next-line @typescript-eslint/max-params
878
981
  async startPresentation(e, t, {
879
982
  isNeedReinvite: s,
880
- contentHint: i,
881
- sendEncodings: r,
983
+ contentHint: r,
984
+ sendEncodings: i,
882
985
  onAddedTransceiver: a
883
986
  } = {}, o) {
884
987
  const c = this.getRtcSessionProtected();
@@ -889,8 +992,8 @@ class et {
889
992
  stream: t,
890
993
  presentationOptions: {
891
994
  isNeedReinvite: s,
892
- contentHint: i,
893
- sendEncodings: r,
995
+ contentHint: r,
996
+ sendEncodings: i,
894
997
  onAddedTransceiver: a
895
998
  },
896
999
  options: o
@@ -902,17 +1005,17 @@ class et {
902
1005
  let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
903
1006
  this.promisePendingStartPresentation && await this.promisePendingStartPresentation.catch(() => {
904
1007
  });
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;
1008
+ const r = this.callManager.getEstablishedRTCSession();
1009
+ return r && t ? s = e().then(async () => r.stopPresentation(t)).catch((i) => {
1010
+ throw this.events.trigger(f.FAILED_PRESENTATION, i), i;
908
1011
  }) : t && this.events.trigger(f.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
909
1012
  this.resetPresentation();
910
1013
  });
911
1014
  }
912
1015
  async updatePresentation(e, t, {
913
1016
  contentHint: s,
914
- sendEncodings: i,
915
- onAddedTransceiver: r
1017
+ sendEncodings: r,
1018
+ onAddedTransceiver: i
916
1019
  } = {}) {
917
1020
  const a = this.getRtcSessionProtected();
918
1021
  if (!this.streamPresentationCurrent)
@@ -920,8 +1023,8 @@ class et {
920
1023
  return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
921
1024
  contentHint: s,
922
1025
  isNeedReinvite: !1,
923
- sendEncodings: i,
924
- onAddedTransceiver: r
1026
+ sendEncodings: r,
1027
+ onAddedTransceiver: i
925
1028
  }).then(async (o) => (await this.setMaxBitrate(), o));
926
1029
  }
927
1030
  cancelSendPresentationWithRepeatedCalls() {
@@ -962,37 +1065,37 @@ class et {
962
1065
  async sendPresentationWithDuplicatedCalls(e, {
963
1066
  rtcSession: t,
964
1067
  stream: s,
965
- presentationOptions: i,
966
- options: r = {
967
- callLimit: Ze
1068
+ presentationOptions: r,
1069
+ options: i = {
1070
+ callLimit: et
968
1071
  }
969
1072
  }) {
970
1073
  const a = async () => this.sendPresentation(
971
1074
  e,
972
1075
  t,
973
1076
  s,
974
- i
1077
+ r
975
1078
  ), o = () => !!this.streamPresentationCurrent;
976
- return this.cancelableSendPresentationWithRepeatedCalls = K({
1079
+ return this.cancelableSendPresentationWithRepeatedCalls = j({
977
1080
  targetFunction: a,
978
1081
  isComplete: o,
979
1082
  isRejectAsValid: !0,
980
- ...r
1083
+ ...i
981
1084
  }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
982
1085
  }
983
1086
  // eslint-disable-next-line @typescript-eslint/max-params
984
1087
  async sendPresentation(e, t, s, {
985
- isNeedReinvite: i = !0,
986
- contentHint: r = "detail",
1088
+ isNeedReinvite: r = !0,
1089
+ contentHint: i = "detail",
987
1090
  degradationPreference: a,
988
1091
  sendEncodings: o,
989
1092
  onAddedTransceiver: c
990
1093
  }) {
991
- const d = B(s, { contentHint: r });
1094
+ const d = L(s, { contentHint: i });
992
1095
  if (d === void 0)
993
1096
  throw new Error("No streamPresentationTarget");
994
1097
  this.streamPresentationCurrent = d;
995
- const u = e().then(async () => t.startPresentation(d, i, {
1098
+ const u = e().then(async () => t.startPresentation(d, r, {
996
1099
  degradationPreference: a,
997
1100
  sendEncodings: o,
998
1101
  onAddedTransceiver: c
@@ -1007,8 +1110,8 @@ class et {
1007
1110
  const { connection: e } = this.callManager, { streamPresentationCurrent: t } = this, { maxBitrate: s } = this;
1008
1111
  if (!e || !t || s === void 0)
1009
1112
  return;
1010
- const i = e.getSenders();
1011
- await Ke(i, t, s);
1113
+ const r = e.getSenders();
1114
+ await Ze(r, t, s);
1012
1115
  };
1013
1116
  getRtcSessionProtected = () => {
1014
1117
  const e = this.callManager.getEstablishedRTCSession();
@@ -1029,7 +1132,7 @@ class et {
1029
1132
  delete this.streamPresentationCurrent;
1030
1133
  }
1031
1134
  }
1032
- class tt {
1135
+ class nt {
1033
1136
  data = {};
1034
1137
  getUa;
1035
1138
  constructor(e) {
@@ -1102,7 +1205,7 @@ class tt {
1102
1205
  return this.data.register === !0;
1103
1206
  }
1104
1207
  }
1105
- 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 || {});
1208
+ var A = /* @__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))(A || {});
1106
1209
  const he = [
1107
1210
  "connecting",
1108
1211
  "connected",
@@ -1113,8 +1216,8 @@ const he = [
1113
1216
  "registrationFailed",
1114
1217
  "newMessage",
1115
1218
  "sipEvent"
1116
- ], ge = [...he], nt = 3;
1117
- class st {
1219
+ ], ge = [...he], st = 3;
1220
+ class rt {
1118
1221
  cancelableConnectWithRepeatedCalls;
1119
1222
  JsSIP;
1120
1223
  events;
@@ -1133,93 +1236,93 @@ class st {
1133
1236
  }
1134
1237
  connect = async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t));
1135
1238
  set = async ({ displayName: e }) => new Promise((t, s) => {
1136
- const i = this.getUa();
1137
- if (!i) {
1239
+ const r = this.getUa();
1240
+ if (!r) {
1138
1241
  s(new Error("this.ua is not initialized"));
1139
1242
  return;
1140
1243
  }
1141
- let r = !1;
1244
+ let i = !1;
1142
1245
  const a = this.getConnectionConfiguration();
1143
- e !== void 0 && e !== a.displayName && (r = i.set("display_name", se(e)), this.updateConnectionConfiguration("displayName", e));
1144
- const o = r;
1246
+ e !== void 0 && e !== a.displayName && (i = r.set("display_name", se(e)), this.updateConnectionConfiguration("displayName", e));
1247
+ const o = i;
1145
1248
  o ? t(o) : s(new Error("nothing changed"));
1146
1249
  });
1147
1250
  disconnect = async () => {
1148
1251
  const e = new Promise((s) => {
1149
- this.events.once(N.DISCONNECTED, () => {
1252
+ this.events.once(A.DISCONNECTED, () => {
1150
1253
  s();
1151
1254
  });
1152
1255
  }), t = this.getUa();
1153
- return t ? t.stop() : this.events.trigger(N.DISCONNECTED, void 0), e.finally(() => {
1256
+ return t ? t.stop() : this.events.trigger(A.DISCONNECTED, void 0), e.finally(() => {
1154
1257
  this.setUa(void 0), this.stateMachine.reset();
1155
1258
  });
1156
1259
  };
1157
1260
  cancelRequests() {
1158
1261
  this.cancelConnectWithRepeatedCalls();
1159
1262
  }
1160
- 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);
1263
+ connectWithDuplicatedCalls = async (e, { callLimit: t = st } = {}) => {
1264
+ const s = async () => this.connectInner(e), r = (i) => {
1265
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = i != null && !ke(i);
1163
1266
  return c || d;
1164
1267
  };
1165
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = K({
1268
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = j({
1166
1269
  targetFunction: s,
1167
- isComplete: i,
1270
+ isComplete: r,
1168
1271
  callLimit: t,
1169
1272
  isRejectAsValid: !0,
1170
1273
  isCheckBeforeCall: !1
1171
- }), this.cancelableConnectWithRepeatedCalls.then((r) => {
1172
- if (r instanceof this.JsSIP.UA)
1173
- return r;
1174
- throw r;
1274
+ }), this.cancelableConnectWithRepeatedCalls.then((i) => {
1275
+ if (i instanceof this.JsSIP.UA)
1276
+ return i;
1277
+ throw i;
1175
1278
  });
1176
1279
  };
1177
1280
  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;
1281
+ const { configuration: t } = this.uaFactory.createConfiguration(e), r = this.getUa()?.configuration;
1282
+ 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
1283
  }
1181
1284
  connectInner = async (e) => this.initUa(e).then(async () => this.start());
1182
1285
  initUa = async ({
1183
1286
  user: e,
1184
1287
  password: t,
1185
1288
  sipServerUrl: s,
1186
- sipWebSocketServerURL: i,
1187
- remoteAddress: r,
1289
+ sipWebSocketServerURL: r,
1290
+ remoteAddress: i,
1188
1291
  sessionTimers: a,
1189
1292
  registerExpires: o,
1190
1293
  connectionRecoveryMinInterval: c,
1191
1294
  connectionRecoveryMaxInterval: d,
1192
1295
  userAgent: u,
1193
1296
  displayName: T = "",
1194
- register: h = !1,
1297
+ register: g = !1,
1195
1298
  extraHeaders: S = []
1196
1299
  }) => {
1197
1300
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1198
1301
  sipServerUrl: s,
1199
1302
  displayName: T,
1200
- register: h,
1303
+ register: g,
1201
1304
  user: e,
1202
1305
  password: t
1203
1306
  }), this.getUa() && await this.disconnect();
1204
- const { ua: I, helpers: A } = this.uaFactory.createUAWithConfiguration(
1307
+ const { ua: _, helpers: R } = this.uaFactory.createUAWithConfiguration(
1205
1308
  {
1206
1309
  user: e,
1207
1310
  password: t,
1208
1311
  sipServerUrl: s,
1209
- sipWebSocketServerURL: i,
1312
+ sipWebSocketServerURL: r,
1210
1313
  displayName: T,
1211
- register: h,
1314
+ register: g,
1212
1315
  sessionTimers: a,
1213
1316
  registerExpires: o,
1214
1317
  connectionRecoveryMinInterval: c,
1215
1318
  connectionRecoveryMaxInterval: d,
1216
1319
  userAgent: u,
1217
- remoteAddress: r,
1320
+ remoteAddress: i,
1218
1321
  extraHeaders: S
1219
1322
  },
1220
1323
  this.events
1221
1324
  );
1222
- return this.setUa(I), this.setSipServerUrl(A.getSipServerUrl), this.setSocket(A.socket), I;
1325
+ return this.setUa(_), this.setSipServerUrl(R.getSipServerUrl), this.setSocket(R.socket), _;
1223
1326
  };
1224
1327
  start = async () => new Promise((e, t) => {
1225
1328
  const s = this.getUa();
@@ -1227,22 +1330,22 @@ class st {
1227
1330
  t(new Error("this.ua is not initialized"));
1228
1331
  return;
1229
1332
  }
1230
- let i;
1231
- i = ((c, d) => {
1333
+ let r;
1334
+ r = ((c, d) => {
1232
1335
  if (this.getConnectionConfiguration().register === !0)
1233
1336
  return this.registrationManager.subscribeToStartEvents(c, d);
1234
- const T = N.CONNECTED, h = [N.DISCONNECTED];
1235
- return this.events.on(T, c), h.forEach((S) => {
1337
+ const T = A.CONNECTED, g = [A.DISCONNECTED];
1338
+ return this.events.on(T, c), g.forEach((S) => {
1236
1339
  this.events.on(S, d);
1237
1340
  }), () => {
1238
- this.events.off(T, c), h.forEach((S) => {
1341
+ this.events.off(T, c), g.forEach((S) => {
1239
1342
  this.events.off(S, d);
1240
1343
  });
1241
1344
  };
1242
1345
  })(() => {
1243
- i?.(), e(s);
1346
+ r?.(), e(s);
1244
1347
  }, (c) => {
1245
- i?.(), t(c);
1348
+ r?.(), t(c);
1246
1349
  }), s.start();
1247
1350
  });
1248
1351
  cancelConnectWithRepeatedCalls() {
@@ -1257,10 +1360,10 @@ const it = _e({
1257
1360
  },
1258
1361
  actions: {
1259
1362
  logTransition: (n, e) => {
1260
- R(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1363
+ E(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1261
1364
  },
1262
1365
  logStateChange: (n, e) => {
1263
- R("ConnectionStateMachine state changed", e.state);
1366
+ E("ConnectionStateMachine state changed", e.state);
1264
1367
  }
1265
1368
  }
1266
1369
  }).createMachine({
@@ -1564,17 +1667,17 @@ const it = _e({
1564
1667
  }
1565
1668
  }
1566
1669
  });
1567
- class rt {
1670
+ class at {
1568
1671
  actor;
1569
1672
  stateChangeListeners = /* @__PURE__ */ new Set();
1570
1673
  events;
1571
1674
  unsubscribeFromEvents;
1572
1675
  actorSubscription;
1573
1676
  constructor(e) {
1574
- this.events = e, this.actor = Me(it), this.actorSubscription = this.actor.subscribe((t) => {
1677
+ this.events = e, this.actor = me(it), this.actorSubscription = this.actor.subscribe((t) => {
1575
1678
  const s = t.value;
1576
- this.stateChangeListeners.forEach((i) => {
1577
- i(s);
1679
+ this.stateChangeListeners.forEach((r) => {
1680
+ r(s);
1578
1681
  });
1579
1682
  }), this.actor.start(), this.subscribeToEvents();
1580
1683
  }
@@ -1665,7 +1768,7 @@ class rt {
1665
1768
  sendEvent(e) {
1666
1769
  const t = this.actor.getSnapshot(), s = { type: e };
1667
1770
  if (!t.can(s)) {
1668
- R(
1771
+ E(
1669
1772
  `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
1670
1773
  );
1671
1774
  return;
@@ -1726,7 +1829,7 @@ class rt {
1726
1829
  };
1727
1830
  }
1728
1831
  }
1729
- class at {
1832
+ class ot {
1730
1833
  events;
1731
1834
  getUaProtected;
1732
1835
  constructor(e) {
@@ -1735,35 +1838,35 @@ class at {
1735
1838
  async register() {
1736
1839
  const e = this.getUaProtected();
1737
1840
  return new Promise((t, s) => {
1738
- e.on(N.REGISTERED, t), e.on(N.REGISTRATION_FAILED, s), e.register();
1841
+ e.on(A.REGISTERED, t), e.on(A.REGISTRATION_FAILED, s), e.register();
1739
1842
  });
1740
1843
  }
1741
1844
  async unregister() {
1742
1845
  const e = this.getUaProtected();
1743
1846
  return new Promise((t) => {
1744
- e.on(N.UNREGISTERED, t), e.unregister();
1847
+ e.on(A.UNREGISTERED, t), e.unregister();
1745
1848
  });
1746
1849
  }
1747
1850
  async tryRegister() {
1748
1851
  try {
1749
1852
  await this.unregister();
1750
1853
  } catch (e) {
1751
- R("tryRegister", e);
1854
+ E("tryRegister", e);
1752
1855
  }
1753
1856
  return this.register();
1754
1857
  }
1755
1858
  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);
1859
+ const s = A.REGISTERED, r = [A.REGISTRATION_FAILED, A.DISCONNECTED];
1860
+ return this.events.on(s, e), r.forEach((i) => {
1861
+ this.events.on(i, t);
1759
1862
  }), () => {
1760
- this.events.off(s, e), i.forEach((r) => {
1761
- this.events.off(r, t);
1863
+ this.events.off(s, e), r.forEach((i) => {
1864
+ this.events.off(i, t);
1762
1865
  });
1763
1866
  };
1764
1867
  }
1765
1868
  }
1766
- class ot {
1869
+ class ct {
1767
1870
  uaFactory;
1768
1871
  getUaProtected;
1769
1872
  constructor(e) {
@@ -1773,14 +1876,14 @@ class ot {
1773
1876
  * Отправляет SIP OPTIONS запрос к указанному адресу
1774
1877
  */
1775
1878
  async sendOptions(e, t, s) {
1776
- const i = this.getUaProtected();
1777
- return new Promise((r, a) => {
1879
+ const r = this.getUaProtected();
1880
+ return new Promise((i, a) => {
1778
1881
  try {
1779
- i.sendOptions(e, t, {
1882
+ r.sendOptions(e, t, {
1780
1883
  extraHeaders: s,
1781
1884
  eventHandlers: {
1782
1885
  succeeded: () => {
1783
- r();
1886
+ i();
1784
1887
  },
1785
1888
  failed: a
1786
1889
  }
@@ -1794,8 +1897,8 @@ class ot {
1794
1897
  * Отправляет SIP OPTIONS запрос к собственному URI (ping)
1795
1898
  */
1796
1899
  async ping(e, t) {
1797
- const i = this.getUaProtected().configuration.uri;
1798
- return this.sendOptions(i, e, t);
1900
+ const r = this.getUaProtected().configuration.uri;
1901
+ return this.sendOptions(r, e, t);
1799
1902
  }
1800
1903
  /**
1801
1904
  * Проверяет доступность телефонии, создавая временное соединение
@@ -1804,35 +1907,35 @@ class ot {
1804
1907
  userAgent: e,
1805
1908
  displayName: t,
1806
1909
  sipServerUrl: s,
1807
- sipWebSocketServerURL: i,
1808
- remoteAddress: r,
1910
+ sipWebSocketServerURL: r,
1911
+ remoteAddress: i,
1809
1912
  extraHeaders: a
1810
1913
  }) {
1811
1914
  return new Promise((o, c) => {
1812
1915
  const { configuration: d } = this.uaFactory.createConfiguration({
1813
- sipWebSocketServerURL: i,
1916
+ sipWebSocketServerURL: r,
1814
1917
  displayName: t,
1815
1918
  userAgent: e,
1816
1919
  sipServerUrl: s
1817
- }), u = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), T = () => {
1920
+ }), u = this.uaFactory.createUA({ ...d, remoteAddress: i, extraHeaders: a }), T = () => {
1818
1921
  const S = new Error("Telephony is not available");
1819
1922
  c(S);
1820
1923
  };
1821
- u.once(N.DISCONNECTED, T);
1822
- const h = () => {
1823
- u.removeAllListeners(), u.once(N.DISCONNECTED, () => {
1924
+ u.once(A.DISCONNECTED, T);
1925
+ const g = () => {
1926
+ u.removeAllListeners(), u.once(A.DISCONNECTED, () => {
1824
1927
  o();
1825
1928
  }), u.stop();
1826
1929
  };
1827
- u.once(N.CONNECTED, h), u.start();
1930
+ u.once(A.CONNECTED, g), u.start();
1828
1931
  });
1829
1932
  }
1830
1933
  }
1831
- const ct = (n) => {
1934
+ const dt = (n) => {
1832
1935
  const e = [];
1833
1936
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1834
1937
  };
1835
- class v {
1938
+ class O {
1836
1939
  JsSIP;
1837
1940
  constructor(e) {
1838
1941
  this.JsSIP = e;
@@ -1844,12 +1947,12 @@ class v {
1844
1947
  register: e,
1845
1948
  password: t,
1846
1949
  user: s,
1847
- sipServerUrl: i,
1848
- sipWebSocketServerURL: r
1950
+ sipServerUrl: r,
1951
+ sipWebSocketServerURL: i
1849
1952
  }) {
1850
- if (!i)
1851
- throw new Error("sipServerUrl is required");
1852
1953
  if (!r)
1954
+ throw new Error("sipServerUrl is required");
1955
+ if (!i)
1853
1956
  throw new Error("sipWebSocketServerURL is required");
1854
1957
  if (e && (t === void 0 || t === ""))
1855
1958
  throw new Error("password is required for authorized connection");
@@ -1857,18 +1960,18 @@ class v {
1857
1960
  throw new Error("user is required for authorized connection");
1858
1961
  }
1859
1962
  static resolveAuthorizationUser(e, t) {
1860
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${Oe()}`;
1963
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${fe()}`;
1861
1964
  }
1862
1965
  static buildExtraHeaders(e, t) {
1863
- const s = e !== void 0 && e !== "" ? ct(e) : [];
1966
+ const s = e !== void 0 && e !== "" ? dt(e) : [];
1864
1967
  return t === void 0 ? s : [...s, ...t];
1865
1968
  }
1866
1969
  createConfiguration({
1867
1970
  user: e,
1868
1971
  password: t,
1869
1972
  sipWebSocketServerURL: s,
1870
- displayName: i = "",
1871
- sipServerUrl: r,
1973
+ displayName: r = "",
1974
+ sipServerUrl: i,
1872
1975
  register: a = !1,
1873
1976
  sessionTimers: o = !1,
1874
1977
  registerExpires: c = 300,
@@ -1877,54 +1980,54 @@ class v {
1877
1980
  connectionRecoveryMaxInterval: u = 6,
1878
1981
  userAgent: T
1879
1982
  }) {
1880
- v.validateConfiguration({
1983
+ O.validateConfiguration({
1881
1984
  register: a,
1882
1985
  password: t,
1883
1986
  user: e,
1884
- sipServerUrl: r,
1987
+ sipServerUrl: i,
1885
1988
  sipWebSocketServerURL: s
1886
1989
  });
1887
- const h = v.resolveAuthorizationUser(a, e), S = Pe(r), m = S(h), I = new this.JsSIP.WebSocketInterface(s);
1990
+ const g = O.resolveAuthorizationUser(a, e), S = Pe(i), I = S(g), _ = new this.JsSIP.WebSocketInterface(s);
1888
1991
  return {
1889
1992
  configuration: {
1890
1993
  password: t,
1891
1994
  register: a,
1892
- uri: m,
1893
- display_name: se(i),
1995
+ uri: I,
1996
+ display_name: se(r),
1894
1997
  user_agent: T,
1895
1998
  sdpSemantics: "unified-plan",
1896
- sockets: [I],
1999
+ sockets: [_],
1897
2000
  session_timers: o,
1898
2001
  register_expires: c,
1899
2002
  connection_recovery_min_interval: d,
1900
2003
  connection_recovery_max_interval: u
1901
2004
  },
1902
2005
  helpers: {
1903
- socket: I,
2006
+ socket: _,
1904
2007
  getSipServerUrl: S
1905
2008
  }
1906
2009
  };
1907
2010
  }
1908
2011
  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;
2012
+ const r = new this.JsSIP.UA(s), i = O.buildExtraHeaders(e, t);
2013
+ return i.length > 0 && r.registrator().setExtraHeaders(i), r;
1911
2014
  }
1912
2015
  /**
1913
2016
  * Создает UA с полным жизненным циклом - конфигурация + создание + настройка событий
1914
2017
  */
1915
2018
  createUAWithConfiguration(e, t) {
1916
- const { configuration: s, helpers: i } = this.createConfiguration(e), r = this.createUA({
2019
+ const { configuration: s, helpers: r } = this.createConfiguration(e), i = this.createUA({
1917
2020
  ...s,
1918
2021
  remoteAddress: e.remoteAddress,
1919
2022
  extraHeaders: e.extraHeaders
1920
2023
  });
1921
2024
  return t.eachTriggers((a, o) => {
1922
2025
  const c = he.find((d) => d === o);
1923
- c && r.on(c, a);
1924
- }), { ua: r, helpers: i };
2026
+ c && i.on(c, a);
2027
+ }), { ua: i, helpers: r };
1925
2028
  }
1926
2029
  }
1927
- class dt {
2030
+ class ht {
1928
2031
  events;
1929
2032
  ua;
1930
2033
  socket;
@@ -1936,15 +2039,15 @@ class dt {
1936
2039
  configurationManager;
1937
2040
  JsSIP;
1938
2041
  constructor({ JsSIP: e }) {
1939
- this.JsSIP = e, this.events = new D(ge), this.uaFactory = new v(e), this.registrationManager = new at({
2042
+ this.JsSIP = e, this.events = new D(ge), this.uaFactory = new O(e), this.registrationManager = new ot({
1940
2043
  events: this.events,
1941
2044
  getUaProtected: this.getUaProtected
1942
- }), this.stateMachine = new rt(this.events), this.configurationManager = new tt({
2045
+ }), this.stateMachine = new at(this.events), this.configurationManager = new nt({
1943
2046
  getUa: this.getUa
1944
- }), this.sipOperations = new ot({
2047
+ }), this.sipOperations = new ct({
1945
2048
  uaFactory: this.uaFactory,
1946
2049
  getUaProtected: this.getUaProtected
1947
- }), this.connectionFlow = new st({
2050
+ }), this.connectionFlow = new rt({
1948
2051
  JsSIP: this.JsSIP,
1949
2052
  events: this.events,
1950
2053
  uaFactory: this.uaFactory,
@@ -1982,7 +2085,7 @@ class dt {
1982
2085
  return this.stateMachine.state;
1983
2086
  }
1984
2087
  get isRegistered() {
1985
- return v.isRegisteredUA(this.ua);
2088
+ return O.isRegisteredUA(this.ua);
1986
2089
  }
1987
2090
  get isRegisterConfig() {
1988
2091
  return this.configurationManager.isRegister();
@@ -2035,7 +2138,7 @@ class dt {
2035
2138
  };
2036
2139
  getUa = () => this.ua;
2037
2140
  }
2038
- class ht {
2141
+ class gt {
2039
2142
  connectionManager;
2040
2143
  stackPromises = Z({
2041
2144
  noRunIsNotActual: !0
@@ -2059,8 +2162,8 @@ const ue = [
2059
2162
  "declinedIncomingCall",
2060
2163
  "terminatedIncomingCall",
2061
2164
  "failedIncomingCall"
2062
- ], gt = 486, lt = 487;
2063
- class ut {
2165
+ ], lt = 486, ut = 487;
2166
+ class Tt {
2064
2167
  events;
2065
2168
  incomingRTCSession;
2066
2169
  connectionManager;
@@ -2095,19 +2198,19 @@ class ut {
2095
2198
  return this.removeIncomingSession(), e;
2096
2199
  };
2097
2200
  async declineToIncomingCall({
2098
- statusCode: e = lt
2201
+ statusCode: e = ut
2099
2202
  } = {}) {
2100
2203
  return new Promise((t, s) => {
2101
2204
  try {
2102
- const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
2103
- this.removeIncomingSession(), this.events.trigger(U.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2104
- } catch (i) {
2105
- s(i);
2205
+ const r = this.getIncomingRTCSession(), i = this.remoteCallerData;
2206
+ this.removeIncomingSession(), this.events.trigger(U.DECLINED_INCOMING_CALL, i), r.terminate({ status_code: e }), t();
2207
+ } catch (r) {
2208
+ s(r);
2106
2209
  }
2107
2210
  });
2108
2211
  }
2109
2212
  async busyIncomingCall() {
2110
- return this.declineToIncomingCall({ statusCode: gt });
2213
+ return this.declineToIncomingCall({ statusCode: lt });
2111
2214
  }
2112
2215
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2113
2216
  on(e, t) {
@@ -2151,12 +2254,12 @@ class ut {
2151
2254
  delete this.incomingRTCSession;
2152
2255
  }
2153
2256
  }
2154
- const w = 1e3;
2155
- 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 || {});
2156
- const Te = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
2257
+ const b = 1e3;
2258
+ 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 || {});
2259
+ const Te = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), w = (n) => [...n.keys()].reduce((e, t) => {
2157
2260
  const s = n.get(t);
2158
2261
  return s === void 0 ? e : { ...e, [s.type]: s };
2159
- }, {}), Tt = (n) => {
2262
+ }, {}), St = (n) => {
2160
2263
  if (!n)
2161
2264
  return {
2162
2265
  outboundRtp: void 0,
@@ -2164,12 +2267,12 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2164
2267
  mediaSource: void 0,
2165
2268
  remoteInboundRtp: void 0
2166
2269
  };
2167
- const e = L(n);
2270
+ const e = w(n);
2168
2271
  return {
2169
- outboundRtp: e[E.OUTBOUND_RTP],
2170
- codec: e[E.CODEC],
2171
- mediaSource: e[E.MEDIA_SOURCE],
2172
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2272
+ outboundRtp: e[C.OUTBOUND_RTP],
2273
+ codec: e[C.CODEC],
2274
+ mediaSource: e[C.MEDIA_SOURCE],
2275
+ remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2173
2276
  };
2174
2277
  }, z = (n) => {
2175
2278
  if (!n)
@@ -2179,14 +2282,14 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2179
2282
  mediaSource: void 0,
2180
2283
  remoteInboundRtp: void 0
2181
2284
  };
2182
- const e = L(n);
2285
+ const e = w(n);
2183
2286
  return {
2184
- outboundRtp: e[E.OUTBOUND_RTP],
2185
- codec: e[E.CODEC],
2186
- mediaSource: e[E.MEDIA_SOURCE],
2187
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2287
+ outboundRtp: e[C.OUTBOUND_RTP],
2288
+ codec: e[C.CODEC],
2289
+ mediaSource: e[C.MEDIA_SOURCE],
2290
+ remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2188
2291
  };
2189
- }, J = ({
2292
+ }, X = ({
2190
2293
  videoReceiversStats: n,
2191
2294
  synchronizationSourcesVideo: e
2192
2295
  }) => {
@@ -2196,13 +2299,13 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2196
2299
  codec: void 0,
2197
2300
  synchronizationSources: e
2198
2301
  };
2199
- const t = L(n);
2302
+ const t = w(n);
2200
2303
  return {
2201
- inboundRtp: t[E.INBOUND_RTP],
2202
- codec: t[E.CODEC],
2304
+ inboundRtp: t[C.INBOUND_RTP],
2305
+ codec: t[C.CODEC],
2203
2306
  synchronizationSources: e
2204
2307
  };
2205
- }, St = ({
2308
+ }, Ct = ({
2206
2309
  audioReceiverStats: n,
2207
2310
  synchronizationSourcesAudio: e
2208
2311
  }) => {
@@ -2213,11 +2316,11 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2213
2316
  remoteOutboundRtp: void 0,
2214
2317
  synchronizationSources: e
2215
2318
  };
2216
- const t = L(n);
2319
+ const t = w(n);
2217
2320
  return {
2218
- inboundRtp: t[E.INBOUND_RTP],
2219
- codec: t[E.CODEC],
2220
- remoteOutboundRtp: t[E.REMOTE_OUTBOUND_RTP],
2321
+ inboundRtp: t[C.INBOUND_RTP],
2322
+ codec: t[C.CODEC],
2323
+ remoteOutboundRtp: t[C.REMOTE_OUTBOUND_RTP],
2221
2324
  synchronizationSources: e
2222
2325
  };
2223
2326
  }, Se = (n) => {
@@ -2229,13 +2332,13 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2229
2332
  remoteCandidate: void 0,
2230
2333
  transport: void 0
2231
2334
  };
2232
- const e = L(n);
2335
+ const e = w(n);
2233
2336
  return {
2234
- candidatePair: e[E.CANDIDATE_PAIR],
2235
- certificate: e[E.CERTIFICATE],
2236
- localCandidate: e[E.LOCAL_CANDIDATE],
2237
- remoteCandidate: e[E.REMOTE_CANDIDATE],
2238
- transport: e[E.TRANSPORT]
2337
+ candidatePair: e[C.CANDIDATE_PAIR],
2338
+ certificate: e[C.CERTIFICATE],
2339
+ localCandidate: e[C.LOCAL_CANDIDATE],
2340
+ remoteCandidate: e[C.REMOTE_CANDIDATE],
2341
+ transport: e[C.TRANSPORT]
2239
2342
  };
2240
2343
  }, Et = ({
2241
2344
  audioSenderStats: n,
@@ -2244,56 +2347,56 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2244
2347
  }) => ({
2245
2348
  video: z(e),
2246
2349
  secondVideo: z(t),
2247
- audio: Tt(n),
2350
+ audio: St(n),
2248
2351
  additional: Se(
2249
2352
  n ?? e ?? t
2250
2353
  )
2251
- }), Ct = ({
2354
+ }), Nt = ({
2252
2355
  audioReceiverStats: n,
2253
2356
  videoReceiverFirstStats: e,
2254
2357
  videoReceiverSecondStats: t,
2255
2358
  synchronizationSources: s
2256
2359
  }) => ({
2257
- video: J({
2360
+ video: X({
2258
2361
  videoReceiversStats: e,
2259
2362
  synchronizationSourcesVideo: s.video
2260
2363
  }),
2261
- secondVideo: J({
2364
+ secondVideo: X({
2262
2365
  videoReceiversStats: t,
2263
2366
  synchronizationSourcesVideo: s.video
2264
2367
  }),
2265
- audio: St({
2368
+ audio: Ct({
2266
2369
  audioReceiverStats: n,
2267
2370
  synchronizationSourcesAudio: s.audio
2268
2371
  }),
2269
2372
  additional: Se(
2270
2373
  n ?? e ?? t
2271
2374
  )
2272
- }), Nt = ({
2375
+ }), At = ({
2273
2376
  audioSenderStats: n,
2274
2377
  videoSenderFirstStats: e,
2275
2378
  videoSenderSecondStats: t,
2276
2379
  audioReceiverStats: s,
2277
- videoReceiverFirstStats: i,
2278
- videoReceiverSecondStats: r,
2380
+ videoReceiverFirstStats: r,
2381
+ videoReceiverSecondStats: i,
2279
2382
  synchronizationSources: a
2280
2383
  }) => {
2281
2384
  const o = Et({
2282
2385
  audioSenderStats: n,
2283
2386
  videoSenderFirstStats: e,
2284
2387
  videoSenderSecondStats: t
2285
- }), c = Ct({
2388
+ }), c = Nt({
2286
2389
  audioReceiverStats: s,
2287
- videoReceiverFirstStats: i,
2288
- videoReceiverSecondStats: r,
2390
+ videoReceiverFirstStats: r,
2391
+ videoReceiverSecondStats: i,
2289
2392
  synchronizationSources: a
2290
2393
  });
2291
2394
  return {
2292
2395
  outbound: o,
2293
2396
  inbound: c
2294
2397
  };
2295
- }, At = async (n) => {
2296
- 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 = {
2398
+ }, Rt = async (n) => {
2399
+ 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 = {
2297
2400
  trackIdentifier: o?.track.id,
2298
2401
  item: o?.getSynchronizationSources()[0]
2299
2402
  }, u = {
@@ -2304,47 +2407,47 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2304
2407
  video: u
2305
2408
  };
2306
2409
  return Promise.all([
2307
- i?.getStats(),
2308
- r[0]?.getStats(),
2309
- r[1]?.getStats(),
2310
- o?.getStats(),
2311
- c[0]?.getStats(),
2312
- c[1]?.getStats()
2313
- ]).then((h) => {
2410
+ r?.getStats() ?? Promise.resolve(void 0),
2411
+ i[0]?.getStats() ?? Promise.resolve(void 0),
2412
+ i[1]?.getStats() ?? Promise.resolve(void 0),
2413
+ o?.getStats() ?? Promise.resolve(void 0),
2414
+ c[0]?.getStats() ?? Promise.resolve(void 0),
2415
+ c[1]?.getStats() ?? Promise.resolve(void 0)
2416
+ ]).then((g) => {
2314
2417
  const [
2315
2418
  S,
2316
- m,
2317
2419
  I,
2318
- A,
2420
+ _,
2421
+ R,
2319
2422
  y,
2320
- b
2321
- ] = h;
2423
+ $
2424
+ ] = g;
2322
2425
  return {
2323
2426
  synchronizationSources: T,
2324
2427
  audioSenderStats: S,
2325
- videoSenderFirstStats: m,
2326
- videoSenderSecondStats: I,
2327
- audioReceiverStats: A,
2428
+ videoSenderFirstStats: I,
2429
+ videoSenderSecondStats: _,
2430
+ audioReceiverStats: R,
2328
2431
  videoReceiverFirstStats: y,
2329
- videoReceiverSecondStats: b
2432
+ videoReceiverSecondStats: $
2330
2433
  };
2331
2434
  });
2332
- }, Rt = (n) => {
2333
- R(String(n));
2435
+ }, It = (n) => {
2436
+ E(String(n));
2334
2437
  };
2335
- class It {
2438
+ class _t {
2336
2439
  events;
2337
2440
  setTimeoutRequest;
2338
- requesterAllStatistics = new Re(At);
2441
+ requesterAllStatistics = new Re(Rt);
2339
2442
  constructor() {
2340
- this.events = new j(Te), this.setTimeoutRequest = new ee();
2443
+ this.events = new K(Te), this.setTimeoutRequest = new ee();
2341
2444
  }
2342
2445
  get requested() {
2343
2446
  return this.setTimeoutRequest.requested;
2344
2447
  }
2345
2448
  start(e, {
2346
- interval: t = w,
2347
- onError: s = Rt
2449
+ interval: t = b,
2450
+ onError: s = It
2348
2451
  } = {}) {
2349
2452
  this.stop(), this.setTimeoutRequest.request(() => {
2350
2453
  this.collectStatistics(e, {
@@ -2374,20 +2477,20 @@ class It {
2374
2477
  onError: t
2375
2478
  }) => {
2376
2479
  const s = Y();
2377
- this.requesterAllStatistics.request(e).then((i) => {
2378
- this.events.trigger("collected", Nt(i));
2480
+ this.requesterAllStatistics.request(e).then((r) => {
2481
+ this.events.trigger("collected", At(r));
2379
2482
  const a = Y() - s;
2380
- let o = w;
2381
- a > 48 ? o = w * 4 : a > 32 ? o = w * 3 : a > 16 && (o = w * 2), this.start(e, {
2483
+ let o = b;
2484
+ a > 48 ? o = b * 4 : a > 32 ? o = b * 3 : a > 16 && (o = b * 2), this.start(e, {
2382
2485
  onError: t,
2383
2486
  interval: o
2384
2487
  });
2385
- }).catch((i) => {
2386
- t && t(i);
2488
+ }).catch((r) => {
2489
+ t && t(r);
2387
2490
  });
2388
2491
  };
2389
2492
  }
2390
- class _t {
2493
+ class mt {
2391
2494
  availableIncomingBitrate;
2392
2495
  statsPeerConnection;
2393
2496
  callManager;
@@ -2397,7 +2500,7 @@ class _t {
2397
2500
  callManager: e,
2398
2501
  apiManager: t
2399
2502
  }) {
2400
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new It(), this.subscribe();
2503
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new _t(), this.subscribe();
2401
2504
  }
2402
2505
  get events() {
2403
2506
  return this.statsPeerConnection.events;
@@ -2435,36 +2538,36 @@ class _t {
2435
2538
  };
2436
2539
  maybeSendStats() {
2437
2540
  this.availableIncomingBitrate !== void 0 && this.hasAvailableIncomingBitrateChangedQuarter() && this.apiManager.sendStats({ availableIncomingBitrate: this.availableIncomingBitrate }).catch((e) => {
2438
- R("Failed to send stats", e);
2541
+ E("Failed to send stats", e);
2439
2542
  });
2440
2543
  }
2441
2544
  }
2442
- const Mt = (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) => {
2443
- const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
2444
- return Mt(s, i);
2445
- }, pt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2446
- 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;
2545
+ 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)), pt = (n) => {
2546
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, r = t === null ? [] : t.codecs;
2547
+ return Mt(s, r);
2548
+ }, Pt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2549
+ 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;
2447
2550
  return a - o;
2448
- }), Pt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), ft = (n, {
2551
+ }), vt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), ft = (n, {
2449
2552
  preferredMimeTypesVideoCodecs: e,
2450
2553
  excludeMimeTypesVideoCodecs: t
2451
2554
  }) => {
2452
2555
  try {
2453
2556
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
2454
- const s = mt("video"), i = Pt(s, t), r = pt(i, e);
2455
- n.setCodecPreferences(r);
2557
+ const s = pt("video"), r = vt(s, t), i = Pt(r, e);
2558
+ n.setCodecPreferences(i);
2456
2559
  }
2457
2560
  } catch (s) {
2458
- R("setCodecPreferences error", s);
2561
+ E("setCodecPreferences error", s);
2459
2562
  }
2460
- }, 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);
2461
- class yt {
2563
+ }, Ot = (n) => [...n.keys()].map((e) => n.get(e)), Dt = (n, e) => Ot(n).find((t) => t?.type === e), yt = async (n) => n.getStats().then((e) => Dt(e, "codec")?.mimeType);
2564
+ class bt {
2462
2565
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2463
2566
  async getCodecFromSender(e) {
2464
- return await Dt(e) ?? "";
2567
+ return await yt(e) ?? "";
2465
2568
  }
2466
2569
  }
2467
- class bt {
2570
+ class Ut {
2468
2571
  stackPromises = Z({
2469
2572
  noRunIsNotActual: !0
2470
2573
  });
@@ -2485,7 +2588,7 @@ class bt {
2485
2588
  */
2486
2589
  async run() {
2487
2590
  return this.stackPromises().catch((e) => {
2488
- R("TaskQueue: error", e);
2591
+ E("TaskQueue: error", e);
2489
2592
  });
2490
2593
  }
2491
2594
  }
@@ -2493,7 +2596,7 @@ class wt {
2493
2596
  taskQueue;
2494
2597
  onSetParameters;
2495
2598
  constructor(e) {
2496
- this.onSetParameters = e, this.taskQueue = new bt();
2599
+ this.onSetParameters = e, this.taskQueue = new Ut();
2497
2600
  }
2498
2601
  async setEncodingsToSender(e, t) {
2499
2602
  return this.taskQueue.add(async () => ce(e, t, this.onSetParameters));
@@ -2502,17 +2605,17 @@ class wt {
2502
2605
  this.taskQueue.stop();
2503
2606
  }
2504
2607
  }
2505
- const Ee = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Ut = 1e6, p = (n) => n * Ut, Ce = p(0.06), Ne = p(4), Lt = (n) => n <= 64 ? Ce : 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) => Ee(n, Bt), Ft = 0.6, Q = (n, e) => kt(e) ? n * Ft : n, $t = (n) => Q(Ce, n), Vt = (n) => Q(Ne, n), X = (n, e) => {
2506
- const t = Lt(n);
2608
+ const Ce = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Lt = 1e6, p = (n) => n * Lt, Ee = p(0.06), Ne = p(4), Bt = (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, kt = "av1", Ft = (n) => Ce(n, kt), $t = 0.6, Q = (n, e) => Ft(e) ? n * $t : n, Vt = (n) => Q(Ee, n), Wt = (n) => Q(Ne, n), J = (n, e) => {
2609
+ const t = Bt(n);
2507
2610
  return Q(t, e);
2508
- }, V = 1, Wt = ({
2611
+ }, V = 1, Ht = ({
2509
2612
  videoTrack: n,
2510
2613
  targetSize: e
2511
2614
  }) => {
2512
- 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;
2513
- return Math.max(r, a, V);
2615
+ 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;
2616
+ return Math.max(i, a, V);
2514
2617
  };
2515
- class Ht {
2618
+ class xt {
2516
2619
  ignoreForCodec;
2517
2620
  senderFinder;
2518
2621
  codecProvider;
@@ -2531,8 +2634,8 @@ class Ht {
2531
2634
  senderFinder: e,
2532
2635
  codecProvider: t,
2533
2636
  parametersSetter: s
2534
- }, i) {
2535
- this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = i.ignoreForCodec;
2637
+ }, r) {
2638
+ this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = r.ignoreForCodec;
2536
2639
  }
2537
2640
  /**
2538
2641
  * Выполняет балансировку на основе заголовков от сервера
@@ -2541,21 +2644,21 @@ class Ht {
2541
2644
  * @returns Promise с результатом балансировки
2542
2645
  */
2543
2646
  async balance(e, t) {
2544
- const s = e.getSenders(), i = this.senderFinder.findVideoSender(s);
2545
- if (!i?.track)
2546
- return { ...this.resultNoChanged, sender: i };
2547
- const r = await this.codecProvider.getCodecFromSender(i);
2548
- if (Ee(r, this.ignoreForCodec))
2549
- return { ...this.resultNoChanged, sender: i };
2647
+ const s = e.getSenders(), r = this.senderFinder.findVideoSender(s);
2648
+ if (!r?.track)
2649
+ return { ...this.resultNoChanged, sender: r };
2650
+ const i = await this.codecProvider.getCodecFromSender(r);
2651
+ if (Ce(i, this.ignoreForCodec))
2652
+ return { ...this.resultNoChanged, sender: r };
2550
2653
  const { mainCam: a, resolutionMainCam: o } = t ?? {};
2551
2654
  return this.processSender(
2552
2655
  { mainCam: a, resolutionMainCam: o },
2553
2656
  {
2554
- sender: i,
2555
- codec: r,
2556
- videoTrack: i.track
2657
+ sender: r,
2658
+ codec: i,
2659
+ videoTrack: r.track
2557
2660
  }
2558
- ).then((c) => ({ ...c, sender: i }));
2661
+ ).then((c) => ({ ...c, sender: r }));
2559
2662
  }
2560
2663
  /**
2561
2664
  * Обрабатывает отправитель в зависимости от команды управления
@@ -2563,14 +2666,14 @@ class Ht {
2563
2666
  * @returns Promise с результатом обработки
2564
2667
  */
2565
2668
  async processSender(e, t) {
2566
- const { mainCam: s, resolutionMainCam: i } = e;
2669
+ const { mainCam: s, resolutionMainCam: r } = e;
2567
2670
  switch (s) {
2568
2671
  case P.PAUSE_MAIN_CAM:
2569
2672
  return this.downgradeResolutionSender(t);
2570
2673
  case P.RESUME_MAIN_CAM:
2571
2674
  return this.setBitrateByTrackResolution(t);
2572
2675
  case P.MAX_MAIN_CAM_RESOLUTION:
2573
- return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
2676
+ return r !== void 0 ? this.setResolutionSender(r, t) : this.setBitrateByTrackResolution(t);
2574
2677
  case P.ADMIN_STOP_MAIN_CAM:
2575
2678
  case P.ADMIN_START_MAIN_CAM:
2576
2679
  case void 0:
@@ -2585,11 +2688,11 @@ class Ht {
2585
2688
  * @returns Promise с результатом
2586
2689
  */
2587
2690
  async downgradeResolutionSender(e) {
2588
- const { sender: t, codec: s } = e, i = {
2691
+ const { sender: t, codec: s } = e, r = {
2589
2692
  scaleResolutionDownBy: 200,
2590
- maxBitrate: $t(s)
2693
+ maxBitrate: Vt(s)
2591
2694
  };
2592
- return this.parametersSetter.setEncodingsToSender(t, i);
2695
+ return this.parametersSetter.setEncodingsToSender(t, r);
2593
2696
  }
2594
2697
  /**
2595
2698
  * Устанавливает битрейт на основе разрешения трека
@@ -2597,7 +2700,7 @@ class Ht {
2597
2700
  * @returns Promise с результатом
2598
2701
  */
2599
2702
  async setBitrateByTrackResolution(e) {
2600
- const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? Vt(i) : X(a, i);
2703
+ const { sender: t, videoTrack: s, codec: r } = e, a = s.getSettings().width, o = a === void 0 ? Wt(r) : J(a, r);
2601
2704
  return this.parametersSetter.setEncodingsToSender(t, {
2602
2705
  scaleResolutionDownBy: 1,
2603
2706
  maxBitrate: o
@@ -2610,27 +2713,27 @@ class Ht {
2610
2713
  * @returns Promise с результатом
2611
2714
  */
2612
2715
  async setResolutionSender(e, t) {
2613
- const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
2716
+ const [s, r] = e.split("x"), { sender: i, videoTrack: a, codec: o } = t, c = {
2614
2717
  width: Number(s),
2615
- height: Number(i)
2616
- }, d = Wt({
2718
+ height: Number(r)
2719
+ }, d = Ht({
2617
2720
  videoTrack: a,
2618
2721
  targetSize: c
2619
- }), u = X(c.width, o), T = {
2722
+ }), u = J(c.width, o), T = {
2620
2723
  scaleResolutionDownBy: d,
2621
2724
  maxBitrate: u
2622
2725
  };
2623
- return this.parametersSetter.setEncodingsToSender(r, T);
2726
+ return this.parametersSetter.setEncodingsToSender(i, T);
2624
2727
  }
2625
2728
  }
2626
- const xt = (n) => n.find((e) => e.track?.kind === "video");
2627
- class qt {
2729
+ const qt = (n) => n.find((e) => e.track?.kind === "video");
2730
+ class Gt {
2628
2731
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2629
2732
  findVideoSender(e) {
2630
- return xt(e);
2733
+ return qt(e);
2631
2734
  }
2632
2735
  }
2633
- class Gt {
2736
+ class Qt {
2634
2737
  currentSender;
2635
2738
  originalReplaceTrack;
2636
2739
  lastWidth;
@@ -2662,8 +2765,8 @@ class Gt {
2662
2765
  attachSender(e, t) {
2663
2766
  this.currentSender = e;
2664
2767
  const s = e.replaceTrack.bind(e);
2665
- this.originalReplaceTrack = s, e.replaceTrack = async (i) => {
2666
- await s(i), this.attachTrack(t, i ?? void 0), t();
2768
+ this.originalReplaceTrack = s, e.replaceTrack = async (r) => {
2769
+ await s(r), this.attachTrack(t, r ?? void 0), t();
2667
2770
  }, this.attachTrack(t, e.track);
2668
2771
  }
2669
2772
  detachSender() {
@@ -2672,8 +2775,8 @@ class Gt {
2672
2775
  attachTrack(e, t) {
2673
2776
  if (this.detachTrack(), !t)
2674
2777
  return;
2675
- const { width: s, height: i } = t.getSettings();
2676
- this.lastWidth = s, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2778
+ const { width: s, height: r } = t.getSettings();
2779
+ this.lastWidth = s, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2677
2780
  }
2678
2781
  /**
2679
2782
  * Периодически опрашивает track с экспоненциальной адаптацией частоты.
@@ -2682,8 +2785,8 @@ class Gt {
2682
2785
  */
2683
2786
  schedulePoll(e, t) {
2684
2787
  const s = () => {
2685
- const { width: i, height: r } = e.getSettings();
2686
- i !== this.lastWidth || r !== this.lastHeight ? (this.lastWidth = i, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2788
+ const { width: r, height: i } = e.getSettings();
2789
+ r !== this.lastWidth || i !== this.lastHeight ? (this.lastWidth = r, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2687
2790
  this.currentPollIntervalMs * 2,
2688
2791
  this.maxPollIntervalMs
2689
2792
  ), this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
@@ -2694,7 +2797,7 @@ class Gt {
2694
2797
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
2695
2798
  }
2696
2799
  }
2697
- class Qt {
2800
+ class Yt {
2698
2801
  apiManager;
2699
2802
  currentHandler;
2700
2803
  constructor(e) {
@@ -2714,7 +2817,7 @@ class Qt {
2714
2817
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
2715
2818
  }
2716
2819
  }
2717
- class Yt {
2820
+ class zt {
2718
2821
  eventHandler;
2719
2822
  senderBalancer;
2720
2823
  parametersSetterWithQueue;
@@ -2723,19 +2826,19 @@ class Yt {
2723
2826
  trackMonitor;
2724
2827
  constructor(e, t, {
2725
2828
  ignoreForCodec: s,
2726
- onSetParameters: i,
2727
- pollIntervalMs: r
2829
+ onSetParameters: r,
2830
+ pollIntervalMs: i
2728
2831
  } = {}) {
2729
- this.getConnection = t, this.eventHandler = new Qt(e), this.parametersSetterWithQueue = new wt(i), this.senderBalancer = new Ht(
2832
+ this.getConnection = t, this.eventHandler = new Yt(e), this.parametersSetterWithQueue = new wt(r), this.senderBalancer = new xt(
2730
2833
  {
2731
- senderFinder: new qt(),
2732
- codecProvider: new yt(),
2834
+ senderFinder: new Gt(),
2835
+ codecProvider: new bt(),
2733
2836
  parametersSetter: this.parametersSetterWithQueue
2734
2837
  },
2735
2838
  {
2736
2839
  ignoreForCodec: s
2737
2840
  }
2738
- ), this.trackMonitor = new Gt({ pollIntervalMs: r });
2841
+ ), this.trackMonitor = new Qt({ pollIntervalMs: i });
2739
2842
  }
2740
2843
  /**
2741
2844
  * Подписывается на события управления главной камерой
@@ -2766,7 +2869,7 @@ class Yt {
2766
2869
  const t = await this.senderBalancer.balance(e, this.serverHeaders);
2767
2870
  return this.trackMonitor.subscribe(t.sender, () => {
2768
2871
  this.balance().catch((s) => {
2769
- R("balance on track change: error", s);
2872
+ E("balance on track change: error", s);
2770
2873
  });
2771
2874
  }), t;
2772
2875
  }
@@ -2776,7 +2879,7 @@ class Yt {
2776
2879
  */
2777
2880
  handleMainCamControl = (e) => {
2778
2881
  this.serverHeaders = e, this.balance().catch((t) => {
2779
- R("handleMainCamControl: error", t);
2882
+ E("handleMainCamControl: error", t);
2780
2883
  });
2781
2884
  };
2782
2885
  }
@@ -2786,7 +2889,7 @@ const Ae = [
2786
2889
  "balancing-stopped",
2787
2890
  "parameters-updated"
2788
2891
  ];
2789
- class zt {
2892
+ class Xt {
2790
2893
  isBalancingActive = !1;
2791
2894
  events;
2792
2895
  callManager;
@@ -2794,13 +2897,13 @@ class zt {
2794
2897
  videoSendingBalancer;
2795
2898
  startBalancingTimer;
2796
2899
  constructor(e, t, s = {}) {
2797
- this.events = new j(Ae), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Yt(
2900
+ this.events = new K(Ae), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new zt(
2798
2901
  t,
2799
2902
  () => e.connection,
2800
2903
  {
2801
2904
  ...s,
2802
- onSetParameters: (i) => {
2803
- this.events.trigger("parameters-updated", i), s.onSetParameters?.(i);
2905
+ onSetParameters: (r) => {
2906
+ this.events.trigger("parameters-updated", r), s.onSetParameters?.(r);
2804
2907
  }
2805
2908
  }
2806
2909
  ), this.subscribe();
@@ -2856,7 +2959,7 @@ class zt {
2856
2959
  scheduleBalancingStart() {
2857
2960
  this.clearStartTimer(), this.startBalancingTimer = setTimeout(() => {
2858
2961
  this.startBalancingTimer = void 0, this.startBalancing().catch((e) => {
2859
- R("startBalancing: error", e);
2962
+ E("startBalancing: error", e);
2860
2963
  });
2861
2964
  }, this.balancingStartDelay), this.events.trigger("balancing-scheduled", { delay: this.balancingStartDelay });
2862
2965
  }
@@ -2864,16 +2967,16 @@ class zt {
2864
2967
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
2865
2968
  }
2866
2969
  }
2867
- const Jt = 1e6, Xt = ge.map((n) => `connection:${n}`), jt = ne.map((n) => `call:${n}`), Kt = re.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 = [
2868
- ...Xt,
2869
- ...jt,
2970
+ const Jt = 1e6, Kt = ge.map((n) => `connection:${n}`), jt = ne.map((n) => `call:${n}`), Zt = ie.map((n) => `api:${n}`), en = ue.map((n) => `incoming-call:${n}`), tn = de.map((n) => `presentation:${n}`), nn = Te.map((n) => `stats:${n}`), sn = Ae.map((n) => `video-balancer:${n}`), rn = [
2870
2971
  ...Kt,
2972
+ ...jt,
2871
2973
  ...Zt,
2872
2974
  ...en,
2873
2975
  ...tn,
2874
- ...nn
2976
+ ...nn,
2977
+ ...sn
2875
2978
  ];
2876
- class Cn {
2979
+ class Nn {
2877
2980
  events;
2878
2981
  connectionManager;
2879
2982
  connectionQueueManager;
@@ -2888,23 +2991,23 @@ class Cn {
2888
2991
  constructor({ JsSIP: e }, {
2889
2992
  preferredMimeTypesVideoCodecs: t,
2890
2993
  excludeMimeTypesVideoCodecs: s,
2891
- videoBalancerOptions: i
2994
+ videoBalancerOptions: r
2892
2995
  } = {}) {
2893
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(sn), this.connectionManager = new dt({ JsSIP: e }), this.connectionQueueManager = new ht({
2996
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(rn), this.connectionManager = new ht({ JsSIP: e }), this.connectionQueueManager = new gt({
2894
2997
  connectionManager: this.connectionManager
2895
- }), this.callManager = new we(), this.apiManager = new $e({
2998
+ }), this.callManager = new we(), this.apiManager = new Ve({
2896
2999
  connectionManager: this.connectionManager,
2897
3000
  callManager: this.callManager
2898
- }), this.incomingCallManager = new ut(this.connectionManager), this.presentationManager = new et({
3001
+ }), this.incomingCallManager = new Tt(this.connectionManager), this.presentationManager = new tt({
2899
3002
  callManager: this.callManager,
2900
3003
  maxBitrate: Jt
2901
- }), this.statsManager = new _t({
3004
+ }), this.statsManager = new mt({
2902
3005
  callManager: this.callManager,
2903
3006
  apiManager: this.apiManager
2904
- }), this.videoSendingBalancerManager = new zt(
3007
+ }), this.videoSendingBalancerManager = new Xt(
2905
3008
  this.callManager,
2906
3009
  this.apiManager,
2907
- i
3010
+ r
2908
3011
  ), this.subscribe();
2909
3012
  }
2910
3013
  get requestedConnection() {
@@ -2984,8 +3087,8 @@ class Cn {
2984
3087
  this.getSipServerUrl,
2985
3088
  {
2986
3089
  ...s,
2987
- onAddedTransceiver: async (i, r, a) => {
2988
- this.setCodecPreferences(i), await t?.(i, r, a);
3090
+ onAddedTransceiver: async (r, i, a) => {
3091
+ this.setCodecPreferences(r), await t?.(r, i, a);
2989
3092
  }
2990
3093
  }
2991
3094
  );
@@ -2997,8 +3100,8 @@ class Cn {
2997
3100
  this.incomingCallManager.extractIncomingRTCSession,
2998
3101
  {
2999
3102
  ...s,
3000
- onAddedTransceiver: async (i, r, a) => {
3001
- this.setCodecPreferences(i), await t?.(i, r, a);
3103
+ onAddedTransceiver: async (r, i, a) => {
3104
+ this.setCodecPreferences(r), await t?.(r, i, a);
3002
3105
  }
3003
3106
  }
3004
3107
  );
@@ -3009,7 +3112,7 @@ class Cn {
3009
3112
  getRemoteStreams = () => this.callManager.getRemoteStreams();
3010
3113
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
3011
3114
  async startPresentation(e, t = {}) {
3012
- const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
3115
+ const { isP2P: s, callLimit: r, onAddedTransceiver: i, ...a } = t;
3013
3116
  return this.presentationManager.startPresentation(
3014
3117
  async () => {
3015
3118
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
@@ -3018,10 +3121,10 @@ class Cn {
3018
3121
  {
3019
3122
  ...a,
3020
3123
  onAddedTransceiver: async (o, c, d) => {
3021
- this.setCodecPreferences(o), await r?.(o, c, d);
3124
+ this.setCodecPreferences(o), await i?.(o, c, d);
3022
3125
  }
3023
3126
  },
3024
- i === void 0 ? void 0 : { callLimit: i }
3127
+ r === void 0 ? void 0 : { callLimit: r }
3025
3128
  );
3026
3129
  }
3027
3130
  async stopPresentation(e = {}) {
@@ -3031,16 +3134,16 @@ class Cn {
3031
3134
  });
3032
3135
  }
3033
3136
  async updatePresentation(e, t = {}) {
3034
- const { isP2P: s, onAddedTransceiver: i, ...r } = t;
3137
+ const { isP2P: s, onAddedTransceiver: r, ...i } = t;
3035
3138
  return this.presentationManager.updatePresentation(
3036
3139
  async () => {
3037
3140
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
3038
3141
  },
3039
3142
  e,
3040
3143
  {
3041
- ...r,
3144
+ ...i,
3042
3145
  onAddedTransceiver: async (a, o, c) => {
3043
- this.setCodecPreferences(a), await i?.(a, o, c);
3146
+ this.setCodecPreferences(a), await r?.(a, o, c);
3044
3147
  }
3045
3148
  }
3046
3149
  );
@@ -3122,22 +3225,39 @@ class Cn {
3122
3225
  this.videoSendingBalancerManager.on(t, (s) => {
3123
3226
  this.events.trigger(`video-balancer:${t}`, s);
3124
3227
  });
3228
+ }), this.apiManager.on("restart", this.handleRestart);
3229
+ }
3230
+ handleRestart = (e) => {
3231
+ this.updateTransceivers(e).catch((t) => {
3232
+ E("Failed to update transceivers", t);
3233
+ }).finally(() => {
3234
+ this.callManager.restartIce().catch((t) => {
3235
+ E("Failed to restart ICE", t);
3236
+ });
3125
3237
  });
3126
- }
3238
+ };
3239
+ updateTransceivers = async (e) => {
3240
+ const { videoTrackCount: t } = e;
3241
+ t === 2 && (this.callManager.getTransceivers().presentationVideo !== void 0 || await this.callManager.addTransceiver("video", {
3242
+ direction: "recvonly"
3243
+ }).catch((i) => {
3244
+ E("Failed to add presentation video transceiver", i);
3245
+ }));
3246
+ };
3127
3247
  }
3128
3248
  export {
3129
- ie as E,
3130
- $ as O,
3131
- Cn as S,
3132
- Xe as a,
3133
- Fe as b,
3134
- E as c,
3135
- Sn as d,
3136
- Tn as e,
3137
- It as f,
3138
- Dt as g,
3249
+ re as E,
3250
+ F as O,
3251
+ Nn as S,
3252
+ Ke as a,
3253
+ $e as b,
3254
+ C as c,
3255
+ Cn as d,
3256
+ Sn as e,
3257
+ _t as f,
3258
+ yt as g,
3139
3259
  En as h,
3140
- R as l,
3141
- B as p,
3260
+ E as l,
3261
+ L as p,
3142
3262
  ce as s
3143
3263
  };