@16x/webphone-sdk 3.0.1 → 3.1.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 (40) hide show
  1. package/CHANGELOG.md +39 -22
  2. package/LICENSE +1 -2
  3. package/README.md +113 -113
  4. package/dist/{CCBarClient-BdbynNBi.js → CCBarClient-CcPfEToZ.js} +431 -179
  5. package/dist/CCBarClient-DCQ8XjcL.cjs +1 -0
  6. package/dist/{Diagnostics-BYVvmxil.cjs → Diagnostics-D38Hm3NT.cjs} +1 -1
  7. package/dist/{Diagnostics-Cw2HVrCD.js → Diagnostics-Di049OpT.js} +9 -9
  8. package/dist/JsSipAdapter-BBRrDaM4.cjs +1 -0
  9. package/dist/{JsSipAdapter-GHzVSCDh.js → JsSipAdapter-Bke1Qjfe.js} +37 -25
  10. package/dist/SharedWorkerProtocol-39dch6xL.cjs +1 -0
  11. package/dist/{SharedWorkerProtocol-BqUafs8d.js → SharedWorkerProtocol-DKVQ5-po.js} +31 -17
  12. package/dist/core/CCBarClient.d.ts +36 -4
  13. package/dist/core/CallManager.d.ts +2 -0
  14. package/dist/{createJsSipFactory-yttVU3d6.js → createJsSipFactory-9CPsweDR.js} +4 -1
  15. package/dist/{createJsSipFactory-2X4FBIU2.cjs → createJsSipFactory-Dr8HbLl-.cjs} +1 -1
  16. package/dist/diagnostics/Diagnostics.d.ts +1 -0
  17. package/dist/diagnostics/index.cjs +1 -1
  18. package/dist/diagnostics/index.d.ts +1 -1
  19. package/dist/diagnostics/index.js +3 -6
  20. package/dist/errors/CCBarError.d.ts +6 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +9 -139
  23. package/dist/index.umd.js +17 -17
  24. package/dist/legacy/index.cjs +1 -1
  25. package/dist/legacy/index.js +2 -2
  26. package/dist/shared/SharedWorkerProtocol.d.ts +2 -0
  27. package/dist/shared-worker.cjs +1 -1
  28. package/dist/shared-worker.js +13 -6
  29. package/dist/styles.css +7 -7
  30. package/dist/types.d.ts +5 -0
  31. package/dist/ui/XCallCCBarElement.d.ts +2 -0
  32. package/dist/ui/index.cjs +1 -1
  33. package/dist/ui/index.js +138 -130
  34. package/dist/version.d.ts +1 -0
  35. package/package.json +111 -107
  36. package/dist/CCBarClient-DKWdvgf5.cjs +0 -1
  37. package/dist/CCBarError-CIqJE8zK.cjs +0 -1
  38. package/dist/CCBarError-DSbPw2dA.js +0 -14
  39. package/dist/JsSipAdapter-jtGdoXrm.cjs +0 -1
  40. package/dist/SharedWorkerProtocol-CYN0AprP.cjs +0 -1
@@ -1,7 +1,7 @@
1
- import { t as e } from "./CCBarError-DSbPw2dA.js";
2
- import { t } from "./Diagnostics-Cw2HVrCD.js";
1
+ import { i as e, t } from "./SharedWorkerProtocol-DKVQ5-po.js";
2
+ import { r as n, t as r } from "./Diagnostics-Di049OpT.js";
3
3
  //#region src/events/TypedEventBus.ts
4
- var n = class {
4
+ var i = class {
5
5
  handlers = /* @__PURE__ */ new Map();
6
6
  on(e, t) {
7
7
  let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set();
@@ -27,7 +27,7 @@ var n = class {
27
27
  clear() {
28
28
  this.handlers.clear();
29
29
  }
30
- }, r = {
30
+ }, a = {
31
31
  new: /* @__PURE__ */ new Set([
32
32
  "dialing",
33
33
  "ringing",
@@ -61,19 +61,19 @@ var n = class {
61
61
  ]),
62
62
  ended: /* @__PURE__ */ new Set(),
63
63
  failed: /* @__PURE__ */ new Set()
64
- }, i = (e, t) => r[e].has(t);
65
- function a(e, t) {
66
- if (!i(e, t)) throw new o(e, t);
64
+ }, o = (e, t) => a[e].has(t);
65
+ function s(e, t) {
66
+ if (!o(e, t)) throw new c(e, t);
67
67
  return t;
68
68
  }
69
- var o = class extends e {
69
+ var c = class extends e {
70
70
  constructor(e, t) {
71
71
  super("CALL_OPERATION_NOT_ALLOWED", "call", !1, { cause: {
72
72
  from: e,
73
73
  to: t
74
74
  } });
75
75
  }
76
- }, s = a, c = 60, l = class {
76
+ }, l = s, u = 60, d = class {
77
77
  tokenProvider;
78
78
  cachedToken;
79
79
  cachedRequestKey = "";
@@ -95,7 +95,7 @@ var o = class extends e {
95
95
  this.generation += 1, this.cachedToken = void 0, this.cachedRequestKey = "", this.refreshing = void 0;
96
96
  }
97
97
  needsRefresh(e) {
98
- return e.expiresAt !== void 0 && e.expiresAt <= Math.floor(Date.now() / 1e3) + c;
98
+ return e.expiresAt !== void 0 && e.expiresAt <= Math.floor(Date.now() / 1e3) + u;
99
99
  }
100
100
  async refresh(e, t, n) {
101
101
  let r = await this.tokenProvider(e), i = typeof r == "string" ? { accessToken: r } : r;
@@ -104,7 +104,7 @@ var o = class extends e {
104
104
  clearRefresh(e) {
105
105
  this.refreshing === e && (this.refreshing = void 0);
106
106
  }
107
- }, u = {
107
+ }, f = {
108
108
  ORIGIN_NOT_ALLOWED: {
109
109
  code: "CONFIG_ORIGIN_NOT_ALLOWED",
110
110
  category: "configuration",
@@ -145,6 +145,11 @@ var o = class extends e {
145
145
  category: "call",
146
146
  retryable: !1
147
147
  },
148
+ SESSION_EXPIRED: {
149
+ code: "CALL_NOT_CONNECTED",
150
+ category: "call",
151
+ retryable: !1
152
+ },
148
153
  SEAT_IN_USE: {
149
154
  code: "CALL_ALREADY_EXISTS",
150
155
  category: "call",
@@ -185,13 +190,13 @@ var o = class extends e {
185
190
  category: "internal",
186
191
  retryable: !0
187
192
  }
188
- }, d = class {
193
+ }, p = class {
189
194
  tokenManager;
190
195
  fetcher;
191
196
  baseUrl;
192
197
  timeoutMs;
193
198
  constructor(e) {
194
- this.tokenManager = new l(e.tokenProvider), this.fetcher = e.fetcher ?? fetch.bind(globalThis), this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.timeoutMs = e.timeoutMs ?? 1e4;
199
+ this.tokenManager = new d(e.tokenProvider), this.fetcher = e.fetcher ?? fetch.bind(globalThis), this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.timeoutMs = e.timeoutMs ?? 1e4;
195
200
  }
196
201
  invalidateToken() {
197
202
  this.tokenManager.invalidate();
@@ -220,6 +225,7 @@ var o = class extends e {
220
225
  try {
221
226
  let e = await this.tokenManager.getValidToken(), a = await this.fetcher(`${this.baseUrl}${n}`, {
222
227
  method: t,
228
+ credentials: "omit",
223
229
  headers: {
224
230
  Authorization: `Bearer ${e}`,
225
231
  ...r === void 0 ? {} : { "Content-Type": "application/json" }
@@ -250,8 +256,12 @@ var o = class extends e {
250
256
  }
251
257
  }
252
258
  toCCBarError(t, n) {
253
- let r = u[n.code ?? ""] ?? this.mapStatus(t);
254
- return new e(r.code, r.category, r.retryable, { requestId: n.requestId });
259
+ let r = f[n.code ?? ""] ?? this.mapStatus(t);
260
+ return new e(r.code, r.category, r.retryable, {
261
+ requestId: n.requestId,
262
+ serverCode: n.code,
263
+ status: t
264
+ });
255
265
  }
256
266
  mapStatus(e) {
257
267
  return e === 401 ? {
@@ -272,7 +282,7 @@ var o = class extends e {
272
282
  retryable: !1
273
283
  };
274
284
  }
275
- }, f = [
285
+ }, m = [
276
286
  "progress",
277
287
  "accepted",
278
288
  "confirmed",
@@ -280,7 +290,7 @@ var o = class extends e {
280
290
  "failed",
281
291
  "hold",
282
292
  "unhold"
283
- ], p = 3e4, m = class {
293
+ ], h = 3e4, g = class {
284
294
  options;
285
295
  currentState = "new";
286
296
  sessionUnsubscribers = [];
@@ -296,7 +306,7 @@ var o = class extends e {
296
306
  constructor(t) {
297
307
  this.options = t, this.id = t.id, this.destination = t.destination, this.platform = t.platform, this.capabilities = t.capabilities ?? /* @__PURE__ */ new Set();
298
308
  try {
299
- f.forEach((e) => {
309
+ m.forEach((e) => {
300
310
  this.sessionUnsubscribers.push(t.session.on(e, (t) => this.handleSessionEvent(e, t)));
301
311
  });
302
312
  } catch (n) {
@@ -357,11 +367,11 @@ var o = class extends e {
357
367
  this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
358
368
  }
359
369
  async transfer(e, t) {
360
- if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !g(e) || e.target.trim() === "") throw this.operationError();
370
+ if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !v(e) || e.target.trim() === "") throw this.operationError();
361
371
  this.invoke(() => this.options.session.refer(e.target.trim()));
362
372
  }
363
373
  async hangup(e) {
364
- if (this.assertNotDisposed(), this.assertOwner(e), h(this.currentState)) throw this.operationError();
374
+ if (this.assertNotDisposed(), this.assertOwner(e), _(this.currentState)) throw this.operationError();
365
375
  try {
366
376
  this.options.session.terminate(), this.transitionTo("ended");
367
377
  } catch (e) {
@@ -391,7 +401,7 @@ var o = class extends e {
391
401
  }
392
402
  dispose() {
393
403
  if (!this.disposed) {
394
- if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !h(this.currentState)) try {
404
+ if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !_(this.currentState)) try {
395
405
  this.options.session.terminate();
396
406
  } catch (e) {
397
407
  this.reportOperationError(e);
@@ -403,7 +413,7 @@ var o = class extends e {
403
413
  }
404
414
  }
405
415
  handleSessionEvent(e, t) {
406
- if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || h(this.currentState))) switch (e) {
416
+ if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || _(this.currentState))) switch (e) {
407
417
  case "progress":
408
418
  this.transitionIfAllowed("ringing", t, e);
409
419
  break;
@@ -429,16 +439,16 @@ var o = class extends e {
429
439
  this.currentState !== "active" && ((this.currentState === "dialing" || this.currentState === "ringing") && this.transitionTo("connecting", e), this.transitionIfAllowed("active", e, "confirmed"));
430
440
  }
431
441
  transitionIfAllowed(e, t, n) {
432
- this.currentState !== e && (i(this.currentState, e) ? this.transitionTo(e, t) : this.reportIllegalTransition(e, n));
442
+ this.currentState !== e && (o(this.currentState, e) ? this.transitionTo(e, t) : this.reportIllegalTransition(e, n));
433
443
  }
434
444
  transitionIfStillRinging(e, t) {
435
445
  this.currentState === "ringing" && this.transitionTo(e, t);
436
446
  }
437
447
  transitionTo(e, t) {
438
448
  if (this.currentState === e) return;
439
- if (!i(this.currentState, e)) throw this.operationError();
449
+ if (!o(this.currentState, e)) throw this.operationError();
440
450
  let n = this.currentState;
441
- this.currentState = e, h(e) && this.rejectPendingOperation();
451
+ this.currentState = e, _(e) && this.rejectPendingOperation();
442
452
  try {
443
453
  this.options.onStateChanged?.({
444
454
  callId: this.id,
@@ -446,7 +456,7 @@ var o = class extends e {
446
456
  to: e
447
457
  }, t);
448
458
  } catch {} finally {
449
- h(e) && this.dispose();
459
+ _(e) && this.dispose();
450
460
  }
451
461
  }
452
462
  startPendingOperation(e, t, n) {
@@ -458,7 +468,7 @@ var o = class extends e {
458
468
  resolve: r,
459
469
  reject: i
460
470
  };
461
- this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), p);
471
+ this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), h);
462
472
  let o;
463
473
  try {
464
474
  o = n();
@@ -471,7 +481,7 @@ var o = class extends e {
471
481
  }
472
482
  resolvePendingOperation(e) {
473
483
  if (this.pendingOperation === e) {
474
- if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || h(this.currentState)) {
484
+ if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || _(this.currentState)) {
475
485
  e.reject(this.operationError());
476
486
  return;
477
487
  }
@@ -570,22 +580,22 @@ var o = class extends e {
570
580
  });
571
581
  }
572
582
  };
573
- function h(e) {
583
+ function _(e) {
574
584
  return e === "ended" || e === "failed";
575
585
  }
576
- function g(e) {
586
+ function v(e) {
577
587
  return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
578
588
  }
579
589
  //#endregion
580
590
  //#region src/core/callId.ts
581
- var _ = 0;
582
- function v() {
583
- return _ += 1, `call_${Date.now().toString(36)}_${_.toString(36)}`;
591
+ var y = 0;
592
+ function b() {
593
+ return y += 1, `call_${Date.now().toString(36)}_${y.toString(36)}`;
584
594
  }
585
595
  //#endregion
586
596
  //#region src/core/CallManager.ts
587
- var y = class {
588
- events = new b();
597
+ var x = class {
598
+ events = new ee();
589
599
  calls = /* @__PURE__ */ new Map();
590
600
  options;
591
601
  incomingUnsubscribe;
@@ -623,7 +633,7 @@ var y = class {
623
633
  if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= a) throw this.capabilityError();
624
634
  if (this.calls.size + this.pendingDialCount >= a || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new e("CALL_ALREADY_EXISTS", "call", !1);
625
635
  this.pendingDialCount += 1, this.pendingDestinations.add(i);
626
- let o = v(), s;
636
+ let o = b(), s;
627
637
  try {
628
638
  s = await this.holdActiveCallForNewCall(), this.assertGeneration(r, o);
629
639
  let e;
@@ -635,7 +645,7 @@ var y = class {
635
645
  this.assertGeneration(r, o);
636
646
  let a;
637
647
  try {
638
- a = new m({
648
+ a = new g({
639
649
  id: o,
640
650
  destination: i,
641
651
  platform: this.options.platform,
@@ -695,7 +705,8 @@ var y = class {
695
705
  let e = [...this.calls.values()].map((e) => e.getResourceCounts());
696
706
  return {
697
707
  timers: e.reduce((e, t) => e + t.timers, 0),
698
- listeners: this.events.listenerCount() + e.reduce((e, t) => e + t.listeners, 0)
708
+ listeners: this.events.listenerCount() + e.reduce((e, t) => e + t.listeners, 0),
709
+ terminalRecords: this.terminalNotified.size + this.terminalOperations.size
699
710
  };
700
711
  }
701
712
  getActiveCall() {
@@ -770,7 +781,9 @@ var y = class {
770
781
  n ??= e;
771
782
  }
772
783
  if (n !== void 0) throw n;
773
- })).then(() => void 0);
784
+ })).finally(() => {
785
+ this.terminalNotified.clear(), this.terminalOperations.clear();
786
+ }).then(() => void 0);
774
787
  return this.disposeOperation = n, n;
775
788
  }
776
789
  updateSession(e) {
@@ -814,10 +827,10 @@ var y = class {
814
827
  }
815
828
  t.to === "held" && this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), (t.to === "ended" || t.to === "failed") && (this.calls.delete(e.id), this.callSessions.delete(e.id), this.callOwners.delete(e.id), this.ownerLostCalls.delete(e.id), this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), this.notifyCallTerminal(e.id), t.to === "ended" ? this.events.emit("call.ended", {
816
829
  callId: e.id,
817
- reason: x(n)
830
+ reason: te(n)
818
831
  }) : this.events.emit("call.failed", {
819
832
  callId: e.id,
820
- error: S(n, e.id)
833
+ error: ne(n, e.id)
821
834
  }));
822
835
  }
823
836
  async switchAutomaticActiveCall(e, t, n) {
@@ -883,7 +896,7 @@ var y = class {
883
896
  }
884
897
  handleIncoming(t) {
885
898
  if (this.disposed) return;
886
- let n = v();
899
+ let n = b();
887
900
  if (this.options.platform === "mobile-web") {
888
901
  this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
889
902
  return;
@@ -900,7 +913,7 @@ var y = class {
900
913
  }
901
914
  let a;
902
915
  try {
903
- a = new m({
916
+ a = new g({
904
917
  id: n,
905
918
  destination: i,
906
919
  platform: this.options.platform,
@@ -974,12 +987,15 @@ var y = class {
974
987
  } catch (t) {
975
988
  this.events.emit("error", { error: this.callOperationError(e, t) });
976
989
  let n = Promise.reject(this.callOperationError(e, t));
977
- return this.terminalOperations.set(e, n), n.catch(() => void 0), n;
990
+ return this.terminalOperations.set(e, n), n.catch(() => void 0).finally(() => this.pruneTerminalRecord(e, n)), n;
978
991
  }
979
992
  let r = Promise.resolve(n).catch((t) => {
980
993
  throw this.events.emit("error", { error: this.callOperationError(e, t) }), t;
981
994
  });
982
- return this.terminalOperations.set(e, r), r.catch(() => void 0), r;
995
+ return this.terminalOperations.set(e, r), r.catch(() => void 0).finally(() => this.pruneTerminalRecord(e, r)), r;
996
+ }
997
+ pruneTerminalRecord(e, t) {
998
+ this.terminalOperations.get(e) === t && this.terminalOperations.delete(e), this.calls.has(e) || this.terminalNotified.delete(e);
983
999
  }
984
1000
  assertNotDisposed() {
985
1001
  if (this.disposed) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
@@ -1022,7 +1038,7 @@ var y = class {
1022
1038
  cause: t
1023
1039
  });
1024
1040
  }
1025
- }, b = class {
1041
+ }, ee = class {
1026
1042
  handlers = /* @__PURE__ */ new Map();
1027
1043
  on(e, t) {
1028
1044
  let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
@@ -1047,12 +1063,12 @@ var y = class {
1047
1063
  this.handlers.clear();
1048
1064
  }
1049
1065
  };
1050
- function x(e) {
1066
+ function te(e) {
1051
1067
  if (typeof e != "object" || !e || !("reason" in e)) return "ended";
1052
1068
  let t = e.reason;
1053
1069
  return typeof t == "string" && t !== "" ? t : "ended";
1054
1070
  }
1055
- function S(t, n) {
1071
+ function ne(t, n) {
1056
1072
  if (t instanceof e) return new e(t.code, t.category, t.retryable, {
1057
1073
  requestId: t.requestId,
1058
1074
  callId: n,
@@ -1076,8 +1092,141 @@ function S(t, n) {
1076
1092
  });
1077
1093
  }
1078
1094
  //#endregion
1095
+ //#region src/shared/SharedWorkerClient.ts
1096
+ var S = class {
1097
+ port;
1098
+ timeoutMs;
1099
+ pending = /* @__PURE__ */ new Map();
1100
+ eventHandlers = /* @__PURE__ */ new Set();
1101
+ closed = !1;
1102
+ lifecycleState = "connected";
1103
+ constructor(e, t = {}) {
1104
+ this.port = e, this.timeoutMs = t.timeoutMs ?? 15e3, this.port.onmessage = (e) => this.handleMessage(e.data), this.port.start();
1105
+ }
1106
+ request(t) {
1107
+ return this.closed ? Promise.reject(new e("SDK_ALREADY_DISPOSED", "internal", !1)) : this.pending.has(t.requestId) ? Promise.reject(new e("SDK_INTERNAL_ERROR", "internal", !1, { requestId: t.requestId })) : this.lifecycleState === "reconnecting" && t.type === "command" && (t.command === "dial" || t.command === "answer") ? Promise.reject(new e("CALL_OPERATION_NOT_ALLOWED", "call", !0, { callId: t.payload?.callId })) : new Promise((n, r) => {
1108
+ let i = setTimeout(() => {
1109
+ this.pending.delete(t.requestId), r(new e("NETWORK_TIMEOUT", "network", !0, { requestId: t.requestId }));
1110
+ }, this.timeoutMs);
1111
+ this.pending.set(t.requestId, {
1112
+ resolve: (e) => n(e),
1113
+ reject: r,
1114
+ timer: i
1115
+ }), this.port.postMessage(t);
1116
+ });
1117
+ }
1118
+ onEvent(e) {
1119
+ return this.closed ? () => void 0 : (this.eventHandlers.add(e), () => this.eventHandlers.delete(e));
1120
+ }
1121
+ getLifecycleState() {
1122
+ return this.lifecycleState;
1123
+ }
1124
+ close() {
1125
+ this.closed || (this.closed = !0, this.pending.forEach((t) => {
1126
+ clearTimeout(t.timer), t.reject(new e("SDK_ALREADY_DISPOSED", "internal", !1));
1127
+ }), this.pending.clear(), this.eventHandlers.clear(), this.port.close());
1128
+ }
1129
+ handleMessage(e) {
1130
+ try {
1131
+ let n = t(e);
1132
+ if (n.type === "event") {
1133
+ n.event === "connection.stateChanged" && re(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
1134
+ return;
1135
+ }
1136
+ if (n.type !== "response") return;
1137
+ let r = this.pending.get(n.requestId);
1138
+ if (r === void 0) return;
1139
+ this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(C(n));
1140
+ } catch (e) {
1141
+ this.pending.forEach((t) => {
1142
+ clearTimeout(t.timer), t.reject(e);
1143
+ }), this.pending.clear();
1144
+ }
1145
+ }
1146
+ };
1147
+ function re(e) {
1148
+ return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1149
+ }
1150
+ function C(t) {
1151
+ let n = t.error;
1152
+ return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1153
+ requestId: t.requestId,
1154
+ ...n?.message === void 0 ? {} : { cause: n.message },
1155
+ ...n?.serverCode === void 0 ? {} : { serverCode: n.serverCode },
1156
+ ...n?.status === void 0 ? {} : { status: n.status }
1157
+ });
1158
+ }
1159
+ //#endregion
1160
+ //#region src/shared/SharedWorkerFactory.ts
1161
+ function w(t = {}) {
1162
+ if ((t.enabled ?? "auto") === !1) return {
1163
+ mode: "single-tab",
1164
+ reason: "disabled"
1165
+ };
1166
+ let n = t.locationHref ?? E(), r = T(t.url, n), i = (n) => {
1167
+ if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
1168
+ return {
1169
+ mode: "single-tab",
1170
+ reason: n
1171
+ };
1172
+ };
1173
+ if (r === void 0) return i("SharedWorker URL is unavailable");
1174
+ if (!O(r, n)) return i("SharedWorker URL must be same-origin");
1175
+ let a = t.workerCtor ?? D();
1176
+ if (a === void 0) return i("SharedWorker is not supported");
1177
+ let o;
1178
+ try {
1179
+ o = new a(r, t.name === void 0 ? void 0 : { name: t.name });
1180
+ } catch (e) {
1181
+ return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1182
+ }
1183
+ let s = t.tabId ?? ie(), c = new S(o.port), l = {
1184
+ version: 1,
1185
+ type: "attach",
1186
+ requestId: ae(),
1187
+ tabId: s
1188
+ }, u = c.request(l).then(() => void 0).catch((e) => {
1189
+ throw c.close(), e;
1190
+ });
1191
+ return {
1192
+ mode: "shared",
1193
+ worker: o,
1194
+ client: c,
1195
+ tabId: s,
1196
+ workerUrl: r,
1197
+ ready: u
1198
+ };
1199
+ }
1200
+ function T(e, t = E()) {
1201
+ try {
1202
+ return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
1203
+ } catch {
1204
+ return;
1205
+ }
1206
+ }
1207
+ function E() {
1208
+ return typeof location > "u" ? void 0 : location.href;
1209
+ }
1210
+ function D() {
1211
+ if (typeof SharedWorker == "function") return SharedWorker;
1212
+ }
1213
+ function O(e, t) {
1214
+ if (t === void 0) return !0;
1215
+ try {
1216
+ return new URL(e, t).origin === new URL(t).origin;
1217
+ } catch {
1218
+ return !1;
1219
+ }
1220
+ }
1221
+ function ie() {
1222
+ return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1223
+ }
1224
+ function ae() {
1225
+ return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1226
+ }
1227
+ //#endregion
1079
1228
  //#region src/media/DeviceManager.ts
1080
- var C = class {
1229
+ var oe = class {
1081
1230
  mediaDevices;
1082
1231
  createAudioElement;
1083
1232
  outputCapability;
@@ -1085,23 +1234,23 @@ var C = class {
1085
1234
  outputGeneration = 0;
1086
1235
  outputTail;
1087
1236
  constructor(e = {}) {
1088
- this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? w(), this.createAudioElement = e.createAudioElement;
1237
+ this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? k(), this.createAudioElement = e.createAudioElement;
1089
1238
  }
1090
1239
  async requestPermission(e = {}) {
1091
1240
  let t = this.requireMediaDevices(), n;
1092
1241
  try {
1093
1242
  n = await t.getUserMedia({ audio: e });
1094
1243
  } catch (e) {
1095
- throw E(e);
1244
+ throw M(e);
1096
1245
  }
1097
- T(n);
1246
+ A(n);
1098
1247
  }
1099
1248
  async getDevices() {
1100
1249
  if (this.mediaDevices === void 0) return [];
1101
1250
  try {
1102
1251
  return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
1103
1252
  } catch (e) {
1104
- throw te(e);
1253
+ throw N(e);
1105
1254
  }
1106
1255
  }
1107
1256
  getCapabilities() {
@@ -1139,7 +1288,7 @@ var C = class {
1139
1288
  try {
1140
1289
  await r.setSinkId(t);
1141
1290
  } catch (e) {
1142
- throw ne(e);
1291
+ throw P(e);
1143
1292
  }
1144
1293
  }
1145
1294
  enqueueOutput(e) {
@@ -1153,7 +1302,7 @@ var C = class {
1153
1302
  try {
1154
1303
  return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
1155
1304
  } catch (e) {
1156
- throw ee(e);
1305
+ throw j(e);
1157
1306
  }
1158
1307
  }
1159
1308
  requireMediaDevices() {
@@ -1173,10 +1322,10 @@ var C = class {
1173
1322
  }
1174
1323
  }
1175
1324
  };
1176
- function w() {
1325
+ function k() {
1177
1326
  return globalThis.navigator?.mediaDevices;
1178
1327
  }
1179
- function T(e) {
1328
+ function A(e) {
1180
1329
  let t;
1181
1330
  try {
1182
1331
  t = e.getTracks();
@@ -1189,57 +1338,57 @@ function T(e) {
1189
1338
  } catch {}
1190
1339
  });
1191
1340
  }
1192
- function ee(t) {
1193
- let n = D(t);
1341
+ function j(t) {
1342
+ let n = F(t);
1194
1343
  return n === "NotFoundError" || n === "OverconstrainedError" ? new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: t }) : n === "NotReadableError" || n === "AbortError" ? new e("MEDIA_DEVICE_IN_USE", "media", !0, { cause: t }) : n === "NotAllowedError" || n === "SecurityError" ? new e("MEDIA_PERMISSION_DENIED", "media", !1, { cause: t }) : new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
1195
1344
  }
1196
- function E(t) {
1197
- let n = D(t);
1345
+ function M(t) {
1346
+ let n = F(t);
1198
1347
  return n === "NotFoundError" || n === "OverconstrainedError" ? new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: t }) : n === "NotReadableError" || n === "AbortError" ? new e("MEDIA_DEVICE_IN_USE", "media", !0, { cause: t }) : n === "NotAllowedError" || n === "SecurityError" ? new e("MEDIA_PERMISSION_DENIED", "media", !1, { cause: t }) : new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
1199
1348
  }
1200
- function te(t) {
1201
- let n = D(t);
1349
+ function N(t) {
1350
+ let n = F(t);
1202
1351
  return n === "NotFoundError" ? new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: t }) : n === "NotAllowedError" || n === "SecurityError" ? new e("MEDIA_PERMISSION_DENIED", "media", !1, { cause: t }) : n === "AbortError" || n === "NotReadableError" ? new e("MEDIA_DEVICE_IN_USE", "media", !0, { cause: t }) : new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
1203
1352
  }
1204
- function ne(t) {
1205
- let n = D(t);
1353
+ function P(t) {
1354
+ let n = F(t);
1206
1355
  return n === "NotFoundError" ? new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: t }) : n === "NotAllowedError" || n === "SecurityError" ? new e("MEDIA_PERMISSION_DENIED", "media", !1, { cause: t }) : n === "AbortError" || n === "NotReadableError" ? new e("MEDIA_DEVICE_IN_USE", "media", !0, { cause: t }) : new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
1207
1356
  }
1208
- function D(e) {
1357
+ function F(e) {
1209
1358
  if (typeof e != "object" || !e || !("name" in e)) return;
1210
1359
  let t = e.name;
1211
1360
  return typeof t == "string" ? t : void 0;
1212
1361
  }
1213
1362
  //#endregion
1214
1363
  //#region src/media/RemoteAudio.ts
1215
- var O = class {
1364
+ var I = class {
1216
1365
  createAudioElement;
1217
1366
  bindings = /* @__PURE__ */ new Map();
1218
1367
  audioOwners = /* @__PURE__ */ new Map();
1219
1368
  trackOwners = /* @__PURE__ */ new Map();
1220
1369
  generations = /* @__PURE__ */ new Map();
1221
1370
  pendingPlays = /* @__PURE__ */ new Map();
1222
- constructor(e = k) {
1371
+ constructor(e = L) {
1223
1372
  this.createAudioElement = e;
1224
1373
  }
1225
1374
  async bind(t, n) {
1226
1375
  let r = this.bindings.get(t);
1227
1376
  if (r?.stream === n) return;
1228
- let i = A(t, n), a;
1377
+ let i = R(t, n), a;
1229
1378
  try {
1230
1379
  a = this.createAudioElement();
1231
1380
  } catch (n) {
1232
- throw j(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1381
+ throw z(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1233
1382
  callId: t,
1234
1383
  cause: n
1235
1384
  });
1236
1385
  }
1237
1386
  let o = this.audioOwners.get(a);
1238
- if (o !== void 0 && o !== t) throw j(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1387
+ if (o !== void 0 && o !== t) throw z(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1239
1388
  try {
1240
1389
  a.autoplay = !0, a.playsInline = !0;
1241
1390
  } catch (n) {
1242
- throw j(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1391
+ throw z(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1243
1392
  callId: t,
1244
1393
  cause: n
1245
1394
  });
@@ -1247,7 +1396,7 @@ var O = class {
1247
1396
  try {
1248
1397
  a.srcObject = n;
1249
1398
  } catch (n) {
1250
- throw j(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1399
+ throw z(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1251
1400
  callId: t,
1252
1401
  cause: n
1253
1402
  });
@@ -1323,7 +1472,7 @@ var O = class {
1323
1472
  releaseTrack(e) {
1324
1473
  let t = this.trackOwners.get(e);
1325
1474
  if (t === void 0 || t <= 1) {
1326
- this.trackOwners.delete(e), N(e);
1475
+ this.trackOwners.delete(e), V(e);
1327
1476
  return;
1328
1477
  }
1329
1478
  this.trackOwners.set(e, t - 1);
@@ -1346,42 +1495,42 @@ var O = class {
1346
1495
  return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
1347
1496
  }
1348
1497
  };
1349
- function k() {
1498
+ function L() {
1350
1499
  if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1351
1500
  return document.createElement("audio");
1352
1501
  }
1353
- function A(t, n) {
1502
+ function R(t, n) {
1354
1503
  try {
1355
1504
  return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
1356
1505
  } catch (r) {
1357
1506
  try {
1358
1507
  return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
1359
1508
  } catch (i) {
1360
- throw M(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1509
+ throw B(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1361
1510
  callId: t,
1362
1511
  cause: r ?? i
1363
1512
  });
1364
1513
  }
1365
1514
  }
1366
1515
  }
1367
- function j(e, t) {
1516
+ function z(e, t) {
1368
1517
  e.forEach((e) => {
1369
- (t.get(e) ?? 0) === 0 && N(e);
1518
+ (t.get(e) ?? 0) === 0 && V(e);
1370
1519
  });
1371
1520
  }
1372
- function M(e) {
1521
+ function B(e) {
1373
1522
  try {
1374
- [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(N);
1523
+ [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
1375
1524
  } catch {}
1376
1525
  }
1377
- function N(e) {
1526
+ function V(e) {
1378
1527
  try {
1379
1528
  e.stop();
1380
1529
  } catch {}
1381
1530
  }
1382
1531
  //#endregion
1383
1532
  //#region src/media/MediaManager.ts
1384
- var P = class {
1533
+ var H = class {
1385
1534
  deviceManager;
1386
1535
  remoteAudio;
1387
1536
  getActiveCall;
@@ -1402,7 +1551,7 @@ var P = class {
1402
1551
  mediaDevices: e.mediaDevices,
1403
1552
  createAudioElement: e.createAudioElement
1404
1553
  };
1405
- this.deviceManager = new C(t), this.remoteAudio = new O(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? V;
1554
+ this.deviceManager = new oe(t), this.remoteAudio = new I(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? se;
1406
1555
  }
1407
1556
  requestPermission(e) {
1408
1557
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1422,7 +1571,7 @@ var P = class {
1422
1571
  n !== void 0 && this.releaseResource(n).catch((e) => {
1423
1572
  this.releaseErrors.set(n, e);
1424
1573
  });
1425
- let r = F(t) ? t : { peerConnection: t }, i = {
1574
+ let r = U(t) ? t : { peerConnection: t }, i = {
1426
1575
  callId: e,
1427
1576
  peerConnection: r.peerConnection,
1428
1577
  senders: /* @__PURE__ */ new Map(),
@@ -1504,7 +1653,7 @@ var P = class {
1504
1653
  this.remoteAudio.release(r), this.releaseErrors.delete(t), this.calls.get(r) === t && this.calls.delete(r), t.generation += 1, t.released = !0, this.unsubscribeTrackSource(t);
1505
1654
  let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
1506
1655
  senderResource: e,
1507
- promise: this.enqueueSender(t, e, () => L(e.sender), !0)
1656
+ promise: this.enqueueSender(t, e, () => G(e.sender), !0)
1508
1657
  })), o = Promise.all(a.map(async (e) => {
1509
1658
  try {
1510
1659
  return await e.promise, {
@@ -1522,14 +1671,14 @@ var P = class {
1522
1671
  if (n.forEach((e) => {
1523
1672
  if (e.cause !== void 0) {
1524
1673
  o.push(e.cause);
1525
- let t = I(e.senderResource.sender);
1674
+ let t = W(e.senderResource.sender);
1526
1675
  t?.kind === "audio" && a.add(t);
1527
1676
  return;
1528
1677
  }
1529
- let t = I(e.senderResource.sender);
1678
+ let t = W(e.senderResource.sender);
1530
1679
  t?.kind === "audio" && i.add(t);
1531
1680
  }), i.forEach((e) => {
1532
- a.has(e) || B(e);
1681
+ a.has(e) || J(e);
1533
1682
  }), o.length > 0) throw t.localTracks.clear(), t.pendingTracks.clear(), a.forEach((e) => t.localTracks.add(e)), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1534
1683
  callId: r,
1535
1684
  cause: o[0]
@@ -1537,7 +1686,7 @@ var P = class {
1537
1686
  if (!t.peerClosed && t.peerConnection.close !== void 0) try {
1538
1687
  await t.peerConnection.close(), t.peerClosed = !0;
1539
1688
  } catch (n) {
1540
- let i = [...t.senders.values()].map((e) => I(e.sender)).find((e) => e?.kind === "audio");
1689
+ let i = [...t.senders.values()].map((e) => W(e.sender)).find((e) => e?.kind === "audio");
1541
1690
  throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1542
1691
  callId: r,
1543
1692
  cause: n
@@ -1605,11 +1754,11 @@ var P = class {
1605
1754
  }
1606
1755
  async performInputSwitch(t, n, r) {
1607
1756
  if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
1608
- let i = this.findAudioSender(r), a = I(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1757
+ let i = this.findAudioSender(r), a = W(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1609
1758
  try {
1610
1759
  c = s.getTracks();
1611
1760
  } catch (t) {
1612
- throw R(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1761
+ throw K(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1613
1762
  callId: n.callId,
1614
1763
  cause: t
1615
1764
  });
@@ -1618,26 +1767,26 @@ var P = class {
1618
1767
  try {
1619
1768
  l = s.getAudioTracks();
1620
1769
  } catch (t) {
1621
- throw z(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1770
+ throw q(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1622
1771
  callId: n.callId,
1623
1772
  cause: t
1624
1773
  });
1625
1774
  }
1626
1775
  let u = l[0];
1627
- if (u === void 0) throw z(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1628
- if (!this.canCommitInputSwitch(n, r, i, a, o)) throw z(c), this.callOperationError(n.callId);
1776
+ if (u === void 0) throw q(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1777
+ if (!this.canCommitInputSwitch(n, r, i, a, o)) throw q(c), this.callOperationError(n.callId);
1629
1778
  c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
1630
1779
  try {
1631
1780
  await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
1632
1781
  } catch (t) {
1633
- throw r.released ? this.callOperationError(n.callId) : (r.released || (c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), await this.rollbackSender(r, i, a, u), z(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
1782
+ throw r.released ? this.callOperationError(n.callId) : (r.released || (c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), await this.rollbackSender(r, i, a, u), q(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
1634
1783
  callId: n.callId,
1635
1784
  cause: t
1636
1785
  }));
1637
1786
  }
1638
1787
  if (!this.canCommitInputSwitch(n, r, i, u, o)) {
1639
1788
  if (!r.released) try {
1640
- await this.enqueueSender(r, i, () => I(i.sender) === u ? L(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), z(c);
1789
+ await this.enqueueSender(r, i, () => W(i.sender) === u ? G(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), q(c);
1641
1790
  } catch (t) {
1642
1791
  throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
1643
1792
  callId: n.callId,
@@ -1646,8 +1795,8 @@ var P = class {
1646
1795
  }
1647
1796
  throw this.callOperationError(n.callId);
1648
1797
  }
1649
- c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), B(a)), c.forEach((e) => {
1650
- e !== u && B(e);
1798
+ c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), J(a)), c.forEach((e) => {
1799
+ e !== u && J(e);
1651
1800
  });
1652
1801
  }
1653
1802
  ensureCallMedia(e) {
@@ -1670,7 +1819,7 @@ var P = class {
1670
1819
  });
1671
1820
  }
1672
1821
  r.forEach((r) => {
1673
- let i = I(r), a;
1822
+ let i = W(r), a;
1674
1823
  try {
1675
1824
  a = n?.(r) ?? r.senderKind ?? r.kind;
1676
1825
  } catch (n) {
@@ -1687,7 +1836,7 @@ var P = class {
1687
1836
  });
1688
1837
  }
1689
1838
  findAudioSender(e) {
1690
- let t = [...e.senders.values()].find((e) => e.audio && (I(e.sender)?.kind === "audio" || I(e.sender) === null));
1839
+ let t = [...e.senders.values()].find((e) => e.audio && (W(e.sender)?.kind === "audio" || W(e.sender) === null));
1691
1840
  if (t === void 0) throw this.capabilityError(e.callId);
1692
1841
  return t;
1693
1842
  }
@@ -1703,7 +1852,7 @@ var P = class {
1703
1852
  } catch {
1704
1853
  return !1;
1705
1854
  }
1706
- return I(n.sender) === r;
1855
+ return W(n.sender) === r;
1707
1856
  }
1708
1857
  enqueueSender(e, t, n, r = !1) {
1709
1858
  t.queue.pending += 1;
@@ -1732,7 +1881,7 @@ var P = class {
1732
1881
  });
1733
1882
  }
1734
1883
  async rollbackSender(e, t, n, r) {
1735
- e.released || I(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1884
+ e.released || W(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1736
1885
  }
1737
1886
  isCurrentResource(e, t = e.generation) {
1738
1887
  return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
@@ -1759,37 +1908,37 @@ var P = class {
1759
1908
  if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1760
1909
  }
1761
1910
  };
1762
- function F(e) {
1911
+ function U(e) {
1763
1912
  return "peerConnection" in e;
1764
1913
  }
1765
- function I(e) {
1914
+ function W(e) {
1766
1915
  try {
1767
1916
  return e.track;
1768
1917
  } catch {
1769
1918
  return null;
1770
1919
  }
1771
1920
  }
1772
- function L(e) {
1921
+ function G(e) {
1773
1922
  try {
1774
1923
  return e.replaceTrack(null);
1775
1924
  } catch (e) {
1776
1925
  return Promise.reject(e);
1777
1926
  }
1778
1927
  }
1779
- function R(e) {
1928
+ function K(e) {
1780
1929
  try {
1781
- z(e.getTracks());
1930
+ q(e.getTracks());
1782
1931
  } catch {}
1783
1932
  }
1784
- function z(e) {
1785
- e.forEach(B);
1933
+ function q(e) {
1934
+ e.forEach(J);
1786
1935
  }
1787
- function B(e) {
1936
+ function J(e) {
1788
1937
  try {
1789
1938
  e.stop();
1790
1939
  } catch {}
1791
1940
  }
1792
- function V(e) {
1941
+ function se(e) {
1793
1942
  if (typeof MediaStream < "u") try {
1794
1943
  return new MediaStream([e]);
1795
1944
  } catch {
@@ -1798,8 +1947,8 @@ function V(e) {
1798
1947
  }
1799
1948
  //#endregion
1800
1949
  //#region src/core/mediaBridge.ts
1801
- function H(t, n = {}) {
1802
- let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = n.ownershipRequired === !0, s = !1, c = !1, l, u = () => t(), d = new P({ getActiveCall: u });
1950
+ function ce(t, n = {}) {
1951
+ let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = n.ownershipRequired === !0, s = !1, c = !1, l, u = () => t(), d = new H({ getActiveCall: u });
1803
1952
  return {
1804
1953
  publicMedia: {
1805
1954
  requestPermission: () => (f(), d.requestPermission()),
@@ -1812,7 +1961,7 @@ function H(t, n = {}) {
1812
1961
  releaseAll: () => (f(), d.releaseAll())
1813
1962
  },
1814
1963
  registerCall(e, t) {
1815
- s || c || !U(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1964
+ s || c || !Y(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1816
1965
  },
1817
1966
  async setCallOwnership(e, t) {
1818
1967
  if (s) return;
@@ -1855,9 +2004,9 @@ function H(t, n = {}) {
1855
2004
  if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1856
2005
  }
1857
2006
  function p(e, t) {
1858
- if (!U(t) || typeof t.getMediaRegistration != "function") return;
2007
+ if (!Y(t) || typeof t.getMediaRegistration != "function") return;
1859
2008
  let n = t.getMediaRegistration();
1860
- if (W(n) && r.get(e)?.peerConnection !== n.peerConnection) {
2009
+ if (le(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1861
2010
  r.set(e, n);
1862
2011
  try {
1863
2012
  d.registerCallMedia(e, n);
@@ -1867,22 +2016,22 @@ function H(t, n = {}) {
1867
2016
  }
1868
2017
  }
1869
2018
  }
1870
- function U(e) {
2019
+ function Y(e) {
1871
2020
  return typeof e == "object" && !!e;
1872
2021
  }
1873
- function W(e) {
2022
+ function le(e) {
1874
2023
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
1875
2024
  }
1876
2025
  //#endregion
1877
2026
  //#region src/reconnect/backoff.ts
1878
- var G = 1e3, K = 3e4;
1879
- function q(e, t = Math.random) {
1880
- let n = Math.min(K, G * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
2027
+ var ue = 1e3, de = 3e4;
2028
+ function fe(e, t = Math.random) {
2029
+ let n = Math.min(de, ue * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
1881
2030
  return Math.round(n * (1 + r * .2));
1882
2031
  }
1883
2032
  //#endregion
1884
2033
  //#region src/reconnect/ReconnectManager.ts
1885
- var J = class {
2034
+ var pe = class {
1886
2035
  recover;
1887
2036
  random;
1888
2037
  isOnline;
@@ -1899,7 +2048,7 @@ var J = class {
1899
2048
  }
1900
2049
  start() {
1901
2050
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
1902
- let e = this.generation, t = q(this.attempt, this.random);
2051
+ let e = this.generation, t = fe(this.attempt, this.random);
1903
2052
  this.pendingTimer = setTimeout(() => {
1904
2053
  this.pendingTimer = void 0, this.run(e);
1905
2054
  }, t);
@@ -1941,13 +2090,13 @@ var J = class {
1941
2090
  clearPendingTimer() {
1942
2091
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
1943
2092
  }
1944
- }, Y = class r {
2093
+ }, me = class t {
1945
2094
  media;
1946
2095
  options;
1947
2096
  api;
1948
2097
  suppliedSip;
1949
2098
  sip;
1950
- events = new n();
2099
+ events = new i();
1951
2100
  mediaBridge;
1952
2101
  reconnect;
1953
2102
  diagnostics;
@@ -1958,6 +2107,7 @@ var J = class {
1958
2107
  disposed = !1;
1959
2108
  intentionalDisconnect = !1;
1960
2109
  deferredRebuild = !1;
2110
+ sessionRecoveryPending = !1;
1961
2111
  detectedPlatform;
1962
2112
  support;
1963
2113
  acceptingEvents = !0;
@@ -1975,28 +2125,35 @@ var J = class {
1975
2125
  ownedSessionIds = /* @__PURE__ */ new Set();
1976
2126
  terminalReleaseOperations = /* @__PURE__ */ new Map();
1977
2127
  tokenRequest = {};
1978
- constructor(e) {
1979
- this.options = e;
1980
- let n = (e) => this.options.tokenProvider({
1981
- ...e,
2128
+ sharedWorkerSelection;
2129
+ constructor(t) {
2130
+ if (this.options = t, t.api === void 0 && t.sessionProvider === void 0 && t.tokenProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 tokenProvider 或 sessionProvider" });
2131
+ let n = t.tokenProvider, i = (t) => n === void 0 ? Promise.reject(new e("CONFIG_INVALID", "configuration", !1, { cause: "未提供 tokenProvider" })) : n({
2132
+ ...t,
1982
2133
  ...this.tokenRequest
1983
2134
  });
1984
- this.api = e.api === void 0 ? new d({
1985
- baseUrl: e.baseUrl ?? "",
1986
- tokenProvider: n
1987
- }) : re(e.api), this.suppliedSip = e.sip === void 0 ? void 0 : ie(e.sip), this.mediaBridge = H(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new J({
2135
+ this.api = t.api === void 0 ? t.sessionProvider === void 0 ? new p({
2136
+ baseUrl: t.baseUrl ?? "",
2137
+ tokenProvider: i
2138
+ }) : X(_e(t.sessionProvider)) : X(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : ve(t.sip), this.mediaBridge = ce(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new pe({
1988
2139
  recover: () => this.recoverConnection(),
1989
2140
  onAttempt: (e) => {
1990
2141
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
1991
2142
  }
1992
- }), this.diagnostics = new t({
2143
+ }), this.diagnostics = new r({
1993
2144
  getSnapshot: () => this.createDiagnosticsSnapshot(),
1994
2145
  getPermission: () => this.readMicrophonePermission(),
1995
2146
  getDeviceNames: async () => (await this.media.getDevices()).map((e) => e.label).filter((e) => e !== "")
2147
+ }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2148
+ mode: "single-tab",
2149
+ reason: "disabled"
2150
+ } : w({
2151
+ ...t.sharedWorker,
2152
+ ...t.sharedWorkerHost ?? {}
1996
2153
  });
1997
2154
  }
1998
2155
  static async checkSupport() {
1999
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Z(typeof navigator < "u" ? navigator.userAgent : "");
2156
+ let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = ge(typeof navigator < "u" ? navigator.userAgent : "");
2000
2157
  return {
2001
2158
  supported: e && t,
2002
2159
  platform: n,
@@ -2007,8 +2164,8 @@ var J = class {
2007
2164
  }
2008
2165
  async initialize() {
2009
2166
  if (this.assertNotDisposed(), this.initialized) return;
2010
- let e = await r.checkSupport();
2011
- this.support = e, this.options.platform === void 0 && (e.platform === "web" || e.platform === "mobile-web") && (this.detectedPlatform = e.platform), this.assertNotDisposed(), this.initialized = !0;
2167
+ let e = await t.checkSupport();
2168
+ this.support = e, this.options.platform === void 0 && (e.platform === "web" || e.platform === "mobile-web") && (this.detectedPlatform = e.platform), await this.awaitSharedWorkerReady(), this.assertNotDisposed(), this.initialized = !0;
2012
2169
  }
2013
2170
  connect(e) {
2014
2171
  this.assertNotDisposed();
@@ -2031,7 +2188,7 @@ var J = class {
2031
2188
  }
2032
2189
  dispose() {
2033
2190
  if (this.disposeOperation !== void 0) return this.disposeOperation;
2034
- this.disposed = !0, this.lifecycleGeneration += 1, this.intentionalDisconnect = !0, this.acceptingEvents = !1, this.reconnect.dispose(), this.clearRefreshTimer(), this.detachNetworkListeners(), this.state = "disconnected", this.diagnostics.log("info", "connection.stateChanged", { state: "disconnected" }), this.detachSipListener(), this.detachManagerListeners();
2191
+ this.disposed = !0, this.lifecycleGeneration += 1, this.intentionalDisconnect = !0, this.acceptingEvents = !1, this.reconnect.dispose(), this.clearRefreshTimer(), this.detachNetworkListeners(), this.releaseSharedWorker(), this.state = "disconnected", this.diagnostics.log("info", "connection.stateChanged", { state: "disconnected" }), this.detachSipListener(), this.detachManagerListeners();
2035
2192
  let e = !1, t = this.performDispose().then(() => {
2036
2193
  e = !0;
2037
2194
  }).finally(() => {
@@ -2069,6 +2226,16 @@ var J = class {
2069
2226
  getAgent() {
2070
2227
  return this.session?.agent;
2071
2228
  }
2229
+ getSharedWorkerState() {
2230
+ let e = this.sharedWorkerSelection;
2231
+ return e.mode === "shared" ? {
2232
+ mode: "shared",
2233
+ tabId: e.tabId
2234
+ } : {
2235
+ mode: "single-tab",
2236
+ reason: e.reason
2237
+ };
2238
+ }
2072
2239
  getDiagnostics(e = {}) {
2073
2240
  return this.diagnostics.getReport(e);
2074
2241
  }
@@ -2085,22 +2252,22 @@ var J = class {
2085
2252
  this.events.off(e, t);
2086
2253
  }
2087
2254
  async performConnect(e) {
2088
- let t, n, r;
2255
+ let t, r, i;
2089
2256
  try {
2090
2257
  await this.initialize(), this.assertGeneration(e);
2091
- let i = this.resolvePlatform();
2258
+ let a = this.resolvePlatform();
2092
2259
  this.intentionalDisconnect = !1, this.acceptingEvents = !0, this.setConnectionState("connecting"), t = await this.api.createSession({
2093
- sdkVersion: "0.1.0",
2094
- platform: i === "mobile-web" ? "mobile_web" : "web",
2260
+ sdkVersion: n,
2261
+ platform: a === "mobile-web" ? "mobile_web" : "web",
2095
2262
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2096
- requestedCapabilities: [...this.options.requestedCapabilities ?? ce(i)]
2097
- }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), n = await this.getSip(), this.assertGeneration(e), this.session = t;
2098
- let a = this.callManager ?? this.createCallManager(n, t, i);
2099
- this.callManager === void 0 && (r = a), a.updateSession(t), this.callManager = a, this.attachSipListener(n), this.attachNetworkListeners(), await n.connect(t), this.assertGeneration(e), this.setConnectionState("connected"), this.events.emit("connection.registered", { registered: !0 }), this.scheduleRefresh(t);
2100
- } catch (i) {
2101
- if (await this.rollbackConnect(t, n, r), this.disposed) throw this.disposedError();
2102
- if (e !== this.lifecycleGeneration) throw i;
2103
- let a = Q(i, "REGISTRATION_FAILED", "registration", !0);
2263
+ requestedCapabilities: [...this.options.requestedCapabilities ?? Se(a)]
2264
+ }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2265
+ let o = this.callManager ?? this.createCallManager(r, t, a);
2266
+ this.callManager === void 0 && (i = o), o.updateSession(t), this.callManager = o, this.attachSipListener(r), this.attachNetworkListeners(), await r.connect(t), this.assertGeneration(e), this.setConnectionState("connected"), this.events.emit("connection.registered", { registered: !0 }), this.scheduleRefresh(t);
2267
+ } catch (n) {
2268
+ if (await this.rollbackConnect(t, r, i), this.disposed) throw this.disposedError();
2269
+ if (e !== this.lifecycleGeneration) throw n;
2270
+ let a = Z(n, "REGISTRATION_FAILED", "registration", !0);
2104
2271
  throw this.setConnectionState("failed"), this.events.emit("connection.failed", { error: a }), a;
2105
2272
  }
2106
2273
  }
@@ -2117,7 +2284,7 @@ var J = class {
2117
2284
  } catch (t) {
2118
2285
  $(t) || (e ??= t);
2119
2286
  }
2120
- this.reconnect.cancel(), this.clearRefreshTimer(), this.intentionalDisconnect = !0, this.detachSipListener(), this.detachManagerListeners();
2287
+ this.reconnect.cancel(), this.clearRefreshTimer(), this.intentionalDisconnect = !0, this.detachNetworkListeners(), this.detachSipListener(), this.detachManagerListeners();
2121
2288
  let r = this.callManager, i = this.sip;
2122
2289
  this.callManager = void 0;
2123
2290
  try {
@@ -2141,10 +2308,10 @@ var J = class {
2141
2308
  } catch (t) {
2142
2309
  e ??= t;
2143
2310
  }
2144
- if (this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
2311
+ if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
2145
2312
  }
2146
2313
  createCallManager(e, t, n) {
2147
- let r = new y({
2314
+ let r = new x({
2148
2315
  sip: e,
2149
2316
  platform: n,
2150
2317
  session: t,
@@ -2199,7 +2366,7 @@ var J = class {
2199
2366
  try {
2200
2367
  await this.media.releaseAll();
2201
2368
  } catch (t) {
2202
- ae(t) || (e ??= t);
2369
+ ye(t) || (e ??= t);
2203
2370
  }
2204
2371
  try {
2205
2372
  await this.mediaBridge.dispose();
@@ -2216,7 +2383,7 @@ var J = class {
2216
2383
  } catch (t) {
2217
2384
  e ??= t;
2218
2385
  }
2219
- if (this.session = void 0, this.sipUnsubscribe = void 0, this.events.clear(), e !== void 0) throw e;
2386
+ if (this.pruneDeletedSessionTombstones(), this.session = void 0, this.sipUnsubscribe = void 0, this.events.clear(), e !== void 0) throw e;
2220
2387
  }
2221
2388
  async awaitMediaReleaseBarriers() {
2222
2389
  let e;
@@ -2277,21 +2444,27 @@ var J = class {
2277
2444
  let n = this.mediaBridge.releaseCall(e).then(() => {
2278
2445
  this.terminalReleaseOperations.get(e) === n && this.terminalReleaseOperations.delete(e);
2279
2446
  }).catch((t) => {
2280
- throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: Q(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
2447
+ throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: Z(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
2281
2448
  });
2282
2449
  return this.terminalReleaseOperations.set(e, n), n;
2283
2450
  }
2284
2451
  async startDeferredRecovery() {
2285
2452
  try {
2286
- await this.awaitMediaReleaseBarriers(), this.deferredRebuild && !this.hasNonTerminalCalls() && !this.disposed && (this.deferredRebuild = !1, this.clearRefreshTimer(), this.reconnect.start());
2453
+ if (await this.awaitMediaReleaseBarriers(), this.deferredRebuild && !this.hasNonTerminalCalls() && !this.disposed) {
2454
+ if (this.sessionRecoveryPending) {
2455
+ this.recoverInvalidSession();
2456
+ return;
2457
+ }
2458
+ this.deferredRebuild = !1, this.clearRefreshTimer(), this.reconnect.start();
2459
+ }
2287
2460
  } catch {
2288
- this.disposed || this.reconnect.start();
2461
+ !this.disposed && !this.sessionRecoveryPending && this.reconnect.start();
2289
2462
  }
2290
2463
  }
2291
2464
  async refreshAndRebuild() {
2292
2465
  if (this.refreshOperation !== void 0) return this.refreshOperation;
2293
2466
  let e = this.performRefreshAndRebuild().finally(() => {
2294
- this.refreshOperation === e && (this.refreshOperation = void 0);
2467
+ this.refreshOperation === e && (this.refreshOperation = void 0), this.sessionRecoveryPending && !this.hasNonTerminalCalls() && !this.disposed && this.recoverInvalidSession();
2295
2468
  });
2296
2469
  return this.refreshOperation = e, e;
2297
2470
  }
@@ -2315,8 +2488,28 @@ var J = class {
2315
2488
  }
2316
2489
  handleRefreshFailure(e, t) {
2317
2490
  if (this.disposed) return;
2318
- let n = Q(t, "NETWORK_OFFLINE", "network", !0);
2319
- this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), this.deferredRebuild = !0, this.hasNonTerminalCalls() || this.reconnect.start();
2491
+ let n = Z(t, "NETWORK_OFFLINE", "network", !0);
2492
+ if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), Q(t)) {
2493
+ this.clearRefreshTimer(), this.reconnect.cancel(), this.deletedSessions.add(e.sessionId), this.sessionRecoveryPending = !0, this.deferredRebuild = !0, (n.code === "AUTH_TOKEN_UNAVAILABLE" || n.code === "AUTH_TOKEN_EXPIRED") && this.api.invalidateToken?.();
2494
+ return;
2495
+ }
2496
+ this.deferredRebuild = !0, this.hasNonTerminalCalls() || this.reconnect.start();
2497
+ }
2498
+ async recoverInvalidSession() {
2499
+ if (!(!this.sessionRecoveryPending || this.disposed || this.hasNonTerminalCalls())) {
2500
+ this.sessionRecoveryPending = !1, this.deferredRebuild = !1;
2501
+ try {
2502
+ await this.performDisconnect();
2503
+ } catch (e) {
2504
+ this.disposed || this.events.emit("error", { error: Z(e, "SDK_INTERNAL_ERROR", "internal", !0) });
2505
+ return;
2506
+ }
2507
+ if (!this.disposed) try {
2508
+ await this.performConnect(this.lifecycleGeneration);
2509
+ } catch {
2510
+ this.reconnect.cancel();
2511
+ }
2512
+ }
2320
2513
  }
2321
2514
  scheduleRefresh(e) {
2322
2515
  this.clearRefreshTimer();
@@ -2326,12 +2519,12 @@ var J = class {
2326
2519
  }, n);
2327
2520
  }
2328
2521
  async recoverConnection() {
2329
- this.disposed || this.hasNonTerminalCalls() || (await this.awaitMediaReleaseBarriers(), await this.refreshAndRebuild());
2522
+ this.disposed || this.intentionalDisconnect || this.hasNonTerminalCalls() || (await this.awaitMediaReleaseBarriers(), await this.refreshAndRebuild());
2330
2523
  }
2331
2524
  async getSip() {
2332
2525
  if (this.sip !== void 0) return this.sip;
2333
2526
  if (this.suppliedSip !== void 0) return this.sip = this.suppliedSip, this.sip;
2334
- let [e, t] = await Promise.all([import("./createJsSipFactory-yttVU3d6.js"), import("./JsSipAdapter-GHzVSCDh.js")]);
2527
+ let [e, t] = await Promise.all([import("./createJsSipFactory-9CPsweDR.js"), import("./JsSipAdapter-Bke1Qjfe.js")]);
2335
2528
  return this.sip = new t.JsSipAdapter(e.createJsSipFactory(), this.options.baseUrl), this.sip;
2336
2529
  }
2337
2530
  attachSipListener(e) {
@@ -2341,7 +2534,7 @@ var J = class {
2341
2534
  this.setConnectionState("connected");
2342
2535
  return;
2343
2536
  }
2344
- this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: Q(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
2537
+ this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: Z(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
2345
2538
  }
2346
2539
  }));
2347
2540
  }
@@ -2373,7 +2566,7 @@ var J = class {
2373
2566
  destination: e.destination
2374
2567
  })),
2375
2568
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2376
- ice: X(e),
2569
+ ice: he(e),
2377
2570
  wss: {
2378
2571
  configured: e !== void 0,
2379
2572
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2393,7 +2586,8 @@ var J = class {
2393
2586
  tracks: e.tracks,
2394
2587
  peerConnections: e.peerConnections,
2395
2588
  audioElements: e.audioElements,
2396
- webSockets: n?.webSockets ?? +!!i
2589
+ webSockets: n?.webSockets ?? +!!i,
2590
+ deletedSessions: this.deletedSessions.size
2397
2591
  };
2398
2592
  }
2399
2593
  async readMicrophonePermission() {
@@ -2411,11 +2605,20 @@ var J = class {
2411
2605
  if (t !== void 0) return t;
2412
2606
  let n = this.api.deleteSession(e).then(() => {
2413
2607
  this.deletedSessions.add(e);
2608
+ }).catch((t) => {
2609
+ if (Q(t)) {
2610
+ this.deletedSessions.add(e);
2611
+ return;
2612
+ }
2613
+ throw t;
2414
2614
  }).finally(() => {
2415
2615
  this.sessionDeleteOperations.get(e) === n && this.sessionDeleteOperations.delete(e);
2416
2616
  });
2417
2617
  return this.sessionDeleteOperations.set(e, n), n;
2418
2618
  }
2619
+ pruneDeletedSessionTombstones() {
2620
+ for (let e of [...this.deletedSessions]) !this.ownedSessionIds.has(e) && !this.sessionDeleteOperations.has(e) && this.deletedSessions.delete(e);
2621
+ }
2419
2622
  async deleteOwnedSessions() {
2420
2623
  let e;
2421
2624
  for (let t of [...this.ownedSessionIds]) try {
@@ -2443,6 +2646,36 @@ var J = class {
2443
2646
  isCurrentGeneration(e) {
2444
2647
  return !this.disposed && e === this.lifecycleGeneration;
2445
2648
  }
2649
+ async awaitSharedWorkerReady() {
2650
+ let e = this.sharedWorkerSelection;
2651
+ if (e.mode === "shared") try {
2652
+ await e.ready;
2653
+ } catch (e) {
2654
+ if (this.disposed) return;
2655
+ if (this.options.sharedWorker?.fallback === "error") throw e;
2656
+ this.sharedWorkerSelection = {
2657
+ mode: "single-tab",
2658
+ reason: e instanceof Error ? e.message : "SharedWorker attach failed"
2659
+ };
2660
+ }
2661
+ }
2662
+ releaseSharedWorker() {
2663
+ let e = this.sharedWorkerSelection;
2664
+ if (this.sharedWorkerSelection = {
2665
+ mode: "single-tab",
2666
+ reason: "disposed"
2667
+ }, e.mode === "shared") {
2668
+ try {
2669
+ e.client.request({
2670
+ version: 1,
2671
+ type: "detach",
2672
+ requestId: `detach-${e.tabId}`,
2673
+ tabId: e.tabId
2674
+ }).catch(() => void 0);
2675
+ } catch {}
2676
+ e.client.close();
2677
+ }
2678
+ }
2446
2679
  assertNotDisposed() {
2447
2680
  if (this.disposed) throw this.disposedError();
2448
2681
  }
@@ -2450,7 +2683,7 @@ var J = class {
2450
2683
  return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2451
2684
  }
2452
2685
  };
2453
- function X(e) {
2686
+ function he(e) {
2454
2687
  if (e === void 0) return {
2455
2688
  configured: !1,
2456
2689
  serverCount: 0,
@@ -2468,34 +2701,53 @@ function X(e) {
2468
2701
  turnServerCount: n
2469
2702
  };
2470
2703
  }
2471
- function Z(e) {
2704
+ function ge(e) {
2472
2705
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2473
2706
  }
2474
- function re(t) {
2707
+ function X(t) {
2475
2708
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2476
2709
  return t;
2477
2710
  }
2478
- function ie(t) {
2711
+ function _e(t) {
2712
+ let r = {
2713
+ createSession: (e) => t.createSession(e),
2714
+ refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
2715
+ sdkVersion: n,
2716
+ platform: "web"
2717
+ }) : t.refreshSession(e),
2718
+ deleteSession: async (e) => {
2719
+ t.deleteSession !== void 0 && await t.deleteSession(e);
2720
+ },
2721
+ setAgentStatus: (n) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n)
2722
+ }, i = t.invalidateToken;
2723
+ return i !== void 0 && (r.invalidateToken = () => i()), r;
2724
+ }
2725
+ function ve(t) {
2479
2726
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2480
2727
  return t;
2481
2728
  }
2482
- function Q(t, n, r, i, a) {
2729
+ function Z(t, n, r, i, a) {
2483
2730
  return t instanceof e ? new e(t.code, t.category, t.retryable, {
2484
2731
  requestId: t.requestId,
2485
2732
  callId: a ?? t.callId,
2486
- cause: t.cause ?? t
2733
+ cause: t.cause ?? t,
2734
+ serverCode: t.serverCode,
2735
+ status: t.status
2487
2736
  }) : new e(n, r, i, {
2488
2737
  callId: a,
2489
2738
  cause: t
2490
2739
  });
2491
2740
  }
2492
- function ae(t) {
2741
+ function Q(t) {
2742
+ return t instanceof e ? t.status !== void 0 && t.status >= 400 && t.status < 500 || t.serverCode === "SESSION_NOT_FOUND" || t.serverCode === "SESSION_EXPIRED" || t.serverCode === "TOKEN_INVALID" || t.serverCode === "TOKEN_EXPIRED" || t.code === "AUTH_TOKEN_UNAVAILABLE" || t.code === "AUTH_TOKEN_EXPIRED" : !1;
2743
+ }
2744
+ function ye(t) {
2493
2745
  return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2494
2746
  }
2495
2747
  function $(t) {
2496
2748
  return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
2497
2749
  }
2498
- var oe = [
2750
+ var be = [
2499
2751
  "outbound",
2500
2752
  "inbound",
2501
2753
  "mute",
@@ -2503,13 +2755,13 @@ var oe = [
2503
2755
  "dtmf",
2504
2756
  "blind_transfer",
2505
2757
  "device_selection"
2506
- ], se = [
2758
+ ], xe = [
2507
2759
  "outbound",
2508
2760
  "mute",
2509
2761
  "dtmf"
2510
2762
  ];
2511
- function ce(e) {
2512
- return e === "mobile-web" ? se : oe;
2763
+ function Se(e) {
2764
+ return e === "mobile-web" ? xe : be;
2513
2765
  }
2514
2766
  //#endregion
2515
- export { l as a, i as c, n as d, d as i, s as l, y as n, o, m as r, a as s, Y as t, r as u };
2767
+ export { g as a, c, l as d, a as f, x as i, s as l, w as n, p as o, i as p, T as r, d as s, me as t, o as u };