sip-connector 19.8.3 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +131 -138
  2. package/dist/@SipConnector-CZiURTVf.cjs +1 -0
  3. package/dist/{@SipConnector-BmkeKEDD.js → @SipConnector-D4DfiZRM.js} +1117 -977
  4. package/dist/ApiManager/@ApiManager.d.ts +0 -1
  5. package/dist/ApiManager/constants.d.ts +3 -8
  6. package/dist/ApiManager/eventNames.d.ts +15 -6
  7. package/dist/ApiManager/index.d.ts +0 -1
  8. package/dist/ApiManager/types.d.ts +0 -6
  9. package/dist/CallManager/@CallManager.d.ts +44 -15
  10. package/dist/CallManager/MCUSession.d.ts +0 -2
  11. package/dist/CallManager/RecvSession.d.ts +29 -0
  12. package/dist/CallManager/RemoteStreamsManager.d.ts +20 -5
  13. package/dist/CallManager/RoleManager.d.ts +31 -0
  14. package/dist/CallManager/eventNames.d.ts +9 -2
  15. package/dist/CallManager/index.d.ts +1 -2
  16. package/dist/CallManager/types.d.ts +29 -35
  17. package/dist/ConnectionManager/@ConnectionManager.d.ts +2 -2
  18. package/dist/ConnectionManager/ConfigurationManager.d.ts +6 -1
  19. package/dist/ConnectionManager/ConnectionFlow.d.ts +5 -4
  20. package/dist/ConnectionManager/SipOperations.d.ts +2 -2
  21. package/dist/ConnectionManager/UAFactory.d.ts +4 -4
  22. package/dist/SipConnector/@SipConnector.d.ts +4 -4
  23. package/dist/SipConnector/eventNames.d.ts +1 -1
  24. package/dist/SipConnectorFacade/@SipConnectorFacade.d.ts +0 -2
  25. package/dist/VideoSendingBalancer/__fixtures__/createMockTrack.d.ts +1 -1
  26. package/dist/__fixtures__/RTCPeerConnectionMock.d.ts +14 -18
  27. package/dist/__fixtures__/index.d.ts +4 -4
  28. package/dist/doMock.cjs +1 -1
  29. package/dist/doMock.js +134 -131
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.js +156 -171
  32. package/dist/tools/__fixtures__/connectToServer.d.ts +15 -15
  33. package/dist/tools/__fixtures__/permissions.d.ts +2 -2
  34. package/dist/tools/__fixtures__/processRequest.d.ts +2 -2
  35. package/dist/tools/index.d.ts +1 -0
  36. package/dist/tools/sendOffer.d.ts +39 -0
  37. package/dist/utils/utils.d.ts +1 -1
  38. package/package.json +13 -5
  39. package/dist/@SipConnector-BHakZWEK.cjs +0 -1
  40. package/dist/CallManager/AbstractCallStrategy.d.ts +0 -54
  41. package/dist/CallManager/MCUCallStrategy.d.ts +0 -31
  42. package/dist/TransceiverManager/@TransceiverManager.d.ts +0 -70
  43. package/dist/TransceiverManager/index.d.ts +0 -1
  44. package/dist/TransceiverManager/types.d.ts +0 -11
@@ -1,19 +1,19 @@
1
- import { TypedEvents as y } from "events-constructor";
2
- import W from "debug";
3
- import { CancelableRequest as x, isCanceledError as pe } from "@krivega/cancelable-promise";
4
- import { resolveRequesterByTimeout as _e, requesterByTimeoutsWithFailCalls as Me, DelayRequester as fe, hasCanceledError as ve, SetTimeoutRequest as Z } from "@krivega/timeout-requester";
5
- import { hasCanceledError as Pe, repeatedCallsAsync as ee } from "repeated-calls";
6
- import { setup as Oe, createActor as ye } from "xstate";
7
- import { createStackPromises as te, isPromiseIsNotActualError as De } from "stack-promises";
1
+ import { TypedEvents as O } from "events-constructor";
2
+ import V from "debug";
3
+ import { CancelableRequest as x, isCanceledError as Pe } from "@krivega/cancelable-promise";
4
+ import { resolveRequesterByTimeout as Oe, requesterByTimeoutsWithFailCalls as ye, DelayRequester as De, hasCanceledError as be, SetTimeoutRequest as ne } from "@krivega/timeout-requester";
5
+ import { hasCanceledError as we, repeatedCallsAsync as se } from "repeated-calls";
6
+ import { setup as Ue, createActor as Le } from "xstate";
7
+ import { createStackPromises as ie, isPromiseIsNotActualError as Be } from "stack-promises";
8
8
  import "ua-parser-js";
9
9
  import "sequent-promises";
10
- const G = "sip-connector", c = W(G), Wn = () => {
11
- W.enable(G);
12
- }, xn = () => {
13
- W.enable(`-${G}`);
14
- }, be = "Error decline with 603", we = 1006, Ue = (n) => typeof n == "object" && n !== null && "code" in n && n.code === we, Le = (n) => n.message === be;
15
- 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))(u || {}), L = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(L || {}), q = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(q || {}), P = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.RESTART = "application/vinteo.webrtc.restart", n))(P || {}), p = /* @__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))(p || {}), 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 || {}), V = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(V || {}), H = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(H || {}), Be = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Be || {}), g = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants", n.PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request", n.PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request", n.WEBCAST_STARTED = "webcast:started", n.WEBCAST_STOPPED = "webcast:stopped", n.ACCOUNT_CHANGED = "account:changed", n.ACCOUNT_DELETED = "account:deleted", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n.RESTART = "restart", n))(g || {});
16
- const ne = [
10
+ const Q = "sip-connector", h = V(Q), Jn = () => {
11
+ V.enable(Q);
12
+ }, Kn = () => {
13
+ V.enable(`-${Q}`);
14
+ }, ke = "Error decline with 603", Fe = 1006, $e = (n) => typeof n == "object" && n !== null && "code" in n && n.code === Fe, qe = (n) => n.message === ke;
15
+ 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 || {}), B = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(B || {}), W = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(W || {}), 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 || {}), m = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n.STATS = "application/vinteo.webrtc.stats", n))(m || {}), M = /* @__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))(M || {}), H = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(H || {}), G = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(G || {}), We = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(We || {}), 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 || {});
16
+ const re = [
17
17
  "participation:accepting-word-request",
18
18
  "participation:cancelling-word-request",
19
19
  "participant:move-request-to-stream",
@@ -26,6 +26,8 @@ const ne = [
26
26
  "participant:added-to-list-moderators",
27
27
  "participant:removed-from-list-moderators",
28
28
  "participant:move-request-to-spectators",
29
+ "participant:move-request-to-spectators-synthetic",
30
+ "participant:move-request-to-spectators-with-audio-id",
29
31
  "participant:move-request-to-participants",
30
32
  "channels",
31
33
  "enterRoom",
@@ -40,11 +42,10 @@ const ne = [
40
42
  "availableSecondRemoteStream",
41
43
  "notAvailableSecondRemoteStream",
42
44
  "mustStopPresentation",
43
- "newDTMF",
44
- "restart"
45
+ "newDTMF"
45
46
  ];
46
- 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 || {});
47
- class Fe {
47
+ var N = /* @__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))(N || {});
48
+ class He {
48
49
  events;
49
50
  connectionManager;
50
51
  callManager;
@@ -52,64 +53,64 @@ class Fe {
52
53
  connectionManager: e,
53
54
  callManager: t
54
55
  }) {
55
- this.connectionManager = e, this.callManager = t, this.events = new y(ne), this.subscribe();
56
+ this.connectionManager = e, this.callManager = t, this.events = new O(re), this.subscribe();
56
57
  }
57
58
  async waitChannels() {
58
- return this.wait(g.CHANNELS);
59
+ return this.wait(l.CHANNELS);
59
60
  }
60
61
  async waitSyncMediaState() {
61
- return this.wait(g.ADMIN_FORCE_SYNC_MEDIA_STATE);
62
+ return this.wait(l.ADMIN_FORCE_SYNC_MEDIA_STATE);
62
63
  }
63
64
  async sendDTMF(e) {
64
65
  return new Promise((t, s) => {
65
- let r;
66
+ let i;
66
67
  try {
67
- r = this.getEstablishedRTCSessionProtected();
68
- } catch (i) {
69
- s(i);
68
+ i = this.getEstablishedRTCSessionProtected();
69
+ } catch (r) {
70
+ s(r);
70
71
  }
71
- r && (this.callManager.once("newDTMF", ({ originator: i }) => {
72
- i === "local" && t();
73
- }), r.sendDTMF(e, {
72
+ i && (this.callManager.once("newDTMF", ({ originator: r }) => {
73
+ r === "local" && t();
74
+ }), i.sendDTMF(e, {
74
75
  duration: 120,
75
76
  interToneGap: 600
76
77
  }));
77
78
  });
78
79
  }
79
80
  async sendChannels({ inputChannels: e, outputChannels: t }) {
80
- const s = this.getEstablishedRTCSessionProtected(), r = `${u.INPUT_CHANNELS}: ${e}`, i = `${u.OUTPUT_CHANNELS}: ${t}`, a = [
81
- r,
82
- i
81
+ const s = this.getEstablishedRTCSessionProtected(), i = `${u.INPUT_CHANNELS}: ${e}`, r = `${u.OUTPUT_CHANNELS}: ${t}`, a = [
82
+ i,
83
+ r
83
84
  ];
84
- return s.sendInfo(p.CHANNELS, void 0, { extraHeaders: a });
85
+ return s.sendInfo(m.CHANNELS, void 0, { extraHeaders: a });
85
86
  }
86
87
  async sendMediaState({ cam: e, mic: t }, s = {}) {
87
- const r = this.getEstablishedRTCSessionProtected(), i = `${u.MEDIA_STATE}: currentstate`, a = `${u.MAIN_CAM_STATE}: ${Number(e)}`, o = `${u.MIC_STATE}: ${Number(t)}`, h = [
88
- i,
88
+ const i = this.getEstablishedRTCSessionProtected(), r = `${u.MEDIA_STATE}: currentstate`, a = `${u.MAIN_CAM_STATE}: ${Number(e)}`, o = `${u.MIC_STATE}: ${Number(t)}`, c = [
89
+ r,
89
90
  a,
90
91
  o
91
92
  ];
92
- return r.sendInfo(p.MEDIA_STATE, void 0, {
93
+ return i.sendInfo(m.MEDIA_STATE, void 0, {
93
94
  noTerminateWhenError: !0,
94
95
  ...s,
95
- extraHeaders: h
96
+ extraHeaders: c
96
97
  });
97
98
  }
98
99
  async sendStats({
99
100
  availableIncomingBitrate: e
100
101
  }) {
101
- const t = this.getEstablishedRTCSessionProtected(), r = [`${u.AVAILABLE_INCOMING_BITRATE}: ${e}`];
102
- return t.sendInfo(p.STATS, void 0, {
102
+ const t = this.getEstablishedRTCSessionProtected(), i = [`${u.AVAILABLE_INCOMING_BITRATE}: ${e}`];
103
+ return t.sendInfo(m.STATS, void 0, {
103
104
  noTerminateWhenError: !0,
104
- extraHeaders: r
105
+ extraHeaders: i
105
106
  });
106
107
  }
107
108
  async sendRefusalToTurnOn(e, t = {}) {
108
- const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, h = [`${u.MEDIA_TYPE}: ${a}`];
109
- return s.sendInfo(p.REFUSAL, void 0, {
109
+ const s = this.getEstablishedRTCSessionProtected(), a = e === "mic" ? 0 : 1, c = [`${u.MEDIA_TYPE}: ${a}`];
110
+ return s.sendInfo(m.REFUSAL, void 0, {
110
111
  noTerminateWhenError: !0,
111
112
  ...t,
112
- extraHeaders: h
113
+ extraHeaders: c
113
114
  });
114
115
  }
115
116
  async sendRefusalToTurnOnMic(e = {}) {
@@ -119,39 +120,39 @@ class Fe {
119
120
  return this.sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
120
121
  }
121
122
  async sendMustStopPresentationP2P() {
122
- await this.getEstablishedRTCSessionProtected().sendInfo(p.SHARE_STATE, void 0, {
123
+ await this.getEstablishedRTCSessionProtected().sendInfo(m.SHARE_STATE, void 0, {
123
124
  extraHeaders: [u.MUST_STOP_PRESENTATION_P2P]
124
125
  });
125
126
  }
126
127
  async sendStoppedPresentationP2P() {
127
- await this.getEstablishedRTCSessionProtected().sendInfo(p.SHARE_STATE, void 0, {
128
+ await this.getEstablishedRTCSessionProtected().sendInfo(m.SHARE_STATE, void 0, {
128
129
  extraHeaders: [u.STOP_PRESENTATION_P2P]
129
130
  });
130
131
  }
131
132
  async sendStoppedPresentation() {
132
- await this.getEstablishedRTCSessionProtected().sendInfo(p.SHARE_STATE, void 0, {
133
+ await this.getEstablishedRTCSessionProtected().sendInfo(m.SHARE_STATE, void 0, {
133
134
  extraHeaders: [u.STOP_PRESENTATION]
134
135
  });
135
136
  }
136
137
  async askPermissionToStartPresentationP2P() {
137
- await this.getEstablishedRTCSessionProtected().sendInfo(p.SHARE_STATE, void 0, {
138
+ await this.getEstablishedRTCSessionProtected().sendInfo(m.SHARE_STATE, void 0, {
138
139
  extraHeaders: [u.START_PRESENTATION_P2P]
139
140
  });
140
141
  }
141
142
  async askPermissionToStartPresentation() {
142
- await this.getEstablishedRTCSessionProtected().sendInfo(p.SHARE_STATE, void 0, {
143
+ await this.getEstablishedRTCSessionProtected().sendInfo(m.SHARE_STATE, void 0, {
143
144
  extraHeaders: [u.START_PRESENTATION]
144
145
  });
145
146
  }
146
147
  async askPermissionToEnableCam(e = {}) {
147
148
  const t = this.getEstablishedRTCSessionProtected(), s = [u.ENABLE_MAIN_CAM];
148
- return t.sendInfo(p.MAIN_CAM, void 0, {
149
+ return t.sendInfo(m.MAIN_CAM, void 0, {
149
150
  noTerminateWhenError: !0,
150
151
  ...e,
151
152
  extraHeaders: s
152
- }).catch((r) => {
153
- if (Le(r))
154
- throw r;
153
+ }).catch((i) => {
154
+ if (qe(i))
155
+ throw i;
155
156
  });
156
157
  }
157
158
  on(e, t) {
@@ -191,115 +192,111 @@ class Fe {
191
192
  this.handleNotify(s);
192
193
  }
193
194
  } catch (t) {
194
- c("error parse notify", t);
195
+ h("error parse notify", t);
195
196
  }
196
197
  };
197
198
  handleNotify = (e) => {
198
199
  switch (e.cmd) {
199
- case m.CHANNELS: {
200
+ case N.CHANNELS: {
200
201
  const t = e;
201
202
  this.triggerChannelsNotify(t);
202
203
  break;
203
204
  }
204
- case m.WEBCAST_STARTED: {
205
+ case N.WEBCAST_STARTED: {
205
206
  const t = e;
206
207
  this.triggerWebcastStartedNotify(t);
207
208
  break;
208
209
  }
209
- case m.WEBCAST_STOPPED: {
210
+ case N.WEBCAST_STOPPED: {
210
211
  const t = e;
211
212
  this.triggerWebcastStoppedNotify(t);
212
213
  break;
213
214
  }
214
- case m.ADDED_TO_LIST_MODERATORS: {
215
+ case N.ADDED_TO_LIST_MODERATORS: {
215
216
  const t = e;
216
217
  this.triggerAddedToListModeratorsNotify(t);
217
218
  break;
218
219
  }
219
- case m.REMOVED_FROM_LIST_MODERATORS: {
220
+ case N.REMOVED_FROM_LIST_MODERATORS: {
220
221
  const t = e;
221
222
  this.triggerRemovedFromListModeratorsNotify(t);
222
223
  break;
223
224
  }
224
- case m.ACCEPTING_WORD_REQUEST: {
225
+ case N.ACCEPTING_WORD_REQUEST: {
225
226
  const t = e;
226
227
  this.triggerParticipationAcceptingWordRequest(t);
227
228
  break;
228
229
  }
229
- case m.CANCELLING_WORD_REQUEST: {
230
+ case N.CANCELLING_WORD_REQUEST: {
230
231
  const t = e;
231
232
  this.triggerParticipationCancellingWordRequest(t);
232
233
  break;
233
234
  }
234
- case m.MOVE_REQUEST_TO_STREAM: {
235
+ case N.MOVE_REQUEST_TO_STREAM: {
235
236
  const t = e;
236
237
  this.triggerParticipantMoveRequestToStream(t);
237
238
  break;
238
239
  }
239
- case m.ACCOUNT_CHANGED: {
240
+ case N.ACCOUNT_CHANGED: {
240
241
  this.triggerAccountChangedNotify();
241
242
  break;
242
243
  }
243
- case m.ACCOUNT_DELETED: {
244
+ case N.ACCOUNT_DELETED: {
244
245
  this.triggerAccountDeletedNotify();
245
246
  break;
246
247
  }
247
- case m.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
248
+ case N.CONFERENCE_PARTICIPANT_TOKEN_ISSUED: {
248
249
  const t = e;
249
250
  this.triggerConferenceParticipantTokenIssued(t);
250
251
  break;
251
252
  }
252
253
  default:
253
- c("unknown cmd", e);
254
+ h("unknown cmd", e);
254
255
  }
255
256
  };
256
257
  handleNewInfo = (e) => {
257
258
  const { originator: t } = e;
258
259
  if (t !== "remote")
259
260
  return;
260
- const { request: s } = e, r = s, i = r.getHeader(u.CONTENT_TYPE);
261
- if (i !== void 0)
262
- switch (i) {
263
- case P.ENTER_ROOM: {
264
- this.triggerEnterRoom(r), this.maybeTriggerChannels(r);
261
+ const { request: s } = e, i = s, r = i.getHeader(u.CONTENT_TYPE);
262
+ if (r !== void 0)
263
+ switch (r) {
264
+ case y.ENTER_ROOM: {
265
+ this.triggerEnterRoom(i), this.maybeTriggerChannels(i);
265
266
  break;
266
267
  }
267
- case P.NOTIFY: {
268
- this.maybeHandleNotify(r);
268
+ case y.NOTIFY: {
269
+ this.maybeHandleNotify(i);
269
270
  break;
270
271
  }
271
- case P.SHARE_STATE: {
272
- this.triggerShareState(r);
272
+ case y.SHARE_STATE: {
273
+ this.triggerShareState(i);
273
274
  break;
274
275
  }
275
- case P.MAIN_CAM: {
276
- this.triggerMainCamControl(r);
276
+ case y.MAIN_CAM: {
277
+ this.triggerMainCamControl(i);
277
278
  break;
278
279
  }
279
- case P.MIC: {
280
- this.triggerMicControl(r);
280
+ case y.MIC: {
281
+ this.triggerMicControl(i);
281
282
  break;
282
283
  }
283
- case P.USE_LICENSE: {
284
- this.triggerUseLicense(r);
284
+ case y.USE_LICENSE: {
285
+ this.triggerUseLicense(i);
285
286
  break;
286
287
  }
287
- case P.PARTICIPANT_STATE: {
288
- this.maybeTriggerParticipantMoveRequest(r);
289
- break;
290
- }
291
- case P.RESTART: {
292
- this.triggerRestart(r);
288
+ case y.PARTICIPANT_STATE: {
289
+ this.maybeTriggerParticipantMoveRequest(i);
293
290
  break;
294
291
  }
295
292
  }
296
293
  };
297
294
  triggerChannelsNotify = (e) => {
298
- const t = e.input, s = e.output, r = {
295
+ const t = e.input, s = e.output, i = {
299
296
  inputChannels: t,
300
297
  outputChannels: s
301
298
  };
302
- this.events.trigger(g.CHANNELS_NOTIFY, r);
299
+ this.events.trigger(l.CHANNELS_NOTIFY, i);
303
300
  };
304
301
  triggerWebcastStartedNotify = ({
305
302
  body: { conference: e, type: t }
@@ -308,7 +305,7 @@ class Fe {
308
305
  conference: e,
309
306
  type: t
310
307
  };
311
- this.events.trigger(g.WEBCAST_STARTED, s);
308
+ this.events.trigger(l.WEBCAST_STARTED, s);
312
309
  };
313
310
  triggerWebcastStoppedNotify = ({
314
311
  body: { conference: e, type: t }
@@ -317,7 +314,7 @@ class Fe {
317
314
  conference: e,
318
315
  type: t
319
316
  };
320
- this.events.trigger(g.WEBCAST_STOPPED, s);
317
+ this.events.trigger(l.WEBCAST_STOPPED, s);
321
318
  };
322
319
  triggerAddedToListModeratorsNotify = ({
323
320
  conference: e
@@ -326,7 +323,7 @@ class Fe {
326
323
  conference: e
327
324
  };
328
325
  this.events.trigger(
329
- g.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
326
+ l.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
330
327
  t
331
328
  );
332
329
  };
@@ -337,7 +334,7 @@ class Fe {
337
334
  conference: e
338
335
  };
339
336
  this.events.trigger(
340
- g.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
337
+ l.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
341
338
  t
342
339
  );
343
340
  };
@@ -347,7 +344,7 @@ class Fe {
347
344
  const t = {
348
345
  conference: e
349
346
  };
350
- this.events.trigger(g.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
347
+ this.events.trigger(l.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
351
348
  };
352
349
  triggerParticipationCancellingWordRequest = ({
353
350
  body: { conference: e }
@@ -355,7 +352,7 @@ class Fe {
355
352
  const t = {
356
353
  conference: e
357
354
  };
358
- this.events.trigger(g.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
355
+ this.events.trigger(l.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
359
356
  };
360
357
  triggerParticipantMoveRequestToStream = ({
361
358
  body: { conference: e }
@@ -363,101 +360,96 @@ class Fe {
363
360
  const t = {
364
361
  conference: e
365
362
  };
366
- this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
363
+ this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
367
364
  };
368
365
  triggerAccountChangedNotify = () => {
369
- this.events.trigger(g.ACCOUNT_CHANGED, {});
366
+ this.events.trigger(l.ACCOUNT_CHANGED, {});
370
367
  };
371
368
  triggerAccountDeletedNotify = () => {
372
- this.events.trigger(g.ACCOUNT_DELETED, {});
369
+ this.events.trigger(l.ACCOUNT_DELETED, {});
373
370
  };
374
371
  triggerConferenceParticipantTokenIssued = ({
375
372
  body: { conference: e, participant: t, jwt: s }
376
373
  }) => {
377
- const r = {
374
+ const i = {
378
375
  conference: e,
379
376
  participant: t,
380
377
  jwt: s
381
378
  };
382
379
  this.events.trigger(
383
- g.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
384
- r
380
+ l.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
381
+ i
385
382
  );
386
383
  };
387
384
  maybeTriggerChannels = (e) => {
388
385
  const t = e.getHeader(u.INPUT_CHANNELS), s = e.getHeader(u.OUTPUT_CHANNELS);
389
386
  if (t && s) {
390
- const r = {
387
+ const i = {
391
388
  inputChannels: t,
392
389
  outputChannels: s
393
390
  };
394
- this.events.trigger(g.CHANNELS, r);
391
+ this.events.trigger(l.CHANNELS, i);
395
392
  }
396
393
  };
397
394
  triggerEnterRoom = (e) => {
398
395
  const t = e.getHeader(u.CONTENT_ENTER_ROOM), s = e.getHeader(u.PARTICIPANT_NAME);
399
- this.events.trigger(g.ENTER_ROOM, { room: t, participantName: s });
396
+ this.events.trigger(l.ENTER_ROOM, { room: t, participantName: s });
400
397
  };
401
398
  triggerShareState = (e) => {
402
399
  const t = e.getHeader(u.CONTENT_SHARE_STATE);
403
400
  if (t !== void 0)
404
401
  switch (t) {
405
- case L.AVAILABLE_SECOND_REMOTE_STREAM: {
406
- this.events.trigger(g.AVAILABLE_SECOND_REMOTE_STREAM, {});
402
+ case B.AVAILABLE_SECOND_REMOTE_STREAM: {
403
+ this.events.trigger(l.AVAILABLE_SECOND_REMOTE_STREAM, {});
407
404
  break;
408
405
  }
409
- case L.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
410
- this.events.trigger(g.NOT_AVAILABLE_SECOND_REMOTE_STREAM, {});
406
+ case B.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
407
+ this.events.trigger(l.NOT_AVAILABLE_SECOND_REMOTE_STREAM, {});
411
408
  break;
412
409
  }
413
- case L.MUST_STOP_PRESENTATION: {
414
- this.events.trigger(g.MUST_STOP_PRESENTATION, {});
410
+ case B.MUST_STOP_PRESENTATION: {
411
+ this.events.trigger(l.MUST_STOP_PRESENTATION, {});
415
412
  break;
416
413
  }
417
414
  }
418
415
  };
419
416
  maybeTriggerParticipantMoveRequest = (e) => {
420
- const t = e.getHeader(u.CONTENT_PARTICIPANT_STATE);
421
- t === q.SPECTATOR && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, {}), t === q.PARTICIPANT && this.events.trigger(g.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
417
+ const t = e.getHeader(u.CONTENT_PARTICIPANT_STATE), s = e.getHeader(u.AUDIO_ID);
418
+ t === W.SPECTATOR && (s ? (this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_WITH_AUDIO_ID, {
419
+ audioId: s
420
+ }), this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, {
421
+ isSynthetic: !1,
422
+ audioId: s
423
+ })) : (this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_SYNTHETIC, {}), this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, { isSynthetic: !0 }))), t === W.PARTICIPANT && this.events.trigger(l.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, {});
422
424
  };
423
425
  triggerMainCamControl = (e) => {
424
- const t = e.getHeader(u.MAIN_CAM), s = e.getHeader(u.MEDIA_SYNC), r = s === H.ADMIN_SYNC_FORCED;
425
- if (t === v.ADMIN_START_MAIN_CAM) {
426
- this.events.trigger(g.ADMIN_START_MAIN_CAM, { isSyncForced: r });
426
+ const t = e.getHeader(u.MAIN_CAM), s = e.getHeader(u.MEDIA_SYNC), i = s === G.ADMIN_SYNC_FORCED;
427
+ if (t === M.ADMIN_START_MAIN_CAM) {
428
+ this.events.trigger(l.ADMIN_START_MAIN_CAM, { isSyncForced: i });
427
429
  return;
428
430
  }
429
- if (t === v.ADMIN_STOP_MAIN_CAM) {
430
- this.events.trigger(g.ADMIN_STOP_MAIN_CAM, { isSyncForced: r });
431
+ if (t === M.ADMIN_STOP_MAIN_CAM) {
432
+ this.events.trigger(l.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
431
433
  return;
432
434
  }
433
- (t === v.RESUME_MAIN_CAM || t === v.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(g.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: r });
434
- const i = e.getHeader(u.MAIN_CAM_RESOLUTION);
435
- this.events.trigger(g.MAIN_CAM_CONTROL, {
435
+ (t === M.RESUME_MAIN_CAM || t === M.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(l.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
436
+ const r = e.getHeader(u.MAIN_CAM_RESOLUTION);
437
+ this.events.trigger(l.MAIN_CAM_CONTROL, {
436
438
  mainCam: t,
437
- resolutionMainCam: i
439
+ resolutionMainCam: r
438
440
  });
439
441
  };
440
442
  triggerMicControl = (e) => {
441
- const t = e.getHeader(u.MIC), r = e.getHeader(u.MEDIA_SYNC) === H.ADMIN_SYNC_FORCED;
442
- t === V.ADMIN_START_MIC ? this.events.trigger(g.ADMIN_START_MIC, { isSyncForced: r }) : t === V.ADMIN_STOP_MIC && this.events.trigger(g.ADMIN_STOP_MIC, { isSyncForced: r });
443
+ const t = e.getHeader(u.MIC), i = e.getHeader(u.MEDIA_SYNC) === G.ADMIN_SYNC_FORCED;
444
+ t === H.ADMIN_START_MIC ? this.events.trigger(l.ADMIN_START_MIC, { isSyncForced: i }) : t === H.ADMIN_STOP_MIC && this.events.trigger(l.ADMIN_STOP_MIC, { isSyncForced: i });
443
445
  };
444
446
  triggerUseLicense = (e) => {
445
447
  const t = e.getHeader(u.CONTENT_USE_LICENSE);
446
- this.events.trigger(g.USE_LICENSE, t);
447
- };
448
- triggerRestart = (e) => {
449
- const t = e.getHeader(
450
- u.TRACKS_DIRECTION
451
- ), s = Number(
452
- e.getHeader(u.AUDIO_TRACK_COUNT)
453
- ), r = Number(
454
- e.getHeader(u.VIDEO_TRACK_COUNT)
455
- ), i = { tracksDirection: t, audioTrackCount: s, videoTrackCount: r };
456
- this.events.trigger(g.RESTART, i);
448
+ this.events.trigger(l.USE_LICENSE, t);
457
449
  };
458
450
  }
459
- 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))(R || {}), ke = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(ke || {});
460
- const se = [
451
+ 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 || {}), Ge = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(Ge || {});
452
+ const ae = [
461
453
  "peerconnection",
462
454
  "connecting",
463
455
  "sending",
@@ -484,48 +476,30 @@ const se = [
484
476
  "peerconnection:createanswerfailed",
485
477
  "peerconnection:setlocaldescriptionfailed",
486
478
  "peerconnection:setremotedescriptionfailed"
487
- ], $e = [
479
+ ], Ve = [
488
480
  "peerconnection:confirmed",
489
481
  "peerconnection:ontrack",
490
482
  "ended:fromserver",
491
- "call-status-changed"
492
- ], re = [
493
- ...se,
494
- ...$e
495
- ];
496
- function qe(n) {
497
- return (e) => `sip:${e}@${n}`;
498
- }
499
- const Ve = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, ie = (n) => n.trim().replaceAll(" ", "_"), He = Ve(1e5, 99999999), We = (n) => n.some((t) => {
500
- const { kind: s } = t;
501
- return s === "video";
502
- });
503
- class xe {
504
- isPendingCall = !1;
505
- isPendingAnswer = !1;
506
- rtcSession;
507
- remoteStreams = {};
508
- events;
509
- callConfiguration = {};
510
- constructor(e) {
511
- this.events = e;
512
- }
513
- }
514
- const Ge = (n, e) => {
483
+ "call-status-changed",
484
+ "remote-streams-changed"
485
+ ], oe = [
486
+ ...ae,
487
+ ...Ve
488
+ ], xe = (n, e) => {
515
489
  n.getVideoTracks().forEach((s) => {
516
490
  "contentHint" in s && s.contentHint !== e && (s.contentHint = e);
517
491
  });
518
- }, B = (n, {
492
+ }, k = (n, {
519
493
  directionVideo: e,
520
494
  directionAudio: t,
521
495
  contentHint: s
522
496
  } = {}) => {
523
497
  if (!n || e === "recvonly" && t === "recvonly")
524
498
  return;
525
- const r = t === "recvonly" ? [] : n.getAudioTracks(), i = e === "recvonly" ? [] : n.getVideoTracks(), a = [...r, ...i], o = new MediaStream(a);
526
- return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && Ge(o, s), o;
499
+ const i = t === "recvonly" ? [] : n.getAudioTracks(), r = e === "recvonly" ? [] : n.getVideoTracks(), a = [...i, ...r], o = new MediaStream(a);
500
+ return o.getTracks = () => [...o.getAudioTracks(), ...o.getVideoTracks()], s && s !== "none" && xe(o, s), o;
527
501
  };
528
- var ae = /* @__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))(ae || {});
502
+ var ce = /* @__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))(ce || {});
529
503
  class Qe {
530
504
  events;
531
505
  rtcSession;
@@ -543,51 +517,50 @@ class Qe {
543
517
  getEstablishedRTCSession = () => this.rtcSession?.isEstablished() === !0 ? this.rtcSession : void 0;
544
518
  startCall = async (e, t, {
545
519
  number: s,
546
- mediaStream: r,
547
- extraHeaders: i = [],
548
- ontrack: a,
549
- iceServers: o,
550
- directionVideo: h,
551
- directionAudio: d,
552
- contentHint: T,
520
+ mediaStream: i,
521
+ extraHeaders: r = [],
522
+ iceServers: a,
523
+ directionVideo: o,
524
+ directionAudio: c,
525
+ contentHint: d,
553
526
  offerToReceiveAudio: S = !0,
554
- offerToReceiveVideo: l = !0,
555
- degradationPreference: E,
556
- sendEncodings: I,
557
- onAddedTransceiver: N
558
- }) => new Promise((M, F) => {
559
- this.handleCall({ ontrack: a }).then(M).catch((k) => {
560
- F(k);
527
+ offerToReceiveVideo: g = !0,
528
+ degradationPreference: T,
529
+ sendEncodings: p,
530
+ onAddedTransceiver: v
531
+ }) => new Promise((A, D) => {
532
+ this.handleCall().then(A).catch((F) => {
533
+ D(F);
561
534
  }), this.rtcSession = e.call(t(s), {
562
- mediaStream: B(r, {
563
- directionVideo: h,
564
- directionAudio: d,
565
- contentHint: T
535
+ mediaStream: k(i, {
536
+ directionVideo: o,
537
+ directionAudio: c,
538
+ contentHint: d
566
539
  }),
567
540
  pcConfig: {
568
- iceServers: o
541
+ iceServers: a
569
542
  },
570
543
  rtcOfferConstraints: {
571
544
  offerToReceiveAudio: S,
572
- offerToReceiveVideo: l
545
+ offerToReceiveVideo: g
573
546
  },
574
547
  // необходимо передавать в методе call, чтобы подписаться на события peerconnection,
575
548
  // так как в методе call создается RTCSession
576
549
  // и после создания нет возможности подписаться на события peerconnection через subscribeToSessionEvents
577
550
  eventHandlers: this.events.triggers,
578
- extraHeaders: i,
579
- directionVideo: h,
580
- directionAudio: d,
581
- degradationPreference: E,
582
- sendEncodings: I,
583
- onAddedTransceiver: N
551
+ extraHeaders: r,
552
+ directionVideo: o,
553
+ directionAudio: c,
554
+ degradationPreference: T,
555
+ sendEncodings: p,
556
+ onAddedTransceiver: v
584
557
  });
585
558
  });
586
559
  async endCall() {
587
560
  const { rtcSession: e } = this;
588
561
  if (e && !e.isEnded())
589
562
  return e.terminateAsync({
590
- cause: ae.CANCELED
563
+ cause: ce.CANCELED
591
564
  }).finally(() => {
592
565
  this.reset();
593
566
  });
@@ -595,99 +568,88 @@ class Qe {
595
568
  }
596
569
  answerToIncomingCall = async (e, {
597
570
  mediaStream: t,
598
- ontrack: s,
599
- extraHeaders: r = [],
571
+ extraHeaders: s = [],
600
572
  iceServers: i,
601
- directionVideo: a,
602
- directionAudio: o,
603
- offerToReceiveAudio: h,
604
- offerToReceiveVideo: d,
605
- contentHint: T,
573
+ directionVideo: r,
574
+ directionAudio: a,
575
+ offerToReceiveAudio: o,
576
+ offerToReceiveVideo: c,
577
+ contentHint: d,
606
578
  degradationPreference: S,
607
- sendEncodings: l,
608
- onAddedTransceiver: E
609
- }) => new Promise((I, N) => {
579
+ sendEncodings: g,
580
+ onAddedTransceiver: T
581
+ }) => new Promise((p, v) => {
610
582
  try {
611
- this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall({ ontrack: s }).then(I).catch((M) => {
612
- N(M);
583
+ this.rtcSession = e, this.subscribeToSessionEvents(e), this.handleCall().then(p).catch((A) => {
584
+ v(A);
613
585
  }), e.answer({
614
586
  pcConfig: {
615
587
  iceServers: i
616
588
  },
617
589
  rtcOfferConstraints: {
618
- offerToReceiveAudio: h,
619
- offerToReceiveVideo: d
590
+ offerToReceiveAudio: o,
591
+ offerToReceiveVideo: c
620
592
  },
621
- mediaStream: B(t, {
622
- directionVideo: a,
623
- directionAudio: o,
624
- contentHint: T
593
+ mediaStream: k(t, {
594
+ directionVideo: r,
595
+ directionAudio: a,
596
+ contentHint: d
625
597
  }),
626
- extraHeaders: r,
627
- directionVideo: a,
628
- directionAudio: o,
598
+ extraHeaders: s,
599
+ directionVideo: r,
600
+ directionAudio: a,
629
601
  degradationPreference: S,
630
- sendEncodings: l,
631
- onAddedTransceiver: E
602
+ sendEncodings: g,
603
+ onAddedTransceiver: T
632
604
  });
633
- } catch (M) {
634
- N(M);
605
+ } catch (A) {
606
+ v(A);
635
607
  }
636
608
  });
637
- getRemoteTracks() {
638
- return this.connection ? this.connection.getReceivers().map(({ track: s }) => s) : void 0;
639
- }
640
609
  async replaceMediaStream(e, t) {
641
610
  if (!this.rtcSession)
642
611
  throw new Error("No rtcSession established");
643
- const { contentHint: s } = t ?? {}, r = B(e, { contentHint: s });
644
- if (r === void 0)
612
+ const { contentHint: s } = t ?? {}, i = k(e, { contentHint: s });
613
+ if (i === void 0)
645
614
  throw new Error("No preparedMediaStream");
646
- return this.rtcSession.replaceMediaStream(r, t);
615
+ return this.rtcSession.replaceMediaStream(i, t);
647
616
  }
648
617
  async restartIce(e) {
649
618
  if (!this.rtcSession)
650
619
  throw new Error("No rtcSession established");
651
620
  return this.rtcSession.restartIce(e);
652
621
  }
653
- async addTransceiver(e, t) {
654
- if (!this.rtcSession)
655
- throw new Error("No rtcSession established");
656
- return this.rtcSession.addTransceiver(e, t);
657
- }
658
- handleCall = async ({
659
- ontrack: e
660
- }) => new Promise((t, s) => {
661
- const r = () => {
662
- this.events.on(R.PEER_CONNECTION, T), this.events.on(R.CONFIRMED, S);
622
+ handleCall = async () => new Promise((e, t) => {
623
+ const s = () => {
624
+ this.events.on(R.PEER_CONNECTION, d), this.events.on(R.CONFIRMED, S);
663
625
  }, i = () => {
664
- this.events.off(R.PEER_CONNECTION, T), this.events.off(R.CONFIRMED, S);
626
+ this.events.off(R.PEER_CONNECTION, d), this.events.off(R.CONFIRMED, S);
627
+ }, r = () => {
628
+ this.events.on(R.FAILED, o), this.events.on(R.ENDED, o);
665
629
  }, a = () => {
666
- this.events.on(R.FAILED, h), this.events.on(R.ENDED, h);
667
- }, o = () => {
668
- this.events.off(R.FAILED, h), this.events.off(R.ENDED, h);
669
- }, h = (l) => {
670
- i(), o(), s(l);
630
+ this.events.off(R.FAILED, o), this.events.off(R.ENDED, o);
631
+ }, o = (g) => {
632
+ i(), a(), t(g);
671
633
  };
672
- let d;
673
- const T = ({ peerconnection: l }) => {
674
- d = l;
675
- const E = (I) => {
676
- this.events.trigger(R.PEER_CONNECTION_ONTRACK, I), e && e(I);
634
+ let c;
635
+ const d = ({ peerconnection: g }) => {
636
+ c = g;
637
+ const T = (p) => {
638
+ this.events.trigger(R.PEER_CONNECTION_ONTRACK, p);
677
639
  };
678
- l.addEventListener("track", E), this.disposers.add(() => {
679
- l.removeEventListener("track", E);
640
+ g.addEventListener("track", T), this.disposers.add(() => {
641
+ g.removeEventListener("track", T);
680
642
  });
681
643
  }, S = () => {
682
- d !== void 0 && this.events.trigger(R.PEER_CONNECTION_CONFIRMED, d), i(), o(), t(d);
644
+ c !== void 0 && this.events.trigger(R.PEER_CONNECTION_CONFIRMED, c), i(), a(), e(c);
683
645
  };
684
- r(), a();
646
+ s(), r();
685
647
  });
686
648
  subscribeToSessionEvents(e) {
687
649
  this.events.eachTriggers((t, s) => {
688
- const r = se.find((i) => i === s);
689
- r && (e.on(r, t), this.disposers.add(() => {
690
- e.off(r, t);
650
+ const i = ae.find((r) => r === s);
651
+ i && (e.on(i, t), this.disposers.add(() => {
652
+ e.off(i, t);
691
653
  }));
692
654
  });
693
655
  }
@@ -705,39 +667,226 @@ class Qe {
705
667
  };
706
668
  }
707
669
  class Ye {
708
- remoteStreams = {};
670
+ config;
671
+ tools;
672
+ connection;
673
+ constructor(e, t) {
674
+ this.config = e, this.tools = t, this.connection = new RTCPeerConnection(e.pcConfig), this.addTransceivers();
675
+ }
676
+ get settings() {
677
+ return this.config;
678
+ }
679
+ get peerConnection() {
680
+ return this.connection;
681
+ }
682
+ close() {
683
+ this.connection.close();
684
+ }
685
+ async call(e) {
686
+ const t = this.waitForTracks(), s = await this.createOffer(), i = await this.tools.sendOffer(
687
+ { conferenceNumber: e, quality: this.config.quality, audioChannel: this.config.audioChannel },
688
+ s
689
+ );
690
+ await this.setRemoteDescription(i), await t;
691
+ }
692
+ async createOffer() {
693
+ const e = await this.connection.createOffer();
694
+ return await this.connection.setLocalDescription(e), e;
695
+ }
696
+ async setRemoteDescription(e) {
697
+ return this.connection.setRemoteDescription(e);
698
+ }
699
+ async waitForTracks() {
700
+ return new Promise((e) => {
701
+ const t = /* @__PURE__ */ new Set(), s = (i) => {
702
+ const { track: r } = i;
703
+ t.add(r.kind), t.has("audio") && t.has("video") && (this.connection.removeEventListener("track", s), e());
704
+ };
705
+ this.connection.addEventListener("track", s);
706
+ });
707
+ }
708
+ addTransceivers() {
709
+ this.addRecvOnlyTransceiver("audio"), this.addRecvOnlyTransceiver("video"), this.addRecvOnlyTransceiver("video"), this.addRecvOnlyTransceiver("video"), this.addRecvOnlyTransceiver("video");
710
+ }
711
+ addRecvOnlyTransceiver(e) {
712
+ const t = {
713
+ direction: "recvonly"
714
+ };
715
+ return this.connection.addTransceiver(e, t);
716
+ }
717
+ }
718
+ const he = (n) => n.getSettings(), ze = (n, e) => {
719
+ const t = he(n);
720
+ let s = e;
721
+ s ??= n.label;
722
+ let i = t?.msid;
723
+ return i ??= s, i ??= n.id, i;
724
+ }, Xe = (n, e) => {
725
+ const t = he(n);
726
+ let s = e;
727
+ return s ??= t?.msid, s ??= n.label, (s && s.length > 0 ? s : void 0) ?? n.id;
728
+ };
729
+ class z {
730
+ participantGroups = /* @__PURE__ */ new Map();
731
+ trackToGroup = /* @__PURE__ */ new Map();
732
+ trackDisposers = /* @__PURE__ */ new Map();
709
733
  reset() {
710
- this.remoteStreams = {};
711
- }
712
- generateStream(e, t) {
713
- const { id: s } = e, r = this.remoteStreams[s] ?? new MediaStream();
714
- return t && r.addTrack(t), r.addTrack(e), this.remoteStreams[s] = r, r;
715
- }
716
- generateAudioStream(e) {
717
- const { id: t } = e, s = this.remoteStreams[t] ?? new MediaStream();
718
- return s.addTrack(e), this.remoteStreams[t] = s, s;
719
- }
720
- generateStreams(e) {
721
- const t = [];
722
- return e.forEach((s, r) => {
723
- if (s.kind === "audio")
724
- return;
725
- const i = s, a = e[r - 1];
726
- let o;
727
- a?.kind === "audio" && (o = a);
728
- const h = this.generateStream(i, o);
729
- t.push(h);
730
- }), t;
734
+ this.participantGroups.clear(), this.trackToGroup.clear(), this.trackDisposers.forEach((e) => {
735
+ e();
736
+ }), this.trackDisposers.clear();
737
+ }
738
+ addTrack(e, {
739
+ onRemoved: t,
740
+ streamHint: s
741
+ } = {}) {
742
+ const i = Xe(e, s), r = ze(e, s);
743
+ if (this.trackToGroup.has(e.id))
744
+ return { isAdded: !1 };
745
+ const a = this.getParticipantGroups(i);
746
+ let o = a.get(r);
747
+ o || (o = {
748
+ participantId: i,
749
+ groupId: r,
750
+ stream: new MediaStream(),
751
+ trackIds: /* @__PURE__ */ new Set()
752
+ }, a.set(r, o)), o.stream.addTrack(e), o.trackIds.add(e.id), this.trackToGroup.set(e.id, { participantId: i, groupId: r });
753
+ const c = () => {
754
+ this.disposeTrackListener(e.id), this.removeTrack(e.id) && t?.({ trackId: e.id, participantId: i });
755
+ };
756
+ return e.addEventListener("ended", c), this.trackDisposers.set(e.id, () => {
757
+ e.removeEventListener("ended", c);
758
+ }), { isAdded: !0, participantId: i };
759
+ }
760
+ removeTrack(e) {
761
+ this.disposeTrackListener(e);
762
+ const t = this.trackToGroup.get(e);
763
+ if (!t)
764
+ return !1;
765
+ const { participantId: s, groupId: i } = t, r = this.participantGroups.get(s), a = r?.get(i);
766
+ if (!a)
767
+ return this.trackToGroup.delete(e), !1;
768
+ const o = a.stream.getTracks().find((c) => c.id === e);
769
+ 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;
770
+ }
771
+ removeStaleTracks(e, t) {
772
+ const s = this.participantGroups.get(e);
773
+ if (!s)
774
+ return !1;
775
+ let i = !1;
776
+ return [...s.values()].forEach((a) => {
777
+ [...a.trackIds].filter((c) => !t.includes(c)).forEach((c) => {
778
+ const d = this.removeTrack(c);
779
+ i ||= d;
780
+ });
781
+ }), i;
782
+ }
783
+ getStreams(e) {
784
+ if (e !== void 0) {
785
+ const t = this.participantGroups.get(e);
786
+ return t ? [...t.values()].map((s) => s.stream) : [];
787
+ }
788
+ return [...this.participantGroups.values()].flatMap((t) => [...t.values()]).map((t) => t.stream);
789
+ }
790
+ disposeTrackListener(e) {
791
+ const t = this.trackDisposers.get(e);
792
+ t && (t(), this.trackDisposers.delete(e));
731
793
  }
732
- generateAudioStreams(e) {
733
- return e.map((t) => this.generateAudioStream(t));
794
+ getParticipantGroups(e) {
795
+ const t = this.participantGroups.get(e);
796
+ if (t)
797
+ return t;
798
+ const s = /* @__PURE__ */ new Map();
799
+ return this.participantGroups.set(e, s), s;
734
800
  }
735
801
  }
736
- class ze extends xe {
737
- remoteStreamsManager = new Ye();
802
+ const $ = {
803
+ type: "participant"
804
+ }, Je = {
805
+ type: "spectator_synthetic"
806
+ }, Ke = (n) => ({
807
+ type: "spectator",
808
+ recvParams: n
809
+ });
810
+ class f {
811
+ role = $;
812
+ mainManager;
813
+ recvManager;
814
+ onRoleChanged;
815
+ constructor({
816
+ mainManager: e,
817
+ recvManager: t
818
+ }, s) {
819
+ this.mainManager = e, this.recvManager = t, this.onRoleChanged = s;
820
+ }
821
+ static hasParticipant(e) {
822
+ return e.type === "participant";
823
+ }
824
+ static hasSpectatorSynthetic(e) {
825
+ return e.type === "spectator_synthetic";
826
+ }
827
+ static hasSpectator(e) {
828
+ return e.type === "spectator";
829
+ }
830
+ getRole() {
831
+ return this.role;
832
+ }
833
+ setCallRoleParticipant() {
834
+ this.changeRole($);
835
+ }
836
+ setCallRoleSpectatorSynthetic() {
837
+ this.changeRole(Je);
838
+ }
839
+ setCallRoleSpectator(e) {
840
+ this.changeRole(Ke(e));
841
+ }
842
+ changeRole(e) {
843
+ const t = this.role;
844
+ if (t.type !== e.type) {
845
+ this.setRole(e);
846
+ return;
847
+ }
848
+ f.hasSpectator(e) && f.hasSpectator(t) && t.recvParams.audioId !== e.recvParams.audioId && this.setRole(e);
849
+ }
850
+ reset() {
851
+ this.role = $, this.recvManager.reset();
852
+ }
853
+ getActiveManager() {
854
+ return this.hasSpectator() ? this.recvManager : this.mainManager;
855
+ }
856
+ hasParticipant() {
857
+ return f.hasParticipant(this.role);
858
+ }
859
+ hasSpectatorSynthetic() {
860
+ return f.hasSpectatorSynthetic(this.role);
861
+ }
862
+ hasSpectator() {
863
+ return f.hasSpectator(this.role);
864
+ }
865
+ setRole(e) {
866
+ const t = this.role;
867
+ this.role = e, this.onRoleChanged?.({ previous: t, next: e });
868
+ }
869
+ }
870
+ const X = (n) => n.streams[0]?.id;
871
+ class je {
872
+ events;
873
+ isPendingCall = !1;
874
+ isPendingAnswer = !1;
875
+ rtcSession;
876
+ callConfiguration = {};
877
+ mainRemoteStreamsManager = new z();
878
+ recvRemoteStreamsManager = new z();
879
+ roleManager = new f(
880
+ { mainManager: this.mainRemoteStreamsManager, recvManager: this.recvRemoteStreamsManager },
881
+ (e) => {
882
+ this.onRoleChanged(e);
883
+ }
884
+ );
738
885
  mcuSession;
739
- constructor(e) {
740
- super(e), this.mcuSession = new Qe(e, { onReset: this.reset });
886
+ recvSession;
887
+ disposeRecvSessionTrackListener;
888
+ constructor() {
889
+ this.events = new O(oe), this.mcuSession = new Qe(this.events, { onReset: this.reset }), this.subscribeCallStatusChange(), this.subscribeMcuRemoteTrackEvents();
741
890
  }
742
891
  get requested() {
743
892
  return this.isPendingCall || this.isPendingAnswer;
@@ -749,6 +898,24 @@ class ze extends xe {
749
898
  return this.mcuSession.isCallActive;
750
899
  }
751
900
  getEstablishedRTCSession = () => this.mcuSession.getEstablishedRTCSession();
901
+ on(e, t) {
902
+ return this.events.on(e, t);
903
+ }
904
+ onRace(e, t) {
905
+ return this.events.onRace(e, t);
906
+ }
907
+ once(e, t) {
908
+ return this.events.once(e, t);
909
+ }
910
+ onceRace(e, t) {
911
+ return this.events.onceRace(e, t);
912
+ }
913
+ async wait(e) {
914
+ return this.events.wait(e);
915
+ }
916
+ off(e, t) {
917
+ this.events.off(e, t);
918
+ }
752
919
  startCall = async (e, t, s) => (this.isPendingCall = !0, this.callConfiguration.number = s.number, this.callConfiguration.answer = !1, this.mcuSession.startCall(e, t, s).finally(() => {
753
920
  this.isPendingCall = !1;
754
921
  }));
@@ -766,9 +933,16 @@ class ze extends xe {
766
933
  return { ...this.callConfiguration };
767
934
  }
768
935
  getRemoteStreams() {
769
- const e = this.mcuSession.getRemoteTracks();
770
- if (e)
771
- return We(e) ? this.remoteStreamsManager.generateStreams(e) : this.remoteStreamsManager.generateAudioStreams(e);
936
+ return this.getActiveStreamsManager().getStreams();
937
+ }
938
+ setCallRoleParticipant() {
939
+ this.roleManager.setCallRoleParticipant();
940
+ }
941
+ setCallRoleSpectatorSynthetic() {
942
+ this.roleManager.setCallRoleSpectatorSynthetic();
943
+ }
944
+ setCallRoleSpectator(e) {
945
+ this.roleManager.setCallRoleSpectator(e);
772
946
  }
773
947
  async replaceMediaStream(e, t) {
774
948
  return this.mcuSession.replaceMediaStream(e, t);
@@ -776,103 +950,122 @@ class ze extends xe {
776
950
  async restartIce(e) {
777
951
  return this.mcuSession.restartIce(e);
778
952
  }
779
- async addTransceiver(e, t) {
780
- return this.mcuSession.addTransceiver(e, t);
781
- }
782
953
  reset = () => {
783
- this.remoteStreamsManager.reset(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1;
954
+ this.mainRemoteStreamsManager.reset(), this.callConfiguration.number = void 0, this.callConfiguration.answer = !1, this.roleManager.reset(), this.stopRecvSession();
784
955
  };
785
- }
786
- class Xe {
787
- events;
788
- strategy;
789
- constructor(e) {
790
- this.events = new y(re), this.strategy = e ?? new ze(this.events), this.subscribeCallStatusChange();
791
- }
792
- get requested() {
793
- return this.strategy.requested;
794
- }
795
- get connection() {
796
- return this.strategy.connection;
797
- }
798
- get isCallActive() {
799
- return this.strategy.isCallActive;
956
+ subscribeCallStatusChange() {
957
+ let { isCallActive: e } = this;
958
+ const { ACCEPTED: t, CONFIRMED: s, ENDED: i, FAILED: r } = R;
959
+ this.onRace([t, s, i, r], () => {
960
+ e = this.maybeTriggerCallStatus(e);
961
+ });
800
962
  }
801
- getEstablishedRTCSession = () => this.strategy.getEstablishedRTCSession();
802
- on(e, t) {
803
- return this.events.on(e, t);
963
+ maybeTriggerCallStatus(e) {
964
+ const t = this.isCallActive;
965
+ return t !== e && this.events.trigger(R.CALL_STATUS_CHANGED, { isCallActive: t }), t;
804
966
  }
805
- onRace(e, t) {
806
- return this.events.onRace(e, t);
967
+ subscribeMcuRemoteTrackEvents() {
968
+ this.on(R.PEER_CONNECTION_ONTRACK, (e) => {
969
+ this.addRemoteTrack(this.mainRemoteStreamsManager, e.track, X(e));
970
+ });
807
971
  }
808
- once(e, t) {
809
- return this.events.once(e, t);
972
+ addRemoteTrack(e, t, s) {
973
+ const i = e.addTrack(t, {
974
+ streamHint: s,
975
+ onRemoved: (r) => {
976
+ this.emitRemoteStreamsChanged(e, "removed", {
977
+ trackId: r.trackId,
978
+ participantId: r.participantId
979
+ });
980
+ }
981
+ });
982
+ i.isAdded && this.emitRemoteStreamsChanged(e, "added", {
983
+ trackId: t.id,
984
+ participantId: i.participantId
985
+ });
810
986
  }
811
- onceRace(e, t) {
812
- return this.events.onceRace(e, t);
987
+ emitRemoteStreamsChanged(e, t, { trackId: s, participantId: i }) {
988
+ const r = this.getActiveStreamsManager();
989
+ if (e !== r)
990
+ return;
991
+ const a = [...r.getStreams()];
992
+ this.events.trigger(R.REMOTE_STREAMS_CHANGED, {
993
+ participantId: i,
994
+ changeType: t,
995
+ trackId: s,
996
+ streams: a
997
+ });
813
998
  }
814
- async wait(e) {
815
- return this.events.wait(e);
999
+ getActiveStreamsManager() {
1000
+ return this.roleManager.getActiveManager();
816
1001
  }
817
- off(e, t) {
818
- this.events.off(e, t);
1002
+ attachRecvSessionTracks(e) {
1003
+ const { peerConnection: t } = e, s = (i) => {
1004
+ this.addRemoteTrack(this.recvRemoteStreamsManager, i.track, X(i));
1005
+ };
1006
+ t.addEventListener("track", s), this.disposeRecvSessionTrackListener = () => {
1007
+ t.removeEventListener("track", s);
1008
+ };
819
1009
  }
820
- setStrategy(e) {
821
- this.strategy = e;
822
- }
823
- startCall = async (...e) => this.strategy.startCall(...e);
824
- endCall = async () => this.strategy.endCall();
825
- answerToIncomingCall = async (...e) => this.strategy.answerToIncomingCall(...e);
826
- getCallConfiguration = () => this.strategy.getCallConfiguration();
827
- getRemoteStreams = () => this.strategy.getRemoteStreams();
828
- addTransceiver = async (...e) => this.strategy.addTransceiver(...e);
829
- replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
830
- restartIce = async (e) => this.strategy.restartIce(e);
831
- subscribeCallStatusChange() {
832
- let { isCallActive: e } = this;
833
- const { ACCEPTED: t, CONFIRMED: s, ENDED: r, FAILED: i } = R;
834
- this.onRace([t, s, r, i], () => {
835
- e = this.maybeTriggerCallStatus(e);
1010
+ startRecvSession(e, t) {
1011
+ const { number: s } = this.callConfiguration;
1012
+ if (s === void 0)
1013
+ return;
1014
+ this.stopRecvSession();
1015
+ const i = {
1016
+ quality: "high",
1017
+ audioChannel: e
1018
+ }, r = new Ye(i, { sendOffer: t });
1019
+ this.recvSession = r, this.recvRemoteStreamsManager.reset(), this.attachRecvSessionTracks(r), r.call(s).catch(() => {
1020
+ this.stopRecvSession();
836
1021
  });
837
1022
  }
838
- maybeTriggerCallStatus(e) {
839
- const t = this.isCallActive;
840
- return t !== e && this.events.trigger(R.CALL_STATUS_CHANGED, { isCallActive: t }), t;
1023
+ stopRecvSession() {
1024
+ this.recvSession?.close(), this.recvSession = void 0, this.disposeRecvSessionTrackListener?.(), this.disposeRecvSessionTrackListener = void 0, this.recvRemoteStreamsManager.reset();
841
1025
  }
1026
+ onRoleChanged = ({
1027
+ previous: e,
1028
+ next: t
1029
+ }) => {
1030
+ if (f.hasSpectator(e) && !f.hasSpectator(t) && this.stopRecvSession(), f.hasSpectator(t)) {
1031
+ const s = t.recvParams;
1032
+ this.startRecvSession(s.audioId, s.sendOffer);
1033
+ }
1034
+ };
842
1035
  }
843
- const Je = (n, e) => (n.degradationPreference = e.degradationPreference, n), Ke = (n, e) => {
1036
+ const Ze = (n, e) => (n.degradationPreference = e.degradationPreference, n), et = (n, e) => {
844
1037
  n.encodings ??= [];
845
1038
  for (let t = n.encodings.length; t < e; t += 1)
846
1039
  n.encodings.push({});
847
1040
  return n;
848
- }, oe = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, je = oe(), Ze = (n, e) => {
849
- if (je(n, e))
1041
+ }, de = (n) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== n, tt = de(), nt = (n, e) => {
1042
+ if (tt(n, e))
850
1043
  return n;
851
- }, et = (n, e) => {
852
- const t = n.maxBitrate, s = Ze(e, t);
1044
+ }, st = (n, e) => {
1045
+ const t = n.maxBitrate, s = nt(e, t);
853
1046
  return s !== void 0 && (n.maxBitrate = s), n;
854
- }, ce = 1, tt = oe(
855
- ce
856
- ), nt = (n, e) => {
857
- const t = n === void 0 ? void 0 : Math.max(n, ce);
858
- if (t !== void 0 && tt(
1047
+ }, le = 1, it = de(
1048
+ le
1049
+ ), rt = (n, e) => {
1050
+ const t = n === void 0 ? void 0 : Math.max(n, le);
1051
+ if (t !== void 0 && it(
859
1052
  t,
860
1053
  e
861
1054
  ))
862
1055
  return t;
863
- }, st = (n, e) => {
864
- const t = n.scaleResolutionDownBy, s = nt(
1056
+ }, at = (n, e) => {
1057
+ const t = n.scaleResolutionDownBy, s = rt(
865
1058
  e,
866
1059
  t
867
1060
  );
868
1061
  return s !== void 0 && (n.scaleResolutionDownBy = s), n;
869
- }, rt = (n, e) => {
1062
+ }, ot = (n, e) => {
870
1063
  const t = e.encodings?.length ?? 0;
871
- return Ke(n, t), n.encodings.forEach((s, r) => {
872
- const i = (e?.encodings ?? [])[r], a = i?.maxBitrate, o = i?.scaleResolutionDownBy;
873
- et(s, a), st(s, o);
1064
+ return et(n, t), n.encodings.forEach((s, i) => {
1065
+ const r = (e?.encodings ?? [])[i], a = r?.maxBitrate, o = r?.scaleResolutionDownBy;
1066
+ st(s, a), at(s, o);
874
1067
  }), n;
875
- }, it = (n, e) => {
1068
+ }, ct = (n, e) => {
876
1069
  if (n.codecs?.length !== e.codecs?.length)
877
1070
  return !0;
878
1071
  for (let t = 0; t < (n.codecs?.length ?? 0); t++)
@@ -889,15 +1082,15 @@ const Je = (n, e) => (n.degradationPreference = e.degradationPreference, n), Ke
889
1082
  if (JSON.stringify(n.encodings[t]) !== JSON.stringify(e.encodings[t]))
890
1083
  return !0;
891
1084
  return n.rtcp?.cname !== e.rtcp?.cname || n.rtcp?.reducedSize !== e.rtcp?.reducedSize || n.degradationPreference !== e.degradationPreference;
892
- }, at = async (n, e) => {
1085
+ }, ht = async (n, e) => {
893
1086
  const t = n.getParameters(), s = JSON.parse(
894
1087
  JSON.stringify(t)
895
1088
  );
896
- rt(t, e), Je(t, e);
897
- const r = it(s, t);
898
- return r && await n.setParameters(t), { parameters: t, isChanged: r };
899
- }, he = async (n, e, t) => {
900
- const { isChanged: s, parameters: r } = await at(n, {
1089
+ ot(t, e), Ze(t, e);
1090
+ const i = ct(s, t);
1091
+ return i && await n.setParameters(t), { parameters: t, isChanged: i };
1092
+ }, ue = async (n, e, t) => {
1093
+ const { isChanged: s, parameters: i } = await ht(n, {
901
1094
  encodings: [
902
1095
  {
903
1096
  scaleResolutionDownBy: e.scaleResolutionDownBy,
@@ -905,21 +1098,21 @@ const Je = (n, e) => (n.degradationPreference = e.degradationPreference, n), Ke
905
1098
  }
906
1099
  ]
907
1100
  });
908
- return s && t && t(r), { isChanged: s, parameters: r };
909
- }, ot = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), ct = async (n, e, t) => {
910
- const s = ot(n, e);
1101
+ return s && t && t(i), { isChanged: s, parameters: i };
1102
+ }, dt = (n, e) => n.find((t) => t.track !== null && e.getTracks().includes(t.track)), lt = async (n, e, t) => {
1103
+ const s = dt(n, e);
911
1104
  if (s)
912
- return he(s, { maxBitrate: t });
1105
+ return ue(s, { maxBitrate: t });
913
1106
  };
914
- 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 || {});
915
- const de = [
1107
+ 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 || {});
1108
+ const ge = [
916
1109
  "presentation:start",
917
1110
  "presentation:started",
918
1111
  "presentation:end",
919
1112
  "presentation:ended",
920
1113
  "presentation:failed"
921
- ], ht = 1, Gn = (n) => Pe(n);
922
- class dt {
1114
+ ], ut = 1, jn = (n) => we(n);
1115
+ class gt {
923
1116
  events;
924
1117
  promisePendingStartPresentation;
925
1118
  promisePendingStopPresentation;
@@ -931,7 +1124,7 @@ class dt {
931
1124
  callManager: e,
932
1125
  maxBitrate: t
933
1126
  }) {
934
- this.callManager = e, this.maxBitrate = t, this.events = new y(de), this.subscribe();
1127
+ this.callManager = e, this.maxBitrate = t, this.events = new O(ge), this.subscribe();
935
1128
  }
936
1129
  get isPendingPresentation() {
937
1130
  return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
@@ -939,20 +1132,20 @@ class dt {
939
1132
  // eslint-disable-next-line @typescript-eslint/max-params
940
1133
  async startPresentation(e, t, {
941
1134
  isNeedReinvite: s,
942
- contentHint: r,
943
- sendEncodings: i,
1135
+ contentHint: i,
1136
+ sendEncodings: r,
944
1137
  onAddedTransceiver: a
945
1138
  } = {}, o) {
946
- const h = this.getRtcSessionProtected();
1139
+ const c = this.getRtcSessionProtected();
947
1140
  if (this.streamPresentationCurrent)
948
1141
  throw new Error("Presentation is already started");
949
1142
  return this.sendPresentationWithDuplicatedCalls(e, {
950
- rtcSession: h,
1143
+ rtcSession: c,
951
1144
  stream: t,
952
1145
  presentationOptions: {
953
1146
  isNeedReinvite: s,
954
- contentHint: r,
955
- sendEncodings: i,
1147
+ contentHint: i,
1148
+ sendEncodings: r,
956
1149
  onAddedTransceiver: a
957
1150
  },
958
1151
  options: o
@@ -964,18 +1157,18 @@ class dt {
964
1157
  let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
965
1158
  this.promisePendingStartPresentation && await this.promisePendingStartPresentation.catch(() => {
966
1159
  });
967
- const r = this.callManager.getEstablishedRTCSession();
968
- return r && t ? s = e().then(async () => r.stopPresentation(t)).catch((i) => {
969
- const a = i instanceof Error ? i : new Error(String(i));
970
- throw this.events.trigger(O.FAILED_PRESENTATION, a), i;
971
- }) : t && this.events.trigger(O.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
1160
+ const i = this.callManager.getEstablishedRTCSession();
1161
+ return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
1162
+ const a = r instanceof Error ? r : new Error(String(r));
1163
+ throw this.events.trigger(P.FAILED_PRESENTATION, a), r;
1164
+ }) : t && this.events.trigger(P.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
972
1165
  this.resetPresentation();
973
1166
  });
974
1167
  }
975
1168
  async updatePresentation(e, t, {
976
1169
  contentHint: s,
977
- sendEncodings: r,
978
- onAddedTransceiver: i
1170
+ sendEncodings: i,
1171
+ onAddedTransceiver: r
979
1172
  } = {}) {
980
1173
  const a = this.getRtcSessionProtected();
981
1174
  if (!this.streamPresentationCurrent)
@@ -983,8 +1176,8 @@ class dt {
983
1176
  return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
984
1177
  contentHint: s,
985
1178
  isNeedReinvite: !1,
986
- sendEncodings: r,
987
- onAddedTransceiver: i
1179
+ sendEncodings: i,
1180
+ onAddedTransceiver: r
988
1181
  }).then(async (o) => (await this.setMaxBitrate(), o));
989
1182
  }
990
1183
  cancelSendPresentationWithRepeatedCalls() {
@@ -1007,60 +1200,60 @@ class dt {
1007
1200
  }
1008
1201
  subscribe() {
1009
1202
  this.callManager.on("presentation:start", (e) => {
1010
- this.events.trigger(O.START_PRESENTATION, e);
1203
+ this.events.trigger(P.START_PRESENTATION, e);
1011
1204
  }), this.callManager.on("presentation:started", (e) => {
1012
- this.events.trigger(O.STARTED_PRESENTATION, e);
1205
+ this.events.trigger(P.STARTED_PRESENTATION, e);
1013
1206
  }), this.callManager.on("presentation:end", (e) => {
1014
- this.events.trigger(O.END_PRESENTATION, e);
1207
+ this.events.trigger(P.END_PRESENTATION, e);
1015
1208
  }), this.callManager.on("presentation:ended", (e) => {
1016
- this.events.trigger(O.ENDED_PRESENTATION, e);
1209
+ this.events.trigger(P.ENDED_PRESENTATION, e);
1017
1210
  }), this.callManager.on("presentation:failed", (e) => {
1018
- this.events.trigger(O.FAILED_PRESENTATION, e);
1211
+ this.events.trigger(P.FAILED_PRESENTATION, e);
1019
1212
  }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
1020
1213
  }
1021
1214
  async sendPresentationWithDuplicatedCalls(e, {
1022
1215
  rtcSession: t,
1023
1216
  stream: s,
1024
- presentationOptions: r,
1025
- options: i = {
1026
- callLimit: ht
1217
+ presentationOptions: i,
1218
+ options: r = {
1219
+ callLimit: ut
1027
1220
  }
1028
1221
  }) {
1029
1222
  const a = async () => this.sendPresentation(
1030
1223
  e,
1031
1224
  t,
1032
1225
  s,
1033
- r
1226
+ i
1034
1227
  ), o = () => !!this.streamPresentationCurrent;
1035
- return this.cancelableSendPresentationWithRepeatedCalls = ee({
1228
+ return this.cancelableSendPresentationWithRepeatedCalls = se({
1036
1229
  targetFunction: a,
1037
1230
  isComplete: o,
1038
1231
  isRejectAsValid: !0,
1039
- ...i
1040
- }), this.cancelableSendPresentationWithRepeatedCalls.then((h) => h);
1232
+ ...r
1233
+ }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
1041
1234
  }
1042
1235
  // eslint-disable-next-line @typescript-eslint/max-params
1043
1236
  async sendPresentation(e, t, s, {
1044
- isNeedReinvite: r = !0,
1045
- contentHint: i = "detail",
1237
+ isNeedReinvite: i = !0,
1238
+ contentHint: r = "detail",
1046
1239
  degradationPreference: a,
1047
1240
  sendEncodings: o,
1048
- onAddedTransceiver: h
1241
+ onAddedTransceiver: c
1049
1242
  }) {
1050
- const d = B(s, { contentHint: i });
1243
+ const d = k(s, { contentHint: r });
1051
1244
  if (d === void 0)
1052
1245
  throw new Error("No streamPresentationTarget");
1053
1246
  this.streamPresentationCurrent = d;
1054
- const T = e().then(async () => t.startPresentation(d, r, {
1247
+ const S = e().then(async () => t.startPresentation(d, i, {
1055
1248
  degradationPreference: a,
1056
1249
  sendEncodings: o,
1057
- onAddedTransceiver: h
1058
- })).then(this.setMaxBitrate).then(() => s).catch((S) => {
1250
+ onAddedTransceiver: c
1251
+ })).then(this.setMaxBitrate).then(() => s).catch((g) => {
1059
1252
  this.removeStreamPresentationCurrent();
1060
- const l = S instanceof Error ? S : new Error(String(S));
1061
- throw this.events.trigger(O.FAILED_PRESENTATION, l), S;
1253
+ const T = g instanceof Error ? g : new Error(String(g));
1254
+ throw this.events.trigger(P.FAILED_PRESENTATION, T), g;
1062
1255
  });
1063
- return this.promisePendingStartPresentation = T, T.finally(() => {
1256
+ return this.promisePendingStartPresentation = S, S.finally(() => {
1064
1257
  this.promisePendingStartPresentation = void 0;
1065
1258
  });
1066
1259
  }
@@ -1068,8 +1261,8 @@ class dt {
1068
1261
  const { connection: e } = this.callManager, { streamPresentationCurrent: t } = this, { maxBitrate: s } = this;
1069
1262
  if (!e || !t || s === void 0)
1070
1263
  return;
1071
- const r = e.getSenders();
1072
- await ct(r, t, s);
1264
+ const i = e.getSenders();
1265
+ await lt(i, t, s);
1073
1266
  };
1074
1267
  getRtcSessionProtected = () => {
1075
1268
  const e = this.callManager.getEstablishedRTCSession();
@@ -1090,7 +1283,7 @@ class dt {
1090
1283
  delete this.streamPresentationCurrent;
1091
1284
  }
1092
1285
  }
1093
- class lt {
1286
+ class Tt {
1094
1287
  data;
1095
1288
  getUa;
1096
1289
  constructor(e) {
@@ -1140,7 +1333,13 @@ class lt {
1140
1333
  return this.data?.register === !0;
1141
1334
  }
1142
1335
  /**
1143
- * Получает SIP сервер URL из конфигурации
1336
+ * Получает SIP сервер IP из конфигурации
1337
+ */
1338
+ getSipServerIp() {
1339
+ return this.data?.sipServerIp;
1340
+ }
1341
+ /**
1342
+ * Получает SIP сервер URL (WebSocket) из конфигурации
1144
1343
  */
1145
1344
  getSipServerUrl() {
1146
1345
  return this.data?.sipServerUrl;
@@ -1171,7 +1370,7 @@ class lt {
1171
1370
  }
1172
1371
  }
1173
1372
  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 || {});
1174
- const le = [
1373
+ const Te = [
1175
1374
  "connecting",
1176
1375
  "connected",
1177
1376
  "disconnected",
@@ -1181,7 +1380,7 @@ const le = [
1181
1380
  "registrationFailed",
1182
1381
  "newMessage",
1183
1382
  "sipEvent"
1184
- ], ut = [
1383
+ ], St = [
1185
1384
  "disconnecting",
1186
1385
  "connect-started",
1187
1386
  "connect-succeeded",
@@ -1189,8 +1388,12 @@ const le = [
1189
1388
  "connect-parameters-resolve-success",
1190
1389
  "connect-parameters-resolve-failed",
1191
1390
  "connected-with-configuration"
1192
- ], ue = [...le, ...ut], gt = 3;
1193
- class Tt {
1391
+ ], Se = [...Te, ...St];
1392
+ function Ct(n) {
1393
+ return (e) => `sip:${e}@${n}`;
1394
+ }
1395
+ const Et = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, Ce = (n) => n.trim().replaceAll(" ", "_"), pt = Et(1e5, 99999999), Rt = 3;
1396
+ class At {
1194
1397
  cancelableConnectWithRepeatedCalls;
1195
1398
  JsSIP;
1196
1399
  events;
@@ -1202,22 +1405,22 @@ class Tt {
1202
1405
  getConnectionConfiguration;
1203
1406
  setConnectionConfiguration;
1204
1407
  updateConnectionConfiguration;
1205
- setSipServerUrl;
1408
+ setGetUri;
1206
1409
  setSocket;
1207
1410
  constructor(e) {
1208
- this.JsSIP = e.JsSIP, this.events = e.events, this.uaFactory = e.uaFactory, this.stateMachine = e.stateMachine, this.registrationManager = e.registrationManager, this.getUa = e.getUa, this.setUa = e.setUa, this.getConnectionConfiguration = e.getConnectionConfiguration, this.setConnectionConfiguration = e.setConnectionConfiguration, this.updateConnectionConfiguration = e.updateConnectionConfiguration, this.setSipServerUrl = e.setSipServerUrl, this.setSocket = e.setSocket, this.proxyEvents();
1411
+ this.JsSIP = e.JsSIP, this.events = e.events, this.uaFactory = e.uaFactory, this.stateMachine = e.stateMachine, this.registrationManager = e.registrationManager, this.getUa = e.getUa, this.setUa = e.setUa, this.getConnectionConfiguration = e.getConnectionConfiguration, this.setConnectionConfiguration = e.setConnectionConfiguration, this.updateConnectionConfiguration = e.updateConnectionConfiguration, this.setGetUri = e.setGetUri, this.setSocket = e.setSocket, this.proxyEvents();
1209
1412
  }
1210
1413
  connect = async (e, t) => (this.cancelRequests(), this.connectWithDuplicatedCalls(e, t));
1211
1414
  set = async ({ displayName: e }) => new Promise((t, s) => {
1212
- const r = this.getUa();
1213
- if (!r) {
1415
+ const i = this.getUa();
1416
+ if (!i) {
1214
1417
  s(new Error("this.ua is not initialized"));
1215
1418
  return;
1216
1419
  }
1217
- let i = !1;
1420
+ let r = !1;
1218
1421
  const a = this.getConnectionConfiguration();
1219
- e !== void 0 && e !== a?.displayName && (i = r.set("display_name", ie(e)), this.updateConnectionConfiguration("displayName", e));
1220
- const o = i;
1422
+ e !== void 0 && e !== a?.displayName && (r = i.set("display_name", Ce(e)), this.updateConnectionConfiguration("displayName", e));
1423
+ const o = r;
1221
1424
  o ? t(o) : s(new Error("nothing changed"));
1222
1425
  });
1223
1426
  disconnect = async () => {
@@ -1228,32 +1431,32 @@ class Tt {
1228
1431
  });
1229
1432
  }), t = this.getUa();
1230
1433
  return t ? t.stop() : this.events.trigger(C.DISCONNECTED, { socket: {}, error: !1 }), e.finally(() => {
1231
- this.setUa(void 0), this.stateMachine.reset();
1434
+ t?.removeAllListeners(), this.setUa(void 0), this.stateMachine.reset();
1232
1435
  });
1233
1436
  };
1234
1437
  cancelRequests() {
1235
1438
  this.cancelConnectWithRepeatedCalls();
1236
1439
  }
1237
- connectWithDuplicatedCalls = async (e, { callLimit: t = gt } = {}) => {
1238
- const s = async () => this.connectInner(e), r = (i) => {
1239
- const h = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = i != null && !Ue(i);
1240
- return h || d;
1440
+ connectWithDuplicatedCalls = async (e, { callLimit: t = Rt } = {}) => {
1441
+ const s = async () => this.connectInner(e), i = (r) => {
1442
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), d = r != null && !$e(r);
1443
+ return c || d;
1241
1444
  };
1242
- return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = ee({
1445
+ return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = se({
1243
1446
  targetFunction: s,
1244
- isComplete: r,
1447
+ isComplete: i,
1245
1448
  callLimit: t,
1246
1449
  isRejectAsValid: !0,
1247
1450
  isCheckBeforeCall: !1
1248
- }), this.cancelableConnectWithRepeatedCalls.then((i) => {
1249
- if ("ua" in i && i.ua instanceof this.JsSIP.UA)
1250
- return i;
1251
- throw i;
1451
+ }), this.cancelableConnectWithRepeatedCalls.then((r) => {
1452
+ if ("ua" in r && r.ua instanceof this.JsSIP.UA)
1453
+ return r;
1454
+ throw r;
1252
1455
  });
1253
1456
  };
1254
1457
  hasEqualConnectionConfiguration(e) {
1255
- const { configuration: t } = this.uaFactory.createConfiguration(e), r = this.getUa()?.configuration;
1256
- return r ? r.password === t.password && r.register === t.register && r.uri.toString() === t.uri && r.display_name === t.display_name && r.user_agent === t.user_agent && r.sockets === t.sockets && r.session_timers === t.session_timers && r.register_expires === t.register_expires && r.connection_recovery_min_interval === t.connection_recovery_min_interval && r.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1458
+ const { configuration: t } = this.uaFactory.createConfiguration(e), i = this.getUa()?.configuration;
1459
+ return i ? i.password === t.password && i.register === t.register && i.uri.toString() === t.uri && i.display_name === t.display_name && i.user_agent === t.user_agent && i.sockets === t.sockets && i.session_timers === t.session_timers && i.register_expires === t.register_expires && i.connection_recovery_min_interval === t.connection_recovery_min_interval && i.connection_recovery_max_interval === t.connection_recovery_max_interval : !1;
1257
1460
  }
1258
1461
  connectInner = async (e) => this.initUa(e).then(async () => this.start()).then((t) => {
1259
1462
  const s = this.getConnectionConfiguration();
@@ -1267,44 +1470,45 @@ class Tt {
1267
1470
  initUa = async ({
1268
1471
  user: e,
1269
1472
  password: t,
1270
- sipServerUrl: s,
1271
- sipWebSocketServerURL: r,
1272
- remoteAddress: i,
1473
+ sipServerIp: s,
1474
+ sipServerUrl: i,
1475
+ remoteAddress: r,
1273
1476
  sessionTimers: a,
1274
1477
  registerExpires: o,
1275
- connectionRecoveryMinInterval: h,
1478
+ connectionRecoveryMinInterval: c,
1276
1479
  connectionRecoveryMaxInterval: d,
1277
- userAgent: T,
1278
- displayName: S = "",
1279
- register: l = !1,
1280
- extraHeaders: E = []
1480
+ userAgent: S,
1481
+ displayName: g = "",
1482
+ register: T = !1,
1483
+ extraHeaders: p = []
1281
1484
  }) => {
1282
1485
  this.stateMachine.startInitUa(), this.setConnectionConfiguration({
1283
- sipServerUrl: s,
1284
- displayName: S,
1285
- register: l,
1486
+ sipServerIp: s,
1487
+ sipServerUrl: i,
1488
+ displayName: g,
1489
+ register: T,
1286
1490
  user: e,
1287
1491
  password: t
1288
1492
  }), this.getUa() && await this.disconnect();
1289
- const { ua: N, helpers: M } = this.uaFactory.createUAWithConfiguration(
1493
+ const { ua: A, helpers: D } = this.uaFactory.createUAWithConfiguration(
1290
1494
  {
1291
1495
  user: e,
1292
1496
  password: t,
1293
- sipServerUrl: s,
1294
- sipWebSocketServerURL: r,
1295
- displayName: S,
1296
- register: l,
1497
+ sipServerIp: s,
1498
+ sipServerUrl: i,
1499
+ displayName: g,
1500
+ register: T,
1297
1501
  sessionTimers: a,
1298
1502
  registerExpires: o,
1299
- connectionRecoveryMinInterval: h,
1503
+ connectionRecoveryMinInterval: c,
1300
1504
  connectionRecoveryMaxInterval: d,
1301
- userAgent: T,
1302
- remoteAddress: i,
1303
- extraHeaders: E
1505
+ userAgent: S,
1506
+ remoteAddress: r,
1507
+ extraHeaders: p
1304
1508
  },
1305
1509
  this.events
1306
1510
  );
1307
- return this.setUa(N), this.setSipServerUrl(M.getSipServerUrl), this.setSocket(M.socket), N;
1511
+ return this.setUa(A), this.setGetUri(D.getUri), this.setSocket(D.socket), A;
1308
1512
  };
1309
1513
  start = async () => new Promise((e, t) => {
1310
1514
  const s = this.getUa();
@@ -1312,22 +1516,22 @@ class Tt {
1312
1516
  t(new Error("this.ua is not initialized"));
1313
1517
  return;
1314
1518
  }
1315
- let r;
1316
- r = ((h, d) => {
1519
+ let i;
1520
+ i = ((c, d) => {
1317
1521
  if (this.getConnectionConfiguration()?.register === !0)
1318
- return this.registrationManager.subscribeToStartEvents(h, d);
1319
- const S = C.CONNECTED, l = [C.DISCONNECTED];
1320
- return this.events.on(S, h), l.forEach((E) => {
1321
- this.events.on(E, d);
1522
+ return this.registrationManager.subscribeToStartEvents(c, d);
1523
+ const g = C.CONNECTED, T = [C.DISCONNECTED];
1524
+ return this.events.on(g, c), T.forEach((p) => {
1525
+ this.events.on(p, d);
1322
1526
  }), () => {
1323
- this.events.off(S, h), l.forEach((E) => {
1324
- this.events.off(E, d);
1527
+ this.events.off(g, c), T.forEach((p) => {
1528
+ this.events.off(p, d);
1325
1529
  });
1326
1530
  };
1327
1531
  })(() => {
1328
- r?.(), e(s);
1329
- }, (h) => {
1330
- r?.(), t(h);
1532
+ i?.(), e(s);
1533
+ }, (c) => {
1534
+ i?.(), t(c);
1331
1535
  }), s.start();
1332
1536
  });
1333
1537
  cancelConnectWithRepeatedCalls() {
@@ -1343,18 +1547,18 @@ class Tt {
1343
1547
  });
1344
1548
  }
1345
1549
  }
1346
- var ge = /* @__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))(ge || {});
1347
- const St = Oe({
1550
+ var Ee = /* @__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))(Ee || {});
1551
+ const Nt = Ue({
1348
1552
  types: {
1349
1553
  context: {},
1350
1554
  events: {}
1351
1555
  },
1352
1556
  actions: {
1353
1557
  logTransition: (n, e) => {
1354
- c(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1558
+ h(`State transition: ${e.from} -> ${e.to} (${e.event})`);
1355
1559
  },
1356
1560
  logStateChange: (n, e) => {
1357
- c("ConnectionStateMachine state changed", e.state);
1561
+ h("ConnectionStateMachine state changed", e.state);
1358
1562
  }
1359
1563
  }
1360
1564
  }).createMachine({
@@ -1658,17 +1862,17 @@ const St = Oe({
1658
1862
  }
1659
1863
  }
1660
1864
  });
1661
- class Ct {
1865
+ class mt {
1662
1866
  actor;
1663
1867
  stateChangeListeners = /* @__PURE__ */ new Set();
1664
1868
  events;
1665
1869
  unsubscribeFromEvents;
1666
1870
  actorSubscription;
1667
1871
  constructor(e) {
1668
- this.events = e, this.actor = ye(St), this.actorSubscription = this.actor.subscribe((t) => {
1872
+ this.events = e, this.actor = Le(Nt), this.actorSubscription = this.actor.subscribe((t) => {
1669
1873
  const s = t.value;
1670
- this.stateChangeListeners.forEach((r) => {
1671
- r(s);
1874
+ this.stateChangeListeners.forEach((i) => {
1875
+ i(s);
1672
1876
  });
1673
1877
  }), this.actor.start(), this.subscribeToEvents();
1674
1878
  }
@@ -1751,7 +1955,7 @@ class Ct {
1751
1955
  return this.actor.getSnapshot().can({ type: e });
1752
1956
  }
1753
1957
  getValidEvents() {
1754
- return Object.values(ge).filter((e) => this.canTransition(e));
1958
+ return Object.values(Ee).filter((e) => this.canTransition(e));
1755
1959
  }
1756
1960
  hasState(e) {
1757
1961
  return this.actor.getSnapshot().matches(e);
@@ -1759,7 +1963,7 @@ class Ct {
1759
1963
  sendEvent(e) {
1760
1964
  const t = this.actor.getSnapshot(), s = { type: e };
1761
1965
  if (!t.can(s)) {
1762
- c(
1966
+ h(
1763
1967
  `Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`
1764
1968
  );
1765
1969
  return;
@@ -1820,7 +2024,7 @@ class Ct {
1820
2024
  };
1821
2025
  }
1822
2026
  }
1823
- class Et {
2027
+ class It {
1824
2028
  events;
1825
2029
  getUaProtected;
1826
2030
  constructor(e) {
@@ -1842,22 +2046,22 @@ class Et {
1842
2046
  try {
1843
2047
  await this.unregister();
1844
2048
  } catch (e) {
1845
- c("tryRegister", e);
2049
+ h("tryRegister", e);
1846
2050
  }
1847
2051
  return this.register();
1848
2052
  }
1849
2053
  subscribeToStartEvents(e, t) {
1850
- const s = C.REGISTERED, r = [C.REGISTRATION_FAILED, C.DISCONNECTED];
1851
- return this.events.on(s, e), r.forEach((i) => {
1852
- this.events.on(i, t);
2054
+ const s = C.REGISTERED, i = [C.REGISTRATION_FAILED, C.DISCONNECTED];
2055
+ return this.events.on(s, e), i.forEach((r) => {
2056
+ this.events.on(r, t);
1853
2057
  }), () => {
1854
- this.events.off(s, e), r.forEach((i) => {
1855
- this.events.off(i, t);
2058
+ this.events.off(s, e), i.forEach((r) => {
2059
+ this.events.off(r, t);
1856
2060
  });
1857
2061
  };
1858
2062
  }
1859
2063
  }
1860
- class At {
2064
+ class _t {
1861
2065
  uaFactory;
1862
2066
  getUaProtected;
1863
2067
  constructor(e) {
@@ -1867,14 +2071,14 @@ class At {
1867
2071
  * Отправляет SIP OPTIONS запрос к указанному адресу
1868
2072
  */
1869
2073
  async sendOptions(e, t, s) {
1870
- const r = this.getUaProtected();
1871
- return new Promise((i, a) => {
2074
+ const i = this.getUaProtected();
2075
+ return new Promise((r, a) => {
1872
2076
  try {
1873
- r.sendOptions(e, t, {
2077
+ i.sendOptions(e, t, {
1874
2078
  extraHeaders: s,
1875
2079
  eventHandlers: {
1876
2080
  succeeded: () => {
1877
- i();
2081
+ r();
1878
2082
  },
1879
2083
  failed: a
1880
2084
  }
@@ -1888,8 +2092,8 @@ class At {
1888
2092
  * Отправляет SIP OPTIONS запрос к собственному URI (ping)
1889
2093
  */
1890
2094
  async ping(e, t) {
1891
- const r = this.getUaProtected().configuration.uri;
1892
- return this.sendOptions(r, e, t);
2095
+ const i = this.getUaProtected().configuration.uri;
2096
+ return this.sendOptions(i, e, t);
1893
2097
  }
1894
2098
  /**
1895
2099
  * Проверяет доступность телефонии, создавая временное соединение
@@ -1897,36 +2101,36 @@ class At {
1897
2101
  async checkTelephony({
1898
2102
  userAgent: e,
1899
2103
  displayName: t,
1900
- sipServerUrl: s,
1901
- sipWebSocketServerURL: r,
1902
- remoteAddress: i,
2104
+ sipServerIp: s,
2105
+ sipServerUrl: i,
2106
+ remoteAddress: r,
1903
2107
  extraHeaders: a
1904
2108
  }) {
1905
- return new Promise((o, h) => {
2109
+ return new Promise((o, c) => {
1906
2110
  const { configuration: d } = this.uaFactory.createConfiguration({
1907
- sipWebSocketServerURL: r,
2111
+ sipServerUrl: i,
1908
2112
  displayName: t,
1909
2113
  userAgent: e,
1910
- sipServerUrl: s
1911
- }), T = this.uaFactory.createUA({ ...d, remoteAddress: i, extraHeaders: a }), S = () => {
1912
- const E = new Error("Telephony is not available");
1913
- h(E);
2114
+ sipServerIp: s
2115
+ }), S = this.uaFactory.createUA({ ...d, remoteAddress: r, extraHeaders: a }), g = () => {
2116
+ const p = new Error("Telephony is not available");
2117
+ c(p);
1914
2118
  };
1915
- T.once(C.DISCONNECTED, S);
1916
- const l = () => {
1917
- T.removeAllListeners(), T.once(C.DISCONNECTED, () => {
2119
+ S.once(C.DISCONNECTED, g);
2120
+ const T = () => {
2121
+ S.removeAllListeners(), S.once(C.DISCONNECTED, () => {
1918
2122
  o();
1919
- }), T.stop();
2123
+ }), S.stop();
1920
2124
  };
1921
- T.once(C.CONNECTED, l), T.start();
2125
+ S.once(C.CONNECTED, T), S.start();
1922
2126
  });
1923
2127
  }
1924
2128
  }
1925
- const Rt = (n) => {
2129
+ const Mt = (n) => {
1926
2130
  const e = [];
1927
2131
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1928
2132
  };
1929
- class D {
2133
+ class b {
1930
2134
  JsSIP;
1931
2135
  constructor(e) {
1932
2136
  this.JsSIP = e;
@@ -1938,88 +2142,88 @@ class D {
1938
2142
  register: e,
1939
2143
  password: t,
1940
2144
  user: s,
1941
- sipServerUrl: r,
1942
- sipWebSocketServerURL: i
2145
+ sipServerIp: i,
2146
+ sipServerUrl: r
1943
2147
  }) {
2148
+ if (!i)
2149
+ throw new Error("sipServerIp is required");
1944
2150
  if (!r)
1945
2151
  throw new Error("sipServerUrl is required");
1946
- if (!i)
1947
- throw new Error("sipWebSocketServerURL is required");
1948
2152
  if (e && (t === void 0 || t === ""))
1949
2153
  throw new Error("password is required for authorized connection");
1950
2154
  if (e && (s === void 0 || s === ""))
1951
2155
  throw new Error("user is required for authorized connection");
1952
2156
  }
1953
2157
  static resolveAuthorizationUser(e, t) {
1954
- return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${He()}`;
2158
+ return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${pt()}`;
1955
2159
  }
1956
2160
  static buildExtraHeaders(e, t) {
1957
- const s = e !== void 0 && e !== "" ? Rt(e) : [];
2161
+ const s = e !== void 0 && e !== "" ? Mt(e) : [];
1958
2162
  return t === void 0 ? s : [...s, ...t];
1959
2163
  }
1960
2164
  createConfiguration({
1961
2165
  user: e,
1962
2166
  password: t,
1963
- sipWebSocketServerURL: s,
1964
- displayName: r = "",
1965
- sipServerUrl: i,
2167
+ sipServerUrl: s,
2168
+ displayName: i = "",
2169
+ sipServerIp: r,
1966
2170
  register: a = !1,
1967
2171
  sessionTimers: o = !1,
1968
- registerExpires: h = 300,
2172
+ registerExpires: c = 300,
1969
2173
  // 5 minutes in sec
1970
2174
  connectionRecoveryMinInterval: d = 2,
1971
- connectionRecoveryMaxInterval: T = 6,
1972
- userAgent: S
2175
+ connectionRecoveryMaxInterval: S = 6,
2176
+ userAgent: g
1973
2177
  }) {
1974
- D.validateParametersConnection({
2178
+ b.validateParametersConnection({
1975
2179
  register: a,
1976
2180
  password: t,
1977
2181
  user: e,
1978
- sipServerUrl: i,
1979
- sipWebSocketServerURL: s
2182
+ sipServerIp: r,
2183
+ sipServerUrl: s
1980
2184
  });
1981
- const l = D.resolveAuthorizationUser(a, e), E = qe(i), I = E(l), N = new this.JsSIP.WebSocketInterface(s);
2185
+ const T = b.resolveAuthorizationUser(a, e), p = Ct(r), v = p(T), A = new this.JsSIP.WebSocketInterface(`wss://${s}/webrtc/wss/`);
1982
2186
  return {
1983
2187
  configuration: {
1984
2188
  password: t,
1985
2189
  register: a,
1986
- uri: I,
1987
- display_name: ie(r),
1988
- user_agent: S,
2190
+ uri: v,
2191
+ display_name: Ce(i),
2192
+ user_agent: g,
1989
2193
  sdpSemantics: "unified-plan",
1990
- sockets: [N],
2194
+ sockets: [A],
1991
2195
  session_timers: o,
1992
- register_expires: h,
2196
+ register_expires: c,
1993
2197
  connection_recovery_min_interval: d,
1994
- connection_recovery_max_interval: T
2198
+ connection_recovery_max_interval: S
1995
2199
  },
1996
2200
  helpers: {
1997
- socket: N,
1998
- getSipServerUrl: E
2201
+ socket: A,
2202
+ getUri: p
1999
2203
  }
2000
2204
  };
2001
2205
  }
2002
2206
  createUA({ remoteAddress: e, extraHeaders: t, ...s }) {
2003
- const r = new this.JsSIP.UA(s), i = D.buildExtraHeaders(e, t);
2004
- return i.length > 0 && r.registrator().setExtraHeaders(i), r;
2207
+ const i = new this.JsSIP.UA(s), r = b.buildExtraHeaders(e, t);
2208
+ return r.length > 0 && i.registrator().setExtraHeaders(r), i;
2005
2209
  }
2006
2210
  /**
2007
2211
  * Создает UA с полным жизненным циклом - конфигурация + создание + настройка событий
2008
2212
  */
2009
2213
  createUAWithConfiguration(e, t) {
2010
- const { configuration: s, helpers: r } = this.createConfiguration(e), i = this.createUA({
2214
+ const { configuration: s, helpers: i } = this.createConfiguration(e), r = this.createUA({
2011
2215
  ...s,
2012
2216
  remoteAddress: e.remoteAddress,
2013
2217
  extraHeaders: e.extraHeaders
2014
2218
  });
2015
2219
  return t.eachTriggers((a, o) => {
2016
- const h = le.find((d) => d === o);
2017
- h && i.on(h, a);
2018
- }), { ua: i, helpers: r };
2220
+ const c = Te.find((d) => d === o);
2221
+ c && r.on(c, a);
2222
+ }), { ua: r, helpers: i };
2019
2223
  }
2020
2224
  }
2021
- const Te = "Not ready for connection", Nt = (n) => n instanceof Error && n.message === Te, mt = () => new Error(Te), It = async (n) => typeof n == "function" ? n() : n;
2022
- class pt {
2225
+ const pe = "Not ready for connection", ft = (n) => n instanceof Error && n.message === pe, vt = () => new Error(pe), Pt = async (n) => typeof n == "function" ? n() : n;
2226
+ class Ot {
2023
2227
  events;
2024
2228
  ua;
2025
2229
  socket;
@@ -2031,15 +2235,15 @@ class pt {
2031
2235
  configurationManager;
2032
2236
  JsSIP;
2033
2237
  constructor({ JsSIP: e }) {
2034
- this.JsSIP = e, this.events = new y(ue), this.uaFactory = new D(e), this.registrationManager = new Et({
2238
+ this.JsSIP = e, this.events = new O(Se), this.uaFactory = new b(e), this.registrationManager = new It({
2035
2239
  events: this.events,
2036
2240
  getUaProtected: this.getUaProtected
2037
- }), this.stateMachine = new Ct(this.events), this.configurationManager = new lt({
2241
+ }), this.stateMachine = new mt(this.events), this.configurationManager = new Tt({
2038
2242
  getUa: this.getUa
2039
- }), this.sipOperations = new At({
2243
+ }), this.sipOperations = new _t({
2040
2244
  uaFactory: this.uaFactory,
2041
2245
  getUaProtected: this.getUaProtected
2042
- }), this.connectionFlow = new Tt({
2246
+ }), this.connectionFlow = new At({
2043
2247
  JsSIP: this.JsSIP,
2044
2248
  events: this.events,
2045
2249
  uaFactory: this.uaFactory,
@@ -2056,8 +2260,8 @@ class pt {
2056
2260
  setUa: (t) => {
2057
2261
  this.ua = t;
2058
2262
  },
2059
- setSipServerUrl: (t) => {
2060
- this.getSipServerUrl = t;
2263
+ setGetUri: (t) => {
2264
+ this.getUri = t;
2061
2265
  },
2062
2266
  setSocket: (t) => {
2063
2267
  this.socket = t;
@@ -2086,13 +2290,13 @@ class pt {
2086
2290
  return this.stateMachine.state;
2087
2291
  }
2088
2292
  get isRegistered() {
2089
- return D.isRegisteredUA(this.ua);
2293
+ return b.isRegisteredUA(this.ua);
2090
2294
  }
2091
2295
  get isRegisterConfig() {
2092
2296
  return this.configurationManager.isRegister();
2093
2297
  }
2094
2298
  connect = async (e, t) => this.disconnect().catch((s) => {
2095
- c("connect: disconnect error", s);
2299
+ h("connect: disconnect error", s);
2096
2300
  }).then(async () => this.connectWithProcessError(e, t));
2097
2301
  set = async ({ displayName: e }) => this.connectionFlow.set({ displayName: e });
2098
2302
  disconnect = async () => {
@@ -2132,7 +2336,7 @@ class pt {
2132
2336
  this.stateMachine.destroy();
2133
2337
  }
2134
2338
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
2135
- getSipServerUrl = (e) => e;
2339
+ getUri = (e) => e;
2136
2340
  getUaProtected = () => {
2137
2341
  if (!this.ua)
2138
2342
  throw new Error("UA not initialized");
@@ -2141,28 +2345,28 @@ class pt {
2141
2345
  getUa = () => this.ua;
2142
2346
  connectWithProcessError = async (e, t) => {
2143
2347
  if (!(t?.hasReadyForConnection?.() ?? !0))
2144
- throw mt();
2145
- return this.processConnect(e, t).catch(async (r) => {
2146
- const i = r;
2348
+ throw vt();
2349
+ return this.processConnect(e, t).catch(async (i) => {
2350
+ const r = i;
2147
2351
  return this.disconnect().then(() => {
2148
- throw i;
2352
+ throw r;
2149
2353
  }).catch(() => {
2150
- throw i;
2354
+ throw r;
2151
2355
  });
2152
2356
  });
2153
2357
  };
2154
- processConnect = async (e, t) => (this.events.trigger(C.CONNECT_STARTED, {}), It(e).then((s) => (this.events.trigger(C.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
2358
+ processConnect = async (e, t) => (this.events.trigger(C.CONNECT_STARTED, {}), Pt(e).then((s) => (this.events.trigger(C.CONNECT_PARAMETERS_RESOLVE_SUCCESS, s), s)).catch((s) => {
2155
2359
  throw this.events.trigger(C.CONNECT_PARAMETERS_RESOLVE_FAILED, s), s;
2156
2360
  }).then(async (s) => this.connectionFlow.connect(s, t)).then((s) => (this.events.trigger(C.CONNECT_SUCCEEDED, {
2157
2361
  ...s
2158
2362
  }), s)).catch((s) => {
2159
- const r = s ?? new Error("Failed to connect to server");
2160
- throw this.events.trigger(C.CONNECT_FAILED, r), r;
2363
+ const i = s ?? new Error("Failed to connect to server");
2364
+ throw this.events.trigger(C.CONNECT_FAILED, i), i;
2161
2365
  }));
2162
2366
  }
2163
- class _t {
2367
+ class yt {
2164
2368
  connectionManager;
2165
- stackPromises = te({
2369
+ stackPromises = ie({
2166
2370
  noRunIsNotActual: !0
2167
2371
  });
2168
2372
  constructor({ connectionManager: e }) {
@@ -2174,11 +2378,11 @@ class _t {
2174
2378
  this.stackPromises.stop();
2175
2379
  }
2176
2380
  }
2177
- const Y = 0, Mt = 30;
2178
- class ft {
2179
- countInner = Y;
2180
- initialCount = Y;
2181
- limitInner = Mt;
2381
+ const J = 0, Dt = 30;
2382
+ class bt {
2383
+ countInner = J;
2384
+ initialCount = J;
2385
+ limitInner = Dt;
2182
2386
  isInProgress = !1;
2183
2387
  onStatusChange;
2184
2388
  constructor({
@@ -2211,7 +2415,7 @@ class ft {
2211
2415
  this.countInner = this.initialCount, this.finishAttempt();
2212
2416
  }
2213
2417
  }
2214
- class vt {
2418
+ class wt {
2215
2419
  connectionManager;
2216
2420
  interval;
2217
2421
  checkTelephonyByTimeout = void 0;
@@ -2227,14 +2431,14 @@ class vt {
2227
2431
  onSuccessRequest: t,
2228
2432
  onFailRequest: s
2229
2433
  }) {
2230
- this.stop(), this.cancelableBeforeRequest = new x(e), this.checkTelephonyByTimeout = _e({
2434
+ this.stop(), this.cancelableBeforeRequest = new x(e), this.checkTelephonyByTimeout = Oe({
2231
2435
  isDontStopOnFail: !0,
2232
2436
  requestInterval: this.interval,
2233
2437
  request: async () => {
2234
2438
  if (!this.cancelableBeforeRequest)
2235
2439
  throw new Error("cancelableBeforeRequest is not defined");
2236
- const r = await this.cancelableBeforeRequest.request();
2237
- return this.connectionManager.checkTelephony(r);
2440
+ const i = await this.cancelableBeforeRequest.request();
2441
+ return this.connectionManager.checkTelephony(i);
2238
2442
  }
2239
2443
  }), this.checkTelephonyByTimeout.start(void 0, {
2240
2444
  onFailRequest: s,
@@ -2247,8 +2451,8 @@ class vt {
2247
2451
  this.checkTelephonyByTimeout?.stop(), this.checkTelephonyByTimeout = void 0, this.cancelableBeforeRequest?.cancelRequest(), this.cancelableBeforeRequest = void 0;
2248
2452
  }
2249
2453
  }
2250
- var _ = /* @__PURE__ */ ((n) => (n.BEFORE_ATTEMPT = "before-attempt", n.SUCCESS = "success", n.FAILED_ALL_ATTEMPTS = "failed-all-attempts", n.CANCELLED_ATTEMPTS = "cancelled-attempts", n.CHANGED_ATTEMPT_STATUS = "changed-attempt-status", n.STOP_ATTEMPTS_BY_ERROR = "stop-attempts-by-error", n.LIMIT_REACHED_ATTEMPTS = "limit-reached-attempts", n))(_ || {});
2251
- const Se = [
2454
+ 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 || {});
2455
+ const Re = [
2252
2456
  "before-attempt",
2253
2457
  "success",
2254
2458
  "failed-all-attempts",
@@ -2256,28 +2460,28 @@ const Se = [
2256
2460
  "changed-attempt-status",
2257
2461
  "stop-attempts-by-error",
2258
2462
  "limit-reached-attempts"
2259
- ], Pt = 15e3, Ot = 2;
2260
- class yt {
2463
+ ], Ut = 15e3, Lt = 2;
2464
+ class Bt {
2261
2465
  connectionManager;
2262
2466
  pingServerByTimeoutWithFailCalls;
2263
2467
  constructor({ connectionManager: e }) {
2264
- this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = Me(Ot, {
2468
+ this.connectionManager = e, this.pingServerByTimeoutWithFailCalls = ye(Lt, {
2265
2469
  whenPossibleRequest: async () => {
2266
2470
  },
2267
- requestInterval: Pt,
2268
- request: async () => (c("ping"), this.connectionManager.ping().then(() => {
2269
- c("ping success");
2471
+ requestInterval: Ut,
2472
+ request: async () => (h("ping"), this.connectionManager.ping().then(() => {
2473
+ h("ping success");
2270
2474
  }))
2271
2475
  });
2272
2476
  }
2273
2477
  start({ onFailRequest: e }) {
2274
- this.pingServerByTimeoutWithFailCalls.start(void 0, { onFailRequest: e }).catch(c);
2478
+ this.pingServerByTimeoutWithFailCalls.start(void 0, { onFailRequest: e }).catch(h);
2275
2479
  }
2276
2480
  stop() {
2277
2481
  this.pingServerByTimeoutWithFailCalls.stop();
2278
2482
  }
2279
2483
  }
2280
- class Dt {
2484
+ class kt {
2281
2485
  callManager;
2282
2486
  pingServerRequester;
2283
2487
  disposeCallStatusChange;
@@ -2285,17 +2489,17 @@ class Dt {
2285
2489
  connectionManager: e,
2286
2490
  callManager: t
2287
2491
  }) {
2288
- this.callManager = t, this.pingServerRequester = new yt({
2492
+ this.callManager = t, this.pingServerRequester = new Bt({
2289
2493
  connectionManager: e
2290
2494
  });
2291
2495
  }
2292
2496
  start({ onFailRequest: e }) {
2293
- c("start"), this.disposeCallStatusChange = this.callManager.on("call-status-changed", () => {
2497
+ h("start"), this.disposeCallStatusChange = this.callManager.on("call-status-changed", () => {
2294
2498
  this.handleCallStatusChange({ onFailRequest: e });
2295
2499
  }), this.handleCallStatusChange({ onFailRequest: e });
2296
2500
  }
2297
2501
  stop() {
2298
- c("stop"), this.pingServerRequester.stop(), this.unsubscribeCallStatusChange();
2502
+ h("stop"), this.pingServerRequester.stop(), this.unsubscribeCallStatusChange();
2299
2503
  }
2300
2504
  unsubscribeCallStatusChange() {
2301
2505
  this.disposeCallStatusChange?.(), this.disposeCallStatusChange = void 0;
@@ -2304,7 +2508,7 @@ class Dt {
2304
2508
  this.callManager.isCallActive ? this.pingServerRequester.stop() : this.pingServerRequester.start({ onFailRequest: e });
2305
2509
  }
2306
2510
  }
2307
- class bt {
2511
+ class Ft {
2308
2512
  connectionManager;
2309
2513
  callManager;
2310
2514
  isRegistrationFailed = !1;
@@ -2338,12 +2542,12 @@ class bt {
2338
2542
  this.isRegistrationFailed = !1;
2339
2543
  }
2340
2544
  }
2341
- const wt = 3e3, Ut = 15e3, z = {
2545
+ const $t = 3e3, qt = 15e3, K = {
2342
2546
  LIMIT_REACHED: "Limit reached",
2343
2547
  FAILED_TO_RECONNECT: "Failed to reconnect"
2344
- }, Lt = async () => {
2345
- }, Bt = (n) => !0;
2346
- class Ft {
2548
+ }, Wt = async () => {
2549
+ }, Ht = (n) => !0;
2550
+ class Gt {
2347
2551
  events;
2348
2552
  connectionManager;
2349
2553
  connectionQueueManager;
@@ -2361,29 +2565,29 @@ class Ft {
2361
2565
  connectionQueueManager: e,
2362
2566
  connectionManager: t,
2363
2567
  callManager: s
2364
- }, r) {
2365
- const i = r?.onBeforeRetry ?? Lt, a = r?.canRetryOnError ?? Bt;
2366
- this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = i, this.canRetryOnError = a, this.networkInterfacesSubscriber = r?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = r?.resumeFromSleepModeSubscriber, this.events = new y(Se), this.checkTelephonyRequester = new vt({
2568
+ }, i) {
2569
+ const r = i?.onBeforeRetry ?? Wt, a = i?.canRetryOnError ?? Ht;
2570
+ this.connectionQueueManager = e, this.connectionManager = t, this.onBeforeRetry = r, this.canRetryOnError = a, this.networkInterfacesSubscriber = i?.networkInterfacesSubscriber, this.resumeFromSleepModeSubscriber = i?.resumeFromSleepModeSubscriber, this.events = new O(Re), this.checkTelephonyRequester = new wt({
2367
2571
  connectionManager: t,
2368
- interval: r?.checkTelephonyRequestInterval ?? Ut
2369
- }), this.pingServerIfNotActiveCallRequester = new Dt({
2572
+ interval: i?.checkTelephonyRequestInterval ?? qt
2573
+ }), this.pingServerIfNotActiveCallRequester = new kt({
2370
2574
  connectionManager: t,
2371
2575
  callManager: s
2372
- }), this.registrationFailedOutOfCallSubscriber = new bt({
2576
+ }), this.registrationFailedOutOfCallSubscriber = new Ft({
2373
2577
  connectionManager: t,
2374
2578
  callManager: s
2375
- }), this.attemptsState = new ft({
2579
+ }), this.attemptsState = new bt({
2376
2580
  onStatusChange: this.emitStatusChange
2377
- }), this.cancelableRequestBeforeRetry = new x(i), this.delayBetweenAttempts = new fe(
2378
- r?.timeoutBetweenAttempts ?? wt
2581
+ }), this.cancelableRequestBeforeRetry = new x(r), this.delayBetweenAttempts = new De(
2582
+ i?.timeoutBetweenAttempts ?? $t
2379
2583
  );
2380
2584
  }
2381
2585
  start(e) {
2382
- c("auto connector start"), this.restartConnectionAttempts(e), this.subscribeToHardwareTriggers(e);
2586
+ h("auto connector start"), this.restartConnectionAttempts(e), this.subscribeToHardwareTriggers(e);
2383
2587
  }
2384
2588
  stop() {
2385
- c("auto connector stop"), this.unsubscribeFromHardwareTriggers(), this.stopConnectionFlow().catch((e) => {
2386
- c("auto connector stop from stop method: error", e);
2589
+ h("auto connector stop"), this.unsubscribeFromHardwareTriggers(), this.stopConnectionFlow().catch((e) => {
2590
+ h("auto connector stop from stop method: error", e);
2387
2591
  });
2388
2592
  }
2389
2593
  on(e, t) {
@@ -2402,78 +2606,78 @@ class Ft {
2402
2606
  this.events.off(e, t);
2403
2607
  }
2404
2608
  restartConnectionAttempts(e) {
2405
- c("auto connector restart connection attempts"), this.stopConnectionFlow().then(async () => this.attemptConnection(e)).catch((t) => {
2406
- c("auto connector failed to restart connection attempts:", t);
2609
+ h("auto connector restart connection attempts"), this.stopConnectionFlow().then(async () => this.attemptConnection(e)).catch((t) => {
2610
+ h("auto connector failed to restart connection attempts:", t);
2407
2611
  });
2408
2612
  }
2409
2613
  async stopConnectionFlow() {
2410
- c("stopConnectionFlow"), this.stopAttempts(), this.stopConnectTriggers(), await this.connectionQueueManager.disconnect();
2614
+ h("stopConnectionFlow"), this.stopAttempts(), this.stopConnectTriggers(), await this.connectionQueueManager.disconnect();
2411
2615
  }
2412
2616
  stopAttempts() {
2413
2617
  this.attemptsState.isAttemptInProgress && this.connectionQueueManager.stop(), this.delayBetweenAttempts.cancelRequest(), this.cancelableRequestBeforeRetry.cancelRequest(), this.attemptsState.reset();
2414
2618
  }
2415
2619
  stopConnectTriggers() {
2416
- c("stopConnectTriggers"), this.stopPingRequester(), this.checkTelephonyRequester.stop(), this.registrationFailedOutOfCallSubscriber.unsubscribe();
2620
+ h("stopConnectTriggers"), this.stopPingRequester(), this.checkTelephonyRequester.stop(), this.registrationFailedOutOfCallSubscriber.unsubscribe();
2417
2621
  }
2418
2622
  startCheckTelephony(e) {
2419
- c("startCheckTelephony"), this.checkTelephonyRequester.start({
2623
+ h("startCheckTelephony"), this.checkTelephonyRequester.start({
2420
2624
  onBeforeRequest: async () => (await this.onBeforeRetry(), e.getParameters()),
2421
2625
  onSuccessRequest: () => {
2422
- c("startCheckTelephony: onSuccessRequest"), this.connectIfDisconnected(e);
2626
+ h("startCheckTelephony: onSuccessRequest"), this.connectIfDisconnected(e);
2423
2627
  },
2424
2628
  onFailRequest: (t) => {
2425
- c("startCheckTelephony: onFailRequest", t.message);
2629
+ h("startCheckTelephony: onFailRequest", t.message);
2426
2630
  }
2427
2631
  });
2428
2632
  }
2429
2633
  async attemptConnection(e) {
2430
- if (c("attemptConnection: attempts.count", this.attemptsState.count), this.events.trigger(_.BEFORE_ATTEMPT, {}), this.stopConnectTriggers(), this.attemptsState.hasLimitReached()) {
2431
- c("attemptConnection: limit reached"), this.handleLimitReached(e);
2634
+ if (h("attemptConnection: attempts.count", this.attemptsState.count), this.events.trigger(I.BEFORE_ATTEMPT, {}), this.stopConnectTriggers(), this.attemptsState.hasLimitReached()) {
2635
+ h("attemptConnection: limit reached"), this.handleLimitReached(e);
2432
2636
  return;
2433
2637
  }
2434
2638
  return this.attemptsState.startAttempt(), this.attemptsState.increment(), this.executeConnectionAttempt(e);
2435
2639
  }
2436
2640
  async executeConnectionAttempt(e) {
2437
2641
  try {
2438
- await this.connectionQueueManager.connect(e.getParameters, e.options), c("executeConnectionAttempt: success"), this.handleSucceededAttempt(e);
2642
+ await this.connectionQueueManager.connect(e.getParameters, e.options), h("executeConnectionAttempt: success"), this.handleSucceededAttempt(e);
2439
2643
  } catch (t) {
2440
2644
  this.handleConnectionError(t, e);
2441
2645
  }
2442
2646
  }
2443
2647
  handleConnectionError(e, t) {
2444
- if (Nt(e)) {
2445
- this.attemptsState.finishAttempt(), this.events.trigger(_.STOP_ATTEMPTS_BY_ERROR, e);
2648
+ if (ft(e)) {
2649
+ this.attemptsState.finishAttempt(), this.events.trigger(I.STOP_ATTEMPTS_BY_ERROR, e);
2446
2650
  return;
2447
2651
  }
2448
2652
  if (!this.canRetryOnError(e)) {
2449
- c("executeConnectionAttempt: error does not allow retry", e), this.attemptsState.finishAttempt(), this.events.trigger(_.STOP_ATTEMPTS_BY_ERROR, e);
2653
+ h("executeConnectionAttempt: error does not allow retry", e), this.attemptsState.finishAttempt(), this.events.trigger(I.STOP_ATTEMPTS_BY_ERROR, e);
2450
2654
  return;
2451
2655
  }
2452
- if (De(e)) {
2453
- c("executeConnectionAttempt: not actual error", e), this.attemptsState.finishAttempt(), this.events.trigger(_.CANCELLED_ATTEMPTS, e);
2656
+ if (Be(e)) {
2657
+ h("executeConnectionAttempt: not actual error", e), this.attemptsState.finishAttempt(), this.events.trigger(I.CANCELLED_ATTEMPTS, e);
2454
2658
  return;
2455
2659
  }
2456
- c("executeConnectionAttempt: error", e), this.scheduleReconnect(t);
2660
+ h("executeConnectionAttempt: error", e), this.scheduleReconnect(t);
2457
2661
  }
2458
2662
  handleLimitReached(e) {
2459
- this.attemptsState.finishAttempt(), this.events.trigger(_.LIMIT_REACHED_ATTEMPTS, new Error(z.LIMIT_REACHED)), this.startCheckTelephony(e);
2663
+ this.attemptsState.finishAttempt(), this.events.trigger(I.LIMIT_REACHED_ATTEMPTS, new Error(K.LIMIT_REACHED)), this.startCheckTelephony(e);
2460
2664
  }
2461
2665
  handleSucceededAttempt(e) {
2462
- c("handleSucceededAttempt"), this.subscribeToConnectTriggers(e), this.events.trigger(_.SUCCESS);
2666
+ h("handleSucceededAttempt"), this.subscribeToConnectTriggers(e), this.events.trigger(I.SUCCESS);
2463
2667
  }
2464
2668
  subscribeToConnectTriggers(e) {
2465
2669
  this.startPingRequester(e), this.registrationFailedOutOfCallSubscriber.subscribe(() => {
2466
- c("registrationFailedOutOfCallListener callback"), this.restartConnectionAttempts(e);
2670
+ h("registrationFailedOutOfCallListener callback"), this.restartConnectionAttempts(e);
2467
2671
  });
2468
2672
  }
2469
2673
  subscribeToHardwareTriggers(e) {
2470
- this.unsubscribeFromHardwareTriggers(), c("subscribeToHardwareTriggers"), this.networkInterfacesSubscriber?.subscribe({
2674
+ this.unsubscribeFromHardwareTriggers(), h("subscribeToHardwareTriggers"), this.networkInterfacesSubscriber?.subscribe({
2471
2675
  onChange: () => {
2472
- c("networkInterfacesSubscriber onChange"), this.restartConnectionAttempts(e);
2676
+ h("networkInterfacesSubscriber onChange"), this.restartConnectionAttempts(e);
2473
2677
  },
2474
2678
  onUnavailable: () => {
2475
- c("networkInterfacesSubscriber onUnavailable"), this.stopConnectionFlow().catch((t) => {
2476
- c(
2679
+ h("networkInterfacesSubscriber onUnavailable"), this.stopConnectionFlow().catch((t) => {
2680
+ h(
2477
2681
  "auto connector stop from networkInterfacesSubscriber onUnavailable: error",
2478
2682
  t
2479
2683
  );
@@ -2481,12 +2685,12 @@ class Ft {
2481
2685
  }
2482
2686
  }), this.resumeFromSleepModeSubscriber?.subscribe({
2483
2687
  onResume: () => {
2484
- c("resumeFromSleepModeSubscriber onResume"), this.restartConnectionAttempts(e);
2688
+ h("resumeFromSleepModeSubscriber onResume"), this.restartConnectionAttempts(e);
2485
2689
  }
2486
2690
  });
2487
2691
  }
2488
2692
  unsubscribeFromHardwareTriggers() {
2489
- c("unsubscribeFromHardwareTriggers"), this.networkInterfacesSubscriber?.unsubscribe(), this.resumeFromSleepModeSubscriber?.unsubscribe();
2693
+ h("unsubscribeFromHardwareTriggers"), this.networkInterfacesSubscriber?.unsubscribe(), this.resumeFromSleepModeSubscriber?.unsubscribe();
2490
2694
  }
2491
2695
  stopPingRequester() {
2492
2696
  this.pingServerIfNotActiveCallRequester.stop();
@@ -2494,18 +2698,18 @@ class Ft {
2494
2698
  startPingRequester(e) {
2495
2699
  this.pingServerIfNotActiveCallRequester.start({
2496
2700
  onFailRequest: () => {
2497
- c("pingRequester: onFailRequest"), this.restartConnectionAttempts(e);
2701
+ h("pingRequester: onFailRequest"), this.restartConnectionAttempts(e);
2498
2702
  }
2499
2703
  });
2500
2704
  }
2501
2705
  connectIfDisconnected(e) {
2502
2706
  const t = this.isConnectionUnavailable();
2503
- c("connectIfDisconnected: isUnavailable", t), t ? this.restartConnectionAttempts(e) : (this.stopConnectTriggers(), this.events.trigger(_.SUCCESS));
2707
+ h("connectIfDisconnected: isUnavailable", t), t ? this.restartConnectionAttempts(e) : (this.stopConnectTriggers(), this.events.trigger(I.SUCCESS));
2504
2708
  }
2505
2709
  scheduleReconnect(e) {
2506
- c("scheduleReconnect"), this.delayBetweenAttempts.request().then(async () => (c("scheduleReconnect: delayBetweenAttempts success"), this.cancelableRequestBeforeRetry.request())).then(async () => (c("scheduleReconnect: onBeforeRetry success"), this.attemptConnection(e))).catch((t) => {
2507
- const s = t instanceof Error ? t : new Error(z.FAILED_TO_RECONNECT);
2508
- this.attemptsState.finishAttempt(), pe(t) || ve(t) ? this.events.trigger(_.CANCELLED_ATTEMPTS, s) : this.events.trigger(_.FAILED_ALL_ATTEMPTS, s), c("scheduleReconnect: error", t);
2710
+ 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) => {
2711
+ const s = t instanceof Error ? t : new Error(K.FAILED_TO_RECONNECT);
2712
+ this.attemptsState.finishAttempt(), Pe(t) || be(t) ? this.events.trigger(I.CANCELLED_ATTEMPTS, s) : this.events.trigger(I.FAILED_ALL_ATTEMPTS, s), h("scheduleReconnect: error", t);
2509
2713
  });
2510
2714
  }
2511
2715
  isConnectionUnavailable() {
@@ -2513,22 +2717,22 @@ class Ft {
2513
2717
  return e || t || s;
2514
2718
  }
2515
2719
  emitStatusChange = ({ isInProgress: e }) => {
2516
- this.events.trigger(_.CHANGED_ATTEMPT_STATUS, { isInProgress: e });
2720
+ this.events.trigger(I.CHANGED_ATTEMPT_STATUS, { isInProgress: e });
2517
2721
  };
2518
2722
  }
2519
- var w = /* @__PURE__ */ ((n) => (n.INCOMING_CALL = "incomingCall", n.DECLINED_INCOMING_CALL = "declinedIncomingCall", n.TERMINATED_INCOMING_CALL = "terminatedIncomingCall", n.FAILED_INCOMING_CALL = "failedIncomingCall", n))(w || {});
2520
- const Ce = [
2723
+ 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 || {});
2724
+ const Ae = [
2521
2725
  "incomingCall",
2522
2726
  "declinedIncomingCall",
2523
2727
  "terminatedIncomingCall",
2524
2728
  "failedIncomingCall"
2525
- ], kt = 486, $t = 487;
2526
- class qt {
2729
+ ], Vt = 486, xt = 487;
2730
+ class Qt {
2527
2731
  events;
2528
2732
  incomingRTCSession;
2529
2733
  connectionManager;
2530
2734
  constructor(e) {
2531
- this.connectionManager = e, this.events = new y(Ce), this.start();
2735
+ this.connectionManager = e, this.events = new O(Ae), this.start();
2532
2736
  }
2533
2737
  get remoteCallerData() {
2534
2738
  return {
@@ -2558,19 +2762,19 @@ class qt {
2558
2762
  return this.removeIncomingSession(), e;
2559
2763
  };
2560
2764
  async declineToIncomingCall({
2561
- statusCode: e = $t
2765
+ statusCode: e = xt
2562
2766
  } = {}) {
2563
2767
  return new Promise((t, s) => {
2564
2768
  try {
2565
- const r = this.getIncomingRTCSession(), i = this.remoteCallerData;
2566
- this.removeIncomingSession(), this.events.trigger(w.DECLINED_INCOMING_CALL, i), r.terminate({ status_code: e }), t();
2567
- } catch (r) {
2568
- s(r);
2769
+ const i = this.getIncomingRTCSession(), r = this.remoteCallerData;
2770
+ this.removeIncomingSession(), this.events.trigger(U.DECLINED_INCOMING_CALL, r), i.terminate({ status_code: e }), t();
2771
+ } catch (i) {
2772
+ s(i);
2569
2773
  }
2570
2774
  });
2571
2775
  }
2572
2776
  async busyIncomingCall() {
2573
- return this.declineToIncomingCall({ statusCode: kt });
2777
+ return this.declineToIncomingCall({ statusCode: Vt });
2574
2778
  }
2575
2779
  on(e, t) {
2576
2780
  return this.events.on(e, t);
@@ -2603,19 +2807,49 @@ class qt {
2603
2807
  this.incomingRTCSession = e;
2604
2808
  const t = this.remoteCallerData;
2605
2809
  e.on("failed", (s) => {
2606
- this.removeIncomingSession(), s.originator === "local" ? this.events.trigger(w.TERMINATED_INCOMING_CALL, t) : this.events.trigger(w.FAILED_INCOMING_CALL, t);
2607
- }), this.events.trigger(w.INCOMING_CALL, t);
2810
+ this.removeIncomingSession(), s.originator === "local" ? this.events.trigger(U.TERMINATED_INCOMING_CALL, t) : this.events.trigger(U.FAILED_INCOMING_CALL, t);
2811
+ }), this.events.trigger(U.INCOMING_CALL, t);
2608
2812
  }
2609
2813
  removeIncomingSession() {
2610
2814
  delete this.incomingRTCSession;
2611
2815
  }
2612
2816
  }
2613
- const b = 1e3;
2614
- var A = /* @__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))(A || {});
2615
- const Ee = ["collected"], X = () => "performance" in window ? performance.now() : Date.now(), U = (n) => [...n.keys()].reduce((e, t) => {
2817
+ const w = 1e3;
2818
+ 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 || {});
2819
+ const Ne = ["collected"], Yt = "api/v2/rtp2webrtc/offer", zt = async ({
2820
+ serverUrl: n,
2821
+ conferenceNumber: e,
2822
+ quality: t,
2823
+ audio: s,
2824
+ offer: i
2825
+ }) => {
2826
+ const r = new URL(
2827
+ `https://${n.replace(/\/$/, "")}/${Yt}/${encodeURIComponent(e)}`
2828
+ );
2829
+ r.searchParams.set("quality", t), r.searchParams.set("audio", String(s));
2830
+ const a = await fetch(r.toString(), {
2831
+ method: "POST",
2832
+ headers: {
2833
+ "Content-Type": "application/json"
2834
+ },
2835
+ referrerPolicy: "no-referrer",
2836
+ credentials: "same-origin",
2837
+ body: JSON.stringify(i)
2838
+ });
2839
+ if (!a.ok)
2840
+ throw new Error(`sendOffer failed with status ${a.status}`);
2841
+ const o = await a.json();
2842
+ return {
2843
+ type: o.type,
2844
+ sdp: o.sdp,
2845
+ toJSON() {
2846
+ return o;
2847
+ }
2848
+ };
2849
+ }, j = () => "performance" in window ? performance.now() : Date.now(), L = (n) => [...n.keys()].reduce((e, t) => {
2616
2850
  const s = n.get(t);
2617
2851
  return s === void 0 ? e : { ...e, [s.type]: s };
2618
- }, {}), Vt = (n) => {
2852
+ }, {}), Xt = (n) => {
2619
2853
  if (!n)
2620
2854
  return {
2621
2855
  outboundRtp: void 0,
@@ -2623,14 +2857,14 @@ const Ee = ["collected"], X = () => "performance" in window ? performance.now()
2623
2857
  mediaSource: void 0,
2624
2858
  remoteInboundRtp: void 0
2625
2859
  };
2626
- const e = U(n);
2860
+ const e = L(n);
2627
2861
  return {
2628
- outboundRtp: e[A.OUTBOUND_RTP],
2629
- codec: e[A.CODEC],
2630
- mediaSource: e[A.MEDIA_SOURCE],
2631
- remoteInboundRtp: e[A.REMOTE_INBOUND_RTP]
2862
+ outboundRtp: e[E.OUTBOUND_RTP],
2863
+ codec: e[E.CODEC],
2864
+ mediaSource: e[E.MEDIA_SOURCE],
2865
+ remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2632
2866
  };
2633
- }, J = (n) => {
2867
+ }, Z = (n) => {
2634
2868
  if (!n)
2635
2869
  return {
2636
2870
  outboundRtp: void 0,
@@ -2638,14 +2872,14 @@ const Ee = ["collected"], X = () => "performance" in window ? performance.now()
2638
2872
  mediaSource: void 0,
2639
2873
  remoteInboundRtp: void 0
2640
2874
  };
2641
- const e = U(n);
2875
+ const e = L(n);
2642
2876
  return {
2643
- outboundRtp: e[A.OUTBOUND_RTP],
2644
- codec: e[A.CODEC],
2645
- mediaSource: e[A.MEDIA_SOURCE],
2646
- remoteInboundRtp: e[A.REMOTE_INBOUND_RTP]
2877
+ outboundRtp: e[E.OUTBOUND_RTP],
2878
+ codec: e[E.CODEC],
2879
+ mediaSource: e[E.MEDIA_SOURCE],
2880
+ remoteInboundRtp: e[E.REMOTE_INBOUND_RTP]
2647
2881
  };
2648
- }, K = ({
2882
+ }, ee = ({
2649
2883
  videoReceiversStats: n,
2650
2884
  synchronizationSourcesVideo: e
2651
2885
  }) => {
@@ -2655,13 +2889,13 @@ const Ee = ["collected"], X = () => "performance" in window ? performance.now()
2655
2889
  codec: void 0,
2656
2890
  synchronizationSources: e
2657
2891
  };
2658
- const t = U(n);
2892
+ const t = L(n);
2659
2893
  return {
2660
- inboundRtp: t[A.INBOUND_RTP],
2661
- codec: t[A.CODEC],
2894
+ inboundRtp: t[E.INBOUND_RTP],
2895
+ codec: t[E.CODEC],
2662
2896
  synchronizationSources: e
2663
2897
  };
2664
- }, Ht = ({
2898
+ }, Jt = ({
2665
2899
  audioReceiverStats: n,
2666
2900
  synchronizationSourcesAudio: e
2667
2901
  }) => {
@@ -2672,14 +2906,14 @@ const Ee = ["collected"], X = () => "performance" in window ? performance.now()
2672
2906
  remoteOutboundRtp: void 0,
2673
2907
  synchronizationSources: e
2674
2908
  };
2675
- const t = U(n);
2909
+ const t = L(n);
2676
2910
  return {
2677
- inboundRtp: t[A.INBOUND_RTP],
2678
- codec: t[A.CODEC],
2679
- remoteOutboundRtp: t[A.REMOTE_OUTBOUND_RTP],
2911
+ inboundRtp: t[E.INBOUND_RTP],
2912
+ codec: t[E.CODEC],
2913
+ remoteOutboundRtp: t[E.REMOTE_OUTBOUND_RTP],
2680
2914
  synchronizationSources: e
2681
2915
  };
2682
- }, Ae = (n) => {
2916
+ }, me = (n) => {
2683
2917
  if (!n)
2684
2918
  return {
2685
2919
  candidatePair: void 0,
@@ -2688,122 +2922,122 @@ const Ee = ["collected"], X = () => "performance" in window ? performance.now()
2688
2922
  remoteCandidate: void 0,
2689
2923
  transport: void 0
2690
2924
  };
2691
- const e = U(n);
2925
+ const e = L(n);
2692
2926
  return {
2693
- candidatePair: e[A.CANDIDATE_PAIR],
2694
- certificate: e[A.CERTIFICATE],
2695
- localCandidate: e[A.LOCAL_CANDIDATE],
2696
- remoteCandidate: e[A.REMOTE_CANDIDATE],
2697
- transport: e[A.TRANSPORT]
2927
+ candidatePair: e[E.CANDIDATE_PAIR],
2928
+ certificate: e[E.CERTIFICATE],
2929
+ localCandidate: e[E.LOCAL_CANDIDATE],
2930
+ remoteCandidate: e[E.REMOTE_CANDIDATE],
2931
+ transport: e[E.TRANSPORT]
2698
2932
  };
2699
- }, Wt = ({
2933
+ }, Kt = ({
2700
2934
  audioSenderStats: n,
2701
2935
  videoSenderFirstStats: e,
2702
2936
  videoSenderSecondStats: t
2703
2937
  }) => ({
2704
- video: J(e),
2705
- secondVideo: J(t),
2706
- audio: Vt(n),
2707
- additional: Ae(
2938
+ video: Z(e),
2939
+ secondVideo: Z(t),
2940
+ audio: Xt(n),
2941
+ additional: me(
2708
2942
  n ?? e ?? t
2709
2943
  )
2710
- }), xt = ({
2944
+ }), jt = ({
2711
2945
  audioReceiverStats: n,
2712
2946
  videoReceiverFirstStats: e,
2713
2947
  videoReceiverSecondStats: t,
2714
2948
  synchronizationSources: s
2715
2949
  }) => ({
2716
- video: K({
2950
+ video: ee({
2717
2951
  videoReceiversStats: e,
2718
2952
  synchronizationSourcesVideo: s.video
2719
2953
  }),
2720
- secondVideo: K({
2954
+ secondVideo: ee({
2721
2955
  videoReceiversStats: t,
2722
2956
  synchronizationSourcesVideo: s.video
2723
2957
  }),
2724
- audio: Ht({
2958
+ audio: Jt({
2725
2959
  audioReceiverStats: n,
2726
2960
  synchronizationSourcesAudio: s.audio
2727
2961
  }),
2728
- additional: Ae(
2962
+ additional: me(
2729
2963
  n ?? e ?? t
2730
2964
  )
2731
- }), Gt = ({
2965
+ }), Zt = ({
2732
2966
  audioSenderStats: n,
2733
2967
  videoSenderFirstStats: e,
2734
2968
  videoSenderSecondStats: t,
2735
2969
  audioReceiverStats: s,
2736
- videoReceiverFirstStats: r,
2737
- videoReceiverSecondStats: i,
2970
+ videoReceiverFirstStats: i,
2971
+ videoReceiverSecondStats: r,
2738
2972
  synchronizationSources: a
2739
2973
  }) => {
2740
- const o = Wt({
2974
+ const o = Kt({
2741
2975
  audioSenderStats: n,
2742
2976
  videoSenderFirstStats: e,
2743
2977
  videoSenderSecondStats: t
2744
- }), h = xt({
2978
+ }), c = jt({
2745
2979
  audioReceiverStats: s,
2746
- videoReceiverFirstStats: r,
2747
- videoReceiverSecondStats: i,
2980
+ videoReceiverFirstStats: i,
2981
+ videoReceiverSecondStats: r,
2748
2982
  synchronizationSources: a
2749
2983
  });
2750
2984
  return {
2751
2985
  outbound: o,
2752
- inbound: h
2986
+ inbound: c
2753
2987
  };
2754
- }, Qt = async (n) => {
2755
- const e = "audio", t = "video", s = n.getSenders(), r = s.find((l) => l.track?.kind === e), i = s.filter((l) => l.track?.kind === t), a = n.getReceivers(), o = a.find((l) => l.track.kind === e), h = a.filter((l) => l.track.kind === t), d = {
2988
+ }, en = async (n) => {
2989
+ 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 = {
2756
2990
  trackIdentifier: o?.track.id,
2757
2991
  item: o?.getSynchronizationSources()[0]
2758
- }, T = {
2759
- trackIdentifier: h[0]?.track.id,
2760
- item: h[0]?.getSynchronizationSources()[0]
2761
2992
  }, S = {
2993
+ trackIdentifier: c[0]?.track.id,
2994
+ item: c[0]?.getSynchronizationSources()[0]
2995
+ }, g = {
2762
2996
  audio: d,
2763
- video: T
2997
+ video: S
2764
2998
  };
2765
2999
  return Promise.all([
2766
- r?.getStats() ?? Promise.resolve(void 0),
2767
- i[0]?.getStats() ?? Promise.resolve(void 0),
2768
- i[1]?.getStats() ?? Promise.resolve(void 0),
3000
+ i?.getStats() ?? Promise.resolve(void 0),
3001
+ r[0]?.getStats() ?? Promise.resolve(void 0),
3002
+ r[1]?.getStats() ?? Promise.resolve(void 0),
2769
3003
  o?.getStats() ?? Promise.resolve(void 0),
2770
- h[0]?.getStats() ?? Promise.resolve(void 0),
2771
- h[1]?.getStats() ?? Promise.resolve(void 0)
2772
- ]).then((l) => {
3004
+ c[0]?.getStats() ?? Promise.resolve(void 0),
3005
+ c[1]?.getStats() ?? Promise.resolve(void 0)
3006
+ ]).then((T) => {
2773
3007
  const [
2774
- E,
2775
- I,
2776
- N,
2777
- M,
3008
+ p,
3009
+ v,
3010
+ A,
3011
+ D,
2778
3012
  F,
2779
- k
2780
- ] = l;
3013
+ ve
3014
+ ] = T;
2781
3015
  return {
2782
- synchronizationSources: S,
2783
- audioSenderStats: E,
2784
- videoSenderFirstStats: I,
2785
- videoSenderSecondStats: N,
2786
- audioReceiverStats: M,
3016
+ synchronizationSources: g,
3017
+ audioSenderStats: p,
3018
+ videoSenderFirstStats: v,
3019
+ videoSenderSecondStats: A,
3020
+ audioReceiverStats: D,
2787
3021
  videoReceiverFirstStats: F,
2788
- videoReceiverSecondStats: k
3022
+ videoReceiverSecondStats: ve
2789
3023
  };
2790
3024
  });
2791
- }, Yt = (n) => {
2792
- c(String(n));
3025
+ }, tn = (n) => {
3026
+ h(String(n));
2793
3027
  };
2794
- class zt {
3028
+ class nn {
2795
3029
  events;
2796
3030
  setTimeoutRequest;
2797
- requesterAllStatistics = new x(Qt);
3031
+ requesterAllStatistics = new x(en);
2798
3032
  constructor() {
2799
- this.events = new y(Ee), this.setTimeoutRequest = new Z();
3033
+ this.events = new O(Ne), this.setTimeoutRequest = new ne();
2800
3034
  }
2801
3035
  get requested() {
2802
3036
  return this.setTimeoutRequest.requested;
2803
3037
  }
2804
3038
  start(e, {
2805
- interval: t = b,
2806
- onError: s = Yt
3039
+ interval: t = w,
3040
+ onError: s = tn
2807
3041
  } = {}) {
2808
3042
  this.stop(), this.setTimeoutRequest.request(() => {
2809
3043
  this.collectStatistics(e, {
@@ -2832,21 +3066,21 @@ class zt {
2832
3066
  collectStatistics = (e, {
2833
3067
  onError: t
2834
3068
  }) => {
2835
- const s = X();
2836
- this.requesterAllStatistics.request(e).then((r) => {
2837
- this.events.trigger("collected", Gt(r));
2838
- const a = X() - s;
2839
- let o = b;
2840
- a > 48 ? o = b * 4 : a > 32 ? o = b * 3 : a > 16 && (o = b * 2), this.start(e, {
3069
+ const s = j();
3070
+ this.requesterAllStatistics.request(e).then((i) => {
3071
+ this.events.trigger("collected", Zt(i));
3072
+ const a = j() - s;
3073
+ let o = w;
3074
+ a > 48 ? o = w * 4 : a > 32 ? o = w * 3 : a > 16 && (o = w * 2), this.start(e, {
2841
3075
  onError: t,
2842
3076
  interval: o
2843
3077
  });
2844
- }).catch((r) => {
2845
- t && t(r);
3078
+ }).catch((i) => {
3079
+ t && t(i);
2846
3080
  });
2847
3081
  };
2848
3082
  }
2849
- class Xt {
3083
+ class sn {
2850
3084
  availableIncomingBitrate;
2851
3085
  statsPeerConnection;
2852
3086
  callManager;
@@ -2856,7 +3090,7 @@ class Xt {
2856
3090
  callManager: e,
2857
3091
  apiManager: t
2858
3092
  }) {
2859
- this.callManager = e, this.apiManager = t, this.statsPeerConnection = new zt(), this.subscribe();
3093
+ this.callManager = e, this.apiManager = t, this.statsPeerConnection = new nn(), this.subscribe();
2860
3094
  }
2861
3095
  get events() {
2862
3096
  return this.statsPeerConnection.events;
@@ -2894,145 +3128,37 @@ class Xt {
2894
3128
  };
2895
3129
  maybeSendStats() {
2896
3130
  this.availableIncomingBitrate !== void 0 && this.hasAvailableIncomingBitrateChangedQuarter() && this.apiManager.sendStats({ availableIncomingBitrate: this.availableIncomingBitrate }).catch((e) => {
2897
- c("Failed to send stats", e);
3131
+ h("Failed to send stats", e);
2898
3132
  });
2899
3133
  }
2900
3134
  }
2901
- const Jt = (n, e) => n.filter((s) => e.some((r) => r.clockRate === s.clockRate && r.mimeType === s.mimeType && r.channels === s.channels && r.sdpFmtpLine === s.sdpFmtpLine)), Kt = (n) => {
2902
- const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, r = t === null ? [] : t.codecs;
2903
- return Jt(s, r);
2904
- }, jt = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
2905
- const r = e.indexOf(t.mimeType), i = e.indexOf(s.mimeType), a = r === -1 ? Number.MAX_VALUE : r, o = i === -1 ? Number.MAX_VALUE : i;
3135
+ const rn = (n, e) => n.filter((s) => e.some((i) => i.clockRate === s.clockRate && i.mimeType === s.mimeType && i.channels === s.channels && i.sdpFmtpLine === s.sdpFmtpLine)), an = (n) => {
3136
+ const e = RTCRtpSender.getCapabilities(n), t = RTCRtpReceiver.getCapabilities(n), s = e === null ? [] : e.codecs, i = t === null ? [] : t.codecs;
3137
+ return rn(s, i);
3138
+ }, on = (n, e) => e === void 0 || e.length === 0 ? n : n.sort((t, s) => {
3139
+ 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;
2906
3140
  return a - o;
2907
- }), Zt = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), en = (n, {
3141
+ }), cn = (n, e) => e === void 0 || e.length === 0 ? n : n.filter((t) => !e.includes(t.mimeType)), hn = (n, {
2908
3142
  preferredMimeTypesVideoCodecs: e,
2909
3143
  excludeMimeTypesVideoCodecs: t
2910
3144
  }) => {
2911
3145
  try {
2912
3146
  if (typeof n.setCodecPreferences == "function" && n.sender.track?.kind === "video" && (e !== void 0 && e.length > 0 || t !== void 0 && t.length > 0)) {
2913
- const s = Kt("video"), r = Zt(s, t), i = jt(r, e);
2914
- n.setCodecPreferences(i);
3147
+ const s = an("video"), i = cn(s, t), r = on(i, e);
3148
+ n.setCodecPreferences(r);
2915
3149
  }
2916
3150
  } catch (s) {
2917
- c("setCodecPreferences error", s);
2918
- }
2919
- };
2920
- class tn {
2921
- /**
2922
- * Хранилище основных transceiver'ов
2923
- */
2924
- transceivers = {};
2925
- callManager;
2926
- apiManager;
2927
- constructor({
2928
- callManager: e,
2929
- apiManager: t
2930
- }) {
2931
- this.callManager = e, this.apiManager = t, this.subscribe();
3151
+ h("setCodecPreferences error", s);
2932
3152
  }
2933
- /**
2934
- * Сохраняет transceiver в соответствующем хранилище в зависимости от типа трека и mid
2935
- */
2936
- storeTransceiver(e, t) {
2937
- const { kind: s } = t;
2938
- if (s === "audio")
2939
- this.transceivers.mainAudio ??= e;
2940
- else {
2941
- const { mid: r } = e;
2942
- r === "2" ? this.transceivers.presentationVideo ??= e : this.transceivers.mainVideo ??= e;
2943
- }
2944
- }
2945
- /**
2946
- * Возвращает все сохраненные transceiver'ы
2947
- */
2948
- getTransceivers() {
2949
- return { ...this.transceivers };
2950
- }
2951
- /**
2952
- * Возвращает основной аудио transceiver
2953
- */
2954
- getMainAudioTransceiver() {
2955
- return this.transceivers.mainAudio;
2956
- }
2957
- /**
2958
- * Возвращает основной видео transceiver
2959
- */
2960
- getMainVideoTransceiver() {
2961
- return this.transceivers.mainVideo;
2962
- }
2963
- /**
2964
- * Возвращает презентационный видео transceiver
2965
- */
2966
- getPresentationVideoTransceiver() {
2967
- return this.transceivers.presentationVideo;
2968
- }
2969
- /**
2970
- * Проверяет, есть ли сохраненный transceiver для указанного типа
2971
- */
2972
- hasTransceiver(e) {
2973
- return this.transceivers[e] !== void 0;
2974
- }
2975
- /**
2976
- * Очищает все сохраненные transceiver'ы
2977
- */
2978
- clear() {
2979
- this.transceivers.mainVideo = void 0, this.transceivers.mainAudio = void 0, this.transceivers.presentationVideo = void 0;
2980
- }
2981
- /**
2982
- * Возвращает количество сохраненных transceiver'ов
2983
- */
2984
- getCount() {
2985
- let e = 0;
2986
- return this.transceivers.mainAudio && (e += 1), this.transceivers.mainVideo && (e += 1), this.transceivers.presentationVideo && (e += 1), e;
2987
- }
2988
- /**
2989
- * Проверяет, пустое ли хранилище
2990
- */
2991
- isEmpty() {
2992
- return this.getCount() === 0;
2993
- }
2994
- /**
2995
- * Обрабатывает событие restart от ApiManager
2996
- */
2997
- handleRestart = (e) => {
2998
- this.updateTransceivers(e).catch((t) => {
2999
- c("Failed to update transceivers", t);
3000
- }).finally(() => {
3001
- this.callManager.restartIce().catch((t) => {
3002
- c("Failed to restart ICE", t);
3003
- });
3004
- });
3005
- };
3006
- /**
3007
- * Обновляет transceiver'ы в соответствии с данными restart
3008
- */
3009
- updateTransceivers = async (e) => {
3010
- const { videoTrackCount: t } = e;
3011
- t === 2 && (this.getTransceivers().presentationVideo !== void 0 || await this.callManager.addTransceiver("video", {
3012
- direction: "recvonly"
3013
- }).catch((i) => {
3014
- c("Failed to add presentation video transceiver", i);
3015
- }));
3016
- };
3017
- subscribe() {
3018
- this.callManager.on("peerconnection:ontrack", this.handleTrack), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded), this.apiManager.on("restart", this.handleRestart);
3019
- }
3020
- handleTrack = (e) => {
3021
- this.storeTransceiver(e.transceiver, e.track);
3022
- };
3023
- handleEnded = () => {
3024
- this.clear();
3025
- };
3026
- }
3027
- const nn = (n) => [...n.keys()].map((e) => n.get(e)), sn = (n, e) => nn(n).find((t) => t?.type === e), rn = async (n) => n.getStats().then((e) => sn(e, "codec")?.mimeType);
3028
- class an {
3153
+ }, dn = (n) => [...n.keys()].map((e) => n.get(e)), ln = (n, e) => dn(n).find((t) => t?.type === e), un = async (n) => n.getStats().then((e) => ln(e, "codec")?.mimeType);
3154
+ class gn {
3029
3155
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
3030
3156
  async getCodecFromSender(e) {
3031
- return await rn(e) ?? "";
3157
+ return await un(e) ?? "";
3032
3158
  }
3033
3159
  }
3034
- class on {
3035
- stackPromises = te({
3160
+ class Tn {
3161
+ stackPromises = ie({
3036
3162
  noRunIsNotActual: !0
3037
3163
  });
3038
3164
  /**
@@ -3052,34 +3178,34 @@ class on {
3052
3178
  */
3053
3179
  async run() {
3054
3180
  return this.stackPromises().catch((e) => {
3055
- c("TaskQueue: error", e);
3181
+ h("TaskQueue: error", e);
3056
3182
  });
3057
3183
  }
3058
3184
  }
3059
- class cn {
3185
+ class Sn {
3060
3186
  taskQueue;
3061
3187
  onSetParameters;
3062
3188
  constructor(e) {
3063
- this.onSetParameters = e, this.taskQueue = new on();
3189
+ this.onSetParameters = e, this.taskQueue = new Tn();
3064
3190
  }
3065
3191
  async setEncodingsToSender(e, t) {
3066
- return this.taskQueue.add(async () => he(e, t, this.onSetParameters));
3192
+ return this.taskQueue.add(async () => ue(e, t, this.onSetParameters));
3067
3193
  }
3068
3194
  stop() {
3069
3195
  this.taskQueue.stop();
3070
3196
  }
3071
3197
  }
3072
- const Re = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), hn = 1e6, f = (n) => n * hn, Ne = f(0.06), me = f(4), dn = (n) => n <= 64 ? Ne : n <= 128 ? f(0.12) : n <= 256 ? f(0.25) : n <= 384 ? f(0.32) : n <= 426 ? f(0.38) : n <= 640 ? f(0.5) : n <= 848 ? f(0.7) : n <= 1280 ? f(1) : n <= 1920 ? f(2) : me, ln = "av1", un = (n) => Re(n, ln), gn = 0.6, Q = (n, e) => un(e) ? n * gn : n, Tn = (n) => Q(Ne, n), Sn = (n) => Q(me, n), j = (n, e) => {
3073
- const t = dn(n);
3074
- return Q(t, e);
3075
- }, $ = 1, Cn = ({
3198
+ const Ie = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Cn = 1e6, _ = (n) => n * Cn, _e = _(0.06), Me = _(4), En = (n) => n <= 64 ? _e : n <= 128 ? _(0.12) : n <= 256 ? _(0.25) : n <= 384 ? _(0.32) : n <= 426 ? _(0.38) : n <= 640 ? _(0.5) : n <= 848 ? _(0.7) : n <= 1280 ? _(1) : n <= 1920 ? _(2) : Me, pn = "av1", Rn = (n) => Ie(n, pn), An = 0.6, Y = (n, e) => Rn(e) ? n * An : n, Nn = (n) => Y(_e, n), mn = (n) => Y(Me, n), te = (n, e) => {
3199
+ const t = En(n);
3200
+ return Y(t, e);
3201
+ }, q = 1, In = ({
3076
3202
  videoTrack: n,
3077
3203
  targetSize: e
3078
3204
  }) => {
3079
- const t = n.getSettings(), s = t.width, r = t.height, i = s === void 0 ? $ : s / e.width, a = r === void 0 ? $ : r / e.height;
3080
- return Math.max(i, a, $);
3205
+ const t = n.getSettings(), s = t.width, i = t.height, r = s === void 0 ? q : s / e.width, a = i === void 0 ? q : i / e.height;
3206
+ return Math.max(r, a, q);
3081
3207
  };
3082
- class En {
3208
+ class _n {
3083
3209
  ignoreForCodec;
3084
3210
  senderFinder;
3085
3211
  codecProvider;
@@ -3098,8 +3224,8 @@ class En {
3098
3224
  senderFinder: e,
3099
3225
  codecProvider: t,
3100
3226
  parametersSetter: s
3101
- }, r) {
3102
- this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = r.ignoreForCodec;
3227
+ }, i) {
3228
+ this.senderFinder = e, this.codecProvider = t, this.parametersSetter = s, this.ignoreForCodec = i.ignoreForCodec;
3103
3229
  }
3104
3230
  /**
3105
3231
  * Выполняет балансировку на основе заголовков от сервера
@@ -3108,21 +3234,21 @@ class En {
3108
3234
  * @returns Promise с результатом балансировки
3109
3235
  */
3110
3236
  async balance(e, t) {
3111
- const s = e.getSenders(), r = this.senderFinder.findVideoSender(s);
3112
- if (!r?.track)
3113
- return { ...this.resultNoChanged, sender: r };
3114
- const i = await this.codecProvider.getCodecFromSender(r);
3115
- if (Re(i, this.ignoreForCodec))
3116
- return { ...this.resultNoChanged, sender: r };
3237
+ const s = e.getSenders(), i = this.senderFinder.findVideoSender(s);
3238
+ if (!i?.track)
3239
+ return { ...this.resultNoChanged, sender: i };
3240
+ const r = await this.codecProvider.getCodecFromSender(i);
3241
+ if (Ie(r, this.ignoreForCodec))
3242
+ return { ...this.resultNoChanged, sender: i };
3117
3243
  const { mainCam: a, resolutionMainCam: o } = t ?? {};
3118
3244
  return this.processSender(
3119
3245
  { mainCam: a, resolutionMainCam: o },
3120
3246
  {
3121
- sender: r,
3122
- codec: i,
3123
- videoTrack: r.track
3247
+ sender: i,
3248
+ codec: r,
3249
+ videoTrack: i.track
3124
3250
  }
3125
- ).then((h) => ({ ...h, sender: r }));
3251
+ ).then((c) => ({ ...c, sender: i }));
3126
3252
  }
3127
3253
  /**
3128
3254
  * Обрабатывает отправитель в зависимости от команды управления
@@ -3130,16 +3256,16 @@ class En {
3130
3256
  * @returns Promise с результатом обработки
3131
3257
  */
3132
3258
  async processSender(e, t) {
3133
- const { mainCam: s, resolutionMainCam: r } = e;
3259
+ const { mainCam: s, resolutionMainCam: i } = e;
3134
3260
  switch (s) {
3135
- case v.PAUSE_MAIN_CAM:
3261
+ case M.PAUSE_MAIN_CAM:
3136
3262
  return this.downgradeResolutionSender(t);
3137
- case v.RESUME_MAIN_CAM:
3263
+ case M.RESUME_MAIN_CAM:
3138
3264
  return this.setBitrateByTrackResolution(t);
3139
- case v.MAX_MAIN_CAM_RESOLUTION:
3140
- return r !== void 0 ? this.setResolutionSender(r, t) : this.setBitrateByTrackResolution(t);
3141
- case v.ADMIN_STOP_MAIN_CAM:
3142
- case v.ADMIN_START_MAIN_CAM:
3265
+ case M.MAX_MAIN_CAM_RESOLUTION:
3266
+ return i !== void 0 ? this.setResolutionSender(i, t) : this.setBitrateByTrackResolution(t);
3267
+ case M.ADMIN_STOP_MAIN_CAM:
3268
+ case M.ADMIN_START_MAIN_CAM:
3143
3269
  case void 0:
3144
3270
  return this.setBitrateByTrackResolution(t);
3145
3271
  default:
@@ -3152,11 +3278,11 @@ class En {
3152
3278
  * @returns Promise с результатом
3153
3279
  */
3154
3280
  async downgradeResolutionSender(e) {
3155
- const { sender: t, codec: s } = e, r = {
3281
+ const { sender: t, codec: s } = e, i = {
3156
3282
  scaleResolutionDownBy: 200,
3157
- maxBitrate: Tn(s)
3283
+ maxBitrate: Nn(s)
3158
3284
  };
3159
- return this.parametersSetter.setEncodingsToSender(t, r);
3285
+ return this.parametersSetter.setEncodingsToSender(t, i);
3160
3286
  }
3161
3287
  /**
3162
3288
  * Устанавливает битрейт на основе разрешения трека
@@ -3164,7 +3290,7 @@ class En {
3164
3290
  * @returns Promise с результатом
3165
3291
  */
3166
3292
  async setBitrateByTrackResolution(e) {
3167
- const { sender: t, videoTrack: s, codec: r } = e, a = s.getSettings().width, o = a === void 0 ? Sn(r) : j(a, r);
3293
+ const { sender: t, videoTrack: s, codec: i } = e, a = s.getSettings().width, o = a === void 0 ? mn(i) : te(a, i);
3168
3294
  return this.parametersSetter.setEncodingsToSender(t, {
3169
3295
  scaleResolutionDownBy: 1,
3170
3296
  maxBitrate: o
@@ -3177,27 +3303,27 @@ class En {
3177
3303
  * @returns Promise с результатом
3178
3304
  */
3179
3305
  async setResolutionSender(e, t) {
3180
- const [s, r] = e.split("x"), { sender: i, videoTrack: a, codec: o } = t, h = {
3306
+ const [s, i] = e.split("x"), { sender: r, videoTrack: a, codec: o } = t, c = {
3181
3307
  width: Number(s),
3182
- height: Number(r)
3183
- }, d = Cn({
3308
+ height: Number(i)
3309
+ }, d = In({
3184
3310
  videoTrack: a,
3185
- targetSize: h
3186
- }), T = j(h.width, o), S = {
3311
+ targetSize: c
3312
+ }), S = te(c.width, o), g = {
3187
3313
  scaleResolutionDownBy: d,
3188
- maxBitrate: T
3314
+ maxBitrate: S
3189
3315
  };
3190
- return this.parametersSetter.setEncodingsToSender(i, S);
3316
+ return this.parametersSetter.setEncodingsToSender(r, g);
3191
3317
  }
3192
3318
  }
3193
- const An = (n) => n.find((e) => e.track?.kind === "video");
3194
- class Rn {
3319
+ const Mn = (n) => n.find((e) => e.track?.kind === "video");
3320
+ class fn {
3195
3321
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
3196
3322
  findVideoSender(e) {
3197
- return An(e);
3323
+ return Mn(e);
3198
3324
  }
3199
3325
  }
3200
- class Nn {
3326
+ class vn {
3201
3327
  currentSender;
3202
3328
  originalReplaceTrack;
3203
3329
  lastWidth;
@@ -3210,7 +3336,7 @@ class Nn {
3210
3336
  pollIntervalMs: e = 1e3,
3211
3337
  maxPollIntervalMs: t
3212
3338
  }) {
3213
- this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new Z();
3339
+ this.pollIntervalMs = e, this.maxPollIntervalMs = t ?? e * 16, this.currentPollIntervalMs = this.pollIntervalMs, this.setTimeoutRequest = new ne();
3214
3340
  }
3215
3341
  /**
3216
3342
  * Проверяет актуальный video-sender и (при необходимости) перенастраивает наблюдение.
@@ -3229,8 +3355,8 @@ class Nn {
3229
3355
  attachSender(e, t) {
3230
3356
  this.currentSender = e;
3231
3357
  const s = e.replaceTrack.bind(e);
3232
- this.originalReplaceTrack = s, e.replaceTrack = async (r) => {
3233
- await s(r), this.attachTrack(t, r ?? void 0), t();
3358
+ this.originalReplaceTrack = s, e.replaceTrack = async (i) => {
3359
+ await s(i), this.attachTrack(t, i ?? void 0), t();
3234
3360
  }, this.attachTrack(t, e.track);
3235
3361
  }
3236
3362
  detachSender() {
@@ -3239,8 +3365,8 @@ class Nn {
3239
3365
  attachTrack(e, t) {
3240
3366
  if (this.detachTrack(), !t)
3241
3367
  return;
3242
- const { width: s, height: r } = t.getSettings();
3243
- this.lastWidth = s, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
3368
+ const { width: s, height: i } = t.getSettings();
3369
+ this.lastWidth = s, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, this.schedulePoll(t, e);
3244
3370
  }
3245
3371
  /**
3246
3372
  * Периодически опрашивает track с экспоненциальной адаптацией частоты.
@@ -3249,8 +3375,8 @@ class Nn {
3249
3375
  */
3250
3376
  schedulePoll(e, t) {
3251
3377
  const s = () => {
3252
- const { width: r, height: i } = e.getSettings();
3253
- r !== this.lastWidth || i !== this.lastHeight ? (this.lastWidth = r, this.lastHeight = i, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
3378
+ const { width: i, height: r } = e.getSettings();
3379
+ i !== this.lastWidth || r !== this.lastHeight ? (this.lastWidth = i, this.lastHeight = r, this.currentPollIntervalMs = this.pollIntervalMs, t()) : this.currentPollIntervalMs = Math.min(
3254
3380
  this.currentPollIntervalMs * 2,
3255
3381
  this.maxPollIntervalMs
3256
3382
  ), this.setTimeoutRequest.request(s, this.currentPollIntervalMs);
@@ -3261,7 +3387,7 @@ class Nn {
3261
3387
  this.setTimeoutRequest.cancelRequest(), this.lastWidth = void 0, this.lastHeight = void 0;
3262
3388
  }
3263
3389
  }
3264
- class mn {
3390
+ class Pn {
3265
3391
  apiManager;
3266
3392
  currentHandler;
3267
3393
  constructor(e) {
@@ -3281,7 +3407,7 @@ class mn {
3281
3407
  this.currentHandler && (this.apiManager.off("main-cam-control", this.currentHandler), this.currentHandler = void 0);
3282
3408
  }
3283
3409
  }
3284
- class In {
3410
+ class On {
3285
3411
  eventHandler;
3286
3412
  senderBalancer;
3287
3413
  parametersSetterWithQueue;
@@ -3290,19 +3416,19 @@ class In {
3290
3416
  trackMonitor;
3291
3417
  constructor(e, t, {
3292
3418
  ignoreForCodec: s,
3293
- onSetParameters: r,
3294
- pollIntervalMs: i
3419
+ onSetParameters: i,
3420
+ pollIntervalMs: r
3295
3421
  } = {}) {
3296
- this.getConnection = t, this.eventHandler = new mn(e), this.parametersSetterWithQueue = new cn(r), this.senderBalancer = new En(
3422
+ this.getConnection = t, this.eventHandler = new Pn(e), this.parametersSetterWithQueue = new Sn(i), this.senderBalancer = new _n(
3297
3423
  {
3298
- senderFinder: new Rn(),
3299
- codecProvider: new an(),
3424
+ senderFinder: new fn(),
3425
+ codecProvider: new gn(),
3300
3426
  parametersSetter: this.parametersSetterWithQueue
3301
3427
  },
3302
3428
  {
3303
3429
  ignoreForCodec: s
3304
3430
  }
3305
- ), this.trackMonitor = new Nn({ pollIntervalMs: i });
3431
+ ), this.trackMonitor = new vn({ pollIntervalMs: r });
3306
3432
  }
3307
3433
  /**
3308
3434
  * Подписывается на события управления главной камерой
@@ -3333,7 +3459,7 @@ class In {
3333
3459
  const t = await this.senderBalancer.balance(e, this.serverHeaders);
3334
3460
  return this.trackMonitor.subscribe(t.sender, () => {
3335
3461
  this.balance().catch((s) => {
3336
- c("balance on track change: error", s);
3462
+ h("balance on track change: error", s);
3337
3463
  });
3338
3464
  }), t;
3339
3465
  }
@@ -3343,17 +3469,17 @@ class In {
3343
3469
  */
3344
3470
  handleMainCamControl = (e) => {
3345
3471
  this.serverHeaders = e, this.balance().catch((t) => {
3346
- c("handleMainCamControl: error", t);
3472
+ h("handleMainCamControl: error", t);
3347
3473
  });
3348
3474
  };
3349
3475
  }
3350
- const Ie = [
3476
+ const fe = [
3351
3477
  "balancing-scheduled",
3352
3478
  "balancing-started",
3353
3479
  "balancing-stopped",
3354
3480
  "parameters-updated"
3355
3481
  ];
3356
- class pn {
3482
+ class yn {
3357
3483
  isBalancingActive = !1;
3358
3484
  events;
3359
3485
  callManager;
@@ -3361,13 +3487,13 @@ class pn {
3361
3487
  videoSendingBalancer;
3362
3488
  startBalancingTimer;
3363
3489
  constructor(e, t, s = {}) {
3364
- this.events = new y(Ie), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new In(
3490
+ this.events = new O(fe), this.callManager = e, this.balancingStartDelay = s.balancingStartDelay ?? 1e4, this.videoSendingBalancer = new On(
3365
3491
  t,
3366
3492
  () => e.connection,
3367
3493
  {
3368
3494
  ...s,
3369
- onSetParameters: (r) => {
3370
- this.events.trigger("parameters-updated", r), s.onSetParameters?.(r);
3495
+ onSetParameters: (i) => {
3496
+ this.events.trigger("parameters-updated", i), s.onSetParameters?.(i);
3371
3497
  }
3372
3498
  }
3373
3499
  ), this.subscribe();
@@ -3423,7 +3549,7 @@ class pn {
3423
3549
  scheduleBalancingStart() {
3424
3550
  this.clearStartTimer(), this.startBalancingTimer = setTimeout(() => {
3425
3551
  this.startBalancingTimer = void 0, this.startBalancing().catch((e) => {
3426
- c("startBalancing: error", e);
3552
+ h("startBalancing: error", e);
3427
3553
  });
3428
3554
  }, this.balancingStartDelay), this.events.trigger("balancing-scheduled", { delay: this.balancingStartDelay });
3429
3555
  }
@@ -3431,17 +3557,17 @@ class pn {
3431
3557
  this.startBalancingTimer && (clearTimeout(this.startBalancingTimer), this.startBalancingTimer = void 0);
3432
3558
  }
3433
3559
  }
3434
- const _n = 1e6, Mn = Se.map((n) => `auto-connect:${n}`), fn = ue.map((n) => `connection:${n}`), vn = re.map((n) => `call:${n}`), Pn = ne.map((n) => `api:${n}`), On = Ce.map((n) => `incoming-call:${n}`), yn = de.map((n) => `presentation:${n}`), Dn = Ee.map((n) => `stats:${n}`), bn = Ie.map((n) => `video-balancer:${n}`), wn = [
3435
- ...Mn,
3436
- ...fn,
3437
- ...vn,
3438
- ...Pn,
3439
- ...On,
3440
- ...yn,
3441
- ...Dn,
3442
- ...bn
3560
+ const Dn = 1e6, bn = Re.map((n) => `auto-connect:${n}`), wn = Se.map((n) => `connection:${n}`), Un = oe.map((n) => `call:${n}`), Ln = re.map((n) => `api:${n}`), Bn = Ae.map((n) => `incoming-call:${n}`), kn = ge.map((n) => `presentation:${n}`), Fn = Ne.map((n) => `stats:${n}`), $n = fe.map((n) => `video-balancer:${n}`), qn = [
3561
+ ...bn,
3562
+ ...wn,
3563
+ ...Un,
3564
+ ...Ln,
3565
+ ...Bn,
3566
+ ...kn,
3567
+ ...Fn,
3568
+ ...$n
3443
3569
  ];
3444
- class Qn {
3570
+ class Zn {
3445
3571
  events;
3446
3572
  connectionManager;
3447
3573
  connectionQueueManager;
@@ -3452,40 +3578,36 @@ class Qn {
3452
3578
  presentationManager;
3453
3579
  statsManager;
3454
3580
  videoSendingBalancerManager;
3455
- transceiverManager;
3456
3581
  preferredMimeTypesVideoCodecs;
3457
3582
  excludeMimeTypesVideoCodecs;
3458
3583
  constructor({ JsSIP: e }, {
3459
3584
  preferredMimeTypesVideoCodecs: t,
3460
3585
  excludeMimeTypesVideoCodecs: s,
3461
- videoBalancerOptions: r,
3462
- autoConnectorOptions: i
3586
+ videoBalancerOptions: i,
3587
+ autoConnectorOptions: r
3463
3588
  } = {}) {
3464
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new y(wn), this.connectionManager = new pt({ JsSIP: e }), this.connectionQueueManager = new _t({
3589
+ this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.events = new O(qn), this.connectionManager = new Ot({ JsSIP: e }), this.connectionQueueManager = new yt({
3465
3590
  connectionManager: this.connectionManager
3466
- }), this.callManager = new Xe(), this.apiManager = new Fe({
3591
+ }), this.callManager = new je(), this.apiManager = new He({
3467
3592
  connectionManager: this.connectionManager,
3468
3593
  callManager: this.callManager
3469
- }), this.incomingCallManager = new qt(this.connectionManager), this.presentationManager = new dt({
3594
+ }), this.incomingCallManager = new Qt(this.connectionManager), this.presentationManager = new gt({
3470
3595
  callManager: this.callManager,
3471
- maxBitrate: _n
3472
- }), this.statsManager = new Xt({
3596
+ maxBitrate: Dn
3597
+ }), this.statsManager = new sn({
3473
3598
  callManager: this.callManager,
3474
3599
  apiManager: this.apiManager
3475
- }), this.autoConnectorManager = new Ft(
3600
+ }), this.autoConnectorManager = new Gt(
3476
3601
  {
3477
3602
  connectionQueueManager: this.connectionQueueManager,
3478
3603
  connectionManager: this.connectionManager,
3479
3604
  callManager: this.callManager
3480
3605
  },
3481
- i
3482
- ), this.transceiverManager = new tn({
3483
- callManager: this.callManager,
3484
- apiManager: this.apiManager
3485
- }), this.videoSendingBalancerManager = new pn(
3606
+ r
3607
+ ), this.videoSendingBalancerManager = new yn(
3486
3608
  this.callManager,
3487
3609
  this.apiManager,
3488
- r
3610
+ i
3489
3611
  ), this.subscribe();
3490
3612
  }
3491
3613
  get requestedConnection() {
@@ -3550,7 +3672,7 @@ class Qn {
3550
3672
  checkTelephony = async (e) => this.connectionManager.checkTelephony(e);
3551
3673
  isConfigured = () => this.connectionManager.isConfigured();
3552
3674
  getConnectionConfiguration = () => this.connectionManager.getConnectionConfiguration();
3553
- getSipServerUrl = (e) => this.connectionManager.getSipServerUrl(e);
3675
+ getUri = (e) => this.connectionManager.getUri(e);
3554
3676
  startAutoConnect = (...e) => {
3555
3677
  this.autoConnectorManager.start(...e);
3556
3678
  };
@@ -3559,14 +3681,10 @@ class Qn {
3559
3681
  };
3560
3682
  call = async (e) => {
3561
3683
  const { onAddedTransceiver: t, ...s } = e;
3562
- return this.callManager.startCall(
3563
- this.connectionManager.getUaProtected(),
3564
- this.getSipServerUrl,
3565
- {
3566
- ...s,
3567
- onAddedTransceiver: this.resolveHandleAddTransceiver(t)
3568
- }
3569
- );
3684
+ return this.callManager.startCall(this.connectionManager.getUaProtected(), this.getUri, {
3685
+ ...s,
3686
+ onAddedTransceiver: this.resolveHandleAddTransceiver(t)
3687
+ });
3570
3688
  };
3571
3689
  hangUp = async () => this.callManager.endCall();
3572
3690
  answerToIncomingCall = async (e) => {
@@ -3585,7 +3703,7 @@ class Qn {
3585
3703
  getRemoteStreams = () => this.callManager.getRemoteStreams();
3586
3704
  replaceMediaStream = async (...e) => this.callManager.replaceMediaStream(...e);
3587
3705
  async startPresentation(e, t = {}) {
3588
- const { isP2P: s, callLimit: r, onAddedTransceiver: i, ...a } = t;
3706
+ const { isP2P: s, callLimit: i, onAddedTransceiver: r, ...a } = t;
3589
3707
  return this.presentationManager.startPresentation(
3590
3708
  async () => {
3591
3709
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
@@ -3593,9 +3711,9 @@ class Qn {
3593
3711
  e,
3594
3712
  {
3595
3713
  ...a,
3596
- onAddedTransceiver: this.resolveHandleAddTransceiver(i)
3714
+ onAddedTransceiver: this.resolveHandleAddTransceiver(r)
3597
3715
  },
3598
- r === void 0 ? void 0 : { callLimit: r }
3716
+ i === void 0 ? void 0 : { callLimit: i }
3599
3717
  );
3600
3718
  }
3601
3719
  async stopPresentation(e = {}) {
@@ -3605,15 +3723,15 @@ class Qn {
3605
3723
  });
3606
3724
  }
3607
3725
  async updatePresentation(e, t = {}) {
3608
- const { isP2P: s, onAddedTransceiver: r, ...i } = t;
3726
+ const { isP2P: s, onAddedTransceiver: i, ...r } = t;
3609
3727
  return this.presentationManager.updatePresentation(
3610
3728
  async () => {
3611
3729
  s === !0 ? (await this.apiManager.sendMustStopPresentationP2P(), await this.apiManager.askPermissionToStartPresentationP2P()) : await this.apiManager.askPermissionToStartPresentation();
3612
3730
  },
3613
3731
  e,
3614
3732
  {
3615
- ...i,
3616
- onAddedTransceiver: this.resolveHandleAddTransceiver(r)
3733
+ ...r,
3734
+ onAddedTransceiver: this.resolveHandleAddTransceiver(i)
3617
3735
  }
3618
3736
  );
3619
3737
  }
@@ -3659,40 +3777,62 @@ class Qn {
3659
3777
  async askPermissionToEnableCam(...e) {
3660
3778
  return this.apiManager.askPermissionToEnableCam(...e);
3661
3779
  }
3780
+ subscribeChangeRole() {
3781
+ this.apiManager.on("participant:move-request-to-participants", () => {
3782
+ this.callManager.setCallRoleParticipant();
3783
+ }), this.apiManager.on("participant:move-request-to-spectators-synthetic", () => {
3784
+ this.callManager.setCallRoleSpectatorSynthetic();
3785
+ }), this.apiManager.on("participant:move-request-to-spectators-with-audio-id", ({ audioId: e }) => {
3786
+ this.callManager.setCallRoleSpectator({ audioId: e, sendOffer: this.sendOffer });
3787
+ });
3788
+ }
3789
+ sendOffer = async (e, t) => {
3790
+ const i = this.connectionManager.getConnectionConfiguration()?.sipServerUrl;
3791
+ if (i === void 0)
3792
+ throw new Error("No sipServerUrl for sendOffer");
3793
+ return zt({
3794
+ serverUrl: i,
3795
+ offer: t,
3796
+ conferenceNumber: e.conferenceNumber,
3797
+ quality: e.quality,
3798
+ audio: e.audioChannel
3799
+ });
3800
+ };
3662
3801
  setCodecPreferences(e) {
3663
- en(e, {
3802
+ hn(e, {
3664
3803
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
3665
3804
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
3666
3805
  });
3667
3806
  }
3668
3807
  subscribe() {
3669
- this.bridgeEvents("auto-connect", this.autoConnectorManager), this.bridgeEvents("connection", this.connectionManager), this.bridgeEvents("call", this.callManager), this.bridgeEvents("api", this.apiManager), this.bridgeEvents("incoming-call", this.incomingCallManager), this.bridgeEvents("presentation", this.presentationManager), this.bridgeEvents("stats", this.statsManager), this.bridgeEvents("video-balancer", this.videoSendingBalancerManager);
3808
+ this.bridgeEvents("auto-connect", this.autoConnectorManager), this.bridgeEvents("connection", this.connectionManager), this.bridgeEvents("call", this.callManager), this.bridgeEvents("api", this.apiManager), this.bridgeEvents("incoming-call", this.incomingCallManager), this.bridgeEvents("presentation", this.presentationManager), this.bridgeEvents("stats", this.statsManager), this.bridgeEvents("video-balancer", this.videoSendingBalancerManager), this.subscribeChangeRole();
3670
3809
  }
3671
3810
  bridgeEvents = (e, t) => {
3672
- t.events.eachTriggers((s, r) => {
3673
- t.on(r, (i) => {
3674
- this.events.trigger(`${e}:${r}`, i);
3811
+ t.events.eachTriggers((s, i) => {
3812
+ t.on(i, (r) => {
3813
+ this.events.trigger(`${e}:${i}`, r);
3675
3814
  });
3676
3815
  });
3677
3816
  };
3678
- resolveHandleAddTransceiver = (e) => async (t, s, r) => {
3679
- this.setCodecPreferences(t), await e?.(t, s, r);
3817
+ resolveHandleAddTransceiver = (e) => async (t, s, i) => {
3818
+ this.setCodecPreferences(t), await e?.(t, s, i);
3680
3819
  };
3681
3820
  }
3682
3821
  export {
3683
- ae as E,
3684
- ke as O,
3685
- Qn as S,
3686
- at as a,
3687
- Be as b,
3688
- Gn as c,
3689
- xn as d,
3690
- Wn as e,
3691
- A as f,
3692
- zt as g,
3693
- Nt as h,
3694
- rn as i,
3695
- c as l,
3696
- B as p,
3697
- he as s
3822
+ ce as E,
3823
+ Ge as O,
3824
+ Zn as S,
3825
+ ue as a,
3826
+ ht as b,
3827
+ We as c,
3828
+ Kn as d,
3829
+ Jn as e,
3830
+ jn as f,
3831
+ E as g,
3832
+ ft as h,
3833
+ nn as i,
3834
+ un as j,
3835
+ h as l,
3836
+ k as p,
3837
+ zt as s
3698
3838
  };