@16x/webphone-sdk 3.1.8 → 3.1.9

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.
@@ -1,5 +1,5 @@
1
1
  import { i as e, t } from "./SharedWorkerProtocol-DKVQ5-po.js";
2
- import { r as n, t as r } from "./Diagnostics-BaGHYBAX.js";
2
+ import { r as n, t as r } from "./Diagnostics-CfbmMp-b.js";
3
3
  //#region src/events/TypedEventBus.ts
4
4
  var i = class {
5
5
  handlers = /* @__PURE__ */ new Map();
@@ -73,216 +73,7 @@ var c = class extends e {
73
73
  to: t
74
74
  } });
75
75
  }
76
- }, l = s, u = 60, d = class {
77
- tokenProvider;
78
- cachedToken;
79
- cachedRequestKey = "";
80
- refreshing;
81
- generation = 0;
82
- constructor(e) {
83
- this.tokenProvider = e;
84
- }
85
- getValidToken(e) {
86
- let t = e?.extension?.trim() ?? "";
87
- if (this.cachedToken && this.cachedRequestKey === t && !this.needsRefresh(this.cachedToken)) return Promise.resolve(this.cachedToken.accessToken);
88
- if (!this.refreshing) {
89
- let n = this.generation, r = this.refresh(e, t, n);
90
- this.refreshing = r, r.then(() => this.clearRefresh(r), () => this.clearRefresh(r));
91
- }
92
- return this.refreshing;
93
- }
94
- invalidate() {
95
- this.generation += 1, this.cachedToken = void 0, this.cachedRequestKey = "", this.refreshing = void 0;
96
- }
97
- needsRefresh(e) {
98
- return e.expiresAt !== void 0 && e.expiresAt <= Math.floor(Date.now() / 1e3) + u;
99
- }
100
- async refresh(e, t, n) {
101
- let r = await this.tokenProvider(e), i = typeof r == "string" ? { accessToken: r } : r;
102
- return n === this.generation && (this.cachedToken = i, this.cachedRequestKey = t), i.accessToken;
103
- }
104
- clearRefresh(e) {
105
- this.refreshing === e && (this.refreshing = void 0);
106
- }
107
- }, f = {
108
- ORIGIN_NOT_ALLOWED: {
109
- code: "CONFIG_ORIGIN_NOT_ALLOWED",
110
- category: "configuration",
111
- retryable: !1
112
- },
113
- CAPABILITY_DENIED: {
114
- code: "CAPABILITY_NOT_SUPPORTED",
115
- category: "capability",
116
- retryable: !1
117
- },
118
- TOKEN_INVALID: {
119
- code: "AUTH_TOKEN_UNAVAILABLE",
120
- category: "auth",
121
- retryable: !1
122
- },
123
- TOKEN_EXPIRED: {
124
- code: "AUTH_TOKEN_EXPIRED",
125
- category: "auth",
126
- retryable: !1
127
- },
128
- INVALID_ARGUMENT: {
129
- code: "CONFIG_INVALID",
130
- category: "configuration",
131
- retryable: !1
132
- },
133
- INVALID_EXTENSION: {
134
- code: "CONFIG_INVALID",
135
- category: "configuration",
136
- retryable: !1
137
- },
138
- SEAT_NOT_FOUND: {
139
- code: "AUTH_PERMISSION_DENIED",
140
- category: "auth",
141
- retryable: !1
142
- },
143
- SESSION_NOT_FOUND: {
144
- code: "CALL_NOT_CONNECTED",
145
- category: "call",
146
- retryable: !1
147
- },
148
- SESSION_EXPIRED: {
149
- code: "CALL_NOT_CONNECTED",
150
- category: "call",
151
- retryable: !1
152
- },
153
- SEAT_IN_USE: {
154
- code: "CALL_ALREADY_EXISTS",
155
- category: "call",
156
- retryable: !1
157
- },
158
- SESSION_CONFLICT: {
159
- code: "CALL_ALREADY_EXISTS",
160
- category: "call",
161
- retryable: !1
162
- },
163
- SEAT_NOT_ASSIGNED: {
164
- code: "AUTH_PERMISSION_DENIED",
165
- category: "auth",
166
- retryable: !1
167
- },
168
- QUEUE_NOT_ASSIGNED: {
169
- code: "CAPABILITY_NOT_SUPPORTED",
170
- category: "capability",
171
- retryable: !1
172
- },
173
- RATE_LIMITED: {
174
- code: "NETWORK_OFFLINE",
175
- category: "network",
176
- retryable: !0
177
- },
178
- SIP_GATEWAY_UNAVAILABLE: {
179
- code: "SIP_WS_UNAVAILABLE",
180
- category: "registration",
181
- retryable: !0
182
- },
183
- SERVICE_UNAVAILABLE: {
184
- code: "NETWORK_OFFLINE",
185
- category: "network",
186
- retryable: !0
187
- },
188
- INTERNAL_ERROR: {
189
- code: "SDK_INTERNAL_ERROR",
190
- category: "internal",
191
- retryable: !0
192
- }
193
- }, p = class {
194
- tokenManager;
195
- fetcher;
196
- baseUrl;
197
- timeoutMs;
198
- constructor(e) {
199
- this.tokenManager = new d(e.tokenProvider), this.fetcher = e.fetcher ?? fetch.bind(globalThis), this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.timeoutMs = e.timeoutMs ?? 1e4;
200
- }
201
- invalidateToken() {
202
- this.tokenManager.invalidate();
203
- }
204
- createSession(e) {
205
- return this.request("POST", "/webphone/v1/sessions", e).then((e) => this.requireData(e));
206
- }
207
- refreshSession(e, t = { refresh: [
208
- "sip_register_ticket",
209
- "wss_ticket",
210
- "turn_credentials"
211
- ] }) {
212
- return this.request("POST", `/webphone/v1/sessions/${encodeURIComponent(e)}/refresh`, t).then((e) => this.requireData(e));
213
- }
214
- deleteSession(e) {
215
- return this.request("DELETE", `/webphone/v1/sessions/${encodeURIComponent(e)}`).then(() => void 0);
216
- }
217
- setAgentStatus(e) {
218
- return this.request("PUT", "/webphone/v1/agents/me/status", e).then(() => void 0);
219
- }
220
- getCapabilities() {
221
- return this.request("GET", "/webphone/v1/capabilities").then((e) => this.requireData(e));
222
- }
223
- async request(t, n, r) {
224
- let i = new AbortController(), a = setTimeout(() => i.abort(), this.timeoutMs);
225
- try {
226
- let e = await this.tokenManager.getValidToken(), a = await this.fetcher(`${this.baseUrl}${n}`, {
227
- method: t,
228
- credentials: "omit",
229
- headers: {
230
- Authorization: `Bearer ${e}`,
231
- ...r === void 0 ? {} : { "Content-Type": "application/json" }
232
- },
233
- ...r === void 0 ? {} : { body: JSON.stringify(r) },
234
- signal: i.signal
235
- }), o = await this.parseResponse(a);
236
- if (!a.ok || o.code !== "OK") throw this.toCCBarError(a.status, o);
237
- return {
238
- data: o.data,
239
- requestId: o.requestId
240
- };
241
- } catch (t) {
242
- throw t instanceof e ? t : t instanceof DOMException && t.name === "AbortError" ? new e("NETWORK_TIMEOUT", "network", !0, { cause: t }) : new e("NETWORK_OFFLINE", "network", !0, { cause: t });
243
- } finally {
244
- clearTimeout(a);
245
- }
246
- }
247
- requireData(t) {
248
- if (t.data === void 0 || t.data === null) throw new e("SDK_INTERNAL_ERROR", "internal", !1, { requestId: t.requestId });
249
- return t.data;
250
- }
251
- async parseResponse(t) {
252
- try {
253
- return await t.json();
254
- } catch (n) {
255
- throw new e("SDK_INTERNAL_ERROR", "internal", t.status >= 500, { cause: n });
256
- }
257
- }
258
- toCCBarError(t, n) {
259
- let r = f[n.code ?? ""] ?? this.mapStatus(t);
260
- return new e(r.code, r.category, r.retryable, {
261
- requestId: n.requestId,
262
- serverCode: n.code,
263
- status: t
264
- });
265
- }
266
- mapStatus(e) {
267
- return e === 401 ? {
268
- code: "AUTH_TOKEN_EXPIRED",
269
- category: "auth",
270
- retryable: !1
271
- } : e === 403 ? {
272
- code: "AUTH_PERMISSION_DENIED",
273
- category: "auth",
274
- retryable: !1
275
- } : e >= 500 ? {
276
- code: "SDK_INTERNAL_ERROR",
277
- category: "internal",
278
- retryable: !0
279
- } : {
280
- code: "SDK_INTERNAL_ERROR",
281
- category: "internal",
282
- retryable: !1
283
- };
284
- }
285
- }, ee = [
76
+ }, l = s, u = [
286
77
  "progress",
287
78
  "accepted",
288
79
  "confirmed",
@@ -291,7 +82,7 @@ var c = class extends e {
291
82
  "hold",
292
83
  "unhold",
293
84
  "mediaConnected"
294
- ], te = 3e4, m = class {
85
+ ], d = 3e4, f = class {
295
86
  options;
296
87
  currentState = "new";
297
88
  sessionUnsubscribers = [];
@@ -307,7 +98,7 @@ var c = class extends e {
307
98
  constructor(t) {
308
99
  this.options = t, this.id = t.id, this.destination = t.destination, this.platform = t.platform, this.capabilities = t.capabilities ?? /* @__PURE__ */ new Set();
309
100
  try {
310
- ee.forEach((e) => {
101
+ u.forEach((e) => {
311
102
  this.sessionUnsubscribers.push(t.session.on(e, (t) => this.handleSessionEvent(e, t)));
312
103
  });
313
104
  } catch (n) {
@@ -368,13 +159,13 @@ var c = class extends e {
368
159
  this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
369
160
  }
370
161
  async transfer(e, t) {
371
- if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !ne(e) || e.target.trim() === "") throw this.operationError();
162
+ if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !m(e) || e.target.trim() === "") throw this.operationError();
372
163
  this.invoke(() => this.options.session.refer(e.target.trim()));
373
164
  }
374
165
  async hangup(e) {
375
- if (this.assertNotDisposed(), this.assertOwner(e), h(this.currentState)) throw this.operationError();
166
+ if (this.assertNotDisposed(), this.assertOwner(e), p(this.currentState)) throw this.operationError();
376
167
  try {
377
- this.options.session.terminate(), h(this.currentState) || this.transitionTo("ended");
168
+ this.options.session.terminate(), p(this.currentState) || this.transitionTo("ended");
378
169
  } catch (e) {
379
170
  throw this.operationError(e);
380
171
  }
@@ -402,7 +193,7 @@ var c = class extends e {
402
193
  }
403
194
  dispose() {
404
195
  if (!this.disposed) {
405
- if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !h(this.currentState)) try {
196
+ if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !p(this.currentState)) try {
406
197
  this.options.session.terminate();
407
198
  } catch (e) {
408
199
  this.reportOperationError(e);
@@ -414,7 +205,7 @@ var c = class extends e {
414
205
  }
415
206
  }
416
207
  handleSessionEvent(e, t) {
417
- if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || h(this.currentState))) switch (e) {
208
+ if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || p(this.currentState))) switch (e) {
418
209
  case "progress":
419
210
  this.transitionIfAllowed("ringing", t, e);
420
211
  break;
@@ -452,7 +243,7 @@ var c = class extends e {
452
243
  if (this.currentState === e) return;
453
244
  if (!o(this.currentState, e)) throw this.operationError();
454
245
  let n = this.currentState;
455
- this.currentState = e, h(e) && this.rejectPendingOperation();
246
+ this.currentState = e, p(e) && this.rejectPendingOperation();
456
247
  try {
457
248
  this.options.onStateChanged?.({
458
249
  callId: this.id,
@@ -460,7 +251,7 @@ var c = class extends e {
460
251
  to: e
461
252
  }, t);
462
253
  } catch {} finally {
463
- h(e) && this.dispose();
254
+ p(e) && this.dispose();
464
255
  }
465
256
  }
466
257
  startPendingOperation(e, t, n) {
@@ -472,7 +263,7 @@ var c = class extends e {
472
263
  resolve: r,
473
264
  reject: i
474
265
  };
475
- this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), te);
266
+ this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), d);
476
267
  let o;
477
268
  try {
478
269
  o = n();
@@ -485,7 +276,7 @@ var c = class extends e {
485
276
  }
486
277
  resolvePendingOperation(e) {
487
278
  if (this.pendingOperation === e) {
488
- if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || h(this.currentState)) {
279
+ if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || p(this.currentState)) {
489
280
  e.reject(this.operationError());
490
281
  return;
491
282
  }
@@ -585,32 +376,32 @@ var c = class extends e {
585
376
  });
586
377
  }
587
378
  };
588
- function h(e) {
379
+ function p(e) {
589
380
  return e === "ended" || e === "failed";
590
381
  }
591
- function ne(e) {
382
+ function m(e) {
592
383
  return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
593
384
  }
594
385
  //#endregion
595
386
  //#region src/core/callId.ts
596
- var g = 0;
597
- function _() {
598
- return g += 1, `call_${Date.now().toString(36)}_${g.toString(36)}`;
387
+ var h = 0;
388
+ function g() {
389
+ return h += 1, `call_${Date.now().toString(36)}_${h.toString(36)}`;
599
390
  }
600
391
  //#endregion
601
392
  //#region src/core/userData.ts
602
- var re = "X-User-Data", v = /[^\x20-\x7E]/, y = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
603
- function b(t) {
393
+ var ee = "X-User-Data", te = /[^\x20-\x7E]/, ne = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
394
+ function _(t) {
604
395
  if (typeof t != "string") return [];
605
396
  let n = t.trim();
606
397
  if (n === "") return [];
607
- if (v.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: y });
608
- return [`${re}: ${n}`];
398
+ if (te.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: ne });
399
+ return [`${ee}: ${n}`];
609
400
  }
610
401
  //#endregion
611
402
  //#region src/core/CallManager.ts
612
- var x = class {
613
- events = new ie();
403
+ var v = class {
404
+ events = new y();
614
405
  calls = /* @__PURE__ */ new Map();
615
406
  options;
616
407
  incomingUnsubscribe;
@@ -643,13 +434,13 @@ var x = class {
643
434
  this.assertNotDisposed();
644
435
  let r = this.operationGeneration, i = t.destination.trim();
645
436
  if (i === "") throw new e("CALL_INVALID_DESTINATION", "call", !1);
646
- let a = b(t.userdata);
437
+ let a = _(t.userdata);
647
438
  this.requireCapability(n, "outbound");
648
439
  let o = this.callLimit(n);
649
440
  if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= o) throw this.capabilityError();
650
441
  if (this.calls.size + this.pendingDialCount >= o || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new e("CALL_ALREADY_EXISTS", "call", !1);
651
442
  this.pendingDialCount += 1, this.pendingDestinations.add(i);
652
- let s = _(), c;
443
+ let s = g(), c;
653
444
  try {
654
445
  c = await this.holdActiveCallForNewCall(), this.assertGeneration(r, s);
655
446
  let e;
@@ -661,7 +452,7 @@ var x = class {
661
452
  this.assertGeneration(r, s);
662
453
  let o;
663
454
  try {
664
- o = new m({
455
+ o = new f({
665
456
  id: s,
666
457
  destination: i,
667
458
  platform: this.options.platform,
@@ -843,10 +634,10 @@ var x = class {
843
634
  }
844
635
  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", {
845
636
  callId: e.id,
846
- reason: ae(n)
637
+ reason: b(n)
847
638
  }) : this.events.emit("call.failed", {
848
639
  callId: e.id,
849
- error: oe(n, e.id)
640
+ error: x(n, e.id)
850
641
  }));
851
642
  }
852
643
  async switchAutomaticActiveCall(e, t, n) {
@@ -912,7 +703,7 @@ var x = class {
912
703
  }
913
704
  handleIncoming(t) {
914
705
  if (this.disposed) return;
915
- let n = _(), r = this.incomingSessionSnapshot;
706
+ let n = g(), r = this.incomingSessionSnapshot;
916
707
  if (r === void 0 || !r.policy.incomingEnabled || !this.effectiveCapabilities(r).has("inbound")) {
917
708
  this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
918
709
  return;
@@ -924,7 +715,7 @@ var x = class {
924
715
  }
925
716
  let a;
926
717
  try {
927
- a = new m({
718
+ a = new f({
928
719
  id: n,
929
720
  destination: i,
930
721
  platform: this.options.platform,
@@ -1053,7 +844,7 @@ var x = class {
1053
844
  cause: t
1054
845
  });
1055
846
  }
1056
- }, ie = class {
847
+ }, y = class {
1057
848
  handlers = /* @__PURE__ */ new Map();
1058
849
  on(e, t) {
1059
850
  let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
@@ -1078,12 +869,12 @@ var x = class {
1078
869
  this.handlers.clear();
1079
870
  }
1080
871
  };
1081
- function ae(e) {
872
+ function b(e) {
1082
873
  if (typeof e != "object" || !e || !("reason" in e)) return "ended";
1083
874
  let t = e.reason;
1084
875
  return typeof t == "string" && t !== "" ? t : "ended";
1085
876
  }
1086
- function oe(t, n) {
877
+ function x(t, n) {
1087
878
  if (t instanceof e) return new e(t.code, t.category, t.retryable, {
1088
879
  requestId: t.requestId,
1089
880
  callId: n,
@@ -1108,7 +899,7 @@ function oe(t, n) {
1108
899
  }
1109
900
  //#endregion
1110
901
  //#region src/shared/SharedWorkerClient.ts
1111
- var se = class {
902
+ var S = class {
1112
903
  port;
1113
904
  timeoutMs;
1114
905
  pending = /* @__PURE__ */ new Map();
@@ -1145,13 +936,13 @@ var se = class {
1145
936
  try {
1146
937
  let n = t(e);
1147
938
  if (n.type === "event") {
1148
- n.event === "connection.stateChanged" && ce(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
939
+ n.event === "connection.stateChanged" && re(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
1149
940
  return;
1150
941
  }
1151
942
  if (n.type !== "response") return;
1152
943
  let r = this.pending.get(n.requestId);
1153
944
  if (r === void 0) return;
1154
- this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(le(n));
945
+ this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(ie(n));
1155
946
  } catch (e) {
1156
947
  this.pending.forEach((t) => {
1157
948
  clearTimeout(t.timer), t.reject(e);
@@ -1159,10 +950,10 @@ var se = class {
1159
950
  }
1160
951
  }
1161
952
  };
1162
- function ce(e) {
953
+ function re(e) {
1163
954
  return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1164
955
  }
1165
- function le(t) {
956
+ function ie(t) {
1166
957
  let n = t.error;
1167
958
  return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1168
959
  requestId: t.requestId,
@@ -1173,12 +964,12 @@ function le(t) {
1173
964
  }
1174
965
  //#endregion
1175
966
  //#region src/shared/SharedWorkerFactory.ts
1176
- function S(t = {}) {
967
+ function C(t = {}) {
1177
968
  if ((t.enabled ?? "auto") === !1) return {
1178
969
  mode: "single-tab",
1179
970
  reason: "disabled"
1180
971
  };
1181
- let n = t.locationHref ?? w(), r = C(t.url, n), i = (n) => {
972
+ let n = t.locationHref ?? T(), r = w(t.url, n), i = (n) => {
1182
973
  if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
1183
974
  return {
1184
975
  mode: "single-tab",
@@ -1186,8 +977,8 @@ function S(t = {}) {
1186
977
  };
1187
978
  };
1188
979
  if (r === void 0) return i("SharedWorker URL is unavailable");
1189
- if (!de(r, n)) return i("SharedWorker URL must be same-origin");
1190
- let a = t.workerCtor ?? ue();
980
+ if (!oe(r, n)) return i("SharedWorker URL must be same-origin");
981
+ let a = t.workerCtor ?? ae();
1191
982
  if (a === void 0) return i("SharedWorker is not supported");
1192
983
  let o;
1193
984
  try {
@@ -1195,7 +986,7 @@ function S(t = {}) {
1195
986
  } catch (e) {
1196
987
  return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1197
988
  }
1198
- let s = t.tabId ?? T(), c = new se(o.port), l = {
989
+ let s = t.tabId ?? se(), c = new S(o.port), l = {
1199
990
  version: 1,
1200
991
  type: "attach",
1201
992
  requestId: E(),
@@ -1212,20 +1003,20 @@ function S(t = {}) {
1212
1003
  ready: u
1213
1004
  };
1214
1005
  }
1215
- function C(e, t = w()) {
1006
+ function w(e, t = T()) {
1216
1007
  try {
1217
1008
  return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
1218
1009
  } catch {
1219
1010
  return;
1220
1011
  }
1221
1012
  }
1222
- function w() {
1013
+ function T() {
1223
1014
  return typeof location > "u" ? void 0 : location.href;
1224
1015
  }
1225
- function ue() {
1016
+ function ae() {
1226
1017
  if (typeof SharedWorker == "function") return SharedWorker;
1227
1018
  }
1228
- function de(e, t) {
1019
+ function oe(e, t) {
1229
1020
  if (t === void 0) return !0;
1230
1021
  try {
1231
1022
  return new URL(e, t).origin === new URL(t).origin;
@@ -1233,7 +1024,7 @@ function de(e, t) {
1233
1024
  return !1;
1234
1025
  }
1235
1026
  }
1236
- function T() {
1027
+ function se() {
1237
1028
  return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1238
1029
  }
1239
1030
  function E() {
@@ -1566,7 +1357,7 @@ var V = class {
1566
1357
  mediaDevices: e.mediaDevices,
1567
1358
  createAudioElement: e.createAudioElement
1568
1359
  };
1569
- this.deviceManager = new D(t), this.remoteAudio = new F(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? pe;
1360
+ this.deviceManager = new D(t), this.remoteAudio = new F(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? le;
1570
1361
  }
1571
1362
  requestPermission(e) {
1572
1363
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1773,7 +1564,7 @@ var V = class {
1773
1564
  try {
1774
1565
  c = s.getTracks();
1775
1566
  } catch (t) {
1776
- throw fe(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1567
+ throw ce(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1777
1568
  callId: n.callId,
1778
1569
  cause: t
1779
1570
  });
@@ -1945,7 +1736,7 @@ function G(e) {
1945
1736
  return W(e) ? Promise.resolve() : Promise.reject(e);
1946
1737
  }
1947
1738
  }
1948
- function fe(e) {
1739
+ function ce(e) {
1949
1740
  try {
1950
1741
  K(e.getTracks());
1951
1742
  } catch {}
@@ -1958,7 +1749,7 @@ function q(e) {
1958
1749
  e.stop();
1959
1750
  } catch {}
1960
1751
  }
1961
- function pe(e) {
1752
+ function le(e) {
1962
1753
  if (typeof MediaStream < "u") try {
1963
1754
  return new MediaStream([e]);
1964
1755
  } catch {
@@ -1967,7 +1758,7 @@ function pe(e) {
1967
1758
  }
1968
1759
  //#endregion
1969
1760
  //#region src/core/mediaBridge.ts
1970
- function me(t, n = {}) {
1761
+ function ue(t, n = {}) {
1971
1762
  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 V({ getActiveCall: u });
1972
1763
  return {
1973
1764
  publicMedia: {
@@ -2026,7 +1817,7 @@ function me(t, n = {}) {
2026
1817
  function p(e, t) {
2027
1818
  if (!J(t) || typeof t.getMediaRegistration != "function") return;
2028
1819
  let n = t.getMediaRegistration();
2029
- if (he(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1820
+ if (de(n) && r.get(e)?.peerConnection !== n.peerConnection) {
2030
1821
  r.set(e, n);
2031
1822
  try {
2032
1823
  d.registerCallMedia(e, n);
@@ -2039,19 +1830,19 @@ function me(t, n = {}) {
2039
1830
  function J(e) {
2040
1831
  return typeof e == "object" && !!e;
2041
1832
  }
2042
- function he(e) {
1833
+ function de(e) {
2043
1834
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
2044
1835
  }
2045
1836
  //#endregion
2046
1837
  //#region src/reconnect/backoff.ts
2047
- var ge = 1e3, _e = 3e4;
2048
- function ve(e, t = Math.random) {
2049
- let n = Math.min(_e, ge * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
1838
+ var fe = 1e3, pe = 3e4;
1839
+ function me(e, t = Math.random) {
1840
+ let n = Math.min(pe, fe * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
2050
1841
  return Math.round(n * (1 + r * .2));
2051
1842
  }
2052
1843
  //#endregion
2053
1844
  //#region src/reconnect/ReconnectManager.ts
2054
- var ye = class {
1845
+ var he = class {
2055
1846
  recover;
2056
1847
  random;
2057
1848
  isOnline;
@@ -2068,7 +1859,7 @@ var ye = class {
2068
1859
  }
2069
1860
  start() {
2070
1861
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
2071
- let e = this.generation, t = ve(this.attempt, this.random);
1862
+ let e = this.generation, t = me(this.attempt, this.random);
2072
1863
  this.pendingTimer = setTimeout(() => {
2073
1864
  this.pendingTimer = void 0, this.run(e);
2074
1865
  }, t);
@@ -2110,7 +1901,7 @@ var ye = class {
2110
1901
  clearPendingTimer() {
2111
1902
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
2112
1903
  }
2113
- }, be = class t {
1904
+ }, ge = class t {
2114
1905
  media;
2115
1906
  options;
2116
1907
  api;
@@ -2144,18 +1935,10 @@ var ye = class {
2144
1935
  deletedSessions = /* @__PURE__ */ new Set();
2145
1936
  ownedSessionIds = /* @__PURE__ */ new Set();
2146
1937
  terminalReleaseOperations = /* @__PURE__ */ new Map();
2147
- tokenRequest = {};
2148
1938
  sharedWorkerSelection;
2149
1939
  constructor(t) {
2150
- if (this.options = t, t.api === void 0 && t.sessionProvider === void 0 && t.tokenProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 tokenProvider 或 sessionProvider" });
2151
- let n = t.tokenProvider, i = (t) => n === void 0 ? Promise.reject(new e("CONFIG_INVALID", "configuration", !1, { cause: "未提供 tokenProvider" })) : n({
2152
- ...t,
2153
- ...this.tokenRequest
2154
- });
2155
- this.api = t.api === void 0 ? t.sessionProvider === void 0 ? new p({
2156
- baseUrl: t.baseUrl ?? "",
2157
- tokenProvider: i
2158
- }) : Y(Ce(t.sessionProvider)) : Y(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : X(t.sip), this.mediaBridge = me(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new ye({
1940
+ if (this.options = t, t.api === void 0 && t.sessionProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 sessionProvider" });
1941
+ this.api = t.api === void 0 ? X(ve(t.sessionProvider)) : X(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : ye(t.sip), this.mediaBridge = ue(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new he({
2159
1942
  recover: () => this.recoverConnection(),
2160
1943
  onAttempt: (e) => {
2161
1944
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
@@ -2167,13 +1950,13 @@ var ye = class {
2167
1950
  }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2168
1951
  mode: "single-tab",
2169
1952
  reason: "disabled"
2170
- } : S({
1953
+ } : C({
2171
1954
  ...t.sharedWorker,
2172
1955
  ...t.sharedWorkerHost ?? {}
2173
1956
  });
2174
1957
  }
2175
1958
  static async checkSupport() {
2176
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Se(typeof navigator < "u" ? navigator.userAgent : "");
1959
+ let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Y(typeof navigator < "u" ? navigator.userAgent : "");
2177
1960
  return {
2178
1961
  supported: e && t,
2179
1962
  platform: n,
@@ -2187,15 +1970,13 @@ var ye = class {
2187
1970
  let e = await t.checkSupport();
2188
1971
  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;
2189
1972
  }
2190
- connect(e) {
2191
- this.assertNotDisposed();
2192
- let t = e?.extension?.trim();
2193
- if (this.tokenRequest = t === void 0 || t === "" ? {} : { extension: t }, this.api.invalidateToken?.(), this.connectOperation !== void 0) return this.connectOperation;
1973
+ connect() {
1974
+ if (this.assertNotDisposed(), this.api.invalidateToken?.(), this.connectOperation !== void 0) return this.connectOperation;
2194
1975
  if (this.state === "connected") return Promise.resolve();
2195
- let n = this.lifecycleGeneration, r = this.performConnect(n).finally(() => {
2196
- this.connectOperation === r && (this.connectOperation = void 0);
1976
+ let e = this.lifecycleGeneration, t = this.performConnect(e).finally(() => {
1977
+ this.connectOperation === t && (this.connectOperation = void 0);
2197
1978
  });
2198
- return this.connectOperation = r, r;
1979
+ return this.connectOperation = t, t;
2199
1980
  }
2200
1981
  disconnect() {
2201
1982
  if (this.assertNotDisposed(), this.disconnectOperation !== void 0) return this.disconnectOperation;
@@ -2260,10 +2041,12 @@ var ye = class {
2260
2041
  return this.diagnostics.getReport(e);
2261
2042
  }
2262
2043
  async setAgentStatus(e) {
2263
- this.assertNotDisposed(), await this.api.setAgentStatus({
2044
+ this.assertNotDisposed();
2045
+ let t = this.session?.transport.wssUrl;
2046
+ await this.api.setAgentStatus({
2264
2047
  status: e,
2265
2048
  reason: ""
2266
- }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
2049
+ }, t === void 0 ? void 0 : { wssUrl: t }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
2267
2050
  }
2268
2051
  on(e, t) {
2269
2052
  return this.disposed ? () => void 0 : this.events.on(e, t);
@@ -2280,7 +2063,7 @@ var ye = class {
2280
2063
  sdkVersion: n,
2281
2064
  platform: a === "mobile-web" ? "mobile_web" : "web",
2282
2065
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2283
- requestedCapabilities: [...this.options.requestedCapabilities ?? De(a)]
2066
+ requestedCapabilities: [...this.options.requestedCapabilities ?? Ce(a)]
2284
2067
  }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2285
2068
  let o = this.callManager ?? this.createCallManager(r, t, a);
2286
2069
  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);
@@ -2331,7 +2114,7 @@ var ye = class {
2331
2114
  if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
2332
2115
  }
2333
2116
  createCallManager(e, t, n) {
2334
- let r = new x({
2117
+ let r = new v({
2335
2118
  sip: e,
2336
2119
  platform: n,
2337
2120
  session: t,
@@ -2386,7 +2169,7 @@ var ye = class {
2386
2169
  try {
2387
2170
  await this.media.releaseAll();
2388
2171
  } catch (t) {
2389
- we(t) || (e ??= t);
2172
+ be(t) || (e ??= t);
2390
2173
  }
2391
2174
  try {
2392
2175
  await this.mediaBridge.dispose();
@@ -2586,7 +2369,7 @@ var ye = class {
2586
2369
  destination: e.destination
2587
2370
  })),
2588
2371
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2589
- ice: xe(e),
2372
+ ice: _e(e),
2590
2373
  wss: {
2591
2374
  configured: e !== void 0,
2592
2375
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2703,7 +2486,7 @@ var ye = class {
2703
2486
  return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2704
2487
  }
2705
2488
  };
2706
- function xe(e) {
2489
+ function _e(e) {
2707
2490
  if (e === void 0) return {
2708
2491
  configured: !1,
2709
2492
  serverCount: 0,
@@ -2721,14 +2504,14 @@ function xe(e) {
2721
2504
  turnServerCount: n
2722
2505
  };
2723
2506
  }
2724
- function Se(e) {
2507
+ function Y(e) {
2725
2508
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2726
2509
  }
2727
- function Y(t) {
2510
+ function X(t) {
2728
2511
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2729
2512
  return t;
2730
2513
  }
2731
- function Ce(t) {
2514
+ function ve(t) {
2732
2515
  let r = {
2733
2516
  createSession: (e) => t.createSession(e),
2734
2517
  refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
@@ -2738,11 +2521,11 @@ function Ce(t) {
2738
2521
  deleteSession: async (e) => {
2739
2522
  t.deleteSession !== void 0 && await t.deleteSession(e);
2740
2523
  },
2741
- setAgentStatus: (n) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n)
2524
+ setAgentStatus: (n, r) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n, r)
2742
2525
  }, i = t.invalidateToken;
2743
2526
  return i !== void 0 && (r.invalidateToken = () => i()), r;
2744
2527
  }
2745
- function X(t) {
2528
+ function ye(t) {
2746
2529
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2747
2530
  return t;
2748
2531
  }
@@ -2761,13 +2544,13 @@ function Z(t, n, r, i, a) {
2761
2544
  function Q(t) {
2762
2545
  return t instanceof e ? t.status !== void 0 && t.status >= 400 && t.status < 500 || t.serverCode === "SESSION_NOT_FOUND" || t.serverCode === "SESSION_EXPIRED" || t.serverCode === "TOKEN_INVALID" || t.serverCode === "TOKEN_EXPIRED" || t.code === "AUTH_TOKEN_UNAVAILABLE" || t.code === "AUTH_TOKEN_EXPIRED" : !1;
2763
2546
  }
2764
- function we(t) {
2547
+ function be(t) {
2765
2548
  return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2766
2549
  }
2767
2550
  function $(t) {
2768
2551
  return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
2769
2552
  }
2770
- var Te = [
2553
+ var xe = [
2771
2554
  "outbound",
2772
2555
  "inbound",
2773
2556
  "mute",
@@ -2775,13 +2558,13 @@ var Te = [
2775
2558
  "dtmf",
2776
2559
  "blind_transfer",
2777
2560
  "device_selection"
2778
- ], Ee = [
2561
+ ], Se = [
2779
2562
  "outbound",
2780
2563
  "mute",
2781
2564
  "dtmf"
2782
2565
  ];
2783
- function De(e) {
2784
- return e === "mobile-web" ? Ee : Te;
2566
+ function Ce(e) {
2567
+ return e === "mobile-web" ? Se : xe;
2785
2568
  }
2786
2569
  //#endregion
2787
- export { m as a, c, l as d, a as f, x as i, s as l, S as n, p as o, i as p, C as r, d as s, be as t, o as u };
2570
+ export { f as a, o as c, i as d, v as i, l, C as n, c as o, w as r, s, ge as t, a as u };