@16x/webphone-sdk 3.1.10 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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-WkQagE6_.js";
2
+ import { r as n, t as r } from "./Diagnostics-Cs02iAlB.js";
3
3
  //#region src/events/TypedEventBus.ts
4
4
  var i = class {
5
5
  handlers = /* @__PURE__ */ new Map();
@@ -637,7 +637,7 @@ var v = class {
637
637
  reason: b(n)
638
638
  }) : this.events.emit("call.failed", {
639
639
  callId: e.id,
640
- error: re(n, e.id)
640
+ error: x(n, e.id)
641
641
  }));
642
642
  }
643
643
  async switchAutomaticActiveCall(e, t, n) {
@@ -874,7 +874,7 @@ function b(e) {
874
874
  let t = e.reason;
875
875
  return typeof t == "string" && t !== "" ? t : "ended";
876
876
  }
877
- function re(t, n) {
877
+ function x(t, n) {
878
878
  if (t instanceof e) return new e(t.code, t.category, t.retryable, {
879
879
  requestId: t.requestId,
880
880
  callId: n,
@@ -898,65 +898,8 @@ function re(t, n) {
898
898
  });
899
899
  }
900
900
  //#endregion
901
- //#region src/crypto/legacySipTicket.ts
902
- var ie = "q7X4p6MvK1z8Lb3A", ae = "W9e2T4mN0aQ7Ru6C", oe = 16, se = "�";
903
- function ce(e) {
904
- for (let t of e) {
905
- let e = t.codePointAt(0) ?? 0;
906
- if (e === 127 || e < 32 && e !== 9) return !0;
907
- }
908
- return !1;
909
- }
910
- async function x(t, n = {}) {
911
- let r = String(t ?? "").replace(/\s+/g, "");
912
- if (!r) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
913
- let i = n.subtle ?? globalThis.crypto?.subtle;
914
- if (i === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
915
- let a = S(r);
916
- if (a === void 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
917
- let o = await i.importKey("raw", C(n.key ?? ie), "AES-CBC", !1, ["decrypt"]);
918
- try {
919
- let e = await i.decrypt({
920
- name: "AES-CBC",
921
- iv: C(n.iv ?? ae)
922
- }, o, a);
923
- return new TextDecoder("utf-8").decode(e).trim();
924
- } catch (t) {
925
- throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: `SIP 密码解密失败(检查 key/iv 与该环境是否一致):${t instanceof Error ? t.message : String(t)}` });
926
- }
927
- }
928
- async function le(e, t = {}) {
929
- let n = String(e ?? "").replace(/\s+/g, "");
930
- if (ue(n)) try {
931
- let e = await x(n, t);
932
- return de(e) ? e : void 0;
933
- } catch {
934
- return;
935
- }
936
- }
937
- function ue(e) {
938
- let t = S(e);
939
- return t !== void 0 && t.byteLength > 0 && t.byteLength % oe === 0;
940
- }
941
- function de(e) {
942
- return e.length === 0 || e.includes(se) ? !1 : !ce(e);
943
- }
944
- function S(e) {
945
- if (e.length !== 0 && e.length % 4 == 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(e)) try {
946
- let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length));
947
- for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
948
- return n;
949
- } catch {
950
- return;
951
- }
952
- }
953
- function C(e) {
954
- let t = new TextEncoder().encode(e), n = new Uint8Array(new ArrayBuffer(t.byteLength));
955
- return n.set(t), n;
956
- }
957
- //#endregion
958
901
  //#region src/shared/SharedWorkerClient.ts
959
- var fe = class {
902
+ var S = class {
960
903
  port;
961
904
  timeoutMs;
962
905
  pending = /* @__PURE__ */ new Map();
@@ -993,13 +936,13 @@ var fe = class {
993
936
  try {
994
937
  let n = t(e);
995
938
  if (n.type === "event") {
996
- n.event === "connection.stateChanged" && pe(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));
997
940
  return;
998
941
  }
999
942
  if (n.type !== "response") return;
1000
943
  let r = this.pending.get(n.requestId);
1001
944
  if (r === void 0) return;
1002
- this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(me(n));
945
+ this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(ie(n));
1003
946
  } catch (e) {
1004
947
  this.pending.forEach((t) => {
1005
948
  clearTimeout(t.timer), t.reject(e);
@@ -1007,10 +950,10 @@ var fe = class {
1007
950
  }
1008
951
  }
1009
952
  };
1010
- function pe(e) {
953
+ function re(e) {
1011
954
  return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1012
955
  }
1013
- function me(t) {
956
+ function ie(t) {
1014
957
  let n = t.error;
1015
958
  return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1016
959
  requestId: t.requestId,
@@ -1021,12 +964,12 @@ function me(t) {
1021
964
  }
1022
965
  //#endregion
1023
966
  //#region src/shared/SharedWorkerFactory.ts
1024
- function w(t = {}) {
967
+ function C(t = {}) {
1025
968
  if ((t.enabled ?? "auto") === !1) return {
1026
969
  mode: "single-tab",
1027
970
  reason: "disabled"
1028
971
  };
1029
- let n = t.locationHref ?? E(), r = T(t.url, n), i = (n) => {
972
+ let n = t.locationHref ?? T(), r = w(t.url, n), i = (n) => {
1030
973
  if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
1031
974
  return {
1032
975
  mode: "single-tab",
@@ -1034,8 +977,8 @@ function w(t = {}) {
1034
977
  };
1035
978
  };
1036
979
  if (r === void 0) return i("SharedWorker URL is unavailable");
1037
- if (!O(r, n)) return i("SharedWorker URL must be same-origin");
1038
- let a = t.workerCtor ?? D();
980
+ if (!oe(r, n)) return i("SharedWorker URL must be same-origin");
981
+ let a = t.workerCtor ?? ae();
1039
982
  if (a === void 0) return i("SharedWorker is not supported");
1040
983
  let o;
1041
984
  try {
@@ -1043,10 +986,10 @@ function w(t = {}) {
1043
986
  } catch (e) {
1044
987
  return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1045
988
  }
1046
- let s = t.tabId ?? k(), c = new fe(o.port), l = {
989
+ let s = t.tabId ?? se(), c = new S(o.port), l = {
1047
990
  version: 1,
1048
991
  type: "attach",
1049
- requestId: A(),
992
+ requestId: E(),
1050
993
  tabId: s
1051
994
  }, u = c.request(l).then(() => void 0).catch((e) => {
1052
995
  throw c.close(), e;
@@ -1060,20 +1003,20 @@ function w(t = {}) {
1060
1003
  ready: u
1061
1004
  };
1062
1005
  }
1063
- function T(e, t = E()) {
1006
+ function w(e, t = T()) {
1064
1007
  try {
1065
1008
  return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
1066
1009
  } catch {
1067
1010
  return;
1068
1011
  }
1069
1012
  }
1070
- function E() {
1013
+ function T() {
1071
1014
  return typeof location > "u" ? void 0 : location.href;
1072
1015
  }
1073
- function D() {
1016
+ function ae() {
1074
1017
  if (typeof SharedWorker == "function") return SharedWorker;
1075
1018
  }
1076
- function O(e, t) {
1019
+ function oe(e, t) {
1077
1020
  if (t === void 0) return !0;
1078
1021
  try {
1079
1022
  return new URL(e, t).origin === new URL(t).origin;
@@ -1081,15 +1024,15 @@ function O(e, t) {
1081
1024
  return !1;
1082
1025
  }
1083
1026
  }
1084
- function k() {
1027
+ function se() {
1085
1028
  return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1086
1029
  }
1087
- function A() {
1030
+ function E() {
1088
1031
  return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1089
1032
  }
1090
1033
  //#endregion
1091
1034
  //#region src/media/DeviceManager.ts
1092
- var j = class {
1035
+ var D = class {
1093
1036
  mediaDevices;
1094
1037
  createAudioElement;
1095
1038
  outputCapability;
@@ -1097,23 +1040,23 @@ var j = class {
1097
1040
  outputGeneration = 0;
1098
1041
  outputTail;
1099
1042
  constructor(e = {}) {
1100
- this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? M(), this.createAudioElement = e.createAudioElement;
1043
+ this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? O(), this.createAudioElement = e.createAudioElement;
1101
1044
  }
1102
1045
  async requestPermission(e = {}) {
1103
1046
  let t = this.requireMediaDevices(), n;
1104
1047
  try {
1105
1048
  n = await t.getUserMedia({ audio: e });
1106
1049
  } catch (e) {
1107
- throw F(e);
1050
+ throw j(e);
1108
1051
  }
1109
- N(n);
1052
+ k(n);
1110
1053
  }
1111
1054
  async getDevices() {
1112
1055
  if (this.mediaDevices === void 0) return [];
1113
1056
  try {
1114
1057
  return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
1115
1058
  } catch (e) {
1116
- throw I(e);
1059
+ throw M(e);
1117
1060
  }
1118
1061
  }
1119
1062
  getCapabilities() {
@@ -1151,7 +1094,7 @@ var j = class {
1151
1094
  try {
1152
1095
  await r.setSinkId(t);
1153
1096
  } catch (e) {
1154
- throw L(e);
1097
+ throw N(e);
1155
1098
  }
1156
1099
  }
1157
1100
  enqueueOutput(e) {
@@ -1165,7 +1108,7 @@ var j = class {
1165
1108
  try {
1166
1109
  return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
1167
1110
  } catch (e) {
1168
- throw P(e);
1111
+ throw A(e);
1169
1112
  }
1170
1113
  }
1171
1114
  requireMediaDevices() {
@@ -1185,10 +1128,10 @@ var j = class {
1185
1128
  }
1186
1129
  }
1187
1130
  };
1188
- function M() {
1131
+ function O() {
1189
1132
  return globalThis.navigator?.mediaDevices;
1190
1133
  }
1191
- function N(e) {
1134
+ function k(e) {
1192
1135
  let t;
1193
1136
  try {
1194
1137
  t = e.getTracks();
@@ -1201,57 +1144,57 @@ function N(e) {
1201
1144
  } catch {}
1202
1145
  });
1203
1146
  }
1204
- function P(t) {
1205
- let n = R(t);
1147
+ function A(t) {
1148
+ let n = P(t);
1206
1149
  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 });
1207
1150
  }
1208
- function F(t) {
1209
- let n = R(t);
1151
+ function j(t) {
1152
+ let n = P(t);
1210
1153
  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 });
1211
1154
  }
1212
- function I(t) {
1213
- let n = R(t);
1155
+ function M(t) {
1156
+ let n = P(t);
1214
1157
  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 });
1215
1158
  }
1216
- function L(t) {
1217
- let n = R(t);
1159
+ function N(t) {
1160
+ let n = P(t);
1218
1161
  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 });
1219
1162
  }
1220
- function R(e) {
1163
+ function P(e) {
1221
1164
  if (typeof e != "object" || !e || !("name" in e)) return;
1222
1165
  let t = e.name;
1223
1166
  return typeof t == "string" ? t : void 0;
1224
1167
  }
1225
1168
  //#endregion
1226
1169
  //#region src/media/RemoteAudio.ts
1227
- var z = class {
1170
+ var F = class {
1228
1171
  createAudioElement;
1229
1172
  bindings = /* @__PURE__ */ new Map();
1230
1173
  audioOwners = /* @__PURE__ */ new Map();
1231
1174
  trackOwners = /* @__PURE__ */ new Map();
1232
1175
  generations = /* @__PURE__ */ new Map();
1233
1176
  pendingPlays = /* @__PURE__ */ new Map();
1234
- constructor(e = he) {
1177
+ constructor(e = I) {
1235
1178
  this.createAudioElement = e;
1236
1179
  }
1237
1180
  async bind(t, n) {
1238
1181
  let r = this.bindings.get(t);
1239
1182
  if (r?.stream === n) return;
1240
- let i = ge(t, n), a;
1183
+ let i = L(t, n), a;
1241
1184
  try {
1242
1185
  a = this.createAudioElement();
1243
1186
  } catch (n) {
1244
- throw B(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1187
+ throw R(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1245
1188
  callId: t,
1246
1189
  cause: n
1247
1190
  });
1248
1191
  }
1249
1192
  let o = this.audioOwners.get(a);
1250
- if (o !== void 0 && o !== t) throw B(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1193
+ if (o !== void 0 && o !== t) throw R(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1251
1194
  try {
1252
1195
  a.autoplay = !0, a.playsInline = !0;
1253
1196
  } catch (n) {
1254
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1197
+ throw R(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1255
1198
  callId: t,
1256
1199
  cause: n
1257
1200
  });
@@ -1259,7 +1202,7 @@ var z = class {
1259
1202
  try {
1260
1203
  a.srcObject = n;
1261
1204
  } catch (n) {
1262
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1205
+ throw R(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1263
1206
  callId: t,
1264
1207
  cause: n
1265
1208
  });
@@ -1335,7 +1278,7 @@ var z = class {
1335
1278
  releaseTrack(e) {
1336
1279
  let t = this.trackOwners.get(e);
1337
1280
  if (t === void 0 || t <= 1) {
1338
- this.trackOwners.delete(e), V(e);
1281
+ this.trackOwners.delete(e), B(e);
1339
1282
  return;
1340
1283
  }
1341
1284
  this.trackOwners.set(e, t - 1);
@@ -1358,42 +1301,42 @@ var z = class {
1358
1301
  return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
1359
1302
  }
1360
1303
  };
1361
- function he() {
1304
+ function I() {
1362
1305
  if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1363
1306
  return document.createElement("audio");
1364
1307
  }
1365
- function ge(t, n) {
1308
+ function L(t, n) {
1366
1309
  try {
1367
1310
  return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
1368
1311
  } catch (r) {
1369
1312
  try {
1370
1313
  return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
1371
1314
  } catch (i) {
1372
- throw _e(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1315
+ throw z(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1373
1316
  callId: t,
1374
1317
  cause: r ?? i
1375
1318
  });
1376
1319
  }
1377
1320
  }
1378
1321
  }
1379
- function B(e, t) {
1322
+ function R(e, t) {
1380
1323
  e.forEach((e) => {
1381
- (t.get(e) ?? 0) === 0 && V(e);
1324
+ (t.get(e) ?? 0) === 0 && B(e);
1382
1325
  });
1383
1326
  }
1384
- function _e(e) {
1327
+ function z(e) {
1385
1328
  try {
1386
- [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
1329
+ [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(B);
1387
1330
  } catch {}
1388
1331
  }
1389
- function V(e) {
1332
+ function B(e) {
1390
1333
  try {
1391
1334
  e.stop();
1392
1335
  } catch {}
1393
1336
  }
1394
1337
  //#endregion
1395
1338
  //#region src/media/MediaManager.ts
1396
- var ve = class {
1339
+ var V = class {
1397
1340
  deviceManager;
1398
1341
  remoteAudio;
1399
1342
  getActiveCall;
@@ -1414,7 +1357,7 @@ var ve = class {
1414
1357
  mediaDevices: e.mediaDevices,
1415
1358
  createAudioElement: e.createAudioElement
1416
1359
  };
1417
- this.deviceManager = new j(t), this.remoteAudio = new z(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? xe;
1360
+ this.deviceManager = new D(t), this.remoteAudio = new F(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? le;
1418
1361
  }
1419
1362
  requestPermission(e) {
1420
1363
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1434,7 +1377,7 @@ var ve = class {
1434
1377
  n !== void 0 && this.releaseResource(n).catch((e) => {
1435
1378
  this.releaseErrors.set(n, e);
1436
1379
  });
1437
- let r = ye(t) ? t : { peerConnection: t }, i = {
1380
+ let r = H(t) ? t : { peerConnection: t }, i = {
1438
1381
  callId: e,
1439
1382
  peerConnection: r.peerConnection,
1440
1383
  senders: /* @__PURE__ */ new Map(),
@@ -1516,7 +1459,7 @@ var ve = class {
1516
1459
  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);
1517
1460
  let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
1518
1461
  senderResource: e,
1519
- promise: this.enqueueSender(t, e, () => W(e.sender), !0)
1462
+ promise: this.enqueueSender(t, e, () => G(e.sender), !0)
1520
1463
  })), o = Promise.all(a.map(async (e) => {
1521
1464
  try {
1522
1465
  return await e.promise, {
@@ -1534,14 +1477,14 @@ var ve = class {
1534
1477
  if (n.forEach((e) => {
1535
1478
  if (e.cause !== void 0) {
1536
1479
  o.push(e.cause);
1537
- let t = H(e.senderResource.sender);
1480
+ let t = U(e.senderResource.sender);
1538
1481
  t?.kind === "audio" && a.add(t);
1539
1482
  return;
1540
1483
  }
1541
- let t = H(e.senderResource.sender);
1484
+ let t = U(e.senderResource.sender);
1542
1485
  t?.kind === "audio" && i.add(t);
1543
1486
  }), i.forEach((e) => {
1544
- a.has(e) || K(e);
1487
+ a.has(e) || q(e);
1545
1488
  }), o.length > 0) throw t.localTracks.clear(), t.pendingTracks.clear(), a.forEach((e) => t.localTracks.add(e)), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1546
1489
  callId: r,
1547
1490
  cause: o[0]
@@ -1549,7 +1492,7 @@ var ve = class {
1549
1492
  if (!t.peerClosed && t.peerConnection.close !== void 0) try {
1550
1493
  await t.peerConnection.close(), t.peerClosed = !0;
1551
1494
  } catch (n) {
1552
- let i = [...t.senders.values()].map((e) => H(e.sender)).find((e) => e?.kind === "audio");
1495
+ let i = [...t.senders.values()].map((e) => U(e.sender)).find((e) => e?.kind === "audio");
1553
1496
  throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1554
1497
  callId: r,
1555
1498
  cause: n
@@ -1617,11 +1560,11 @@ var ve = class {
1617
1560
  }
1618
1561
  async performInputSwitch(t, n, r) {
1619
1562
  if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
1620
- let i = this.findAudioSender(r), a = H(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1563
+ let i = this.findAudioSender(r), a = U(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1621
1564
  try {
1622
1565
  c = s.getTracks();
1623
1566
  } catch (t) {
1624
- throw be(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1567
+ throw ce(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1625
1568
  callId: n.callId,
1626
1569
  cause: t
1627
1570
  });
@@ -1630,26 +1573,26 @@ var ve = class {
1630
1573
  try {
1631
1574
  l = s.getAudioTracks();
1632
1575
  } catch (t) {
1633
- throw G(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1576
+ throw K(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1634
1577
  callId: n.callId,
1635
1578
  cause: t
1636
1579
  });
1637
1580
  }
1638
1581
  let u = l[0];
1639
- if (u === void 0) throw G(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1640
- if (!this.canCommitInputSwitch(n, r, i, a, o)) throw G(c), this.callOperationError(n.callId);
1582
+ if (u === void 0) throw K(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1583
+ if (!this.canCommitInputSwitch(n, r, i, a, o)) throw K(c), this.callOperationError(n.callId);
1641
1584
  c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
1642
1585
  try {
1643
1586
  await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
1644
1587
  } catch (t) {
1645
- 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, {
1588
+ 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), K(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
1646
1589
  callId: n.callId,
1647
1590
  cause: t
1648
1591
  }));
1649
1592
  }
1650
1593
  if (!this.canCommitInputSwitch(n, r, i, u, o)) {
1651
1594
  if (!r.released) try {
1652
- 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);
1595
+ await this.enqueueSender(r, i, () => U(i.sender) === u ? G(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), K(c);
1653
1596
  } catch (t) {
1654
1597
  throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
1655
1598
  callId: n.callId,
@@ -1658,8 +1601,8 @@ var ve = class {
1658
1601
  }
1659
1602
  throw this.callOperationError(n.callId);
1660
1603
  }
1661
- 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) => {
1662
- e !== u && K(e);
1604
+ c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), q(a)), c.forEach((e) => {
1605
+ e !== u && q(e);
1663
1606
  });
1664
1607
  }
1665
1608
  ensureCallMedia(e) {
@@ -1682,7 +1625,7 @@ var ve = class {
1682
1625
  });
1683
1626
  }
1684
1627
  r.forEach((r) => {
1685
- let i = H(r), a;
1628
+ let i = U(r), a;
1686
1629
  try {
1687
1630
  a = n?.(r) ?? r.senderKind ?? r.kind;
1688
1631
  } catch (n) {
@@ -1699,7 +1642,7 @@ var ve = class {
1699
1642
  });
1700
1643
  }
1701
1644
  findAudioSender(e) {
1702
- let t = [...e.senders.values()].find((e) => e.audio && (H(e.sender)?.kind === "audio" || H(e.sender) === null));
1645
+ let t = [...e.senders.values()].find((e) => e.audio && (U(e.sender)?.kind === "audio" || U(e.sender) === null));
1703
1646
  if (t === void 0) throw this.capabilityError(e.callId);
1704
1647
  return t;
1705
1648
  }
@@ -1715,7 +1658,7 @@ var ve = class {
1715
1658
  } catch {
1716
1659
  return !1;
1717
1660
  }
1718
- return H(n.sender) === r;
1661
+ return U(n.sender) === r;
1719
1662
  }
1720
1663
  enqueueSender(e, t, n, r = !1) {
1721
1664
  t.queue.pending += 1;
@@ -1744,7 +1687,7 @@ var ve = class {
1744
1687
  });
1745
1688
  }
1746
1689
  async rollbackSender(e, t, n, r) {
1747
- e.released || H(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1690
+ e.released || U(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1748
1691
  }
1749
1692
  isCurrentResource(e, t = e.generation) {
1750
1693
  return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
@@ -1771,42 +1714,42 @@ var ve = class {
1771
1714
  if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1772
1715
  }
1773
1716
  };
1774
- function ye(e) {
1717
+ function H(e) {
1775
1718
  return "peerConnection" in e;
1776
1719
  }
1777
- function H(e) {
1720
+ function U(e) {
1778
1721
  try {
1779
1722
  return e.track;
1780
1723
  } catch {
1781
1724
  return null;
1782
1725
  }
1783
1726
  }
1784
- function U(e) {
1727
+ function W(e) {
1785
1728
  return typeof e == "object" && !!e && e.name === "InvalidStateError";
1786
1729
  }
1787
- function W(e) {
1730
+ function G(e) {
1788
1731
  try {
1789
1732
  return e.replaceTrack(null).catch((e) => {
1790
- if (!U(e)) throw e;
1733
+ if (!W(e)) throw e;
1791
1734
  });
1792
1735
  } catch (e) {
1793
- return U(e) ? Promise.resolve() : Promise.reject(e);
1736
+ return W(e) ? Promise.resolve() : Promise.reject(e);
1794
1737
  }
1795
1738
  }
1796
- function be(e) {
1739
+ function ce(e) {
1797
1740
  try {
1798
- G(e.getTracks());
1741
+ K(e.getTracks());
1799
1742
  } catch {}
1800
1743
  }
1801
- function G(e) {
1802
- e.forEach(K);
1803
- }
1804
1744
  function K(e) {
1745
+ e.forEach(q);
1746
+ }
1747
+ function q(e) {
1805
1748
  try {
1806
1749
  e.stop();
1807
1750
  } catch {}
1808
1751
  }
1809
- function xe(e) {
1752
+ function le(e) {
1810
1753
  if (typeof MediaStream < "u") try {
1811
1754
  return new MediaStream([e]);
1812
1755
  } catch {
@@ -1815,8 +1758,8 @@ function xe(e) {
1815
1758
  }
1816
1759
  //#endregion
1817
1760
  //#region src/core/mediaBridge.ts
1818
- function Se(t, n = {}) {
1819
- 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 });
1761
+ function ue(t, n = {}) {
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 });
1820
1763
  return {
1821
1764
  publicMedia: {
1822
1765
  requestPermission: () => (f(), d.requestPermission()),
@@ -1829,7 +1772,7 @@ function Se(t, n = {}) {
1829
1772
  releaseAll: () => (f(), d.releaseAll())
1830
1773
  },
1831
1774
  registerCall(e, t) {
1832
- s || c || !q(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1775
+ s || c || !J(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1833
1776
  },
1834
1777
  async setCallOwnership(e, t) {
1835
1778
  if (s) return;
@@ -1872,9 +1815,9 @@ function Se(t, n = {}) {
1872
1815
  if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1873
1816
  }
1874
1817
  function p(e, t) {
1875
- if (!q(t) || typeof t.getMediaRegistration != "function") return;
1818
+ if (!J(t) || typeof t.getMediaRegistration != "function") return;
1876
1819
  let n = t.getMediaRegistration();
1877
- if (Ce(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1820
+ if (de(n) && r.get(e)?.peerConnection !== n.peerConnection) {
1878
1821
  r.set(e, n);
1879
1822
  try {
1880
1823
  d.registerCallMedia(e, n);
@@ -1884,22 +1827,22 @@ function Se(t, n = {}) {
1884
1827
  }
1885
1828
  }
1886
1829
  }
1887
- function q(e) {
1830
+ function J(e) {
1888
1831
  return typeof e == "object" && !!e;
1889
1832
  }
1890
- function Ce(e) {
1833
+ function de(e) {
1891
1834
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
1892
1835
  }
1893
1836
  //#endregion
1894
1837
  //#region src/reconnect/backoff.ts
1895
- var we = 1e3, Te = 3e4;
1896
- function Ee(e, t = Math.random) {
1897
- let n = Math.min(Te, we * 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()));
1898
1841
  return Math.round(n * (1 + r * .2));
1899
1842
  }
1900
1843
  //#endregion
1901
1844
  //#region src/reconnect/ReconnectManager.ts
1902
- var De = class {
1845
+ var he = class {
1903
1846
  recover;
1904
1847
  random;
1905
1848
  isOnline;
@@ -1916,7 +1859,7 @@ var De = class {
1916
1859
  }
1917
1860
  start() {
1918
1861
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
1919
- let e = this.generation, t = Ee(this.attempt, this.random);
1862
+ let e = this.generation, t = me(this.attempt, this.random);
1920
1863
  this.pendingTimer = setTimeout(() => {
1921
1864
  this.pendingTimer = void 0, this.run(e);
1922
1865
  }, t);
@@ -1958,7 +1901,7 @@ var De = class {
1958
1901
  clearPendingTimer() {
1959
1902
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
1960
1903
  }
1961
- }, Oe = class t {
1904
+ }, ge = class t {
1962
1905
  media;
1963
1906
  options;
1964
1907
  api;
@@ -1995,7 +1938,7 @@ var De = class {
1995
1938
  sharedWorkerSelection;
1996
1939
  constructor(t) {
1997
1940
  if (this.options = t, t.api === void 0 && t.sessionProvider === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "CCBarClient 需要 sessionProvider" });
1998
- this.api = t.api === void 0 ? J(X(t.sessionProvider)) : J(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : je(t.sip), this.mediaBridge = Se(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new De({
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({
1999
1942
  recover: () => this.recoverConnection(),
2000
1943
  onAttempt: (e) => {
2001
1944
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
@@ -2007,13 +1950,13 @@ var De = class {
2007
1950
  }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2008
1951
  mode: "single-tab",
2009
1952
  reason: "disabled"
2010
- } : w({
1953
+ } : C({
2011
1954
  ...t.sharedWorker,
2012
1955
  ...t.sharedWorkerHost ?? {}
2013
1956
  });
2014
1957
  }
2015
1958
  static async checkSupport() {
2016
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Ae(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 : "");
2017
1960
  return {
2018
1961
  supported: e && t,
2019
1962
  platform: n,
@@ -2098,12 +2041,10 @@ var De = class {
2098
2041
  return this.diagnostics.getReport(e);
2099
2042
  }
2100
2043
  async setAgentStatus(e) {
2101
- this.assertNotDisposed();
2102
- let t = this.session?.transport.wssUrl;
2103
- await this.api.setAgentStatus({
2044
+ this.assertNotDisposed(), await this.api.setAgentStatus({
2104
2045
  status: e,
2105
2046
  reason: ""
2106
- }, t === void 0 ? void 0 : { wssUrl: t }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
2047
+ }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
2107
2048
  }
2108
2049
  on(e, t) {
2109
2050
  return this.disposed ? () => void 0 : this.events.on(e, t);
@@ -2120,7 +2061,7 @@ var De = class {
2120
2061
  sdkVersion: n,
2121
2062
  platform: a === "mobile-web" ? "mobile_web" : "web",
2122
2063
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2123
- requestedCapabilities: [...this.options.requestedCapabilities ?? Fe(a)]
2064
+ requestedCapabilities: [...this.options.requestedCapabilities ?? Ce(a)]
2124
2065
  }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2125
2066
  let o = this.callManager ?? this.createCallManager(r, t, a);
2126
2067
  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);
@@ -2226,7 +2167,7 @@ var De = class {
2226
2167
  try {
2227
2168
  await this.media.releaseAll();
2228
2169
  } catch (t) {
2229
- Me(t) || (e ??= t);
2170
+ be(t) || (e ??= t);
2230
2171
  }
2231
2172
  try {
2232
2173
  await this.mediaBridge.dispose();
@@ -2426,7 +2367,7 @@ var De = class {
2426
2367
  destination: e.destination
2427
2368
  })),
2428
2369
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2429
- ice: ke(e),
2370
+ ice: _e(e),
2430
2371
  wss: {
2431
2372
  configured: e !== void 0,
2432
2373
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2543,7 +2484,7 @@ var De = class {
2543
2484
  return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2544
2485
  }
2545
2486
  };
2546
- function ke(e) {
2487
+ function _e(e) {
2547
2488
  if (e === void 0) return {
2548
2489
  configured: !1,
2549
2490
  serverCount: 0,
@@ -2561,40 +2502,28 @@ function ke(e) {
2561
2502
  turnServerCount: n
2562
2503
  };
2563
2504
  }
2564
- function Ae(e) {
2505
+ function Y(e) {
2565
2506
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2566
2507
  }
2567
- function J(t) {
2508
+ function X(t) {
2568
2509
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2569
2510
  return t;
2570
2511
  }
2571
- async function Y(e) {
2572
- let t = e.sip?.registerTicket;
2573
- if (typeof t != "string" || t === "") return e;
2574
- let n = await le(t);
2575
- return n === void 0 || n === t ? e : {
2576
- ...e,
2577
- sip: {
2578
- ...e.sip,
2579
- registerTicket: n
2580
- }
2581
- };
2582
- }
2583
- function X(t) {
2512
+ function ve(t) {
2584
2513
  let r = {
2585
- createSession: async (e) => Y(await t.createSession(e)),
2586
- refreshSession: async (e) => Y(t.refreshSession === void 0 ? await t.createSession({
2514
+ createSession: (e) => t.createSession(e),
2515
+ refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
2587
2516
  sdkVersion: n,
2588
2517
  platform: "web"
2589
- }) : await t.refreshSession(e)),
2518
+ }) : t.refreshSession(e),
2590
2519
  deleteSession: async (e) => {
2591
2520
  t.deleteSession !== void 0 && await t.deleteSession(e);
2592
2521
  },
2593
- setAgentStatus: (n, r) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n, r)
2522
+ setAgentStatus: (n) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n)
2594
2523
  }, i = t.invalidateToken;
2595
2524
  return i !== void 0 && (r.invalidateToken = () => i()), r;
2596
2525
  }
2597
- function je(t) {
2526
+ function ye(t) {
2598
2527
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2599
2528
  return t;
2600
2529
  }
@@ -2613,13 +2542,13 @@ function Z(t, n, r, i, a) {
2613
2542
  function Q(t) {
2614
2543
  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;
2615
2544
  }
2616
- function Me(t) {
2545
+ function be(t) {
2617
2546
  return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2618
2547
  }
2619
2548
  function $(t) {
2620
2549
  return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
2621
2550
  }
2622
- var Ne = [
2551
+ var xe = [
2623
2552
  "outbound",
2624
2553
  "inbound",
2625
2554
  "mute",
@@ -2627,13 +2556,13 @@ var Ne = [
2627
2556
  "dtmf",
2628
2557
  "blind_transfer",
2629
2558
  "device_selection"
2630
- ], Pe = [
2559
+ ], Se = [
2631
2560
  "outbound",
2632
2561
  "mute",
2633
2562
  "dtmf"
2634
2563
  ];
2635
- function Fe(e) {
2636
- return e === "mobile-web" ? Pe : Ne;
2564
+ function Ce(e) {
2565
+ return e === "mobile-web" ? Se : xe;
2637
2566
  }
2638
2567
  //#endregion
2639
- 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, Oe as t, l as u };
2568
+ 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 };