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