sip-connector 14.1.0-alpha.9 → 14.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/SipConnector-DRjfFGAZ.js +1339 -0
  2. package/dist/SipConnector-EXAO9Z-2.cjs +1 -0
  3. package/dist/doMock.cjs +1 -1
  4. package/dist/doMock.js +162 -267
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +526 -577
  7. package/dist/src/SipConnector.d.ts +235 -0
  8. package/dist/{SipConnectorFacade → src/SipConnectorFacade}/SipConnectorFacade.d.ts +16 -7
  9. package/dist/{__fixtures__ → src/__fixtures__}/BaseSession.mock.d.ts +5 -5
  10. package/dist/{__fixtures__ → src/__fixtures__}/RTCSessionMock.d.ts +4 -9
  11. package/dist/{__fixtures__ → src/__fixtures__}/UA.mock.d.ts +14 -12
  12. package/dist/{__fixtures__ → src/__fixtures__}/index.d.ts +4 -4
  13. package/dist/{__fixtures__ → src/__fixtures__}/jssip.mock.d.ts +3 -3
  14. package/dist/src/causes.d.ts +23 -0
  15. package/dist/{doMock.d.ts → src/doMock.d.ts} +1 -2
  16. package/dist/{__fixtures__ → src}/eventNames.d.ts +1 -1
  17. package/dist/src/headers.d.ts +37 -0
  18. package/dist/src/index.d.ts +11 -0
  19. package/dist/{tools → src/tools}/__fixtures__/connectToServer.d.ts +2 -2
  20. package/dist/{tools → src/tools}/__fixtures__/processRequest.d.ts +1 -1
  21. package/dist/{tools → src/tools}/error/getLinkError.d.ts +1 -1
  22. package/dist/{tools → src/tools}/error/getTypeFromError.d.ts +1 -1
  23. package/dist/{tools → src/tools}/error/getValuesFromError.d.ts +1 -1
  24. package/dist/{tools → src/tools}/index.d.ts +1 -1
  25. package/dist/{tools → src/tools}/prepareMediaStream.d.ts +1 -1
  26. package/dist/{tools → src/tools}/setVideoTrackContentHints.d.ts +1 -1
  27. package/dist/{tools → src/tools}/syncMediaState/index.d.ts +1 -1
  28. package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMainCam.d.ts +1 -1
  29. package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMic.d.ts +1 -1
  30. package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMainCam.d.ts +1 -1
  31. package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMic.d.ts +1 -1
  32. package/dist/src/types.d.ts +69 -0
  33. package/dist/{videoSendingBalancer → src/videoSendingBalancer}/balance.d.ts +1 -1
  34. package/dist/{videoSendingBalancer → src/videoSendingBalancer}/index.d.ts +1 -1
  35. package/dist/{videoSendingBalancer → src/videoSendingBalancer}/processSender.d.ts +1 -1
  36. package/dist/src/videoSendingBalancer/scaleBitrate.d.ts +2 -0
  37. package/package.json +32 -26
  38. package/dist/@SipConnector-BOHJ000Z.cjs +0 -1
  39. package/dist/@SipConnector-BxitfweK.js +0 -2267
  40. package/dist/ApiManager/@ApiManager.d.ts +0 -58
  41. package/dist/ApiManager/constants.d.ts +0 -71
  42. package/dist/ApiManager/eventNames.d.ts +0 -33
  43. package/dist/ApiManager/index.d.ts +0 -3
  44. package/dist/ApiManager/types.d.ts +0 -99
  45. package/dist/CallManager/@CallManager.d.ts +0 -26
  46. package/dist/CallManager/AbstractCallStrategy.d.ts +0 -47
  47. package/dist/CallManager/MCUCallStrategy.d.ts +0 -30
  48. package/dist/CallManager/RemoteStreamsManager.d.ts +0 -8
  49. package/dist/CallManager/causes.d.ts +0 -13
  50. package/dist/CallManager/eventNames.d.ts +0 -45
  51. package/dist/CallManager/hasCanceledCallError.d.ts +0 -2
  52. package/dist/CallManager/index.d.ts +0 -7
  53. package/dist/CallManager/types.d.ts +0 -59
  54. package/dist/ConnectionManager/@ConnectionManager.d.ts +0 -48
  55. package/dist/ConnectionManager/ConfigurationManager.d.ts +0 -60
  56. package/dist/ConnectionManager/ConnectionFlow.d.ts +0 -84
  57. package/dist/ConnectionManager/ConnectionStateMachine.d.ts +0 -61
  58. package/dist/ConnectionManager/RegistrationManager.d.ts +0 -17
  59. package/dist/ConnectionManager/SipOperations.d.ts +0 -32
  60. package/dist/ConnectionManager/UAFactory.d.ts +0 -50
  61. package/dist/ConnectionManager/eventNames.d.ts +0 -16
  62. package/dist/ConnectionManager/index.d.ts +0 -3
  63. package/dist/IncomingCallManager/@IncomingCallManager.d.ts +0 -37
  64. package/dist/IncomingCallManager/eventNames.d.ts +0 -13
  65. package/dist/IncomingCallManager/index.d.ts +0 -2
  66. package/dist/PresentationManager/@PresentationManager.d.ts +0 -47
  67. package/dist/PresentationManager/constants.d.ts +0 -1
  68. package/dist/PresentationManager/eventNames.d.ts +0 -11
  69. package/dist/PresentationManager/index.d.ts +0 -2
  70. package/dist/PresentationManager/types.d.ts +0 -2
  71. package/dist/SipConnector/@SipConnector.d.ts +0 -96
  72. package/dist/SipConnector/eventNames.d.ts +0 -4
  73. package/dist/SipConnector/index.d.ts +0 -2
  74. package/dist/index.d.ts +0 -14
  75. package/dist/types.d.ts +0 -23
  76. package/dist/videoSendingBalancer/scaleBitrate.d.ts +0 -2
  77. /package/dist/{SipConnectorFacade → src/SipConnectorFacade}/index.d.ts +0 -0
  78. /package/dist/{__fixtures__ → src/__fixtures__}/RTCPeerConnectionMock.d.ts +0 -0
  79. /package/dist/{__fixtures__ → src/__fixtures__}/RTCRtpSenderMock.d.ts +0 -0
  80. /package/dist/{__fixtures__ → src/__fixtures__}/Registrator.mock.d.ts +0 -0
  81. /package/dist/{__fixtures__ → src/__fixtures__}/Request.mock.d.ts +0 -0
  82. /package/dist/{__fixtures__ → src/__fixtures__}/WebSocketInterface.mock.d.ts +0 -0
  83. /package/dist/{__fixtures__ → src/__fixtures__}/accountNotify.d.ts +0 -0
  84. /package/dist/{__fixtures__ → src/__fixtures__}/channels.d.ts +0 -0
  85. /package/dist/{__fixtures__ → src/__fixtures__}/channelsNotify.d.ts +0 -0
  86. /package/dist/{__fixtures__ → src/__fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
  87. /package/dist/{__fixtures__ → src/__fixtures__}/delayPromise.d.ts +0 -0
  88. /package/dist/{__fixtures__ → src/__fixtures__}/enterRoom.d.ts +0 -0
  89. /package/dist/{__fixtures__ → src/__fixtures__}/mediaState.d.ts +0 -0
  90. /package/dist/{__fixtures__ → src/__fixtures__}/participantMoveRequests.d.ts +0 -0
  91. /package/dist/{__fixtures__ → src/__fixtures__}/participantNotify.d.ts +0 -0
  92. /package/dist/{__fixtures__ → src/__fixtures__}/remoteCallerData.d.ts +0 -0
  93. /package/dist/{__fixtures__ → src/__fixtures__}/utils.d.ts +0 -0
  94. /package/dist/{__fixtures__ → src/__fixtures__}/webcastNotify.d.ts +0 -0
  95. /package/dist/{__fixtures__ → src}/constants.d.ts +0 -0
  96. /package/dist/{ConnectionManager → src}/getExtraHeadersRemoteAddress.d.ts +0 -0
  97. /package/dist/{logger.d.ts → src/logger.d.ts} +0 -0
  98. /package/dist/{setParametersToSender → src/setParametersToSender}/configureDegradationPreference.d.ts +0 -0
  99. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
  100. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEncodings.d.ts +0 -0
  101. /package/dist/{setParametersToSender → src/setParametersToSender}/configureMaxBitrate.d.ts +0 -0
  102. /package/dist/{setParametersToSender → src/setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
  103. /package/dist/{setParametersToSender → src/setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
  104. /package/dist/{setParametersToSender → src/setParametersToSender}/index.d.ts +0 -0
  105. /package/dist/{setParametersToSender → src/setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
  106. /package/dist/{setParametersToSender → src/setParametersToSender}/setParametersToSender.d.ts +0 -0
  107. /package/dist/{tools → src/tools}/__fixtures__/call.d.ts +0 -0
  108. /package/dist/{tools → src/tools}/__fixtures__/hasValidUri.d.ts +0 -0
  109. /package/dist/{tools → src/tools}/__fixtures__/permissions.d.ts +0 -0
  110. /package/dist/{tools → src/tools}/__tests-utils__/parseObject.d.ts +0 -0
  111. /package/dist/{tools → src/tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
  112. /package/dist/{tools → src/tools}/error/index.d.ts +0 -0
  113. /package/dist/{tools → src/tools}/error/stringifyMessage.d.ts +0 -0
  114. /package/dist/{tools → src/tools}/generateSimulcastEncodings.d.ts +0 -0
  115. /package/dist/{tools → src/tools}/getExtraHeaders.d.ts +0 -0
  116. /package/dist/{tools → src/tools}/getUserAgent.d.ts +0 -0
  117. /package/dist/{tools → src/tools}/hasPurgatory.d.ts +0 -0
  118. /package/dist/{tools → src/tools}/resolveUpdateTransceiver.d.ts +0 -0
  119. /package/dist/{tools/sendDtmfFAccumulated.d.ts → src/tools/sendDTMFAccumulated.d.ts} +0 -0
  120. /package/dist/{utils → src/utils}/errors.d.ts +0 -0
  121. /package/dist/{utils → src/utils}/findSenderByStream.d.ts +0 -0
  122. /package/dist/{utils → src/utils}/findVideoSender.d.ts +0 -0
  123. /package/dist/{utils → src/utils}/findVideoTrack.d.ts +0 -0
  124. /package/dist/{utils → src/utils}/getCodecFromSender.d.ts +0 -0
  125. /package/dist/{utils → src/utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
  126. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidth.d.ts +0 -0
  127. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +0 -0
  128. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
  129. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasIncludesString.d.ts +0 -0
  130. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
  131. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
  132. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,138 +1,358 @@
1
- import "events-constructor";
2
- import { E as y, O as ce, l as c, a as w } from "./@SipConnector-BxitfweK.js";
3
- import { b as On, S as Nn, d as Bn, e as wn, h as Dn } from "./@SipConnector-BxitfweK.js";
4
- import { isCanceledError as K } from "@krivega/cancelable-promise";
5
- import { hasCanceledError as ae } from "repeated-calls";
6
- import { debounce as ue } from "ts-debounce";
1
+ import { B as K, N as Y, l as i, E as w, s as oe, a as re, P as ie, b as ce } from "./SipConnector-DRjfFGAZ.js";
2
+ import { j as fn, k as mn, n as hn, m as pn, S as Rn, c as gn, d as yn, f as Tn, g as En, e as Mn, h as bn, i as vn } from "./SipConnector-DRjfFGAZ.js";
3
+ import { sequentPromises as ae } from "sequent-promises";
4
+ import { createStackPromises as ue } from "stack-promises";
7
5
  import I from "debug";
8
- import { default as In } from "debug";
9
- import { sequentPromises as de } from "sequent-promises";
10
- import { createStackPromises as le } from "stack-promises";
11
- const fe = (e) => e instanceof Object && ("originator" in e || "cause" in e), Tn = (e) => {
12
- if (K(e))
13
- return !0;
14
- if (!fe(e))
15
- return !1;
16
- const { originator: n, cause: t } = e;
17
- return typeof t == "string" ? t === y.REQUEST_TIMEOUT || t === y.REJECTED || n === ce.LOCAL && (t === y.CANCELED || t === y.BYE) : !1;
18
- }, he = (e, n) => (e.degradationPreference = n.degradationPreference, e), ge = (e, n) => {
19
- e.encodings ??= [];
20
- for (let t = e.encodings.length; t < n; t += 1)
21
- e.encodings.push({});
6
+ import { default as An } from "debug";
7
+ import { isCanceledError as de } from "@krivega/cancelable-promise";
8
+ import { hasCanceledError as le } from "repeated-calls";
9
+ import { debounce as Ce } from "ts-debounce";
10
+ const U = (n) => {
11
+ const { url: e, cause: t } = n;
12
+ let s = e;
13
+ return (t === K || t === Y) && (s = `${n.message.to.uri.user}@${n.message.to.uri.host}`), s;
14
+ };
15
+ var q = /* @__PURE__ */ ((n) => (n.CONNECT_SERVER_FAILED = "CONNECT_SERVER_FAILED", n.WRONG_USER_OR_PASSWORD = "WRONG_USER_OR_PASSWORD", n.BAD_MEDIA_ERROR = "BAD_MEDIA_ERROR", n.NOT_FOUND_ERROR = "NOT_FOUND_ERROR", n.WS_CONNECTION_FAILED = "WS_CONNECTION_FAILED", n.CONNECT_SERVER_FAILED_BY_LINK = "CONNECT_SERVER_FAILED_BY_LINK", n))(q || {});
16
+ const Se = new Error("Unknown error"), fe = (n = Se) => {
17
+ const { cause: e, socket: t } = n;
18
+ let s = "CONNECT_SERVER_FAILED";
19
+ switch (e) {
20
+ case "Forbidden": {
21
+ s = "WRONG_USER_OR_PASSWORD";
22
+ break;
23
+ }
24
+ case K: {
25
+ s = "BAD_MEDIA_ERROR";
26
+ break;
27
+ }
28
+ case Y: {
29
+ s = "NOT_FOUND_ERROR";
30
+ break;
31
+ }
32
+ default:
33
+ t !== void 0 && t._ws?.readyState === 3 ? s = "WS_CONNECTION_FAILED" : U(n) !== void 0 && U(n) !== "" && (s = "CONNECT_SERVER_FAILED_BY_LINK");
34
+ }
35
+ return s;
36
+ }, me = (n) => {
37
+ let e = "";
38
+ try {
39
+ e = JSON.stringify(n);
40
+ } catch (t) {
41
+ i("failed to stringify message", t);
42
+ }
22
43
  return e;
23
- }, Y = (e) => (n, t) => t !== void 0 && n !== t || t === void 0 && n !== e, Ce = Y(), Se = (e, n) => {
24
- if (Ce(e, n))
25
- return e;
26
- }, me = (e, n) => {
27
- const t = e.maxBitrate, o = Se(n, t);
28
- return o !== void 0 && (e.maxBitrate = o), e;
29
- }, q = 1, Re = Y(
30
- q
31
- ), pe = (e, n) => {
32
- const t = e === void 0 ? void 0 : Math.max(e, q);
33
- if (t !== void 0 && Re(
34
- t,
35
- n
36
- ))
37
- return t;
38
- }, ye = (e, n) => {
39
- const t = e.scaleResolutionDownBy, o = pe(
40
- n,
41
- t
42
- );
43
- return o !== void 0 && (e.scaleResolutionDownBy = o), e;
44
- }, Ee = (e, n) => {
45
- const t = n.encodings?.length ?? 0;
46
- return ge(e, t), e.encodings.forEach((o, s) => {
47
- const r = (n?.encodings ?? [])[s], i = r?.maxBitrate, a = r?.scaleResolutionDownBy;
48
- me(o, i), ye(o, a);
49
- }), e;
50
- }, Te = (e, n) => {
51
- if (e.codecs?.length !== n.codecs?.length)
52
- return !0;
53
- for (let t = 0; t < (e.codecs?.length ?? 0); t++)
54
- if (JSON.stringify(e.codecs[t]) !== JSON.stringify(n.codecs[t]))
55
- return !0;
56
- if (e.headerExtensions?.length !== n.headerExtensions?.length)
57
- return !0;
58
- for (let t = 0; t < (e.headerExtensions?.length ?? 0); t++)
59
- if (JSON.stringify(e.headerExtensions[t]) !== JSON.stringify(n.headerExtensions[t]))
60
- return !0;
61
- if (e.encodings?.length !== n.encodings?.length)
62
- return !0;
63
- for (let t = 0; t < (e.encodings.length ?? 0); t++)
64
- if (JSON.stringify(e.encodings[t]) !== JSON.stringify(n.encodings[t]))
65
- return !0;
66
- return e.rtcp?.cname !== n.rtcp?.cname || e.rtcp?.reducedSize !== n.rtcp?.reducedSize || e.degradationPreference !== n.degradationPreference;
67
- }, z = async (e, n) => {
68
- const t = e.getParameters(), o = JSON.parse(
69
- JSON.stringify(t)
70
- );
71
- Ee(t, n), he(t, n);
72
- const s = Te(o, t);
73
- return s && await e.setParameters(t), { parameters: t, isChanged: s };
74
- }, ve = (e) => e.getVideoTracks()[0], Me = 1e6, m = (e) => e * Me, Q = m(0.06), be = m(4), _e = (e) => e <= 64 ? Q : e <= 128 ? m(0.12) : e <= 256 ? m(0.25) : e <= 384 ? m(0.32) : e <= 426 ? m(0.38) : e <= 640 ? m(0.5) : e <= 848 ? m(0.7) : e <= 1280 ? m(1) : e <= 1920 ? m(2) : be, Z = (e, n) => e !== void 0 && n !== void 0 && e.toLowerCase().includes(n.toLowerCase()), Ae = "av1", Oe = (e) => Z(e, Ae), Ne = 0.6, ee = (e, n) => Oe(n) ? e * Ne : e, Be = (e) => ee(Q, e), ne = (e, n) => {
75
- const t = _e(e);
76
- return ee(t, n);
77
- }, J = 1, te = ({
78
- videoTrack: e,
79
- targetSize: n,
44
+ }, he = new Error("Unknown error"), pe = (n = he) => {
45
+ const { code: e, cause: t, message: s } = n, o = U(n), r = { code: "", cause: "", message: "" };
46
+ return typeof s == "object" && s !== null ? r.message = me(s) : s && (r.message = String(s)), o !== void 0 && o !== "" && (r.link = o), e !== void 0 && e !== "" && (r.code = e), t !== void 0 && t !== "" && (r.cause = t), r;
47
+ }, Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
48
+ __proto__: null,
49
+ EErrorTypes: q,
50
+ getLinkError: U,
51
+ getTypeFromError: fe,
52
+ getValuesFromError: pe
53
+ }, Symbol.toStringTag, { value: "Module" })), ge = ({
54
+ sessionId: n,
55
+ remoteAddress: e,
56
+ isMutedAudio: t,
57
+ isMutedVideo: s,
58
+ isRegistered: o,
59
+ isPresentationCall: r
60
+ }) => {
61
+ const c = [], a = t ? "0" : "1", u = s ? "0" : "1";
62
+ return c.push(`X-Vinteo-Mic-State: ${a}`, `X-Vinteo-MainCam-State: ${u}`), (o === !1 || o === void 0) && c.push("X-Vinteo-Purgatory-Call: yes"), n !== void 0 && n !== "" && c.push(`X-Vinteo-Session: ${n}`), r === !0 && c.push("X-Vinteo-Presentation-Call: yes"), e !== void 0 && e !== "" && c.push(`X-Vinteo-Remote: ${e}`), c;
63
+ }, ye = "[@*!|]", Te = "_", Ee = (n) => {
64
+ let e = n;
65
+ return e = e.replaceAll(new RegExp(ye, "g"), Te), e;
66
+ }, Me = ({
67
+ appName: n,
68
+ appVersion: e,
69
+ browserName: t,
70
+ browserVersion: s
71
+ }) => {
72
+ const r = `${Ee(n)} ${e}`;
73
+ return `ChromeNew - ${t === void 0 ? r : `${t} ${s}, ${r}`}`;
74
+ }, be = ({
75
+ isUnifiedSdpSemantic: n,
76
+ appVersion: e,
77
+ browserName: t,
78
+ browserVersion: s,
79
+ appName: o
80
+ }) => n ? Me({ appVersion: e, browserName: t, browserVersion: s, appName: o }) : "Chrome", z = "purgatory", D = (n) => n === z, ve = (n) => (e) => [...e].map((s) => async () => n(s)), _e = async ({
81
+ accumulatedKeys: n,
82
+ sendKey: e,
83
+ canRunTask: t
84
+ }) => {
85
+ const o = ve(e)(n);
86
+ return ae(o, t);
87
+ }, Ae = (n) => (t) => (i("onStartMainCam"), n.onSession("admin-start-main-cam", t)), Oe = (n) => (t) => (i("onStartMic"), n.onSession("admin-start-mic", t)), Ne = (n) => (t) => (i("onStopMainCam"), n.onSession("admin-stop-main-cam", t)), we = (n) => (t) => (i("onStopMic"), n.onSession("admin-stop-mic", t)), Be = ({ sipConnector: n }) => {
88
+ const e = (f, R) => ({ isSyncForced: m = !1 }) => {
89
+ if (m) {
90
+ f();
91
+ return;
92
+ }
93
+ R();
94
+ }, t = Ae(n), s = Ne(n), o = Oe(n), r = we(n);
95
+ let c = () => {
96
+ }, a = () => {
97
+ }, u = () => {
98
+ }, l = () => {
99
+ };
100
+ const S = ({
101
+ onStartMainCamForced: f,
102
+ onStartMainCamNotForced: R,
103
+ onStopMainCamForced: m,
104
+ onStopMainCamNotForced: h,
105
+ onStartMicForced: g,
106
+ onStartMicNotForced: y,
107
+ onStopMicForced: T,
108
+ onStopMicNotForced: E
109
+ }) => {
110
+ const v = e(
111
+ f,
112
+ R
113
+ );
114
+ c = t(v);
115
+ const _ = e(
116
+ m,
117
+ h
118
+ );
119
+ a = s(_);
120
+ const A = e(g, y);
121
+ u = o(A);
122
+ const O = e(T, E);
123
+ l = r(O);
124
+ }, C = () => {
125
+ c(), a(), u(), l();
126
+ };
127
+ return {
128
+ start: (f) => {
129
+ S(f);
130
+ },
131
+ stop: () => {
132
+ C();
133
+ }
134
+ };
135
+ }, un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
136
+ __proto__: null,
137
+ PURGATORY_CONFERENCE_NUMBER: z,
138
+ createSyncMediaState: Be,
139
+ error: Re,
140
+ getExtraHeaders: ge,
141
+ getUserAgent: be,
142
+ hasPurgatory: D,
143
+ sendDtmfAccumulated: _e
144
+ }, Symbol.toStringTag, { value: "Module" })), Pe = (n) => [...n.keys()].map((e) => n.get(e)), Ie = (n, e) => Pe(n).find((t) => t?.type === e), De = async (n) => n.getStats().then((e) => Ie(e, "codec")?.mimeType), ke = (n) => n.find((e) => e.track?.kind === "video"), Q = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Fe = 1e6, p = (n) => n * Fe, J = p(0.06), Ve = p(4), Ue = (n) => n <= 64 ? J : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ve, xe = "av1", Le = (n) => Q(n, xe), $e = 0.6, Z = (n, e) => Le(e) ? n * $e : n, He = (n) => Z(J, n), ee = (n, e) => {
145
+ const t = Ue(n);
146
+ return Z(t, e);
147
+ }, H = 1, ne = ({
148
+ videoTrack: n,
149
+ targetSize: e,
80
150
  codec: t
81
151
  }) => {
82
- const o = e.getSettings(), s = o.width, r = o.height, i = s === void 0 ? J : s / n.width, a = r === void 0 ? J : r / n.height, u = Math.max(i, a, J), l = ne(n.width, t);
152
+ const s = n.getSettings(), o = s.width, r = s.height, c = o === void 0 ? H : o / e.width, a = r === void 0 ? H : r / e.height, u = Math.max(c, a, H), l = ee(e.width, t);
83
153
  return { scaleResolutionDownBy: u, maxBitrate: l };
84
- }, D = ({
85
- mediaStream: e,
86
- simulcastEncodings: n,
154
+ }, te = ue(), Xe = async () => te().catch((n) => {
155
+ i("videoSendingBalancer: error", n);
156
+ }), je = async (n) => (te.add(n), Xe()), j = async ({
157
+ sender: n,
158
+ scaleResolutionDownBy: e,
159
+ maxBitrate: t,
160
+ onSetParameters: s
161
+ }) => je(async () => oe(n, { scaleResolutionDownBy: e, maxBitrate: t }, s)), We = async ({ sender: n, codec: e }, t) => {
162
+ const o = He(e);
163
+ return j({
164
+ sender: n,
165
+ maxBitrate: o,
166
+ onSetParameters: t,
167
+ scaleResolutionDownBy: 200
168
+ });
169
+ }, V = async ({
170
+ sender: n,
171
+ videoTrack: e,
172
+ codec: t
173
+ }, s) => {
174
+ const c = e.getSettings().width, a = ee(c ?? 0, t);
175
+ return j({
176
+ sender: n,
177
+ maxBitrate: a,
178
+ onSetParameters: s,
179
+ scaleResolutionDownBy: 1
180
+ });
181
+ }, Ge = async ({
182
+ sender: n,
183
+ videoTrack: e,
184
+ resolution: t,
185
+ codec: s
186
+ }, o) => {
187
+ const [r, c] = t.split("x"), { maxBitrate: a, scaleResolutionDownBy: u } = ne({
188
+ videoTrack: e,
189
+ codec: s,
190
+ targetSize: {
191
+ width: Number(r),
192
+ height: Number(c)
193
+ }
194
+ });
195
+ return j({
196
+ sender: n,
197
+ maxBitrate: a,
198
+ onSetParameters: o,
199
+ scaleResolutionDownBy: u
200
+ });
201
+ }, Ke = async ({
202
+ mainCam: n,
203
+ resolutionMainCam: e,
204
+ sender: t,
205
+ videoTrack: s,
206
+ codec: o
207
+ }, r) => {
208
+ switch (n) {
209
+ case w.PAUSE_MAIN_CAM:
210
+ return We({ sender: t, codec: o }, r);
211
+ case w.RESUME_MAIN_CAM:
212
+ return V({ sender: t, videoTrack: s, codec: o }, r);
213
+ case w.MAX_MAIN_CAM_RESOLUTION:
214
+ return e !== void 0 ? Ge(
215
+ { sender: t, videoTrack: s, codec: o, resolution: e },
216
+ r
217
+ ) : V({ sender: t, videoTrack: s, codec: o }, r);
218
+ case w.ADMIN_STOP_MAIN_CAM:
219
+ case w.ADMIN_START_MAIN_CAM:
220
+ case void 0:
221
+ return V({ sender: t, videoTrack: s, codec: o }, r);
222
+ default:
223
+ return V({ sender: t, videoTrack: s, codec: o }, r);
224
+ }
225
+ }, W = {
226
+ isChanged: !1,
227
+ parameters: {
228
+ encodings: [{}],
229
+ transactionId: "0",
230
+ codecs: [],
231
+ headerExtensions: [],
232
+ rtcp: {}
233
+ }
234
+ }, G = async ({
235
+ mainCam: n,
236
+ resolutionMainCam: e,
237
+ connection: t,
238
+ onSetParameters: s,
239
+ ignoreForCodec: o
240
+ }) => {
241
+ const r = t.getSenders(), c = ke(r);
242
+ if (!c?.track)
243
+ return W;
244
+ const a = await De(c);
245
+ return Q(a, o) ? W : Ke(
246
+ {
247
+ mainCam: n,
248
+ resolutionMainCam: e,
249
+ sender: c,
250
+ codec: a,
251
+ videoTrack: c.track
252
+ },
253
+ s
254
+ );
255
+ }, dn = (n, {
256
+ ignoreForCodec: e,
257
+ onSetParameters: t
258
+ } = {}) => {
259
+ const s = async () => {
260
+ const { connection: u } = n;
261
+ if (!u)
262
+ throw new Error("connection is not exist");
263
+ return G({
264
+ connection: u,
265
+ onSetParameters: t,
266
+ ignoreForCodec: e
267
+ });
268
+ };
269
+ let o = s;
270
+ const r = (u) => {
271
+ o = async () => {
272
+ const { mainCam: l, resolutionMainCam: S } = u, { connection: C } = n;
273
+ if (!C)
274
+ throw new Error("connection is not exist");
275
+ return G({
276
+ mainCam: l,
277
+ resolutionMainCam: S,
278
+ connection: C,
279
+ onSetParameters: t,
280
+ ignoreForCodec: e
281
+ });
282
+ }, o().catch(I);
283
+ };
284
+ return {
285
+ subscribe: () => {
286
+ n.onSession("main-cam-control", r);
287
+ },
288
+ unsubscribe: () => {
289
+ n.offSession("main-cam-control", r);
290
+ },
291
+ balanceByTrack: s,
292
+ resetMainCamControl() {
293
+ o = s;
294
+ },
295
+ async reBalance() {
296
+ return o();
297
+ }
298
+ };
299
+ }, Ye = (n) => n.getVideoTracks()[0], B = ({
300
+ mediaStream: n,
301
+ simulcastEncodings: e,
87
302
  sendEncodings: t
88
303
  }) => {
89
- if (n && n.length > 0) {
90
- const o = t ?? [], s = ve(e);
91
- if (s === void 0)
304
+ if (e && e.length > 0) {
305
+ const s = t ?? [], o = Ye(n);
306
+ if (o === void 0)
92
307
  throw new Error("No video track");
93
- return n.forEach((r, i) => {
94
- const a = o[i] ?? {};
308
+ return e.forEach((r, c) => {
309
+ const a = s[c] ?? {};
95
310
  a.active = !0, r.rid !== void 0 && (a.rid = r.rid), r.scalabilityMode !== void 0 && (a.scalabilityMode = r.scalabilityMode);
96
- const { maxBitrate: u, scaleResolutionDownBy: l } = te({
97
- videoTrack: s,
311
+ const { maxBitrate: u, scaleResolutionDownBy: l } = ne({
312
+ videoTrack: o,
98
313
  targetSize: {
99
314
  width: r.width,
100
315
  height: r.height
101
316
  }
102
317
  });
103
- a.maxBitrate = u, a.scaleResolutionDownBy = l, o[i] = a;
104
- }), o;
318
+ a.maxBitrate = u, a.scaleResolutionDownBy = l, s[c] = a;
319
+ }), s;
105
320
  }
106
321
  return t;
107
- }, oe = "purgatory", x = (e) => e === oe, we = (e, n) => e.filter((o) => n.some((s) => s.clockRate === o.clockRate && s.mimeType === o.mimeType && s.channels === o.channels && s.sdpFmtpLine === o.sdpFmtpLine)), De = (e) => {
108
- const n = RTCRtpSender.getCapabilities(e), t = RTCRtpReceiver.getCapabilities(e), o = n === null ? [] : n.codecs, s = t === null ? [] : t.codecs;
109
- return we(o, s);
110
- }, Pe = (e, n) => n === void 0 || n.length === 0 ? e : e.sort((t, o) => {
111
- const s = n.indexOf(t.mimeType), r = n.indexOf(o.mimeType), i = s === -1 ? Number.MAX_VALUE : s, a = r === -1 ? Number.MAX_VALUE : r;
112
- return i - a;
113
- }), Ie = (e, n) => n === void 0 || n.length === 0 ? e : e.filter((t) => !n.includes(t.mimeType)), P = (e, {
114
- preferredMimeTypesVideoCodecs: n,
322
+ }, qe = (n, e) => n.filter((s) => e.some((o) => o.clockRate === s.clockRate && o.mimeType === s.mimeType && o.channels === s.channels && o.sdpFmtpLine === s.sdpFmtpLine)), ze = (n) => {
323
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, o = t === null ? [] : t.codecs;
324
+ return qe(s, o);
325
+ }, Qe = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
326
+ const o = e.indexOf(t.mimeType), r = e.indexOf(s.mimeType), c = o === -1 ? Number.MAX_VALUE : o, a = r === -1 ? Number.MAX_VALUE : r;
327
+ return c - a;
328
+ }), Je = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), P = (n, {
329
+ preferredMimeTypesVideoCodecs: e,
115
330
  excludeMimeTypesVideoCodecs: t
116
- }) => async (o) => {
331
+ }) => async (s) => {
117
332
  try {
118
- if (typeof o.setCodecPreferences == "function" && o.sender.track?.kind === "video" && (n !== void 0 && n.length > 0 || t !== void 0 && t.length > 0)) {
119
- const s = De("video"), r = Ie(s, t), i = Pe(r, n);
120
- o.setCodecPreferences(i);
333
+ if (typeof s.setCodecPreferences == "function" && s.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
334
+ const o = ze("video"), r = Je(o, t), c = Qe(r, e);
335
+ s.setCodecPreferences(c);
121
336
  }
122
- Object.keys(e).length > 0 && await z(o.sender, e);
123
- } catch (s) {
124
- c("updateTransceiver error", s);
337
+ Object.keys(n).length > 0 && await re(s.sender, n);
338
+ } catch (o) {
339
+ i("updateTransceiver error", o);
125
340
  }
126
- }, X = (e) => {
127
- if (!K(e) && !ae(e))
128
- throw e;
341
+ }, X = (n) => {
342
+ if (!de(n) && !le(n))
343
+ throw n;
129
344
  return { isSuccessful: !1 };
130
- }, xe = ({ kind: e, readyState: n }) => e === "video" && n === "live", Fe = /* @__PURE__ */ new Set([
345
+ }, Ze = ({ kind: n, readyState: e }) => n === "video" && e === "live", en = /* @__PURE__ */ new Set([
131
346
  "on",
132
347
  "once",
133
348
  "onceRace",
134
349
  "wait",
135
350
  "off",
351
+ "onSession",
352
+ "onceSession",
353
+ "onceRaceSession",
354
+ "waitSession",
355
+ "offSession",
136
356
  "sendDTMF",
137
357
  "hangUp",
138
358
  "declineToIncomingCall",
@@ -144,7 +364,7 @@ const fe = (e) => e instanceof Object && ("originator" in e || "cause" in e), Tn
144
364
  "isConfigured",
145
365
  "isRegistered"
146
366
  ]);
147
- class vn {
367
+ class ln {
148
368
  // @ts-expect-error: proxy method
149
369
  on;
150
370
  // @ts-expect-error: proxy method
@@ -156,6 +376,16 @@ class vn {
156
376
  // @ts-expect-error: proxy method
157
377
  off;
158
378
  // @ts-expect-error: proxy method
379
+ onSession;
380
+ // @ts-expect-error: proxy method
381
+ onceSession;
382
+ // @ts-expect-error: proxy method
383
+ onceRaceSession;
384
+ // @ts-expect-error: proxy method
385
+ waitSession;
386
+ // @ts-expect-error: proxy method
387
+ offSession;
388
+ // @ts-expect-error: proxy method
159
389
  sendDTMF;
160
390
  // @ts-expect-error: proxy method
161
391
  hangUp;
@@ -178,73 +408,73 @@ class vn {
178
408
  sipConnector;
179
409
  preferredMimeTypesVideoCodecs;
180
410
  excludeMimeTypesVideoCodecs;
181
- constructor(n, {
411
+ constructor(e, {
182
412
  preferredMimeTypesVideoCodecs: t,
183
- excludeMimeTypesVideoCodecs: o
413
+ excludeMimeTypesVideoCodecs: s
184
414
  } = {}) {
185
- return this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = o, this.sipConnector = n, new Proxy(this, {
186
- get: (s, r, i) => {
187
- if (typeof r == "string" && Fe.has(r) && r in this.sipConnector) {
415
+ return this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.sipConnector = e, new Proxy(this, {
416
+ get: (o, r, c) => {
417
+ if (typeof r == "string" && en.has(r) && r in this.sipConnector) {
188
418
  const u = Reflect.get(this.sipConnector, r, this.sipConnector);
189
419
  return typeof u == "function" ? u.bind(this.sipConnector) : u;
190
420
  }
191
- const a = Reflect.get(s, r, i);
192
- return typeof a == "function" ? a.bind(s) : a;
421
+ const a = Reflect.get(o, r, c);
422
+ return typeof a == "function" ? a.bind(o) : a;
193
423
  }
194
424
  });
195
425
  }
196
- connectToServer = async (n) => {
426
+ connectToServer = async (e) => {
197
427
  const {
198
428
  userAgent: t,
199
- sipWebSocketServerURL: o,
200
- sipServerUrl: s,
429
+ sipWebSocketServerURL: s,
430
+ sipServerUrl: o,
201
431
  remoteAddress: r,
202
- displayName: i,
432
+ displayName: c,
203
433
  name: a,
204
434
  password: u,
205
435
  isRegisteredUser: l,
206
- isDisconnectOnFail: h
207
- } = n;
208
- return c("connectToServer", n), this.sipConnector.connect({
436
+ isDisconnectOnFail: S
437
+ } = e;
438
+ return i("connectToServer", e), this.sipConnector.connect({
209
439
  userAgent: t,
210
- sipWebSocketServerURL: o,
211
- sipServerUrl: s,
440
+ sipWebSocketServerURL: s,
441
+ sipServerUrl: o,
212
442
  remoteAddress: r,
213
- displayName: i,
443
+ displayName: c,
214
444
  password: u,
215
445
  user: a,
216
446
  register: l
217
- }).then((f) => (c("connectToServer then"), { ua: f, isSuccessful: !0 })).catch(async (f) => (c("connectToServer catch: error", f), h === !0 ? this.sipConnector.disconnect().then(() => X(f)).catch(() => X(f)) : X(f)));
447
+ }).then((C) => (i("connectToServer then"), { ua: C, isSuccessful: !0 })).catch(async (C) => (i("connectToServer catch: error", C), S === !0 ? this.sipConnector.disconnect().then(() => X(C)).catch(() => X(C)) : X(C)));
218
448
  };
219
- callToServer = async (n) => {
449
+ callToServer = async (e) => {
220
450
  const {
221
451
  conference: t,
222
- mediaStream: o,
223
- extraHeaders: s,
452
+ mediaStream: s,
453
+ extraHeaders: o,
224
454
  iceServers: r,
225
- contentHint: i,
455
+ contentHint: c,
226
456
  simulcastEncodings: a,
227
457
  degradationPreference: u,
228
458
  sendEncodings: l,
229
- offerToReceiveAudio: h,
230
- offerToReceiveVideo: f,
231
- directionVideo: F,
232
- directionAudio: k,
233
- setRemoteStreams: g,
459
+ offerToReceiveAudio: S,
460
+ offerToReceiveVideo: C,
461
+ directionVideo: k,
462
+ directionAudio: F,
463
+ setRemoteStreams: f,
234
464
  onBeforeProgressCall: R,
235
- onSuccessProgressCall: C,
236
- onEnterPurgatory: S,
237
- onEnterConference: p,
238
- onFailProgressCall: E,
465
+ onSuccessProgressCall: m,
466
+ onEnterPurgatory: h,
467
+ onEnterConference: g,
468
+ onFailProgressCall: y,
239
469
  onFinishProgressCall: T,
240
- onEndedCall: v
241
- } = n, _ = this.resolveHandleReadyRemoteStreamsDebounced({
242
- onReadyRemoteStreams: g
243
- }), A = this.resolveHandleReadyRemoteStreams({
470
+ onEndedCall: E
471
+ } = e, v = this.resolveHandleReadyRemoteStreamsDebounced({
472
+ onReadyRemoteStreams: f
473
+ }), _ = this.resolveHandleReadyRemoteStreams({
244
474
  onReadyRemoteStreams: () => {
245
- _().catch(I);
475
+ v().catch(I);
246
476
  }
247
- }), O = P(
477
+ }), A = P(
248
478
  {
249
479
  degradationPreference: u
250
480
  },
@@ -253,67 +483,67 @@ class vn {
253
483
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
254
484
  }
255
485
  );
256
- c("callToServer", n);
257
- const N = async () => (c("startCall"), this.sipConnector.call({
258
- mediaStream: o,
259
- extraHeaders: s,
486
+ i("callToServer", e);
487
+ const O = async () => (i("startCall"), this.sipConnector.call({
488
+ mediaStream: s,
489
+ extraHeaders: o,
260
490
  iceServers: r,
261
- contentHint: i,
262
- offerToReceiveAudio: h,
263
- offerToReceiveVideo: f,
264
- directionVideo: F,
265
- directionAudio: k,
266
- sendEncodings: D({
267
- mediaStream: o,
491
+ contentHint: c,
492
+ offerToReceiveAudio: S,
493
+ offerToReceiveVideo: C,
494
+ directionVideo: k,
495
+ directionAudio: F,
496
+ sendEncodings: B({
497
+ mediaStream: s,
268
498
  simulcastEncodings: a,
269
499
  sendEncodings: l
270
500
  }),
271
501
  number: t,
272
- onAddedTransceiver: O,
273
- ontrack: A
502
+ onAddedTransceiver: A,
503
+ ontrack: _
274
504
  }));
275
505
  let M = !1, b;
276
- const B = (c("subscribeEnterConference: onEnterConference", p), S ?? p ? this.sipConnector.on("api:enterRoom", ({ room: d }) => {
277
- c("enterRoom", { _room: d, isSuccessProgressCall: M }), b = d, x(b) ? S && S() : p && p({ isSuccessProgressCall: M });
506
+ const N = (i("subscribeEnterConference: onEnterConference", g), h ?? g ? this.sipConnector.onSession("enterRoom", ({ room: d }) => {
507
+ i("enterRoom", { _room: d, isSuccessProgressCall: M }), b = d, D(b) ? h && h() : g && g({ isSuccessProgressCall: M });
278
508
  }) : () => {
279
- }), L = (d) => (c("onSuccess"), M = !0, _().catch(I), C && C({ isPurgatory: x(b) }), this.sipConnector.onceRace(["call:ended", "call:failed"], () => {
280
- B(), v && v();
281
- }), d), H = (d) => {
282
- throw c("onFail"), E && E(), B(), d;
509
+ }), x = (d) => (i("onSuccess"), M = !0, v().catch(I), m && m({ isPurgatory: D(b) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
510
+ N(), E && E();
511
+ }), d), L = (d) => {
512
+ throw i("onFail"), y && y(), N(), d;
283
513
  }, $ = () => {
284
- c("onFinish"), T && T();
514
+ i("onFinish"), T && T();
285
515
  };
286
- return c("onBeforeProgressCall"), R && R(t), N().then(L).catch((d) => H(d)).finally($);
516
+ return i("onBeforeProgressCall"), R && R(t), O().then(x).catch((d) => L(d)).finally($);
287
517
  };
288
- disconnectFromServer = async () => this.sipConnector.disconnect().then(() => (c("disconnectFromServer: then"), { isSuccessful: !0 })).catch((n) => (c("disconnectFromServer: catch", n), { isSuccessful: !1 }));
289
- answerToIncomingCall = async (n) => {
518
+ disconnectFromServer = async () => this.sipConnector.disconnect().then(() => (i("disconnectFromServer: then"), { isSuccessful: !0 })).catch((e) => (i("disconnectFromServer: catch", e), { isSuccessful: !1 }));
519
+ answerIncomingCall = async (e) => {
290
520
  const {
291
521
  mediaStream: t,
292
- extraHeaders: o,
293
- iceServers: s,
522
+ extraHeaders: s,
523
+ iceServers: o,
294
524
  contentHint: r,
295
- simulcastEncodings: i,
525
+ simulcastEncodings: c,
296
526
  degradationPreference: a,
297
527
  sendEncodings: u,
298
528
  offerToReceiveAudio: l,
299
- offerToReceiveVideo: h,
300
- directionVideo: f,
301
- directionAudio: F,
302
- setRemoteStreams: k,
303
- onBeforeProgressCall: g,
529
+ offerToReceiveVideo: S,
530
+ directionVideo: C,
531
+ directionAudio: k,
532
+ setRemoteStreams: F,
533
+ onBeforeProgressCall: f,
304
534
  onSuccessProgressCall: R,
305
- onEnterPurgatory: C,
306
- onEnterConference: S,
307
- onFailProgressCall: p,
308
- onFinishProgressCall: E,
535
+ onEnterPurgatory: m,
536
+ onEnterConference: h,
537
+ onFailProgressCall: g,
538
+ onFinishProgressCall: y,
309
539
  onEndedCall: T
310
- } = n, v = this.resolveHandleReadyRemoteStreamsDebounced({
311
- onReadyRemoteStreams: k
312
- }), _ = this.resolveHandleReadyRemoteStreams({
540
+ } = e, E = this.resolveHandleReadyRemoteStreamsDebounced({
541
+ onReadyRemoteStreams: F
542
+ }), v = this.resolveHandleReadyRemoteStreams({
313
543
  onReadyRemoteStreams: () => {
314
- v().catch(I);
544
+ E().catch(I);
315
545
  }
316
- }), A = P(
546
+ }), _ = P(
317
547
  {
318
548
  degradationPreference: a
319
549
  },
@@ -322,137 +552,139 @@ class vn {
322
552
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
323
553
  }
324
554
  );
325
- c("answerToIncomingCall", n);
326
- const O = async () => this.sipConnector.answerToIncomingCall({
555
+ i("answerIncomingCall", e);
556
+ const A = async () => this.sipConnector.answerToIncomingCall({
327
557
  mediaStream: t,
328
- extraHeaders: o,
329
- iceServers: s,
558
+ extraHeaders: s,
559
+ iceServers: o,
330
560
  contentHint: r,
331
561
  offerToReceiveAudio: l,
332
- offerToReceiveVideo: h,
333
- directionVideo: f,
334
- directionAudio: F,
335
- sendEncodings: D({
562
+ offerToReceiveVideo: S,
563
+ directionVideo: C,
564
+ directionAudio: k,
565
+ sendEncodings: B({
336
566
  mediaStream: t,
337
- simulcastEncodings: i,
567
+ simulcastEncodings: c,
338
568
  sendEncodings: u
339
569
  }),
340
- onAddedTransceiver: A,
341
- ontrack: _
342
- }), N = () => {
570
+ onAddedTransceiver: _,
571
+ ontrack: v
572
+ }), O = () => {
343
573
  const { remoteCallerData: d } = this.sipConnector;
344
574
  return d.incomingNumber;
345
575
  };
346
576
  let M = !1, b;
347
- const B = (c("subscribeEnterConference: onEnterConference", S), C ?? S ? this.sipConnector.on("api:enterRoom", (d) => {
348
- c("enterRoom", { _room: d, isSuccessProgressCall: M }), b = d, x(b) ? C && C() : S && S({ isSuccessProgressCall: M });
577
+ const N = (i("subscribeEnterConference: onEnterConference", h), m ?? h ? this.sipConnector.onSession("enterRoom", (d) => {
578
+ i("enterRoom", { _room: d, isSuccessProgressCall: M }), b = d, D(b) ? m && m() : h && h({ isSuccessProgressCall: M });
349
579
  }) : () => {
350
- }), L = (d) => (c("onSuccess"), M = !0, v().catch(I), R && R({ isPurgatory: x(b) }), this.sipConnector.onceRace(["call:ended", "call:failed"], () => {
351
- B(), T && T();
352
- }), d), H = (d) => {
353
- throw c("onFail"), p && p(), B(), d;
580
+ }), x = (d) => (i("onSuccess"), M = !0, E().catch(I), R && R({ isPurgatory: D(b) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
581
+ N(), T && T();
582
+ }), d), L = (d) => {
583
+ throw i("onFail"), g && g(), N(), d;
354
584
  }, $ = () => {
355
- c("onFinish"), E && E();
585
+ i("onFinish"), y && y();
356
586
  };
357
- if (c("onBeforeProgressCall"), g) {
358
- const d = N();
359
- g(d);
587
+ if (i("onBeforeProgressCall"), f) {
588
+ const d = O();
589
+ f(d);
360
590
  }
361
- return O().then(L).catch((d) => H(d)).finally($);
591
+ return A().then(x).catch((d) => L(d)).finally($);
362
592
  };
363
593
  updatePresentation = async ({
364
- mediaStream: n,
594
+ mediaStream: e,
365
595
  isP2P: t,
366
- maxBitrate: o,
367
- contentHint: s,
596
+ maxBitrate: s,
597
+ contentHint: o,
368
598
  simulcastEncodings: r,
369
- degradationPreference: i,
599
+ degradationPreference: c,
370
600
  sendEncodings: a,
371
601
  preferredMimeTypesVideoCodecs: u,
372
602
  excludeMimeTypesVideoCodecs: l
373
603
  }) => {
374
- const h = P(
604
+ const S = P(
375
605
  {
376
- degradationPreference: i
606
+ degradationPreference: c
377
607
  },
378
608
  {
379
609
  preferredMimeTypesVideoCodecs: u,
380
610
  excludeMimeTypesVideoCodecs: l
381
611
  }
382
612
  );
383
- return c("updatePresentation"), this.sipConnector.updatePresentation(n, {
613
+ return i("updatePresentation"), this.sipConnector.updatePresentation(e, {
384
614
  isP2P: t,
385
- maxBitrate: o,
386
- contentHint: s,
387
- sendEncodings: D({
388
- mediaStream: n,
615
+ maxBitrate: s,
616
+ contentHint: o,
617
+ sendEncodings: B({
618
+ mediaStream: e,
389
619
  simulcastEncodings: r,
390
620
  sendEncodings: a
391
621
  }),
392
- onAddedTransceiver: h
622
+ onAddedTransceiver: S
393
623
  });
394
624
  };
395
625
  startPresentation = async ({
396
- mediaStream: n,
626
+ mediaStream: e,
397
627
  isP2P: t,
398
- maxBitrate: o,
399
- contentHint: s,
628
+ maxBitrate: s,
629
+ contentHint: o,
400
630
  simulcastEncodings: r,
401
- degradationPreference: i,
631
+ degradationPreference: c,
402
632
  sendEncodings: a,
403
633
  preferredMimeTypesVideoCodecs: u,
404
- excludeMimeTypesVideoCodecs: l,
405
- callLimit: h
406
- }) => {
407
- const f = P(
634
+ excludeMimeTypesVideoCodecs: l
635
+ }, S) => {
636
+ const C = P(
408
637
  {
409
- degradationPreference: i
638
+ degradationPreference: c
410
639
  },
411
640
  {
412
641
  preferredMimeTypesVideoCodecs: u,
413
642
  excludeMimeTypesVideoCodecs: l
414
643
  }
415
644
  );
416
- return c("startPresentation"), this.sipConnector.startPresentation(n, {
417
- isP2P: t,
418
- maxBitrate: o,
419
- contentHint: s,
420
- callLimit: h,
421
- sendEncodings: D({
422
- mediaStream: n,
423
- simulcastEncodings: r,
424
- sendEncodings: a
425
- }),
426
- onAddedTransceiver: f
427
- });
645
+ return i("startPresentation"), this.sipConnector.startPresentation(
646
+ e,
647
+ {
648
+ isP2P: t,
649
+ maxBitrate: s,
650
+ contentHint: o,
651
+ sendEncodings: B({
652
+ mediaStream: e,
653
+ simulcastEncodings: r,
654
+ sendEncodings: a
655
+ }),
656
+ onAddedTransceiver: C
657
+ },
658
+ S
659
+ );
428
660
  };
429
- stopShareSipConnector = async ({ isP2P: n = !1 } = {}) => (c("stopShareSipConnector"), this.sipConnector.stopPresentation({
430
- isP2P: n
661
+ stopShareSipConnector = async ({ isP2P: e = !1 } = {}) => (i("stopShareSipConnector"), this.sipConnector.stopPresentation({
662
+ isP2P: e
431
663
  }).catch((t) => {
432
- c(t);
664
+ i(t);
433
665
  }));
434
666
  sendRefusalToTurnOnMic = async () => {
435
- c("sendRefusalToTurnOnMic"), await this.sipConnector.sendRefusalToTurnOnMic().catch((n) => {
436
- c("sendRefusalToTurnOnMic: error", n);
437
- });
667
+ this.sipConnector.isCallActive && (i("sendRefusalToTurnOnMic"), await this.sipConnector.sendRefusalToTurnOnMic().catch((e) => {
668
+ i("sendRefusalToTurnOnMic: error", e);
669
+ }));
438
670
  };
439
671
  sendRefusalToTurnOnCam = async () => {
440
- c("sendRefusalToTurnOnCam"), await this.sipConnector.sendRefusalToTurnOnCam().catch((n) => {
441
- c("sendRefusalToTurnOnCam: error", n);
442
- });
672
+ this.sipConnector.isCallActive && (i("sendRefusalToTurnOnCam"), await this.sipConnector.sendRefusalToTurnOnCam().catch((e) => {
673
+ i("sendRefusalToTurnOnCam: error", e);
674
+ }));
443
675
  };
444
676
  sendMediaState = async ({
445
- isEnabledCam: n,
677
+ isEnabledCam: e,
446
678
  isEnabledMic: t
447
679
  }) => {
448
- c("sendMediaState"), await this.sipConnector.sendMediaState({ cam: n, mic: t });
680
+ this.sipConnector.isCallActive && (i("sendMediaState"), await this.sipConnector.sendMediaState({ cam: e, mic: t }));
449
681
  };
450
- replaceMediaStream = async (n, {
682
+ replaceMediaStream = async (e, {
451
683
  deleteExisting: t,
452
- addMissing: o,
453
- forceRenegotiation: s,
684
+ addMissing: s,
685
+ forceRenegotiation: o,
454
686
  contentHint: r,
455
- simulcastEncodings: i,
687
+ simulcastEncodings: c,
456
688
  degradationPreference: a,
457
689
  sendEncodings: u
458
690
  } = {}) => {
@@ -465,341 +697,58 @@ class vn {
465
697
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
466
698
  }
467
699
  );
468
- return c("replaceMediaStream"), this.sipConnector.replaceMediaStream(n, {
700
+ return i("replaceMediaStream"), this.sipConnector.replaceMediaStream(e, {
469
701
  deleteExisting: t,
470
- addMissing: o,
471
- forceRenegotiation: s,
702
+ addMissing: s,
703
+ forceRenegotiation: o,
472
704
  contentHint: r,
473
- sendEncodings: D({
474
- mediaStream: n,
475
- simulcastEncodings: i,
705
+ sendEncodings: B({
706
+ mediaStream: e,
707
+ simulcastEncodings: c,
476
708
  sendEncodings: u
477
709
  }),
478
710
  onAddedTransceiver: l
479
711
  });
480
712
  };
481
713
  askPermissionToEnableCam = async () => {
482
- c("askPermissionToEnableCam"), await this.sipConnector.askPermissionToEnableCam();
714
+ this.sipConnector.isCallActive && (i("askPermissionToEnableCam"), await this.sipConnector.askPermissionToEnableCam());
483
715
  };
484
716
  resolveHandleReadyRemoteStreamsDebounced = ({
485
- onReadyRemoteStreams: n
486
- }) => ue(() => {
717
+ onReadyRemoteStreams: e
718
+ }) => Ce(() => {
487
719
  const t = this.sipConnector.getRemoteStreams();
488
- c("remoteStreams", t), t && n(t);
720
+ i("remoteStreams", t), t && e(t);
489
721
  }, 200);
490
722
  // eslint-disable-next-line class-methods-use-this
491
723
  resolveHandleReadyRemoteStreams = ({
492
- onReadyRemoteStreams: n
724
+ onReadyRemoteStreams: e
493
725
  }) => ({ track: t }) => {
494
- xe(t) && n();
726
+ Ze(t) && e();
495
727
  };
496
- getRemoteStreams = () => (c("getRemoteStreams"), this.sipConnector.getRemoteStreams());
497
- onUseLicense = (n) => (c("onUseLicense"), this.sipConnector.on("api:useLicense", n));
498
- onMustStopPresentation = (n) => (c("onMustStopPresentation"), this.sipConnector.on("api:mustStopPresentation", n));
499
- onMoveToSpectators = (n) => (c("onMoveToSpectators"), this.sipConnector.on("api:participant:move-request-to-spectators", n));
500
- onMoveToParticipants = (n) => (c("onMoveToParticipants"), this.sipConnector.on("api:participant:move-request-to-participants", n));
728
+ getRemoteStreams = () => (i("getRemoteStreams"), this.sipConnector.getRemoteStreams());
729
+ onUseLicense = (e) => (i("onUseLicense"), this.sipConnector.onSession("useLicense", e));
730
+ onMustStopPresentation = (e) => (i("onMustStopPresentation"), this.sipConnector.onSession("mustStopPresentation", e));
731
+ onMoveToSpectators = (e) => (i("onMoveToSpectators"), this.sipConnector.onSession(ie, e));
732
+ onMoveToParticipants = (e) => (i("onMoveToParticipants"), this.sipConnector.onSession(ce, e));
501
733
  }
502
- const V = (e) => {
503
- const { url: n, cause: t } = e;
504
- let o = n;
505
- return (t === y.BAD_MEDIA_DESCRIPTION || t === y.NOT_FOUND) && (o = `${e.message.to.uri.user}@${e.message.to.uri.host}`), o;
506
- };
507
- var se = /* @__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))(se || {});
508
- const ke = new Error("Unknown error"), Ue = (e = ke) => {
509
- const { cause: n, socket: t } = e;
510
- let o = "CONNECT_SERVER_FAILED";
511
- switch (n) {
512
- case "Forbidden": {
513
- o = "WRONG_USER_OR_PASSWORD";
514
- break;
515
- }
516
- case y.BAD_MEDIA_DESCRIPTION: {
517
- o = "BAD_MEDIA_ERROR";
518
- break;
519
- }
520
- case y.NOT_FOUND: {
521
- o = "NOT_FOUND_ERROR";
522
- break;
523
- }
524
- default:
525
- t !== void 0 && t._ws?.readyState === 3 ? o = "WS_CONNECTION_FAILED" : V(e) !== void 0 && V(e) !== "" && (o = "CONNECT_SERVER_FAILED_BY_LINK");
526
- }
527
- return o;
528
- }, Ve = (e) => {
529
- let n = "";
530
- try {
531
- n = JSON.stringify(e);
532
- } catch (t) {
533
- c("failed to stringify message", t);
534
- }
535
- return n;
536
- }, Le = new Error("Unknown error"), He = (e = Le) => {
537
- const { code: n, cause: t, message: o } = e, s = V(e), r = { code: "", cause: "", message: "" };
538
- return typeof o == "object" && o !== null ? r.message = Ve(o) : o && (r.message = String(o)), s !== void 0 && s !== "" && (r.link = s), n !== void 0 && n !== "" && (r.code = n), t !== void 0 && t !== "" && (r.cause = t), r;
539
- }, $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
540
- __proto__: null,
541
- EErrorTypes: se,
542
- getLinkError: V,
543
- getTypeFromError: Ue,
544
- getValuesFromError: He
545
- }, Symbol.toStringTag, { value: "Module" })), Je = ({
546
- sessionId: e,
547
- remoteAddress: n,
548
- isMutedAudio: t,
549
- isMutedVideo: o,
550
- isRegistered: s,
551
- isPresentationCall: r
552
- }) => {
553
- const i = [], a = t ? "0" : "1", u = o ? "0" : "1";
554
- return i.push(`X-Vinteo-Mic-State: ${a}`, `X-Vinteo-MainCam-State: ${u}`), (s === !1 || s === void 0) && i.push("X-Vinteo-Purgatory-Call: yes"), e !== void 0 && e !== "" && i.push(`X-Vinteo-Session: ${e}`), r === !0 && i.push("X-Vinteo-Presentation-Call: yes"), n !== void 0 && n !== "" && i.push(`X-Vinteo-Remote: ${n}`), i;
555
- }, Xe = "[@*!|]", We = "_", je = (e) => {
556
- let n = e;
557
- return n = n.replaceAll(new RegExp(Xe, "g"), We), n;
558
- }, Ge = ({
559
- appName: e,
560
- appVersion: n,
561
- browserName: t,
562
- browserVersion: o
563
- }) => {
564
- const r = `${je(e)} ${n}`;
565
- return `ChromeNew - ${t === void 0 ? r : `${t} ${o}, ${r}`}`;
566
- }, Ke = ({
567
- isUnifiedSdpSemantic: e,
568
- appVersion: n,
569
- browserName: t,
570
- browserVersion: o,
571
- appName: s
572
- }) => e ? Ge({ appVersion: n, browserName: t, browserVersion: o, appName: s }) : "Chrome", Ye = (e) => (n) => [...n].map((o) => async () => e(o)), qe = async ({
573
- accumulatedKeys: e,
574
- sendKey: n,
575
- canRunTask: t
576
- }) => {
577
- const s = Ye(n)(e);
578
- return de(s, t);
579
- }, ze = (e) => (t) => (c("onStartMainCam"), e.on("api:admin-start-main-cam", t)), Qe = (e) => (t) => (c("onStartMic"), e.on("api:admin-start-mic", t)), Ze = (e) => (t) => (c("onStopMainCam"), e.on("api:admin-stop-main-cam", t)), en = (e) => (t) => (c("onStopMic"), e.on("api:admin-stop-mic", t)), nn = ({ sipConnector: e }) => {
580
- const n = (g, R) => ({ isSyncForced: C }) => {
581
- if (C === !0) {
582
- g();
583
- return;
584
- }
585
- R();
586
- }, t = ze(e), o = Ze(e), s = Qe(e), r = en(e);
587
- let i, a, u, l;
588
- const h = ({
589
- onStartMainCamForced: g,
590
- onStartMainCamNotForced: R,
591
- onStopMainCamForced: C,
592
- onStopMainCamNotForced: S,
593
- onStartMicForced: p,
594
- onStartMicNotForced: E,
595
- onStopMicForced: T,
596
- onStopMicNotForced: v
597
- }) => {
598
- const _ = n(
599
- g,
600
- R
601
- );
602
- i = t(_);
603
- const A = n(
604
- C,
605
- S
606
- );
607
- a = o(A);
608
- const O = n(p, E);
609
- u = s(O);
610
- const N = n(T, v);
611
- l = r(N);
612
- }, f = () => {
613
- i?.(), a?.(), u?.(), l?.();
614
- };
615
- return {
616
- start: (g) => {
617
- h(g);
618
- },
619
- stop: () => {
620
- f();
621
- }
622
- };
623
- }, Mn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
624
- __proto__: null,
625
- PURGATORY_CONFERENCE_NUMBER: oe,
626
- createSyncMediaState: nn,
627
- error: $e,
628
- getExtraHeaders: Je,
629
- getUserAgent: Ke,
630
- hasPurgatory: x,
631
- sendDtmfAccumulated: qe
632
- }, Symbol.toStringTag, { value: "Module" }));
633
- var tn = /* @__PURE__ */ ((e) => (e.VP8 = "video/VP8", e.VP9 = "video/VP9", e.H264 = "video/H264", e.AV1 = "video/AV1", e.rtx = "video/rtx", e.red = "video/red", e.flexfec03 = "video/flexfec-03", e))(tn || {});
634
- const on = (e) => [...e.keys()].map((n) => e.get(n)), sn = (e, n) => on(e).find((t) => t?.type === n), rn = async (e) => e.getStats().then((n) => sn(n, "codec")?.mimeType), cn = (e) => e.find((n) => n.track?.kind === "video"), an = async (e, n, t) => {
635
- const { isChanged: o, parameters: s } = await z(e, {
636
- encodings: [
637
- {
638
- scaleResolutionDownBy: n.scaleResolutionDownBy,
639
- maxBitrate: n.maxBitrate
640
- }
641
- ]
642
- });
643
- return o && t && t(s), { isChanged: o, parameters: s };
644
- }, re = le(), un = async () => re().catch((e) => {
645
- c("videoSendingBalancer: error", e);
646
- }), dn = async (e) => (re.add(e), un()), W = async ({
647
- sender: e,
648
- scaleResolutionDownBy: n,
649
- maxBitrate: t,
650
- onSetParameters: o
651
- }) => dn(async () => an(e, { scaleResolutionDownBy: n, maxBitrate: t }, o)), ln = async ({ sender: e, codec: n }, t) => {
652
- const s = Be(n);
653
- return W({
654
- sender: e,
655
- maxBitrate: s,
656
- onSetParameters: t,
657
- scaleResolutionDownBy: 200
658
- });
659
- }, U = async ({
660
- sender: e,
661
- videoTrack: n,
662
- codec: t
663
- }, o) => {
664
- const i = n.getSettings().width, a = ne(i ?? 0, t);
665
- return W({
666
- sender: e,
667
- maxBitrate: a,
668
- onSetParameters: o,
669
- scaleResolutionDownBy: 1
670
- });
671
- }, fn = async ({
672
- sender: e,
673
- videoTrack: n,
674
- resolution: t,
675
- codec: o
676
- }, s) => {
677
- const [r, i] = t.split("x"), { maxBitrate: a, scaleResolutionDownBy: u } = te({
678
- videoTrack: n,
679
- codec: o,
680
- targetSize: {
681
- width: Number(r),
682
- height: Number(i)
683
- }
684
- });
685
- return W({
686
- sender: e,
687
- maxBitrate: a,
688
- onSetParameters: s,
689
- scaleResolutionDownBy: u
690
- });
691
- }, hn = async ({
692
- mainCam: e,
693
- resolutionMainCam: n,
694
- sender: t,
695
- videoTrack: o,
696
- codec: s
697
- }, r) => {
698
- switch (e) {
699
- case w.PAUSE_MAIN_CAM:
700
- return ln({ sender: t, codec: s }, r);
701
- case w.RESUME_MAIN_CAM:
702
- return U({ sender: t, videoTrack: o, codec: s }, r);
703
- case w.MAX_MAIN_CAM_RESOLUTION:
704
- return n !== void 0 ? fn(
705
- { sender: t, videoTrack: o, codec: s, resolution: n },
706
- r
707
- ) : U({ sender: t, videoTrack: o, codec: s }, r);
708
- case w.ADMIN_STOP_MAIN_CAM:
709
- case w.ADMIN_START_MAIN_CAM:
710
- case void 0:
711
- return U({ sender: t, videoTrack: o, codec: s }, r);
712
- default:
713
- return U({ sender: t, videoTrack: o, codec: s }, r);
714
- }
715
- }, j = {
716
- isChanged: !1,
717
- parameters: {
718
- encodings: [{}],
719
- transactionId: "0",
720
- codecs: [],
721
- headerExtensions: [],
722
- rtcp: {}
723
- }
724
- }, G = async ({
725
- mainCam: e,
726
- resolutionMainCam: n,
727
- connection: t,
728
- onSetParameters: o,
729
- ignoreForCodec: s
730
- }) => {
731
- const r = t.getSenders(), i = cn(r);
732
- if (!i?.track)
733
- return j;
734
- const a = await rn(i);
735
- return Z(a, s) ? j : hn(
736
- {
737
- mainCam: e,
738
- resolutionMainCam: n,
739
- sender: i,
740
- codec: a,
741
- videoTrack: i.track
742
- },
743
- o
744
- );
745
- }, bn = (e, {
746
- ignoreForCodec: n,
747
- onSetParameters: t
748
- } = {}) => {
749
- const o = async () => {
750
- const { connection: u } = e;
751
- if (!u)
752
- throw new Error("connection is not exist");
753
- return G({
754
- connection: u,
755
- onSetParameters: t,
756
- ignoreForCodec: n
757
- });
758
- };
759
- let s = o;
760
- const r = (u) => {
761
- s = async () => {
762
- const { mainCam: l, resolutionMainCam: h } = u, { connection: f } = e;
763
- if (!f)
764
- throw new Error("connection is not exist");
765
- return G({
766
- mainCam: l,
767
- resolutionMainCam: h,
768
- connection: f,
769
- onSetParameters: t,
770
- ignoreForCodec: n
771
- });
772
- }, s().catch(I);
773
- };
774
- return {
775
- subscribe: () => {
776
- e.on("api:main-cam-control", r);
777
- },
778
- unsubscribe: () => {
779
- e.off("api:main-cam-control", r);
780
- },
781
- balanceByTrack: o,
782
- resetMainCamControl() {
783
- s = o;
784
- },
785
- async reBalance() {
786
- return s();
787
- }
788
- };
789
- };
790
734
  export {
791
- y as ECallCause,
792
- tn as EMimeTypesVideoCodecs,
793
- On as EUseLicense,
794
- Nn as SipConnector,
795
- vn as SipConnectorFacade,
796
- In as debug,
797
- Bn as disableDebug,
798
- wn as enableDebug,
799
- rn as getCodecFromSender,
800
- Tn as hasCanceledCallError,
801
- Dn as hasCanceledStartPresentationError,
802
- bn as resolveVideoSendingBalancer,
803
- z as setParametersToSender,
804
- Mn as tools
735
+ w as EEventsMainCAM,
736
+ fn as EEventsMic,
737
+ mn as EEventsSyncMediaState,
738
+ hn as EMimeTypesVideoCodecs,
739
+ pn as EUseLicense,
740
+ Rn as SipConnector,
741
+ ln as SipConnectorFacade,
742
+ gn as causes,
743
+ yn as constants,
744
+ An as debug,
745
+ Tn as disableDebug,
746
+ En as enableDebug,
747
+ Mn as eventNames,
748
+ De as getCodecFromSender,
749
+ bn as hasCanceledCallError,
750
+ vn as hasCanceledStartPresentationError,
751
+ dn as resolveVideoSendingBalancer,
752
+ re as setParametersToSender,
753
+ un as tools
805
754
  };