sip-connector 14.1.0-alpha.2 → 14.1.0-alpha.4

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.
@@ -3,13 +3,8 @@ import "@krivega/cancelable-promise";
3
3
  import k from "debug";
4
4
  import { hasCanceledError as K, repeatedCallsAsync as V } from "repeated-calls";
5
5
  import { setup as j, createActor as Z } from "xstate";
6
- const W = "sip-connector", P = k(W), Ve = () => {
7
- k.enable(W);
8
- }, He = () => {
9
- k.enable(`-${W}`);
10
- };
11
- var H = /* @__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))(H || {}), N = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(N || {}), U = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(U || {});
12
- const G = [
6
+ var N = /* @__PURE__ */ ((n) => (n.PEER_CONNECTION = "peerconnection", n.CONNECTING = "connecting", n.SENDING = "sending", n.PROGRESS = "progress", n.ACCEPTED = "accepted", n.CONFIRMED = "confirmed", n.ENDED = "ended", n.FAILED = "failed", n.NEW_DTMF = "newDTMF", n.NEW_INFO = "newInfo", n.HOLD = "hold", n.UNHOLD = "unhold", n.MUTED = "muted", n.UNMUTED = "unmuted", n.REINVITE = "reinvite", n.UPDATE = "update", n.REFER = "refer", n.REPLACES = "replaces", n.SDP = "sdp", n.ICE_CANDIDATE = "icecandidate", n.GET_USER_MEDIA_FAILED = "getusermediafailed", n.PEER_CONNECTION_CREATE_OFFER_FAILED = "peerconnection:createofferfailed", n.PEER_CONNECTION_CREATE_ANSWER_FAILED = "peerconnection:createanswerfailed", n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED = "peerconnection:setlocaldescriptionfailed", n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED = "peerconnection:setremotedescriptionfailed", n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n.PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed", n.PEER_CONNECTION_ONTRACK = "peerconnection:ontrack", n.ENDED_FROM_SERVER = "ended:fromserver", n))(N || {}), U = /* @__PURE__ */ ((n) => (n.LOCAL = "local", n.REMOTE = "remote", n.SYSTEM = "system", n))(U || {});
7
+ const H = [
13
8
  "peerconnection",
14
9
  "connecting",
15
10
  "sending",
@@ -40,14 +35,14 @@ const G = [
40
35
  "peerconnection:confirmed",
41
36
  "peerconnection:ontrack",
42
37
  "ended:fromserver"
43
- ], B = [
44
- ...G,
38
+ ], G = [
39
+ ...H,
45
40
  ...ee
46
41
  ];
47
42
  function te(n) {
48
43
  return (e) => `sip:${e}@${n}`;
49
44
  }
50
- const ne = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, x = (n) => n.trim().replaceAll(" ", "_"), se = ne(1e5, 99999999), ie = (n) => n.some((t) => {
45
+ const ne = (n, e) => () => Math.floor(Math.random() * (e - n)) + n, B = (n) => n.trim().replaceAll(" ", "_"), se = ne(1e5, 99999999), ie = (n) => n.some((t) => {
51
46
  const { kind: s } = t;
52
47
  return s === "video";
53
48
  }), re = (n, e) => {
@@ -75,6 +70,7 @@ class ae {
75
70
  this.events = e;
76
71
  }
77
72
  }
73
+ var x = /* @__PURE__ */ ((n) => (n.BYE = "Terminated", n.WEBRTC_ERROR = "WebRTC Error", n.CANCELED = "Canceled", n.REQUEST_TIMEOUT = "Request Timeout", n.REJECTED = "Rejected", n.REDIRECTED = "Redirected", n.UNAVAILABLE = "Unavailable", n.NOT_FOUND = "Not Found", n.ADDRESS_INCOMPLETE = "Address Incomplete", n.INCOMPATIBLE_SDP = "Incompatible SDP", n.BAD_MEDIA_DESCRIPTION = "Bad Media Description", n))(x || {});
78
74
  class oe {
79
75
  remoteStreams = {};
80
76
  reset() {
@@ -164,7 +160,7 @@ class ce extends ae {
164
160
  const { rtcSession: e } = this;
165
161
  if (e && !e.isEnded())
166
162
  return e.terminateAsync({
167
- cause: H.CANCELED
163
+ cause: x.CANCELED
168
164
  }).finally(() => {
169
165
  this.reset();
170
166
  });
@@ -264,7 +260,7 @@ class ce extends ae {
264
260
  });
265
261
  subscribeToSessionEvents(e) {
266
262
  this.events.eachTriggers((t, s) => {
267
- const i = G.find((r) => r === s);
263
+ const i = H.find((r) => r === s);
268
264
  i && (e.on(i, t), this.disposers.add(() => {
269
265
  e.off(i, t);
270
266
  }));
@@ -287,7 +283,7 @@ class ge {
287
283
  events;
288
284
  strategy;
289
285
  constructor(e) {
290
- this.events = new O(B), this.strategy = e ?? new ce(this.events);
286
+ this.events = new O(G), this.strategy = e ?? new ce(this.events);
291
287
  }
292
288
  get requested() {
293
289
  return this.strategy.requested;
@@ -331,179 +327,13 @@ class ge {
331
327
  getRemoteStreams = () => this.strategy.getRemoteStreams();
332
328
  replaceMediaStream = async (...e) => this.strategy.replaceMediaStream(...e);
333
329
  }
334
- var R = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(R || {});
330
+ const W = "sip-connector", P = k(W), He = () => {
331
+ k.enable(W);
332
+ }, Ge = () => {
333
+ k.enable(`-${W}`);
334
+ }, Te = "Error decline with 603", he = 1006, de = (n) => typeof n == "object" && n !== null && "code" in n && n.code === he, le = (n) => n.message === Te;
335
+ var h = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE_NAME = "content-type", n.CONTENT_ENTER_ROOM = "x-webrtc-enter-room", n.CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE", n.PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME", n.INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS", n.OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS", n.MAIN_CAM = "X-WEBRTC-MAINCAM", n.MIC = "X-WEBRTC-MIC", n.MEDIA_SYNC = "X-WEBRTC-SYNC", n.MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION", n.MEDIA_STATE = "X-WEBRTC-MEDIA-STATE", n.MEDIA_TYPE = "X-Vinteo-Media-Type", n.MAIN_CAM_STATE = "X-Vinteo-MainCam-State", n.MIC_STATE = "X-Vinteo-Mic-State", n.CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE", n.NOTIFY = "X-VINTEO-NOTIFY", n.CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", n.CONTENT_SHARE_STATE = "x-webrtc-share-state", n.MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT", n.START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT", n.STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND", n.STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION", n.START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION", n.ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM", n))(h || {}), y = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(y || {}), w = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(w || {}), M = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(M || {}), _ = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(_ || {}), f = /* @__PURE__ */ ((n) => (n.PAUSE_MAIN_CAM = "PAUSEMAINCAM", n.RESUME_MAIN_CAM = "RESUMEMAINCAM", n.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", n.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", n.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", n))(f || {}), L = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(L || {}), F = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(F || {}), Ee = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Ee || {}), T = /* @__PURE__ */ ((n) => (n.CHANNELS_NOTIFY = "channels:notify", n.PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators", n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators", n.PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream", n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators", n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants", n.PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request", n.PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request", n.WEBCAST_STARTED = "webcast:started", n.WEBCAST_STOPPED = "webcast:stopped", n.ACCOUNT_CHANGED = "account:changed", n.ACCOUNT_DELETED = "account:deleted", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "conference:participant-token-issued", n.CHANNELS = "channels", n.ENTER_ROOM = "enterRoom", n.SHARE_STATE = "shareState", n.MAIN_CAM_CONTROL = "main-cam-control", n.USE_LICENSE = "useLicense", n.ADMIN_START_MAIN_CAM = "admin-start-main-cam", n.ADMIN_STOP_MAIN_CAM = "admin-stop-main-cam", n.ADMIN_START_MIC = "admin-start-mic", n.ADMIN_STOP_MIC = "admin-stop-mic", n.ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-state", n.AVAILABLE_SECOND_REMOTE_STREAM = "availableSecondRemoteStream", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "notAvailableSecondRemoteStream", n.MUST_STOP_PRESENTATION = "mustStopPresentation", n.NEW_DTMF = "newDTMF", n))(T || {});
335
336
  const q = [
336
- "presentation:start",
337
- "presentation:started",
338
- "presentation:end",
339
- "presentation:ended",
340
- "presentation:failed"
341
- ], he = 1, Ge = (n) => K(n);
342
- class Te {
343
- events;
344
- promisePendingStartPresentation;
345
- promisePendingStopPresentation;
346
- streamPresentationCurrent;
347
- cancelableSendPresentationWithRepeatedCalls;
348
- callManager;
349
- constructor({ callManager: e }) {
350
- this.callManager = e, this.events = new O(q), this.subscribe();
351
- }
352
- get isPendingPresentation() {
353
- return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
354
- }
355
- // eslint-disable-next-line @typescript-eslint/max-params
356
- async startPresentation(e, t, {
357
- isNeedReinvite: s,
358
- maxBitrate: i,
359
- contentHint: r,
360
- sendEncodings: a,
361
- onAddedTransceiver: o
362
- } = {}, c) {
363
- const g = this.getRtcSessionProtected();
364
- if (this.streamPresentationCurrent)
365
- throw new Error("Presentation is already started");
366
- return this.sendPresentationWithDuplicatedCalls(e, {
367
- rtcSession: g,
368
- stream: t,
369
- presentationOptions: {
370
- isNeedReinvite: s,
371
- maxBitrate: i,
372
- contentHint: r,
373
- sendEncodings: a,
374
- onAddedTransceiver: o
375
- },
376
- options: c
377
- });
378
- }
379
- async stopPresentation(e) {
380
- this.cancelSendPresentationWithRepeatedCalls();
381
- const t = this.streamPresentationCurrent;
382
- let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
383
- const i = this.callManager.getEstablishedRTCSession();
384
- return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
385
- throw this.events.trigger(R.FAILED_PRESENTATION, r), r;
386
- }) : t && this.events.trigger(R.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
387
- this.resetPresentation();
388
- });
389
- }
390
- async updatePresentation(e, t, {
391
- // maxBitrate,
392
- contentHint: s,
393
- sendEncodings: i,
394
- onAddedTransceiver: r
395
- } = {}) {
396
- const a = this.getRtcSessionProtected();
397
- if (!this.streamPresentationCurrent)
398
- throw new Error("Presentation has not started yet");
399
- return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
400
- // maxBitrate,
401
- contentHint: s,
402
- isNeedReinvite: !1,
403
- sendEncodings: i,
404
- onAddedTransceiver: r
405
- });
406
- }
407
- cancelSendPresentationWithRepeatedCalls() {
408
- this.cancelableSendPresentationWithRepeatedCalls?.cancel();
409
- }
410
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
411
- on(e, t) {
412
- return this.events.on(e, t);
413
- }
414
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
415
- once(e, t) {
416
- return this.events.once(e, t);
417
- }
418
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
419
- onceRace(e, t) {
420
- return this.events.onceRace(e, t);
421
- }
422
- async wait(e) {
423
- return this.events.wait(e);
424
- }
425
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
426
- off(e, t) {
427
- this.events.off(e, t);
428
- }
429
- subscribe() {
430
- this.callManager.on("presentation:start", (e) => {
431
- this.events.trigger(R.START_PRESENTATION, e);
432
- }), this.callManager.on("presentation:started", (e) => {
433
- this.events.trigger(R.STARTED_PRESENTATION, e);
434
- }), this.callManager.on("presentation:end", (e) => {
435
- this.events.trigger(R.END_PRESENTATION, e);
436
- }), this.callManager.on("presentation:ended", (e) => {
437
- this.events.trigger(R.ENDED_PRESENTATION, e);
438
- }), this.callManager.on("presentation:failed", (e) => {
439
- this.events.trigger(R.FAILED_PRESENTATION, e);
440
- }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
441
- }
442
- async sendPresentationWithDuplicatedCalls(e, {
443
- rtcSession: t,
444
- stream: s,
445
- presentationOptions: i,
446
- options: r = {
447
- callLimit: he
448
- }
449
- }) {
450
- const a = async () => this.sendPresentation(
451
- e,
452
- t,
453
- s,
454
- i
455
- ), o = () => !!this.streamPresentationCurrent;
456
- return this.cancelableSendPresentationWithRepeatedCalls = V({
457
- targetFunction: a,
458
- isComplete: o,
459
- isRejectAsValid: !0,
460
- ...r
461
- }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
462
- }
463
- // eslint-disable-next-line @typescript-eslint/max-params
464
- async sendPresentation(e, t, s, {
465
- // maxBitrate = ONE_MEGABIT_IN_BITS,
466
- isNeedReinvite: i = !0,
467
- contentHint: r = "detail",
468
- sendEncodings: a,
469
- onAddedTransceiver: o
470
- }) {
471
- const c = v(s, { contentHint: r });
472
- if (c === void 0)
473
- throw new Error("No streamPresentationTarget");
474
- this.streamPresentationCurrent = c;
475
- const g = e().then(async () => t.startPresentation(c, i, {
476
- sendEncodings: a,
477
- onAddedTransceiver: o
478
- })).then(() => s).catch((d) => {
479
- throw this.removeStreamPresentationCurrent(), this.events.trigger(R.FAILED_PRESENTATION, d), d;
480
- });
481
- return this.promisePendingStartPresentation = g, g.finally(() => {
482
- this.promisePendingStartPresentation = void 0;
483
- });
484
- }
485
- getRtcSessionProtected = () => {
486
- const e = this.callManager.getEstablishedRTCSession();
487
- if (!e)
488
- throw new Error("No rtcSession established");
489
- return e;
490
- };
491
- handleEnded = () => {
492
- this.reset();
493
- };
494
- reset() {
495
- this.cancelSendPresentationWithRepeatedCalls(), this.resetPresentation();
496
- }
497
- resetPresentation() {
498
- this.removeStreamPresentationCurrent(), this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
499
- }
500
- removeStreamPresentationCurrent() {
501
- delete this.streamPresentationCurrent;
502
- }
503
- }
504
- const de = "Error decline with 603", le = 1006, Ee = (n) => typeof n == "object" && n !== null && "code" in n && n.code === le, Se = (n) => n.message === de;
505
- var T = /* @__PURE__ */ ((n) => (n.CONTENT_TYPE_NAME = "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))(T || {}), y = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(y || {}), w = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(w || {}), M = /* @__PURE__ */ ((n) => (n.ENTER_ROOM = "application/vinteo.webrtc.roomname", n.MIC = "application/vinteo.webrtc.mic", n.USE_LICENSE = "application/vinteo.webrtc.uselic", n.PARTICIPANT_STATE = "application/vinteo.webrtc.partstate", n.NOTIFY = "application/vinteo.webrtc.notify", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(M || {}), _ = /* @__PURE__ */ ((n) => (n.CHANNELS = "application/vinteo.webrtc.channels", n.MEDIA_STATE = "application/vinteo.webrtc.mediastate", n.REFUSAL = "application/vinteo.webrtc.refusal", n.SHARE_STATE = "application/vinteo.webrtc.sharedesktop", n.MAIN_CAM = "application/vinteo.webrtc.maincam", n))(_ || {}), f = /* @__PURE__ */ ((n) => (n.PAUSE_MAIN_CAM = "PAUSEMAINCAM", n.RESUME_MAIN_CAM = "RESUMEMAINCAM", n.MAX_MAIN_CAM_RESOLUTION = "MAXMAINCAMRESOLUTION", n.ADMIN_STOP_MAIN_CAM = "ADMINSTOPMAINCAM", n.ADMIN_START_MAIN_CAM = "ADMINSTARTMAINCAM", n))(f || {}), L = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(L || {}), F = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(F || {}), h = /* @__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))(h || {});
506
- const Y = [
507
337
  "participation:accepting-word-request",
508
338
  "participation:cancelling-word-request",
509
339
  "participant:move-request-to-stream",
@@ -533,7 +363,7 @@ const Y = [
533
363
  "newDTMF"
534
364
  ];
535
365
  var A = /* @__PURE__ */ ((n) => (n.CHANNELS = "channels", n.WEBCAST_STARTED = "WebcastStarted", n.WEBCAST_STOPPED = "WebcastStopped", n.ACCOUNT_CHANGED = "accountChanged", n.ACCOUNT_DELETED = "accountDeleted", n.ADDED_TO_LIST_MODERATORS = "addedToListModerators", n.REMOVED_FROM_LIST_MODERATORS = "removedFromListModerators", n.ACCEPTING_WORD_REQUEST = "ParticipationRequestAccepted", n.CANCELLING_WORD_REQUEST = "ParticipationRequestRejected", n.MOVE_REQUEST_TO_STREAM = "ParticipantMovedToWebcast", n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "ConferenceParticipantTokenIssued", n))(A || {});
536
- class Ce {
366
+ class Se {
537
367
  events;
538
368
  connectionManager;
539
369
  callManager;
@@ -541,13 +371,13 @@ class Ce {
541
371
  connectionManager: e,
542
372
  callManager: t
543
373
  }) {
544
- this.connectionManager = e, this.callManager = t, this.events = new O(Y), this.subscribe();
374
+ this.connectionManager = e, this.callManager = t, this.events = new O(q), this.subscribe();
545
375
  }
546
376
  async waitChannels() {
547
- return this.wait(h.CHANNELS);
377
+ return this.wait(T.CHANNELS);
548
378
  }
549
379
  async waitSyncMediaState() {
550
- return this.wait(h.ADMIN_FORCE_SYNC_MEDIA_STATE);
380
+ return this.wait(T.ADMIN_FORCE_SYNC_MEDIA_STATE);
551
381
  }
552
382
  async sendDTMF(e) {
553
383
  return new Promise((t, s) => {
@@ -568,7 +398,7 @@ class Ce {
568
398
  const s = this.callManager.getEstablishedRTCSession();
569
399
  if (!s)
570
400
  throw new Error("No rtcSession established");
571
- const i = `${T.INPUT_CHANNELS}: ${e}`, r = `${T.OUTPUT_CHANNELS}: ${t}`, a = [
401
+ const i = `${h.INPUT_CHANNELS}: ${e}`, r = `${h.OUTPUT_CHANNELS}: ${t}`, a = [
572
402
  i,
573
403
  r
574
404
  ];
@@ -578,7 +408,7 @@ class Ce {
578
408
  const i = this.callManager.getEstablishedRTCSession();
579
409
  if (!i)
580
410
  throw new Error("No rtcSession established");
581
- const r = `${T.MEDIA_STATE}: currentstate`, a = `${T.MAIN_CAM_STATE}: ${Number(e)}`, o = `${T.MIC_STATE}: ${Number(t)}`, c = [
411
+ const r = `${h.MEDIA_STATE}: currentstate`, a = `${h.MAIN_CAM_STATE}: ${Number(e)}`, o = `${h.MIC_STATE}: ${Number(t)}`, c = [
582
412
  r,
583
413
  a,
584
414
  o
@@ -593,7 +423,7 @@ class Ce {
593
423
  const s = this.callManager.getEstablishedRTCSession();
594
424
  if (!s)
595
425
  throw new Error("No rtcSession established");
596
- const a = e === "mic" ? 0 : 1, c = [`${T.MEDIA_TYPE}: ${a}`];
426
+ const a = e === "mic" ? 0 : 1, c = [`${h.MEDIA_TYPE}: ${a}`];
597
427
  return s.sendInfo(_.REFUSAL, void 0, {
598
428
  noTerminateWhenError: !0,
599
429
  ...t,
@@ -615,7 +445,7 @@ class Ce {
615
445
  if (!e)
616
446
  throw new Error("No rtcSession established");
617
447
  await e.sendInfo(_.SHARE_STATE, void 0, {
618
- extraHeaders: [T.MUST_STOP_PRESENTATION_P2P]
448
+ extraHeaders: [h.MUST_STOP_PRESENTATION_P2P]
619
449
  });
620
450
  }
621
451
  async sendStoppedPresentationP2P() {
@@ -623,7 +453,7 @@ class Ce {
623
453
  if (!e)
624
454
  throw new Error("No rtcSession established");
625
455
  await e.sendInfo(_.SHARE_STATE, void 0, {
626
- extraHeaders: [T.STOP_PRESENTATION_P2P]
456
+ extraHeaders: [h.STOP_PRESENTATION_P2P]
627
457
  });
628
458
  }
629
459
  async sendStoppedPresentation() {
@@ -631,7 +461,7 @@ class Ce {
631
461
  if (!e)
632
462
  throw new Error("No rtcSession established");
633
463
  await e.sendInfo(_.SHARE_STATE, void 0, {
634
- extraHeaders: [T.STOP_PRESENTATION]
464
+ extraHeaders: [h.STOP_PRESENTATION]
635
465
  });
636
466
  }
637
467
  async askPermissionToStartPresentationP2P() {
@@ -639,7 +469,7 @@ class Ce {
639
469
  if (!e)
640
470
  throw new Error("No rtcSession established");
641
471
  await e.sendInfo(_.SHARE_STATE, void 0, {
642
- extraHeaders: [T.START_PRESENTATION_P2P]
472
+ extraHeaders: [h.START_PRESENTATION_P2P]
643
473
  });
644
474
  }
645
475
  async askPermissionToStartPresentation() {
@@ -647,20 +477,20 @@ class Ce {
647
477
  if (!e)
648
478
  throw new Error("No rtcSession established");
649
479
  await e.sendInfo(_.SHARE_STATE, void 0, {
650
- extraHeaders: [T.START_PRESENTATION]
480
+ extraHeaders: [h.START_PRESENTATION]
651
481
  });
652
482
  }
653
483
  async askPermissionToEnableCam(e = {}) {
654
484
  const t = this.callManager.getEstablishedRTCSession();
655
485
  if (!t)
656
486
  throw new Error("No rtcSession established");
657
- const s = [T.ENABLE_MAIN_CAM];
487
+ const s = [h.ENABLE_MAIN_CAM];
658
488
  return t.sendInfo(_.MAIN_CAM, void 0, {
659
489
  noTerminateWhenError: !0,
660
490
  ...e,
661
491
  extraHeaders: s
662
492
  }).catch((i) => {
663
- if (Se(i))
493
+ if (le(i))
664
494
  throw i;
665
495
  });
666
496
  }
@@ -693,7 +523,7 @@ class Ce {
693
523
  };
694
524
  maybeHandleNotify = (e) => {
695
525
  try {
696
- const t = e.getHeader(T.NOTIFY);
526
+ const t = e.getHeader(h.NOTIFY);
697
527
  if (t) {
698
528
  const s = JSON.parse(t);
699
529
  this.handleNotify(s);
@@ -765,7 +595,7 @@ class Ce {
765
595
  const { originator: t } = e;
766
596
  if (t !== U.REMOTE)
767
597
  return;
768
- const { request: s } = e, i = s.getHeader(T.CONTENT_TYPE_NAME);
598
+ const { request: s } = e, i = s.getHeader(h.CONTENT_TYPE_NAME);
769
599
  if (i !== void 0)
770
600
  switch (i) {
771
601
  case M.ENTER_ROOM: {
@@ -803,7 +633,7 @@ class Ce {
803
633
  inputChannels: t,
804
634
  outputChannels: s
805
635
  };
806
- this.events.trigger(h.CHANNELS_NOTIFY, i);
636
+ this.events.trigger(T.CHANNELS_NOTIFY, i);
807
637
  };
808
638
  triggerWebcastStartedNotify = ({
809
639
  body: { conference: e, type: t }
@@ -812,7 +642,7 @@ class Ce {
812
642
  conference: e,
813
643
  type: t
814
644
  };
815
- this.events.trigger(h.WEBCAST_STARTED, s);
645
+ this.events.trigger(T.WEBCAST_STARTED, s);
816
646
  };
817
647
  triggerWebcastStoppedNotify = ({
818
648
  body: { conference: e, type: t }
@@ -821,7 +651,7 @@ class Ce {
821
651
  conference: e,
822
652
  type: t
823
653
  };
824
- this.events.trigger(h.WEBCAST_STOPPED, s);
654
+ this.events.trigger(T.WEBCAST_STOPPED, s);
825
655
  };
826
656
  triggerAddedToListModeratorsNotify = ({
827
657
  conference: e
@@ -830,7 +660,7 @@ class Ce {
830
660
  conference: e
831
661
  };
832
662
  this.events.trigger(
833
- h.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
663
+ T.PARTICIPANT_ADDED_TO_LIST_MODERATORS,
834
664
  t
835
665
  );
836
666
  };
@@ -841,7 +671,7 @@ class Ce {
841
671
  conference: e
842
672
  };
843
673
  this.events.trigger(
844
- h.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
674
+ T.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,
845
675
  t
846
676
  );
847
677
  };
@@ -851,7 +681,7 @@ class Ce {
851
681
  const t = {
852
682
  conference: e
853
683
  };
854
- this.events.trigger(h.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
684
+ this.events.trigger(T.PARTICIPATION_ACCEPTING_WORD_REQUEST, t);
855
685
  };
856
686
  triggerParticipationCancellingWordRequest = ({
857
687
  body: { conference: e }
@@ -859,7 +689,7 @@ class Ce {
859
689
  const t = {
860
690
  conference: e
861
691
  };
862
- this.events.trigger(h.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
692
+ this.events.trigger(T.PARTICIPATION_CANCELLING_WORD_REQUEST, t);
863
693
  };
864
694
  triggerParticipantMoveRequestToStream = ({
865
695
  body: { conference: e }
@@ -867,13 +697,13 @@ class Ce {
867
697
  const t = {
868
698
  conference: e
869
699
  };
870
- this.events.trigger(h.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
700
+ this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_STREAM, t);
871
701
  };
872
702
  triggerAccountChangedNotify = () => {
873
- this.events.trigger(h.ACCOUNT_CHANGED, void 0);
703
+ this.events.trigger(T.ACCOUNT_CHANGED, void 0);
874
704
  };
875
705
  triggerAccountDeletedNotify = () => {
876
- this.events.trigger(h.ACCOUNT_DELETED, void 0);
706
+ this.events.trigger(T.ACCOUNT_DELETED, void 0);
877
707
  };
878
708
  triggerConferenceParticipantTokenIssued = ({
879
709
  body: { conference: e, participant: t, jwt: s }
@@ -884,73 +714,243 @@ class Ce {
884
714
  jwt: s
885
715
  };
886
716
  this.events.trigger(
887
- h.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
717
+ T.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,
888
718
  i
889
719
  );
890
720
  };
891
721
  maybeTriggerChannels = (e) => {
892
- const t = e.getHeader(T.INPUT_CHANNELS), s = e.getHeader(T.OUTPUT_CHANNELS);
722
+ const t = e.getHeader(h.INPUT_CHANNELS), s = e.getHeader(h.OUTPUT_CHANNELS);
893
723
  if (t && s) {
894
724
  const i = {
895
725
  inputChannels: t,
896
726
  outputChannels: s
897
727
  };
898
- this.events.trigger(h.CHANNELS, i);
728
+ this.events.trigger(T.CHANNELS, i);
899
729
  }
900
730
  };
901
731
  triggerEnterRoom = (e) => {
902
- const t = e.getHeader(T.CONTENT_ENTER_ROOM), s = e.getHeader(T.PARTICIPANT_NAME);
903
- this.events.trigger(h.ENTER_ROOM, { room: t, participantName: s });
732
+ const t = e.getHeader(h.CONTENT_ENTER_ROOM), s = e.getHeader(h.PARTICIPANT_NAME);
733
+ this.events.trigger(T.ENTER_ROOM, { room: t, participantName: s });
904
734
  };
905
735
  triggerShareState = (e) => {
906
- const t = e.getHeader(T.CONTENT_SHARE_STATE);
736
+ const t = e.getHeader(h.CONTENT_SHARE_STATE);
907
737
  if (t !== void 0)
908
738
  switch (t) {
909
739
  case y.AVAILABLE_SECOND_REMOTE_STREAM: {
910
- this.events.trigger(h.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
740
+ this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM, void 0);
911
741
  break;
912
742
  }
913
743
  case y.NOT_AVAILABLE_SECOND_REMOTE_STREAM: {
914
- this.events.trigger(h.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
744
+ this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM, void 0);
915
745
  break;
916
746
  }
917
747
  case y.MUST_STOP_PRESENTATION: {
918
- this.events.trigger(h.MUST_STOP_PRESENTATION, void 0);
748
+ this.events.trigger(T.MUST_STOP_PRESENTATION, void 0);
919
749
  break;
920
750
  }
921
751
  }
922
752
  };
923
753
  maybeTriggerParticipantMoveRequest = (e) => {
924
- const t = e.getHeader(T.CONTENT_PARTICIPANT_STATE);
925
- t === w.SPECTATOR && this.events.trigger(h.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === w.PARTICIPANT && this.events.trigger(h.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0);
754
+ const t = e.getHeader(h.CONTENT_PARTICIPANT_STATE);
755
+ t === w.SPECTATOR && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS, void 0), t === w.PARTICIPANT && this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS, void 0);
926
756
  };
927
757
  triggerMainCamControl = (e) => {
928
- const t = e.getHeader(T.MAIN_CAM), s = e.getHeader(T.MEDIA_SYNC), i = s === F.ADMIN_SYNC_FORCED;
758
+ const t = e.getHeader(h.MAIN_CAM), s = e.getHeader(h.MEDIA_SYNC), i = s === F.ADMIN_SYNC_FORCED;
929
759
  if (t === f.ADMIN_START_MAIN_CAM) {
930
- this.events.trigger(h.ADMIN_START_MAIN_CAM, { isSyncForced: i });
760
+ this.events.trigger(T.ADMIN_START_MAIN_CAM, { isSyncForced: i });
931
761
  return;
932
762
  }
933
763
  if (t === f.ADMIN_STOP_MAIN_CAM) {
934
- this.events.trigger(h.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
764
+ this.events.trigger(T.ADMIN_STOP_MAIN_CAM, { isSyncForced: i });
935
765
  return;
936
766
  }
937
- (t === f.RESUME_MAIN_CAM || t === f.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(h.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
938
- const r = e.getHeader(T.MAIN_CAM_RESOLUTION);
939
- this.events.trigger(h.MAIN_CAM_CONTROL, {
767
+ (t === f.RESUME_MAIN_CAM || t === f.PAUSE_MAIN_CAM) && s !== void 0 && this.events.trigger(T.ADMIN_FORCE_SYNC_MEDIA_STATE, { isSyncForced: i });
768
+ const r = e.getHeader(h.MAIN_CAM_RESOLUTION);
769
+ this.events.trigger(T.MAIN_CAM_CONTROL, {
940
770
  mainCam: t,
941
771
  resolutionMainCam: r
942
772
  });
943
773
  };
944
774
  triggerMicControl = (e) => {
945
- const t = e.getHeader(T.MIC), i = e.getHeader(T.MEDIA_SYNC) === F.ADMIN_SYNC_FORCED;
946
- t === L.ADMIN_START_MIC ? this.events.trigger(h.ADMIN_START_MIC, { isSyncForced: i }) : t === L.ADMIN_STOP_MIC && this.events.trigger(h.ADMIN_STOP_MIC, { isSyncForced: i });
775
+ const t = e.getHeader(h.MIC), i = e.getHeader(h.MEDIA_SYNC) === F.ADMIN_SYNC_FORCED;
776
+ t === L.ADMIN_START_MIC ? this.events.trigger(T.ADMIN_START_MIC, { isSyncForced: i }) : t === L.ADMIN_STOP_MIC && this.events.trigger(T.ADMIN_STOP_MIC, { isSyncForced: i });
947
777
  };
948
778
  triggerUseLicense = (e) => {
949
- const t = e.getHeader(T.CONTENT_USE_LICENSE);
950
- this.events.trigger(h.USE_LICENSE, t);
779
+ const t = e.getHeader(h.CONTENT_USE_LICENSE);
780
+ this.events.trigger(T.USE_LICENSE, t);
951
781
  };
952
782
  }
783
+ var R = /* @__PURE__ */ ((n) => (n.START_PRESENTATION = "presentation:start", n.STARTED_PRESENTATION = "presentation:started", n.END_PRESENTATION = "presentation:end", n.ENDED_PRESENTATION = "presentation:ended", n.FAILED_PRESENTATION = "presentation:failed", n))(R || {});
784
+ const Y = [
785
+ "presentation:start",
786
+ "presentation:started",
787
+ "presentation:end",
788
+ "presentation:ended",
789
+ "presentation:failed"
790
+ ], Ce = 1, Be = (n) => K(n);
953
791
  class Ne {
792
+ events;
793
+ promisePendingStartPresentation;
794
+ promisePendingStopPresentation;
795
+ streamPresentationCurrent;
796
+ cancelableSendPresentationWithRepeatedCalls;
797
+ callManager;
798
+ constructor({ callManager: e }) {
799
+ this.callManager = e, this.events = new O(Y), this.subscribe();
800
+ }
801
+ get isPendingPresentation() {
802
+ return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
803
+ }
804
+ // eslint-disable-next-line @typescript-eslint/max-params
805
+ async startPresentation(e, t, {
806
+ isNeedReinvite: s,
807
+ maxBitrate: i,
808
+ contentHint: r,
809
+ sendEncodings: a,
810
+ onAddedTransceiver: o
811
+ } = {}, c) {
812
+ const g = this.getRtcSessionProtected();
813
+ if (this.streamPresentationCurrent)
814
+ throw new Error("Presentation is already started");
815
+ return this.sendPresentationWithDuplicatedCalls(e, {
816
+ rtcSession: g,
817
+ stream: t,
818
+ presentationOptions: {
819
+ isNeedReinvite: s,
820
+ maxBitrate: i,
821
+ contentHint: r,
822
+ sendEncodings: a,
823
+ onAddedTransceiver: o
824
+ },
825
+ options: c
826
+ });
827
+ }
828
+ async stopPresentation(e) {
829
+ this.cancelSendPresentationWithRepeatedCalls();
830
+ const t = this.streamPresentationCurrent;
831
+ let s = this.promisePendingStartPresentation ?? Promise.resolve(void 0);
832
+ const i = this.callManager.getEstablishedRTCSession();
833
+ return i && t ? s = e().then(async () => i.stopPresentation(t)).catch((r) => {
834
+ throw this.events.trigger(R.FAILED_PRESENTATION, r), r;
835
+ }) : t && this.events.trigger(R.ENDED_PRESENTATION, t), this.promisePendingStopPresentation = s, s.finally(() => {
836
+ this.resetPresentation();
837
+ });
838
+ }
839
+ async updatePresentation(e, t, {
840
+ // maxBitrate,
841
+ contentHint: s,
842
+ sendEncodings: i,
843
+ onAddedTransceiver: r
844
+ } = {}) {
845
+ const a = this.getRtcSessionProtected();
846
+ if (!this.streamPresentationCurrent)
847
+ throw new Error("Presentation has not started yet");
848
+ return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this.sendPresentation(e, a, t, {
849
+ // maxBitrate,
850
+ contentHint: s,
851
+ isNeedReinvite: !1,
852
+ sendEncodings: i,
853
+ onAddedTransceiver: r
854
+ });
855
+ }
856
+ cancelSendPresentationWithRepeatedCalls() {
857
+ this.cancelableSendPresentationWithRepeatedCalls?.cancel();
858
+ }
859
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
860
+ on(e, t) {
861
+ return this.events.on(e, t);
862
+ }
863
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
864
+ once(e, t) {
865
+ return this.events.once(e, t);
866
+ }
867
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
868
+ onceRace(e, t) {
869
+ return this.events.onceRace(e, t);
870
+ }
871
+ async wait(e) {
872
+ return this.events.wait(e);
873
+ }
874
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
875
+ off(e, t) {
876
+ this.events.off(e, t);
877
+ }
878
+ subscribe() {
879
+ this.callManager.on("presentation:start", (e) => {
880
+ this.events.trigger(R.START_PRESENTATION, e);
881
+ }), this.callManager.on("presentation:started", (e) => {
882
+ this.events.trigger(R.STARTED_PRESENTATION, e);
883
+ }), this.callManager.on("presentation:end", (e) => {
884
+ this.events.trigger(R.END_PRESENTATION, e);
885
+ }), this.callManager.on("presentation:ended", (e) => {
886
+ this.events.trigger(R.ENDED_PRESENTATION, e);
887
+ }), this.callManager.on("presentation:failed", (e) => {
888
+ this.events.trigger(R.FAILED_PRESENTATION, e);
889
+ }), this.callManager.on("failed", this.handleEnded), this.callManager.on("ended", this.handleEnded);
890
+ }
891
+ async sendPresentationWithDuplicatedCalls(e, {
892
+ rtcSession: t,
893
+ stream: s,
894
+ presentationOptions: i,
895
+ options: r = {
896
+ callLimit: Ce
897
+ }
898
+ }) {
899
+ const a = async () => this.sendPresentation(
900
+ e,
901
+ t,
902
+ s,
903
+ i
904
+ ), o = () => !!this.streamPresentationCurrent;
905
+ return this.cancelableSendPresentationWithRepeatedCalls = V({
906
+ targetFunction: a,
907
+ isComplete: o,
908
+ isRejectAsValid: !0,
909
+ ...r
910
+ }), this.cancelableSendPresentationWithRepeatedCalls.then((c) => c);
911
+ }
912
+ // eslint-disable-next-line @typescript-eslint/max-params
913
+ async sendPresentation(e, t, s, {
914
+ // maxBitrate = ONE_MEGABIT_IN_BITS,
915
+ isNeedReinvite: i = !0,
916
+ contentHint: r = "detail",
917
+ sendEncodings: a,
918
+ onAddedTransceiver: o
919
+ }) {
920
+ const c = v(s, { contentHint: r });
921
+ if (c === void 0)
922
+ throw new Error("No streamPresentationTarget");
923
+ this.streamPresentationCurrent = c;
924
+ const g = e().then(async () => t.startPresentation(c, i, {
925
+ sendEncodings: a,
926
+ onAddedTransceiver: o
927
+ })).then(() => s).catch((d) => {
928
+ throw this.removeStreamPresentationCurrent(), this.events.trigger(R.FAILED_PRESENTATION, d), d;
929
+ });
930
+ return this.promisePendingStartPresentation = g, g.finally(() => {
931
+ this.promisePendingStartPresentation = void 0;
932
+ });
933
+ }
934
+ getRtcSessionProtected = () => {
935
+ const e = this.callManager.getEstablishedRTCSession();
936
+ if (!e)
937
+ throw new Error("No rtcSession established");
938
+ return e;
939
+ };
940
+ handleEnded = () => {
941
+ this.reset();
942
+ };
943
+ reset() {
944
+ this.cancelSendPresentationWithRepeatedCalls(), this.resetPresentation();
945
+ }
946
+ resetPresentation() {
947
+ this.removeStreamPresentationCurrent(), this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
948
+ }
949
+ removeStreamPresentationCurrent() {
950
+ delete this.streamPresentationCurrent;
951
+ }
952
+ }
953
+ class ue {
954
954
  data = {};
955
955
  getUa;
956
956
  constructor(e) {
@@ -1034,8 +1034,8 @@ const z = [
1034
1034
  "registrationFailed",
1035
1035
  "newMessage",
1036
1036
  "sipEvent"
1037
- ], Q = [...z], ue = 3;
1038
- class Ae {
1037
+ ], Q = [...z], Ae = 3;
1038
+ class _e {
1039
1039
  cancelableConnectWithRepeatedCalls;
1040
1040
  JsSIP;
1041
1041
  events;
@@ -1061,7 +1061,7 @@ class Ae {
1061
1061
  }
1062
1062
  let r = !1;
1063
1063
  const a = this.getConnectionConfiguration();
1064
- e !== void 0 && e !== a.displayName && (r = i.set("display_name", x(e)), this.updateConnectionConfiguration("displayName", e));
1064
+ e !== void 0 && e !== a.displayName && (r = i.set("display_name", B(e)), this.updateConnectionConfiguration("displayName", e));
1065
1065
  const o = r;
1066
1066
  o ? t(o) : s(new Error("nothing changed"));
1067
1067
  });
@@ -1078,9 +1078,9 @@ class Ae {
1078
1078
  cancelRequests() {
1079
1079
  this.cancelConnectWithRepeatedCalls();
1080
1080
  }
1081
- connectWithDuplicatedCalls = async (e, { callLimit: t = ue } = {}) => {
1081
+ connectWithDuplicatedCalls = async (e, { callLimit: t = Ae } = {}) => {
1082
1082
  const s = async () => this.connectInner(e), i = (r) => {
1083
- const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), g = r != null && !Ee(r);
1083
+ const c = this.getUa()?.isConnected() === !0 && this.hasEqualConnectionConfiguration(e), g = r != null && !de(r);
1084
1084
  return c || g;
1085
1085
  };
1086
1086
  return this.stateMachine.startConnect(), this.cancelableConnectWithRepeatedCalls = V({
@@ -1171,7 +1171,7 @@ class Ae {
1171
1171
  }
1172
1172
  }
1173
1173
  var X = /* @__PURE__ */ ((n) => (n.START_CONNECT = "START_CONNECT", n.START_INIT_UA = "START_INIT_UA", n.UA_CONNECTED = "UA_CONNECTED", n.UA_REGISTERED = "UA_REGISTERED", n.UA_UNREGISTERED = "UA_UNREGISTERED", n.UA_DISCONNECTED = "UA_DISCONNECTED", n.CONNECTION_FAILED = "CONNECTION_FAILED", n.RESET = "RESET", n))(X || {});
1174
- const _e = j({
1174
+ const Ie = j({
1175
1175
  types: {
1176
1176
  context: {},
1177
1177
  events: {}
@@ -1485,14 +1485,14 @@ const _e = j({
1485
1485
  }
1486
1486
  }
1487
1487
  });
1488
- class Ie {
1488
+ class Re {
1489
1489
  actor;
1490
1490
  stateChangeListeners = /* @__PURE__ */ new Set();
1491
1491
  events;
1492
1492
  unsubscribeFromEvents;
1493
1493
  actorSubscription;
1494
1494
  constructor(e) {
1495
- this.events = e, this.actor = Z(_e), this.actorSubscription = this.actor.subscribe((t) => {
1495
+ this.events = e, this.actor = Z(Ie), this.actorSubscription = this.actor.subscribe((t) => {
1496
1496
  const s = t.value;
1497
1497
  this.stateChangeListeners.forEach((i) => {
1498
1498
  i(s);
@@ -1647,7 +1647,7 @@ class Ie {
1647
1647
  };
1648
1648
  }
1649
1649
  }
1650
- class Re {
1650
+ class Me {
1651
1651
  events;
1652
1652
  getUaProtected;
1653
1653
  constructor(e) {
@@ -1684,7 +1684,7 @@ class Re {
1684
1684
  };
1685
1685
  }
1686
1686
  }
1687
- class Me {
1687
+ class pe {
1688
1688
  uaFactory;
1689
1689
  getUaProtected;
1690
1690
  constructor(e) {
@@ -1749,7 +1749,7 @@ class Me {
1749
1749
  });
1750
1750
  }
1751
1751
  }
1752
- const pe = (n) => {
1752
+ const me = (n) => {
1753
1753
  const e = [];
1754
1754
  return n !== void 0 && n !== "" && e.push(`X-Vinteo-Remote: ${n}`), e;
1755
1755
  };
@@ -1781,7 +1781,7 @@ class m {
1781
1781
  return e && t !== void 0 && t.trim() !== "" ? t.trim() : `${se()}`;
1782
1782
  }
1783
1783
  static buildExtraHeaders(e, t) {
1784
- const s = e !== void 0 && e !== "" ? pe(e) : [];
1784
+ const s = e !== void 0 && e !== "" ? me(e) : [];
1785
1785
  return t === void 0 ? s : [...s, ...t];
1786
1786
  }
1787
1787
  createConfiguration({
@@ -1811,7 +1811,7 @@ class m {
1811
1811
  password: t,
1812
1812
  register: a,
1813
1813
  uri: I,
1814
- display_name: x(i),
1814
+ display_name: B(i),
1815
1815
  user_agent: S,
1816
1816
  sdpSemantics: "unified-plan",
1817
1817
  sockets: [C],
@@ -1845,7 +1845,7 @@ class m {
1845
1845
  }), { ua: r, helpers: i };
1846
1846
  }
1847
1847
  }
1848
- class me {
1848
+ class Pe {
1849
1849
  events;
1850
1850
  ua;
1851
1851
  socket;
@@ -1857,15 +1857,15 @@ class me {
1857
1857
  configurationManager;
1858
1858
  JsSIP;
1859
1859
  constructor({ JsSIP: e }) {
1860
- this.JsSIP = e, this.events = new O(Q), this.uaFactory = new m(e), this.registrationManager = new Re({
1860
+ this.JsSIP = e, this.events = new O(Q), this.uaFactory = new m(e), this.registrationManager = new Me({
1861
1861
  events: this.events,
1862
1862
  getUaProtected: this.getUaProtected
1863
- }), this.stateMachine = new Ie(this.events), this.configurationManager = new Ne({
1863
+ }), this.stateMachine = new Re(this.events), this.configurationManager = new ue({
1864
1864
  getUa: this.getUa
1865
- }), this.sipOperations = new Me({
1865
+ }), this.sipOperations = new pe({
1866
1866
  uaFactory: this.uaFactory,
1867
1867
  getUaProtected: this.getUaProtected
1868
- }), this.connectionFlow = new Ae({
1868
+ }), this.connectionFlow = new _e({
1869
1869
  JsSIP: this.JsSIP,
1870
1870
  events: this.events,
1871
1871
  uaFactory: this.uaFactory,
@@ -1962,8 +1962,8 @@ const J = [
1962
1962
  "declinedIncomingCall",
1963
1963
  "terminatedIncomingCall",
1964
1964
  "failedIncomingCall"
1965
- ], Pe = 486, Oe = 487;
1966
- class fe {
1965
+ ], Oe = 486, fe = 487;
1966
+ class De {
1967
1967
  events;
1968
1968
  incomingRTCSession;
1969
1969
  connectionManager;
@@ -1998,7 +1998,7 @@ class fe {
1998
1998
  return this.removeIncomingSession(), e;
1999
1999
  };
2000
2000
  async declineToIncomingCall({
2001
- statusCode: e = Oe
2001
+ statusCode: e = fe
2002
2002
  } = {}) {
2003
2003
  return new Promise((t, s) => {
2004
2004
  try {
@@ -2010,7 +2010,7 @@ class fe {
2010
2010
  });
2011
2011
  }
2012
2012
  async busyIncomingCall() {
2013
- return this.declineToIncomingCall({ statusCode: Pe });
2013
+ return this.declineToIncomingCall({ statusCode: Oe });
2014
2014
  }
2015
2015
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2016
2016
  on(e, t) {
@@ -2054,14 +2054,14 @@ class fe {
2054
2054
  delete this.incomingRTCSession;
2055
2055
  }
2056
2056
  }
2057
- const De = Q.map((n) => `connection:${n}`), ve = B.map((n) => `call:${n}`), ye = Y.map((n) => `api:${n}`), Ue = J.map((n) => `incoming-call:${n}`), be = q.map((n) => `presentation:${n}`), we = [
2058
- ...De,
2057
+ const ve = Q.map((n) => `connection:${n}`), ye = G.map((n) => `call:${n}`), Ue = q.map((n) => `api:${n}`), be = J.map((n) => `incoming-call:${n}`), we = Y.map((n) => `presentation:${n}`), Le = [
2059
2058
  ...ve,
2060
2059
  ...ye,
2061
2060
  ...Ue,
2062
- ...be
2061
+ ...be,
2062
+ ...we
2063
2063
  ];
2064
- class Be {
2064
+ class xe {
2065
2065
  events;
2066
2066
  connectionManager;
2067
2067
  callManager;
@@ -2069,10 +2069,10 @@ class Be {
2069
2069
  incomingCallManager;
2070
2070
  presentationManager;
2071
2071
  constructor({ JsSIP: e }) {
2072
- this.events = new O(we), this.connectionManager = new me({ JsSIP: e }), this.callManager = new ge(), this.apiManager = new Ce({
2072
+ this.events = new O(Le), this.connectionManager = new Pe({ JsSIP: e }), this.callManager = new ge(), this.apiManager = new Se({
2073
2073
  connectionManager: this.connectionManager,
2074
2074
  callManager: this.callManager
2075
- }), this.incomingCallManager = new fe(this.connectionManager), this.presentationManager = new Te({
2075
+ }), this.incomingCallManager = new De(this.connectionManager), this.presentationManager = new Ne({
2076
2076
  callManager: this.callManager
2077
2077
  }), this.subscribe();
2078
2078
  }
@@ -2255,11 +2255,13 @@ class Be {
2255
2255
  }
2256
2256
  }
2257
2257
  export {
2258
- H as E,
2258
+ x as E,
2259
2259
  U as O,
2260
- Be as S,
2261
- He as d,
2262
- Ve as e,
2263
- Ge as h,
2260
+ xe as S,
2261
+ f as a,
2262
+ Ee as b,
2263
+ Ge as d,
2264
+ He as e,
2265
+ Be as h,
2264
2266
  P as l
2265
2267
  };