@16x/webphone-sdk 3.1.5 → 3.1.6

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-DdxaOkkw.js";
2
+ import { r as n, t as r } from "./Diagnostics-D4metmcj.js";
3
3
  //#region src/events/TypedEventBus.ts
4
4
  var i = class {
5
5
  handlers = /* @__PURE__ */ new Map();
@@ -290,7 +290,7 @@ var c = class extends e {
290
290
  "failed",
291
291
  "hold",
292
292
  "unhold"
293
- ], m = 3e4, h = class {
293
+ ], te = 3e4, m = class {
294
294
  options;
295
295
  currentState = "new";
296
296
  sessionUnsubscribers = [];
@@ -342,6 +342,7 @@ var c = class extends e {
342
342
  } catch (e) {
343
343
  throw this.incomingOperation = void 0, this.finishFailedIncomingOperation(e), this.operationError(e);
344
344
  }
345
+ this.transitionIfAllowed("connecting", void 0, "accepted");
345
346
  }
346
347
  async reject(e = {}, t) {
347
348
  this.assertNotDisposed(), this.assertOwner(t), this.assertIncomingCall(), this.assertIncomingOperationAvailable(), this.incomingOperation = "reject";
@@ -366,13 +367,13 @@ var c = class extends e {
366
367
  this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
367
368
  }
368
369
  async transfer(e, t) {
369
- if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !te(e) || e.target.trim() === "") throw this.operationError();
370
+ if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !ne(e) || e.target.trim() === "") throw this.operationError();
370
371
  this.invoke(() => this.options.session.refer(e.target.trim()));
371
372
  }
372
373
  async hangup(e) {
373
- if (this.assertNotDisposed(), this.assertOwner(e), g(this.currentState)) throw this.operationError();
374
+ if (this.assertNotDisposed(), this.assertOwner(e), h(this.currentState)) throw this.operationError();
374
375
  try {
375
- this.options.session.terminate(), this.transitionTo("ended");
376
+ this.options.session.terminate(), h(this.currentState) || this.transitionTo("ended");
376
377
  } catch (e) {
377
378
  throw this.operationError(e);
378
379
  }
@@ -400,7 +401,7 @@ var c = class extends e {
400
401
  }
401
402
  dispose() {
402
403
  if (!this.disposed) {
403
- if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !g(this.currentState)) try {
404
+ if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !h(this.currentState)) try {
404
405
  this.options.session.terminate();
405
406
  } catch (e) {
406
407
  this.reportOperationError(e);
@@ -412,7 +413,7 @@ var c = class extends e {
412
413
  }
413
414
  }
414
415
  handleSessionEvent(e, t) {
415
- if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || g(this.currentState))) switch (e) {
416
+ if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || h(this.currentState))) switch (e) {
416
417
  case "progress":
417
418
  this.transitionIfAllowed("ringing", t, e);
418
419
  break;
@@ -447,7 +448,7 @@ var c = class extends e {
447
448
  if (this.currentState === e) return;
448
449
  if (!o(this.currentState, e)) throw this.operationError();
449
450
  let n = this.currentState;
450
- this.currentState = e, g(e) && this.rejectPendingOperation();
451
+ this.currentState = e, h(e) && this.rejectPendingOperation();
451
452
  try {
452
453
  this.options.onStateChanged?.({
453
454
  callId: this.id,
@@ -455,7 +456,7 @@ var c = class extends e {
455
456
  to: e
456
457
  }, t);
457
458
  } catch {} finally {
458
- g(e) && this.dispose();
459
+ h(e) && this.dispose();
459
460
  }
460
461
  }
461
462
  startPendingOperation(e, t, n) {
@@ -467,7 +468,7 @@ var c = class extends e {
467
468
  resolve: r,
468
469
  reject: i
469
470
  };
470
- this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), m);
471
+ this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), te);
471
472
  let o;
472
473
  try {
473
474
  o = n();
@@ -480,7 +481,7 @@ var c = class extends e {
480
481
  }
481
482
  resolvePendingOperation(e) {
482
483
  if (this.pendingOperation === e) {
483
- if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || g(this.currentState)) {
484
+ if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || h(this.currentState)) {
484
485
  e.reject(this.operationError());
485
486
  return;
486
487
  }
@@ -515,6 +516,7 @@ var c = class extends e {
515
516
  } catch {}
516
517
  }
517
518
  finishFailedIncomingOperation(e) {
519
+ this.reportOperationError(e);
518
520
  try {
519
521
  this.options.session.terminate();
520
522
  } catch (t) {
@@ -579,27 +581,27 @@ var c = class extends e {
579
581
  });
580
582
  }
581
583
  };
582
- function g(e) {
584
+ function h(e) {
583
585
  return e === "ended" || e === "failed";
584
586
  }
585
- function te(e) {
587
+ function ne(e) {
586
588
  return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
587
589
  }
588
590
  //#endregion
589
591
  //#region src/core/callId.ts
590
- var _ = 0;
591
- function v() {
592
- return _ += 1, `call_${Date.now().toString(36)}_${_.toString(36)}`;
592
+ var g = 0;
593
+ function _() {
594
+ return g += 1, `call_${Date.now().toString(36)}_${g.toString(36)}`;
593
595
  }
594
596
  //#endregion
595
597
  //#region src/core/userData.ts
596
- var ne = "X-User-Data", re = /[^\x20-\x7E]/, y = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
598
+ var re = "X-User-Data", v = /[^\x20-\x7E]/, y = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
597
599
  function b(t) {
598
600
  if (typeof t != "string") return [];
599
601
  let n = t.trim();
600
602
  if (n === "") return [];
601
- if (re.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: y });
602
- return [`${ne}: ${n}`];
603
+ if (v.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: y });
604
+ return [`${re}: ${n}`];
603
605
  }
604
606
  //#endregion
605
607
  //#region src/core/CallManager.ts
@@ -643,7 +645,7 @@ var x = class {
643
645
  if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= o) throw this.capabilityError();
644
646
  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);
645
647
  this.pendingDialCount += 1, this.pendingDestinations.add(i);
646
- let s = v(), c;
648
+ let s = _(), c;
647
649
  try {
648
650
  c = await this.holdActiveCallForNewCall(), this.assertGeneration(r, s);
649
651
  let e;
@@ -655,7 +657,7 @@ var x = class {
655
657
  this.assertGeneration(r, s);
656
658
  let o;
657
659
  try {
658
- o = new h({
660
+ o = new m({
659
661
  id: s,
660
662
  destination: i,
661
663
  platform: this.options.platform,
@@ -906,7 +908,7 @@ var x = class {
906
908
  }
907
909
  handleIncoming(t) {
908
910
  if (this.disposed) return;
909
- let n = v(), r = this.incomingSessionSnapshot;
911
+ let n = _(), r = this.incomingSessionSnapshot;
910
912
  if (r === void 0 || !r.policy.incomingEnabled || !this.effectiveCapabilities(r).has("inbound")) {
911
913
  this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
912
914
  return;
@@ -918,7 +920,7 @@ var x = class {
918
920
  }
919
921
  let a;
920
922
  try {
921
- a = new h({
923
+ a = new m({
922
924
  id: n,
923
925
  destination: i,
924
926
  platform: this.options.platform,
@@ -1139,13 +1141,13 @@ var se = class {
1139
1141
  try {
1140
1142
  let n = t(e);
1141
1143
  if (n.type === "event") {
1142
- n.event === "connection.stateChanged" && S(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
1144
+ n.event === "connection.stateChanged" && ce(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
1143
1145
  return;
1144
1146
  }
1145
1147
  if (n.type !== "response") return;
1146
1148
  let r = this.pending.get(n.requestId);
1147
1149
  if (r === void 0) return;
1148
- this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(ce(n));
1150
+ this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(le(n));
1149
1151
  } catch (e) {
1150
1152
  this.pending.forEach((t) => {
1151
1153
  clearTimeout(t.timer), t.reject(e);
@@ -1153,10 +1155,10 @@ var se = class {
1153
1155
  }
1154
1156
  }
1155
1157
  };
1156
- function S(e) {
1158
+ function ce(e) {
1157
1159
  return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
1158
1160
  }
1159
- function ce(t) {
1161
+ function le(t) {
1160
1162
  let n = t.error;
1161
1163
  return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
1162
1164
  requestId: t.requestId,
@@ -1167,12 +1169,12 @@ function ce(t) {
1167
1169
  }
1168
1170
  //#endregion
1169
1171
  //#region src/shared/SharedWorkerFactory.ts
1170
- function C(t = {}) {
1172
+ function S(t = {}) {
1171
1173
  if ((t.enabled ?? "auto") === !1) return {
1172
1174
  mode: "single-tab",
1173
1175
  reason: "disabled"
1174
1176
  };
1175
- let n = t.locationHref ?? T(), r = w(t.url, n), i = (n) => {
1177
+ let n = t.locationHref ?? w(), r = C(t.url, n), i = (n) => {
1176
1178
  if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
1177
1179
  return {
1178
1180
  mode: "single-tab",
@@ -1180,8 +1182,8 @@ function C(t = {}) {
1180
1182
  };
1181
1183
  };
1182
1184
  if (r === void 0) return i("SharedWorker URL is unavailable");
1183
- if (!E(r, n)) return i("SharedWorker URL must be same-origin");
1184
- let a = t.workerCtor ?? le();
1185
+ if (!de(r, n)) return i("SharedWorker URL must be same-origin");
1186
+ let a = t.workerCtor ?? ue();
1185
1187
  if (a === void 0) return i("SharedWorker is not supported");
1186
1188
  let o;
1187
1189
  try {
@@ -1189,10 +1191,10 @@ function C(t = {}) {
1189
1191
  } catch (e) {
1190
1192
  return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
1191
1193
  }
1192
- let s = t.tabId ?? D(), c = new se(o.port), l = {
1194
+ let s = t.tabId ?? T(), c = new se(o.port), l = {
1193
1195
  version: 1,
1194
1196
  type: "attach",
1195
- requestId: O(),
1197
+ requestId: E(),
1196
1198
  tabId: s
1197
1199
  }, u = c.request(l).then(() => void 0).catch((e) => {
1198
1200
  throw c.close(), e;
@@ -1206,20 +1208,20 @@ function C(t = {}) {
1206
1208
  ready: u
1207
1209
  };
1208
1210
  }
1209
- function w(e, t = T()) {
1211
+ function C(e, t = w()) {
1210
1212
  try {
1211
1213
  return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
1212
1214
  } catch {
1213
1215
  return;
1214
1216
  }
1215
1217
  }
1216
- function T() {
1218
+ function w() {
1217
1219
  return typeof location > "u" ? void 0 : location.href;
1218
1220
  }
1219
- function le() {
1221
+ function ue() {
1220
1222
  if (typeof SharedWorker == "function") return SharedWorker;
1221
1223
  }
1222
- function E(e, t) {
1224
+ function de(e, t) {
1223
1225
  if (t === void 0) return !0;
1224
1226
  try {
1225
1227
  return new URL(e, t).origin === new URL(t).origin;
@@ -1227,15 +1229,15 @@ function E(e, t) {
1227
1229
  return !1;
1228
1230
  }
1229
1231
  }
1230
- function D() {
1232
+ function T() {
1231
1233
  return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
1232
1234
  }
1233
- function O() {
1235
+ function E() {
1234
1236
  return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1235
1237
  }
1236
1238
  //#endregion
1237
1239
  //#region src/media/DeviceManager.ts
1238
- var k = class {
1240
+ var D = class {
1239
1241
  mediaDevices;
1240
1242
  createAudioElement;
1241
1243
  outputCapability;
@@ -1243,23 +1245,23 @@ var k = class {
1243
1245
  outputGeneration = 0;
1244
1246
  outputTail;
1245
1247
  constructor(e = {}) {
1246
- this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? A(), this.createAudioElement = e.createAudioElement;
1248
+ this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? O(), this.createAudioElement = e.createAudioElement;
1247
1249
  }
1248
1250
  async requestPermission(e = {}) {
1249
1251
  let t = this.requireMediaDevices(), n;
1250
1252
  try {
1251
1253
  n = await t.getUserMedia({ audio: e });
1252
1254
  } catch (e) {
1253
- throw N(e);
1255
+ throw j(e);
1254
1256
  }
1255
- j(n);
1257
+ k(n);
1256
1258
  }
1257
1259
  async getDevices() {
1258
1260
  if (this.mediaDevices === void 0) return [];
1259
1261
  try {
1260
1262
  return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
1261
1263
  } catch (e) {
1262
- throw P(e);
1264
+ throw M(e);
1263
1265
  }
1264
1266
  }
1265
1267
  getCapabilities() {
@@ -1297,7 +1299,7 @@ var k = class {
1297
1299
  try {
1298
1300
  await r.setSinkId(t);
1299
1301
  } catch (e) {
1300
- throw F(e);
1302
+ throw N(e);
1301
1303
  }
1302
1304
  }
1303
1305
  enqueueOutput(e) {
@@ -1311,7 +1313,7 @@ var k = class {
1311
1313
  try {
1312
1314
  return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
1313
1315
  } catch (e) {
1314
- throw M(e);
1316
+ throw A(e);
1315
1317
  }
1316
1318
  }
1317
1319
  requireMediaDevices() {
@@ -1331,10 +1333,10 @@ var k = class {
1331
1333
  }
1332
1334
  }
1333
1335
  };
1334
- function A() {
1336
+ function O() {
1335
1337
  return globalThis.navigator?.mediaDevices;
1336
1338
  }
1337
- function j(e) {
1339
+ function k(e) {
1338
1340
  let t;
1339
1341
  try {
1340
1342
  t = e.getTracks();
@@ -1347,57 +1349,57 @@ function j(e) {
1347
1349
  } catch {}
1348
1350
  });
1349
1351
  }
1350
- function M(t) {
1351
- let n = I(t);
1352
+ function A(t) {
1353
+ let n = P(t);
1352
1354
  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 });
1353
1355
  }
1354
- function N(t) {
1355
- let n = I(t);
1356
+ function j(t) {
1357
+ let n = P(t);
1356
1358
  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 });
1357
1359
  }
1358
- function P(t) {
1359
- let n = I(t);
1360
+ function M(t) {
1361
+ let n = P(t);
1360
1362
  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 });
1361
1363
  }
1362
- function F(t) {
1363
- let n = I(t);
1364
+ function N(t) {
1365
+ let n = P(t);
1364
1366
  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 });
1365
1367
  }
1366
- function I(e) {
1368
+ function P(e) {
1367
1369
  if (typeof e != "object" || !e || !("name" in e)) return;
1368
1370
  let t = e.name;
1369
1371
  return typeof t == "string" ? t : void 0;
1370
1372
  }
1371
1373
  //#endregion
1372
1374
  //#region src/media/RemoteAudio.ts
1373
- var L = class {
1375
+ var F = class {
1374
1376
  createAudioElement;
1375
1377
  bindings = /* @__PURE__ */ new Map();
1376
1378
  audioOwners = /* @__PURE__ */ new Map();
1377
1379
  trackOwners = /* @__PURE__ */ new Map();
1378
1380
  generations = /* @__PURE__ */ new Map();
1379
1381
  pendingPlays = /* @__PURE__ */ new Map();
1380
- constructor(e = R) {
1382
+ constructor(e = I) {
1381
1383
  this.createAudioElement = e;
1382
1384
  }
1383
1385
  async bind(t, n) {
1384
1386
  let r = this.bindings.get(t);
1385
1387
  if (r?.stream === n) return;
1386
- let i = z(t, n), a;
1388
+ let i = L(t, n), a;
1387
1389
  try {
1388
1390
  a = this.createAudioElement();
1389
1391
  } catch (n) {
1390
- throw B(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1392
+ throw R(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
1391
1393
  callId: t,
1392
1394
  cause: n
1393
1395
  });
1394
1396
  }
1395
1397
  let o = this.audioOwners.get(a);
1396
- if (o !== void 0 && o !== t) throw B(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1398
+ if (o !== void 0 && o !== t) throw R(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
1397
1399
  try {
1398
1400
  a.autoplay = !0, a.playsInline = !0;
1399
1401
  } catch (n) {
1400
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1402
+ throw R(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1401
1403
  callId: t,
1402
1404
  cause: n
1403
1405
  });
@@ -1405,7 +1407,7 @@ var L = class {
1405
1407
  try {
1406
1408
  a.srcObject = n;
1407
1409
  } catch (n) {
1408
- throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1410
+ throw R(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1409
1411
  callId: t,
1410
1412
  cause: n
1411
1413
  });
@@ -1481,7 +1483,7 @@ var L = class {
1481
1483
  releaseTrack(e) {
1482
1484
  let t = this.trackOwners.get(e);
1483
1485
  if (t === void 0 || t <= 1) {
1484
- this.trackOwners.delete(e), H(e);
1486
+ this.trackOwners.delete(e), B(e);
1485
1487
  return;
1486
1488
  }
1487
1489
  this.trackOwners.set(e, t - 1);
@@ -1504,42 +1506,42 @@ var L = class {
1504
1506
  return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
1505
1507
  }
1506
1508
  };
1507
- function R() {
1509
+ function I() {
1508
1510
  if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
1509
1511
  return document.createElement("audio");
1510
1512
  }
1511
- function z(t, n) {
1513
+ function L(t, n) {
1512
1514
  try {
1513
1515
  return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
1514
1516
  } catch (r) {
1515
1517
  try {
1516
1518
  return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
1517
1519
  } catch (i) {
1518
- throw V(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1520
+ throw z(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1519
1521
  callId: t,
1520
1522
  cause: r ?? i
1521
1523
  });
1522
1524
  }
1523
1525
  }
1524
1526
  }
1525
- function B(e, t) {
1527
+ function R(e, t) {
1526
1528
  e.forEach((e) => {
1527
- (t.get(e) ?? 0) === 0 && H(e);
1529
+ (t.get(e) ?? 0) === 0 && B(e);
1528
1530
  });
1529
1531
  }
1530
- function V(e) {
1532
+ function z(e) {
1531
1533
  try {
1532
- [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(H);
1534
+ [...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(B);
1533
1535
  } catch {}
1534
1536
  }
1535
- function H(e) {
1537
+ function B(e) {
1536
1538
  try {
1537
1539
  e.stop();
1538
1540
  } catch {}
1539
1541
  }
1540
1542
  //#endregion
1541
1543
  //#region src/media/MediaManager.ts
1542
- var U = class {
1544
+ var V = class {
1543
1545
  deviceManager;
1544
1546
  remoteAudio;
1545
1547
  getActiveCall;
@@ -1560,7 +1562,7 @@ var U = class {
1560
1562
  mediaDevices: e.mediaDevices,
1561
1563
  createAudioElement: e.createAudioElement
1562
1564
  };
1563
- this.deviceManager = new k(t), this.remoteAudio = new L(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? de;
1565
+ this.deviceManager = new D(t), this.remoteAudio = new F(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? pe;
1564
1566
  }
1565
1567
  requestPermission(e) {
1566
1568
  return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
@@ -1580,7 +1582,7 @@ var U = class {
1580
1582
  n !== void 0 && this.releaseResource(n).catch((e) => {
1581
1583
  this.releaseErrors.set(n, e);
1582
1584
  });
1583
- let r = W(t) ? t : { peerConnection: t }, i = {
1585
+ let r = H(t) ? t : { peerConnection: t }, i = {
1584
1586
  callId: e,
1585
1587
  peerConnection: r.peerConnection,
1586
1588
  senders: /* @__PURE__ */ new Map(),
@@ -1662,7 +1664,7 @@ var U = class {
1662
1664
  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);
1663
1665
  let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
1664
1666
  senderResource: e,
1665
- promise: this.enqueueSender(t, e, () => K(e.sender), !0)
1667
+ promise: this.enqueueSender(t, e, () => G(e.sender), !0)
1666
1668
  })), o = Promise.all(a.map(async (e) => {
1667
1669
  try {
1668
1670
  return await e.promise, {
@@ -1680,14 +1682,14 @@ var U = class {
1680
1682
  if (n.forEach((e) => {
1681
1683
  if (e.cause !== void 0) {
1682
1684
  o.push(e.cause);
1683
- let t = G(e.senderResource.sender);
1685
+ let t = U(e.senderResource.sender);
1684
1686
  t?.kind === "audio" && a.add(t);
1685
1687
  return;
1686
1688
  }
1687
- let t = G(e.senderResource.sender);
1689
+ let t = U(e.senderResource.sender);
1688
1690
  t?.kind === "audio" && i.add(t);
1689
1691
  }), i.forEach((e) => {
1690
- a.has(e) || J(e);
1692
+ a.has(e) || q(e);
1691
1693
  }), o.length > 0) throw t.localTracks.clear(), t.pendingTracks.clear(), a.forEach((e) => t.localTracks.add(e)), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1692
1694
  callId: r,
1693
1695
  cause: o[0]
@@ -1695,7 +1697,7 @@ var U = class {
1695
1697
  if (!t.peerClosed && t.peerConnection.close !== void 0) try {
1696
1698
  await t.peerConnection.close(), t.peerClosed = !0;
1697
1699
  } catch (n) {
1698
- let i = [...t.senders.values()].map((e) => G(e.sender)).find((e) => e?.kind === "audio");
1700
+ let i = [...t.senders.values()].map((e) => U(e.sender)).find((e) => e?.kind === "audio");
1699
1701
  throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
1700
1702
  callId: r,
1701
1703
  cause: n
@@ -1763,11 +1765,11 @@ var U = class {
1763
1765
  }
1764
1766
  async performInputSwitch(t, n, r) {
1765
1767
  if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
1766
- let i = this.findAudioSender(r), a = G(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1768
+ let i = this.findAudioSender(r), a = U(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
1767
1769
  try {
1768
1770
  c = s.getTracks();
1769
1771
  } catch (t) {
1770
- throw ue(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1772
+ throw fe(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1771
1773
  callId: n.callId,
1772
1774
  cause: t
1773
1775
  });
@@ -1776,26 +1778,26 @@ var U = class {
1776
1778
  try {
1777
1779
  l = s.getAudioTracks();
1778
1780
  } catch (t) {
1779
- throw q(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1781
+ throw K(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
1780
1782
  callId: n.callId,
1781
1783
  cause: t
1782
1784
  });
1783
1785
  }
1784
1786
  let u = l[0];
1785
- if (u === void 0) throw q(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1786
- if (!this.canCommitInputSwitch(n, r, i, a, o)) throw q(c), this.callOperationError(n.callId);
1787
+ if (u === void 0) throw K(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
1788
+ if (!this.canCommitInputSwitch(n, r, i, a, o)) throw K(c), this.callOperationError(n.callId);
1787
1789
  c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
1788
1790
  try {
1789
1791
  await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
1790
1792
  } catch (t) {
1791
- throw r.released ? this.callOperationError(n.callId) : (r.released || (c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), await this.rollbackSender(r, i, a, u), q(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
1793
+ 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, {
1792
1794
  callId: n.callId,
1793
1795
  cause: t
1794
1796
  }));
1795
1797
  }
1796
1798
  if (!this.canCommitInputSwitch(n, r, i, u, o)) {
1797
1799
  if (!r.released) try {
1798
- await this.enqueueSender(r, i, () => G(i.sender) === u ? K(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), q(c);
1800
+ 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);
1799
1801
  } catch (t) {
1800
1802
  throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
1801
1803
  callId: n.callId,
@@ -1804,8 +1806,8 @@ var U = class {
1804
1806
  }
1805
1807
  throw this.callOperationError(n.callId);
1806
1808
  }
1807
- c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), J(a)), c.forEach((e) => {
1808
- e !== u && J(e);
1809
+ 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) => {
1810
+ e !== u && q(e);
1809
1811
  });
1810
1812
  }
1811
1813
  ensureCallMedia(e) {
@@ -1828,7 +1830,7 @@ var U = class {
1828
1830
  });
1829
1831
  }
1830
1832
  r.forEach((r) => {
1831
- let i = G(r), a;
1833
+ let i = U(r), a;
1832
1834
  try {
1833
1835
  a = n?.(r) ?? r.senderKind ?? r.kind;
1834
1836
  } catch (n) {
@@ -1845,7 +1847,7 @@ var U = class {
1845
1847
  });
1846
1848
  }
1847
1849
  findAudioSender(e) {
1848
- let t = [...e.senders.values()].find((e) => e.audio && (G(e.sender)?.kind === "audio" || G(e.sender) === null));
1850
+ let t = [...e.senders.values()].find((e) => e.audio && (U(e.sender)?.kind === "audio" || U(e.sender) === null));
1849
1851
  if (t === void 0) throw this.capabilityError(e.callId);
1850
1852
  return t;
1851
1853
  }
@@ -1861,7 +1863,7 @@ var U = class {
1861
1863
  } catch {
1862
1864
  return !1;
1863
1865
  }
1864
- return G(n.sender) === r;
1866
+ return U(n.sender) === r;
1865
1867
  }
1866
1868
  enqueueSender(e, t, n, r = !1) {
1867
1869
  t.queue.pending += 1;
@@ -1890,7 +1892,7 @@ var U = class {
1890
1892
  });
1891
1893
  }
1892
1894
  async rollbackSender(e, t, n, r) {
1893
- e.released || G(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1895
+ e.released || U(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
1894
1896
  }
1895
1897
  isCurrentResource(e, t = e.generation) {
1896
1898
  return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
@@ -1917,37 +1919,42 @@ var U = class {
1917
1919
  if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
1918
1920
  }
1919
1921
  };
1920
- function W(e) {
1922
+ function H(e) {
1921
1923
  return "peerConnection" in e;
1922
1924
  }
1923
- function G(e) {
1925
+ function U(e) {
1924
1926
  try {
1925
1927
  return e.track;
1926
1928
  } catch {
1927
1929
  return null;
1928
1930
  }
1929
1931
  }
1930
- function K(e) {
1932
+ function W(e) {
1933
+ return typeof e == "object" && !!e && e.name === "InvalidStateError";
1934
+ }
1935
+ function G(e) {
1931
1936
  try {
1932
- return e.replaceTrack(null);
1937
+ return e.replaceTrack(null).catch((e) => {
1938
+ if (!W(e)) throw e;
1939
+ });
1933
1940
  } catch (e) {
1934
- return Promise.reject(e);
1941
+ return W(e) ? Promise.resolve() : Promise.reject(e);
1935
1942
  }
1936
1943
  }
1937
- function ue(e) {
1944
+ function fe(e) {
1938
1945
  try {
1939
- q(e.getTracks());
1946
+ K(e.getTracks());
1940
1947
  } catch {}
1941
1948
  }
1942
- function q(e) {
1943
- e.forEach(J);
1949
+ function K(e) {
1950
+ e.forEach(q);
1944
1951
  }
1945
- function J(e) {
1952
+ function q(e) {
1946
1953
  try {
1947
1954
  e.stop();
1948
1955
  } catch {}
1949
1956
  }
1950
- function de(e) {
1957
+ function pe(e) {
1951
1958
  if (typeof MediaStream < "u") try {
1952
1959
  return new MediaStream([e]);
1953
1960
  } catch {
@@ -1956,8 +1963,8 @@ function de(e) {
1956
1963
  }
1957
1964
  //#endregion
1958
1965
  //#region src/core/mediaBridge.ts
1959
- function fe(t, n = {}) {
1960
- 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 U({ getActiveCall: u });
1966
+ function me(t, n = {}) {
1967
+ 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 });
1961
1968
  return {
1962
1969
  publicMedia: {
1963
1970
  requestPermission: () => (f(), d.requestPermission()),
@@ -1970,7 +1977,7 @@ function fe(t, n = {}) {
1970
1977
  releaseAll: () => (f(), d.releaseAll())
1971
1978
  },
1972
1979
  registerCall(e, t) {
1973
- s || c || !Y(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1980
+ s || c || !J(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
1974
1981
  },
1975
1982
  async setCallOwnership(e, t) {
1976
1983
  if (s) return;
@@ -2013,9 +2020,9 @@ function fe(t, n = {}) {
2013
2020
  if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
2014
2021
  }
2015
2022
  function p(e, t) {
2016
- if (!Y(t) || typeof t.getMediaRegistration != "function") return;
2023
+ if (!J(t) || typeof t.getMediaRegistration != "function") return;
2017
2024
  let n = t.getMediaRegistration();
2018
- if (pe(n) && r.get(e)?.peerConnection !== n.peerConnection) {
2025
+ if (he(n) && r.get(e)?.peerConnection !== n.peerConnection) {
2019
2026
  r.set(e, n);
2020
2027
  try {
2021
2028
  d.registerCallMedia(e, n);
@@ -2025,22 +2032,22 @@ function fe(t, n = {}) {
2025
2032
  }
2026
2033
  }
2027
2034
  }
2028
- function Y(e) {
2035
+ function J(e) {
2029
2036
  return typeof e == "object" && !!e;
2030
2037
  }
2031
- function pe(e) {
2038
+ function he(e) {
2032
2039
  return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
2033
2040
  }
2034
2041
  //#endregion
2035
2042
  //#region src/reconnect/backoff.ts
2036
- var me = 1e3, he = 3e4;
2037
- function ge(e, t = Math.random) {
2038
- let n = Math.min(he, me * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
2043
+ var ge = 1e3, _e = 3e4;
2044
+ function ve(e, t = Math.random) {
2045
+ let n = Math.min(_e, ge * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
2039
2046
  return Math.round(n * (1 + r * .2));
2040
2047
  }
2041
2048
  //#endregion
2042
2049
  //#region src/reconnect/ReconnectManager.ts
2043
- var _e = class {
2050
+ var ye = class {
2044
2051
  recover;
2045
2052
  random;
2046
2053
  isOnline;
@@ -2057,7 +2064,7 @@ var _e = class {
2057
2064
  }
2058
2065
  start() {
2059
2066
  if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
2060
- let e = this.generation, t = ge(this.attempt, this.random);
2067
+ let e = this.generation, t = ve(this.attempt, this.random);
2061
2068
  this.pendingTimer = setTimeout(() => {
2062
2069
  this.pendingTimer = void 0, this.run(e);
2063
2070
  }, t);
@@ -2099,7 +2106,7 @@ var _e = class {
2099
2106
  clearPendingTimer() {
2100
2107
  this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
2101
2108
  }
2102
- }, ve = class t {
2109
+ }, be = class t {
2103
2110
  media;
2104
2111
  options;
2105
2112
  api;
@@ -2144,7 +2151,7 @@ var _e = class {
2144
2151
  this.api = t.api === void 0 ? t.sessionProvider === void 0 ? new p({
2145
2152
  baseUrl: t.baseUrl ?? "",
2146
2153
  tokenProvider: i
2147
- }) : X(xe(t.sessionProvider)) : X(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : Se(t.sip), this.mediaBridge = fe(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new _e({
2154
+ }) : 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({
2148
2155
  recover: () => this.recoverConnection(),
2149
2156
  onAttempt: (e) => {
2150
2157
  this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
@@ -2156,13 +2163,13 @@ var _e = class {
2156
2163
  }), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
2157
2164
  mode: "single-tab",
2158
2165
  reason: "disabled"
2159
- } : C({
2166
+ } : S({
2160
2167
  ...t.sharedWorker,
2161
2168
  ...t.sharedWorkerHost ?? {}
2162
2169
  });
2163
2170
  }
2164
2171
  static async checkSupport() {
2165
- let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = be(typeof navigator < "u" ? navigator.userAgent : "");
2172
+ let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Se(typeof navigator < "u" ? navigator.userAgent : "");
2166
2173
  return {
2167
2174
  supported: e && t,
2168
2175
  platform: n,
@@ -2269,7 +2276,7 @@ var _e = class {
2269
2276
  sdkVersion: n,
2270
2277
  platform: a === "mobile-web" ? "mobile_web" : "web",
2271
2278
  ...this.options.locale === void 0 ? {} : { locale: this.options.locale },
2272
- requestedCapabilities: [...this.options.requestedCapabilities ?? Ee(a)]
2279
+ requestedCapabilities: [...this.options.requestedCapabilities ?? De(a)]
2273
2280
  }), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
2274
2281
  let o = this.callManager ?? this.createCallManager(r, t, a);
2275
2282
  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);
@@ -2375,7 +2382,7 @@ var _e = class {
2375
2382
  try {
2376
2383
  await this.media.releaseAll();
2377
2384
  } catch (t) {
2378
- Ce(t) || (e ??= t);
2385
+ we(t) || (e ??= t);
2379
2386
  }
2380
2387
  try {
2381
2388
  await this.mediaBridge.dispose();
@@ -2575,7 +2582,7 @@ var _e = class {
2575
2582
  destination: e.destination
2576
2583
  })),
2577
2584
  permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
2578
- ice: ye(e),
2585
+ ice: xe(e),
2579
2586
  wss: {
2580
2587
  configured: e !== void 0,
2581
2588
  secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
@@ -2692,7 +2699,7 @@ var _e = class {
2692
2699
  return new e("SDK_ALREADY_DISPOSED", "internal", !1);
2693
2700
  }
2694
2701
  };
2695
- function ye(e) {
2702
+ function xe(e) {
2696
2703
  if (e === void 0) return {
2697
2704
  configured: !1,
2698
2705
  serverCount: 0,
@@ -2710,14 +2717,14 @@ function ye(e) {
2710
2717
  turnServerCount: n
2711
2718
  };
2712
2719
  }
2713
- function be(e) {
2720
+ function Se(e) {
2714
2721
  return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
2715
2722
  }
2716
- function X(t) {
2723
+ function Y(t) {
2717
2724
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2718
2725
  return t;
2719
2726
  }
2720
- function xe(t) {
2727
+ function Ce(t) {
2721
2728
  let r = {
2722
2729
  createSession: (e) => t.createSession(e),
2723
2730
  refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
@@ -2731,7 +2738,7 @@ function xe(t) {
2731
2738
  }, i = t.invalidateToken;
2732
2739
  return i !== void 0 && (r.invalidateToken = () => i()), r;
2733
2740
  }
2734
- function Se(t) {
2741
+ function X(t) {
2735
2742
  if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
2736
2743
  return t;
2737
2744
  }
@@ -2750,13 +2757,13 @@ function Z(t, n, r, i, a) {
2750
2757
  function Q(t) {
2751
2758
  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;
2752
2759
  }
2753
- function Ce(t) {
2760
+ function we(t) {
2754
2761
  return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
2755
2762
  }
2756
2763
  function $(t) {
2757
2764
  return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
2758
2765
  }
2759
- var we = [
2766
+ var Te = [
2760
2767
  "outbound",
2761
2768
  "inbound",
2762
2769
  "mute",
@@ -2764,13 +2771,13 @@ var we = [
2764
2771
  "dtmf",
2765
2772
  "blind_transfer",
2766
2773
  "device_selection"
2767
- ], Te = [
2774
+ ], Ee = [
2768
2775
  "outbound",
2769
2776
  "mute",
2770
2777
  "dtmf"
2771
2778
  ];
2772
- function Ee(e) {
2773
- return e === "mobile-web" ? Te : we;
2779
+ function De(e) {
2780
+ return e === "mobile-web" ? Ee : Te;
2774
2781
  }
2775
2782
  //#endregion
2776
- export { h as a, c, l as d, a as f, x as i, s as l, C as n, p as o, i as p, w as r, d as s, ve as t, o as u };
2783
+ 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 };