sip-connector 6.22.1 → 6.22.3

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.
package/dist/index.js CHANGED
@@ -1,132 +1,131 @@
1
- import { l as o, B as V, N as $, E as B, s as z, S as Ye } from "./SipConnector-Hg44qtgr.js";
2
- import { f as sn, g as rn, i as on, c as an, a as cn, d as un, b as ln, e as Sn, h as mn } from "./SipConnector-Hg44qtgr.js";
3
- import { debounce as q } from "ts-debounce";
4
- import { isCanceledError as J } from "@krivega/cancelable-promise";
5
- import Q from "stack-promises";
6
- import { default as fn } from "debug";
1
+ import { l as c, B as V, N as $, E as P, s as q, S as nn } from "./SipConnector-Hg44qtgr.js";
2
+ import { f as ln, g as Sn, i as dn, c as mn, a as fn, d as Cn, b as En, e as gn, h as Rn } from "./SipConnector-Hg44qtgr.js";
3
+ import { debounce as J } from "ts-debounce";
4
+ import { isCanceledError as Q } from "@krivega/cancelable-promise";
5
+ import { default as yn } from "debug";
7
6
  import "events-constructor";
8
- const x = "purgatory", A = (e) => e === x, w = (e) => () => (o("getRemoteStreams"), e.getRemoteStreams()), Z = ({ kind: e, readyState: n }) => e === "video" && n === "live", G = (e) => ({ track: n }) => {
7
+ const G = "purgatory", A = (e) => e === G, k = (e) => () => (c("getRemoteStreams"), e.getRemoteStreams()), Z = ({ kind: e, readyState: n }) => e === "video" && n === "live", j = (e) => ({ track: n }) => {
9
8
  Z(n) && e();
10
9
  }, D = ({
11
10
  getRemoteStreams: e,
12
11
  setRemoteStreams: n
13
- }) => q(() => {
12
+ }) => J(() => {
14
13
  const t = e();
15
- o("remoteStreams", t), t && n(t);
14
+ c("remoteStreams", t), t && n(t);
16
15
  }, 200), ee = (e) => async (t) => {
17
16
  const {
18
17
  mediaStream: s,
19
18
  extraHeaders: r,
20
- iceServers: a,
21
- degradationPreference: c,
22
- setRemoteStreams: i,
23
- onBeforeProgressCall: u,
24
- onSuccessProgressCall: m,
25
- onEnterPurgatory: d,
26
- onEnterConference: l,
27
- onFailProgressCall: R,
28
- onFinishProgressCall: f,
29
- onEndedCall: C
19
+ iceServers: o,
20
+ degradationPreference: a,
21
+ setRemoteStreams: u,
22
+ onBeforeProgressCall: m,
23
+ onSuccessProgressCall: E,
24
+ onEnterPurgatory: C,
25
+ onEnterConference: f,
26
+ onFailProgressCall: T,
27
+ onFinishProgressCall: h,
28
+ onEndedCall: y
30
29
  } = t, g = D({
31
- setRemoteStreams: i,
32
- getRemoteStreams: w(e)
33
- }), y = G(g);
34
- o("answerIncomingCall", t);
35
- const h = async () => e.answerToIncomingCall({
30
+ setRemoteStreams: u,
31
+ getRemoteStreams: k(e)
32
+ }), M = j(g);
33
+ c("answerIncomingCall", t);
34
+ const v = async () => e.answerToIncomingCall({
36
35
  mediaStream: s,
37
36
  extraHeaders: r,
38
- iceServers: a,
39
- degradationPreference: c,
40
- ontrack: y
41
- }), b = () => {
42
- const { remoteCallerData: S } = e;
43
- return S.incomingNumber;
37
+ iceServers: o,
38
+ degradationPreference: a,
39
+ ontrack: M
40
+ }), p = () => {
41
+ const { remoteCallerData: d } = e;
42
+ return d.incomingNumber;
44
43
  };
45
- let T = !1, M;
46
- const _ = (o("subscribeEnterConference: onEnterConference", l), d ?? l ? e.onSession("enterRoom", (S) => {
47
- o("enterRoom", { _room: S, isSuccessProgressCall: T }), M = S, A(M) ? d && d() : l && l({ isSuccessProgressCall: T });
44
+ let _ = !1, i;
45
+ const l = (c("subscribeEnterConference: onEnterConference", f), C ?? f ? e.onSession("enterRoom", (d) => {
46
+ c("enterRoom", { _room: d, isSuccessProgressCall: _ }), i = d, A(i) ? C && C() : f && f({ isSuccessProgressCall: _ });
48
47
  }) : () => {
49
- }), O = (S) => (o("onSuccess"), T = !0, g(), m && m({ isPurgatory: A(M) }), e.onceRaceSession(["ended", "failed"], () => {
50
- _(), C && C();
51
- }), S), N = (S) => {
52
- throw o("onFail"), R && R(), _(), S;
53
- }, v = () => {
54
- o("onFinish"), f && f();
48
+ }), R = (d) => (c("onSuccess"), _ = !0, g(), E && E({ isPurgatory: A(i) }), e.onceRaceSession(["ended", "failed"], () => {
49
+ l(), y && y();
50
+ }), d), b = (d) => {
51
+ throw c("onFail"), T && T(), l(), d;
52
+ }, O = () => {
53
+ c("onFinish"), h && h();
55
54
  };
56
- if (o("onBeforeProgressCall"), u) {
57
- const S = b();
58
- u(S);
55
+ if (c("onBeforeProgressCall"), m) {
56
+ const d = p();
57
+ m(d);
59
58
  }
60
- return h().then(O).catch(N).finally(v);
59
+ return v().then(R).catch(b).finally(O);
61
60
  }, ne = (e) => async (t) => {
62
61
  const {
63
62
  conference: s,
64
63
  mediaStream: r,
65
- extraHeaders: a,
66
- iceServers: c,
67
- degradationPreference: i,
68
- setRemoteStreams: u,
69
- onBeforeProgressCall: m,
70
- onSuccessProgressCall: d,
71
- onEnterPurgatory: l,
72
- onEnterConference: R,
73
- onFailProgressCall: f,
74
- onFinishProgressCall: C,
64
+ extraHeaders: o,
65
+ iceServers: a,
66
+ degradationPreference: u,
67
+ setRemoteStreams: m,
68
+ onBeforeProgressCall: E,
69
+ onSuccessProgressCall: C,
70
+ onEnterPurgatory: f,
71
+ onEnterConference: T,
72
+ onFailProgressCall: h,
73
+ onFinishProgressCall: y,
75
74
  onEndedCall: g
76
- } = t, y = D({
77
- setRemoteStreams: u,
78
- getRemoteStreams: w(e)
79
- }), h = G(y);
80
- o("callToServer", t);
81
- const b = async () => (o("startCall"), e.call({
75
+ } = t, M = D({
76
+ setRemoteStreams: m,
77
+ getRemoteStreams: k(e)
78
+ }), v = j(M);
79
+ c("callToServer", t);
80
+ const p = async () => (c("startCall"), e.call({
82
81
  mediaStream: r,
83
- extraHeaders: a,
84
- iceServers: c,
85
- degradationPreference: i,
82
+ extraHeaders: o,
83
+ iceServers: a,
84
+ degradationPreference: u,
86
85
  number: s,
87
- ontrack: h
86
+ ontrack: v
88
87
  }));
89
- let T = !1, M;
90
- const _ = (o("subscribeEnterConference: onEnterConference", R), l ?? R ? e.onSession("enterRoom", (S) => {
91
- o("enterRoom", { _room: S, isSuccessProgressCall: T }), M = S, A(M) ? l && l() : R && R({ isSuccessProgressCall: T });
88
+ let _ = !1, i;
89
+ const l = (c("subscribeEnterConference: onEnterConference", T), f ?? T ? e.onSession("enterRoom", (d) => {
90
+ c("enterRoom", { _room: d, isSuccessProgressCall: _ }), i = d, A(i) ? f && f() : T && T({ isSuccessProgressCall: _ });
92
91
  }) : () => {
93
- }), O = (S) => (o("onSuccess"), T = !0, y(), d && d({ isPurgatory: A(M) }), e.onceRaceSession(["ended", "failed"], () => {
94
- _(), g && g();
95
- }), S), N = (S) => {
96
- throw o("onFail"), f && f(), _(), S;
97
- }, v = () => {
98
- o("onFinish"), C && C();
92
+ }), R = (d) => (c("onSuccess"), _ = !0, M(), C && C({ isPurgatory: A(i) }), e.onceRaceSession(["ended", "failed"], () => {
93
+ l(), g && g();
94
+ }), d), b = (d) => {
95
+ throw c("onFail"), h && h(), l(), d;
96
+ }, O = () => {
97
+ c("onFinish"), y && y();
99
98
  };
100
- return o("onBeforeProgressCall"), m && m(s), b().then(O).catch(N).finally(v);
101
- }, P = (e) => {
102
- if (!J(e))
99
+ return c("onBeforeProgressCall"), E && E(s), p().then(R).catch(b).finally(O);
100
+ }, w = (e) => {
101
+ if (!Q(e))
103
102
  throw e;
104
103
  return !1;
105
104
  }, te = (e) => async (t) => {
106
105
  const {
107
106
  userAgent: s,
108
107
  sipWebSocketServerURL: r,
109
- sipServerUrl: a,
110
- remoteAddress: c,
111
- displayName: i,
112
- name: u,
113
- password: m,
114
- isRegisteredUser: d,
115
- sdpSemantics: l,
116
- isDisconnectOnFail: R
108
+ sipServerUrl: o,
109
+ remoteAddress: a,
110
+ displayName: u,
111
+ name: m,
112
+ password: E,
113
+ isRegisteredUser: C,
114
+ sdpSemantics: f,
115
+ isDisconnectOnFail: T
117
116
  } = t;
118
- return o("connectToServer", t), e.connect({
117
+ return c("connectToServer", t), e.connect({
119
118
  userAgent: s,
120
- sdpSemantics: l,
119
+ sdpSemantics: f,
121
120
  sipWebSocketServerURL: r,
122
- sipServerUrl: a,
123
- remoteAddress: c,
124
- displayName: i,
125
- password: m,
126
- user: u,
127
- register: d
128
- }).then(() => (o("connectToServer then"), !0)).catch(async (f) => (o("connectToServer catch: error", f), R === !0 ? e.disconnect().then(() => P(f)).catch(() => P(f)) : P(f)));
129
- }, se = (e) => async () => (o("disconnectFromServer"), e.disconnect().then(() => (o("disconnectFromServer: then"), !1)).catch((n) => (o("disconnectFromServer: catch", n), !1))), F = (e) => {
121
+ sipServerUrl: o,
122
+ remoteAddress: a,
123
+ displayName: u,
124
+ password: E,
125
+ user: m,
126
+ register: C
127
+ }).then(() => (c("connectToServer then"), !0)).catch(async (h) => (c("connectToServer catch: error", h), T === !0 ? e.disconnect().then(() => w(h)).catch(() => w(h)) : w(h)));
128
+ }, se = (e) => async () => (c("disconnectFromServer"), e.disconnect().then(() => (c("disconnectFromServer: then"), !1)).catch((n) => (c("disconnectFromServer: catch", n), !1))), F = (e) => {
130
129
  const { url: n, cause: t } = e;
131
130
  let s = n;
132
131
  return (t === V || t === $) && (s = `${e.message.to.uri.user}@${e.message.to.uri.host}`), s;
@@ -154,24 +153,24 @@ const re = (e = new Error()) => {
154
153
  }
155
154
  return s;
156
155
  }, oe = (e = new Error()) => {
157
- const { code: n, cause: t, message: s } = e, r = F(e), a = {};
158
- return s && (a.message = s), r && (a.link = r), n && (a.code = n), t && (a.cause = t), a;
159
- }, ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
156
+ const { code: n, cause: t, message: s } = e, r = F(e), o = {};
157
+ return s && (o.message = s), r && (o.link = r), n && (o.code = n), t && (o.cause = t), o;
158
+ }, ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
160
159
  __proto__: null,
161
160
  EErrorTypes: X,
162
161
  getLinkError: F,
163
162
  getTypeFromError: re,
164
163
  getValuesFromError: oe
165
- }, Symbol.toStringTag, { value: "Module" })), ce = ({
164
+ }, Symbol.toStringTag, { value: "Module" })), ae = ({
166
165
  sessionId: e,
167
166
  remoteAddress: n,
168
167
  isMutedAudio: t,
169
168
  isMutedVideo: s,
170
169
  isRegistered: r,
171
- isPresentationCall: a
170
+ isPresentationCall: o
172
171
  }) => {
173
- const c = [], i = t ? "0" : "1", u = s ? "0" : "1";
174
- return c.push(`X-Vinteo-Mic-State: ${i}`, `X-Vinteo-MainCam-State: ${u}`), r || c.push("X-Vinteo-Purgatory-Call: yes"), e && c.push(`X-Vinteo-Session: ${e}`), a && c.push("X-Vinteo-Presentation-Call: yes"), n && c.push(`X-Vinteo-Remote: ${n}`), c;
172
+ const a = [], u = t ? "0" : "1", m = s ? "0" : "1";
173
+ return a.push(`X-Vinteo-Mic-State: ${u}`, `X-Vinteo-MainCam-State: ${m}`), r || a.push("X-Vinteo-Purgatory-Call: yes"), e && a.push(`X-Vinteo-Session: ${e}`), o && a.push("X-Vinteo-Presentation-Call: yes"), n && a.push(`X-Vinteo-Remote: ${n}`), a;
175
174
  }, ie = ({
176
175
  appName: e,
177
176
  appVersion: n,
@@ -188,57 +187,57 @@ const re = (e = new Error()) => {
188
187
  appName: r
189
188
  }) => e ? ie({ appVersion: n, browserName: t, browserVersion: s, appName: r }) : "Chrome", le = (e) => async () => {
190
189
  if (e.isCallActive)
191
- return o("askPermissionToEnableCam"), e.askPermissionToEnableCam();
192
- }, Se = (e) => (t) => (o("onMustStopPresentation"), e.onSession("mustStopPresentation", t)), me = (e) => (t) => (o("onUseLicense"), e.onSession("useLicense", t)), de = (e) => async ({
190
+ return c("askPermissionToEnableCam"), e.askPermissionToEnableCam();
191
+ }, Se = (e) => (t) => (c("onMustStopPresentation"), e.onSession("mustStopPresentation", t)), de = (e) => (t) => (c("onUseLicense"), e.onSession("useLicense", t)), me = (e) => async ({
193
192
  isEnabledCam: t,
194
193
  isEnabledMic: s
195
194
  }) => {
196
195
  if (e.isCallActive)
197
- return o("sendMediaState"), e.sendMediaState({ cam: t, mic: s });
196
+ return c("sendMediaState"), e.sendMediaState({ cam: t, mic: s });
198
197
  }, fe = (e) => async () => {
199
198
  if (e.isCallActive)
200
- return o("sendRefusalToTurnOnCam"), e.sendRefusalToTurnOnCam().catch((t) => {
201
- o("sendRefusalToTurnOnCam: error", t);
199
+ return c("sendRefusalToTurnOnCam"), e.sendRefusalToTurnOnCam().catch((t) => {
200
+ c("sendRefusalToTurnOnCam: error", t);
202
201
  });
203
202
  }, Ce = (e) => async () => {
204
203
  if (e.isCallActive)
205
- return o("sendRefusalToTurnOnMic"), e.sendRefusalToTurnOnMic().catch((t) => {
206
- o("sendRefusalToTurnOnMic: error", t);
204
+ return c("sendRefusalToTurnOnMic"), e.sendRefusalToTurnOnMic().catch((t) => {
205
+ c("sendRefusalToTurnOnMic: error", t);
207
206
  });
208
- }, Re = 1e6, Ee = ({
209
- maxBitrate: e = Re,
207
+ }, Ee = 1e6, ge = ({
208
+ maxBitrate: e = Ee,
210
209
  sipConnector: n
211
210
  }) => async ({
212
211
  mediaStream: s,
213
212
  isP2P: r = !1
214
- }) => (o("startPresentation"), n.startPresentation(s, {
213
+ }) => (c("startPresentation"), n.startPresentation(s, {
215
214
  isP2P: r,
216
215
  maxBitrate: e
217
- })), ge = ({ sipConnector: e }) => async ({ isP2P: t = !1 } = {}) => (o("stopShareSipConnector"), e.stopPresentation({
216
+ })), Re = ({ sipConnector: e }) => async ({ isP2P: t = !1 } = {}) => (c("stopShareSipConnector"), e.stopPresentation({
218
217
  isP2P: t
219
- }).catch(o)), Te = 1e6, Me = ({
218
+ }).catch(c)), he = 1e6, ye = ({
220
219
  sipConnector: e,
221
- maxBitrate: n = Te
220
+ maxBitrate: n = he
222
221
  }) => async ({
223
222
  mediaStream: s,
224
223
  isP2P: r = !1
225
- }) => (o("updatePresentation"), e.updatePresentation(s, {
224
+ }) => (c("updatePresentation"), e.updatePresentation(s, {
226
225
  isP2P: r,
227
226
  maxBitrate: n
228
- })), ye = "ERROR_NOT_RUNNING", _e = (e) => {
227
+ })), Te = "ERROR_NOT_RUNNING", Me = (e) => {
229
228
  const n = new Error("Promise was not running");
230
- return n.basePromise = e, n.id = ye, n.name = "Not running", n;
231
- }, he = async (e, n) => e.reduce(
232
- async (t, s) => t.then(async ({ success: r, errors: a, results: c }) => (!n || n(s) ? s() : Promise.reject(_e(s))).then((i) => ({
233
- errors: a,
234
- success: [...r, i],
235
- results: [...c, i],
229
+ return n.basePromise = e, n.id = Te, n.name = "Not running", n;
230
+ }, _e = async (e, n) => e.reduce(
231
+ async (t, s) => t.then(async ({ success: r, errors: o, results: a }) => (!n || n(s) ? s() : Promise.reject(Me(s))).then((u) => ({
232
+ errors: o,
233
+ success: [...r, u],
234
+ results: [...a, u],
236
235
  isSuccessful: !0,
237
236
  isError: !1
238
- })).catch((i) => ({
237
+ })).catch((u) => ({
239
238
  success: r,
240
- errors: [...a, i],
241
- results: [...c, i],
239
+ errors: [...o, u],
240
+ results: [...a, u],
242
241
  isSuccessful: !1,
243
242
  isError: !0
244
243
  }))),
@@ -249,67 +248,67 @@ const re = (e = new Error()) => {
249
248
  isSuccessful: !1,
250
249
  isError: !1
251
250
  })
252
- ), be = (e) => (n) => [...n].map((s) => async () => e(s)), Oe = async ({
251
+ ), be = (e) => (n) => [...n].map((s) => async () => e(s)), Ne = async ({
253
252
  accumulatedKeys: e,
254
253
  sendKey: n,
255
254
  canRunTask: t
256
255
  }) => {
257
256
  const r = be(n)(e);
258
- return he(r, t);
259
- }, Ne = (e) => (t) => (o("onStartMainCam"), e.onSession("admin-start-main-cam", t)), ve = (e) => (t) => (o("onStartMic"), e.onSession("admin-start-mic", t)), Ae = (e) => (t) => (o("onStopMainCam"), e.onSession("admin-stop-main-cam", t)), pe = (e) => (t) => (o("onStopMic"), e.onSession("admin-stop-mic", t)), Be = ({ sipConnector: e }) => {
260
- const n = (C, g) => ({ isSyncForced: y = !1 }) => {
261
- if (y) {
262
- C();
257
+ return _e(r, t);
258
+ }, Oe = (e) => (t) => (c("onStartMainCam"), e.onSession("admin-start-main-cam", t)), ve = (e) => (t) => (c("onStartMic"), e.onSession("admin-start-mic", t)), pe = (e) => (t) => (c("onStopMainCam"), e.onSession("admin-stop-main-cam", t)), Ae = (e) => (t) => (c("onStopMic"), e.onSession("admin-stop-mic", t)), Pe = ({ sipConnector: e }) => {
259
+ const n = (y, g) => ({ isSyncForced: M = !1 }) => {
260
+ if (M) {
261
+ y();
263
262
  return;
264
263
  }
265
264
  g();
266
- }, t = Ne(e), s = Ae(e), r = ve(e), a = pe(e);
267
- let c = () => {
268
- }, i = () => {
265
+ }, t = Oe(e), s = pe(e), r = ve(e), o = Ae(e);
266
+ let a = () => {
269
267
  }, u = () => {
270
268
  }, m = () => {
269
+ }, E = () => {
271
270
  };
272
- const d = ({
273
- onStartMainCamForced: C,
271
+ const C = ({
272
+ onStartMainCamForced: y,
274
273
  onStartMainCamNotForced: g,
275
- onStopMainCamForced: y,
276
- onStopMainCamNotForced: h,
277
- onStartMicForced: b,
278
- onStartMicNotForced: T,
279
- onStopMicForced: M,
280
- onStopMicNotForced: p
274
+ onStopMainCamForced: M,
275
+ onStopMainCamNotForced: v,
276
+ onStartMicForced: p,
277
+ onStartMicNotForced: _,
278
+ onStopMicForced: i,
279
+ onStopMicNotForced: S
281
280
  }) => {
282
- const _ = n(
283
- C,
281
+ const l = n(
282
+ y,
284
283
  g
285
284
  );
286
- c = t(_);
287
- const O = n(
288
- y,
289
- h
285
+ a = t(l);
286
+ const R = n(
287
+ M,
288
+ v
290
289
  );
291
- i = s(O);
292
- const N = n(b, T);
293
- u = r(N);
294
- const v = n(M, p);
295
- m = a(v);
296
- }, l = () => {
297
- c(), i(), u(), m();
290
+ u = s(R);
291
+ const b = n(p, _);
292
+ m = r(b);
293
+ const O = n(i, S);
294
+ E = o(O);
295
+ }, f = () => {
296
+ a(), u(), m(), E();
298
297
  };
299
298
  return {
300
- start: (C) => {
301
- d(C);
299
+ start: (y) => {
300
+ C(y);
302
301
  },
303
302
  stop: () => {
304
- l();
303
+ f();
305
304
  }
306
305
  };
307
- }, Ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
306
+ }, on = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
308
307
  __proto__: null,
309
- PURGATORY_CONFERENCE_NUMBER: x,
310
- createSyncMediaState: Be,
311
- error: ae,
312
- getExtraHeaders: ce,
308
+ PURGATORY_CONFERENCE_NUMBER: G,
309
+ createSyncMediaState: Pe,
310
+ error: ce,
311
+ getExtraHeaders: ae,
313
312
  getUserAgent: ue,
314
313
  hasPurgatory: A,
315
314
  resolveAnswerIncomingCall: ee,
@@ -317,83 +316,180 @@ const re = (e = new Error()) => {
317
316
  resolveCallToServer: ne,
318
317
  resolveConnectToServer: te,
319
318
  resolveDisconnectFromServer: se,
320
- resolveGetRemoteStreams: w,
319
+ resolveGetRemoteStreams: k,
321
320
  resolveOnMustStopPresentation: Se,
322
- resolveOnUseLicense: me,
323
- resolveSendMediaState: de,
321
+ resolveOnUseLicense: de,
322
+ resolveSendMediaState: me,
324
323
  resolveSendRefusalToTurnOnCam: fe,
325
324
  resolveSendRefusalToTurnOnMic: Ce,
326
- resolveStartPresentation: Ee,
327
- resolveStopShareSipConnector: ge,
328
- resolveUpdatePresentation: Me,
325
+ resolveStartPresentation: ge,
326
+ resolveStopShareSipConnector: Re,
327
+ resolveUpdatePresentation: ye,
329
328
  resolveUpdateRemoteStreams: D,
330
- sendDTMFAccumulated: Oe
331
- }, Symbol.toStringTag, { value: "Module" })), Pe = (e) => [...e.keys()].map((n) => e.get(n)), Ie = (e, n) => Pe(e).find((t) => t.type === n), we = async (e) => e.getStats().then((n) => {
329
+ sendDTMFAccumulated: Ne
330
+ }, Symbol.toStringTag, { value: "Module" })), we = (e) => [...e.keys()].map((n) => e.get(n)), Ie = (e, n) => we(e).find((t) => t.type === n), Be = async (e) => e.getStats().then((n) => {
332
331
  const t = Ie(n, "codec");
333
332
  return t == null ? void 0 : t.mimeType;
334
- }), De = (e) => e.find((n) => {
333
+ }), ke = (e) => e.find((n) => {
335
334
  var t;
336
335
  return ((t = n == null ? void 0 : n.track) == null ? void 0 : t.kind) === "video";
337
- }), K = (e, n) => e !== void 0 && n !== void 0 && e.toLowerCase().includes(n.toLowerCase()), Fe = 1e6, E = (e) => e * Fe, W = E(0.06), ke = E(4), Ue = (e) => e <= 64 ? W : e <= 128 ? E(0.12) : e <= 256 ? E(0.25) : e <= 384 ? E(0.32) : e <= 426 ? E(0.38) : e <= 640 ? E(0.5) : e <= 848 ? E(0.7) : e <= 1280 ? E(1) : e <= 1920 ? E(2) : ke, Le = "av1", Ve = (e) => K(e, Le), $e = 0.6, j = (e, n) => Ve(n) ? e * $e : e, xe = (e) => j(W, e), H = (e, n) => {
338
- const t = Ue(e);
339
- return j(t, n);
340
- }, Y = Q(), Ge = async () => Y().catch((e) => {
341
- o("videoSendingBalancer: error", e);
342
- }), Xe = async (e) => (Y.add(e), Ge()), k = async ({
336
+ }), K = (e, n) => e !== void 0 && n !== void 0 && e.toLowerCase().includes(n.toLowerCase()), De = "ERROR_NOT_RUNNING", Fe = (e) => {
337
+ const n = new Error("Promise was not running");
338
+ return n.basePromise = e, n.id = De, n.name = "Not running", n;
339
+ }, Ue = async (e, n) => e.reduce(
340
+ async (t, s) => t.then(async ({ success: r, errors: o, results: a }) => (!n || n(s) ? s() : Promise.reject(Fe(s))).then((u) => ({
341
+ errors: o,
342
+ success: [...r, u],
343
+ results: [...a, u],
344
+ isSuccessful: !0,
345
+ isError: !1
346
+ })).catch((u) => ({
347
+ success: r,
348
+ errors: [...o, u],
349
+ results: [...a, u],
350
+ isSuccessful: !1,
351
+ isError: !0
352
+ }))),
353
+ Promise.resolve({
354
+ success: [],
355
+ errors: [],
356
+ results: [],
357
+ isSuccessful: !1,
358
+ isError: !1
359
+ })
360
+ ), Le = new Error("Stack is empty"), I = (e) => e[e.length - 1], xe = new Error("Promise is not actual"), Ve = new Error(
361
+ "stackPromises only works with functions that returns a Promise"
362
+ ), $e = ({
363
+ noRejectIsNotActual: e = !1,
364
+ noRunIsNotActual: n = !1
365
+ } = {}) => {
366
+ const t = [], s = [], r = ({ task: i, index: S }) => {
367
+ s.push({ task: i, index: S });
368
+ }, o = (i, { task: S, index: l }) => {
369
+ const R = s.find(({ task: b, index: O }) => S === b && l === O);
370
+ if (!R)
371
+ throw new Error("Task not found");
372
+ if (R.promise)
373
+ throw new Error("Task is already running");
374
+ R.promise = i;
375
+ }, a = ({
376
+ task: i,
377
+ index: S
378
+ }) => {
379
+ const l = s.find(({ task: R, index: b }) => i === R && S === b);
380
+ if (l)
381
+ return l.promise;
382
+ }, u = ({ task: i }) => {
383
+ const S = I(s);
384
+ return (S == null ? void 0 : S.task) === i;
385
+ }, m = ({ task: i, index: S }) => (r({ task: i, index: S }), async () => {
386
+ let l = a({ task: i, index: S });
387
+ const R = u({ task: i });
388
+ return !l && n && !R ? Promise.resolve() : (l || (l = i({ isActual: R }), o(l, { task: i, index: S })), l);
389
+ }), E = ({
390
+ resolve: i,
391
+ reject: S
392
+ }) => ({ results: l, isSuccessful: R }) => {
393
+ const b = l.length, O = t.length;
394
+ if (b === O) {
395
+ const d = I(l);
396
+ if (R) {
397
+ i(d);
398
+ return;
399
+ }
400
+ S(d);
401
+ return;
402
+ }
403
+ if (e) {
404
+ const d = I(l);
405
+ i(d);
406
+ return;
407
+ }
408
+ S(xe);
409
+ };
410
+ let C = !1;
411
+ const f = () => {
412
+ C = !0;
413
+ }, T = () => {
414
+ C = !1;
415
+ }, h = () => C, y = async () => (f(), Ue(t, h)), g = async () => {
416
+ if (t.length === 0)
417
+ throw Le;
418
+ return new Promise((i, S) => {
419
+ const l = E({ resolve: i, reject: S });
420
+ y().then(l).catch(l);
421
+ });
422
+ }, M = (i) => {
423
+ if (typeof i != "function")
424
+ throw Ve;
425
+ const S = t.length;
426
+ return t.push(m({ task: i, index: S })), g;
427
+ }, v = async (i) => (M(i), g()), p = () => {
428
+ t.length = 0, s.length = 0;
429
+ }, _ = () => {
430
+ T(), p();
431
+ };
432
+ return g.add = M, g.run = v, g.stop = _, g;
433
+ }, Ge = 1e6, N = (e) => e * Ge, W = N(0.06), je = N(4), Xe = (e) => e <= 64 ? W : e <= 128 ? N(0.12) : e <= 256 ? N(0.25) : e <= 384 ? N(0.32) : e <= 426 ? N(0.38) : e <= 640 ? N(0.5) : e <= 848 ? N(0.7) : e <= 1280 ? N(1) : e <= 1920 ? N(2) : je, Ke = "av1", We = (e) => K(e, Ke), He = 0.6, H = (e, n) => We(n) ? e * He : e, Ye = (e) => H(W, e), Y = (e, n) => {
434
+ const t = Xe(e);
435
+ return H(t, n);
436
+ }, z = $e(), ze = async () => z().catch((e) => {
437
+ c("videoSendingBalancer: error", e);
438
+ }), qe = async (e) => (z.add(e), ze()), U = async ({
343
439
  sender: e,
344
440
  scaleResolutionDownBy: n,
345
441
  maxBitrate: t,
346
442
  onSetParameters: s
347
- }) => Xe(async () => z(e, { scaleResolutionDownBy: n, maxBitrate: t }, s)), Ke = async ({ sender: e, codec: n }, t) => {
348
- const r = xe(n);
349
- return k({
443
+ }) => qe(async () => q(e, { scaleResolutionDownBy: n, maxBitrate: t }, s)), Je = async ({ sender: e, codec: n }, t) => {
444
+ const r = Ye(n);
445
+ return U({
350
446
  sender: e,
351
447
  maxBitrate: r,
352
448
  onSetParameters: t,
353
449
  scaleResolutionDownBy: 200
354
450
  });
355
- }, I = async ({ sender: e, track: n, codec: t }, s) => {
356
- const c = n.getSettings().width, i = H(c, t);
357
- return k({
451
+ }, B = async ({ sender: e, track: n, codec: t }, s) => {
452
+ const a = n.getSettings().width, u = Y(a, t);
453
+ return U({
358
454
  sender: e,
359
- maxBitrate: i,
455
+ maxBitrate: u,
360
456
  onSetParameters: s,
361
457
  scaleResolutionDownBy: 1
362
458
  });
363
- }, We = async ({
459
+ }, Qe = async ({
364
460
  sender: e,
365
461
  track: n,
366
462
  resolution: t,
367
463
  codec: s
368
464
  }, r) => {
369
- const a = n.getSettings(), c = a.width, i = a.height, [u, m] = t.split("x"), d = c / Number(u), l = i / Number(m), f = Math.max(d, l, 1), C = H(Number(u), s);
370
- return k({
465
+ const o = n.getSettings(), a = o.width, u = o.height, [m, E] = t.split("x"), C = a / Number(m), f = u / Number(E), h = Math.max(C, f, 1), y = Y(Number(m), s);
466
+ return U({
371
467
  sender: e,
372
- maxBitrate: C,
468
+ maxBitrate: y,
373
469
  onSetParameters: r,
374
- scaleResolutionDownBy: f
470
+ scaleResolutionDownBy: h
375
471
  });
376
- }, je = async ({
472
+ }, Ze = async ({
377
473
  mainCam: e,
378
474
  resolutionMainCam: n,
379
475
  sender: t,
380
476
  track: s,
381
477
  codec: r
382
- }, a) => {
478
+ }, o) => {
383
479
  switch (e) {
384
- case B.PAUSE_MAIN_CAM:
385
- return Ke({ sender: t, codec: r }, a);
386
- case B.RESUME_MAIN_CAM:
387
- return I({ sender: t, track: s, codec: r }, a);
388
- case B.MAX_MAIN_CAM_RESOLUTION:
389
- return n !== void 0 ? We(
480
+ case P.PAUSE_MAIN_CAM:
481
+ return Je({ sender: t, codec: r }, o);
482
+ case P.RESUME_MAIN_CAM:
483
+ return B({ sender: t, track: s, codec: r }, o);
484
+ case P.MAX_MAIN_CAM_RESOLUTION:
485
+ return n !== void 0 ? Qe(
390
486
  { sender: t, track: s, codec: r, resolution: n },
391
- a
392
- ) : I({ sender: t, track: s, codec: r }, a);
487
+ o
488
+ ) : B({ sender: t, track: s, codec: r }, o);
393
489
  default:
394
- return I({ sender: t, track: s, codec: r }, a);
490
+ return B({ sender: t, track: s, codec: r }, o);
395
491
  }
396
- }, U = {
492
+ }, L = {
397
493
  isChanged: !1,
398
494
  parameters: {
399
495
  encodings: [{}],
@@ -402,54 +498,54 @@ const re = (e = new Error()) => {
402
498
  headerExtensions: [],
403
499
  rtcp: {}
404
500
  }
405
- }, L = async ({
501
+ }, x = async ({
406
502
  mainCam: e,
407
503
  resolutionMainCam: n,
408
504
  connection: t,
409
505
  onSetParameters: s,
410
506
  ignoreForCodec: r
411
507
  }) => {
412
- const a = t.getSenders(), c = De(a);
413
- if (!(c != null && c.track))
414
- return U;
415
- const i = await we(c);
416
- return K(i, r) ? U : je(
417
- { mainCam: e, resolutionMainCam: n, sender: c, codec: i, track: c.track },
508
+ const o = t.getSenders(), a = ke(o);
509
+ if (!(a != null && a.track))
510
+ return L;
511
+ const u = await Be(a);
512
+ return K(u, r) ? L : Ze(
513
+ { mainCam: e, resolutionMainCam: n, sender: a, codec: u, track: a.track },
418
514
  s
419
515
  );
420
- }, en = (e, {
516
+ }, cn = (e, {
421
517
  ignoreForCodec: n,
422
518
  onSetParameters: t
423
519
  } = {}) => {
424
520
  const s = async () => {
425
- const { connection: u } = e;
426
- if (!u)
521
+ const { connection: m } = e;
522
+ if (!m)
427
523
  throw new Error("connection is not exist");
428
- return L({
429
- connection: u,
524
+ return x({
525
+ connection: m,
430
526
  onSetParameters: t,
431
527
  ignoreForCodec: n
432
528
  });
433
529
  };
434
530
  let r = s;
435
- const a = async (u) => (r = async () => {
436
- const { mainCam: m, resolutionMainCam: d } = u, { connection: l } = e;
437
- if (!l)
531
+ const o = async (m) => (r = async () => {
532
+ const { mainCam: E, resolutionMainCam: C } = m, { connection: f } = e;
533
+ if (!f)
438
534
  throw new Error("connection is not exist");
439
- return L({
440
- mainCam: m,
441
- resolutionMainCam: d,
442
- connection: l,
535
+ return x({
536
+ mainCam: E,
537
+ resolutionMainCam: C,
538
+ connection: f,
443
539
  onSetParameters: t,
444
540
  ignoreForCodec: n
445
541
  });
446
542
  }, r());
447
543
  return {
448
544
  subscribe: () => {
449
- e.onSession("main-cam-control", a);
545
+ e.onSession("main-cam-control", o);
450
546
  },
451
547
  unsubscribe: () => {
452
- e.offSession("main-cam-control", a);
548
+ e.offSession("main-cam-control", o);
453
549
  },
454
550
  balanceByTrack: s,
455
551
  resetMainCamControl() {
@@ -461,19 +557,19 @@ const re = (e = new Error()) => {
461
557
  };
462
558
  };
463
559
  export {
464
- B as EEventsMainCAM,
465
- sn as EEventsMic,
466
- rn as EEventsSyncMediaState,
467
- on as EUseLicense,
468
- an as causes,
469
- cn as constants,
470
- fn as debug,
471
- Ye as default,
472
- un as disableDebug,
473
- ln as enableDebug,
474
- Sn as eventNames,
475
- we as getCodecFromSender,
476
- mn as hasCanceledCallError,
477
- en as resolveVideoSendingBalancer,
478
- Ze as tools
560
+ P as EEventsMainCAM,
561
+ ln as EEventsMic,
562
+ Sn as EEventsSyncMediaState,
563
+ dn as EUseLicense,
564
+ mn as causes,
565
+ fn as constants,
566
+ yn as debug,
567
+ nn as default,
568
+ Cn as disableDebug,
569
+ En as enableDebug,
570
+ gn as eventNames,
571
+ Be as getCodecFromSender,
572
+ Rn as hasCanceledCallError,
573
+ cn as resolveVideoSendingBalancer,
574
+ on as tools
479
575
  };