sip-connector 15.3.1 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +763 -103
  3. package/dist/@SipConnector-DcaeAFrM.cjs +1 -0
  4. package/dist/{@SipConnector-5Rac5oq2.js → @SipConnector-uiUlVCMv.js} +955 -395
  5. package/dist/CallManager/types.d.ts +2 -0
  6. package/dist/PresentationManager/@PresentationManager.d.ts +5 -3
  7. package/dist/SipConnector/@SipConnector.d.ts +14 -4
  8. package/dist/SipConnector/eventNames.d.ts +1 -1
  9. package/dist/SipConnectorFacade/SipConnectorFacade.d.ts +10 -21
  10. package/dist/VideoSendingBalancer/SenderBalancer.d.ts +3 -1
  11. package/dist/VideoSendingBalancer/TrackMonitor.d.ts +38 -0
  12. package/dist/VideoSendingBalancer/VideoSendingBalancer.d.ts +8 -9
  13. package/dist/VideoSendingBalancer/VideoSendingEventHandler.d.ts +4 -9
  14. package/dist/VideoSendingBalancer/__fixtures__/createMockTrack.d.ts +5 -0
  15. package/dist/VideoSendingBalancer/__fixtures__/index.d.ts +1 -0
  16. package/dist/VideoSendingBalancer/index.d.ts +1 -2
  17. package/dist/VideoSendingBalancer/types.d.ts +0 -1
  18. package/dist/VideoSendingBalancerManager/@VideoSendingBalancerManager.d.ts +47 -0
  19. package/dist/VideoSendingBalancerManager/eventNames.d.ts +20 -0
  20. package/dist/VideoSendingBalancerManager/index.d.ts +3 -0
  21. package/dist/doMock.cjs +1 -1
  22. package/dist/doMock.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.js +281 -748
  26. package/dist/logger.d.ts +0 -1
  27. package/dist/tools/setCodecPreferences.d.ts +5 -0
  28. package/dist/tools/setParametersToSender/index.d.ts +1 -0
  29. package/package.json +8 -8
  30. package/dist/@SipConnector-Bv3-Y4Rz.cjs +0 -1
  31. package/dist/tools/generateSimulcastEncodings.d.ts +0 -7
  32. package/dist/tools/resolveUpdateTransceiver.d.ts +0 -6
  33. package/dist/tools/scaleResolutionAndBitrate.d.ts +0 -10
  34. /package/dist/{PresentationManager → SipConnector}/constants.d.ts +0 -0
@@ -1,13 +1,14 @@
1
- import { Events as f, TypedEvents as ae } from "events-constructor";
2
- import { CancelableRequest as oe } from "@krivega/cancelable-promise";
3
- import B from "debug";
4
- import { hasCanceledError as ce, repeatedCallsAsync as Y } from "repeated-calls";
5
- import { setup as ge, createActor as de } from "xstate";
6
- import { SetTimeoutRequest as Te } from "@krivega/timeout-requester";
1
+ import { Events as D, TypedEvents as j } from "events-constructor";
2
+ import { CancelableRequest as Ae } from "@krivega/cancelable-promise";
3
+ import q from "debug";
4
+ import { hasCanceledError as Re, repeatedCallsAsync as K } from "repeated-calls";
5
+ import { setup as Ie, createActor as _e } from "xstate";
6
+ import { SetTimeoutRequest as Z } from "@krivega/timeout-requester";
7
7
  import "ua-parser-js";
8
8
  import "sequent-promises";
9
- 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 || {}), $ = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))($ || {});
10
- const z = [
9
+ import { createStackPromises as Me } from "stack-promises";
10
+ var C = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(C || {}), $ = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))($ || {});
11
+ const ee = [
11
12
  "peerconnection",
12
13
  "connecting",
13
14
  "sending",
@@ -34,18 +35,18 @@ const z = [
34
35
  "peerconnection:createanswerfailed",
35
36
  "peerconnection:setlocaldescriptionfailed",
36
37
  "peerconnection:setremotedescriptionfailed"
37
- ], he = [
38
+ ], me = [
38
39
  "peerconnection:confirmed",
39
40
  "peerconnection:ontrack",
40
41
  "ended:fromserver"
41
- ], Q = [
42
- ...z,
43
- ...he
44
- ], le = (n, e) => {
42
+ ], te = [
43
+ ...ee,
44
+ ...me
45
+ ], pe = (n, e) => {
45
46
  n.getVideoTracks().forEach((s) => {
46
47
  "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
47
48
  });
48
- }, w = (n, {
49
+ }, B = (n, {
49
50
  directionVideo: e,
50
51
  directionAudio: t,
51
52
  contentHint: s
@@ -53,16 +54,16 @@ const z = [
53
54
  if (!n || e === "recvonly" && t === "recvonly")
54
55
  return;
55
56
  const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
56
- return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && le(o, s), o;
57
+ return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && pe(o, s), o;
57
58
  };
58
- function Se(n) {
59
+ function Pe(n) {
59
60
  return (e) => `sip:${e}@${n}`;
60
61
  }
61
- const Ee = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, X = (n) => n.trim().replaceAll(" ", "_"), ue = Ee(1e5, 99999999), Ce = (n) => n.some((t) => {
62
+ const fe = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, ne = (n) => n.trim().replaceAll(" ", "_"), Oe = fe(1e5, 99999999), ve = (n) => n.some((t) => {
62
63
  const { kind: s } = t;
63
64
  return s === "video";
64
65
  });
65
- class Ne {
66
+ class De {
66
67
  isPendingCall = !1;
67
68
  isPendingAnswer = !1;
68
69
  rtcSession;
@@ -73,8 +74,8 @@ class Ne {
73
74
  this.events = e;
74
75
  }
75
76
  }
76
- var J = /* @__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))(J || {});
77
- class Ae {
77
+ var se = /* @__PURE__ */ ((n) => (n.BYE = "Terminated", n.WEBRTC_ERROR = "WebRTC Error", n.CANCELED = "Canceled", n.REQUEST_TIMEOUT = "Request Timeout", n.REJECTED = "Rejected", n.REDIRECTED = "Redirected", n.UNAVAILABLE = "Unavailable", n.NOT_FOUND = "Not Found", n.ADDRESS_INCOMPLETE = "Address Incomplete", n.INCOMPATIBLE_SDP = "Incompatible SDP", n.BAD_MEDIA_DESCRIPTION = "Bad Media Description", n))(se || {});
78
+ class ye {
78
79
  remoteStreams = {};
79
80
  reset() {
80
81
  this.remoteStreams = {};
@@ -103,11 +104,11 @@ class Ae {
103
104
  return e.map((t) => this.generateAudioStream(t));
104
105
  }
105
106
  }
106
- class Re extends Ne {
107
- remoteStreamsManager = new Ae();
107
+ class be extends De {
108
+ remoteStreamsManager = new ye();
108
109
  disposers = /* @__PURE__ */ new Set();
109
110
  constructor(e) {
110
- super(e), e.on(N.FAILED, this.handleEnded), e.on(N.ENDED, this.handleEnded);
111
+ super(e), e.on(C.FAILED, this.handleEnded), e.on(C.ENDED, this.handleEnded);
111
112
  }
112
113
  get requested() {
113
114
  return this.isPendingCall || this.isPendingAnswer;
@@ -128,37 +129,39 @@ class Re extends Ne {
128
129
  ontrack: a,
129
130
  iceServers: o,
130
131
  directionVideo: c,
131
- directionAudio: g,
132
- contentHint: l,
133
- offerToReceiveAudio: u = !0,
134
- offerToReceiveVideo: d = !0,
135
- sendEncodings: S,
136
- onAddedTransceiver: _
137
- }) => (this.isPendingCall = !0, new Promise((C, p) => {
138
- this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(C).catch((v) => {
139
- p(v);
132
+ directionAudio: d,
133
+ contentHint: u,
134
+ offerToReceiveAudio: T = !0,
135
+ offerToReceiveVideo: h = !0,
136
+ 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);
140
142
  }), this.rtcSession = e.call(t(s), {
141
143
  extraHeaders: r,
142
- mediaStream: w(i, {
144
+ mediaStream: B(i, {
143
145
  directionVideo: c,
144
- directionAudio: g,
145
- contentHint: l
146
+ directionAudio: d,
147
+ contentHint: u
146
148
  }),
147
149
  // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
148
150
  // так как в методе call создается RTCSession
149
151
  // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
150
152
  eventHandlers: this.events.triggers,
151
153
  directionVideo: c,
152
- directionAudio: g,
154
+ directionAudio: d,
153
155
  pcConfig: {
154
156
  iceServers: o
155
157
  },
156
158
  rtcOfferConstraints: {
157
- offerToReceiveAudio: u,
158
- offerToReceiveVideo: d
159
+ offerToReceiveAudio: T,
160
+ offerToReceiveVideo: h
159
161
  },
160
- sendEncodings: S,
161
- onAddedTransceiver: _
162
+ degradationPreference: S,
163
+ sendEncodings: m,
164
+ onAddedTransceiver: I
162
165
  });
163
166
  }).finally(() => {
164
167
  this.isPendingCall = !1;
@@ -167,7 +170,7 @@ class Re extends Ne {
167
170
  const { rtcSession: e } = this;
168
171
  if (e && !e.isEnded())
169
172
  return e.terminateAsync({
170
- cause: J.CANCELED
173
+ cause: se.CANCELED
171
174
  }).finally(() => {
172
175
  this.reset();
173
176
  });
@@ -181,38 +184,40 @@ class Re extends Ne {
181
184
  directionVideo: a,
182
185
  directionAudio: o,
183
186
  offerToReceiveAudio: c,
184
- offerToReceiveVideo: g,
185
- contentHint: l,
186
- sendEncodings: u,
187
- onAddedTransceiver: d
188
- }) => (this.isPendingAnswer = !0, new Promise((S, _) => {
187
+ offerToReceiveVideo: d,
188
+ contentHint: u,
189
+ degradationPreference: T,
190
+ sendEncodings: h,
191
+ onAddedTransceiver: S
192
+ }) => (this.isPendingAnswer = !0, new Promise((m, I) => {
189
193
  try {
190
- const C = e();
191
- this.rtcSession = C, this.subscribeToSessionEvents(C), this.callConfiguration.answer = !0, this.callConfiguration.number = C.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(S).catch((v) => {
192
- _(v);
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);
193
197
  });
194
- const p = w(t, {
198
+ const y = B(t, {
195
199
  directionVideo: a,
196
200
  directionAudio: o,
197
- contentHint: l
201
+ contentHint: u
198
202
  });
199
- C.answer({
203
+ A.answer({
200
204
  extraHeaders: i,
201
205
  directionVideo: a,
202
206
  directionAudio: o,
203
- mediaStream: p,
207
+ mediaStream: y,
204
208
  pcConfig: {
205
209
  iceServers: r
206
210
  },
207
211
  rtcOfferConstraints: {
208
212
  offerToReceiveAudio: c,
209
- offerToReceiveVideo: g
213
+ offerToReceiveVideo: d
210
214
  },
211
- sendEncodings: u,
212
- onAddedTransceiver: d
215
+ degradationPreference: T,
216
+ sendEncodings: h,
217
+ onAddedTransceiver: S
213
218
  });
214
- } catch (C) {
215
- _(C);
219
+ } catch (A) {
220
+ I(A);
216
221
  }
217
222
  }).finally(() => {
218
223
  this.isPendingAnswer = !1;
@@ -227,12 +232,12 @@ class Re extends Ne {
227
232
  if (!this.connection)
228
233
  return;
229
234
  const t = this.connection.getReceivers().map(({ track: s }) => s);
230
- return Ce(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
235
+ return ve(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
231
236
  }
232
237
  async replaceMediaStream(e, t) {
233
238
  if (!this.rtcSession)
234
239
  throw new Error("No rtcSession established");
235
- const { contentHint: s } = t ?? {}, i = w(e, { contentHint: s });
240
+ const { contentHint: s } = t ?? {}, i = B(e, { contentHint: s });
236
241
  if (i === void 0)
237
242
  throw new Error("No preparedMediaStream");
238
243
  return this.rtcSession.replaceMediaStream(i, t);
@@ -241,33 +246,33 @@ class Re extends Ne {
241
246
  ontrack: e
242
247
  }) => new Promise((t, s) => {
243
248
  const i = () => {
244
- this.events.on(N.PEER_CONNECTION, l), this.events.on(N.CONFIRMED, u);
249
+ this.events.on(C.PEER_CONNECTION, u), this.events.on(C.CONFIRMED, T);
245
250
  }, r = () => {
246
- this.events.off(N.PEER_CONNECTION, l), this.events.off(N.CONFIRMED, u);
251
+ this.events.off(C.PEER_CONNECTION, u), this.events.off(C.CONFIRMED, T);
247
252
  }, a = () => {
248
- this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
253
+ this.events.on(C.FAILED, c), this.events.on(C.ENDED, c);
249
254
  }, o = () => {
250
- this.events.off(N.FAILED, c), this.events.off(N.ENDED, c);
251
- }, c = (d) => {
252
- r(), o(), s(d);
255
+ this.events.off(C.FAILED, c), this.events.off(C.ENDED, c);
256
+ }, c = (h) => {
257
+ r(), o(), s(h);
253
258
  };
254
- let g;
255
- const l = ({ peerconnection: d }) => {
256
- g = d;
257
- const S = (_) => {
258
- this.events.trigger(N.PEER_CONNECTION_ONTRACK, d), e && e(_);
259
+ 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);
259
264
  };
260
- d.addEventListener("track", S), this.disposers.add(() => {
261
- d.removeEventListener("track", S);
265
+ h.addEventListener("track", S), this.disposers.add(() => {
266
+ h.removeEventListener("track", S);
262
267
  });
263
- }, u = () => {
264
- g !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, g), r(), o(), t(g);
268
+ }, T = () => {
269
+ d !== void 0 && this.events.trigger(C.PEER_CONNECTION_CONFIRMED, d), r(), o(), t(d);
265
270
  };
266
271
  i(), a();
267
272
  });
268
273
  subscribeToSessionEvents(e) {
269
274
  this.events.eachTriggers((t, s) => {
270
- const i = z.find((r) => r === s);
275
+ const i = ee.find((r) => r === s);
271
276
  i && (e.on(i, t), this.disposers.add(() => {
272
277
  e.off(i, t);
273
278
  }));
@@ -280,17 +285,17 @@ class Re extends Ne {
280
285
  }
281
286
  handleEnded = (e) => {
282
287
  const { originator: t } = e;
283
- t === $.REMOTE && this.events.trigger(N.ENDED_FROM_SERVER, e), this.reset();
288
+ t === $.REMOTE && this.events.trigger(C.ENDED_FROM_SERVER, e), this.reset();
284
289
  };
285
290
  reset = () => {
286
291
  delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
287
292
  };
288
293
  }
289
- class _e {
294
+ class Ue {
290
295
  events;
291
296
  strategy;
292
297
  constructor(e) {
293
- this.events = new f(Q), this.strategy = e ?? new Re(this.events);
298
+ this.events = new D(te), this.strategy = e ?? new be(this.events);
294
299
  }
295
300
  get requested() {
296
301
  return this.strategy.requested;
@@ -334,13 +339,13 @@ class _e {
334
339
  getRemoteStreams = () => this.strategy.getRemoteStreams();
335
340
  replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
336
341
  }
337
- const G = "sip-connector", P = B(G), ht = () => {
338
- B.enable(G);
339
- }, lt = () => {
340
- B.enable(`-${G}`);
341
- }, Ie = "Error decline with 603", Me = 1006, pe = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Me, me = (n) => n.message === Ie;
342
- 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))(h || {}), L = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(L || {}), F = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n.SPECTATOR_OVER_SFU = "SPECTATOROVERSFU", n))(F || {}), m = /* @__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))(m || {}), I = /* @__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))(I || {}), y = /* @__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))(y || {}), k = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(k || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(W || {}), Pe = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Pe || {}), T = /* @__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))(T || {});
343
- const j = [
342
+ const G = "sip-connector", R = q(G), un = () => {
343
+ q.enable(G);
344
+ }, Tn = () => {
345
+ q.enable(`-${G}`);
346
+ }, we = "Error decline with 603", Le = 1006, Be = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Le, ke = (n) => n.message === we;
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 ie = [
344
349
  "participation:accepting-word-request",
345
350
  "participation:cancelling-word-request",
346
351
  "participant:move-request-to-stream",
@@ -370,8 +375,8 @@ const j = [
370
375
  "mustStopPresentation",
371
376
  "newDTMF"
372
377
  ];
373
- var R = /* @__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))(R || {});
374
- class Oe {
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 {
375
380
  events;
376
381
  connectionManager;
377
382
  callManager;
@@ -379,13 +384,13 @@ class Oe {
379
384
  connectionManager: e,
380
385
  callManager: t
381
386
  }) {
382
- this.connectionManager = e, this.callManager = t, this.events = new f(j), this.subscribe();
387
+ this.connectionManager = e, this.callManager = t, this.events = new D(ie), this.subscribe();
383
388
  }
384
389
  async waitChannels() {
385
- return this.wait(T.CHANNELS);
390
+ return this.wait(g.CHANNELS);
386
391
  }
387
392
  async waitSyncMediaState() {
388
- return this.wait(T.ADMIN_FORCE_SYNC_MEDIA_STATE);
393
+ return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
389
394
  }
390
395
  async sendDTMF(e) {
391
396
  return new Promise((t, s) => {
@@ -404,19 +409,19 @@ class Oe {
404
409
  });
405
410
  }
406
411
  async sendChannels({ inputChannels: e, outputChannels: t }) {
407
- const s = this.getEstablishedRTCSessionProtected(), i = `${h.INPUT_CHANNELS}: ${e}`, r = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
412
+ const s = this.getEstablishedRTCSessionProtected(), i = `${l.INPUT_CHANNELS}: ${e}`, r = `${l.OUTPUT_CHANNELS}: ${t}`, a = [
408
413
  i,
409
414
  r
410
415
  ];
411
- return s.sendInfo(I.CHANNELS, void 0, { extraHeaders: a });
416
+ return s.sendInfo(M.CHANNELS, void 0, { extraHeaders: a });
412
417
  }
413
418
  async sendMediaState({ cam: e, mic: t }, s = {}) {
414
- const i = this.getEstablishedRTCSessionProtected(), r = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
419
+ const i = this.getEstablishedRTCSessionProtected(), r = `${l.MEDIA_STATE}: currentstate`, a = `${l.MAIN_CAM_STATE}: ${Number(e)}`, o = `${l.MIC_STATE}: ${Number(t)}`, c = [
415
420
  r,
416
421
  a,
417
422
  o
418
423
  ];
419
- return i.sendInfo(I.MEDIA_STATE, void 0, {
424
+ return i.sendInfo(M.MEDIA_STATE, void 0, {
420
425
  noTerminateWhenError: !0,
421
426
  ...s,
422
427
  extraHeaders: c
@@ -425,15 +430,15 @@ class Oe {
425
430
  async sendStats({
426
431
  availableIncomingBitrate: e
427
432
  }) {
428
- const t = this.getEstablishedRTCSessionProtected(), i = [`${h.AVAILABLE_INCOMING_BITRATE}: ${e}`];
429
- return t.sendInfo(I.STATS, void 0, {
433
+ const t = this.getEstablishedRTCSessionProtected(), i = [`${l.AVAILABLE_INCOMING_BITRATE}: ${e}`];
434
+ return t.sendInfo(M.STATS, void 0, {
430
435
  noTerminateWhenError: !0,
431
436
  extraHeaders: i
432
437
  });
433
438
  }
434
439
  async sendRefusalToTurnOn(e, t = {}) {
435
- const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${h.MEDIA_TYPE}: ${a}`];
436
- return s.sendInfo(I.REFUSAL, void 0, {
440
+ const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${l.MEDIA_TYPE}: ${a}`];
441
+ return s.sendInfo(M.REFUSAL, void 0, {
437
442
  noTerminateWhenError: !0,
438
443
  ...t,
439
444
  extraHeaders: c
@@ -446,38 +451,38 @@ class Oe {
446
451
  return this.sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
447
452
  }
448
453
  async sendMustStopPresentationP2P() {
449
- await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
450
- extraHeaders: [h.MUST_STOP_PRESENTATION_P2P]
454
+ await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
455
+ extraHeaders: [l.MUST_STOP_PRESENTATION_P2P]
451
456
  });
452
457
  }
453
458
  async sendStoppedPresentationP2P() {
454
- await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
455
- extraHeaders: [h.STOP_PRESENTATION_P2P]
459
+ await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
460
+ extraHeaders: [l.STOP_PRESENTATION_P2P]
456
461
  });
457
462
  }
458
463
  async sendStoppedPresentation() {
459
- await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
460
- extraHeaders: [h.STOP_PRESENTATION]
464
+ await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
465
+ extraHeaders: [l.STOP_PRESENTATION]
461
466
  });
462
467
  }
463
468
  async askPermissionToStartPresentationP2P() {
464
- await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
465
- extraHeaders: [h.START_PRESENTATION_P2P]
469
+ await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
470
+ extraHeaders: [l.START_PRESENTATION_P2P]
466
471
  });
467
472
  }
468
473
  async askPermissionToStartPresentation() {
469
- await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
470
- extraHeaders: [h.START_PRESENTATION]
474
+ await this.getEstablishedRTCSessionProtected().sendInfo(M.SHARE_STATE, void 0, {
475
+ extraHeaders: [l.START_PRESENTATION]
471
476
  });
472
477
  }
473
478
  async askPermissionToEnableCam(e = {}) {
474
- const t = this.getEstablishedRTCSessionProtected(), s = [h.ENABLE_MAIN_CAM];
475
- return t.sendInfo(I.MAIN_CAM, void 0, {
479
+ const t = this.getEstablishedRTCSessionProtected(), s = [l.ENABLE_MAIN_CAM];
480
+ return t.sendInfo(M.MAIN_CAM, void 0, {
476
481
  noTerminateWhenError: !0,
477
482
  ...e,
478
483
  extraHeaders: s
479
484
  }).catch((i) => {
480
- if (me(i))
485
+ if (ke(i))
481
486
  throw i;
482
487
  });
483
488
  }
@@ -516,106 +521,106 @@ class Oe {
516
521
  };
517
522
  maybeHandleNotify = (e) => {
518
523
  try {
519
- const t = e.getHeader(h.NOTIFY);
524
+ const t = e.getHeader(l.NOTIFY);
520
525
  if (t) {
521
526
  const s = JSON.parse(t);
522
527
  this.handleNotify(s);
523
528
  }
524
529
  } catch (t) {
525
- P("error parse notify", t);
530
+ R("error parse notify", t);
526
531
  }
527
532
  };
528
533
  handleNotify = (e) => {
529
534
  switch (e.cmd) {
530
- case R.CHANNELS: {
535
+ case _.CHANNELS: {
531
536
  const t = e;
532
537
  this.triggerChannelsNotify(t);
533
538
  break;
534
539
  }
535
- case R.WEBCAST_STARTED: {
540
+ case _.WEBCAST_STARTED: {
536
541
  const t = e;
537
542
  this.triggerWebcastStartedNotify(t);
538
543
  break;
539
544
  }
540
- case R.WEBCAST_STOPPED: {
545
+ case _.WEBCAST_STOPPED: {
541
546
  const t = e;
542
547
  this.triggerWebcastStoppedNotify(t);
543
548
  break;
544
549
  }
545
- case R.ADDED_TO_LIST_MODERATORS: {
550
+ case _.ADDED_TO_LIST_MODERATORS: {
546
551
  const t = e;
547
552
  this.triggerAddedToListModeratorsNotify(t);
548
553
  break;
549
554
  }
550
- case R.REMOVED_FROM_LIST_MODERATORS: {
555
+ case _.REMOVED_FROM_LIST_MODERATORS: {
551
556
  const t = e;
552
557
  this.triggerRemovedFromListModeratorsNotify(t);
553
558
  break;
554
559
  }
555
- case R.ACCEPTING_WORD_REQUEST: {
560
+ case _.ACCEPTING_WORD_REQUEST: {
556
561
  const t = e;
557
562
  this.triggerParticipationAcceptingWordRequest(t);
558
563
  break;
559
564
  }
560
- case R.CANCELLING_WORD_REQUEST: {
565
+ case _.CANCELLING_WORD_REQUEST: {
561
566
  const t = e;
562
567
  this.triggerParticipationCancellingWordRequest(t);
563
568
  break;
564
569
  }
565
- case R.MOVE_REQUEST_TO_STREAM: {
570
+ case _.MOVE_REQUEST_TO_STREAM: {
566
571
  const t = e;
567
572
  this.triggerParticipantMoveRequestToStream(t);
568
573
  break;
569
574
  }
570
- case R.ACCOUNT_CHANGED: {
575
+ case _.ACCOUNT_CHANGED: {
571
576
  this.triggerAccountChangedNotify();
572
577
  break;
573
578
  }
574
- case R.ACCOUNT_DELETED: {
579
+ case _.ACCOUNT_DELETED: {
575
580
  this.triggerAccountDeletedNotify();
576
581
  break;
577
582
  }
578
- case R.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
583
+ case _.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
579
584
  const t = e;
580
585
  this.triggerConferenceParticipantTokenIssued(t);
581
586
  break;
582
587
  }
583
588
  default:
584
- P("unknown cmd", e);
589
+ R("unknown cmd", e);
585
590
  }
586
591
  };
587
592
  handleNewInfo = (e) => {
588
593
  const { originator: t } = e;
589
594
  if (t !== $.REMOTE)
590
595
  return;
591
- const { request: s } = e, i = s.getHeader(h.CONTENT_TYPE);
596
+ const { request: s } = e, i = s.getHeader(l.CONTENT_TYPE);
592
597
  if (i !== void 0)
593
598
  switch (i) {
594
- case m.ENTER_ROOM: {
599
+ case O.ENTER_ROOM: {
595
600
  this.triggerEnterRoom(s), this.maybeTriggerChannels(s);
596
601
  break;
597
602
  }
598
- case m.NOTIFY: {
603
+ case O.NOTIFY: {
599
604
  this.maybeHandleNotify(s);
600
605
  break;
601
606
  }
602
- case m.SHARE_STATE: {
607
+ case O.SHARE_STATE: {
603
608
  this.triggerShareState(s);
604
609
  break;
605
610
  }
606
- case m.MAIN_CAM: {
611
+ case O.MAIN_CAM: {
607
612
  this.triggerMainCamControl(s);
608
613
  break;
609
614
  }
610
- case m.MIC: {
615
+ case O.MIC: {
611
616
  this.triggerMicControl(s);
612
617
  break;
613
618
  }
614
- case m.USE_LICENSE: {
619
+ case O.USE_LICENSE: {
615
620
  this.triggerUseLicense(s);
616
621
  break;
617
622
  }
618
- case m.PARTICIPANT_STATE: {
623
+ case O.PARTICIPANT_STATE: {
619
624
  this.maybeTriggerParticipantMoveRequest(s);
620
625
  break;
621
626
  }
@@ -626,7 +631,7 @@ class Oe {
626
631
  inputChannels: t,
627
632
  outputChannels: s
628
633
  };
629
- this.events.trigger(T.CHANNELS_NOTIFY, i);
634
+ this.events.trigger(g.CHANNELS_NOTIFY, i);
630
635
  };
631
636
  triggerWebcastStartedNotify = ({
632
637
  body: { conference: e, type: t }
@@ -635,7 +640,7 @@ class Oe {
635
640
  conference: e,
636
641
  type: t
637
642
  };
638
- this.events.trigger(T.WEBCAST_STARTED, s);
643
+ this.events.trigger(g.WEBCAST_STARTED, s);
639
644
  };
640
645
  triggerWebcastStoppedNotify = ({
641
646
  body: { conference: e, type: t }
@@ -644,7 +649,7 @@ class Oe {
644
649
  conference: e,
645
650
  type: t
646
651
  };
647
- this.events.trigger(T.WEBCAST_STOPPED, s);
652
+ this.events.trigger(g.WEBCAST_STOPPED, s);
648
653
  };
649
654
  triggerAddedToListModeratorsNotify = ({
650
655
  conference: e
@@ -653,7 +658,7 @@ class Oe {
653
658
  conference: e
654
659
  };
655
660
  this.events.trigger(
656
- T.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
661
+ g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
657
662
  t
658
663
  );
659
664
  };
@@ -664,7 +669,7 @@ class Oe {
664
669
  conference: e
665
670
  };
666
671
  this.events.trigger(
667
- T.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
672
+ g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
668
673
  t
669
674
  );
670
675
  };
@@ -674,7 +679,7 @@ class Oe {
674
679
  const t = {
675
680
  conference: e
676
681
  };
677
- this.events.trigger(T.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
682
+ this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
678
683
  };
679
684
  triggerParticipationCancellingWordRequest = ({
680
685
  body: { conference: e }
@@ -682,7 +687,7 @@ class Oe {
682
687
  const t = {
683
688
  conference: e
684
689
  };
685
- this.events.trigger(T.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
690
+ this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
686
691
  };
687
692
  triggerParticipantMoveRequestToStream = ({
688
693
  body: { conference: e }
@@ -690,13 +695,13 @@ class Oe {
690
695
  const t = {
691
696
  conference: e
692
697
  };
693
- this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
698
+ this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
694
699
  };
695
700
  triggerAccountChangedNotify = () => {
696
- this.events.trigger(T.ACCOUNT_CHANGED, void 0);
701
+ this.events.trigger(g.ACCOUNT_CHANGED, void 0);
697
702
  };
698
703
  triggerAccountDeletedNotify = () => {
699
- this.events.trigger(T.ACCOUNT_DELETED, void 0);
704
+ this.events.trigger(g.ACCOUNT_DELETED, void 0);
700
705
  };
701
706
  triggerConferenceParticipantTokenIssued = ({
702
707
  body: { conference: e, participant: t, jwt: s }
@@ -707,89 +712,164 @@ class Oe {
707
712
  jwt: s
708
713
  };
709
714
  this.events.trigger(
710
- T.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
715
+ g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
711
716
  i
712
717
  );
713
718
  };
714
719
  maybeTriggerChannels = (e) => {
715
- const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
720
+ const t = e.getHeader(l.INPUT_CHANNELS), s = e.getHeader(l.OUTPUT_CHANNELS);
716
721
  if (t && s) {
717
722
  const i = {
718
723
  inputChannels: t,
719
724
  outputChannels: s
720
725
  };
721
- this.events.trigger(T.CHANNELS, i);
726
+ this.events.trigger(g.CHANNELS, i);
722
727
  }
723
728
  };
724
729
  triggerEnterRoom = (e) => {
725
- const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
726
- this.events.trigger(T.ENTER_ROOM, { room: t, participantName: s });
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 });
727
732
  };
728
733
  triggerShareState = (e) => {
729
- const t = e.getHeader(h.CONTENT_SHARE_STATE);
734
+ const t = e.getHeader(l.CONTENT_SHARE_STATE);
730
735
  if (t !== void 0)
731
736
  switch (t) {
732
- case L.AVAILABLE_SECOND_REMOTE_STREAM: {
733
- this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
737
+ case k.AVAILABLE_SECOND_REMOTE_STREAM: {
738
+ this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
734
739
  break;
735
740
  }
736
- case L.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
737
- this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
741
+ case k.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
742
+ this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
738
743
  break;
739
744
  }
740
- case L.MUST_STOP_PRESENTATION: {
741
- this.events.trigger(T.MUST_STOP_PRESENTATION, void 0);
745
+ case k.MUST_STOP_PRESENTATION: {
746
+ this.events.trigger(g.MUST_STOP_PRESENTATION, void 0);
742
747
  break;
743
748
  }
744
749
  }
745
750
  };
746
751
  maybeTriggerParticipantMoveRequest = (e) => {
747
- const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
748
- t === F.SPECTATOR && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === F.PARTICIPANT && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0), t === F.SPECTATOR_OVER_SFU && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU, void 0);
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);
749
754
  };
750
755
  triggerMainCamControl = (e) => {
751
- const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), i = s === W.ADMIN_SYNC_FORCED;
752
- if (t === y.ADMIN_START_MAIN_CAM) {
753
- this.events.trigger(T.ADMIN_START_MAIN_CAM, { isSyncForced: i });
756
+ const t = e.getHeader(l.MAIN_CAM), s = e.getHeader(l.MEDIA_SYNC), i = s === H.ADMIN_SYNC_FORCED;
757
+ if (t === P.ADMIN_START_MAIN_CAM) {
758
+ this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: i });
754
759
  return;
755
760
  }
756
- if (t === y.ADMIN_STOP_MAIN_CAM) {
757
- this.events.trigger(T.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
761
+ if (t === P.ADMIN_STOP_MAIN_CAM) {
762
+ this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
758
763
  return;
759
764
  }
760
- (t === y.RESUME_MAIN_CAM || t === y.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(T.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
761
- const r = e.getHeader(h.MAIN_CAM_RESOLUTION);
762
- this.events.trigger(T.MAIN_CAM_CONTROL, {
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, {
763
768
  mainCam: t,
764
769
  resolutionMainCam: r
765
770
  });
766
771
  };
767
772
  triggerMicControl = (e) => {
768
- const t = e.getHeader(h.MIC), i = e.getHeader(h.MEDIA_SYNC) === W.ADMIN_SYNC_FORCED;
769
- t === k.ADMIN_START_MIC ? this.events.trigger(T.ADMIN_START_MIC, { isSyncForced: i }) : t === k.ADMIN_STOP_MIC && this.events.trigger(T.ADMIN_STOP_MIC, { isSyncForced: i });
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 });
770
775
  };
771
776
  triggerUseLicense = (e) => {
772
- const t = e.getHeader(h.CONTENT_USE_LICENSE);
773
- this.events.trigger(T.USE_LICENSE, t);
777
+ const t = e.getHeader(l.CONTENT_USE_LICENSE);
778
+ this.events.trigger(g.USE_LICENSE, t);
774
779
  };
775
780
  }
776
- var M = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(M || {});
777
- const K = [
781
+ const Ve = (n, e) => (n.degradationPreference = e.degradationPreference, n), We = (n, e) => {
782
+ n.encodings ??= [];
783
+ for (let t = n.encodings.length; t < e; t += 1)
784
+ n.encodings.push({});
785
+ return n;
786
+ }, re = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, He = re(), xe = (n, e) => {
787
+ if (He(n, e))
788
+ return n;
789
+ }, qe = (n, e) => {
790
+ const t = n.maxBitrate, s = xe(e, t);
791
+ return s !== void 0 && (n.maxBitrate = s), n;
792
+ }, ae = 1, Ge = re(
793
+ ae
794
+ ), Qe = (n, e) => {
795
+ const t = n === void 0 ? void 0 : Math.max(n, ae);
796
+ if (t !== void 0 && Ge(
797
+ t,
798
+ e
799
+ ))
800
+ return t;
801
+ }, Ye = (n, e) => {
802
+ const t = n.scaleResolutionDownBy, s = Qe(
803
+ e,
804
+ t
805
+ );
806
+ return s !== void 0 && (n.scaleResolutionDownBy = s), n;
807
+ }, ze = (n, e) => {
808
+ 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);
812
+ }), n;
813
+ }, Je = (n, e) => {
814
+ if (n.codecs?.length !== e.codecs?.length)
815
+ return !0;
816
+ for (let t = 0; t < (n.codecs?.length ?? 0); t++)
817
+ if (JSON.stringify(n.codecs[t]) !== JSON.stringify(e.codecs[t]))
818
+ return !0;
819
+ if (n.headerExtensions?.length !== e.headerExtensions?.length)
820
+ return !0;
821
+ for (let t = 0; t < (n.headerExtensions?.length ?? 0); t++)
822
+ if (JSON.stringify(n.headerExtensions[t]) !== JSON.stringify(e.headerExtensions[t]))
823
+ return !0;
824
+ if (n.encodings?.length !== e.encodings?.length)
825
+ return !0;
826
+ for (let t = 0; t < (n.encodings?.length ?? 0); t++)
827
+ if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
828
+ return !0;
829
+ return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
830
+ }, Xe = async (n, e) => {
831
+ const t = n.getParameters(), s = JSON.parse(
832
+ JSON.stringify(t)
833
+ );
834
+ ze(t, e), Ve(t, e);
835
+ const i = Je(s, t);
836
+ return i && await n.setParameters(t), { parameters: t, isChanged: i };
837
+ }, oe = async (n, e, t) => {
838
+ const { isChanged: s, parameters: i } = await Xe(n, {
839
+ encodings: [
840
+ {
841
+ scaleResolutionDownBy: e.scaleResolutionDownBy,
842
+ maxBitrate: e.maxBitrate
843
+ }
844
+ ]
845
+ });
846
+ return s && t && t(i), { isChanged: s, parameters: i };
847
+ }, je = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ke = async (n, e, t) => {
848
+ const s = je(n, e);
849
+ if (s)
850
+ return oe(s, { maxBitrate: t });
851
+ };
852
+ var f = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(f || {});
853
+ const ce = [
778
854
  "presentation:start",
779
855
  "presentation:started",
780
856
  "presentation:end",
781
857
  "presentation:ended",
782
858
  "presentation:failed"
783
- ], fe = 1, St = (n) => ce(n);
784
- class ve {
859
+ ], Ze = 1, Sn = (n) => Re(n);
860
+ class et {
785
861
  events;
786
862
  promisePendingStartPresentation;
787
863
  promisePendingStopPresentation;
788
864
  streamPresentationCurrent;
865
+ maxBitrate;
789
866
  cancelableSendPresentationWithRepeatedCalls;
790
867
  callManager;
791
- constructor({ callManager: e }) {
792
- this.callManager = e, this.events = new f(K), this.subscribe();
868
+ constructor({
869
+ callManager: e,
870
+ maxBitrate: t
871
+ }) {
872
+ this.callManager = e, this.maxBitrate = t, this.events = new D(ce), this.subscribe();
793
873
  }
794
874
  get isPendingPresentation() {
795
875
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
@@ -797,25 +877,23 @@ class ve {
797
877
  // eslint-disable-next-line @typescript-eslint/max-params
798
878
  async startPresentation(e, t, {
799
879
  isNeedReinvite: s,
800
- maxBitrate: i,
801
- contentHint: r,
802
- sendEncodings: a,
803
- onAddedTransceiver: o
804
- } = {}, c) {
805
- const g = this.getRtcSessionProtected();
880
+ contentHint: i,
881
+ sendEncodings: r,
882
+ onAddedTransceiver: a
883
+ } = {}, o) {
884
+ const c = this.getRtcSessionProtected();
806
885
  if (this.streamPresentationCurrent)
807
886
  throw new Error("Presentation is already started");
808
887
  return this.sendPresentationWithDuplicatedCalls(e, {
809
- rtcSession: g,
888
+ rtcSession: c,
810
889
  stream: t,
811
890
  presentationOptions: {
812
891
  isNeedReinvite: s,
813
- maxBitrate: i,
814
- contentHint: r,
815
- sendEncodings: a,
816
- onAddedTransceiver: o
892
+ contentHint: i,
893
+ sendEncodings: r,
894
+ onAddedTransceiver: a
817
895
  },
818
- options: c
896
+ options: o
819
897
  });
820
898
  }
821
899
  async stopPresentation(e) {
@@ -824,13 +902,12 @@ class ve {
824
902
  let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
825
903
  const i = this.callManager.getEstablishedRTCSession();
826
904
  return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
827
- throw this.events.trigger(M.FAILED_PRESENTATION, r), r;
828
- }) : t && this.events.trigger(M.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
905
+ throw this.events.trigger(f.FAILED_PRESENTATION, r), r;
906
+ }) : t && this.events.trigger(f.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
829
907
  this.resetPresentation();
830
908
  });
831
909
  }
832
910
  async updatePresentation(e, t, {
833
- // maxBitrate,
834
911
  contentHint: s,
835
912
  sendEncodings: i,
836
913
  onAddedTransceiver: r
@@ -839,12 +916,11 @@ class ve {
839
916
  if (!this.streamPresentationCurrent)
840
917
  throw new Error("Presentation has not started yet");
841
918
  return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
842
- // maxBitrate,
843
919
  contentHint: s,
844
920
  isNeedReinvite: !1,
845
921
  sendEncodings: i,
846
922
  onAddedTransceiver: r
847
- });
923
+ }).then(async (o) => (await this.setMaxBitrate(), o));
848
924
  }
849
925
  cancelSendPresentationWithRepeatedCalls() {
850
926
  this.cancelableSendPresentationWithRepeatedCalls?.cancel();
@@ -870,15 +946,15 @@ class ve {
870
946
  }
871
947
  subscribe() {
872
948
  this.callManager.on("presentation:start", (e) => {
873
- this.events.trigger(M.START_PRESENTATION, e);
949
+ this.events.trigger(f.START_PRESENTATION, e);
874
950
  }), this.callManager.on("presentation:started", (e) => {
875
- this.events.trigger(M.STARTED_PRESENTATION, e);
951
+ this.events.trigger(f.STARTED_PRESENTATION, e);
876
952
  }), this.callManager.on("presentation:end", (e) => {
877
- this.events.trigger(M.END_PRESENTATION, e);
953
+ this.events.trigger(f.END_PRESENTATION, e);
878
954
  }), this.callManager.on("presentation:ended", (e) => {
879
- this.events.trigger(M.ENDED_PRESENTATION, e);
955
+ this.events.trigger(f.ENDED_PRESENTATION, e);
880
956
  }), this.callManager.on("presentation:failed", (e) => {
881
- this.events.trigger(M.FAILED_PRESENTATION, e);
957
+ this.events.trigger(f.FAILED_PRESENTATION, e);
882
958
  }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
883
959
  }
884
960
  async sendPresentationWithDuplicatedCalls(e, {
@@ -886,7 +962,7 @@ class ve {
886
962
  stream: s,
887
963
  presentationOptions: i,
888
964
  options: r = {
889
- callLimit: fe
965
+ callLimit: Ze
890
966
  }
891
967
  }) {
892
968
  const a = async () => this.sendPresentation(
@@ -895,7 +971,7 @@ class ve {
895
971
  s,
896
972
  i
897
973
  ), o = () => !!this.streamPresentationCurrent;
898
- return this.cancelableSendPresentationWithRepeatedCalls = Y({
974
+ return this.cancelableSendPresentationWithRepeatedCalls = K({
899
975
  targetFunction: a,
900
976
  isComplete: o,
901
977
  isRejectAsValid: !0,
@@ -904,26 +980,34 @@ class ve {
904
980
  }
905
981
  // eslint-disable-next-line @typescript-eslint/max-params
906
982
  async sendPresentation(e, t, s, {
907
- // maxBitrate = ONE_MEGABIT_IN_BITS,
908
983
  isNeedReinvite: i = !0,
909
984
  contentHint: r = "detail",
910
- sendEncodings: a,
911
- onAddedTransceiver: o
985
+ degradationPreference: a,
986
+ sendEncodings: o,
987
+ onAddedTransceiver: c
912
988
  }) {
913
- const c = w(s, { contentHint: r });
914
- if (c === void 0)
989
+ const d = B(s, { contentHint: r });
990
+ if (d === void 0)
915
991
  throw new Error("No streamPresentationTarget");
916
- this.streamPresentationCurrent = c;
917
- const g = e().then(async () => t.startPresentation(c, i, {
918
- sendEncodings: a,
919
- onAddedTransceiver: o
920
- })).then(() => s).catch((l) => {
921
- throw this.removeStreamPresentationCurrent(), this.events.trigger(M.FAILED_PRESENTATION, l), l;
992
+ this.streamPresentationCurrent = d;
993
+ const u = e().then(async () => t.startPresentation(d, i, {
994
+ degradationPreference: a,
995
+ sendEncodings: o,
996
+ onAddedTransceiver: c
997
+ })).then(this.setMaxBitrate).then(() => s).catch((T) => {
998
+ throw this.removeStreamPresentationCurrent(), this.events.trigger(f.FAILED_PRESENTATION, T), T;
922
999
  });
923
- return this.promisePendingStartPresentation = g, g.finally(() => {
1000
+ return this.promisePendingStartPresentation = u, u.finally(() => {
924
1001
  this.promisePendingStartPresentation = void 0;
925
1002
  });
926
1003
  }
1004
+ setMaxBitrate = async () => {
1005
+ const { connection: e } = this.callManager, { streamPresentationCurrent: t } = this, { maxBitrate: s } = this;
1006
+ if (!e || !t || s === void 0)
1007
+ return;
1008
+ const i = e.getSenders();
1009
+ await Ke(i, t, s);
1010
+ };
927
1011
  getRtcSessionProtected = () => {
928
1012
  const e = this.callManager.getEstablishedRTCSession();
929
1013
  if (!e)
@@ -943,7 +1027,7 @@ class ve {
943
1027
  delete this.streamPresentationCurrent;
944
1028
  }
945
1029
  }
946
- class De {
1030
+ class tt {
947
1031
  data = {};
948
1032
  getUa;
949
1033
  constructor(e) {
@@ -1016,8 +1100,8 @@ class De {
1016
1100
  return this.data.register === !0;
1017
1101
  }
1018
1102
  }
1019
- 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 || {});
1020
- const Z = [
1103
+ 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 || {});
1104
+ const de = [
1021
1105
  "connecting",
1022
1106
  "connected",
1023
1107
  "disconnected",
@@ -1027,8 +1111,8 @@ const Z = [
1027
1111
  "registrationFailed",
1028
1112
  "newMessage",
1029
1113
  "sipEvent"
1030
- ], ee = [...Z], ye = 3;
1031
- class be {
1114
+ ], he = [...de], nt = 3;
1115
+ class st {
1032
1116
  cancelableConnectWithRepeatedCalls;
1033
1117
  JsSIP;
1034
1118
  events;
@@ -1054,29 +1138,29 @@ class be {
1054
1138
  }
1055
1139
  let r = !1;
1056
1140
  const a = this.getConnectionConfiguration();
1057
- e !== void 0 && e !== a.displayName && (r = i.set("display_name", X(e)), this.updateConnectionConfiguration("displayName", e));
1141
+ e !== void 0 && e !== a.displayName && (r = i.set("display_name", ne(e)), this.updateConnectionConfiguration("displayName", e));
1058
1142
  const o = r;
1059
1143
  o ? t(o) : s(new Error("nothing changed"));
1060
1144
  });
1061
1145
  disconnect = async () => {
1062
1146
  const e = new Promise((s) => {
1063
- this.events.once(A.DISCONNECTED, () => {
1147
+ this.events.once(N.DISCONNECTED, () => {
1064
1148
  s();
1065
1149
  });
1066
1150
  }), t = this.getUa();
1067
- return t ? t.stop() : this.events.trigger(A.DISCONNECTED, void 0), e.finally(() => {
1151
+ return t ? t.stop() : this.events.trigger(N.DISCONNECTED, void 0), e.finally(() => {
1068
1152
  this.setUa(void 0), this.stateMachine.reset();
1069
1153
  });
1070
1154
  };
1071
1155
  cancelRequests() {
1072
1156
  this.cancelConnectWithRepeatedCalls();
1073
1157
  }
1074
- connectWithDuplicatedCalls = async (e, { callLimit: t = ye } = {}) => {
1158
+ connectWithDuplicatedCalls = async (e, { callLimit: t = nt } = {}) => {
1075
1159
  const s = async () => this.connectInner(e), i = (r) => {
1076
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), g = r != null && !pe(r);
1077
- return c || g;
1160
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !Be(r);
1161
+ return c || d;
1078
1162
  };
1079
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = Y({
1163
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = K({
1080
1164
  targetFunction: s,
1081
1165
  isComplete: i,
1082
1166
  callLimit: t,
@@ -1102,38 +1186,38 @@ class be {
1102
1186
  sessionTimers: a,
1103
1187
  registerExpires: o,
1104
1188
  connectionRecoveryMinInterval: c,
1105
- connectionRecoveryMaxInterval: g,
1106
- userAgent: l,
1107
- displayName: u = "",
1108
- register: d = !1,
1189
+ connectionRecoveryMaxInterval: d,
1190
+ userAgent: u,
1191
+ displayName: T = "",
1192
+ register: h = !1,
1109
1193
  extraHeaders: S = []
1110
1194
  }) => {
1111
1195
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1112
1196
  sipServerUrl: s,
1113
- displayName: u,
1114
- register: d,
1197
+ displayName: T,
1198
+ register: h,
1115
1199
  user: e,
1116
1200
  password: t
1117
1201
  }), this.getUa() && await this.disconnect();
1118
- const { ua: C, helpers: p } = this.uaFactory.createUAWithConfiguration(
1202
+ const { ua: I, helpers: A } = this.uaFactory.createUAWithConfiguration(
1119
1203
  {
1120
1204
  user: e,
1121
1205
  password: t,
1122
1206
  sipServerUrl: s,
1123
1207
  sipWebSocketServerURL: i,
1124
- displayName: u,
1125
- register: d,
1208
+ displayName: T,
1209
+ register: h,
1126
1210
  sessionTimers: a,
1127
1211
  registerExpires: o,
1128
1212
  connectionRecoveryMinInterval: c,
1129
- connectionRecoveryMaxInterval: g,
1130
- userAgent: l,
1213
+ connectionRecoveryMaxInterval: d,
1214
+ userAgent: u,
1131
1215
  remoteAddress: r,
1132
1216
  extraHeaders: S
1133
1217
  },
1134
1218
  this.events
1135
1219
  );
1136
- return this.setUa(C), this.setSipServerUrl(p.getSipServerUrl), this.setSocket(p.socket), C;
1220
+ return this.setUa(I), this.setSipServerUrl(A.getSipServerUrl), this.setSocket(A.socket), I;
1137
1221
  };
1138
1222
  start = async () => new Promise((e, t) => {
1139
1223
  const s = this.getUa();
@@ -1142,15 +1226,15 @@ class be {
1142
1226
  return;
1143
1227
  }
1144
1228
  let i;
1145
- i = ((c, g) => {
1229
+ i = ((c, d) => {
1146
1230
  if (this.getConnectionConfiguration().register === !0)
1147
- return this.registrationManager.subscribeToStartEvents(c, g);
1148
- const u = A.CONNECTED, d = [A.DISCONNECTED];
1149
- return this.events.on(u, c), d.forEach((S) => {
1150
- this.events.on(S, g);
1231
+ return this.registrationManager.subscribeToStartEvents(c, d);
1232
+ const T = N.CONNECTED, h = [N.DISCONNECTED];
1233
+ return this.events.on(T, c), h.forEach((S) => {
1234
+ this.events.on(S, d);
1151
1235
  }), () => {
1152
- this.events.off(u, c), d.forEach((S) => {
1153
- this.events.off(S, g);
1236
+ this.events.off(T, c), h.forEach((S) => {
1237
+ this.events.off(S, d);
1154
1238
  });
1155
1239
  };
1156
1240
  })(() => {
@@ -1163,18 +1247,18 @@ class be {
1163
1247
  this.cancelableConnectWithRepeatedCalls?.cancel();
1164
1248
  }
1165
1249
  }
1166
- var te = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(te || {});
1167
- const Ue = ge({
1250
+ var ge = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(ge || {});
1251
+ const it = Ie({
1168
1252
  types: {
1169
1253
  context: {},
1170
1254
  events: {}
1171
1255
  },
1172
1256
  actions: {
1173
1257
  logTransition: (n, e) => {
1174
- P(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1258
+ R(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1175
1259
  },
1176
1260
  logStateChange: (n, e) => {
1177
- P("ConnectionStateMachine state changed", e.state);
1261
+ R("ConnectionStateMachine state changed", e.state);
1178
1262
  }
1179
1263
  }
1180
1264
  }).createMachine({
@@ -1478,14 +1562,14 @@ const Ue = ge({
1478
1562
  }
1479
1563
  }
1480
1564
  });
1481
- class we {
1565
+ class rt {
1482
1566
  actor;
1483
1567
  stateChangeListeners = /* @__PURE__ */ new Set();
1484
1568
  events;
1485
1569
  unsubscribeFromEvents;
1486
1570
  actorSubscription;
1487
1571
  constructor(e) {
1488
- this.events = e, this.actor = de(Ue), this.actorSubscription = this.actor.subscribe((t) => {
1572
+ this.events = e, this.actor = _e(it), this.actorSubscription = this.actor.subscribe((t) => {
1489
1573
  const s = t.value;
1490
1574
  this.stateChangeListeners.forEach((i) => {
1491
1575
  i(s);
@@ -1571,7 +1655,7 @@ class we {
1571
1655
  return this.actor.getSnapshot().can({ type: e });
1572
1656
  }
1573
1657
  getValidEvents() {
1574
- return Object.values(te).filter((e) => this.canTransition(e));
1658
+ return Object.values(ge).filter((e) => this.canTransition(e));
1575
1659
  }
1576
1660
  hasState(e) {
1577
1661
  return this.actor.getSnapshot().matches(e);
@@ -1579,7 +1663,7 @@ class we {
1579
1663
  sendEvent(e) {
1580
1664
  const t = this.actor.getSnapshot(), s = { type: e };
1581
1665
  if (!t.can(s)) {
1582
- P(
1666
+ R(
1583
1667
  `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
1584
1668
  );
1585
1669
  return;
@@ -1640,7 +1724,7 @@ class we {
1640
1724
  };
1641
1725
  }
1642
1726
  }
1643
- class Le {
1727
+ class at {
1644
1728
  events;
1645
1729
  getUaProtected;
1646
1730
  constructor(e) {
@@ -1649,25 +1733,25 @@ class Le {
1649
1733
  async register() {
1650
1734
  const e = this.getUaProtected();
1651
1735
  return new Promise((t, s) => {
1652
- e.on(A.REGISTERED, t), e.on(A.REGISTRATION_FAILED, s), e.register();
1736
+ e.on(N.REGISTERED, t), e.on(N.REGISTRATION_FAILED, s), e.register();
1653
1737
  });
1654
1738
  }
1655
1739
  async unregister() {
1656
1740
  const e = this.getUaProtected();
1657
1741
  return new Promise((t) => {
1658
- e.on(A.UNREGISTERED, t), e.unregister();
1742
+ e.on(N.UNREGISTERED, t), e.unregister();
1659
1743
  });
1660
1744
  }
1661
1745
  async tryRegister() {
1662
1746
  try {
1663
1747
  await this.unregister();
1664
1748
  } catch (e) {
1665
- P("tryRegister", e);
1749
+ R("tryRegister", e);
1666
1750
  }
1667
1751
  return this.register();
1668
1752
  }
1669
1753
  subscribeToStartEvents(e, t) {
1670
- const s = A.REGISTERED, i = [A.REGISTRATION_FAILED, A.DISCONNECTED];
1754
+ const s = N.REGISTERED, i = [N.REGISTRATION_FAILED, N.DISCONNECTED];
1671
1755
  return this.events.on(s, e), i.forEach((r) => {
1672
1756
  this.events.on(r, t);
1673
1757
  }), () => {
@@ -1677,7 +1761,7 @@ class Le {
1677
1761
  };
1678
1762
  }
1679
1763
  }
1680
- class Fe {
1764
+ class ot {
1681
1765
  uaFactory;
1682
1766
  getUaProtected;
1683
1767
  constructor(e) {
@@ -1723,30 +1807,30 @@ class Fe {
1723
1807
  extraHeaders: a
1724
1808
  }) {
1725
1809
  return new Promise((o, c) => {
1726
- const { configuration: g } = this.uaFactory.createConfiguration({
1810
+ const { configuration: d } = this.uaFactory.createConfiguration({
1727
1811
  sipWebSocketServerURL: i,
1728
1812
  displayName: t,
1729
1813
  userAgent: e,
1730
1814
  sipServerUrl: s
1731
- }), l = this.uaFactory.createUA({ ...g, remoteAddress: r, extraHeaders: a }), u = () => {
1815
+ }), u = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), T = () => {
1732
1816
  const S = new Error("Telephony is not available");
1733
1817
  c(S);
1734
1818
  };
1735
- l.once(A.DISCONNECTED, u);
1736
- const d = () => {
1737
- l.removeAllListeners(), l.once(A.DISCONNECTED, () => {
1819
+ u.once(N.DISCONNECTED, T);
1820
+ const h = () => {
1821
+ u.removeAllListeners(), u.once(N.DISCONNECTED, () => {
1738
1822
  o();
1739
- }), l.stop();
1823
+ }), u.stop();
1740
1824
  };
1741
- l.once(A.CONNECTED, d), l.start();
1825
+ u.once(N.CONNECTED, h), u.start();
1742
1826
  });
1743
1827
  }
1744
1828
  }
1745
- const $e = (n) => {
1829
+ const ct = (n) => {
1746
1830
  const e = [];
1747
1831
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1748
1832
  };
1749
- class O {
1833
+ class v {
1750
1834
  JsSIP;
1751
1835
  constructor(e) {
1752
1836
  this.JsSIP = e;
@@ -1771,10 +1855,10 @@ class O {
1771
1855
  throw new Error("user is required for authorized connection");
1772
1856
  }
1773
1857
  static resolveAuthorizationUser(e, t) {
1774
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${ue()}`;
1858
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${Oe()}`;
1775
1859
  }
1776
1860
  static buildExtraHeaders(e, t) {
1777
- const s = e !== void 0 && e !== "" ? $e(e) : [];
1861
+ const s = e !== void 0 && e !== "" ? ct(e) : [];
1778
1862
  return t === void 0 ? s : [...s, ...t];
1779
1863
  }
1780
1864
  createConfiguration({
@@ -1787,40 +1871,40 @@ class O {
1787
1871
  sessionTimers: o = !1,
1788
1872
  registerExpires: c = 300,
1789
1873
  // 5 minutes in sec
1790
- connectionRecoveryMinInterval: g = 2,
1791
- connectionRecoveryMaxInterval: l = 6,
1792
- userAgent: u
1874
+ connectionRecoveryMinInterval: d = 2,
1875
+ connectionRecoveryMaxInterval: u = 6,
1876
+ userAgent: T
1793
1877
  }) {
1794
- O.validateConfiguration({
1878
+ v.validateConfiguration({
1795
1879
  register: a,
1796
1880
  password: t,
1797
1881
  user: e,
1798
1882
  sipServerUrl: r,
1799
1883
  sipWebSocketServerURL: s
1800
1884
  });
1801
- const d = O.resolveAuthorizationUser(a, e), S = Se(r), _ = S(d), C = new this.JsSIP.WebSocketInterface(s);
1885
+ const h = v.resolveAuthorizationUser(a, e), S = Pe(r), m = S(h), I = new this.JsSIP.WebSocketInterface(s);
1802
1886
  return {
1803
1887
  configuration: {
1804
1888
  password: t,
1805
1889
  register: a,
1806
- uri: _,
1807
- display_name: X(i),
1808
- user_agent: u,
1890
+ uri: m,
1891
+ display_name: ne(i),
1892
+ user_agent: T,
1809
1893
  sdpSemantics: "unified-plan",
1810
- sockets: [C],
1894
+ sockets: [I],
1811
1895
  session_timers: o,
1812
1896
  register_expires: c,
1813
- connection_recovery_min_interval: g,
1814
- connection_recovery_max_interval: l
1897
+ connection_recovery_min_interval: d,
1898
+ connection_recovery_max_interval: u
1815
1899
  },
1816
1900
  helpers: {
1817
- socket: C,
1901
+ socket: I,
1818
1902
  getSipServerUrl: S
1819
1903
  }
1820
1904
  };
1821
1905
  }
1822
1906
  createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
1823
- const i = new this.JsSIP.UA(s), r = O.buildExtraHeaders(e, t);
1907
+ const i = new this.JsSIP.UA(s), r = v.buildExtraHeaders(e, t);
1824
1908
  return r.length > 0 && i.registrator().setExtraHeaders(r), i;
1825
1909
  }
1826
1910
  /**
@@ -1833,12 +1917,12 @@ class O {
1833
1917
  extraHeaders: e.extraHeaders
1834
1918
  });
1835
1919
  return t.eachTriggers((a, o) => {
1836
- const c = Z.find((g) => g === o);
1920
+ const c = de.find((d) => d === o);
1837
1921
  c && r.on(c, a);
1838
1922
  }), { ua: r, helpers: i };
1839
1923
  }
1840
1924
  }
1841
- class ke {
1925
+ class dt {
1842
1926
  events;
1843
1927
  ua;
1844
1928
  socket;
@@ -1850,15 +1934,15 @@ class ke {
1850
1934
  configurationManager;
1851
1935
  JsSIP;
1852
1936
  constructor({ JsSIP: e }) {
1853
- this.JsSIP = e, this.events = new f(ee), this.uaFactory = new O(e), this.registrationManager = new Le({
1937
+ this.JsSIP = e, this.events = new D(he), this.uaFactory = new v(e), this.registrationManager = new at({
1854
1938
  events: this.events,
1855
1939
  getUaProtected: this.getUaProtected
1856
- }), this.stateMachine = new we(this.events), this.configurationManager = new De({
1940
+ }), this.stateMachine = new rt(this.events), this.configurationManager = new tt({
1857
1941
  getUa: this.getUa
1858
- }), this.sipOperations = new Fe({
1942
+ }), this.sipOperations = new ot({
1859
1943
  uaFactory: this.uaFactory,
1860
1944
  getUaProtected: this.getUaProtected
1861
- }), this.connectionFlow = new be({
1945
+ }), this.connectionFlow = new st({
1862
1946
  JsSIP: this.JsSIP,
1863
1947
  events: this.events,
1864
1948
  uaFactory: this.uaFactory,
@@ -1896,7 +1980,7 @@ class ke {
1896
1980
  return this.stateMachine.state;
1897
1981
  }
1898
1982
  get isRegistered() {
1899
- return O.isRegisteredUA(this.ua);
1983
+ return v.isRegisteredUA(this.ua);
1900
1984
  }
1901
1985
  get isRegisterConfig() {
1902
1986
  return this.configurationManager.isRegister();
@@ -1949,19 +2033,19 @@ class ke {
1949
2033
  };
1950
2034
  getUa = () => this.ua;
1951
2035
  }
1952
- var b = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(b || {}), V = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(V || {});
1953
- const ne = [
2036
+ var w = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(w || {}), x = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(x || {});
2037
+ const le = [
1954
2038
  "incomingCall",
1955
2039
  "declinedIncomingCall",
1956
2040
  "terminatedIncomingCall",
1957
2041
  "failedIncomingCall"
1958
- ], We = 486, Ve = 487;
1959
- class Be {
2042
+ ], ht = 486, gt = 487;
2043
+ class lt {
1960
2044
  events;
1961
2045
  incomingRTCSession;
1962
2046
  connectionManager;
1963
2047
  constructor(e) {
1964
- this.connectionManager = e, this.events = new f(ne), this.start();
2048
+ this.connectionManager = e, this.events = new D(le), this.start();
1965
2049
  }
1966
2050
  get remoteCallerData() {
1967
2051
  return {
@@ -1991,19 +2075,19 @@ class Be {
1991
2075
  return this.removeIncomingSession(), e;
1992
2076
  };
1993
2077
  async declineToIncomingCall({
1994
- statusCode: e = Ve
2078
+ statusCode: e = gt
1995
2079
  } = {}) {
1996
2080
  return new Promise((t, s) => {
1997
2081
  try {
1998
2082
  const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
1999
- this.removeIncomingSession(), this.events.trigger(b.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2083
+ this.removeIncomingSession(), this.events.trigger(w.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2000
2084
  } catch (i) {
2001
2085
  s(i);
2002
2086
  }
2003
2087
  });
2004
2088
  }
2005
2089
  async busyIncomingCall() {
2006
- return this.declineToIncomingCall({ statusCode: We });
2090
+ return this.declineToIncomingCall({ statusCode: ht });
2007
2091
  }
2008
2092
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2009
2093
  on(e, t) {
@@ -2034,25 +2118,25 @@ class Be {
2034
2118
  originator: e,
2035
2119
  session: t
2036
2120
  }) => {
2037
- e === V.REMOTE && this.setIncomingSession(t);
2121
+ e === x.REMOTE && this.setIncomingSession(t);
2038
2122
  };
2039
2123
  setIncomingSession(e) {
2040
2124
  this.incomingRTCSession = e;
2041
2125
  const t = this.remoteCallerData;
2042
2126
  e.on("failed", (s) => {
2043
- this.removeIncomingSession(), s.originator === V.LOCAL ? this.events.trigger(b.TERMINATED_INCOMING_CALL, t) : this.events.trigger(b.FAILED_INCOMING_CALL, t);
2044
- }), this.events.trigger(b.INCOMING_CALL, t);
2127
+ this.removeIncomingSession(), s.originator === x.LOCAL ? this.events.trigger(w.TERMINATED_INCOMING_CALL, t) : this.events.trigger(w.FAILED_INCOMING_CALL, t);
2128
+ }), this.events.trigger(w.INCOMING_CALL, t);
2045
2129
  }
2046
2130
  removeIncomingSession() {
2047
2131
  delete this.incomingRTCSession;
2048
2132
  }
2049
2133
  }
2050
- const D = 1e3;
2134
+ const U = 1e3;
2051
2135
  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 || {});
2052
- const se = ["collected"], H = () => "performance" in window ? performance.now() : Date.now(), U = (n) => [...n.keys()].reduce((e, t) => {
2136
+ const ue = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
2053
2137
  const s = n.get(t);
2054
2138
  return s === void 0 ? e : { ...e, [s.type]: s };
2055
- }, {}), Ge = (n) => {
2139
+ }, {}), ut = (n) => {
2056
2140
  if (!n)
2057
2141
  return {
2058
2142
  outboundRtp: void 0,
@@ -2060,14 +2144,14 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2060
2144
  mediaSource: void 0,
2061
2145
  remoteInboundRtp: void 0
2062
2146
  };
2063
- const e = U(n);
2147
+ const e = L(n);
2064
2148
  return {
2065
2149
  outboundRtp: e[E.OUTBOUND_RTP],
2066
2150
  codec: e[E.CODEC],
2067
2151
  mediaSource: e[E.MEDIA_SOURCE],
2068
2152
  remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2069
2153
  };
2070
- }, q = (n) => {
2154
+ }, z = (n) => {
2071
2155
  if (!n)
2072
2156
  return {
2073
2157
  outboundRtp: void 0,
@@ -2075,14 +2159,14 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2075
2159
  mediaSource: void 0,
2076
2160
  remoteInboundRtp: void 0
2077
2161
  };
2078
- const e = U(n);
2162
+ const e = L(n);
2079
2163
  return {
2080
2164
  outboundRtp: e[E.OUTBOUND_RTP],
2081
2165
  codec: e[E.CODEC],
2082
2166
  mediaSource: e[E.MEDIA_SOURCE],
2083
2167
  remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2084
2168
  };
2085
- }, x = ({
2169
+ }, J = ({
2086
2170
  videoReceiversStats: n,
2087
2171
  synchronizationSourcesVideo: e
2088
2172
  }) => {
@@ -2092,13 +2176,13 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2092
2176
  codec: void 0,
2093
2177
  synchronizationSources: e
2094
2178
  };
2095
- const t = U(n);
2179
+ const t = L(n);
2096
2180
  return {
2097
2181
  inboundRtp: t[E.INBOUND_RTP],
2098
2182
  codec: t[E.CODEC],
2099
2183
  synchronizationSources: e
2100
2184
  };
2101
- }, He = ({
2185
+ }, Tt = ({
2102
2186
  audioReceiverStats: n,
2103
2187
  synchronizationSourcesAudio: e
2104
2188
  }) => {
@@ -2109,14 +2193,14 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2109
2193
  remoteOutboundRtp: void 0,
2110
2194
  synchronizationSources: e
2111
2195
  };
2112
- const t = U(n);
2196
+ const t = L(n);
2113
2197
  return {
2114
2198
  inboundRtp: t[E.INBOUND_RTP],
2115
2199
  codec: t[E.CODEC],
2116
2200
  remoteOutboundRtp: t[E.REMOTE_OUTBOUND_RTP],
2117
2201
  synchronizationSources: e
2118
2202
  };
2119
- }, ie = (n) => {
2203
+ }, Te = (n) => {
2120
2204
  if (!n)
2121
2205
  return {
2122
2206
  candidatePair: void 0,
@@ -2125,7 +2209,7 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2125
2209
  remoteCandidate: void 0,
2126
2210
  transport: void 0
2127
2211
  };
2128
- const e = U(n);
2212
+ const e = L(n);
2129
2213
  return {
2130
2214
  candidatePair: e[E.CANDIDATE_PAIR],
2131
2215
  certificate: e[E.CERTIFICATE],
@@ -2133,39 +2217,39 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2133
2217
  remoteCandidate: e[E.REMOTE_CANDIDATE],
2134
2218
  transport: e[E.TRANSPORT]
2135
2219
  };
2136
- }, qe = ({
2220
+ }, St = ({
2137
2221
  audioSenderStats: n,
2138
2222
  videoSenderFirstStats: e,
2139
2223
  videoSenderSecondStats: t
2140
2224
  }) => ({
2141
- video: q(e),
2142
- secondVideo: q(t),
2143
- audio: Ge(n),
2144
- additional: ie(
2225
+ video: z(e),
2226
+ secondVideo: z(t),
2227
+ audio: ut(n),
2228
+ additional: Te(
2145
2229
  n ?? e ?? t
2146
2230
  )
2147
- }), xe = ({
2231
+ }), Et = ({
2148
2232
  audioReceiverStats: n,
2149
2233
  videoReceiverFirstStats: e,
2150
2234
  videoReceiverSecondStats: t,
2151
2235
  synchronizationSources: s
2152
2236
  }) => ({
2153
- video: x({
2237
+ video: J({
2154
2238
  videoReceiversStats: e,
2155
2239
  synchronizationSourcesVideo: s.video
2156
2240
  }),
2157
- secondVideo: x({
2241
+ secondVideo: J({
2158
2242
  videoReceiversStats: t,
2159
2243
  synchronizationSourcesVideo: s.video
2160
2244
  }),
2161
- audio: He({
2245
+ audio: Tt({
2162
2246
  audioReceiverStats: n,
2163
2247
  synchronizationSourcesAudio: s.audio
2164
2248
  }),
2165
- additional: ie(
2249
+ additional: Te(
2166
2250
  n ?? e ?? t
2167
2251
  )
2168
- }), Ye = ({
2252
+ }), Ct = ({
2169
2253
  audioSenderStats: n,
2170
2254
  videoSenderFirstStats: e,
2171
2255
  videoSenderSecondStats: t,
@@ -2174,11 +2258,11 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2174
2258
  videoReceiverSecondStats: r,
2175
2259
  synchronizationSources: a
2176
2260
  }) => {
2177
- const o = qe({
2261
+ const o = St({
2178
2262
  audioSenderStats: n,
2179
2263
  videoSenderFirstStats: e,
2180
2264
  videoSenderSecondStats: t
2181
- }), c = xe({
2265
+ }), c = Et({
2182
2266
  audioReceiverStats: s,
2183
2267
  videoReceiverFirstStats: i,
2184
2268
  videoReceiverSecondStats: r,
@@ -2188,16 +2272,16 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2188
2272
  outbound: o,
2189
2273
  inbound: c
2190
2274
  };
2191
- }, ze = async (n) => {
2192
- const e = "audio", t = "video", s = n.getSenders(), i = s.find((d) => d.track?.kind === e), r = s.filter((d) => d.track?.kind === t), a = n.getReceivers(), o = a.find((d) => d.track.kind === e), c = a.filter((d) => d.track.kind === t), g = {
2275
+ }, Nt = async (n) => {
2276
+ 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 = {
2193
2277
  trackIdentifier: o?.track.id,
2194
2278
  item: o?.getSynchronizationSources()[0]
2195
- }, l = {
2279
+ }, u = {
2196
2280
  trackIdentifier: c[0]?.track.id,
2197
2281
  item: c[0]?.getSynchronizationSources()[0]
2198
- }, u = {
2199
- audio: g,
2200
- video: l
2282
+ }, T = {
2283
+ audio: d,
2284
+ video: u
2201
2285
  };
2202
2286
  return Promise.all([
2203
2287
  i?.getStats(),
@@ -2206,41 +2290,41 @@ const se = ["collected"], H = () => "performance" in window ? performance.now()
2206
2290
  o?.getStats(),
2207
2291
  c[0]?.getStats(),
2208
2292
  c[1]?.getStats()
2209
- ]).then((d) => {
2293
+ ]).then((h) => {
2210
2294
  const [
2211
2295
  S,
2212
- _,
2213
- C,
2214
- p,
2215
- v,
2216
- re
2217
- ] = d;
2296
+ m,
2297
+ I,
2298
+ A,
2299
+ y,
2300
+ b
2301
+ ] = h;
2218
2302
  return {
2219
- synchronizationSources: u,
2303
+ synchronizationSources: T,
2220
2304
  audioSenderStats: S,
2221
- videoSenderFirstStats: _,
2222
- videoSenderSecondStats: C,
2223
- audioReceiverStats: p,
2224
- videoReceiverFirstStats: v,
2225
- videoReceiverSecondStats: re
2305
+ videoSenderFirstStats: m,
2306
+ videoSenderSecondStats: I,
2307
+ audioReceiverStats: A,
2308
+ videoReceiverFirstStats: y,
2309
+ videoReceiverSecondStats: b
2226
2310
  };
2227
2311
  });
2228
- }, Qe = (n) => {
2229
- P(String(n));
2312
+ }, At = (n) => {
2313
+ R(String(n));
2230
2314
  };
2231
- class Xe {
2315
+ class Rt {
2232
2316
  events;
2233
2317
  setTimeoutRequest;
2234
- requesterAllStatistics = new oe(ze);
2318
+ requesterAllStatistics = new Ae(Nt);
2235
2319
  constructor() {
2236
- this.events = new ae(se), this.setTimeoutRequest = new Te();
2320
+ this.events = new j(ue), this.setTimeoutRequest = new Z();
2237
2321
  }
2238
2322
  get requested() {
2239
2323
  return this.setTimeoutRequest.requested;
2240
2324
  }
2241
2325
  start(e, {
2242
- interval: t = D,
2243
- onError: s = Qe
2326
+ interval: t = U,
2327
+ onError: s = At
2244
2328
  } = {}) {
2245
2329
  this.stop(), this.setTimeoutRequest.request(() => {
2246
2330
  this.collectStatistics(e, {
@@ -2269,12 +2353,12 @@ class Xe {
2269
2353
  collectStatistics = (e, {
2270
2354
  onError: t
2271
2355
  }) => {
2272
- const s = H();
2356
+ const s = Y();
2273
2357
  this.requesterAllStatistics.request(e).then((i) => {
2274
- this.events.trigger("collected", Ye(i));
2275
- const a = H() - s;
2276
- let o = D;
2277
- a > 48 ? o = D * 4 : a > 32 ? o = D * 3 : a > 16 && (o = D * 2), this.start(e, {
2358
+ this.events.trigger("collected", Ct(i));
2359
+ const a = Y() - s;
2360
+ let o = U;
2361
+ a > 48 ? o = U * 4 : a > 32 ? o = U * 3 : a > 16 && (o = U * 2), this.start(e, {
2278
2362
  onError: t,
2279
2363
  interval: o
2280
2364
  });
@@ -2283,7 +2367,7 @@ class Xe {
2283
2367
  });
2284
2368
  };
2285
2369
  }
2286
- class Je {
2370
+ class It {
2287
2371
  availableIncomingBitrate;
2288
2372
  statsPeerConnection;
2289
2373
  callManager;
@@ -2293,7 +2377,7 @@ class Je {
2293
2377
  callManager: e,
2294
2378
  apiManager: t
2295
2379
  }) {
2296
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Xe(), this.subscribe();
2380
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Rt(), this.subscribe();
2297
2381
  }
2298
2382
  get events() {
2299
2383
  return this.statsPeerConnection.events;
@@ -2331,19 +2415,445 @@ class Je {
2331
2415
  };
2332
2416
  maybeSendStats() {
2333
2417
  this.availableIncomingBitrate !== void 0 && this.hasAvailableIncomingBitrateChangedQuarter() && this.apiManager.sendStats({ availableIncomingBitrate: this.availableIncomingBitrate }).catch((e) => {
2334
- P("Failed to send stats", e);
2418
+ R("Failed to send stats", e);
2419
+ });
2420
+ }
2421
+ }
2422
+ const _t = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), Mt = (n) => {
2423
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
2424
+ return _t(s, i);
2425
+ }, mt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2426
+ 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;
2427
+ return a - o;
2428
+ }), pt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Pt = (n, {
2429
+ preferredMimeTypesVideoCodecs: e,
2430
+ excludeMimeTypesVideoCodecs: t
2431
+ }) => {
2432
+ try {
2433
+ if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
2434
+ const s = Mt("video"), i = pt(s, t), r = mt(i, e);
2435
+ n.setCodecPreferences(r);
2436
+ }
2437
+ } catch (s) {
2438
+ R("setCodecPreferences error", s);
2439
+ }
2440
+ }, ft = (n) => [...n.keys()].map((e) => n.get(e)), Ot = (n, e) => ft(n).find((t) => t?.type === e), vt = async (n) => n.getStats().then((e) => Ot(e, "codec")?.mimeType);
2441
+ class Dt {
2442
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2443
+ async getCodecFromSender(e) {
2444
+ return await vt(e) ?? "";
2445
+ }
2446
+ }
2447
+ class yt {
2448
+ stackPromises = Me({
2449
+ noRunIsNotActual: !0
2450
+ });
2451
+ /**
2452
+ * Добавляет задачу в очередь и возвращает Promise с результатом
2453
+ * @param task - Функция для выполнения
2454
+ * @returns Promise с результатом выполнения задачи
2455
+ */
2456
+ async add(e) {
2457
+ return this.stackPromises.add(e), this.run();
2458
+ }
2459
+ stop() {
2460
+ this.stackPromises.stop();
2461
+ }
2462
+ /**
2463
+ * Выполняет задачи из очереди с обработкой ошибок
2464
+ * @returns Promise с результатом выполнения
2465
+ */
2466
+ async run() {
2467
+ return this.stackPromises().catch((e) => {
2468
+ R("TaskQueue: error", e);
2469
+ });
2470
+ }
2471
+ }
2472
+ class bt {
2473
+ taskQueue;
2474
+ onSetParameters;
2475
+ constructor(e) {
2476
+ this.onSetParameters = e, this.taskQueue = new yt();
2477
+ }
2478
+ async setEncodingsToSender(e, t) {
2479
+ return this.taskQueue.add(async () => oe(e, t, this.onSetParameters));
2480
+ }
2481
+ stop() {
2482
+ this.taskQueue.stop();
2483
+ }
2484
+ }
2485
+ const Se = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Ut = 1e6, p = (n) => n * Ut, Ee = p(0.06), Ce = p(4), wt = (n) => n <= 64 ? Ee : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ce, Lt = "av1", Bt = (n) => Se(n, Lt), kt = 0.6, Q = (n, e) => Bt(e) ? n * kt : n, Ft = (n) => Q(Ee, n), $t = (n) => Q(Ce, n), X = (n, e) => {
2486
+ const t = wt(n);
2487
+ return Q(t, e);
2488
+ }, V = 1, Vt = ({
2489
+ videoTrack: n,
2490
+ targetSize: e
2491
+ }) => {
2492
+ 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;
2493
+ return Math.max(r, a, V);
2494
+ };
2495
+ class Wt {
2496
+ ignoreForCodec;
2497
+ senderFinder;
2498
+ codecProvider;
2499
+ parametersSetter;
2500
+ resultNoChanged = {
2501
+ isChanged: !1,
2502
+ parameters: {
2503
+ encodings: [{}],
2504
+ transactionId: "0",
2505
+ codecs: [],
2506
+ headerExtensions: [],
2507
+ rtcp: {}
2508
+ }
2509
+ };
2510
+ constructor({
2511
+ senderFinder: e,
2512
+ codecProvider: t,
2513
+ parametersSetter: s
2514
+ }, i) {
2515
+ this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = i.ignoreForCodec;
2516
+ }
2517
+ /**
2518
+ * Выполняет балансировку на основе заголовков от сервера
2519
+ * @param connection - RTCPeerConnection для получения отправителей
2520
+ * @param headers - Заголовки от сервера с командами управления
2521
+ * @returns Promise с результатом балансировки
2522
+ */
2523
+ async balance(e, t) {
2524
+ const s = e.getSenders(), i = this.senderFinder.findVideoSender(s);
2525
+ if (!i?.track)
2526
+ return { ...this.resultNoChanged, sender: i };
2527
+ const r = await this.codecProvider.getCodecFromSender(i);
2528
+ if (Se(r, this.ignoreForCodec))
2529
+ return { ...this.resultNoChanged, sender: i };
2530
+ const { mainCam: a, resolutionMainCam: o } = t ?? {};
2531
+ return this.processSender(
2532
+ { mainCam: a, resolutionMainCam: o },
2533
+ {
2534
+ sender: i,
2535
+ codec: r,
2536
+ videoTrack: i.track
2537
+ }
2538
+ ).then((c) => ({ ...c, sender: i }));
2539
+ }
2540
+ /**
2541
+ * Обрабатывает отправитель в зависимости от команды управления
2542
+ * @param context - Контекст балансировки
2543
+ * @returns Promise с результатом обработки
2544
+ */
2545
+ async processSender(e, t) {
2546
+ const { mainCam: s, resolutionMainCam: i } = e;
2547
+ switch (s) {
2548
+ case P.PAUSE_MAIN_CAM:
2549
+ return this.downgradeResolutionSender(t);
2550
+ case P.RESUME_MAIN_CAM:
2551
+ return this.setBitrateByTrackResolution(t);
2552
+ case P.MAX_MAIN_CAM_RESOLUTION:
2553
+ return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
2554
+ case P.ADMIN_STOP_MAIN_CAM:
2555
+ case P.ADMIN_START_MAIN_CAM:
2556
+ case void 0:
2557
+ return this.setBitrateByTrackResolution(t);
2558
+ default:
2559
+ return this.setBitrateByTrackResolution(t);
2560
+ }
2561
+ }
2562
+ /**
2563
+ * Понижает разрешение отправителя (пауза камеры)
2564
+ * @param context - Контекст балансировки
2565
+ * @returns Promise с результатом
2566
+ */
2567
+ async downgradeResolutionSender(e) {
2568
+ const { sender: t, codec: s } = e, i = {
2569
+ scaleResolutionDownBy: 200,
2570
+ maxBitrate: Ft(s)
2571
+ };
2572
+ return this.parametersSetter.setEncodingsToSender(t, i);
2573
+ }
2574
+ /**
2575
+ * Устанавливает битрейт на основе разрешения трека
2576
+ * @param context - Контекст балансировки
2577
+ * @returns Promise с результатом
2578
+ */
2579
+ async setBitrateByTrackResolution(e) {
2580
+ const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? $t(i) : X(a, i);
2581
+ return this.parametersSetter.setEncodingsToSender(t, {
2582
+ scaleResolutionDownBy: 1,
2583
+ maxBitrate: o
2584
+ });
2585
+ }
2586
+ /**
2587
+ * Устанавливает разрешение отправителя на основе заголовка
2588
+ * @param resolutionMainCam - Разрешение главной камеры
2589
+ * @param context - Контекст балансировки
2590
+ * @returns Promise с результатом
2591
+ */
2592
+ async setResolutionSender(e, t) {
2593
+ const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
2594
+ width: Number(s),
2595
+ height: Number(i)
2596
+ }, d = Vt({
2597
+ videoTrack: a,
2598
+ targetSize: c
2599
+ }), u = X(c.width, o), T = {
2600
+ scaleResolutionDownBy: d,
2601
+ maxBitrate: u
2602
+ };
2603
+ return this.parametersSetter.setEncodingsToSender(r, T);
2604
+ }
2605
+ }
2606
+ const Ht = (n) => n.find((e) => e.track?.kind === "video");
2607
+ class xt {
2608
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2609
+ findVideoSender(e) {
2610
+ return Ht(e);
2611
+ }
2612
+ }
2613
+ class qt {
2614
+ currentSender;
2615
+ originalReplaceTrack;
2616
+ lastWidth;
2617
+ lastHeight;
2618
+ maxPollIntervalMs;
2619
+ currentPollIntervalMs;
2620
+ pollIntervalMs;
2621
+ setTimeoutRequest;
2622
+ constructor({
2623
+ pollIntervalMs: e = 1e3,
2624
+ maxPollIntervalMs: t
2625
+ }) {
2626
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new Z();
2627
+ }
2628
+ /**
2629
+ * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
2630
+ */
2631
+ subscribe(e, t) {
2632
+ if (!e) {
2633
+ this.detachSender();
2634
+ return;
2635
+ }
2636
+ this.currentSender !== e && (this.detachSender(), this.attachSender(e, t));
2637
+ }
2638
+ /** Останавливает всю активность мониторинга */
2639
+ unsubscribe() {
2640
+ this.detachSender();
2641
+ }
2642
+ attachSender(e, t) {
2643
+ this.currentSender = e;
2644
+ const s = e.replaceTrack.bind(e);
2645
+ this.originalReplaceTrack = s, e.replaceTrack = async (i) => {
2646
+ await s(i), this.attachTrack(t, i ?? void 0), t();
2647
+ }, this.attachTrack(t, e.track);
2648
+ }
2649
+ detachSender() {
2650
+ this.currentSender && this.originalReplaceTrack && (this.currentSender.replaceTrack = this.originalReplaceTrack), this.originalReplaceTrack = void 0, this.currentSender = void 0, this.detachTrack();
2651
+ }
2652
+ attachTrack(e, t) {
2653
+ if (this.detachTrack(), !t)
2654
+ return;
2655
+ const { width: s, height: i } = t.getSettings();
2656
+ this.lastWidth = s, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2657
+ }
2658
+ /**
2659
+ * Периодически опрашивает track с экспоненциальной адаптацией частоты.
2660
+ * При отсутствии изменений интервал удваивается до maxPollIntervalMs,
2661
+ * при обнаружении изменений сбрасывается до начального.
2662
+ */
2663
+ schedulePoll(e, t) {
2664
+ const s = () => {
2665
+ const { width: i, height: r } = e.getSettings();
2666
+ i !== this.lastWidth || r !== this.lastHeight ? (this.lastWidth = i, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2667
+ this.currentPollIntervalMs * 2,
2668
+ this.maxPollIntervalMs
2669
+ ), this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
2670
+ };
2671
+ this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
2672
+ }
2673
+ detachTrack() {
2674
+ this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
2675
+ }
2676
+ }
2677
+ class Gt {
2678
+ apiManager;
2679
+ currentHandler;
2680
+ constructor(e) {
2681
+ this.apiManager = e;
2682
+ }
2683
+ /**
2684
+ * Подписывается на события управления главной камерой
2685
+ * @param handler - Обработчик события
2686
+ */
2687
+ subscribe(e) {
2688
+ this.currentHandler = e, this.apiManager.on("main-cam-control", e);
2689
+ }
2690
+ /**
2691
+ * Отписывается от событий управления главной камерой
2692
+ */
2693
+ unsubscribe() {
2694
+ this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
2695
+ }
2696
+ }
2697
+ class Qt {
2698
+ eventHandler;
2699
+ senderBalancer;
2700
+ parametersSetterWithQueue;
2701
+ getConnection;
2702
+ serverHeaders;
2703
+ trackMonitor;
2704
+ constructor(e, t, {
2705
+ ignoreForCodec: s,
2706
+ onSetParameters: i,
2707
+ pollIntervalMs: r
2708
+ } = {}) {
2709
+ this.getConnection = t, this.eventHandler = new Gt(e), this.parametersSetterWithQueue = new bt(i), this.senderBalancer = new Wt(
2710
+ {
2711
+ senderFinder: new xt(),
2712
+ codecProvider: new Dt(),
2713
+ parametersSetter: this.parametersSetterWithQueue
2714
+ },
2715
+ {
2716
+ ignoreForCodec: s
2717
+ }
2718
+ ), this.trackMonitor = new qt({ pollIntervalMs: r });
2719
+ }
2720
+ /**
2721
+ * Подписывается на события управления главной камерой
2722
+ */
2723
+ subscribe() {
2724
+ this.eventHandler.subscribe(this.handleMainCamControl);
2725
+ }
2726
+ /**
2727
+ * Отписывается от событий и сбрасывает состояние
2728
+ */
2729
+ unsubscribe() {
2730
+ this.eventHandler.unsubscribe(), this.parametersSetterWithQueue.stop(), this.reset();
2731
+ }
2732
+ /**
2733
+ * Сбрасывает состояние балансировщика
2734
+ */
2735
+ reset() {
2736
+ delete this.serverHeaders, this.trackMonitor.unsubscribe();
2737
+ }
2738
+ /**
2739
+ * Выполняет балансировку на основе текущего состояния
2740
+ * @returns Promise с результатом балансировки
2741
+ */
2742
+ async balance() {
2743
+ const e = this.getConnection();
2744
+ if (!e)
2745
+ throw new Error("connection is not exist");
2746
+ const t = await this.senderBalancer.balance(e, this.serverHeaders);
2747
+ return this.trackMonitor.subscribe(t.sender, () => {
2748
+ this.balance().catch((s) => {
2749
+ R("balance on track change: error", s);
2750
+ });
2751
+ }), t;
2752
+ }
2753
+ /**
2754
+ * Обработчик событий управления главной камерой
2755
+ * @param headers - Заголовки от сервера
2756
+ */
2757
+ handleMainCamControl = (e) => {
2758
+ this.serverHeaders = e, this.balance().catch((t) => {
2759
+ R("handleMainCamControl: error", t);
2335
2760
  });
2761
+ };
2762
+ }
2763
+ const Ne = [
2764
+ "balancing-scheduled",
2765
+ "balancing-started",
2766
+ "balancing-stopped",
2767
+ "parameters-updated"
2768
+ ];
2769
+ class Yt {
2770
+ isBalancingActive = !1;
2771
+ events;
2772
+ callManager;
2773
+ balancingStartDelay;
2774
+ videoSendingBalancer;
2775
+ startBalancingTimer;
2776
+ constructor(e, t, s = {}) {
2777
+ this.events = new j(Ne), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Qt(
2778
+ t,
2779
+ () => e.connection,
2780
+ {
2781
+ ...s,
2782
+ onSetParameters: (i) => {
2783
+ this.events.trigger("parameters-updated", i), s.onSetParameters?.(i);
2784
+ }
2785
+ }
2786
+ ), this.subscribe();
2787
+ }
2788
+ /**
2789
+ * Проверить, запланирован ли запуск балансировки
2790
+ */
2791
+ get isBalancingScheduled() {
2792
+ return this.startBalancingTimer !== void 0;
2793
+ }
2794
+ /**
2795
+ * Принудительно запустить балансировку
2796
+ */
2797
+ async startBalancing() {
2798
+ this.isBalancingActive || (this.clearStartTimer(), await this.videoSendingBalancer.balance(), this.videoSendingBalancer.subscribe(), this.isBalancingActive = !0, this.events.trigger("balancing-started", { delay: this.balancingStartDelay }));
2799
+ }
2800
+ /**
2801
+ * Остановить балансировку
2802
+ */
2803
+ stopBalancing() {
2804
+ this.clearStartTimer(), this.videoSendingBalancer.unsubscribe(), this.isBalancingActive = !1, this.events.trigger("balancing-stopped", {});
2805
+ }
2806
+ /**
2807
+ * Выполнить ручную балансировку
2808
+ */
2809
+ async balance() {
2810
+ return this.videoSendingBalancer.balance();
2811
+ }
2812
+ on(e, t) {
2813
+ return this.events.on(e, t);
2814
+ }
2815
+ once(e, t) {
2816
+ return this.events.once(e, t);
2817
+ }
2818
+ onceRace(e, t) {
2819
+ return this.events.onceRace(e, t);
2820
+ }
2821
+ async wait(e) {
2822
+ return this.events.wait(e);
2823
+ }
2824
+ off(e, t) {
2825
+ this.events.off(e, t);
2826
+ }
2827
+ subscribe() {
2828
+ this.callManager.on("peerconnection:confirmed", this.handleCallStarted), this.callManager.on("ended", this.handleCallEnded), this.callManager.on("failed", this.handleCallEnded);
2829
+ }
2830
+ handleCallStarted = () => {
2831
+ this.scheduleBalancingStart();
2832
+ };
2833
+ handleCallEnded = () => {
2834
+ this.stopBalancing();
2835
+ };
2836
+ scheduleBalancingStart() {
2837
+ this.clearStartTimer(), this.startBalancingTimer = setTimeout(() => {
2838
+ this.startBalancingTimer = void 0, this.startBalancing().catch((e) => {
2839
+ R("startBalancing: error", e);
2840
+ });
2841
+ }, this.balancingStartDelay), this.events.trigger("balancing-scheduled", { delay: this.balancingStartDelay });
2842
+ }
2843
+ clearStartTimer() {
2844
+ this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
2336
2845
  }
2337
2846
  }
2338
- const je = ee.map((n) => `connection:${n}`), Ke = Q.map((n) => `call:${n}`), Ze = j.map((n) => `api:${n}`), et = ne.map((n) => `incoming-call:${n}`), tt = K.map((n) => `presentation:${n}`), nt = se.map((n) => `stats:${n}`), st = [
2339
- ...je,
2340
- ...Ke,
2341
- ...Ze,
2342
- ...et,
2343
- ...tt,
2344
- ...nt
2847
+ const zt = 1e6, Jt = he.map((n) => `connection:${n}`), Xt = te.map((n) => `call:${n}`), jt = ie.map((n) => `api:${n}`), Kt = le.map((n) => `incoming-call:${n}`), Zt = ce.map((n) => `presentation:${n}`), en = ue.map((n) => `stats:${n}`), tn = Ne.map((n) => `video-balancer:${n}`), nn = [
2848
+ ...Jt,
2849
+ ...Xt,
2850
+ ...jt,
2851
+ ...Kt,
2852
+ ...Zt,
2853
+ ...en,
2854
+ ...tn
2345
2855
  ];
2346
- class Et {
2856
+ class En {
2347
2857
  events;
2348
2858
  connectionManager;
2349
2859
  callManager;
@@ -2351,16 +2861,28 @@ class Et {
2351
2861
  incomingCallManager;
2352
2862
  presentationManager;
2353
2863
  statsManager;
2354
- constructor({ JsSIP: e }) {
2355
- this.events = new f(st), this.connectionManager = new ke({ JsSIP: e }), this.callManager = new _e(), this.apiManager = new Oe({
2864
+ videoSendingBalancerManager;
2865
+ preferredMimeTypesVideoCodecs;
2866
+ excludeMimeTypesVideoCodecs;
2867
+ constructor({ JsSIP: e }, {
2868
+ preferredMimeTypesVideoCodecs: t,
2869
+ excludeMimeTypesVideoCodecs: s,
2870
+ videoBalancerOptions: i
2871
+ } = {}) {
2872
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(nn), this.connectionManager = new dt({ JsSIP: e }), this.callManager = new Ue(), this.apiManager = new $e({
2356
2873
  connectionManager: this.connectionManager,
2357
2874
  callManager: this.callManager
2358
- }), this.incomingCallManager = new Be(this.connectionManager), this.presentationManager = new ve({
2359
- callManager: this.callManager
2360
- }), this.statsManager = new Je({
2875
+ }), this.incomingCallManager = new lt(this.connectionManager), this.presentationManager = new et({
2876
+ callManager: this.callManager,
2877
+ maxBitrate: zt
2878
+ }), this.statsManager = new It({
2361
2879
  callManager: this.callManager,
2362
2880
  apiManager: this.apiManager
2363
- }), this.subscribe();
2881
+ }), this.videoSendingBalancerManager = new Yt(
2882
+ this.callManager,
2883
+ this.apiManager,
2884
+ i
2885
+ ), this.subscribe();
2364
2886
  }
2365
2887
  get requestedConnection() {
2366
2888
  return this.connectionManager.requested;
@@ -2432,29 +2954,50 @@ class Et {
2432
2954
  isConfigured = () => this.connectionManager.isConfigured();
2433
2955
  getConnectionConfiguration = () => this.connectionManager.getConnectionConfiguration();
2434
2956
  getSipServerUrl = (e) => this.connectionManager.getSipServerUrl(e);
2435
- call = async (e) => this.callManager.startCall(
2436
- this.connectionManager.getUaProtected(),
2437
- this.getSipServerUrl,
2438
- e
2439
- );
2957
+ call = async (e) => {
2958
+ const { onAddedTransceiver: t, ...s } = e;
2959
+ return this.callManager.startCall(
2960
+ this.connectionManager.getUaProtected(),
2961
+ this.getSipServerUrl,
2962
+ {
2963
+ ...s,
2964
+ onAddedTransceiver: async (i, r, a) => {
2965
+ this.setCodecPreferences(i), await t?.(i, r, a);
2966
+ }
2967
+ }
2968
+ );
2969
+ };
2440
2970
  hangUp = async () => this.callManager.endCall();
2441
- answerToIncomingCall = async (e) => this.callManager.answerToIncomingCall(
2442
- this.incomingCallManager.extractIncomingRTCSession,
2443
- e
2444
- );
2971
+ answerToIncomingCall = async (e) => {
2972
+ const { onAddedTransceiver: t, ...s } = e;
2973
+ return this.callManager.answerToIncomingCall(
2974
+ this.incomingCallManager.extractIncomingRTCSession,
2975
+ {
2976
+ ...s,
2977
+ onAddedTransceiver: async (i, r, a) => {
2978
+ this.setCodecPreferences(i), await t?.(i, r, a);
2979
+ }
2980
+ }
2981
+ );
2982
+ };
2445
2983
  declineToIncomingCall = async (...e) => this.incomingCallManager.declineToIncomingCall(...e);
2446
2984
  getEstablishedRTCSession = () => this.callManager.getEstablishedRTCSession();
2447
2985
  getCallConfiguration = () => this.callManager.getCallConfiguration();
2448
2986
  getRemoteStreams = () => this.callManager.getRemoteStreams();
2449
2987
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
2450
2988
  async startPresentation(e, t = {}) {
2451
- const { isP2P: s, callLimit: i, ...r } = t;
2989
+ const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
2452
2990
  return this.presentationManager.startPresentation(
2453
2991
  async () => {
2454
2992
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
2455
2993
  },
2456
2994
  e,
2457
- r,
2995
+ {
2996
+ ...a,
2997
+ onAddedTransceiver: async (o, c, d) => {
2998
+ this.setCodecPreferences(o), await r?.(o, c, d);
2999
+ }
3000
+ },
2458
3001
  i === void 0 ? void 0 : { callLimit: i }
2459
3002
  );
2460
3003
  }
@@ -2465,13 +3008,18 @@ class Et {
2465
3008
  });
2466
3009
  }
2467
3010
  async updatePresentation(e, t = {}) {
2468
- const { isP2P: s, ...i } = t;
3011
+ const { isP2P: s, onAddedTransceiver: i, ...r } = t;
2469
3012
  return this.presentationManager.updatePresentation(
2470
3013
  async () => {
2471
3014
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
2472
3015
  },
2473
3016
  e,
2474
- i
3017
+ {
3018
+ ...r,
3019
+ onAddedTransceiver: async (a, o, c) => {
3020
+ this.setCodecPreferences(a), await i?.(a, o, c);
3021
+ }
3022
+ }
2475
3023
  );
2476
3024
  }
2477
3025
  async waitChannels(...e) {
@@ -2516,6 +3064,12 @@ class Et {
2516
3064
  async askPermissionToEnableCam(...e) {
2517
3065
  return this.apiManager.askPermissionToEnableCam(...e);
2518
3066
  }
3067
+ setCodecPreferences(e) {
3068
+ Pt(e, {
3069
+ preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
3070
+ excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
3071
+ });
3072
+ }
2519
3073
  subscribe() {
2520
3074
  this.connectionManager.events.eachTriggers((e, t) => {
2521
3075
  this.connectionManager.on(t, (s) => {
@@ -2541,20 +3095,26 @@ class Et {
2541
3095
  this.statsManager.on(t, (s) => {
2542
3096
  this.events.trigger(`stats:${t}`, s);
2543
3097
  });
3098
+ }), this.videoSendingBalancerManager.events.eachTriggers((e, t) => {
3099
+ this.videoSendingBalancerManager.on(t, (s) => {
3100
+ this.events.trigger(`video-balancer:${t}`, s);
3101
+ });
2544
3102
  });
2545
3103
  }
2546
3104
  }
2547
3105
  export {
2548
- J as E,
3106
+ se as E,
2549
3107
  $ as O,
2550
- Et as S,
2551
- y as a,
2552
- Pe as b,
3108
+ En as S,
3109
+ Xe as a,
3110
+ Fe as b,
2553
3111
  E as c,
2554
- lt as d,
2555
- ht as e,
2556
- Xe as f,
2557
- St as h,
2558
- P as l,
2559
- w as p
3112
+ Tn as d,
3113
+ un as e,
3114
+ Rt as f,
3115
+ vt as g,
3116
+ Sn as h,
3117
+ R as l,
3118
+ B as p,
3119
+ oe as s
2560
3120
  };