sip-connector 17.0.0 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/@SipConnector-CFYT0HQB.cjs +1 -0
  2. package/dist/{@SipConnector-DADbRZIb.js → @SipConnector-UTHCoMXw.js} +882 -896
  3. package/dist/ApiManager/__tests-utils__/helpers.d.ts +2 -4
  4. package/dist/ApiManager/constants.d.ts +1 -2
  5. package/dist/ApiManager/eventNames.d.ts +1 -2
  6. package/dist/CallManager/@CallManager.d.ts +6 -7
  7. package/dist/CallManager/AbstractCallStrategy.d.ts +2 -6
  8. package/dist/CallManager/MCUCallStrategy.d.ts +1 -9
  9. package/dist/CallManager/eventNames.d.ts +42 -2
  10. package/dist/CallManager/index.d.ts +3 -3
  11. package/dist/CallManager/types.d.ts +1 -13
  12. package/dist/SipConnector/@SipConnector.d.ts +4 -2
  13. package/dist/SipConnector/eventNames.d.ts +1 -1
  14. package/dist/SipConnectorFacade/index.d.ts +1 -1
  15. package/dist/StatsPeerConnection/index.d.ts +1 -1
  16. package/dist/{CallManager/TransceiverManager.d.ts → TransceiverManager/@TransceiverManager.d.ts} +19 -0
  17. package/dist/TransceiverManager/index.d.ts +1 -0
  18. package/dist/TransceiverManager/types.d.ts +11 -0
  19. package/dist/VideoSendingBalancer/index.d.ts +1 -1
  20. package/dist/__fixtures__/eventNames.d.ts +1 -1
  21. package/dist/doMock.cjs +1 -1
  22. package/dist/doMock.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +83 -83
  25. package/package.json +9 -9
  26. package/dist/@SipConnector-aB66gnC6.cjs +0 -1
  27. /package/dist/SipConnectorFacade/{SipConnectorFacade.d.ts → @SipConnectorFacade.d.ts} +0 -0
  28. /package/dist/StatsPeerConnection/{StatsPeerConnection.d.ts → @StatsPeerConnection.d.ts} +0 -0
  29. /package/dist/VideoSendingBalancer/{VideoSendingBalancer.d.ts → @VideoSendingBalancer.d.ts} +0 -0
@@ -1,439 +1,19 @@
1
- import { Events as D, TypedEvents as K } from "events-constructor";
2
- import { CancelableRequest as Re } from "@krivega/cancelable-promise";
3
- import q from "debug";
4
- import { hasCanceledError as Ie, repeatedCallsAsync as j } from "repeated-calls";
5
- import { setup as _e, createActor as me } from "xstate";
6
- import { createStackPromises as Z } from "stack-promises";
7
- import { SetTimeoutRequest as ee } from "@krivega/timeout-requester";
1
+ import { Events as w, TypedEvents as H } from "events-constructor";
2
+ import x from "debug";
3
+ import { hasCanceledError as Ne, repeatedCallsAsync as J } from "repeated-calls";
4
+ import { setup as Ae, createActor as Re } from "xstate";
5
+ import { createStackPromises as K } from "stack-promises";
6
+ import { CancelableRequest as Ie } from "@krivega/cancelable-promise";
7
+ import { SetTimeoutRequest as j } from "@krivega/timeout-requester";
8
8
  import "ua-parser-js";
9
9
  import "sequent-promises";
10
- 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 || {}), F = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(F || {});
11
- const te = [
12
- "peerconnection",
13
- "connecting",
14
- "sending",
15
- "progress",
16
- "accepted",
17
- "confirmed",
18
- "ended",
19
- "failed",
20
- "newInfo",
21
- "newDTMF",
22
- "presentation:start",
23
- "presentation:started",
24
- "presentation:end",
25
- "presentation:ended",
26
- "presentation:failed",
27
- "reinvite",
28
- "update",
29
- "refer",
30
- "replaces",
31
- "sdp",
32
- "icecandidate",
33
- "getusermediafailed",
34
- "peerconnection:createofferfailed",
35
- "peerconnection:createanswerfailed",
36
- "peerconnection:setlocaldescriptionfailed",
37
- "peerconnection:setremotedescriptionfailed"
38
- ], Me = [
39
- "peerconnection:confirmed",
40
- "peerconnection:ontrack",
41
- "ended:fromserver"
42
- ], ne = [
43
- ...te,
44
- ...Me
45
- ], pe = (n, e) => {
46
- n.getVideoTracks().forEach((s) => {
47
- "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
48
- });
49
- }, L = (n, {
50
- directionVideo: e,
51
- directionAudio: t,
52
- contentHint: s
53
- } = {}) => {
54
- if (!n || e === "recvonly" && t === "recvonly")
55
- return;
56
- const r = t === "recvonly" ? [] : n.getAudioTracks(), i = e === "recvonly" ? [] : n.getVideoTracks(), a = [...r, ...i], o = new MediaStream(a);
57
- return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && pe(o, s), o;
58
- };
59
- function Pe(n) {
60
- return (e) => `sip:${e}@${n}`;
61
- }
62
- const ve = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, se = (n) => n.trim().replaceAll(" ", "_"), fe = ve(1e5, 99999999), Oe = (n) => n.some((t) => {
63
- const { kind: s } = t;
64
- return s === "video";
65
- });
66
- class De {
67
- isPendingCall = !1;
68
- isPendingAnswer = !1;
69
- rtcSession;
70
- remoteStreams = {};
71
- events;
72
- callConfiguration = {};
73
- constructor(e) {
74
- this.events = e;
75
- }
76
- }
77
- var re = /* @__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))(re || {});
78
- class ye {
79
- remoteStreams = {};
80
- reset() {
81
- this.remoteStreams = {};
82
- }
83
- generateStream(e, t) {
84
- const { id: s } = e, r = this.remoteStreams[s] ?? new MediaStream();
85
- return t && r.addTrack(t), r.addTrack(e), this.remoteStreams[s] = r, r;
86
- }
87
- generateAudioStream(e) {
88
- const { id: t } = e, s = this.remoteStreams[t] ?? new MediaStream();
89
- return s.addTrack(e), this.remoteStreams[t] = s, s;
90
- }
91
- generateStreams(e) {
92
- const t = [];
93
- return e.forEach((s, r) => {
94
- if (s.kind === "audio")
95
- return;
96
- const i = s, a = e[r - 1];
97
- let o;
98
- a?.kind === "audio" && (o = a);
99
- const c = this.generateStream(i, o);
100
- t.push(c);
101
- }), t;
102
- }
103
- generateAudioStreams(e) {
104
- return e.map((t) => this.generateAudioStream(t));
105
- }
106
- }
107
- class be {
108
- /**
109
- * Хранилище основных transceiver'ов
110
- */
111
- transceivers = {};
112
- /**
113
- * Сохраняет transceiver в соответствующем хранилище в зависимости от типа трека и mid
114
- */
115
- storeTransceiver(e, t) {
116
- const { kind: s } = t;
117
- if (s === "audio")
118
- this.transceivers.mainAudio ??= e;
119
- else {
120
- const { mid: r } = e;
121
- r === "2" ? this.transceivers.presentationVideo ??= e : this.transceivers.mainVideo ??= e;
122
- }
123
- }
124
- /**
125
- * Возвращает все сохраненные transceiver'ы
126
- */
127
- getTransceivers() {
128
- return { ...this.transceivers };
129
- }
130
- /**
131
- * Возвращает основной аудио transceiver
132
- */
133
- getMainAudioTransceiver() {
134
- return this.transceivers.mainAudio;
135
- }
136
- /**
137
- * Возвращает основной видео transceiver
138
- */
139
- getMainVideoTransceiver() {
140
- return this.transceivers.mainVideo;
141
- }
142
- /**
143
- * Возвращает презентационный видео transceiver
144
- */
145
- getPresentationVideoTransceiver() {
146
- return this.transceivers.presentationVideo;
147
- }
148
- /**
149
- * Проверяет, есть ли сохраненный transceiver для указанного типа
150
- */
151
- hasTransceiver(e) {
152
- return this.transceivers[e] !== void 0;
153
- }
154
- /**
155
- * Очищает все сохраненные transceiver'ы
156
- */
157
- clear() {
158
- this.transceivers.mainVideo = void 0, this.transceivers.mainAudio = void 0, this.transceivers.presentationVideo = void 0;
159
- }
160
- /**
161
- * Возвращает количество сохраненных transceiver'ов
162
- */
163
- getCount() {
164
- let e = 0;
165
- return this.transceivers.mainAudio && (e += 1), this.transceivers.mainVideo && (e += 1), this.transceivers.presentationVideo && (e += 1), e;
166
- }
167
- /**
168
- * Проверяет, пустое ли хранилище
169
- */
170
- isEmpty() {
171
- return this.getCount() === 0;
172
- }
173
- }
174
- class Ue extends De {
175
- remoteStreamsManager = new ye();
176
- disposers = /* @__PURE__ */ new Set();
177
- /**
178
- * Менеджер для управления transceiver'ами
179
- */
180
- transceiverManager = new be();
181
- constructor(e) {
182
- super(e), e.on(N.FAILED, this.handleEnded), e.on(N.ENDED, this.handleEnded);
183
- }
184
- get requested() {
185
- return this.isPendingCall || this.isPendingAnswer;
186
- }
187
- get connection() {
188
- return this.rtcSession?.connection;
189
- }
190
- get isCallActive() {
191
- return this.rtcSession?.isEstablished() === !0;
192
- }
193
- get establishedRTCSession() {
194
- return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
195
- }
196
- startCall = async (e, t, {
197
- number: s,
198
- mediaStream: r,
199
- extraHeaders: i = [],
200
- ontrack: a,
201
- iceServers: o,
202
- directionVideo: c,
203
- directionAudio: d,
204
- contentHint: u,
205
- offerToReceiveAudio: T = !0,
206
- offerToReceiveVideo: g = !0,
207
- degradationPreference: S,
208
- sendEncodings: I,
209
- onAddedTransceiver: _
210
- }) => (this.isPendingCall = !0, new Promise((R, y) => {
211
- this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(R).catch(($) => {
212
- y($);
213
- }), this.rtcSession = e.call(t(s), {
214
- mediaStream: L(r, {
215
- directionVideo: c,
216
- directionAudio: d,
217
- contentHint: u
218
- }),
219
- pcConfig: {
220
- iceServers: o
221
- },
222
- rtcOfferConstraints: {
223
- offerToReceiveAudio: T,
224
- offerToReceiveVideo: g
225
- },
226
- // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
227
- // так как в методе call создается RTCSession
228
- // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
229
- eventHandlers: this.events.triggers,
230
- extraHeaders: i,
231
- directionVideo: c,
232
- directionAudio: d,
233
- degradationPreference: S,
234
- sendEncodings: I,
235
- onAddedTransceiver: _
236
- });
237
- }).finally(() => {
238
- this.isPendingCall = !1;
239
- }));
240
- async endCall() {
241
- const { rtcSession: e } = this;
242
- if (e && !e.isEnded())
243
- return e.terminateAsync({
244
- cause: re.CANCELED
245
- }).finally(() => {
246
- this.reset();
247
- });
248
- this.reset();
249
- }
250
- answerToIncomingCall = async (e, {
251
- mediaStream: t,
252
- ontrack: s,
253
- extraHeaders: r = [],
254
- iceServers: i,
255
- directionVideo: a,
256
- directionAudio: o,
257
- offerToReceiveAudio: c,
258
- offerToReceiveVideo: d,
259
- contentHint: u,
260
- degradationPreference: T,
261
- sendEncodings: g,
262
- onAddedTransceiver: S
263
- }) => (this.isPendingAnswer = !0, new Promise((I, _) => {
264
- try {
265
- const R = e();
266
- this.rtcSession = R, this.subscribeToSessionEvents(R), this.callConfiguration.answer = !0, this.callConfiguration.number = R.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(I).catch((y) => {
267
- _(y);
268
- }), R.answer({
269
- pcConfig: {
270
- iceServers: i
271
- },
272
- rtcOfferConstraints: {
273
- offerToReceiveAudio: c,
274
- offerToReceiveVideo: d
275
- },
276
- mediaStream: L(t, {
277
- directionVideo: a,
278
- directionAudio: o,
279
- contentHint: u
280
- }),
281
- extraHeaders: r,
282
- directionVideo: a,
283
- directionAudio: o,
284
- degradationPreference: T,
285
- sendEncodings: g,
286
- onAddedTransceiver: S
287
- });
288
- } catch (R) {
289
- _(R);
290
- }
291
- }).finally(() => {
292
- this.isPendingAnswer = !1;
293
- }));
294
- getEstablishedRTCSession() {
295
- return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
296
- }
297
- getCallConfiguration() {
298
- return { ...this.callConfiguration };
299
- }
300
- getRemoteStreams() {
301
- if (!this.connection)
302
- return;
303
- const t = this.connection.getReceivers().map(({ track: s }) => s);
304
- return Oe(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
305
- }
306
- async replaceMediaStream(e, t) {
307
- if (!this.rtcSession)
308
- throw new Error("No rtcSession established");
309
- const { contentHint: s } = t ?? {}, r = L(e, { contentHint: s });
310
- if (r === void 0)
311
- throw new Error("No preparedMediaStream");
312
- return this.rtcSession.replaceMediaStream(r, t);
313
- }
314
- async restartIce(e) {
315
- if (!this.rtcSession)
316
- throw new Error("No rtcSession established");
317
- return this.rtcSession.restartIce(e);
318
- }
319
- async addTransceiver(e, t) {
320
- if (!this.rtcSession)
321
- throw new Error("No rtcSession established");
322
- return this.rtcSession.addTransceiver(e, t);
323
- }
324
- /**
325
- * Возвращает сохраненные transceiver'ы
326
- */
327
- getTransceivers() {
328
- return this.transceiverManager.getTransceivers();
329
- }
330
- handleCall = async ({
331
- ontrack: e
332
- }) => new Promise((t, s) => {
333
- const r = () => {
334
- this.events.on(N.PEER_CONNECTION, u), this.events.on(N.CONFIRMED, T);
335
- }, i = () => {
336
- this.events.off(N.PEER_CONNECTION, u), this.events.off(N.CONFIRMED, T);
337
- }, a = () => {
338
- this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
339
- }, o = () => {
340
- this.events.off(N.FAILED, c), this.events.off(N.ENDED, c);
341
- }, c = (g) => {
342
- i(), o(), s(g);
343
- };
344
- let d;
345
- const u = ({ peerconnection: g }) => {
346
- d = g;
347
- const S = (I) => {
348
- this.events.trigger(N.PEER_CONNECTION_ONTRACK, g), this.transceiverManager.storeTransceiver(I.transceiver, I.track), e && e(I);
349
- };
350
- g.addEventListener("track", S), this.disposers.add(() => {
351
- g.removeEventListener("track", S);
352
- });
353
- }, T = () => {
354
- d !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, d), i(), o(), t(d);
355
- };
356
- r(), a();
357
- });
358
- subscribeToSessionEvents(e) {
359
- this.events.eachTriggers((t, s) => {
360
- const r = te.find((i) => i === s);
361
- r && (e.on(r, t), this.disposers.add(() => {
362
- e.off(r, t);
363
- }));
364
- });
365
- }
366
- unsubscribeFromSessionEvents() {
367
- this.disposers.forEach((e) => {
368
- e();
369
- }), this.disposers.clear();
370
- }
371
- handleEnded = (e) => {
372
- const { originator: t } = e;
373
- t === F.REMOTE && this.events.trigger(N.ENDED_FROM_SERVER, e), this.reset();
374
- };
375
- reset = () => {
376
- delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1, this.transceiverManager.clear();
377
- };
378
- }
379
- class we {
380
- events;
381
- strategy;
382
- constructor(e) {
383
- this.events = new D(ne), this.strategy = e ?? new Ue(this.events);
384
- }
385
- get requested() {
386
- return this.strategy.requested;
387
- }
388
- get connection() {
389
- return this.strategy.connection;
390
- }
391
- get establishedRTCSession() {
392
- return this.strategy.establishedRTCSession;
393
- }
394
- get isCallActive() {
395
- return this.strategy.isCallActive;
396
- }
397
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
398
- on(e, t) {
399
- return this.events.on(e, t);
400
- }
401
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
402
- once(e, t) {
403
- return this.events.once(e, t);
404
- }
405
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
406
- onceRace(e, t) {
407
- return this.events.onceRace(e, t);
408
- }
409
- async wait(e) {
410
- return this.events.wait(e);
411
- }
412
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
413
- off(e, t) {
414
- this.events.off(e, t);
415
- }
416
- setStrategy(e) {
417
- this.strategy = e;
418
- }
419
- startCall = async (...e) => this.strategy.startCall(...e);
420
- endCall = async () => this.strategy.endCall();
421
- answerToIncomingCall = async (...e) => this.strategy.answerToIncomingCall(...e);
422
- getEstablishedRTCSession = () => this.strategy.getEstablishedRTCSession();
423
- getCallConfiguration = () => this.strategy.getCallConfiguration();
424
- getRemoteStreams = () => this.strategy.getRemoteStreams();
425
- getTransceivers = () => this.strategy.getTransceivers();
426
- addTransceiver = async (...e) => this.strategy.addTransceiver(...e);
427
- replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
428
- restartIce = async (e) => this.strategy.restartIce(e);
429
- }
430
- const G = "sip-connector", E = q(G), Sn = () => {
431
- q.enable(G);
432
- }, Cn = () => {
433
- q.enable(`-${G}`);
434
- }, Le = "Error decline with 603", Be = 1006, ke = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Be, Fe = (n) => n.message === Le;
435
- 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.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n.AUDIO_TRACK_COUNT = "X-WEBRTC-AUDIO-TRACK-COUNT", n.VIDEO_TRACK_COUNT = "X-WEBRTC-VIDEO-TRACK-COUNT", n.TRACKS_DIRECTION = "X-WEBRTC-TRACKS-DIRECTION", n))(h || {}), B = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(B || {}), k = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n.SPECTATOR_OVER_SFU = "SPECTATOROVERSFU", n))(k || {}), v = /* @__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.RESTART = "application/vinteo.webrtc.restart", n))(v || {}), 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.STATS = "application/vinteo.webrtc.stats", n))(M || {}), P = /* @__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))(P || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(W || {}), H = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(H || {}), $e = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))($e || {}), l = /* @__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.RESTART = "restart", n))(l || {});
436
- const ie = [
10
+ const q = "sip-connector", E = x(q), Tn = () => {
11
+ x.enable(q);
12
+ }, Sn = () => {
13
+ x.enable(`-${q}`);
14
+ }, _e = "Error decline with 603", me = 1006, Me = (n) => typeof n == "object" && n !== null && "code" in n && n.code === me, pe = (n) => n.message === _e;
15
+ 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.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n.AUDIO_TRACK_COUNT = "X-WEBRTC-AUDIO-TRACK-COUNT", n.VIDEO_TRACK_COUNT = "X-WEBRTC-VIDEO-TRACK-COUNT", n.TRACKS_DIRECTION = "X-WEBRTC-TRACKS-DIRECTION", n))(h || {}), L = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(L || {}), $ = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))($ || {}), v = /* @__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.RESTART = "application/vinteo.webrtc.restart", n))(v || {}), 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.STATS = "application/vinteo.webrtc.stats", n))(M || {}), P = /* @__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))(P || {}), V = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(V || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(W || {}), Pe = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Pe || {}), 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.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.RESTART = "restart", n))(g || {});
16
+ const Z = [
437
17
  "participation:accepting-word-request",
438
18
  "participation:cancelling-word-request",
439
19
  "participant:move-request-to-stream",
@@ -447,7 +27,6 @@ const ie = [
447
27
  "participant:removed-from-list-moderators",
448
28
  "participant:move-request-to-spectators",
449
29
  "participant:move-request-to-participants",
450
- "participant:move-request-to-spectators-over-sfu",
451
30
  "channels",
452
31
  "enterRoom",
453
32
  "shareState",
@@ -464,8 +43,8 @@ const ie = [
464
43
  "newDTMF",
465
44
  "restart"
466
45
  ];
467
- var m = /* @__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))(m || {});
468
- class Ve {
46
+ var _ = /* @__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))(_ || {});
47
+ class ve {
469
48
  events;
470
49
  connectionManager;
471
50
  callManager;
@@ -473,44 +52,44 @@ class Ve {
473
52
  connectionManager: e,
474
53
  callManager: t
475
54
  }) {
476
- this.connectionManager = e, this.callManager = t, this.events = new D(ie), this.subscribe();
55
+ this.connectionManager = e, this.callManager = t, this.events = new w(Z), this.subscribe();
477
56
  }
478
57
  async waitChannels() {
479
- return this.wait(l.CHANNELS);
58
+ return this.wait(g.CHANNELS);
480
59
  }
481
60
  async waitSyncMediaState() {
482
- return this.wait(l.ADMIN_FORCE_SYNC_MEDIA_STATE);
61
+ return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
483
62
  }
484
63
  async sendDTMF(e) {
485
64
  return new Promise((t, s) => {
486
- let r;
65
+ let i;
487
66
  try {
488
- r = this.getEstablishedRTCSessionProtected();
489
- } catch (i) {
490
- s(i);
67
+ i = this.getEstablishedRTCSessionProtected();
68
+ } catch (r) {
69
+ s(r);
491
70
  }
492
- r && (this.callManager.once("newDTMF", ({ originator: i }) => {
493
- i === F.LOCAL && t();
494
- }), r.sendDTMF(e, {
71
+ i && (this.callManager.once("newDTMF", ({ originator: r }) => {
72
+ r === "local" && t();
73
+ }), i.sendDTMF(e, {
495
74
  duration: 120,
496
75
  interToneGap: 600
497
76
  }));
498
77
  });
499
78
  }
500
79
  async sendChannels({ inputChannels: e, outputChannels: t }) {
501
- const s = this.getEstablishedRTCSessionProtected(), r = `${h.INPUT_CHANNELS}: ${e}`, i = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
502
- r,
503
- i
80
+ const s = this.getEstablishedRTCSessionProtected(), i = `${h.INPUT_CHANNELS}: ${e}`, r = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
81
+ i,
82
+ r
504
83
  ];
505
84
  return s.sendInfo(M.CHANNELS, void 0, { extraHeaders: a });
506
85
  }
507
86
  async sendMediaState({ cam: e, mic: t }, s = {}) {
508
- const r = this.getEstablishedRTCSessionProtected(), i = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
509
- i,
87
+ const i = this.getEstablishedRTCSessionProtected(), r = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
88
+ r,
510
89
  a,
511
90
  o
512
91
  ];
513
- return r.sendInfo(M.MEDIA_STATE, void 0, {
92
+ return i.sendInfo(M.MEDIA_STATE, void 0, {
514
93
  noTerminateWhenError: !0,
515
94
  ...s,
516
95
  extraHeaders: c
@@ -519,10 +98,10 @@ class Ve {
519
98
  async sendStats({
520
99
  availableIncomingBitrate: e
521
100
  }) {
522
- const t = this.getEstablishedRTCSessionProtected(), r = [`${h.AVAILABLE_INCOMING_BITRATE}: ${e}`];
101
+ const t = this.getEstablishedRTCSessionProtected(), i = [`${h.AVAILABLE_INCOMING_BITRATE}: ${e}`];
523
102
  return t.sendInfo(M.STATS, void 0, {
524
103
  noTerminateWhenError: !0,
525
- extraHeaders: r
104
+ extraHeaders: i
526
105
  });
527
106
  }
528
107
  async sendRefusalToTurnOn(e, t = {}) {
@@ -570,9 +149,9 @@ class Ve {
570
149
  noTerminateWhenError: !0,
571
150
  ...e,
572
151
  extraHeaders: s
573
- }).catch((r) => {
574
- if (Fe(r))
575
- throw r;
152
+ }).catch((i) => {
153
+ if (pe(i))
154
+ throw i;
576
155
  });
577
156
  }
578
157
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
@@ -621,55 +200,55 @@ class Ve {
621
200
  };
622
201
  handleNotify = (e) => {
623
202
  switch (e.cmd) {
624
- case m.CHANNELS: {
203
+ case _.CHANNELS: {
625
204
  const t = e;
626
205
  this.triggerChannelsNotify(t);
627
206
  break;
628
207
  }
629
- case m.WEBCAST_STARTED: {
208
+ case _.WEBCAST_STARTED: {
630
209
  const t = e;
631
210
  this.triggerWebcastStartedNotify(t);
632
211
  break;
633
212
  }
634
- case m.WEBCAST_STOPPED: {
213
+ case _.WEBCAST_STOPPED: {
635
214
  const t = e;
636
215
  this.triggerWebcastStoppedNotify(t);
637
216
  break;
638
217
  }
639
- case m.ADDED_TO_LIST_MODERATORS: {
218
+ case _.ADDED_TO_LIST_MODERATORS: {
640
219
  const t = e;
641
220
  this.triggerAddedToListModeratorsNotify(t);
642
221
  break;
643
222
  }
644
- case m.REMOVED_FROM_LIST_MODERATORS: {
223
+ case _.REMOVED_FROM_LIST_MODERATORS: {
645
224
  const t = e;
646
225
  this.triggerRemovedFromListModeratorsNotify(t);
647
226
  break;
648
227
  }
649
- case m.ACCEPTING_WORD_REQUEST: {
228
+ case _.ACCEPTING_WORD_REQUEST: {
650
229
  const t = e;
651
230
  this.triggerParticipationAcceptingWordRequest(t);
652
231
  break;
653
232
  }
654
- case m.CANCELLING_WORD_REQUEST: {
233
+ case _.CANCELLING_WORD_REQUEST: {
655
234
  const t = e;
656
235
  this.triggerParticipationCancellingWordRequest(t);
657
236
  break;
658
237
  }
659
- case m.MOVE_REQUEST_TO_STREAM: {
238
+ case _.MOVE_REQUEST_TO_STREAM: {
660
239
  const t = e;
661
240
  this.triggerParticipantMoveRequestToStream(t);
662
241
  break;
663
242
  }
664
- case m.ACCOUNT_CHANGED: {
243
+ case _.ACCOUNT_CHANGED: {
665
244
  this.triggerAccountChangedNotify();
666
245
  break;
667
246
  }
668
- case m.ACCOUNT_DELETED: {
247
+ case _.ACCOUNT_DELETED: {
669
248
  this.triggerAccountDeletedNotify();
670
249
  break;
671
250
  }
672
- case m.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
251
+ case _.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
673
252
  const t = e;
674
253
  this.triggerConferenceParticipantTokenIssued(t);
675
254
  break;
@@ -680,51 +259,51 @@ class Ve {
680
259
  };
681
260
  handleNewInfo = (e) => {
682
261
  const { originator: t } = e;
683
- if (t !== F.REMOTE)
262
+ if (t !== "remote")
684
263
  return;
685
- const { request: s } = e, r = s.getHeader(h.CONTENT_TYPE);
264
+ const { request: s } = e, i = s, r = i.getHeader(h.CONTENT_TYPE);
686
265
  if (r !== void 0)
687
266
  switch (r) {
688
267
  case v.ENTER_ROOM: {
689
- this.triggerEnterRoom(s), this.maybeTriggerChannels(s);
268
+ this.triggerEnterRoom(i), this.maybeTriggerChannels(i);
690
269
  break;
691
270
  }
692
271
  case v.NOTIFY: {
693
- this.maybeHandleNotify(s);
272
+ this.maybeHandleNotify(i);
694
273
  break;
695
274
  }
696
275
  case v.SHARE_STATE: {
697
- this.triggerShareState(s);
276
+ this.triggerShareState(i);
698
277
  break;
699
278
  }
700
279
  case v.MAIN_CAM: {
701
- this.triggerMainCamControl(s);
280
+ this.triggerMainCamControl(i);
702
281
  break;
703
282
  }
704
283
  case v.MIC: {
705
- this.triggerMicControl(s);
284
+ this.triggerMicControl(i);
706
285
  break;
707
286
  }
708
287
  case v.USE_LICENSE: {
709
- this.triggerUseLicense(s);
288
+ this.triggerUseLicense(i);
710
289
  break;
711
290
  }
712
291
  case v.PARTICIPANT_STATE: {
713
- this.maybeTriggerParticipantMoveRequest(s);
292
+ this.maybeTriggerParticipantMoveRequest(i);
714
293
  break;
715
294
  }
716
295
  case v.RESTART: {
717
- this.triggerRestart(s);
296
+ this.triggerRestart(i);
718
297
  break;
719
298
  }
720
299
  }
721
300
  };
722
301
  triggerChannelsNotify = (e) => {
723
- const t = e.input, s = e.output, r = {
302
+ const t = e.input, s = e.output, i = {
724
303
  inputChannels: t,
725
304
  outputChannels: s
726
305
  };
727
- this.events.trigger(l.CHANNELS_NOTIFY, r);
306
+ this.events.trigger(g.CHANNELS_NOTIFY, i);
728
307
  };
729
308
  triggerWebcastStartedNotify = ({
730
309
  body: { conference: e, type: t }
@@ -733,7 +312,7 @@ class Ve {
733
312
  conference: e,
734
313
  type: t
735
314
  };
736
- this.events.trigger(l.WEBCAST_STARTED, s);
315
+ this.events.trigger(g.WEBCAST_STARTED, s);
737
316
  };
738
317
  triggerWebcastStoppedNotify = ({
739
318
  body: { conference: e, type: t }
@@ -742,7 +321,7 @@ class Ve {
742
321
  conference: e,
743
322
  type: t
744
323
  };
745
- this.events.trigger(l.WEBCAST_STOPPED, s);
324
+ this.events.trigger(g.WEBCAST_STOPPED, s);
746
325
  };
747
326
  triggerAddedToListModeratorsNotify = ({
748
327
  conference: e
@@ -751,7 +330,7 @@ class Ve {
751
330
  conference: e
752
331
  };
753
332
  this.events.trigger(
754
- l.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
333
+ g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
755
334
  t
756
335
  );
757
336
  };
@@ -762,7 +341,7 @@ class Ve {
762
341
  conference: e
763
342
  };
764
343
  this.events.trigger(
765
- l.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
344
+ g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
766
345
  t
767
346
  );
768
347
  };
@@ -772,7 +351,7 @@ class Ve {
772
351
  const t = {
773
352
  conference: e
774
353
  };
775
- this.events.trigger(l.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
354
+ this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
776
355
  };
777
356
  triggerParticipationCancellingWordRequest = ({
778
357
  body: { conference: e }
@@ -780,7 +359,7 @@ class Ve {
780
359
  const t = {
781
360
  conference: e
782
361
  };
783
- this.events.trigger(l.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
362
+ this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
784
363
  };
785
364
  triggerParticipantMoveRequestToStream = ({
786
365
  body: { conference: e }
@@ -788,132 +367,470 @@ class Ve {
788
367
  const t = {
789
368
  conference: e
790
369
  };
791
- this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
370
+ this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
792
371
  };
793
372
  triggerAccountChangedNotify = () => {
794
- this.events.trigger(l.ACCOUNT_CHANGED, void 0);
373
+ this.events.trigger(g.ACCOUNT_CHANGED, void 0);
795
374
  };
796
375
  triggerAccountDeletedNotify = () => {
797
- this.events.trigger(l.ACCOUNT_DELETED, void 0);
376
+ this.events.trigger(g.ACCOUNT_DELETED, void 0);
798
377
  };
799
378
  triggerConferenceParticipantTokenIssued = ({
800
379
  body: { conference: e, participant: t, jwt: s }
801
380
  }) => {
802
- const r = {
381
+ const i = {
803
382
  conference: e,
804
383
  participant: t,
805
384
  jwt: s
806
385
  };
807
386
  this.events.trigger(
808
- l.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
809
- r
387
+ g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
388
+ i
810
389
  );
811
390
  };
812
391
  maybeTriggerChannels = (e) => {
813
392
  const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
814
393
  if (t && s) {
815
- const r = {
394
+ const i = {
816
395
  inputChannels: t,
817
396
  outputChannels: s
818
397
  };
819
- this.events.trigger(l.CHANNELS, r);
398
+ this.events.trigger(g.CHANNELS, i);
820
399
  }
821
400
  };
822
401
  triggerEnterRoom = (e) => {
823
402
  const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
824
- this.events.trigger(l.ENTER_ROOM, { room: t, participantName: s });
403
+ this.events.trigger(g.ENTER_ROOM, { room: t, participantName: s });
825
404
  };
826
405
  triggerShareState = (e) => {
827
406
  const t = e.getHeader(h.CONTENT_SHARE_STATE);
828
407
  if (t !== void 0)
829
408
  switch (t) {
830
- case B.AVAILABLE_SECOND_REMOTE_STREAM: {
831
- this.events.trigger(l.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
409
+ case L.AVAILABLE_SECOND_REMOTE_STREAM: {
410
+ this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
832
411
  break;
833
412
  }
834
- case B.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
835
- this.events.trigger(l.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
413
+ case L.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
414
+ this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
836
415
  break;
837
416
  }
838
- case B.MUST_STOP_PRESENTATION: {
839
- this.events.trigger(l.MUST_STOP_PRESENTATION, void 0);
417
+ case L.MUST_STOP_PRESENTATION: {
418
+ this.events.trigger(g.MUST_STOP_PRESENTATION, void 0);
840
419
  break;
841
420
  }
842
421
  }
843
422
  };
844
423
  maybeTriggerParticipantMoveRequest = (e) => {
845
424
  const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
846
- t === k.SPECTATOR && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === k.PARTICIPANT && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0), t === k.SPECTATOR_OVER_SFU && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU, void 0);
425
+ t === $.SPECTATOR && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === $.PARTICIPANT && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0);
847
426
  };
848
427
  triggerMainCamControl = (e) => {
849
- const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), r = s === H.ADMIN_SYNC_FORCED;
428
+ const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), i = s === W.ADMIN_SYNC_FORCED;
850
429
  if (t === P.ADMIN_START_MAIN_CAM) {
851
- this.events.trigger(l.ADMIN_START_MAIN_CAM, { isSyncForced: r });
430
+ this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: i });
852
431
  return;
853
432
  }
854
433
  if (t === P.ADMIN_STOP_MAIN_CAM) {
855
- this.events.trigger(l.ADMIN_STOP_MAIN_CAM, { isSyncForced: r });
434
+ this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
856
435
  return;
857
436
  }
858
- (t === P.RESUME_MAIN_CAM || t === P.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(l.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: r });
859
- const i = e.getHeader(h.MAIN_CAM_RESOLUTION);
860
- this.events.trigger(l.MAIN_CAM_CONTROL, {
437
+ (t === P.RESUME_MAIN_CAM || t === P.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(g.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
438
+ const r = e.getHeader(h.MAIN_CAM_RESOLUTION);
439
+ this.events.trigger(g.MAIN_CAM_CONTROL, {
861
440
  mainCam: t,
862
- resolutionMainCam: i
441
+ resolutionMainCam: r
442
+ });
443
+ };
444
+ triggerMicControl = (e) => {
445
+ const t = e.getHeader(h.MIC), i = e.getHeader(h.MEDIA_SYNC) === W.ADMIN_SYNC_FORCED;
446
+ t === V.ADMIN_START_MIC ? this.events.trigger(g.ADMIN_START_MIC, { isSyncForced: i }) : t === V.ADMIN_STOP_MIC && this.events.trigger(g.ADMIN_STOP_MIC, { isSyncForced: i });
447
+ };
448
+ triggerUseLicense = (e) => {
449
+ const t = e.getHeader(h.CONTENT_USE_LICENSE);
450
+ this.events.trigger(g.USE_LICENSE, t);
451
+ };
452
+ triggerRestart = (e) => {
453
+ const t = e.getHeader(
454
+ h.TRACKS_DIRECTION
455
+ ), s = Number(
456
+ e.getHeader(h.AUDIO_TRACK_COUNT)
457
+ ), i = Number(
458
+ e.getHeader(h.VIDEO_TRACK_COUNT)
459
+ ), r = { tracksDirection: t, audioTrackCount: s, videoTrackCount: i };
460
+ this.events.trigger(g.RESTART, r);
461
+ };
462
+ }
463
+ 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 || {}), fe = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(fe || {});
464
+ const ee = [
465
+ "peerconnection",
466
+ "connecting",
467
+ "sending",
468
+ "progress",
469
+ "accepted",
470
+ "confirmed",
471
+ "ended",
472
+ "failed",
473
+ "newInfo",
474
+ "newDTMF",
475
+ "presentation:start",
476
+ "presentation:started",
477
+ "presentation:end",
478
+ "presentation:ended",
479
+ "presentation:failed",
480
+ "reinvite",
481
+ "update",
482
+ "refer",
483
+ "replaces",
484
+ "sdp",
485
+ "icecandidate",
486
+ "getusermediafailed",
487
+ "peerconnection:createofferfailed",
488
+ "peerconnection:createanswerfailed",
489
+ "peerconnection:setlocaldescriptionfailed",
490
+ "peerconnection:setremotedescriptionfailed"
491
+ ], Oe = [
492
+ "peerconnection:confirmed",
493
+ "peerconnection:ontrack",
494
+ "ended:fromserver"
495
+ ], te = [
496
+ ...ee,
497
+ ...Oe
498
+ ], De = (n, e) => {
499
+ n.getVideoTracks().forEach((s) => {
500
+ "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
501
+ });
502
+ }, B = (n, {
503
+ directionVideo: e,
504
+ directionAudio: t,
505
+ contentHint: s
506
+ } = {}) => {
507
+ if (!n || e === "recvonly" && t === "recvonly")
508
+ return;
509
+ const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
510
+ return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && De(o, s), o;
511
+ };
512
+ function ye(n) {
513
+ return (e) => `sip:${e}@${n}`;
514
+ }
515
+ const be = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, ne = (n) => n.trim().replaceAll(" ", "_"), we = be(1e5, 99999999), Ue = (n) => n.some((t) => {
516
+ const { kind: s } = t;
517
+ return s === "video";
518
+ });
519
+ class Le {
520
+ isPendingCall = !1;
521
+ isPendingAnswer = !1;
522
+ rtcSession;
523
+ remoteStreams = {};
524
+ events;
525
+ callConfiguration = {};
526
+ constructor(e) {
527
+ this.events = e;
528
+ }
529
+ }
530
+ var se = /* @__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))(se || {});
531
+ class Be {
532
+ remoteStreams = {};
533
+ reset() {
534
+ this.remoteStreams = {};
535
+ }
536
+ generateStream(e, t) {
537
+ const { id: s } = e, i = this.remoteStreams[s] ?? new MediaStream();
538
+ return t && i.addTrack(t), i.addTrack(e), this.remoteStreams[s] = i, i;
539
+ }
540
+ generateAudioStream(e) {
541
+ const { id: t } = e, s = this.remoteStreams[t] ?? new MediaStream();
542
+ return s.addTrack(e), this.remoteStreams[t] = s, s;
543
+ }
544
+ generateStreams(e) {
545
+ const t = [];
546
+ return e.forEach((s, i) => {
547
+ if (s.kind === "audio")
548
+ return;
549
+ const r = s, a = e[i - 1];
550
+ let o;
551
+ a?.kind === "audio" && (o = a);
552
+ const c = this.generateStream(r, o);
553
+ t.push(c);
554
+ }), t;
555
+ }
556
+ generateAudioStreams(e) {
557
+ return e.map((t) => this.generateAudioStream(t));
558
+ }
559
+ }
560
+ class ke extends Le {
561
+ remoteStreamsManager = new Be();
562
+ disposers = /* @__PURE__ */ new Set();
563
+ constructor(e) {
564
+ super(e), e.on(N.FAILED, this.handleEnded), e.on(N.ENDED, this.handleEnded);
565
+ }
566
+ get requested() {
567
+ return this.isPendingCall || this.isPendingAnswer;
568
+ }
569
+ get connection() {
570
+ return this.rtcSession?.connection;
571
+ }
572
+ get isCallActive() {
573
+ return this.rtcSession?.isEstablished() === !0;
574
+ }
575
+ get establishedRTCSession() {
576
+ return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
577
+ }
578
+ startCall = async (e, t, {
579
+ number: s,
580
+ mediaStream: i,
581
+ extraHeaders: r = [],
582
+ ontrack: a,
583
+ iceServers: o,
584
+ directionVideo: c,
585
+ directionAudio: d,
586
+ contentHint: u,
587
+ offerToReceiveAudio: T = !0,
588
+ offerToReceiveVideo: l = !0,
589
+ degradationPreference: S,
590
+ sendEncodings: m,
591
+ onAddedTransceiver: I
592
+ }) => (this.isPendingCall = !0, new Promise((R, D) => {
593
+ this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(R).catch((k) => {
594
+ D(k);
595
+ }), this.rtcSession = e.call(t(s), {
596
+ mediaStream: B(i, {
597
+ directionVideo: c,
598
+ directionAudio: d,
599
+ contentHint: u
600
+ }),
601
+ pcConfig: {
602
+ iceServers: o
603
+ },
604
+ rtcOfferConstraints: {
605
+ offerToReceiveAudio: T,
606
+ offerToReceiveVideo: l
607
+ },
608
+ // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
609
+ // так как в методе call создается RTCSession
610
+ // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
611
+ eventHandlers: this.events.triggers,
612
+ extraHeaders: r,
613
+ directionVideo: c,
614
+ directionAudio: d,
615
+ degradationPreference: S,
616
+ sendEncodings: m,
617
+ onAddedTransceiver: I
618
+ });
619
+ }).finally(() => {
620
+ this.isPendingCall = !1;
621
+ }));
622
+ async endCall() {
623
+ const { rtcSession: e } = this;
624
+ if (e && !e.isEnded())
625
+ return e.terminateAsync({
626
+ cause: se.CANCELED
627
+ }).finally(() => {
628
+ this.reset();
629
+ });
630
+ this.reset();
631
+ }
632
+ answerToIncomingCall = async (e, {
633
+ mediaStream: t,
634
+ ontrack: s,
635
+ extraHeaders: i = [],
636
+ iceServers: r,
637
+ directionVideo: a,
638
+ directionAudio: o,
639
+ offerToReceiveAudio: c,
640
+ offerToReceiveVideo: d,
641
+ contentHint: u,
642
+ degradationPreference: T,
643
+ sendEncodings: l,
644
+ onAddedTransceiver: S
645
+ }) => (this.isPendingAnswer = !0, new Promise((m, I) => {
646
+ try {
647
+ const R = e();
648
+ this.rtcSession = R, this.subscribeToSessionEvents(R), this.callConfiguration.answer = !0, this.callConfiguration.number = R.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(m).catch((D) => {
649
+ I(D);
650
+ }), R.answer({
651
+ pcConfig: {
652
+ iceServers: r
653
+ },
654
+ rtcOfferConstraints: {
655
+ offerToReceiveAudio: c,
656
+ offerToReceiveVideo: d
657
+ },
658
+ mediaStream: B(t, {
659
+ directionVideo: a,
660
+ directionAudio: o,
661
+ contentHint: u
662
+ }),
663
+ extraHeaders: i,
664
+ directionVideo: a,
665
+ directionAudio: o,
666
+ degradationPreference: T,
667
+ sendEncodings: l,
668
+ onAddedTransceiver: S
669
+ });
670
+ } catch (R) {
671
+ I(R);
672
+ }
673
+ }).finally(() => {
674
+ this.isPendingAnswer = !1;
675
+ }));
676
+ getEstablishedRTCSession() {
677
+ return this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
678
+ }
679
+ getCallConfiguration() {
680
+ return { ...this.callConfiguration };
681
+ }
682
+ getRemoteStreams() {
683
+ if (!this.connection)
684
+ return;
685
+ const t = this.connection.getReceivers().map(({ track: s }) => s);
686
+ return Ue(t) ? this.remoteStreamsManager.generateStreams(t) : this.remoteStreamsManager.generateAudioStreams(t);
687
+ }
688
+ async replaceMediaStream(e, t) {
689
+ if (!this.rtcSession)
690
+ throw new Error("No rtcSession established");
691
+ const { contentHint: s } = t ?? {}, i = B(e, { contentHint: s });
692
+ if (i === void 0)
693
+ throw new Error("No preparedMediaStream");
694
+ return this.rtcSession.replaceMediaStream(i, t);
695
+ }
696
+ async restartIce(e) {
697
+ if (!this.rtcSession)
698
+ throw new Error("No rtcSession established");
699
+ return this.rtcSession.restartIce(e);
700
+ }
701
+ async addTransceiver(e, t) {
702
+ if (!this.rtcSession)
703
+ throw new Error("No rtcSession established");
704
+ return this.rtcSession.addTransceiver(e, t);
705
+ }
706
+ handleCall = async ({
707
+ ontrack: e
708
+ }) => new Promise((t, s) => {
709
+ const i = () => {
710
+ this.events.on(N.PEER_CONNECTION, u), this.events.on(N.CONFIRMED, T);
711
+ }, r = () => {
712
+ this.events.off(N.PEER_CONNECTION, u), this.events.off(N.CONFIRMED, T);
713
+ }, a = () => {
714
+ this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
715
+ }, o = () => {
716
+ this.events.off(N.FAILED, c), this.events.off(N.ENDED, c);
717
+ }, c = (l) => {
718
+ r(), o(), s(l);
719
+ };
720
+ let d;
721
+ const u = ({ peerconnection: l }) => {
722
+ d = l;
723
+ const S = (m) => {
724
+ this.events.trigger(N.PEER_CONNECTION_ONTRACK, m), e && e(m);
725
+ };
726
+ l.addEventListener("track", S), this.disposers.add(() => {
727
+ l.removeEventListener("track", S);
728
+ });
729
+ }, T = () => {
730
+ d !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, d), r(), o(), t(d);
731
+ };
732
+ i(), a();
733
+ });
734
+ subscribeToSessionEvents(e) {
735
+ this.events.eachTriggers((t, s) => {
736
+ const i = ee.find((r) => r === s);
737
+ i && (e.on(i, t), this.disposers.add(() => {
738
+ e.off(i, t);
739
+ }));
863
740
  });
741
+ }
742
+ unsubscribeFromSessionEvents() {
743
+ this.disposers.forEach((e) => {
744
+ e();
745
+ }), this.disposers.clear();
746
+ }
747
+ handleEnded = (e) => {
748
+ const { originator: t } = e;
749
+ t === "remote" && this.events.trigger(N.ENDED_FROM_SERVER, e), this.reset();
864
750
  };
865
- triggerMicControl = (e) => {
866
- const t = e.getHeader(h.MIC), r = e.getHeader(h.MEDIA_SYNC) === H.ADMIN_SYNC_FORCED;
867
- t === W.ADMIN_START_MIC ? this.events.trigger(l.ADMIN_START_MIC, { isSyncForced: r }) : t === W.ADMIN_STOP_MIC && this.events.trigger(l.ADMIN_STOP_MIC, { isSyncForced: r });
868
- };
869
- triggerUseLicense = (e) => {
870
- const t = e.getHeader(h.CONTENT_USE_LICENSE);
871
- this.events.trigger(l.USE_LICENSE, t);
872
- };
873
- triggerRestart = (e) => {
874
- const t = e.getHeader(
875
- h.TRACKS_DIRECTION
876
- ), s = Number(
877
- e.getHeader(h.AUDIO_TRACK_COUNT)
878
- ), r = Number(
879
- e.getHeader(h.VIDEO_TRACK_COUNT)
880
- ), i = { tracksDirection: t, audioTrackCount: s, videoTrackCount: r };
881
- this.events.trigger(l.RESTART, i);
751
+ reset = () => {
752
+ delete this.rtcSession, this.remoteStreamsManager.reset(), this.unsubscribeFromSessionEvents(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
882
753
  };
883
754
  }
884
- const We = (n, e) => (n.degradationPreference = e.degradationPreference, n), He = (n, e) => {
755
+ class Fe {
756
+ events;
757
+ strategy;
758
+ constructor(e) {
759
+ this.events = new H(te), this.strategy = e ?? new ke(this.events);
760
+ }
761
+ get requested() {
762
+ return this.strategy.requested;
763
+ }
764
+ get connection() {
765
+ return this.strategy.connection;
766
+ }
767
+ get establishedRTCSession() {
768
+ return this.strategy.establishedRTCSession;
769
+ }
770
+ get isCallActive() {
771
+ return this.strategy.isCallActive;
772
+ }
773
+ on(e, t) {
774
+ return this.events.on(e, t);
775
+ }
776
+ once(e, t) {
777
+ return this.events.once(e, t);
778
+ }
779
+ onceRace(e, t) {
780
+ return this.events.onceRace(e, t);
781
+ }
782
+ async wait(e) {
783
+ return this.events.wait(e);
784
+ }
785
+ off(e, t) {
786
+ this.events.off(e, t);
787
+ }
788
+ setStrategy(e) {
789
+ this.strategy = e;
790
+ }
791
+ startCall = async (...e) => this.strategy.startCall(...e);
792
+ endCall = async () => this.strategy.endCall();
793
+ answerToIncomingCall = async (...e) => this.strategy.answerToIncomingCall(...e);
794
+ getEstablishedRTCSession = () => this.strategy.getEstablishedRTCSession();
795
+ getCallConfiguration = () => this.strategy.getCallConfiguration();
796
+ getRemoteStreams = () => this.strategy.getRemoteStreams();
797
+ addTransceiver = async (...e) => this.strategy.addTransceiver(...e);
798
+ replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
799
+ restartIce = async (e) => this.strategy.restartIce(e);
800
+ }
801
+ const $e = (n, e) => (n.degradationPreference = e.degradationPreference, n), Ve = (n, e) => {
885
802
  n.encodings ??= [];
886
803
  for (let t = n.encodings.length; t < e; t += 1)
887
804
  n.encodings.push({});
888
805
  return n;
889
- }, ae = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, xe = ae(), qe = (n, e) => {
890
- if (xe(n, e))
806
+ }, ie = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, We = ie(), He = (n, e) => {
807
+ if (We(n, e))
891
808
  return n;
892
- }, Ge = (n, e) => {
893
- const t = n.maxBitrate, s = qe(e, t);
809
+ }, xe = (n, e) => {
810
+ const t = n.maxBitrate, s = He(e, t);
894
811
  return s !== void 0 && (n.maxBitrate = s), n;
895
- }, oe = 1, Qe = ae(
896
- oe
897
- ), Ye = (n, e) => {
898
- const t = n === void 0 ? void 0 : Math.max(n, oe);
899
- if (t !== void 0 && Qe(
812
+ }, re = 1, qe = ie(
813
+ re
814
+ ), Ge = (n, e) => {
815
+ const t = n === void 0 ? void 0 : Math.max(n, re);
816
+ if (t !== void 0 && qe(
900
817
  t,
901
818
  e
902
819
  ))
903
820
  return t;
904
- }, ze = (n, e) => {
905
- const t = n.scaleResolutionDownBy, s = Ye(
821
+ }, Qe = (n, e) => {
822
+ const t = n.scaleResolutionDownBy, s = Ge(
906
823
  e,
907
824
  t
908
825
  );
909
826
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
910
- }, Xe = (n, e) => {
827
+ }, Ye = (n, e) => {
911
828
  const t = e.encodings?.length ?? 0;
912
- return He(n, t), n.encodings.forEach((s, r) => {
913
- const i = (e?.encodings ?? [])[r], a = i?.maxBitrate, o = i?.scaleResolutionDownBy;
914
- Ge(s, a), ze(s, o);
829
+ return Ve(n, t), n.encodings.forEach((s, i) => {
830
+ const r = (e?.encodings ?? [])[i], a = r?.maxBitrate, o = r?.scaleResolutionDownBy;
831
+ xe(s, a), Qe(s, o);
915
832
  }), n;
916
- }, Je = (n, e) => {
833
+ }, ze = (n, e) => {
917
834
  if (n.codecs?.length !== e.codecs?.length)
918
835
  return !0;
919
836
  for (let t = 0; t < (n.codecs?.length ?? 0); t++)
@@ -930,15 +847,15 @@ const We = (n, e) => (n.degradationPreference = e.degradationPreference, n), He
930
847
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
931
848
  return !0;
932
849
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
933
- }, Ke = async (n, e) => {
850
+ }, Xe = async (n, e) => {
934
851
  const t = n.getParameters(), s = JSON.parse(
935
852
  JSON.stringify(t)
936
853
  );
937
- Xe(t, e), We(t, e);
938
- const r = Je(s, t);
939
- return r && await n.setParameters(t), { parameters: t, isChanged: r };
940
- }, ce = async (n, e, t) => {
941
- const { isChanged: s, parameters: r } = await Ke(n, {
854
+ Ye(t, e), $e(t, e);
855
+ const i = ze(s, t);
856
+ return i && await n.setParameters(t), { parameters: t, isChanged: i };
857
+ }, ae = async (n, e, t) => {
858
+ const { isChanged: s, parameters: i } = await Xe(n, {
942
859
  encodings: [
943
860
  {
944
861
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -946,21 +863,21 @@ const We = (n, e) => (n.degradationPreference = e.degradationPreference, n), He
946
863
  }
947
864
  ]
948
865
  });
949
- return s && t && t(r), { isChanged: s, parameters: r };
950
- }, je = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ze = async (n, e, t) => {
951
- const s = je(n, e);
866
+ return s && t && t(i), { isChanged: s, parameters: i };
867
+ }, Je = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ke = async (n, e, t) => {
868
+ const s = Je(n, e);
952
869
  if (s)
953
- return ce(s, { maxBitrate: t });
870
+ return ae(s, { maxBitrate: t });
954
871
  };
955
872
  var f = /* @__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))(f || {});
956
- const de = [
873
+ const oe = [
957
874
  "presentation:start",
958
875
  "presentation:started",
959
876
  "presentation:end",
960
877
  "presentation:ended",
961
878
  "presentation:failed"
962
- ], et = 1, En = (n) => Ie(n);
963
- class tt {
879
+ ], je = 1, Cn = (n) => Ne(n);
880
+ class Ze {
964
881
  events;
965
882
  promisePendingStartPresentation;
966
883
  promisePendingStopPresentation;
@@ -972,7 +889,7 @@ class tt {
972
889
  callManager: e,
973
890
  maxBitrate: t
974
891
  }) {
975
- this.callManager = e, this.maxBitrate = t, this.events = new D(de), this.subscribe();
892
+ this.callManager = e, this.maxBitrate = t, this.events = new w(oe), this.subscribe();
976
893
  }
977
894
  get isPendingPresentation() {
978
895
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
@@ -980,8 +897,8 @@ class tt {
980
897
  // eslint-disable-next-line @typescript-eslint/max-params
981
898
  async startPresentation(e, t, {
982
899
  isNeedReinvite: s,
983
- contentHint: r,
984
- sendEncodings: i,
900
+ contentHint: i,
901
+ sendEncodings: r,
985
902
  onAddedTransceiver: a
986
903
  } = {}, o) {
987
904
  const c = this.getRtcSessionProtected();
@@ -992,8 +909,8 @@ class tt {
992
909
  stream: t,
993
910
  presentationOptions: {
994
911
  isNeedReinvite: s,
995
- contentHint: r,
996
- sendEncodings: i,
912
+ contentHint: i,
913
+ sendEncodings: r,
997
914
  onAddedTransceiver: a
998
915
  },
999
916
  options: o
@@ -1005,17 +922,17 @@ class tt {
1005
922
  let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
1006
923
  this.promisePendingStartPresentation && await this.promisePendingStartPresentation.catch(() => {
1007
924
  });
1008
- const r = this.callManager.getEstablishedRTCSession();
1009
- return r && t ? s = e().then(async () => r.stopPresentation(t)).catch((i) => {
1010
- throw this.events.trigger(f.FAILED_PRESENTATION, i), i;
925
+ const i = this.callManager.getEstablishedRTCSession();
926
+ return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
927
+ throw this.events.trigger(f.FAILED_PRESENTATION, r), r;
1011
928
  }) : t && this.events.trigger(f.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
1012
929
  this.resetPresentation();
1013
930
  });
1014
931
  }
1015
932
  async updatePresentation(e, t, {
1016
933
  contentHint: s,
1017
- sendEncodings: r,
1018
- onAddedTransceiver: i
934
+ sendEncodings: i,
935
+ onAddedTransceiver: r
1019
936
  } = {}) {
1020
937
  const a = this.getRtcSessionProtected();
1021
938
  if (!this.streamPresentationCurrent)
@@ -1023,8 +940,8 @@ class tt {
1023
940
  return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
1024
941
  contentHint: s,
1025
942
  isNeedReinvite: !1,
1026
- sendEncodings: r,
1027
- onAddedTransceiver: i
943
+ sendEncodings: i,
944
+ onAddedTransceiver: r
1028
945
  }).then(async (o) => (await this.setMaxBitrate(), o));
1029
946
  }
1030
947
  cancelSendPresentationWithRepeatedCalls() {
@@ -1065,37 +982,37 @@ class tt {
1065
982
  async sendPresentationWithDuplicatedCalls(e, {
1066
983
  rtcSession: t,
1067
984
  stream: s,
1068
- presentationOptions: r,
1069
- options: i = {
1070
- callLimit: et
985
+ presentationOptions: i,
986
+ options: r = {
987
+ callLimit: je
1071
988
  }
1072
989
  }) {
1073
990
  const a = async () => this.sendPresentation(
1074
991
  e,
1075
992
  t,
1076
993
  s,
1077
- r
994
+ i
1078
995
  ), o = () => !!this.streamPresentationCurrent;
1079
- return this.cancelableSendPresentationWithRepeatedCalls = j({
996
+ return this.cancelableSendPresentationWithRepeatedCalls = J({
1080
997
  targetFunction: a,
1081
998
  isComplete: o,
1082
999
  isRejectAsValid: !0,
1083
- ...i
1000
+ ...r
1084
1001
  }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
1085
1002
  }
1086
1003
  // eslint-disable-next-line @typescript-eslint/max-params
1087
1004
  async sendPresentation(e, t, s, {
1088
- isNeedReinvite: r = !0,
1089
- contentHint: i = "detail",
1005
+ isNeedReinvite: i = !0,
1006
+ contentHint: r = "detail",
1090
1007
  degradationPreference: a,
1091
1008
  sendEncodings: o,
1092
1009
  onAddedTransceiver: c
1093
1010
  }) {
1094
- const d = L(s, { contentHint: i });
1011
+ const d = B(s, { contentHint: r });
1095
1012
  if (d === void 0)
1096
1013
  throw new Error("No streamPresentationTarget");
1097
1014
  this.streamPresentationCurrent = d;
1098
- const u = e().then(async () => t.startPresentation(d, r, {
1015
+ const u = e().then(async () => t.startPresentation(d, i, {
1099
1016
  degradationPreference: a,
1100
1017
  sendEncodings: o,
1101
1018
  onAddedTransceiver: c
@@ -1110,8 +1027,8 @@ class tt {
1110
1027
  const { connection: e } = this.callManager, { streamPresentationCurrent: t } = this, { maxBitrate: s } = this;
1111
1028
  if (!e || !t || s === void 0)
1112
1029
  return;
1113
- const r = e.getSenders();
1114
- await Ze(r, t, s);
1030
+ const i = e.getSenders();
1031
+ await Ke(i, t, s);
1115
1032
  };
1116
1033
  getRtcSessionProtected = () => {
1117
1034
  const e = this.callManager.getEstablishedRTCSession();
@@ -1132,7 +1049,7 @@ class tt {
1132
1049
  delete this.streamPresentationCurrent;
1133
1050
  }
1134
1051
  }
1135
- class nt {
1052
+ class et {
1136
1053
  data = {};
1137
1054
  getUa;
1138
1055
  constructor(e) {
@@ -1206,7 +1123,7 @@ class nt {
1206
1123
  }
1207
1124
  }
1208
1125
  var A = /* @__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))(A || {});
1209
- const he = [
1126
+ const ce = [
1210
1127
  "connecting",
1211
1128
  "connected",
1212
1129
  "disconnected",
@@ -1216,8 +1133,8 @@ const he = [
1216
1133
  "registrationFailed",
1217
1134
  "newMessage",
1218
1135
  "sipEvent"
1219
- ], ge = [...he], st = 3;
1220
- class rt {
1136
+ ], de = [...ce], tt = 3;
1137
+ class nt {
1221
1138
  cancelableConnectWithRepeatedCalls;
1222
1139
  JsSIP;
1223
1140
  events;
@@ -1236,15 +1153,15 @@ class rt {
1236
1153
  }
1237
1154
  connect = async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t));
1238
1155
  set = async ({ displayName: e }) => new Promise((t, s) => {
1239
- const r = this.getUa();
1240
- if (!r) {
1156
+ const i = this.getUa();
1157
+ if (!i) {
1241
1158
  s(new Error("this.ua is not initialized"));
1242
1159
  return;
1243
1160
  }
1244
- let i = !1;
1161
+ let r = !1;
1245
1162
  const a = this.getConnectionConfiguration();
1246
- e !== void 0 && e !== a.displayName && (i = r.set("display_name", se(e)), this.updateConnectionConfiguration("displayName", e));
1247
- const o = i;
1163
+ e !== void 0 && e !== a.displayName && (r = i.set("display_name", ne(e)), this.updateConnectionConfiguration("displayName", e));
1164
+ const o = r;
1248
1165
  o ? t(o) : s(new Error("nothing changed"));
1249
1166
  });
1250
1167
  disconnect = async () => {
@@ -1260,69 +1177,69 @@ class rt {
1260
1177
  cancelRequests() {
1261
1178
  this.cancelConnectWithRepeatedCalls();
1262
1179
  }
1263
- connectWithDuplicatedCalls = async (e, { callLimit: t = st } = {}) => {
1264
- const s = async () => this.connectInner(e), r = (i) => {
1265
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = i != null && !ke(i);
1180
+ connectWithDuplicatedCalls = async (e, { callLimit: t = tt } = {}) => {
1181
+ const s = async () => this.connectInner(e), i = (r) => {
1182
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !Me(r);
1266
1183
  return c || d;
1267
1184
  };
1268
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = j({
1185
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = J({
1269
1186
  targetFunction: s,
1270
- isComplete: r,
1187
+ isComplete: i,
1271
1188
  callLimit: t,
1272
1189
  isRejectAsValid: !0,
1273
1190
  isCheckBeforeCall: !1
1274
- }), this.cancelableConnectWithRepeatedCalls.then((i) => {
1275
- if (i instanceof this.JsSIP.UA)
1276
- return i;
1277
- throw i;
1191
+ }), this.cancelableConnectWithRepeatedCalls.then((r) => {
1192
+ if (r instanceof this.JsSIP.UA)
1193
+ return r;
1194
+ throw r;
1278
1195
  });
1279
1196
  };
1280
1197
  hasEqualConnectionConfiguration(e) {
1281
- const { configuration: t } = this.uaFactory.createConfiguration(e), r = this.getUa()?.configuration;
1282
- return r ? r.password === t.password && r.register === t.register && r.uri.toString() === t.uri && r.display_name === t.display_name && r.user_agent === t.user_agent && r.sockets === t.sockets && r.session_timers === t.session_timers && r.register_expires === t.register_expires && r.connection_recovery_min_interval === t.connection_recovery_min_interval && r.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1198
+ const { configuration: t } = this.uaFactory.createConfiguration(e), i = this.getUa()?.configuration;
1199
+ 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;
1283
1200
  }
1284
1201
  connectInner = async (e) => this.initUa(e).then(async () => this.start());
1285
1202
  initUa = async ({
1286
1203
  user: e,
1287
1204
  password: t,
1288
1205
  sipServerUrl: s,
1289
- sipWebSocketServerURL: r,
1290
- remoteAddress: i,
1206
+ sipWebSocketServerURL: i,
1207
+ remoteAddress: r,
1291
1208
  sessionTimers: a,
1292
1209
  registerExpires: o,
1293
1210
  connectionRecoveryMinInterval: c,
1294
1211
  connectionRecoveryMaxInterval: d,
1295
1212
  userAgent: u,
1296
1213
  displayName: T = "",
1297
- register: g = !1,
1214
+ register: l = !1,
1298
1215
  extraHeaders: S = []
1299
1216
  }) => {
1300
1217
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1301
1218
  sipServerUrl: s,
1302
1219
  displayName: T,
1303
- register: g,
1220
+ register: l,
1304
1221
  user: e,
1305
1222
  password: t
1306
1223
  }), this.getUa() && await this.disconnect();
1307
- const { ua: _, helpers: R } = this.uaFactory.createUAWithConfiguration(
1224
+ const { ua: I, helpers: R } = this.uaFactory.createUAWithConfiguration(
1308
1225
  {
1309
1226
  user: e,
1310
1227
  password: t,
1311
1228
  sipServerUrl: s,
1312
- sipWebSocketServerURL: r,
1229
+ sipWebSocketServerURL: i,
1313
1230
  displayName: T,
1314
- register: g,
1231
+ register: l,
1315
1232
  sessionTimers: a,
1316
1233
  registerExpires: o,
1317
1234
  connectionRecoveryMinInterval: c,
1318
1235
  connectionRecoveryMaxInterval: d,
1319
1236
  userAgent: u,
1320
- remoteAddress: i,
1237
+ remoteAddress: r,
1321
1238
  extraHeaders: S
1322
1239
  },
1323
1240
  this.events
1324
1241
  );
1325
- return this.setUa(_), this.setSipServerUrl(R.getSipServerUrl), this.setSocket(R.socket), _;
1242
+ return this.setUa(I), this.setSipServerUrl(R.getSipServerUrl), this.setSocket(R.socket), I;
1326
1243
  };
1327
1244
  start = async () => new Promise((e, t) => {
1328
1245
  const s = this.getUa();
@@ -1330,30 +1247,30 @@ class rt {
1330
1247
  t(new Error("this.ua is not initialized"));
1331
1248
  return;
1332
1249
  }
1333
- let r;
1334
- r = ((c, d) => {
1250
+ let i;
1251
+ i = ((c, d) => {
1335
1252
  if (this.getConnectionConfiguration().register === !0)
1336
1253
  return this.registrationManager.subscribeToStartEvents(c, d);
1337
- const T = A.CONNECTED, g = [A.DISCONNECTED];
1338
- return this.events.on(T, c), g.forEach((S) => {
1254
+ const T = A.CONNECTED, l = [A.DISCONNECTED];
1255
+ return this.events.on(T, c), l.forEach((S) => {
1339
1256
  this.events.on(S, d);
1340
1257
  }), () => {
1341
- this.events.off(T, c), g.forEach((S) => {
1258
+ this.events.off(T, c), l.forEach((S) => {
1342
1259
  this.events.off(S, d);
1343
1260
  });
1344
1261
  };
1345
1262
  })(() => {
1346
- r?.(), e(s);
1263
+ i?.(), e(s);
1347
1264
  }, (c) => {
1348
- r?.(), t(c);
1265
+ i?.(), t(c);
1349
1266
  }), s.start();
1350
1267
  });
1351
1268
  cancelConnectWithRepeatedCalls() {
1352
1269
  this.cancelableConnectWithRepeatedCalls?.cancel();
1353
1270
  }
1354
1271
  }
1355
- var le = /* @__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))(le || {});
1356
- const it = _e({
1272
+ var he = /* @__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))(he || {});
1273
+ const st = Ae({
1357
1274
  types: {
1358
1275
  context: {},
1359
1276
  events: {}
@@ -1667,17 +1584,17 @@ const it = _e({
1667
1584
  }
1668
1585
  }
1669
1586
  });
1670
- class at {
1587
+ class it {
1671
1588
  actor;
1672
1589
  stateChangeListeners = /* @__PURE__ */ new Set();
1673
1590
  events;
1674
1591
  unsubscribeFromEvents;
1675
1592
  actorSubscription;
1676
1593
  constructor(e) {
1677
- this.events = e, this.actor = me(it), this.actorSubscription = this.actor.subscribe((t) => {
1594
+ this.events = e, this.actor = Re(st), this.actorSubscription = this.actor.subscribe((t) => {
1678
1595
  const s = t.value;
1679
- this.stateChangeListeners.forEach((r) => {
1680
- r(s);
1596
+ this.stateChangeListeners.forEach((i) => {
1597
+ i(s);
1681
1598
  });
1682
1599
  }), this.actor.start(), this.subscribeToEvents();
1683
1600
  }
@@ -1760,7 +1677,7 @@ class at {
1760
1677
  return this.actor.getSnapshot().can({ type: e });
1761
1678
  }
1762
1679
  getValidEvents() {
1763
- return Object.values(le).filter((e) => this.canTransition(e));
1680
+ return Object.values(he).filter((e) => this.canTransition(e));
1764
1681
  }
1765
1682
  hasState(e) {
1766
1683
  return this.actor.getSnapshot().matches(e);
@@ -1829,7 +1746,7 @@ class at {
1829
1746
  };
1830
1747
  }
1831
1748
  }
1832
- class ot {
1749
+ class rt {
1833
1750
  events;
1834
1751
  getUaProtected;
1835
1752
  constructor(e) {
@@ -1856,17 +1773,17 @@ class ot {
1856
1773
  return this.register();
1857
1774
  }
1858
1775
  subscribeToStartEvents(e, t) {
1859
- const s = A.REGISTERED, r = [A.REGISTRATION_FAILED, A.DISCONNECTED];
1860
- return this.events.on(s, e), r.forEach((i) => {
1861
- this.events.on(i, t);
1776
+ const s = A.REGISTERED, i = [A.REGISTRATION_FAILED, A.DISCONNECTED];
1777
+ return this.events.on(s, e), i.forEach((r) => {
1778
+ this.events.on(r, t);
1862
1779
  }), () => {
1863
- this.events.off(s, e), r.forEach((i) => {
1864
- this.events.off(i, t);
1780
+ this.events.off(s, e), i.forEach((r) => {
1781
+ this.events.off(r, t);
1865
1782
  });
1866
1783
  };
1867
1784
  }
1868
1785
  }
1869
- class ct {
1786
+ class at {
1870
1787
  uaFactory;
1871
1788
  getUaProtected;
1872
1789
  constructor(e) {
@@ -1876,14 +1793,14 @@ class ct {
1876
1793
  * Отправляет SIP OPTIONS запрос к указанному адресу
1877
1794
  */
1878
1795
  async sendOptions(e, t, s) {
1879
- const r = this.getUaProtected();
1880
- return new Promise((i, a) => {
1796
+ const i = this.getUaProtected();
1797
+ return new Promise((r, a) => {
1881
1798
  try {
1882
- r.sendOptions(e, t, {
1799
+ i.sendOptions(e, t, {
1883
1800
  extraHeaders: s,
1884
1801
  eventHandlers: {
1885
1802
  succeeded: () => {
1886
- i();
1803
+ r();
1887
1804
  },
1888
1805
  failed: a
1889
1806
  }
@@ -1897,8 +1814,8 @@ class ct {
1897
1814
  * Отправляет SIP OPTIONS запрос к собственному URI (ping)
1898
1815
  */
1899
1816
  async ping(e, t) {
1900
- const r = this.getUaProtected().configuration.uri;
1901
- return this.sendOptions(r, e, t);
1817
+ const i = this.getUaProtected().configuration.uri;
1818
+ return this.sendOptions(i, e, t);
1902
1819
  }
1903
1820
  /**
1904
1821
  * Проверяет доступность телефонии, создавая временное соединение
@@ -1907,31 +1824,31 @@ class ct {
1907
1824
  userAgent: e,
1908
1825
  displayName: t,
1909
1826
  sipServerUrl: s,
1910
- sipWebSocketServerURL: r,
1911
- remoteAddress: i,
1827
+ sipWebSocketServerURL: i,
1828
+ remoteAddress: r,
1912
1829
  extraHeaders: a
1913
1830
  }) {
1914
1831
  return new Promise((o, c) => {
1915
1832
  const { configuration: d } = this.uaFactory.createConfiguration({
1916
- sipWebSocketServerURL: r,
1833
+ sipWebSocketServerURL: i,
1917
1834
  displayName: t,
1918
1835
  userAgent: e,
1919
1836
  sipServerUrl: s
1920
- }), u = this.uaFactory.createUA({ ...d, remoteAddress: i, extraHeaders: a }), T = () => {
1837
+ }), u = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), T = () => {
1921
1838
  const S = new Error("Telephony is not available");
1922
1839
  c(S);
1923
1840
  };
1924
1841
  u.once(A.DISCONNECTED, T);
1925
- const g = () => {
1842
+ const l = () => {
1926
1843
  u.removeAllListeners(), u.once(A.DISCONNECTED, () => {
1927
1844
  o();
1928
1845
  }), u.stop();
1929
1846
  };
1930
- u.once(A.CONNECTED, g), u.start();
1847
+ u.once(A.CONNECTED, l), u.start();
1931
1848
  });
1932
1849
  }
1933
1850
  }
1934
- const dt = (n) => {
1851
+ const ot = (n) => {
1935
1852
  const e = [];
1936
1853
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1937
1854
  };
@@ -1947,12 +1864,12 @@ class O {
1947
1864
  register: e,
1948
1865
  password: t,
1949
1866
  user: s,
1950
- sipServerUrl: r,
1951
- sipWebSocketServerURL: i
1867
+ sipServerUrl: i,
1868
+ sipWebSocketServerURL: r
1952
1869
  }) {
1953
- if (!r)
1954
- throw new Error("sipServerUrl is required");
1955
1870
  if (!i)
1871
+ throw new Error("sipServerUrl is required");
1872
+ if (!r)
1956
1873
  throw new Error("sipWebSocketServerURL is required");
1957
1874
  if (e && (t === void 0 || t === ""))
1958
1875
  throw new Error("password is required for authorized connection");
@@ -1960,18 +1877,18 @@ class O {
1960
1877
  throw new Error("user is required for authorized connection");
1961
1878
  }
1962
1879
  static resolveAuthorizationUser(e, t) {
1963
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${fe()}`;
1880
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${we()}`;
1964
1881
  }
1965
1882
  static buildExtraHeaders(e, t) {
1966
- const s = e !== void 0 && e !== "" ? dt(e) : [];
1883
+ const s = e !== void 0 && e !== "" ? ot(e) : [];
1967
1884
  return t === void 0 ? s : [...s, ...t];
1968
1885
  }
1969
1886
  createConfiguration({
1970
1887
  user: e,
1971
1888
  password: t,
1972
1889
  sipWebSocketServerURL: s,
1973
- displayName: r = "",
1974
- sipServerUrl: i,
1890
+ displayName: i = "",
1891
+ sipServerUrl: r,
1975
1892
  register: a = !1,
1976
1893
  sessionTimers: o = !1,
1977
1894
  registerExpires: c = 300,
@@ -1984,50 +1901,50 @@ class O {
1984
1901
  register: a,
1985
1902
  password: t,
1986
1903
  user: e,
1987
- sipServerUrl: i,
1904
+ sipServerUrl: r,
1988
1905
  sipWebSocketServerURL: s
1989
1906
  });
1990
- const g = O.resolveAuthorizationUser(a, e), S = Pe(i), I = S(g), _ = new this.JsSIP.WebSocketInterface(s);
1907
+ const l = O.resolveAuthorizationUser(a, e), S = ye(r), m = S(l), I = new this.JsSIP.WebSocketInterface(s);
1991
1908
  return {
1992
1909
  configuration: {
1993
1910
  password: t,
1994
1911
  register: a,
1995
- uri: I,
1996
- display_name: se(r),
1912
+ uri: m,
1913
+ display_name: ne(i),
1997
1914
  user_agent: T,
1998
1915
  sdpSemantics: "unified-plan",
1999
- sockets: [_],
1916
+ sockets: [I],
2000
1917
  session_timers: o,
2001
1918
  register_expires: c,
2002
1919
  connection_recovery_min_interval: d,
2003
1920
  connection_recovery_max_interval: u
2004
1921
  },
2005
1922
  helpers: {
2006
- socket: _,
1923
+ socket: I,
2007
1924
  getSipServerUrl: S
2008
1925
  }
2009
1926
  };
2010
1927
  }
2011
1928
  createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
2012
- const r = new this.JsSIP.UA(s), i = O.buildExtraHeaders(e, t);
2013
- return i.length > 0 && r.registrator().setExtraHeaders(i), r;
1929
+ const i = new this.JsSIP.UA(s), r = O.buildExtraHeaders(e, t);
1930
+ return r.length > 0 && i.registrator().setExtraHeaders(r), i;
2014
1931
  }
2015
1932
  /**
2016
1933
  * Создает UA с полным жизненным циклом - конфигурация + создание + настройка событий
2017
1934
  */
2018
1935
  createUAWithConfiguration(e, t) {
2019
- const { configuration: s, helpers: r } = this.createConfiguration(e), i = this.createUA({
1936
+ const { configuration: s, helpers: i } = this.createConfiguration(e), r = this.createUA({
2020
1937
  ...s,
2021
1938
  remoteAddress: e.remoteAddress,
2022
1939
  extraHeaders: e.extraHeaders
2023
1940
  });
2024
1941
  return t.eachTriggers((a, o) => {
2025
- const c = he.find((d) => d === o);
2026
- c && i.on(c, a);
2027
- }), { ua: i, helpers: r };
1942
+ const c = ce.find((d) => d === o);
1943
+ c && r.on(c, a);
1944
+ }), { ua: r, helpers: i };
2028
1945
  }
2029
1946
  }
2030
- class ht {
1947
+ class ct {
2031
1948
  events;
2032
1949
  ua;
2033
1950
  socket;
@@ -2039,15 +1956,15 @@ class ht {
2039
1956
  configurationManager;
2040
1957
  JsSIP;
2041
1958
  constructor({ JsSIP: e }) {
2042
- this.JsSIP = e, this.events = new D(ge), this.uaFactory = new O(e), this.registrationManager = new ot({
1959
+ this.JsSIP = e, this.events = new w(de), this.uaFactory = new O(e), this.registrationManager = new rt({
2043
1960
  events: this.events,
2044
1961
  getUaProtected: this.getUaProtected
2045
- }), this.stateMachine = new at(this.events), this.configurationManager = new nt({
1962
+ }), this.stateMachine = new it(this.events), this.configurationManager = new et({
2046
1963
  getUa: this.getUa
2047
- }), this.sipOperations = new ct({
1964
+ }), this.sipOperations = new at({
2048
1965
  uaFactory: this.uaFactory,
2049
1966
  getUaProtected: this.getUaProtected
2050
- }), this.connectionFlow = new rt({
1967
+ }), this.connectionFlow = new nt({
2051
1968
  JsSIP: this.JsSIP,
2052
1969
  events: this.events,
2053
1970
  uaFactory: this.uaFactory,
@@ -2138,9 +2055,9 @@ class ht {
2138
2055
  };
2139
2056
  getUa = () => this.ua;
2140
2057
  }
2141
- class gt {
2058
+ class dt {
2142
2059
  connectionManager;
2143
- stackPromises = Z({
2060
+ stackPromises = K({
2144
2061
  noRunIsNotActual: !0
2145
2062
  });
2146
2063
  constructor({ connectionManager: e }) {
@@ -2156,19 +2073,19 @@ class gt {
2156
2073
  ping = async (...e) => this.stackPromises.run(async () => this.connectionManager.ping(...e));
2157
2074
  set = async (...e) => this.stackPromises.run(async () => this.connectionManager.set(...e));
2158
2075
  }
2159
- var U = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(U || {}), x = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(x || {});
2160
- const ue = [
2076
+ var b = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(b || {});
2077
+ const le = [
2161
2078
  "incomingCall",
2162
2079
  "declinedIncomingCall",
2163
2080
  "terminatedIncomingCall",
2164
2081
  "failedIncomingCall"
2165
- ], lt = 486, ut = 487;
2166
- class Tt {
2082
+ ], ht = 486, lt = 487;
2083
+ class gt {
2167
2084
  events;
2168
2085
  incomingRTCSession;
2169
2086
  connectionManager;
2170
2087
  constructor(e) {
2171
- this.connectionManager = e, this.events = new D(ue), this.start();
2088
+ this.connectionManager = e, this.events = new w(le), this.start();
2172
2089
  }
2173
2090
  get remoteCallerData() {
2174
2091
  return {
@@ -2198,19 +2115,19 @@ class Tt {
2198
2115
  return this.removeIncomingSession(), e;
2199
2116
  };
2200
2117
  async declineToIncomingCall({
2201
- statusCode: e = ut
2118
+ statusCode: e = lt
2202
2119
  } = {}) {
2203
2120
  return new Promise((t, s) => {
2204
2121
  try {
2205
- const r = this.getIncomingRTCSession(), i = this.remoteCallerData;
2206
- this.removeIncomingSession(), this.events.trigger(U.DECLINED_INCOMING_CALL, i), r.terminate({ status_code: e }), t();
2207
- } catch (r) {
2208
- s(r);
2122
+ const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
2123
+ this.removeIncomingSession(), this.events.trigger(b.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2124
+ } catch (i) {
2125
+ s(i);
2209
2126
  }
2210
2127
  });
2211
2128
  }
2212
2129
  async busyIncomingCall() {
2213
- return this.declineToIncomingCall({ statusCode: lt });
2130
+ return this.declineToIncomingCall({ statusCode: ht });
2214
2131
  }
2215
2132
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2216
2133
  on(e, t) {
@@ -2241,25 +2158,25 @@ class Tt {
2241
2158
  originator: e,
2242
2159
  session: t
2243
2160
  }) => {
2244
- e === x.REMOTE && this.setIncomingSession(t);
2161
+ e === "remote" && this.setIncomingSession(t);
2245
2162
  };
2246
2163
  setIncomingSession(e) {
2247
2164
  this.incomingRTCSession = e;
2248
2165
  const t = this.remoteCallerData;
2249
2166
  e.on("failed", (s) => {
2250
- this.removeIncomingSession(), s.originator === x.LOCAL ? this.events.trigger(U.TERMINATED_INCOMING_CALL, t) : this.events.trigger(U.FAILED_INCOMING_CALL, t);
2251
- }), this.events.trigger(U.INCOMING_CALL, t);
2167
+ this.removeIncomingSession(), s.originator === "local" ? this.events.trigger(b.TERMINATED_INCOMING_CALL, t) : this.events.trigger(b.FAILED_INCOMING_CALL, t);
2168
+ }), this.events.trigger(b.INCOMING_CALL, t);
2252
2169
  }
2253
2170
  removeIncomingSession() {
2254
2171
  delete this.incomingRTCSession;
2255
2172
  }
2256
2173
  }
2257
- const b = 1e3;
2174
+ const y = 1e3;
2258
2175
  var C = /* @__PURE__ */ ((n) => (n.INBOUND_RTP = "inbound-rtp", n.REMOTE_OUTBOUND_RTP = "remote-outbound-rtp", n.MEDIA_SOURCE = "media-source", n.OUTBOUND_RTP = "outbound-rtp", n.REMOTE_INBOUND_RTP = "remote-inbound-rtp", n.CODEC = "codec", n.CANDIDATE_PAIR = "candidate-pair", n.CERTIFICATE = "certificate", n.TRANSPORT = "transport", n.LOCAL_CANDIDATE = "local-candidate", n.REMOTE_CANDIDATE = "remote-candidate", n))(C || {});
2259
- const Te = ["collected"], Y = () => "performance" in window ? performance.now() : Date.now(), w = (n) => [...n.keys()].reduce((e, t) => {
2176
+ const ge = ["collected"], Q = () => "performance" in window ? performance.now() : Date.now(), U = (n) => [...n.keys()].reduce((e, t) => {
2260
2177
  const s = n.get(t);
2261
2178
  return s === void 0 ? e : { ...e, [s.type]: s };
2262
- }, {}), St = (n) => {
2179
+ }, {}), ut = (n) => {
2263
2180
  if (!n)
2264
2181
  return {
2265
2182
  outboundRtp: void 0,
@@ -2267,14 +2184,14 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2267
2184
  mediaSource: void 0,
2268
2185
  remoteInboundRtp: void 0
2269
2186
  };
2270
- const e = w(n);
2187
+ const e = U(n);
2271
2188
  return {
2272
2189
  outboundRtp: e[C.OUTBOUND_RTP],
2273
2190
  codec: e[C.CODEC],
2274
2191
  mediaSource: e[C.MEDIA_SOURCE],
2275
2192
  remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2276
2193
  };
2277
- }, z = (n) => {
2194
+ }, Y = (n) => {
2278
2195
  if (!n)
2279
2196
  return {
2280
2197
  outboundRtp: void 0,
@@ -2282,14 +2199,14 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2282
2199
  mediaSource: void 0,
2283
2200
  remoteInboundRtp: void 0
2284
2201
  };
2285
- const e = w(n);
2202
+ const e = U(n);
2286
2203
  return {
2287
2204
  outboundRtp: e[C.OUTBOUND_RTP],
2288
2205
  codec: e[C.CODEC],
2289
2206
  mediaSource: e[C.MEDIA_SOURCE],
2290
2207
  remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
2291
2208
  };
2292
- }, X = ({
2209
+ }, z = ({
2293
2210
  videoReceiversStats: n,
2294
2211
  synchronizationSourcesVideo: e
2295
2212
  }) => {
@@ -2299,13 +2216,13 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2299
2216
  codec: void 0,
2300
2217
  synchronizationSources: e
2301
2218
  };
2302
- const t = w(n);
2219
+ const t = U(n);
2303
2220
  return {
2304
2221
  inboundRtp: t[C.INBOUND_RTP],
2305
2222
  codec: t[C.CODEC],
2306
2223
  synchronizationSources: e
2307
2224
  };
2308
- }, Ct = ({
2225
+ }, Tt = ({
2309
2226
  audioReceiverStats: n,
2310
2227
  synchronizationSourcesAudio: e
2311
2228
  }) => {
@@ -2316,14 +2233,14 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2316
2233
  remoteOutboundRtp: void 0,
2317
2234
  synchronizationSources: e
2318
2235
  };
2319
- const t = w(n);
2236
+ const t = U(n);
2320
2237
  return {
2321
2238
  inboundRtp: t[C.INBOUND_RTP],
2322
2239
  codec: t[C.CODEC],
2323
2240
  remoteOutboundRtp: t[C.REMOTE_OUTBOUND_RTP],
2324
2241
  synchronizationSources: e
2325
2242
  };
2326
- }, Se = (n) => {
2243
+ }, ue = (n) => {
2327
2244
  if (!n)
2328
2245
  return {
2329
2246
  candidatePair: void 0,
@@ -2332,7 +2249,7 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2332
2249
  remoteCandidate: void 0,
2333
2250
  transport: void 0
2334
2251
  };
2335
- const e = w(n);
2252
+ const e = U(n);
2336
2253
  return {
2337
2254
  candidatePair: e[C.CANDIDATE_PAIR],
2338
2255
  certificate: e[C.CERTIFICATE],
@@ -2340,63 +2257,63 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2340
2257
  remoteCandidate: e[C.REMOTE_CANDIDATE],
2341
2258
  transport: e[C.TRANSPORT]
2342
2259
  };
2343
- }, Et = ({
2260
+ }, St = ({
2344
2261
  audioSenderStats: n,
2345
2262
  videoSenderFirstStats: e,
2346
2263
  videoSenderSecondStats: t
2347
2264
  }) => ({
2348
- video: z(e),
2349
- secondVideo: z(t),
2350
- audio: St(n),
2351
- additional: Se(
2265
+ video: Y(e),
2266
+ secondVideo: Y(t),
2267
+ audio: ut(n),
2268
+ additional: ue(
2352
2269
  n ?? e ?? t
2353
2270
  )
2354
- }), Nt = ({
2271
+ }), Ct = ({
2355
2272
  audioReceiverStats: n,
2356
2273
  videoReceiverFirstStats: e,
2357
2274
  videoReceiverSecondStats: t,
2358
2275
  synchronizationSources: s
2359
2276
  }) => ({
2360
- video: X({
2277
+ video: z({
2361
2278
  videoReceiversStats: e,
2362
2279
  synchronizationSourcesVideo: s.video
2363
2280
  }),
2364
- secondVideo: X({
2281
+ secondVideo: z({
2365
2282
  videoReceiversStats: t,
2366
2283
  synchronizationSourcesVideo: s.video
2367
2284
  }),
2368
- audio: Ct({
2285
+ audio: Tt({
2369
2286
  audioReceiverStats: n,
2370
2287
  synchronizationSourcesAudio: s.audio
2371
2288
  }),
2372
- additional: Se(
2289
+ additional: ue(
2373
2290
  n ?? e ?? t
2374
2291
  )
2375
- }), At = ({
2292
+ }), Et = ({
2376
2293
  audioSenderStats: n,
2377
2294
  videoSenderFirstStats: e,
2378
2295
  videoSenderSecondStats: t,
2379
2296
  audioReceiverStats: s,
2380
- videoReceiverFirstStats: r,
2381
- videoReceiverSecondStats: i,
2297
+ videoReceiverFirstStats: i,
2298
+ videoReceiverSecondStats: r,
2382
2299
  synchronizationSources: a
2383
2300
  }) => {
2384
- const o = Et({
2301
+ const o = St({
2385
2302
  audioSenderStats: n,
2386
2303
  videoSenderFirstStats: e,
2387
2304
  videoSenderSecondStats: t
2388
- }), c = Nt({
2305
+ }), c = Ct({
2389
2306
  audioReceiverStats: s,
2390
- videoReceiverFirstStats: r,
2391
- videoReceiverSecondStats: i,
2307
+ videoReceiverFirstStats: i,
2308
+ videoReceiverSecondStats: r,
2392
2309
  synchronizationSources: a
2393
2310
  });
2394
2311
  return {
2395
2312
  outbound: o,
2396
2313
  inbound: c
2397
2314
  };
2398
- }, Rt = async (n) => {
2399
- const e = "audio", t = "video", s = n.getSenders(), r = s.find((g) => g.track?.kind === e), i = s.filter((g) => g.track?.kind === t), a = n.getReceivers(), o = a.find((g) => g.track.kind === e), c = a.filter((g) => g.track.kind === t), d = {
2315
+ }, Nt = async (n) => {
2316
+ const e = "audio", t = "video", s = n.getSenders(), i = s.find((l) => l.track?.kind === e), r = s.filter((l) => l.track?.kind === t), a = n.getReceivers(), o = a.find((l) => l.track.kind === e), c = a.filter((l) => l.track.kind === t), d = {
2400
2317
  trackIdentifier: o?.track.id,
2401
2318
  item: o?.getSynchronizationSources()[0]
2402
2319
  }, u = {
@@ -2407,47 +2324,47 @@ const Te = ["collected"], Y = () => "performance" in window ? performance.now()
2407
2324
  video: u
2408
2325
  };
2409
2326
  return Promise.all([
2410
- r?.getStats() ?? Promise.resolve(void 0),
2411
- i[0]?.getStats() ?? Promise.resolve(void 0),
2412
- i[1]?.getStats() ?? Promise.resolve(void 0),
2327
+ i?.getStats() ?? Promise.resolve(void 0),
2328
+ r[0]?.getStats() ?? Promise.resolve(void 0),
2329
+ r[1]?.getStats() ?? Promise.resolve(void 0),
2413
2330
  o?.getStats() ?? Promise.resolve(void 0),
2414
2331
  c[0]?.getStats() ?? Promise.resolve(void 0),
2415
2332
  c[1]?.getStats() ?? Promise.resolve(void 0)
2416
- ]).then((g) => {
2333
+ ]).then((l) => {
2417
2334
  const [
2418
2335
  S,
2336
+ m,
2419
2337
  I,
2420
- _,
2421
2338
  R,
2422
- y,
2423
- $
2424
- ] = g;
2339
+ D,
2340
+ k
2341
+ ] = l;
2425
2342
  return {
2426
2343
  synchronizationSources: T,
2427
2344
  audioSenderStats: S,
2428
- videoSenderFirstStats: I,
2429
- videoSenderSecondStats: _,
2345
+ videoSenderFirstStats: m,
2346
+ videoSenderSecondStats: I,
2430
2347
  audioReceiverStats: R,
2431
- videoReceiverFirstStats: y,
2432
- videoReceiverSecondStats: $
2348
+ videoReceiverFirstStats: D,
2349
+ videoReceiverSecondStats: k
2433
2350
  };
2434
2351
  });
2435
- }, It = (n) => {
2352
+ }, At = (n) => {
2436
2353
  E(String(n));
2437
2354
  };
2438
- class _t {
2355
+ class Rt {
2439
2356
  events;
2440
2357
  setTimeoutRequest;
2441
- requesterAllStatistics = new Re(Rt);
2358
+ requesterAllStatistics = new Ie(Nt);
2442
2359
  constructor() {
2443
- this.events = new K(Te), this.setTimeoutRequest = new ee();
2360
+ this.events = new H(ge), this.setTimeoutRequest = new j();
2444
2361
  }
2445
2362
  get requested() {
2446
2363
  return this.setTimeoutRequest.requested;
2447
2364
  }
2448
2365
  start(e, {
2449
- interval: t = b,
2450
- onError: s = It
2366
+ interval: t = y,
2367
+ onError: s = At
2451
2368
  } = {}) {
2452
2369
  this.stop(), this.setTimeoutRequest.request(() => {
2453
2370
  this.collectStatistics(e, {
@@ -2476,21 +2393,21 @@ class _t {
2476
2393
  collectStatistics = (e, {
2477
2394
  onError: t
2478
2395
  }) => {
2479
- const s = Y();
2480
- this.requesterAllStatistics.request(e).then((r) => {
2481
- this.events.trigger("collected", At(r));
2482
- const a = Y() - s;
2483
- let o = b;
2484
- a > 48 ? o = b * 4 : a > 32 ? o = b * 3 : a > 16 && (o = b * 2), this.start(e, {
2396
+ const s = Q();
2397
+ this.requesterAllStatistics.request(e).then((i) => {
2398
+ this.events.trigger("collected", Et(i));
2399
+ const a = Q() - s;
2400
+ let o = y;
2401
+ a > 48 ? o = y * 4 : a > 32 ? o = y * 3 : a > 16 && (o = y * 2), this.start(e, {
2485
2402
  onError: t,
2486
2403
  interval: o
2487
2404
  });
2488
- }).catch((r) => {
2489
- t && t(r);
2405
+ }).catch((i) => {
2406
+ t && t(i);
2490
2407
  });
2491
2408
  };
2492
2409
  }
2493
- class mt {
2410
+ class It {
2494
2411
  availableIncomingBitrate;
2495
2412
  statsPeerConnection;
2496
2413
  callManager;
@@ -2500,7 +2417,7 @@ class mt {
2500
2417
  callManager: e,
2501
2418
  apiManager: t
2502
2419
  }) {
2503
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new _t(), this.subscribe();
2420
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Rt(), this.subscribe();
2504
2421
  }
2505
2422
  get events() {
2506
2423
  return this.statsPeerConnection.events;
@@ -2542,33 +2459,141 @@ class mt {
2542
2459
  });
2543
2460
  }
2544
2461
  }
2545
- const Mt = (n, e) => n.filter((s) => e.some((r) => r.clockRate === s.clockRate && r.mimeType === s.mimeType && r.channels === s.channels && r.sdpFmtpLine === s.sdpFmtpLine)), pt = (n) => {
2546
- const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, r = t === null ? [] : t.codecs;
2547
- return Mt(s, r);
2548
- }, Pt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2549
- const r = e.indexOf(t.mimeType), i = e.indexOf(s.mimeType), a = r === -1 ? Number.MAX_VALUE : r, o = i === -1 ? Number.MAX_VALUE : i;
2462
+ const _t = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), mt = (n) => {
2463
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
2464
+ return _t(s, i);
2465
+ }, Mt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2466
+ const i = e.indexOf(t.mimeType), r = e.indexOf(s.mimeType), a = i === -1 ? Number.MAX_VALUE : i, o = r === -1 ? Number.MAX_VALUE : r;
2550
2467
  return a - o;
2551
- }), vt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), ft = (n, {
2468
+ }), pt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Pt = (n, {
2552
2469
  preferredMimeTypesVideoCodecs: e,
2553
2470
  excludeMimeTypesVideoCodecs: t
2554
2471
  }) => {
2555
2472
  try {
2556
2473
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
2557
- const s = pt("video"), r = vt(s, t), i = Pt(r, e);
2558
- n.setCodecPreferences(i);
2474
+ const s = mt("video"), i = pt(s, t), r = Mt(i, e);
2475
+ n.setCodecPreferences(r);
2559
2476
  }
2560
2477
  } catch (s) {
2561
2478
  E("setCodecPreferences error", s);
2562
2479
  }
2563
- }, Ot = (n) => [...n.keys()].map((e) => n.get(e)), Dt = (n, e) => Ot(n).find((t) => t?.type === e), yt = async (n) => n.getStats().then((e) => Dt(e, "codec")?.mimeType);
2564
- class bt {
2480
+ };
2481
+ class vt {
2482
+ /**
2483
+ * Хранилище основных transceiver'ов
2484
+ */
2485
+ transceivers = {};
2486
+ callManager;
2487
+ apiManager;
2488
+ constructor({
2489
+ callManager: e,
2490
+ apiManager: t
2491
+ }) {
2492
+ this.callManager = e, this.apiManager = t, this.subscribe();
2493
+ }
2494
+ /**
2495
+ * Сохраняет transceiver в соответствующем хранилище в зависимости от типа трека и mid
2496
+ */
2497
+ storeTransceiver(e, t) {
2498
+ const { kind: s } = t;
2499
+ if (s === "audio")
2500
+ this.transceivers.mainAudio ??= e;
2501
+ else {
2502
+ const { mid: i } = e;
2503
+ i === "2" ? this.transceivers.presentationVideo ??= e : this.transceivers.mainVideo ??= e;
2504
+ }
2505
+ }
2506
+ /**
2507
+ * Возвращает все сохраненные transceiver'ы
2508
+ */
2509
+ getTransceivers() {
2510
+ return { ...this.transceivers };
2511
+ }
2512
+ /**
2513
+ * Возвращает основной аудио transceiver
2514
+ */
2515
+ getMainAudioTransceiver() {
2516
+ return this.transceivers.mainAudio;
2517
+ }
2518
+ /**
2519
+ * Возвращает основной видео transceiver
2520
+ */
2521
+ getMainVideoTransceiver() {
2522
+ return this.transceivers.mainVideo;
2523
+ }
2524
+ /**
2525
+ * Возвращает презентационный видео transceiver
2526
+ */
2527
+ getPresentationVideoTransceiver() {
2528
+ return this.transceivers.presentationVideo;
2529
+ }
2530
+ /**
2531
+ * Проверяет, есть ли сохраненный transceiver для указанного типа
2532
+ */
2533
+ hasTransceiver(e) {
2534
+ return this.transceivers[e] !== void 0;
2535
+ }
2536
+ /**
2537
+ * Очищает все сохраненные transceiver'ы
2538
+ */
2539
+ clear() {
2540
+ this.transceivers.mainVideo = void 0, this.transceivers.mainAudio = void 0, this.transceivers.presentationVideo = void 0;
2541
+ }
2542
+ /**
2543
+ * Возвращает количество сохраненных transceiver'ов
2544
+ */
2545
+ getCount() {
2546
+ let e = 0;
2547
+ return this.transceivers.mainAudio && (e += 1), this.transceivers.mainVideo && (e += 1), this.transceivers.presentationVideo && (e += 1), e;
2548
+ }
2549
+ /**
2550
+ * Проверяет, пустое ли хранилище
2551
+ */
2552
+ isEmpty() {
2553
+ return this.getCount() === 0;
2554
+ }
2555
+ /**
2556
+ * Обрабатывает событие restart от ApiManager
2557
+ */
2558
+ handleRestart = (e) => {
2559
+ this.updateTransceivers(e).catch((t) => {
2560
+ E("Failed to update transceivers", t);
2561
+ }).finally(() => {
2562
+ this.callManager.restartIce().catch((t) => {
2563
+ E("Failed to restart ICE", t);
2564
+ });
2565
+ });
2566
+ };
2567
+ /**
2568
+ * Обновляет transceiver'ы в соответствии с данными restart
2569
+ */
2570
+ updateTransceivers = async (e) => {
2571
+ const { videoTrackCount: t } = e;
2572
+ t === 2 && (this.getTransceivers().presentationVideo !== void 0 || await this.callManager.addTransceiver("video", {
2573
+ direction: "recvonly"
2574
+ }).catch((r) => {
2575
+ E("Failed to add presentation video transceiver", r);
2576
+ }));
2577
+ };
2578
+ subscribe() {
2579
+ this.callManager.on("peerconnection:ontrack", this.handleTrack), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded), this.apiManager.on("restart", this.handleRestart);
2580
+ }
2581
+ handleTrack = (e) => {
2582
+ this.storeTransceiver(e.transceiver, e.track);
2583
+ };
2584
+ handleEnded = () => {
2585
+ this.clear();
2586
+ };
2587
+ }
2588
+ const ft = (n) => [...n.keys()].map((e) => n.get(e)), Ot = (n, e) => ft(n).find((t) => t?.type === e), Dt = async (n) => n.getStats().then((e) => Ot(e, "codec")?.mimeType);
2589
+ class yt {
2565
2590
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2566
2591
  async getCodecFromSender(e) {
2567
- return await yt(e) ?? "";
2592
+ return await Dt(e) ?? "";
2568
2593
  }
2569
2594
  }
2570
- class Ut {
2571
- stackPromises = Z({
2595
+ class bt {
2596
+ stackPromises = K({
2572
2597
  noRunIsNotActual: !0
2573
2598
  });
2574
2599
  /**
@@ -2596,26 +2621,26 @@ class wt {
2596
2621
  taskQueue;
2597
2622
  onSetParameters;
2598
2623
  constructor(e) {
2599
- this.onSetParameters = e, this.taskQueue = new Ut();
2624
+ this.onSetParameters = e, this.taskQueue = new bt();
2600
2625
  }
2601
2626
  async setEncodingsToSender(e, t) {
2602
- return this.taskQueue.add(async () => ce(e, t, this.onSetParameters));
2627
+ return this.taskQueue.add(async () => ae(e, t, this.onSetParameters));
2603
2628
  }
2604
2629
  stop() {
2605
2630
  this.taskQueue.stop();
2606
2631
  }
2607
2632
  }
2608
- const Ce = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Lt = 1e6, p = (n) => n * Lt, Ee = p(0.06), Ne = p(4), Bt = (n) => n <= 64 ? Ee : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ne, kt = "av1", Ft = (n) => Ce(n, kt), $t = 0.6, Q = (n, e) => Ft(e) ? n * $t : n, Vt = (n) => Q(Ee, n), Wt = (n) => Q(Ne, n), J = (n, e) => {
2609
- const t = Bt(n);
2610
- return Q(t, e);
2611
- }, V = 1, Ht = ({
2633
+ const Te = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Ut = 1e6, p = (n) => n * Ut, Se = p(0.06), Ce = p(4), Lt = (n) => n <= 64 ? Se : n <= 128 ? p(0.12) : n <= 256 ? p(0.25) : n <= 384 ? p(0.32) : n <= 426 ? p(0.38) : n <= 640 ? p(0.5) : n <= 848 ? p(0.7) : n <= 1280 ? p(1) : n <= 1920 ? p(2) : Ce, Bt = "av1", kt = (n) => Te(n, Bt), Ft = 0.6, G = (n, e) => kt(e) ? n * Ft : n, $t = (n) => G(Se, n), Vt = (n) => G(Ce, n), X = (n, e) => {
2634
+ const t = Lt(n);
2635
+ return G(t, e);
2636
+ }, F = 1, Wt = ({
2612
2637
  videoTrack: n,
2613
2638
  targetSize: e
2614
2639
  }) => {
2615
- const t = n.getSettings(), s = t.width, r = t.height, i = s === void 0 ? V : s / e.width, a = r === void 0 ? V : r / e.height;
2616
- return Math.max(i, a, V);
2640
+ const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? F : s / e.width, a = i === void 0 ? F : i / e.height;
2641
+ return Math.max(r, a, F);
2617
2642
  };
2618
- class xt {
2643
+ class Ht {
2619
2644
  ignoreForCodec;
2620
2645
  senderFinder;
2621
2646
  codecProvider;
@@ -2634,8 +2659,8 @@ class xt {
2634
2659
  senderFinder: e,
2635
2660
  codecProvider: t,
2636
2661
  parametersSetter: s
2637
- }, r) {
2638
- this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = r.ignoreForCodec;
2662
+ }, i) {
2663
+ this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = i.ignoreForCodec;
2639
2664
  }
2640
2665
  /**
2641
2666
  * Выполняет балансировку на основе заголовков от сервера
@@ -2644,21 +2669,21 @@ class xt {
2644
2669
  * @returns Promise с результатом балансировки
2645
2670
  */
2646
2671
  async balance(e, t) {
2647
- const s = e.getSenders(), r = this.senderFinder.findVideoSender(s);
2648
- if (!r?.track)
2649
- return { ...this.resultNoChanged, sender: r };
2650
- const i = await this.codecProvider.getCodecFromSender(r);
2651
- if (Ce(i, this.ignoreForCodec))
2652
- return { ...this.resultNoChanged, sender: r };
2672
+ const s = e.getSenders(), i = this.senderFinder.findVideoSender(s);
2673
+ if (!i?.track)
2674
+ return { ...this.resultNoChanged, sender: i };
2675
+ const r = await this.codecProvider.getCodecFromSender(i);
2676
+ if (Te(r, this.ignoreForCodec))
2677
+ return { ...this.resultNoChanged, sender: i };
2653
2678
  const { mainCam: a, resolutionMainCam: o } = t ?? {};
2654
2679
  return this.processSender(
2655
2680
  { mainCam: a, resolutionMainCam: o },
2656
2681
  {
2657
- sender: r,
2658
- codec: i,
2659
- videoTrack: r.track
2682
+ sender: i,
2683
+ codec: r,
2684
+ videoTrack: i.track
2660
2685
  }
2661
- ).then((c) => ({ ...c, sender: r }));
2686
+ ).then((c) => ({ ...c, sender: i }));
2662
2687
  }
2663
2688
  /**
2664
2689
  * Обрабатывает отправитель в зависимости от команды управления
@@ -2666,14 +2691,14 @@ class xt {
2666
2691
  * @returns Promise с результатом обработки
2667
2692
  */
2668
2693
  async processSender(e, t) {
2669
- const { mainCam: s, resolutionMainCam: r } = e;
2694
+ const { mainCam: s, resolutionMainCam: i } = e;
2670
2695
  switch (s) {
2671
2696
  case P.PAUSE_MAIN_CAM:
2672
2697
  return this.downgradeResolutionSender(t);
2673
2698
  case P.RESUME_MAIN_CAM:
2674
2699
  return this.setBitrateByTrackResolution(t);
2675
2700
  case P.MAX_MAIN_CAM_RESOLUTION:
2676
- return r !== void 0 ? this.setResolutionSender(r, t) : this.setBitrateByTrackResolution(t);
2701
+ return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
2677
2702
  case P.ADMIN_STOP_MAIN_CAM:
2678
2703
  case P.ADMIN_START_MAIN_CAM:
2679
2704
  case void 0:
@@ -2688,11 +2713,11 @@ class xt {
2688
2713
  * @returns Promise с результатом
2689
2714
  */
2690
2715
  async downgradeResolutionSender(e) {
2691
- const { sender: t, codec: s } = e, r = {
2716
+ const { sender: t, codec: s } = e, i = {
2692
2717
  scaleResolutionDownBy: 200,
2693
- maxBitrate: Vt(s)
2718
+ maxBitrate: $t(s)
2694
2719
  };
2695
- return this.parametersSetter.setEncodingsToSender(t, r);
2720
+ return this.parametersSetter.setEncodingsToSender(t, i);
2696
2721
  }
2697
2722
  /**
2698
2723
  * Устанавливает битрейт на основе разрешения трека
@@ -2700,7 +2725,7 @@ class xt {
2700
2725
  * @returns Promise с результатом
2701
2726
  */
2702
2727
  async setBitrateByTrackResolution(e) {
2703
- const { sender: t, videoTrack: s, codec: r } = e, a = s.getSettings().width, o = a === void 0 ? Wt(r) : J(a, r);
2728
+ const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? Vt(i) : X(a, i);
2704
2729
  return this.parametersSetter.setEncodingsToSender(t, {
2705
2730
  scaleResolutionDownBy: 1,
2706
2731
  maxBitrate: o
@@ -2713,27 +2738,27 @@ class xt {
2713
2738
  * @returns Promise с результатом
2714
2739
  */
2715
2740
  async setResolutionSender(e, t) {
2716
- const [s, r] = e.split("x"), { sender: i, videoTrack: a, codec: o } = t, c = {
2741
+ const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
2717
2742
  width: Number(s),
2718
- height: Number(r)
2719
- }, d = Ht({
2743
+ height: Number(i)
2744
+ }, d = Wt({
2720
2745
  videoTrack: a,
2721
2746
  targetSize: c
2722
- }), u = J(c.width, o), T = {
2747
+ }), u = X(c.width, o), T = {
2723
2748
  scaleResolutionDownBy: d,
2724
2749
  maxBitrate: u
2725
2750
  };
2726
- return this.parametersSetter.setEncodingsToSender(i, T);
2751
+ return this.parametersSetter.setEncodingsToSender(r, T);
2727
2752
  }
2728
2753
  }
2729
- const qt = (n) => n.find((e) => e.track?.kind === "video");
2730
- class Gt {
2754
+ const xt = (n) => n.find((e) => e.track?.kind === "video");
2755
+ class qt {
2731
2756
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2732
2757
  findVideoSender(e) {
2733
- return qt(e);
2758
+ return xt(e);
2734
2759
  }
2735
2760
  }
2736
- class Qt {
2761
+ class Gt {
2737
2762
  currentSender;
2738
2763
  originalReplaceTrack;
2739
2764
  lastWidth;
@@ -2746,7 +2771,7 @@ class Qt {
2746
2771
  pollIntervalMs: e = 1e3,
2747
2772
  maxPollIntervalMs: t
2748
2773
  }) {
2749
- this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new ee();
2774
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new j();
2750
2775
  }
2751
2776
  /**
2752
2777
  * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
@@ -2765,8 +2790,8 @@ class Qt {
2765
2790
  attachSender(e, t) {
2766
2791
  this.currentSender = e;
2767
2792
  const s = e.replaceTrack.bind(e);
2768
- this.originalReplaceTrack = s, e.replaceTrack = async (r) => {
2769
- await s(r), this.attachTrack(t, r ?? void 0), t();
2793
+ this.originalReplaceTrack = s, e.replaceTrack = async (i) => {
2794
+ await s(i), this.attachTrack(t, i ?? void 0), t();
2770
2795
  }, this.attachTrack(t, e.track);
2771
2796
  }
2772
2797
  detachSender() {
@@ -2775,8 +2800,8 @@ class Qt {
2775
2800
  attachTrack(e, t) {
2776
2801
  if (this.detachTrack(), !t)
2777
2802
  return;
2778
- const { width: s, height: r } = t.getSettings();
2779
- this.lastWidth = s, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2803
+ const { width: s, height: i } = t.getSettings();
2804
+ this.lastWidth = s, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
2780
2805
  }
2781
2806
  /**
2782
2807
  * Периодически опрашивает track с экспоненциальной адаптацией частоты.
@@ -2785,8 +2810,8 @@ class Qt {
2785
2810
  */
2786
2811
  schedulePoll(e, t) {
2787
2812
  const s = () => {
2788
- const { width: r, height: i } = e.getSettings();
2789
- r !== this.lastWidth || i !== this.lastHeight ? (this.lastWidth = r, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2813
+ const { width: i, height: r } = e.getSettings();
2814
+ i !== this.lastWidth || r !== this.lastHeight ? (this.lastWidth = i, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
2790
2815
  this.currentPollIntervalMs * 2,
2791
2816
  this.maxPollIntervalMs
2792
2817
  ), this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
@@ -2797,7 +2822,7 @@ class Qt {
2797
2822
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
2798
2823
  }
2799
2824
  }
2800
- class Yt {
2825
+ class Qt {
2801
2826
  apiManager;
2802
2827
  currentHandler;
2803
2828
  constructor(e) {
@@ -2817,7 +2842,7 @@ class Yt {
2817
2842
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
2818
2843
  }
2819
2844
  }
2820
- class zt {
2845
+ class Yt {
2821
2846
  eventHandler;
2822
2847
  senderBalancer;
2823
2848
  parametersSetterWithQueue;
@@ -2826,19 +2851,19 @@ class zt {
2826
2851
  trackMonitor;
2827
2852
  constructor(e, t, {
2828
2853
  ignoreForCodec: s,
2829
- onSetParameters: r,
2830
- pollIntervalMs: i
2854
+ onSetParameters: i,
2855
+ pollIntervalMs: r
2831
2856
  } = {}) {
2832
- this.getConnection = t, this.eventHandler = new Yt(e), this.parametersSetterWithQueue = new wt(r), this.senderBalancer = new xt(
2857
+ this.getConnection = t, this.eventHandler = new Qt(e), this.parametersSetterWithQueue = new wt(i), this.senderBalancer = new Ht(
2833
2858
  {
2834
- senderFinder: new Gt(),
2835
- codecProvider: new bt(),
2859
+ senderFinder: new qt(),
2860
+ codecProvider: new yt(),
2836
2861
  parametersSetter: this.parametersSetterWithQueue
2837
2862
  },
2838
2863
  {
2839
2864
  ignoreForCodec: s
2840
2865
  }
2841
- ), this.trackMonitor = new Qt({ pollIntervalMs: i });
2866
+ ), this.trackMonitor = new Gt({ pollIntervalMs: r });
2842
2867
  }
2843
2868
  /**
2844
2869
  * Подписывается на события управления главной камерой
@@ -2883,13 +2908,13 @@ class zt {
2883
2908
  });
2884
2909
  };
2885
2910
  }
2886
- const Ae = [
2911
+ const Ee = [
2887
2912
  "balancing-scheduled",
2888
2913
  "balancing-started",
2889
2914
  "balancing-stopped",
2890
2915
  "parameters-updated"
2891
2916
  ];
2892
- class Xt {
2917
+ class zt {
2893
2918
  isBalancingActive = !1;
2894
2919
  events;
2895
2920
  callManager;
@@ -2897,13 +2922,13 @@ class Xt {
2897
2922
  videoSendingBalancer;
2898
2923
  startBalancingTimer;
2899
2924
  constructor(e, t, s = {}) {
2900
- this.events = new K(Ae), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new zt(
2925
+ this.events = new H(Ee), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Yt(
2901
2926
  t,
2902
2927
  () => e.connection,
2903
2928
  {
2904
2929
  ...s,
2905
- onSetParameters: (r) => {
2906
- this.events.trigger("parameters-updated", r), s.onSetParameters?.(r);
2930
+ onSetParameters: (i) => {
2931
+ this.events.trigger("parameters-updated", i), s.onSetParameters?.(i);
2907
2932
  }
2908
2933
  }
2909
2934
  ), this.subscribe();
@@ -2967,16 +2992,16 @@ class Xt {
2967
2992
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
2968
2993
  }
2969
2994
  }
2970
- const Jt = 1e6, Kt = ge.map((n) => `connection:${n}`), jt = ne.map((n) => `call:${n}`), Zt = ie.map((n) => `api:${n}`), en = ue.map((n) => `incoming-call:${n}`), tn = de.map((n) => `presentation:${n}`), nn = Te.map((n) => `stats:${n}`), sn = Ae.map((n) => `video-balancer:${n}`), rn = [
2995
+ const Xt = 1e6, Jt = de.map((n) => `connection:${n}`), Kt = te.map((n) => `call:${n}`), jt = Z.map((n) => `api:${n}`), Zt = le.map((n) => `incoming-call:${n}`), en = oe.map((n) => `presentation:${n}`), tn = ge.map((n) => `stats:${n}`), nn = Ee.map((n) => `video-balancer:${n}`), sn = [
2996
+ ...Jt,
2971
2997
  ...Kt,
2972
2998
  ...jt,
2973
2999
  ...Zt,
2974
3000
  ...en,
2975
3001
  ...tn,
2976
- ...nn,
2977
- ...sn
3002
+ ...nn
2978
3003
  ];
2979
- class Nn {
3004
+ class En {
2980
3005
  events;
2981
3006
  connectionManager;
2982
3007
  connectionQueueManager;
@@ -2986,28 +3011,32 @@ class Nn {
2986
3011
  presentationManager;
2987
3012
  statsManager;
2988
3013
  videoSendingBalancerManager;
3014
+ transceiverManager;
2989
3015
  preferredMimeTypesVideoCodecs;
2990
3016
  excludeMimeTypesVideoCodecs;
2991
3017
  constructor({ JsSIP: e }, {
2992
3018
  preferredMimeTypesVideoCodecs: t,
2993
3019
  excludeMimeTypesVideoCodecs: s,
2994
- videoBalancerOptions: r
3020
+ videoBalancerOptions: i
2995
3021
  } = {}) {
2996
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new D(rn), this.connectionManager = new ht({ JsSIP: e }), this.connectionQueueManager = new gt({
3022
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new w(sn), this.connectionManager = new ct({ JsSIP: e }), this.connectionQueueManager = new dt({
2997
3023
  connectionManager: this.connectionManager
2998
- }), this.callManager = new we(), this.apiManager = new Ve({
3024
+ }), this.callManager = new Fe(), this.apiManager = new ve({
2999
3025
  connectionManager: this.connectionManager,
3000
3026
  callManager: this.callManager
3001
- }), this.incomingCallManager = new Tt(this.connectionManager), this.presentationManager = new tt({
3027
+ }), this.incomingCallManager = new gt(this.connectionManager), this.presentationManager = new Ze({
3002
3028
  callManager: this.callManager,
3003
- maxBitrate: Jt
3004
- }), this.statsManager = new mt({
3029
+ maxBitrate: Xt
3030
+ }), this.statsManager = new It({
3031
+ callManager: this.callManager,
3032
+ apiManager: this.apiManager
3033
+ }), this.transceiverManager = new vt({
3005
3034
  callManager: this.callManager,
3006
3035
  apiManager: this.apiManager
3007
- }), this.videoSendingBalancerManager = new Xt(
3036
+ }), this.videoSendingBalancerManager = new zt(
3008
3037
  this.callManager,
3009
3038
  this.apiManager,
3010
- r
3039
+ i
3011
3040
  ), this.subscribe();
3012
3041
  }
3013
3042
  get requestedConnection() {
@@ -3087,9 +3116,7 @@ class Nn {
3087
3116
  this.getSipServerUrl,
3088
3117
  {
3089
3118
  ...s,
3090
- onAddedTransceiver: async (r, i, a) => {
3091
- this.setCodecPreferences(r), await t?.(r, i, a);
3092
- }
3119
+ onAddedTransceiver: this.resolveHandleAddTransceiver(t)
3093
3120
  }
3094
3121
  );
3095
3122
  };
@@ -3100,9 +3127,7 @@ class Nn {
3100
3127
  this.incomingCallManager.extractIncomingRTCSession,
3101
3128
  {
3102
3129
  ...s,
3103
- onAddedTransceiver: async (r, i, a) => {
3104
- this.setCodecPreferences(r), await t?.(r, i, a);
3105
- }
3130
+ onAddedTransceiver: this.resolveHandleAddTransceiver(t)
3106
3131
  }
3107
3132
  );
3108
3133
  };
@@ -3112,7 +3137,7 @@ class Nn {
3112
3137
  getRemoteStreams = () => this.callManager.getRemoteStreams();
3113
3138
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
3114
3139
  async startPresentation(e, t = {}) {
3115
- const { isP2P: s, callLimit: r, onAddedTransceiver: i, ...a } = t;
3140
+ const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
3116
3141
  return this.presentationManager.startPresentation(
3117
3142
  async () => {
3118
3143
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
@@ -3120,11 +3145,9 @@ class Nn {
3120
3145
  e,
3121
3146
  {
3122
3147
  ...a,
3123
- onAddedTransceiver: async (o, c, d) => {
3124
- this.setCodecPreferences(o), await i?.(o, c, d);
3125
- }
3148
+ onAddedTransceiver: this.resolveHandleAddTransceiver(r)
3126
3149
  },
3127
- r === void 0 ? void 0 : { callLimit: r }
3150
+ i === void 0 ? void 0 : { callLimit: i }
3128
3151
  );
3129
3152
  }
3130
3153
  async stopPresentation(e = {}) {
@@ -3134,17 +3157,15 @@ class Nn {
3134
3157
  });
3135
3158
  }
3136
3159
  async updatePresentation(e, t = {}) {
3137
- const { isP2P: s, onAddedTransceiver: r, ...i } = t;
3160
+ const { isP2P: s, onAddedTransceiver: i, ...r } = t;
3138
3161
  return this.presentationManager.updatePresentation(
3139
3162
  async () => {
3140
3163
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
3141
3164
  },
3142
3165
  e,
3143
3166
  {
3144
- ...i,
3145
- onAddedTransceiver: async (a, o, c) => {
3146
- this.setCodecPreferences(a), await r?.(a, o, c);
3147
- }
3167
+ ...r,
3168
+ onAddedTransceiver: this.resolveHandleAddTransceiver(i)
3148
3169
  }
3149
3170
  );
3150
3171
  }
@@ -3191,73 +3212,38 @@ class Nn {
3191
3212
  return this.apiManager.askPermissionToEnableCam(...e);
3192
3213
  }
3193
3214
  setCodecPreferences(e) {
3194
- ft(e, {
3215
+ Pt(e, {
3195
3216
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
3196
3217
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
3197
3218
  });
3198
3219
  }
3199
3220
  subscribe() {
3200
- this.connectionManager.events.eachTriggers((e, t) => {
3201
- this.connectionManager.on(t, (s) => {
3202
- this.events.trigger(`connection:${t}`, s);
3203
- });
3204
- }), this.callManager.events.eachTriggers((e, t) => {
3205
- this.callManager.on(t, (s) => {
3206
- this.events.trigger(`call:${t}`, s);
3207
- });
3208
- }), this.apiManager.events.eachTriggers((e, t) => {
3209
- this.apiManager.on(t, (s) => {
3210
- this.events.trigger(`api:${t}`, s);
3211
- });
3212
- }), this.incomingCallManager.events.eachTriggers((e, t) => {
3213
- this.incomingCallManager.on(t, (s) => {
3214
- this.events.trigger(`incoming-call:${t}`, s);
3215
- });
3216
- }), this.presentationManager.events.eachTriggers((e, t) => {
3217
- this.presentationManager.on(t, (s) => {
3218
- this.events.trigger(`presentation:${t}`, s);
3219
- });
3220
- }), this.statsManager.events.eachTriggers((e, t) => {
3221
- this.statsManager.on(t, (s) => {
3222
- this.events.trigger(`stats:${t}`, s);
3223
- });
3224
- }), this.videoSendingBalancerManager.events.eachTriggers((e, t) => {
3225
- this.videoSendingBalancerManager.on(t, (s) => {
3226
- this.events.trigger(`video-balancer:${t}`, s);
3227
- });
3228
- }), this.apiManager.on("restart", this.handleRestart);
3221
+ this.bridgeEvents("connection", this.connectionManager), this.bridgeEvents("call", this.callManager), this.bridgeEvents("api", this.apiManager), this.bridgeEvents("incoming-call", this.incomingCallManager), this.bridgeEvents("presentation", this.presentationManager), this.bridgeEvents("stats", this.statsManager), this.bridgeEvents("video-balancer", this.videoSendingBalancerManager);
3229
3222
  }
3230
- handleRestart = (e) => {
3231
- this.updateTransceivers(e).catch((t) => {
3232
- E("Failed to update transceivers", t);
3233
- }).finally(() => {
3234
- this.callManager.restartIce().catch((t) => {
3235
- E("Failed to restart ICE", t);
3223
+ bridgeEvents = (e, t) => {
3224
+ t.events.eachTriggers((s, i) => {
3225
+ t.on(i, (r) => {
3226
+ this.events.trigger(`${e}:${i}`, r);
3236
3227
  });
3237
3228
  });
3238
3229
  };
3239
- updateTransceivers = async (e) => {
3240
- const { videoTrackCount: t } = e;
3241
- t === 2 && (this.callManager.getTransceivers().presentationVideo !== void 0 || await this.callManager.addTransceiver("video", {
3242
- direction: "recvonly"
3243
- }).catch((i) => {
3244
- E("Failed to add presentation video transceiver", i);
3245
- }));
3230
+ resolveHandleAddTransceiver = (e) => async (t, s, i) => {
3231
+ this.setCodecPreferences(t), await e?.(t, s, i);
3246
3232
  };
3247
3233
  }
3248
3234
  export {
3249
- re as E,
3250
- F as O,
3251
- Nn as S,
3252
- Ke as a,
3253
- $e as b,
3235
+ se as E,
3236
+ fe as O,
3237
+ En as S,
3238
+ Xe as a,
3239
+ Pe as b,
3254
3240
  C as c,
3255
- Cn as d,
3256
- Sn as e,
3257
- _t as f,
3258
- yt as g,
3259
- En as h,
3241
+ Sn as d,
3242
+ Tn as e,
3243
+ Rt as f,
3244
+ Dt as g,
3245
+ Cn as h,
3260
3246
  E as l,
3261
- L as p,
3262
- ce as s
3247
+ B as p,
3248
+ ae as s
3263
3249
  };