sip-connector 20.2.1 → 20.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
- import x from "debug";
2
- import { TypedEvents as M } from "events-constructor";
3
- import { CancelableRequest as k, isCanceledError as be } from "@krivega/cancelable-promise";
4
- import { resolveRequesterByTimeout as ye, requesterByTimeoutsWithFailCalls as De, DelayRequester as we, hasCanceledError as Ue, SetTimeoutRequest as se } from "@krivega/timeout-requester";
5
- import { hasCanceledError as Le, repeatedCallsAsync as ie } from "repeated-calls";
6
- import { setup as Fe, createActor as Be } from "xstate";
7
- import { createStackPromises as re, isPromiseIsNotActualError as ke } from "stack-promises";
1
+ import z from "debug";
2
+ import { TypedEvents as O } from "events-constructor";
3
+ import { CancelableRequest as G, isCanceledError as we } from "@krivega/cancelable-promise";
4
+ import { resolveRequesterByTimeout as Ue, requesterByTimeoutsWithFailCalls as Fe, DelayRequester as Be, hasCanceledError as ke, SetTimeoutRequest as oe } from "@krivega/timeout-requester";
5
+ import { hasCanceledError as Ge, repeatedCallsAsync as ce } from "repeated-calls";
6
+ import { createActor as $e, setup as $, assign as b } from "xstate";
7
+ import { createStackPromises as le, isPromiseIsNotActualError as qe } from "stack-promises";
8
8
  import "ua-parser-js";
9
9
  import "sequent-promises";
10
- import $e from "lodash";
11
- const Q = "sip-connector", h = x(Q), Cs = () => {
12
- x.enable(Q);
13
- }, Es = () => {
14
- x.enable(`-${Q}`);
15
- }, qe = "Error decline with 603", Ve = 1006, He = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Ve, We = (n) => n.message === qe;
16
- var u = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n.AUDIO_TRACK_COUNT = "X-WEBRTC-AUDIO-TRACK-COUNT", n.VIDEO_TRACK_COUNT = "X-WEBRTC-VIDEO-TRACK-COUNT", n.TRACKS_DIRECTION = "X-WEBRTC-TRACKS-DIRECTION", n.AUDIO_ID = "X-WEBRTC-AUDIOID", n))(u || {}), F = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(F || {}), H = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(H || {}), b = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(b || {}), N = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.STATS = "application/vinteo.webrtc.stats", n))(N || {}), _ = /* @__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))(_ || {}), W = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(W || {}), G = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(G || {}), Ge = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Ge || {}), l = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_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.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n))(l || {});
17
- const ae = [
10
+ import Ve from "lodash";
11
+ const X = "sip-connector", l = z(X), Ds = () => {
12
+ z.enable(X);
13
+ }, ys = () => {
14
+ z.enable(`-${X}`);
15
+ }, He = "Error decline with 603", We = 1006, xe = (n) => typeof n == "object" && n !== null && "code" in n && n.code === We, Qe = (n) => n.message === He;
16
+ var E = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n.AVAILABLE_INCOMING_BITRATE = "X-WEBRTC-AVAILABLE-INCOMING-BITRATE", n.AUDIO_TRACK_COUNT = "X-WEBRTC-AUDIO-TRACK-COUNT", n.VIDEO_TRACK_COUNT = "X-WEBRTC-VIDEO-TRACK-COUNT", n.TRACKS_DIRECTION = "X-WEBRTC-TRACKS-DIRECTION", n.AUDIO_ID = "X-WEBRTC-AUDIOID", n))(E || {}), B = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(B || {}), x = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(x || {}), y = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(y || {}), I = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.STATS = "application/vinteo.webrtc.stats", n))(I || {}), v = /* @__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))(v || {}), Q = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(Q || {}), Y = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(Y || {}), Ye = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Ye || {}), g = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_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.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n))(g || {});
17
+ const de = [
18
18
  "participation:accepting-word-request",
19
19
  "participation:cancelling-word-request",
20
20
  "participant:move-request-to-stream",
@@ -44,9 +44,9 @@ const ae = [
44
44
  "notAvailableSecondRemoteStream",
45
45
  "mustStopPresentation",
46
46
  "newDTMF"
47
- ], xe = () => new M(ae);
48
- var m = /* @__PURE__ */ ((n) => (n.CHANNELS = "channels", n.WEBCAST_STARTED = "WebcastStarted", n.WEBCAST_STOPPED = "WebcastStopped", n.ACCOUNT_CHANGED = "accountChanged", n.ACCOUNT_DELETED = "accountDeleted", n.ADDED_TO_LIST_MODERATORS = "addedToListModerators", n.REMOVED_FROM_LIST_MODERATORS = "removedFromListModerators", n.ACCEPTING_WORD_REQUEST = "ParticipationRequestAccepted", n.CANCELLING_WORD_REQUEST = "ParticipationRequestRejected", n.MOVE_REQUEST_TO_STREAM = "ParticipantMovedToWebcast", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "ConferenceParticipantTokenIssued", n))(m || {});
49
- class Qe {
47
+ ], ze = () => new O(de);
48
+ var R = /* @__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))(R || {});
49
+ class Xe {
50
50
  events;
51
51
  connectionManager;
52
52
  callManager;
@@ -54,13 +54,13 @@ class Qe {
54
54
  connectionManager: e,
55
55
  callManager: t
56
56
  }) {
57
- this.connectionManager = e, this.callManager = t, this.events = xe(), this.subscribe();
57
+ this.connectionManager = e, this.callManager = t, this.events = ze(), this.subscribe();
58
58
  }
59
59
  async waitChannels() {
60
- return this.wait(l.CHANNELS);
60
+ return this.wait(g.CHANNELS);
61
61
  }
62
62
  async waitSyncMediaState() {
63
- return this.wait(l.ADMIN_FORCE_SYNC_MEDIA_STATE);
63
+ return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
64
64
  }
65
65
  async sendDTMF(e) {
66
66
  return new Promise((t, s) => {
@@ -79,19 +79,19 @@ class Qe {
79
79
  });
80
80
  }
81
81
  async sendChannels({ inputChannels: e, outputChannels: t }) {
82
- const s = this.getEstablishedRTCSessionProtected(), i = `${u.INPUT_CHANNELS}: ${e}`, r = `${u.OUTPUT_CHANNELS}: ${t}`, a = [
82
+ const s = this.getEstablishedRTCSessionProtected(), i = `${E.INPUT_CHANNELS}: ${e}`, r = `${E.OUTPUT_CHANNELS}: ${t}`, o = [
83
83
  i,
84
84
  r
85
85
  ];
86
- return s.sendInfo(N.CHANNELS, void 0, { extraHeaders: a });
86
+ return s.sendInfo(I.CHANNELS, void 0, { extraHeaders: o });
87
87
  }
88
88
  async sendMediaState({ cam: e, mic: t }, s = {}) {
89
- const i = this.getEstablishedRTCSessionProtected(), r = `${u.MEDIA_STATE}: currentstate`, a = `${u.MAIN_CAM_STATE}: ${Number(e)}`, o = `${u.MIC_STATE}: ${Number(t)}`, c = [
89
+ const i = this.getEstablishedRTCSessionProtected(), r = `${E.MEDIA_STATE}: currentstate`, o = `${E.MAIN_CAM_STATE}: ${Number(e)}`, a = `${E.MIC_STATE}: ${Number(t)}`, c = [
90
90
  r,
91
- a,
92
- o
91
+ o,
92
+ a
93
93
  ];
94
- return i.sendInfo(N.MEDIA_STATE, void 0, {
94
+ return i.sendInfo(I.MEDIA_STATE, void 0, {
95
95
  noTerminateWhenError: !0,
96
96
  ...s,
97
97
  extraHeaders: c
@@ -100,15 +100,15 @@ class Qe {
100
100
  async sendStats({
101
101
  availableIncomingBitrate: e
102
102
  }) {
103
- const t = this.getEstablishedRTCSessionProtected(), i = [`${u.AVAILABLE_INCOMING_BITRATE}: ${e}`];
104
- return t.sendInfo(N.STATS, void 0, {
103
+ const t = this.getEstablishedRTCSessionProtected(), i = [`${E.AVAILABLE_INCOMING_BITRATE}: ${e}`];
104
+ return t.sendInfo(I.STATS, void 0, {
105
105
  noTerminateWhenError: !0,
106
106
  extraHeaders: i
107
107
  });
108
108
  }
109
109
  async sendRefusalToTurnOn(e, t = {}) {
110
- const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${u.MEDIA_TYPE}: ${a}`];
111
- return s.sendInfo(N.REFUSAL, void 0, {
110
+ const s = this.getEstablishedRTCSessionProtected(), o = e === "mic" ? 0 : 1, c = [`${E.MEDIA_TYPE}: ${o}`];
111
+ return s.sendInfo(I.REFUSAL, void 0, {
112
112
  noTerminateWhenError: !0,
113
113
  ...t,
114
114
  extraHeaders: c
@@ -121,38 +121,38 @@ class Qe {
121
121
  return this.sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
122
122
  }
123
123
  async sendMustStopPresentationP2P() {
124
- await this.getEstablishedRTCSessionProtected().sendInfo(N.SHARE_STATE, void 0, {
125
- extraHeaders: [u.MUST_STOP_PRESENTATION_P2P]
124
+ await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
125
+ extraHeaders: [E.MUST_STOP_PRESENTATION_P2P]
126
126
  });
127
127
  }
128
128
  async sendStoppedPresentationP2P() {
129
- await this.getEstablishedRTCSessionProtected().sendInfo(N.SHARE_STATE, void 0, {
130
- extraHeaders: [u.STOP_PRESENTATION_P2P]
129
+ await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
130
+ extraHeaders: [E.STOP_PRESENTATION_P2P]
131
131
  });
132
132
  }
133
133
  async sendStoppedPresentation() {
134
- await this.getEstablishedRTCSessionProtected().sendInfo(N.SHARE_STATE, void 0, {
135
- extraHeaders: [u.STOP_PRESENTATION]
134
+ await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
135
+ extraHeaders: [E.STOP_PRESENTATION]
136
136
  });
137
137
  }
138
138
  async askPermissionToStartPresentationP2P() {
139
- await this.getEstablishedRTCSessionProtected().sendInfo(N.SHARE_STATE, void 0, {
140
- extraHeaders: [u.START_PRESENTATION_P2P]
139
+ await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
140
+ extraHeaders: [E.START_PRESENTATION_P2P]
141
141
  });
142
142
  }
143
143
  async askPermissionToStartPresentation() {
144
- await this.getEstablishedRTCSessionProtected().sendInfo(N.SHARE_STATE, void 0, {
145
- extraHeaders: [u.START_PRESENTATION]
144
+ await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE, void 0, {
145
+ extraHeaders: [E.START_PRESENTATION]
146
146
  });
147
147
  }
148
148
  async askPermissionToEnableCam(e = {}) {
149
- const t = this.getEstablishedRTCSessionProtected(), s = [u.ENABLE_MAIN_CAM];
150
- return t.sendInfo(N.MAIN_CAM, void 0, {
149
+ const t = this.getEstablishedRTCSessionProtected(), s = [E.ENABLE_MAIN_CAM];
150
+ return t.sendInfo(I.MAIN_CAM, void 0, {
151
151
  noTerminateWhenError: !0,
152
152
  ...e,
153
153
  extraHeaders: s
154
154
  }).catch((i) => {
155
- if (We(i))
155
+ if (Qe(i))
156
156
  throw i;
157
157
  });
158
158
  }
@@ -187,106 +187,106 @@ class Qe {
187
187
  };
188
188
  maybeHandleNotify = (e) => {
189
189
  try {
190
- const t = e.getHeader(u.NOTIFY);
190
+ const t = e.getHeader(E.NOTIFY);
191
191
  if (t) {
192
192
  const s = JSON.parse(t);
193
193
  this.handleNotify(s);
194
194
  }
195
195
  } catch (t) {
196
- h("error parse notify", t);
196
+ l("error parse notify", t);
197
197
  }
198
198
  };
199
199
  handleNotify = (e) => {
200
200
  switch (e.cmd) {
201
- case m.CHANNELS: {
201
+ case R.CHANNELS: {
202
202
  const t = e;
203
203
  this.triggerChannelsNotify(t);
204
204
  break;
205
205
  }
206
- case m.WEBCAST_STARTED: {
206
+ case R.WEBCAST_STARTED: {
207
207
  const t = e;
208
208
  this.triggerWebcastStartedNotify(t);
209
209
  break;
210
210
  }
211
- case m.WEBCAST_STOPPED: {
211
+ case R.WEBCAST_STOPPED: {
212
212
  const t = e;
213
213
  this.triggerWebcastStoppedNotify(t);
214
214
  break;
215
215
  }
216
- case m.ADDED_TO_LIST_MODERATORS: {
216
+ case R.ADDED_TO_LIST_MODERATORS: {
217
217
  const t = e;
218
218
  this.triggerAddedToListModeratorsNotify(t);
219
219
  break;
220
220
  }
221
- case m.REMOVED_FROM_LIST_MODERATORS: {
221
+ case R.REMOVED_FROM_LIST_MODERATORS: {
222
222
  const t = e;
223
223
  this.triggerRemovedFromListModeratorsNotify(t);
224
224
  break;
225
225
  }
226
- case m.ACCEPTING_WORD_REQUEST: {
226
+ case R.ACCEPTING_WORD_REQUEST: {
227
227
  const t = e;
228
228
  this.triggerParticipationAcceptingWordRequest(t);
229
229
  break;
230
230
  }
231
- case m.CANCELLING_WORD_REQUEST: {
231
+ case R.CANCELLING_WORD_REQUEST: {
232
232
  const t = e;
233
233
  this.triggerParticipationCancellingWordRequest(t);
234
234
  break;
235
235
  }
236
- case m.MOVE_REQUEST_TO_STREAM: {
236
+ case R.MOVE_REQUEST_TO_STREAM: {
237
237
  const t = e;
238
238
  this.triggerParticipantMoveRequestToStream(t);
239
239
  break;
240
240
  }
241
- case m.ACCOUNT_CHANGED: {
241
+ case R.ACCOUNT_CHANGED: {
242
242
  this.triggerAccountChangedNotify();
243
243
  break;
244
244
  }
245
- case m.ACCOUNT_DELETED: {
245
+ case R.ACCOUNT_DELETED: {
246
246
  this.triggerAccountDeletedNotify();
247
247
  break;
248
248
  }
249
- case m.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
249
+ case R.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
250
250
  const t = e;
251
251
  this.triggerConferenceParticipantTokenIssued(t);
252
252
  break;
253
253
  }
254
254
  default:
255
- h("unknown cmd", e);
255
+ l("unknown cmd", e);
256
256
  }
257
257
  };
258
258
  handleNewInfo = (e) => {
259
259
  const { originator: t } = e;
260
260
  if (t !== "remote")
261
261
  return;
262
- const { request: s } = e, i = s, r = i.getHeader(u.CONTENT_TYPE);
262
+ const { request: s } = e, i = s, r = i.getHeader(E.CONTENT_TYPE);
263
263
  if (r !== void 0)
264
264
  switch (r) {
265
- case b.ENTER_ROOM: {
265
+ case y.ENTER_ROOM: {
266
266
  this.triggerEnterRoom(i), this.maybeTriggerChannels(i);
267
267
  break;
268
268
  }
269
- case b.NOTIFY: {
269
+ case y.NOTIFY: {
270
270
  this.maybeHandleNotify(i);
271
271
  break;
272
272
  }
273
- case b.SHARE_STATE: {
273
+ case y.SHARE_STATE: {
274
274
  this.triggerShareState(i);
275
275
  break;
276
276
  }
277
- case b.MAIN_CAM: {
277
+ case y.MAIN_CAM: {
278
278
  this.triggerMainCamControl(i);
279
279
  break;
280
280
  }
281
- case b.MIC: {
281
+ case y.MIC: {
282
282
  this.triggerMicControl(i);
283
283
  break;
284
284
  }
285
- case b.USE_LICENSE: {
285
+ case y.USE_LICENSE: {
286
286
  this.triggerUseLicense(i);
287
287
  break;
288
288
  }
289
- case b.PARTICIPANT_STATE: {
289
+ case y.PARTICIPANT_STATE: {
290
290
  this.maybeTriggerParticipantMoveRequest(i);
291
291
  break;
292
292
  }
@@ -297,7 +297,7 @@ class Qe {
297
297
  inputChannels: t,
298
298
  outputChannels: s
299
299
  };
300
- this.events.trigger(l.CHANNELS_NOTIFY, i);
300
+ this.events.trigger(g.CHANNELS_NOTIFY, i);
301
301
  };
302
302
  triggerWebcastStartedNotify = ({
303
303
  body: { conference: e, type: t }
@@ -306,7 +306,7 @@ class Qe {
306
306
  conference: e,
307
307
  type: t
308
308
  };
309
- this.events.trigger(l.WEBCAST_STARTED, s);
309
+ this.events.trigger(g.WEBCAST_STARTED, s);
310
310
  };
311
311
  triggerWebcastStoppedNotify = ({
312
312
  body: { conference: e, type: t }
@@ -315,7 +315,7 @@ class Qe {
315
315
  conference: e,
316
316
  type: t
317
317
  };
318
- this.events.trigger(l.WEBCAST_STOPPED, s);
318
+ this.events.trigger(g.WEBCAST_STOPPED, s);
319
319
  };
320
320
  triggerAddedToListModeratorsNotify = ({
321
321
  conference: e
@@ -324,7 +324,7 @@ class Qe {
324
324
  conference: e
325
325
  };
326
326
  this.events.trigger(
327
- l.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
327
+ g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
328
328
  t
329
329
  );
330
330
  };
@@ -335,7 +335,7 @@ class Qe {
335
335
  conference: e
336
336
  };
337
337
  this.events.trigger(
338
- l.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
338
+ g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
339
339
  t
340
340
  );
341
341
  };
@@ -345,7 +345,7 @@ class Qe {
345
345
  const t = {
346
346
  conference: e
347
347
  };
348
- this.events.trigger(l.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
348
+ this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
349
349
  };
350
350
  triggerParticipationCancellingWordRequest = ({
351
351
  body: { conference: e }
@@ -353,7 +353,7 @@ class Qe {
353
353
  const t = {
354
354
  conference: e
355
355
  };
356
- this.events.trigger(l.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
356
+ this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
357
357
  };
358
358
  triggerParticipantMoveRequestToStream = ({
359
359
  body: { conference: e }
@@ -361,13 +361,13 @@ class Qe {
361
361
  const t = {
362
362
  conference: e
363
363
  };
364
- this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
364
+ this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
365
365
  };
366
366
  triggerAccountChangedNotify = () => {
367
- this.events.trigger(l.ACCOUNT_CHANGED, {});
367
+ this.events.trigger(g.ACCOUNT_CHANGED, {});
368
368
  };
369
369
  triggerAccountDeletedNotify = () => {
370
- this.events.trigger(l.ACCOUNT_DELETED, {});
370
+ this.events.trigger(g.ACCOUNT_DELETED, {});
371
371
  };
372
372
  triggerConferenceParticipantTokenIssued = ({
373
373
  body: { conference: e, participant: t, jwt: s }
@@ -378,79 +378,288 @@ class Qe {
378
378
  jwt: s
379
379
  };
380
380
  this.events.trigger(
381
- l.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
381
+ g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
382
382
  i
383
383
  );
384
384
  };
385
385
  maybeTriggerChannels = (e) => {
386
- const t = e.getHeader(u.INPUT_CHANNELS), s = e.getHeader(u.OUTPUT_CHANNELS);
386
+ const t = e.getHeader(E.INPUT_CHANNELS), s = e.getHeader(E.OUTPUT_CHANNELS);
387
387
  if (t && s) {
388
388
  const i = {
389
389
  inputChannels: t,
390
390
  outputChannels: s
391
391
  };
392
- this.events.trigger(l.CHANNELS, i);
392
+ this.events.trigger(g.CHANNELS, i);
393
393
  }
394
394
  };
395
395
  triggerEnterRoom = (e) => {
396
- const t = e.getHeader(u.CONTENT_ENTER_ROOM), s = e.getHeader(u.PARTICIPANT_NAME);
397
- this.events.trigger(l.ENTER_ROOM, { room: t, participantName: s });
396
+ const t = e.getHeader(E.CONTENT_ENTER_ROOM), s = e.getHeader(E.PARTICIPANT_NAME);
397
+ this.events.trigger(g.ENTER_ROOM, { room: t, participantName: s });
398
398
  };
399
399
  triggerShareState = (e) => {
400
- const t = e.getHeader(u.CONTENT_SHARE_STATE);
400
+ const t = e.getHeader(E.CONTENT_SHARE_STATE);
401
401
  if (t !== void 0)
402
402
  switch (t) {
403
- case F.AVAILABLE_SECOND_REMOTE_STREAM: {
404
- this.events.trigger(l.AVAILABLE_SECOND_REMOTE_STREAM, {});
403
+ case B.AVAILABLE_SECOND_REMOTE_STREAM: {
404
+ this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, {});
405
405
  break;
406
406
  }
407
- case F.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
408
- this.events.trigger(l.NOT_AVAILABLE_SECOND_REMOTE_STREAM, {});
407
+ case B.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
408
+ this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, {});
409
409
  break;
410
410
  }
411
- case F.MUST_STOP_PRESENTATION: {
412
- this.events.trigger(l.MUST_STOP_PRESENTATION, {});
411
+ case B.MUST_STOP_PRESENTATION: {
412
+ this.events.trigger(g.MUST_STOP_PRESENTATION, {});
413
413
  break;
414
414
  }
415
415
  }
416
416
  };
417
417
  maybeTriggerParticipantMoveRequest = (e) => {
418
- const t = e.getHeader(u.CONTENT_PARTICIPANT_STATE), s = e.getHeader(u.AUDIO_ID);
419
- t === H.SPECTATOR && (s ? (this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID, {
418
+ const t = e.getHeader(E.CONTENT_PARTICIPANT_STATE), s = e.getHeader(E.AUDIO_ID);
419
+ t === x.SPECTATOR && (s ? (this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID, {
420
420
  audioId: s
421
- }), this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, {
421
+ }), this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, {
422
422
  isSynthetic: !1,
423
423
  audioId: s
424
- })) : (this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_SYNTHETIC, {}), this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, { isSynthetic: !0 }))), t === H.PARTICIPANT && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
424
+ })) : (this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_SYNTHETIC, {}), this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, { isSynthetic: !0 }))), t === x.PARTICIPANT && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
425
425
  };
426
426
  triggerMainCamControl = (e) => {
427
- const t = e.getHeader(u.MAIN_CAM), s = e.getHeader(u.MEDIA_SYNC), i = s === G.ADMIN_SYNC_FORCED;
428
- if (t === _.ADMIN_START_MAIN_CAM) {
429
- this.events.trigger(l.ADMIN_START_MAIN_CAM, { isSyncForced: i });
427
+ const t = e.getHeader(E.MAIN_CAM), s = e.getHeader(E.MEDIA_SYNC), i = s === Y.ADMIN_SYNC_FORCED;
428
+ if (t === v.ADMIN_START_MAIN_CAM) {
429
+ this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: i });
430
430
  return;
431
431
  }
432
- if (t === _.ADMIN_STOP_MAIN_CAM) {
433
- this.events.trigger(l.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
432
+ if (t === v.ADMIN_STOP_MAIN_CAM) {
433
+ this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
434
434
  return;
435
435
  }
436
- (t === _.RESUME_MAIN_CAM || t === _.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(l.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
437
- const r = e.getHeader(u.MAIN_CAM_RESOLUTION);
438
- this.events.trigger(l.MAIN_CAM_CONTROL, {
436
+ (t === v.RESUME_MAIN_CAM || t === v.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(g.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
437
+ const r = e.getHeader(E.MAIN_CAM_RESOLUTION);
438
+ this.events.trigger(g.MAIN_CAM_CONTROL, {
439
439
  mainCam: t,
440
440
  resolutionMainCam: r
441
441
  });
442
442
  };
443
443
  triggerMicControl = (e) => {
444
- const t = e.getHeader(u.MIC), i = e.getHeader(u.MEDIA_SYNC) === G.ADMIN_SYNC_FORCED;
445
- t === W.ADMIN_START_MIC ? this.events.trigger(l.ADMIN_START_MIC, { isSyncForced: i }) : t === W.ADMIN_STOP_MIC && this.events.trigger(l.ADMIN_STOP_MIC, { isSyncForced: i });
444
+ const t = e.getHeader(E.MIC), i = e.getHeader(E.MEDIA_SYNC) === Y.ADMIN_SYNC_FORCED;
445
+ t === Q.ADMIN_START_MIC ? this.events.trigger(g.ADMIN_START_MIC, { isSyncForced: i }) : t === Q.ADMIN_STOP_MIC && this.events.trigger(g.ADMIN_STOP_MIC, { isSyncForced: i });
446
446
  };
447
447
  triggerUseLicense = (e) => {
448
- const t = e.getHeader(u.CONTENT_USE_LICENSE);
449
- this.events.trigger(l.USE_LICENSE, t);
448
+ const t = e.getHeader(E.CONTENT_USE_LICENSE);
449
+ this.events.trigger(g.USE_LICENSE, t);
450
450
  };
451
451
  }
452
- var R = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n.CALL_STATUS_CHANGED = "call-status-changed", n.REMOTE_STREAMS_CHANGED = "remote-streams-changed", n))(R || {}), Ye = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(Ye || {});
453
- const oe = [
452
+ class q {
453
+ actor;
454
+ subscriptions = [];
455
+ constructor(e) {
456
+ this.actor = $e(e), this.actor.start();
457
+ }
458
+ get actorRef() {
459
+ return this.actor;
460
+ }
461
+ get state() {
462
+ return this.getSnapshot().value;
463
+ }
464
+ send(e) {
465
+ this.actor.send(e);
466
+ }
467
+ getSnapshot() {
468
+ return this.actor.getSnapshot();
469
+ }
470
+ subscribe(e) {
471
+ const t = this.actor.subscribe(e);
472
+ return this.addSubscription(t), t;
473
+ }
474
+ stop() {
475
+ this.subscriptions.forEach((e) => {
476
+ e();
477
+ }), this.subscriptions.length = 0, this.actor.stop();
478
+ }
479
+ addSubscription(e) {
480
+ const t = typeof e == "function" ? e : () => {
481
+ e.unsubscribe();
482
+ };
483
+ return this.subscriptions.push(t), t;
484
+ }
485
+ }
486
+ var Je = /* @__PURE__ */ ((n) => (n.IDLE = "call:idle", n.CONNECTING = "call:connecting", n.RINGING = "call:ringing", n.ACCEPTED = "call:accepted", n.IN_CALL = "call:inCall", n.ENDED = "call:ended", n.FAILED = "call:failed", n))(Je || {});
487
+ const Ke = $({
488
+ types: {
489
+ context: {},
490
+ events: {}
491
+ },
492
+ actions: {
493
+ rememberError: b(({ event: n }) => "error" in n && n.error !== void 0 ? {
494
+ lastError: n.error instanceof Error ? n.error : new Error(JSON.stringify(n.error))
495
+ } : { lastError: void 0 }),
496
+ resetError: b({ lastError: void 0 })
497
+ }
498
+ }).createMachine({
499
+ id: "call",
500
+ initial: "call:idle",
501
+ context: {},
502
+ states: {
503
+ "call:idle": {
504
+ on: {
505
+ "CALL.CONNECTING": {
506
+ target: "call:connecting",
507
+ actions: "resetError"
508
+ },
509
+ "CALL.RINGING": {
510
+ target: "call:ringing",
511
+ actions: "resetError"
512
+ }
513
+ }
514
+ },
515
+ "call:connecting": {
516
+ on: {
517
+ "CALL.RINGING": "call:ringing",
518
+ "CALL.ACCEPTED": "call:accepted",
519
+ "CALL.CONFIRMED": "call:inCall",
520
+ "CALL.ENDED": "call:ended",
521
+ "CALL.FAILED": {
522
+ target: "call:failed",
523
+ actions: "rememberError"
524
+ }
525
+ }
526
+ },
527
+ "call:ringing": {
528
+ on: {
529
+ "CALL.ACCEPTED": "call:accepted",
530
+ "CALL.CONFIRMED": "call:inCall",
531
+ "CALL.ENDED": "call:ended",
532
+ "CALL.FAILED": {
533
+ target: "call:failed",
534
+ actions: "rememberError"
535
+ }
536
+ }
537
+ },
538
+ "call:accepted": {
539
+ on: {
540
+ "CALL.CONFIRMED": "call:inCall",
541
+ "CALL.ENDED": "call:ended",
542
+ "CALL.FAILED": {
543
+ target: "call:failed",
544
+ actions: "rememberError"
545
+ }
546
+ }
547
+ },
548
+ "call:inCall": {
549
+ on: {
550
+ "CALL.ENDED": "call:ended",
551
+ "CALL.FAILED": {
552
+ target: "call:failed",
553
+ actions: "rememberError"
554
+ }
555
+ }
556
+ },
557
+ "call:ended": {
558
+ on: {
559
+ "CALL.RESET": {
560
+ target: "call:idle",
561
+ actions: "resetError"
562
+ },
563
+ "CALL.CONNECTING": {
564
+ target: "call:connecting",
565
+ actions: "resetError"
566
+ }
567
+ }
568
+ },
569
+ "call:failed": {
570
+ on: {
571
+ "CALL.RESET": {
572
+ target: "call:idle",
573
+ actions: "resetError"
574
+ },
575
+ "CALL.CONNECTING": {
576
+ target: "call:connecting",
577
+ actions: "resetError"
578
+ },
579
+ "CALL.ENDED": {
580
+ target: "call:ended",
581
+ actions: "resetError"
582
+ }
583
+ }
584
+ }
585
+ }
586
+ });
587
+ class je extends q {
588
+ constructor(e) {
589
+ super(Ke), this.subscribeToEvents(e);
590
+ }
591
+ get isIdle() {
592
+ return this.state === "call:idle";
593
+ }
594
+ get isConnecting() {
595
+ return this.state === "call:connecting";
596
+ }
597
+ get isRinging() {
598
+ return this.state === "call:ringing";
599
+ }
600
+ get isAccepted() {
601
+ return this.state === "call:accepted";
602
+ }
603
+ get isInCall() {
604
+ return this.state === "call:inCall";
605
+ }
606
+ get isEnded() {
607
+ return this.state === "call:ended";
608
+ }
609
+ get isFailed() {
610
+ return this.state === "call:failed";
611
+ }
612
+ get isActive() {
613
+ return this.isAccepted || this.isInCall;
614
+ }
615
+ get isPending() {
616
+ return this.isConnecting || this.isRinging;
617
+ }
618
+ get lastError() {
619
+ return this.getSnapshot().context.lastError;
620
+ }
621
+ reset() {
622
+ this.send({ type: "CALL.RESET" });
623
+ }
624
+ send(e) {
625
+ if (!this.getSnapshot().can(e)) {
626
+ console.warn(
627
+ `[CallStateMachine] Invalid transition: ${e.type} from ${this.state}. Event cannot be processed in current state.`
628
+ );
629
+ return;
630
+ }
631
+ super.send(e);
632
+ }
633
+ subscribeToEvents(e) {
634
+ this.addSubscription(
635
+ e.on("connecting", () => {
636
+ this.send({ type: "CALL.CONNECTING" });
637
+ })
638
+ ), this.addSubscription(
639
+ e.on("progress", () => {
640
+ this.send({ type: "CALL.RINGING" });
641
+ })
642
+ ), this.addSubscription(
643
+ e.on("accepted", () => {
644
+ this.send({ type: "CALL.ACCEPTED" });
645
+ })
646
+ ), this.addSubscription(
647
+ e.on("confirmed", () => {
648
+ this.send({ type: "CALL.CONFIRMED" });
649
+ })
650
+ ), this.addSubscription(
651
+ e.on("ended", () => {
652
+ this.send({ type: "CALL.ENDED" });
653
+ })
654
+ ), this.addSubscription(
655
+ e.on("failed", (t) => {
656
+ this.send({ type: "CALL.FAILED", error: t });
657
+ })
658
+ );
659
+ }
660
+ }
661
+ var C = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n.CALL_STATUS_CHANGED = "call-status-changed", n.REMOTE_STREAMS_CHANGED = "remote-streams-changed", n))(C || {}), Ze = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(Ze || {});
662
+ const he = [
454
663
  "peerconnection",
455
664
  "connecting",
456
665
  "sending",
@@ -477,37 +686,37 @@ const oe = [
477
686
  "peerconnection:createanswerfailed",
478
687
  "peerconnection:setlocaldescriptionfailed",
479
688
  "peerconnection:setremotedescriptionfailed"
480
- ], ze = [
689
+ ], et = [
481
690
  "peerconnection:confirmed",
482
691
  "peerconnection:ontrack",
483
692
  "ended:fromserver",
484
693
  "call-status-changed",
485
694
  "remote-streams-changed"
486
- ], ce = [
487
- ...oe,
488
- ...ze
489
- ], Xe = () => new M(ce), Je = (n, e) => {
695
+ ], ge = [
696
+ ...he,
697
+ ...et
698
+ ], tt = () => new O(ge), nt = (n, e) => {
490
699
  n.getVideoTracks().forEach((s) => {
491
700
  "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
492
701
  });
493
- }, B = (n, {
702
+ }, k = (n, {
494
703
  directionVideo: e,
495
704
  directionAudio: t,
496
705
  contentHint: s
497
706
  } = {}) => {
498
707
  if (!n || e === "recvonly" && t === "recvonly")
499
708
  return;
500
- const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
501
- return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && Je(o, s), o;
709
+ const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), o = [...i, ...r], a = new MediaStream(o);
710
+ return a.getTracks = () => [...a.getAudioTracks(), ...a.getVideoTracks()], s && s !== "none" && nt(a, s), a;
502
711
  };
503
- var he = /* @__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))(he || {});
504
- class Ke {
712
+ var ue = /* @__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))(ue || {});
713
+ class st {
505
714
  events;
506
715
  rtcSession;
507
716
  disposers = /* @__PURE__ */ new Set();
508
717
  onReset;
509
718
  constructor(e, { onReset: t }) {
510
- this.events = e, this.onReset = t, e.on(R.FAILED, this.handleEnded), e.on(R.ENDED, this.handleEnded);
719
+ this.events = e, this.onReset = t, e.on(C.FAILED, this.handleEnded), e.on(C.ENDED, this.handleEnded);
511
720
  }
512
721
  get connection() {
513
722
  return this.rtcSession?.connection;
@@ -525,48 +734,48 @@ class Ke {
525
734
  number: s,
526
735
  mediaStream: i,
527
736
  extraHeaders: r = [],
528
- iceServers: a,
529
- directionVideo: o,
737
+ iceServers: o,
738
+ directionVideo: a,
530
739
  directionAudio: c,
531
740
  contentHint: d,
532
- offerToReceiveAudio: S = !0,
533
- offerToReceiveVideo: g = !0,
534
- degradationPreference: T,
741
+ offerToReceiveAudio: T = !0,
742
+ offerToReceiveVideo: h = !0,
743
+ degradationPreference: u,
535
744
  sendEncodings: p,
536
- onAddedTransceiver: P
537
- }) => new Promise((A, y) => {
538
- this.handleCall().then(A).catch(($) => {
539
- y($);
745
+ onAddedTransceiver: A
746
+ }) => new Promise((N, D) => {
747
+ this.handleCall().then(N).catch((V) => {
748
+ D(V);
540
749
  }), this.rtcSession = e.call(t(s), {
541
- mediaStream: B(i, {
542
- directionVideo: o,
750
+ mediaStream: k(i, {
751
+ directionVideo: a,
543
752
  directionAudio: c,
544
753
  contentHint: d
545
754
  }),
546
755
  pcConfig: {
547
- iceServers: a
756
+ iceServers: o
548
757
  },
549
758
  rtcOfferConstraints: {
550
- offerToReceiveAudio: S,
551
- offerToReceiveVideo: g
759
+ offerToReceiveAudio: T,
760
+ offerToReceiveVideo: h
552
761
  },
553
762
  // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
554
763
  // так как в методе call создается RTCSession
555
764
  // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
556
765
  eventHandlers: this.events.triggers,
557
766
  extraHeaders: r,
558
- directionVideo: o,
767
+ directionVideo: a,
559
768
  directionAudio: c,
560
- degradationPreference: T,
769
+ degradationPreference: u,
561
770
  sendEncodings: p,
562
- onAddedTransceiver: P
771
+ onAddedTransceiver: A
563
772
  });
564
773
  });
565
774
  async endCall() {
566
775
  const { rtcSession: e } = this;
567
776
  if (e && !e.isEnded())
568
777
  return e.terminateAsync({
569
- cause: he.CANCELED
778
+ cause: ue.CANCELED
570
779
  }).finally(() => {
571
780
  this.reset();
572
781
  });
@@ -577,45 +786,45 @@ class Ke {
577
786
  extraHeaders: s = [],
578
787
  iceServers: i,
579
788
  directionVideo: r,
580
- directionAudio: a,
581
- offerToReceiveAudio: o,
789
+ directionAudio: o,
790
+ offerToReceiveAudio: a,
582
791
  offerToReceiveVideo: c,
583
792
  contentHint: d,
584
- degradationPreference: S,
585
- sendEncodings: g,
586
- onAddedTransceiver: T
587
- }) => new Promise((p, P) => {
793
+ degradationPreference: T,
794
+ sendEncodings: h,
795
+ onAddedTransceiver: u
796
+ }) => new Promise((p, A) => {
588
797
  try {
589
- this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall().then(p).catch((A) => {
590
- P(A);
798
+ this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall().then(p).catch((N) => {
799
+ A(N);
591
800
  }), e.answer({
592
801
  pcConfig: {
593
802
  iceServers: i
594
803
  },
595
804
  rtcOfferConstraints: {
596
- offerToReceiveAudio: o,
805
+ offerToReceiveAudio: a,
597
806
  offerToReceiveVideo: c
598
807
  },
599
- mediaStream: B(t, {
808
+ mediaStream: k(t, {
600
809
  directionVideo: r,
601
- directionAudio: a,
810
+ directionAudio: o,
602
811
  contentHint: d
603
812
  }),
604
813
  extraHeaders: s,
605
814
  directionVideo: r,
606
- directionAudio: a,
607
- degradationPreference: S,
608
- sendEncodings: g,
609
- onAddedTransceiver: T
815
+ directionAudio: o,
816
+ degradationPreference: T,
817
+ sendEncodings: h,
818
+ onAddedTransceiver: u
610
819
  });
611
- } catch (A) {
612
- P(A);
820
+ } catch (N) {
821
+ A(N);
613
822
  }
614
823
  });
615
824
  async replaceMediaStream(e, t) {
616
825
  if (!this.rtcSession)
617
826
  throw new Error("No rtcSession established");
618
- const { contentHint: s } = t ?? {}, i = B(e, { contentHint: s });
827
+ const { contentHint: s } = t ?? {}, i = k(e, { contentHint: s });
619
828
  if (i === void 0)
620
829
  throw new Error("No preparedMediaStream");
621
830
  return this.rtcSession.replaceMediaStream(i, t);
@@ -627,33 +836,33 @@ class Ke {
627
836
  }
628
837
  handleCall = async () => new Promise((e, t) => {
629
838
  const s = () => {
630
- this.events.on(R.PEER_CONNECTION, d), this.events.on(R.CONFIRMED, S);
839
+ this.events.on(C.PEER_CONNECTION, d), this.events.on(C.CONFIRMED, T);
631
840
  }, i = () => {
632
- this.events.off(R.PEER_CONNECTION, d), this.events.off(R.CONFIRMED, S);
841
+ this.events.off(C.PEER_CONNECTION, d), this.events.off(C.CONFIRMED, T);
633
842
  }, r = () => {
634
- this.events.on(R.FAILED, o), this.events.on(R.ENDED, o);
635
- }, a = () => {
636
- this.events.off(R.FAILED, o), this.events.off(R.ENDED, o);
637
- }, o = (g) => {
638
- i(), a(), t(g);
843
+ this.events.on(C.FAILED, a), this.events.on(C.ENDED, a);
844
+ }, o = () => {
845
+ this.events.off(C.FAILED, a), this.events.off(C.ENDED, a);
846
+ }, a = (h) => {
847
+ i(), o(), t(h);
639
848
  };
640
849
  let c;
641
- const d = ({ peerconnection: g }) => {
642
- c = g;
643
- const T = (p) => {
644
- this.events.trigger(R.PEER_CONNECTION_ONTRACK, p);
850
+ const d = ({ peerconnection: h }) => {
851
+ c = h;
852
+ const u = (p) => {
853
+ this.events.trigger(C.PEER_CONNECTION_ONTRACK, p);
645
854
  };
646
- g.addEventListener("track", T), this.disposers.add(() => {
647
- g.removeEventListener("track", T);
855
+ h.addEventListener("track", u), this.disposers.add(() => {
856
+ h.removeEventListener("track", u);
648
857
  });
649
- }, S = () => {
650
- c !== void 0 && this.events.trigger(R.PEER_CONNECTION_CONFIRMED, c), i(), a(), e(c);
858
+ }, T = () => {
859
+ c !== void 0 && this.events.trigger(C.PEER_CONNECTION_CONFIRMED, c), i(), o(), e(c);
651
860
  };
652
861
  s(), r();
653
862
  });
654
863
  subscribeToSessionEvents(e) {
655
864
  this.events.eachTriggers((t, s) => {
656
- const i = oe.find((r) => r === s);
865
+ const i = he.find((r) => r === s);
657
866
  i && (e.on(i, t), this.disposers.add(() => {
658
867
  e.off(i, t);
659
868
  }));
@@ -666,13 +875,13 @@ class Ke {
666
875
  }
667
876
  handleEnded = (e) => {
668
877
  const { originator: t } = e;
669
- t === "remote" && this.events.trigger(R.ENDED_FROM_SERVER, e), this.reset();
878
+ t === "remote" && this.events.trigger(C.ENDED_FROM_SERVER, e), this.reset();
670
879
  };
671
880
  reset = () => {
672
881
  delete this.rtcSession, this.unsubscribeFromSessionEvents(), this.onReset();
673
882
  };
674
883
  }
675
- class je {
884
+ class it {
676
885
  config;
677
886
  tools;
678
887
  connection;
@@ -721,18 +930,18 @@ class je {
721
930
  return this.connection.addTransceiver(e, t);
722
931
  }
723
932
  }
724
- const de = (n) => n.getSettings(), Ze = (n, e) => {
725
- const t = de(n);
933
+ const Te = (n) => n.getSettings(), rt = (n, e) => {
934
+ const t = Te(n);
726
935
  let s = e;
727
936
  s ??= n.label;
728
937
  let i = t?.msid;
729
938
  return i ??= s, i ??= n.id, i;
730
- }, et = (n, e) => {
731
- const t = de(n);
939
+ }, at = (n, e) => {
940
+ const t = Te(n);
732
941
  let s = e;
733
942
  return s ??= t?.msid, s ??= n.label, (s && s.length > 0 ? s : void 0) ?? n.id;
734
943
  };
735
- class X {
944
+ class j {
736
945
  participantGroups = /* @__PURE__ */ new Map();
737
946
  trackToGroup = /* @__PURE__ */ new Map();
738
947
  trackDisposers = /* @__PURE__ */ new Map();
@@ -749,17 +958,17 @@ class X {
749
958
  onRemoved: t,
750
959
  streamHint: s
751
960
  } = {}) {
752
- const i = et(e, s), r = Ze(e, s);
961
+ const i = at(e, s), r = rt(e, s);
753
962
  if (this.trackToGroup.has(e.id))
754
963
  return { isAdded: !1 };
755
- const a = this.getParticipantGroups(i);
756
- let o = a.get(r);
757
- o || (o = {
964
+ const o = this.getParticipantGroups(i);
965
+ let a = o.get(r);
966
+ a || (a = {
758
967
  participantId: i,
759
968
  groupId: r,
760
969
  stream: new MediaStream(),
761
970
  trackIds: /* @__PURE__ */ new Set()
762
- }, a.set(r, o)), o.stream.addTrack(e), o.trackIds.add(e.id), this.trackToGroup.set(e.id, { participantId: i, groupId: r });
971
+ }, o.set(r, a)), a.stream.addTrack(e), a.trackIds.add(e.id), this.trackToGroup.set(e.id, { participantId: i, groupId: r });
763
972
  const c = () => {
764
973
  this.disposeTrackListener(e.id), this.removeTrack(e.id) && t?.({ trackId: e.id, participantId: i });
765
974
  };
@@ -772,19 +981,19 @@ class X {
772
981
  const t = this.trackToGroup.get(e);
773
982
  if (!t)
774
983
  return !1;
775
- const { participantId: s, groupId: i } = t, r = this.participantGroups.get(s), a = r?.get(i);
776
- if (!a)
984
+ const { participantId: s, groupId: i } = t, r = this.participantGroups.get(s), o = r?.get(i);
985
+ if (!o)
777
986
  return this.trackToGroup.delete(e), !1;
778
- const o = a.stream.getTracks().find((c) => c.id === e);
779
- return o && a.stream.removeTrack(o), a.trackIds.delete(e), this.trackToGroup.delete(e), a.trackIds.size === 0 && (r?.delete(i), r?.size === 0 && this.participantGroups.delete(s)), !0;
987
+ const a = o.stream.getTracks().find((c) => c.id === e);
988
+ return a && o.stream.removeTrack(a), o.trackIds.delete(e), this.trackToGroup.delete(e), o.trackIds.size === 0 && (r?.delete(i), r?.size === 0 && this.participantGroups.delete(s)), !0;
780
989
  }
781
990
  removeStaleTracks(e, t) {
782
991
  const s = this.participantGroups.get(e);
783
992
  if (!s)
784
993
  return !1;
785
994
  let i = !1;
786
- return [...s.values()].forEach((a) => {
787
- [...a.trackIds].filter((c) => !t.includes(c)).forEach((c) => {
995
+ return [...s.values()].forEach((o) => {
996
+ [...o.trackIds].filter((c) => !t.includes(c)).forEach((c) => {
788
997
  const d = this.removeTrack(c);
789
998
  i ||= d;
790
999
  });
@@ -809,16 +1018,16 @@ class X {
809
1018
  return this.participantGroups.set(e, s), s;
810
1019
  }
811
1020
  }
812
- const q = {
1021
+ const H = {
813
1022
  type: "participant"
814
- }, tt = {
1023
+ }, ot = {
815
1024
  type: "spectator_synthetic"
816
- }, nt = (n) => ({
1025
+ }, ct = (n) => ({
817
1026
  type: "spectator",
818
1027
  recvParams: n
819
1028
  });
820
- class f {
821
- role = q;
1029
+ class _ {
1030
+ role = H;
822
1031
  mainManager;
823
1032
  recvManager;
824
1033
  onRoleChanged;
@@ -841,13 +1050,13 @@ class f {
841
1050
  return this.role;
842
1051
  }
843
1052
  setCallRoleParticipant() {
844
- this.changeRole(q);
1053
+ this.changeRole(H);
845
1054
  }
846
1055
  setCallRoleSpectatorSynthetic() {
847
- this.changeRole(tt);
1056
+ this.changeRole(ot);
848
1057
  }
849
1058
  setCallRoleSpectator(e) {
850
- this.changeRole(nt(e));
1059
+ this.changeRole(ct(e));
851
1060
  }
852
1061
  changeRole(e) {
853
1062
  const t = this.role;
@@ -855,38 +1064,39 @@ class f {
855
1064
  this.setRole(e);
856
1065
  return;
857
1066
  }
858
- f.hasSpectator(e) && f.hasSpectator(t) && t.recvParams.audioId !== e.recvParams.audioId && this.setRole(e);
1067
+ _.hasSpectator(e) && _.hasSpectator(t) && t.recvParams.audioId !== e.recvParams.audioId && this.setRole(e);
859
1068
  }
860
1069
  reset() {
861
- this.role = q, this.recvManager.reset();
1070
+ this.role = H, this.recvManager.reset();
862
1071
  }
863
1072
  getActiveManager() {
864
1073
  return this.hasSpectator() ? this.recvManager : this.mainManager;
865
1074
  }
866
1075
  hasParticipant() {
867
- return f.hasParticipant(this.role);
1076
+ return _.hasParticipant(this.role);
868
1077
  }
869
1078
  hasSpectatorSynthetic() {
870
- return f.hasSpectatorSynthetic(this.role);
1079
+ return _.hasSpectatorSynthetic(this.role);
871
1080
  }
872
1081
  hasSpectator() {
873
- return f.hasSpectator(this.role);
1082
+ return _.hasSpectator(this.role);
874
1083
  }
875
1084
  setRole(e) {
876
1085
  const t = this.role;
877
1086
  this.role = e, this.onRoleChanged?.({ previous: t, next: e });
878
1087
  }
879
1088
  }
880
- const J = (n) => n.streams[0]?.id;
881
- class st {
1089
+ const Z = (n) => n.streams[0]?.id;
1090
+ class lt {
882
1091
  events;
1092
+ callStateMachine;
883
1093
  isPendingCall = !1;
884
1094
  isPendingAnswer = !1;
885
1095
  rtcSession;
886
1096
  callConfiguration = {};
887
- mainRemoteStreamsManager = new X();
888
- recvRemoteStreamsManager = new X();
889
- roleManager = new f(
1097
+ mainRemoteStreamsManager = new j();
1098
+ recvRemoteStreamsManager = new j();
1099
+ roleManager = new _(
890
1100
  { mainManager: this.mainRemoteStreamsManager, recvManager: this.recvRemoteStreamsManager },
891
1101
  (e) => {
892
1102
  this.onRoleChanged(e);
@@ -896,7 +1106,10 @@ class st {
896
1106
  recvSession;
897
1107
  disposeRecvSessionTrackListener;
898
1108
  constructor() {
899
- this.events = Xe(), this.mcuSession = new Ke(this.events, { onReset: this.reset }), this.subscribeCallStatusChange(), this.subscribeMcuRemoteTrackEvents();
1109
+ this.events = tt(), this.mcuSession = new st(this.events, { onReset: this.reset }), this.callStateMachine = new je(this.events), this.subscribeCallStatusChange(), this.subscribeMcuRemoteTrackEvents();
1110
+ }
1111
+ get callActor() {
1112
+ return this.callStateMachine.actorRef;
900
1113
  }
901
1114
  get requested() {
902
1115
  return this.isPendingCall || this.isPendingAnswer;
@@ -971,18 +1184,18 @@ class st {
971
1184
  };
972
1185
  subscribeCallStatusChange() {
973
1186
  let { isCallActive: e } = this;
974
- const { ACCEPTED: t, CONFIRMED: s, ENDED: i, FAILED: r } = R;
1187
+ const { ACCEPTED: t, CONFIRMED: s, ENDED: i, FAILED: r } = C;
975
1188
  this.onRace([t, s, i, r], () => {
976
1189
  e = this.maybeTriggerCallStatus(e);
977
1190
  });
978
1191
  }
979
1192
  maybeTriggerCallStatus(e) {
980
1193
  const t = this.isCallActive;
981
- return t !== e && this.events.trigger(R.CALL_STATUS_CHANGED, { isCallActive: t }), t;
1194
+ return t !== e && this.events.trigger(C.CALL_STATUS_CHANGED, { isCallActive: t }), t;
982
1195
  }
983
1196
  subscribeMcuRemoteTrackEvents() {
984
- this.on(R.PEER_CONNECTION_ONTRACK, (e) => {
985
- this.addRemoteTrack(this.mainRemoteStreamsManager, e.track, J(e));
1197
+ this.on(C.PEER_CONNECTION_ONTRACK, (e) => {
1198
+ this.addRemoteTrack(this.mainRemoteStreamsManager, e.track, Z(e));
986
1199
  });
987
1200
  }
988
1201
  addRemoteTrack(e, t, s) {
@@ -1004,12 +1217,12 @@ class st {
1004
1217
  const r = this.getActiveStreamsManager();
1005
1218
  if (e !== r)
1006
1219
  return;
1007
- const a = [...r.getStreams()];
1008
- this.events.trigger(R.REMOTE_STREAMS_CHANGED, {
1220
+ const o = [...r.getStreams()];
1221
+ this.events.trigger(C.REMOTE_STREAMS_CHANGED, {
1009
1222
  participantId: i,
1010
1223
  changeType: t,
1011
1224
  trackId: s,
1012
- streams: a
1225
+ streams: o
1013
1226
  });
1014
1227
  }
1015
1228
  getActiveStreamsManager() {
@@ -1017,7 +1230,7 @@ class st {
1017
1230
  }
1018
1231
  attachRecvSessionTracks(e) {
1019
1232
  const { peerConnection: t } = e, s = (i) => {
1020
- this.addRemoteTrack(this.recvRemoteStreamsManager, i.track, J(i));
1233
+ this.addRemoteTrack(this.recvRemoteStreamsManager, i.track, Z(i));
1021
1234
  };
1022
1235
  t.addEventListener("track", s), this.disposeRecvSessionTrackListener = () => {
1023
1236
  t.removeEventListener("track", s);
@@ -1031,7 +1244,7 @@ class st {
1031
1244
  const i = {
1032
1245
  quality: "high",
1033
1246
  audioChannel: e
1034
- }, r = new je(i, { sendOffer: t });
1247
+ }, r = new it(i, { sendOffer: t });
1035
1248
  this.recvSession = r, this.recvRemoteStreamsManager.reset(), this.attachRecvSessionTracks(r), r.call(s).catch(() => {
1036
1249
  this.stopRecvSession();
1037
1250
  });
@@ -1043,45 +1256,45 @@ class st {
1043
1256
  previous: e,
1044
1257
  next: t
1045
1258
  }) => {
1046
- if (f.hasSpectator(e) && !f.hasSpectator(t) && this.stopRecvSession(), f.hasSpectator(t)) {
1259
+ if (_.hasSpectator(e) && !_.hasSpectator(t) && this.stopRecvSession(), _.hasSpectator(t)) {
1047
1260
  const s = t.recvParams;
1048
1261
  this.startRecvSession(s.audioId, s.sendOffer);
1049
1262
  }
1050
1263
  };
1051
1264
  }
1052
- const it = (n, e) => (n.degradationPreference = e.degradationPreference, n), rt = (n, e) => {
1265
+ const dt = (n, e) => (n.degradationPreference = e.degradationPreference, n), ht = (n, e) => {
1053
1266
  n.encodings ??= [];
1054
1267
  for (let t = n.encodings.length; t < e; t += 1)
1055
1268
  n.encodings.push({});
1056
1269
  return n;
1057
- }, le = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, at = le(), ot = (n, e) => {
1058
- if (at(n, e))
1270
+ }, Ee = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, gt = Ee(), ut = (n, e) => {
1271
+ if (gt(n, e))
1059
1272
  return n;
1060
- }, ct = (n, e) => {
1061
- const t = n.maxBitrate, s = ot(e, t);
1273
+ }, Tt = (n, e) => {
1274
+ const t = n.maxBitrate, s = ut(e, t);
1062
1275
  return s !== void 0 && (n.maxBitrate = s), n;
1063
- }, ue = 1, ht = le(
1064
- ue
1065
- ), dt = (n, e) => {
1066
- const t = n === void 0 ? void 0 : Math.max(n, ue);
1067
- if (t !== void 0 && ht(
1276
+ }, Ce = 1, Et = Ee(
1277
+ Ce
1278
+ ), Ct = (n, e) => {
1279
+ const t = n === void 0 ? void 0 : Math.max(n, Ce);
1280
+ if (t !== void 0 && Et(
1068
1281
  t,
1069
1282
  e
1070
1283
  ))
1071
1284
  return t;
1072
- }, lt = (n, e) => {
1073
- const t = n.scaleResolutionDownBy, s = dt(
1285
+ }, St = (n, e) => {
1286
+ const t = n.scaleResolutionDownBy, s = Ct(
1074
1287
  e,
1075
1288
  t
1076
1289
  );
1077
1290
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
1078
- }, ut = (n, e) => {
1291
+ }, pt = (n, e) => {
1079
1292
  const t = e.encodings?.length ?? 0;
1080
- return rt(n, t), n.encodings.forEach((s, i) => {
1081
- const r = (e?.encodings ?? [])[i], a = r?.maxBitrate, o = r?.scaleResolutionDownBy;
1082
- ct(s, a), lt(s, o);
1293
+ return ht(n, t), n.encodings.forEach((s, i) => {
1294
+ const r = (e?.encodings ?? [])[i], o = r?.maxBitrate, a = r?.scaleResolutionDownBy;
1295
+ Tt(s, o), St(s, a);
1083
1296
  }), n;
1084
- }, gt = (n, e) => {
1297
+ }, mt = (n, e) => {
1085
1298
  if (n.codecs?.length !== e.codecs?.length)
1086
1299
  return !0;
1087
1300
  for (let t = 0; t < (n.codecs?.length ?? 0); t++)
@@ -1098,15 +1311,15 @@ const it = (n, e) => (n.degradationPreference = e.degradationPreference, n), rt
1098
1311
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
1099
1312
  return !0;
1100
1313
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
1101
- }, Tt = async (n, e) => {
1314
+ }, Nt = async (n, e) => {
1102
1315
  const t = n.getParameters(), s = JSON.parse(
1103
1316
  JSON.stringify(t)
1104
1317
  );
1105
- ut(t, e), it(t, e);
1106
- const i = gt(s, t);
1318
+ pt(t, e), dt(t, e);
1319
+ const i = mt(s, t);
1107
1320
  return i && await n.setParameters(t), { parameters: t, isChanged: i };
1108
- }, ge = async (n, e, t) => {
1109
- const { isChanged: s, parameters: i } = await Tt(n, {
1321
+ }, Se = async (n, e, t) => {
1322
+ const { isChanged: s, parameters: i } = await Nt(n, {
1110
1323
  encodings: [
1111
1324
  {
1112
1325
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -1115,21 +1328,421 @@ const it = (n, e) => (n.degradationPreference = e.degradationPreference, n), rt
1115
1328
  ]
1116
1329
  });
1117
1330
  return s && t && t(i), { isChanged: s, parameters: i };
1118
- }, St = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), Ct = async (n, e, t) => {
1119
- const s = St(n, e);
1331
+ }, Rt = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), At = async (n, e, t) => {
1332
+ const s = Rt(n, e);
1120
1333
  if (s)
1121
- return ge(s, { maxBitrate: t });
1334
+ return Se(s, { maxBitrate: t });
1122
1335
  };
1123
- var O = /* @__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))(O || {});
1124
- const Te = [
1336
+ 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 || {});
1337
+ const pe = [
1125
1338
  "presentation:start",
1126
1339
  "presentation:started",
1127
1340
  "presentation:end",
1128
1341
  "presentation:ended",
1129
1342
  "presentation:failed"
1130
- ], Et = () => new M(Te), pt = 1, ps = (n) => Le(n);
1131
- class Rt {
1343
+ ], It = () => new O(pe);
1344
+ var ft = /* @__PURE__ */ ((n) => (n.IDLE = "presentation:idle", n.STARTING = "presentation:starting", n.ACTIVE = "presentation:active", n.STOPPING = "presentation:stopping", n.FAILED = "presentation:failed", n))(ft || {});
1345
+ const Mt = $({
1346
+ types: {
1347
+ context: {},
1348
+ events: {}
1349
+ },
1350
+ actions: {
1351
+ logTransition: (n, e) => {
1352
+ l(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1353
+ },
1354
+ logStateChange: (n, e) => {
1355
+ l("PresentationStateMachine state changed", e.state);
1356
+ },
1357
+ setError: b(({ event: n }) => "error" in n && n.error !== void 0 ? {
1358
+ lastError: n.error instanceof Error ? n.error : new Error(JSON.stringify(n.error))
1359
+ } : { lastError: void 0 }),
1360
+ clearError: b({ lastError: void 0 })
1361
+ }
1362
+ }).createMachine({
1363
+ id: "presentation",
1364
+ initial: "presentation:idle",
1365
+ context: {},
1366
+ states: {
1367
+ "presentation:idle": {
1368
+ entry: {
1369
+ type: "logStateChange",
1370
+ params: {
1371
+ state: "presentation:idle"
1372
+ /* IDLE */
1373
+ }
1374
+ },
1375
+ on: {
1376
+ "SCREEN.STARTING": {
1377
+ target: "presentation:starting",
1378
+ actions: [
1379
+ "clearError",
1380
+ {
1381
+ type: "logTransition",
1382
+ params: {
1383
+ from: "presentation:idle",
1384
+ to: "presentation:starting",
1385
+ event: "SCREEN.STARTING"
1386
+ }
1387
+ }
1388
+ ]
1389
+ }
1390
+ }
1391
+ },
1392
+ "presentation:starting": {
1393
+ entry: {
1394
+ type: "logStateChange",
1395
+ params: {
1396
+ state: "presentation:starting"
1397
+ /* STARTING */
1398
+ }
1399
+ },
1400
+ on: {
1401
+ "SCREEN.STARTED": {
1402
+ target: "presentation:active",
1403
+ actions: {
1404
+ type: "logTransition",
1405
+ params: {
1406
+ from: "presentation:starting",
1407
+ to: "presentation:active",
1408
+ event: "SCREEN.STARTED"
1409
+ }
1410
+ }
1411
+ },
1412
+ "SCREEN.FAILED": {
1413
+ target: "presentation:failed",
1414
+ actions: [
1415
+ "setError",
1416
+ {
1417
+ type: "logTransition",
1418
+ params: {
1419
+ from: "presentation:starting",
1420
+ to: "presentation:failed",
1421
+ event: "SCREEN.FAILED"
1422
+ }
1423
+ }
1424
+ ]
1425
+ },
1426
+ "SCREEN.ENDED": {
1427
+ target: "presentation:idle",
1428
+ actions: [
1429
+ "clearError",
1430
+ {
1431
+ type: "logTransition",
1432
+ params: {
1433
+ from: "presentation:starting",
1434
+ to: "presentation:idle",
1435
+ event: "SCREEN.ENDED"
1436
+ }
1437
+ }
1438
+ ]
1439
+ },
1440
+ "CALL.ENDED": {
1441
+ target: "presentation:idle",
1442
+ actions: [
1443
+ "clearError",
1444
+ {
1445
+ type: "logTransition",
1446
+ params: {
1447
+ from: "presentation:starting",
1448
+ to: "presentation:idle",
1449
+ event: "CALL.ENDED"
1450
+ }
1451
+ }
1452
+ ]
1453
+ },
1454
+ "CALL.FAILED": {
1455
+ target: "presentation:failed",
1456
+ actions: [
1457
+ "setError",
1458
+ {
1459
+ type: "logTransition",
1460
+ params: {
1461
+ from: "presentation:starting",
1462
+ to: "presentation:failed",
1463
+ event: "CALL.FAILED"
1464
+ }
1465
+ }
1466
+ ]
1467
+ }
1468
+ }
1469
+ },
1470
+ "presentation:active": {
1471
+ entry: {
1472
+ type: "logStateChange",
1473
+ params: {
1474
+ state: "presentation:active"
1475
+ /* ACTIVE */
1476
+ }
1477
+ },
1478
+ on: {
1479
+ "SCREEN.ENDING": {
1480
+ target: "presentation:stopping",
1481
+ actions: {
1482
+ type: "logTransition",
1483
+ params: {
1484
+ from: "presentation:active",
1485
+ to: "presentation:stopping",
1486
+ event: "SCREEN.ENDING"
1487
+ }
1488
+ }
1489
+ },
1490
+ "SCREEN.ENDED": {
1491
+ target: "presentation:idle",
1492
+ actions: [
1493
+ "clearError",
1494
+ {
1495
+ type: "logTransition",
1496
+ params: {
1497
+ from: "presentation:active",
1498
+ to: "presentation:idle",
1499
+ event: "SCREEN.ENDED"
1500
+ }
1501
+ }
1502
+ ]
1503
+ },
1504
+ "SCREEN.FAILED": {
1505
+ target: "presentation:failed",
1506
+ actions: [
1507
+ "setError",
1508
+ {
1509
+ type: "logTransition",
1510
+ params: {
1511
+ from: "presentation:active",
1512
+ to: "presentation:failed",
1513
+ event: "SCREEN.FAILED"
1514
+ }
1515
+ }
1516
+ ]
1517
+ },
1518
+ "CALL.ENDED": {
1519
+ target: "presentation:idle",
1520
+ actions: [
1521
+ "clearError",
1522
+ {
1523
+ type: "logTransition",
1524
+ params: {
1525
+ from: "presentation:active",
1526
+ to: "presentation:idle",
1527
+ event: "CALL.ENDED"
1528
+ }
1529
+ }
1530
+ ]
1531
+ },
1532
+ "CALL.FAILED": {
1533
+ target: "presentation:failed",
1534
+ actions: [
1535
+ "setError",
1536
+ {
1537
+ type: "logTransition",
1538
+ params: {
1539
+ from: "presentation:active",
1540
+ to: "presentation:failed",
1541
+ event: "CALL.FAILED"
1542
+ }
1543
+ }
1544
+ ]
1545
+ }
1546
+ }
1547
+ },
1548
+ "presentation:stopping": {
1549
+ entry: {
1550
+ type: "logStateChange",
1551
+ params: {
1552
+ state: "presentation:stopping"
1553
+ /* STOPPING */
1554
+ }
1555
+ },
1556
+ on: {
1557
+ "SCREEN.ENDED": {
1558
+ target: "presentation:idle",
1559
+ actions: [
1560
+ "clearError",
1561
+ {
1562
+ type: "logTransition",
1563
+ params: {
1564
+ from: "presentation:stopping",
1565
+ to: "presentation:idle",
1566
+ event: "SCREEN.ENDED"
1567
+ }
1568
+ }
1569
+ ]
1570
+ },
1571
+ "SCREEN.FAILED": {
1572
+ target: "presentation:failed",
1573
+ actions: [
1574
+ "setError",
1575
+ {
1576
+ type: "logTransition",
1577
+ params: {
1578
+ from: "presentation:stopping",
1579
+ to: "presentation:failed",
1580
+ event: "SCREEN.FAILED"
1581
+ }
1582
+ }
1583
+ ]
1584
+ },
1585
+ "CALL.ENDED": {
1586
+ target: "presentation:idle",
1587
+ actions: [
1588
+ "clearError",
1589
+ {
1590
+ type: "logTransition",
1591
+ params: {
1592
+ from: "presentation:stopping",
1593
+ to: "presentation:idle",
1594
+ event: "CALL.ENDED"
1595
+ }
1596
+ }
1597
+ ]
1598
+ },
1599
+ "CALL.FAILED": {
1600
+ target: "presentation:failed",
1601
+ actions: [
1602
+ "setError",
1603
+ {
1604
+ type: "logTransition",
1605
+ params: {
1606
+ from: "presentation:stopping",
1607
+ to: "presentation:failed",
1608
+ event: "CALL.FAILED"
1609
+ }
1610
+ }
1611
+ ]
1612
+ }
1613
+ }
1614
+ },
1615
+ "presentation:failed": {
1616
+ entry: {
1617
+ type: "logStateChange",
1618
+ params: {
1619
+ state: "presentation:failed"
1620
+ /* FAILED */
1621
+ }
1622
+ },
1623
+ on: {
1624
+ "SCREEN.STARTING": {
1625
+ target: "presentation:starting",
1626
+ actions: [
1627
+ "clearError",
1628
+ {
1629
+ type: "logTransition",
1630
+ params: {
1631
+ from: "presentation:failed",
1632
+ to: "presentation:starting",
1633
+ event: "SCREEN.STARTING"
1634
+ }
1635
+ }
1636
+ ]
1637
+ },
1638
+ "SCREEN.ENDED": {
1639
+ target: "presentation:idle",
1640
+ actions: [
1641
+ "clearError",
1642
+ {
1643
+ type: "logTransition",
1644
+ params: {
1645
+ from: "presentation:failed",
1646
+ to: "presentation:idle",
1647
+ event: "SCREEN.ENDED"
1648
+ }
1649
+ }
1650
+ ]
1651
+ },
1652
+ "PRESENTATION.RESET": {
1653
+ target: "presentation:idle",
1654
+ actions: [
1655
+ "clearError",
1656
+ {
1657
+ type: "logTransition",
1658
+ params: {
1659
+ from: "presentation:failed",
1660
+ to: "presentation:idle",
1661
+ event: "PRESENTATION.RESET"
1662
+ }
1663
+ }
1664
+ ]
1665
+ }
1666
+ }
1667
+ }
1668
+ }
1669
+ });
1670
+ class vt extends q {
1671
+ constructor(e) {
1672
+ super(Mt), this.subscribeCallEvents(e);
1673
+ }
1674
+ get isIdle() {
1675
+ return this.state === "presentation:idle";
1676
+ }
1677
+ get isStarting() {
1678
+ return this.state === "presentation:starting";
1679
+ }
1680
+ get isActive() {
1681
+ return this.state === "presentation:active";
1682
+ }
1683
+ get isStopping() {
1684
+ return this.state === "presentation:stopping";
1685
+ }
1686
+ get isFailed() {
1687
+ return this.state === "presentation:failed";
1688
+ }
1689
+ get isPending() {
1690
+ return this.isStarting || this.isStopping;
1691
+ }
1692
+ get isActiveOrPending() {
1693
+ return this.isActive || this.isPending;
1694
+ }
1695
+ get lastError() {
1696
+ return this.getSnapshot().context.lastError;
1697
+ }
1698
+ reset() {
1699
+ this.send({ type: "PRESENTATION.RESET" });
1700
+ }
1701
+ send(e) {
1702
+ if (!this.getSnapshot().can(e)) {
1703
+ console.warn(
1704
+ `[PresentationStateMachine] Invalid transition: ${e.type} from ${this.state}. Event cannot be processed in current state.`
1705
+ );
1706
+ return;
1707
+ }
1708
+ super.send(e);
1709
+ }
1710
+ subscribeCallEvents(e) {
1711
+ this.addSubscription(
1712
+ e.on(C.START_PRESENTATION, () => {
1713
+ this.send({ type: "SCREEN.STARTING" });
1714
+ })
1715
+ ), this.addSubscription(
1716
+ e.on(C.STARTED_PRESENTATION, () => {
1717
+ this.send({ type: "SCREEN.STARTED" });
1718
+ })
1719
+ ), this.addSubscription(
1720
+ e.on(C.END_PRESENTATION, () => {
1721
+ this.send({ type: "SCREEN.ENDING" });
1722
+ })
1723
+ ), this.addSubscription(
1724
+ e.on(C.ENDED_PRESENTATION, () => {
1725
+ this.send({ type: "SCREEN.ENDED" });
1726
+ })
1727
+ ), this.addSubscription(
1728
+ e.on(C.FAILED_PRESENTATION, (t) => {
1729
+ this.send({ type: "SCREEN.FAILED", error: t });
1730
+ })
1731
+ ), this.addSubscription(
1732
+ e.on(C.ENDED, () => {
1733
+ this.send({ type: "CALL.ENDED" });
1734
+ })
1735
+ ), this.addSubscription(
1736
+ e.on(C.FAILED, (t) => {
1737
+ this.send({ type: "CALL.FAILED", error: t });
1738
+ })
1739
+ );
1740
+ }
1741
+ }
1742
+ const _t = 1, Ls = (n) => Ge(n);
1743
+ class Ot {
1132
1744
  events;
1745
+ presentationStateMachine;
1133
1746
  promisePendingStartPresentation;
1134
1747
  promisePendingStopPresentation;
1135
1748
  streamPresentationCurrent;
@@ -1140,18 +1753,24 @@ class Rt {
1140
1753
  callManager: e,
1141
1754
  maxBitrate: t
1142
1755
  }) {
1143
- this.callManager = e, this.maxBitrate = t, this.events = Et(), this.subscribe();
1756
+ this.callManager = e, this.maxBitrate = t, this.events = It(), this.presentationStateMachine = new vt(this.callManager.events), this.subscribe();
1757
+ }
1758
+ get presentationActor() {
1759
+ return this.presentationStateMachine.actorRef;
1144
1760
  }
1145
1761
  get isPendingPresentation() {
1146
1762
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
1147
1763
  }
1764
+ get isPresentationInProcess() {
1765
+ return !!this.streamPresentationCurrent || this.isPendingPresentation;
1766
+ }
1148
1767
  // eslint-disable-next-line @typescript-eslint/max-params
1149
1768
  async startPresentation(e, t, {
1150
1769
  isNeedReinvite: s,
1151
1770
  contentHint: i,
1152
1771
  sendEncodings: r,
1153
- onAddedTransceiver: a
1154
- } = {}, o) {
1772
+ onAddedTransceiver: o
1773
+ } = {}, a) {
1155
1774
  const c = this.getRtcSessionProtected();
1156
1775
  if (this.streamPresentationCurrent)
1157
1776
  throw new Error("Presentation is already started");
@@ -1162,9 +1781,9 @@ class Rt {
1162
1781
  isNeedReinvite: s,
1163
1782
  contentHint: i,
1164
1783
  sendEncodings: r,
1165
- onAddedTransceiver: a
1784
+ onAddedTransceiver: o
1166
1785
  },
1167
- options: o
1786
+ options: a
1168
1787
  });
1169
1788
  }
1170
1789
  async stopPresentation(e) {
@@ -1175,9 +1794,9 @@ class Rt {
1175
1794
  });
1176
1795
  const i = this.callManager.getEstablishedRTCSession();
1177
1796
  return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
1178
- const a = r instanceof Error ? r : new Error(String(r));
1179
- throw this.events.trigger(O.FAILED_PRESENTATION, a), r;
1180
- }) : t && this.events.trigger(O.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
1797
+ const o = r instanceof Error ? r : new Error(String(r));
1798
+ throw this.events.trigger(P.FAILED_PRESENTATION, o), r;
1799
+ }) : t && this.events.trigger(P.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
1181
1800
  this.resetPresentation();
1182
1801
  });
1183
1802
  }
@@ -1186,15 +1805,15 @@ class Rt {
1186
1805
  sendEncodings: i,
1187
1806
  onAddedTransceiver: r
1188
1807
  } = {}) {
1189
- const a = this.getRtcSessionProtected();
1808
+ const o = this.getRtcSessionProtected();
1190
1809
  if (!this.streamPresentationCurrent)
1191
1810
  throw new Error("Presentation has not started yet");
1192
- return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
1811
+ return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, o, t, {
1193
1812
  contentHint: s,
1194
1813
  isNeedReinvite: !1,
1195
1814
  sendEncodings: i,
1196
1815
  onAddedTransceiver: r
1197
- }).then(async (o) => (await this.setMaxBitrate(), o));
1816
+ }).then(async (a) => (await this.setMaxBitrate(), a));
1198
1817
  }
1199
1818
  cancelSendPresentationWithRepeatedCalls() {
1200
1819
  this.cancelableSendPresentationWithRepeatedCalls?.stopRepeatedCalls();
@@ -1216,15 +1835,15 @@ class Rt {
1216
1835
  }
1217
1836
  subscribe() {
1218
1837
  this.callManager.on("presentation:start", (e) => {
1219
- this.events.trigger(O.START_PRESENTATION, e);
1838
+ this.events.trigger(P.START_PRESENTATION, e);
1220
1839
  }), this.callManager.on("presentation:started", (e) => {
1221
- this.events.trigger(O.STARTED_PRESENTATION, e);
1840
+ this.events.trigger(P.STARTED_PRESENTATION, e);
1222
1841
  }), this.callManager.on("presentation:end", (e) => {
1223
- this.events.trigger(O.END_PRESENTATION, e);
1842
+ this.events.trigger(P.END_PRESENTATION, e);
1224
1843
  }), this.callManager.on("presentation:ended", (e) => {
1225
- this.events.trigger(O.ENDED_PRESENTATION, e);
1844
+ this.events.trigger(P.ENDED_PRESENTATION, e);
1226
1845
  }), this.callManager.on("presentation:failed", (e) => {
1227
- this.events.trigger(O.FAILED_PRESENTATION, e);
1846
+ this.events.trigger(P.FAILED_PRESENTATION, e);
1228
1847
  }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
1229
1848
  }
1230
1849
  async sendPresentationWithDuplicatedCalls(e, {
@@ -1232,18 +1851,18 @@ class Rt {
1232
1851
  stream: s,
1233
1852
  presentationOptions: i,
1234
1853
  options: r = {
1235
- callLimit: pt
1854
+ callLimit: _t
1236
1855
  }
1237
1856
  }) {
1238
- const a = async () => this.sendPresentation(
1857
+ const o = async () => this.sendPresentation(
1239
1858
  e,
1240
1859
  t,
1241
1860
  s,
1242
1861
  i
1243
- ), o = () => !!this.streamPresentationCurrent;
1244
- return this.cancelableSendPresentationWithRepeatedCalls = ie({
1245
- targetFunction: a,
1246
- isComplete: o,
1862
+ ), a = () => !!this.streamPresentationCurrent;
1863
+ return this.cancelableSendPresentationWithRepeatedCalls = ce({
1864
+ targetFunction: o,
1865
+ isComplete: a,
1247
1866
  isRejectAsValid: !0,
1248
1867
  ...r
1249
1868
  }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
@@ -1252,24 +1871,24 @@ class Rt {
1252
1871
  async sendPresentation(e, t, s, {
1253
1872
  isNeedReinvite: i = !0,
1254
1873
  contentHint: r = "detail",
1255
- degradationPreference: a,
1256
- sendEncodings: o,
1874
+ degradationPreference: o,
1875
+ sendEncodings: a,
1257
1876
  onAddedTransceiver: c
1258
1877
  }) {
1259
- const d = B(s, { contentHint: r });
1878
+ const d = k(s, { contentHint: r });
1260
1879
  if (d === void 0)
1261
1880
  throw new Error("No streamPresentationTarget");
1262
1881
  this.streamPresentationCurrent = d;
1263
- const S = e().then(async () => t.startPresentation(d, i, {
1264
- degradationPreference: a,
1265
- sendEncodings: o,
1882
+ const T = e().then(async () => t.startPresentation(d, i, {
1883
+ degradationPreference: o,
1884
+ sendEncodings: a,
1266
1885
  onAddedTransceiver: c
1267
- })).then(this.setMaxBitrate).then(() => s).catch((g) => {
1886
+ })).then(this.setMaxBitrate).then(() => s).catch((h) => {
1268
1887
  this.removeStreamPresentationCurrent();
1269
- const T = g instanceof Error ? g : new Error(String(g));
1270
- throw this.events.trigger(O.FAILED_PRESENTATION, T), g;
1888
+ const u = h instanceof Error ? h : new Error(String(h));
1889
+ throw this.events.trigger(P.FAILED_PRESENTATION, u), h;
1271
1890
  });
1272
- return this.promisePendingStartPresentation = S, S.finally(() => {
1891
+ return this.promisePendingStartPresentation = T, T.finally(() => {
1273
1892
  this.promisePendingStartPresentation = void 0;
1274
1893
  });
1275
1894
  }
@@ -1278,7 +1897,7 @@ class Rt {
1278
1897
  if (!e || !t || s === void 0)
1279
1898
  return;
1280
1899
  const i = e.getSenders();
1281
- await Ct(i, t, s);
1900
+ await At(i, t, s);
1282
1901
  };
1283
1902
  getRtcSessionProtected = () => {
1284
1903
  const e = this.callManager.getEstablishedRTCSession();
@@ -1299,7 +1918,7 @@ class Rt {
1299
1918
  delete this.streamPresentationCurrent;
1300
1919
  }
1301
1920
  }
1302
- class At {
1921
+ class Pt {
1303
1922
  data;
1304
1923
  getUa;
1305
1924
  constructor(e) {
@@ -1385,8 +2004,8 @@ class At {
1385
2004
  return this.data?.register === !0;
1386
2005
  }
1387
2006
  }
1388
- var C = /* @__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))(C || {});
1389
- const Se = [
2007
+ var S = /* @__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))(S || {});
2008
+ const me = [
1390
2009
  "connecting",
1391
2010
  "connected",
1392
2011
  "disconnected",
@@ -1396,7 +2015,7 @@ const Se = [
1396
2015
  "registrationFailed",
1397
2016
  "newMessage",
1398
2017
  "sipEvent"
1399
- ], mt = [
2018
+ ], bt = [
1400
2019
  "disconnecting",
1401
2020
  "connect-started",
1402
2021
  "connect-succeeded",
@@ -1404,12 +2023,12 @@ const Se = [
1404
2023
  "connect-parameters-resolve-success",
1405
2024
  "connect-parameters-resolve-failed",
1406
2025
  "connected-with-configuration"
1407
- ], Ce = [...Se, ...mt], Nt = () => new M(Ce);
1408
- function It(n) {
2026
+ ], Ne = [...me, ...bt], Dt = () => new O(Ne);
2027
+ function yt(n) {
1409
2028
  return (e) => `sip:${e}@${n}`;
1410
2029
  }
1411
- const vt = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, Ee = (n) => n.trim().replaceAll(" ", "_"), _t = vt(1e5, 99999999), ft = 3;
1412
- class Mt {
2030
+ const Lt = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, Re = (n) => n.trim().replaceAll(" ", "_"), wt = Lt(1e5, 99999999), Ut = 3;
2031
+ class Ft {
1413
2032
  cancelableConnectWithRepeatedCalls;
1414
2033
  JsSIP;
1415
2034
  events;
@@ -1434,31 +2053,31 @@ class Mt {
1434
2053
  return;
1435
2054
  }
1436
2055
  let r = !1;
1437
- const a = this.getConnectionConfiguration();
1438
- e !== void 0 && e !== a?.displayName && (r = i.set("display_name", Ee(e)), this.updateConnectionConfiguration("displayName", e));
1439
- const o = r;
1440
- o ? t(o) : s(new Error("nothing changed"));
2056
+ const o = this.getConnectionConfiguration();
2057
+ e !== void 0 && e !== o?.displayName && (r = i.set("display_name", Re(e)), this.updateConnectionConfiguration("displayName", e));
2058
+ const a = r;
2059
+ a ? t(a) : s(new Error("nothing changed"));
1441
2060
  });
1442
2061
  disconnect = async () => {
1443
- this.events.trigger(C.DISCONNECTING, {});
2062
+ this.events.trigger(S.DISCONNECTING, {});
1444
2063
  const e = new Promise((s) => {
1445
- this.events.once(C.DISCONNECTED, () => {
2064
+ this.events.once(S.DISCONNECTED, () => {
1446
2065
  s();
1447
2066
  });
1448
2067
  }), t = this.getUa();
1449
- return t ? t.stop() : this.events.trigger(C.DISCONNECTED, { socket: {}, error: !1 }), e.finally(() => {
2068
+ return t ? t.stop() : this.events.trigger(S.DISCONNECTED, { socket: {}, error: !1 }), e.finally(() => {
1450
2069
  t?.removeAllListeners(), this.setUa(void 0), this.stateMachine.reset();
1451
2070
  });
1452
2071
  };
1453
2072
  cancelRequests() {
1454
2073
  this.cancelConnectWithRepeatedCalls();
1455
2074
  }
1456
- connectWithDuplicatedCalls = async (e, { callLimit: t = ft } = {}) => {
2075
+ connectWithDuplicatedCalls = async (e, { callLimit: t = Ut } = {}) => {
1457
2076
  const s = async () => this.connectInner(e), i = (r) => {
1458
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !He(r);
2077
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !xe(r);
1459
2078
  return c || d;
1460
2079
  };
1461
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = ie({
2080
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = ce({
1462
2081
  targetFunction: s,
1463
2082
  isComplete: i,
1464
2083
  callLimit: t,
@@ -1489,42 +2108,42 @@ class Mt {
1489
2108
  sipServerIp: s,
1490
2109
  sipServerUrl: i,
1491
2110
  remoteAddress: r,
1492
- sessionTimers: a,
1493
- registerExpires: o,
2111
+ sessionTimers: o,
2112
+ registerExpires: a,
1494
2113
  connectionRecoveryMinInterval: c,
1495
2114
  connectionRecoveryMaxInterval: d,
1496
- userAgent: S,
1497
- displayName: g = "",
1498
- register: T = !1,
2115
+ userAgent: T,
2116
+ displayName: h = "",
2117
+ register: u = !1,
1499
2118
  extraHeaders: p = []
1500
2119
  }) => {
1501
2120
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1502
2121
  sipServerIp: s,
1503
2122
  sipServerUrl: i,
1504
- displayName: g,
1505
- register: T,
2123
+ displayName: h,
2124
+ register: u,
1506
2125
  user: e,
1507
2126
  password: t
1508
2127
  }), this.getUa() && await this.disconnect();
1509
- const { ua: A, helpers: y } = this.uaFactory.createUAWithConfiguration(
2128
+ const { ua: N, helpers: D } = this.uaFactory.createUAWithConfiguration(
1510
2129
  {
1511
2130
  user: e,
1512
2131
  password: t,
1513
2132
  sipServerIp: s,
1514
2133
  sipServerUrl: i,
1515
- displayName: g,
1516
- register: T,
1517
- sessionTimers: a,
1518
- registerExpires: o,
2134
+ displayName: h,
2135
+ register: u,
2136
+ sessionTimers: o,
2137
+ registerExpires: a,
1519
2138
  connectionRecoveryMinInterval: c,
1520
2139
  connectionRecoveryMaxInterval: d,
1521
- userAgent: S,
2140
+ userAgent: T,
1522
2141
  remoteAddress: r,
1523
2142
  extraHeaders: p
1524
2143
  },
1525
2144
  this.events
1526
2145
  );
1527
- return this.setUa(A), this.setGetUri(y.getUri), this.setSocket(y.socket), A;
2146
+ return this.setUa(N), this.setGetUri(D.getUri), this.setSocket(D.socket), N;
1528
2147
  };
1529
2148
  start = async () => new Promise((e, t) => {
1530
2149
  const s = this.getUa();
@@ -1536,11 +2155,11 @@ class Mt {
1536
2155
  i = ((c, d) => {
1537
2156
  if (this.getConnectionConfiguration()?.register === !0)
1538
2157
  return this.registrationManager.subscribeToStartEvents(c, d);
1539
- const g = C.CONNECTED, T = [C.DISCONNECTED];
1540
- return this.events.on(g, c), T.forEach((p) => {
2158
+ const h = S.CONNECTED, u = [S.DISCONNECTED];
2159
+ return this.events.on(h, c), u.forEach((p) => {
1541
2160
  this.events.on(p, d);
1542
2161
  }), () => {
1543
- this.events.off(g, c), T.forEach((p) => {
2162
+ this.events.off(h, c), u.forEach((p) => {
1544
2163
  this.events.off(p, d);
1545
2164
  });
1546
2165
  };
@@ -1554,28 +2173,40 @@ class Mt {
1554
2173
  this.cancelableConnectWithRepeatedCalls?.cancel();
1555
2174
  }
1556
2175
  proxyEvents() {
1557
- this.events.on(C.CONNECTED, () => {
2176
+ this.events.on(S.CONNECTED, () => {
1558
2177
  const e = this.getConnectionConfiguration(), t = this.getUa();
1559
- e !== void 0 && t !== void 0 && this.events.trigger(C.CONNECTED_WITH_CONFIGURATION, {
2178
+ e !== void 0 && t !== void 0 && this.events.trigger(S.CONNECTED_WITH_CONFIGURATION, {
1560
2179
  ...e,
1561
2180
  ua: t
1562
2181
  });
1563
2182
  });
1564
2183
  }
1565
2184
  }
1566
- var pe = /* @__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))(pe || {});
1567
- const Pt = Object.values(pe), Ot = Fe({
2185
+ var Ae = /* @__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))(Ae || {});
2186
+ const Bt = Object.values(Ae);
2187
+ var kt = /* @__PURE__ */ ((n) => (n.IDLE = "connection:idle", n.CONNECTING = "connection:connecting", n.INITIALIZING = "connection:initializing", n.CONNECTED = "connection:connected", n.REGISTERED = "connection:registered", n.DISCONNECTED = "connection:disconnected", n.FAILED = "connection:failed", n))(kt || {});
2188
+ const Gt = $({
1568
2189
  types: {
1569
2190
  context: {},
1570
2191
  events: {}
1571
2192
  },
1572
2193
  actions: {
1573
2194
  logTransition: (n, e) => {
1574
- h(`State transition: ${e.from} -> ${e.to} (${e.event})`);
2195
+ l(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1575
2196
  },
1576
2197
  logStateChange: (n, e) => {
1577
- h("ConnectionStateMachine state changed", e.state);
1578
- }
2198
+ l("ConnectionStateMachine state changed", e.state);
2199
+ },
2200
+ setError: b({
2201
+ error: ({ event: n }) => {
2202
+ if (n.type === "CONNECTION_FAILED" && "error" in n)
2203
+ return n.error;
2204
+ }
2205
+ }),
2206
+ clearError: b({
2207
+ error: () => {
2208
+ }
2209
+ })
1579
2210
  }
1580
2211
  }).createMachine({
1581
2212
  id: "connection",
@@ -1623,7 +2254,6 @@ const Pt = Object.values(pe), Ot = Fe({
1623
2254
  to: "connection:initializing",
1624
2255
  event: "START_INIT_UA"
1625
2256
  /* START_INIT_UA */
1626
- // TODO: remove
1627
2257
  }
1628
2258
  }
1629
2259
  },
@@ -1641,15 +2271,21 @@ const Pt = Object.values(pe), Ot = Fe({
1641
2271
  },
1642
2272
  CONNECTION_FAILED: {
1643
2273
  target: "connection:failed",
1644
- actions: {
1645
- type: "logTransition",
1646
- params: {
1647
- from: "connection:connecting",
1648
- to: "connection:failed",
1649
- event: "CONNECTION_FAILED"
1650
- /* CONNECTION_FAILED */
2274
+ actions: [
2275
+ {
2276
+ type: "logTransition",
2277
+ params: {
2278
+ from: "connection:connecting",
2279
+ to: "connection:failed",
2280
+ event: "CONNECTION_FAILED"
2281
+ /* CONNECTION_FAILED */
2282
+ }
2283
+ },
2284
+ {
2285
+ type: "setError"
2286
+ /* SET_ERROR */
1651
2287
  }
1652
- }
2288
+ ]
1653
2289
  }
1654
2290
  }
1655
2291
  },
@@ -1700,15 +2336,21 @@ const Pt = Object.values(pe), Ot = Fe({
1700
2336
  },
1701
2337
  CONNECTION_FAILED: {
1702
2338
  target: "connection:failed",
1703
- actions: {
1704
- type: "logTransition",
1705
- params: {
1706
- from: "connection:initializing",
1707
- to: "connection:failed",
1708
- event: "CONNECTION_FAILED"
1709
- /* CONNECTION_FAILED */
2339
+ actions: [
2340
+ {
2341
+ type: "logTransition",
2342
+ params: {
2343
+ from: "connection:initializing",
2344
+ to: "connection:failed",
2345
+ event: "CONNECTION_FAILED"
2346
+ /* CONNECTION_FAILED */
2347
+ }
2348
+ },
2349
+ {
2350
+ type: "setError"
2351
+ /* SET_ERROR */
1710
2352
  }
1711
- }
2353
+ ]
1712
2354
  }
1713
2355
  }
1714
2356
  },
@@ -1747,15 +2389,21 @@ const Pt = Object.values(pe), Ot = Fe({
1747
2389
  },
1748
2390
  CONNECTION_FAILED: {
1749
2391
  target: "connection:failed",
1750
- actions: {
1751
- type: "logTransition",
1752
- params: {
1753
- from: "connection:connected",
1754
- to: "connection:failed",
1755
- event: "CONNECTION_FAILED"
1756
- /* CONNECTION_FAILED */
2392
+ actions: [
2393
+ {
2394
+ type: "logTransition",
2395
+ params: {
2396
+ from: "connection:connected",
2397
+ to: "connection:failed",
2398
+ event: "CONNECTION_FAILED"
2399
+ /* CONNECTION_FAILED */
2400
+ }
2401
+ },
2402
+ {
2403
+ type: "setError"
2404
+ /* SET_ERROR */
1757
2405
  }
1758
- }
2406
+ ]
1759
2407
  }
1760
2408
  }
1761
2409
  },
@@ -1794,15 +2442,21 @@ const Pt = Object.values(pe), Ot = Fe({
1794
2442
  },
1795
2443
  CONNECTION_FAILED: {
1796
2444
  target: "connection:failed",
1797
- actions: {
1798
- type: "logTransition",
1799
- params: {
1800
- from: "connection:registered",
1801
- to: "connection:failed",
1802
- event: "CONNECTION_FAILED"
1803
- /* CONNECTION_FAILED */
2445
+ actions: [
2446
+ {
2447
+ type: "logTransition",
2448
+ params: {
2449
+ from: "connection:registered",
2450
+ to: "connection:failed",
2451
+ event: "CONNECTION_FAILED"
2452
+ /* CONNECTION_FAILED */
2453
+ }
2454
+ },
2455
+ {
2456
+ type: "setError"
2457
+ /* SET_ERROR */
1804
2458
  }
1805
- }
2459
+ ]
1806
2460
  }
1807
2461
  }
1808
2462
  },
@@ -1852,48 +2506,57 @@ const Pt = Object.values(pe), Ot = Fe({
1852
2506
  on: {
1853
2507
  RESET: {
1854
2508
  target: "connection:idle",
1855
- actions: {
1856
- type: "logTransition",
1857
- params: {
1858
- from: "connection:failed",
1859
- to: "connection:idle",
1860
- event: "RESET"
1861
- /* RESET */
2509
+ actions: [
2510
+ {
2511
+ type: "logTransition",
2512
+ params: {
2513
+ from: "connection:failed",
2514
+ to: "connection:idle",
2515
+ event: "RESET"
2516
+ /* RESET */
2517
+ }
2518
+ },
2519
+ {
2520
+ type: "clearError"
2521
+ /* CLEAR_ERROR */
1862
2522
  }
1863
- }
2523
+ ]
1864
2524
  },
1865
2525
  START_CONNECT: {
1866
2526
  target: "connection:connecting",
1867
- actions: {
1868
- type: "logTransition",
1869
- params: {
1870
- from: "connection:failed",
1871
- to: "connection:connecting",
1872
- event: "START_CONNECT"
1873
- /* START_CONNECT */
2527
+ actions: [
2528
+ {
2529
+ type: "logTransition",
2530
+ params: {
2531
+ from: "connection:failed",
2532
+ to: "connection:connecting",
2533
+ event: "START_CONNECT"
2534
+ /* START_CONNECT */
2535
+ }
2536
+ },
2537
+ {
2538
+ type: "clearError"
2539
+ /* CLEAR_ERROR */
1874
2540
  }
1875
- }
2541
+ ]
1876
2542
  }
1877
2543
  }
1878
2544
  }
1879
2545
  }
1880
2546
  });
1881
- class bt {
1882
- actor;
2547
+ class $t extends q {
1883
2548
  stateChangeListeners = /* @__PURE__ */ new Set();
1884
2549
  events;
1885
2550
  unsubscribeFromEvents;
1886
- actorSubscription;
1887
2551
  constructor(e) {
1888
- this.events = e, this.actor = Be(Ot), this.actorSubscription = this.actor.subscribe((t) => {
1889
- const s = t.value;
1890
- this.stateChangeListeners.forEach((i) => {
1891
- i(s);
1892
- });
1893
- }), this.actor.start(), this.subscribeToEvents();
1894
- }
1895
- get state() {
1896
- return this.actor.getSnapshot().value;
2552
+ super(Gt), this.events = e, this.addSubscription(
2553
+ this.subscribe((t) => {
2554
+ const s = t.value;
2555
+ this.stateChangeListeners.forEach((i) => {
2556
+ i(s);
2557
+ });
2558
+ })
2559
+ ), this.subscribeToEvents();
1897
2560
  }
1898
2561
  get isIdle() {
1899
2562
  return this.hasState(
@@ -1937,6 +2600,9 @@ class bt {
1937
2600
  /* FAILED */
1938
2601
  );
1939
2602
  }
2603
+ get error() {
2604
+ return this.getSnapshot().context.error;
2605
+ }
1940
2606
  get isPending() {
1941
2607
  return this.isConnecting || this.isInitializing;
1942
2608
  }
@@ -1960,7 +2626,7 @@ class bt {
1960
2626
  this.toIdle();
1961
2627
  }
1962
2628
  destroy() {
1963
- this.unsubscribeFromEvents?.(), this.actorSubscription?.unsubscribe(), this.actor.stop();
2629
+ this.stateChangeListeners.clear(), this.unsubscribeFromEvents?.(), this.stop();
1964
2630
  }
1965
2631
  onStateChange(e) {
1966
2632
  return this.stateChangeListeners.add(e), () => {
@@ -1968,79 +2634,82 @@ class bt {
1968
2634
  };
1969
2635
  }
1970
2636
  canTransition(e) {
1971
- return this.actor.getSnapshot().can({ type: e });
2637
+ return this.getSnapshot().can({ type: e });
1972
2638
  }
1973
2639
  getValidEvents() {
1974
- return Pt.filter((e) => this.canTransition(e));
2640
+ return Bt.filter((e) => this.canTransition(e));
1975
2641
  }
1976
2642
  hasState(e) {
1977
- return this.actor.getSnapshot().matches(e);
2643
+ return this.getSnapshot().matches(e);
1978
2644
  }
1979
2645
  sendEvent(e) {
1980
- const t = this.actor.getSnapshot(), s = { type: e };
1981
- if (!t.can(s)) {
1982
- h(
1983
- `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
2646
+ if (!this.getSnapshot().can(e)) {
2647
+ l(
2648
+ `Invalid transition: ${e.type} from ${this.state}. Event cannot be processed in current state.`
1984
2649
  );
1985
2650
  return;
1986
2651
  }
1987
- this.actor.send(s);
2652
+ this.send(e);
1988
2653
  }
1989
2654
  toStartConnect = () => {
1990
- this.sendEvent(
1991
- "START_CONNECT"
2655
+ this.sendEvent({
2656
+ type: "START_CONNECT"
1992
2657
  /* START_CONNECT */
1993
- );
2658
+ });
1994
2659
  };
1995
2660
  toStartInitUa = () => {
1996
- this.sendEvent(
1997
- "START_INIT_UA"
2661
+ this.sendEvent({
2662
+ type: "START_INIT_UA"
1998
2663
  /* START_INIT_UA */
1999
- );
2664
+ });
2000
2665
  };
2001
2666
  toConnected = () => {
2002
- this.sendEvent(
2003
- "UA_CONNECTED"
2667
+ this.sendEvent({
2668
+ type: "UA_CONNECTED"
2004
2669
  /* UA_CONNECTED */
2005
- );
2670
+ });
2006
2671
  };
2007
2672
  toRegistered = () => {
2008
- this.sendEvent(
2009
- "UA_REGISTERED"
2673
+ this.sendEvent({
2674
+ type: "UA_REGISTERED"
2010
2675
  /* UA_REGISTERED */
2011
- );
2676
+ });
2012
2677
  };
2013
2678
  toUnregistered = () => {
2014
- this.sendEvent(
2015
- "UA_UNREGISTERED"
2679
+ this.sendEvent({
2680
+ type: "UA_UNREGISTERED"
2016
2681
  /* UA_UNREGISTERED */
2017
- );
2682
+ });
2018
2683
  };
2019
2684
  toDisconnected = () => {
2020
- this.sendEvent(
2021
- "UA_DISCONNECTED"
2685
+ this.sendEvent({
2686
+ type: "UA_DISCONNECTED"
2022
2687
  /* UA_DISCONNECTED */
2023
- );
2688
+ });
2024
2689
  };
2025
- toFailed = () => {
2026
- this.sendEvent(
2027
- "CONNECTION_FAILED"
2028
- /* CONNECTION_FAILED */
2029
- );
2690
+ toFailed = (e) => {
2691
+ this.sendEvent({ type: "CONNECTION_FAILED", error: e });
2030
2692
  };
2031
2693
  toIdle = () => {
2032
- this.sendEvent(
2033
- "RESET"
2694
+ this.sendEvent({
2695
+ type: "RESET"
2034
2696
  /* RESET */
2035
- );
2697
+ });
2036
2698
  };
2037
2699
  subscribeToEvents() {
2038
- this.events.on("connected", this.toConnected), this.events.on("registered", this.toRegistered), this.events.on("unregistered", this.toUnregistered), this.events.on("disconnected", this.toDisconnected), this.events.on("registrationFailed", this.toFailed), this.unsubscribeFromEvents = () => {
2039
- this.events.off("connected", this.toConnected), this.events.off("registered", this.toRegistered), this.events.off("unregistered", this.toUnregistered), this.events.off("disconnected", this.toDisconnected), this.events.off("registrationFailed", this.toFailed);
2700
+ this.events.on("connected", this.toConnected), this.events.on("registered", this.toRegistered), this.events.on("unregistered", this.toUnregistered), this.events.on("disconnected", this.toDisconnected), this.events.on("registrationFailed", this.handleRegistrationFailed), this.events.on("connect-failed", this.handleConnectFailed), this.unsubscribeFromEvents = () => {
2701
+ this.events.off("connected", this.toConnected), this.events.off("registered", this.toRegistered), this.events.off("unregistered", this.toUnregistered), this.events.off("disconnected", this.toDisconnected), this.events.off("registrationFailed", this.handleRegistrationFailed), this.events.off("connect-failed", this.handleConnectFailed);
2040
2702
  };
2041
2703
  }
2704
+ handleRegistrationFailed = (e) => {
2705
+ const { response: t } = e, s = t.status_code || "Unknown", i = t.reason_phrase || "Registration failed", r = new Error(`Registration failed: ${s} ${i}`);
2706
+ this.toFailed(r);
2707
+ };
2708
+ handleConnectFailed = (e) => {
2709
+ this.toFailed(e instanceof Error ? e : void 0);
2710
+ };
2042
2711
  }
2043
- class yt {
2712
+ class qt {
2044
2713
  events;
2045
2714
  getUaProtected;
2046
2715
  constructor(e) {
@@ -2049,25 +2718,25 @@ class yt {
2049
2718
  async register() {
2050
2719
  const e = this.getUaProtected();
2051
2720
  return new Promise((t, s) => {
2052
- e.on(C.REGISTERED, t), e.on(C.REGISTRATION_FAILED, s), e.register();
2721
+ e.on(S.REGISTERED, t), e.on(S.REGISTRATION_FAILED, s), e.register();
2053
2722
  });
2054
2723
  }
2055
2724
  async unregister() {
2056
2725
  const e = this.getUaProtected();
2057
2726
  return new Promise((t) => {
2058
- e.on(C.UNREGISTERED, t), e.unregister();
2727
+ e.on(S.UNREGISTERED, t), e.unregister();
2059
2728
  });
2060
2729
  }
2061
2730
  async tryRegister() {
2062
2731
  try {
2063
2732
  await this.unregister();
2064
2733
  } catch (e) {
2065
- h("tryRegister", e);
2734
+ l("tryRegister", e);
2066
2735
  }
2067
2736
  return this.register();
2068
2737
  }
2069
2738
  subscribeToStartEvents(e, t) {
2070
- const s = C.REGISTERED, i = [C.REGISTRATION_FAILED, C.DISCONNECTED];
2739
+ const s = S.REGISTERED, i = [S.REGISTRATION_FAILED, S.DISCONNECTED];
2071
2740
  return this.events.on(s, e), i.forEach((r) => {
2072
2741
  this.events.on(r, t);
2073
2742
  }), () => {
@@ -2077,7 +2746,7 @@ class yt {
2077
2746
  };
2078
2747
  }
2079
2748
  }
2080
- class Dt {
2749
+ class Vt {
2081
2750
  uaFactory;
2082
2751
  getUaProtected;
2083
2752
  constructor(e) {
@@ -2088,7 +2757,7 @@ class Dt {
2088
2757
  */
2089
2758
  async sendOptions(e, t, s) {
2090
2759
  const i = this.getUaProtected();
2091
- return new Promise((r, a) => {
2760
+ return new Promise((r, o) => {
2092
2761
  try {
2093
2762
  i.sendOptions(e, t, {
2094
2763
  extraHeaders: s,
@@ -2096,11 +2765,11 @@ class Dt {
2096
2765
  succeeded: () => {
2097
2766
  r();
2098
2767
  },
2099
- failed: a
2768
+ failed: o
2100
2769
  }
2101
2770
  });
2102
- } catch (o) {
2103
- a(o);
2771
+ } catch (a) {
2772
+ o(a);
2104
2773
  }
2105
2774
  });
2106
2775
  }
@@ -2120,33 +2789,33 @@ class Dt {
2120
2789
  sipServerIp: s,
2121
2790
  sipServerUrl: i,
2122
2791
  remoteAddress: r,
2123
- extraHeaders: a
2792
+ extraHeaders: o
2124
2793
  }) {
2125
- return new Promise((o, c) => {
2794
+ return new Promise((a, c) => {
2126
2795
  const { configuration: d } = this.uaFactory.createConfiguration({
2127
2796
  sipServerUrl: i,
2128
2797
  displayName: t,
2129
2798
  userAgent: e,
2130
2799
  sipServerIp: s
2131
- }), S = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), g = () => {
2800
+ }), T = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: o }), h = () => {
2132
2801
  const p = new Error("Telephony is not available");
2133
2802
  c(p);
2134
2803
  };
2135
- S.once(C.DISCONNECTED, g);
2136
- const T = () => {
2137
- S.removeAllListeners(), S.once(C.DISCONNECTED, () => {
2138
- o();
2139
- }), S.stop();
2804
+ T.once(S.DISCONNECTED, h);
2805
+ const u = () => {
2806
+ T.removeAllListeners(), T.once(S.DISCONNECTED, () => {
2807
+ a();
2808
+ }), T.stop();
2140
2809
  };
2141
- S.once(C.CONNECTED, T), S.start();
2810
+ T.once(S.CONNECTED, u), T.start();
2142
2811
  });
2143
2812
  }
2144
2813
  }
2145
- const wt = (n) => {
2814
+ const Ht = (n) => {
2146
2815
  const e = [];
2147
2816
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
2148
2817
  };
2149
- class D {
2818
+ class L {
2150
2819
  JsSIP;
2151
2820
  constructor(e) {
2152
2821
  this.JsSIP = e;
@@ -2171,10 +2840,10 @@ class D {
2171
2840
  throw new Error("user is required for authorized connection");
2172
2841
  }
2173
2842
  static resolveAuthorizationUser(e, t) {
2174
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${_t()}`;
2843
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${wt()}`;
2175
2844
  }
2176
2845
  static buildExtraHeaders(e, t) {
2177
- const s = e !== void 0 && e !== "" ? wt(e) : [];
2846
+ const s = e !== void 0 && e !== "" ? Ht(e) : [];
2178
2847
  return t === void 0 ? s : [...s, ...t];
2179
2848
  }
2180
2849
  createConfiguration({
@@ -2183,44 +2852,44 @@ class D {
2183
2852
  sipServerUrl: s,
2184
2853
  displayName: i = "",
2185
2854
  sipServerIp: r,
2186
- register: a = !1,
2187
- sessionTimers: o = !1,
2855
+ register: o = !1,
2856
+ sessionTimers: a = !1,
2188
2857
  registerExpires: c = 300,
2189
2858
  // 5 minutes in sec
2190
2859
  connectionRecoveryMinInterval: d = 2,
2191
- connectionRecoveryMaxInterval: S = 6,
2192
- userAgent: g
2860
+ connectionRecoveryMaxInterval: T = 6,
2861
+ userAgent: h
2193
2862
  }) {
2194
- D.validateParametersConnection({
2195
- register: a,
2863
+ L.validateParametersConnection({
2864
+ register: o,
2196
2865
  password: t,
2197
2866
  user: e,
2198
2867
  sipServerIp: r,
2199
2868
  sipServerUrl: s
2200
2869
  });
2201
- const T = D.resolveAuthorizationUser(a, e), p = It(r), P = p(T), A = new this.JsSIP.WebSocketInterface(`wss://${s}/webrtc/wss/`);
2870
+ const u = L.resolveAuthorizationUser(o, e), p = yt(r), A = p(u), N = new this.JsSIP.WebSocketInterface(`wss://${s}/webrtc/wss/`);
2202
2871
  return {
2203
2872
  configuration: {
2204
2873
  password: t,
2205
- register: a,
2206
- uri: P,
2207
- display_name: Ee(i),
2208
- user_agent: g,
2874
+ register: o,
2875
+ uri: A,
2876
+ display_name: Re(i),
2877
+ user_agent: h,
2209
2878
  sdpSemantics: "unified-plan",
2210
- sockets: [A],
2211
- session_timers: o,
2879
+ sockets: [N],
2880
+ session_timers: a,
2212
2881
  register_expires: c,
2213
2882
  connection_recovery_min_interval: d,
2214
- connection_recovery_max_interval: S
2883
+ connection_recovery_max_interval: T
2215
2884
  },
2216
2885
  helpers: {
2217
- socket: A,
2886
+ socket: N,
2218
2887
  getUri: p
2219
2888
  }
2220
2889
  };
2221
2890
  }
2222
2891
  createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
2223
- const i = new this.JsSIP.UA(s), r = D.buildExtraHeaders(e, t);
2892
+ const i = new this.JsSIP.UA(s), r = L.buildExtraHeaders(e, t);
2224
2893
  return r.length > 0 && i.registrator().setExtraHeaders(r), i;
2225
2894
  }
2226
2895
  /**
@@ -2232,14 +2901,14 @@ class D {
2232
2901
  remoteAddress: e.remoteAddress,
2233
2902
  extraHeaders: e.extraHeaders
2234
2903
  });
2235
- return t.eachTriggers((a, o) => {
2236
- const c = Se.find((d) => d === o);
2237
- c && r.on(c, a);
2904
+ return t.eachTriggers((o, a) => {
2905
+ const c = me.find((d) => d === a);
2906
+ c && r.on(c, o);
2238
2907
  }), { ua: r, helpers: i };
2239
2908
  }
2240
2909
  }
2241
- const Re = "Not ready for connection", Ut = (n) => n instanceof Error && n.message === Re, Lt = () => new Error(Re), Ft = async (n) => typeof n == "function" ? n() : n;
2242
- class Bt {
2910
+ const Ie = "Not ready for connection", Wt = (n) => n instanceof Error && n.message === Ie, xt = () => new Error(Ie), Qt = async (n) => typeof n == "function" ? n() : n;
2911
+ class Yt {
2243
2912
  events;
2244
2913
  ua;
2245
2914
  socket;
@@ -2251,15 +2920,15 @@ class Bt {
2251
2920
  configurationManager;
2252
2921
  JsSIP;
2253
2922
  constructor({ JsSIP: e }) {
2254
- this.JsSIP = e, this.events = Nt(), this.uaFactory = new D(e), this.registrationManager = new yt({
2923
+ this.JsSIP = e, this.events = Dt(), this.uaFactory = new L(e), this.registrationManager = new qt({
2255
2924
  events: this.events,
2256
2925
  getUaProtected: this.getUaProtected
2257
- }), this.stateMachine = new bt(this.events), this.configurationManager = new At({
2926
+ }), this.stateMachine = new $t(this.events), this.configurationManager = new Pt({
2258
2927
  getUa: this.getUa
2259
- }), this.sipOperations = new Dt({
2928
+ }), this.sipOperations = new Vt({
2260
2929
  uaFactory: this.uaFactory,
2261
2930
  getUaProtected: this.getUaProtected
2262
- }), this.connectionFlow = new Mt({
2931
+ }), this.connectionFlow = new Ft({
2263
2932
  JsSIP: this.JsSIP,
2264
2933
  events: this.events,
2265
2934
  uaFactory: this.uaFactory,
@@ -2302,17 +2971,20 @@ class Bt {
2302
2971
  get isFailed() {
2303
2972
  return this.stateMachine.isFailed;
2304
2973
  }
2974
+ get connectionActor() {
2975
+ return this.stateMachine.actorRef;
2976
+ }
2305
2977
  get connectionState() {
2306
2978
  return this.stateMachine.state;
2307
2979
  }
2308
2980
  get isRegistered() {
2309
- return D.isRegisteredUA(this.ua);
2981
+ return L.isRegisteredUA(this.ua);
2310
2982
  }
2311
2983
  get isRegisterConfig() {
2312
2984
  return this.configurationManager.isRegister();
2313
2985
  }
2314
2986
  connect = async (e, t) => this.disconnect().catch((s) => {
2315
- h("connect: disconnect error", s);
2987
+ l("connect: disconnect error", s);
2316
2988
  }).then(async () => this.connectWithProcessError(e, t));
2317
2989
  set = async ({ displayName: e }) => this.connectionFlow.set({ displayName: e });
2318
2990
  disconnect = async () => {
@@ -2361,7 +3033,7 @@ class Bt {
2361
3033
  getUa = () => this.ua;
2362
3034
  connectWithProcessError = async (e, t) => {
2363
3035
  if (!(t?.hasReadyForConnection?.() ?? !0))
2364
- throw Lt();
3036
+ throw xt();
2365
3037
  return this.processConnect(e, t).catch(async (i) => {
2366
3038
  const r = i;
2367
3039
  return this.disconnect().then(() => {
@@ -2371,18 +3043,18 @@ class Bt {
2371
3043
  });
2372
3044
  });
2373
3045
  };
2374
- processConnect = async (e, t) => (this.events.trigger(C.CONNECT_STARTED, {}), Ft(e).then((s) => (this.events.trigger(C.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
2375
- throw this.events.trigger(C.CONNECT_PARAMETERS_RESOLVE_FAILED, s), s;
2376
- }).then(async (s) => this.connectionFlow.connect(s, t)).then((s) => (this.events.trigger(C.CONNECT_SUCCEEDED, {
3046
+ processConnect = async (e, t) => (this.events.trigger(S.CONNECT_STARTED, {}), Qt(e).then((s) => (this.events.trigger(S.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
3047
+ throw this.events.trigger(S.CONNECT_PARAMETERS_RESOLVE_FAILED, s), s;
3048
+ }).then(async (s) => this.connectionFlow.connect(s, t)).then((s) => (this.events.trigger(S.CONNECT_SUCCEEDED, {
2377
3049
  ...s
2378
3050
  }), s)).catch((s) => {
2379
3051
  const i = s ?? new Error("Failed to connect to server");
2380
- throw this.events.trigger(C.CONNECT_FAILED, i), i;
3052
+ throw this.events.trigger(S.CONNECT_FAILED, i), i;
2381
3053
  }));
2382
3054
  }
2383
- class kt {
3055
+ class zt {
2384
3056
  connectionManager;
2385
- stackPromises = re({
3057
+ stackPromises = le({
2386
3058
  noRunIsNotActual: !0
2387
3059
  });
2388
3060
  constructor({ connectionManager: e }) {
@@ -2394,11 +3066,11 @@ class kt {
2394
3066
  this.stackPromises.stop();
2395
3067
  }
2396
3068
  }
2397
- const K = 0, $t = 30;
2398
- class qt {
2399
- countInner = K;
2400
- initialCount = K;
2401
- limitInner = $t;
3069
+ const ee = 0, Xt = 30;
3070
+ class Jt {
3071
+ countInner = ee;
3072
+ initialCount = ee;
3073
+ limitInner = Xt;
2402
3074
  isInProgress = !1;
2403
3075
  onStatusChange;
2404
3076
  constructor({
@@ -2431,7 +3103,7 @@ class qt {
2431
3103
  this.countInner = this.initialCount, this.finishAttempt();
2432
3104
  }
2433
3105
  }
2434
- class Vt {
3106
+ class Kt {
2435
3107
  connectionManager;
2436
3108
  interval;
2437
3109
  checkTelephonyByTimeout = void 0;
@@ -2447,7 +3119,7 @@ class Vt {
2447
3119
  onSuccessRequest: t,
2448
3120
  onFailRequest: s
2449
3121
  }) {
2450
- this.stop(), this.cancelableBeforeRequest = new k(e), this.checkTelephonyByTimeout = ye({
3122
+ this.stop(), this.cancelableBeforeRequest = new G(e), this.checkTelephonyByTimeout = Ue({
2451
3123
  isDontStopOnFail: !0,
2452
3124
  requestInterval: this.interval,
2453
3125
  request: async () => {
@@ -2467,8 +3139,8 @@ class Vt {
2467
3139
  this.checkTelephonyByTimeout?.stop(), this.checkTelephonyByTimeout = void 0, this.cancelableBeforeRequest?.cancelRequest(), this.cancelableBeforeRequest = void 0;
2468
3140
  }
2469
3141
  }
2470
- var I = /* @__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))(I || {});
2471
- const Ae = [
3142
+ var f = /* @__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))(f || {});
3143
+ const fe = [
2472
3144
  "before-attempt",
2473
3145
  "success",
2474
3146
  "failed-all-attempts",
@@ -2476,8 +3148,8 @@ const Ae = [
2476
3148
  "changed-attempt-status",
2477
3149
  "stop-attempts-by-error",
2478
3150
  "limit-reached-attempts"
2479
- ], Ht = () => new M(Ae);
2480
- class Y {
3151
+ ], jt = () => new O(fe);
3152
+ class J {
2481
3153
  callManager;
2482
3154
  disposers = [];
2483
3155
  constructor({ callManager: e }) {
@@ -2502,40 +3174,40 @@ class Y {
2502
3174
  this.callManager.isCallActive ? e?.() : t();
2503
3175
  }
2504
3176
  }
2505
- const Wt = 15e3, Gt = 2;
2506
- class xt {
3177
+ const Zt = 15e3, en = 2;
3178
+ class tn {
2507
3179
  connectionManager;
2508
3180
  pingServerByTimeoutWithFailCalls;
2509
3181
  constructor({ connectionManager: e }) {
2510
- this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = De(Gt, {
3182
+ this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = Fe(en, {
2511
3183
  whenPossibleRequest: async () => {
2512
3184
  },
2513
- requestInterval: Wt,
2514
- request: async () => (h("ping"), this.connectionManager.ping().then(() => {
2515
- h("ping success");
3185
+ requestInterval: Zt,
3186
+ request: async () => (l("ping"), this.connectionManager.ping().then(() => {
3187
+ l("ping success");
2516
3188
  }))
2517
3189
  });
2518
3190
  }
2519
3191
  start({ onFailRequest: e }) {
2520
- this.pingServerByTimeoutWithFailCalls.start(void 0, { onFailRequest: e }).catch(h);
3192
+ this.pingServerByTimeoutWithFailCalls.start(void 0, { onFailRequest: e }).catch(l);
2521
3193
  }
2522
3194
  stop() {
2523
3195
  this.pingServerByTimeoutWithFailCalls.stop();
2524
3196
  }
2525
3197
  }
2526
- class Qt {
3198
+ class nn {
2527
3199
  pingServerRequester;
2528
3200
  notActiveCallSubscriber;
2529
3201
  constructor({
2530
3202
  connectionManager: e,
2531
3203
  callManager: t
2532
3204
  }) {
2533
- this.pingServerRequester = new xt({
3205
+ this.pingServerRequester = new tn({
2534
3206
  connectionManager: e
2535
- }), this.notActiveCallSubscriber = new Y({ callManager: t });
3207
+ }), this.notActiveCallSubscriber = new J({ callManager: t });
2536
3208
  }
2537
3209
  start({ onFailRequest: e }) {
2538
- h("start"), this.notActiveCallSubscriber.subscribe({
3210
+ l("start"), this.notActiveCallSubscriber.subscribe({
2539
3211
  onActive: () => {
2540
3212
  this.pingServerRequester.stop();
2541
3213
  },
@@ -2545,13 +3217,13 @@ class Qt {
2545
3217
  });
2546
3218
  }
2547
3219
  stop() {
2548
- h("stop"), this.pingServerRequester.stop(), this.unsubscribeCallStatusChange();
3220
+ l("stop"), this.pingServerRequester.stop(), this.unsubscribeCallStatusChange();
2549
3221
  }
2550
3222
  unsubscribeCallStatusChange() {
2551
3223
  this.notActiveCallSubscriber.unsubscribe();
2552
3224
  }
2553
3225
  }
2554
- class Yt {
3226
+ class sn {
2555
3227
  connectionManager;
2556
3228
  isRegistrationFailed = !1;
2557
3229
  disposers = [];
@@ -2560,7 +3232,7 @@ class Yt {
2560
3232
  connectionManager: e,
2561
3233
  callManager: t
2562
3234
  }) {
2563
- this.connectionManager = e, this.notActiveCallSubscriber = new Y({ callManager: t });
3235
+ this.connectionManager = e, this.notActiveCallSubscriber = new J({ callManager: t });
2564
3236
  }
2565
3237
  subscribe(e) {
2566
3238
  this.unsubscribe(), this.disposers.push(
@@ -2587,12 +3259,12 @@ class Yt {
2587
3259
  this.isRegistrationFailed = !1;
2588
3260
  }
2589
3261
  }
2590
- const zt = 3e3, Xt = 15e3, j = {
3262
+ const rn = 3e3, an = 15e3, te = {
2591
3263
  LIMIT_REACHED: "Limit reached",
2592
3264
  FAILED_TO_RECONNECT: "Failed to reconnect"
2593
- }, Jt = async () => {
2594
- }, Kt = (n) => !0;
2595
- class jt {
3265
+ }, on = async () => {
3266
+ }, cn = (n) => !0;
3267
+ class ln {
2596
3268
  events;
2597
3269
  connectionManager;
2598
3270
  connectionQueueManager;
@@ -2612,28 +3284,28 @@ class jt {
2612
3284
  connectionManager: t,
2613
3285
  callManager: s
2614
3286
  }, i) {
2615
- const r = i?.onBeforeRetry ?? Jt, a = i?.canRetryOnError ?? Kt;
2616
- this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = r, this.canRetryOnError = a, this.networkInterfacesSubscriber = i?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = i?.resumeFromSleepModeSubscriber, this.events = Ht(), this.checkTelephonyRequester = new Vt({
3287
+ const r = i?.onBeforeRetry ?? on, o = i?.canRetryOnError ?? cn;
3288
+ this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = r, this.canRetryOnError = o, this.networkInterfacesSubscriber = i?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = i?.resumeFromSleepModeSubscriber, this.events = jt(), this.checkTelephonyRequester = new Kt({
2617
3289
  connectionManager: t,
2618
- interval: i?.checkTelephonyRequestInterval ?? Xt
2619
- }), this.pingServerIfNotActiveCallRequester = new Qt({
3290
+ interval: i?.checkTelephonyRequestInterval ?? an
3291
+ }), this.pingServerIfNotActiveCallRequester = new nn({
2620
3292
  connectionManager: t,
2621
3293
  callManager: s
2622
- }), this.registrationFailedOutOfCallSubscriber = new Yt({
3294
+ }), this.registrationFailedOutOfCallSubscriber = new sn({
2623
3295
  connectionManager: t,
2624
3296
  callManager: s
2625
- }), this.attemptsState = new qt({
3297
+ }), this.attemptsState = new Jt({
2626
3298
  onStatusChange: this.emitStatusChange
2627
- }), this.cancelableRequestBeforeRetry = new k(r), this.delayBetweenAttempts = new we(
2628
- i?.timeoutBetweenAttempts ?? zt
2629
- ), this.notActiveCallSubscriber = new Y({ callManager: s });
3299
+ }), this.cancelableRequestBeforeRetry = new G(r), this.delayBetweenAttempts = new Be(
3300
+ i?.timeoutBetweenAttempts ?? rn
3301
+ ), this.notActiveCallSubscriber = new J({ callManager: s });
2630
3302
  }
2631
3303
  start(e) {
2632
- h("auto connector start"), this.restartConnectionAttempts(e), this.subscribeToNotActiveCall(e);
3304
+ l("auto connector start"), this.restartConnectionAttempts(e), this.subscribeToNotActiveCall(e);
2633
3305
  }
2634
3306
  stop() {
2635
- h("auto connector stop"), this.unsubscribeFromNotActiveCall(), this.unsubscribeFromHardwareTriggers(), this.stopConnectionFlow().catch((e) => {
2636
- h("auto connector stop from stop method: error", e);
3307
+ l("auto connector stop"), this.unsubscribeFromNotActiveCall(), this.unsubscribeFromHardwareTriggers(), this.stopConnectionFlow().catch((e) => {
3308
+ l("auto connector stop from stop method: error", e);
2637
3309
  });
2638
3310
  }
2639
3311
  on(e, t) {
@@ -2652,77 +3324,77 @@ class jt {
2652
3324
  this.events.off(e, t);
2653
3325
  }
2654
3326
  restartConnectionAttempts(e) {
2655
- h("auto connector restart connection attempts"), this.stopConnectionFlow().then(async () => this.attemptConnection(e)).catch((t) => {
2656
- h("auto connector failed to restart connection attempts:", t);
3327
+ l("auto connector restart connection attempts"), this.stopConnectionFlow().then(async () => this.attemptConnection(e)).catch((t) => {
3328
+ l("auto connector failed to restart connection attempts:", t);
2657
3329
  });
2658
3330
  }
2659
3331
  async stopConnectionFlow() {
2660
- h("stopConnectionFlow"), this.stopAttempts(), this.stopConnectTriggers(), await this.connectionQueueManager.disconnect();
3332
+ l("stopConnectionFlow"), this.stopAttempts(), this.stopConnectTriggers(), await this.connectionQueueManager.disconnect();
2661
3333
  }
2662
3334
  stopAttempts() {
2663
3335
  this.attemptsState.isAttemptInProgress && this.connectionQueueManager.stop(), this.delayBetweenAttempts.cancelRequest(), this.cancelableRequestBeforeRetry.cancelRequest(), this.attemptsState.reset();
2664
3336
  }
2665
3337
  stopConnectTriggers() {
2666
- h("stopConnectTriggers"), this.stopPingRequester(), this.checkTelephonyRequester.stop(), this.registrationFailedOutOfCallSubscriber.unsubscribe();
3338
+ l("stopConnectTriggers"), this.stopPingRequester(), this.checkTelephonyRequester.stop(), this.registrationFailedOutOfCallSubscriber.unsubscribe();
2667
3339
  }
2668
3340
  startCheckTelephony(e) {
2669
- h("startCheckTelephony"), this.checkTelephonyRequester.start({
3341
+ l("startCheckTelephony"), this.checkTelephonyRequester.start({
2670
3342
  onBeforeRequest: async () => (await this.onBeforeRetry(), e.getParameters()),
2671
3343
  onSuccessRequest: () => {
2672
- h("startCheckTelephony: onSuccessRequest"), this.connectIfDisconnected(e);
3344
+ l("startCheckTelephony: onSuccessRequest"), this.connectIfDisconnected(e);
2673
3345
  },
2674
3346
  onFailRequest: (t) => {
2675
- h("startCheckTelephony: onFailRequest", t.message);
3347
+ l("startCheckTelephony: onFailRequest", t.message);
2676
3348
  }
2677
3349
  });
2678
3350
  }
2679
3351
  async attemptConnection(e) {
2680
- if (h("attemptConnection: attempts.count", this.attemptsState.count), this.events.trigger(I.BEFORE_ATTEMPT, {}), this.stopConnectTriggers(), this.attemptsState.hasLimitReached()) {
2681
- h("attemptConnection: limit reached"), this.handleLimitReached(e);
3352
+ if (l("attemptConnection: attempts.count", this.attemptsState.count), this.events.trigger(f.BEFORE_ATTEMPT, {}), this.stopConnectTriggers(), this.attemptsState.hasLimitReached()) {
3353
+ l("attemptConnection: limit reached"), this.handleLimitReached(e);
2682
3354
  return;
2683
3355
  }
2684
3356
  return this.attemptsState.startAttempt(), this.attemptsState.increment(), this.executeConnectionAttempt(e);
2685
3357
  }
2686
3358
  async executeConnectionAttempt(e) {
2687
3359
  try {
2688
- await this.connectionQueueManager.connect(e.getParameters, e.options), h("executeConnectionAttempt: success"), this.handleSucceededAttempt(e);
3360
+ await this.connectionQueueManager.connect(e.getParameters, e.options), l("executeConnectionAttempt: success"), this.handleSucceededAttempt(e);
2689
3361
  } catch (t) {
2690
3362
  this.handleConnectionError(t, e);
2691
3363
  }
2692
3364
  }
2693
3365
  handleConnectionError(e, t) {
2694
- if (Ut(e)) {
2695
- this.attemptsState.finishAttempt(), this.events.trigger(I.STOP_ATTEMPTS_BY_ERROR, e);
3366
+ if (Wt(e)) {
3367
+ this.attemptsState.finishAttempt(), this.events.trigger(f.STOP_ATTEMPTS_BY_ERROR, e);
2696
3368
  return;
2697
3369
  }
2698
3370
  if (!this.canRetryOnError(e)) {
2699
- h("executeConnectionAttempt: error does not allow retry", e), this.attemptsState.finishAttempt(), this.events.trigger(I.STOP_ATTEMPTS_BY_ERROR, e);
3371
+ l("executeConnectionAttempt: error does not allow retry", e), this.attemptsState.finishAttempt(), this.events.trigger(f.STOP_ATTEMPTS_BY_ERROR, e);
2700
3372
  return;
2701
3373
  }
2702
- if (ke(e)) {
2703
- h("executeConnectionAttempt: not actual error", e), this.attemptsState.finishAttempt(), this.events.trigger(I.CANCELLED_ATTEMPTS, e);
3374
+ if (qe(e)) {
3375
+ l("executeConnectionAttempt: not actual error", e), this.attemptsState.finishAttempt(), this.events.trigger(f.CANCELLED_ATTEMPTS, e);
2704
3376
  return;
2705
3377
  }
2706
- h("executeConnectionAttempt: error", e), this.scheduleReconnect(t);
3378
+ l("executeConnectionAttempt: error", e), this.scheduleReconnect(t);
2707
3379
  }
2708
3380
  handleLimitReached(e) {
2709
- this.attemptsState.finishAttempt(), this.events.trigger(I.LIMIT_REACHED_ATTEMPTS, new Error(j.LIMIT_REACHED)), this.startCheckTelephony(e);
3381
+ this.attemptsState.finishAttempt(), this.events.trigger(f.LIMIT_REACHED_ATTEMPTS, new Error(te.LIMIT_REACHED)), this.startCheckTelephony(e);
2710
3382
  }
2711
3383
  handleSucceededAttempt(e) {
2712
- h("handleSucceededAttempt"), this.subscribeToConnectTriggers(e), this.events.trigger(I.SUCCESS);
3384
+ l("handleSucceededAttempt"), this.subscribeToConnectTriggers(e), this.events.trigger(f.SUCCESS);
2713
3385
  }
2714
3386
  subscribeToConnectTriggers(e) {
2715
3387
  this.startPingRequester(e), this.registrationFailedOutOfCallSubscriber.subscribe(() => {
2716
- h("registrationFailedOutOfCallListener callback"), this.restartConnectionAttempts(e);
3388
+ l("registrationFailedOutOfCallListener callback"), this.restartConnectionAttempts(e);
2717
3389
  });
2718
3390
  }
2719
3391
  subscribeToNotActiveCall(e) {
2720
3392
  this.notActiveCallSubscriber.subscribe({
2721
3393
  onActive: () => {
2722
- h("subscribeToNotActiveCall onActive"), this.unsubscribeFromHardwareTriggers();
3394
+ l("subscribeToNotActiveCall onActive"), this.unsubscribeFromHardwareTriggers();
2723
3395
  },
2724
3396
  onInactive: () => {
2725
- h("subscribeToNotActiveCall onInactive"), this.subscribeToHardwareTriggers(e);
3397
+ l("subscribeToNotActiveCall onInactive"), this.subscribeToHardwareTriggers(e);
2726
3398
  }
2727
3399
  });
2728
3400
  }
@@ -2730,13 +3402,13 @@ class jt {
2730
3402
  this.notActiveCallSubscriber.unsubscribe();
2731
3403
  }
2732
3404
  subscribeToHardwareTriggers(e) {
2733
- this.unsubscribeFromHardwareTriggers(), h("subscribeToHardwareTriggers"), this.networkInterfacesSubscriber?.subscribe({
3405
+ this.unsubscribeFromHardwareTriggers(), l("subscribeToHardwareTriggers"), this.networkInterfacesSubscriber?.subscribe({
2734
3406
  onChange: () => {
2735
- h("networkInterfacesSubscriber onChange"), this.restartConnectionAttempts(e);
3407
+ l("networkInterfacesSubscriber onChange"), this.restartConnectionAttempts(e);
2736
3408
  },
2737
3409
  onUnavailable: () => {
2738
- h("networkInterfacesSubscriber onUnavailable"), this.stopConnectionFlow().catch((t) => {
2739
- h(
3410
+ l("networkInterfacesSubscriber onUnavailable"), this.stopConnectionFlow().catch((t) => {
3411
+ l(
2740
3412
  "auto connector stop from networkInterfacesSubscriber onUnavailable: error",
2741
3413
  t
2742
3414
  );
@@ -2744,12 +3416,12 @@ class jt {
2744
3416
  }
2745
3417
  }), this.resumeFromSleepModeSubscriber?.subscribe({
2746
3418
  onResume: () => {
2747
- h("resumeFromSleepModeSubscriber onResume"), this.restartConnectionAttempts(e);
3419
+ l("resumeFromSleepModeSubscriber onResume"), this.restartConnectionAttempts(e);
2748
3420
  }
2749
3421
  });
2750
3422
  }
2751
3423
  unsubscribeFromHardwareTriggers() {
2752
- h("unsubscribeFromHardwareTriggers"), this.networkInterfacesSubscriber?.unsubscribe(), this.resumeFromSleepModeSubscriber?.unsubscribe();
3424
+ l("unsubscribeFromHardwareTriggers"), this.networkInterfacesSubscriber?.unsubscribe(), this.resumeFromSleepModeSubscriber?.unsubscribe();
2753
3425
  }
2754
3426
  stopPingRequester() {
2755
3427
  this.pingServerIfNotActiveCallRequester.stop();
@@ -2757,18 +3429,18 @@ class jt {
2757
3429
  startPingRequester(e) {
2758
3430
  this.pingServerIfNotActiveCallRequester.start({
2759
3431
  onFailRequest: () => {
2760
- h("pingRequester: onFailRequest"), this.restartConnectionAttempts(e);
3432
+ l("pingRequester: onFailRequest"), this.restartConnectionAttempts(e);
2761
3433
  }
2762
3434
  });
2763
3435
  }
2764
3436
  connectIfDisconnected(e) {
2765
3437
  const t = this.isConnectionUnavailable();
2766
- h("connectIfDisconnected: isUnavailable", t), t ? this.restartConnectionAttempts(e) : (this.stopConnectTriggers(), this.events.trigger(I.SUCCESS));
3438
+ l("connectIfDisconnected: isUnavailable", t), t ? this.restartConnectionAttempts(e) : (this.stopConnectTriggers(), this.events.trigger(f.SUCCESS));
2767
3439
  }
2768
3440
  scheduleReconnect(e) {
2769
- h("scheduleReconnect"), this.delayBetweenAttempts.request().then(async () => (h("scheduleReconnect: delayBetweenAttempts success"), this.cancelableRequestBeforeRetry.request())).then(async () => (h("scheduleReconnect: onBeforeRetry success"), this.attemptConnection(e))).catch((t) => {
2770
- const s = t instanceof Error ? t : new Error(j.FAILED_TO_RECONNECT);
2771
- this.attemptsState.finishAttempt(), be(t) || Ue(t) ? this.events.trigger(I.CANCELLED_ATTEMPTS, s) : this.events.trigger(I.FAILED_ALL_ATTEMPTS, s), h("scheduleReconnect: error", t);
3441
+ l("scheduleReconnect"), this.delayBetweenAttempts.request().then(async () => (l("scheduleReconnect: delayBetweenAttempts success"), this.cancelableRequestBeforeRetry.request())).then(async () => (l("scheduleReconnect: onBeforeRetry success"), this.attemptConnection(e))).catch((t) => {
3442
+ const s = t instanceof Error ? t : new Error(te.FAILED_TO_RECONNECT);
3443
+ this.attemptsState.finishAttempt(), we(t) || ke(t) ? this.events.trigger(f.CANCELLED_ATTEMPTS, s) : this.events.trigger(f.FAILED_ALL_ATTEMPTS, s), l("scheduleReconnect: error", t);
2772
3444
  });
2773
3445
  }
2774
3446
  isConnectionUnavailable() {
@@ -2776,22 +3448,450 @@ class jt {
2776
3448
  return e || t || s;
2777
3449
  }
2778
3450
  emitStatusChange = ({ isInProgress: e }) => {
2779
- this.events.trigger(I.CHANGED_ATTEMPT_STATUS, { isInProgress: e });
3451
+ this.events.trigger(f.CHANGED_ATTEMPT_STATUS, { isInProgress: e });
2780
3452
  };
2781
3453
  }
2782
3454
  var U = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(U || {});
2783
- const me = [
3455
+ const Me = [
2784
3456
  "incomingCall",
2785
3457
  "declinedIncomingCall",
2786
3458
  "terminatedIncomingCall",
2787
3459
  "failedIncomingCall"
2788
- ], Zt = () => new M(me), en = 486, tn = 487;
2789
- class nn {
3460
+ ], dn = () => new O(Me);
3461
+ var hn = /* @__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))(hn || {});
3462
+ const gn = $({
3463
+ types: {
3464
+ context: {},
3465
+ events: {}
3466
+ },
3467
+ actions: {
3468
+ logTransition: (n, e) => {
3469
+ l(`State transition: ${e.from} -> ${e.to} (${e.event})`);
3470
+ },
3471
+ logStateChange: (n, e) => {
3472
+ l("IncomingCallStateMachine state changed", e.state);
3473
+ },
3474
+ rememberIncoming: b(({ event: n }) => {
3475
+ const { data: e } = n;
3476
+ return { remoteCallerData: e, lastReason: void 0 };
3477
+ }),
3478
+ rememberReason: b(({ event: n, context: e }) => n.type === "INCOMING.CONSUMED" ? {
3479
+ remoteCallerData: e.remoteCallerData,
3480
+ lastReason: "incoming:consumed"
3481
+ /* CONSUMED */
3482
+ } : n.type === "INCOMING.DECLINED" ? {
3483
+ remoteCallerData: n.data,
3484
+ lastReason: "incoming:declined"
3485
+ /* DECLINED */
3486
+ } : n.type === "INCOMING.TERMINATED" ? {
3487
+ remoteCallerData: n.data,
3488
+ lastReason: "incoming:terminated"
3489
+ /* TERMINATED */
3490
+ } : {
3491
+ remoteCallerData: n.data,
3492
+ lastReason: "incoming:failed"
3493
+ /* FAILED */
3494
+ }),
3495
+ clearIncoming: b(() => ({ remoteCallerData: void 0, lastReason: void 0 }))
3496
+ }
3497
+ }).createMachine({
3498
+ id: "incoming",
3499
+ initial: "incoming:idle",
3500
+ context: {},
3501
+ states: {
3502
+ "incoming:idle": {
3503
+ entry: {
3504
+ type: "logStateChange",
3505
+ params: {
3506
+ state: "incoming:idle"
3507
+ /* IDLE */
3508
+ }
3509
+ },
3510
+ on: {
3511
+ "INCOMING.RINGING": {
3512
+ target: "incoming:ringing",
3513
+ actions: [
3514
+ "rememberIncoming",
3515
+ {
3516
+ type: "logTransition",
3517
+ params: {
3518
+ from: "incoming:idle",
3519
+ to: "incoming:ringing",
3520
+ event: "INCOMING.RINGING"
3521
+ }
3522
+ }
3523
+ ]
3524
+ },
3525
+ "INCOMING.CLEAR": {
3526
+ target: "incoming:idle",
3527
+ actions: [
3528
+ "clearIncoming",
3529
+ {
3530
+ type: "logTransition",
3531
+ params: {
3532
+ from: "incoming:idle",
3533
+ to: "incoming:idle",
3534
+ event: "INCOMING.CLEAR"
3535
+ }
3536
+ }
3537
+ ]
3538
+ }
3539
+ }
3540
+ },
3541
+ "incoming:ringing": {
3542
+ entry: {
3543
+ type: "logStateChange",
3544
+ params: {
3545
+ state: "incoming:ringing"
3546
+ /* RINGING */
3547
+ }
3548
+ },
3549
+ on: {
3550
+ "INCOMING.RINGING": {
3551
+ target: "incoming:ringing",
3552
+ actions: [
3553
+ "rememberIncoming",
3554
+ {
3555
+ type: "logTransition",
3556
+ params: {
3557
+ from: "incoming:ringing",
3558
+ to: "incoming:ringing",
3559
+ event: "INCOMING.RINGING"
3560
+ }
3561
+ }
3562
+ ]
3563
+ },
3564
+ "INCOMING.CONSUMED": {
3565
+ target: "incoming:consumed",
3566
+ actions: [
3567
+ "rememberReason",
3568
+ {
3569
+ type: "logTransition",
3570
+ params: {
3571
+ from: "incoming:ringing",
3572
+ to: "incoming:consumed",
3573
+ event: "INCOMING.CONSUMED"
3574
+ }
3575
+ }
3576
+ ]
3577
+ },
3578
+ "INCOMING.DECLINED": {
3579
+ target: "incoming:declined",
3580
+ actions: [
3581
+ "rememberReason",
3582
+ {
3583
+ type: "logTransition",
3584
+ params: {
3585
+ from: "incoming:ringing",
3586
+ to: "incoming:declined",
3587
+ event: "INCOMING.DECLINED"
3588
+ }
3589
+ }
3590
+ ]
3591
+ },
3592
+ "INCOMING.TERMINATED": {
3593
+ target: "incoming:terminated",
3594
+ actions: [
3595
+ "rememberReason",
3596
+ {
3597
+ type: "logTransition",
3598
+ params: {
3599
+ from: "incoming:ringing",
3600
+ to: "incoming:terminated",
3601
+ event: "INCOMING.TERMINATED"
3602
+ }
3603
+ }
3604
+ ]
3605
+ },
3606
+ "INCOMING.FAILED": {
3607
+ target: "incoming:failed",
3608
+ actions: [
3609
+ "rememberReason",
3610
+ {
3611
+ type: "logTransition",
3612
+ params: {
3613
+ from: "incoming:ringing",
3614
+ to: "incoming:failed",
3615
+ event: "INCOMING.FAILED"
3616
+ }
3617
+ }
3618
+ ]
3619
+ },
3620
+ "INCOMING.CLEAR": {
3621
+ target: "incoming:idle",
3622
+ actions: [
3623
+ "clearIncoming",
3624
+ {
3625
+ type: "logTransition",
3626
+ params: {
3627
+ from: "incoming:ringing",
3628
+ to: "incoming:idle",
3629
+ event: "INCOMING.CLEAR"
3630
+ }
3631
+ }
3632
+ ]
3633
+ }
3634
+ }
3635
+ },
3636
+ "incoming:consumed": {
3637
+ entry: {
3638
+ type: "logStateChange",
3639
+ params: {
3640
+ state: "incoming:consumed"
3641
+ /* CONSUMED */
3642
+ }
3643
+ },
3644
+ on: {
3645
+ "INCOMING.CLEAR": {
3646
+ target: "incoming:idle",
3647
+ actions: [
3648
+ "clearIncoming",
3649
+ {
3650
+ type: "logTransition",
3651
+ params: {
3652
+ from: "incoming:consumed",
3653
+ to: "incoming:idle",
3654
+ event: "INCOMING.CLEAR"
3655
+ }
3656
+ }
3657
+ ]
3658
+ },
3659
+ "INCOMING.RINGING": {
3660
+ target: "incoming:ringing",
3661
+ actions: [
3662
+ "rememberIncoming",
3663
+ {
3664
+ type: "logTransition",
3665
+ params: {
3666
+ from: "incoming:consumed",
3667
+ to: "incoming:ringing",
3668
+ event: "INCOMING.RINGING"
3669
+ }
3670
+ }
3671
+ ]
3672
+ }
3673
+ }
3674
+ },
3675
+ "incoming:declined": {
3676
+ entry: {
3677
+ type: "logStateChange",
3678
+ params: {
3679
+ state: "incoming:declined"
3680
+ /* DECLINED */
3681
+ }
3682
+ },
3683
+ on: {
3684
+ "INCOMING.CLEAR": {
3685
+ target: "incoming:idle",
3686
+ actions: [
3687
+ "clearIncoming",
3688
+ {
3689
+ type: "logTransition",
3690
+ params: {
3691
+ from: "incoming:declined",
3692
+ to: "incoming:idle",
3693
+ event: "INCOMING.CLEAR"
3694
+ }
3695
+ }
3696
+ ]
3697
+ },
3698
+ "INCOMING.RINGING": {
3699
+ target: "incoming:ringing",
3700
+ actions: [
3701
+ "rememberIncoming",
3702
+ {
3703
+ type: "logTransition",
3704
+ params: {
3705
+ from: "incoming:declined",
3706
+ to: "incoming:ringing",
3707
+ event: "INCOMING.RINGING"
3708
+ }
3709
+ }
3710
+ ]
3711
+ }
3712
+ }
3713
+ },
3714
+ "incoming:terminated": {
3715
+ entry: {
3716
+ type: "logStateChange",
3717
+ params: {
3718
+ state: "incoming:terminated"
3719
+ /* TERMINATED */
3720
+ }
3721
+ },
3722
+ on: {
3723
+ "INCOMING.CLEAR": {
3724
+ target: "incoming:idle",
3725
+ actions: [
3726
+ "clearIncoming",
3727
+ {
3728
+ type: "logTransition",
3729
+ params: {
3730
+ from: "incoming:terminated",
3731
+ to: "incoming:idle",
3732
+ event: "INCOMING.CLEAR"
3733
+ }
3734
+ }
3735
+ ]
3736
+ },
3737
+ "INCOMING.RINGING": {
3738
+ target: "incoming:ringing",
3739
+ actions: [
3740
+ "rememberIncoming",
3741
+ {
3742
+ type: "logTransition",
3743
+ params: {
3744
+ from: "incoming:terminated",
3745
+ to: "incoming:ringing",
3746
+ event: "INCOMING.RINGING"
3747
+ }
3748
+ }
3749
+ ]
3750
+ }
3751
+ }
3752
+ },
3753
+ "incoming:failed": {
3754
+ entry: {
3755
+ type: "logStateChange",
3756
+ params: {
3757
+ state: "incoming:failed"
3758
+ /* FAILED */
3759
+ }
3760
+ },
3761
+ on: {
3762
+ "INCOMING.CLEAR": {
3763
+ target: "incoming:idle",
3764
+ actions: [
3765
+ "clearIncoming",
3766
+ {
3767
+ type: "logTransition",
3768
+ params: {
3769
+ from: "incoming:failed",
3770
+ to: "incoming:idle",
3771
+ event: "INCOMING.CLEAR"
3772
+ }
3773
+ }
3774
+ ]
3775
+ },
3776
+ "INCOMING.RINGING": {
3777
+ target: "incoming:ringing",
3778
+ actions: [
3779
+ "rememberIncoming",
3780
+ {
3781
+ type: "logTransition",
3782
+ params: {
3783
+ from: "incoming:failed",
3784
+ to: "incoming:ringing",
3785
+ event: "INCOMING.RINGING"
3786
+ }
3787
+ }
3788
+ ]
3789
+ }
3790
+ }
3791
+ }
3792
+ }
3793
+ });
3794
+ class un extends q {
3795
+ constructor({ incomingEvents: e, connectionEvents: t }) {
3796
+ super(gn), this.subscribeIncomingEvents(e), this.subscribeConnectionEvents(t);
3797
+ }
3798
+ get isIdle() {
3799
+ return this.state === "incoming:idle";
3800
+ }
3801
+ get isRinging() {
3802
+ return this.state === "incoming:ringing";
3803
+ }
3804
+ get isConsumed() {
3805
+ return this.state === "incoming:consumed";
3806
+ }
3807
+ get isDeclined() {
3808
+ return this.state === "incoming:declined";
3809
+ }
3810
+ get isTerminated() {
3811
+ return this.state === "incoming:terminated";
3812
+ }
3813
+ get isFailed() {
3814
+ return this.state === "incoming:failed";
3815
+ }
3816
+ get isActive() {
3817
+ return this.isRinging;
3818
+ }
3819
+ get isFinished() {
3820
+ return this.isConsumed || this.isDeclined || this.isTerminated || this.isFailed;
3821
+ }
3822
+ get remoteCallerData() {
3823
+ return this.getSnapshot().context.remoteCallerData;
3824
+ }
3825
+ get lastReason() {
3826
+ return this.getSnapshot().context.lastReason;
3827
+ }
3828
+ reset() {
3829
+ this.send({ type: "INCOMING.CLEAR" });
3830
+ }
3831
+ send(e) {
3832
+ if (!this.getSnapshot().can(e)) {
3833
+ console.warn(
3834
+ `[IncomingCallStateMachine] Invalid transition: ${e.type} from ${this.state}. Event cannot be processed in current state.`
3835
+ );
3836
+ return;
3837
+ }
3838
+ super.send(e);
3839
+ }
3840
+ toConsumed() {
3841
+ this.send({ type: "INCOMING.CONSUMED" });
3842
+ }
3843
+ subscribeIncomingEvents(e) {
3844
+ this.addSubscription(
3845
+ e.on("incomingCall", (t) => {
3846
+ this.send({ type: "INCOMING.RINGING", data: t });
3847
+ })
3848
+ ), this.addSubscription(
3849
+ e.on("declinedIncomingCall", (t) => {
3850
+ this.send({ type: "INCOMING.DECLINED", data: t });
3851
+ })
3852
+ ), this.addSubscription(
3853
+ e.on("terminatedIncomingCall", (t) => {
3854
+ this.send({ type: "INCOMING.TERMINATED", data: t });
3855
+ })
3856
+ ), this.addSubscription(
3857
+ e.on("failedIncomingCall", (t) => {
3858
+ this.send({ type: "INCOMING.FAILED", data: t });
3859
+ })
3860
+ );
3861
+ }
3862
+ subscribeConnectionEvents(e) {
3863
+ this.addSubscription(
3864
+ e.on(S.DISCONNECTED, () => {
3865
+ this.toClearIncoming();
3866
+ })
3867
+ ), this.addSubscription(
3868
+ e.on(S.REGISTRATION_FAILED, () => {
3869
+ this.toClearIncoming();
3870
+ })
3871
+ ), this.addSubscription(
3872
+ e.on(S.CONNECT_FAILED, () => {
3873
+ this.toClearIncoming();
3874
+ })
3875
+ );
3876
+ }
3877
+ toClearIncoming() {
3878
+ this.send({ type: "INCOMING.CLEAR" });
3879
+ }
3880
+ }
3881
+ const Tn = 486, En = 487;
3882
+ class Cn {
2790
3883
  events;
3884
+ incomingStateMachine;
2791
3885
  incomingRTCSession;
2792
3886
  connectionManager;
2793
3887
  constructor(e) {
2794
- this.connectionManager = e, this.events = Zt(), this.start();
3888
+ this.connectionManager = e, this.events = dn(), this.incomingStateMachine = new un({
3889
+ incomingEvents: this.events,
3890
+ connectionEvents: this.connectionManager.events
3891
+ }), this.start();
3892
+ }
3893
+ get incomingActor() {
3894
+ return this.incomingStateMachine.actorRef;
2795
3895
  }
2796
3896
  get remoteCallerData() {
2797
3897
  return {
@@ -2818,10 +3918,10 @@ class nn {
2818
3918
  };
2819
3919
  extractIncomingRTCSession = () => {
2820
3920
  const e = this.getIncomingRTCSession();
2821
- return this.removeIncomingSession(), e;
3921
+ return this.incomingStateMachine.toConsumed(), this.removeIncomingSession(), e;
2822
3922
  };
2823
3923
  async declineToIncomingCall({
2824
- statusCode: e = tn
3924
+ statusCode: e = En
2825
3925
  } = {}) {
2826
3926
  return new Promise((t, s) => {
2827
3927
  try {
@@ -2833,7 +3933,7 @@ class nn {
2833
3933
  });
2834
3934
  }
2835
3935
  async busyIncomingCall() {
2836
- return this.declineToIncomingCall({ statusCode: en });
3936
+ return this.declineToIncomingCall({ statusCode: Tn });
2837
3937
  }
2838
3938
  on(e, t) {
2839
3939
  return this.events.on(e, t);
@@ -2873,9 +3973,56 @@ class nn {
2873
3973
  delete this.incomingRTCSession;
2874
3974
  }
2875
3975
  }
2876
- const w = 1e3;
2877
- var E = /* @__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))(E || {});
2878
- const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer", an = async ({
3976
+ const Sn = (n, e) => Object.is(n, e), ne = (n) => ({
3977
+ connection: n.connection.getSnapshot(),
3978
+ call: n.call.getSnapshot(),
3979
+ incoming: n.incoming.getSnapshot(),
3980
+ presentation: n.presentation.getSnapshot()
3981
+ }), pn = (n) => {
3982
+ const e = {
3983
+ connection: n.connectionManager.connectionActor,
3984
+ call: n.callManager.callActor,
3985
+ incoming: n.incomingCallManager.incomingActor,
3986
+ presentation: n.presentationManager.presentationActor
3987
+ };
3988
+ let t = ne(e);
3989
+ const s = /* @__PURE__ */ new Set(), i = () => {
3990
+ t = ne(e);
3991
+ for (const a of s) {
3992
+ const c = a.selector(t);
3993
+ a.equals(a.current, c) || (a.current = c, a.listener(c));
3994
+ }
3995
+ }, r = [
3996
+ e.connection.subscribe(i),
3997
+ e.call.subscribe(i),
3998
+ e.incoming.subscribe(i),
3999
+ e.presentation.subscribe(i)
4000
+ ];
4001
+ function o(a, c, d) {
4002
+ const T = typeof c == "function", h = T ? a : (D) => D, u = T ? c : a, p = (T ? d : void 0) ?? Sn, A = h(t), N = {
4003
+ selector: h,
4004
+ listener: u,
4005
+ equals: p,
4006
+ current: A
4007
+ };
4008
+ return s.add(N), () => {
4009
+ s.delete(N);
4010
+ };
4011
+ }
4012
+ return {
4013
+ actor: e,
4014
+ actors: e,
4015
+ getSnapshot: () => t,
4016
+ subscribe: o,
4017
+ stop: () => {
4018
+ s.clear(), r.forEach((a) => {
4019
+ a.unsubscribe();
4020
+ });
4021
+ }
4022
+ };
4023
+ }, w = 1e3;
4024
+ var m = /* @__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))(m || {});
4025
+ const ve = ["collected"], mn = () => new O(ve), Nn = "api/v2/rtp2webrtc/offer", Rn = async ({
2879
4026
  serverUrl: n,
2880
4027
  conferenceNumber: e,
2881
4028
  quality: t,
@@ -2883,10 +4030,10 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2883
4030
  offer: i
2884
4031
  }) => {
2885
4032
  const r = new URL(
2886
- `https://${n.replace(/\/$/, "")}/${rn}/${encodeURIComponent(e)}`
4033
+ `https://${n.replace(/\/$/, "")}/${Nn}/${encodeURIComponent(e)}`
2887
4034
  );
2888
4035
  r.searchParams.set("quality", t), r.searchParams.set("audio", String(s));
2889
- const a = await fetch(r.toString(), {
4036
+ const o = await fetch(r.toString(), {
2890
4037
  method: "POST",
2891
4038
  headers: {
2892
4039
  "Content-Type": "application/json"
@@ -2894,20 +4041,20 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2894
4041
  credentials: "same-origin",
2895
4042
  body: JSON.stringify(i)
2896
4043
  });
2897
- if (!a.ok)
2898
- throw new Error(`sendOffer failed with status ${a.status}`);
2899
- const o = await a.json();
4044
+ if (!o.ok)
4045
+ throw new Error(`sendOffer failed with status ${o.status}`);
4046
+ const a = await o.json();
2900
4047
  return {
2901
- type: o.type,
2902
- sdp: o.sdp,
4048
+ type: a.type,
4049
+ sdp: a.sdp,
2903
4050
  toJSON() {
2904
- return o;
4051
+ return a;
2905
4052
  }
2906
4053
  };
2907
- }, Z = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
4054
+ }, se = () => "performance" in window ? performance.now() : Date.now(), F = (n) => [...n.keys()].reduce((e, t) => {
2908
4055
  const s = n.get(t);
2909
4056
  return s === void 0 ? e : { ...e, [s.type]: s };
2910
- }, {}), on = (n) => {
4057
+ }, {}), An = (n) => {
2911
4058
  if (!n)
2912
4059
  return {
2913
4060
  outboundRtp: void 0,
@@ -2915,14 +4062,14 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2915
4062
  mediaSource: void 0,
2916
4063
  remoteInboundRtp: void 0
2917
4064
  };
2918
- const e = L(n);
4065
+ const e = F(n);
2919
4066
  return {
2920
- outboundRtp: e[E.OUTBOUND_RTP],
2921
- codec: e[E.CODEC],
2922
- mediaSource: e[E.MEDIA_SOURCE],
2923
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
4067
+ outboundRtp: e[m.OUTBOUND_RTP],
4068
+ codec: e[m.CODEC],
4069
+ mediaSource: e[m.MEDIA_SOURCE],
4070
+ remoteInboundRtp: e[m.REMOTE_INBOUND_RTP]
2924
4071
  };
2925
- }, ee = (n) => {
4072
+ }, ie = (n) => {
2926
4073
  if (!n)
2927
4074
  return {
2928
4075
  outboundRtp: void 0,
@@ -2930,14 +4077,14 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2930
4077
  mediaSource: void 0,
2931
4078
  remoteInboundRtp: void 0
2932
4079
  };
2933
- const e = L(n);
4080
+ const e = F(n);
2934
4081
  return {
2935
- outboundRtp: e[E.OUTBOUND_RTP],
2936
- codec: e[E.CODEC],
2937
- mediaSource: e[E.MEDIA_SOURCE],
2938
- remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
4082
+ outboundRtp: e[m.OUTBOUND_RTP],
4083
+ codec: e[m.CODEC],
4084
+ mediaSource: e[m.MEDIA_SOURCE],
4085
+ remoteInboundRtp: e[m.REMOTE_INBOUND_RTP]
2939
4086
  };
2940
- }, te = ({
4087
+ }, re = ({
2941
4088
  videoReceiversStats: n,
2942
4089
  synchronizationSourcesVideo: e
2943
4090
  }) => {
@@ -2947,13 +4094,13 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2947
4094
  codec: void 0,
2948
4095
  synchronizationSources: e
2949
4096
  };
2950
- const t = L(n);
4097
+ const t = F(n);
2951
4098
  return {
2952
- inboundRtp: t[E.INBOUND_RTP],
2953
- codec: t[E.CODEC],
4099
+ inboundRtp: t[m.INBOUND_RTP],
4100
+ codec: t[m.CODEC],
2954
4101
  synchronizationSources: e
2955
4102
  };
2956
- }, cn = ({
4103
+ }, In = ({
2957
4104
  audioReceiverStats: n,
2958
4105
  synchronizationSourcesAudio: e
2959
4106
  }) => {
@@ -2964,14 +4111,14 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2964
4111
  remoteOutboundRtp: void 0,
2965
4112
  synchronizationSources: e
2966
4113
  };
2967
- const t = L(n);
4114
+ const t = F(n);
2968
4115
  return {
2969
- inboundRtp: t[E.INBOUND_RTP],
2970
- codec: t[E.CODEC],
2971
- remoteOutboundRtp: t[E.REMOTE_OUTBOUND_RTP],
4116
+ inboundRtp: t[m.INBOUND_RTP],
4117
+ codec: t[m.CODEC],
4118
+ remoteOutboundRtp: t[m.REMOTE_OUTBOUND_RTP],
2972
4119
  synchronizationSources: e
2973
4120
  };
2974
- }, Ie = (n) => {
4121
+ }, _e = (n) => {
2975
4122
  if (!n)
2976
4123
  return {
2977
4124
  candidatePair: void 0,
@@ -2980,122 +4127,122 @@ const Ne = ["collected"], sn = () => new M(Ne), rn = "api/v2/rtp2webrtc/offer",
2980
4127
  remoteCandidate: void 0,
2981
4128
  transport: void 0
2982
4129
  };
2983
- const e = L(n);
4130
+ const e = F(n);
2984
4131
  return {
2985
- candidatePair: e[E.CANDIDATE_PAIR],
2986
- certificate: e[E.CERTIFICATE],
2987
- localCandidate: e[E.LOCAL_CANDIDATE],
2988
- remoteCandidate: e[E.REMOTE_CANDIDATE],
2989
- transport: e[E.TRANSPORT]
4132
+ candidatePair: e[m.CANDIDATE_PAIR],
4133
+ certificate: e[m.CERTIFICATE],
4134
+ localCandidate: e[m.LOCAL_CANDIDATE],
4135
+ remoteCandidate: e[m.REMOTE_CANDIDATE],
4136
+ transport: e[m.TRANSPORT]
2990
4137
  };
2991
- }, hn = ({
4138
+ }, fn = ({
2992
4139
  audioSenderStats: n,
2993
4140
  videoSenderFirstStats: e,
2994
4141
  videoSenderSecondStats: t
2995
4142
  }) => ({
2996
- video: ee(e),
2997
- secondVideo: ee(t),
2998
- audio: on(n),
2999
- additional: Ie(
4143
+ video: ie(e),
4144
+ secondVideo: ie(t),
4145
+ audio: An(n),
4146
+ additional: _e(
3000
4147
  n ?? e ?? t
3001
4148
  )
3002
- }), dn = ({
4149
+ }), Mn = ({
3003
4150
  audioReceiverStats: n,
3004
4151
  videoReceiverFirstStats: e,
3005
4152
  videoReceiverSecondStats: t,
3006
4153
  synchronizationSources: s
3007
4154
  }) => ({
3008
- video: te({
4155
+ video: re({
3009
4156
  videoReceiversStats: e,
3010
4157
  synchronizationSourcesVideo: s.video
3011
4158
  }),
3012
- secondVideo: te({
4159
+ secondVideo: re({
3013
4160
  videoReceiversStats: t,
3014
4161
  synchronizationSourcesVideo: s.video
3015
4162
  }),
3016
- audio: cn({
4163
+ audio: In({
3017
4164
  audioReceiverStats: n,
3018
4165
  synchronizationSourcesAudio: s.audio
3019
4166
  }),
3020
- additional: Ie(
4167
+ additional: _e(
3021
4168
  n ?? e ?? t
3022
4169
  )
3023
- }), ln = ({
4170
+ }), vn = ({
3024
4171
  audioSenderStats: n,
3025
4172
  videoSenderFirstStats: e,
3026
4173
  videoSenderSecondStats: t,
3027
4174
  audioReceiverStats: s,
3028
4175
  videoReceiverFirstStats: i,
3029
4176
  videoReceiverSecondStats: r,
3030
- synchronizationSources: a
4177
+ synchronizationSources: o
3031
4178
  }) => {
3032
- const o = hn({
4179
+ const a = fn({
3033
4180
  audioSenderStats: n,
3034
4181
  videoSenderFirstStats: e,
3035
4182
  videoSenderSecondStats: t
3036
- }), c = dn({
4183
+ }), c = Mn({
3037
4184
  audioReceiverStats: s,
3038
4185
  videoReceiverFirstStats: i,
3039
4186
  videoReceiverSecondStats: r,
3040
- synchronizationSources: a
4187
+ synchronizationSources: o
3041
4188
  });
3042
4189
  return {
3043
- outbound: o,
4190
+ outbound: a,
3044
4191
  inbound: c
3045
4192
  };
3046
- }, un = async (n) => {
3047
- const e = "audio", t = "video", s = n.getSenders(), i = s.find((T) => T.track?.kind === e), r = s.filter((T) => T.track?.kind === t), a = n.getReceivers(), o = a.find((T) => T.track.kind === e), c = a.filter((T) => T.track.kind === t), d = {
3048
- trackIdentifier: o?.track.id,
3049
- item: o?.getSynchronizationSources()[0]
3050
- }, S = {
4193
+ }, _n = async (n) => {
4194
+ const e = "audio", t = "video", s = n.getSenders(), i = s.find((u) => u.track?.kind === e), r = s.filter((u) => u.track?.kind === t), o = n.getReceivers(), a = o.find((u) => u.track.kind === e), c = o.filter((u) => u.track.kind === t), d = {
4195
+ trackIdentifier: a?.track.id,
4196
+ item: a?.getSynchronizationSources()[0]
4197
+ }, T = {
3051
4198
  trackIdentifier: c[0]?.track.id,
3052
4199
  item: c[0]?.getSynchronizationSources()[0]
3053
- }, g = {
4200
+ }, h = {
3054
4201
  audio: d,
3055
- video: S
4202
+ video: T
3056
4203
  };
3057
4204
  return Promise.all([
3058
4205
  i?.getStats() ?? Promise.resolve(void 0),
3059
4206
  r[0]?.getStats() ?? Promise.resolve(void 0),
3060
4207
  r[1]?.getStats() ?? Promise.resolve(void 0),
3061
- o?.getStats() ?? Promise.resolve(void 0),
4208
+ a?.getStats() ?? Promise.resolve(void 0),
3062
4209
  c[0]?.getStats() ?? Promise.resolve(void 0),
3063
4210
  c[1]?.getStats() ?? Promise.resolve(void 0)
3064
- ]).then((T) => {
4211
+ ]).then((u) => {
3065
4212
  const [
3066
4213
  p,
3067
- P,
3068
4214
  A,
3069
- y,
3070
- $,
3071
- Oe
3072
- ] = T;
4215
+ N,
4216
+ D,
4217
+ V,
4218
+ Le
4219
+ ] = u;
3073
4220
  return {
3074
- synchronizationSources: g,
4221
+ synchronizationSources: h,
3075
4222
  audioSenderStats: p,
3076
- videoSenderFirstStats: P,
3077
- videoSenderSecondStats: A,
3078
- audioReceiverStats: y,
3079
- videoReceiverFirstStats: $,
3080
- videoReceiverSecondStats: Oe
4223
+ videoSenderFirstStats: A,
4224
+ videoSenderSecondStats: N,
4225
+ audioReceiverStats: D,
4226
+ videoReceiverFirstStats: V,
4227
+ videoReceiverSecondStats: Le
3081
4228
  };
3082
4229
  });
3083
- }, gn = (n) => {
3084
- h(String(n));
4230
+ }, On = (n) => {
4231
+ l(String(n));
3085
4232
  };
3086
- class Tn {
4233
+ class Pn {
3087
4234
  events;
3088
4235
  setTimeoutRequest;
3089
- requesterAllStatistics = new k(un);
4236
+ requesterAllStatistics = new G(_n);
3090
4237
  constructor() {
3091
- this.events = sn(), this.setTimeoutRequest = new se();
4238
+ this.events = mn(), this.setTimeoutRequest = new oe();
3092
4239
  }
3093
4240
  get requested() {
3094
4241
  return this.setTimeoutRequest.requested;
3095
4242
  }
3096
4243
  start(e, {
3097
4244
  interval: t = w,
3098
- onError: s = gn
4245
+ onError: s = On
3099
4246
  } = {}) {
3100
4247
  this.stop(), this.setTimeoutRequest.request(() => {
3101
4248
  this.collectStatistics(e, {
@@ -3124,21 +4271,21 @@ class Tn {
3124
4271
  collectStatistics = (e, {
3125
4272
  onError: t
3126
4273
  }) => {
3127
- const s = Z();
4274
+ const s = se();
3128
4275
  this.requesterAllStatistics.request(e).then((i) => {
3129
- this.events.trigger("collected", ln(i));
3130
- const a = Z() - s;
3131
- let o = w;
3132
- a > 48 ? o = w * 4 : a > 32 ? o = w * 3 : a > 16 && (o = w * 2), this.start(e, {
4276
+ this.events.trigger("collected", vn(i));
4277
+ const o = se() - s;
4278
+ let a = w;
4279
+ o > 48 ? a = w * 4 : o > 32 ? a = w * 3 : o > 16 && (a = w * 2), this.start(e, {
3133
4280
  onError: t,
3134
- interval: o
4281
+ interval: a
3135
4282
  });
3136
4283
  }).catch((i) => {
3137
4284
  t && t(i);
3138
4285
  });
3139
4286
  };
3140
4287
  }
3141
- class Sn {
4288
+ class bn {
3142
4289
  statsPeerConnection;
3143
4290
  availableStats;
3144
4291
  previousAvailableStats;
@@ -3148,7 +4295,7 @@ class Sn {
3148
4295
  callManager: e,
3149
4296
  apiManager: t
3150
4297
  }) {
3151
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Tn(), this.subscribe();
4298
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new Pn(), this.subscribe();
3152
4299
  }
3153
4300
  get events() {
3154
4301
  return this.statsPeerConnection.events;
@@ -3221,37 +4368,37 @@ class Sn {
3221
4368
  };
3222
4369
  maybeSendStats() {
3223
4370
  this.availableIncomingBitrate !== void 0 && this.hasAvailableIncomingBitrateChangedQuarter() && this.apiManager.sendStats({ availableIncomingBitrate: this.availableIncomingBitrate }).catch((e) => {
3224
- h("Failed to send stats", e);
4371
+ l("Failed to send stats", e);
3225
4372
  });
3226
4373
  }
3227
4374
  }
3228
- const Cn = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), En = (n) => {
4375
+ const Dn = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), yn = (n) => {
3229
4376
  const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
3230
- return Cn(s, i);
3231
- }, pn = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
3232
- 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;
3233
- return a - o;
3234
- }), Rn = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), An = (n, {
4377
+ return Dn(s, i);
4378
+ }, Ln = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
4379
+ const i = e.indexOf(t.mimeType), r = e.indexOf(s.mimeType), o = i === -1 ? Number.MAX_VALUE : i, a = r === -1 ? Number.MAX_VALUE : r;
4380
+ return o - a;
4381
+ }), wn = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), Un = (n, {
3235
4382
  preferredMimeTypesVideoCodecs: e,
3236
4383
  excludeMimeTypesVideoCodecs: t
3237
4384
  }) => {
3238
4385
  try {
3239
4386
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
3240
- const s = En("video"), i = Rn(s, t), r = pn(i, e);
4387
+ const s = yn("video"), i = wn(s, t), r = Ln(i, e);
3241
4388
  n.setCodecPreferences(r);
3242
4389
  }
3243
4390
  } catch (s) {
3244
- h("setCodecPreferences error", s);
4391
+ l("setCodecPreferences error", s);
3245
4392
  }
3246
- }, mn = (n) => [...n.keys()].map((e) => n.get(e)), Nn = (n, e) => mn(n).find((t) => t?.type === e), In = async (n) => n.getStats().then((e) => Nn(e, "codec")?.mimeType);
3247
- class vn {
4393
+ }, Fn = (n) => [...n.keys()].map((e) => n.get(e)), Bn = (n, e) => Fn(n).find((t) => t?.type === e), kn = async (n) => n.getStats().then((e) => Bn(e, "codec")?.mimeType);
4394
+ class Gn {
3248
4395
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
3249
4396
  async getCodecFromSender(e) {
3250
- return await In(e) ?? "";
4397
+ return await kn(e) ?? "";
3251
4398
  }
3252
4399
  }
3253
- class _n {
3254
- stackPromises = re({
4400
+ class $n {
4401
+ stackPromises = le({
3255
4402
  noRunIsNotActual: !0
3256
4403
  });
3257
4404
  /**
@@ -3271,34 +4418,34 @@ class _n {
3271
4418
  */
3272
4419
  async run() {
3273
4420
  return this.stackPromises().catch((e) => {
3274
- h("TaskQueue: error", e);
4421
+ l("TaskQueue: error", e);
3275
4422
  });
3276
4423
  }
3277
4424
  }
3278
- class fn {
4425
+ class qn {
3279
4426
  taskQueue;
3280
4427
  onSetParameters;
3281
4428
  constructor(e) {
3282
- this.onSetParameters = e, this.taskQueue = new _n();
4429
+ this.onSetParameters = e, this.taskQueue = new $n();
3283
4430
  }
3284
4431
  async setEncodingsToSender(e, t) {
3285
- return this.taskQueue.add(async () => ge(e, t, this.onSetParameters));
4432
+ return this.taskQueue.add(async () => Se(e, t, this.onSetParameters));
3286
4433
  }
3287
4434
  stop() {
3288
4435
  this.taskQueue.stop();
3289
4436
  }
3290
4437
  }
3291
- const ve = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Mn = 1e6, v = (n) => n * Mn, _e = v(0.06), fe = v(4), Pn = (n) => n <= 64 ? _e : n <= 128 ? v(0.12) : n <= 256 ? v(0.25) : n <= 384 ? v(0.32) : n <= 426 ? v(0.38) : n <= 640 ? v(0.5) : n <= 848 ? v(0.7) : n <= 1280 ? v(1) : n <= 1920 ? v(2) : fe, On = "av1", bn = (n) => ve(n, On), yn = 0.6, z = (n, e) => bn(e) ? n * yn : n, Dn = (n) => z(_e, n), wn = (n) => z(fe, n), ne = (n, e) => {
3292
- const t = Pn(n);
3293
- return z(t, e);
3294
- }, V = 1, Un = ({
4438
+ const Oe = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Vn = 1e6, M = (n) => n * Vn, Pe = M(0.06), be = M(4), Hn = (n) => n <= 64 ? Pe : n <= 128 ? M(0.12) : n <= 256 ? M(0.25) : n <= 384 ? M(0.32) : n <= 426 ? M(0.38) : n <= 640 ? M(0.5) : n <= 848 ? M(0.7) : n <= 1280 ? M(1) : n <= 1920 ? M(2) : be, Wn = "av1", xn = (n) => Oe(n, Wn), Qn = 0.6, K = (n, e) => xn(e) ? n * Qn : n, Yn = (n) => K(Pe, n), zn = (n) => K(be, n), ae = (n, e) => {
4439
+ const t = Hn(n);
4440
+ return K(t, e);
4441
+ }, W = 1, Xn = ({
3295
4442
  videoTrack: n,
3296
4443
  targetSize: e
3297
4444
  }) => {
3298
- const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? V : s / e.width, a = i === void 0 ? V : i / e.height;
3299
- return Math.max(r, a, V);
4445
+ const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? W : s / e.width, o = i === void 0 ? W : i / e.height;
4446
+ return Math.max(r, o, W);
3300
4447
  };
3301
- class Ln {
4448
+ class Jn {
3302
4449
  ignoreForCodec;
3303
4450
  senderFinder;
3304
4451
  codecProvider;
@@ -3331,11 +4478,11 @@ class Ln {
3331
4478
  if (!i?.track)
3332
4479
  return { ...this.resultNoChanged, sender: i };
3333
4480
  const r = await this.codecProvider.getCodecFromSender(i);
3334
- if (ve(r, this.ignoreForCodec))
4481
+ if (Oe(r, this.ignoreForCodec))
3335
4482
  return { ...this.resultNoChanged, sender: i };
3336
- const { mainCam: a, resolutionMainCam: o } = t ?? {};
4483
+ const { mainCam: o, resolutionMainCam: a } = t ?? {};
3337
4484
  return this.processSender(
3338
- { mainCam: a, resolutionMainCam: o },
4485
+ { mainCam: o, resolutionMainCam: a },
3339
4486
  {
3340
4487
  sender: i,
3341
4488
  codec: r,
@@ -3351,14 +4498,14 @@ class Ln {
3351
4498
  async processSender(e, t) {
3352
4499
  const { mainCam: s, resolutionMainCam: i } = e;
3353
4500
  switch (s) {
3354
- case _.PAUSE_MAIN_CAM:
4501
+ case v.PAUSE_MAIN_CAM:
3355
4502
  return this.downgradeResolutionSender(t);
3356
- case _.RESUME_MAIN_CAM:
4503
+ case v.RESUME_MAIN_CAM:
3357
4504
  return this.setBitrateByTrackResolution(t);
3358
- case _.MAX_MAIN_CAM_RESOLUTION:
4505
+ case v.MAX_MAIN_CAM_RESOLUTION:
3359
4506
  return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
3360
- case _.ADMIN_STOP_MAIN_CAM:
3361
- case _.ADMIN_START_MAIN_CAM:
4507
+ case v.ADMIN_STOP_MAIN_CAM:
4508
+ case v.ADMIN_START_MAIN_CAM:
3362
4509
  case void 0:
3363
4510
  return this.setBitrateByTrackResolution(t);
3364
4511
  default:
@@ -3373,7 +4520,7 @@ class Ln {
3373
4520
  async downgradeResolutionSender(e) {
3374
4521
  const { sender: t, codec: s } = e, i = {
3375
4522
  scaleResolutionDownBy: 200,
3376
- maxBitrate: Dn(s)
4523
+ maxBitrate: Yn(s)
3377
4524
  };
3378
4525
  return this.parametersSetter.setEncodingsToSender(t, i);
3379
4526
  }
@@ -3383,10 +4530,10 @@ class Ln {
3383
4530
  * @returns Promise с результатом
3384
4531
  */
3385
4532
  async setBitrateByTrackResolution(e) {
3386
- const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? wn(i) : ne(a, i);
4533
+ const { sender: t, videoTrack: s, codec: i } = e, o = s.getSettings().width, a = o === void 0 ? zn(i) : ae(o, i);
3387
4534
  return this.parametersSetter.setEncodingsToSender(t, {
3388
4535
  scaleResolutionDownBy: 1,
3389
- maxBitrate: o
4536
+ maxBitrate: a
3390
4537
  });
3391
4538
  }
3392
4539
  /**
@@ -3396,27 +4543,27 @@ class Ln {
3396
4543
  * @returns Promise с результатом
3397
4544
  */
3398
4545
  async setResolutionSender(e, t) {
3399
- const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
4546
+ const [s, i] = e.split("x"), { sender: r, videoTrack: o, codec: a } = t, c = {
3400
4547
  width: Number(s),
3401
4548
  height: Number(i)
3402
- }, d = Un({
3403
- videoTrack: a,
4549
+ }, d = Xn({
4550
+ videoTrack: o,
3404
4551
  targetSize: c
3405
- }), S = ne(c.width, o), g = {
4552
+ }), T = ae(c.width, a), h = {
3406
4553
  scaleResolutionDownBy: d,
3407
- maxBitrate: S
4554
+ maxBitrate: T
3408
4555
  };
3409
- return this.parametersSetter.setEncodingsToSender(r, g);
4556
+ return this.parametersSetter.setEncodingsToSender(r, h);
3410
4557
  }
3411
4558
  }
3412
- const Fn = (n) => n.find((e) => e.track?.kind === "video");
3413
- class Bn {
4559
+ const Kn = (n) => n.find((e) => e.track?.kind === "video");
4560
+ class jn {
3414
4561
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
3415
4562
  findVideoSender(e) {
3416
- return Fn(e);
4563
+ return Kn(e);
3417
4564
  }
3418
4565
  }
3419
- class kn {
4566
+ class Zn {
3420
4567
  currentSender;
3421
4568
  originalReplaceTrack;
3422
4569
  lastWidth;
@@ -3429,7 +4576,7 @@ class kn {
3429
4576
  pollIntervalMs: e = 1e3,
3430
4577
  maxPollIntervalMs: t
3431
4578
  }) {
3432
- this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new se();
4579
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new oe();
3433
4580
  }
3434
4581
  /**
3435
4582
  * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
@@ -3480,7 +4627,7 @@ class kn {
3480
4627
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
3481
4628
  }
3482
4629
  }
3483
- class $n {
4630
+ class es {
3484
4631
  apiManager;
3485
4632
  currentHandler;
3486
4633
  constructor(e) {
@@ -3500,7 +4647,7 @@ class $n {
3500
4647
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
3501
4648
  }
3502
4649
  }
3503
- class qn {
4650
+ class ts {
3504
4651
  eventHandler;
3505
4652
  senderBalancer;
3506
4653
  parametersSetterWithQueue;
@@ -3512,16 +4659,16 @@ class qn {
3512
4659
  onSetParameters: i,
3513
4660
  pollIntervalMs: r
3514
4661
  } = {}) {
3515
- this.getConnection = t, this.eventHandler = new $n(e), this.parametersSetterWithQueue = new fn(i), this.senderBalancer = new Ln(
4662
+ this.getConnection = t, this.eventHandler = new es(e), this.parametersSetterWithQueue = new qn(i), this.senderBalancer = new Jn(
3516
4663
  {
3517
- senderFinder: new Bn(),
3518
- codecProvider: new vn(),
4664
+ senderFinder: new jn(),
4665
+ codecProvider: new Gn(),
3519
4666
  parametersSetter: this.parametersSetterWithQueue
3520
4667
  },
3521
4668
  {
3522
4669
  ignoreForCodec: s
3523
4670
  }
3524
- ), this.trackMonitor = new kn({ pollIntervalMs: r });
4671
+ ), this.trackMonitor = new Zn({ pollIntervalMs: r });
3525
4672
  }
3526
4673
  /**
3527
4674
  * Подписывается на события управления главной камерой
@@ -3552,7 +4699,7 @@ class qn {
3552
4699
  const t = await this.senderBalancer.balance(e, this.serverHeaders);
3553
4700
  return this.trackMonitor.subscribe(t.sender, () => {
3554
4701
  this.balance().catch((s) => {
3555
- h("balance on track change: error", s);
4702
+ l("balance on track change: error", s);
3556
4703
  });
3557
4704
  }), t;
3558
4705
  }
@@ -3562,17 +4709,17 @@ class qn {
3562
4709
  */
3563
4710
  handleMainCamControl = (e) => {
3564
4711
  this.serverHeaders = e, this.balance().catch((t) => {
3565
- h("handleMainCamControl: error", t);
4712
+ l("handleMainCamControl: error", t);
3566
4713
  });
3567
4714
  };
3568
4715
  }
3569
- const Me = [
4716
+ const De = [
3570
4717
  "balancing-scheduled",
3571
4718
  "balancing-started",
3572
4719
  "balancing-stopped",
3573
4720
  "parameters-updated"
3574
- ], Vn = () => new M(Me);
3575
- class Hn {
4721
+ ], ns = () => new O(De);
4722
+ class ss {
3576
4723
  isBalancingActive = !1;
3577
4724
  events;
3578
4725
  callManager;
@@ -3580,7 +4727,7 @@ class Hn {
3580
4727
  videoSendingBalancer;
3581
4728
  startBalancingTimer;
3582
4729
  constructor(e, t, s = {}) {
3583
- this.events = Vn(), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new qn(
4730
+ this.events = ns(), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new ts(
3584
4731
  t,
3585
4732
  () => e.connection,
3586
4733
  {
@@ -3642,7 +4789,7 @@ class Hn {
3642
4789
  scheduleBalancingStart() {
3643
4790
  this.clearStartTimer(), this.startBalancingTimer = setTimeout(() => {
3644
4791
  this.startBalancingTimer = void 0, this.startBalancing().catch((e) => {
3645
- h("startBalancing: error", e);
4792
+ l("startBalancing: error", e);
3646
4793
  });
3647
4794
  }, this.balancingStartDelay), this.events.trigger("balancing-scheduled", { delay: this.balancingStartDelay });
3648
4795
  }
@@ -3650,13 +4797,13 @@ class Hn {
3650
4797
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
3651
4798
  }
3652
4799
  }
3653
- const Pe = "no-inbound-frames", Wn = [Pe], Gn = () => new M(Wn);
3654
- class xn {
4800
+ const ye = "no-inbound-frames", is = [ye], rs = () => new O(is);
4801
+ class as {
3655
4802
  events;
3656
4803
  statsManager;
3657
4804
  callManager;
3658
4805
  constructor(e, t) {
3659
- this.statsManager = e, this.callManager = t, this.events = Gn(), this.subscribe();
4806
+ this.statsManager = e, this.callManager = t, this.events = rs(), this.subscribe();
3660
4807
  }
3661
4808
  get mainVideoTrack() {
3662
4809
  return this.callManager.getMainStream()?.getVideoTracks()[0];
@@ -3669,36 +4816,36 @@ class xn {
3669
4816
  return this.events.on(e, t);
3670
4817
  }
3671
4818
  handleStatsCollected = () => {
3672
- this.hasNoIncomingFrames() && this.events.trigger(Pe, {});
4819
+ this.hasNoIncomingFrames() && this.events.trigger(ye, {});
3673
4820
  };
3674
4821
  hasNoIncomingFrames = () => this.statsManager.isNotValidFramesStats && this.isMutedMainVideoTrack;
3675
4822
  subscribe() {
3676
4823
  this.statsManager.on("collected", this.handleStatsCollected);
3677
4824
  }
3678
4825
  }
3679
- const Qn = 3e3;
3680
- class Yn {
4826
+ const os = 3e3;
4827
+ class cs {
3681
4828
  renegotiateRequester;
3682
4829
  renegotiateThrottled;
3683
4830
  callManager;
3684
- constructor(e, t = Qn) {
3685
- this.callManager = e, this.renegotiateRequester = new k(e.renegotiate.bind(e)), this.renegotiateThrottled = $e.throttle(
4831
+ constructor(e, t = os) {
4832
+ this.callManager = e, this.renegotiateRequester = new G(e.renegotiate.bind(e)), this.renegotiateThrottled = Ve.throttle(
3686
4833
  this.requestRenegotiate.bind(this),
3687
4834
  t
3688
4835
  ), this.subscribe();
3689
4836
  }
3690
4837
  recover() {
3691
- h("trying to recover main stream"), this.renegotiateThrottled();
4838
+ l("trying to recover main stream"), this.renegotiateThrottled();
3692
4839
  }
3693
4840
  requestRenegotiate = () => {
3694
- if (h("trying to renegotiate"), this.renegotiateRequester.requested) {
3695
- h("previous renegotiate is not finished yet");
4841
+ if (l("trying to renegotiate"), this.renegotiateRequester.requested) {
4842
+ l("previous renegotiate is not finished yet");
3696
4843
  return;
3697
4844
  }
3698
4845
  this.renegotiateRequester.request().then(() => {
3699
- h("renegotiate has successful");
4846
+ l("renegotiate has successful");
3700
4847
  }).catch((e) => {
3701
- h("failed to renegotiate main media stream", e);
4848
+ l("failed to renegotiate main media stream", e);
3702
4849
  });
3703
4850
  };
3704
4851
  subscribe() {
@@ -3707,25 +4854,25 @@ class Yn {
3707
4854
  });
3708
4855
  }
3709
4856
  cancel() {
3710
- h("cancel recover main stream"), this.renegotiateThrottled.cancel(), this.renegotiateRequester.cancelRequest();
4857
+ l("cancel recover main stream"), this.renegotiateThrottled.cancel(), this.renegotiateRequester.cancelRequest();
3711
4858
  }
3712
4859
  }
3713
- const zn = 1e6, Xn = Ae.map((n) => `auto-connect:${n}`), Jn = Ce.map((n) => `connection:${n}`), Kn = ce.map((n) => `call:${n}`), jn = ae.map((n) => `api:${n}`), Zn = me.map((n) => `incoming-call:${n}`), es = Te.map((n) => `presentation:${n}`), ts = Ne.map((n) => `stats:${n}`), ns = Me.map((n) => `video-balancer:${n}`), ss = [
4860
+ const ls = 1e6, ds = fe.map((n) => `auto-connect:${n}`), hs = Ne.map((n) => `connection:${n}`), gs = ge.map((n) => `call:${n}`), us = de.map((n) => `api:${n}`), Ts = Me.map((n) => `incoming-call:${n}`), Es = pe.map((n) => `presentation:${n}`), Cs = ve.map((n) => `stats:${n}`), Ss = De.map((n) => `video-balancer:${n}`), ps = [
3714
4861
  "disconnected-from-out-of-call",
3715
4862
  "connected-with-configuration-from-out-of-call",
3716
4863
  "stopped-presentation-by-server-command"
3717
- ], is = [
3718
- ...Xn,
3719
- ...Jn,
3720
- ...Kn,
3721
- ...jn,
3722
- ...Zn,
3723
- ...es,
3724
- ...ts,
3725
- ...ns,
3726
- ...ss
3727
- ], rs = () => new M(is);
3728
- class Rs {
4864
+ ], ms = [
4865
+ ...ds,
4866
+ ...hs,
4867
+ ...gs,
4868
+ ...us,
4869
+ ...Ts,
4870
+ ...Es,
4871
+ ...Cs,
4872
+ ...Ss,
4873
+ ...ps
4874
+ ], Ns = () => new O(ms);
4875
+ class ws {
3729
4876
  events;
3730
4877
  connectionManager;
3731
4878
  connectionQueueManager;
@@ -3736,6 +4883,7 @@ class Rs {
3736
4883
  presentationManager;
3737
4884
  statsManager;
3738
4885
  videoSendingBalancerManager;
4886
+ session;
3739
4887
  mainStreamHealthMonitor;
3740
4888
  mainStreamRecovery;
3741
4889
  preferredMimeTypesVideoCodecs;
@@ -3746,29 +4894,34 @@ class Rs {
3746
4894
  videoBalancerOptions: i,
3747
4895
  autoConnectorOptions: r
3748
4896
  } = {}) {
3749
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = rs(), this.connectionManager = new Bt({ JsSIP: e }), this.connectionQueueManager = new kt({
4897
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = Ns(), this.connectionManager = new Yt({ JsSIP: e }), this.connectionQueueManager = new zt({
3750
4898
  connectionManager: this.connectionManager
3751
- }), this.callManager = new st(), this.apiManager = new Qe({
4899
+ }), this.callManager = new lt(), this.apiManager = new Xe({
3752
4900
  connectionManager: this.connectionManager,
3753
4901
  callManager: this.callManager
3754
- }), this.incomingCallManager = new nn(this.connectionManager), this.presentationManager = new Rt({
4902
+ }), this.incomingCallManager = new Cn(this.connectionManager), this.presentationManager = new Ot({
3755
4903
  callManager: this.callManager,
3756
- maxBitrate: zn
3757
- }), this.statsManager = new Sn({
4904
+ maxBitrate: ls
4905
+ }), this.statsManager = new bn({
3758
4906
  callManager: this.callManager,
3759
4907
  apiManager: this.apiManager
3760
- }), this.autoConnectorManager = new jt(
4908
+ }), this.autoConnectorManager = new ln(
3761
4909
  {
3762
4910
  connectionQueueManager: this.connectionQueueManager,
3763
4911
  connectionManager: this.connectionManager,
3764
4912
  callManager: this.callManager
3765
4913
  },
3766
4914
  r
3767
- ), this.videoSendingBalancerManager = new Hn(
4915
+ ), this.videoSendingBalancerManager = new ss(
3768
4916
  this.callManager,
3769
4917
  this.apiManager,
3770
4918
  i
3771
- ), this.mainStreamHealthMonitor = new xn(this.statsManager, this.callManager), this.mainStreamRecovery = new Yn(this.callManager), this.subscribe();
4919
+ ), this.mainStreamHealthMonitor = new as(this.statsManager, this.callManager), this.mainStreamRecovery = new cs(this.callManager), this.session = pn({
4920
+ connectionManager: this.connectionManager,
4921
+ callManager: this.callManager,
4922
+ incomingCallManager: this.incomingCallManager,
4923
+ presentationManager: this.presentationManager
4924
+ }), this.subscribe();
3772
4925
  }
3773
4926
  get requestedConnection() {
3774
4927
  return this.connectionManager.requested;
@@ -3863,14 +5016,14 @@ class Rs {
3863
5016
  getRemoteStreams = () => this.callManager.getRemoteStreams();
3864
5017
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
3865
5018
  async startPresentation(e, t = {}) {
3866
- const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
5019
+ const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...o } = t;
3867
5020
  return this.presentationManager.startPresentation(
3868
5021
  async () => {
3869
5022
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
3870
5023
  },
3871
5024
  e,
3872
5025
  {
3873
- ...a,
5026
+ ...o,
3874
5027
  onAddedTransceiver: this.resolveHandleAddTransceiver(r)
3875
5028
  },
3876
5029
  i === void 0 ? void 0 : { callLimit: i }
@@ -3947,25 +5100,26 @@ class Rs {
3947
5100
  this.isCallActive || this.events.trigger("connected-with-configuration-from-out-of-call", e);
3948
5101
  });
3949
5102
  }
5103
+ mayBeStopPresentationAndNotify() {
5104
+ this.presentationManager.isPresentationInProcess && (this.stopPresentation().catch(() => {
5105
+ }), this.events.trigger("stopped-presentation-by-server-command", {}));
5106
+ }
3950
5107
  subscribeToApiEvents() {
3951
5108
  this.apiManager.on("participant:move-request-to-participants", () => {
3952
5109
  this.callManager.setCallRoleParticipant();
3953
5110
  }), this.apiManager.on("participant:move-request-to-spectators-synthetic", () => {
3954
- this.callManager.setCallRoleSpectatorSynthetic(), this.stopPresentation().catch(() => {
3955
- }), this.events.trigger("stopped-presentation-by-server-command", {});
5111
+ this.callManager.setCallRoleSpectatorSynthetic(), this.mayBeStopPresentationAndNotify();
3956
5112
  }), this.apiManager.on("participant:move-request-to-spectators-with-audio-id", ({ audioId: e }) => {
3957
- this.callManager.setCallRoleSpectator({ audioId: e, sendOffer: this.sendOffer }), this.stopPresentation().catch(() => {
3958
- }), this.events.trigger("stopped-presentation-by-server-command", {});
5113
+ this.callManager.setCallRoleSpectator({ audioId: e, sendOffer: this.sendOffer }), this.mayBeStopPresentationAndNotify();
3959
5114
  }), this.apiManager.on("mustStopPresentation", () => {
3960
- this.stopPresentation().catch(() => {
3961
- }), this.events.trigger("stopped-presentation-by-server-command", {});
5115
+ this.mayBeStopPresentationAndNotify();
3962
5116
  });
3963
5117
  }
3964
5118
  sendOffer = async (e, t) => {
3965
5119
  const i = this.connectionManager.getConnectionConfiguration()?.sipServerUrl;
3966
5120
  if (i === void 0)
3967
5121
  throw new Error("No sipServerUrl for sendOffer");
3968
- return an({
5122
+ return Rn({
3969
5123
  serverUrl: i,
3970
5124
  offer: t,
3971
5125
  conferenceNumber: e.conferenceNumber,
@@ -3974,7 +5128,7 @@ class Rs {
3974
5128
  });
3975
5129
  };
3976
5130
  setCodecPreferences(e) {
3977
- An(e, {
5131
+ Un(e, {
3978
5132
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
3979
5133
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
3980
5134
  });
@@ -3999,20 +5153,24 @@ class Rs {
3999
5153
  };
4000
5154
  }
4001
5155
  export {
4002
- he as E,
4003
- Ye as O,
4004
- Rs as S,
4005
- ge as a,
4006
- Tt as b,
4007
- Ge as c,
4008
- Es as d,
4009
- Cs as e,
4010
- ps as f,
4011
- E as g,
4012
- Ut as h,
4013
- Tn as i,
4014
- In as j,
4015
- h as l,
4016
- B as p,
4017
- an as s
5156
+ ue as E,
5157
+ Ze as O,
5158
+ ws as S,
5159
+ Je as a,
5160
+ hn as b,
5161
+ Se as c,
5162
+ Nt as d,
5163
+ Ye as e,
5164
+ ys as f,
5165
+ Ds as g,
5166
+ Wt as h,
5167
+ Ls as i,
5168
+ m as j,
5169
+ Pn as k,
5170
+ l,
5171
+ kn as m,
5172
+ kt as n,
5173
+ ft as o,
5174
+ k as p,
5175
+ Rn as s
4018
5176
  };