sip-connector 25.4.0 → 25.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,23 @@
1
- import ie from "debug";
2
- import { TypedEvents as f } from "events-constructor";
3
- import { CancelableRequest as X, isCanceledError as st } from "@krivega/cancelable-promise";
4
- import { resolveRequesterByTimeout as it, requesterByTimeoutsWithFailCalls as rt, DelayRequester as at, hasCanceledError as ot, SetTimeoutRequest as Ae } from "@krivega/timeout-requester";
5
- import { repeatedCallsAsync as re, hasCanceledError as ct } from "repeated-calls";
6
- import { createActor as dt, setup as V, assign as I } from "xstate";
7
- import { createStackPromises as Ie, isPromiseIsNotActualError as ht } from "stack-promises";
1
+ import { IncomingResponse as rt, C as at } from "@krivega/jssip";
2
+ import oe from "debug";
3
+ import { TypedEvents as M } from "events-constructor";
4
+ import { CancelableRequest as X, isCanceledError as ot } from "@krivega/cancelable-promise";
5
+ import { resolveRequesterByTimeout as ct, requesterByTimeoutsWithFailCalls as dt, DelayRequester as ht, hasCanceledError as lt, SetTimeoutRequest as ve } from "@krivega/timeout-requester";
6
+ import { repeatedCallsAsync as ce, hasCanceledError as ut } from "repeated-calls";
7
+ import { createActor as gt, setup as V, assign as v } from "xstate";
8
+ import { createStackPromises as fe, isPromiseIsNotActualError as Tt } from "stack-promises";
8
9
  import "ua-parser-js";
9
10
  import "sequent-promises";
10
- import lt from "lodash";
11
- const ae = "sip-connector", d = ie(ae), he = (n, e) => {
11
+ import Et from "lodash";
12
+ const de = "sip-connector", d = oe(de), ue = (n, e) => {
12
13
  d(`${n}:`, e);
13
- }, bi = () => {
14
- ie.enable(ae);
15
- }, Oi = () => {
16
- ie.enable(`-${ae}`);
17
- }, ut = "Error decline with 603", gt = 1006, Tt = (n) => typeof n == "object" && n !== null && "code" in n && n.code === gt, Et = (n) => n.message === ut;
18
- var Y = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(Y || {}), w = /* @__PURE__ */ ((n) => (n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", 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))(w || {}), O = /* @__PURE__ */ ((n) => (n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.STATS = "application/vinteo.webrtc.stats", n))(O || {}), b = /* @__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))(b || {}), z = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(z || {}), ve = /* @__PURE__ */ ((n) => (n.H264 = "H264", n.VP8 = "VP8", n.VP9 = "VP9", n.AV1 = "AV1", n))(ve || {}), 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.CONTENTED_STREAM_STATE = "x-webrtc-share-state", n.CONTENTED_STREAM_CODEC = "x-webrtc-share-codec", 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.AUDIO_ID = "x-webrtc-audioid", n.BEARER_TOKEN = "x-bearer-token", n))(h || {}), q = /* @__PURE__ */ ((n) => (n.AVAILABLE_CONTENTED_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_CONTENTED_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(q || {}), F = /* @__PURE__ */ ((n) => (n.AVAILABLE_CONTENTED_STREAM = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_CONTENTED_STREAM = "x-webrtc-share-state: CONTENTEND", n.ACK_PERMISSION_TO_START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.STOPPED_CLIENT_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.ENABLE_MAIN_CAM = "x-webrtc-request-enable-media-device: LETMESTARTMAINCAM", n))(F || {}), J = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(J || {}), fe = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(fe || {}), u = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "enter-room", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "use-license", n.NEW_DTMF = "new-dtmf", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CONTENTED_STREAM_AVAILABLE = "contented-stream:available", n.CONTENTED_STREAM_NOT_AVAILABLE = "contented-stream:not-available", n.PRESENTATION_MUST_STOP = "presentation:must-stop", n.CHANNELS_ALL = "channels:all", 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_SPECTATORS_SYNTHETIC = "participant:move-request-to-spectators-synthetic", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID = "participant:move-request-to-spectators-with-audio-id", 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.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))(u || {});
19
- const Me = [
14
+ }, Gi = () => {
15
+ oe.enable(de);
16
+ }, qi = () => {
17
+ oe.enable(`-${de}`);
18
+ }, St = "Error decline with 603", mt = 1006, pt = (n) => typeof n == "object" && n !== null && "code" in n && n.code === mt, Ct = (n) => n.message === St;
19
+ var z = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(z || {}), P = /* @__PURE__ */ ((n) => (n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", 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))(P || {}), O = /* @__PURE__ */ ((n) => (n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.STATS = "application/vinteo.webrtc.stats", n))(O || {}), b = /* @__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))(b || {}), J = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(J || {}), Me = /* @__PURE__ */ ((n) => (n.H264 = "H264", n.VP8 = "VP8", n.VP9 = "VP9", n.AV1 = "AV1", n))(Me || {}), 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.CONTENTED_STREAM_STATE = "x-webrtc-share-state", n.CONTENTED_STREAM_CODEC = "x-webrtc-share-codec", 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.AUDIO_ID = "x-webrtc-audioid", n.BEARER_TOKEN = "x-bearer-token", n.IS_DIRECT_PEER_TO_PEER = "x-webrtc-is-direct-p2p", n))(h || {}), q = /* @__PURE__ */ ((n) => (n.AVAILABLE_CONTENTED_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_CONTENTED_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(q || {}), F = /* @__PURE__ */ ((n) => (n.AVAILABLE_CONTENTED_STREAM = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_CONTENTED_STREAM = "x-webrtc-share-state: CONTENTEND", n.ACK_PERMISSION_TO_START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.STOPPED_CLIENT_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.ENABLE_MAIN_CAM = "x-webrtc-request-enable-media-device: LETMESTARTMAINCAM", n))(F || {}), j = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(j || {}), _e = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(_e || {}), u = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "enter-room", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "use-license", n.NEW_DTMF = "new-dtmf", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CONTENTED_STREAM_AVAILABLE = "contented-stream:available", n.CONTENTED_STREAM_NOT_AVAILABLE = "contented-stream:not-available", n.PRESENTATION_MUST_STOP = "presentation:must-stop", n.CHANNELS_ALL = "channels:all", 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_SPECTATORS_SYNTHETIC = "participant:move-request-to-spectators-synthetic", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID = "participant:move-request-to-spectators-with-audio-id", 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.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.FAILED_SEND_ROOM_DIRECT_P2P = "failed-send-room-direct-p2p", n))(u || {});
20
+ const be = [
20
21
  "enter-room",
21
22
  "main-cam-control",
22
23
  "use-license",
@@ -44,16 +45,23 @@ const Me = [
44
45
  "admin:stop-main-cam",
45
46
  "admin:start-mic",
46
47
  "admin:stop-mic",
47
- "admin:force-sync-media-state"
48
- ], St = () => new f(Me), mt = (n) => typeof n == "string" && n.trim().length > 0, L = (n, e) => {
48
+ "admin:force-sync-media-state",
49
+ "failed-send-room-direct-p2p"
50
+ ], Rt = () => new M(be), Nt = (n) => typeof n == "string" && n.trim().length > 0, w = (n, e) => {
49
51
  const t = e.toLowerCase(), s = Object.entries(n).find(([, i]) => typeof i == "string" && i.toLowerCase() === t);
50
52
  return s ? s[1] : void 0;
51
- }, pt = (n) => typeof n == "string" && !Number.isNaN(Number(n)) && Number.isFinite(Number(n)), Ct = (n) => {
52
- if (pt(n))
53
+ }, At = (n) => typeof n == "string" && !Number.isNaN(Number(n)) && Number.isFinite(Number(n)), It = (n) => {
54
+ if (At(n))
53
55
  return Number(n);
54
- }, R = (n, e) => {
56
+ }, vt = (n) => {
57
+ const e = n.toLowerCase();
58
+ if (e === "true" || e === "1")
59
+ return !0;
60
+ if (e === "false" || e === "0")
61
+ return !1;
62
+ }, N = (n, e) => {
55
63
  const t = n.getHeader(e.toLowerCase());
56
- if (!mt(t))
64
+ if (!Nt(t))
57
65
  return;
58
66
  const s = t.toLowerCase();
59
67
  switch (e) {
@@ -76,33 +84,35 @@ const Me = [
76
84
  case h.AVAILABLE_INCOMING_BITRATE:
77
85
  case h.AUDIO_TRACK_COUNT:
78
86
  case h.VIDEO_TRACK_COUNT:
79
- return Ct(s);
87
+ return It(s);
80
88
  case h.CONTENTED_STREAM_CODEC:
81
- return L(ve, s);
89
+ return w(Me, s);
82
90
  case h.CONTENT_TYPE:
83
- return L(w, s);
91
+ return w(P, s);
84
92
  case h.CONTENT_USE_LICENSE:
85
- return L(fe, s);
93
+ return w(_e, s);
86
94
  case h.MAIN_CAM:
87
- return L(b, s);
95
+ return w(b, s);
88
96
  case h.MIC:
89
- return L(z, s);
97
+ return w(J, s);
90
98
  case h.MEDIA_SYNC:
91
- return L(J, s);
99
+ return w(j, s);
92
100
  case h.CONTENT_PARTICIPANT_STATE:
93
- return L(Y, s);
101
+ return w(z, s);
94
102
  case h.CONTENTED_STREAM_STATE:
95
- return L(q, s);
103
+ return w(q, s);
104
+ case h.IS_DIRECT_PEER_TO_PEER:
105
+ return vt(s);
96
106
  default:
97
107
  return;
98
108
  }
99
109
  };
100
- var v = /* @__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))(v || {});
101
- class Nt {
110
+ var f = /* @__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))(f || {});
111
+ class ft {
102
112
  events;
103
113
  callManager;
104
114
  constructor() {
105
- this.events = St();
115
+ this.events = Rt();
106
116
  }
107
117
  subscribe({
108
118
  connectionManager: e,
@@ -141,6 +151,11 @@ class Nt {
141
151
  ];
142
152
  return s.sendInfo(O.CHANNELS, void 0, { extraHeaders: a });
143
153
  }
154
+ sendEnterRoom(e) {
155
+ this.sendEnterRoomProtected(e).catch((t) => {
156
+ this.events.trigger(u.FAILED_SEND_ROOM_DIRECT_P2P, { error: t });
157
+ });
158
+ }
144
159
  async sendMediaState({ cam: e, mic: t }, s = {}) {
145
160
  const i = this.getEstablishedRTCSessionProtected(), r = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
146
161
  r,
@@ -203,7 +218,7 @@ class Nt {
203
218
  ...e,
204
219
  extraHeaders: s
205
220
  }).catch((i) => {
206
- if (Et(i))
221
+ if (Ct(i))
207
222
  throw i;
208
223
  });
209
224
  }
@@ -244,55 +259,55 @@ class Nt {
244
259
  };
245
260
  handleNotify = (e) => {
246
261
  switch (e.cmd) {
247
- case v.CHANNELS: {
262
+ case f.CHANNELS: {
248
263
  const t = e;
249
264
  this.triggerChannelsNotify(t);
250
265
  break;
251
266
  }
252
- case v.WEBCAST_STARTED: {
267
+ case f.WEBCAST_STARTED: {
253
268
  const t = e;
254
269
  this.triggerWebcastStartedNotify(t);
255
270
  break;
256
271
  }
257
- case v.WEBCAST_STOPPED: {
272
+ case f.WEBCAST_STOPPED: {
258
273
  const t = e;
259
274
  this.triggerWebcastStoppedNotify(t);
260
275
  break;
261
276
  }
262
- case v.ADDED_TO_LIST_MODERATORS: {
277
+ case f.ADDED_TO_LIST_MODERATORS: {
263
278
  const t = e;
264
279
  this.triggerAddedToListModeratorsNotify(t);
265
280
  break;
266
281
  }
267
- case v.REMOVED_FROM_LIST_MODERATORS: {
282
+ case f.REMOVED_FROM_LIST_MODERATORS: {
268
283
  const t = e;
269
284
  this.triggerRemovedFromListModeratorsNotify(t);
270
285
  break;
271
286
  }
272
- case v.ACCEPTING_WORD_REQUEST: {
287
+ case f.ACCEPTING_WORD_REQUEST: {
273
288
  const t = e;
274
289
  this.triggerParticipationAcceptingWordRequest(t);
275
290
  break;
276
291
  }
277
- case v.CANCELLING_WORD_REQUEST: {
292
+ case f.CANCELLING_WORD_REQUEST: {
278
293
  const t = e;
279
294
  this.triggerParticipationCancellingWordRequest(t);
280
295
  break;
281
296
  }
282
- case v.MOVE_REQUEST_TO_STREAM: {
297
+ case f.MOVE_REQUEST_TO_STREAM: {
283
298
  const t = e;
284
299
  this.triggerParticipantMoveRequestToStream(t);
285
300
  break;
286
301
  }
287
- case v.ACCOUNT_CHANGED: {
302
+ case f.ACCOUNT_CHANGED: {
288
303
  this.triggerAccountChangedNotify();
289
304
  break;
290
305
  }
291
- case v.ACCOUNT_DELETED: {
306
+ case f.ACCOUNT_DELETED: {
292
307
  this.triggerAccountDeletedNotify();
293
308
  break;
294
309
  }
295
- case v.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
310
+ case f.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
296
311
  const t = e;
297
312
  this.triggerConferenceParticipantTokenIssued(t);
298
313
  break;
@@ -305,34 +320,34 @@ class Nt {
305
320
  const { originator: t } = e;
306
321
  if (t !== "remote")
307
322
  return;
308
- const { request: s } = e, i = s, r = R(i, h.CONTENT_TYPE);
323
+ const { request: s } = e, i = s, r = N(i, h.CONTENT_TYPE);
309
324
  if (r !== void 0)
310
325
  switch (r) {
311
- case w.ENTER_ROOM: {
326
+ case P.ENTER_ROOM: {
312
327
  this.triggerEnterRoom(i), this.maybeTriggerChannels(i);
313
328
  break;
314
329
  }
315
- case w.NOTIFY: {
330
+ case P.NOTIFY: {
316
331
  this.maybeHandleNotify(i);
317
332
  break;
318
333
  }
319
- case w.SHARE_STATE: {
334
+ case P.SHARE_STATE: {
320
335
  this.triggerContentedStreamState(i);
321
336
  break;
322
337
  }
323
- case w.MAIN_CAM: {
338
+ case P.MAIN_CAM: {
324
339
  this.triggerMainCamControl(i);
325
340
  break;
326
341
  }
327
- case w.MIC: {
342
+ case P.MIC: {
328
343
  this.triggerMicControl(i);
329
344
  break;
330
345
  }
331
- case w.USE_LICENSE: {
346
+ case P.USE_LICENSE: {
332
347
  this.triggerUseLicense(i);
333
348
  break;
334
349
  }
335
- case w.PARTICIPANT_STATE: {
350
+ case P.PARTICIPANT_STATE: {
336
351
  this.maybeTriggerParticipantMoveRequest(i);
337
352
  break;
338
353
  }
@@ -429,7 +444,7 @@ class Nt {
429
444
  );
430
445
  };
431
446
  maybeTriggerChannels = (e) => {
432
- const t = R(e, h.INPUT_CHANNELS), s = R(e, h.OUTPUT_CHANNELS);
447
+ const t = N(e, h.INPUT_CHANNELS), s = N(e, h.OUTPUT_CHANNELS);
433
448
  if (t !== void 0 && s !== void 0) {
434
449
  const i = {
435
450
  inputChannels: t,
@@ -439,15 +454,20 @@ class Nt {
439
454
  }
440
455
  };
441
456
  triggerEnterRoom = (e) => {
442
- const t = R(e, h.CONTENT_ENTER_ROOM), s = R(e, h.PARTICIPANT_NAME), i = R(e, h.BEARER_TOKEN);
443
- t !== void 0 && s !== void 0 && this.events.trigger(u.ENTER_ROOM, { room: t, participantName: s, bearerToken: i });
457
+ const t = N(e, h.CONTENT_ENTER_ROOM), s = N(e, h.PARTICIPANT_NAME), i = N(e, h.BEARER_TOKEN), r = N(e, h.IS_DIRECT_PEER_TO_PEER);
458
+ t !== void 0 && s !== void 0 && this.events.trigger(u.ENTER_ROOM, {
459
+ room: t,
460
+ participantName: s,
461
+ bearerToken: i,
462
+ isDirectPeerToPeer: r
463
+ });
444
464
  };
445
465
  triggerContentedStreamState = (e) => {
446
- const t = R(e, h.CONTENTED_STREAM_STATE);
466
+ const t = N(e, h.CONTENTED_STREAM_STATE);
447
467
  if (t !== void 0)
448
468
  switch (t) {
449
469
  case q.AVAILABLE_CONTENTED_STREAM: {
450
- const s = R(e, h.CONTENTED_STREAM_CODEC);
470
+ const s = N(e, h.CONTENTED_STREAM_CODEC);
451
471
  this.events.trigger(u.CONTENTED_STREAM_AVAILABLE, { codec: s });
452
472
  break;
453
473
  }
@@ -462,16 +482,16 @@ class Nt {
462
482
  }
463
483
  };
464
484
  maybeTriggerParticipantMoveRequest = (e) => {
465
- const t = R(e, h.CONTENT_PARTICIPANT_STATE), s = R(e, h.AUDIO_ID);
466
- t === Y.SPECTATOR && (s === void 0 ? (this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_SYNTHETIC, {}), this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, { isSynthetic: !0 })) : (this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID, {
485
+ const t = N(e, h.CONTENT_PARTICIPANT_STATE), s = N(e, h.AUDIO_ID);
486
+ t === z.SPECTATOR && (s === void 0 ? (this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_SYNTHETIC, {}), this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, { isSynthetic: !0 })) : (this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID, {
467
487
  audioId: s
468
488
  }), this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, {
469
489
  isSynthetic: !1,
470
490
  audioId: s
471
- }))), t === Y.PARTICIPANT && this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
491
+ }))), t === z.PARTICIPANT && this.events.trigger(u.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
472
492
  };
473
493
  triggerMainCamControl = (e) => {
474
- const t = R(e, h.MAIN_CAM), s = R(e, h.MEDIA_SYNC), i = s === J.ADMIN_SYNC_FORCED;
494
+ const t = N(e, h.MAIN_CAM), s = N(e, h.MEDIA_SYNC), i = s === j.ADMIN_SYNC_FORCED;
475
495
  if (t === b.ADMIN_START_MAIN_CAM) {
476
496
  this.events.trigger(u.ADMIN_START_MAIN_CAM, { isSyncForced: i });
477
497
  return;
@@ -481,26 +501,29 @@ class Nt {
481
501
  return;
482
502
  }
483
503
  (t === b.RESUME_MAIN_CAM || t === b.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(u.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
484
- const r = R(e, h.MAIN_CAM_RESOLUTION);
504
+ const r = N(e, h.MAIN_CAM_RESOLUTION);
485
505
  this.events.trigger(u.MAIN_CAM_CONTROL, {
486
506
  mainCam: t,
487
507
  resolutionMainCam: r
488
508
  });
489
509
  };
490
510
  triggerMicControl = (e) => {
491
- const t = R(e, h.MIC), i = R(e, h.MEDIA_SYNC) === J.ADMIN_SYNC_FORCED;
492
- t === z.ADMIN_START_MIC ? this.events.trigger(u.ADMIN_START_MIC, { isSyncForced: i }) : t === z.ADMIN_STOP_MIC && this.events.trigger(u.ADMIN_STOP_MIC, { isSyncForced: i });
511
+ const t = N(e, h.MIC), i = N(e, h.MEDIA_SYNC) === j.ADMIN_SYNC_FORCED;
512
+ t === J.ADMIN_START_MIC ? this.events.trigger(u.ADMIN_START_MIC, { isSyncForced: i }) : t === J.ADMIN_STOP_MIC && this.events.trigger(u.ADMIN_STOP_MIC, { isSyncForced: i });
493
513
  };
494
514
  triggerUseLicense = (e) => {
495
- const t = R(e, h.CONTENT_USE_LICENSE);
515
+ const t = N(e, h.CONTENT_USE_LICENSE);
496
516
  t !== void 0 && this.events.trigger(u.USE_LICENSE, t);
497
517
  };
518
+ async sendEnterRoomProtected(e) {
519
+ return this.getEstablishedRTCSessionProtected().sendInfo(P.ENTER_ROOM, void 0, { extraHeaders: e });
520
+ }
498
521
  }
499
- const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
522
+ const Mt = /^p2p.+to.+$/i, Oe = (n) => n !== void 0 && n.length > 0 && Mt.test(n), _t = "purgatory", Pe = (n) => n === _t, bt = (n, e) => {
500
523
  n.getVideoTracks().forEach((s) => {
501
524
  "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
502
525
  });
503
- }, Q = (n, {
526
+ }, Y = (n, {
504
527
  directionVideo: e,
505
528
  directionAudio: t,
506
529
  contentHint: s
@@ -508,8 +531,8 @@ const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
508
531
  if (!n || e === "recvonly" && t === "recvonly")
509
532
  return;
510
533
  const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
511
- return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && At(o, s), o;
512
- }, It = "api/v2/rtp2webrtc/offer", vt = async ({
534
+ return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && bt(o, s), o;
535
+ }, Ot = "api/v2/rtp2webrtc/offer", Pt = async ({
513
536
  serverUrl: n,
514
537
  conferenceNumber: e,
515
538
  quality: t,
@@ -518,7 +541,7 @@ const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
518
541
  token: r
519
542
  }) => {
520
543
  const a = new URL(
521
- `https://${n.replace(/\/$/, "")}/${It}/${encodeURIComponent(e)}`
544
+ `https://${n.replace(/\/$/, "")}/${Ot}/${encodeURIComponent(e)}`
522
545
  );
523
546
  a.searchParams.set("quality", t), a.searchParams.set("audio", String(s));
524
547
  const o = {
@@ -540,39 +563,39 @@ const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
540
563
  return l;
541
564
  }
542
565
  };
543
- }, ft = (n, e) => (n.degradationPreference = e.degradationPreference, n), Mt = (n, e) => {
566
+ }, yt = (n, e) => (n.degradationPreference = e.degradationPreference, n), Dt = (n, e) => {
544
567
  n.encodings ??= [];
545
568
  for (let t = n.encodings.length; t < e; t += 1)
546
569
  n.encodings.push({});
547
570
  return n;
548
- }, be = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, _t = be(), bt = (n, e) => {
549
- if (_t(n, e))
571
+ }, ye = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, Lt = ye(), wt = (n, e) => {
572
+ if (Lt(n, e))
550
573
  return n;
551
- }, Ot = (n, e, { isResetAllowed: t = !1 } = {}) => {
552
- const s = n.maxBitrate, i = bt(e, s);
574
+ }, Ut = (n, e, { isResetAllowed: t = !1 } = {}) => {
575
+ const s = n.maxBitrate, i = wt(e, s);
553
576
  return (i !== void 0 || t) && (n.maxBitrate = i), n;
554
- }, Oe = 1, yt = be(
555
- Oe
556
- ), Dt = (n, e) => {
557
- const t = n === void 0 ? void 0 : Math.max(n, Oe);
558
- if (t !== void 0 && yt(
577
+ }, De = 1, Ft = ye(
578
+ De
579
+ ), kt = (n, e) => {
580
+ const t = n === void 0 ? void 0 : Math.max(n, De);
581
+ if (t !== void 0 && Ft(
559
582
  t,
560
583
  e
561
584
  ))
562
585
  return t;
563
- }, Pt = (n, e) => {
564
- const t = n.scaleResolutionDownBy, s = Dt(
586
+ }, Bt = (n, e) => {
587
+ const t = n.scaleResolutionDownBy, s = kt(
565
588
  e,
566
589
  t
567
590
  );
568
591
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
569
- }, wt = (n, e, { isResetAllowed: t } = {}) => {
592
+ }, $t = (n, e, { isResetAllowed: t } = {}) => {
570
593
  const s = e.encodings?.length ?? 0;
571
- return Mt(n, s), n.encodings.forEach((i, r) => {
594
+ return Dt(n, s), n.encodings.forEach((i, r) => {
572
595
  const a = (e?.encodings ?? [])[r], o = a?.maxBitrate, c = a?.scaleResolutionDownBy;
573
- Ot(i, o, { isResetAllowed: t }), Pt(i, c);
596
+ Ut(i, o, { isResetAllowed: t }), Bt(i, c);
574
597
  }), n;
575
- }, Lt = (n, e) => {
598
+ }, Gt = (n, e) => {
576
599
  if (n.codecs?.length !== e.codecs?.length)
577
600
  return !0;
578
601
  for (let t = 0; t < (n.codecs?.length ?? 0); t++)
@@ -589,15 +612,15 @@ const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
589
612
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
590
613
  return !0;
591
614
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
592
- }, te = async (n, e, { isResetAllowed: t } = {}) => {
615
+ }, ie = async (n, e, { isResetAllowed: t } = {}) => {
593
616
  const s = n.getParameters(), i = JSON.parse(
594
617
  JSON.stringify(s)
595
618
  );
596
- wt(s, e, { isResetAllowed: t }), ft(s, e);
597
- const r = Lt(i, s);
619
+ $t(s, e, { isResetAllowed: t }), yt(s, e);
620
+ const r = Gt(i, s);
598
621
  return r && await n.setParameters(s), { parameters: s, isChanged: r };
599
- }, ye = async (n, e, t) => {
600
- const { isChanged: s, parameters: i } = await te(n, {
622
+ }, Le = async (n, e, t) => {
623
+ const { isChanged: s, parameters: i } = await ie(n, {
601
624
  encodings: [
602
625
  {
603
626
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -606,12 +629,12 @@ const Rt = "purgatory", _e = (n) => n === Rt, At = (n, e) => {
606
629
  ]
607
630
  });
608
631
  return s && t && t(i), { isChanged: s, parameters: i };
609
- }, Ut = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ft = async (n, e, t) => {
610
- const s = Ut(n, e);
632
+ }, qt = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Vt = async (n, e, t) => {
633
+ const s = qt(n, e);
611
634
  if (s)
612
- return ye(s, { maxBitrate: t });
635
+ return Le(s, { maxBitrate: t });
613
636
  };
614
- class kt {
637
+ class xt {
615
638
  command = void 0;
616
639
  unsubscribe;
617
640
  options;
@@ -632,7 +655,7 @@ class x {
632
655
  subscriptions = [];
633
656
  stateChangeListeners = /* @__PURE__ */ new Set();
634
657
  constructor(e) {
635
- this.actor = dt(e), this.actor.start(), this.addSubscription(
658
+ this.actor = gt(e), this.actor.start(), this.addSubscription(
636
659
  this.subscribe((t) => {
637
660
  const s = t.value;
638
661
  this.stateChangeListeners.forEach((i) => {
@@ -674,37 +697,38 @@ class x {
674
697
  return this.subscriptions.push(t), t;
675
698
  }
676
699
  }
677
- var ne = /* @__PURE__ */ ((n) => (n.IDLE = "call:idle", n.CONNECTING = "call:connecting", n.PURGATORY = "call:purgatory", n.IN_ROOM = "call:inRoom", n))(ne || {});
678
- const M = "evaluate", j = (n) => typeof n == "string" && n.length > 0, oe = (n) => "number" in n && j(n.number) && typeof n.answer == "boolean", De = (n) => "room" in n && j(n.room) && j(n.participantName), Pe = (n) => "token" in n && j(n.token), Bt = (n) => oe(n) && De(n) && !Pe(n) && "room" in n && _e(n.room), we = (n) => oe(n) && De(n) && Pe(n), $t = {}, le = () => ({
700
+ var re = /* @__PURE__ */ ((n) => (n.IDLE = "call:idle", n.CONNECTING = "call:connecting", n.PURGATORY = "call:purgatory", n.P2P_ROOM = "call:p2pRoom", n.DIRECT_P2P_ROOM = "call:directP2pRoom", n.IN_ROOM = "call:inRoom", n))(re || {});
701
+ const A = "evaluate", K = (n) => typeof n == "string" && n.length > 0, H = (n) => "number" in n && K(n.number) && typeof n.answer == "boolean", Z = (n) => "room" in n && K(n.room) && K(n.participantName), ee = (n) => "token" in n && K(n.token), we = ({ isDirectPeerToPeer: n }) => n === !0, Ht = (n) => Pe(n.room) || Oe(n.room) || we(n), Wt = (n) => H(n) && Z(n) && !ee(n) && "room" in n && Pe(n.room), Qt = (n) => H(n) && Z(n) && !ee(n) && "room" in n && Oe(n.room), Yt = (n) => "isDirectPeerToPeer" in n && we(n), zt = (n) => H(n) && Z(n) && !ee(n) && "room" in n && Yt(n), Ue = (n) => H(n) && Z(n) && ee(n), Jt = {}, ge = () => ({
679
702
  number: void 0,
680
703
  answer: void 0,
681
704
  room: void 0,
682
705
  participantName: void 0,
683
- token: void 0
684
- }), Gt = V({
706
+ token: void 0,
707
+ isDirectPeerToPeer: void 0
708
+ }), jt = V({
685
709
  types: {
686
- context: $t,
710
+ context: Jt,
687
711
  events: {}
688
712
  },
689
713
  actions: {
690
- setConnecting: I(({ event: n, context: e }) => n.type !== "CALL.CONNECTING" ? e : {
691
- ...le(),
714
+ setConnecting: v(({ event: n, context: e }) => n.type !== "CALL.CONNECTING" ? e : {
715
+ ...ge(),
692
716
  number: n.number,
693
717
  answer: n.answer
694
718
  }),
695
- setRoomInfo: I(({ event: n, context: e }) => {
719
+ setRoomInfo: v(({ event: n, context: e }) => {
696
720
  if (n.type !== "CALL.ENTER_ROOM")
697
721
  return e;
698
722
  const t = {
699
723
  room: n.room,
700
724
  participantName: n.participantName
701
725
  };
702
- return n.token !== void 0 ? t.token = n.token : _e(n.room) && (t.token = void 0), t;
726
+ return n.token !== void 0 ? t.token = n.token : Ht(n) && (t.token = void 0), n.isDirectPeerToPeer !== void 0 && (t.isDirectPeerToPeer = n.isDirectPeerToPeer), t;
703
727
  }),
704
- setTokenInfo: I(({ event: n, context: e }) => n.type !== "CALL.TOKEN_ISSUED" ? e : {
728
+ setTokenInfo: v(({ event: n, context: e }) => n.type !== "CALL.TOKEN_ISSUED" ? e : {
705
729
  token: n.token
706
730
  }),
707
- reset: I(le())
731
+ reset: v(ge())
708
732
  }
709
733
  }).createMachine({
710
734
  id: "call",
@@ -714,7 +738,7 @@ const M = "evaluate", j = (n) => typeof n == "string" && n.length > 0, oe = (n)
714
738
  "call:idle": {
715
739
  on: {
716
740
  "CALL.CONNECTING": {
717
- target: M,
741
+ target: A,
718
742
  actions: "setConnecting"
719
743
  }
720
744
  }
@@ -722,15 +746,15 @@ const M = "evaluate", j = (n) => typeof n == "string" && n.length > 0, oe = (n)
722
746
  "call:connecting": {
723
747
  on: {
724
748
  "CALL.ENTER_ROOM": {
725
- target: M,
749
+ target: A,
726
750
  actions: "setRoomInfo"
727
751
  },
728
752
  "CALL.TOKEN_ISSUED": {
729
- target: M,
753
+ target: A,
730
754
  actions: "setTokenInfo"
731
755
  },
732
756
  "CALL.RESET": {
733
- target: M,
757
+ target: A,
734
758
  actions: "reset"
735
759
  }
736
760
  }
@@ -738,32 +762,40 @@ const M = "evaluate", j = (n) => typeof n == "string" && n.length > 0, oe = (n)
738
762
  "call:inRoom": {
739
763
  on: {
740
764
  "CALL.ENTER_ROOM": {
741
- target: M,
765
+ target: A,
742
766
  actions: "setRoomInfo"
743
767
  },
744
768
  "CALL.TOKEN_ISSUED": {
745
- target: M,
769
+ target: A,
746
770
  actions: "setTokenInfo"
747
771
  },
748
772
  "CALL.RESET": {
749
- target: M,
773
+ target: A,
750
774
  actions: "reset"
751
775
  }
752
776
  }
753
777
  },
754
- [M]: {
778
+ [A]: {
755
779
  always: [
756
780
  {
757
781
  target: "call:inRoom",
758
- guard: ({ context: n }) => we(n)
782
+ guard: ({ context: n }) => Ue(n)
783
+ },
784
+ {
785
+ target: "call:directP2pRoom",
786
+ guard: ({ context: n }) => zt(n)
787
+ },
788
+ {
789
+ target: "call:p2pRoom",
790
+ guard: ({ context: n }) => Qt(n)
759
791
  },
760
792
  {
761
793
  target: "call:purgatory",
762
- guard: ({ context: n }) => Bt(n)
794
+ guard: ({ context: n }) => Wt(n)
763
795
  },
764
796
  {
765
797
  target: "call:connecting",
766
- guard: ({ context: n }) => oe(n)
798
+ guard: ({ context: n }) => H(n)
767
799
  },
768
800
  {
769
801
  target: "call:idle"
@@ -774,24 +806,56 @@ const M = "evaluate", j = (n) => typeof n == "string" && n.length > 0, oe = (n)
774
806
  "call:purgatory": {
775
807
  on: {
776
808
  "CALL.ENTER_ROOM": {
777
- target: M,
809
+ target: A,
810
+ actions: "setRoomInfo"
811
+ },
812
+ "CALL.TOKEN_ISSUED": {
813
+ target: A,
814
+ actions: "setTokenInfo"
815
+ },
816
+ "CALL.RESET": {
817
+ target: A,
818
+ actions: "reset"
819
+ }
820
+ }
821
+ },
822
+ "call:p2pRoom": {
823
+ on: {
824
+ "CALL.ENTER_ROOM": {
825
+ target: A,
826
+ actions: "setRoomInfo"
827
+ },
828
+ "CALL.TOKEN_ISSUED": {
829
+ target: A,
830
+ actions: "setTokenInfo"
831
+ },
832
+ "CALL.RESET": {
833
+ target: A,
834
+ actions: "reset"
835
+ }
836
+ }
837
+ },
838
+ "call:directP2pRoom": {
839
+ on: {
840
+ "CALL.ENTER_ROOM": {
841
+ target: A,
778
842
  actions: "setRoomInfo"
779
843
  },
780
844
  "CALL.TOKEN_ISSUED": {
781
- target: M,
845
+ target: A,
782
846
  actions: "setTokenInfo"
783
847
  },
784
848
  "CALL.RESET": {
785
- target: M,
849
+ target: A,
786
850
  actions: "reset"
787
851
  }
788
852
  }
789
853
  }
790
854
  }
791
855
  });
792
- class qt extends x {
856
+ class Kt extends x {
793
857
  constructor(e) {
794
- super(Gt), this.subscribeToEvents(e);
858
+ super(jt), this.subscribeToEvents(e);
795
859
  }
796
860
  get isIdle() {
797
861
  return this.state === "call:idle";
@@ -802,16 +866,22 @@ class qt extends x {
802
866
  get isInPurgatory() {
803
867
  return this.state === "call:purgatory";
804
868
  }
869
+ get isP2PRoom() {
870
+ return this.state === "call:p2pRoom";
871
+ }
872
+ get isDirectP2PRoom() {
873
+ return this.state === "call:directP2pRoom";
874
+ }
805
875
  get isInRoom() {
806
876
  return this.state === "call:inRoom";
807
877
  }
808
878
  /** Контекст в состоянии IN_ROOM; undefined в остальных состояниях. Использовать вместо каста context. */
809
879
  get inRoomContext() {
810
880
  const { context: e } = this;
811
- return we(e) ? e : void 0;
881
+ return Ue(e) ? e : void 0;
812
882
  }
813
883
  get isActive() {
814
- return this.isInRoom || this.isInPurgatory;
884
+ return this.isInRoom || this.isInPurgatory || this.isP2PRoom || this.isDirectP2PRoom;
815
885
  }
816
886
  get isPending() {
817
887
  return this.isConnecting;
@@ -826,6 +896,13 @@ class qt extends x {
826
896
  if ("token" in e)
827
897
  return e.token;
828
898
  }
899
+ get isCallInitiator() {
900
+ return !this.isCallAnswerer;
901
+ }
902
+ get isCallAnswerer() {
903
+ const { context: e } = this;
904
+ return "answer" in e ? e.answer : !1;
905
+ }
829
906
  reset() {
830
907
  this.send({ type: "CALL.RESET" });
831
908
  }
@@ -840,8 +917,14 @@ class qt extends x {
840
917
  }
841
918
  subscribeToApiEvents(e) {
842
919
  this.addSubscription(
843
- e.on("enter-room", ({ room: t, participantName: s, bearerToken: i }) => {
844
- this.send({ type: "CALL.ENTER_ROOM", room: t, participantName: s, token: i });
920
+ e.on("enter-room", ({ room: t, participantName: s, bearerToken: i, isDirectPeerToPeer: r }) => {
921
+ this.send({
922
+ type: "CALL.ENTER_ROOM",
923
+ room: t,
924
+ participantName: s,
925
+ token: i,
926
+ isDirectPeerToPeer: r
927
+ });
845
928
  })
846
929
  ), this.addSubscription(
847
930
  e.on("conference:participant-token-issued", ({ jwt: t }) => {
@@ -865,8 +948,8 @@ class qt extends x {
865
948
  );
866
949
  }
867
950
  }
868
- var S = /* @__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.START_CALL = "start-call", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n.CALL_STATUS_CHANGED = "call-status-changed", n.REMOTE_TRACKS_CHANGED = "remote-tracks-changed", n.REMOTE_STREAMS_CHANGED = "remote-streams-changed", n.RECV_SESSION_STARTED = "recv-session-started", n.RECV_SESSION_ENDED = "recv-session-ended", n.RECV_QUALITY_CHANGED = "recv-quality-changed", n))(S || {}), Vt = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(Vt || {});
869
- const Le = [
951
+ var E = /* @__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.START_CALL = "start-call", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n.CALL_STATUS_CHANGED = "call-status-changed", n.REMOTE_TRACKS_CHANGED = "remote-tracks-changed", n.REMOTE_STREAMS_CHANGED = "remote-streams-changed", n.RECV_SESSION_STARTED = "recv-session-started", n.RECV_SESSION_ENDED = "recv-session-ended", n.RECV_QUALITY_CHANGED = "recv-quality-changed", n))(E || {}), Xt = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(Xt || {});
952
+ const Fe = [
870
953
  "peerconnection",
871
954
  "connecting",
872
955
  "sending",
@@ -897,7 +980,7 @@ const Le = [
897
980
  "peerconnection:createanswerfailed",
898
981
  "peerconnection:setlocaldescriptionfailed",
899
982
  "peerconnection:setremotedescriptionfailed"
900
- ], xt = [
983
+ ], Zt = [
901
984
  "start-call",
902
985
  "peerconnection:confirmed",
903
986
  "peerconnection:ontrack",
@@ -908,11 +991,11 @@ const Le = [
908
991
  "recv-session-started",
909
992
  "recv-session-ended",
910
993
  "recv-quality-changed"
911
- ], Ue = [
912
- ...Le,
913
- ...xt
914
- ], Ht = () => new f(Ue), Wt = 6e3, Qt = 1e3, W = (n, e) => n.getSenders().filter((t) => t.track?.kind === e), Yt = (n) => n === "audio" ? Wt : Qt, zt = (n) => n.track !== null;
915
- class Jt {
994
+ ], ke = [
995
+ ...Fe,
996
+ ...Zt
997
+ ], en = () => new M(ke), tn = 6e3, nn = 1e3, Q = (n, e) => n.getSenders().filter((t) => t.track?.kind === e), sn = (n) => n === "audio" ? tn : nn, rn = (n) => n.track !== null;
998
+ class an {
916
999
  previousBitrates = /* @__PURE__ */ new Map();
917
1000
  /**
918
1001
  * Устанавливает минимальный битрейт для указанных типов потоков
@@ -923,18 +1006,18 @@ class Jt {
923
1006
  const s = [];
924
1007
  if (!e)
925
1008
  return;
926
- (t === "audio" || t === "all") && s.push(...W(e, "audio")), (t === "video" || t === "all") && s.push(...W(e, "video"));
927
- const i = s.filter(zt).map(async (r) => {
1009
+ (t === "audio" || t === "all") && s.push(...Q(e, "audio")), (t === "video" || t === "all") && s.push(...Q(e, "video"));
1010
+ const i = s.filter(rn).map(async (r) => {
928
1011
  const a = r.getParameters();
929
1012
  this.saveCurrentBitrate(r, a);
930
1013
  const o = {
931
1014
  ...a,
932
1015
  encodings: a.encodings.map((c) => ({
933
1016
  ...c,
934
- maxBitrate: Yt(r.track.kind)
1017
+ maxBitrate: sn(r.track.kind)
935
1018
  }))
936
1019
  };
937
- await te(r, o);
1020
+ await ie(r, o);
938
1021
  });
939
1022
  await Promise.all(i);
940
1023
  }
@@ -947,7 +1030,7 @@ class Jt {
947
1030
  const s = [];
948
1031
  if (!e)
949
1032
  return;
950
- (t === "audio" || t === "all") && s.push(...W(e, "audio")), (t === "video" || t === "all") && s.push(...W(e, "video"));
1033
+ (t === "audio" || t === "all") && s.push(...Q(e, "audio")), (t === "video" || t === "all") && s.push(...Q(e, "video"));
951
1034
  const i = s.map(async (r) => {
952
1035
  const a = this.getSavedBitrate(r);
953
1036
  if (a) {
@@ -955,7 +1038,7 @@ class Jt {
955
1038
  ...r.getParameters(),
956
1039
  encodings: a
957
1040
  };
958
- await te(r, c, { isResetAllowed: !0 }), this.clearSavedBitrate(r);
1041
+ await ie(r, c, { isResetAllowed: !0 }), this.clearSavedBitrate(r);
959
1042
  }
960
1043
  });
961
1044
  await Promise.all(i);
@@ -998,16 +1081,16 @@ class Jt {
998
1081
  this.previousBitrates.set(e, s);
999
1082
  }
1000
1083
  }
1001
- var Fe = /* @__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))(Fe || {});
1002
- class jt {
1084
+ var Be = /* @__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))(Be || {});
1085
+ class on {
1003
1086
  events;
1004
1087
  rtcSession;
1005
1088
  disposers = /* @__PURE__ */ new Set();
1006
1089
  onReset;
1007
1090
  // Менеджер состояния битрейта
1008
- bitrateStateManager = new Jt();
1091
+ bitrateStateManager = new an();
1009
1092
  constructor(e, { onReset: t }) {
1010
- this.events = e, this.onReset = t, e.on(S.FAILED, this.handleEnded), e.on(S.ENDED, this.handleEnded);
1093
+ this.events = e, this.onReset = t, e.on(E.FAILED, this.handleEnded), e.on(E.ENDED, this.handleEnded);
1011
1094
  }
1012
1095
  get connection() {
1013
1096
  return this.rtcSession?.connection;
@@ -1031,14 +1114,14 @@ class jt {
1031
1114
  contentHint: l,
1032
1115
  offerToReceiveAudio: T = !0,
1033
1116
  offerToReceiveVideo: g = !0,
1034
- degradationPreference: E,
1035
- sendEncodings: N,
1117
+ degradationPreference: S,
1118
+ sendEncodings: R,
1036
1119
  onAddedTransceiver: D
1037
- }) => new Promise((A, U) => {
1038
- this.handleCall().then(A).catch((B) => {
1120
+ }) => new Promise((I, U) => {
1121
+ this.handleCall().then(I).catch((B) => {
1039
1122
  U(B);
1040
1123
  }), this.rtcSession = e.call(t(s), {
1041
- mediaStream: Q(i, {
1124
+ mediaStream: Y(i, {
1042
1125
  directionVideo: o,
1043
1126
  directionAudio: c,
1044
1127
  contentHint: l
@@ -1057,8 +1140,8 @@ class jt {
1057
1140
  extraHeaders: r,
1058
1141
  directionVideo: o,
1059
1142
  directionAudio: c,
1060
- degradationPreference: E,
1061
- sendEncodings: N,
1143
+ degradationPreference: S,
1144
+ sendEncodings: R,
1062
1145
  onAddedTransceiver: D
1063
1146
  });
1064
1147
  });
@@ -1066,7 +1149,7 @@ class jt {
1066
1149
  const { rtcSession: e } = this;
1067
1150
  if (e && !e.isEnded())
1068
1151
  return e.terminateAsync({
1069
- cause: Fe.CANCELED
1152
+ cause: Be.CANCELED
1070
1153
  }).finally(() => {
1071
1154
  this.reset();
1072
1155
  });
@@ -1083,11 +1166,11 @@ class jt {
1083
1166
  contentHint: l,
1084
1167
  degradationPreference: T,
1085
1168
  sendEncodings: g,
1086
- onAddedTransceiver: E
1087
- }) => new Promise((N, D) => {
1169
+ onAddedTransceiver: S
1170
+ }) => new Promise((R, D) => {
1088
1171
  try {
1089
- this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall().then(N).catch((A) => {
1090
- D(A);
1172
+ this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall().then(R).catch((I) => {
1173
+ D(I);
1091
1174
  }), e.answer({
1092
1175
  pcConfig: {
1093
1176
  iceServers: i
@@ -1096,7 +1179,7 @@ class jt {
1096
1179
  offerToReceiveAudio: o,
1097
1180
  offerToReceiveVideo: c
1098
1181
  },
1099
- mediaStream: Q(t, {
1182
+ mediaStream: Y(t, {
1100
1183
  directionVideo: r,
1101
1184
  directionAudio: a,
1102
1185
  contentHint: l
@@ -1106,16 +1189,16 @@ class jt {
1106
1189
  directionAudio: a,
1107
1190
  degradationPreference: T,
1108
1191
  sendEncodings: g,
1109
- onAddedTransceiver: E
1192
+ onAddedTransceiver: S
1110
1193
  });
1111
- } catch (A) {
1112
- D(A);
1194
+ } catch (I) {
1195
+ D(I);
1113
1196
  }
1114
1197
  });
1115
1198
  async replaceMediaStream(e, t) {
1116
1199
  if (!this.rtcSession)
1117
1200
  throw new Error("No rtcSession established");
1118
- const { contentHint: s } = t ?? {}, i = Q(e, { contentHint: s });
1201
+ const { contentHint: s } = t ?? {}, i = Y(e, { contentHint: s });
1119
1202
  if (i === void 0)
1120
1203
  throw new Error("No preparedMediaStream");
1121
1204
  return this.rtcSession.replaceMediaStream(i, t);
@@ -1131,7 +1214,7 @@ class jt {
1131
1214
  */
1132
1215
  setMinBitrateForSenders(e = "all") {
1133
1216
  this.bitrateStateManager.setMinBitrateForSenders(this.connection, e).catch((t) => {
1134
- he("MCUSession.setMinBitrateForSenders", t);
1217
+ ue("MCUSession.setMinBitrateForSenders", t);
1135
1218
  });
1136
1219
  }
1137
1220
  /**
@@ -1140,38 +1223,38 @@ class jt {
1140
1223
  */
1141
1224
  restoreBitrateForSenders(e = "all") {
1142
1225
  this.bitrateStateManager.restoreBitrateForSenders(this.connection, e).catch((t) => {
1143
- he("MCUSession.restoreBitrateForSenders", t);
1226
+ ue("MCUSession.restoreBitrateForSenders", t);
1144
1227
  });
1145
1228
  }
1146
1229
  handleCall = async () => new Promise((e, t) => {
1147
1230
  const s = () => {
1148
- this.events.on(S.PEER_CONNECTION, l), this.events.on(S.CONFIRMED, T);
1231
+ this.events.on(E.PEER_CONNECTION, l), this.events.on(E.CONFIRMED, T);
1149
1232
  }, i = () => {
1150
- this.events.off(S.PEER_CONNECTION, l), this.events.off(S.CONFIRMED, T);
1233
+ this.events.off(E.PEER_CONNECTION, l), this.events.off(E.CONFIRMED, T);
1151
1234
  }, r = () => {
1152
- this.events.on(S.FAILED, o), this.events.on(S.ENDED, o);
1235
+ this.events.on(E.FAILED, o), this.events.on(E.ENDED, o);
1153
1236
  }, a = () => {
1154
- this.events.off(S.FAILED, o), this.events.off(S.ENDED, o);
1237
+ this.events.off(E.FAILED, o), this.events.off(E.ENDED, o);
1155
1238
  }, o = (g) => {
1156
1239
  i(), a(), t(g);
1157
1240
  };
1158
1241
  let c;
1159
1242
  const l = ({ peerconnection: g }) => {
1160
1243
  c = g;
1161
- const E = (N) => {
1162
- this.events.trigger(S.PEER_CONNECTION_ONTRACK, N);
1244
+ const S = (R) => {
1245
+ this.events.trigger(E.PEER_CONNECTION_ONTRACK, R);
1163
1246
  };
1164
- g.addEventListener("track", E), this.disposers.add(() => {
1165
- g.removeEventListener("track", E);
1247
+ g.addEventListener("track", S), this.disposers.add(() => {
1248
+ g.removeEventListener("track", S);
1166
1249
  });
1167
1250
  }, T = () => {
1168
- c !== void 0 && this.events.trigger(S.PEER_CONNECTION_CONFIRMED, c), i(), a(), e(c);
1251
+ c !== void 0 && this.events.trigger(E.PEER_CONNECTION_CONFIRMED, c), i(), a(), e(c);
1169
1252
  };
1170
1253
  s(), r();
1171
1254
  });
1172
1255
  subscribeToSessionEvents(e) {
1173
1256
  this.events.eachTriggers((t, s) => {
1174
- const i = Le.find((r) => r === s);
1257
+ const i = Fe.find((r) => r === s);
1175
1258
  i && (e.on(i, t), this.disposers.add(() => {
1176
1259
  e.off(i, t);
1177
1260
  }));
@@ -1184,14 +1267,14 @@ class jt {
1184
1267
  }
1185
1268
  handleEnded = (e) => {
1186
1269
  const { originator: t } = e;
1187
- t === "remote" && this.events.trigger(S.ENDED_FROM_SERVER, e), this.reset();
1270
+ t === "remote" && this.events.trigger(E.ENDED_FROM_SERVER, e), this.reset();
1188
1271
  };
1189
1272
  reset = () => {
1190
1273
  delete this.rtcSession, this.unsubscribeFromSessionEvents(), this.bitrateStateManager.clearAll(), this.onReset();
1191
1274
  };
1192
1275
  }
1193
- const ue = (n) => n === "auto" ? "high" : n, Xt = 10, Kt = 100;
1194
- class Zt {
1276
+ const Te = (n) => n === "auto" ? "high" : n, cn = 10, dn = 100;
1277
+ class hn {
1195
1278
  cancelableSendOfferWithRepeatedCalls;
1196
1279
  config;
1197
1280
  tools;
@@ -1202,7 +1285,7 @@ class Zt {
1202
1285
  this.config = {
1203
1286
  ...e,
1204
1287
  quality: s,
1205
- effectiveQuality: ue(s)
1288
+ effectiveQuality: Te(s)
1206
1289
  }, this.tools = t, this.connection = new RTCPeerConnection(e.pcConfig), this.addTransceivers();
1207
1290
  }
1208
1291
  get settings() {
@@ -1220,7 +1303,7 @@ class Zt {
1220
1303
  async setQuality(e) {
1221
1304
  if (!this.lastCallParams)
1222
1305
  return !1;
1223
- const t = this.config.effectiveQuality, s = this.config.quality, i = ue(e);
1306
+ const t = this.config.effectiveQuality, s = this.config.quality, i = Te(e);
1224
1307
  return e === s && i === t ? !1 : (this.config.quality = e, this.config.effectiveQuality = i, i !== t && await this.renegotiate(this.lastCallParams), !0);
1225
1308
  }
1226
1309
  async applyQuality(e) {
@@ -1245,11 +1328,11 @@ class Zt {
1245
1328
  },
1246
1329
  s
1247
1330
  ), r = (o) => !(o instanceof Error);
1248
- this.cancelableSendOfferWithRepeatedCalls = re({
1331
+ this.cancelableSendOfferWithRepeatedCalls = ce({
1249
1332
  targetFunction: i,
1250
1333
  isComplete: r,
1251
- callLimit: Xt,
1252
- delay: Kt,
1334
+ callLimit: cn,
1335
+ delay: dn,
1253
1336
  isRejectAsValid: !0,
1254
1337
  isCheckBeforeCall: !1
1255
1338
  });
@@ -1287,18 +1370,18 @@ class Zt {
1287
1370
  this.cancelableSendOfferWithRepeatedCalls?.cancel();
1288
1371
  }
1289
1372
  }
1290
- const ke = (n) => n.getSettings(), en = (n, e) => {
1291
- const t = ke(n);
1373
+ const $e = (n) => n.getSettings(), ln = (n, e) => {
1374
+ const t = $e(n);
1292
1375
  let s = e;
1293
1376
  s ??= n.label;
1294
1377
  let i = t?.msid;
1295
1378
  return i ??= s, i ??= n.id, i;
1296
- }, tn = (n, e) => {
1297
- const t = ke(n);
1379
+ }, un = (n, e) => {
1380
+ const t = $e(n);
1298
1381
  let s = e;
1299
1382
  return s ??= t?.msid, s ??= n.label, (s && s.length > 0 ? s : void 0) ?? n.id;
1300
1383
  };
1301
- class ge {
1384
+ class Ee {
1302
1385
  participantGroups = /* @__PURE__ */ new Map();
1303
1386
  trackToGroup = /* @__PURE__ */ new Map();
1304
1387
  trackDisposers = /* @__PURE__ */ new Map();
@@ -1315,7 +1398,7 @@ class ge {
1315
1398
  onRemoved: t,
1316
1399
  streamHint: s
1317
1400
  } = {}) {
1318
- const i = tn(e, s), r = en(e, s);
1401
+ const i = un(e, s), r = ln(e, s);
1319
1402
  if (this.trackToGroup.has(e.id))
1320
1403
  return { isAddedTrack: !1, isAddedStream: !1 };
1321
1404
  const a = this.getParticipantGroups(i), o = a.get(r), c = !o;
@@ -1383,16 +1466,16 @@ class ge {
1383
1466
  return this.participantGroups.set(e, s), s;
1384
1467
  }
1385
1468
  }
1386
- const K = {
1469
+ const te = {
1387
1470
  type: "participant"
1388
- }, nn = {
1471
+ }, gn = {
1389
1472
  type: "spectator_synthetic"
1390
- }, sn = (n) => ({
1473
+ }, Tn = (n) => ({
1391
1474
  type: "spectator",
1392
1475
  recvParams: n
1393
1476
  });
1394
1477
  class p {
1395
- role = K;
1478
+ role = te;
1396
1479
  onRoleChanged;
1397
1480
  constructor(e) {
1398
1481
  this.onRoleChanged = e;
@@ -1424,13 +1507,13 @@ class p {
1424
1507
  return this.role;
1425
1508
  }
1426
1509
  setCallRoleParticipant() {
1427
- this.changeRole(K);
1510
+ this.changeRole(te);
1428
1511
  }
1429
1512
  setCallRoleSpectatorSynthetic() {
1430
- this.changeRole(nn);
1513
+ this.changeRole(gn);
1431
1514
  }
1432
1515
  setCallRoleSpectator(e) {
1433
- this.changeRole(sn(e));
1516
+ this.changeRole(Tn(e));
1434
1517
  }
1435
1518
  changeRole(e) {
1436
1519
  const t = this.role;
@@ -1441,7 +1524,7 @@ class p {
1441
1524
  p.hasSpectator(e) && p.hasSpectator(t) && t.recvParams.audioId !== e.recvParams.audioId && this.setRole(e);
1442
1525
  }
1443
1526
  reset() {
1444
- this.role = K;
1527
+ this.role = te;
1445
1528
  }
1446
1529
  hasParticipant() {
1447
1530
  return p.hasParticipant(this.role);
@@ -1457,13 +1540,13 @@ class p {
1457
1540
  this.role = e, this.onRoleChanged?.({ previous: t, next: e });
1458
1541
  }
1459
1542
  }
1460
- const rn = (n, e) => {
1543
+ const En = (n, e) => {
1461
1544
  if (!n || !e)
1462
1545
  return n === e;
1463
1546
  const t = n.mainStream?.id, s = e.mainStream?.id, i = n.contentedStream?.id, r = e.contentedStream?.id;
1464
1547
  return t === s && i === r;
1465
1548
  };
1466
- class an {
1549
+ class Sn {
1467
1550
  lastEmittedStreams;
1468
1551
  /**
1469
1552
  * Проверяет, изменились ли streams с последнего сохраненного состояния
@@ -1471,7 +1554,7 @@ class an {
1471
1554
  * @returns true, если streams изменились
1472
1555
  */
1473
1556
  hasChanged(e) {
1474
- return !rn(this.lastEmittedStreams, e);
1557
+ return !En(this.lastEmittedStreams, e);
1475
1558
  }
1476
1559
  /**
1477
1560
  * Сохраняет текущие streams как последнее эмитнутое состояние
@@ -1494,8 +1577,8 @@ class an {
1494
1577
  this.lastEmittedStreams = void 0;
1495
1578
  }
1496
1579
  }
1497
- const on = "default", cn = "dual", dn = "content_", hn = (n) => `${dn}${n.toLowerCase()}`, ln = (n) => [...n.getTracks()].some((e) => e.label.includes(cn));
1498
- class un {
1580
+ const mn = "default", pn = "dual", Cn = "content_", Rn = (n) => `${Cn}${n.toLowerCase()}`, Nn = (n) => [...n.getTracks()].some((e) => e.label.includes(pn));
1581
+ class An {
1499
1582
  mainRemoteStreamsManager;
1500
1583
  recvRemoteStreamsManager;
1501
1584
  constructor(e, t) {
@@ -1512,7 +1595,7 @@ class un {
1512
1595
  }) {
1513
1596
  const t = this.mainRemoteStreamsManager;
1514
1597
  return { manager: t, getRemoteStreams: () => {
1515
- const i = t.getStreams(), r = i.find((o) => !ln(o)), a = e.isAvailable ? i.find((o) => o !== r) : void 0;
1598
+ const i = t.getStreams(), r = i.find((o) => !Nn(o)), a = e.isAvailable ? i.find((o) => o !== r) : void 0;
1516
1599
  return { mainStream: r, contentedStream: a };
1517
1600
  } };
1518
1601
  }
@@ -1521,7 +1604,7 @@ class un {
1521
1604
  }) {
1522
1605
  const t = this.recvRemoteStreamsManager;
1523
1606
  return { manager: t, getRemoteStreams: () => {
1524
- const r = t.getStreams(on)[0], a = this.getRecvRemoteContentedStream({ stateInfo: e });
1607
+ const r = t.getStreams(mn)[0], a = this.getRecvRemoteContentedStream({ stateInfo: e });
1525
1608
  return { mainStream: r, contentedStream: a };
1526
1609
  } };
1527
1610
  }
@@ -1530,12 +1613,12 @@ class un {
1530
1613
  }) {
1531
1614
  if (!e.isAvailable || e.codec === void 0)
1532
1615
  return;
1533
- const t = hn(e.codec);
1616
+ const t = Rn(e.codec);
1534
1617
  return this.recvRemoteStreamsManager.getStreams(t)[0];
1535
1618
  }
1536
1619
  }
1537
- const Te = (n) => n.streams[0]?.id;
1538
- function gn(n) {
1620
+ const Se = (n) => n.streams[0]?.id;
1621
+ function In(n) {
1539
1622
  const { inRoomContext: e } = n;
1540
1623
  if (e === void 0)
1541
1624
  throw new Error(
@@ -1543,13 +1626,13 @@ function gn(n) {
1543
1626
  );
1544
1627
  return e.token;
1545
1628
  }
1546
- class Tn {
1629
+ class vn {
1547
1630
  events;
1548
1631
  stateMachine;
1549
1632
  isPendingCall = !1;
1550
1633
  isPendingAnswer = !1;
1551
- mainRemoteStreamsManager = new ge();
1552
- recvRemoteStreamsManager = new ge();
1634
+ mainRemoteStreamsManager = new Ee();
1635
+ recvRemoteStreamsManager = new Ee();
1553
1636
  streamsManagerProvider;
1554
1637
  contentedStreamManager;
1555
1638
  roleManager = new p((e) => {
@@ -1559,17 +1642,17 @@ class Tn {
1559
1642
  recvSession;
1560
1643
  disposeRecvSessionTrackListener;
1561
1644
  deferredStartRecvSessionRunner;
1562
- streamsChangeTracker = new an();
1645
+ streamsChangeTracker = new Sn();
1563
1646
  constructor(e) {
1564
- this.contentedStreamManager = e, this.events = Ht(), this.mcuSession = new jt(this.events, { onReset: this.reset }), this.stateMachine = new qt(this.events), this.streamsManagerProvider = new un(
1647
+ this.contentedStreamManager = e, this.events = en(), this.mcuSession = new on(this.events, { onReset: this.reset }), this.stateMachine = new Kt(this.events), this.streamsManagerProvider = new An(
1565
1648
  this.mainRemoteStreamsManager,
1566
1649
  this.recvRemoteStreamsManager
1567
- ), this.deferredStartRecvSessionRunner = new kt({
1650
+ ), this.deferredStartRecvSessionRunner = new xt({
1568
1651
  subscribe: (t) => this.stateMachine.onStateChange(t),
1569
- isReady: (t) => t === ne.IN_ROOM,
1570
- isCancelled: (t) => t === ne.IDLE,
1652
+ isReady: (t) => t === re.IN_ROOM,
1653
+ isCancelled: (t) => t === re.IDLE,
1571
1654
  onExecute: (t) => {
1572
- const s = gn(this.stateMachine);
1655
+ const s = In(this.stateMachine);
1573
1656
  this.startRecvSession(t.audioId, {
1574
1657
  sendOffer: t.sendOffer,
1575
1658
  token: s
@@ -1586,6 +1669,15 @@ class Tn {
1586
1669
  get isCallActive() {
1587
1670
  return this.mcuSession.isCallActive;
1588
1671
  }
1672
+ get number() {
1673
+ return this.stateMachine.number;
1674
+ }
1675
+ get isCallInitiator() {
1676
+ return this.stateMachine.isCallInitiator;
1677
+ }
1678
+ get isDirectP2PRoom() {
1679
+ return this.stateMachine.isDirectP2PRoom;
1680
+ }
1589
1681
  // For testing purposes
1590
1682
  getStreamsManagerProvider() {
1591
1683
  return this.streamsManagerProvider;
@@ -1615,7 +1707,7 @@ class Tn {
1615
1707
  subscribeToApiEvents(e) {
1616
1708
  this.stateMachine.subscribeToApiEvents(e.events);
1617
1709
  }
1618
- startCall = async (e, t, s) => (this.isPendingCall = !0, this.events.emit("start-call", {
1710
+ startCall = async (e, t, s) => (this.isPendingCall = !0, this.events.emit(E.START_CALL, {
1619
1711
  number: s.number,
1620
1712
  answer: !1
1621
1713
  }), this.mcuSession.startCall(e, t, s).finally(() => {
@@ -1630,7 +1722,7 @@ class Tn {
1630
1722
  answerToIncomingCall = async (e, t) => {
1631
1723
  this.isPendingAnswer = !0;
1632
1724
  const s = e();
1633
- return this.events.emit("start-call", {
1725
+ return this.events.emit(E.START_CALL, {
1634
1726
  answer: !0,
1635
1727
  number: s.remote_identity.uri.user
1636
1728
  }), this.mcuSession.answerToIncomingCall(s, t).finally(() => {
@@ -1679,17 +1771,23 @@ class Tn {
1679
1771
  if (!this.roleManager.hasSpectator() || !t)
1680
1772
  return !1;
1681
1773
  const s = t.getQuality(), i = await t.applyQuality(e);
1682
- return i.applied && this.events.trigger(S.RECV_QUALITY_CHANGED, {
1774
+ return i.applied && this.events.trigger(E.RECV_QUALITY_CHANGED, {
1683
1775
  previousQuality: s,
1684
1776
  quality: e,
1685
1777
  effectiveQuality: i.effectiveQuality
1686
1778
  }), i.applied;
1687
1779
  }
1780
+ async failed(e, t) {
1781
+ this.emitFailedCall(e, t), await this.endCall();
1782
+ }
1783
+ emitFailedCall(e, t) {
1784
+ this.events.trigger(E.FAILED, { message: e, cause: t, originator: "local" });
1785
+ }
1688
1786
  reset = () => {
1689
1787
  this.mainRemoteStreamsManager.reset(), this.roleManager.reset(), this.recvRemoteStreamsManager.reset(), this.stopRecvSession(), this.deferredStartRecvSessionRunner.cancel(), this.streamsChangeTracker.reset();
1690
1788
  };
1691
1789
  subscribeCallStatusChange() {
1692
- const { ACCEPTED: e, CONFIRMED: t, ENDED: s, FAILED: i } = S, r = this.createCallStatusChangeListener();
1790
+ const { ACCEPTED: e, CONFIRMED: t, ENDED: s, FAILED: i } = E, r = this.createCallStatusChangeListener();
1693
1791
  this.onRace([e, t, s, i], r);
1694
1792
  }
1695
1793
  /** Хранит prev/next и эмитит CALL_STATUS_CHANGED только при реальном изменении. */
@@ -1697,12 +1795,12 @@ class Tn {
1697
1795
  let e = this.isCallActive;
1698
1796
  return () => {
1699
1797
  const t = this.isCallActive;
1700
- t !== e && this.events.trigger(S.CALL_STATUS_CHANGED, { isCallActive: t }), e = t;
1798
+ t !== e && this.events.trigger(E.CALL_STATUS_CHANGED, { isCallActive: t }), e = t;
1701
1799
  };
1702
1800
  }
1703
1801
  subscribeMcuRemoteTrackEvents() {
1704
- this.on(S.PEER_CONNECTION_ONTRACK, (e) => {
1705
- this.addRemoteTrack(this.mainRemoteStreamsManager, e.track, Te(e));
1802
+ this.on(E.PEER_CONNECTION_ONTRACK, (e) => {
1803
+ this.addRemoteTrack(this.mainRemoteStreamsManager, e.track, Se(e));
1706
1804
  });
1707
1805
  }
1708
1806
  addRemoteTrack(e, t, s) {
@@ -1737,7 +1835,7 @@ class Tn {
1737
1835
  this.emitEventChangedRemoteTracks(c, t, { trackId: s, participantId: i }), (a || r) && this.emitEventChangedRemoteStreams(c);
1738
1836
  }
1739
1837
  emitEventChangedRemoteTracks(e, t, { trackId: s, participantId: i }) {
1740
- this.events.trigger(S.REMOTE_TRACKS_CHANGED, {
1838
+ this.events.trigger(E.REMOTE_TRACKS_CHANGED, {
1741
1839
  streams: e,
1742
1840
  changeType: t,
1743
1841
  trackId: s,
@@ -1748,7 +1846,7 @@ class Tn {
1748
1846
  this.emitEventChangedRemoteStreams(this.getRemoteStreams());
1749
1847
  };
1750
1848
  emitEventChangedRemoteStreams(e) {
1751
- this.streamsChangeTracker.hasChanged(e) && (this.streamsChangeTracker.updateLastEmittedStreams(e), this.events.trigger(S.REMOTE_STREAMS_CHANGED, { streams: e }));
1849
+ this.streamsChangeTracker.hasChanged(e) && (this.streamsChangeTracker.updateLastEmittedStreams(e), this.events.trigger(E.REMOTE_STREAMS_CHANGED, { streams: e }));
1752
1850
  }
1753
1851
  getActiveStreamsManagerTools() {
1754
1852
  return this.streamsManagerProvider.getActiveStreamsManagerTools({
@@ -1758,7 +1856,7 @@ class Tn {
1758
1856
  }
1759
1857
  attachRecvSessionTracks(e) {
1760
1858
  const { peerConnection: t } = e, s = (i) => {
1761
- this.addRemoteTrack(this.recvRemoteStreamsManager, i.track, Te(i));
1859
+ this.addRemoteTrack(this.recvRemoteStreamsManager, i.track, Se(i));
1762
1860
  };
1763
1861
  t.addEventListener("track", s), this.disposeRecvSessionTrackListener = () => {
1764
1862
  t.removeEventListener("track", s);
@@ -1771,7 +1869,7 @@ class Tn {
1771
1869
  this.stopRecvSession();
1772
1870
  const r = {
1773
1871
  audioChannel: e
1774
- }, a = new Zt(r, { sendOffer: t });
1872
+ }, a = new hn(r, { sendOffer: t });
1775
1873
  this.recvSession = a, this.recvRemoteStreamsManager.reset(), this.attachRecvSessionTracks(a), a.call({ conferenceNumber: i, token: s }).then(() => {
1776
1874
  this.events.emit("recv-session-started");
1777
1875
  }).catch(() => {
@@ -1808,16 +1906,16 @@ class Tn {
1808
1906
  return this.mcuSession.renegotiate();
1809
1907
  }
1810
1908
  }
1811
- var P = /* @__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))(P || {});
1812
- const Be = [
1909
+ var L = /* @__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))(L || {});
1910
+ const Ge = [
1813
1911
  "presentation:start",
1814
1912
  "presentation:started",
1815
1913
  "presentation:end",
1816
1914
  "presentation:ended",
1817
1915
  "presentation:failed"
1818
- ], En = () => new f(Be);
1819
- var Sn = /* @__PURE__ */ ((n) => (n.IDLE = "presentation:idle", n.STARTING = "presentation:starting", n.ACTIVE = "presentation:active", n.STOPPING = "presentation:stopping", n.FAILED = "presentation:failed", n))(Sn || {});
1820
- const mn = V({
1916
+ ], fn = () => new M(Ge);
1917
+ var Mn = /* @__PURE__ */ ((n) => (n.IDLE = "presentation:idle", n.STARTING = "presentation:starting", n.ACTIVE = "presentation:active", n.STOPPING = "presentation:stopping", n.FAILED = "presentation:failed", n))(Mn || {});
1918
+ const _n = V({
1821
1919
  types: {
1822
1920
  context: {},
1823
1921
  events: {}
@@ -1829,10 +1927,10 @@ const mn = V({
1829
1927
  logStateChange: (n, e) => {
1830
1928
  d("PresentationStateMachine state changed", e.state);
1831
1929
  },
1832
- setError: I(({ event: n }) => "error" in n && n.error !== void 0 ? {
1930
+ setError: v(({ event: n }) => "error" in n && n.error !== void 0 ? {
1833
1931
  lastError: n.error instanceof Error ? n.error : new Error(JSON.stringify(n.error))
1834
1932
  } : { lastError: void 0 }),
1835
- clearError: I({ lastError: void 0 })
1933
+ clearError: v({ lastError: void 0 })
1836
1934
  }
1837
1935
  }).createMachine({
1838
1936
  id: "presentation",
@@ -2142,9 +2240,9 @@ const mn = V({
2142
2240
  }
2143
2241
  }
2144
2242
  });
2145
- class pn extends x {
2243
+ class bn extends x {
2146
2244
  constructor(e) {
2147
- super(mn), this.subscribeCallEvents(e);
2245
+ super(_n), this.subscribeCallEvents(e);
2148
2246
  }
2149
2247
  get isIdle() {
2150
2248
  return this.state === "presentation:idle";
@@ -2184,38 +2282,38 @@ class pn extends x {
2184
2282
  }
2185
2283
  subscribeCallEvents(e) {
2186
2284
  this.addSubscription(
2187
- e.on(S.START_PRESENTATION, () => {
2285
+ e.on(E.START_PRESENTATION, () => {
2188
2286
  this.send({ type: "SCREEN.STARTING" });
2189
2287
  })
2190
2288
  ), this.addSubscription(
2191
- e.on(S.STARTED_PRESENTATION, () => {
2289
+ e.on(E.STARTED_PRESENTATION, () => {
2192
2290
  this.send({ type: "SCREEN.STARTED" });
2193
2291
  })
2194
2292
  ), this.addSubscription(
2195
- e.on(S.END_PRESENTATION, () => {
2293
+ e.on(E.END_PRESENTATION, () => {
2196
2294
  this.send({ type: "SCREEN.ENDING" });
2197
2295
  })
2198
2296
  ), this.addSubscription(
2199
- e.on(S.ENDED_PRESENTATION, () => {
2297
+ e.on(E.ENDED_PRESENTATION, () => {
2200
2298
  this.send({ type: "SCREEN.ENDED" });
2201
2299
  })
2202
2300
  ), this.addSubscription(
2203
- e.on(S.FAILED_PRESENTATION, (t) => {
2301
+ e.on(E.FAILED_PRESENTATION, (t) => {
2204
2302
  this.send({ type: "SCREEN.FAILED", error: t });
2205
2303
  })
2206
2304
  ), this.addSubscription(
2207
- e.on(S.ENDED, () => {
2305
+ e.on(E.ENDED, () => {
2208
2306
  this.send({ type: "CALL.ENDED" });
2209
2307
  })
2210
2308
  ), this.addSubscription(
2211
- e.on(S.FAILED, (t) => {
2309
+ e.on(E.FAILED, (t) => {
2212
2310
  this.send({ type: "CALL.FAILED", error: t });
2213
2311
  })
2214
2312
  );
2215
2313
  }
2216
2314
  }
2217
- const Cn = 1, yi = (n) => ct(n);
2218
- class Nn {
2315
+ const On = 1, Vi = (n) => ut(n);
2316
+ class Pn {
2219
2317
  events;
2220
2318
  stateMachine;
2221
2319
  promisePendingStartPresentation;
@@ -2228,7 +2326,7 @@ class Nn {
2228
2326
  callManager: e,
2229
2327
  maxBitrate: t
2230
2328
  }) {
2231
- this.callManager = e, this.maxBitrate = t, this.events = En(), this.stateMachine = new pn(this.callManager.events), this.subscribe();
2329
+ this.callManager = e, this.maxBitrate = t, this.events = fn(), this.stateMachine = new bn(this.callManager.events), this.subscribe();
2232
2330
  }
2233
2331
  get isPendingPresentation() {
2234
2332
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
@@ -2267,8 +2365,8 @@ class Nn {
2267
2365
  const i = this.callManager.getEstablishedRTCSession();
2268
2366
  return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
2269
2367
  const a = r instanceof Error ? r : new Error(String(r));
2270
- throw this.events.trigger(P.FAILED_PRESENTATION, a), r;
2271
- }) : t && this.events.trigger(P.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
2368
+ throw this.events.trigger(L.FAILED_PRESENTATION, a), r;
2369
+ }) : t && this.events.trigger(L.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
2272
2370
  this.resetPresentation();
2273
2371
  });
2274
2372
  }
@@ -2307,15 +2405,15 @@ class Nn {
2307
2405
  }
2308
2406
  subscribe() {
2309
2407
  this.callManager.on("presentation:start", (e) => {
2310
- this.events.trigger(P.START_PRESENTATION, e);
2408
+ this.events.trigger(L.START_PRESENTATION, e);
2311
2409
  }), this.callManager.on("presentation:started", (e) => {
2312
- this.events.trigger(P.STARTED_PRESENTATION, e);
2410
+ this.events.trigger(L.STARTED_PRESENTATION, e);
2313
2411
  }), this.callManager.on("presentation:end", (e) => {
2314
- this.events.trigger(P.END_PRESENTATION, e);
2412
+ this.events.trigger(L.END_PRESENTATION, e);
2315
2413
  }), this.callManager.on("presentation:ended", (e) => {
2316
- this.events.trigger(P.ENDED_PRESENTATION, e);
2414
+ this.events.trigger(L.ENDED_PRESENTATION, e);
2317
2415
  }), this.callManager.on("presentation:failed", (e) => {
2318
- this.events.trigger(P.FAILED_PRESENTATION, e);
2416
+ this.events.trigger(L.FAILED_PRESENTATION, e);
2319
2417
  }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
2320
2418
  }
2321
2419
  async sendPresentationWithDuplicatedCalls(e, {
@@ -2323,7 +2421,7 @@ class Nn {
2323
2421
  stream: s,
2324
2422
  presentationOptions: i,
2325
2423
  options: r = {
2326
- callLimit: Cn
2424
+ callLimit: On
2327
2425
  }
2328
2426
  }) {
2329
2427
  const a = async () => this.sendPresentation(
@@ -2332,7 +2430,7 @@ class Nn {
2332
2430
  s,
2333
2431
  i
2334
2432
  ), o = () => !!this.streamPresentationCurrent;
2335
- return this.cancelableSendPresentationWithRepeatedCalls = re({
2433
+ return this.cancelableSendPresentationWithRepeatedCalls = ce({
2336
2434
  targetFunction: a,
2337
2435
  isComplete: o,
2338
2436
  isRejectAsValid: !0,
@@ -2347,7 +2445,7 @@ class Nn {
2347
2445
  sendEncodings: o,
2348
2446
  onAddedTransceiver: c
2349
2447
  }) {
2350
- const l = Q(s, { contentHint: r });
2448
+ const l = Y(s, { contentHint: r });
2351
2449
  if (l === void 0)
2352
2450
  throw new Error("No streamPresentationTarget");
2353
2451
  this.streamPresentationCurrent = l;
@@ -2357,8 +2455,8 @@ class Nn {
2357
2455
  onAddedTransceiver: c
2358
2456
  })).then(this.setMaxBitrate).then(() => s).catch((g) => {
2359
2457
  this.removeStreamPresentationCurrent();
2360
- const E = g instanceof Error ? g : new Error(String(g));
2361
- throw this.events.trigger(P.FAILED_PRESENTATION, E), g;
2458
+ const S = g instanceof Error ? g : new Error(String(g));
2459
+ throw this.events.trigger(L.FAILED_PRESENTATION, S), g;
2362
2460
  });
2363
2461
  return this.promisePendingStartPresentation = T, T.finally(() => {
2364
2462
  this.promisePendingStartPresentation = void 0;
@@ -2369,7 +2467,7 @@ class Nn {
2369
2467
  if (!e || !t || s === void 0)
2370
2468
  return;
2371
2469
  const i = e.getSenders();
2372
- await Ft(i, t, s);
2470
+ await Vt(i, t, s);
2373
2471
  };
2374
2472
  getRtcSessionProtected = () => {
2375
2473
  const e = this.callManager.getEstablishedRTCSession();
@@ -2390,7 +2488,7 @@ class Nn {
2390
2488
  delete this.streamPresentationCurrent;
2391
2489
  }
2392
2490
  }
2393
- class Rn {
2491
+ class yn {
2394
2492
  data;
2395
2493
  getUa;
2396
2494
  constructor(e) {
@@ -2477,7 +2575,7 @@ class Rn {
2477
2575
  }
2478
2576
  }
2479
2577
  var m = /* @__PURE__ */ ((n) => (n.CONNECTING = "connecting", n.CONNECTED = "connected", n.DISCONNECTED = "disconnected", n.DISCONNECTING = "disconnecting", n.NEW_RTC_SESSION = "newRTCSession", n.REGISTERED = "registered", n.UNREGISTERED = "unregistered", n.REGISTRATION_FAILED = "registrationFailed", n.NEW_MESSAGE = "newMessage", n.SIP_EVENT = "sipEvent", n.CONNECT_STARTED = "connect-started", n.CONNECT_SUCCEEDED = "connect-succeeded", n.CONNECT_FAILED = "connect-failed", n.CONNECT_PARAMETERS_RESOLVE_SUCCESS = "connect-parameters-resolve-success", n.CONNECT_PARAMETERS_RESOLVE_FAILED = "connect-parameters-resolve-failed", n.CONNECTED_WITH_CONFIGURATION = "connected-with-configuration", n))(m || {});
2480
- const $e = [
2578
+ const qe = [
2481
2579
  "connecting",
2482
2580
  "connected",
2483
2581
  "disconnected",
@@ -2487,7 +2585,7 @@ const $e = [
2487
2585
  "registrationFailed",
2488
2586
  "newMessage",
2489
2587
  "sipEvent"
2490
- ], An = [
2588
+ ], Dn = [
2491
2589
  "disconnecting",
2492
2590
  "connect-started",
2493
2591
  "connect-succeeded",
@@ -2495,12 +2593,12 @@ const $e = [
2495
2593
  "connect-parameters-resolve-success",
2496
2594
  "connect-parameters-resolve-failed",
2497
2595
  "connected-with-configuration"
2498
- ], Ge = [...$e, ...An], In = () => new f(Ge);
2499
- function vn(n) {
2596
+ ], Ve = [...qe, ...Dn], Ln = () => new M(Ve);
2597
+ function wn(n) {
2500
2598
  return (e) => `sip:${e}@${n}`;
2501
2599
  }
2502
- const fn = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, qe = (n) => n.trim().replaceAll(" ", "_"), Mn = fn(1e5, 99999999), _n = 3;
2503
- class bn {
2600
+ const Un = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, xe = (n) => n.trim().replaceAll(" ", "_"), Fn = Un(1e5, 99999999), kn = 3;
2601
+ class Bn {
2504
2602
  cancelableConnectWithRepeatedCalls;
2505
2603
  events;
2506
2604
  uaFactory;
@@ -2525,7 +2623,7 @@ class bn {
2525
2623
  }
2526
2624
  let r = !1;
2527
2625
  const a = this.getConnectionConfiguration();
2528
- e !== void 0 && e !== a?.displayName && (r = i.set("display_name", qe(e)), this.updateConnectionConfiguration("displayName", e));
2626
+ e !== void 0 && e !== a?.displayName && (r = i.set("display_name", xe(e)), this.updateConnectionConfiguration("displayName", e));
2529
2627
  const o = r;
2530
2628
  o ? t(o) : s(new Error("nothing changed"));
2531
2629
  });
@@ -2543,12 +2641,12 @@ class bn {
2543
2641
  cancelRequests() {
2544
2642
  this.cancelConnectWithRepeatedCalls();
2545
2643
  }
2546
- connectWithDuplicatedCalls = async (e, { callLimit: t = _n } = {}) => {
2644
+ connectWithDuplicatedCalls = async (e, { callLimit: t = kn } = {}) => {
2547
2645
  const s = async () => this.connectInner(e), i = (r) => {
2548
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), l = r != null && !Tt(r);
2646
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), l = r != null && !pt(r);
2549
2647
  return c || l;
2550
2648
  };
2551
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = re({
2649
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = ce({
2552
2650
  targetFunction: s,
2553
2651
  isComplete: i,
2554
2652
  callLimit: t,
@@ -2582,37 +2680,37 @@ class bn {
2582
2680
  connectionRecoveryMaxInterval: l,
2583
2681
  userAgent: T,
2584
2682
  displayName: g = "",
2585
- register: E = !1,
2586
- extraHeaders: N = []
2683
+ register: S = !1,
2684
+ extraHeaders: R = []
2587
2685
  }) => {
2588
2686
  this.stateMachine.startInitUa(), this.getUa() && await this.disconnect();
2589
- const { ua: A, helpers: U } = this.uaFactory.createUAWithConfiguration(
2687
+ const { ua: I, helpers: U } = this.uaFactory.createUAWithConfiguration(
2590
2688
  {
2591
2689
  user: e,
2592
2690
  password: t,
2593
2691
  sipServerIp: s,
2594
2692
  sipServerUrl: i,
2595
2693
  displayName: g,
2596
- register: E,
2694
+ register: S,
2597
2695
  sessionTimers: a,
2598
2696
  registerExpires: o,
2599
2697
  connectionRecoveryMinInterval: c,
2600
2698
  connectionRecoveryMaxInterval: l,
2601
2699
  userAgent: T,
2602
2700
  remoteAddress: r,
2603
- extraHeaders: N
2701
+ extraHeaders: R
2604
2702
  },
2605
2703
  this.events
2606
- ), B = A.configuration.uri.user;
2704
+ ), B = I.configuration.uri.user;
2607
2705
  return this.setConnectionConfiguration({
2608
2706
  sipServerIp: s,
2609
2707
  sipServerUrl: i,
2610
2708
  displayName: g,
2611
2709
  authorizationUser: B,
2612
- register: E,
2710
+ register: S,
2613
2711
  user: e,
2614
2712
  password: t
2615
- }), this.setUa(A), this.setGetUri(U.getUri), this.setSocket(U.socket), A;
2713
+ }), this.setUa(I), this.setGetUri(U.getUri), this.setSocket(U.socket), I;
2616
2714
  };
2617
2715
  start = async () => new Promise((e, t) => {
2618
2716
  const s = this.getUa();
@@ -2624,12 +2722,12 @@ class bn {
2624
2722
  i = ((c, l) => {
2625
2723
  if (this.getConnectionConfiguration()?.register === !0)
2626
2724
  return this.registrationManager.subscribeToStartEvents(c, l);
2627
- const g = m.CONNECTED, E = [m.DISCONNECTED];
2628
- return this.events.on(g, c), E.forEach((N) => {
2629
- this.events.on(N, l);
2725
+ const g = m.CONNECTED, S = [m.DISCONNECTED];
2726
+ return this.events.on(g, c), S.forEach((R) => {
2727
+ this.events.on(R, l);
2630
2728
  }), () => {
2631
- this.events.off(g, c), E.forEach((N) => {
2632
- this.events.off(N, l);
2729
+ this.events.off(g, c), S.forEach((R) => {
2730
+ this.events.off(R, l);
2633
2731
  });
2634
2732
  };
2635
2733
  })(() => {
@@ -2648,8 +2746,8 @@ class bn {
2648
2746
  });
2649
2747
  }
2650
2748
  }
2651
- var On = /* @__PURE__ */ ((n) => (n.IDLE = "connection:idle", n.PREPARING = "connection:preparing", n.CONNECTING = "connection:connecting", n.CONNECTED = "connection:connected", n.REGISTERED = "connection:registered", n.ESTABLISHED = "connection:established", n.DISCONNECTED = "connection:disconnected", n.FAILED = "connection:failed", n))(On || {}), Ve = /* @__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))(Ve || {});
2652
- const yn = Object.values(Ve), Dn = V({
2749
+ var $n = /* @__PURE__ */ ((n) => (n.IDLE = "connection:idle", n.PREPARING = "connection:preparing", n.CONNECTING = "connection:connecting", n.CONNECTED = "connection:connected", n.REGISTERED = "connection:registered", n.ESTABLISHED = "connection:established", n.DISCONNECTED = "connection:disconnected", n.FAILED = "connection:failed", n))($n || {}), 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 || {});
2750
+ const Gn = Object.values(He), qn = V({
2653
2751
  types: {
2654
2752
  context: {},
2655
2753
  events: {}
@@ -2661,13 +2759,13 @@ const yn = Object.values(Ve), Dn = V({
2661
2759
  logStateChange: (n, e) => {
2662
2760
  d("ConnectionStateMachine state changed", e.state);
2663
2761
  },
2664
- setError: I({
2762
+ setError: v({
2665
2763
  error: ({ event: n }) => {
2666
2764
  if (n.type === "CONNECTION_FAILED" && "error" in n)
2667
2765
  return n.error;
2668
2766
  }
2669
2767
  }),
2670
- clearError: I({
2768
+ clearError: v({
2671
2769
  error: () => {
2672
2770
  }
2673
2771
  })
@@ -3029,11 +3127,11 @@ const yn = Object.values(Ve), Dn = V({
3029
3127
  }
3030
3128
  }
3031
3129
  });
3032
- class Pn extends x {
3130
+ class Vn extends x {
3033
3131
  events;
3034
3132
  unsubscribeFromEvents;
3035
3133
  constructor(e) {
3036
- super(Dn), this.events = e, this.subscribeToEvents();
3134
+ super(qn), this.events = e, this.subscribeToEvents();
3037
3135
  }
3038
3136
  get isIdle() {
3039
3137
  return this.hasState(
@@ -3115,7 +3213,7 @@ class Pn extends x {
3115
3213
  return this.actor.getSnapshot().can({ type: e });
3116
3214
  }
3117
3215
  getValidEvents() {
3118
- return yn.filter((e) => this.canTransition(e));
3216
+ return Gn.filter((e) => this.canTransition(e));
3119
3217
  }
3120
3218
  hasState(e) {
3121
3219
  return this.actor.getSnapshot().matches(e);
@@ -3187,7 +3285,7 @@ class Pn extends x {
3187
3285
  this.toFailed(e instanceof Error ? e : void 0);
3188
3286
  };
3189
3287
  }
3190
- class wn {
3288
+ class xn {
3191
3289
  events;
3192
3290
  getUaProtected;
3193
3291
  constructor(e) {
@@ -3224,7 +3322,7 @@ class wn {
3224
3322
  };
3225
3323
  }
3226
3324
  }
3227
- class Ln {
3325
+ class Hn {
3228
3326
  uaFactory;
3229
3327
  getUaProtected;
3230
3328
  constructor(e) {
@@ -3276,20 +3374,20 @@ class Ln {
3276
3374
  userAgent: e,
3277
3375
  sipServerIp: s
3278
3376
  }), T = this.uaFactory.createUA({ ...l, remoteAddress: r, extraHeaders: a }), g = () => {
3279
- const N = new Error("Telephony is not available");
3280
- c(N);
3377
+ const R = new Error("Telephony is not available");
3378
+ c(R);
3281
3379
  };
3282
3380
  T.once(m.DISCONNECTED, g);
3283
- const E = () => {
3381
+ const S = () => {
3284
3382
  T.removeAllListeners(), T.once(m.DISCONNECTED, () => {
3285
3383
  o();
3286
3384
  }), T.stop();
3287
3385
  };
3288
- T.once(m.CONNECTED, E), T.start();
3386
+ T.once(m.CONNECTED, S), T.start();
3289
3387
  });
3290
3388
  }
3291
3389
  }
3292
- const Un = (n) => {
3390
+ const Wn = (n) => {
3293
3391
  const e = [];
3294
3392
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
3295
3393
  };
@@ -3318,10 +3416,10 @@ class k {
3318
3416
  throw new Error("user is required for authorized connection");
3319
3417
  }
3320
3418
  static resolveAuthorizationUser(e, t) {
3321
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${Mn()}`;
3419
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${Fn()}`;
3322
3420
  }
3323
3421
  static buildExtraHeaders(e, t) {
3324
- const s = e !== void 0 && e !== "" ? Un(e) : [];
3422
+ const s = e !== void 0 && e !== "" ? Wn(e) : [];
3325
3423
  return t === void 0 ? s : [...s, ...t];
3326
3424
  }
3327
3425
  createConfiguration({
@@ -3345,24 +3443,24 @@ class k {
3345
3443
  sipServerIp: r,
3346
3444
  sipServerUrl: s
3347
3445
  });
3348
- const E = k.resolveAuthorizationUser(a, e), N = vn(r), D = N(E), A = new this.JsSIP.WebSocketInterface(`wss://${s}/webrtc/wss/`);
3446
+ const S = k.resolveAuthorizationUser(a, e), R = wn(r), D = R(S), I = new this.JsSIP.WebSocketInterface(`wss://${s}/webrtc/wss/`);
3349
3447
  return {
3350
3448
  configuration: {
3351
3449
  password: t,
3352
3450
  register: a,
3353
3451
  uri: D,
3354
- display_name: qe(i),
3452
+ display_name: xe(i),
3355
3453
  user_agent: g,
3356
3454
  sdpSemantics: "unified-plan",
3357
- sockets: [A],
3455
+ sockets: [I],
3358
3456
  session_timers: o,
3359
3457
  register_expires: c,
3360
3458
  connection_recovery_min_interval: l,
3361
3459
  connection_recovery_max_interval: T
3362
3460
  },
3363
3461
  helpers: {
3364
- socket: A,
3365
- getUri: N
3462
+ socket: I,
3463
+ getUri: R
3366
3464
  }
3367
3465
  };
3368
3466
  }
@@ -3380,13 +3478,13 @@ class k {
3380
3478
  extraHeaders: e.extraHeaders
3381
3479
  });
3382
3480
  return t.eachTriggers((a, o) => {
3383
- const c = $e.find((l) => l === o);
3481
+ const c = qe.find((l) => l === o);
3384
3482
  c && r.on(c, a);
3385
3483
  }), { ua: r, helpers: i };
3386
3484
  }
3387
3485
  }
3388
- const xe = "Not ready for connection", Fn = (n) => n instanceof Error && n.message === xe, kn = () => new Error(xe), Bn = async (n) => typeof n == "function" ? n() : n;
3389
- class $n {
3486
+ const We = "Not ready for connection", Qn = (n) => n instanceof Error && n.message === We, Yn = () => new Error(We), zn = async (n) => typeof n == "function" ? n() : n;
3487
+ class Jn {
3390
3488
  events;
3391
3489
  stateMachine;
3392
3490
  ua;
@@ -3397,15 +3495,15 @@ class $n {
3397
3495
  sipOperations;
3398
3496
  configurationManager;
3399
3497
  constructor({ JsSIP: e }) {
3400
- this.events = In(), this.uaFactory = new k(e), this.registrationManager = new wn({
3498
+ this.events = Ln(), this.uaFactory = new k(e), this.registrationManager = new xn({
3401
3499
  events: this.events,
3402
3500
  getUaProtected: this.getUaProtected
3403
- }), this.stateMachine = new Pn(this.events), this.configurationManager = new Rn({
3501
+ }), this.stateMachine = new Vn(this.events), this.configurationManager = new yn({
3404
3502
  getUa: this.getUa
3405
- }), this.sipOperations = new Ln({
3503
+ }), this.sipOperations = new Hn({
3406
3504
  uaFactory: this.uaFactory,
3407
3505
  getUaProtected: this.getUaProtected
3408
- }), this.connectionFlow = new bn({
3506
+ }), this.connectionFlow = new Bn({
3409
3507
  events: this.events,
3410
3508
  uaFactory: this.uaFactory,
3411
3509
  stateMachine: this.stateMachine,
@@ -3498,6 +3596,13 @@ class $n {
3498
3596
  }
3499
3597
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
3500
3598
  getUri = (e) => e;
3599
+ getUser() {
3600
+ try {
3601
+ return this.getUaProtected().configuration.uri.user;
3602
+ } catch {
3603
+ return;
3604
+ }
3605
+ }
3501
3606
  getUaProtected = () => {
3502
3607
  if (!this.ua)
3503
3608
  throw new Error("UA not initialized");
@@ -3506,7 +3611,7 @@ class $n {
3506
3611
  getUa = () => this.ua;
3507
3612
  connectWithProcessError = async (e, t) => {
3508
3613
  if (!(t?.hasReadyForConnection?.() ?? !0))
3509
- throw kn();
3614
+ throw Yn();
3510
3615
  return this.processConnect(e, t).catch(async (i) => {
3511
3616
  const r = i;
3512
3617
  return this.disconnect().then(() => {
@@ -3516,7 +3621,7 @@ class $n {
3516
3621
  });
3517
3622
  });
3518
3623
  };
3519
- processConnect = async (e, t) => (this.events.trigger(m.CONNECT_STARTED, {}), Bn(e).then((s) => (this.events.trigger(m.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
3624
+ processConnect = async (e, t) => (this.events.trigger(m.CONNECT_STARTED, {}), zn(e).then((s) => (this.events.trigger(m.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
3520
3625
  throw this.events.trigger(m.CONNECT_PARAMETERS_RESOLVE_FAILED, s), s;
3521
3626
  }).then(async (s) => this.connectionFlow.connect(s, t)).then((s) => (this.events.trigger(m.CONNECT_SUCCEEDED, {
3522
3627
  ...s
@@ -3525,9 +3630,9 @@ class $n {
3525
3630
  throw this.events.trigger(m.CONNECT_FAILED, i), i;
3526
3631
  }));
3527
3632
  }
3528
- class Gn {
3633
+ class jn {
3529
3634
  connectionManager;
3530
- stackPromises = Ie({
3635
+ stackPromises = fe({
3531
3636
  noRunIsNotActual: !0
3532
3637
  });
3533
3638
  constructor({ connectionManager: e }) {
@@ -3539,11 +3644,11 @@ class Gn {
3539
3644
  this.stackPromises.stop();
3540
3645
  }
3541
3646
  }
3542
- const Ee = 0, qn = 30;
3543
- class Vn {
3544
- countInner = Ee;
3545
- initialCount = Ee;
3546
- limitInner = qn;
3647
+ const me = 0, Kn = 30;
3648
+ class Xn {
3649
+ countInner = me;
3650
+ initialCount = me;
3651
+ limitInner = Kn;
3547
3652
  isInProgress = !1;
3548
3653
  onStatusChange;
3549
3654
  constructor({
@@ -3576,7 +3681,7 @@ class Vn {
3576
3681
  this.countInner = this.initialCount, this.finishAttempt();
3577
3682
  }
3578
3683
  }
3579
- class xn {
3684
+ class Zn {
3580
3685
  connectionManager;
3581
3686
  interval;
3582
3687
  checkTelephonyByTimeout = void 0;
@@ -3592,7 +3697,7 @@ class xn {
3592
3697
  onSuccessRequest: t,
3593
3698
  onFailRequest: s
3594
3699
  }) {
3595
- this.stop(), this.cancelableBeforeRequest = new X(e), this.checkTelephonyByTimeout = it({
3700
+ this.stop(), this.cancelableBeforeRequest = new X(e), this.checkTelephonyByTimeout = ct({
3596
3701
  isDontStopOnFail: !0,
3597
3702
  requestInterval: this.interval,
3598
3703
  request: async () => {
@@ -3613,7 +3718,7 @@ class xn {
3613
3718
  }
3614
3719
  }
3615
3720
  var _ = /* @__PURE__ */ ((n) => (n.BEFORE_ATTEMPT = "before-attempt", n.SUCCESS = "success", n.FAILED_ALL_ATTEMPTS = "failed-all-attempts", n.CANCELLED_ATTEMPTS = "cancelled-attempts", n.CHANGED_ATTEMPT_STATUS = "changed-attempt-status", n.STOP_ATTEMPTS_BY_ERROR = "stop-attempts-by-error", n.LIMIT_REACHED_ATTEMPTS = "limit-reached-attempts", n))(_ || {});
3616
- const He = [
3721
+ const Qe = [
3617
3722
  "before-attempt",
3618
3723
  "success",
3619
3724
  "failed-all-attempts",
@@ -3621,8 +3726,8 @@ const He = [
3621
3726
  "changed-attempt-status",
3622
3727
  "stop-attempts-by-error",
3623
3728
  "limit-reached-attempts"
3624
- ], Hn = () => new f(He);
3625
- class ce {
3729
+ ], es = () => new M(Qe);
3730
+ class he {
3626
3731
  callManager;
3627
3732
  disposers = [];
3628
3733
  constructor({ callManager: e }) {
@@ -3647,15 +3752,15 @@ class ce {
3647
3752
  this.callManager.isCallActive ? e?.() : t();
3648
3753
  }
3649
3754
  }
3650
- const Wn = 15e3, Qn = 2;
3651
- class Yn {
3755
+ const ts = 15e3, ns = 2;
3756
+ class ss {
3652
3757
  connectionManager;
3653
3758
  pingServerByTimeoutWithFailCalls;
3654
3759
  constructor({ connectionManager: e }) {
3655
- this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = rt(Qn, {
3760
+ this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = dt(ns, {
3656
3761
  whenPossibleRequest: async () => {
3657
3762
  },
3658
- requestInterval: Wn,
3763
+ requestInterval: ts,
3659
3764
  request: async () => (d("ping"), this.connectionManager.ping().then(() => {
3660
3765
  d("ping success");
3661
3766
  }))
@@ -3668,16 +3773,16 @@ class Yn {
3668
3773
  this.pingServerByTimeoutWithFailCalls.stop();
3669
3774
  }
3670
3775
  }
3671
- class zn {
3776
+ class is {
3672
3777
  pingServerRequester;
3673
3778
  notActiveCallSubscriber;
3674
3779
  constructor({
3675
3780
  connectionManager: e,
3676
3781
  callManager: t
3677
3782
  }) {
3678
- this.pingServerRequester = new Yn({
3783
+ this.pingServerRequester = new ss({
3679
3784
  connectionManager: e
3680
- }), this.notActiveCallSubscriber = new ce({ callManager: t });
3785
+ }), this.notActiveCallSubscriber = new he({ callManager: t });
3681
3786
  }
3682
3787
  start({ onFailRequest: e }) {
3683
3788
  d("start"), this.notActiveCallSubscriber.subscribe({
@@ -3696,7 +3801,7 @@ class zn {
3696
3801
  this.notActiveCallSubscriber.unsubscribe();
3697
3802
  }
3698
3803
  }
3699
- class Jn {
3804
+ class rs {
3700
3805
  connectionManager;
3701
3806
  isRegistrationFailed = !1;
3702
3807
  disposers = [];
@@ -3705,7 +3810,7 @@ class Jn {
3705
3810
  connectionManager: e,
3706
3811
  callManager: t
3707
3812
  }) {
3708
- this.connectionManager = e, this.notActiveCallSubscriber = new ce({ callManager: t });
3813
+ this.connectionManager = e, this.notActiveCallSubscriber = new he({ callManager: t });
3709
3814
  }
3710
3815
  subscribe(e) {
3711
3816
  this.unsubscribe(), this.disposers.push(
@@ -3732,12 +3837,12 @@ class Jn {
3732
3837
  this.isRegistrationFailed = !1;
3733
3838
  }
3734
3839
  }
3735
- const jn = 3e3, Xn = 15e3, Se = {
3840
+ const as = 3e3, os = 15e3, pe = {
3736
3841
  LIMIT_REACHED: "Limit reached",
3737
3842
  FAILED_TO_RECONNECT: "Failed to reconnect"
3738
- }, Kn = async () => {
3739
- }, Zn = (n) => !0;
3740
- class es {
3843
+ }, cs = async () => {
3844
+ }, ds = (n) => !0;
3845
+ class hs {
3741
3846
  events;
3742
3847
  connectionManager;
3743
3848
  connectionQueueManager;
@@ -3757,21 +3862,21 @@ class es {
3757
3862
  connectionManager: t,
3758
3863
  callManager: s
3759
3864
  }, i) {
3760
- const r = i?.onBeforeRetry ?? Kn, a = i?.canRetryOnError ?? Zn;
3761
- this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = r, this.canRetryOnError = a, this.networkInterfacesSubscriber = i?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = i?.resumeFromSleepModeSubscriber, this.events = Hn(), this.checkTelephonyRequester = new xn({
3865
+ const r = i?.onBeforeRetry ?? cs, a = i?.canRetryOnError ?? ds;
3866
+ this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = r, this.canRetryOnError = a, this.networkInterfacesSubscriber = i?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = i?.resumeFromSleepModeSubscriber, this.events = es(), this.checkTelephonyRequester = new Zn({
3762
3867
  connectionManager: t,
3763
- interval: i?.checkTelephonyRequestInterval ?? Xn
3764
- }), this.pingServerIfNotActiveCallRequester = new zn({
3868
+ interval: i?.checkTelephonyRequestInterval ?? os
3869
+ }), this.pingServerIfNotActiveCallRequester = new is({
3765
3870
  connectionManager: t,
3766
3871
  callManager: s
3767
- }), this.registrationFailedOutOfCallSubscriber = new Jn({
3872
+ }), this.registrationFailedOutOfCallSubscriber = new rs({
3768
3873
  connectionManager: t,
3769
3874
  callManager: s
3770
- }), this.attemptsState = new Vn({
3875
+ }), this.attemptsState = new Xn({
3771
3876
  onStatusChange: this.emitStatusChange
3772
- }), this.cancelableRequestBeforeRetry = new X(r), this.delayBetweenAttempts = new at(
3773
- i?.timeoutBetweenAttempts ?? jn
3774
- ), this.notActiveCallSubscriber = new ce({ callManager: s });
3877
+ }), this.cancelableRequestBeforeRetry = new X(r), this.delayBetweenAttempts = new ht(
3878
+ i?.timeoutBetweenAttempts ?? as
3879
+ ), this.notActiveCallSubscriber = new he({ callManager: s });
3775
3880
  }
3776
3881
  start(e) {
3777
3882
  d("auto connector start"), this.restartConnectionAttempts(e), this.subscribeToNotActiveCall(e);
@@ -3836,7 +3941,7 @@ class es {
3836
3941
  }
3837
3942
  }
3838
3943
  handleConnectionError(e, t) {
3839
- if (Fn(e)) {
3944
+ if (Qn(e)) {
3840
3945
  this.attemptsState.finishAttempt(), this.events.trigger(_.STOP_ATTEMPTS_BY_ERROR, e);
3841
3946
  return;
3842
3947
  }
@@ -3844,14 +3949,14 @@ class es {
3844
3949
  d("executeConnectionAttempt: error does not allow retry", e), this.attemptsState.finishAttempt(), this.events.trigger(_.STOP_ATTEMPTS_BY_ERROR, e);
3845
3950
  return;
3846
3951
  }
3847
- if (ht(e)) {
3952
+ if (Tt(e)) {
3848
3953
  d("executeConnectionAttempt: not actual error", e), this.attemptsState.finishAttempt(), this.events.trigger(_.CANCELLED_ATTEMPTS, e);
3849
3954
  return;
3850
3955
  }
3851
3956
  d("executeConnectionAttempt: error", e), this.scheduleReconnect(t);
3852
3957
  }
3853
3958
  handleLimitReached(e) {
3854
- this.attemptsState.finishAttempt(), this.events.trigger(_.LIMIT_REACHED_ATTEMPTS, new Error(Se.LIMIT_REACHED)), this.startCheckTelephony(e);
3959
+ this.attemptsState.finishAttempt(), this.events.trigger(_.LIMIT_REACHED_ATTEMPTS, new Error(pe.LIMIT_REACHED)), this.startCheckTelephony(e);
3855
3960
  }
3856
3961
  handleSucceededAttempt(e) {
3857
3962
  d("handleSucceededAttempt"), this.subscribeToConnectTriggers(e), this.events.trigger(_.SUCCESS);
@@ -3912,8 +4017,8 @@ class es {
3912
4017
  }
3913
4018
  scheduleReconnect(e) {
3914
4019
  d("scheduleReconnect"), this.delayBetweenAttempts.request().then(async () => (d("scheduleReconnect: delayBetweenAttempts success"), this.cancelableRequestBeforeRetry.request())).then(async () => (d("scheduleReconnect: onBeforeRetry success"), this.attemptConnection(e))).catch((t) => {
3915
- const s = t instanceof Error ? t : new Error(Se.FAILED_TO_RECONNECT);
3916
- this.attemptsState.finishAttempt(), st(t) || ot(t) ? this.events.trigger(_.CANCELLED_ATTEMPTS, s) : this.events.trigger(_.FAILED_ALL_ATTEMPTS, s), d("scheduleReconnect: error", t);
4020
+ const s = t instanceof Error ? t : new Error(pe.FAILED_TO_RECONNECT);
4021
+ this.attemptsState.finishAttempt(), ot(t) || lt(t) ? this.events.trigger(_.CANCELLED_ATTEMPTS, s) : this.events.trigger(_.FAILED_ALL_ATTEMPTS, s), d("scheduleReconnect: error", t);
3917
4022
  });
3918
4023
  }
3919
4024
  isConnectionUnavailable() {
@@ -3924,14 +4029,14 @@ class es {
3924
4029
  this.events.trigger(_.CHANGED_ATTEMPT_STATUS, { isInProgress: e });
3925
4030
  };
3926
4031
  }
3927
- const ts = V({
4032
+ const ls = V({
3928
4033
  types: {
3929
4034
  context: {},
3930
4035
  events: {}
3931
4036
  },
3932
4037
  actions: {
3933
- setCodec: I(({ event: n }) => "codec" in n ? { codec: n.codec } : {}),
3934
- clearCodec: I({ codec: void 0 })
4038
+ setCodec: v(({ event: n }) => "codec" in n ? { codec: n.codec } : {}),
4039
+ clearCodec: v({ codec: void 0 })
3935
4040
  }
3936
4041
  }).createMachine({
3937
4042
  id: "contented-stream",
@@ -3965,9 +4070,9 @@ const ts = V({
3965
4070
  }
3966
4071
  }
3967
4072
  });
3968
- class ns extends x {
4073
+ class us extends x {
3969
4074
  constructor() {
3970
- super(ts);
4075
+ super(ls);
3971
4076
  }
3972
4077
  get isAvailable() {
3973
4078
  return this.state === "contented-stream:available";
@@ -4008,17 +4113,17 @@ class ns extends x {
4008
4113
  );
4009
4114
  }
4010
4115
  }
4011
- var se = /* @__PURE__ */ ((n) => (n.AVAILABLE = "available", n.NOT_AVAILABLE = "not-available", n))(se || {});
4012
- const ss = [
4116
+ var ae = /* @__PURE__ */ ((n) => (n.AVAILABLE = "available", n.NOT_AVAILABLE = "not-available", n))(ae || {});
4117
+ const gs = [
4013
4118
  "available",
4014
4119
  "not-available"
4015
4120
  /* NOT_AVAILABLE */
4016
- ], is = () => new f(ss);
4017
- class rs {
4121
+ ], Ts = () => new M(gs);
4122
+ class Es {
4018
4123
  events;
4019
4124
  stateMachine;
4020
4125
  constructor() {
4021
- this.events = is(), this.stateMachine = new ns(), this.proxyEvents();
4126
+ this.events = Ts(), this.stateMachine = new us(), this.proxyEvents();
4022
4127
  }
4023
4128
  get isAvailable() {
4024
4129
  return this.stateMachine.isAvailable;
@@ -4047,19 +4152,19 @@ class rs {
4047
4152
  proxyEvents() {
4048
4153
  this.stateMachine.onStateChange(() => {
4049
4154
  const e = this.getStateInfo();
4050
- e.isAvailable ? this.events.trigger(se.AVAILABLE, { codec: e.codec }) : this.events.trigger(se.NOT_AVAILABLE, {});
4155
+ e.isAvailable ? this.events.trigger(ae.AVAILABLE, { codec: e.codec }) : this.events.trigger(ae.NOT_AVAILABLE, {});
4051
4156
  });
4052
4157
  }
4053
4158
  }
4054
4159
  var G = /* @__PURE__ */ ((n) => (n.RINGING = "ringing", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(G || {});
4055
- const We = [
4160
+ const Ye = [
4056
4161
  "ringing",
4057
4162
  "declinedIncomingCall",
4058
4163
  "terminatedIncomingCall",
4059
4164
  "failedIncomingCall"
4060
- ], as = () => new f(We);
4061
- var os = /* @__PURE__ */ ((n) => (n.IDLE = "incoming:idle", n.RINGING = "incoming:ringing", n.CONSUMED = "incoming:consumed", n.DECLINED = "incoming:declined", n.TERMINATED = "incoming:terminated", n.FAILED = "incoming:failed", n))(os || {});
4062
- const cs = V({
4165
+ ], Ss = () => new M(Ye);
4166
+ var ms = /* @__PURE__ */ ((n) => (n.IDLE = "incoming:idle", n.RINGING = "incoming:ringing", n.CONSUMED = "incoming:consumed", n.DECLINED = "incoming:declined", n.TERMINATED = "incoming:terminated", n.FAILED = "incoming:failed", n))(ms || {});
4167
+ const ps = V({
4063
4168
  types: {
4064
4169
  context: {},
4065
4170
  events: {}
@@ -4071,11 +4176,11 @@ const cs = V({
4071
4176
  logStateChange: (n, e) => {
4072
4177
  d("IncomingCallStateMachine state changed", e.state);
4073
4178
  },
4074
- rememberIncoming: I(({ event: n }) => {
4179
+ rememberIncoming: v(({ event: n }) => {
4075
4180
  const { data: e } = n;
4076
4181
  return { remoteCallerData: e, lastReason: void 0 };
4077
4182
  }),
4078
- rememberReason: I(({ event: n, context: e }) => n.type === "INCOMING.CONSUMED" ? {
4183
+ rememberReason: v(({ event: n, context: e }) => n.type === "INCOMING.CONSUMED" ? {
4079
4184
  remoteCallerData: e.remoteCallerData,
4080
4185
  lastReason: "incoming:consumed"
4081
4186
  /* CONSUMED */
@@ -4092,7 +4197,7 @@ const cs = V({
4092
4197
  lastReason: "incoming:failed"
4093
4198
  /* FAILED */
4094
4199
  }),
4095
- clearIncoming: I(() => ({ remoteCallerData: void 0, lastReason: void 0 }))
4200
+ clearIncoming: v(() => ({ remoteCallerData: void 0, lastReason: void 0 }))
4096
4201
  }
4097
4202
  }).createMachine({
4098
4203
  id: "incoming",
@@ -4391,9 +4496,9 @@ const cs = V({
4391
4496
  }
4392
4497
  }
4393
4498
  });
4394
- class ds extends x {
4499
+ class Cs extends x {
4395
4500
  constructor({ incomingEvents: e, connectionEvents: t }) {
4396
- super(cs), this.subscribeIncomingEvents(e), this.subscribeConnectionEvents(t);
4501
+ super(ps), this.subscribeIncomingEvents(e), this.subscribeConnectionEvents(t);
4397
4502
  }
4398
4503
  get isIdle() {
4399
4504
  return this.state === "incoming:idle";
@@ -4478,26 +4583,26 @@ class ds extends x {
4478
4583
  this.send({ type: "INCOMING.CLEAR" });
4479
4584
  }
4480
4585
  }
4481
- const hs = 486, ls = 487, Z = (n) => ({
4586
+ const Rs = 486, Ns = 487, ne = (n) => ({
4482
4587
  displayName: n.remote_identity.display_name,
4483
4588
  host: n.remote_identity.uri.host,
4484
4589
  incomingNumber: n.remote_identity.uri.user,
4485
4590
  rtcSession: n
4486
4591
  });
4487
- class us {
4592
+ class As {
4488
4593
  events;
4489
4594
  stateMachine;
4490
4595
  incomingRTCSession;
4491
4596
  connectionManager;
4492
4597
  constructor(e) {
4493
- this.connectionManager = e, this.events = as(), this.stateMachine = new ds({
4598
+ this.connectionManager = e, this.events = Ss(), this.stateMachine = new Cs({
4494
4599
  incomingEvents: this.events,
4495
4600
  connectionEvents: this.connectionManager.events
4496
4601
  }), this.start();
4497
4602
  }
4498
4603
  get remoteCallerData() {
4499
4604
  if (this.incomingRTCSession)
4500
- return Z(this.incomingRTCSession);
4605
+ return ne(this.incomingRTCSession);
4501
4606
  }
4502
4607
  get isAvailableIncomingCall() {
4503
4608
  return !!this.incomingRTCSession;
@@ -4519,11 +4624,11 @@ class us {
4519
4624
  return this.stateMachine.toConsumed(), this.removeIncomingSession(), e;
4520
4625
  };
4521
4626
  async declineToIncomingCall({
4522
- statusCode: e = ls
4627
+ statusCode: e = Ns
4523
4628
  } = {}) {
4524
4629
  return new Promise((t, s) => {
4525
4630
  try {
4526
- const i = this.getIncomingRTCSession(), r = Z(i);
4631
+ const i = this.getIncomingRTCSession(), r = ne(i);
4527
4632
  this.removeIncomingSession(), this.events.trigger(G.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
4528
4633
  } catch (i) {
4529
4634
  s(i);
@@ -4531,7 +4636,7 @@ class us {
4531
4636
  });
4532
4637
  }
4533
4638
  async busyIncomingCall() {
4534
- return this.declineToIncomingCall({ statusCode: hs });
4639
+ return this.declineToIncomingCall({ statusCode: Rs });
4535
4640
  }
4536
4641
  on(e, t) {
4537
4642
  return this.events.on(e, t);
@@ -4562,7 +4667,7 @@ class us {
4562
4667
  };
4563
4668
  setIncomingSession(e) {
4564
4669
  this.incomingRTCSession = e;
4565
- const t = Z(e);
4670
+ const t = ne(e);
4566
4671
  e.on("failed", (s) => {
4567
4672
  this.removeIncomingSession(), s.originator === "local" ? this.events.trigger(G.TERMINATED_INCOMING_CALL, t) : this.events.trigger(G.FAILED_INCOMING_CALL, t);
4568
4673
  }), this.events.trigger(G.RINGING, t);
@@ -4571,26 +4676,62 @@ class us {
4571
4676
  delete this.incomingRTCSession;
4572
4677
  }
4573
4678
  }
4574
- var Qe = /* @__PURE__ */ ((n) => (n.SNAPSHOT_CHANGED = "snapshot-changed", n))(Qe || {});
4575
- const Ye = ["snapshot-changed"], gs = () => new f(Ye), Ts = (n, e) => Object.is(n, e), me = (n) => ({
4679
+ class Is {
4680
+ apiManager;
4681
+ connectionManager;
4682
+ callManager;
4683
+ get user() {
4684
+ return this.connectionManager?.getUser();
4685
+ }
4686
+ get number() {
4687
+ return this.callManager?.number;
4688
+ }
4689
+ get isCallInitiator() {
4690
+ return !!this.callManager?.isCallInitiator;
4691
+ }
4692
+ get peerToPeerRoom() {
4693
+ if (!(this.user === void 0 || this.number === void 0))
4694
+ return this.isCallInitiator ? `p2p${this.user}to${this.number}` : `p2p${this.number}to${this.user}`;
4695
+ }
4696
+ subscribe({
4697
+ apiManager: e,
4698
+ connectionManager: t,
4699
+ callManager: s
4700
+ }) {
4701
+ this.apiManager = e, this.connectionManager = t, this.callManager = s, s.on("confirmed", this.maybeSendDirectPeerToPeerRoom);
4702
+ }
4703
+ maybeSendDirectPeerToPeerRoom = () => {
4704
+ const { peerToPeerRoom: e, number: t, apiManager: s } = this;
4705
+ if (e === void 0 || t === void 0 || s === void 0)
4706
+ return;
4707
+ const i = [
4708
+ `${h.CONTENT_ENTER_ROOM}: ${this.peerToPeerRoom}`,
4709
+ `${h.PARTICIPANT_NAME}: ${this.number}`,
4710
+ `${h.IS_DIRECT_PEER_TO_PEER}: true`
4711
+ ];
4712
+ s.sendEnterRoom(i);
4713
+ };
4714
+ }
4715
+ var ze = /* @__PURE__ */ ((n) => (n.SNAPSHOT_CHANGED = "snapshot-changed", n))(ze || {});
4716
+ const Je = ["snapshot-changed"], vs = () => new M(Je), fs = (n, e) => Object.is(n, e), Ce = (n) => ({
4576
4717
  connection: n.connection.getSnapshot(),
4577
4718
  call: n.call.getSnapshot(),
4578
4719
  incoming: n.incoming.getSnapshot(),
4579
4720
  presentation: n.presentation.getSnapshot()
4580
4721
  });
4581
- class Es {
4722
+ class Ms {
4582
4723
  events;
4583
4724
  machines;
4584
4725
  currentSnapshot;
4585
4726
  subscribers = /* @__PURE__ */ new Set();
4586
4727
  actorSubscriptions = [];
4587
4728
  constructor(e) {
4588
- this.events = gs(), this.machines = {
4729
+ this.events = vs(), this.machines = {
4589
4730
  connection: e.connectionManager.stateMachine,
4590
4731
  call: e.callManager.stateMachine,
4591
4732
  incoming: e.incomingCallManager.stateMachine,
4592
4733
  presentation: e.presentationManager.stateMachine
4593
- }, this.currentSnapshot = me(this.machines), this.actorSubscriptions.push(
4734
+ }, this.currentSnapshot = Ce(this.machines), this.actorSubscriptions.push(
4594
4735
  this.machines.connection.subscribe(this.notifySubscribers),
4595
4736
  this.machines.call.subscribe(this.notifySubscribers),
4596
4737
  this.machines.incoming.subscribe(this.notifySubscribers),
@@ -4601,7 +4742,7 @@ class Es {
4601
4742
  return this.currentSnapshot;
4602
4743
  }
4603
4744
  subscribe(e, t, s) {
4604
- const i = typeof t == "function", r = i ? e : (T) => T, a = i ? t : e, o = (i ? s : void 0) ?? Ts, c = r(this.currentSnapshot), l = {
4745
+ const i = typeof t == "function", r = i ? e : (T) => T, a = i ? t : e, o = (i ? s : void 0) ?? fs, c = r(this.currentSnapshot), l = {
4605
4746
  selector: r,
4606
4747
  listener: a,
4607
4748
  equals: o,
@@ -4624,12 +4765,12 @@ class Es {
4624
4765
  }
4625
4766
  notifySubscribers = () => {
4626
4767
  const e = this.currentSnapshot;
4627
- this.currentSnapshot = me(this.machines);
4768
+ this.currentSnapshot = Ce(this.machines);
4628
4769
  for (const t of this.subscribers) {
4629
4770
  const s = t.selector(this.currentSnapshot);
4630
4771
  t.equals(t.current, s) || (t.current = s, t.listener(s));
4631
4772
  }
4632
- this.events.trigger(Qe.SNAPSHOT_CHANGED, {
4773
+ this.events.trigger(ze.SNAPSHOT_CHANGED, {
4633
4774
  previous: e,
4634
4775
  current: this.currentSnapshot
4635
4776
  });
@@ -4637,10 +4778,10 @@ class Es {
4637
4778
  }
4638
4779
  const $ = 1e3;
4639
4780
  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 || {});
4640
- const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in window ? performance.now() : Date.now(), H = (n) => [...n.keys()].reduce((e, t) => {
4781
+ const je = ["collected"], _s = () => new M(je), Re = () => "performance" in window ? performance.now() : Date.now(), W = (n) => [...n.keys()].reduce((e, t) => {
4641
4782
  const s = n.get(t);
4642
4783
  return s === void 0 ? e : { ...e, [s.type]: s };
4643
- }, {}), ms = (n) => {
4784
+ }, {}), bs = (n) => {
4644
4785
  if (!n)
4645
4786
  return {
4646
4787
  outboundRtp: void 0,
@@ -4648,14 +4789,14 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4648
4789
  mediaSource: void 0,
4649
4790
  remoteInboundRtp: void 0
4650
4791
  };
4651
- const e = H(n);
4792
+ const e = W(n);
4652
4793
  return {
4653
4794
  outboundRtp: e[C.OUTBOUND_RTP],
4654
4795
  codec: e[C.CODEC],
4655
4796
  mediaSource: e[C.MEDIA_SOURCE],
4656
4797
  remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
4657
4798
  };
4658
- }, Ce = (n) => {
4799
+ }, Ne = (n) => {
4659
4800
  if (!n)
4660
4801
  return {
4661
4802
  outboundRtp: void 0,
@@ -4663,14 +4804,14 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4663
4804
  mediaSource: void 0,
4664
4805
  remoteInboundRtp: void 0
4665
4806
  };
4666
- const e = H(n);
4807
+ const e = W(n);
4667
4808
  return {
4668
4809
  outboundRtp: e[C.OUTBOUND_RTP],
4669
4810
  codec: e[C.CODEC],
4670
4811
  mediaSource: e[C.MEDIA_SOURCE],
4671
4812
  remoteInboundRtp: e[C.REMOTE_INBOUND_RTP]
4672
4813
  };
4673
- }, Ne = ({
4814
+ }, Ae = ({
4674
4815
  videoReceiversStats: n,
4675
4816
  synchronizationSourcesVideo: e
4676
4817
  }) => {
@@ -4680,13 +4821,13 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4680
4821
  codec: void 0,
4681
4822
  synchronizationSources: e
4682
4823
  };
4683
- const t = H(n);
4824
+ const t = W(n);
4684
4825
  return {
4685
4826
  inboundRtp: t[C.INBOUND_RTP],
4686
4827
  codec: t[C.CODEC],
4687
4828
  synchronizationSources: e
4688
4829
  };
4689
- }, ps = ({
4830
+ }, Os = ({
4690
4831
  audioReceiverStats: n,
4691
4832
  synchronizationSourcesAudio: e
4692
4833
  }) => {
@@ -4697,14 +4838,14 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4697
4838
  remoteOutboundRtp: void 0,
4698
4839
  synchronizationSources: e
4699
4840
  };
4700
- const t = H(n);
4841
+ const t = W(n);
4701
4842
  return {
4702
4843
  inboundRtp: t[C.INBOUND_RTP],
4703
4844
  codec: t[C.CODEC],
4704
4845
  remoteOutboundRtp: t[C.REMOTE_OUTBOUND_RTP],
4705
4846
  synchronizationSources: e
4706
4847
  };
4707
- }, Je = (n) => {
4848
+ }, Ke = (n) => {
4708
4849
  if (!n)
4709
4850
  return {
4710
4851
  candidatePair: void 0,
@@ -4713,7 +4854,7 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4713
4854
  remoteCandidate: void 0,
4714
4855
  transport: void 0
4715
4856
  };
4716
- const e = H(n);
4857
+ const e = W(n);
4717
4858
  return {
4718
4859
  candidatePair: e[C.CANDIDATE_PAIR],
4719
4860
  certificate: e[C.CERTIFICATE],
@@ -4721,39 +4862,39 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4721
4862
  remoteCandidate: e[C.REMOTE_CANDIDATE],
4722
4863
  transport: e[C.TRANSPORT]
4723
4864
  };
4724
- }, Cs = ({
4865
+ }, Ps = ({
4725
4866
  audioSenderStats: n,
4726
4867
  videoSenderFirstStats: e,
4727
4868
  videoSenderSecondStats: t
4728
4869
  }) => ({
4729
- video: Ce(e),
4730
- secondVideo: Ce(t),
4731
- audio: ms(n),
4732
- additional: Je(
4870
+ video: Ne(e),
4871
+ secondVideo: Ne(t),
4872
+ audio: bs(n),
4873
+ additional: Ke(
4733
4874
  n ?? e ?? t
4734
4875
  )
4735
- }), Ns = ({
4876
+ }), ys = ({
4736
4877
  audioReceiverStats: n,
4737
4878
  videoReceiverFirstStats: e,
4738
4879
  videoReceiverSecondStats: t,
4739
4880
  synchronizationSources: s
4740
4881
  }) => ({
4741
- video: Ne({
4882
+ video: Ae({
4742
4883
  videoReceiversStats: e,
4743
4884
  synchronizationSourcesVideo: s.video
4744
4885
  }),
4745
- secondVideo: Ne({
4886
+ secondVideo: Ae({
4746
4887
  videoReceiversStats: t,
4747
4888
  synchronizationSourcesVideo: s.video
4748
4889
  }),
4749
- audio: ps({
4890
+ audio: Os({
4750
4891
  audioReceiverStats: n,
4751
4892
  synchronizationSourcesAudio: s.audio
4752
4893
  }),
4753
- additional: Je(
4894
+ additional: Ke(
4754
4895
  n ?? e ?? t
4755
4896
  )
4756
- }), Rs = ({
4897
+ }), Ds = ({
4757
4898
  audioSenderStats: n,
4758
4899
  videoSenderFirstStats: e,
4759
4900
  videoSenderSecondStats: t,
@@ -4762,11 +4903,11 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4762
4903
  videoReceiverSecondStats: r,
4763
4904
  synchronizationSources: a
4764
4905
  }) => {
4765
- const o = Cs({
4906
+ const o = Ps({
4766
4907
  audioSenderStats: n,
4767
4908
  videoSenderFirstStats: e,
4768
4909
  videoSenderSecondStats: t
4769
- }), c = Ns({
4910
+ }), c = ys({
4770
4911
  audioReceiverStats: s,
4771
4912
  videoReceiverFirstStats: i,
4772
4913
  videoReceiverSecondStats: r,
@@ -4776,8 +4917,8 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4776
4917
  outbound: o,
4777
4918
  inbound: c
4778
4919
  };
4779
- }, As = async (n) => {
4780
- const e = "audio", t = "video", s = n.getSenders(), i = s.find((E) => E.track?.kind === e), r = s.filter((E) => E.track?.kind === t), a = n.getReceivers(), o = a.find((E) => E.track.kind === e), c = a.filter((E) => E.track.kind === t), l = {
4920
+ }, Ls = async (n) => {
4921
+ const e = "audio", t = "video", s = n.getSenders(), i = s.find((S) => S.track?.kind === e), r = s.filter((S) => S.track?.kind === t), a = n.getReceivers(), o = a.find((S) => S.track.kind === e), c = a.filter((S) => S.track.kind === t), l = {
4781
4922
  trackIdentifier: o?.track.id,
4782
4923
  item: o?.getSynchronizationSources()[0]
4783
4924
  }, T = {
@@ -4794,41 +4935,41 @@ const ze = ["collected"], Ss = () => new f(ze), pe = () => "performance" in wind
4794
4935
  o?.getStats() ?? Promise.resolve(void 0),
4795
4936
  c[0]?.getStats() ?? Promise.resolve(void 0),
4796
4937
  c[1]?.getStats() ?? Promise.resolve(void 0)
4797
- ]).then((E) => {
4938
+ ]).then((S) => {
4798
4939
  const [
4799
- N,
4940
+ R,
4800
4941
  D,
4801
- A,
4942
+ I,
4802
4943
  U,
4803
4944
  B,
4804
- nt
4805
- ] = E;
4945
+ it
4946
+ ] = S;
4806
4947
  return {
4807
4948
  synchronizationSources: g,
4808
- audioSenderStats: N,
4949
+ audioSenderStats: R,
4809
4950
  videoSenderFirstStats: D,
4810
- videoSenderSecondStats: A,
4951
+ videoSenderSecondStats: I,
4811
4952
  audioReceiverStats: U,
4812
4953
  videoReceiverFirstStats: B,
4813
- videoReceiverSecondStats: nt
4954
+ videoReceiverSecondStats: it
4814
4955
  };
4815
4956
  });
4816
- }, Is = (n) => {
4957
+ }, ws = (n) => {
4817
4958
  d(String(n));
4818
4959
  };
4819
- class vs {
4960
+ class Us {
4820
4961
  events;
4821
4962
  setTimeoutRequest;
4822
- requesterAllStatistics = new X(As);
4963
+ requesterAllStatistics = new X(Ls);
4823
4964
  constructor() {
4824
- this.events = Ss(), this.setTimeoutRequest = new Ae();
4965
+ this.events = _s(), this.setTimeoutRequest = new ve();
4825
4966
  }
4826
4967
  get requested() {
4827
4968
  return this.setTimeoutRequest.requested;
4828
4969
  }
4829
4970
  start(e, {
4830
4971
  interval: t = $,
4831
- onError: s = Is
4972
+ onError: s = ws
4832
4973
  } = {}) {
4833
4974
  this.stop(), this.setTimeoutRequest.request(() => {
4834
4975
  this.collectStatistics(e, {
@@ -4857,10 +4998,10 @@ class vs {
4857
4998
  collectStatistics = (e, {
4858
4999
  onError: t
4859
5000
  }) => {
4860
- const s = pe();
5001
+ const s = Re();
4861
5002
  this.requestAllStatistics(e).then((i) => {
4862
- this.events.trigger("collected", Rs(i));
4863
- const a = pe() - s;
5003
+ this.events.trigger("collected", Ds(i));
5004
+ const a = Re() - s;
4864
5005
  let o = $;
4865
5006
  a > 48 ? o = $ * 4 : a > 32 ? o = $ * 3 : a > 16 && (o = $ * 2), this.start(e, {
4866
5007
  onError: t,
@@ -4877,8 +5018,8 @@ class vs {
4877
5018
  return this.requesterAllStatistics.request(t);
4878
5019
  };
4879
5020
  }
4880
- const fs = 500;
4881
- class Ms {
5021
+ const Fs = 500;
5022
+ class ks {
4882
5023
  statsPeerConnection;
4883
5024
  availableStats;
4884
5025
  previousAvailableStats;
@@ -4888,7 +5029,7 @@ class Ms {
4888
5029
  callManager: e,
4889
5030
  apiManager: t
4890
5031
  }) {
4891
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new vs(), this.subscribe();
5032
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Us(), this.subscribe();
4892
5033
  }
4893
5034
  get events() {
4894
5035
  return this.statsPeerConnection.events;
@@ -4938,7 +5079,7 @@ class Ms {
4938
5079
  return this.previousInboundRtp?.packetsReceived;
4939
5080
  }
4940
5081
  get isReceivingPackets() {
4941
- const e = this.packetsReceived !== void 0 && this.packetsReceived >= fs, t = this.packetsReceived !== this.previousPacketsReceived;
5082
+ const e = this.packetsReceived !== void 0 && this.packetsReceived >= Fs, t = this.packetsReceived !== this.previousPacketsReceived;
4942
5083
  return e && t;
4943
5084
  }
4944
5085
  on(e, t) {
@@ -4978,33 +5119,33 @@ class Ms {
4978
5119
  });
4979
5120
  }
4980
5121
  }
4981
- const _s = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), bs = (n) => {
5122
+ const Bs = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), $s = (n) => {
4982
5123
  const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
4983
- return _s(s, i);
4984
- }, Os = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
5124
+ return Bs(s, i);
5125
+ }, Gs = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
4985
5126
  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;
4986
5127
  return a - o;
4987
- }), ys = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Ds = (n, {
5128
+ }), qs = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Vs = (n, {
4988
5129
  preferredMimeTypesVideoCodecs: e,
4989
5130
  excludeMimeTypesVideoCodecs: t
4990
5131
  }) => {
4991
5132
  try {
4992
5133
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
4993
- const s = bs("video"), i = ys(s, t), r = Os(i, e);
5134
+ const s = $s("video"), i = qs(s, t), r = Gs(i, e);
4994
5135
  n.setCodecPreferences(r);
4995
5136
  }
4996
5137
  } catch (s) {
4997
5138
  d("setCodecPreferences error", s);
4998
5139
  }
4999
- }, Ps = (n) => [...n.keys()].map((e) => n.get(e)), ws = (n, e) => Ps(n).find((t) => t?.type === e), Ls = async (n) => n.getStats().then((e) => ws(e, "codec")?.mimeType);
5000
- class Us {
5140
+ }, xs = (n) => [...n.keys()].map((e) => n.get(e)), Hs = (n, e) => xs(n).find((t) => t?.type === e), Ws = async (n) => n.getStats().then((e) => Hs(e, "codec")?.mimeType);
5141
+ class Qs {
5001
5142
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
5002
5143
  async getCodecFromSender(e) {
5003
- return await Ls(e) ?? "";
5144
+ return await Ws(e) ?? "";
5004
5145
  }
5005
5146
  }
5006
- class Fs {
5007
- stackPromises = Ie({
5147
+ class Ys {
5148
+ stackPromises = fe({
5008
5149
  noRunIsNotActual: !0
5009
5150
  });
5010
5151
  /**
@@ -5028,30 +5169,30 @@ class Fs {
5028
5169
  });
5029
5170
  }
5030
5171
  }
5031
- class ks {
5172
+ class zs {
5032
5173
  taskQueue;
5033
5174
  onSetParameters;
5034
5175
  constructor(e) {
5035
- this.onSetParameters = e, this.taskQueue = new Fs();
5176
+ this.onSetParameters = e, this.taskQueue = new Ys();
5036
5177
  }
5037
5178
  async setEncodingsToSender(e, t) {
5038
- return this.taskQueue.add(async () => ye(e, t, this.onSetParameters));
5179
+ return this.taskQueue.add(async () => Le(e, t, this.onSetParameters));
5039
5180
  }
5040
5181
  stop() {
5041
5182
  this.taskQueue.stop();
5042
5183
  }
5043
5184
  }
5044
- const je = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Bs = 1e6, y = (n) => n * Bs, Xe = y(0.06), Ke = y(4), $s = (n) => n <= 64 ? Xe : n <= 128 ? y(0.12) : n <= 256 ? y(0.25) : n <= 384 ? y(0.32) : n <= 426 ? y(0.38) : n <= 640 ? y(0.5) : n <= 848 ? y(0.7) : n <= 1280 ? y(1) : n <= 1920 ? y(2) : Ke, Gs = "av1", qs = (n) => je(n, Gs), Vs = 0.6, de = (n, e) => qs(e) ? n * Vs : n, xs = (n) => de(Xe, n), Hs = (n) => de(Ke, n), Re = (n, e) => {
5045
- const t = $s(n);
5046
- return de(t, e);
5047
- }, ee = 1, Ws = ({
5185
+ const Xe = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Js = 1e6, y = (n) => n * Js, Ze = y(0.06), et = y(4), js = (n) => n <= 64 ? Ze : n <= 128 ? y(0.12) : n <= 256 ? y(0.25) : n <= 384 ? y(0.32) : n <= 426 ? y(0.38) : n <= 640 ? y(0.5) : n <= 848 ? y(0.7) : n <= 1280 ? y(1) : n <= 1920 ? y(2) : et, Ks = "av1", Xs = (n) => Xe(n, Ks), Zs = 0.6, le = (n, e) => Xs(e) ? n * Zs : n, ei = (n) => le(Ze, n), ti = (n) => le(et, n), Ie = (n, e) => {
5186
+ const t = js(n);
5187
+ return le(t, e);
5188
+ }, se = 1, ni = ({
5048
5189
  videoTrack: n,
5049
5190
  targetSize: e
5050
5191
  }) => {
5051
- const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? ee : s / e.width, a = i === void 0 ? ee : i / e.height;
5052
- return Math.max(r, a, ee);
5192
+ const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? se : s / e.width, a = i === void 0 ? se : i / e.height;
5193
+ return Math.max(r, a, se);
5053
5194
  };
5054
- class Qs {
5195
+ class si {
5055
5196
  ignoreForCodec;
5056
5197
  senderFinder;
5057
5198
  codecProvider;
@@ -5084,7 +5225,7 @@ class Qs {
5084
5225
  if (!i?.track)
5085
5226
  return { ...this.resultNoChanged, sender: i };
5086
5227
  const r = await this.codecProvider.getCodecFromSender(i);
5087
- if (je(r, this.ignoreForCodec))
5228
+ if (Xe(r, this.ignoreForCodec))
5088
5229
  return { ...this.resultNoChanged, sender: i };
5089
5230
  const { mainCam: a, resolutionMainCam: o } = t ?? {};
5090
5231
  return this.processSender(
@@ -5126,7 +5267,7 @@ class Qs {
5126
5267
  async downgradeResolutionSender(e) {
5127
5268
  const { sender: t, codec: s } = e, i = {
5128
5269
  scaleResolutionDownBy: 200,
5129
- maxBitrate: xs(s)
5270
+ maxBitrate: ei(s)
5130
5271
  };
5131
5272
  return this.parametersSetter.setEncodingsToSender(t, i);
5132
5273
  }
@@ -5136,7 +5277,7 @@ class Qs {
5136
5277
  * @returns Promise с результатом
5137
5278
  */
5138
5279
  async setBitrateByTrackResolution(e) {
5139
- const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? Hs(i) : Re(a, i);
5280
+ const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? ti(i) : Ie(a, i);
5140
5281
  return this.parametersSetter.setEncodingsToSender(t, {
5141
5282
  scaleResolutionDownBy: 1,
5142
5283
  maxBitrate: o
@@ -5152,24 +5293,24 @@ class Qs {
5152
5293
  const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
5153
5294
  width: Number(s),
5154
5295
  height: Number(i)
5155
- }, l = Ws({
5296
+ }, l = ni({
5156
5297
  videoTrack: a,
5157
5298
  targetSize: c
5158
- }), T = Re(c.width, o), g = {
5299
+ }), T = Ie(c.width, o), g = {
5159
5300
  scaleResolutionDownBy: l,
5160
5301
  maxBitrate: T
5161
5302
  };
5162
5303
  return this.parametersSetter.setEncodingsToSender(r, g);
5163
5304
  }
5164
5305
  }
5165
- const Ys = (n) => n.find((e) => e.track?.kind === "video");
5166
- class zs {
5306
+ const ii = (n) => n.find((e) => e.track?.kind === "video");
5307
+ class ri {
5167
5308
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
5168
5309
  findVideoSender(e) {
5169
- return Ys(e);
5310
+ return ii(e);
5170
5311
  }
5171
5312
  }
5172
- class Js {
5313
+ class ai {
5173
5314
  currentSender;
5174
5315
  originalReplaceTrack;
5175
5316
  lastWidth;
@@ -5182,7 +5323,7 @@ class Js {
5182
5323
  pollIntervalMs: e = 1e3,
5183
5324
  maxPollIntervalMs: t
5184
5325
  }) {
5185
- this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new Ae();
5326
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new ve();
5186
5327
  }
5187
5328
  /**
5188
5329
  * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
@@ -5233,7 +5374,7 @@ class Js {
5233
5374
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
5234
5375
  }
5235
5376
  }
5236
- class js {
5377
+ class oi {
5237
5378
  apiManager;
5238
5379
  currentHandler;
5239
5380
  constructor(e) {
@@ -5253,7 +5394,7 @@ class js {
5253
5394
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
5254
5395
  }
5255
5396
  }
5256
- class Xs {
5397
+ class ci {
5257
5398
  eventHandler;
5258
5399
  senderBalancer;
5259
5400
  parametersSetterWithQueue;
@@ -5265,16 +5406,16 @@ class Xs {
5265
5406
  onSetParameters: i,
5266
5407
  pollIntervalMs: r
5267
5408
  } = {}) {
5268
- this.getConnection = t, this.eventHandler = new js(e), this.parametersSetterWithQueue = new ks(i), this.senderBalancer = new Qs(
5409
+ this.getConnection = t, this.eventHandler = new oi(e), this.parametersSetterWithQueue = new zs(i), this.senderBalancer = new si(
5269
5410
  {
5270
- senderFinder: new zs(),
5271
- codecProvider: new Us(),
5411
+ senderFinder: new ri(),
5412
+ codecProvider: new Qs(),
5272
5413
  parametersSetter: this.parametersSetterWithQueue
5273
5414
  },
5274
5415
  {
5275
5416
  ignoreForCodec: s
5276
5417
  }
5277
- ), this.trackMonitor = new Js({ pollIntervalMs: r });
5418
+ ), this.trackMonitor = new ai({ pollIntervalMs: r });
5278
5419
  }
5279
5420
  /**
5280
5421
  * Подписывается на события управления главной камерой
@@ -5319,13 +5460,13 @@ class Xs {
5319
5460
  });
5320
5461
  };
5321
5462
  }
5322
- const Ze = [
5463
+ const tt = [
5323
5464
  "balancing-scheduled",
5324
5465
  "balancing-started",
5325
5466
  "balancing-stopped",
5326
5467
  "parameters-updated"
5327
- ], Ks = () => new f(Ze);
5328
- class Zs {
5468
+ ], di = () => new M(tt);
5469
+ class hi {
5329
5470
  isBalancingActive = !1;
5330
5471
  events;
5331
5472
  callManager;
@@ -5333,7 +5474,7 @@ class Zs {
5333
5474
  videoSendingBalancer;
5334
5475
  startBalancingTimer;
5335
5476
  constructor(e, t, s = {}) {
5336
- this.events = Ks(), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new Xs(
5477
+ this.events = di(), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new ci(
5337
5478
  t,
5338
5479
  () => e.connection,
5339
5480
  {
@@ -5403,13 +5544,13 @@ class Zs {
5403
5544
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
5404
5545
  }
5405
5546
  }
5406
- const et = "no-inbound-frames", tt = [et], ei = () => new f(tt);
5407
- class ti {
5547
+ const nt = "no-inbound-frames", st = [nt], li = () => new M(st);
5548
+ class ui {
5408
5549
  events;
5409
5550
  statsManager;
5410
5551
  callManager;
5411
5552
  constructor(e, t) {
5412
- this.statsManager = e, this.callManager = t, this.events = ei(), this.subscribe();
5553
+ this.statsManager = e, this.callManager = t, this.events = li(), this.subscribe();
5413
5554
  }
5414
5555
  get mainVideoTrack() {
5415
5556
  return this.callManager.getMainRemoteStream()?.getVideoTracks()[0];
@@ -5422,20 +5563,20 @@ class ti {
5422
5563
  return this.events.on(e, t);
5423
5564
  }
5424
5565
  handleStatsCollected = () => {
5425
- this.hasNoIncomingFrames() && this.events.trigger(et, {});
5566
+ this.hasNoIncomingFrames() && this.events.trigger(nt, {});
5426
5567
  };
5427
5568
  hasNoIncomingFrames = () => this.statsManager.isInvalidInboundFrames && this.isMutedMainVideoTrack;
5428
5569
  subscribe() {
5429
5570
  this.statsManager.on("collected", this.handleStatsCollected);
5430
5571
  }
5431
5572
  }
5432
- const ni = 3e3;
5433
- class si {
5573
+ const gi = 3e3;
5574
+ class Ti {
5434
5575
  renegotiateRequester;
5435
5576
  renegotiateThrottled;
5436
5577
  callManager;
5437
- constructor(e, t = ni) {
5438
- this.callManager = e, this.renegotiateRequester = new X(e.renegotiate.bind(e)), this.renegotiateThrottled = lt.throttle(
5578
+ constructor(e, t = gi) {
5579
+ this.callManager = e, this.renegotiateRequester = new X(e.renegotiate.bind(e)), this.renegotiateThrottled = Et.throttle(
5439
5580
  this.requestRenegotiate.bind(this),
5440
5581
  t
5441
5582
  ), this.subscribe();
@@ -5463,24 +5604,24 @@ class si {
5463
5604
  d("cancel recover main stream"), this.renegotiateThrottled.cancel(), this.renegotiateRequester.cancelRequest();
5464
5605
  }
5465
5606
  }
5466
- const ii = 1e6, ri = He.map((n) => `auto-connect:${n}`), ai = Ge.map((n) => `connection:${n}`), oi = Ue.map((n) => `call:${n}`), ci = Me.map((n) => `api:${n}`), di = We.map((n) => `incoming-call:${n}`), hi = Be.map((n) => `presentation:${n}`), li = ze.map((n) => `stats:${n}`), ui = Ze.map((n) => `video-balancer:${n}`), gi = tt.map((n) => `main-stream-health:${n}`), Ti = Ye.map((n) => `session:${n}`), Ei = [
5607
+ const Ei = 1e6, Si = Qe.map((n) => `auto-connect:${n}`), mi = Ve.map((n) => `connection:${n}`), pi = ke.map((n) => `call:${n}`), Ci = be.map((n) => `api:${n}`), Ri = Ye.map((n) => `incoming-call:${n}`), Ni = Ge.map((n) => `presentation:${n}`), Ai = je.map((n) => `stats:${n}`), Ii = tt.map((n) => `video-balancer:${n}`), vi = st.map((n) => `main-stream-health:${n}`), fi = Je.map((n) => `session:${n}`), Mi = [
5467
5608
  "disconnected-from-out-of-call",
5468
5609
  "connected-with-configuration-from-out-of-call",
5469
5610
  "stopped-presentation-by-server-command"
5470
- ], Si = [
5471
- ...ri,
5472
- ...ai,
5473
- ...oi,
5474
- ...ci,
5475
- ...di,
5476
- ...hi,
5477
- ...li,
5478
- ...ui,
5479
- ...gi,
5480
- ...Ti,
5481
- ...Ei
5482
- ], mi = () => new f(Si);
5483
- class Di {
5611
+ ], _i = [
5612
+ ...Si,
5613
+ ...mi,
5614
+ ...pi,
5615
+ ...Ci,
5616
+ ...Ri,
5617
+ ...Ni,
5618
+ ...Ai,
5619
+ ...Ii,
5620
+ ...vi,
5621
+ ...fi,
5622
+ ...Mi
5623
+ ], bi = () => new M(_i);
5624
+ class xi {
5484
5625
  events;
5485
5626
  connectionManager;
5486
5627
  connectionQueueManager;
@@ -5494,6 +5635,7 @@ class Di {
5494
5635
  videoSendingBalancerManager;
5495
5636
  sessionManager;
5496
5637
  mainStreamHealthMonitor;
5638
+ peerToPeerManager;
5497
5639
  mainStreamRecovery;
5498
5640
  preferredMimeTypesVideoCodecs;
5499
5641
  excludeMimeTypesVideoCodecs;
@@ -5503,26 +5645,26 @@ class Di {
5503
5645
  videoBalancerOptions: i,
5504
5646
  autoConnectorOptions: r
5505
5647
  } = {}) {
5506
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = mi(), this.apiManager = new Nt(), this.connectionManager = new $n({ JsSIP: e }), this.connectionQueueManager = new Gn({
5648
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = bi(), this.apiManager = new ft(), this.connectionManager = new Jn({ JsSIP: e }), this.connectionQueueManager = new jn({
5507
5649
  connectionManager: this.connectionManager
5508
- }), this.contentedStreamManager = new rs(), this.callManager = new Tn(this.contentedStreamManager), this.incomingCallManager = new us(this.connectionManager), this.presentationManager = new Nn({
5650
+ }), this.contentedStreamManager = new Es(), this.callManager = new vn(this.contentedStreamManager), this.incomingCallManager = new As(this.connectionManager), this.presentationManager = new Pn({
5509
5651
  callManager: this.callManager,
5510
- maxBitrate: ii
5511
- }), this.statsManager = new Ms({
5652
+ maxBitrate: Ei
5653
+ }), this.statsManager = new ks({
5512
5654
  callManager: this.callManager,
5513
5655
  apiManager: this.apiManager
5514
- }), this.autoConnectorManager = new es(
5656
+ }), this.autoConnectorManager = new hs(
5515
5657
  {
5516
5658
  connectionQueueManager: this.connectionQueueManager,
5517
5659
  connectionManager: this.connectionManager,
5518
5660
  callManager: this.callManager
5519
5661
  },
5520
5662
  r
5521
- ), this.videoSendingBalancerManager = new Zs(
5663
+ ), this.videoSendingBalancerManager = new hi(
5522
5664
  this.callManager,
5523
5665
  this.apiManager,
5524
5666
  i
5525
- ), this.mainStreamHealthMonitor = new ti(this.statsManager, this.callManager), this.mainStreamRecovery = new si(this.callManager), this.sessionManager = new Es({
5667
+ ), this.mainStreamHealthMonitor = new ui(this.statsManager, this.callManager), this.mainStreamRecovery = new Ti(this.callManager), this.sessionManager = new Ms({
5526
5668
  connectionManager: this.connectionManager,
5527
5669
  callManager: this.callManager,
5528
5670
  incomingCallManager: this.incomingCallManager,
@@ -5530,6 +5672,10 @@ class Di {
5530
5672
  }), this.callManager.subscribeToApiEvents(this.apiManager), this.contentedStreamManager.subscribeToApiEvents(this.apiManager), this.apiManager.subscribe({
5531
5673
  connectionManager: this.connectionManager,
5532
5674
  callManager: this.callManager
5675
+ }), this.peerToPeerManager = new Is(), this.peerToPeerManager.subscribe({
5676
+ connectionManager: this.connectionManager,
5677
+ callManager: this.callManager,
5678
+ apiManager: this.apiManager
5533
5679
  }), this.subscribe();
5534
5680
  }
5535
5681
  get requestedConnection() {
@@ -5568,6 +5714,9 @@ class Di {
5568
5714
  get isAvailableIncomingCall() {
5569
5715
  return this.incomingCallManager.isAvailableIncomingCall;
5570
5716
  }
5717
+ get isDirectP2PRoom() {
5718
+ return this.callManager.isDirectP2PRoom;
5719
+ }
5571
5720
  on(e, t) {
5572
5721
  return this.events.on(e, t);
5573
5722
  }
@@ -5626,35 +5775,34 @@ class Di {
5626
5775
  setRecvQuality = async (e) => this.callManager.setRecvQuality(e);
5627
5776
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
5628
5777
  async startPresentation(e, t = {}) {
5629
- const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
5778
+ const { callLimit: s, onAddedTransceiver: i, ...r } = t;
5630
5779
  return this.presentationManager.startPresentation(
5631
5780
  async () => {
5632
- await (s === !0 ? this.apiManager.sendAvailableContentedStream() : this.apiManager.askPermissionToStartPresentation());
5781
+ await (this.isDirectP2PRoom ? this.apiManager.sendAvailableContentedStream() : this.apiManager.askPermissionToStartPresentation());
5633
5782
  },
5634
5783
  e,
5635
5784
  {
5636
- ...a,
5637
- onAddedTransceiver: this.resolveHandleAddTransceiver(r)
5785
+ ...r,
5786
+ onAddedTransceiver: this.resolveHandleAddTransceiver(i)
5638
5787
  },
5639
- i === void 0 ? void 0 : { callLimit: i }
5788
+ s === void 0 ? void 0 : { callLimit: s }
5640
5789
  );
5641
5790
  }
5642
- async stopPresentation(e = {}) {
5643
- const { isP2P: t } = e;
5791
+ async stopPresentation() {
5644
5792
  return this.presentationManager.stopPresentation(async () => {
5645
- await (t === !0 ? this.apiManager.sendNotAvailableContentedStream() : this.apiManager.sendStoppedPresentation());
5793
+ await (this.isDirectP2PRoom ? this.apiManager.sendNotAvailableContentedStream() : this.apiManager.sendStoppedPresentation());
5646
5794
  });
5647
5795
  }
5648
5796
  async updatePresentation(e, t = {}) {
5649
- const { isP2P: s, onAddedTransceiver: i, ...r } = t;
5797
+ const { onAddedTransceiver: s, ...i } = t;
5650
5798
  return this.presentationManager.updatePresentation(
5651
5799
  async () => {
5652
- await (s === !0 ? this.apiManager.sendAvailableContentedStream() : this.apiManager.askPermissionToStartPresentation());
5800
+ await (this.isDirectP2PRoom ? this.apiManager.sendAvailableContentedStream() : this.apiManager.askPermissionToStartPresentation());
5653
5801
  },
5654
5802
  e,
5655
5803
  {
5656
- ...r,
5657
- onAddedTransceiver: this.resolveHandleAddTransceiver(i)
5804
+ ...i,
5805
+ onAddedTransceiver: this.resolveHandleAddTransceiver(s)
5658
5806
  }
5659
5807
  );
5660
5808
  }
@@ -5708,13 +5856,20 @@ class Di {
5708
5856
  this.callManager.setCallRoleSpectator({ audioId: e, sendOffer: this.sendOffer }), this.mayBeStopPresentationAndNotify();
5709
5857
  }), this.apiManager.on("presentation:must-stop", () => {
5710
5858
  this.mayBeStopPresentationAndNotify();
5859
+ }), this.apiManager.on("failed-send-room-direct-p2p", ({ error: e }) => {
5860
+ const t = new rt();
5861
+ t.body = e instanceof Error ? e.message : String(e);
5862
+ const s = at.causes.INTERNAL_ERROR;
5863
+ this.callManager.failed(t, s).catch((i) => {
5864
+ d("Failed to end call after failed:", i);
5865
+ });
5711
5866
  });
5712
5867
  }
5713
5868
  sendOffer = async (e, t) => {
5714
5869
  const i = this.connectionManager.getConnectionConfiguration()?.sipServerUrl;
5715
5870
  if (i === void 0)
5716
5871
  throw new Error("No sipServerUrl for sendOffer");
5717
- return vt({
5872
+ return Pt({
5718
5873
  serverUrl: i,
5719
5874
  offer: t,
5720
5875
  token: e.token,
@@ -5724,7 +5879,7 @@ class Di {
5724
5879
  });
5725
5880
  };
5726
5881
  setCodecPreferences(e) {
5727
- Ds(e, {
5882
+ Vs(e, {
5728
5883
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
5729
5884
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
5730
5885
  });
@@ -5749,27 +5904,28 @@ class Di {
5749
5904
  };
5750
5905
  }
5751
5906
  export {
5752
- kt as D,
5753
- Fe as E,
5754
- Vt as O,
5755
- Rt as P,
5756
- Di as S,
5757
- ye as a,
5758
- te as b,
5759
- ne as c,
5760
- On as d,
5761
- os as e,
5762
- Fn as f,
5763
- fe as g,
5764
- _e as h,
5765
- Sn as i,
5766
- C as j,
5767
- vs as k,
5907
+ xt as D,
5908
+ Be as E,
5909
+ Xt as O,
5910
+ _t as P,
5911
+ xi as S,
5912
+ Pe as a,
5913
+ Le as b,
5914
+ ie as c,
5915
+ re as d,
5916
+ $n as e,
5917
+ ms as f,
5918
+ Qn as g,
5919
+ Oe as h,
5920
+ _e as i,
5921
+ Mn as j,
5922
+ C as k,
5768
5923
  d as l,
5769
- Oi as m,
5770
- bi as n,
5771
- Ls as o,
5772
- Q as p,
5773
- yi as q,
5774
- vt as s
5924
+ Us as m,
5925
+ qi as n,
5926
+ Gi as o,
5927
+ Y as p,
5928
+ Ws as q,
5929
+ Vi as r,
5930
+ Pt as s
5775
5931
  };