sip-connector 14.1.2-7 → 15.0.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 (131) hide show
  1. package/dist/@SipConnector-CZo7A8_q.cjs +1 -0
  2. package/dist/@SipConnector-DbvV1Leg.js +2247 -0
  3. package/dist/ApiManager/@ApiManager.d.ts +59 -0
  4. package/dist/ApiManager/constants.d.ts +71 -0
  5. package/dist/ApiManager/eventNames.d.ts +33 -0
  6. package/dist/ApiManager/index.d.ts +3 -0
  7. package/dist/ApiManager/types.d.ts +99 -0
  8. package/dist/CallManager/@CallManager.d.ts +26 -0
  9. package/dist/CallManager/AbstractCallStrategy.d.ts +47 -0
  10. package/dist/CallManager/MCUCallStrategy.d.ts +30 -0
  11. package/dist/CallManager/RemoteStreamsManager.d.ts +8 -0
  12. package/dist/CallManager/causes.d.ts +13 -0
  13. package/dist/CallManager/eventNames.d.ts +45 -0
  14. package/dist/CallManager/hasCanceledCallError.d.ts +2 -0
  15. package/dist/CallManager/index.d.ts +7 -0
  16. package/dist/CallManager/types.d.ts +59 -0
  17. package/dist/ConnectionManager/@ConnectionManager.d.ts +48 -0
  18. package/dist/ConnectionManager/ConfigurationManager.d.ts +60 -0
  19. package/dist/ConnectionManager/ConnectionFlow.d.ts +84 -0
  20. package/dist/ConnectionManager/ConnectionStateMachine.d.ts +61 -0
  21. package/dist/ConnectionManager/RegistrationManager.d.ts +17 -0
  22. package/dist/ConnectionManager/SipOperations.d.ts +32 -0
  23. package/dist/ConnectionManager/UAFactory.d.ts +50 -0
  24. package/dist/ConnectionManager/eventNames.d.ts +16 -0
  25. package/dist/ConnectionManager/index.d.ts +3 -0
  26. package/dist/IncomingCallManager/@IncomingCallManager.d.ts +37 -0
  27. package/dist/IncomingCallManager/eventNames.d.ts +13 -0
  28. package/dist/IncomingCallManager/index.d.ts +2 -0
  29. package/dist/PresentationManager/@PresentationManager.d.ts +47 -0
  30. package/dist/PresentationManager/constants.d.ts +1 -0
  31. package/dist/PresentationManager/eventNames.d.ts +11 -0
  32. package/dist/PresentationManager/index.d.ts +2 -0
  33. package/dist/PresentationManager/types.d.ts +2 -0
  34. package/dist/SipConnector/@SipConnector.d.ts +96 -0
  35. package/dist/SipConnector/eventNames.d.ts +4 -0
  36. package/dist/SipConnector/index.d.ts +2 -0
  37. package/dist/{src/SipConnectorFacade → SipConnectorFacade}/SipConnectorFacade.d.ts +7 -16
  38. package/dist/{src/__fixtures__ → __fixtures__}/BaseSession.mock.d.ts +9 -9
  39. package/dist/{src/__fixtures__ → __fixtures__}/RTCPeerConnectionMock.d.ts +6 -0
  40. package/dist/{src/__fixtures__ → __fixtures__}/RTCSessionMock.d.ts +13 -8
  41. package/dist/{src/__fixtures__ → __fixtures__}/UA.mock.d.ts +13 -15
  42. package/dist/{src → __fixtures__}/eventNames.d.ts +1 -1
  43. package/dist/{src/__fixtures__ → __fixtures__}/index.d.ts +4 -4
  44. package/dist/{src/__fixtures__ → __fixtures__}/jssip.mock.d.ts +3 -3
  45. package/dist/doMock.cjs +1 -1
  46. package/dist/{src/doMock.d.ts → doMock.d.ts} +2 -1
  47. package/dist/doMock.js +442 -341
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.d.ts +14 -0
  50. package/dist/index.js +718 -671
  51. package/dist/{src/setParametersToSender → setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +1 -1
  52. package/dist/{src/tools → tools}/__fixtures__/connectToServer.d.ts +2 -2
  53. package/dist/{src/tools → tools}/__fixtures__/processRequest.d.ts +1 -1
  54. package/dist/{src/tools → tools}/error/getLinkError.d.ts +1 -1
  55. package/dist/{src/tools → tools}/error/getTypeFromError.d.ts +1 -1
  56. package/dist/{src/tools → tools}/error/getValuesFromError.d.ts +1 -1
  57. package/dist/{src/tools → tools}/index.d.ts +1 -1
  58. package/dist/{src/tools → tools}/prepareMediaStream.d.ts +1 -1
  59. package/dist/{src/tools → tools}/setVideoTrackContentHints.d.ts +1 -1
  60. package/dist/{src/tools → tools}/syncMediaState/index.d.ts +1 -1
  61. package/dist/{src/tools → tools}/syncMediaState/resolveOnStartMainCam.d.ts +1 -1
  62. package/dist/{src/tools → tools}/syncMediaState/resolveOnStartMic.d.ts +1 -1
  63. package/dist/{src/tools → tools}/syncMediaState/resolveOnStopMainCam.d.ts +1 -1
  64. package/dist/{src/tools → tools}/syncMediaState/resolveOnStopMic.d.ts +1 -1
  65. package/dist/types.d.ts +23 -0
  66. package/dist/{src/videoSendingBalancer → videoSendingBalancer}/balance.d.ts +1 -1
  67. package/dist/{src/videoSendingBalancer → videoSendingBalancer}/getMaxBitrateByWidth.d.ts +1 -0
  68. package/dist/{src/videoSendingBalancer → videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +1 -0
  69. package/dist/{src/videoSendingBalancer → videoSendingBalancer}/index.d.ts +1 -1
  70. package/dist/{src/videoSendingBalancer → videoSendingBalancer}/processSender.d.ts +1 -1
  71. package/package.json +35 -42
  72. package/dist/SipConnector-BHvTGgmw.js +0 -1352
  73. package/dist/SipConnector-ChW25Tx9.cjs +0 -1
  74. package/dist/src/SipConnector.d.ts +0 -235
  75. package/dist/src/causes.d.ts +0 -23
  76. package/dist/src/headers.d.ts +0 -37
  77. package/dist/src/index.d.ts +0 -11
  78. package/dist/src/types.d.ts +0 -69
  79. /package/dist/{src → ConnectionManager}/getExtraHeadersRemoteAddress.d.ts +0 -0
  80. /package/dist/{src/SipConnectorFacade → SipConnectorFacade}/index.d.ts +0 -0
  81. /package/dist/{src/__fixtures__ → __fixtures__}/RTCRtpSenderMock.d.ts +0 -0
  82. /package/dist/{src/__fixtures__ → __fixtures__}/Registrator.mock.d.ts +0 -0
  83. /package/dist/{src/__fixtures__ → __fixtures__}/Request.mock.d.ts +0 -0
  84. /package/dist/{src/__fixtures__ → __fixtures__}/WebSocketInterface.mock.d.ts +0 -0
  85. /package/dist/{src/__fixtures__ → __fixtures__}/accountNotify.d.ts +0 -0
  86. /package/dist/{src/__fixtures__ → __fixtures__}/channels.d.ts +0 -0
  87. /package/dist/{src/__fixtures__ → __fixtures__}/channelsNotify.d.ts +0 -0
  88. /package/dist/{src/__fixtures__ → __fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
  89. /package/dist/{src → __fixtures__}/constants.d.ts +0 -0
  90. /package/dist/{src/__fixtures__ → __fixtures__}/delayPromise.d.ts +0 -0
  91. /package/dist/{src/__fixtures__ → __fixtures__}/enterRoom.d.ts +0 -0
  92. /package/dist/{src/__fixtures__ → __fixtures__}/mediaState.d.ts +0 -0
  93. /package/dist/{src/__fixtures__ → __fixtures__}/participantMoveRequests.d.ts +0 -0
  94. /package/dist/{src/__fixtures__ → __fixtures__}/participantNotify.d.ts +0 -0
  95. /package/dist/{src/__fixtures__ → __fixtures__}/remoteCallerData.d.ts +0 -0
  96. /package/dist/{src/__fixtures__ → __fixtures__}/utils.d.ts +0 -0
  97. /package/dist/{src/__fixtures__ → __fixtures__}/webcastNotify.d.ts +0 -0
  98. /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
  99. /package/dist/{src/setParametersToSender → setParametersToSender}/configureDegradationPreference.d.ts +0 -0
  100. /package/dist/{src/setParametersToSender → setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
  101. /package/dist/{src/setParametersToSender → setParametersToSender}/configureEncodings.d.ts +0 -0
  102. /package/dist/{src/setParametersToSender → setParametersToSender}/configureMaxBitrate.d.ts +0 -0
  103. /package/dist/{src/setParametersToSender → setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
  104. /package/dist/{src/setParametersToSender → setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
  105. /package/dist/{src/setParametersToSender → setParametersToSender}/index.d.ts +0 -0
  106. /package/dist/{src/setParametersToSender → setParametersToSender}/setParametersToSender.d.ts +0 -0
  107. /package/dist/{src/tools → tools}/__fixtures__/call.d.ts +0 -0
  108. /package/dist/{src/tools → tools}/__fixtures__/hasValidUri.d.ts +0 -0
  109. /package/dist/{src/tools → tools}/__fixtures__/permissions.d.ts +0 -0
  110. /package/dist/{src/tools → tools}/__tests-utils__/parseObject.d.ts +0 -0
  111. /package/dist/{src/tools → tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
  112. /package/dist/{src/tools → tools}/error/index.d.ts +0 -0
  113. /package/dist/{src/tools → tools}/error/stringifyMessage.d.ts +0 -0
  114. /package/dist/{src/tools → tools}/generateSimulcastEncodings.d.ts +0 -0
  115. /package/dist/{src/tools → tools}/getExtraHeaders.d.ts +0 -0
  116. /package/dist/{src/tools → tools}/getUserAgent.d.ts +0 -0
  117. /package/dist/{src/tools → tools}/hasPurgatory.d.ts +0 -0
  118. /package/dist/{src/tools → tools}/resolveUpdateTransceiver.d.ts +0 -0
  119. /package/dist/{src/tools/sendDTMFAccumulated.d.ts → tools/sendDtmfFAccumulated.d.ts} +0 -0
  120. /package/dist/{src/utils → utils}/errors.d.ts +0 -0
  121. /package/dist/{src/utils → utils}/findSenderByStream.d.ts +0 -0
  122. /package/dist/{src/utils → utils}/findVideoSender.d.ts +0 -0
  123. /package/dist/{src/utils → utils}/findVideoTrack.d.ts +0 -0
  124. /package/dist/{src/utils → utils}/getCodecFromSender.d.ts +0 -0
  125. /package/dist/{src/utils → utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
  126. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
  127. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/hasIncludesString.d.ts +0 -0
  128. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleBitrate.d.ts +0 -0
  129. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
  130. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
  131. /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
@@ -0,0 +1,2247 @@
1
+ import { Events as O } from "events-constructor";
2
+ import "@krivega/cancelable-promise";
3
+ import k from "debug";
4
+ import { hasCanceledError as K, repeatedCallsAsync as V } from "repeated-calls";
5
+ import { setup as j, createActor as Z } from "xstate";
6
+ var N = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(N || {}), U = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(U || {});
7
+ const H = [
8
+ "peerconnection",
9
+ "connecting",
10
+ "sending",
11
+ "progress",
12
+ "accepted",
13
+ "confirmed",
14
+ "ended",
15
+ "failed",
16
+ "newInfo",
17
+ "newDTMF",
18
+ "presentation:start",
19
+ "presentation:started",
20
+ "presentation:end",
21
+ "presentation:ended",
22
+ "presentation:failed",
23
+ "reinvite",
24
+ "update",
25
+ "refer",
26
+ "replaces",
27
+ "sdp",
28
+ "icecandidate",
29
+ "getusermediafailed",
30
+ "peerconnection:createofferfailed",
31
+ "peerconnection:createanswerfailed",
32
+ "peerconnection:setlocaldescriptionfailed",
33
+ "peerconnection:setremotedescriptionfailed"
34
+ ], ee = [
35
+ "peerconnection:confirmed",
36
+ "peerconnection:ontrack",
37
+ "ended:fromserver"
38
+ ], G = [
39
+ ...H,
40
+ ...ee
41
+ ];
42
+ function te(n) {
43
+ return (e) => `sip:${e}@${n}`;
44
+ }
45
+ const ne = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, B = (n) => n.trim().replaceAll(" ", "_"), se = ne(1e5, 99999999), ie = (n) => n.some((t) => {
46
+ const { kind: s } = t;
47
+ return s === "video";
48
+ }), re = (n, e) => {
49
+ n.getVideoTracks().forEach((s) => {
50
+ "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
51
+ });
52
+ }, v = (n, {
53
+ directionVideo: e,
54
+ directionAudio: t,
55
+ contentHint: s
56
+ } = {}) => {
57
+ if (!n || e === "recvonly" && t === "recvonly")
58
+ return;
59
+ const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
60
+ return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && re(o, s), o;
61
+ };
62
+ class ae {
63
+ isPendingCall = !1;
64
+ isPendingAnswer = !1;
65
+ rtcSession;
66
+ remoteStreams = {};
67
+ events;
68
+ callConfiguration = {};
69
+ constructor(e) {
70
+ this.events = e;
71
+ }
72
+ }
73
+ var x = /* @__PURE__ */ ((n) => (n.BYE = "Terminated", n.WEBRTC_ERROR = "WebRTC Error", n.CANCELED = "Canceled", n.REQUEST_TIMEOUT = "Request Timeout", n.REJECTED = "Rejected", n.REDIRECTED = "Redirected", n.UNAVAILABLE = "Unavailable", n.NOT_FOUND = "Not Found", n.ADDRESS_INCOMPLETE = "Address Incomplete", n.INCOMPATIBLE_SDP = "Incompatible SDP", n.BAD_MEDIA_DESCRIPTION = "Bad Media Description", n))(x || {});
74
+ class oe {
75
+ remoteStreams = {};
76
+ reset() {
77
+ this.remoteStreams = {};
78
+ }
79
+ generateStream(e, t) {
80
+ const { id: s } = e, i = this.remoteStreams[s] ?? new MediaStream();
81
+ return t && i.addTrack(t), i.addTrack(e), this.remoteStreams[s] = i, i;
82
+ }
83
+ generateAudioStream(e) {
84
+ const { id: t } = e, s = this.remoteStreams[t] ?? new MediaStream();
85
+ return s.addTrack(e), this.remoteStreams[t] = s, s;
86
+ }
87
+ generateStreams(e) {
88
+ const t = [];
89
+ return e.forEach((s, i) => {
90
+ if (s.kind === "audio")
91
+ return;
92
+ const r = s, a = e[i - 1];
93
+ let o;
94
+ a?.kind === "audio" && (o = a);
95
+ const c = this.generateStream(r, o);
96
+ t.push(c);
97
+ }), t;
98
+ }
99
+ generateAudioStreams(e) {
100
+ return e.map((t) => this.generateAudioStream(t));
101
+ }
102
+ }
103
+ class ce extends ae {
104
+ remoteStreamsManager = new oe();
105
+ disposers = /* @__PURE__ */ new Set();
106
+ constructor(e) {
107
+ super(e), e.on(N.FAILED, this.handleEnded), e.on(N.ENDED, this.handleEnded);
108
+ }
109
+ get requested() {
110
+ return this.isPendingCall || this.isPendingAnswer;
111
+ }
112
+ get connection() {
113
+ return this.rtcSession?.connection;
114
+ }
115
+ get isCallActive() {
116
+ return this.rtcSession?.isEstablished() === !0;
117
+ }
118
+ get establishedRTCSession() {
119
+ return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
120
+ }
121
+ startCall = async (e, t, {
122
+ number: s,
123
+ mediaStream: i,
124
+ extraHeaders: r = [],
125
+ ontrack: a,
126
+ iceServers: o,
127
+ directionVideo: c,
128
+ directionAudio: g,
129
+ contentHint: d,
130
+ offerToReceiveAudio: l = !0,
131
+ offerToReceiveVideo: E = !0,
132
+ sendEncodings: S,
133
+ onAddedTransceiver: I
134
+ }) => (this.isPendingCall = !0, new Promise((C, p) => {
135
+ this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(C).catch((b) => {
136
+ p(b);
137
+ }), this.rtcSession = e.call(t(s), {
138
+ extraHeaders: r,
139
+ mediaStream: v(i, {
140
+ directionVideo: c,
141
+ directionAudio: g,
142
+ contentHint: d
143
+ }),
144
+ // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
145
+ // так как в методе call создается RTCSession
146
+ // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
147
+ eventHandlers: this.events.triggers,
148
+ directionVideo: c,
149
+ directionAudio: g,
150
+ pcConfig: {
151
+ iceServers: o
152
+ },
153
+ rtcOfferConstraints: {
154
+ offerToReceiveAudio: l,
155
+ offerToReceiveVideo: E
156
+ },
157
+ sendEncodings: S,
158
+ onAddedTransceiver: I
159
+ });
160
+ }).finally(() => {
161
+ this.isPendingCall = !1;
162
+ }));
163
+ async endCall() {
164
+ const { rtcSession: e } = this;
165
+ if (e && !e.isEnded())
166
+ return e.terminateAsync({
167
+ cause: x.CANCELED
168
+ }).finally(() => {
169
+ this.reset();
170
+ });
171
+ this.reset();
172
+ }
173
+ answerToIncomingCall = async (e, {
174
+ mediaStream: t,
175
+ ontrack: s,
176
+ extraHeaders: i = [],
177
+ iceServers: r,
178
+ directionVideo: a,
179
+ directionAudio: o,
180
+ offerToReceiveAudio: c,
181
+ offerToReceiveVideo: g,
182
+ contentHint: d,
183
+ sendEncodings: l,
184
+ onAddedTransceiver: E
185
+ }) => (this.isPendingAnswer = !0, new Promise((S, I) => {
186
+ try {
187
+ const C = e();
188
+ this.rtcSession = C, this.subscribeToSessionEvents(C), this.callConfiguration.answer = !0, this.callConfiguration.number = C.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(S).catch((b) => {
189
+ I(b);
190
+ });
191
+ const p = v(t, {
192
+ directionVideo: a,
193
+ directionAudio: o,
194
+ contentHint: d
195
+ });
196
+ C.answer({
197
+ extraHeaders: i,
198
+ directionVideo: a,
199
+ directionAudio: o,
200
+ mediaStream: p,
201
+ pcConfig: {
202
+ iceServers: r
203
+ },
204
+ rtcOfferConstraints: {
205
+ offerToReceiveAudio: c,
206
+ offerToReceiveVideo: g
207
+ },
208
+ sendEncodings: l,
209
+ onAddedTransceiver: E
210
+ });
211
+ } catch (C) {
212
+ I(C);
213
+ }
214
+ }).finally(() => {
215
+ this.isPendingAnswer = !1;
216
+ }));
217
+ getEstablishedRTCSession() {
218
+ return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
219
+ }
220
+ getCallConfiguration() {
221
+ return { ...this.callConfiguration };
222
+ }
223
+ getRemoteStreams() {
224
+ if (!this.connection)
225
+ return;
226
+ const t = this.connection.getReceivers().map(({ track: s }) => s);
227
+ return ie(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
228
+ }
229
+ async replaceMediaStream(e, t) {
230
+ if (!this.rtcSession)
231
+ throw new Error("No rtcSession established");
232
+ const { contentHint: s } = t ?? {}, i = v(e, { contentHint: s });
233
+ if (i === void 0)
234
+ throw new Error("No preparedMediaStream");
235
+ return this.rtcSession.replaceMediaStream(i, t);
236
+ }
237
+ handleCall = async ({
238
+ ontrack: e
239
+ }) => new Promise((t, s) => {
240
+ const i = () => {
241
+ this.events.on(N.PEER_CONNECTION, d), this.events.on(N.CONFIRMED, l);
242
+ }, r = () => {
243
+ this.events.off(N.PEER_CONNECTION, d), this.events.off(N.CONFIRMED, l);
244
+ }, a = () => {
245
+ this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
246
+ }, o = () => {
247
+ this.events.off(N.FAILED, c), this.events.off(N.ENDED, c);
248
+ }, c = (E) => {
249
+ r(), o(), s(E);
250
+ };
251
+ let g;
252
+ const d = ({ peerconnection: E }) => {
253
+ g = E;
254
+ const S = (I) => {
255
+ this.events.trigger(N.PEER_CONNECTION_ONTRACK, E), e && e(I);
256
+ };
257
+ E.addEventListener("track", S), this.disposers.add(() => {
258
+ E.removeEventListener("track", S);
259
+ });
260
+ }, l = () => {
261
+ g !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, g), r(), o(), t(g);
262
+ };
263
+ i(), a();
264
+ });
265
+ subscribeToSessionEvents(e) {
266
+ this.events.eachTriggers((t, s) => {
267
+ const i = H.find((r) => r === s);
268
+ i && (e.on(i, t), this.disposers.add(() => {
269
+ e.off(i, t);
270
+ }));
271
+ });
272
+ }
273
+ unsubscribeFromSessionEvents() {
274
+ this.disposers.forEach((e) => {
275
+ e();
276
+ }), this.disposers.clear();
277
+ }
278
+ handleEnded = (e) => {
279
+ const { originator: t } = e;
280
+ t === U.REMOTE && this.events.trigger(N.ENDED_FROM_SERVER, e), this.reset();
281
+ };
282
+ reset = () => {
283
+ delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
284
+ };
285
+ }
286
+ class ge {
287
+ events;
288
+ strategy;
289
+ constructor(e) {
290
+ this.events = new O(G), this.strategy = e ?? new ce(this.events);
291
+ }
292
+ get requested() {
293
+ return this.strategy.requested;
294
+ }
295
+ get connection() {
296
+ return this.strategy.connection;
297
+ }
298
+ get establishedRTCSession() {
299
+ return this.strategy.establishedRTCSession;
300
+ }
301
+ get isCallActive() {
302
+ return this.strategy.isCallActive;
303
+ }
304
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
305
+ on(e, t) {
306
+ return this.events.on(e, t);
307
+ }
308
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
309
+ once(e, t) {
310
+ return this.events.once(e, t);
311
+ }
312
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
313
+ onceRace(e, t) {
314
+ return this.events.onceRace(e, t);
315
+ }
316
+ async wait(e) {
317
+ return this.events.wait(e);
318
+ }
319
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
320
+ off(e, t) {
321
+ this.events.off(e, t);
322
+ }
323
+ setStrategy(e) {
324
+ this.strategy = e;
325
+ }
326
+ startCall = async (...e) => this.strategy.startCall(...e);
327
+ endCall = async () => this.strategy.endCall();
328
+ answerToIncomingCall = async (...e) => this.strategy.answerToIncomingCall(...e);
329
+ getEstablishedRTCSession = () => this.strategy.getEstablishedRTCSession();
330
+ getCallConfiguration = () => this.strategy.getCallConfiguration();
331
+ getRemoteStreams = () => this.strategy.getRemoteStreams();
332
+ replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
333
+ }
334
+ const W = "sip-connector", m = k(W), He = () => {
335
+ k.enable(W);
336
+ }, Ge = () => {
337
+ k.enable(`-${W}`);
338
+ }, Te = "Error decline with 603", he = 1006, de = (n) => typeof n == "object" && n !== null && "code" in n && n.code === he, Ee = (n) => n.message === Te;
339
+ var h = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n))(h || {}), y = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(y || {}), w = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(w || {}), M = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(M || {}), _ = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(_ || {}), f = /* @__PURE__ */ ((n) => (n.PAUSE_MAIN_CAM = "PAUSEMAINCAM", n.RESUME_MAIN_CAM = "RESUMEMAINCAM", n.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", n.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", n.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", n))(f || {}), L = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(L || {}), F = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(F || {}), Se = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Se || {}), T = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants", n.PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request", n.PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request", n.WEBCAST_STARTED = "webcast:started", n.WEBCAST_STOPPED = "webcast:stopped", n.ACCOUNT_CHANGED = "account:changed", n.ACCOUNT_DELETED = "account:deleted", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n))(T || {});
340
+ const q = [
341
+ "participation:accepting-word-request",
342
+ "participation:cancelling-word-request",
343
+ "participant:move-request-to-stream",
344
+ "channels:notify",
345
+ "conference:participant-token-issued",
346
+ "account:changed",
347
+ "account:deleted",
348
+ "webcast:started",
349
+ "webcast:stopped",
350
+ "participant:added-to-list-moderators",
351
+ "participant:removed-from-list-moderators",
352
+ "participant:move-request-to-spectators",
353
+ "participant:move-request-to-participants",
354
+ "channels",
355
+ "enterRoom",
356
+ "shareState",
357
+ "main-cam-control",
358
+ "useLicense",
359
+ "admin-start-main-cam",
360
+ "admin-stop-main-cam",
361
+ "admin-start-mic",
362
+ "admin-stop-mic",
363
+ "admin-force-sync-media-state",
364
+ "availableSecondRemoteStream",
365
+ "notAvailableSecondRemoteStream",
366
+ "mustStopPresentation",
367
+ "newDTMF"
368
+ ];
369
+ var A = /* @__PURE__ */ ((n) => (n.CHANNELS = "channels", n.WEBCAST_STARTED = "WebcastStarted", n.WEBCAST_STOPPED = "WebcastStopped", n.ACCOUNT_CHANGED = "accountChanged", n.ACCOUNT_DELETED = "accountDeleted", n.ADDED_TO_LIST_MODERATORS = "addedToListModerators", n.REMOVED_FROM_LIST_MODERATORS = "removedFromListModerators", n.ACCEPTING_WORD_REQUEST = "ParticipationRequestAccepted", n.CANCELLING_WORD_REQUEST = "ParticipationRequestRejected", n.MOVE_REQUEST_TO_STREAM = "ParticipantMovedToWebcast", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "ConferenceParticipantTokenIssued", n))(A || {});
370
+ class le {
371
+ events;
372
+ connectionManager;
373
+ callManager;
374
+ constructor({
375
+ connectionManager: e,
376
+ callManager: t
377
+ }) {
378
+ this.connectionManager = e, this.callManager = t, this.events = new O(q), this.subscribe();
379
+ }
380
+ async waitChannels() {
381
+ return this.wait(T.CHANNELS);
382
+ }
383
+ async waitSyncMediaState() {
384
+ return this.wait(T.ADMIN_FORCE_SYNC_MEDIA_STATE);
385
+ }
386
+ async sendDTMF(e) {
387
+ return new Promise((t, s) => {
388
+ let i;
389
+ try {
390
+ i = this.getEstablishedRTCSessionProtected();
391
+ } catch (r) {
392
+ s(r);
393
+ }
394
+ i && (this.callManager.once("newDTMF", ({ originator: r }) => {
395
+ r === U.LOCAL && t();
396
+ }), i.sendDTMF(e, {
397
+ duration: 120,
398
+ interToneGap: 600
399
+ }));
400
+ });
401
+ }
402
+ async sendChannels({ inputChannels: e, outputChannels: t }) {
403
+ const s = this.getEstablishedRTCSessionProtected(), i = `${h.INPUT_CHANNELS}: ${e}`, r = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
404
+ i,
405
+ r
406
+ ];
407
+ return s.sendInfo(_.CHANNELS, void 0, { extraHeaders: a });
408
+ }
409
+ async sendMediaState({ cam: e, mic: t }, s = {}) {
410
+ const i = this.getEstablishedRTCSessionProtected(), r = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
411
+ r,
412
+ a,
413
+ o
414
+ ];
415
+ return i.sendInfo(_.MEDIA_STATE, void 0, {
416
+ noTerminateWhenError: !0,
417
+ ...s,
418
+ extraHeaders: c
419
+ });
420
+ }
421
+ async sendRefusalToTurnOn(e, t = {}) {
422
+ const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${h.MEDIA_TYPE}: ${a}`];
423
+ return s.sendInfo(_.REFUSAL, void 0, {
424
+ noTerminateWhenError: !0,
425
+ ...t,
426
+ extraHeaders: c
427
+ });
428
+ }
429
+ async sendRefusalToTurnOnMic(e = {}) {
430
+ return this.sendRefusalToTurnOn("mic", { noTerminateWhenError: !0, ...e });
431
+ }
432
+ async sendRefusalToTurnOnCam(e = {}) {
433
+ return this.sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
434
+ }
435
+ async sendMustStopPresentationP2P() {
436
+ await this.getEstablishedRTCSessionProtected().sendInfo(_.SHARE_STATE, void 0, {
437
+ extraHeaders: [h.MUST_STOP_PRESENTATION_P2P]
438
+ });
439
+ }
440
+ async sendStoppedPresentationP2P() {
441
+ await this.getEstablishedRTCSessionProtected().sendInfo(_.SHARE_STATE, void 0, {
442
+ extraHeaders: [h.STOP_PRESENTATION_P2P]
443
+ });
444
+ }
445
+ async sendStoppedPresentation() {
446
+ await this.getEstablishedRTCSessionProtected().sendInfo(_.SHARE_STATE, void 0, {
447
+ extraHeaders: [h.STOP_PRESENTATION]
448
+ });
449
+ }
450
+ async askPermissionToStartPresentationP2P() {
451
+ await this.getEstablishedRTCSessionProtected().sendInfo(_.SHARE_STATE, void 0, {
452
+ extraHeaders: [h.START_PRESENTATION_P2P]
453
+ });
454
+ }
455
+ async askPermissionToStartPresentation() {
456
+ await this.getEstablishedRTCSessionProtected().sendInfo(_.SHARE_STATE, void 0, {
457
+ extraHeaders: [h.START_PRESENTATION]
458
+ });
459
+ }
460
+ async askPermissionToEnableCam(e = {}) {
461
+ const t = this.getEstablishedRTCSessionProtected(), s = [h.ENABLE_MAIN_CAM];
462
+ return t.sendInfo(_.MAIN_CAM, void 0, {
463
+ noTerminateWhenError: !0,
464
+ ...e,
465
+ extraHeaders: s
466
+ }).catch((i) => {
467
+ if (Ee(i))
468
+ throw i;
469
+ });
470
+ }
471
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
472
+ on(e, t) {
473
+ return this.events.on(e, t);
474
+ }
475
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
476
+ once(e, t) {
477
+ return this.events.once(e, t);
478
+ }
479
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
480
+ onceRace(e, t) {
481
+ return this.events.onceRace(e, t);
482
+ }
483
+ async wait(e) {
484
+ return this.events.wait(e);
485
+ }
486
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
487
+ off(e, t) {
488
+ this.events.off(e, t);
489
+ }
490
+ getEstablishedRTCSessionProtected = () => {
491
+ const e = this.callManager.getEstablishedRTCSession();
492
+ if (!e)
493
+ throw new Error("No rtcSession established");
494
+ return e;
495
+ };
496
+ subscribe() {
497
+ this.connectionManager.on("sipEvent", this.handleSipEvent), this.callManager.on("newInfo", this.handleNewInfo), this.callManager.on("newDTMF", (e) => {
498
+ this.events.trigger("newDTMF", e);
499
+ });
500
+ }
501
+ handleSipEvent = ({ request: e }) => {
502
+ this.maybeHandleNotify(e);
503
+ };
504
+ maybeHandleNotify = (e) => {
505
+ try {
506
+ const t = e.getHeader(h.NOTIFY);
507
+ if (t) {
508
+ const s = JSON.parse(t);
509
+ this.handleNotify(s);
510
+ }
511
+ } catch (t) {
512
+ m("error parse notify", t);
513
+ }
514
+ };
515
+ handleNotify = (e) => {
516
+ switch (e.cmd) {
517
+ case A.CHANNELS: {
518
+ const t = e;
519
+ this.triggerChannelsNotify(t);
520
+ break;
521
+ }
522
+ case A.WEBCAST_STARTED: {
523
+ const t = e;
524
+ this.triggerWebcastStartedNotify(t);
525
+ break;
526
+ }
527
+ case A.WEBCAST_STOPPED: {
528
+ const t = e;
529
+ this.triggerWebcastStoppedNotify(t);
530
+ break;
531
+ }
532
+ case A.ADDED_TO_LIST_MODERATORS: {
533
+ const t = e;
534
+ this.triggerAddedToListModeratorsNotify(t);
535
+ break;
536
+ }
537
+ case A.REMOVED_FROM_LIST_MODERATORS: {
538
+ const t = e;
539
+ this.triggerRemovedFromListModeratorsNotify(t);
540
+ break;
541
+ }
542
+ case A.ACCEPTING_WORD_REQUEST: {
543
+ const t = e;
544
+ this.triggerParticipationAcceptingWordRequest(t);
545
+ break;
546
+ }
547
+ case A.CANCELLING_WORD_REQUEST: {
548
+ const t = e;
549
+ this.triggerParticipationCancellingWordRequest(t);
550
+ break;
551
+ }
552
+ case A.MOVE_REQUEST_TO_STREAM: {
553
+ const t = e;
554
+ this.triggerParticipantMoveRequestToStream(t);
555
+ break;
556
+ }
557
+ case A.ACCOUNT_CHANGED: {
558
+ this.triggerAccountChangedNotify();
559
+ break;
560
+ }
561
+ case A.ACCOUNT_DELETED: {
562
+ this.triggerAccountDeletedNotify();
563
+ break;
564
+ }
565
+ case A.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
566
+ const t = e;
567
+ this.triggerConferenceParticipantTokenIssued(t);
568
+ break;
569
+ }
570
+ default:
571
+ m("unknown cmd", e);
572
+ }
573
+ };
574
+ handleNewInfo = (e) => {
575
+ const { originator: t } = e;
576
+ if (t !== U.REMOTE)
577
+ return;
578
+ const { request: s } = e, i = s.getHeader(h.CONTENT_TYPE);
579
+ if (i !== void 0)
580
+ switch (i) {
581
+ case M.ENTER_ROOM: {
582
+ this.triggerEnterRoom(s), this.maybeTriggerChannels(s);
583
+ break;
584
+ }
585
+ case M.NOTIFY: {
586
+ this.maybeHandleNotify(s);
587
+ break;
588
+ }
589
+ case M.SHARE_STATE: {
590
+ this.triggerShareState(s);
591
+ break;
592
+ }
593
+ case M.MAIN_CAM: {
594
+ this.triggerMainCamControl(s);
595
+ break;
596
+ }
597
+ case M.MIC: {
598
+ this.triggerMicControl(s);
599
+ break;
600
+ }
601
+ case M.USE_LICENSE: {
602
+ this.triggerUseLicense(s);
603
+ break;
604
+ }
605
+ case M.PARTICIPANT_STATE: {
606
+ this.maybeTriggerParticipantMoveRequest(s);
607
+ break;
608
+ }
609
+ }
610
+ };
611
+ triggerChannelsNotify = (e) => {
612
+ const t = e.input, s = e.output, i = {
613
+ inputChannels: t,
614
+ outputChannels: s
615
+ };
616
+ this.events.trigger(T.CHANNELS_NOTIFY, i);
617
+ };
618
+ triggerWebcastStartedNotify = ({
619
+ body: { conference: e, type: t }
620
+ }) => {
621
+ const s = {
622
+ conference: e,
623
+ type: t
624
+ };
625
+ this.events.trigger(T.WEBCAST_STARTED, s);
626
+ };
627
+ triggerWebcastStoppedNotify = ({
628
+ body: { conference: e, type: t }
629
+ }) => {
630
+ const s = {
631
+ conference: e,
632
+ type: t
633
+ };
634
+ this.events.trigger(T.WEBCAST_STOPPED, s);
635
+ };
636
+ triggerAddedToListModeratorsNotify = ({
637
+ conference: e
638
+ }) => {
639
+ const t = {
640
+ conference: e
641
+ };
642
+ this.events.trigger(
643
+ T.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
644
+ t
645
+ );
646
+ };
647
+ triggerRemovedFromListModeratorsNotify = ({
648
+ conference: e
649
+ }) => {
650
+ const t = {
651
+ conference: e
652
+ };
653
+ this.events.trigger(
654
+ T.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
655
+ t
656
+ );
657
+ };
658
+ triggerParticipationAcceptingWordRequest = ({
659
+ body: { conference: e }
660
+ }) => {
661
+ const t = {
662
+ conference: e
663
+ };
664
+ this.events.trigger(T.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
665
+ };
666
+ triggerParticipationCancellingWordRequest = ({
667
+ body: { conference: e }
668
+ }) => {
669
+ const t = {
670
+ conference: e
671
+ };
672
+ this.events.trigger(T.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
673
+ };
674
+ triggerParticipantMoveRequestToStream = ({
675
+ body: { conference: e }
676
+ }) => {
677
+ const t = {
678
+ conference: e
679
+ };
680
+ this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
681
+ };
682
+ triggerAccountChangedNotify = () => {
683
+ this.events.trigger(T.ACCOUNT_CHANGED, void 0);
684
+ };
685
+ triggerAccountDeletedNotify = () => {
686
+ this.events.trigger(T.ACCOUNT_DELETED, void 0);
687
+ };
688
+ triggerConferenceParticipantTokenIssued = ({
689
+ body: { conference: e, participant: t, jwt: s }
690
+ }) => {
691
+ const i = {
692
+ conference: e,
693
+ participant: t,
694
+ jwt: s
695
+ };
696
+ this.events.trigger(
697
+ T.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
698
+ i
699
+ );
700
+ };
701
+ maybeTriggerChannels = (e) => {
702
+ const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
703
+ if (t && s) {
704
+ const i = {
705
+ inputChannels: t,
706
+ outputChannels: s
707
+ };
708
+ this.events.trigger(T.CHANNELS, i);
709
+ }
710
+ };
711
+ triggerEnterRoom = (e) => {
712
+ const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
713
+ this.events.trigger(T.ENTER_ROOM, { room: t, participantName: s });
714
+ };
715
+ triggerShareState = (e) => {
716
+ const t = e.getHeader(h.CONTENT_SHARE_STATE);
717
+ if (t !== void 0)
718
+ switch (t) {
719
+ case y.AVAILABLE_SECOND_REMOTE_STREAM: {
720
+ this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
721
+ break;
722
+ }
723
+ case y.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
724
+ this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
725
+ break;
726
+ }
727
+ case y.MUST_STOP_PRESENTATION: {
728
+ this.events.trigger(T.MUST_STOP_PRESENTATION, void 0);
729
+ break;
730
+ }
731
+ }
732
+ };
733
+ maybeTriggerParticipantMoveRequest = (e) => {
734
+ const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
735
+ t === w.SPECTATOR && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === w.PARTICIPANT && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0);
736
+ };
737
+ triggerMainCamControl = (e) => {
738
+ const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), i = s === F.ADMIN_SYNC_FORCED;
739
+ if (t === f.ADMIN_START_MAIN_CAM) {
740
+ this.events.trigger(T.ADMIN_START_MAIN_CAM, { isSyncForced: i });
741
+ return;
742
+ }
743
+ if (t === f.ADMIN_STOP_MAIN_CAM) {
744
+ this.events.trigger(T.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
745
+ return;
746
+ }
747
+ (t === f.RESUME_MAIN_CAM || t === f.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(T.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
748
+ const r = e.getHeader(h.MAIN_CAM_RESOLUTION);
749
+ this.events.trigger(T.MAIN_CAM_CONTROL, {
750
+ mainCam: t,
751
+ resolutionMainCam: r
752
+ });
753
+ };
754
+ triggerMicControl = (e) => {
755
+ const t = e.getHeader(h.MIC), i = e.getHeader(h.MEDIA_SYNC) === F.ADMIN_SYNC_FORCED;
756
+ t === L.ADMIN_START_MIC ? this.events.trigger(T.ADMIN_START_MIC, { isSyncForced: i }) : t === L.ADMIN_STOP_MIC && this.events.trigger(T.ADMIN_STOP_MIC, { isSyncForced: i });
757
+ };
758
+ triggerUseLicense = (e) => {
759
+ const t = e.getHeader(h.CONTENT_USE_LICENSE);
760
+ this.events.trigger(T.USE_LICENSE, t);
761
+ };
762
+ }
763
+ var R = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(R || {});
764
+ const Y = [
765
+ "presentation:start",
766
+ "presentation:started",
767
+ "presentation:end",
768
+ "presentation:ended",
769
+ "presentation:failed"
770
+ ], Ce = 1, Be = (n) => K(n);
771
+ class Ne {
772
+ events;
773
+ promisePendingStartPresentation;
774
+ promisePendingStopPresentation;
775
+ streamPresentationCurrent;
776
+ cancelableSendPresentationWithRepeatedCalls;
777
+ callManager;
778
+ constructor({ callManager: e }) {
779
+ this.callManager = e, this.events = new O(Y), this.subscribe();
780
+ }
781
+ get isPendingPresentation() {
782
+ return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
783
+ }
784
+ // eslint-disable-next-line @typescript-eslint/max-params
785
+ async startPresentation(e, t, {
786
+ isNeedReinvite: s,
787
+ maxBitrate: i,
788
+ contentHint: r,
789
+ sendEncodings: a,
790
+ onAddedTransceiver: o
791
+ } = {}, c) {
792
+ const g = this.getRtcSessionProtected();
793
+ if (this.streamPresentationCurrent)
794
+ throw new Error("Presentation is already started");
795
+ return this.sendPresentationWithDuplicatedCalls(e, {
796
+ rtcSession: g,
797
+ stream: t,
798
+ presentationOptions: {
799
+ isNeedReinvite: s,
800
+ maxBitrate: i,
801
+ contentHint: r,
802
+ sendEncodings: a,
803
+ onAddedTransceiver: o
804
+ },
805
+ options: c
806
+ });
807
+ }
808
+ async stopPresentation(e) {
809
+ this.cancelSendPresentationWithRepeatedCalls();
810
+ const t = this.streamPresentationCurrent;
811
+ let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
812
+ const i = this.callManager.getEstablishedRTCSession();
813
+ return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
814
+ throw this.events.trigger(R.FAILED_PRESENTATION, r), r;
815
+ }) : t && this.events.trigger(R.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
816
+ this.resetPresentation();
817
+ });
818
+ }
819
+ async updatePresentation(e, t, {
820
+ // maxBitrate,
821
+ contentHint: s,
822
+ sendEncodings: i,
823
+ onAddedTransceiver: r
824
+ } = {}) {
825
+ const a = this.getRtcSessionProtected();
826
+ if (!this.streamPresentationCurrent)
827
+ throw new Error("Presentation has not started yet");
828
+ return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
829
+ // maxBitrate,
830
+ contentHint: s,
831
+ isNeedReinvite: !1,
832
+ sendEncodings: i,
833
+ onAddedTransceiver: r
834
+ });
835
+ }
836
+ cancelSendPresentationWithRepeatedCalls() {
837
+ this.cancelableSendPresentationWithRepeatedCalls?.cancel();
838
+ }
839
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
840
+ on(e, t) {
841
+ return this.events.on(e, t);
842
+ }
843
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
844
+ once(e, t) {
845
+ return this.events.once(e, t);
846
+ }
847
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
848
+ onceRace(e, t) {
849
+ return this.events.onceRace(e, t);
850
+ }
851
+ async wait(e) {
852
+ return this.events.wait(e);
853
+ }
854
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
855
+ off(e, t) {
856
+ this.events.off(e, t);
857
+ }
858
+ subscribe() {
859
+ this.callManager.on("presentation:start", (e) => {
860
+ this.events.trigger(R.START_PRESENTATION, e);
861
+ }), this.callManager.on("presentation:started", (e) => {
862
+ this.events.trigger(R.STARTED_PRESENTATION, e);
863
+ }), this.callManager.on("presentation:end", (e) => {
864
+ this.events.trigger(R.END_PRESENTATION, e);
865
+ }), this.callManager.on("presentation:ended", (e) => {
866
+ this.events.trigger(R.ENDED_PRESENTATION, e);
867
+ }), this.callManager.on("presentation:failed", (e) => {
868
+ this.events.trigger(R.FAILED_PRESENTATION, e);
869
+ }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
870
+ }
871
+ async sendPresentationWithDuplicatedCalls(e, {
872
+ rtcSession: t,
873
+ stream: s,
874
+ presentationOptions: i,
875
+ options: r = {
876
+ callLimit: Ce
877
+ }
878
+ }) {
879
+ const a = async () => this.sendPresentation(
880
+ e,
881
+ t,
882
+ s,
883
+ i
884
+ ), o = () => !!this.streamPresentationCurrent;
885
+ return this.cancelableSendPresentationWithRepeatedCalls = V({
886
+ targetFunction: a,
887
+ isComplete: o,
888
+ isRejectAsValid: !0,
889
+ ...r
890
+ }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
891
+ }
892
+ // eslint-disable-next-line @typescript-eslint/max-params
893
+ async sendPresentation(e, t, s, {
894
+ // maxBitrate = ONE_MEGABIT_IN_BITS,
895
+ isNeedReinvite: i = !0,
896
+ contentHint: r = "detail",
897
+ sendEncodings: a,
898
+ onAddedTransceiver: o
899
+ }) {
900
+ const c = v(s, { contentHint: r });
901
+ if (c === void 0)
902
+ throw new Error("No streamPresentationTarget");
903
+ this.streamPresentationCurrent = c;
904
+ const g = e().then(async () => t.startPresentation(c, i, {
905
+ sendEncodings: a,
906
+ onAddedTransceiver: o
907
+ })).then(() => s).catch((d) => {
908
+ throw this.removeStreamPresentationCurrent(), this.events.trigger(R.FAILED_PRESENTATION, d), d;
909
+ });
910
+ return this.promisePendingStartPresentation = g, g.finally(() => {
911
+ this.promisePendingStartPresentation = void 0;
912
+ });
913
+ }
914
+ getRtcSessionProtected = () => {
915
+ const e = this.callManager.getEstablishedRTCSession();
916
+ if (!e)
917
+ throw new Error("No rtcSession established");
918
+ return e;
919
+ };
920
+ handleEnded = () => {
921
+ this.reset();
922
+ };
923
+ reset() {
924
+ this.cancelSendPresentationWithRepeatedCalls(), this.resetPresentation();
925
+ }
926
+ resetPresentation() {
927
+ this.removeStreamPresentationCurrent(), this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
928
+ }
929
+ removeStreamPresentationCurrent() {
930
+ delete this.streamPresentationCurrent;
931
+ }
932
+ }
933
+ class ue {
934
+ data = {};
935
+ getUa;
936
+ constructor(e) {
937
+ this.getUa = e.getUa;
938
+ }
939
+ /**
940
+ * Проверяет, настроено ли соединение
941
+ */
942
+ isConfigured() {
943
+ return this.getUa() !== void 0;
944
+ }
945
+ /**
946
+ * Получает текущую конфигурацию подключения
947
+ */
948
+ get() {
949
+ return { ...this.data };
950
+ }
951
+ /**
952
+ * Устанавливает конфигурацию подключения
953
+ */
954
+ set(e) {
955
+ this.data = { ...e };
956
+ }
957
+ /**
958
+ * Обновляет конфигурацию подключения
959
+ */
960
+ update(e, t) {
961
+ this.data[e] = t;
962
+ }
963
+ /**
964
+ * Очищает конфигурацию
965
+ */
966
+ clear() {
967
+ this.data = {};
968
+ }
969
+ /**
970
+ * Проверяет, включена ли регистрация в конфигурации
971
+ */
972
+ isRegister() {
973
+ return this.data.register === !0;
974
+ }
975
+ /**
976
+ * Получает SIP сервер URL из конфигурации
977
+ */
978
+ getSipServerUrl() {
979
+ return this.data.sipServerUrl;
980
+ }
981
+ /**
982
+ * Получает display name из конфигурации
983
+ */
984
+ getDisplayName() {
985
+ return this.data.displayName;
986
+ }
987
+ /**
988
+ * Получает пользователя из конфигурации
989
+ */
990
+ getUser() {
991
+ return this.data.user;
992
+ }
993
+ /**
994
+ * Получает пароль из конфигурации
995
+ */
996
+ getPassword() {
997
+ return this.data.password;
998
+ }
999
+ /**
1000
+ * Проверяет, включена ли регистрация
1001
+ */
1002
+ isRegisterEnabled() {
1003
+ return this.data.register === !0;
1004
+ }
1005
+ }
1006
+ var u = /* @__PURE__ */ ((n) => (n.CONNECTING = "connecting", n.CONNECTED = "connected", n.DISCONNECTED = "disconnected", n.NEW_RTC_SESSION = "newRTCSession", n.REGISTERED = "registered", n.UNREGISTERED = "unregistered", n.REGISTRATION_FAILED = "registrationFailed", n.NEW_MESSAGE = "newMessage", n.SIP_EVENT = "sipEvent", n))(u || {});
1007
+ const z = [
1008
+ "connecting",
1009
+ "connected",
1010
+ "disconnected",
1011
+ "newRTCSession",
1012
+ "registered",
1013
+ "unregistered",
1014
+ "registrationFailed",
1015
+ "newMessage",
1016
+ "sipEvent"
1017
+ ], Q = [...z], Ae = 3;
1018
+ class _e {
1019
+ cancelableConnectWithRepeatedCalls;
1020
+ JsSIP;
1021
+ events;
1022
+ uaFactory;
1023
+ stateMachine;
1024
+ registrationManager;
1025
+ getUa;
1026
+ setUa;
1027
+ getConnectionConfiguration;
1028
+ setConnectionConfiguration;
1029
+ updateConnectionConfiguration;
1030
+ setSipServerUrl;
1031
+ setSocket;
1032
+ constructor(e) {
1033
+ this.JsSIP = e.JsSIP, this.events = e.events, this.uaFactory = e.uaFactory, this.stateMachine = e.stateMachine, this.registrationManager = e.registrationManager, this.getUa = e.getUa, this.setUa = e.setUa, this.getConnectionConfiguration = e.getConnectionConfiguration, this.setConnectionConfiguration = e.setConnectionConfiguration, this.updateConnectionConfiguration = e.updateConnectionConfiguration, this.setSipServerUrl = e.setSipServerUrl, this.setSocket = e.setSocket;
1034
+ }
1035
+ connect = async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t));
1036
+ set = async ({ displayName: e }) => new Promise((t, s) => {
1037
+ const i = this.getUa();
1038
+ if (!i) {
1039
+ s(new Error("this.ua is not initialized"));
1040
+ return;
1041
+ }
1042
+ let r = !1;
1043
+ const a = this.getConnectionConfiguration();
1044
+ e !== void 0 && e !== a.displayName && (r = i.set("display_name", B(e)), this.updateConnectionConfiguration("displayName", e));
1045
+ const o = r;
1046
+ o ? t(o) : s(new Error("nothing changed"));
1047
+ });
1048
+ disconnect = async () => {
1049
+ const e = new Promise((s) => {
1050
+ this.events.once(u.DISCONNECTED, () => {
1051
+ s();
1052
+ });
1053
+ }), t = this.getUa();
1054
+ return t ? t.stop() : this.events.trigger(u.DISCONNECTED, void 0), e.finally(() => {
1055
+ this.setUa(void 0), this.stateMachine.reset();
1056
+ });
1057
+ };
1058
+ cancelRequests() {
1059
+ this.cancelConnectWithRepeatedCalls();
1060
+ }
1061
+ connectWithDuplicatedCalls = async (e, { callLimit: t = Ae } = {}) => {
1062
+ const s = async () => this.connectInner(e), i = (r) => {
1063
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), g = r != null && !de(r);
1064
+ return c || g;
1065
+ };
1066
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = V({
1067
+ targetFunction: s,
1068
+ isComplete: i,
1069
+ callLimit: t,
1070
+ isRejectAsValid: !0,
1071
+ isCheckBeforeCall: !1
1072
+ }), this.cancelableConnectWithRepeatedCalls.then((r) => {
1073
+ if (r instanceof this.JsSIP.UA)
1074
+ return r;
1075
+ throw r;
1076
+ });
1077
+ };
1078
+ hasEqualConnectionConfiguration(e) {
1079
+ const { configuration: t } = this.uaFactory.createConfiguration(e), i = this.getUa()?.configuration;
1080
+ return i ? i.password === t.password && i.register === t.register && i.uri.toString() === t.uri && i.display_name === t.display_name && i.user_agent === t.user_agent && i.sockets === t.sockets && i.session_timers === t.session_timers && i.register_expires === t.register_expires && i.connection_recovery_min_interval === t.connection_recovery_min_interval && i.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1081
+ }
1082
+ connectInner = async (e) => this.initUa(e).then(async () => this.start());
1083
+ initUa = async ({
1084
+ user: e,
1085
+ password: t,
1086
+ sipServerUrl: s,
1087
+ sipWebSocketServerURL: i,
1088
+ remoteAddress: r,
1089
+ sessionTimers: a,
1090
+ registerExpires: o,
1091
+ connectionRecoveryMinInterval: c,
1092
+ connectionRecoveryMaxInterval: g,
1093
+ userAgent: d,
1094
+ displayName: l = "",
1095
+ register: E = !1,
1096
+ extraHeaders: S = []
1097
+ }) => {
1098
+ this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1099
+ sipServerUrl: s,
1100
+ displayName: l,
1101
+ register: E,
1102
+ user: e,
1103
+ password: t
1104
+ }), this.getUa() && await this.disconnect();
1105
+ const { ua: C, helpers: p } = this.uaFactory.createUAWithConfiguration(
1106
+ {
1107
+ user: e,
1108
+ password: t,
1109
+ sipServerUrl: s,
1110
+ sipWebSocketServerURL: i,
1111
+ displayName: l,
1112
+ register: E,
1113
+ sessionTimers: a,
1114
+ registerExpires: o,
1115
+ connectionRecoveryMinInterval: c,
1116
+ connectionRecoveryMaxInterval: g,
1117
+ userAgent: d,
1118
+ remoteAddress: r,
1119
+ extraHeaders: S
1120
+ },
1121
+ this.events
1122
+ );
1123
+ return this.setUa(C), this.setSipServerUrl(p.getSipServerUrl), this.setSocket(p.socket), C;
1124
+ };
1125
+ start = async () => new Promise((e, t) => {
1126
+ const s = this.getUa();
1127
+ if (!s) {
1128
+ t(new Error("this.ua is not initialized"));
1129
+ return;
1130
+ }
1131
+ let i;
1132
+ i = ((c, g) => {
1133
+ if (this.getConnectionConfiguration().register === !0)
1134
+ return this.registrationManager.subscribeToStartEvents(c, g);
1135
+ const l = u.CONNECTED, E = [u.DISCONNECTED];
1136
+ return this.events.on(l, c), E.forEach((S) => {
1137
+ this.events.on(S, g);
1138
+ }), () => {
1139
+ this.events.off(l, c), E.forEach((S) => {
1140
+ this.events.off(S, g);
1141
+ });
1142
+ };
1143
+ })(() => {
1144
+ i?.(), e(s);
1145
+ }, (c) => {
1146
+ i?.(), t(c);
1147
+ }), s.start();
1148
+ });
1149
+ cancelConnectWithRepeatedCalls() {
1150
+ this.cancelableConnectWithRepeatedCalls?.cancel();
1151
+ }
1152
+ }
1153
+ var X = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(X || {});
1154
+ const Ie = j({
1155
+ types: {
1156
+ context: {},
1157
+ events: {}
1158
+ },
1159
+ actions: {
1160
+ logTransition: (n, e) => {
1161
+ m(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1162
+ },
1163
+ logStateChange: (n, e) => {
1164
+ m("ConnectionStateMachine state changed", e.state);
1165
+ }
1166
+ }
1167
+ }).createMachine({
1168
+ id: "connection",
1169
+ initial: "idle",
1170
+ context: {},
1171
+ states: {
1172
+ idle: {
1173
+ entry: {
1174
+ type: "logStateChange",
1175
+ params: {
1176
+ state: "idle"
1177
+ /* IDLE */
1178
+ }
1179
+ },
1180
+ on: {
1181
+ START_CONNECT: {
1182
+ target: "connecting",
1183
+ actions: {
1184
+ type: "logTransition",
1185
+ params: {
1186
+ from: "idle",
1187
+ to: "connecting",
1188
+ event: "START_CONNECT"
1189
+ /* START_CONNECT */
1190
+ }
1191
+ }
1192
+ }
1193
+ }
1194
+ },
1195
+ connecting: {
1196
+ entry: {
1197
+ type: "logStateChange",
1198
+ params: {
1199
+ state: "connecting"
1200
+ /* CONNECTING */
1201
+ }
1202
+ },
1203
+ on: {
1204
+ START_INIT_UA: {
1205
+ target: "initializing",
1206
+ actions: {
1207
+ type: "logTransition",
1208
+ params: {
1209
+ from: "connecting",
1210
+ to: "initializing",
1211
+ event: "START_INIT_UA"
1212
+ /* START_INIT_UA */
1213
+ // TODO: remove
1214
+ }
1215
+ }
1216
+ },
1217
+ UA_DISCONNECTED: {
1218
+ target: "disconnected",
1219
+ actions: {
1220
+ type: "logTransition",
1221
+ params: {
1222
+ from: "connecting",
1223
+ to: "disconnected",
1224
+ event: "UA_DISCONNECTED"
1225
+ /* UA_DISCONNECTED */
1226
+ }
1227
+ }
1228
+ },
1229
+ CONNECTION_FAILED: {
1230
+ target: "failed",
1231
+ actions: {
1232
+ type: "logTransition",
1233
+ params: {
1234
+ from: "connecting",
1235
+ to: "failed",
1236
+ event: "CONNECTION_FAILED"
1237
+ /* CONNECTION_FAILED */
1238
+ }
1239
+ }
1240
+ }
1241
+ }
1242
+ },
1243
+ initializing: {
1244
+ entry: {
1245
+ type: "logStateChange",
1246
+ params: {
1247
+ state: "initializing"
1248
+ /* INITIALIZING */
1249
+ }
1250
+ },
1251
+ on: {
1252
+ UA_CONNECTED: {
1253
+ target: "connected",
1254
+ actions: {
1255
+ type: "logTransition",
1256
+ params: {
1257
+ from: "initializing",
1258
+ to: "connected",
1259
+ event: "UA_CONNECTED"
1260
+ /* UA_CONNECTED */
1261
+ }
1262
+ }
1263
+ },
1264
+ UA_REGISTERED: {
1265
+ target: "registered",
1266
+ actions: {
1267
+ type: "logTransition",
1268
+ params: {
1269
+ from: "initializing",
1270
+ to: "registered",
1271
+ event: "UA_REGISTERED"
1272
+ /* UA_REGISTERED */
1273
+ }
1274
+ }
1275
+ },
1276
+ UA_DISCONNECTED: {
1277
+ target: "disconnected",
1278
+ actions: {
1279
+ type: "logTransition",
1280
+ params: {
1281
+ from: "initializing",
1282
+ to: "disconnected",
1283
+ event: "UA_DISCONNECTED"
1284
+ /* UA_DISCONNECTED */
1285
+ }
1286
+ }
1287
+ },
1288
+ CONNECTION_FAILED: {
1289
+ target: "failed",
1290
+ actions: {
1291
+ type: "logTransition",
1292
+ params: {
1293
+ from: "initializing",
1294
+ to: "failed",
1295
+ event: "CONNECTION_FAILED"
1296
+ /* CONNECTION_FAILED */
1297
+ }
1298
+ }
1299
+ }
1300
+ }
1301
+ },
1302
+ connected: {
1303
+ entry: {
1304
+ type: "logStateChange",
1305
+ params: {
1306
+ state: "connected"
1307
+ /* CONNECTED */
1308
+ }
1309
+ },
1310
+ on: {
1311
+ UA_REGISTERED: {
1312
+ target: "registered",
1313
+ actions: {
1314
+ type: "logTransition",
1315
+ params: {
1316
+ from: "connected",
1317
+ to: "registered",
1318
+ event: "UA_REGISTERED"
1319
+ /* UA_REGISTERED */
1320
+ }
1321
+ }
1322
+ },
1323
+ UA_DISCONNECTED: {
1324
+ target: "disconnected",
1325
+ actions: {
1326
+ type: "logTransition",
1327
+ params: {
1328
+ from: "connected",
1329
+ to: "disconnected",
1330
+ event: "UA_DISCONNECTED"
1331
+ /* UA_DISCONNECTED */
1332
+ }
1333
+ }
1334
+ },
1335
+ CONNECTION_FAILED: {
1336
+ target: "failed",
1337
+ actions: {
1338
+ type: "logTransition",
1339
+ params: {
1340
+ from: "connected",
1341
+ to: "failed",
1342
+ event: "CONNECTION_FAILED"
1343
+ /* CONNECTION_FAILED */
1344
+ }
1345
+ }
1346
+ }
1347
+ }
1348
+ },
1349
+ registered: {
1350
+ entry: {
1351
+ type: "logStateChange",
1352
+ params: {
1353
+ state: "registered"
1354
+ /* REGISTERED */
1355
+ }
1356
+ },
1357
+ on: {
1358
+ UA_UNREGISTERED: {
1359
+ target: "connected",
1360
+ actions: {
1361
+ type: "logTransition",
1362
+ params: {
1363
+ from: "registered",
1364
+ to: "connected",
1365
+ event: "UA_UNREGISTERED"
1366
+ /* UA_UNREGISTERED */
1367
+ }
1368
+ }
1369
+ },
1370
+ UA_DISCONNECTED: {
1371
+ target: "disconnected",
1372
+ actions: {
1373
+ type: "logTransition",
1374
+ params: {
1375
+ from: "registered",
1376
+ to: "disconnected",
1377
+ event: "UA_DISCONNECTED"
1378
+ /* UA_DISCONNECTED */
1379
+ }
1380
+ }
1381
+ },
1382
+ CONNECTION_FAILED: {
1383
+ target: "failed",
1384
+ actions: {
1385
+ type: "logTransition",
1386
+ params: {
1387
+ from: "registered",
1388
+ to: "failed",
1389
+ event: "CONNECTION_FAILED"
1390
+ /* CONNECTION_FAILED */
1391
+ }
1392
+ }
1393
+ }
1394
+ }
1395
+ },
1396
+ disconnected: {
1397
+ entry: {
1398
+ type: "logStateChange",
1399
+ params: {
1400
+ state: "disconnected"
1401
+ /* DISCONNECTED */
1402
+ }
1403
+ },
1404
+ on: {
1405
+ RESET: {
1406
+ target: "idle",
1407
+ actions: {
1408
+ type: "logTransition",
1409
+ params: {
1410
+ from: "disconnected",
1411
+ to: "idle",
1412
+ event: "RESET"
1413
+ /* RESET */
1414
+ }
1415
+ }
1416
+ },
1417
+ START_CONNECT: {
1418
+ target: "connecting",
1419
+ actions: {
1420
+ type: "logTransition",
1421
+ params: {
1422
+ from: "disconnected",
1423
+ to: "connecting",
1424
+ event: "START_CONNECT"
1425
+ /* START_CONNECT */
1426
+ }
1427
+ }
1428
+ }
1429
+ }
1430
+ },
1431
+ failed: {
1432
+ entry: {
1433
+ type: "logStateChange",
1434
+ params: {
1435
+ state: "failed"
1436
+ /* FAILED */
1437
+ }
1438
+ },
1439
+ on: {
1440
+ RESET: {
1441
+ target: "idle",
1442
+ actions: {
1443
+ type: "logTransition",
1444
+ params: {
1445
+ from: "failed",
1446
+ to: "idle",
1447
+ event: "RESET"
1448
+ /* RESET */
1449
+ }
1450
+ }
1451
+ },
1452
+ START_CONNECT: {
1453
+ target: "connecting",
1454
+ actions: {
1455
+ type: "logTransition",
1456
+ params: {
1457
+ from: "failed",
1458
+ to: "connecting",
1459
+ event: "START_CONNECT"
1460
+ /* START_CONNECT */
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ }
1466
+ }
1467
+ });
1468
+ class Re {
1469
+ actor;
1470
+ stateChangeListeners = /* @__PURE__ */ new Set();
1471
+ events;
1472
+ unsubscribeFromEvents;
1473
+ actorSubscription;
1474
+ constructor(e) {
1475
+ this.events = e, this.actor = Z(Ie), this.actorSubscription = this.actor.subscribe((t) => {
1476
+ const s = t.value;
1477
+ this.stateChangeListeners.forEach((i) => {
1478
+ i(s);
1479
+ });
1480
+ }), this.actor.start(), this.subscribeToEvents();
1481
+ }
1482
+ get state() {
1483
+ return this.actor.getSnapshot().value;
1484
+ }
1485
+ get isIdle() {
1486
+ return this.hasState(
1487
+ "idle"
1488
+ /* IDLE */
1489
+ );
1490
+ }
1491
+ get isConnecting() {
1492
+ return this.hasState(
1493
+ "connecting"
1494
+ /* CONNECTING */
1495
+ );
1496
+ }
1497
+ get isInitializing() {
1498
+ return this.hasState(
1499
+ "initializing"
1500
+ /* INITIALIZING */
1501
+ );
1502
+ }
1503
+ get isConnected() {
1504
+ return this.hasState(
1505
+ "connected"
1506
+ /* CONNECTED */
1507
+ );
1508
+ }
1509
+ get isRegistered() {
1510
+ return this.hasState(
1511
+ "registered"
1512
+ /* REGISTERED */
1513
+ );
1514
+ }
1515
+ get isDisconnected() {
1516
+ return this.hasState(
1517
+ "disconnected"
1518
+ /* DISCONNECTED */
1519
+ );
1520
+ }
1521
+ get isFailed() {
1522
+ return this.hasState(
1523
+ "failed"
1524
+ /* FAILED */
1525
+ );
1526
+ }
1527
+ get isPending() {
1528
+ return this.isConnecting || this.isInitializing;
1529
+ }
1530
+ get isPendingConnect() {
1531
+ return this.isConnecting;
1532
+ }
1533
+ get isPendingInitUa() {
1534
+ return this.isInitializing;
1535
+ }
1536
+ get isActiveConnection() {
1537
+ return this.isConnected || this.isRegistered;
1538
+ }
1539
+ // Публичные методы для уведомления о начале операций
1540
+ startConnect() {
1541
+ this.toStartConnect();
1542
+ }
1543
+ startInitUa() {
1544
+ this.toStartInitUa();
1545
+ }
1546
+ reset() {
1547
+ this.toIdle();
1548
+ }
1549
+ destroy() {
1550
+ this.unsubscribeFromEvents?.(), this.actorSubscription?.unsubscribe(), this.actor.stop();
1551
+ }
1552
+ onStateChange(e) {
1553
+ return this.stateChangeListeners.add(e), () => {
1554
+ this.stateChangeListeners.delete(e);
1555
+ };
1556
+ }
1557
+ canTransition(e) {
1558
+ return this.actor.getSnapshot().can({ type: e });
1559
+ }
1560
+ getValidEvents() {
1561
+ return Object.values(X).filter((e) => this.canTransition(e));
1562
+ }
1563
+ hasState(e) {
1564
+ return this.actor.getSnapshot().matches(e);
1565
+ }
1566
+ sendEvent(e) {
1567
+ const t = this.actor.getSnapshot(), s = { type: e };
1568
+ if (!t.can(s)) {
1569
+ m(
1570
+ `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
1571
+ );
1572
+ return;
1573
+ }
1574
+ this.actor.send(s);
1575
+ }
1576
+ toStartConnect = () => {
1577
+ this.sendEvent(
1578
+ "START_CONNECT"
1579
+ /* START_CONNECT */
1580
+ );
1581
+ };
1582
+ toStartInitUa = () => {
1583
+ this.sendEvent(
1584
+ "START_INIT_UA"
1585
+ /* START_INIT_UA */
1586
+ );
1587
+ };
1588
+ toConnected = () => {
1589
+ this.sendEvent(
1590
+ "UA_CONNECTED"
1591
+ /* UA_CONNECTED */
1592
+ );
1593
+ };
1594
+ toRegistered = () => {
1595
+ this.sendEvent(
1596
+ "UA_REGISTERED"
1597
+ /* UA_REGISTERED */
1598
+ );
1599
+ };
1600
+ toUnregistered = () => {
1601
+ this.sendEvent(
1602
+ "UA_UNREGISTERED"
1603
+ /* UA_UNREGISTERED */
1604
+ );
1605
+ };
1606
+ toDisconnected = () => {
1607
+ this.sendEvent(
1608
+ "UA_DISCONNECTED"
1609
+ /* UA_DISCONNECTED */
1610
+ );
1611
+ };
1612
+ toFailed = () => {
1613
+ this.sendEvent(
1614
+ "CONNECTION_FAILED"
1615
+ /* CONNECTION_FAILED */
1616
+ );
1617
+ };
1618
+ toIdle = () => {
1619
+ this.sendEvent(
1620
+ "RESET"
1621
+ /* RESET */
1622
+ );
1623
+ };
1624
+ subscribeToEvents() {
1625
+ this.events.on("connected", this.toConnected), this.events.on("registered", this.toRegistered), this.events.on("unregistered", this.toUnregistered), this.events.on("disconnected", this.toDisconnected), this.events.on("registrationFailed", this.toFailed), this.unsubscribeFromEvents = () => {
1626
+ this.events.off("connected", this.toConnected), this.events.off("registered", this.toRegistered), this.events.off("unregistered", this.toUnregistered), this.events.off("disconnected", this.toDisconnected), this.events.off("registrationFailed", this.toFailed);
1627
+ };
1628
+ }
1629
+ }
1630
+ class Me {
1631
+ events;
1632
+ getUaProtected;
1633
+ constructor(e) {
1634
+ this.events = e.events, this.getUaProtected = e.getUaProtected;
1635
+ }
1636
+ async register() {
1637
+ const e = this.getUaProtected();
1638
+ return new Promise((t, s) => {
1639
+ e.on(u.REGISTERED, t), e.on(u.REGISTRATION_FAILED, s), e.register();
1640
+ });
1641
+ }
1642
+ async unregister() {
1643
+ const e = this.getUaProtected();
1644
+ return new Promise((t) => {
1645
+ e.on(u.UNREGISTERED, t), e.unregister();
1646
+ });
1647
+ }
1648
+ async tryRegister() {
1649
+ try {
1650
+ await this.unregister();
1651
+ } catch (e) {
1652
+ m("tryRegister", e);
1653
+ }
1654
+ return this.register();
1655
+ }
1656
+ subscribeToStartEvents(e, t) {
1657
+ const s = u.REGISTERED, i = [u.REGISTRATION_FAILED, u.DISCONNECTED];
1658
+ return this.events.on(s, e), i.forEach((r) => {
1659
+ this.events.on(r, t);
1660
+ }), () => {
1661
+ this.events.off(s, e), i.forEach((r) => {
1662
+ this.events.off(r, t);
1663
+ });
1664
+ };
1665
+ }
1666
+ }
1667
+ class pe {
1668
+ uaFactory;
1669
+ getUaProtected;
1670
+ constructor(e) {
1671
+ this.uaFactory = e.uaFactory, this.getUaProtected = e.getUaProtected;
1672
+ }
1673
+ /**
1674
+ * Отправляет SIP OPTIONS запрос к указанному адресу
1675
+ */
1676
+ async sendOptions(e, t, s) {
1677
+ const i = this.getUaProtected();
1678
+ return new Promise((r, a) => {
1679
+ try {
1680
+ i.sendOptions(e, t, {
1681
+ extraHeaders: s,
1682
+ eventHandlers: {
1683
+ succeeded: () => {
1684
+ r();
1685
+ },
1686
+ failed: a
1687
+ }
1688
+ });
1689
+ } catch (o) {
1690
+ a(o);
1691
+ }
1692
+ });
1693
+ }
1694
+ /**
1695
+ * Отправляет SIP OPTIONS запрос к собственному URI (ping)
1696
+ */
1697
+ async ping(e, t) {
1698
+ const i = this.getUaProtected().configuration.uri;
1699
+ return this.sendOptions(i, e, t);
1700
+ }
1701
+ /**
1702
+ * Проверяет доступность телефонии, создавая временное соединение
1703
+ */
1704
+ async checkTelephony({
1705
+ userAgent: e,
1706
+ displayName: t,
1707
+ sipServerUrl: s,
1708
+ sipWebSocketServerURL: i,
1709
+ remoteAddress: r,
1710
+ extraHeaders: a
1711
+ }) {
1712
+ return new Promise((o, c) => {
1713
+ const { configuration: g } = this.uaFactory.createConfiguration({
1714
+ sipWebSocketServerURL: i,
1715
+ displayName: t,
1716
+ userAgent: e,
1717
+ sipServerUrl: s
1718
+ }), d = this.uaFactory.createUA({ ...g, remoteAddress: r, extraHeaders: a }), l = () => {
1719
+ const S = new Error("Telephony is not available");
1720
+ c(S);
1721
+ };
1722
+ d.once(u.DISCONNECTED, l);
1723
+ const E = () => {
1724
+ d.removeAllListeners(), d.once(u.DISCONNECTED, () => {
1725
+ o();
1726
+ }), d.stop();
1727
+ };
1728
+ d.once(u.CONNECTED, E), d.start();
1729
+ });
1730
+ }
1731
+ }
1732
+ const Pe = (n) => {
1733
+ const e = [];
1734
+ return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1735
+ };
1736
+ class P {
1737
+ JsSIP;
1738
+ constructor(e) {
1739
+ this.JsSIP = e;
1740
+ }
1741
+ static isRegisteredUA(e) {
1742
+ return !!e && e.isRegistered();
1743
+ }
1744
+ static validateConfiguration({
1745
+ register: e,
1746
+ password: t,
1747
+ user: s,
1748
+ sipServerUrl: i,
1749
+ sipWebSocketServerURL: r
1750
+ }) {
1751
+ if (!i)
1752
+ throw new Error("sipServerUrl is required");
1753
+ if (!r)
1754
+ throw new Error("sipWebSocketServerURL is required");
1755
+ if (e && (t === void 0 || t === ""))
1756
+ throw new Error("password is required for authorized connection");
1757
+ if (e && (s === void 0 || s === ""))
1758
+ throw new Error("user is required for authorized connection");
1759
+ }
1760
+ static resolveAuthorizationUser(e, t) {
1761
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${se()}`;
1762
+ }
1763
+ static buildExtraHeaders(e, t) {
1764
+ const s = e !== void 0 && e !== "" ? Pe(e) : [];
1765
+ return t === void 0 ? s : [...s, ...t];
1766
+ }
1767
+ createConfiguration({
1768
+ user: e,
1769
+ password: t,
1770
+ sipWebSocketServerURL: s,
1771
+ displayName: i = "",
1772
+ sipServerUrl: r,
1773
+ register: a = !1,
1774
+ sessionTimers: o = !1,
1775
+ registerExpires: c = 300,
1776
+ // 5 minutes in sec
1777
+ connectionRecoveryMinInterval: g = 2,
1778
+ connectionRecoveryMaxInterval: d = 6,
1779
+ userAgent: l
1780
+ }) {
1781
+ P.validateConfiguration({
1782
+ register: a,
1783
+ password: t,
1784
+ user: e,
1785
+ sipServerUrl: r,
1786
+ sipWebSocketServerURL: s
1787
+ });
1788
+ const E = P.resolveAuthorizationUser(a, e), S = te(r), I = S(E), C = new this.JsSIP.WebSocketInterface(s);
1789
+ return {
1790
+ configuration: {
1791
+ password: t,
1792
+ register: a,
1793
+ uri: I,
1794
+ display_name: B(i),
1795
+ user_agent: l,
1796
+ sdpSemantics: "unified-plan",
1797
+ sockets: [C],
1798
+ session_timers: o,
1799
+ register_expires: c,
1800
+ connection_recovery_min_interval: g,
1801
+ connection_recovery_max_interval: d
1802
+ },
1803
+ helpers: {
1804
+ socket: C,
1805
+ getSipServerUrl: S
1806
+ }
1807
+ };
1808
+ }
1809
+ createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
1810
+ const i = new this.JsSIP.UA(s), r = P.buildExtraHeaders(e, t);
1811
+ return r.length > 0 && i.registrator().setExtraHeaders(r), i;
1812
+ }
1813
+ /**
1814
+ * Создает UA с полным жизненным циклом - конфигурация + создание + настройка событий
1815
+ */
1816
+ createUAWithConfiguration(e, t) {
1817
+ const { configuration: s, helpers: i } = this.createConfiguration(e), r = this.createUA({
1818
+ ...s,
1819
+ remoteAddress: e.remoteAddress,
1820
+ extraHeaders: e.extraHeaders
1821
+ });
1822
+ return t.eachTriggers((a, o) => {
1823
+ const c = z.find((g) => g === o);
1824
+ c && r.on(c, a);
1825
+ }), { ua: r, helpers: i };
1826
+ }
1827
+ }
1828
+ class me {
1829
+ events;
1830
+ ua;
1831
+ socket;
1832
+ uaFactory;
1833
+ registrationManager;
1834
+ stateMachine;
1835
+ connectionFlow;
1836
+ sipOperations;
1837
+ configurationManager;
1838
+ JsSIP;
1839
+ constructor({ JsSIP: e }) {
1840
+ this.JsSIP = e, this.events = new O(Q), this.uaFactory = new P(e), this.registrationManager = new Me({
1841
+ events: this.events,
1842
+ getUaProtected: this.getUaProtected
1843
+ }), this.stateMachine = new Re(this.events), this.configurationManager = new ue({
1844
+ getUa: this.getUa
1845
+ }), this.sipOperations = new pe({
1846
+ uaFactory: this.uaFactory,
1847
+ getUaProtected: this.getUaProtected
1848
+ }), this.connectionFlow = new _e({
1849
+ JsSIP: this.JsSIP,
1850
+ events: this.events,
1851
+ uaFactory: this.uaFactory,
1852
+ stateMachine: this.stateMachine,
1853
+ registrationManager: this.registrationManager,
1854
+ getUa: this.getUa,
1855
+ getConnectionConfiguration: this.getConnectionConfiguration,
1856
+ setConnectionConfiguration: (t) => {
1857
+ this.configurationManager.set(t);
1858
+ },
1859
+ updateConnectionConfiguration: (t, s) => {
1860
+ this.configurationManager.update(t, s);
1861
+ },
1862
+ setUa: (t) => {
1863
+ this.ua = t;
1864
+ },
1865
+ setSipServerUrl: (t) => {
1866
+ this.getSipServerUrl = t;
1867
+ },
1868
+ setSocket: (t) => {
1869
+ this.socket = t;
1870
+ }
1871
+ });
1872
+ }
1873
+ get requested() {
1874
+ return this.stateMachine.isPending;
1875
+ }
1876
+ get isPendingConnect() {
1877
+ return this.stateMachine.isPendingConnect;
1878
+ }
1879
+ get isPendingInitUa() {
1880
+ return this.stateMachine.isPendingInitUa;
1881
+ }
1882
+ get connectionState() {
1883
+ return this.stateMachine.state;
1884
+ }
1885
+ get isRegistered() {
1886
+ return P.isRegisteredUA(this.ua);
1887
+ }
1888
+ get isRegisterConfig() {
1889
+ return this.configurationManager.isRegister();
1890
+ }
1891
+ connect = async (e, t) => this.connectionFlow.connect(e, t);
1892
+ set = async ({ displayName: e }) => this.connectionFlow.set({ displayName: e });
1893
+ disconnect = async () => this.connectionFlow.disconnect();
1894
+ async register() {
1895
+ return this.registrationManager.register();
1896
+ }
1897
+ async unregister() {
1898
+ return this.registrationManager.unregister();
1899
+ }
1900
+ tryRegister = async () => this.registrationManager.tryRegister();
1901
+ sendOptions = async (e, t, s) => this.sipOperations.sendOptions(e, t, s);
1902
+ ping = async (e, t) => this.sipOperations.ping(e, t);
1903
+ checkTelephony = async (e) => this.sipOperations.checkTelephony(e);
1904
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1905
+ on(e, t) {
1906
+ return this.events.on(e, t);
1907
+ }
1908
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1909
+ once(e, t) {
1910
+ return this.events.once(e, t);
1911
+ }
1912
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1913
+ onceRace(e, t) {
1914
+ return this.events.onceRace(e, t);
1915
+ }
1916
+ async wait(e) {
1917
+ return this.events.wait(e);
1918
+ }
1919
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1920
+ off(e, t) {
1921
+ this.events.off(e, t);
1922
+ }
1923
+ isConfigured() {
1924
+ return this.configurationManager.isConfigured();
1925
+ }
1926
+ getConnectionConfiguration = () => this.configurationManager.get();
1927
+ destroy() {
1928
+ this.stateMachine.destroy();
1929
+ }
1930
+ // eslint-disable-next-line class-methods-use-this
1931
+ getSipServerUrl = (e) => e;
1932
+ getUaProtected = () => {
1933
+ if (!this.ua)
1934
+ throw new Error("UA not initialized");
1935
+ return this.ua;
1936
+ };
1937
+ getUa = () => this.ua;
1938
+ }
1939
+ var D = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(D || {}), $ = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))($ || {});
1940
+ const J = [
1941
+ "incomingCall",
1942
+ "declinedIncomingCall",
1943
+ "terminatedIncomingCall",
1944
+ "failedIncomingCall"
1945
+ ], Oe = 486, fe = 487;
1946
+ class De {
1947
+ events;
1948
+ incomingRTCSession;
1949
+ connectionManager;
1950
+ constructor(e) {
1951
+ this.connectionManager = e, this.events = new O(J), this.start();
1952
+ }
1953
+ get remoteCallerData() {
1954
+ return {
1955
+ displayName: this.incomingRTCSession?.remote_identity.display_name,
1956
+ host: this.incomingRTCSession?.remote_identity.uri.host,
1957
+ incomingNumber: this.incomingRTCSession?.remote_identity.uri.user,
1958
+ rtcSession: this.incomingRTCSession
1959
+ };
1960
+ }
1961
+ get isAvailableIncomingCall() {
1962
+ return !!this.incomingRTCSession;
1963
+ }
1964
+ start() {
1965
+ this.subscribe();
1966
+ }
1967
+ stop() {
1968
+ this.unsubscribe(), this.removeIncomingSession();
1969
+ }
1970
+ getIncomingRTCSession = () => {
1971
+ const { incomingRTCSession: e } = this;
1972
+ if (!e)
1973
+ throw new Error("No incomingRTCSession");
1974
+ return e;
1975
+ };
1976
+ extractIncomingRTCSession = () => {
1977
+ const e = this.getIncomingRTCSession();
1978
+ return this.removeIncomingSession(), e;
1979
+ };
1980
+ async declineToIncomingCall({
1981
+ statusCode: e = fe
1982
+ } = {}) {
1983
+ return new Promise((t, s) => {
1984
+ try {
1985
+ const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
1986
+ this.removeIncomingSession(), this.events.trigger(D.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
1987
+ } catch (i) {
1988
+ s(i);
1989
+ }
1990
+ });
1991
+ }
1992
+ async busyIncomingCall() {
1993
+ return this.declineToIncomingCall({ statusCode: Oe });
1994
+ }
1995
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
1996
+ on(e, t) {
1997
+ return this.events.on(e, t);
1998
+ }
1999
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2000
+ once(e, t) {
2001
+ return this.events.once(e, t);
2002
+ }
2003
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2004
+ onceRace(e, t) {
2005
+ return this.events.onceRace(e, t);
2006
+ }
2007
+ async wait(e) {
2008
+ return this.events.wait(e);
2009
+ }
2010
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2011
+ off(e, t) {
2012
+ this.events.off(e, t);
2013
+ }
2014
+ subscribe() {
2015
+ this.connectionManager.on("newRTCSession", this.handleNewRTCSession);
2016
+ }
2017
+ unsubscribe() {
2018
+ this.connectionManager.off("newRTCSession", this.handleNewRTCSession);
2019
+ }
2020
+ handleNewRTCSession = ({
2021
+ originator: e,
2022
+ session: t
2023
+ }) => {
2024
+ e === $.REMOTE && this.setIncomingSession(t);
2025
+ };
2026
+ setIncomingSession(e) {
2027
+ this.incomingRTCSession = e;
2028
+ const t = this.remoteCallerData;
2029
+ e.on("failed", (s) => {
2030
+ this.removeIncomingSession(), s.originator === $.LOCAL ? this.events.trigger(D.TERMINATED_INCOMING_CALL, t) : this.events.trigger(D.FAILED_INCOMING_CALL, t);
2031
+ }), this.events.trigger(D.INCOMING_CALL, t);
2032
+ }
2033
+ removeIncomingSession() {
2034
+ delete this.incomingRTCSession;
2035
+ }
2036
+ }
2037
+ const ve = Q.map((n) => `connection:${n}`), ye = G.map((n) => `call:${n}`), Ue = q.map((n) => `api:${n}`), be = J.map((n) => `incoming-call:${n}`), we = Y.map((n) => `presentation:${n}`), Le = [
2038
+ ...ve,
2039
+ ...ye,
2040
+ ...Ue,
2041
+ ...be,
2042
+ ...we
2043
+ ];
2044
+ class xe {
2045
+ events;
2046
+ connectionManager;
2047
+ callManager;
2048
+ apiManager;
2049
+ incomingCallManager;
2050
+ presentationManager;
2051
+ constructor({ JsSIP: e }) {
2052
+ this.events = new O(Le), this.connectionManager = new me({ JsSIP: e }), this.callManager = new ge(), this.apiManager = new le({
2053
+ connectionManager: this.connectionManager,
2054
+ callManager: this.callManager
2055
+ }), this.incomingCallManager = new De(this.connectionManager), this.presentationManager = new Ne({
2056
+ callManager: this.callManager
2057
+ }), this.subscribe();
2058
+ }
2059
+ get requestedConnection() {
2060
+ return this.connectionManager.requested;
2061
+ }
2062
+ get isPendingConnect() {
2063
+ return this.connectionManager.isPendingConnect;
2064
+ }
2065
+ get isPendingInitUa() {
2066
+ return this.connectionManager.isPendingInitUa;
2067
+ }
2068
+ get connectionState() {
2069
+ return this.connectionManager.connectionState;
2070
+ }
2071
+ get isRegistered() {
2072
+ return this.connectionManager.isRegistered;
2073
+ }
2074
+ get isRegisterConfig() {
2075
+ return this.connectionManager.isRegisterConfig;
2076
+ }
2077
+ get socket() {
2078
+ return this.connectionManager.socket;
2079
+ }
2080
+ get requestedCall() {
2081
+ return this.callManager.requested;
2082
+ }
2083
+ get connection() {
2084
+ return this.callManager.connection;
2085
+ }
2086
+ get establishedRTCSession() {
2087
+ return this.callManager.establishedRTCSession;
2088
+ }
2089
+ get isCallActive() {
2090
+ return this.callManager.isCallActive;
2091
+ }
2092
+ get remoteCallerData() {
2093
+ return this.incomingCallManager.remoteCallerData;
2094
+ }
2095
+ get isAvailableIncomingCall() {
2096
+ return this.incomingCallManager.isAvailableIncomingCall;
2097
+ }
2098
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2099
+ on(e, t) {
2100
+ return this.events.on(e, t);
2101
+ }
2102
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2103
+ once(e, t) {
2104
+ return this.events.once(e, t);
2105
+ }
2106
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2107
+ onceRace(e, t) {
2108
+ return this.events.onceRace(e, t);
2109
+ }
2110
+ async wait(e) {
2111
+ return this.events.wait(e);
2112
+ }
2113
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2114
+ off(e, t) {
2115
+ this.events.off(e, t);
2116
+ }
2117
+ connect = async (...e) => this.connectionManager.connect(...e);
2118
+ set = async (...e) => this.connectionManager.set(...e);
2119
+ disconnect = async () => this.connectionManager.disconnect();
2120
+ register = async () => this.connectionManager.register();
2121
+ unregister = async () => this.connectionManager.unregister();
2122
+ tryRegister = async () => this.connectionManager.tryRegister();
2123
+ sendOptions = async (e, t, s) => this.connectionManager.sendOptions(e, t, s);
2124
+ ping = async (e, t) => this.connectionManager.ping(e, t);
2125
+ checkTelephony = async (e) => this.connectionManager.checkTelephony(e);
2126
+ isConfigured = () => this.connectionManager.isConfigured();
2127
+ getConnectionConfiguration = () => this.connectionManager.getConnectionConfiguration();
2128
+ getSipServerUrl = (e) => this.connectionManager.getSipServerUrl(e);
2129
+ call = async (e) => this.callManager.startCall(
2130
+ this.connectionManager.getUaProtected(),
2131
+ this.getSipServerUrl,
2132
+ e
2133
+ );
2134
+ hangUp = async () => this.callManager.endCall();
2135
+ answerToIncomingCall = async (e) => this.callManager.answerToIncomingCall(
2136
+ this.incomingCallManager.extractIncomingRTCSession,
2137
+ e
2138
+ );
2139
+ declineToIncomingCall = async (...e) => this.incomingCallManager.declineToIncomingCall(...e);
2140
+ getEstablishedRTCSession = () => this.callManager.getEstablishedRTCSession();
2141
+ getCallConfiguration = () => this.callManager.getCallConfiguration();
2142
+ getRemoteStreams = () => this.callManager.getRemoteStreams();
2143
+ replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
2144
+ async startPresentation(e, t = {}) {
2145
+ const { isP2P: s, callLimit: i, ...r } = t;
2146
+ return this.presentationManager.startPresentation(
2147
+ async () => {
2148
+ s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
2149
+ },
2150
+ e,
2151
+ r,
2152
+ i === void 0 ? void 0 : { callLimit: i }
2153
+ );
2154
+ }
2155
+ async stopPresentation(e = {}) {
2156
+ const { isP2P: t } = e;
2157
+ return this.presentationManager.stopPresentation(async () => {
2158
+ t === !0 ? await this.apiManager.sendMustStopPresentationP2P() : await this.apiManager.sendStoppedPresentation();
2159
+ });
2160
+ }
2161
+ async updatePresentation(e, t = {}) {
2162
+ const { isP2P: s, ...i } = t;
2163
+ return this.presentationManager.updatePresentation(
2164
+ async () => {
2165
+ s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
2166
+ },
2167
+ e,
2168
+ i
2169
+ );
2170
+ }
2171
+ async waitChannels(...e) {
2172
+ return this.apiManager.waitChannels(...e);
2173
+ }
2174
+ async waitSyncMediaState(...e) {
2175
+ return this.apiManager.waitSyncMediaState(...e);
2176
+ }
2177
+ async sendDTMF(...e) {
2178
+ return this.apiManager.sendDTMF(...e);
2179
+ }
2180
+ async sendChannels(...e) {
2181
+ return this.apiManager.sendChannels(...e);
2182
+ }
2183
+ async sendMediaState(...e) {
2184
+ return this.apiManager.sendMediaState(...e);
2185
+ }
2186
+ async sendRefusalToTurnOn(...e) {
2187
+ return this.apiManager.sendRefusalToTurnOn(...e);
2188
+ }
2189
+ async sendRefusalToTurnOnMic(...e) {
2190
+ return this.apiManager.sendRefusalToTurnOnMic(...e);
2191
+ }
2192
+ async sendRefusalToTurnOnCam(...e) {
2193
+ return this.apiManager.sendRefusalToTurnOnCam(...e);
2194
+ }
2195
+ async sendMustStopPresentationP2P(...e) {
2196
+ return this.apiManager.sendMustStopPresentationP2P(...e);
2197
+ }
2198
+ async sendStoppedPresentationP2P(...e) {
2199
+ return this.apiManager.sendStoppedPresentationP2P(...e);
2200
+ }
2201
+ async sendStoppedPresentation(...e) {
2202
+ return this.apiManager.sendStoppedPresentation(...e);
2203
+ }
2204
+ async askPermissionToStartPresentationP2P(...e) {
2205
+ return this.apiManager.askPermissionToStartPresentationP2P(...e);
2206
+ }
2207
+ async askPermissionToStartPresentation(...e) {
2208
+ return this.apiManager.askPermissionToStartPresentation(...e);
2209
+ }
2210
+ async askPermissionToEnableCam(...e) {
2211
+ return this.apiManager.askPermissionToEnableCam(...e);
2212
+ }
2213
+ subscribe() {
2214
+ this.connectionManager.events.eachTriggers((e, t) => {
2215
+ this.connectionManager.on(t, (s) => {
2216
+ this.events.trigger(`connection:${t}`, s);
2217
+ });
2218
+ }), this.callManager.events.eachTriggers((e, t) => {
2219
+ this.callManager.on(t, (s) => {
2220
+ this.events.trigger(`call:${t}`, s);
2221
+ });
2222
+ }), this.apiManager.events.eachTriggers((e, t) => {
2223
+ this.apiManager.on(t, (s) => {
2224
+ this.events.trigger(`api:${t}`, s);
2225
+ });
2226
+ }), this.incomingCallManager.events.eachTriggers((e, t) => {
2227
+ this.incomingCallManager.on(t, (s) => {
2228
+ this.events.trigger(`incoming-call:${t}`, s);
2229
+ });
2230
+ }), this.presentationManager.events.eachTriggers((e, t) => {
2231
+ this.presentationManager.on(t, (s) => {
2232
+ this.events.trigger(`presentation:${t}`, s);
2233
+ });
2234
+ });
2235
+ }
2236
+ }
2237
+ export {
2238
+ x as E,
2239
+ U as O,
2240
+ xe as S,
2241
+ f as a,
2242
+ Se as b,
2243
+ Ge as d,
2244
+ He as e,
2245
+ Be as h,
2246
+ m as l
2247
+ };