sip-connector 14.0.1-0 → 14.1.0

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