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