sip-connector 10.0.1 → 11.1.0

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