@16x/webphone-sdk 3.1.17 → 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 -31
  2. package/LICENSE +1 -1
  3. package/README.md +214 -161
  4. package/dist/{Diagnostics-CK0ai_sy.cjs → Diagnostics-CgDSPlQx.cjs} +1 -1
  5. package/dist/{Diagnostics-B6xGNl8M.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-C2sC86Xi.js → legacySessionProvider-DBrRBB3S.js} +795 -493
  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-GQ3yxDur.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-B6xGNl8M.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: re(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,85 +909,104 @@ 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(t, n) {
917
- if (t instanceof e) return new e(t.code, t.category, t.retryable, {
918
- requestId: t.requestId,
919
- callId: n,
920
- cause: t.cause ?? t,
921
- serverCode: t.serverCode,
922
- platformCode: t.platformCode,
923
- status: t.status
917
+ function ie(e) {
918
+ if (typeof e != "object" || !e) return;
919
+ let { cause: t, cause_code: n, message: r } = e, i = typeof n == "number" ? n : void 0, a = typeof t == "string" ? t : void 0;
920
+ if (i === void 0 && typeof r == "object" && r) {
921
+ let e = r.data;
922
+ if (typeof e == "string") {
923
+ let t = /^SIP\/2\.0\s+(\d{3})/m.exec(e);
924
+ if (t) return { code: Number(t[1]) };
925
+ }
926
+ }
927
+ return i === void 0 && a === void 0 ? void 0 : {
928
+ code: i,
929
+ cause: a
930
+ };
931
+ }
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
924
937
  });
925
- if (typeof t == "object" && t && "error" in t) {
926
- let r = t.error;
927
- 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, {
928
941
  requestId: r.requestId,
929
- callId: n,
930
- cause: r.cause ?? r,
931
- serverCode: r.serverCode,
932
- platformCode: r.platformCode,
933
- status: r.status
942
+ callId: t,
943
+ cause: r.cause ?? r
934
944
  });
935
- if (r instanceof Error) return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
936
- callId: n,
945
+ if (r instanceof Error) return new n("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
946
+ callId: t,
937
947
  cause: r
938
948
  });
939
949
  }
940
- return new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, {
941
- callId: n,
942
- 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
943
963
  });
944
964
  }
945
965
  //#endregion
946
966
  //#region src/crypto/legacySipTicket.ts
947
- var ie = "q7X4p6MvK1z8Lb3A", ae = "W9e2T4mN0aQ7Ru6C", oe = 16, se = "�";
948
- function ce(e) {
967
+ var oe = "q7X4p6MvK1z8Lb3A", se = "W9e2T4mN0aQ7Ru6C", ce = 16, le = "�";
968
+ function ue(e) {
949
969
  for (let t of e) {
950
970
  let e = t.codePointAt(0) ?? 0;
951
971
  if (e === 127 || e < 32 && e !== 9) return !0;
952
972
  }
953
973
  return !1;
954
974
  }
955
- async function x(t, n = {}) {
956
- let r = String(t ?? "").replace(/\s+/g, "");
957
- if (!r) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
958
- let i = n.subtle ?? globalThis.crypto?.subtle;
959
- if (i === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
960
- let a = S(r);
961
- if (a === void 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
962
- let o = await i.importKey("raw", C(n.key ?? ie), "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"]);
963
983
  try {
964
984
  let e = await i.decrypt({
965
985
  name: "AES-CBC",
966
- iv: C(n.iv ?? ae)
986
+ iv: w(t.iv ?? se)
967
987
  }, o, a);
968
988
  return new TextDecoder("utf-8").decode(e).trim();
969
- } catch (t) {
970
- 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)}` });
971
991
  }
972
992
  }
973
- async function le(e, t = {}) {
993
+ async function de(e, t = {}) {
974
994
  let n = String(e ?? "").replace(/\s+/g, "");
975
- if (ue(n)) try {
976
- let e = await x(n, t);
977
- return de(e) ? e : void 0;
995
+ if (fe(n)) try {
996
+ let e = await S(n, t);
997
+ return pe(e) ? e : void 0;
978
998
  } catch {
979
999
  return;
980
1000
  }
981
1001
  }
982
- function ue(e) {
983
- let t = S(e);
984
- return t !== void 0 && t.byteLength > 0 && t.byteLength % oe === 0;
1002
+ function fe(e) {
1003
+ let t = C(e);
1004
+ return t !== void 0 && t.byteLength > 0 && t.byteLength % ce === 0;
985
1005
  }
986
- function de(e) {
987
- return e.length === 0 || e.includes(se) ? !1 : !ce(e);
1006
+ function pe(e) {
1007
+ return e.length === 0 || e.includes(le) ? !1 : !ue(e);
988
1008
  }
989
- function S(e) {
1009
+ function C(e) {
990
1010
  if (e.length !== 0 && e.length % 4 == 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(e)) try {
991
1011
  let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length));
992
1012
  for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
@@ -995,13 +1015,13 @@ function S(e) {
995
1015
  return;
996
1016
  }
997
1017
  }
998
- function C(e) {
1018
+ function w(e) {
999
1019
  let t = new TextEncoder().encode(e), n = new Uint8Array(new ArrayBuffer(t.byteLength));
1000
1020
  return n.set(t), n;
1001
1021
  }
1002
1022
  //#endregion
1003
1023
  //#region src/shared/SharedWorkerClient.ts
1004
- var fe = class {
1024
+ var me = class {
1005
1025
  port;
1006
1026
  timeoutMs;
1007
1027
  pending = /* @__PURE__ */ new Map();
@@ -1011,16 +1031,16 @@ var fe = class {
1011
1031
  constructor(e, t = {}) {
1012
1032
  this.port = e, this.timeoutMs = t.timeoutMs ?? 15e3, this.port.onmessage = (e) => this.handleMessage(e.data), this.port.start();
1013
1033
  }
1014
- request(t) {
1015
- 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) => {
1016
1036
  let i = setTimeout(() => {
1017
- 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 }));
1018
1038
  }, this.timeoutMs);
1019
- this.pending.set(t.requestId, {
1020
- resolve: (e) => n(e),
1039
+ this.pending.set(e.requestId, {
1040
+ resolve: (e) => t(e),
1021
1041
  reject: r,
1022
1042
  timer: i
1023
- }), this.port.postMessage(t);
1043
+ }), this.port.postMessage(e);
1024
1044
  });
1025
1045
  }
1026
1046
  onEvent(e) {
@@ -1030,21 +1050,21 @@ var fe = class {
1030
1050
  return this.lifecycleState;
1031
1051
  }
1032
1052
  close() {
1033
- this.closed || (this.closed = !0, this.pending.forEach((t) => {
1034
- 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));
1035
1055
  }), this.pending.clear(), this.eventHandlers.clear(), this.port.close());
1036
1056
  }
1037
1057
  handleMessage(e) {
1038
1058
  try {
1039
- let n = t(e);
1040
- if (n.type === "event") {
1041
- n.event === "connection.stateChanged" && pe(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));
1042
1062
  return;
1043
1063
  }
1044
- if (n.type !== "response") return;
1045
- let r = this.pending.get(n.requestId);
1046
- if (r === void 0) return;
1047
- this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(me(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));
1048
1068
  } catch (e) {
1049
1069
  this.pending.forEach((t) => {
1050
1070
  clearTimeout(t.timer), t.reject(e);
@@ -1052,48 +1072,49 @@ var fe = class {
1052
1072
  }
1053
1073
  }
1054
1074
  };
1055
- function pe(e) {
1075
+ function he(e) {
1056
1076
  return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1057
1077
  }
1058
- function me(t) {
1059
- let n = t.error;
1060
- return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1061
- requestId: t.requestId,
1062
- ...n?.message === void 0 ? {} : { cause: n.message },
1063
- ...n?.serverCode === void 0 ? {} : { serverCode: n.serverCode },
1064
- ...n?.platformCode === void 0 ? {} : { platformCode: n.platformCode },
1065
- ...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 }
1066
1086
  });
1067
1087
  }
1068
1088
  //#endregion
1069
1089
  //#region src/shared/SharedWorkerFactory.ts
1070
- function w(t = {}) {
1071
- if ((t.enabled ?? "auto") === !1) return {
1090
+ function T(e = {}) {
1091
+ if ((e.enabled ?? "auto") === !1) return {
1072
1092
  mode: "single-tab",
1073
1093
  reason: "disabled"
1074
1094
  };
1075
- let n = t.locationHref ?? E(), r = T(t.url, n), i = (n) => {
1076
- 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 });
1077
1097
  return {
1078
1098
  mode: "single-tab",
1079
- reason: n
1099
+ reason: t
1080
1100
  };
1081
1101
  };
1082
1102
  if (r === void 0) return i("SharedWorker URL is unavailable");
1083
- if (!O(r, n)) return i("SharedWorker URL must be same-origin");
1084
- let a = t.workerCtor ?? D();
1103
+ if (!ve(r, t)) return i("SharedWorker URL must be same-origin");
1104
+ let a = e.workerCtor ?? _e();
1085
1105
  if (a === void 0) return i("SharedWorker is not supported");
1086
1106
  let o;
1087
1107
  try {
1088
- 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 });
1089
1109
  } catch (e) {
1090
1110
  return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1091
1111
  }
1092
- let s = t.tabId ?? k(), c = new fe(o.port), l = {
1112
+ let s = e.tabId ?? ye(), c = new me(o.port), l = {
1093
1113
  version: 1,
1094
1114
  type: "attach",
1095
- requestId: A(),
1096
- tabId: s
1115
+ requestId: be(),
1116
+ tabId: s,
1117
+ ...e.locale === void 0 ? {} : { locale: e.locale }
1097
1118
  }, u = c.request(l).then(() => void 0).catch((e) => {
1098
1119
  throw c.close(), e;
1099
1120
  });
@@ -1106,20 +1127,20 @@ function w(t = {}) {
1106
1127
  ready: u
1107
1128
  };
1108
1129
  }
1109
- function T(e, t = E()) {
1130
+ function E(e, t = D()) {
1110
1131
  try {
1111
1132
  return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
1112
1133
  } catch {
1113
1134
  return;
1114
1135
  }
1115
1136
  }
1116
- function E() {
1137
+ function D() {
1117
1138
  return typeof location > "u" ? void 0 : location.href;
1118
1139
  }
1119
- function D() {
1140
+ function _e() {
1120
1141
  if (typeof SharedWorker == "function") return SharedWorker;
1121
1142
  }
1122
- function O(e, t) {
1143
+ function ve(e, t) {
1123
1144
  if (t === void 0) return !0;
1124
1145
  try {
1125
1146
  return new URL(e, t).origin === new URL(t).origin;
@@ -1127,15 +1148,15 @@ function O(e, t) {
1127
1148
  return !1;
1128
1149
  }
1129
1150
  }
1130
- function k() {
1151
+ function ye() {
1131
1152
  return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1132
1153
  }
1133
- function A() {
1154
+ function be() {
1134
1155
  return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1135
1156
  }
1136
1157
  //#endregion
1137
1158
  //#region src/media/DeviceManager.ts
1138
- var j = class {
1159
+ var xe = class {
1139
1160
  mediaDevices;
1140
1161
  createAudioElement;
1141
1162
  outputCapability;
@@ -1143,23 +1164,23 @@ var j = class {
1143
1164
  outputGeneration = 0;
1144
1165
  outputTail;
1145
1166
  constructor(e = {}) {
1146
- this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? M(), this.createAudioElement = e.createAudioElement;
1167
+ this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? O(), this.createAudioElement = e.createAudioElement;
1147
1168
  }
1148
1169
  async requestPermission(e = {}) {
1149
1170
  let t = this.requireMediaDevices(), n;
1150
1171
  try {
1151
1172
  n = await t.getUserMedia({ audio: e });
1152
1173
  } catch (e) {
1153
- throw F(e);
1174
+ throw j(e);
1154
1175
  }
1155
- N(n);
1176
+ k(n);
1156
1177
  }
1157
1178
  async getDevices() {
1158
1179
  if (this.mediaDevices === void 0) return [];
1159
1180
  try {
1160
1181
  return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
1161
1182
  } catch (e) {
1162
- throw I(e);
1183
+ throw M(e);
1163
1184
  }
1164
1185
  }
1165
1186
  getCapabilities() {
@@ -1173,12 +1194,12 @@ var j = class {
1173
1194
  let e = this.createAudioElementSafely();
1174
1195
  return this.outputCapability = e !== void 0 && typeof e.setSinkId == "function", this.outputCapability;
1175
1196
  }
1176
- async setOutputDevice(t, n) {
1177
- if (!this.supportsOutputSelection()) throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1178
- this.outputDeviceId = t;
1197
+ async setOutputDevice(e, t) {
1198
+ if (!this.supportsOutputSelection()) throw new n("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1199
+ this.outputDeviceId = e;
1179
1200
  let r = ++this.outputGeneration;
1180
- n !== void 0 && await this.enqueueOutput(async () => {
1181
- 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);
1182
1203
  });
1183
1204
  }
1184
1205
  async applyConfiguredOutputDevice(e) {
@@ -1191,13 +1212,13 @@ var j = class {
1191
1212
  getOutputDeviceId() {
1192
1213
  return this.outputDeviceId;
1193
1214
  }
1194
- async applyOutputDevice(t, n) {
1195
- let r = n;
1196
- 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);
1197
1218
  try {
1198
- await r.setSinkId(t);
1219
+ await r.setSinkId(e);
1199
1220
  } catch (e) {
1200
- throw L(e);
1221
+ throw Se(e);
1201
1222
  }
1202
1223
  }
1203
1224
  enqueueOutput(e) {
@@ -1211,11 +1232,11 @@ var j = class {
1211
1232
  try {
1212
1233
  return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
1213
1234
  } catch (e) {
1214
- throw P(e);
1235
+ throw A(e);
1215
1236
  }
1216
1237
  }
1217
1238
  requireMediaDevices() {
1218
- 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);
1219
1240
  return this.mediaDevices;
1220
1241
  }
1221
1242
  createAudioElementSafely() {
@@ -1231,10 +1252,10 @@ var j = class {
1231
1252
  }
1232
1253
  }
1233
1254
  };
1234
- function M() {
1255
+ function O() {
1235
1256
  return globalThis.navigator?.mediaDevices;
1236
1257
  }
1237
- function N(e) {
1258
+ function k(e) {
1238
1259
  let t;
1239
1260
  try {
1240
1261
  t = e.getTracks();
@@ -1247,110 +1268,110 @@ function N(e) {
1247
1268
  } catch {}
1248
1269
  });
1249
1270
  }
1250
- function P(t) {
1251
- let n = R(t);
1252
- 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 });
1253
1274
  }
1254
- function F(t) {
1255
- let n = R(t);
1256
- 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 });
1257
1278
  }
1258
- function I(t) {
1259
- let n = R(t);
1260
- 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 });
1261
1282
  }
1262
- function L(t) {
1263
- let n = R(t);
1264
- 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 });
1265
1286
  }
1266
- function R(e) {
1287
+ function N(e) {
1267
1288
  if (typeof e != "object" || !e || !("name" in e)) return;
1268
1289
  let t = e.name;
1269
1290
  return typeof t == "string" ? t : void 0;
1270
1291
  }
1271
1292
  //#endregion
1272
1293
  //#region src/media/RemoteAudio.ts
1273
- var z = class {
1294
+ var Ce = class {
1274
1295
  createAudioElement;
1275
1296
  bindings = /* @__PURE__ */ new Map();
1276
1297
  audioOwners = /* @__PURE__ */ new Map();
1277
1298
  trackOwners = /* @__PURE__ */ new Map();
1278
1299
  generations = /* @__PURE__ */ new Map();
1279
1300
  pendingPlays = /* @__PURE__ */ new Map();
1280
- constructor(e = he) {
1301
+ constructor(e = we) {
1281
1302
  this.createAudioElement = e;
1282
1303
  }
1283
- async bind(t, n) {
1284
- let r = this.bindings.get(t);
1285
- if (r?.stream === n) return;
1286
- let i = ge(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;
1287
1308
  try {
1288
1309
  a = this.createAudioElement();
1289
- } catch (n) {
1290
- throw B(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1291
- callId: t,
1292
- cause: n
1310
+ } catch (t) {
1311
+ throw P(i, this.trackOwners), new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1312
+ callId: e,
1313
+ cause: t
1293
1314
  });
1294
1315
  }
1295
1316
  let o = this.audioOwners.get(a);
1296
- 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 });
1297
1318
  try {
1298
1319
  a.autoplay = !0, a.playsInline = !0;
1299
- } catch (n) {
1300
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1301
- callId: t,
1302
- cause: n
1320
+ } catch (t) {
1321
+ throw P(i, this.trackOwners), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1322
+ callId: e,
1323
+ cause: t
1303
1324
  });
1304
1325
  }
1305
1326
  try {
1306
- a.srcObject = n;
1307
- } catch (n) {
1308
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1309
- callId: t,
1310
- 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
1311
1332
  });
1312
1333
  }
1313
1334
  this.acquireTracks(i), r !== void 0 && this.releaseBinding(r, r.audio !== a);
1314
- let s = this.nextGeneration(t);
1315
- this.audioOwners.set(a, t);
1335
+ let s = this.nextGeneration(e);
1336
+ this.audioOwners.set(a, e);
1316
1337
  let c = {
1317
- callId: t,
1338
+ callId: e,
1318
1339
  audio: a,
1319
- stream: n,
1340
+ stream: t,
1320
1341
  tracks: i,
1321
1342
  generation: s
1322
1343
  };
1323
- this.bindings.set(t, c), this.beginPlay(t);
1344
+ this.bindings.set(e, c), this.beginPlay(e);
1324
1345
  try {
1325
1346
  await a.play();
1326
- } catch (n) {
1327
- if (!this.isCurrent(t, s)) return;
1328
- throw new e("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1329
- callId: t,
1330
- 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
1331
1352
  });
1332
1353
  } finally {
1333
- this.finishPlay(t);
1354
+ this.finishPlay(e);
1334
1355
  }
1335
- this.isCurrent(t, s);
1356
+ this.isCurrent(e, s);
1336
1357
  }
1337
- async play(t) {
1338
- let n = this.bindings.get(t);
1339
- if (n === void 0) throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1340
- let r = n.generation;
1341
- 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);
1342
1363
  try {
1343
- await n.audio.play();
1344
- } catch (n) {
1345
- if (!this.isCurrent(t, r)) return;
1346
- throw new e("MEDIA_PLAYBACK_BLOCKED", "media", !1, {
1347
- callId: t,
1348
- 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
1349
1370
  });
1350
1371
  } finally {
1351
- this.finishPlay(t);
1372
+ this.finishPlay(e);
1352
1373
  }
1353
- this.isCurrent(t, r);
1374
+ this.isCurrent(e, r);
1354
1375
  }
1355
1376
  getAudioElement(e) {
1356
1377
  return this.bindings.get(e)?.audio;
@@ -1381,7 +1402,7 @@ var z = class {
1381
1402
  releaseTrack(e) {
1382
1403
  let t = this.trackOwners.get(e);
1383
1404
  if (t === void 0 || t <= 1) {
1384
- this.trackOwners.delete(e), V(e);
1405
+ this.trackOwners.delete(e), F(e);
1385
1406
  return;
1386
1407
  }
1387
1408
  this.trackOwners.set(e, t - 1);
@@ -1404,42 +1425,42 @@ var z = class {
1404
1425
  return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
1405
1426
  }
1406
1427
  };
1407
- function he() {
1408
- 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);
1409
1430
  return document.createElement("audio");
1410
1431
  }
1411
- function ge(t, n) {
1432
+ function Te(e, t) {
1412
1433
  try {
1413
- return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
1434
+ return [...new Set(t.getAudioTracks())].filter((e) => e.kind === "audio");
1414
1435
  } catch (r) {
1415
1436
  try {
1416
- return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
1437
+ return [...new Set(t.getTracks())].filter((e) => e.kind === "audio");
1417
1438
  } catch (i) {
1418
- throw _e(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1419
- callId: t,
1439
+ throw Ee(t), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1440
+ callId: e,
1420
1441
  cause: r ?? i
1421
1442
  });
1422
1443
  }
1423
1444
  }
1424
1445
  }
1425
- function B(e, t) {
1446
+ function P(e, t) {
1426
1447
  e.forEach((e) => {
1427
- (t.get(e) ?? 0) === 0 && V(e);
1448
+ (t.get(e) ?? 0) === 0 && F(e);
1428
1449
  });
1429
1450
  }
1430
- function _e(e) {
1451
+ function Ee(e) {
1431
1452
  try {
1432
- [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
1453
+ [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(F);
1433
1454
  } catch {}
1434
1455
  }
1435
- function V(e) {
1456
+ function F(e) {
1436
1457
  try {
1437
1458
  e.stop();
1438
1459
  } catch {}
1439
1460
  }
1440
1461
  //#endregion
1441
1462
  //#region src/media/MediaManager.ts
1442
- var ve = class {
1463
+ var De = class {
1443
1464
  deviceManager;
1444
1465
  remoteAudio;
1445
1466
  getActiveCall;
@@ -1460,7 +1481,7 @@ var ve = class {
1460
1481
  mediaDevices: e.mediaDevices,
1461
1482
  createAudioElement: e.createAudioElement
1462
1483
  };
1463
- this.deviceManager = new j(t), this.remoteAudio = new z(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? xe;
1484
+ this.deviceManager = new xe(t), this.remoteAudio = new Ce(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? Ae;
1464
1485
  }
1465
1486
  requestPermission(e) {
1466
1487
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1480,7 +1501,7 @@ var ve = class {
1480
1501
  n !== void 0 && this.releaseResource(n).catch((e) => {
1481
1502
  this.releaseErrors.set(n, e);
1482
1503
  });
1483
- let r = ye(t) ? t : { peerConnection: t }, i = {
1504
+ let r = Oe(t) ? t : { peerConnection: t }, i = {
1484
1505
  callId: e,
1485
1506
  peerConnection: r.peerConnection,
1486
1507
  senders: /* @__PURE__ */ new Map(),
@@ -1554,15 +1575,15 @@ var ve = class {
1554
1575
  audioElements: t.audioElements
1555
1576
  };
1556
1577
  }
1557
- releaseResource(t) {
1558
- let n = this.releaseOperations.get(t);
1559
- if (n !== void 0) return n;
1560
- if (!this.resources.has(t)) return Promise.resolve();
1561
- let r = t.callId;
1562
- 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);
1563
- let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
1564
- senderResource: e,
1565
- 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)
1566
1587
  })), o = Promise.all(a.map(async (e) => {
1567
1588
  try {
1568
1589
  return await e.promise, {
@@ -1575,39 +1596,39 @@ var ve = class {
1575
1596
  cause: t
1576
1597
  };
1577
1598
  }
1578
- })).then(async (n) => {
1599
+ })).then(async (t) => {
1579
1600
  let a = /* @__PURE__ */ new Set(), o = [];
1580
- if (n.forEach((e) => {
1601
+ if (t.forEach((e) => {
1581
1602
  if (e.cause !== void 0) {
1582
1603
  o.push(e.cause);
1583
- let t = H(e.senderResource.sender);
1604
+ let t = I(e.senderResource.sender);
1584
1605
  t?.kind === "audio" && a.add(t);
1585
1606
  return;
1586
1607
  }
1587
- let t = H(e.senderResource.sender);
1608
+ let t = I(e.senderResource.sender);
1588
1609
  t?.kind === "audio" && i.add(t);
1589
1610
  }), i.forEach((e) => {
1590
- a.has(e) || K(e);
1591
- }), 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, {
1592
1613
  callId: r,
1593
1614
  cause: o[0]
1594
1615
  });
1595
- if (!t.peerClosed && t.peerConnection.close !== void 0) try {
1596
- await t.peerConnection.close(), t.peerClosed = !0;
1597
- } catch (n) {
1598
- let i = [...t.senders.values()].map((e) => H(e.sender)).find((e) => e?.kind === "audio");
1599
- 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, {
1600
1621
  callId: r,
1601
- cause: n
1622
+ cause: t
1602
1623
  });
1603
1624
  }
1604
- t.localTracks.clear(), t.pendingTracks.clear(), t.senders.clear(), this.resources.delete(t), this.releaseUnusedSenderQueues();
1605
- }).catch((e) => {
1606
- 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;
1607
1628
  }).finally(() => {
1608
- this.releaseOperations.get(t) === o && this.releaseOperations.delete(t);
1629
+ this.releaseOperations.get(e) === o && this.releaseOperations.delete(e);
1609
1630
  });
1610
- return this.releaseOperations.set(t, o), o;
1631
+ return this.releaseOperations.set(e, o), o;
1611
1632
  }
1612
1633
  releaseCall(e) {
1613
1634
  let t = this.callReleaseOperations.get(e);
@@ -1661,51 +1682,51 @@ var ve = class {
1661
1682
  let e = [...this.inputOperations.values()];
1662
1683
  e.length !== 0 && await Promise.allSettled(e);
1663
1684
  }
1664
- async performInputSwitch(t, n, r) {
1665
- if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
1666
- 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;
1667
1688
  try {
1668
1689
  c = s.getTracks();
1669
- } catch (t) {
1670
- throw be(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1671
- callId: n.callId,
1672
- cause: t
1690
+ } catch (e) {
1691
+ throw ke(s), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1692
+ callId: t.callId,
1693
+ cause: e
1673
1694
  });
1674
1695
  }
1675
1696
  let l;
1676
1697
  try {
1677
1698
  l = s.getAudioTracks();
1678
- } catch (t) {
1679
- throw G(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1680
- callId: n.callId,
1681
- cause: t
1699
+ } catch (e) {
1700
+ throw z(c), new n("SDK_INTERNAL_ERROR", "internal", !1, {
1701
+ callId: t.callId,
1702
+ cause: e
1682
1703
  });
1683
1704
  }
1684
1705
  let u = l[0];
1685
- if (u === void 0) throw G(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1686
- 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);
1687
1708
  c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
1688
1709
  try {
1689
1710
  await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
1690
- } catch (t) {
1691
- 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, {
1692
- callId: n.callId,
1693
- 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
1694
1715
  }));
1695
1716
  }
1696
- if (!this.canCommitInputSwitch(n, r, i, u, o)) {
1717
+ if (!this.canCommitInputSwitch(t, r, i, u, o)) {
1697
1718
  if (!r.released) try {
1698
- 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);
1699
- } catch (t) {
1700
- throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
1701
- callId: n.callId,
1702
- 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
1703
1724
  });
1704
1725
  }
1705
- throw this.callOperationError(n.callId);
1726
+ throw this.callOperationError(t.callId);
1706
1727
  }
1707
- 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) => {
1708
- 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);
1709
1730
  });
1710
1731
  }
1711
1732
  ensureCallMedia(e) {
@@ -1717,35 +1738,35 @@ var ve = class {
1717
1738
  if (n === void 0) throw this.callOperationError(e.callId);
1718
1739
  return n;
1719
1740
  }
1720
- captureSenders(t, n) {
1741
+ captureSenders(e, t) {
1721
1742
  let r;
1722
1743
  try {
1723
- r = t.peerConnection.getSenders();
1724
- } catch (n) {
1725
- throw new e("SDK_INTERNAL_ERROR", "internal", !1, {
1726
- callId: t.callId,
1727
- 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
1728
1749
  });
1729
1750
  }
1730
1751
  r.forEach((r) => {
1731
- let i = H(r), a;
1752
+ let i = I(r), a;
1732
1753
  try {
1733
- a = n?.(r) ?? r.senderKind ?? r.kind;
1734
- } catch (n) {
1735
- throw new e("SDK_INTERNAL_ERROR", "internal", !1, {
1736
- callId: t.callId,
1737
- 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
1738
1759
  });
1739
1760
  }
1740
- t.senders.set(r, {
1761
+ e.senders.set(r, {
1741
1762
  sender: r,
1742
1763
  audio: a === "audio" || a === void 0 && i?.kind === "audio",
1743
1764
  queue: this.senderQueues.get(r) ?? this.createSenderQueue(r)
1744
- }), i?.kind === "audio" && t.localTracks.add(i);
1765
+ }), i?.kind === "audio" && e.localTracks.add(i);
1745
1766
  });
1746
1767
  }
1747
1768
  findAudioSender(e) {
1748
- 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));
1749
1770
  if (t === void 0) throw this.capabilityError(e.callId);
1750
1771
  return t;
1751
1772
  }
@@ -1761,7 +1782,7 @@ var ve = class {
1761
1782
  } catch {
1762
1783
  return !1;
1763
1784
  }
1764
- return H(n.sender) === r;
1785
+ return I(n.sender) === r;
1765
1786
  }
1766
1787
  enqueueSender(e, t, n, r = !1) {
1767
1788
  t.queue.pending += 1;
@@ -1790,7 +1811,7 @@ var ve = class {
1790
1811
  });
1791
1812
  }
1792
1813
  async rollbackSender(e, t, n, r) {
1793
- 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);
1794
1815
  }
1795
1816
  isCurrentResource(e, t = e.generation) {
1796
1817
  return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
@@ -1801,58 +1822,58 @@ var ve = class {
1801
1822
  t();
1802
1823
  } catch {}
1803
1824
  }
1804
- assertActiveCall(t) {
1805
- 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 });
1806
1827
  }
1807
1828
  assertDeviceSelectionCapability(e) {
1808
1829
  if (e.capabilities === void 0 || !e.capabilities.has("device_selection")) throw this.capabilityError(e.callId);
1809
1830
  }
1810
- capabilityError(t) {
1811
- return new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: t });
1831
+ capabilityError(e) {
1832
+ return new n("CAPABILITY_NOT_SUPPORTED", "capability", !1, { callId: e });
1812
1833
  }
1813
- callOperationError(t) {
1814
- 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 });
1815
1836
  }
1816
1837
  assertNotDisposed() {
1817
- 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);
1818
1839
  }
1819
1840
  };
1820
- function ye(e) {
1841
+ function Oe(e) {
1821
1842
  return "peerConnection" in e;
1822
1843
  }
1823
- function H(e) {
1844
+ function I(e) {
1824
1845
  try {
1825
1846
  return e.track;
1826
1847
  } catch {
1827
1848
  return null;
1828
1849
  }
1829
1850
  }
1830
- function U(e) {
1851
+ function L(e) {
1831
1852
  return typeof e == "object" && !!e && e.name === "InvalidStateError";
1832
1853
  }
1833
- function W(e) {
1854
+ function R(e) {
1834
1855
  try {
1835
1856
  return e.replaceTrack(null).catch((e) => {
1836
- if (!U(e)) throw e;
1857
+ if (!L(e)) throw e;
1837
1858
  });
1838
1859
  } catch (e) {
1839
- return U(e) ? Promise.resolve() : Promise.reject(e);
1860
+ return L(e) ? Promise.resolve() : Promise.reject(e);
1840
1861
  }
1841
1862
  }
1842
- function be(e) {
1863
+ function ke(e) {
1843
1864
  try {
1844
- G(e.getTracks());
1865
+ z(e.getTracks());
1845
1866
  } catch {}
1846
1867
  }
1847
- function G(e) {
1848
- e.forEach(K);
1868
+ function z(e) {
1869
+ e.forEach(B);
1849
1870
  }
1850
- function K(e) {
1871
+ function B(e) {
1851
1872
  try {
1852
1873
  e.stop();
1853
1874
  } catch {}
1854
1875
  }
1855
- function xe(e) {
1876
+ function Ae(e) {
1856
1877
  if (typeof MediaStream < "u") try {
1857
1878
  return new MediaStream([e]);
1858
1879
  } catch {
@@ -1861,8 +1882,8 @@ function xe(e) {
1861
1882
  }
1862
1883
  //#endregion
1863
1884
  //#region src/core/mediaBridge.ts
1864
- function Se(t, n = {}) {
1865
- 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 ve({ 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 });
1866
1887
  return {
1867
1888
  publicMedia: {
1868
1889
  requestPermission: () => (f(), d.requestPermission()),
@@ -1875,7 +1896,7 @@ function Se(t, n = {}) {
1875
1896
  releaseAll: () => (f(), d.releaseAll())
1876
1897
  },
1877
1898
  registerCall(e, t) {
1878
- 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));
1879
1900
  },
1880
1901
  async setCallOwnership(e, t) {
1881
1902
  if (s) return;
@@ -1915,12 +1936,12 @@ function Se(t, n = {}) {
1915
1936
  }
1916
1937
  };
1917
1938
  function f() {
1918
- if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1939
+ if (s) throw new n("SDK_ALREADY_DISPOSED", "internal", !1);
1919
1940
  }
1920
1941
  function p(e, t) {
1921
- if (!q(t) || typeof t.getMediaRegistration != "function") return;
1942
+ if (!H(t) || typeof t.getMediaRegistration != "function") return;
1922
1943
  let n = t.getMediaRegistration();
1923
- if (Ce(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1944
+ if (je(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1924
1945
  r.set(e, n);
1925
1946
  try {
1926
1947
  d.registerCallMedia(e, n);
@@ -1930,22 +1951,22 @@ function Se(t, n = {}) {
1930
1951
  }
1931
1952
  }
1932
1953
  }
1933
- function q(e) {
1954
+ function H(e) {
1934
1955
  return typeof e == "object" && !!e;
1935
1956
  }
1936
- function Ce(e) {
1957
+ function je(e) {
1937
1958
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
1938
1959
  }
1939
1960
  //#endregion
1940
1961
  //#region src/reconnect/backoff.ts
1941
- var we = 1e3, Te = 3e4;
1942
- function Ee(e, t = Math.random) {
1943
- let n = Math.min(Te, we * 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()));
1944
1965
  return Math.round(n * (1 + r * .2));
1945
1966
  }
1946
1967
  //#endregion
1947
1968
  //#region src/reconnect/ReconnectManager.ts
1948
- var De = class {
1969
+ var Fe = class {
1949
1970
  recover;
1950
1971
  isRecovered;
1951
1972
  random;
@@ -1963,7 +1984,7 @@ var De = class {
1963
1984
  }
1964
1985
  start() {
1965
1986
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
1966
- let e = this.generation, t = Ee(this.attempt, this.random);
1987
+ let e = this.generation, t = Pe(this.attempt, this.random);
1967
1988
  this.pendingTimer = setTimeout(() => {
1968
1989
  this.pendingTimer = void 0, this.run(e);
1969
1990
  }, t);
@@ -2005,13 +2026,13 @@ var De = class {
2005
2026
  clearPendingTimer() {
2006
2027
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
2007
2028
  }
2008
- }, Oe = 12e4, ke = 5e3, Ae = class t {
2029
+ }, Ie = 12e4, Le = 5e3, Re = class r {
2009
2030
  media;
2010
2031
  options;
2011
2032
  api;
2012
2033
  suppliedSip;
2013
2034
  sip;
2014
- events = new i();
2035
+ events = new o();
2015
2036
  mediaBridge;
2016
2037
  reconnect;
2017
2038
  diagnostics;
@@ -2042,28 +2063,29 @@ var De = class {
2042
2063
  ownedSessionIds = /* @__PURE__ */ new Set();
2043
2064
  terminalReleaseOperations = /* @__PURE__ */ new Map();
2044
2065
  sharedWorkerSelection;
2045
- constructor(t) {
2046
- if (this.options = t, t.api === void 0 && t.sessionProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 sessionProvider" });
2047
- this.api = t.api === void 0 ? J(Ne(t.sessionProvider)) : J(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : X(t.sip), this.mediaBridge = Se(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new De({
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({
2048
2069
  recover: () => this.recoverConnection(),
2049
2070
  isRecovered: () => this.state === "connected",
2050
2071
  onAttempt: (e) => {
2051
2072
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
2052
2073
  }
2053
- }), this.diagnostics = new r({
2074
+ }), this.diagnostics = new a({
2054
2075
  getSnapshot: () => this.createDiagnosticsSnapshot(),
2055
2076
  getPermission: () => this.readMicrophonePermission(),
2056
2077
  getDeviceNames: async () => (await this.media.getDevices()).map((e) => e.label).filter((e) => e !== "")
2057
- }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2078
+ }), this.sharedWorkerSelection = r.sharedWorker === void 0 ? {
2058
2079
  mode: "single-tab",
2059
2080
  reason: "disabled"
2060
- } : w({
2061
- ...t.sharedWorker,
2062
- ...t.sharedWorkerHost ?? {}
2081
+ } : T({
2082
+ ...r.sharedWorker,
2083
+ ...r.sharedWorkerHost ?? {},
2084
+ locale: e(r.locale)
2063
2085
  });
2064
2086
  }
2065
2087
  static async checkSupport() {
2066
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Me(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 : "");
2067
2089
  return {
2068
2090
  supported: e && t,
2069
2091
  platform: n,
@@ -2074,7 +2096,7 @@ var De = class {
2074
2096
  }
2075
2097
  async initialize() {
2076
2098
  if (this.assertNotDisposed(), this.initialized) return;
2077
- let e = await t.checkSupport();
2099
+ let e = await r.checkSupport();
2078
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;
2079
2101
  }
2080
2102
  connect() {
@@ -2108,23 +2130,23 @@ var De = class {
2108
2130
  recover() {
2109
2131
  return this.assertNotDisposed(), this.recoverConnection();
2110
2132
  }
2111
- dial(t) {
2133
+ dial(e) {
2112
2134
  this.assertConnected();
2113
- let n = this.callManager, r = this.session;
2114
- if (n === void 0 || r === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2115
- 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);
2116
2138
  }
2117
- answer(t, n) {
2139
+ answer(e, t) {
2118
2140
  this.assertConnected();
2119
2141
  let r = this.callManager, i = this.session;
2120
- if (r === void 0 || i === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2121
- 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);
2122
2144
  }
2123
- setActiveCall(t) {
2145
+ setActiveCall(e) {
2124
2146
  this.assertConnected();
2125
- let n = this.callManager;
2126
- if (n === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
2127
- 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);
2128
2150
  }
2129
2151
  getCalls() {
2130
2152
  return this.callManager?.getCalls() ?? [];
@@ -2148,13 +2170,13 @@ var De = class {
2148
2170
  getDiagnostics(e = {}) {
2149
2171
  return this.diagnostics.getReport(e);
2150
2172
  }
2151
- async setAgentStatus(t) {
2152
- if (this.assertNotDisposed(), t !== "available" && t !== "offline" && t !== "break") throw new e("CONFIG_INVALID", "configuration", !1, { cause: `Unsupported agent status: ${String(t)}` });
2153
- 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;
2154
2176
  await this.api.setAgentStatus({
2155
- status: t,
2177
+ status: e,
2156
2178
  reason: ""
2157
- }, 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 });
2158
2180
  }
2159
2181
  on(e, t) {
2160
2182
  return this.disposed ? () => void 0 : this.events.on(e, t);
@@ -2163,22 +2185,22 @@ var De = class {
2163
2185
  this.events.off(e, t);
2164
2186
  }
2165
2187
  async performConnect(e) {
2166
- let t, r, i;
2188
+ let t, n, r;
2167
2189
  try {
2168
2190
  await this.initialize(), this.assertGeneration(e);
2169
2191
  let a = this.resolvePlatform();
2170
2192
  this.intentionalDisconnect = !1, this.acceptingEvents = !0, this.setConnectionState("connecting"), t = await this.api.createSession({
2171
- sdkVersion: n,
2193
+ sdkVersion: i,
2172
2194
  platform: a === "mobile-web" ? "mobile_web" : "web",
2173
2195
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2174
- requestedCapabilities: [...this.options.requestedCapabilities ?? Le(a)]
2175
- }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2176
- let o = this.callManager ?? this.createCallManager(r, t, a);
2177
- 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);
2178
- } catch (n) {
2179
- if (await this.rollbackConnect(t, r, i), this.disposed) throw this.disposedError();
2180
- if (e !== this.lifecycleGeneration) throw n;
2181
- 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);
2182
2204
  throw this.setConnectionState("failed"), this.events.emit("connection.failed", { error: a }), a;
2183
2205
  }
2184
2206
  }
@@ -2187,13 +2209,13 @@ var De = class {
2187
2209
  if (t !== void 0) try {
2188
2210
  await t;
2189
2211
  } catch (t) {
2190
- $(t) || (e ??= t);
2212
+ q(t) || (e ??= t);
2191
2213
  }
2192
2214
  let n = this.refreshOperation;
2193
2215
  if (n !== void 0) try {
2194
2216
  await n;
2195
2217
  } catch (t) {
2196
- $(t) || (e ??= t);
2218
+ q(t) || (e ??= t);
2197
2219
  }
2198
2220
  this.reconnect.cancel(), this.stuckCallsSince = void 0, this.clearRefreshTimer(), this.intentionalDisconnect = !0, this.detachNetworkListeners(), this.detachSipListener(), this.detachManagerListeners();
2199
2221
  let r = this.callManager, i = this.sip;
@@ -2222,7 +2244,7 @@ var De = class {
2222
2244
  if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
2223
2245
  }
2224
2246
  createCallManager(e, t, n) {
2225
- let r = new v({
2247
+ let r = new x({
2226
2248
  sip: e,
2227
2249
  platform: n,
2228
2250
  session: t,
@@ -2260,7 +2282,7 @@ var De = class {
2260
2282
  for (let n of t) try {
2261
2283
  await n;
2262
2284
  } catch (t) {
2263
- $(t) || (e ??= t);
2285
+ q(t) || (e ??= t);
2264
2286
  }
2265
2287
  let n = this.callManager;
2266
2288
  this.callManager = void 0;
@@ -2277,7 +2299,7 @@ var De = class {
2277
2299
  try {
2278
2300
  await this.media.releaseAll();
2279
2301
  } catch (t) {
2280
- Pe(t) || (e ??= t);
2302
+ Ue(t) || (e ??= t);
2281
2303
  }
2282
2304
  try {
2283
2305
  await this.mediaBridge.dispose();
@@ -2309,15 +2331,15 @@ var De = class {
2309
2331
  }
2310
2332
  if (e !== void 0) throw e;
2311
2333
  }
2312
- withBarrierTimeout(t, n, r = ke) {
2334
+ withBarrierTimeout(e, t, r = Le) {
2313
2335
  return new Promise((i, a) => {
2314
2336
  let o = setTimeout(() => {
2315
- a(new e("SDK_INTERNAL_ERROR", "internal", !0, {
2316
- callId: n,
2337
+ a(new n("SDK_INTERNAL_ERROR", "internal", !0, {
2338
+ callId: t,
2317
2339
  cause: "media release barrier timeout"
2318
2340
  }));
2319
2341
  }, Math.max(0, r));
2320
- t.then((e) => {
2342
+ e.then((e) => {
2321
2343
  clearTimeout(o), i(e);
2322
2344
  }, (e) => {
2323
2345
  clearTimeout(o), a(e);
@@ -2370,7 +2392,7 @@ var De = class {
2370
2392
  let n = this.mediaBridge.releaseCall(e).then(() => {
2371
2393
  this.terminalReleaseOperations.get(e) === n && this.terminalReleaseOperations.delete(e);
2372
2394
  }).catch((t) => {
2373
- 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;
2374
2396
  });
2375
2397
  return this.terminalReleaseOperations.set(e, n), n;
2376
2398
  }
@@ -2414,8 +2436,8 @@ var De = class {
2414
2436
  }
2415
2437
  handleRefreshFailure(e, t) {
2416
2438
  if (this.disposed) return;
2417
- let n = Z(t, "NETWORK_OFFLINE", "network", !0);
2418
- 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)) {
2419
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?.();
2420
2442
  return;
2421
2443
  }
@@ -2427,7 +2449,7 @@ var De = class {
2427
2449
  try {
2428
2450
  await this.performDisconnect();
2429
2451
  } catch (e) {
2430
- 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) });
2431
2453
  return;
2432
2454
  }
2433
2455
  if (!this.disposed) try {
@@ -2448,7 +2470,7 @@ var De = class {
2448
2470
  if (!(this.disposed || this.intentionalDisconnect)) {
2449
2471
  if (this.hasNonTerminalCalls()) {
2450
2472
  let e = Date.now();
2451
- if (this.stuckCallsSince === void 0 && (this.stuckCallsSince = e), e - this.stuckCallsSince < Oe) return;
2473
+ if (this.stuckCallsSince === void 0 && (this.stuckCallsSince = e), e - this.stuckCallsSince < Ie) return;
2452
2474
  this.stuckCallsSince = void 0, await this.callManager?.forceTerminateCalls();
2453
2475
  } else this.stuckCallsSince = void 0;
2454
2476
  if (await this.awaitMediaReleaseBarriers(), this.session === void 0) {
@@ -2461,7 +2483,7 @@ var De = class {
2461
2483
  async getSip() {
2462
2484
  if (this.sip !== void 0) return this.sip;
2463
2485
  if (this.suppliedSip !== void 0) return this.sip = this.suppliedSip, this.sip;
2464
- 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")]);
2465
2487
  return this.sip = new t.JsSipAdapter(e.createJsSipFactory(), this.options.baseUrl, this.options.sipKeepaliveSeconds, this.options.agentTerminal, this.options.sipSessionTimers ?? !1), this.sip;
2466
2488
  }
2467
2489
  attachSipListener(e) {
@@ -2471,7 +2493,7 @@ var De = class {
2471
2493
  this.setConnectionState("connected");
2472
2494
  return;
2473
2495
  }
2474
- 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) }));
2475
2497
  }
2476
2498
  }));
2477
2499
  }
@@ -2516,7 +2538,7 @@ var De = class {
2516
2538
  destination: e.destination
2517
2539
  })),
2518
2540
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2519
- ice: je(e, this.sip?.iceQualitySnapshot?.()),
2541
+ ice: ze(e, this.sip?.iceQualitySnapshot?.()),
2520
2542
  wss: {
2521
2543
  configured: e !== void 0,
2522
2544
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2556,7 +2578,7 @@ var De = class {
2556
2578
  let n = this.api.deleteSession(e).then(() => {
2557
2579
  this.deletedSessions.add(e);
2558
2580
  }).catch((t) => {
2559
- if (Q(t)) {
2581
+ if (K(t)) {
2560
2582
  this.deletedSessions.add(e);
2561
2583
  return;
2562
2584
  }
@@ -2579,19 +2601,19 @@ var De = class {
2579
2601
  if (e !== void 0) throw e;
2580
2602
  }
2581
2603
  resolvePlatform() {
2582
- let t = this.options.platform ?? this.detectedPlatform;
2583
- if (t === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: this.support?.platform ?? "unknown" });
2584
- 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;
2585
2607
  }
2586
2608
  setConnectionState(e) {
2587
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 }));
2588
2610
  }
2589
2611
  assertConnected() {
2590
- 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);
2591
2613
  }
2592
- assertGeneration(t) {
2614
+ assertGeneration(e) {
2593
2615
  if (this.disposed) throw this.disposedError();
2594
- 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);
2595
2617
  }
2596
2618
  isCurrentGeneration(e) {
2597
2619
  return !this.disposed && e === this.lifecycleGeneration;
@@ -2630,10 +2652,10 @@ var De = class {
2630
2652
  if (this.disposed) throw this.disposedError();
2631
2653
  }
2632
2654
  disposedError() {
2633
- return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2655
+ return new n("SDK_ALREADY_DISPOSED", "internal", !1);
2634
2656
  }
2635
2657
  };
2636
- function je(e, t) {
2658
+ function ze(e, t) {
2637
2659
  if (e === void 0) return {
2638
2660
  configured: !1,
2639
2661
  serverCount: 0,
@@ -2653,17 +2675,17 @@ function je(e, t) {
2653
2675
  turnServerCount: r
2654
2676
  };
2655
2677
  }
2656
- function Me(e) {
2678
+ function Be(e) {
2657
2679
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2658
2680
  }
2659
- function J(t) {
2660
- if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2661
- return t;
2681
+ function U(e) {
2682
+ if (typeof e != "object" || !e) throw new n("CONFIG_INVALID", "configuration", !1);
2683
+ return e;
2662
2684
  }
2663
- async function Y(e) {
2685
+ async function W(e) {
2664
2686
  let t = e.sip?.registerTicket;
2665
2687
  if (typeof t != "string" || t === "") return e;
2666
- let n = await le(t);
2688
+ let n = await de(t);
2667
2689
  return n === void 0 || n === t ? e : {
2668
2690
  ...e,
2669
2691
  sip: {
@@ -2672,47 +2694,47 @@ async function Y(e) {
2672
2694
  }
2673
2695
  };
2674
2696
  }
2675
- function Ne(t) {
2676
- let r = {
2677
- createSession: async (e) => Y(await t.createSession(e)),
2678
- refreshSession: async (e) => Y(t.refreshSession === void 0 ? await t.createSession({
2679
- 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,
2680
2702
  platform: "web"
2681
- }) : await t.refreshSession(e)),
2682
- deleteSession: async (e) => {
2683
- 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);
2684
2706
  },
2685
- setAgentStatus: (n, r) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n, r)
2686
- }, i = t.invalidateToken;
2687
- 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;
2688
2710
  }
2689
- function X(t) {
2690
- if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2691
- return t;
2711
+ function He(e) {
2712
+ if (typeof e != "object" || !e) throw new n("CONFIG_INVALID", "configuration", !1);
2713
+ return e;
2692
2714
  }
2693
- function Z(t, n, r, i, a) {
2694
- return t instanceof e ? new e(t.code, t.category, t.retryable, {
2695
- requestId: t.requestId,
2696
- callId: a ?? t.callId,
2697
- cause: t.cause ?? t,
2698
- serverCode: t.serverCode,
2699
- platformCode: t.platformCode,
2700
- status: t.status
2701
- }) : 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, {
2702
2724
  callId: a,
2703
- cause: t
2725
+ cause: e
2704
2726
  });
2705
2727
  }
2706
- function Q(t) {
2707
- 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;
2708
2730
  }
2709
- function Pe(t) {
2710
- return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2731
+ function Ue(e) {
2732
+ return e instanceof n && e.code === "SDK_ALREADY_DISPOSED";
2711
2733
  }
2712
- function $(t) {
2713
- 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");
2714
2736
  }
2715
- var Fe = [
2737
+ var We = [
2716
2738
  "outbound",
2717
2739
  "inbound",
2718
2740
  "mute",
@@ -2720,13 +2742,293 @@ var Fe = [
2720
2742
  "dtmf",
2721
2743
  "blind_transfer",
2722
2744
  "device_selection"
2723
- ], Ie = [
2745
+ ], Ge = [
2724
2746
  "outbound",
2725
2747
  "mute",
2726
2748
  "dtmf"
2727
2749
  ];
2728
- function Le(e) {
2729
- return e === "mobile-web" ? Ie : Fe;
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
+ }
2730
3032
  }
2731
3033
  //#endregion
2732
- export { v as a, s as c, a as d, i as f, x as i, o as l, w as n, f as o, T as r, c as s, Ae 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 };