sip-connector 14.1.0-alpha.9 → 14.1.1

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