sip-connector 7.0.3 → 7.0.5

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