sip-connector 14.1.2-1 → 14.1.2-2

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 (97) hide show
  1. package/dist/SipConnector-DGYQOyHy.cjs +1 -0
  2. package/dist/SipConnector-DTNc5BfW.js +1352 -0
  3. package/dist/doMock.cjs +1 -1
  4. package/dist/doMock.js +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +85 -86
  7. package/dist/src/SipConnector.d.ts +235 -0
  8. package/dist/{SipConnectorFacade → src/SipConnectorFacade}/SipConnectorFacade.d.ts +1 -1
  9. package/package.json +1 -1
  10. package/dist/SipConnector-CZwqeStw.cjs +0 -1
  11. package/dist/SipConnector-DfaRIKWv.js +0 -1345
  12. package/dist/SipConnector.d.ts +0 -315
  13. package/dist/utils/utils.d.ts +0 -4
  14. /package/dist/{SipConnectorFacade → src/SipConnectorFacade}/index.d.ts +0 -0
  15. /package/dist/{__fixtures__ → src/__fixtures__}/BaseSession.mock.d.ts +0 -0
  16. /package/dist/{__fixtures__ → src/__fixtures__}/RTCPeerConnectionMock.d.ts +0 -0
  17. /package/dist/{__fixtures__ → src/__fixtures__}/RTCRtpSenderMock.d.ts +0 -0
  18. /package/dist/{__fixtures__ → src/__fixtures__}/RTCSessionMock.d.ts +0 -0
  19. /package/dist/{__fixtures__ → src/__fixtures__}/Registrator.mock.d.ts +0 -0
  20. /package/dist/{__fixtures__ → src/__fixtures__}/Request.mock.d.ts +0 -0
  21. /package/dist/{__fixtures__ → src/__fixtures__}/UA.mock.d.ts +0 -0
  22. /package/dist/{__fixtures__ → src/__fixtures__}/WebSocketInterface.mock.d.ts +0 -0
  23. /package/dist/{__fixtures__ → src/__fixtures__}/accountNotify.d.ts +0 -0
  24. /package/dist/{__fixtures__ → src/__fixtures__}/channels.d.ts +0 -0
  25. /package/dist/{__fixtures__ → src/__fixtures__}/channelsNotify.d.ts +0 -0
  26. /package/dist/{__fixtures__ → src/__fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
  27. /package/dist/{__fixtures__ → src/__fixtures__}/delayPromise.d.ts +0 -0
  28. /package/dist/{__fixtures__ → src/__fixtures__}/enterRoom.d.ts +0 -0
  29. /package/dist/{__fixtures__ → src/__fixtures__}/index.d.ts +0 -0
  30. /package/dist/{__fixtures__ → src/__fixtures__}/jssip.mock.d.ts +0 -0
  31. /package/dist/{__fixtures__ → src/__fixtures__}/mediaState.d.ts +0 -0
  32. /package/dist/{__fixtures__ → src/__fixtures__}/participantMoveRequests.d.ts +0 -0
  33. /package/dist/{__fixtures__ → src/__fixtures__}/participantNotify.d.ts +0 -0
  34. /package/dist/{__fixtures__ → src/__fixtures__}/remoteCallerData.d.ts +0 -0
  35. /package/dist/{__fixtures__ → src/__fixtures__}/utils.d.ts +0 -0
  36. /package/dist/{__fixtures__ → src/__fixtures__}/webcastNotify.d.ts +0 -0
  37. /package/dist/{causes.d.ts → src/causes.d.ts} +0 -0
  38. /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
  39. /package/dist/{doMock.d.ts → src/doMock.d.ts} +0 -0
  40. /package/dist/{eventNames.d.ts → src/eventNames.d.ts} +0 -0
  41. /package/dist/{getExtraHeadersRemoteAddress.d.ts → src/getExtraHeadersRemoteAddress.d.ts} +0 -0
  42. /package/dist/{headers.d.ts → src/headers.d.ts} +0 -0
  43. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  44. /package/dist/{logger.d.ts → src/logger.d.ts} +0 -0
  45. /package/dist/{setParametersToSender → src/setParametersToSender}/configureDegradationPreference.d.ts +0 -0
  46. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
  47. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEncodings.d.ts +0 -0
  48. /package/dist/{setParametersToSender → src/setParametersToSender}/configureMaxBitrate.d.ts +0 -0
  49. /package/dist/{setParametersToSender → src/setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
  50. /package/dist/{setParametersToSender → src/setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
  51. /package/dist/{setParametersToSender → src/setParametersToSender}/index.d.ts +0 -0
  52. /package/dist/{setParametersToSender → src/setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
  53. /package/dist/{setParametersToSender → src/setParametersToSender}/setParametersToSender.d.ts +0 -0
  54. /package/dist/{tools → src/tools}/__fixtures__/call.d.ts +0 -0
  55. /package/dist/{tools → src/tools}/__fixtures__/connectToServer.d.ts +0 -0
  56. /package/dist/{tools → src/tools}/__fixtures__/hasValidUri.d.ts +0 -0
  57. /package/dist/{tools → src/tools}/__fixtures__/permissions.d.ts +0 -0
  58. /package/dist/{tools → src/tools}/__fixtures__/processRequest.d.ts +0 -0
  59. /package/dist/{tools → src/tools}/__tests-utils__/parseObject.d.ts +0 -0
  60. /package/dist/{tools → src/tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
  61. /package/dist/{tools → src/tools}/error/getLinkError.d.ts +0 -0
  62. /package/dist/{tools → src/tools}/error/getTypeFromError.d.ts +0 -0
  63. /package/dist/{tools → src/tools}/error/getValuesFromError.d.ts +0 -0
  64. /package/dist/{tools → src/tools}/error/index.d.ts +0 -0
  65. /package/dist/{tools → src/tools}/error/stringifyMessage.d.ts +0 -0
  66. /package/dist/{tools → src/tools}/generateSimulcastEncodings.d.ts +0 -0
  67. /package/dist/{tools → src/tools}/getExtraHeaders.d.ts +0 -0
  68. /package/dist/{tools → src/tools}/getUserAgent.d.ts +0 -0
  69. /package/dist/{tools → src/tools}/hasPurgatory.d.ts +0 -0
  70. /package/dist/{tools → src/tools}/index.d.ts +0 -0
  71. /package/dist/{tools → src/tools}/prepareMediaStream.d.ts +0 -0
  72. /package/dist/{tools → src/tools}/resolveUpdateTransceiver.d.ts +0 -0
  73. /package/dist/{tools → src/tools}/sendDTMFAccumulated.d.ts +0 -0
  74. /package/dist/{tools → src/tools}/setVideoTrackContentHints.d.ts +0 -0
  75. /package/dist/{tools → src/tools}/syncMediaState/index.d.ts +0 -0
  76. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMainCam.d.ts +0 -0
  77. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMic.d.ts +0 -0
  78. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMainCam.d.ts +0 -0
  79. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMic.d.ts +0 -0
  80. /package/dist/{types.d.ts → src/types.d.ts} +0 -0
  81. /package/dist/{utils → src/utils}/errors.d.ts +0 -0
  82. /package/dist/{utils → src/utils}/findSenderByStream.d.ts +0 -0
  83. /package/dist/{utils → src/utils}/findVideoSender.d.ts +0 -0
  84. /package/dist/{utils → src/utils}/findVideoTrack.d.ts +0 -0
  85. /package/dist/{utils → src/utils}/getCodecFromSender.d.ts +0 -0
  86. /package/dist/{utils → src/utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
  87. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/balance.d.ts +0 -0
  88. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidth.d.ts +0 -0
  89. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +0 -0
  90. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
  91. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasIncludesString.d.ts +0 -0
  92. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/index.d.ts +0 -0
  93. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/processSender.d.ts +0 -0
  94. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrate.d.ts +0 -0
  95. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
  96. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
  97. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
@@ -0,0 +1,1352 @@
1
+ var _t = Object.defineProperty;
2
+ var At = (s, e, t) => e in s ? _t(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var r = (s, e, t) => At(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { isCanceledError as Rt } from "@krivega/cancelable-promise";
5
+ import pe from "events-constructor";
6
+ import { repeatedCallsAsync as ve, hasCanceledError as ft } from "repeated-calls";
7
+ import Y from "debug";
8
+ const It = "Connection Error", He = "Request Timeout", Pt = "SIP Failure Code", mt = "Internal Error", Ot = "Busy", We = "Rejected", Mt = "Redirected", Dt = "Unavailable", pt = "Not Found", vt = "Address Incomplete", yt = "Incompatible SDP", wt = "Missing SDP", bt = "Authentication Error", ke = "Terminated", Lt = "WebRTC Error", q = "Canceled", Ut = "No Answer", Ht = "Expires", Wt = "No ACK", kt = "Dialog Error", Bt = "User Denied Media Access", xt = "Bad Media Description", Ft = "RTP Timeout", ds = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
+ __proto__: null,
10
+ ADDRESS_INCOMPLETE: vt,
11
+ AUTHENTICATION_ERROR: bt,
12
+ BAD_MEDIA_DESCRIPTION: xt,
13
+ BUSY: Ot,
14
+ BYE: ke,
15
+ CANCELED: q,
16
+ CONNECTION_ERROR: It,
17
+ DIALOG_ERROR: kt,
18
+ EXPIRES: Ht,
19
+ INCOMPATIBLE_SDP: yt,
20
+ INTERNAL_ERROR: mt,
21
+ MISSING_SDP: wt,
22
+ NOT_FOUND: pt,
23
+ NO_ACK: Wt,
24
+ NO_ANSWER: Ut,
25
+ REDIRECTED: Mt,
26
+ REJECTED: We,
27
+ REQUEST_TIMEOUT: He,
28
+ RTP_TIMEOUT: Ft,
29
+ SIP_FAILURE_CODE: Pt,
30
+ UNAVAILABLE: Dt,
31
+ USER_DENIED_MEDIA_ACCESS: Bt,
32
+ WEBRTC_ERROR: Lt
33
+ }, Symbol.toStringTag, { value: "Module" })), $ = "incomingCall", G = "declinedIncomingCall", J = "failedIncomingCall", X = "terminatedIncomingCall", W = "connecting", P = "connected", C = "disconnected", v = "newRTCSession", m = "registered", z = "unregistered", O = "registrationFailed", Be = "newMessage", Q = "sipEvent", j = "availableSecondRemoteStream", K = "notAvailableSecondRemoteStream", Z = "mustStopPresentation", y = "shareState", ee = "enterRoom", te = "useLicense", ne = "peerconnection:confirmed", se = "peerconnection:ontrack", w = "channels", ie = "channels:notify", oe = "ended:fromserver", re = "main-cam-control", ae = "admin-stop-main-cam", ce = "admin-start-main-cam", Ee = "admin-stop-mic", de = "admin-start-mic", b = "admin-force-sync-media-state", he = "participant:added-to-list-moderators", Se = "participant:removed-from-list-moderators", Te = "participant:move-request-to-stream", le = "participant:move-request-to-spectators", ue = "participant:move-request-to-participants", ge = "participation:accepting-word-request", Ce = "participation:cancelling-word-request", Ne = "webcast:started", _e = "webcast:stopped", Ae = "account:changed", Re = "account:deleted", fe = "conference:participant-token-issued", M = "ended", xe = "sending", Fe = "reinvite", Ve = "replaces", Ye = "refer", qe = "progress", $e = "accepted", L = "confirmed", U = "peerconnection", A = "failed", Ge = "muted", Je = "unmuted", Ie = "newDTMF", Pe = "newInfo", Xe = "hold", ze = "unhold", Qe = "update", je = "sdp", Ke = "icecandidate", Ze = "getusermediafailed", et = "peerconnection:createofferfailed", tt = "peerconnection:createanswerfailed", nt = "peerconnection:setlocaldescriptionfailed", st = "peerconnection:setremotedescriptionfailed", it = "presentation:start", ot = "presentation:started", rt = "presentation:end", me = "presentation:ended", H = "presentation:failed", at = "SPECTATOR", ct = "PARTICIPANT", Et = 1e6;
34
+ var N = /* @__PURE__ */ ((s) => (s.LOCAL = "local", s.REMOTE = "remote", s.SYSTEM = "system", s))(N || {});
35
+ const hs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
36
+ __proto__: null,
37
+ ACCEPTED: $e,
38
+ ACCOUNT_CHANGED: Ae,
39
+ ACCOUNT_DELETED: Re,
40
+ ADMIN_FORCE_SYNC_MEDIA_STATE: b,
41
+ ADMIN_START_MAIN_CAM: ce,
42
+ ADMIN_START_MIC: de,
43
+ ADMIN_STOP_MAIN_CAM: ae,
44
+ ADMIN_STOP_MIC: Ee,
45
+ AVAILABLE_SECOND_REMOTE_STREAM_EVENT: j,
46
+ CHANNELS: w,
47
+ CHANNELS_NOTIFY: ie,
48
+ CONFERENCE_PARTICIPANT_TOKEN_ISSUED: fe,
49
+ CONFIRMED: L,
50
+ CONNECTED: P,
51
+ CONNECTING: W,
52
+ DECLINED_INCOMING_CALL: G,
53
+ DISCONNECTED: C,
54
+ ENDED: M,
55
+ ENDED_FROM_SERVER: oe,
56
+ ENTER_ROOM: ee,
57
+ FAILED: A,
58
+ FAILED_INCOMING_CALL: J,
59
+ GET_USER_MEDIA_FAILED: Ze,
60
+ HOLD: Xe,
61
+ ICE_CANDIDATE: Ke,
62
+ INCOMING_CALL: $,
63
+ MAIN_CAM_CONTROL: re,
64
+ MUST_STOP_PRESENTATION_EVENT: Z,
65
+ MUTED: Ge,
66
+ NEW_DTMF: Ie,
67
+ NEW_INFO: Pe,
68
+ NEW_MESSAGE: Be,
69
+ NEW_RTC_SESSION: v,
70
+ NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT: K,
71
+ ONE_MEGABIT_IN_BITS: Et,
72
+ Originator: N,
73
+ PARTICIPANT: ct,
74
+ PARTICIPANT_ADDED_TO_LIST_MODERATORS: he,
75
+ PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS: ue,
76
+ PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS: le,
77
+ PARTICIPANT_MOVE_REQUEST_TO_STREAM: Te,
78
+ PARTICIPANT_REMOVED_FROM_LIST_MODERATORS: Se,
79
+ PARTICIPATION_ACCEPTING_WORD_REQUEST: ge,
80
+ PARTICIPATION_CANCELLING_WORD_REQUEST: Ce,
81
+ PEER_CONNECTION: U,
82
+ PEER_CONNECTION_CONFIRMED: ne,
83
+ PEER_CONNECTION_CREATE_ANSWER_FAILED: tt,
84
+ PEER_CONNECTION_CREATE_OFFER_FAILED: et,
85
+ PEER_CONNECTION_ONTRACK: se,
86
+ PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED: nt,
87
+ PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED: st,
88
+ PRESENTATION_END: rt,
89
+ PRESENTATION_ENDED: me,
90
+ PRESENTATION_FAILED: H,
91
+ PRESENTATION_START: it,
92
+ PRESENTATION_STARTED: ot,
93
+ PROGRESS: qe,
94
+ REFER: Ye,
95
+ REGISTERED: m,
96
+ REGISTRATION_FAILED: O,
97
+ REINVITE: Fe,
98
+ REPLACES: Ve,
99
+ SDP: je,
100
+ SENDING: xe,
101
+ SHARE_STATE: y,
102
+ SIP_EVENT: Q,
103
+ SPECTATOR: at,
104
+ TERMINATED_INCOMING_CALL: X,
105
+ UNHOLD: ze,
106
+ UNMUTED: Je,
107
+ UNREGISTERED: z,
108
+ UPDATE: Qe,
109
+ USE_LICENSE: te,
110
+ WEBCAST_STARTED: Ne,
111
+ WEBCAST_STOPPED: _e
112
+ }, Symbol.toStringTag, { value: "Module" })), dt = [
113
+ $,
114
+ G,
115
+ X,
116
+ J,
117
+ ge,
118
+ Ce,
119
+ Te,
120
+ ie,
121
+ fe,
122
+ Ae,
123
+ Re,
124
+ Ne,
125
+ _e,
126
+ he,
127
+ Se
128
+ ], Oe = [
129
+ W,
130
+ P,
131
+ C,
132
+ v,
133
+ m,
134
+ z,
135
+ O,
136
+ Be,
137
+ Q
138
+ ], ht = [
139
+ j,
140
+ K,
141
+ Z,
142
+ y,
143
+ ee,
144
+ te,
145
+ ne,
146
+ se,
147
+ w,
148
+ oe,
149
+ re,
150
+ ce,
151
+ ae,
152
+ Ee,
153
+ de,
154
+ b,
155
+ le,
156
+ ue
157
+ ], Me = [
158
+ M,
159
+ W,
160
+ xe,
161
+ Fe,
162
+ Ve,
163
+ Ye,
164
+ qe,
165
+ $e,
166
+ L,
167
+ U,
168
+ A,
169
+ Ge,
170
+ Je,
171
+ Ie,
172
+ Pe,
173
+ Xe,
174
+ ze,
175
+ Qe,
176
+ je,
177
+ Ke,
178
+ Ze,
179
+ et,
180
+ tt,
181
+ nt,
182
+ st,
183
+ it,
184
+ ot,
185
+ rt,
186
+ me,
187
+ H
188
+ ], St = [...Oe, ...dt], Tt = [
189
+ ...Me,
190
+ ...ht
191
+ ], Ss = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
192
+ __proto__: null,
193
+ SESSION_EVENT_NAMES: Tt,
194
+ SESSION_JSSIP_EVENT_NAMES: Me,
195
+ SESSION_SYNTHETICS_EVENT_NAMES: ht,
196
+ UA_EVENT_NAMES: St,
197
+ UA_JSSIP_EVENT_NAMES: Oe,
198
+ UA_SYNTHETICS_EVENT_NAMES: dt
199
+ }, Symbol.toStringTag, { value: "Module" })), De = "sip-connector", x = Y(De), Ts = () => {
200
+ Y.enable(De);
201
+ }, ls = () => {
202
+ Y.enable(`-${De}`);
203
+ }, Vt = (s, e) => (s.degradationPreference = e.degradationPreference, s), Yt = (s, e) => {
204
+ s.encodings === void 0 && (s.encodings = []);
205
+ for (let t = s.encodings.length; t < e; t += 1)
206
+ s.encodings.push({});
207
+ return s;
208
+ }, lt = (s) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== s, qt = lt(), $t = (s, e) => {
209
+ if (qt(s, e))
210
+ return s;
211
+ }, Gt = (s, e) => {
212
+ const t = s.maxBitrate, n = $t(e, t);
213
+ return n !== void 0 && (s.maxBitrate = n), s;
214
+ }, ut = 1, Jt = lt(
215
+ ut
216
+ ), Xt = (s, e) => {
217
+ const t = s === void 0 ? void 0 : Math.max(s, ut);
218
+ if (t !== void 0 && Jt(
219
+ t,
220
+ e
221
+ ))
222
+ return t;
223
+ }, zt = (s, e) => {
224
+ const t = s.scaleResolutionDownBy, n = Xt(
225
+ e,
226
+ t
227
+ );
228
+ return n !== void 0 && (s.scaleResolutionDownBy = n), s;
229
+ }, Qt = (s, e) => {
230
+ var n;
231
+ const t = ((n = e.encodings) == null ? void 0 : n.length) ?? 0;
232
+ return Yt(s, t), s.encodings.forEach((i, o) => {
233
+ const a = ((e == null ? void 0 : e.encodings) ?? [])[o], c = a == null ? void 0 : a.maxBitrate, E = a == null ? void 0 : a.scaleResolutionDownBy;
234
+ Gt(i, c), zt(i, E);
235
+ }), s;
236
+ }, jt = (s, e) => {
237
+ var t, n, i, o, a, c, E, d, T, l, S, u;
238
+ if (((t = s.codecs) == null ? void 0 : t.length) !== ((n = e.codecs) == null ? void 0 : n.length))
239
+ return !0;
240
+ for (let h = 0; h < (((i = s.codecs) == null ? void 0 : i.length) ?? 0); h++)
241
+ if (JSON.stringify(s.codecs[h]) !== JSON.stringify(e.codecs[h]))
242
+ return !0;
243
+ if (((o = s.headerExtensions) == null ? void 0 : o.length) !== ((a = e.headerExtensions) == null ? void 0 : a.length))
244
+ return !0;
245
+ for (let h = 0; h < (((c = s.headerExtensions) == null ? void 0 : c.length) ?? 0); h++)
246
+ if (JSON.stringify(s.headerExtensions[h]) !== JSON.stringify(e.headerExtensions[h]))
247
+ return !0;
248
+ if (((E = s.encodings) == null ? void 0 : E.length) !== ((d = e.encodings) == null ? void 0 : d.length))
249
+ return !0;
250
+ for (let h = 0; h < (s.encodings.length ?? 0); h++)
251
+ if (JSON.stringify(s.encodings[h]) !== JSON.stringify(e.encodings[h]))
252
+ return !0;
253
+ return ((T = s.rtcp) == null ? void 0 : T.cname) !== ((l = e.rtcp) == null ? void 0 : l.cname) || ((S = s.rtcp) == null ? void 0 : S.reducedSize) !== ((u = e.rtcp) == null ? void 0 : u.reducedSize) || s.degradationPreference !== e.degradationPreference;
254
+ }, Kt = async (s, e) => {
255
+ const t = s.getParameters(), n = JSON.parse(
256
+ JSON.stringify(t)
257
+ );
258
+ Qt(t, e), Vt(t, e);
259
+ const i = jt(n, t);
260
+ return i && await s.setParameters(t), { parameters: t, isChanged: i };
261
+ };
262
+ var I = /* @__PURE__ */ ((s) => (s.PAUSE_MAIN_CAM = "PAUSEMAINCAM", s.RESUME_MAIN_CAM = "RESUMEMAINCAM", s.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", s.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", s.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", s))(I || {}), F = /* @__PURE__ */ ((s) => (s.ADMIN_STOP_MIC = "ADMINSTOPMIC", s.ADMIN_START_MIC = "ADMINSTARTMIC", s))(F || {}), V = /* @__PURE__ */ ((s) => (s.ADMIN_SYNC_FORCED = "1", s.ADMIN_SYNC_NOT_FORCED = "0", s))(V || {}), Zt = /* @__PURE__ */ ((s) => (s.AUDIO = "AUDIO", s.VIDEO = "VIDEO", s.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", s))(Zt || {}), en = /* @__PURE__ */ ((s) => (s.VP8 = "video/VP8", s.VP9 = "video/VP9", s.H264 = "video/H264", s.AV1 = "video/AV1", s.rtx = "video/rtx", s.red = "video/red", s.flexfec03 = "video/flexfec-03", s))(en || {});
263
+ const tn = async (s, e, t) => {
264
+ const { isChanged: n, parameters: i } = await Kt(s, {
265
+ encodings: [
266
+ {
267
+ scaleResolutionDownBy: e.scaleResolutionDownBy,
268
+ maxBitrate: e.maxBitrate
269
+ }
270
+ ]
271
+ });
272
+ return n && t && t(i), { isChanged: n, parameters: i };
273
+ };
274
+ function nn(s) {
275
+ return (e) => `sip:${e}@${s}`;
276
+ }
277
+ const sn = (s, e) => () => Math.floor(Math.random() * (e - s)) + s, ye = (s) => s.trim().replaceAll(" ", "_"), on = sn(1e5, 99999999), rn = (s) => s.some((t) => {
278
+ const { kind: n } = t;
279
+ return n === "video";
280
+ }), an = (s) => {
281
+ const e = [];
282
+ return s !== void 0 && s !== "" && e.push(`X-Vinteo-Remote: ${s}`), e;
283
+ }, cn = "content-type", En = "x-webrtc-enter-room", D = "application/vinteo.webrtc.sharedesktop", dn = "application/vinteo.webrtc.roomname", hn = "application/vinteo.webrtc.channels", Sn = "application/vinteo.webrtc.mediastate", Tn = "application/vinteo.webrtc.refusal", we = "application/vinteo.webrtc.maincam", ln = "application/vinteo.webrtc.mic", un = "application/vinteo.webrtc.uselic", gn = "X-WEBRTC-USE-LICENSE", Cn = "X-WEBRTC-PARTICIPANT-NAME", be = "X-WEBRTC-INPUT-CHANNELS", Le = "X-WEBRTC-OUTPUT-CHANNELS", Nn = "X-WEBRTC-MAINCAM", _n = "X-WEBRTC-MIC", Ue = "X-WEBRTC-SYNC", An = "X-WEBRTC-MAINCAM-RESOLUTION", Rn = "X-WEBRTC-MEDIA-STATE", fn = "X-Vinteo-Media-Type", In = "X-Vinteo-MainCam-State", Pn = "X-Vinteo-Mic-State", mn = "application/vinteo.webrtc.partstate", On = "X-WEBRTC-PARTSTATE", Mn = "application/vinteo.webrtc.notify", Dn = "X-VINTEO-NOTIFY", R = "x-webrtc-share-state", pn = `${R}: LETMESTARTPRESENTATION`, vn = `${R}: STOPPRESENTATION`, gt = "YOUCANRECEIVECONTENT", Ct = "CONTENTEND", Nt = "YOUMUSTSTOPSENDCONTENT", yn = `${R}: ${Nt}`, wn = `${R}: ${gt}`, bn = `${R}: ${Ct}`, Ln = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", Un = `${Ln}: LETMESTARTMAINCAM`, Hn = (s, e) => {
284
+ s.getVideoTracks().forEach((n) => {
285
+ "contentHint" in n && n.contentHint !== e && (n.contentHint = e);
286
+ });
287
+ }, p = (s, {
288
+ directionVideo: e,
289
+ directionAudio: t,
290
+ contentHint: n
291
+ } = {}) => {
292
+ if (!s || e === "recvonly" && t === "recvonly")
293
+ return;
294
+ const i = t === "recvonly" ? [] : s.getAudioTracks(), o = e === "recvonly" ? [] : s.getVideoTracks(), a = [...i, ...o], c = new MediaStream(a);
295
+ return c.getTracks = () => [...c.getAudioTracks(), ...c.getVideoTracks()], n && n !== "none" && Hn(c, n), c;
296
+ }, Wn = "Error decline with 603", kn = 1006, Bn = (s) => typeof s == "object" && s !== null && "code" in s && s.code === kn, xn = (s) => s.message === Wn, Fn = (s, e) => s.find((t) => t.track && e.getTracks().includes(t.track)), Vn = async (s, e, t) => {
297
+ const n = Fn(s, e);
298
+ if (n)
299
+ return tn(n, { maxBitrate: t });
300
+ }, Yn = 486, qn = 487, $n = 3, Gn = 1, Jn = (s) => s instanceof Object && ("originator" in s || "cause" in s), us = (s) => {
301
+ if (Rt(s))
302
+ return !0;
303
+ if (!Jn(s))
304
+ return !1;
305
+ const { originator: e, cause: t } = s;
306
+ return typeof t == "string" ? t === He || t === We || e === N.LOCAL && (t === q || t === ke) : !1;
307
+ }, gs = (s) => ft(s), Xn = "channels", zn = "WebcastStarted", Qn = "WebcastStopped", jn = "accountChanged", Kn = "accountDeleted", Zn = "addedToListModerators", es = "removedFromListModerators", ts = "ParticipationRequestAccepted", ns = "ParticipationRequestRejected", ss = "ParticipantMovedToWebcast", is = "ConferenceParticipantTokenIssued";
308
+ class Cs {
309
+ constructor({ JsSIP: e }) {
310
+ r(this, "promisePendingStartPresentation");
311
+ r(this, "promisePendingStopPresentation");
312
+ r(this, "ua");
313
+ r(this, "rtcSession");
314
+ r(this, "incomingRTCSession");
315
+ r(this, "streamPresentationCurrent");
316
+ r(this, "socket");
317
+ r(this, "isRegisterConfigInner", !1);
318
+ r(this, "connectionConfiguration", {});
319
+ r(this, "remoteStreams", {});
320
+ r(this, "JsSIP");
321
+ r(this, "sessionEvents");
322
+ r(this, "uaEvents");
323
+ r(this, "cancelableConnectWithRepeatedCalls");
324
+ r(this, "cancelableSendPresentationWithRepeatedCalls");
325
+ r(this, "isPendingConnect", !1);
326
+ r(this, "isPendingInitUa", !1);
327
+ r(this, "isPendingCall", !1);
328
+ r(this, "isPendingAnswer", !1);
329
+ r(this, "connect", async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t)));
330
+ r(this, "hangUp", async () => (this.cancelRequests(), this.hangUpWithoutCancelRequests()));
331
+ r(this, "tryRegister", async () => {
332
+ if (!this.isRegisterConfig)
333
+ throw new Error("Config is not registered");
334
+ this.uaEvents.trigger(W, void 0);
335
+ try {
336
+ await this.unregister();
337
+ } catch (e) {
338
+ x("tryRegister", e);
339
+ }
340
+ return this.register();
341
+ });
342
+ r(this, "declineToIncomingCall", async ({
343
+ statusCode: e = qn
344
+ } = {}) => new Promise((t, n) => {
345
+ try {
346
+ const i = this.getIncomingRTCSession(), o = this.remoteCallerData;
347
+ this.removeIncomingSession(), this.uaEvents.trigger(G, o), i.terminate({ status_code: e }), t();
348
+ } catch (i) {
349
+ n(i);
350
+ }
351
+ }));
352
+ r(this, "busyIncomingCall", async () => this.declineToIncomingCall({ statusCode: Yn }));
353
+ r(this, "set", async ({ displayName: e, password: t }) => new Promise((n, i) => {
354
+ const { ua: o } = this;
355
+ if (!o) {
356
+ i(new Error("this.ua is not initialized"));
357
+ return;
358
+ }
359
+ let a = !1, c = !1;
360
+ e !== void 0 && e !== this.connectionConfiguration.displayName && (a = o.set("display_name", ye(e)), this.connectionConfiguration.displayName = e), t !== void 0 && t !== this.connectionConfiguration.password && (c = o.set("password", t), this.connectionConfiguration.password = t);
361
+ const E = a || c;
362
+ c && this.isRegisterConfig ? this.register().then(() => {
363
+ n(E);
364
+ }).catch((d) => {
365
+ i(d);
366
+ }) : E ? n(E) : i(new Error("nothing changed"));
367
+ }));
368
+ r(this, "disconnect", async () => {
369
+ this.off(v, this.handleNewRTCSession);
370
+ const e = new Promise((n) => {
371
+ this.once(C, () => {
372
+ n();
373
+ });
374
+ }), { ua: t } = this;
375
+ return t ? (await this.hangUpWithoutCancelRequests(), t.stop()) : this.uaEvents.trigger(C, void 0), e.finally(() => {
376
+ delete this.ua;
377
+ });
378
+ });
379
+ r(this, "call", async ({
380
+ number: e,
381
+ mediaStream: t,
382
+ extraHeaders: n = [],
383
+ ontrack: i,
384
+ iceServers: o,
385
+ directionVideo: a,
386
+ directionAudio: c,
387
+ contentHint: E,
388
+ offerToReceiveAudio: d = !0,
389
+ offerToReceiveVideo: T = !0,
390
+ sendEncodings: l,
391
+ onAddedTransceiver: S
392
+ }) => (this.isPendingCall = !0, new Promise((u, h) => {
393
+ const { ua: g } = this;
394
+ if (!g) {
395
+ h(new Error("this.ua is not initialized"));
396
+ return;
397
+ }
398
+ this.connectionConfiguration.number = e, this.connectionConfiguration.answer = !1, this.handleCall({ ontrack: i }).then(u).catch((_) => {
399
+ h(_);
400
+ }), this.rtcSession = g.call(this.getSipServerUrl(e), {
401
+ extraHeaders: n,
402
+ mediaStream: p(t, {
403
+ directionVideo: a,
404
+ directionAudio: c,
405
+ contentHint: E
406
+ }),
407
+ eventHandlers: this.sessionEvents.triggers,
408
+ directionVideo: a,
409
+ directionAudio: c,
410
+ pcConfig: {
411
+ iceServers: o
412
+ },
413
+ rtcOfferConstraints: {
414
+ offerToReceiveAudio: d,
415
+ offerToReceiveVideo: T
416
+ },
417
+ sendEncodings: l,
418
+ onAddedTransceiver: S
419
+ });
420
+ }).finally(() => {
421
+ this.isPendingCall = !1;
422
+ })));
423
+ r(this, "answerToIncomingCall", async ({
424
+ mediaStream: e,
425
+ ontrack: t,
426
+ extraHeaders: n = [],
427
+ iceServers: i,
428
+ directionVideo: o,
429
+ directionAudio: a,
430
+ offerToReceiveAudio: c,
431
+ offerToReceiveVideo: E,
432
+ contentHint: d,
433
+ sendEncodings: T,
434
+ onAddedTransceiver: l
435
+ }) => (this.isPendingAnswer = !0, new Promise((S, u) => {
436
+ try {
437
+ const h = this.getIncomingRTCSession();
438
+ this.rtcSession = h, this.removeIncomingSession(), this.sessionEvents.eachTriggers((_, k) => {
439
+ const f = Me.find((B) => B === k);
440
+ f && h.on(f, _);
441
+ }), this.connectionConfiguration.answer = !0, this.connectionConfiguration.number = h.remote_identity.uri.user, this.handleCall({ ontrack: t }).then(S).catch((_) => {
442
+ u(_);
443
+ });
444
+ const g = p(e, {
445
+ directionVideo: o,
446
+ directionAudio: a,
447
+ contentHint: d
448
+ });
449
+ h.answer({
450
+ extraHeaders: n,
451
+ directionVideo: o,
452
+ directionAudio: a,
453
+ mediaStream: g,
454
+ pcConfig: {
455
+ iceServers: i
456
+ },
457
+ rtcOfferConstraints: {
458
+ offerToReceiveAudio: c,
459
+ offerToReceiveVideo: E
460
+ },
461
+ sendEncodings: T,
462
+ onAddedTransceiver: l
463
+ });
464
+ } catch (h) {
465
+ u(h);
466
+ }
467
+ }).finally(() => {
468
+ this.isPendingAnswer = !1;
469
+ })));
470
+ r(this, "sendDTMF", async (e) => new Promise((t, n) => {
471
+ const { rtcSession: i } = this;
472
+ if (!i) {
473
+ n(new Error("No rtcSession established"));
474
+ return;
475
+ }
476
+ this.onceSession(Ie, ({ originator: o }) => {
477
+ o === N.LOCAL && t();
478
+ }), i.sendDTMF(e, {
479
+ duration: 120,
480
+ interToneGap: 600
481
+ });
482
+ }));
483
+ r(this, "removeIncomingSession", () => {
484
+ delete this.incomingRTCSession;
485
+ });
486
+ // eslint-disable-next-line class-methods-use-this
487
+ r(this, "getSipServerUrl", (e) => e);
488
+ r(this, "connectWithDuplicatedCalls", async (e, { callLimit: t = $n } = {}) => {
489
+ const n = async () => this.connectInner(e), i = (o) => {
490
+ var d;
491
+ const c = ((d = this.ua) == null ? void 0 : d.isConnected()) === !0 && this.hasEqualConnectionConfiguration(e), E = o != null && !Bn(o);
492
+ return c || E;
493
+ };
494
+ return this.isPendingConnect = !0, this.cancelableConnectWithRepeatedCalls = ve({
495
+ targetFunction: n,
496
+ isComplete: i,
497
+ callLimit: t,
498
+ isRejectAsValid: !0,
499
+ isCheckBeforeCall: !1
500
+ }), this.cancelableConnectWithRepeatedCalls.then((o) => {
501
+ if (o instanceof this.JsSIP.UA)
502
+ return o;
503
+ throw o;
504
+ }).finally(() => {
505
+ this.isPendingConnect = !1;
506
+ });
507
+ });
508
+ r(this, "handleNewRTCSession", ({
509
+ originator: e,
510
+ session: t
511
+ }) => {
512
+ if (e === N.REMOTE) {
513
+ this.incomingRTCSession = t;
514
+ const n = this.remoteCallerData;
515
+ t.on(A, (i) => {
516
+ this.removeIncomingSession(), i.originator === N.LOCAL ? this.uaEvents.trigger(X, n) : this.uaEvents.trigger(J, n);
517
+ }), this.uaEvents.trigger($, n);
518
+ }
519
+ });
520
+ r(this, "connectInner", async (e) => this.initUa(e).then(async () => this.start()));
521
+ r(this, "initUa", async ({
522
+ user: e,
523
+ password: t,
524
+ sipServerUrl: n,
525
+ sipWebSocketServerURL: i,
526
+ remoteAddress: o,
527
+ sessionTimers: a,
528
+ registerExpires: c,
529
+ connectionRecoveryMinInterval: E,
530
+ connectionRecoveryMaxInterval: d,
531
+ userAgent: T,
532
+ displayName: l = "",
533
+ register: S = !1,
534
+ extraHeaders: u = []
535
+ }) => {
536
+ if (!n)
537
+ throw new Error("sipServerUrl is required");
538
+ if (!i)
539
+ throw new Error("sipWebSocketServerURL is required");
540
+ if (S && (e === void 0 || e === ""))
541
+ throw new Error("user is required for authorized connection");
542
+ if (S && (t === void 0 || t === ""))
543
+ throw new Error("password is required for authorized connection");
544
+ this.isPendingInitUa = !0;
545
+ try {
546
+ this.connectionConfiguration = {
547
+ sipServerUrl: n,
548
+ displayName: l,
549
+ register: S,
550
+ user: e,
551
+ password: t
552
+ };
553
+ const { configuration: h, helpers: g } = this.createUaConfiguration({
554
+ user: e,
555
+ sipServerUrl: n,
556
+ sipWebSocketServerURL: i,
557
+ password: t,
558
+ displayName: l,
559
+ register: S,
560
+ sessionTimers: a,
561
+ registerExpires: c,
562
+ connectionRecoveryMinInterval: E,
563
+ connectionRecoveryMaxInterval: d,
564
+ userAgent: T
565
+ });
566
+ return this.getSipServerUrl = g.getSipServerUrl, this.socket = g.socket, this.ua && await this.disconnect(), this.isRegisterConfigInner = !!S, this.ua = this.createUa({ ...h, remoteAddress: o, extraHeaders: u }), this.uaEvents.eachTriggers((_, k) => {
567
+ const f = Oe.find((B) => B === k);
568
+ f && this.ua && this.ua.on(f, _);
569
+ }), this.ua;
570
+ } finally {
571
+ this.isPendingInitUa = !1;
572
+ }
573
+ });
574
+ r(this, "createUa", ({
575
+ remoteAddress: e,
576
+ extraHeaders: t = [],
577
+ ...n
578
+ }) => {
579
+ const i = new this.JsSIP.UA(n), a = [...e !== void 0 && e !== "" ? an(e) : [], ...t];
580
+ return a.length > 0 && i.registrator().setExtraHeaders(a), i;
581
+ });
582
+ r(this, "start", async () => new Promise((e, t) => {
583
+ const { ua: n } = this;
584
+ if (!n) {
585
+ t(new Error("this.ua is not initialized"));
586
+ return;
587
+ }
588
+ const i = () => {
589
+ c(), e(n);
590
+ }, o = (E) => {
591
+ c(), t(E);
592
+ }, a = () => {
593
+ this.isRegisterConfig ? (this.on(m, i), this.on(O, o)) : this.on(P, i), this.on(C, o);
594
+ }, c = () => {
595
+ this.off(m, i), this.off(O, o), this.off(P, i), this.off(C, o);
596
+ };
597
+ a(), this.on(v, this.handleNewRTCSession), n.start();
598
+ }));
599
+ r(this, "handleCall", async ({
600
+ ontrack: e
601
+ }) => new Promise((t, n) => {
602
+ const i = () => {
603
+ this.onSession(U, T), this.onSession(L, l);
604
+ }, o = () => {
605
+ this.offSession(U, T), this.offSession(L, l);
606
+ }, a = () => {
607
+ this.onSession(A, E), this.onSession(M, E);
608
+ }, c = () => {
609
+ this.offSession(A, E), this.offSession(M, E);
610
+ }, E = (S) => {
611
+ o(), c(), n(S);
612
+ };
613
+ let d;
614
+ const T = ({ peerconnection: S }) => {
615
+ d = S, d.ontrack = (u) => {
616
+ this.sessionEvents.trigger(se, d), e && e(u);
617
+ };
618
+ }, l = () => {
619
+ d !== void 0 && this.sessionEvents.trigger(ne, d), o(), c(), t(d);
620
+ };
621
+ i(), a();
622
+ }));
623
+ r(this, "restoreSession", () => {
624
+ this.cancelRequestsAndResetPresentation(), delete this.connectionConfiguration.number, delete this.rtcSession, this.remoteStreams = {};
625
+ });
626
+ r(this, "hangUpWithoutCancelRequests", async () => {
627
+ if (this.ua && this.rtcSession) {
628
+ const { rtcSession: e } = this;
629
+ if (this.streamPresentationCurrent)
630
+ try {
631
+ await this.stopPresentation();
632
+ } catch (t) {
633
+ x("error stop presentation: ", t);
634
+ }
635
+ if (this.restoreSession(), !e.isEnded())
636
+ return e.terminateAsync({
637
+ cause: q
638
+ });
639
+ }
640
+ });
641
+ r(this, "handleShareState", (e) => {
642
+ switch (e) {
643
+ case gt: {
644
+ this.sessionEvents.trigger(j, void 0);
645
+ break;
646
+ }
647
+ case Ct: {
648
+ this.sessionEvents.trigger(K, void 0);
649
+ break;
650
+ }
651
+ case Nt: {
652
+ this.sessionEvents.trigger(Z, void 0);
653
+ break;
654
+ }
655
+ }
656
+ });
657
+ r(this, "maybeTriggerChannels", (e) => {
658
+ const t = e.getHeader(be), n = e.getHeader(Le);
659
+ if (t && n) {
660
+ const i = {
661
+ inputChannels: t,
662
+ outputChannels: n
663
+ };
664
+ this.sessionEvents.trigger(w, i);
665
+ }
666
+ });
667
+ r(this, "handleNotify", (e) => {
668
+ switch (e.cmd) {
669
+ case Xn: {
670
+ const t = e;
671
+ this.triggerChannelsNotify(t);
672
+ break;
673
+ }
674
+ case zn: {
675
+ const t = e;
676
+ this.triggerWebcastStartedNotify(t);
677
+ break;
678
+ }
679
+ case Qn: {
680
+ const t = e;
681
+ this.triggerWebcastStoppedNotify(t);
682
+ break;
683
+ }
684
+ case Zn: {
685
+ const t = e;
686
+ this.triggerAddedToListModeratorsNotify(t);
687
+ break;
688
+ }
689
+ case es: {
690
+ const t = e;
691
+ this.triggerRemovedFromListModeratorsNotify(t);
692
+ break;
693
+ }
694
+ case ts: {
695
+ const t = e;
696
+ this.triggerParticipationAcceptingWordRequest(t);
697
+ break;
698
+ }
699
+ case ns: {
700
+ const t = e;
701
+ this.triggerParticipationCancellingWordRequest(t);
702
+ break;
703
+ }
704
+ case ss: {
705
+ const t = e;
706
+ this.triggerParticipantMoveRequestToStream(t);
707
+ break;
708
+ }
709
+ case jn: {
710
+ this.triggerAccountChangedNotify();
711
+ break;
712
+ }
713
+ case Kn: {
714
+ this.triggerAccountDeletedNotify();
715
+ break;
716
+ }
717
+ case is: {
718
+ const t = e;
719
+ this.triggerConferenceParticipantTokenIssued(t);
720
+ break;
721
+ }
722
+ default:
723
+ x("unknown cmd", e.cmd);
724
+ }
725
+ });
726
+ r(this, "triggerRemovedFromListModeratorsNotify", ({
727
+ conference: e
728
+ }) => {
729
+ const t = {
730
+ conference: e
731
+ };
732
+ this.uaEvents.trigger(
733
+ Se,
734
+ t
735
+ );
736
+ });
737
+ r(this, "triggerAddedToListModeratorsNotify", ({
738
+ conference: e
739
+ }) => {
740
+ const t = {
741
+ conference: e
742
+ };
743
+ this.uaEvents.trigger(he, t);
744
+ });
745
+ r(this, "triggerWebcastStartedNotify", ({
746
+ body: { conference: e, type: t }
747
+ }) => {
748
+ const n = {
749
+ conference: e,
750
+ type: t
751
+ };
752
+ this.uaEvents.trigger(Ne, n);
753
+ });
754
+ r(this, "triggerWebcastStoppedNotify", ({
755
+ body: { conference: e, type: t }
756
+ }) => {
757
+ const n = {
758
+ conference: e,
759
+ type: t
760
+ };
761
+ this.uaEvents.trigger(_e, n);
762
+ });
763
+ r(this, "triggerAccountChangedNotify", () => {
764
+ this.uaEvents.trigger(Ae, void 0);
765
+ });
766
+ r(this, "triggerAccountDeletedNotify", () => {
767
+ this.uaEvents.trigger(Re, void 0);
768
+ });
769
+ r(this, "triggerConferenceParticipantTokenIssued", ({
770
+ body: { conference: e, participant: t, jwt: n }
771
+ }) => {
772
+ const i = {
773
+ conference: e,
774
+ participant: t,
775
+ jwt: n
776
+ };
777
+ this.uaEvents.trigger(
778
+ fe,
779
+ i
780
+ );
781
+ });
782
+ r(this, "triggerChannelsNotify", (e) => {
783
+ const t = e.input, n = e.output, i = {
784
+ inputChannels: t,
785
+ outputChannels: n
786
+ };
787
+ this.uaEvents.trigger(ie, i);
788
+ });
789
+ r(this, "triggerParticipationAcceptingWordRequest", ({
790
+ body: { conference: e }
791
+ }) => {
792
+ const t = {
793
+ conference: e
794
+ };
795
+ this.uaEvents.trigger(ge, t);
796
+ });
797
+ r(this, "triggerParticipationCancellingWordRequest", ({
798
+ body: { conference: e }
799
+ }) => {
800
+ const t = {
801
+ conference: e
802
+ };
803
+ this.uaEvents.trigger(Ce, t);
804
+ });
805
+ r(this, "triggerParticipantMoveRequestToStream", ({
806
+ body: { conference: e }
807
+ }) => {
808
+ const t = {
809
+ conference: e
810
+ };
811
+ this.uaEvents.trigger(Te, t);
812
+ });
813
+ r(this, "triggerEnterRoom", (e) => {
814
+ const t = e.getHeader(En), n = e.getHeader(Cn);
815
+ this.sessionEvents.trigger(ee, { room: t, participantName: n });
816
+ });
817
+ r(this, "triggerShareState", (e) => {
818
+ const t = e.getHeader(R);
819
+ this.sessionEvents.trigger(y, t);
820
+ });
821
+ r(this, "maybeTriggerParticipantMoveRequest", (e) => {
822
+ const t = e.getHeader(On);
823
+ t === at && this.sessionEvents.trigger(le, void 0), t === ct && this.sessionEvents.trigger(ue, void 0);
824
+ });
825
+ r(this, "triggerMainCamControl", (e) => {
826
+ const t = e.getHeader(Nn), n = e.getHeader(Ue), i = n === V.ADMIN_SYNC_FORCED;
827
+ if (t === I.ADMIN_START_MAIN_CAM) {
828
+ this.sessionEvents.trigger(ce, { isSyncForced: i });
829
+ return;
830
+ }
831
+ if (t === I.ADMIN_STOP_MAIN_CAM) {
832
+ this.sessionEvents.trigger(ae, { isSyncForced: i });
833
+ return;
834
+ }
835
+ (t === I.RESUME_MAIN_CAM || t === I.PAUSE_MAIN_CAM) && n !== void 0 && this.sessionEvents.trigger(b, { isSyncForced: i });
836
+ const o = e.getHeader(An);
837
+ this.sessionEvents.trigger(re, {
838
+ mainCam: t,
839
+ resolutionMainCam: o
840
+ });
841
+ });
842
+ r(this, "triggerMicControl", (e) => {
843
+ const t = e.getHeader(_n), i = e.getHeader(Ue) === V.ADMIN_SYNC_FORCED;
844
+ t === F.ADMIN_START_MIC ? this.sessionEvents.trigger(de, { isSyncForced: i }) : t === F.ADMIN_STOP_MIC && this.sessionEvents.trigger(Ee, { isSyncForced: i });
845
+ });
846
+ r(this, "triggerUseLicense", (e) => {
847
+ const t = e.getHeader(gn);
848
+ this.sessionEvents.trigger(te, t);
849
+ });
850
+ r(this, "handleNewInfo", (e) => {
851
+ const { originator: t } = e;
852
+ if (t !== N.REMOTE)
853
+ return;
854
+ const { request: n } = e, i = n.getHeader(cn);
855
+ if (i)
856
+ switch (i) {
857
+ case dn: {
858
+ this.triggerEnterRoom(n), this.maybeTriggerChannels(n);
859
+ break;
860
+ }
861
+ case Mn: {
862
+ this.maybeHandleNotify(n);
863
+ break;
864
+ }
865
+ case D: {
866
+ this.triggerShareState(n);
867
+ break;
868
+ }
869
+ case we: {
870
+ this.triggerMainCamControl(n);
871
+ break;
872
+ }
873
+ case ln: {
874
+ this.triggerMicControl(n);
875
+ break;
876
+ }
877
+ case un: {
878
+ this.triggerUseLicense(n);
879
+ break;
880
+ }
881
+ case mn: {
882
+ this.maybeTriggerParticipantMoveRequest(n);
883
+ break;
884
+ }
885
+ }
886
+ });
887
+ r(this, "handleSipEvent", ({ request: e }) => {
888
+ this.maybeHandleNotify(e);
889
+ });
890
+ r(this, "maybeHandleNotify", (e) => {
891
+ const t = e.getHeader(Dn);
892
+ if (t) {
893
+ const n = JSON.parse(t);
894
+ this.handleNotify(n);
895
+ }
896
+ });
897
+ r(this, "handleEnded", (e) => {
898
+ const { originator: t } = e;
899
+ t === N.REMOTE && this.sessionEvents.trigger(oe, e), this.restoreSession();
900
+ });
901
+ this.JsSIP = e, this.sessionEvents = new pe(Tt), this.uaEvents = new pe(St), this.onSession(y, this.handleShareState), this.onSession(Pe, this.handleNewInfo), this.on(Q, this.handleSipEvent), this.onSession(A, this.handleEnded), this.onSession(M, this.handleEnded);
902
+ }
903
+ get connection() {
904
+ var t;
905
+ return (t = this.rtcSession) == null ? void 0 : t.connection;
906
+ }
907
+ get remoteCallerData() {
908
+ var e, t, n;
909
+ return {
910
+ displayName: (e = this.incomingRTCSession) == null ? void 0 : e.remote_identity.display_name,
911
+ host: (t = this.incomingRTCSession) == null ? void 0 : t.remote_identity.uri.host,
912
+ incomingNumber: (n = this.incomingRTCSession) == null ? void 0 : n.remote_identity.uri.user,
913
+ rtcSession: this.incomingRTCSession
914
+ };
915
+ }
916
+ get requested() {
917
+ return this.isPendingInitUa || this.isPendingConnect || this.isPendingCall || this.isPendingAnswer;
918
+ }
919
+ get establishedRTCSession() {
920
+ var e;
921
+ return ((e = this.rtcSession) == null ? void 0 : e.isEstablished()) === !0 ? this.rtcSession : void 0;
922
+ }
923
+ get isRegistered() {
924
+ return !!this.ua && this.ua.isRegistered();
925
+ }
926
+ get isRegisterConfig() {
927
+ return !!this.ua && this.isRegisterConfigInner;
928
+ }
929
+ get isCallActive() {
930
+ return !!(this.ua && this.rtcSession);
931
+ }
932
+ get isAvailableIncomingCall() {
933
+ return !!this.incomingRTCSession;
934
+ }
935
+ get isPendingPresentation() {
936
+ return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
937
+ }
938
+ async register() {
939
+ return new Promise((e, t) => {
940
+ this.isRegisterConfig && this.ua ? (this.ua.on(m, e), this.ua.on(O, t), this.ua.register()) : t(new Error("Config is not registered"));
941
+ });
942
+ }
943
+ async unregister() {
944
+ return new Promise((e, t) => {
945
+ this.isRegistered && this.ua ? (this.ua.on(z, e), this.ua.unregister()) : t(new Error("ua is not registered"));
946
+ });
947
+ }
948
+ async sendOptions(e, t, n) {
949
+ if (!this.ua)
950
+ throw new Error("is not connected");
951
+ return new Promise((i, o) => {
952
+ try {
953
+ this.ua.sendOptions(e, t, {
954
+ extraHeaders: n,
955
+ eventHandlers: {
956
+ succeeded: () => {
957
+ i();
958
+ },
959
+ failed: o
960
+ }
961
+ });
962
+ } catch (a) {
963
+ o(a);
964
+ }
965
+ });
966
+ }
967
+ async ping(e, t) {
968
+ var i;
969
+ if (!((i = this.ua) != null && i.configuration.uri))
970
+ throw new Error("is not connected");
971
+ const n = this.ua.configuration.uri;
972
+ return this.sendOptions(n, e, t);
973
+ }
974
+ async checkTelephony({
975
+ userAgent: e,
976
+ displayName: t,
977
+ sipServerUrl: n,
978
+ sipWebSocketServerURL: i,
979
+ remoteAddress: o,
980
+ extraHeaders: a
981
+ }) {
982
+ return new Promise((c, E) => {
983
+ const { configuration: d } = this.createUaConfiguration({
984
+ sipWebSocketServerURL: i,
985
+ displayName: t,
986
+ userAgent: e,
987
+ sipServerUrl: n
988
+ }), T = this.createUa({ ...d, remoteAddress: o, extraHeaders: a }), l = () => {
989
+ const u = new Error("Telephony is not available");
990
+ E(u);
991
+ };
992
+ T.once(C, l);
993
+ const S = () => {
994
+ T.removeAllListeners(), T.once(C, c), T.stop();
995
+ };
996
+ T.once(P, S), T.start();
997
+ });
998
+ }
999
+ async replaceMediaStream(e, t) {
1000
+ if (!this.rtcSession)
1001
+ throw new Error("No rtcSession established");
1002
+ const { contentHint: n } = t ?? {}, i = p(e, { contentHint: n });
1003
+ if (i === void 0)
1004
+ throw new Error("No preparedMediaStream");
1005
+ return this.rtcSession.replaceMediaStream(i, t);
1006
+ }
1007
+ async askPermissionToEnableCam(e = {}) {
1008
+ if (!this.rtcSession)
1009
+ throw new Error("No rtcSession established");
1010
+ const t = [Un];
1011
+ return this.rtcSession.sendInfo(we, void 0, {
1012
+ noTerminateWhenError: !0,
1013
+ ...e,
1014
+ extraHeaders: t
1015
+ }).catch((n) => {
1016
+ if (xn(n))
1017
+ throw n;
1018
+ });
1019
+ }
1020
+ async startPresentation(e, {
1021
+ isNeedReinvite: t,
1022
+ isP2P: n,
1023
+ maxBitrate: i,
1024
+ contentHint: o,
1025
+ sendEncodings: a,
1026
+ onAddedTransceiver: c
1027
+ } = {}, E) {
1028
+ const d = this.establishedRTCSession;
1029
+ if (!d)
1030
+ throw new Error("No rtcSession established");
1031
+ if (this.streamPresentationCurrent)
1032
+ throw new Error("Presentation is already started");
1033
+ return n === !0 && await this.sendMustStopPresentation(), this.sendPresentationWithDuplicatedCalls({
1034
+ rtcSession: d,
1035
+ stream: e,
1036
+ presentationOptions: {
1037
+ isNeedReinvite: t,
1038
+ isP2P: n,
1039
+ maxBitrate: i,
1040
+ contentHint: o,
1041
+ sendEncodings: a,
1042
+ onAddedTransceiver: c
1043
+ },
1044
+ options: E
1045
+ });
1046
+ }
1047
+ async stopPresentation({
1048
+ isP2P: e = !1
1049
+ } = {}) {
1050
+ this.cancelSendPresentationWithRepeatedCalls();
1051
+ const t = this.streamPresentationCurrent;
1052
+ let n = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
1053
+ const i = e ? [bn] : [vn], o = this.establishedRTCSession;
1054
+ return o && t && (n = n.then(async () => o.sendInfo(D, void 0, {
1055
+ extraHeaders: i
1056
+ })).then(async () => o.stopPresentation(t)).catch((a) => {
1057
+ throw this.sessionEvents.trigger(H, a), a;
1058
+ })), !o && t && this.sessionEvents.trigger(me, t), this.promisePendingStopPresentation = n, n.finally(() => {
1059
+ this.resetPresentation();
1060
+ });
1061
+ }
1062
+ async updatePresentation(e, {
1063
+ isP2P: t,
1064
+ maxBitrate: n,
1065
+ contentHint: i,
1066
+ sendEncodings: o,
1067
+ onAddedTransceiver: a
1068
+ } = {}) {
1069
+ const c = this.establishedRTCSession;
1070
+ if (!c)
1071
+ throw new Error("No rtcSession established");
1072
+ if (!this.streamPresentationCurrent)
1073
+ throw new Error("Presentation has not started yet");
1074
+ return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(c, e, {
1075
+ isP2P: t,
1076
+ maxBitrate: n,
1077
+ contentHint: i,
1078
+ isNeedReinvite: !1,
1079
+ sendEncodings: o,
1080
+ onAddedTransceiver: a
1081
+ });
1082
+ }
1083
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1084
+ on(e, t) {
1085
+ return this.uaEvents.on(e, t);
1086
+ }
1087
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1088
+ once(e, t) {
1089
+ return this.uaEvents.once(e, t);
1090
+ }
1091
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1092
+ onceRace(e, t) {
1093
+ return this.uaEvents.onceRace(e, t);
1094
+ }
1095
+ async wait(e) {
1096
+ return this.uaEvents.wait(e);
1097
+ }
1098
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1099
+ off(e, t) {
1100
+ this.uaEvents.off(e, t);
1101
+ }
1102
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1103
+ onSession(e, t) {
1104
+ return this.sessionEvents.on(e, t);
1105
+ }
1106
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1107
+ onceSession(e, t) {
1108
+ return this.sessionEvents.once(e, t);
1109
+ }
1110
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1111
+ onceRaceSession(e, t) {
1112
+ return this.sessionEvents.onceRace(e, t);
1113
+ }
1114
+ async waitSession(e) {
1115
+ return this.sessionEvents.wait(e);
1116
+ }
1117
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1118
+ offSession(e, t) {
1119
+ this.sessionEvents.off(e, t);
1120
+ }
1121
+ isConfigured() {
1122
+ return !!this.ua;
1123
+ }
1124
+ getConnectionConfiguration() {
1125
+ return { ...this.connectionConfiguration };
1126
+ }
1127
+ getRemoteStreams() {
1128
+ if (!this.connection)
1129
+ return;
1130
+ const t = this.connection.getReceivers().map(({ track: n }) => n);
1131
+ return rn(t) ? this.generateStreams(t) : this.generateAudioStreams(t);
1132
+ }
1133
+ getIncomingRTCSession() {
1134
+ const { incomingRTCSession: e } = this;
1135
+ if (!e)
1136
+ throw new Error("No incomingRTCSession");
1137
+ return e;
1138
+ }
1139
+ cancelSendPresentationWithRepeatedCalls() {
1140
+ var e;
1141
+ (e = this.cancelableSendPresentationWithRepeatedCalls) == null || e.cancel();
1142
+ }
1143
+ async waitChannels() {
1144
+ return this.waitSession(w);
1145
+ }
1146
+ async waitSyncMediaState() {
1147
+ return this.waitSession(b);
1148
+ }
1149
+ async sendChannels({ inputChannels: e, outputChannels: t }) {
1150
+ if (!this.rtcSession)
1151
+ throw new Error("No rtcSession established");
1152
+ const n = `${be}: ${e}`, i = `${Le}: ${t}`, o = [
1153
+ n,
1154
+ i
1155
+ ];
1156
+ return this.rtcSession.sendInfo(hn, void 0, { extraHeaders: o });
1157
+ }
1158
+ async sendMediaState({ cam: e, mic: t }, n = {}) {
1159
+ if (!this.rtcSession)
1160
+ throw new Error("No rtcSession established");
1161
+ const i = `${Rn}: currentstate`, o = `${In}: ${Number(e)}`, a = `${Pn}: ${Number(t)}`, c = [
1162
+ i,
1163
+ o,
1164
+ a
1165
+ ];
1166
+ return this.rtcSession.sendInfo(Sn, void 0, {
1167
+ noTerminateWhenError: !0,
1168
+ ...n,
1169
+ extraHeaders: c
1170
+ });
1171
+ }
1172
+ async sendRefusalToTurnOn(e, t = {}) {
1173
+ if (!this.rtcSession)
1174
+ throw new Error("No rtcSession established");
1175
+ const c = [`${fn}: ${e === "mic" ? 0 : 1}`];
1176
+ return this.rtcSession.sendInfo(Tn, void 0, {
1177
+ noTerminateWhenError: !0,
1178
+ ...t,
1179
+ extraHeaders: c
1180
+ });
1181
+ }
1182
+ async sendRefusalToTurnOnMic(e = {}) {
1183
+ if (!this.rtcSession)
1184
+ throw new Error("No rtcSession established");
1185
+ return this.sendRefusalToTurnOn("mic", { noTerminateWhenError: !0, ...e });
1186
+ }
1187
+ async sendRefusalToTurnOnCam(e = {}) {
1188
+ if (!this.rtcSession)
1189
+ throw new Error("No rtcSession established");
1190
+ return this.sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
1191
+ }
1192
+ async sendMustStopPresentation() {
1193
+ const e = this.establishedRTCSession;
1194
+ if (!e)
1195
+ throw new Error("No rtcSession established");
1196
+ await e.sendInfo(D, void 0, {
1197
+ extraHeaders: [yn]
1198
+ });
1199
+ }
1200
+ async sendPresentationWithDuplicatedCalls({
1201
+ rtcSession: e,
1202
+ stream: t,
1203
+ presentationOptions: n,
1204
+ options: i = {
1205
+ callLimit: Gn
1206
+ }
1207
+ }) {
1208
+ const o = async () => this.sendPresentation(e, t, n), a = () => !!this.streamPresentationCurrent;
1209
+ return this.cancelableSendPresentationWithRepeatedCalls = ve({
1210
+ targetFunction: o,
1211
+ isComplete: a,
1212
+ isRejectAsValid: !0,
1213
+ ...i
1214
+ }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
1215
+ }
1216
+ hasEqualConnectionConfiguration(e) {
1217
+ var i;
1218
+ const { configuration: t } = this.createUaConfiguration(e), n = (i = this.ua) == null ? void 0 : i.configuration;
1219
+ return (n == null ? void 0 : n.password) === t.password && (n == null ? void 0 : n.register) === t.register && n.uri.toString() === t.uri && n.display_name === t.display_name && n.user_agent === t.user_agent && n.sockets === t.sockets && n.session_timers === t.session_timers && n.register_expires === t.register_expires && n.connection_recovery_min_interval === t.connection_recovery_min_interval && n.connection_recovery_max_interval === t.connection_recovery_max_interval;
1220
+ }
1221
+ createUaConfiguration({
1222
+ user: e,
1223
+ password: t,
1224
+ sipWebSocketServerURL: n,
1225
+ displayName: i = "",
1226
+ sipServerUrl: o,
1227
+ register: a = !1,
1228
+ sessionTimers: c = !1,
1229
+ registerExpires: E = 60 * 5,
1230
+ // 5 minutes in sec
1231
+ connectionRecoveryMinInterval: d = 2,
1232
+ connectionRecoveryMaxInterval: T = 6,
1233
+ userAgent: l
1234
+ }) {
1235
+ if (a && (t === void 0 || t === ""))
1236
+ throw new Error("password is required for authorized connection");
1237
+ const S = a && e !== void 0 && e.trim() !== "" ? e.trim() : `${on()}`, u = nn(o), h = u(S), g = new this.JsSIP.WebSocketInterface(n);
1238
+ return {
1239
+ configuration: {
1240
+ password: t,
1241
+ register: a,
1242
+ uri: h,
1243
+ display_name: ye(i),
1244
+ user_agent: l,
1245
+ sdp_semantics: "unified-plan",
1246
+ sockets: [g],
1247
+ session_timers: c,
1248
+ register_expires: E,
1249
+ connection_recovery_min_interval: d,
1250
+ connection_recovery_max_interval: T
1251
+ },
1252
+ helpers: {
1253
+ socket: g,
1254
+ getSipServerUrl: u
1255
+ }
1256
+ };
1257
+ }
1258
+ async sendPresentation(e, t, {
1259
+ maxBitrate: n = Et,
1260
+ isNeedReinvite: i = !0,
1261
+ isP2P: o = !1,
1262
+ contentHint: a = "detail",
1263
+ sendEncodings: c,
1264
+ onAddedTransceiver: E
1265
+ }) {
1266
+ const d = p(t, { contentHint: a });
1267
+ if (d === void 0)
1268
+ throw new Error("No streamPresentationCurrent");
1269
+ this.streamPresentationCurrent = d;
1270
+ const T = o ? [wn] : [pn], l = e.sendInfo(D, void 0, {
1271
+ extraHeaders: T
1272
+ }).then(async () => e.startPresentation(d, i, {
1273
+ sendEncodings: c,
1274
+ onAddedTransceiver: E
1275
+ })).then(async () => {
1276
+ const { connection: S } = this;
1277
+ if (!S)
1278
+ return;
1279
+ const u = S.getSenders();
1280
+ await Vn(u, t, n);
1281
+ }).then(() => t).catch((S) => {
1282
+ throw this.removeStreamPresentationCurrent(), this.sessionEvents.trigger(H, S), S;
1283
+ });
1284
+ return this.promisePendingStartPresentation = l, l.finally(() => {
1285
+ this.promisePendingStartPresentation = void 0;
1286
+ });
1287
+ }
1288
+ removeStreamPresentationCurrent() {
1289
+ delete this.streamPresentationCurrent;
1290
+ }
1291
+ resetPresentation() {
1292
+ this.removeStreamPresentationCurrent(), this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
1293
+ }
1294
+ cancelRequestsAndResetPresentation() {
1295
+ this.cancelSendPresentationWithRepeatedCalls(), this.resetPresentation();
1296
+ }
1297
+ generateStream(e, t) {
1298
+ const { id: n } = e, i = this.remoteStreams[n] ?? new MediaStream();
1299
+ return t && i.addTrack(t), i.addTrack(e), this.remoteStreams[n] = i, i;
1300
+ }
1301
+ generateAudioStream(e) {
1302
+ const { id: t } = e, n = this.remoteStreams[t] ?? new MediaStream();
1303
+ return n.addTrack(e), this.remoteStreams[t] = n, n;
1304
+ }
1305
+ generateStreams(e) {
1306
+ const t = [];
1307
+ return e.forEach((n, i) => {
1308
+ if (n.kind === "audio")
1309
+ return;
1310
+ const o = n, a = e[i - 1];
1311
+ let c;
1312
+ (a == null ? void 0 : a.kind) === "audio" && (c = a);
1313
+ const E = this.generateStream(o, c);
1314
+ t.push(E);
1315
+ }), t;
1316
+ }
1317
+ generateAudioStreams(e) {
1318
+ return e.map((n) => this.generateAudioStream(n));
1319
+ }
1320
+ cancelRequests() {
1321
+ this.cancelConnectWithRepeatedCalls();
1322
+ }
1323
+ cancelConnectWithRepeatedCalls() {
1324
+ var e;
1325
+ (e = this.cancelableConnectWithRepeatedCalls) == null || e.cancel();
1326
+ }
1327
+ }
1328
+ export {
1329
+ xt as B,
1330
+ I as E,
1331
+ pt as N,
1332
+ le as P,
1333
+ We as R,
1334
+ Cs as S,
1335
+ Oe as U,
1336
+ Kt as a,
1337
+ ue as b,
1338
+ ds as c,
1339
+ hs as d,
1340
+ Ss as e,
1341
+ ls as f,
1342
+ Ts as g,
1343
+ us as h,
1344
+ gs as i,
1345
+ F as j,
1346
+ V as k,
1347
+ x as l,
1348
+ Zt as m,
1349
+ en as n,
1350
+ Tt as o,
1351
+ tn as s
1352
+ };