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