@16x/webphone-sdk 3.1.18 → 3.1.19

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 (51) hide show
  1. package/CHANGELOG.md +267 -40
  2. package/LICENSE +1 -1
  3. package/README.md +214 -161
  4. package/dist/{Diagnostics-DhX9Uc67.cjs → Diagnostics-CgDSPlQx.cjs} +1 -1
  5. package/dist/{Diagnostics-qnipur6s.js → Diagnostics-DJdBDGad.js} +1 -1
  6. package/dist/{JsSipAdapter-l97xq1ao.cjs → JsSipAdapter-CgBtmR16.cjs} +1 -1
  7. package/dist/{JsSipAdapter-B8ueIoBA.js → JsSipAdapter-CiqM4KOq.js} +1 -1
  8. package/dist/SharedWorkerProtocol-4VARy5ma.cjs +1 -0
  9. package/dist/SharedWorkerProtocol-DvLUl0JZ.js +93 -0
  10. package/dist/core/CCBarCall.d.ts +1 -1
  11. package/dist/createJsSipFactory-9CPsweDR.js +9665 -0
  12. package/dist/createJsSipFactory-Dr8HbLl-.cjs +75 -0
  13. package/dist/crypto/legacySipTicket.d.ts +40 -0
  14. package/dist/diagnostics/index.cjs +1 -1
  15. package/dist/diagnostics/index.js +1 -1
  16. package/dist/errors/CCBarError.d.ts +2 -0
  17. package/dist/i18n/index.d.ts +22 -0
  18. package/dist/i18n/messages/en-US.d.ts +2 -0
  19. package/dist/i18n/messages/es-ES.d.ts +2 -0
  20. package/dist/i18n/messages/id-ID.d.ts +2 -0
  21. package/dist/i18n/messages/index.d.ts +7 -0
  22. package/dist/i18n/messages/zh-CN.d.ts +2 -0
  23. package/dist/i18n/types.d.ts +5 -0
  24. package/dist/i18n-BbEy6K9z.cjs +1 -0
  25. package/dist/i18n-D-DdHtGz.js +150 -0
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +9 -8
  29. package/dist/index.umd.js +69 -16
  30. package/dist/legacy/index.cjs +1 -1
  31. package/dist/legacy/index.js +10 -276
  32. package/dist/legacy/legacySessionProvider.d.ts +20 -9
  33. package/dist/legacySessionProvider-CKJyrade.cjs +1 -0
  34. package/dist/{CCBarClient-5z2ZCceq.js → legacySessionProvider-DBrRBB3S.js} +778 -501
  35. package/dist/shared/SharedWorkerFactory.d.ts +2 -0
  36. package/dist/shared/SharedWorkerProtocol.d.ts +2 -0
  37. package/dist/shared-worker.cjs +1 -1
  38. package/dist/shared-worker.js +65 -64
  39. package/dist/styles.css +7 -7
  40. package/dist/ui/i18n/es-ES.d.ts +2 -0
  41. package/dist/ui/i18n/id-ID.d.ts +2 -0
  42. package/dist/ui/i18n/index.d.ts +2 -0
  43. package/dist/ui/index.cjs +1 -1
  44. package/dist/ui/index.js +278 -170
  45. package/dist/version.d.ts +1 -1
  46. package/package.json +114 -109
  47. package/dist/CCBarClient-UAJK9WcJ.cjs +0 -1
  48. package/dist/SharedWorkerProtocol-C-4KpECM.cjs +0 -1
  49. package/dist/SharedWorkerProtocol-CffZrUXg.js +0 -119
  50. package/dist/createJsSipFactory-B1ORbJiP.cjs +0 -22
  51. package/dist/createJsSipFactory-CoWZN-BC.js +0 -7410
@@ -1,7 +1,8 @@
1
- import { i as e, t } from "./SharedWorkerProtocol-CffZrUXg.js";
2
- import { r as n, t as r } from "./Diagnostics-qnipur6s.js";
1
+ import { o as e, s as t } from "./i18n-D-DdHtGz.js";
2
+ import { i as n, t as r } from "./SharedWorkerProtocol-DvLUl0JZ.js";
3
+ import { r as i, t as a } from "./Diagnostics-DJdBDGad.js";
3
4
  //#region src/events/TypedEventBus.ts
4
- var i = class {
5
+ var o = class {
5
6
  handlers = /* @__PURE__ */ new Map();
6
7
  on(e, t) {
7
8
  let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set();
@@ -27,10 +28,11 @@ var i = class {
27
28
  clear() {
28
29
  this.handlers.clear();
29
30
  }
30
- }, a = {
31
+ }, s = {
31
32
  new: /* @__PURE__ */ new Set([
32
33
  "dialing",
33
34
  "ringing",
35
+ "ended",
34
36
  "failed"
35
37
  ]),
36
38
  dialing: /* @__PURE__ */ new Set([
@@ -61,19 +63,19 @@ var i = class {
61
63
  ]),
62
64
  ended: /* @__PURE__ */ new Set(),
63
65
  failed: /* @__PURE__ */ new Set()
64
- }, o = (e, t) => a[e].has(t);
65
- function s(e, t) {
66
- if (!o(e, t)) throw new c(e, t);
66
+ }, c = (e, t) => s[e].has(t);
67
+ function l(e, t) {
68
+ if (!c(e, t)) throw new u(e, t);
67
69
  return t;
68
70
  }
69
- var c = class extends e {
71
+ var u = class extends n {
70
72
  constructor(e, t) {
71
73
  super("CALL_OPERATION_NOT_ALLOWED", "call", !1, { cause: {
72
74
  from: e,
73
75
  to: t
74
76
  } });
75
77
  }
76
- }, l = s, u = [
78
+ }, d = l, f = [
77
79
  "progress",
78
80
  "accepted",
79
81
  "confirmed",
@@ -82,7 +84,7 @@ var c = class extends e {
82
84
  "hold",
83
85
  "unhold",
84
86
  "mediaConnected"
85
- ], d = 3e4, f = class {
87
+ ], p = 3e4, m = class {
86
88
  options;
87
89
  currentState = "new";
88
90
  sessionUnsubscribers = [];
@@ -97,20 +99,20 @@ var c = class extends e {
97
99
  id;
98
100
  destination;
99
101
  platform;
100
- constructor(t) {
101
- this.options = t, this.id = t.id, this.destination = t.destination, this.platform = t.platform, this.capabilities = t.capabilities ?? /* @__PURE__ */ new Set();
102
+ constructor(e) {
103
+ this.options = e, this.id = e.id, this.destination = e.destination, this.platform = e.platform, this.capabilities = e.capabilities ?? /* @__PURE__ */ new Set();
102
104
  try {
103
- u.forEach((e) => {
104
- this.sessionUnsubscribers.push(t.session.on(e, (t) => this.handleSessionEvent(e, t)));
105
+ f.forEach((t) => {
106
+ this.sessionUnsubscribers.push(e.session.on(t, (e) => this.handleSessionEvent(t, e)));
105
107
  });
106
- } catch (n) {
108
+ } catch (t) {
107
109
  this.cleanupSessionListeners();
108
110
  try {
109
- t.session.terminate();
111
+ e.session.terminate();
110
112
  } catch {}
111
- throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
113
+ throw new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
112
114
  callId: this.id,
113
- cause: n
115
+ cause: t
114
116
  });
115
117
  }
116
118
  }
@@ -162,15 +164,17 @@ var c = class extends e {
162
164
  this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
163
165
  }
164
166
  async transfer(e, t) {
165
- if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !m(e) || e.target.trim() === "") throw this.operationError();
167
+ if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !g(e) || e.target.trim() === "") throw this.operationError();
166
168
  this.invoke(() => this.options.session.refer(e.target.trim()));
167
169
  }
168
170
  async hangup(e) {
169
- if (this.assertNotDisposed(), this.assertOwner(e), p(this.currentState)) throw this.operationError();
170
- try {
171
- this.options.session.terminate(), p(this.currentState) || this.transitionTo("ended");
172
- } catch (e) {
173
- throw this.operationError(e);
171
+ if (!(this.disposed || h(this.currentState))) {
172
+ this.assertOwner(e);
173
+ try {
174
+ this.options.session.terminate(), h(this.currentState) || this.transitionTo("ended");
175
+ } catch (e) {
176
+ throw this.operationError(e);
177
+ }
174
178
  }
175
179
  }
176
180
  beginOutbound() {
@@ -196,7 +200,7 @@ var c = class extends e {
196
200
  }
197
201
  dispose() {
198
202
  if (!this.disposed) {
199
- if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !p(this.currentState)) try {
203
+ if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !h(this.currentState)) try {
200
204
  this.options.session.terminate();
201
205
  } catch (e) {
202
206
  this.reportOperationError(e);
@@ -208,7 +212,7 @@ var c = class extends e {
208
212
  }
209
213
  }
210
214
  handleSessionEvent(e, t) {
211
- if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || p(this.currentState))) switch (e) {
215
+ if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || h(this.currentState))) switch (e) {
212
216
  case "progress":
213
217
  this.transitionIfAllowed("ringing", t, e);
214
218
  break;
@@ -236,23 +240,23 @@ var c = class extends e {
236
240
  transitionToActive(e) {
237
241
  this.currentState !== "active" && ((this.currentState === "dialing" || this.currentState === "ringing") && this.transitionTo("connecting", e), this.transitionIfAllowed("active", e, "confirmed"));
238
242
  }
239
- transitionIfAllowed(e, t, n) {
240
- this.currentState !== e && (o(this.currentState, e) ? this.transitionTo(e, t) : this.reportIllegalTransition(e, n));
241
- }
242
243
  updateHoldState(e, t, n) {
243
244
  let r = typeof t == "object" && t ? t.originator : void 0;
244
245
  r === "remote" ? this.remoteHeld = e : r === "both" ? (this.localHeld = e, this.remoteHeld = e) : this.localHeld = e;
245
246
  let i = this.localHeld || this.remoteHeld ? "held" : "active";
246
247
  this.transitionIfAllowed(i, t, n);
247
248
  }
249
+ transitionIfAllowed(e, t, n) {
250
+ this.currentState !== e && (c(this.currentState, e) ? this.transitionTo(e, t) : this.reportIllegalTransition(e, n));
251
+ }
248
252
  transitionIfStillRinging(e, t) {
249
253
  this.currentState === "ringing" && this.transitionTo(e, t);
250
254
  }
251
255
  transitionTo(e, t) {
252
256
  if (this.currentState === e) return;
253
- if (!o(this.currentState, e)) throw this.operationError();
257
+ if (!c(this.currentState, e)) throw this.operationError();
254
258
  let n = this.currentState;
255
- this.currentState = e, p(e) && this.rejectPendingOperation();
259
+ this.currentState = e, h(e) && this.rejectPendingOperation();
256
260
  try {
257
261
  this.options.onStateChanged?.({
258
262
  callId: this.id,
@@ -260,7 +264,7 @@ var c = class extends e {
260
264
  to: e
261
265
  }, t);
262
266
  } catch {} finally {
263
- p(e) && this.dispose();
267
+ h(e) && this.dispose();
264
268
  }
265
269
  }
266
270
  startPendingOperation(e, t) {
@@ -274,7 +278,7 @@ var c = class extends e {
274
278
  resolve: n,
275
279
  reject: r
276
280
  };
277
- this.pendingOperation = i, i.timer = setTimeout(() => this.timeoutPendingOperation(i), d);
281
+ this.pendingOperation = i, i.timer = setTimeout(() => this.timeoutPendingOperation(i), p);
278
282
  let a;
279
283
  try {
280
284
  a = t();
@@ -287,7 +291,7 @@ var c = class extends e {
287
291
  }
288
292
  resolvePendingOperation(e) {
289
293
  if (this.pendingOperation === e) {
290
- if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || p(this.currentState)) {
294
+ if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || h(this.currentState)) {
291
295
  e.reject(this.operationError());
292
296
  return;
293
297
  }
@@ -317,10 +321,10 @@ var c = class extends e {
317
321
  to: e
318
322
  });
319
323
  }
320
- reportOperationError(t) {
321
- let n = t instanceof e && t.callId === this.id ? t : this.operationError(t);
324
+ reportOperationError(e) {
325
+ let t = e instanceof n && e.callId === this.id ? e : this.operationError(e);
322
326
  try {
323
- this.options.onError?.(n);
327
+ this.options.onError?.(t);
324
328
  } catch {}
325
329
  }
326
330
  finishFailedIncomingOperation(e) {
@@ -380,41 +384,41 @@ var c = class extends e {
380
384
  if (e !== void 0 && (this.ownerLost || this.ownerTabId !== void 0 && this.ownerTabId !== e)) throw this.operationError();
381
385
  }
382
386
  capabilityError() {
383
- return new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: this.id });
387
+ return new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: this.id });
384
388
  }
385
- operationError(t) {
386
- return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
389
+ operationError(e) {
390
+ return new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
387
391
  callId: this.id,
388
- cause: t
392
+ cause: e
389
393
  });
390
394
  }
391
395
  };
392
- function p(e) {
396
+ function h(e) {
393
397
  return e === "ended" || e === "failed";
394
398
  }
395
- function m(e) {
399
+ function g(e) {
396
400
  return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
397
401
  }
398
402
  //#endregion
399
403
  //#region src/core/callId.ts
400
- var h = 0;
401
- function g() {
402
- return h += 1, `call_${Date.now().toString(36)}_${h.toString(36)}`;
404
+ var _ = 0;
405
+ function v() {
406
+ return _ += 1, `call_${Date.now().toString(36)}_${_.toString(36)}`;
403
407
  }
404
408
  //#endregion
405
409
  //#region src/core/userData.ts
406
- var ee = "X-User-Data", te = /[^\x20-\x7E]/, ne = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
407
- function _(t) {
408
- if (typeof t != "string") return [];
409
- let n = t.trim();
410
- if (n === "") return [];
411
- if (te.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: ne });
412
- return [`${ee}: ${n}`];
410
+ var y = "X-User-Data", b = /[^\x20-\x7E]/, ee = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
411
+ function te(e) {
412
+ if (typeof e != "string") return [];
413
+ let t = e.trim();
414
+ if (t === "") return [];
415
+ if (b.test(t)) throw new n("CALL_INVALID_USERDATA", "call", !1, { cause: ee });
416
+ return [`${y}: ${t}`];
413
417
  }
414
418
  //#endregion
415
419
  //#region src/core/CallManager.ts
416
- var v = class {
417
- events = new y();
420
+ var x = class {
421
+ events = new ne();
418
422
  calls = /* @__PURE__ */ new Map();
419
423
  options;
420
424
  incomingUnsubscribe;
@@ -432,47 +436,47 @@ var v = class {
432
436
  terminalNotified = /* @__PURE__ */ new Set();
433
437
  terminalOperations = /* @__PURE__ */ new Map();
434
438
  disposeOperation;
435
- constructor(t) {
436
- this.options = t, this.incomingSessionSnapshot = t.session;
439
+ constructor(e) {
440
+ this.options = e, this.incomingSessionSnapshot = e.session;
437
441
  try {
438
- this.incomingUnsubscribe = t.sip.onIncoming((e) => this.handleIncoming(e));
439
- } catch (t) {
440
- throw new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
442
+ this.incomingUnsubscribe = e.sip.onIncoming((e) => this.handleIncoming(e));
443
+ } catch (e) {
444
+ throw new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
441
445
  }
442
446
  }
443
447
  on(e, t) {
444
448
  return this.disposed ? () => void 0 : this.events.on(e, t);
445
449
  }
446
- async dial(t, n) {
450
+ async dial(e, t) {
447
451
  this.assertNotDisposed();
448
- let r = this.operationGeneration, i = t.destination.trim();
449
- if (i === "") throw new e("CALL_INVALID_DESTINATION", "call", !1);
452
+ let r = this.operationGeneration, i = e.destination.trim();
453
+ if (i === "") throw new n("CALL_INVALID_DESTINATION", "call", !1);
450
454
  let a = /^\+?\d{3,20}$/.test(i), o = /^sips?:[^\s<>@]+(?:@[^\s<>@]+)?$/i.test(i);
451
- if (!a && !o) throw new e("CALL_INVALID_DESTINATION", "call", !1);
452
- let s = _(t.userdata);
453
- this.requireCapability(n, "outbound");
454
- let c = this.callLimit(n);
455
+ if (!a && !o) throw new n("CALL_INVALID_DESTINATION", "call", !1);
456
+ let s = te(e.userdata);
457
+ this.requireCapability(t, "outbound");
458
+ let c = this.callLimit(t);
455
459
  if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= c) throw this.capabilityError();
456
- if (this.calls.size + this.pendingDialCount >= c || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new e("CALL_ALREADY_EXISTS", "call", !1);
460
+ if (this.calls.size + this.pendingDialCount >= c || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new n("CALL_ALREADY_EXISTS", "call", !1);
457
461
  this.pendingDialCount += 1, this.pendingDestinations.add(i);
458
- let l = g(), u;
462
+ let l = v(), u;
459
463
  try {
460
464
  u = await this.holdActiveCallForNewCall(), this.assertGeneration(r, l);
461
- let e;
465
+ let n;
462
466
  try {
463
- e = this.options.sip.dial(i, this.dialOptions(l, n, t.type, s));
467
+ n = this.options.sip.dial(i, this.dialOptions(l, t, e.type, s));
464
468
  } catch (e) {
465
469
  throw this.dialError(e, l);
466
470
  }
467
471
  this.assertGeneration(r, l);
468
472
  let a;
469
473
  try {
470
- a = new f({
474
+ a = new m({
471
475
  id: l,
472
476
  destination: i,
473
477
  platform: this.options.platform,
474
- capabilities: this.effectiveCapabilities(n),
475
- session: e,
478
+ capabilities: this.effectiveCapabilities(t),
479
+ session: n,
476
480
  onStateChanged: (e, t) => this.handleStateChanged(a, e, t),
477
481
  onError: (e) => this.events.emit("error", { error: e }),
478
482
  onDisposed: () => this.handleDisposed(a)
@@ -481,7 +485,7 @@ var v = class {
481
485
  throw this.dialError(e, l);
482
486
  }
483
487
  if (!this.isCurrentGeneration(r)) throw a.dispose(), this.callOperationError(a.id);
484
- this.calls.set(a.id, a), this.callSessions.set(a.id, e), this.options.onCallCreated?.(a.id, e);
488
+ this.calls.set(a.id, a), this.callSessions.set(a.id, n), this.options.onCallCreated?.(a.id, n);
485
489
  try {
486
490
  a.beginOutbound();
487
491
  } catch (e) {
@@ -670,10 +674,10 @@ var v = class {
670
674
  }
671
675
  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", {
672
676
  callId: e.id,
673
- reason: b(n)
677
+ reason: re(n)
674
678
  }) : this.events.emit("call.failed", {
675
679
  callId: e.id,
676
- error: ie(n, e.id)
680
+ error: ae(n, e.id)
677
681
  }));
678
682
  }
679
683
  async switchAutomaticActiveCall(e, t, n) {
@@ -737,36 +741,36 @@ var v = class {
737
741
  commitActive(e, t = this.operationGeneration) {
738
742
  this.isCurrentGeneration(t) && this.isManagedCall(e) && e.state === "active" && this.activeCallId !== e.id && (this.activeCallId = e.id, this.events.emit("call.activeChanged", { callId: e.id }));
739
743
  }
740
- handleIncoming(t) {
744
+ handleIncoming(e) {
741
745
  if (this.disposed) return;
742
- let n = g(), r = this.incomingSessionSnapshot;
746
+ let t = v(), r = this.incomingSessionSnapshot;
743
747
  if (r === void 0 || !r.policy.incomingEnabled || !this.effectiveCapabilities(r).has("inbound")) {
744
- this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
748
+ this.terminateUnsupportedIncoming(e), this.events.emit("error", { error: this.capabilityError(t) });
745
749
  return;
746
750
  }
747
- let i = t.from ?? t.id;
751
+ let i = e.from ?? e.id;
748
752
  if (this.calls.size + this.pendingDialCount >= this.callLimit(r)) {
749
- this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: new e("CALL_ALREADY_EXISTS", "call", !1, { callId: n }) });
753
+ this.terminateUnsupportedIncoming(e), this.events.emit("error", { error: new n("CALL_ALREADY_EXISTS", "call", !1, { callId: t }) });
750
754
  return;
751
755
  }
752
756
  let a;
753
757
  try {
754
- a = new f({
755
- id: n,
758
+ a = new m({
759
+ id: t,
756
760
  destination: i,
757
761
  platform: this.options.platform,
758
762
  incoming: !0,
759
763
  capabilities: this.effectiveCapabilities(r),
760
- session: t,
764
+ session: e,
761
765
  onStateChanged: (e, t) => this.handleStateChanged(a, e, t),
762
766
  onError: (e) => this.events.emit("error", { error: e }),
763
767
  onDisposed: () => this.handleDisposed(a)
764
768
  });
765
769
  } catch (e) {
766
- this.events.emit("error", { error: this.callOperationError(n, e) });
770
+ this.events.emit("error", { error: this.callOperationError(t, e) });
767
771
  return;
768
772
  }
769
- this.calls.set(a.id, a), this.callSessions.set(a.id, t), this.options.onCallCreated?.(a.id, t);
773
+ this.calls.set(a.id, a), this.callSessions.set(a.id, e), this.options.onCallCreated?.(a.id, e);
770
774
  try {
771
775
  a.beginIncoming(), this.events.emit("call.incoming", {
772
776
  callId: a.id,
@@ -836,16 +840,16 @@ var v = class {
836
840
  this.terminalOperations.get(e) === t && this.terminalOperations.delete(e), this.calls.has(e) || this.terminalNotified.delete(e);
837
841
  }
838
842
  assertNotDisposed() {
839
- if (this.disposed) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
843
+ if (this.disposed) throw new n("SDK_ALREADY_DISPOSED", "internal", !1);
840
844
  }
841
- callOperationError(t, n) {
842
- return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
843
- callId: t,
844
- cause: n
845
+ callOperationError(e, t) {
846
+ return new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
847
+ callId: e,
848
+ cause: t
845
849
  });
846
850
  }
847
- capabilityError(t) {
848
- return new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: t });
851
+ capabilityError(e) {
852
+ return new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: e });
849
853
  }
850
854
  compensationError(e, t, n, r) {
851
855
  return this.callOperationError(e, {
@@ -870,20 +874,17 @@ var v = class {
870
874
  ...n === void 0 ? {} : { type: n }
871
875
  };
872
876
  }
873
- dialError(t, n) {
874
- return t instanceof e ? new e(t.code, t.category, t.retryable, {
875
- requestId: t.requestId,
876
- callId: n,
877
- cause: t.cause ?? t,
878
- serverCode: t.serverCode,
879
- platformCode: t.platformCode,
880
- status: t.status
881
- }) : new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
882
- callId: n,
883
- cause: t
877
+ dialError(e, t) {
878
+ return e instanceof n ? new n(e.code, e.category, e.retryable, {
879
+ requestId: e.requestId,
880
+ callId: t,
881
+ cause: e.cause ?? e
882
+ }) : new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
883
+ callId: t,
884
+ cause: e
884
885
  });
885
886
  }
886
- }, y = class {
887
+ }, ne = class {
887
888
  handlers = /* @__PURE__ */ new Map();
888
889
  on(e, t) {
889
890
  let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
@@ -908,12 +909,12 @@ var v = class {
908
909
  this.handlers.clear();
909
910
  }
910
911
  };
911
- function b(e) {
912
+ function re(e) {
912
913
  if (typeof e != "object" || !e || !("reason" in e)) return "ended";
913
914
  let t = e.reason;
914
915
  return typeof t == "string" && t !== "" ? t : "ended";
915
916
  }
916
- function re(e) {
917
+ function ie(e) {
917
918
  if (typeof e != "object" || !e) return;
918
919
  let { cause: t, cause_code: n, message: r } = e, i = typeof n == "number" ? n : void 0, a = typeof t == "string" ? t : void 0;
919
920
  if (i === void 0 && typeof r == "object" && r) {
@@ -928,90 +929,84 @@ function re(e) {
928
929
  cause: a
929
930
  };
930
931
  }
931
- function ie(t, n) {
932
- if (t instanceof e) return new e(t.code, t.category, t.retryable, {
933
- requestId: t.requestId,
934
- callId: n,
935
- cause: t.cause ?? t,
936
- serverCode: t.serverCode,
937
- platformCode: t.platformCode,
938
- status: t.status
932
+ function ae(e, t) {
933
+ if (e instanceof n) return new n(e.code, e.category, e.retryable, {
934
+ requestId: e.requestId,
935
+ callId: t,
936
+ cause: e.cause ?? e
939
937
  });
940
- if (typeof t == "object" && t && "error" in t) {
941
- let r = t.error;
942
- if (r instanceof e) return new e(r.code, r.category, r.retryable, {
938
+ if (typeof e == "object" && e && "error" in e) {
939
+ let r = e.error;
940
+ if (r instanceof n) return new n(r.code, r.category, r.retryable, {
943
941
  requestId: r.requestId,
944
- callId: n,
945
- cause: r.cause ?? r,
946
- serverCode: r.serverCode,
947
- platformCode: r.platformCode,
948
- status: r.status
942
+ callId: t,
943
+ cause: r.cause ?? r
949
944
  });
950
- if (r instanceof Error) return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
951
- callId: n,
945
+ if (r instanceof Error) return new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
946
+ callId: t,
952
947
  cause: r
953
948
  });
954
949
  }
955
- let r = re(t);
956
- return r === void 0 ? new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
957
- callId: n,
958
- cause: t
959
- }) : r.code === 486 || r.cause === "Busy" ? new e("CALL_BUSY", "call", !1, {
960
- callId: n,
961
- cause: t
962
- }) : r.code === 408 || r.cause === "Request Timeout" ? new e("NETWORK_TIMEOUT", "call", !0, {
963
- callId: n,
964
- cause: t
965
- }) : new e("CALL_REJECTED", "call", !1, {
966
- callId: n,
967
- cause: t
950
+ let r = ie(e);
951
+ return r === void 0 ? new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
952
+ callId: t,
953
+ cause: e
954
+ }) : r.code === 486 || r.cause === "Busy" ? new n("CALL_BUSY", "call", !1, {
955
+ callId: t,
956
+ cause: e
957
+ }) : r.code === 408 || r.cause === "Request Timeout" ? new n("NETWORK_TIMEOUT", "call", !0, {
958
+ callId: t,
959
+ cause: e
960
+ }) : new n("CALL_REJECTED", "call", !1, {
961
+ callId: t,
962
+ cause: e
968
963
  });
969
964
  }
970
965
  //#endregion
971
966
  //#region src/crypto/legacySipTicket.ts
972
- var ae = "q7X4p6MvK1z8Lb3A", oe = "W9e2T4mN0aQ7Ru6C", se = 16, ce = "�";
973
- function le(e) {
967
+ var oe = "q7X4p6MvK1z8Lb3A", se = "W9e2T4mN0aQ7Ru6C", ce = 16, le = "�";
968
+ function ue(e) {
974
969
  for (let t of e) {
975
970
  let e = t.codePointAt(0) ?? 0;
976
971
  if (e === 127 || e < 32 && e !== 9) return !0;
977
972
  }
978
973
  return !1;
979
974
  }
980
- async function x(t, n = {}) {
981
- let r = String(t ?? "").replace(/\s+/g, "");
982
- if (!r) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
983
- let i = n.subtle ?? globalThis.crypto?.subtle;
984
- if (i === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
985
- let a = S(r);
986
- if (a === void 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
987
- let o = await i.importKey("raw", C(n.key ?? ae), "AES-CBC", !1, ["decrypt"]);
975
+ async function S(e, t = {}) {
976
+ let r = String(e ?? "").replace(/\s+/g, "");
977
+ if (!r) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
978
+ let i = t.subtle ?? globalThis.crypto?.subtle;
979
+ if (i === void 0) throw new n("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
980
+ let a = C(r);
981
+ if (a === void 0) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
982
+ let o = await i.importKey("raw", w(t.key ?? oe), "AES-CBC", !1, ["decrypt"]);
988
983
  try {
989
984
  let e = await i.decrypt({
990
985
  name: "AES-CBC",
991
- iv: C(n.iv ?? oe)
986
+ iv: w(t.iv ?? se)
992
987
  }, o, a);
993
988
  return new TextDecoder("utf-8").decode(e).trim();
994
- } catch (t) {
995
- throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: `SIP 密码解密失败(检查 key/iv 与该环境是否一致):${t instanceof Error ? t.message : String(t)}` });
989
+ } catch (e) {
990
+ throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: `SIP 密码解密失败(检查 key/iv 与该环境是否一致):${e instanceof Error ? e.message : String(e)}` });
996
991
  }
997
992
  }
998
- async function ue(e, t = {}) {
993
+ async function de(e, t = {}) {
999
994
  let n = String(e ?? "").replace(/\s+/g, "");
1000
- if (de(n)) try {
1001
- let e = await x(n, t);
1002
- return fe(e) ? e : void 0;
995
+ if (fe(n)) try {
996
+ let e = await S(n, t);
997
+ return pe(e) ? e : void 0;
1003
998
  } catch {
1004
999
  return;
1005
1000
  }
1006
1001
  }
1007
- function de(e) {
1008
- let t = S(e);
1009
- return t !== void 0 && t.byteLength > 0 && t.byteLength % se === 0;
1010
- }
1011
1002
  function fe(e) {
1012
- return e.length === 0 || e.includes(ce) ? !1 : !le(e);
1003
+ let t = C(e);
1004
+ return t !== void 0 && t.byteLength > 0 && t.byteLength % ce === 0;
1005
+ }
1006
+ function pe(e) {
1007
+ return e.length === 0 || e.includes(le) ? !1 : !ue(e);
1013
1008
  }
1014
- function S(e) {
1009
+ function C(e) {
1015
1010
  if (e.length !== 0 && e.length % 4 == 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(e)) try {
1016
1011
  let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length));
1017
1012
  for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
@@ -1020,13 +1015,13 @@ function S(e) {
1020
1015
  return;
1021
1016
  }
1022
1017
  }
1023
- function C(e) {
1018
+ function w(e) {
1024
1019
  let t = new TextEncoder().encode(e), n = new Uint8Array(new ArrayBuffer(t.byteLength));
1025
1020
  return n.set(t), n;
1026
1021
  }
1027
1022
  //#endregion
1028
1023
  //#region src/shared/SharedWorkerClient.ts
1029
- var pe = class {
1024
+ var me = class {
1030
1025
  port;
1031
1026
  timeoutMs;
1032
1027
  pending = /* @__PURE__ */ new Map();
@@ -1036,16 +1031,16 @@ var pe = class {
1036
1031
  constructor(e, t = {}) {
1037
1032
  this.port = e, this.timeoutMs = t.timeoutMs ?? 15e3, this.port.onmessage = (e) => this.handleMessage(e.data), this.port.start();
1038
1033
  }
1039
- request(t) {
1040
- 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) => {
1034
+ request(e) {
1035
+ return this.closed ? Promise.reject(new n("SDK_ALREADY_DISPOSED", "internal", !1)) : this.pending.has(e.requestId) ? Promise.reject(new n("SDK_INTERNAL_ERROR", "internal", !1, { requestId: e.requestId })) : this.lifecycleState === "reconnecting" && e.type === "command" && (e.command === "dial" || e.command === "answer") ? Promise.reject(new n("CALL_OPERATION_NOT_ALLOWED", "call", !0, { callId: e.payload?.callId })) : new Promise((t, r) => {
1041
1036
  let i = setTimeout(() => {
1042
- this.pending.delete(t.requestId), r(new e("NETWORK_TIMEOUT", "network", !0, { requestId: t.requestId }));
1037
+ this.pending.delete(e.requestId), r(new n("NETWORK_TIMEOUT", "network", !0, { requestId: e.requestId }));
1043
1038
  }, this.timeoutMs);
1044
- this.pending.set(t.requestId, {
1045
- resolve: (e) => n(e),
1039
+ this.pending.set(e.requestId, {
1040
+ resolve: (e) => t(e),
1046
1041
  reject: r,
1047
1042
  timer: i
1048
- }), this.port.postMessage(t);
1043
+ }), this.port.postMessage(e);
1049
1044
  });
1050
1045
  }
1051
1046
  onEvent(e) {
@@ -1055,21 +1050,21 @@ var pe = class {
1055
1050
  return this.lifecycleState;
1056
1051
  }
1057
1052
  close() {
1058
- this.closed || (this.closed = !0, this.pending.forEach((t) => {
1059
- clearTimeout(t.timer), t.reject(new e("SDK_ALREADY_DISPOSED", "internal", !1));
1053
+ this.closed || (this.closed = !0, this.pending.forEach((e) => {
1054
+ clearTimeout(e.timer), e.reject(new n("SDK_ALREADY_DISPOSED", "internal", !1));
1060
1055
  }), this.pending.clear(), this.eventHandlers.clear(), this.port.close());
1061
1056
  }
1062
1057
  handleMessage(e) {
1063
1058
  try {
1064
- let n = t(e);
1065
- if (n.type === "event") {
1066
- n.event === "connection.stateChanged" && me(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
1059
+ let t = r(e);
1060
+ if (t.type === "event") {
1061
+ t.event === "connection.stateChanged" && he(t.payload) && (this.lifecycleState = t.payload.state), this.eventHandlers.forEach((e) => e(t));
1067
1062
  return;
1068
1063
  }
1069
- if (n.type !== "response") return;
1070
- let r = this.pending.get(n.requestId);
1071
- if (r === void 0) return;
1072
- this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(w(n));
1064
+ if (t.type !== "response") return;
1065
+ let n = this.pending.get(t.requestId);
1066
+ if (n === void 0) return;
1067
+ this.pending.delete(t.requestId), clearTimeout(n.timer), t.ok ? n.resolve(t.result) : n.reject(ge(t));
1073
1068
  } catch (e) {
1074
1069
  this.pending.forEach((t) => {
1075
1070
  clearTimeout(t.timer), t.reject(e);
@@ -1077,48 +1072,49 @@ var pe = class {
1077
1072
  }
1078
1073
  }
1079
1074
  };
1080
- function me(e) {
1075
+ function he(e) {
1081
1076
  return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1082
1077
  }
1083
- function w(t) {
1084
- let n = t.error;
1085
- return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1086
- requestId: t.requestId,
1087
- ...n?.message === void 0 ? {} : { cause: n.message },
1088
- ...n?.serverCode === void 0 ? {} : { serverCode: n.serverCode },
1089
- ...n?.platformCode === void 0 ? {} : { platformCode: n.platformCode },
1090
- ...n?.status === void 0 ? {} : { status: n.status }
1078
+ function ge(e) {
1079
+ let t = e.error;
1080
+ return new n(t?.code ?? "SDK_INTERNAL_ERROR", t?.category ?? "internal", t?.retryable ?? !1, {
1081
+ requestId: e.requestId,
1082
+ ...t?.message === void 0 ? {} : { cause: t.message },
1083
+ ...t?.serverCode === void 0 ? {} : { serverCode: t.serverCode },
1084
+ ...t?.platformCode === void 0 ? {} : { platformCode: t.platformCode },
1085
+ ...t?.status === void 0 ? {} : { status: t.status }
1091
1086
  });
1092
1087
  }
1093
1088
  //#endregion
1094
1089
  //#region src/shared/SharedWorkerFactory.ts
1095
- function T(t = {}) {
1096
- if ((t.enabled ?? "auto") === !1) return {
1090
+ function T(e = {}) {
1091
+ if ((e.enabled ?? "auto") === !1) return {
1097
1092
  mode: "single-tab",
1098
1093
  reason: "disabled"
1099
1094
  };
1100
- let n = t.locationHref ?? D(), r = E(t.url, n), i = (n) => {
1101
- if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
1095
+ let t = e.locationHref ?? D(), r = E(e.url, t), i = (t) => {
1096
+ if (e.fallback === "error") throw new n("CONFIG_INVALID", "configuration", !1, { cause: t });
1102
1097
  return {
1103
1098
  mode: "single-tab",
1104
- reason: n
1099
+ reason: t
1105
1100
  };
1106
1101
  };
1107
1102
  if (r === void 0) return i("SharedWorker URL is unavailable");
1108
- if (!k(r, n)) return i("SharedWorker URL must be same-origin");
1109
- let a = t.workerCtor ?? O();
1103
+ if (!ve(r, t)) return i("SharedWorker URL must be same-origin");
1104
+ let a = e.workerCtor ?? _e();
1110
1105
  if (a === void 0) return i("SharedWorker is not supported");
1111
1106
  let o;
1112
1107
  try {
1113
- o = new a(r, t.name === void 0 ? void 0 : { name: t.name });
1108
+ o = new a(r, e.name === void 0 ? void 0 : { name: e.name });
1114
1109
  } catch (e) {
1115
1110
  return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1116
1111
  }
1117
- let s = t.tabId ?? A(), c = new pe(o.port), l = {
1112
+ let s = e.tabId ?? ye(), c = new me(o.port), l = {
1118
1113
  version: 1,
1119
1114
  type: "attach",
1120
- requestId: j(),
1121
- tabId: s
1115
+ requestId: be(),
1116
+ tabId: s,
1117
+ ...e.locale === void 0 ? {} : { locale: e.locale }
1122
1118
  }, u = c.request(l).then(() => void 0).catch((e) => {
1123
1119
  throw c.close(), e;
1124
1120
  });
@@ -1141,10 +1137,10 @@ function E(e, t = D()) {
1141
1137
  function D() {
1142
1138
  return typeof location > "u" ? void 0 : location.href;
1143
1139
  }
1144
- function O() {
1140
+ function _e() {
1145
1141
  if (typeof SharedWorker == "function") return SharedWorker;
1146
1142
  }
1147
- function k(e, t) {
1143
+ function ve(e, t) {
1148
1144
  if (t === void 0) return !0;
1149
1145
  try {
1150
1146
  return new URL(e, t).origin === new URL(t).origin;
@@ -1152,15 +1148,15 @@ function k(e, t) {
1152
1148
  return !1;
1153
1149
  }
1154
1150
  }
1155
- function A() {
1151
+ function ye() {
1156
1152
  return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1157
1153
  }
1158
- function j() {
1154
+ function be() {
1159
1155
  return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1160
1156
  }
1161
1157
  //#endregion
1162
1158
  //#region src/media/DeviceManager.ts
1163
- var M = class {
1159
+ var xe = class {
1164
1160
  mediaDevices;
1165
1161
  createAudioElement;
1166
1162
  outputCapability;
@@ -1168,23 +1164,23 @@ var M = class {
1168
1164
  outputGeneration = 0;
1169
1165
  outputTail;
1170
1166
  constructor(e = {}) {
1171
- this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? N(), this.createAudioElement = e.createAudioElement;
1167
+ this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? O(), this.createAudioElement = e.createAudioElement;
1172
1168
  }
1173
1169
  async requestPermission(e = {}) {
1174
1170
  let t = this.requireMediaDevices(), n;
1175
1171
  try {
1176
1172
  n = await t.getUserMedia({ audio: e });
1177
1173
  } catch (e) {
1178
- throw I(e);
1174
+ throw j(e);
1179
1175
  }
1180
- P(n);
1176
+ k(n);
1181
1177
  }
1182
1178
  async getDevices() {
1183
1179
  if (this.mediaDevices === void 0) return [];
1184
1180
  try {
1185
1181
  return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
1186
1182
  } catch (e) {
1187
- throw L(e);
1183
+ throw M(e);
1188
1184
  }
1189
1185
  }
1190
1186
  getCapabilities() {
@@ -1198,12 +1194,12 @@ var M = class {
1198
1194
  let e = this.createAudioElementSafely();
1199
1195
  return this.outputCapability = e !== void 0 && typeof e.setSinkId == "function", this.outputCapability;
1200
1196
  }
1201
- async setOutputDevice(t, n) {
1202
- if (!this.supportsOutputSelection()) throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1203
- this.outputDeviceId = t;
1197
+ async setOutputDevice(e, t) {
1198
+ if (!this.supportsOutputSelection()) throw new n("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1199
+ this.outputDeviceId = e;
1204
1200
  let r = ++this.outputGeneration;
1205
- n !== void 0 && await this.enqueueOutput(async () => {
1206
- r === this.outputGeneration && await this.applyOutputDevice(t, n);
1201
+ t !== void 0 && await this.enqueueOutput(async () => {
1202
+ r === this.outputGeneration && await this.applyOutputDevice(e, t);
1207
1203
  });
1208
1204
  }
1209
1205
  async applyConfiguredOutputDevice(e) {
@@ -1216,13 +1212,13 @@ var M = class {
1216
1212
  getOutputDeviceId() {
1217
1213
  return this.outputDeviceId;
1218
1214
  }
1219
- async applyOutputDevice(t, n) {
1220
- let r = n;
1221
- if (typeof r.setSinkId != "function") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1215
+ async applyOutputDevice(e, t) {
1216
+ let r = t;
1217
+ if (typeof r.setSinkId != "function") throw new n("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1222
1218
  try {
1223
- await r.setSinkId(t);
1219
+ await r.setSinkId(e);
1224
1220
  } catch (e) {
1225
- throw R(e);
1221
+ throw Se(e);
1226
1222
  }
1227
1223
  }
1228
1224
  enqueueOutput(e) {
@@ -1236,11 +1232,11 @@ var M = class {
1236
1232
  try {
1237
1233
  return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
1238
1234
  } catch (e) {
1239
- throw F(e);
1235
+ throw A(e);
1240
1236
  }
1241
1237
  }
1242
1238
  requireMediaDevices() {
1243
- if (this.mediaDevices === void 0) throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1239
+ if (this.mediaDevices === void 0) throw new n("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1244
1240
  return this.mediaDevices;
1245
1241
  }
1246
1242
  createAudioElementSafely() {
@@ -1256,10 +1252,10 @@ var M = class {
1256
1252
  }
1257
1253
  }
1258
1254
  };
1259
- function N() {
1255
+ function O() {
1260
1256
  return globalThis.navigator?.mediaDevices;
1261
1257
  }
1262
- function P(e) {
1258
+ function k(e) {
1263
1259
  let t;
1264
1260
  try {
1265
1261
  t = e.getTracks();
@@ -1272,110 +1268,110 @@ function P(e) {
1272
1268
  } catch {}
1273
1269
  });
1274
1270
  }
1275
- function F(t) {
1276
- let n = z(t);
1277
- 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 });
1271
+ function A(e) {
1272
+ let t = N(e);
1273
+ return t === "NotFoundError" || t === "OverconstrainedError" ? new n("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: e }) : t === "NotReadableError" || t === "AbortError" ? new n("MEDIA_DEVICE_IN_USE", "media", !0, { cause: e }) : t === "NotAllowedError" || t === "SecurityError" ? new n("MEDIA_PERMISSION_DENIED", "media", !1, { cause: e }) : new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
1278
1274
  }
1279
- function I(t) {
1280
- let n = z(t);
1281
- 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 });
1275
+ function j(e) {
1276
+ let t = N(e);
1277
+ return t === "NotFoundError" || t === "OverconstrainedError" ? new n("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: e }) : t === "NotReadableError" || t === "AbortError" ? new n("MEDIA_DEVICE_IN_USE", "media", !0, { cause: e }) : t === "NotAllowedError" || t === "SecurityError" ? new n("MEDIA_PERMISSION_DENIED", "media", !1, { cause: e }) : new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
1282
1278
  }
1283
- function L(t) {
1284
- let n = z(t);
1285
- 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 });
1279
+ function M(e) {
1280
+ let t = N(e);
1281
+ return t === "NotFoundError" ? new n("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: e }) : t === "NotAllowedError" || t === "SecurityError" ? new n("MEDIA_PERMISSION_DENIED", "media", !1, { cause: e }) : t === "AbortError" || t === "NotReadableError" ? new n("MEDIA_DEVICE_IN_USE", "media", !0, { cause: e }) : new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
1286
1282
  }
1287
- function R(t) {
1288
- let n = z(t);
1289
- 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 });
1283
+ function Se(e) {
1284
+ let t = N(e);
1285
+ return t === "NotFoundError" ? new n("MEDIA_DEVICE_NOT_FOUND", "media", !1, { cause: e }) : t === "NotAllowedError" || t === "SecurityError" ? new n("MEDIA_PERMISSION_DENIED", "media", !1, { cause: e }) : t === "AbortError" || t === "NotReadableError" ? new n("MEDIA_DEVICE_IN_USE", "media", !0, { cause: e }) : new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
1290
1286
  }
1291
- function z(e) {
1287
+ function N(e) {
1292
1288
  if (typeof e != "object" || !e || !("name" in e)) return;
1293
1289
  let t = e.name;
1294
1290
  return typeof t == "string" ? t : void 0;
1295
1291
  }
1296
1292
  //#endregion
1297
1293
  //#region src/media/RemoteAudio.ts
1298
- var he = class {
1294
+ var Ce = class {
1299
1295
  createAudioElement;
1300
1296
  bindings = /* @__PURE__ */ new Map();
1301
1297
  audioOwners = /* @__PURE__ */ new Map();
1302
1298
  trackOwners = /* @__PURE__ */ new Map();
1303
1299
  generations = /* @__PURE__ */ new Map();
1304
1300
  pendingPlays = /* @__PURE__ */ new Map();
1305
- constructor(e = ge) {
1301
+ constructor(e = we) {
1306
1302
  this.createAudioElement = e;
1307
1303
  }
1308
- async bind(t, n) {
1309
- let r = this.bindings.get(t);
1310
- if (r?.stream === n) return;
1311
- let i = _e(t, n), a;
1304
+ async bind(e, t) {
1305
+ let r = this.bindings.get(e);
1306
+ if (r?.stream === t) return;
1307
+ let i = Te(e, t), a;
1312
1308
  try {
1313
1309
  a = this.createAudioElement();
1314
- } catch (n) {
1315
- throw B(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1316
- callId: t,
1317
- cause: n
1310
+ } catch (t) {
1311
+ throw P(i, this.trackOwners), new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1312
+ callId: e,
1313
+ cause: t
1318
1314
  });
1319
1315
  }
1320
1316
  let o = this.audioOwners.get(a);
1321
- if (o !== void 0 && o !== t) throw B(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1317
+ if (o !== void 0 && o !== e) throw P(i, this.trackOwners), new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: e });
1322
1318
  try {
1323
1319
  a.autoplay = !0, a.playsInline = !0;
1324
- } catch (n) {
1325
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1326
- callId: t,
1327
- cause: n
1320
+ } catch (t) {
1321
+ throw P(i, this.trackOwners), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1322
+ callId: e,
1323
+ cause: t
1328
1324
  });
1329
1325
  }
1330
1326
  try {
1331
- a.srcObject = n;
1332
- } catch (n) {
1333
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1334
- callId: t,
1335
- cause: n
1327
+ a.srcObject = t;
1328
+ } catch (t) {
1329
+ throw P(i, this.trackOwners), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1330
+ callId: e,
1331
+ cause: t
1336
1332
  });
1337
1333
  }
1338
1334
  this.acquireTracks(i), r !== void 0 && this.releaseBinding(r, r.audio !== a);
1339
- let s = this.nextGeneration(t);
1340
- this.audioOwners.set(a, t);
1335
+ let s = this.nextGeneration(e);
1336
+ this.audioOwners.set(a, e);
1341
1337
  let c = {
1342
- callId: t,
1338
+ callId: e,
1343
1339
  audio: a,
1344
- stream: n,
1340
+ stream: t,
1345
1341
  tracks: i,
1346
1342
  generation: s
1347
1343
  };
1348
- this.bindings.set(t, c), this.beginPlay(t);
1344
+ this.bindings.set(e, c), this.beginPlay(e);
1349
1345
  try {
1350
1346
  await a.play();
1351
- } catch (n) {
1352
- if (!this.isCurrent(t, s)) return;
1353
- throw new e("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1354
- callId: t,
1355
- cause: n
1347
+ } catch (t) {
1348
+ if (!this.isCurrent(e, s)) return;
1349
+ throw new n("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1350
+ callId: e,
1351
+ cause: t
1356
1352
  });
1357
1353
  } finally {
1358
- this.finishPlay(t);
1354
+ this.finishPlay(e);
1359
1355
  }
1360
- this.isCurrent(t, s);
1356
+ this.isCurrent(e, s);
1361
1357
  }
1362
- async play(t) {
1363
- let n = this.bindings.get(t);
1364
- if (n === void 0) throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1365
- let r = n.generation;
1366
- this.beginPlay(t);
1358
+ async play(e) {
1359
+ let t = this.bindings.get(e);
1360
+ if (t === void 0) throw new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: e });
1361
+ let r = t.generation;
1362
+ this.beginPlay(e);
1367
1363
  try {
1368
- await n.audio.play();
1369
- } catch (n) {
1370
- if (!this.isCurrent(t, r)) return;
1371
- throw new e("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1372
- callId: t,
1373
- cause: n
1364
+ await t.audio.play();
1365
+ } catch (t) {
1366
+ if (!this.isCurrent(e, r)) return;
1367
+ throw new n("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1368
+ callId: e,
1369
+ cause: t
1374
1370
  });
1375
1371
  } finally {
1376
- this.finishPlay(t);
1372
+ this.finishPlay(e);
1377
1373
  }
1378
- this.isCurrent(t, r);
1374
+ this.isCurrent(e, r);
1379
1375
  }
1380
1376
  getAudioElement(e) {
1381
1377
  return this.bindings.get(e)?.audio;
@@ -1406,7 +1402,7 @@ var he = class {
1406
1402
  releaseTrack(e) {
1407
1403
  let t = this.trackOwners.get(e);
1408
1404
  if (t === void 0 || t <= 1) {
1409
- this.trackOwners.delete(e), V(e);
1405
+ this.trackOwners.delete(e), F(e);
1410
1406
  return;
1411
1407
  }
1412
1408
  this.trackOwners.set(e, t - 1);
@@ -1429,42 +1425,42 @@ var he = class {
1429
1425
  return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
1430
1426
  }
1431
1427
  };
1432
- function ge() {
1433
- if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1428
+ function we() {
1429
+ if (typeof document > "u") throw new n("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1434
1430
  return document.createElement("audio");
1435
1431
  }
1436
- function _e(t, n) {
1432
+ function Te(e, t) {
1437
1433
  try {
1438
- return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
1434
+ return [...new Set(t.getAudioTracks())].filter((e) => e.kind === "audio");
1439
1435
  } catch (r) {
1440
1436
  try {
1441
- return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
1437
+ return [...new Set(t.getTracks())].filter((e) => e.kind === "audio");
1442
1438
  } catch (i) {
1443
- throw ve(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1444
- callId: t,
1439
+ throw Ee(t), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1440
+ callId: e,
1445
1441
  cause: r ?? i
1446
1442
  });
1447
1443
  }
1448
1444
  }
1449
1445
  }
1450
- function B(e, t) {
1446
+ function P(e, t) {
1451
1447
  e.forEach((e) => {
1452
- (t.get(e) ?? 0) === 0 && V(e);
1448
+ (t.get(e) ?? 0) === 0 && F(e);
1453
1449
  });
1454
1450
  }
1455
- function ve(e) {
1451
+ function Ee(e) {
1456
1452
  try {
1457
- [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
1453
+ [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(F);
1458
1454
  } catch {}
1459
1455
  }
1460
- function V(e) {
1456
+ function F(e) {
1461
1457
  try {
1462
1458
  e.stop();
1463
1459
  } catch {}
1464
1460
  }
1465
1461
  //#endregion
1466
1462
  //#region src/media/MediaManager.ts
1467
- var ye = class {
1463
+ var De = class {
1468
1464
  deviceManager;
1469
1465
  remoteAudio;
1470
1466
  getActiveCall;
@@ -1485,7 +1481,7 @@ var ye = class {
1485
1481
  mediaDevices: e.mediaDevices,
1486
1482
  createAudioElement: e.createAudioElement
1487
1483
  };
1488
- this.deviceManager = new M(t), this.remoteAudio = new he(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? Se;
1484
+ this.deviceManager = new xe(t), this.remoteAudio = new Ce(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? Ae;
1489
1485
  }
1490
1486
  requestPermission(e) {
1491
1487
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1505,7 +1501,7 @@ var ye = class {
1505
1501
  n !== void 0 && this.releaseResource(n).catch((e) => {
1506
1502
  this.releaseErrors.set(n, e);
1507
1503
  });
1508
- let r = be(t) ? t : { peerConnection: t }, i = {
1504
+ let r = Oe(t) ? t : { peerConnection: t }, i = {
1509
1505
  callId: e,
1510
1506
  peerConnection: r.peerConnection,
1511
1507
  senders: /* @__PURE__ */ new Map(),
@@ -1579,15 +1575,15 @@ var ye = class {
1579
1575
  audioElements: t.audioElements
1580
1576
  };
1581
1577
  }
1582
- releaseResource(t) {
1583
- let n = this.releaseOperations.get(t);
1584
- if (n !== void 0) return n;
1585
- if (!this.resources.has(t)) return Promise.resolve();
1586
- let r = t.callId;
1587
- 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);
1588
- let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
1589
- senderResource: e,
1590
- promise: this.enqueueSender(t, e, () => W(e.sender), !0)
1578
+ releaseResource(e) {
1579
+ let t = this.releaseOperations.get(e);
1580
+ if (t !== void 0) return t;
1581
+ if (!this.resources.has(e)) return Promise.resolve();
1582
+ let r = e.callId;
1583
+ this.remoteAudio.release(r), this.releaseErrors.delete(e), this.calls.get(r) === e && this.calls.delete(r), e.generation += 1, e.released = !0, this.unsubscribeTrackSource(e);
1584
+ let i = /* @__PURE__ */ new Set([...e.localTracks, ...e.pendingTracks]), a = [...e.senders.values()].filter((e) => e.audio).map((t) => ({
1585
+ senderResource: t,
1586
+ promise: this.enqueueSender(e, t, () => R(t.sender), !0)
1591
1587
  })), o = Promise.all(a.map(async (e) => {
1592
1588
  try {
1593
1589
  return await e.promise, {
@@ -1600,39 +1596,39 @@ var ye = class {
1600
1596
  cause: t
1601
1597
  };
1602
1598
  }
1603
- })).then(async (n) => {
1599
+ })).then(async (t) => {
1604
1600
  let a = /* @__PURE__ */ new Set(), o = [];
1605
- if (n.forEach((e) => {
1601
+ if (t.forEach((e) => {
1606
1602
  if (e.cause !== void 0) {
1607
1603
  o.push(e.cause);
1608
- let t = H(e.senderResource.sender);
1604
+ let t = I(e.senderResource.sender);
1609
1605
  t?.kind === "audio" && a.add(t);
1610
1606
  return;
1611
1607
  }
1612
- let t = H(e.senderResource.sender);
1608
+ let t = I(e.senderResource.sender);
1613
1609
  t?.kind === "audio" && i.add(t);
1614
1610
  }), i.forEach((e) => {
1615
- a.has(e) || K(e);
1616
- }), o.length > 0) throw t.localTracks.clear(), t.pendingTracks.clear(), a.forEach((e) => t.localTracks.add(e)), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1611
+ a.has(e) || B(e);
1612
+ }), o.length > 0) throw e.localTracks.clear(), e.pendingTracks.clear(), a.forEach((t) => e.localTracks.add(t)), new n("SDK_INTERNAL_ERROR", "internal", !0, {
1617
1613
  callId: r,
1618
1614
  cause: o[0]
1619
1615
  });
1620
- if (!t.peerClosed && t.peerConnection.close !== void 0) try {
1621
- await t.peerConnection.close(), t.peerClosed = !0;
1622
- } catch (n) {
1623
- let i = [...t.senders.values()].map((e) => H(e.sender)).find((e) => e?.kind === "audio");
1624
- throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1616
+ if (!e.peerClosed && e.peerConnection.close !== void 0) try {
1617
+ await e.peerConnection.close(), e.peerClosed = !0;
1618
+ } catch (t) {
1619
+ let i = [...e.senders.values()].map((e) => I(e.sender)).find((e) => e?.kind === "audio");
1620
+ throw e.localTracks.clear(), e.pendingTracks.clear(), i != null && e.localTracks.add(i), new n("SDK_INTERNAL_ERROR", "internal", !0, {
1625
1621
  callId: r,
1626
- cause: n
1622
+ cause: t
1627
1623
  });
1628
1624
  }
1629
- t.localTracks.clear(), t.pendingTracks.clear(), t.senders.clear(), this.resources.delete(t), this.releaseUnusedSenderQueues();
1630
- }).catch((e) => {
1631
- throw this.releaseErrors.set(t, e), this.calls.get(r) === void 0 && this.calls.set(r, t), e;
1625
+ e.localTracks.clear(), e.pendingTracks.clear(), e.senders.clear(), this.resources.delete(e), this.releaseUnusedSenderQueues();
1626
+ }).catch((t) => {
1627
+ throw this.releaseErrors.set(e, t), this.calls.get(r) === void 0 && this.calls.set(r, e), t;
1632
1628
  }).finally(() => {
1633
- this.releaseOperations.get(t) === o && this.releaseOperations.delete(t);
1629
+ this.releaseOperations.get(e) === o && this.releaseOperations.delete(e);
1634
1630
  });
1635
- return this.releaseOperations.set(t, o), o;
1631
+ return this.releaseOperations.set(e, o), o;
1636
1632
  }
1637
1633
  releaseCall(e) {
1638
1634
  let t = this.callReleaseOperations.get(e);
@@ -1686,51 +1682,51 @@ var ye = class {
1686
1682
  let e = [...this.inputOperations.values()];
1687
1683
  e.length !== 0 && await Promise.allSettled(e);
1688
1684
  }
1689
- async performInputSwitch(t, n, r) {
1690
- if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
1691
- let i = this.findAudioSender(r), a = H(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1685
+ async performInputSwitch(e, t, r) {
1686
+ if (this.assertActiveCall(t), this.assertDeviceSelectionCapability(t), !this.isCurrentResource(r) || t.peerConnection !== r.peerConnection) throw this.callOperationError(t.callId);
1687
+ let i = this.findAudioSender(r), a = I(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(e), c;
1692
1688
  try {
1693
1689
  c = s.getTracks();
1694
- } catch (t) {
1695
- throw xe(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1696
- callId: n.callId,
1697
- cause: t
1690
+ } catch (e) {
1691
+ throw ke(s), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1692
+ callId: t.callId,
1693
+ cause: e
1698
1694
  });
1699
1695
  }
1700
1696
  let l;
1701
1697
  try {
1702
1698
  l = s.getAudioTracks();
1703
- } catch (t) {
1704
- throw G(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1705
- callId: n.callId,
1706
- cause: t
1699
+ } catch (e) {
1700
+ throw z(c), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1701
+ callId: t.callId,
1702
+ cause: e
1707
1703
  });
1708
1704
  }
1709
1705
  let u = l[0];
1710
- if (u === void 0) throw G(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1711
- if (!this.canCommitInputSwitch(n, r, i, a, o)) throw G(c), this.callOperationError(n.callId);
1706
+ if (u === void 0) throw z(c), new n("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: t.callId });
1707
+ if (!this.canCommitInputSwitch(t, r, i, a, o)) throw z(c), this.callOperationError(t.callId);
1712
1708
  c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
1713
1709
  try {
1714
1710
  await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
1715
- } catch (t) {
1716
- 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), G(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
1717
- callId: n.callId,
1718
- cause: t
1711
+ } catch (e) {
1712
+ throw r.released ? this.callOperationError(t.callId) : (r.released || (c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), await this.rollbackSender(r, i, a, u), z(c)), new n("MEDIA_DEVICE_IN_USE", "media", !0, {
1713
+ callId: t.callId,
1714
+ cause: e
1719
1715
  }));
1720
1716
  }
1721
- if (!this.canCommitInputSwitch(n, r, i, u, o)) {
1717
+ if (!this.canCommitInputSwitch(t, r, i, u, o)) {
1722
1718
  if (!r.released) try {
1723
- await this.enqueueSender(r, i, () => H(i.sender) === u ? W(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), G(c);
1724
- } catch (t) {
1725
- throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
1726
- callId: n.callId,
1727
- cause: t
1719
+ await this.enqueueSender(r, i, () => I(i.sender) === u ? R(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), z(c);
1720
+ } catch (e) {
1721
+ throw new n("SDK_INTERNAL_ERROR", "internal", !0, {
1722
+ callId: t.callId,
1723
+ cause: e
1728
1724
  });
1729
1725
  }
1730
- throw this.callOperationError(n.callId);
1726
+ throw this.callOperationError(t.callId);
1731
1727
  }
1732
- c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), K(a)), c.forEach((e) => {
1733
- e !== u && K(e);
1728
+ 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) => {
1729
+ e !== u && B(e);
1734
1730
  });
1735
1731
  }
1736
1732
  ensureCallMedia(e) {
@@ -1742,35 +1738,35 @@ var ye = class {
1742
1738
  if (n === void 0) throw this.callOperationError(e.callId);
1743
1739
  return n;
1744
1740
  }
1745
- captureSenders(t, n) {
1741
+ captureSenders(e, t) {
1746
1742
  let r;
1747
1743
  try {
1748
- r = t.peerConnection.getSenders();
1749
- } catch (n) {
1750
- throw new e("SDK_INTERNAL_ERROR", "internal", !1, {
1751
- callId: t.callId,
1752
- cause: n
1744
+ r = e.peerConnection.getSenders();
1745
+ } catch (t) {
1746
+ throw new n("SDK_INTERNAL_ERROR", "internal", !1, {
1747
+ callId: e.callId,
1748
+ cause: t
1753
1749
  });
1754
1750
  }
1755
1751
  r.forEach((r) => {
1756
- let i = H(r), a;
1752
+ let i = I(r), a;
1757
1753
  try {
1758
- a = n?.(r) ?? r.senderKind ?? r.kind;
1759
- } catch (n) {
1760
- throw new e("SDK_INTERNAL_ERROR", "internal", !1, {
1761
- callId: t.callId,
1762
- cause: n
1754
+ a = t?.(r) ?? r.senderKind ?? r.kind;
1755
+ } catch (t) {
1756
+ throw new n("SDK_INTERNAL_ERROR", "internal", !1, {
1757
+ callId: e.callId,
1758
+ cause: t
1763
1759
  });
1764
1760
  }
1765
- t.senders.set(r, {
1761
+ e.senders.set(r, {
1766
1762
  sender: r,
1767
1763
  audio: a === "audio" || a === void 0 && i?.kind === "audio",
1768
1764
  queue: this.senderQueues.get(r) ?? this.createSenderQueue(r)
1769
- }), i?.kind === "audio" && t.localTracks.add(i);
1765
+ }), i?.kind === "audio" && e.localTracks.add(i);
1770
1766
  });
1771
1767
  }
1772
1768
  findAudioSender(e) {
1773
- let t = [...e.senders.values()].find((e) => e.audio && (H(e.sender)?.kind === "audio" || H(e.sender) === null));
1769
+ let t = [...e.senders.values()].find((e) => e.audio && (I(e.sender)?.kind === "audio" || I(e.sender) === null));
1774
1770
  if (t === void 0) throw this.capabilityError(e.callId);
1775
1771
  return t;
1776
1772
  }
@@ -1786,7 +1782,7 @@ var ye = class {
1786
1782
  } catch {
1787
1783
  return !1;
1788
1784
  }
1789
- return H(n.sender) === r;
1785
+ return I(n.sender) === r;
1790
1786
  }
1791
1787
  enqueueSender(e, t, n, r = !1) {
1792
1788
  t.queue.pending += 1;
@@ -1815,7 +1811,7 @@ var ye = class {
1815
1811
  });
1816
1812
  }
1817
1813
  async rollbackSender(e, t, n, r) {
1818
- e.released || H(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1814
+ e.released || I(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1819
1815
  }
1820
1816
  isCurrentResource(e, t = e.generation) {
1821
1817
  return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
@@ -1826,58 +1822,58 @@ var ye = class {
1826
1822
  t();
1827
1823
  } catch {}
1828
1824
  }
1829
- assertActiveCall(t) {
1830
- if (t === void 0 || t.state !== "active") throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t?.callId });
1825
+ assertActiveCall(e) {
1826
+ if (e === void 0 || e.state !== "active") throw new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: e?.callId });
1831
1827
  }
1832
1828
  assertDeviceSelectionCapability(e) {
1833
1829
  if (e.capabilities === void 0 || !e.capabilities.has("device_selection")) throw this.capabilityError(e.callId);
1834
1830
  }
1835
- capabilityError(t) {
1836
- return new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: t });
1831
+ capabilityError(e) {
1832
+ return new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: e });
1837
1833
  }
1838
- callOperationError(t) {
1839
- return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1834
+ callOperationError(e) {
1835
+ return new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: e });
1840
1836
  }
1841
1837
  assertNotDisposed() {
1842
- if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1838
+ if (this.disposed || this.disposing) throw new n("SDK_ALREADY_DISPOSED", "internal", !1);
1843
1839
  }
1844
1840
  };
1845
- function be(e) {
1841
+ function Oe(e) {
1846
1842
  return "peerConnection" in e;
1847
1843
  }
1848
- function H(e) {
1844
+ function I(e) {
1849
1845
  try {
1850
1846
  return e.track;
1851
1847
  } catch {
1852
1848
  return null;
1853
1849
  }
1854
1850
  }
1855
- function U(e) {
1851
+ function L(e) {
1856
1852
  return typeof e == "object" && !!e && e.name === "InvalidStateError";
1857
1853
  }
1858
- function W(e) {
1854
+ function R(e) {
1859
1855
  try {
1860
1856
  return e.replaceTrack(null).catch((e) => {
1861
- if (!U(e)) throw e;
1857
+ if (!L(e)) throw e;
1862
1858
  });
1863
1859
  } catch (e) {
1864
- return U(e) ? Promise.resolve() : Promise.reject(e);
1860
+ return L(e) ? Promise.resolve() : Promise.reject(e);
1865
1861
  }
1866
1862
  }
1867
- function xe(e) {
1863
+ function ke(e) {
1868
1864
  try {
1869
- G(e.getTracks());
1865
+ z(e.getTracks());
1870
1866
  } catch {}
1871
1867
  }
1872
- function G(e) {
1873
- e.forEach(K);
1868
+ function z(e) {
1869
+ e.forEach(B);
1874
1870
  }
1875
- function K(e) {
1871
+ function B(e) {
1876
1872
  try {
1877
1873
  e.stop();
1878
1874
  } catch {}
1879
1875
  }
1880
- function Se(e) {
1876
+ function Ae(e) {
1881
1877
  if (typeof MediaStream < "u") try {
1882
1878
  return new MediaStream([e]);
1883
1879
  } catch {
@@ -1886,8 +1882,8 @@ function Se(e) {
1886
1882
  }
1887
1883
  //#endregion
1888
1884
  //#region src/core/mediaBridge.ts
1889
- function Ce(t, n = {}) {
1890
- 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 ye({ getActiveCall: u });
1885
+ function V(e, t = {}) {
1886
+ let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = t.ownershipRequired === !0, s = !1, c = !1, l, u = () => e(), d = new De({ getActiveCall: u });
1891
1887
  return {
1892
1888
  publicMedia: {
1893
1889
  requestPermission: () => (f(), d.requestPermission()),
@@ -1900,7 +1896,7 @@ function Ce(t, n = {}) {
1900
1896
  releaseAll: () => (f(), d.releaseAll())
1901
1897
  },
1902
1898
  registerCall(e, t) {
1903
- s || c || !q(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1899
+ s || c || !H(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1904
1900
  },
1905
1901
  async setCallOwnership(e, t) {
1906
1902
  if (s) return;
@@ -1940,12 +1936,12 @@ function Ce(t, n = {}) {
1940
1936
  }
1941
1937
  };
1942
1938
  function f() {
1943
- if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1939
+ if (s) throw new n("SDK_ALREADY_DISPOSED", "internal", !1);
1944
1940
  }
1945
1941
  function p(e, t) {
1946
- if (!q(t) || typeof t.getMediaRegistration != "function") return;
1942
+ if (!H(t) || typeof t.getMediaRegistration != "function") return;
1947
1943
  let n = t.getMediaRegistration();
1948
- if (we(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1944
+ if (je(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1949
1945
  r.set(e, n);
1950
1946
  try {
1951
1947
  d.registerCallMedia(e, n);
@@ -1955,22 +1951,22 @@ function Ce(t, n = {}) {
1955
1951
  }
1956
1952
  }
1957
1953
  }
1958
- function q(e) {
1954
+ function H(e) {
1959
1955
  return typeof e == "object" && !!e;
1960
1956
  }
1961
- function we(e) {
1957
+ function je(e) {
1962
1958
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
1963
1959
  }
1964
1960
  //#endregion
1965
1961
  //#region src/reconnect/backoff.ts
1966
- var Te = 1e3, Ee = 3e4;
1967
- function De(e, t = Math.random) {
1968
- let n = Math.min(Ee, Te * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
1962
+ var Me = 1e3, Ne = 3e4;
1963
+ function Pe(e, t = Math.random) {
1964
+ let n = Math.min(Ne, Me * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
1969
1965
  return Math.round(n * (1 + r * .2));
1970
1966
  }
1971
1967
  //#endregion
1972
1968
  //#region src/reconnect/ReconnectManager.ts
1973
- var Oe = class {
1969
+ var Fe = class {
1974
1970
  recover;
1975
1971
  isRecovered;
1976
1972
  random;
@@ -1988,7 +1984,7 @@ var Oe = class {
1988
1984
  }
1989
1985
  start() {
1990
1986
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
1991
- let e = this.generation, t = De(this.attempt, this.random);
1987
+ let e = this.generation, t = Pe(this.attempt, this.random);
1992
1988
  this.pendingTimer = setTimeout(() => {
1993
1989
  this.pendingTimer = void 0, this.run(e);
1994
1990
  }, t);
@@ -2030,13 +2026,13 @@ var Oe = class {
2030
2026
  clearPendingTimer() {
2031
2027
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
2032
2028
  }
2033
- }, ke = 12e4, Ae = 5e3, je = class t {
2029
+ }, Ie = 12e4, Le = 5e3, Re = class r {
2034
2030
  media;
2035
2031
  options;
2036
2032
  api;
2037
2033
  suppliedSip;
2038
2034
  sip;
2039
- events = new i();
2035
+ events = new o();
2040
2036
  mediaBridge;
2041
2037
  reconnect;
2042
2038
  diagnostics;
@@ -2067,28 +2063,29 @@ var Oe = class {
2067
2063
  ownedSessionIds = /* @__PURE__ */ new Set();
2068
2064
  terminalReleaseOperations = /* @__PURE__ */ new Map();
2069
2065
  sharedWorkerSelection;
2070
- constructor(t) {
2071
- if (this.options = t, t.api === void 0 && t.sessionProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 sessionProvider" });
2072
- this.api = t.api === void 0 ? Y(Ne(t.sessionProvider)) : Y(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : Pe(t.sip), this.mediaBridge = Ce(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new Oe({
2066
+ constructor(r) {
2067
+ if (this.options = r, t(e(r.locale)), r.api === void 0 && r.sessionProvider === void 0) throw new n("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 sessionProvider" });
2068
+ this.api = r.api === void 0 ? U(Ve(r.sessionProvider)) : U(r.api), this.suppliedSip = r.sip === void 0 ? void 0 : He(r.sip), this.mediaBridge = V(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new Fe({
2073
2069
  recover: () => this.recoverConnection(),
2074
2070
  isRecovered: () => this.state === "connected",
2075
2071
  onAttempt: (e) => {
2076
2072
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
2077
2073
  }
2078
- }), this.diagnostics = new r({
2074
+ }), this.diagnostics = new a({
2079
2075
  getSnapshot: () => this.createDiagnosticsSnapshot(),
2080
2076
  getPermission: () => this.readMicrophonePermission(),
2081
2077
  getDeviceNames: async () => (await this.media.getDevices()).map((e) => e.label).filter((e) => e !== "")
2082
- }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2078
+ }), this.sharedWorkerSelection = r.sharedWorker === void 0 ? {
2083
2079
  mode: "single-tab",
2084
2080
  reason: "disabled"
2085
2081
  } : T({
2086
- ...t.sharedWorker,
2087
- ...t.sharedWorkerHost ?? {}
2082
+ ...r.sharedWorker,
2083
+ ...r.sharedWorkerHost ?? {},
2084
+ locale: e(r.locale)
2088
2085
  });
2089
2086
  }
2090
2087
  static async checkSupport() {
2091
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = J(typeof navigator < "u" ? navigator.userAgent : "");
2088
+ let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Be(typeof navigator < "u" ? navigator.userAgent : "");
2092
2089
  return {
2093
2090
  supported: e && t,
2094
2091
  platform: n,
@@ -2099,7 +2096,7 @@ var Oe = class {
2099
2096
  }
2100
2097
  async initialize() {
2101
2098
  if (this.assertNotDisposed(), this.initialized) return;
2102
- let e = await t.checkSupport();
2099
+ let e = await r.checkSupport();
2103
2100
  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;
2104
2101
  }
2105
2102
  connect() {
@@ -2133,23 +2130,23 @@ var Oe = class {
2133
2130
  recover() {
2134
2131
  return this.assertNotDisposed(), this.recoverConnection();
2135
2132
  }
2136
- dial(t) {
2133
+ dial(e) {
2137
2134
  this.assertConnected();
2138
- let n = this.callManager, r = this.session;
2139
- if (n === void 0 || r === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2140
- return n.dial(t, r);
2135
+ let t = this.callManager, r = this.session;
2136
+ if (t === void 0 || r === void 0) throw new n("CALL_NOT_CONNECTED", "call", !1);
2137
+ return t.dial(e, r);
2141
2138
  }
2142
- answer(t, n) {
2139
+ answer(e, t) {
2143
2140
  this.assertConnected();
2144
2141
  let r = this.callManager, i = this.session;
2145
- if (r === void 0 || i === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2146
- return r.answer(t, i, n);
2142
+ if (r === void 0 || i === void 0) throw new n("CALL_NOT_CONNECTED", "call", !1);
2143
+ return r.answer(e, i, t);
2147
2144
  }
2148
- setActiveCall(t) {
2145
+ setActiveCall(e) {
2149
2146
  this.assertConnected();
2150
- let n = this.callManager;
2151
- if (n === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2152
- return n.setActiveCall(t);
2147
+ let t = this.callManager;
2148
+ if (t === void 0) throw new n("CALL_NOT_CONNECTED", "call", !1);
2149
+ return t.setActiveCall(e);
2153
2150
  }
2154
2151
  getCalls() {
2155
2152
  return this.callManager?.getCalls() ?? [];
@@ -2173,13 +2170,13 @@ var Oe = class {
2173
2170
  getDiagnostics(e = {}) {
2174
2171
  return this.diagnostics.getReport(e);
2175
2172
  }
2176
- async setAgentStatus(t) {
2177
- if (this.assertNotDisposed(), t !== "available" && t !== "offline" && t !== "break") throw new e("CONFIG_INVALID", "configuration", !1, { cause: `Unsupported agent status: ${String(t)}` });
2178
- let n = this.session?.transport.wssUrl;
2173
+ async setAgentStatus(e) {
2174
+ if (this.assertNotDisposed(), e !== "available" && e !== "offline" && e !== "break") throw new n("CONFIG_INVALID", "configuration", !1, { cause: `Unsupported agent status: ${String(e)}` });
2175
+ let t = this.session?.transport.wssUrl;
2179
2176
  await this.api.setAgentStatus({
2180
- status: t,
2177
+ status: e,
2181
2178
  reason: ""
2182
- }, n === void 0 ? void 0 : { wssUrl: n }), this.disposed || this.events.emit("agent.statusChanged", { status: t });
2179
+ }, t === void 0 ? void 0 : { wssUrl: t }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
2183
2180
  }
2184
2181
  on(e, t) {
2185
2182
  return this.disposed ? () => void 0 : this.events.on(e, t);
@@ -2188,22 +2185,22 @@ var Oe = class {
2188
2185
  this.events.off(e, t);
2189
2186
  }
2190
2187
  async performConnect(e) {
2191
- let t, r, i;
2188
+ let t, n, r;
2192
2189
  try {
2193
2190
  await this.initialize(), this.assertGeneration(e);
2194
2191
  let a = this.resolvePlatform();
2195
2192
  this.intentionalDisconnect = !1, this.acceptingEvents = !0, this.setConnectionState("connecting"), t = await this.api.createSession({
2196
- sdkVersion: n,
2193
+ sdkVersion: i,
2197
2194
  platform: a === "mobile-web" ? "mobile_web" : "web",
2198
2195
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2199
- requestedCapabilities: [...this.options.requestedCapabilities ?? Re(a)]
2200
- }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2201
- let o = this.callManager ?? this.createCallManager(r, t, a);
2202
- 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);
2203
- } catch (n) {
2204
- if (await this.rollbackConnect(t, r, i), this.disposed) throw this.disposedError();
2205
- if (e !== this.lifecycleGeneration) throw n;
2206
- let a = Z(n, "REGISTRATION_FAILED", "registration", !0);
2196
+ requestedCapabilities: [...this.options.requestedCapabilities ?? Ke(a)]
2197
+ }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), n = await this.getSip(), this.assertGeneration(e), this.session = t;
2198
+ let o = this.callManager ?? this.createCallManager(n, t, a);
2199
+ this.callManager === void 0 && (r = o), o.updateSession(t), this.callManager = o, 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);
2200
+ } catch (i) {
2201
+ if (await this.rollbackConnect(t, n, r), this.disposed) throw this.disposedError();
2202
+ if (e !== this.lifecycleGeneration) throw i;
2203
+ let a = G(i, "REGISTRATION_FAILED", "registration", !0);
2207
2204
  throw this.setConnectionState("failed"), this.events.emit("connection.failed", { error: a }), a;
2208
2205
  }
2209
2206
  }
@@ -2212,13 +2209,13 @@ var Oe = class {
2212
2209
  if (t !== void 0) try {
2213
2210
  await t;
2214
2211
  } catch (t) {
2215
- $(t) || (e ??= t);
2212
+ q(t) || (e ??= t);
2216
2213
  }
2217
2214
  let n = this.refreshOperation;
2218
2215
  if (n !== void 0) try {
2219
2216
  await n;
2220
2217
  } catch (t) {
2221
- $(t) || (e ??= t);
2218
+ q(t) || (e ??= t);
2222
2219
  }
2223
2220
  this.reconnect.cancel(), this.stuckCallsSince = void 0, this.clearRefreshTimer(), this.intentionalDisconnect = !0, this.detachNetworkListeners(), this.detachSipListener(), this.detachManagerListeners();
2224
2221
  let r = this.callManager, i = this.sip;
@@ -2247,7 +2244,7 @@ var Oe = class {
2247
2244
  if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
2248
2245
  }
2249
2246
  createCallManager(e, t, n) {
2250
- let r = new v({
2247
+ let r = new x({
2251
2248
  sip: e,
2252
2249
  platform: n,
2253
2250
  session: t,
@@ -2285,7 +2282,7 @@ var Oe = class {
2285
2282
  for (let n of t) try {
2286
2283
  await n;
2287
2284
  } catch (t) {
2288
- $(t) || (e ??= t);
2285
+ q(t) || (e ??= t);
2289
2286
  }
2290
2287
  let n = this.callManager;
2291
2288
  this.callManager = void 0;
@@ -2302,7 +2299,7 @@ var Oe = class {
2302
2299
  try {
2303
2300
  await this.media.releaseAll();
2304
2301
  } catch (t) {
2305
- Fe(t) || (e ??= t);
2302
+ Ue(t) || (e ??= t);
2306
2303
  }
2307
2304
  try {
2308
2305
  await this.mediaBridge.dispose();
@@ -2334,15 +2331,15 @@ var Oe = class {
2334
2331
  }
2335
2332
  if (e !== void 0) throw e;
2336
2333
  }
2337
- withBarrierTimeout(t, n, r = Ae) {
2334
+ withBarrierTimeout(e, t, r = Le) {
2338
2335
  return new Promise((i, a) => {
2339
2336
  let o = setTimeout(() => {
2340
- a(new e("SDK_INTERNAL_ERROR", "internal", !0, {
2341
- callId: n,
2337
+ a(new n("SDK_INTERNAL_ERROR", "internal", !0, {
2338
+ callId: t,
2342
2339
  cause: "media release barrier timeout"
2343
2340
  }));
2344
2341
  }, Math.max(0, r));
2345
- t.then((e) => {
2342
+ e.then((e) => {
2346
2343
  clearTimeout(o), i(e);
2347
2344
  }, (e) => {
2348
2345
  clearTimeout(o), a(e);
@@ -2395,7 +2392,7 @@ var Oe = class {
2395
2392
  let n = this.mediaBridge.releaseCall(e).then(() => {
2396
2393
  this.terminalReleaseOperations.get(e) === n && this.terminalReleaseOperations.delete(e);
2397
2394
  }).catch((t) => {
2398
- throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: Z(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
2395
+ throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: G(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
2399
2396
  });
2400
2397
  return this.terminalReleaseOperations.set(e, n), n;
2401
2398
  }
@@ -2439,8 +2436,8 @@ var Oe = class {
2439
2436
  }
2440
2437
  handleRefreshFailure(e, t) {
2441
2438
  if (this.disposed) return;
2442
- let n = Z(t, "NETWORK_OFFLINE", "network", !0);
2443
- if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), Q(t)) {
2439
+ let n = G(t, "NETWORK_OFFLINE", "network", !0);
2440
+ if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), K(t)) {
2444
2441
  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" || n.code === "AUTH_TOKEN_REJECTED") && this.api.invalidateToken?.();
2445
2442
  return;
2446
2443
  }
@@ -2452,7 +2449,7 @@ var Oe = class {
2452
2449
  try {
2453
2450
  await this.performDisconnect();
2454
2451
  } catch (e) {
2455
- this.disposed || this.events.emit("error", { error: Z(e, "SDK_INTERNAL_ERROR", "internal", !0) });
2452
+ this.disposed || this.events.emit("error", { error: G(e, "SDK_INTERNAL_ERROR", "internal", !0) });
2456
2453
  return;
2457
2454
  }
2458
2455
  if (!this.disposed) try {
@@ -2473,7 +2470,7 @@ var Oe = class {
2473
2470
  if (!(this.disposed || this.intentionalDisconnect)) {
2474
2471
  if (this.hasNonTerminalCalls()) {
2475
2472
  let e = Date.now();
2476
- if (this.stuckCallsSince === void 0 && (this.stuckCallsSince = e), e - this.stuckCallsSince < ke) return;
2473
+ if (this.stuckCallsSince === void 0 && (this.stuckCallsSince = e), e - this.stuckCallsSince < Ie) return;
2477
2474
  this.stuckCallsSince = void 0, await this.callManager?.forceTerminateCalls();
2478
2475
  } else this.stuckCallsSince = void 0;
2479
2476
  if (await this.awaitMediaReleaseBarriers(), this.session === void 0) {
@@ -2486,7 +2483,7 @@ var Oe = class {
2486
2483
  async getSip() {
2487
2484
  if (this.sip !== void 0) return this.sip;
2488
2485
  if (this.suppliedSip !== void 0) return this.sip = this.suppliedSip, this.sip;
2489
- let [e, t] = await Promise.all([import("./createJsSipFactory-CoWZN-BC.js"), import("./JsSipAdapter-B8ueIoBA.js")]);
2486
+ let [e, t] = await Promise.all([import("./createJsSipFactory-9CPsweDR.js"), import("./JsSipAdapter-CiqM4KOq.js")]);
2490
2487
  return this.sip = new t.JsSipAdapter(e.createJsSipFactory(), this.options.baseUrl, this.options.sipKeepaliveSeconds, this.options.agentTerminal, this.options.sipSessionTimers ?? !1), this.sip;
2491
2488
  }
2492
2489
  attachSipListener(e) {
@@ -2496,7 +2493,7 @@ var Oe = class {
2496
2493
  this.setConnectionState("connected");
2497
2494
  return;
2498
2495
  }
2499
- this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: Z(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
2496
+ this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: G(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
2500
2497
  }
2501
2498
  }));
2502
2499
  }
@@ -2541,7 +2538,7 @@ var Oe = class {
2541
2538
  destination: e.destination
2542
2539
  })),
2543
2540
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2544
- ice: Me(e, this.sip?.iceQualitySnapshot?.()),
2541
+ ice: ze(e, this.sip?.iceQualitySnapshot?.()),
2545
2542
  wss: {
2546
2543
  configured: e !== void 0,
2547
2544
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2581,7 +2578,7 @@ var Oe = class {
2581
2578
  let n = this.api.deleteSession(e).then(() => {
2582
2579
  this.deletedSessions.add(e);
2583
2580
  }).catch((t) => {
2584
- if (Q(t)) {
2581
+ if (K(t)) {
2585
2582
  this.deletedSessions.add(e);
2586
2583
  return;
2587
2584
  }
@@ -2604,19 +2601,19 @@ var Oe = class {
2604
2601
  if (e !== void 0) throw e;
2605
2602
  }
2606
2603
  resolvePlatform() {
2607
- let t = this.options.platform ?? this.detectedPlatform;
2608
- if (t === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: this.support?.platform ?? "unknown" });
2609
- return t;
2604
+ let e = this.options.platform ?? this.detectedPlatform;
2605
+ if (e === void 0) throw new n("CONFIG_INVALID", "configuration", !1, { cause: this.support?.platform ?? "unknown" });
2606
+ return e;
2610
2607
  }
2611
2608
  setConnectionState(e) {
2612
2609
  this.state === e || this.disposed || (this.state = e, this.diagnostics.log("info", "connection.stateChanged", { state: e }), this.events.emit("connection.stateChanged", { state: e === "disconnected" || e === "idle" ? "offline" : e }));
2613
2610
  }
2614
2611
  assertConnected() {
2615
- if (this.assertNotDisposed(), this.state !== "connected" || this.callManager === void 0 || this.session === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2612
+ if (this.assertNotDisposed(), this.state !== "connected" || this.callManager === void 0 || this.session === void 0) throw new n("CALL_NOT_CONNECTED", "call", !1);
2616
2613
  }
2617
- assertGeneration(t) {
2614
+ assertGeneration(e) {
2618
2615
  if (this.disposed) throw this.disposedError();
2619
- if (t !== this.lifecycleGeneration) throw new e("CALL_NOT_CONNECTED", "call", !1);
2616
+ if (e !== this.lifecycleGeneration) throw new n("CALL_NOT_CONNECTED", "call", !1);
2620
2617
  }
2621
2618
  isCurrentGeneration(e) {
2622
2619
  return !this.disposed && e === this.lifecycleGeneration;
@@ -2655,10 +2652,10 @@ var Oe = class {
2655
2652
  if (this.disposed) throw this.disposedError();
2656
2653
  }
2657
2654
  disposedError() {
2658
- return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2655
+ return new n("SDK_ALREADY_DISPOSED", "internal", !1);
2659
2656
  }
2660
2657
  };
2661
- function Me(e, t) {
2658
+ function ze(e, t) {
2662
2659
  if (e === void 0) return {
2663
2660
  configured: !1,
2664
2661
  serverCount: 0,
@@ -2678,17 +2675,17 @@ function Me(e, t) {
2678
2675
  turnServerCount: r
2679
2676
  };
2680
2677
  }
2681
- function J(e) {
2678
+ function Be(e) {
2682
2679
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2683
2680
  }
2684
- function Y(t) {
2685
- if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2686
- return t;
2681
+ function U(e) {
2682
+ if (typeof e != "object" || !e) throw new n("CONFIG_INVALID", "configuration", !1);
2683
+ return e;
2687
2684
  }
2688
- async function X(e) {
2685
+ async function W(e) {
2689
2686
  let t = e.sip?.registerTicket;
2690
2687
  if (typeof t != "string" || t === "") return e;
2691
- let n = await ue(t);
2688
+ let n = await de(t);
2692
2689
  return n === void 0 || n === t ? e : {
2693
2690
  ...e,
2694
2691
  sip: {
@@ -2697,47 +2694,47 @@ async function X(e) {
2697
2694
  }
2698
2695
  };
2699
2696
  }
2700
- function Ne(t) {
2701
- let r = {
2702
- createSession: async (e) => X(await t.createSession(e)),
2703
- refreshSession: async (e) => X(t.refreshSession === void 0 ? await t.createSession({
2704
- sdkVersion: n,
2697
+ function Ve(e) {
2698
+ let t = {
2699
+ createSession: async (t) => W(await e.createSession(t)),
2700
+ refreshSession: async (t) => W(e.refreshSession === void 0 ? await e.createSession({
2701
+ sdkVersion: i,
2705
2702
  platform: "web"
2706
- }) : await t.refreshSession(e)),
2707
- deleteSession: async (e) => {
2708
- t.deleteSession !== void 0 && await t.deleteSession(e);
2703
+ }) : await e.refreshSession(t)),
2704
+ deleteSession: async (t) => {
2705
+ e.deleteSession !== void 0 && await e.deleteSession(t);
2709
2706
  },
2710
- setAgentStatus: (n, r) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n, r)
2711
- }, i = t.invalidateToken;
2712
- return i !== void 0 && (r.invalidateToken = () => i()), r;
2707
+ setAgentStatus: (t, r) => e.setAgentStatus === void 0 ? Promise.reject(new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : e.setAgentStatus(t, r)
2708
+ }, r = e.invalidateToken;
2709
+ return r !== void 0 && (t.invalidateToken = () => r()), t;
2713
2710
  }
2714
- function Pe(t) {
2715
- if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2716
- return t;
2711
+ function He(e) {
2712
+ if (typeof e != "object" || !e) throw new n("CONFIG_INVALID", "configuration", !1);
2713
+ return e;
2717
2714
  }
2718
- function Z(t, n, r, i, a) {
2719
- return t instanceof e ? new e(t.code, t.category, t.retryable, {
2720
- requestId: t.requestId,
2721
- callId: a ?? t.callId,
2722
- cause: t.cause ?? t,
2723
- serverCode: t.serverCode,
2724
- platformCode: t.platformCode,
2725
- status: t.status
2726
- }) : new e(n, r, i, {
2715
+ function G(e, t, r, i, a) {
2716
+ return e instanceof n ? new n(e.code, e.category, e.retryable, {
2717
+ requestId: e.requestId,
2718
+ callId: a ?? e.callId,
2719
+ cause: e.cause ?? e,
2720
+ serverCode: e.serverCode,
2721
+ platformCode: e.platformCode,
2722
+ status: e.status
2723
+ }) : new n(t, r, i, {
2727
2724
  callId: a,
2728
- cause: t
2725
+ cause: e
2729
2726
  });
2730
2727
  }
2731
- function Q(t) {
2732
- 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" || t.code === "AUTH_TOKEN_REJECTED" : !1;
2728
+ function K(e) {
2729
+ return e instanceof n ? e.status !== void 0 && e.status >= 400 && e.status < 500 || e.serverCode === "SESSION_NOT_FOUND" || e.serverCode === "SESSION_EXPIRED" || e.serverCode === "TOKEN_INVALID" || e.serverCode === "TOKEN_EXPIRED" || e.code === "AUTH_TOKEN_UNAVAILABLE" || e.code === "AUTH_TOKEN_EXPIRED" || e.code === "AUTH_TOKEN_REJECTED" : !1;
2733
2730
  }
2734
- function Fe(t) {
2735
- return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2731
+ function Ue(e) {
2732
+ return e instanceof n && e.code === "SDK_ALREADY_DISPOSED";
2736
2733
  }
2737
- function $(t) {
2738
- return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
2734
+ function q(e) {
2735
+ return e instanceof n && (e.code === "SDK_ALREADY_DISPOSED" || e.code === "CALL_NOT_CONNECTED");
2739
2736
  }
2740
- var Ie = [
2737
+ var We = [
2741
2738
  "outbound",
2742
2739
  "inbound",
2743
2740
  "mute",
@@ -2745,13 +2742,293 @@ var Ie = [
2745
2742
  "dtmf",
2746
2743
  "blind_transfer",
2747
2744
  "device_selection"
2748
- ], Le = [
2745
+ ], Ge = [
2749
2746
  "outbound",
2750
2747
  "mute",
2751
2748
  "dtmf"
2752
2749
  ];
2753
- function Re(e) {
2754
- return e === "mobile-web" ? Le : Ie;
2750
+ function Ke(e) {
2751
+ return e === "mobile-web" ? Ge : We;
2752
+ }
2753
+ //#endregion
2754
+ //#region src/legacy/legacySessionProvider.ts
2755
+ var qe = "/openapi/token/v1", Je = "/seat/account/get", Ye = "/seats/set-status", Xe = 3478, Ze = 600, Qe = 600, $e = 180, J = 60, et = 5e3, Y = 2e4, tt = [
2756
+ "outbound",
2757
+ "inbound",
2758
+ "mute",
2759
+ "dtmf",
2760
+ "hold",
2761
+ "blind_transfer"
2762
+ ], nt = {
2763
+ available: {
2764
+ status: "Available",
2765
+ reason: "空闲"
2766
+ },
2767
+ break: {
2768
+ status: "On Break",
2769
+ reason: "休息"
2770
+ },
2771
+ offline: {
2772
+ status: "Logged Out",
2773
+ reason: ""
2774
+ }
2775
+ };
2776
+ function X(e) {
2777
+ let t = it(e.host), r = at(e.pathPrefix ?? qe), i = `${t}${r}${Z(e.accountPath ?? Je)}`, a = `${t}${r}${Z(e.statusPath ?? Ye)}`, o = {
2778
+ ...e.aesKey ? { key: e.aesKey } : {},
2779
+ ...e.aesIv ? { iv: e.aesIv } : {}
2780
+ }, s = Math.max(0, e.refreshBufferSeconds ?? $e), c = e.fetchImpl ?? globalThis.fetch, l, u, d = "";
2781
+ async function f() {
2782
+ if (e.getToken !== void 0) return e.getToken();
2783
+ if (e.tokenUrl !== void 0) {
2784
+ let t = e.tokenMethod ?? "POST", r = {
2785
+ method: t,
2786
+ headers: {
2787
+ Accept: "application/json",
2788
+ ...e.tokenHeaders ?? {}
2789
+ },
2790
+ credentials: "include"
2791
+ };
2792
+ t === "POST" && (r.headers = {
2793
+ "Content-Type": "application/json",
2794
+ ...r.headers
2795
+ }, r.body = JSON.stringify(e.tokenBody ?? {}));
2796
+ let i = await $(c, e.tokenUrl, r, "取 token"), a = await i.text();
2797
+ try {
2798
+ return JSON.parse(a);
2799
+ } catch {
2800
+ throw new n("AUTH_TOKEN_UNAVAILABLE", "auth", !0, {
2801
+ status: i.status,
2802
+ cause: `取 token 的接口返回了非 JSON 响应(HTTP ${i.status}):${a.trim().slice(0, 120)}`
2803
+ });
2804
+ }
2805
+ }
2806
+ throw new n("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 getToken 或 tokenUrl;坐席状态也可以直接用会话软电话地址里的 token(setAgentStatus 的 context.wssUrl),但这次调用没有会话可用" });
2807
+ }
2808
+ async function p() {
2809
+ if (l && l.expiresAtMs - Date.now() > et) return l.token;
2810
+ let e;
2811
+ try {
2812
+ e = await f();
2813
+ } catch (e) {
2814
+ throw e instanceof n ? e : new n("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: e });
2815
+ }
2816
+ let t = st(e);
2817
+ if (!t.token) throw new n("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: "取 token 的返回里没有 token(支持 {token}、{accessToken}、{data:{token}} 或裸字符串)" });
2818
+ let r = Q(t.expires, 3600);
2819
+ return l = {
2820
+ token: t.token,
2821
+ expiresAtMs: Date.now() + r * 1e3
2822
+ }, l.token;
2823
+ }
2824
+ function m(e) {
2825
+ if (!e) return "";
2826
+ try {
2827
+ return String(new URL(e).searchParams.get("token") ?? "").trim();
2828
+ } catch {
2829
+ return "";
2830
+ }
2831
+ }
2832
+ async function h(e) {
2833
+ let t = m(e?.wssUrl);
2834
+ return t ? (d = t, t) : d || p();
2835
+ }
2836
+ async function g(e) {
2837
+ let t = e || await p(), r = await $(c, i, {
2838
+ method: "POST",
2839
+ headers: {
2840
+ Authorization: t,
2841
+ "Content-Type": "application/json",
2842
+ Accept: "application/json"
2843
+ },
2844
+ body: "{}"
2845
+ }, "取坐席账号"), a = await r.text(), o;
2846
+ try {
2847
+ o = JSON.parse(a);
2848
+ } catch {
2849
+ throw new n("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
2850
+ status: r.status,
2851
+ cause: `${i} 返回了非 JSON 响应(HTTP ${r.status});请确认 host 填的是接口网关(不是文档站)`
2852
+ });
2853
+ }
2854
+ let s = Number(o.code ?? NaN);
2855
+ if (!r.ok || s !== 0) {
2856
+ let e = r.status === 401 || s === 401 ? "AUTH_TOKEN_REJECTED" : "LEGACY_PLATFORM_REJECTED";
2857
+ throw new n(e, "auth", s === 50, {
2858
+ status: r.status,
2859
+ serverCode: Number.isFinite(s) ? String(s) : void 0,
2860
+ platformCode: Number.isFinite(s) ? s : void 0,
2861
+ cause: o.message || `取坐席账号失败(HTTP ${r.status})`
2862
+ });
2863
+ }
2864
+ if (!o.data) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号接口没有返回 data" });
2865
+ return u = o.data, u;
2866
+ }
2867
+ let _ = (e) => S(e, o);
2868
+ function v(t) {
2869
+ let r = String(e.sipWsUrl ?? "").trim();
2870
+ if (!r) throw new n("CONFIG_INVALID", "configuration", !1, { cause: "需要 sipWsUrl:软电话 WSS 地址由接入方提供(wss:// 或 ws:// 开头的完整地址)" });
2871
+ let i;
2872
+ try {
2873
+ i = new URL(r);
2874
+ } catch {
2875
+ throw new n("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 不是完整地址(需要 wss:// 或 ws:// 开头):${r}` });
2876
+ }
2877
+ if (i.protocol !== "wss:" && i.protocol !== "ws:") throw new n("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 需要 wss:// 或 ws:// 开头:${r}` });
2878
+ return (e.attachTokenToWss ?? !0) && t && i.searchParams.set("token", t), i.toString();
2879
+ }
2880
+ function y(e) {
2881
+ let t = (Array.isArray(e.iceServers) ? e.iceServers : []).map((e) => {
2882
+ let t = (Array.isArray(e?.urls) ? e.urls : typeof e?.urls == "string" ? [e.urls] : []).map((e) => String(e ?? "").trim()).filter(Boolean);
2883
+ if (t.length !== 0) return {
2884
+ urls: t,
2885
+ ...e?.username ? { username: String(e.username) } : {},
2886
+ ...e?.credential ? { credential: String(e.credential) } : {}
2887
+ };
2888
+ }).filter((e) => e !== void 0);
2889
+ if (t.length > 0) return t;
2890
+ let n = String(e.turnIp ?? "").trim();
2891
+ return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) || Xe}`] }] : [];
2892
+ }
2893
+ async function b() {
2894
+ let r = await p(), i = await g(), a = String(i.username ?? i.account ?? "").trim();
2895
+ if (!a) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
2896
+ let o = String(i.registerPassword ?? i.password ?? ""), c = o ? await _(o) : "";
2897
+ if (!c) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 password/registerPassword,或解密后为空" });
2898
+ let u = Q(i.expiresIn ?? i.expires_in, Qe), f = Math.max(0, Math.round((l.expiresAtMs - Date.now()) / 1e3)), m = Math.max(J, Math.min(f || u, u) - s), h = String(i.domain ?? "").trim() || ot(t), b = v(r);
2899
+ return r && (d = r), {
2900
+ sessionId: `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
2901
+ expiresAt: Math.floor(Date.now() / 1e3) + m,
2902
+ agent: {
2903
+ id: a,
2904
+ externalUserId: a,
2905
+ displayName: a,
2906
+ extension: a,
2907
+ status: "Available"
2908
+ },
2909
+ sip: {
2910
+ uri: `sip:${a}@${h}`,
2911
+ registrar: h,
2912
+ registerTicket: c,
2913
+ registerExpires: Number(e.registerExpires) > 0 ? Number(e.registerExpires) : Ze,
2914
+ ticketExpiresIn: m
2915
+ },
2916
+ transport: {
2917
+ wssUrl: b,
2918
+ ticket: "",
2919
+ ticketExpiresIn: m
2920
+ },
2921
+ iceServers: y(i),
2922
+ policy: {
2923
+ maxConcurrentCalls: Number(e.maxConcurrentCalls) > 0 ? Number(e.maxConcurrentCalls) : 2,
2924
+ incomingEnabled: e.incomingEnabled ?? !0,
2925
+ mobileIncomingEnabled: e.mobileIncomingEnabled ?? !0,
2926
+ backgroundCallingSupported: !1
2927
+ },
2928
+ capabilities: [...e.capabilities ?? tt]
2929
+ };
2930
+ }
2931
+ return {
2932
+ createSession: b,
2933
+ refreshSession: b,
2934
+ setAgentStatus: async ({ status: e, reason: t }, r) => {
2935
+ if (e !== "available" && e !== "offline" && e !== "break") throw new n("CONFIG_INVALID", "configuration", !1, { cause: `Unsupported agent status: ${String(e)}` });
2936
+ let i = await h(r), o = u ?? await g(i), s = String(o.username ?? o.account ?? "").trim();
2937
+ if (!s) throw new n("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
2938
+ let l = nt[e], d = await $(c, a, {
2939
+ method: "POST",
2940
+ headers: {
2941
+ Authorization: i,
2942
+ "Content-Type": "application/json",
2943
+ Accept: "application/json"
2944
+ },
2945
+ body: JSON.stringify({
2946
+ extension: s,
2947
+ status: l.status,
2948
+ reason: t || l.reason
2949
+ })
2950
+ }, "设置坐席状态"), f = await d.text(), p;
2951
+ try {
2952
+ p = JSON.parse(f);
2953
+ } catch {
2954
+ throw new n("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
2955
+ status: d.status,
2956
+ cause: `${a} 返回了非 JSON 响应(HTTP ${d.status})`
2957
+ });
2958
+ }
2959
+ let m = Number(p.code ?? NaN);
2960
+ if (!d.ok || m !== 0) {
2961
+ let e = d.status === 401 || m === 401 ? "AUTH_TOKEN_REJECTED" : "LEGACY_PLATFORM_REJECTED";
2962
+ throw new n(e, "auth", m === 50, {
2963
+ status: d.status,
2964
+ serverCode: Number.isFinite(m) ? String(m) : void 0,
2965
+ platformCode: Number.isFinite(m) ? m : void 0,
2966
+ cause: p.message || `设置坐席状态失败(HTTP ${d.status})`
2967
+ });
2968
+ }
2969
+ },
2970
+ invalidateToken: () => {
2971
+ l = void 0, d = "";
2972
+ },
2973
+ getSeatAccount: async () => u ?? g()
2974
+ };
2975
+ }
2976
+ function rt(e) {
2977
+ return X(e);
2978
+ }
2979
+ function it(e) {
2980
+ let t = String(e ?? "").trim().replace(/\/+$/, "");
2981
+ if (!t) throw new n("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 host" });
2982
+ return /^https?:\/\//i.test(t) ? t : `https://${t}`;
2983
+ }
2984
+ function at(e) {
2985
+ let t = String(e ?? "").trim();
2986
+ return !t || t === "/" ? "" : `/${t.replace(/^\/+|\/+$/g, "")}`;
2987
+ }
2988
+ function Z(e) {
2989
+ let t = String(e ?? "").trim();
2990
+ return t.startsWith("/") ? t : `/${t}`;
2991
+ }
2992
+ function ot(e) {
2993
+ try {
2994
+ return new URL(e).hostname;
2995
+ } catch {
2996
+ return "";
2997
+ }
2998
+ }
2999
+ function Q(e, t) {
3000
+ let n = Number(e);
3001
+ return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n), J), 86400));
3002
+ }
3003
+ function st(e) {
3004
+ if (typeof e == "string") return { token: e.trim() };
3005
+ let t = e ?? {}, n = typeof t.data == "object" && t.data !== null ? t.data : void 0;
3006
+ for (let e of [t, n]) {
3007
+ if (e === void 0) continue;
3008
+ let t = e.token ?? e.accessToken;
3009
+ if (typeof t == "string" && t.trim()) {
3010
+ let n = Number(e.expires ?? e.expiresIn ?? e.expires_at);
3011
+ return {
3012
+ token: t.trim(),
3013
+ ...Number.isFinite(n) && n > 0 ? { expires: n } : {}
3014
+ };
3015
+ }
3016
+ }
3017
+ return { token: "" };
3018
+ }
3019
+ async function $(e, t, r, i) {
3020
+ let a = new AbortController(), o = setTimeout(() => a.abort(), Y);
3021
+ try {
3022
+ return await e(t, {
3023
+ ...r,
3024
+ signal: a.signal
3025
+ });
3026
+ } catch (e) {
3027
+ let r = a.signal.aborted;
3028
+ throw new n(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${Y / 1e3} 秒):POST ${t}` : `${i}失败:无法请求 ${t}(${e instanceof Error ? e.message : String(e)})` });
3029
+ } finally {
3030
+ clearTimeout(o);
3031
+ }
2755
3032
  }
2756
3033
  //#endregion
2757
- export { v as a, s as c, a as d, i as f, x as i, o as l, T as n, f as o, E as r, c as s, je as t, l as u };
3034
+ export { E as a, m as c, c as d, d as f, T as i, u as l, o as m, X as n, S as o, s as p, Re as r, x as s, rt as t, l as u };