@16x/webphone-sdk 3.0.2 → 3.1.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.
- package/CHANGELOG.md +39 -26
- package/LICENSE +1 -1
- package/README.md +113 -113
- package/dist/{CCBarClient-xC63i3Qd.js → CCBarClient-CcPfEToZ.js} +225 -162
- package/dist/CCBarClient-DCQ8XjcL.cjs +1 -0
- package/dist/{Diagnostics-CvH6cjih.cjs → Diagnostics-D38Hm3NT.cjs} +1 -1
- package/dist/{Diagnostics-BhsVHELt.js → Diagnostics-Di049OpT.js} +1 -1
- package/dist/JsSipAdapter-BBRrDaM4.cjs +1 -0
- package/dist/{JsSipAdapter-CV6q6UUY.js → JsSipAdapter-Bke1Qjfe.js} +22 -17
- package/dist/SharedWorkerProtocol-39dch6xL.cjs +1 -0
- package/dist/{SharedWorkerProtocol-jfo9N5wa.js → SharedWorkerProtocol-DKVQ5-po.js} +5 -1
- package/dist/core/CCBarClient.d.ts +22 -2
- package/dist/{createJsSipFactory-yttVU3d6.js → createJsSipFactory-9CPsweDR.js} +4 -1
- package/dist/{createJsSipFactory-2X4FBIU2.cjs → createJsSipFactory-Dr8HbLl-.cjs} +1 -1
- package/dist/diagnostics/index.cjs +1 -1
- package/dist/diagnostics/index.js +1 -1
- package/dist/errors/CCBarError.d.ts +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/index.umd.js +2 -2
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.js +2 -2
- package/dist/shared/SharedWorkerProtocol.d.ts +2 -0
- package/dist/shared-worker.cjs +1 -1
- package/dist/shared-worker.js +1 -1
- package/dist/styles.css +7 -7
- package/dist/ui/index.cjs +1 -1
- package/dist/version.d.ts +1 -0
- package/package.json +111 -109
- package/dist/CCBarClient-DdLM2NKm.cjs +0 -1
- package/dist/JsSipAdapter-BM7I95Xb.cjs +0 -1
- package/dist/SharedWorkerProtocol-V_x8Erjv.cjs +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as e, t } from "./SharedWorkerProtocol-
|
|
2
|
-
import { r as n, t as r } from "./Diagnostics-
|
|
1
|
+
import { i as e, t } from "./SharedWorkerProtocol-DKVQ5-po.js";
|
|
2
|
+
import { r as n, t as r } from "./Diagnostics-Di049OpT.js";
|
|
3
3
|
//#region src/events/TypedEventBus.ts
|
|
4
4
|
var i = class {
|
|
5
5
|
handlers = /* @__PURE__ */ new Map();
|
|
@@ -145,6 +145,11 @@ var c = class extends e {
|
|
|
145
145
|
category: "call",
|
|
146
146
|
retryable: !1
|
|
147
147
|
},
|
|
148
|
+
SESSION_EXPIRED: {
|
|
149
|
+
code: "CALL_NOT_CONNECTED",
|
|
150
|
+
category: "call",
|
|
151
|
+
retryable: !1
|
|
152
|
+
},
|
|
148
153
|
SEAT_IN_USE: {
|
|
149
154
|
code: "CALL_ALREADY_EXISTS",
|
|
150
155
|
category: "call",
|
|
@@ -252,7 +257,11 @@ var c = class extends e {
|
|
|
252
257
|
}
|
|
253
258
|
toCCBarError(t, n) {
|
|
254
259
|
let r = f[n.code ?? ""] ?? this.mapStatus(t);
|
|
255
|
-
return new e(r.code, r.category, r.retryable, {
|
|
260
|
+
return new e(r.code, r.category, r.retryable, {
|
|
261
|
+
requestId: n.requestId,
|
|
262
|
+
serverCode: n.code,
|
|
263
|
+
status: t
|
|
264
|
+
});
|
|
256
265
|
}
|
|
257
266
|
mapStatus(e) {
|
|
258
267
|
return e === 401 ? {
|
|
@@ -273,7 +282,7 @@ var c = class extends e {
|
|
|
273
282
|
retryable: !1
|
|
274
283
|
};
|
|
275
284
|
}
|
|
276
|
-
},
|
|
285
|
+
}, m = [
|
|
277
286
|
"progress",
|
|
278
287
|
"accepted",
|
|
279
288
|
"confirmed",
|
|
@@ -281,7 +290,7 @@ var c = class extends e {
|
|
|
281
290
|
"failed",
|
|
282
291
|
"hold",
|
|
283
292
|
"unhold"
|
|
284
|
-
],
|
|
293
|
+
], h = 3e4, g = class {
|
|
285
294
|
options;
|
|
286
295
|
currentState = "new";
|
|
287
296
|
sessionUnsubscribers = [];
|
|
@@ -297,7 +306,7 @@ var c = class extends e {
|
|
|
297
306
|
constructor(t) {
|
|
298
307
|
this.options = t, this.id = t.id, this.destination = t.destination, this.platform = t.platform, this.capabilities = t.capabilities ?? /* @__PURE__ */ new Set();
|
|
299
308
|
try {
|
|
300
|
-
|
|
309
|
+
m.forEach((e) => {
|
|
301
310
|
this.sessionUnsubscribers.push(t.session.on(e, (t) => this.handleSessionEvent(e, t)));
|
|
302
311
|
});
|
|
303
312
|
} catch (n) {
|
|
@@ -358,11 +367,11 @@ var c = class extends e {
|
|
|
358
367
|
this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
|
|
359
368
|
}
|
|
360
369
|
async transfer(e, t) {
|
|
361
|
-
if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !
|
|
370
|
+
if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !v(e) || e.target.trim() === "") throw this.operationError();
|
|
362
371
|
this.invoke(() => this.options.session.refer(e.target.trim()));
|
|
363
372
|
}
|
|
364
373
|
async hangup(e) {
|
|
365
|
-
if (this.assertNotDisposed(), this.assertOwner(e),
|
|
374
|
+
if (this.assertNotDisposed(), this.assertOwner(e), _(this.currentState)) throw this.operationError();
|
|
366
375
|
try {
|
|
367
376
|
this.options.session.terminate(), this.transitionTo("ended");
|
|
368
377
|
} catch (e) {
|
|
@@ -392,7 +401,7 @@ var c = class extends e {
|
|
|
392
401
|
}
|
|
393
402
|
dispose() {
|
|
394
403
|
if (!this.disposed) {
|
|
395
|
-
if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !
|
|
404
|
+
if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !_(this.currentState)) try {
|
|
396
405
|
this.options.session.terminate();
|
|
397
406
|
} catch (e) {
|
|
398
407
|
this.reportOperationError(e);
|
|
@@ -404,7 +413,7 @@ var c = class extends e {
|
|
|
404
413
|
}
|
|
405
414
|
}
|
|
406
415
|
handleSessionEvent(e, t) {
|
|
407
|
-
if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed ||
|
|
416
|
+
if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || _(this.currentState))) switch (e) {
|
|
408
417
|
case "progress":
|
|
409
418
|
this.transitionIfAllowed("ringing", t, e);
|
|
410
419
|
break;
|
|
@@ -439,7 +448,7 @@ var c = class extends e {
|
|
|
439
448
|
if (this.currentState === e) return;
|
|
440
449
|
if (!o(this.currentState, e)) throw this.operationError();
|
|
441
450
|
let n = this.currentState;
|
|
442
|
-
this.currentState = e,
|
|
451
|
+
this.currentState = e, _(e) && this.rejectPendingOperation();
|
|
443
452
|
try {
|
|
444
453
|
this.options.onStateChanged?.({
|
|
445
454
|
callId: this.id,
|
|
@@ -447,7 +456,7 @@ var c = class extends e {
|
|
|
447
456
|
to: e
|
|
448
457
|
}, t);
|
|
449
458
|
} catch {} finally {
|
|
450
|
-
|
|
459
|
+
_(e) && this.dispose();
|
|
451
460
|
}
|
|
452
461
|
}
|
|
453
462
|
startPendingOperation(e, t, n) {
|
|
@@ -459,7 +468,7 @@ var c = class extends e {
|
|
|
459
468
|
resolve: r,
|
|
460
469
|
reject: i
|
|
461
470
|
};
|
|
462
|
-
this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a),
|
|
471
|
+
this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), h);
|
|
463
472
|
let o;
|
|
464
473
|
try {
|
|
465
474
|
o = n();
|
|
@@ -472,7 +481,7 @@ var c = class extends e {
|
|
|
472
481
|
}
|
|
473
482
|
resolvePendingOperation(e) {
|
|
474
483
|
if (this.pendingOperation === e) {
|
|
475
|
-
if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed ||
|
|
484
|
+
if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || _(this.currentState)) {
|
|
476
485
|
e.reject(this.operationError());
|
|
477
486
|
return;
|
|
478
487
|
}
|
|
@@ -571,22 +580,22 @@ var c = class extends e {
|
|
|
571
580
|
});
|
|
572
581
|
}
|
|
573
582
|
};
|
|
574
|
-
function
|
|
583
|
+
function _(e) {
|
|
575
584
|
return e === "ended" || e === "failed";
|
|
576
585
|
}
|
|
577
|
-
function
|
|
586
|
+
function v(e) {
|
|
578
587
|
return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
|
|
579
588
|
}
|
|
580
589
|
//#endregion
|
|
581
590
|
//#region src/core/callId.ts
|
|
582
|
-
var
|
|
583
|
-
function
|
|
584
|
-
return
|
|
591
|
+
var y = 0;
|
|
592
|
+
function b() {
|
|
593
|
+
return y += 1, `call_${Date.now().toString(36)}_${y.toString(36)}`;
|
|
585
594
|
}
|
|
586
595
|
//#endregion
|
|
587
596
|
//#region src/core/CallManager.ts
|
|
588
|
-
var
|
|
589
|
-
events = new
|
|
597
|
+
var x = class {
|
|
598
|
+
events = new ee();
|
|
590
599
|
calls = /* @__PURE__ */ new Map();
|
|
591
600
|
options;
|
|
592
601
|
incomingUnsubscribe;
|
|
@@ -624,7 +633,7 @@ var v = class {
|
|
|
624
633
|
if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= a) throw this.capabilityError();
|
|
625
634
|
if (this.calls.size + this.pendingDialCount >= a || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new e("CALL_ALREADY_EXISTS", "call", !1);
|
|
626
635
|
this.pendingDialCount += 1, this.pendingDestinations.add(i);
|
|
627
|
-
let o =
|
|
636
|
+
let o = b(), s;
|
|
628
637
|
try {
|
|
629
638
|
s = await this.holdActiveCallForNewCall(), this.assertGeneration(r, o);
|
|
630
639
|
let e;
|
|
@@ -636,7 +645,7 @@ var v = class {
|
|
|
636
645
|
this.assertGeneration(r, o);
|
|
637
646
|
let a;
|
|
638
647
|
try {
|
|
639
|
-
a = new
|
|
648
|
+
a = new g({
|
|
640
649
|
id: o,
|
|
641
650
|
destination: i,
|
|
642
651
|
platform: this.options.platform,
|
|
@@ -818,10 +827,10 @@ var v = class {
|
|
|
818
827
|
}
|
|
819
828
|
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", {
|
|
820
829
|
callId: e.id,
|
|
821
|
-
reason:
|
|
830
|
+
reason: te(n)
|
|
822
831
|
}) : this.events.emit("call.failed", {
|
|
823
832
|
callId: e.id,
|
|
824
|
-
error:
|
|
833
|
+
error: ne(n, e.id)
|
|
825
834
|
}));
|
|
826
835
|
}
|
|
827
836
|
async switchAutomaticActiveCall(e, t, n) {
|
|
@@ -887,7 +896,7 @@ var v = class {
|
|
|
887
896
|
}
|
|
888
897
|
handleIncoming(t) {
|
|
889
898
|
if (this.disposed) return;
|
|
890
|
-
let n =
|
|
899
|
+
let n = b();
|
|
891
900
|
if (this.options.platform === "mobile-web") {
|
|
892
901
|
this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
|
|
893
902
|
return;
|
|
@@ -904,7 +913,7 @@ var v = class {
|
|
|
904
913
|
}
|
|
905
914
|
let a;
|
|
906
915
|
try {
|
|
907
|
-
a = new
|
|
916
|
+
a = new g({
|
|
908
917
|
id: n,
|
|
909
918
|
destination: i,
|
|
910
919
|
platform: this.options.platform,
|
|
@@ -1029,7 +1038,7 @@ var v = class {
|
|
|
1029
1038
|
cause: t
|
|
1030
1039
|
});
|
|
1031
1040
|
}
|
|
1032
|
-
},
|
|
1041
|
+
}, ee = class {
|
|
1033
1042
|
handlers = /* @__PURE__ */ new Map();
|
|
1034
1043
|
on(e, t) {
|
|
1035
1044
|
let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
|
|
@@ -1054,12 +1063,12 @@ var v = class {
|
|
|
1054
1063
|
this.handlers.clear();
|
|
1055
1064
|
}
|
|
1056
1065
|
};
|
|
1057
|
-
function
|
|
1066
|
+
function te(e) {
|
|
1058
1067
|
if (typeof e != "object" || !e || !("reason" in e)) return "ended";
|
|
1059
1068
|
let t = e.reason;
|
|
1060
1069
|
return typeof t == "string" && t !== "" ? t : "ended";
|
|
1061
1070
|
}
|
|
1062
|
-
function
|
|
1071
|
+
function ne(t, n) {
|
|
1063
1072
|
if (t instanceof e) return new e(t.code, t.category, t.retryable, {
|
|
1064
1073
|
requestId: t.requestId,
|
|
1065
1074
|
callId: n,
|
|
@@ -1121,13 +1130,13 @@ var S = class {
|
|
|
1121
1130
|
try {
|
|
1122
1131
|
let n = t(e);
|
|
1123
1132
|
if (n.type === "event") {
|
|
1124
|
-
n.event === "connection.stateChanged" &&
|
|
1133
|
+
n.event === "connection.stateChanged" && re(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
|
|
1125
1134
|
return;
|
|
1126
1135
|
}
|
|
1127
1136
|
if (n.type !== "response") return;
|
|
1128
1137
|
let r = this.pending.get(n.requestId);
|
|
1129
1138
|
if (r === void 0) return;
|
|
1130
|
-
this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(
|
|
1139
|
+
this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(C(n));
|
|
1131
1140
|
} catch (e) {
|
|
1132
1141
|
this.pending.forEach((t) => {
|
|
1133
1142
|
clearTimeout(t.timer), t.reject(e);
|
|
@@ -1135,24 +1144,26 @@ var S = class {
|
|
|
1135
1144
|
}
|
|
1136
1145
|
}
|
|
1137
1146
|
};
|
|
1138
|
-
function
|
|
1147
|
+
function re(e) {
|
|
1139
1148
|
return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
|
|
1140
1149
|
}
|
|
1141
|
-
function
|
|
1150
|
+
function C(t) {
|
|
1142
1151
|
let n = t.error;
|
|
1143
1152
|
return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
|
|
1144
1153
|
requestId: t.requestId,
|
|
1145
|
-
...n?.message === void 0 ? {} : { cause: n.message }
|
|
1154
|
+
...n?.message === void 0 ? {} : { cause: n.message },
|
|
1155
|
+
...n?.serverCode === void 0 ? {} : { serverCode: n.serverCode },
|
|
1156
|
+
...n?.status === void 0 ? {} : { status: n.status }
|
|
1146
1157
|
});
|
|
1147
1158
|
}
|
|
1148
1159
|
//#endregion
|
|
1149
1160
|
//#region src/shared/SharedWorkerFactory.ts
|
|
1150
|
-
function
|
|
1161
|
+
function w(t = {}) {
|
|
1151
1162
|
if ((t.enabled ?? "auto") === !1) return {
|
|
1152
1163
|
mode: "single-tab",
|
|
1153
1164
|
reason: "disabled"
|
|
1154
1165
|
};
|
|
1155
|
-
let n = t.locationHref ??
|
|
1166
|
+
let n = t.locationHref ?? E(), r = T(t.url, n), i = (n) => {
|
|
1156
1167
|
if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
|
|
1157
1168
|
return {
|
|
1158
1169
|
mode: "single-tab",
|
|
@@ -1160,8 +1171,8 @@ function T(t = {}) {
|
|
|
1160
1171
|
};
|
|
1161
1172
|
};
|
|
1162
1173
|
if (r === void 0) return i("SharedWorker URL is unavailable");
|
|
1163
|
-
if (!
|
|
1164
|
-
let a = t.workerCtor ??
|
|
1174
|
+
if (!O(r, n)) return i("SharedWorker URL must be same-origin");
|
|
1175
|
+
let a = t.workerCtor ?? D();
|
|
1165
1176
|
if (a === void 0) return i("SharedWorker is not supported");
|
|
1166
1177
|
let o;
|
|
1167
1178
|
try {
|
|
@@ -1169,10 +1180,10 @@ function T(t = {}) {
|
|
|
1169
1180
|
} catch (e) {
|
|
1170
1181
|
return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
1171
1182
|
}
|
|
1172
|
-
let s = t.tabId ??
|
|
1183
|
+
let s = t.tabId ?? ie(), c = new S(o.port), l = {
|
|
1173
1184
|
version: 1,
|
|
1174
1185
|
type: "attach",
|
|
1175
|
-
requestId:
|
|
1186
|
+
requestId: ae(),
|
|
1176
1187
|
tabId: s
|
|
1177
1188
|
}, u = c.request(l).then(() => void 0).catch((e) => {
|
|
1178
1189
|
throw c.close(), e;
|
|
@@ -1186,20 +1197,20 @@ function T(t = {}) {
|
|
|
1186
1197
|
ready: u
|
|
1187
1198
|
};
|
|
1188
1199
|
}
|
|
1189
|
-
function
|
|
1200
|
+
function T(e, t = E()) {
|
|
1190
1201
|
try {
|
|
1191
1202
|
return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
|
|
1192
1203
|
} catch {
|
|
1193
1204
|
return;
|
|
1194
1205
|
}
|
|
1195
1206
|
}
|
|
1196
|
-
function
|
|
1207
|
+
function E() {
|
|
1197
1208
|
return typeof location > "u" ? void 0 : location.href;
|
|
1198
1209
|
}
|
|
1199
|
-
function
|
|
1210
|
+
function D() {
|
|
1200
1211
|
if (typeof SharedWorker == "function") return SharedWorker;
|
|
1201
1212
|
}
|
|
1202
|
-
function
|
|
1213
|
+
function O(e, t) {
|
|
1203
1214
|
if (t === void 0) return !0;
|
|
1204
1215
|
try {
|
|
1205
1216
|
return new URL(e, t).origin === new URL(t).origin;
|
|
@@ -1207,15 +1218,15 @@ function ie(e, t) {
|
|
|
1207
1218
|
return !1;
|
|
1208
1219
|
}
|
|
1209
1220
|
}
|
|
1210
|
-
function
|
|
1221
|
+
function ie() {
|
|
1211
1222
|
return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
|
|
1212
1223
|
}
|
|
1213
|
-
function
|
|
1224
|
+
function ae() {
|
|
1214
1225
|
return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1215
1226
|
}
|
|
1216
1227
|
//#endregion
|
|
1217
1228
|
//#region src/media/DeviceManager.ts
|
|
1218
|
-
var
|
|
1229
|
+
var oe = class {
|
|
1219
1230
|
mediaDevices;
|
|
1220
1231
|
createAudioElement;
|
|
1221
1232
|
outputCapability;
|
|
@@ -1223,23 +1234,23 @@ var A = class {
|
|
|
1223
1234
|
outputGeneration = 0;
|
|
1224
1235
|
outputTail;
|
|
1225
1236
|
constructor(e = {}) {
|
|
1226
|
-
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ??
|
|
1237
|
+
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? k(), this.createAudioElement = e.createAudioElement;
|
|
1227
1238
|
}
|
|
1228
1239
|
async requestPermission(e = {}) {
|
|
1229
1240
|
let t = this.requireMediaDevices(), n;
|
|
1230
1241
|
try {
|
|
1231
1242
|
n = await t.getUserMedia({ audio: e });
|
|
1232
1243
|
} catch (e) {
|
|
1233
|
-
throw
|
|
1244
|
+
throw M(e);
|
|
1234
1245
|
}
|
|
1235
|
-
|
|
1246
|
+
A(n);
|
|
1236
1247
|
}
|
|
1237
1248
|
async getDevices() {
|
|
1238
1249
|
if (this.mediaDevices === void 0) return [];
|
|
1239
1250
|
try {
|
|
1240
1251
|
return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
|
|
1241
1252
|
} catch (e) {
|
|
1242
|
-
throw
|
|
1253
|
+
throw N(e);
|
|
1243
1254
|
}
|
|
1244
1255
|
}
|
|
1245
1256
|
getCapabilities() {
|
|
@@ -1277,7 +1288,7 @@ var A = class {
|
|
|
1277
1288
|
try {
|
|
1278
1289
|
await r.setSinkId(t);
|
|
1279
1290
|
} catch (e) {
|
|
1280
|
-
throw
|
|
1291
|
+
throw P(e);
|
|
1281
1292
|
}
|
|
1282
1293
|
}
|
|
1283
1294
|
enqueueOutput(e) {
|
|
@@ -1291,7 +1302,7 @@ var A = class {
|
|
|
1291
1302
|
try {
|
|
1292
1303
|
return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
|
|
1293
1304
|
} catch (e) {
|
|
1294
|
-
throw
|
|
1305
|
+
throw j(e);
|
|
1295
1306
|
}
|
|
1296
1307
|
}
|
|
1297
1308
|
requireMediaDevices() {
|
|
@@ -1311,10 +1322,10 @@ var A = class {
|
|
|
1311
1322
|
}
|
|
1312
1323
|
}
|
|
1313
1324
|
};
|
|
1314
|
-
function
|
|
1325
|
+
function k() {
|
|
1315
1326
|
return globalThis.navigator?.mediaDevices;
|
|
1316
1327
|
}
|
|
1317
|
-
function
|
|
1328
|
+
function A(e) {
|
|
1318
1329
|
let t;
|
|
1319
1330
|
try {
|
|
1320
1331
|
t = e.getTracks();
|
|
@@ -1327,57 +1338,57 @@ function M(e) {
|
|
|
1327
1338
|
} catch {}
|
|
1328
1339
|
});
|
|
1329
1340
|
}
|
|
1330
|
-
function
|
|
1331
|
-
let n =
|
|
1341
|
+
function j(t) {
|
|
1342
|
+
let n = F(t);
|
|
1332
1343
|
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 });
|
|
1333
1344
|
}
|
|
1334
|
-
function
|
|
1335
|
-
let n =
|
|
1345
|
+
function M(t) {
|
|
1346
|
+
let n = F(t);
|
|
1336
1347
|
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 });
|
|
1337
1348
|
}
|
|
1338
|
-
function
|
|
1339
|
-
let n =
|
|
1349
|
+
function N(t) {
|
|
1350
|
+
let n = F(t);
|
|
1340
1351
|
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 });
|
|
1341
1352
|
}
|
|
1342
|
-
function
|
|
1343
|
-
let n =
|
|
1353
|
+
function P(t) {
|
|
1354
|
+
let n = F(t);
|
|
1344
1355
|
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 });
|
|
1345
1356
|
}
|
|
1346
|
-
function
|
|
1357
|
+
function F(e) {
|
|
1347
1358
|
if (typeof e != "object" || !e || !("name" in e)) return;
|
|
1348
1359
|
let t = e.name;
|
|
1349
1360
|
return typeof t == "string" ? t : void 0;
|
|
1350
1361
|
}
|
|
1351
1362
|
//#endregion
|
|
1352
1363
|
//#region src/media/RemoteAudio.ts
|
|
1353
|
-
var
|
|
1364
|
+
var I = class {
|
|
1354
1365
|
createAudioElement;
|
|
1355
1366
|
bindings = /* @__PURE__ */ new Map();
|
|
1356
1367
|
audioOwners = /* @__PURE__ */ new Map();
|
|
1357
1368
|
trackOwners = /* @__PURE__ */ new Map();
|
|
1358
1369
|
generations = /* @__PURE__ */ new Map();
|
|
1359
1370
|
pendingPlays = /* @__PURE__ */ new Map();
|
|
1360
|
-
constructor(e =
|
|
1371
|
+
constructor(e = L) {
|
|
1361
1372
|
this.createAudioElement = e;
|
|
1362
1373
|
}
|
|
1363
1374
|
async bind(t, n) {
|
|
1364
1375
|
let r = this.bindings.get(t);
|
|
1365
1376
|
if (r?.stream === n) return;
|
|
1366
|
-
let i =
|
|
1377
|
+
let i = R(t, n), a;
|
|
1367
1378
|
try {
|
|
1368
1379
|
a = this.createAudioElement();
|
|
1369
1380
|
} catch (n) {
|
|
1370
|
-
throw
|
|
1381
|
+
throw z(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
|
|
1371
1382
|
callId: t,
|
|
1372
1383
|
cause: n
|
|
1373
1384
|
});
|
|
1374
1385
|
}
|
|
1375
1386
|
let o = this.audioOwners.get(a);
|
|
1376
|
-
if (o !== void 0 && o !== t) throw
|
|
1387
|
+
if (o !== void 0 && o !== t) throw z(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
|
|
1377
1388
|
try {
|
|
1378
1389
|
a.autoplay = !0, a.playsInline = !0;
|
|
1379
1390
|
} catch (n) {
|
|
1380
|
-
throw
|
|
1391
|
+
throw z(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1381
1392
|
callId: t,
|
|
1382
1393
|
cause: n
|
|
1383
1394
|
});
|
|
@@ -1385,7 +1396,7 @@ var R = class {
|
|
|
1385
1396
|
try {
|
|
1386
1397
|
a.srcObject = n;
|
|
1387
1398
|
} catch (n) {
|
|
1388
|
-
throw
|
|
1399
|
+
throw z(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1389
1400
|
callId: t,
|
|
1390
1401
|
cause: n
|
|
1391
1402
|
});
|
|
@@ -1461,7 +1472,7 @@ var R = class {
|
|
|
1461
1472
|
releaseTrack(e) {
|
|
1462
1473
|
let t = this.trackOwners.get(e);
|
|
1463
1474
|
if (t === void 0 || t <= 1) {
|
|
1464
|
-
this.trackOwners.delete(e),
|
|
1475
|
+
this.trackOwners.delete(e), V(e);
|
|
1465
1476
|
return;
|
|
1466
1477
|
}
|
|
1467
1478
|
this.trackOwners.set(e, t - 1);
|
|
@@ -1484,42 +1495,42 @@ var R = class {
|
|
|
1484
1495
|
return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
|
|
1485
1496
|
}
|
|
1486
1497
|
};
|
|
1487
|
-
function
|
|
1498
|
+
function L() {
|
|
1488
1499
|
if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
|
|
1489
1500
|
return document.createElement("audio");
|
|
1490
1501
|
}
|
|
1491
|
-
function
|
|
1502
|
+
function R(t, n) {
|
|
1492
1503
|
try {
|
|
1493
1504
|
return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
|
|
1494
1505
|
} catch (r) {
|
|
1495
1506
|
try {
|
|
1496
1507
|
return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
|
|
1497
1508
|
} catch (i) {
|
|
1498
|
-
throw
|
|
1509
|
+
throw B(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1499
1510
|
callId: t,
|
|
1500
1511
|
cause: r ?? i
|
|
1501
1512
|
});
|
|
1502
1513
|
}
|
|
1503
1514
|
}
|
|
1504
1515
|
}
|
|
1505
|
-
function
|
|
1516
|
+
function z(e, t) {
|
|
1506
1517
|
e.forEach((e) => {
|
|
1507
|
-
(t.get(e) ?? 0) === 0 &&
|
|
1518
|
+
(t.get(e) ?? 0) === 0 && V(e);
|
|
1508
1519
|
});
|
|
1509
1520
|
}
|
|
1510
|
-
function
|
|
1521
|
+
function B(e) {
|
|
1511
1522
|
try {
|
|
1512
|
-
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(
|
|
1523
|
+
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
|
|
1513
1524
|
} catch {}
|
|
1514
1525
|
}
|
|
1515
|
-
function
|
|
1526
|
+
function V(e) {
|
|
1516
1527
|
try {
|
|
1517
1528
|
e.stop();
|
|
1518
1529
|
} catch {}
|
|
1519
1530
|
}
|
|
1520
1531
|
//#endregion
|
|
1521
1532
|
//#region src/media/MediaManager.ts
|
|
1522
|
-
var
|
|
1533
|
+
var H = class {
|
|
1523
1534
|
deviceManager;
|
|
1524
1535
|
remoteAudio;
|
|
1525
1536
|
getActiveCall;
|
|
@@ -1540,7 +1551,7 @@ var W = class {
|
|
|
1540
1551
|
mediaDevices: e.mediaDevices,
|
|
1541
1552
|
createAudioElement: e.createAudioElement
|
|
1542
1553
|
};
|
|
1543
|
-
this.deviceManager = new
|
|
1554
|
+
this.deviceManager = new oe(t), this.remoteAudio = new I(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? se;
|
|
1544
1555
|
}
|
|
1545
1556
|
requestPermission(e) {
|
|
1546
1557
|
return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
|
|
@@ -1560,7 +1571,7 @@ var W = class {
|
|
|
1560
1571
|
n !== void 0 && this.releaseResource(n).catch((e) => {
|
|
1561
1572
|
this.releaseErrors.set(n, e);
|
|
1562
1573
|
});
|
|
1563
|
-
let r =
|
|
1574
|
+
let r = U(t) ? t : { peerConnection: t }, i = {
|
|
1564
1575
|
callId: e,
|
|
1565
1576
|
peerConnection: r.peerConnection,
|
|
1566
1577
|
senders: /* @__PURE__ */ new Map(),
|
|
@@ -1642,7 +1653,7 @@ var W = class {
|
|
|
1642
1653
|
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);
|
|
1643
1654
|
let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
|
|
1644
1655
|
senderResource: e,
|
|
1645
|
-
promise: this.enqueueSender(t, e, () =>
|
|
1656
|
+
promise: this.enqueueSender(t, e, () => G(e.sender), !0)
|
|
1646
1657
|
})), o = Promise.all(a.map(async (e) => {
|
|
1647
1658
|
try {
|
|
1648
1659
|
return await e.promise, {
|
|
@@ -1660,14 +1671,14 @@ var W = class {
|
|
|
1660
1671
|
if (n.forEach((e) => {
|
|
1661
1672
|
if (e.cause !== void 0) {
|
|
1662
1673
|
o.push(e.cause);
|
|
1663
|
-
let t =
|
|
1674
|
+
let t = W(e.senderResource.sender);
|
|
1664
1675
|
t?.kind === "audio" && a.add(t);
|
|
1665
1676
|
return;
|
|
1666
1677
|
}
|
|
1667
|
-
let t =
|
|
1678
|
+
let t = W(e.senderResource.sender);
|
|
1668
1679
|
t?.kind === "audio" && i.add(t);
|
|
1669
1680
|
}), i.forEach((e) => {
|
|
1670
|
-
a.has(e) ||
|
|
1681
|
+
a.has(e) || J(e);
|
|
1671
1682
|
}), o.length > 0) throw t.localTracks.clear(), t.pendingTracks.clear(), a.forEach((e) => t.localTracks.add(e)), new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1672
1683
|
callId: r,
|
|
1673
1684
|
cause: o[0]
|
|
@@ -1675,7 +1686,7 @@ var W = class {
|
|
|
1675
1686
|
if (!t.peerClosed && t.peerConnection.close !== void 0) try {
|
|
1676
1687
|
await t.peerConnection.close(), t.peerClosed = !0;
|
|
1677
1688
|
} catch (n) {
|
|
1678
|
-
let i = [...t.senders.values()].map((e) =>
|
|
1689
|
+
let i = [...t.senders.values()].map((e) => W(e.sender)).find((e) => e?.kind === "audio");
|
|
1679
1690
|
throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1680
1691
|
callId: r,
|
|
1681
1692
|
cause: n
|
|
@@ -1743,11 +1754,11 @@ var W = class {
|
|
|
1743
1754
|
}
|
|
1744
1755
|
async performInputSwitch(t, n, r) {
|
|
1745
1756
|
if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
|
|
1746
|
-
let i = this.findAudioSender(r), a =
|
|
1757
|
+
let i = this.findAudioSender(r), a = W(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
|
|
1747
1758
|
try {
|
|
1748
1759
|
c = s.getTracks();
|
|
1749
1760
|
} catch (t) {
|
|
1750
|
-
throw
|
|
1761
|
+
throw K(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1751
1762
|
callId: n.callId,
|
|
1752
1763
|
cause: t
|
|
1753
1764
|
});
|
|
@@ -1756,26 +1767,26 @@ var W = class {
|
|
|
1756
1767
|
try {
|
|
1757
1768
|
l = s.getAudioTracks();
|
|
1758
1769
|
} catch (t) {
|
|
1759
|
-
throw
|
|
1770
|
+
throw q(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1760
1771
|
callId: n.callId,
|
|
1761
1772
|
cause: t
|
|
1762
1773
|
});
|
|
1763
1774
|
}
|
|
1764
1775
|
let u = l[0];
|
|
1765
|
-
if (u === void 0) throw
|
|
1766
|
-
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw
|
|
1776
|
+
if (u === void 0) throw q(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
|
|
1777
|
+
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw q(c), this.callOperationError(n.callId);
|
|
1767
1778
|
c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
|
|
1768
1779
|
try {
|
|
1769
1780
|
await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
|
|
1770
1781
|
} catch (t) {
|
|
1771
|
-
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),
|
|
1782
|
+
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, {
|
|
1772
1783
|
callId: n.callId,
|
|
1773
1784
|
cause: t
|
|
1774
1785
|
}));
|
|
1775
1786
|
}
|
|
1776
1787
|
if (!this.canCommitInputSwitch(n, r, i, u, o)) {
|
|
1777
1788
|
if (!r.released) try {
|
|
1778
|
-
await this.enqueueSender(r, i, () =>
|
|
1789
|
+
await this.enqueueSender(r, i, () => W(i.sender) === u ? G(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), q(c);
|
|
1779
1790
|
} catch (t) {
|
|
1780
1791
|
throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1781
1792
|
callId: n.callId,
|
|
@@ -1784,8 +1795,8 @@ var W = class {
|
|
|
1784
1795
|
}
|
|
1785
1796
|
throw this.callOperationError(n.callId);
|
|
1786
1797
|
}
|
|
1787
|
-
c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a),
|
|
1788
|
-
e !== u &&
|
|
1798
|
+
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) => {
|
|
1799
|
+
e !== u && J(e);
|
|
1789
1800
|
});
|
|
1790
1801
|
}
|
|
1791
1802
|
ensureCallMedia(e) {
|
|
@@ -1808,7 +1819,7 @@ var W = class {
|
|
|
1808
1819
|
});
|
|
1809
1820
|
}
|
|
1810
1821
|
r.forEach((r) => {
|
|
1811
|
-
let i =
|
|
1822
|
+
let i = W(r), a;
|
|
1812
1823
|
try {
|
|
1813
1824
|
a = n?.(r) ?? r.senderKind ?? r.kind;
|
|
1814
1825
|
} catch (n) {
|
|
@@ -1825,7 +1836,7 @@ var W = class {
|
|
|
1825
1836
|
});
|
|
1826
1837
|
}
|
|
1827
1838
|
findAudioSender(e) {
|
|
1828
|
-
let t = [...e.senders.values()].find((e) => e.audio && (
|
|
1839
|
+
let t = [...e.senders.values()].find((e) => e.audio && (W(e.sender)?.kind === "audio" || W(e.sender) === null));
|
|
1829
1840
|
if (t === void 0) throw this.capabilityError(e.callId);
|
|
1830
1841
|
return t;
|
|
1831
1842
|
}
|
|
@@ -1841,7 +1852,7 @@ var W = class {
|
|
|
1841
1852
|
} catch {
|
|
1842
1853
|
return !1;
|
|
1843
1854
|
}
|
|
1844
|
-
return
|
|
1855
|
+
return W(n.sender) === r;
|
|
1845
1856
|
}
|
|
1846
1857
|
enqueueSender(e, t, n, r = !1) {
|
|
1847
1858
|
t.queue.pending += 1;
|
|
@@ -1870,7 +1881,7 @@ var W = class {
|
|
|
1870
1881
|
});
|
|
1871
1882
|
}
|
|
1872
1883
|
async rollbackSender(e, t, n, r) {
|
|
1873
|
-
e.released ||
|
|
1884
|
+
e.released || W(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
|
|
1874
1885
|
}
|
|
1875
1886
|
isCurrentResource(e, t = e.generation) {
|
|
1876
1887
|
return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
|
|
@@ -1897,37 +1908,37 @@ var W = class {
|
|
|
1897
1908
|
if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
1898
1909
|
}
|
|
1899
1910
|
};
|
|
1900
|
-
function
|
|
1911
|
+
function U(e) {
|
|
1901
1912
|
return "peerConnection" in e;
|
|
1902
1913
|
}
|
|
1903
|
-
function
|
|
1914
|
+
function W(e) {
|
|
1904
1915
|
try {
|
|
1905
1916
|
return e.track;
|
|
1906
1917
|
} catch {
|
|
1907
1918
|
return null;
|
|
1908
1919
|
}
|
|
1909
1920
|
}
|
|
1910
|
-
function
|
|
1921
|
+
function G(e) {
|
|
1911
1922
|
try {
|
|
1912
1923
|
return e.replaceTrack(null);
|
|
1913
1924
|
} catch (e) {
|
|
1914
1925
|
return Promise.reject(e);
|
|
1915
1926
|
}
|
|
1916
1927
|
}
|
|
1917
|
-
function
|
|
1928
|
+
function K(e) {
|
|
1918
1929
|
try {
|
|
1919
|
-
|
|
1930
|
+
q(e.getTracks());
|
|
1920
1931
|
} catch {}
|
|
1921
1932
|
}
|
|
1922
|
-
function
|
|
1923
|
-
e.forEach(
|
|
1933
|
+
function q(e) {
|
|
1934
|
+
e.forEach(J);
|
|
1924
1935
|
}
|
|
1925
|
-
function
|
|
1936
|
+
function J(e) {
|
|
1926
1937
|
try {
|
|
1927
1938
|
e.stop();
|
|
1928
1939
|
} catch {}
|
|
1929
1940
|
}
|
|
1930
|
-
function
|
|
1941
|
+
function se(e) {
|
|
1931
1942
|
if (typeof MediaStream < "u") try {
|
|
1932
1943
|
return new MediaStream([e]);
|
|
1933
1944
|
} catch {
|
|
@@ -1936,8 +1947,8 @@ function oe(e) {
|
|
|
1936
1947
|
}
|
|
1937
1948
|
//#endregion
|
|
1938
1949
|
//#region src/core/mediaBridge.ts
|
|
1939
|
-
function
|
|
1940
|
-
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
|
|
1950
|
+
function ce(t, n = {}) {
|
|
1951
|
+
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 H({ getActiveCall: u });
|
|
1941
1952
|
return {
|
|
1942
1953
|
publicMedia: {
|
|
1943
1954
|
requestPermission: () => (f(), d.requestPermission()),
|
|
@@ -1950,7 +1961,7 @@ function se(t, n = {}) {
|
|
|
1950
1961
|
releaseAll: () => (f(), d.releaseAll())
|
|
1951
1962
|
},
|
|
1952
1963
|
registerCall(e, t) {
|
|
1953
|
-
s || c || !
|
|
1964
|
+
s || c || !Y(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
|
|
1954
1965
|
},
|
|
1955
1966
|
async setCallOwnership(e, t) {
|
|
1956
1967
|
if (s) return;
|
|
@@ -1993,9 +2004,9 @@ function se(t, n = {}) {
|
|
|
1993
2004
|
if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
1994
2005
|
}
|
|
1995
2006
|
function p(e, t) {
|
|
1996
|
-
if (!
|
|
2007
|
+
if (!Y(t) || typeof t.getMediaRegistration != "function") return;
|
|
1997
2008
|
let n = t.getMediaRegistration();
|
|
1998
|
-
if (
|
|
2009
|
+
if (le(n) && r.get(e)?.peerConnection !== n.peerConnection) {
|
|
1999
2010
|
r.set(e, n);
|
|
2000
2011
|
try {
|
|
2001
2012
|
d.registerCallMedia(e, n);
|
|
@@ -2005,22 +2016,22 @@ function se(t, n = {}) {
|
|
|
2005
2016
|
}
|
|
2006
2017
|
}
|
|
2007
2018
|
}
|
|
2008
|
-
function
|
|
2019
|
+
function Y(e) {
|
|
2009
2020
|
return typeof e == "object" && !!e;
|
|
2010
2021
|
}
|
|
2011
|
-
function
|
|
2022
|
+
function le(e) {
|
|
2012
2023
|
return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
|
|
2013
2024
|
}
|
|
2014
2025
|
//#endregion
|
|
2015
2026
|
//#region src/reconnect/backoff.ts
|
|
2016
|
-
var
|
|
2017
|
-
function
|
|
2018
|
-
let n = Math.min(
|
|
2027
|
+
var ue = 1e3, de = 3e4;
|
|
2028
|
+
function fe(e, t = Math.random) {
|
|
2029
|
+
let n = Math.min(de, ue * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
|
|
2019
2030
|
return Math.round(n * (1 + r * .2));
|
|
2020
2031
|
}
|
|
2021
2032
|
//#endregion
|
|
2022
2033
|
//#region src/reconnect/ReconnectManager.ts
|
|
2023
|
-
var
|
|
2034
|
+
var pe = class {
|
|
2024
2035
|
recover;
|
|
2025
2036
|
random;
|
|
2026
2037
|
isOnline;
|
|
@@ -2037,7 +2048,7 @@ var fe = class {
|
|
|
2037
2048
|
}
|
|
2038
2049
|
start() {
|
|
2039
2050
|
if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
|
|
2040
|
-
let e = this.generation, t =
|
|
2051
|
+
let e = this.generation, t = fe(this.attempt, this.random);
|
|
2041
2052
|
this.pendingTimer = setTimeout(() => {
|
|
2042
2053
|
this.pendingTimer = void 0, this.run(e);
|
|
2043
2054
|
}, t);
|
|
@@ -2079,7 +2090,7 @@ var fe = class {
|
|
|
2079
2090
|
clearPendingTimer() {
|
|
2080
2091
|
this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
|
|
2081
2092
|
}
|
|
2082
|
-
},
|
|
2093
|
+
}, me = class t {
|
|
2083
2094
|
media;
|
|
2084
2095
|
options;
|
|
2085
2096
|
api;
|
|
@@ -2096,6 +2107,7 @@ var fe = class {
|
|
|
2096
2107
|
disposed = !1;
|
|
2097
2108
|
intentionalDisconnect = !1;
|
|
2098
2109
|
deferredRebuild = !1;
|
|
2110
|
+
sessionRecoveryPending = !1;
|
|
2099
2111
|
detectedPlatform;
|
|
2100
2112
|
support;
|
|
2101
2113
|
acceptingEvents = !0;
|
|
@@ -2114,16 +2126,16 @@ var fe = class {
|
|
|
2114
2126
|
terminalReleaseOperations = /* @__PURE__ */ new Map();
|
|
2115
2127
|
tokenRequest = {};
|
|
2116
2128
|
sharedWorkerSelection;
|
|
2117
|
-
constructor(
|
|
2118
|
-
this.options = e;
|
|
2119
|
-
let t = (
|
|
2120
|
-
...
|
|
2129
|
+
constructor(t) {
|
|
2130
|
+
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" });
|
|
2131
|
+
let n = t.tokenProvider, i = (t) => n === void 0 ? Promise.reject(new e("CONFIG_INVALID", "configuration", !1, { cause: "未提供 tokenProvider" })) : n({
|
|
2132
|
+
...t,
|
|
2121
2133
|
...this.tokenRequest
|
|
2122
2134
|
});
|
|
2123
|
-
this.api =
|
|
2124
|
-
baseUrl:
|
|
2125
|
-
tokenProvider:
|
|
2126
|
-
}) :
|
|
2135
|
+
this.api = t.api === void 0 ? t.sessionProvider === void 0 ? new p({
|
|
2136
|
+
baseUrl: t.baseUrl ?? "",
|
|
2137
|
+
tokenProvider: i
|
|
2138
|
+
}) : X(_e(t.sessionProvider)) : X(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : ve(t.sip), this.mediaBridge = ce(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new pe({
|
|
2127
2139
|
recover: () => this.recoverConnection(),
|
|
2128
2140
|
onAttempt: (e) => {
|
|
2129
2141
|
this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
|
|
@@ -2132,16 +2144,16 @@ var fe = class {
|
|
|
2132
2144
|
getSnapshot: () => this.createDiagnosticsSnapshot(),
|
|
2133
2145
|
getPermission: () => this.readMicrophonePermission(),
|
|
2134
2146
|
getDeviceNames: async () => (await this.media.getDevices()).map((e) => e.label).filter((e) => e !== "")
|
|
2135
|
-
}), this.sharedWorkerSelection =
|
|
2147
|
+
}), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
|
|
2136
2148
|
mode: "single-tab",
|
|
2137
2149
|
reason: "disabled"
|
|
2138
|
-
} :
|
|
2139
|
-
...
|
|
2140
|
-
...
|
|
2150
|
+
} : w({
|
|
2151
|
+
...t.sharedWorker,
|
|
2152
|
+
...t.sharedWorkerHost ?? {}
|
|
2141
2153
|
});
|
|
2142
2154
|
}
|
|
2143
2155
|
static async checkSupport() {
|
|
2144
|
-
let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n =
|
|
2156
|
+
let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = ge(typeof navigator < "u" ? navigator.userAgent : "");
|
|
2145
2157
|
return {
|
|
2146
2158
|
supported: e && t,
|
|
2147
2159
|
platform: n,
|
|
@@ -2248,14 +2260,14 @@ var fe = class {
|
|
|
2248
2260
|
sdkVersion: n,
|
|
2249
2261
|
platform: a === "mobile-web" ? "mobile_web" : "web",
|
|
2250
2262
|
...this.options.locale === void 0 ? {} : { locale: this.options.locale },
|
|
2251
|
-
requestedCapabilities: [...this.options.requestedCapabilities ??
|
|
2263
|
+
requestedCapabilities: [...this.options.requestedCapabilities ?? Se(a)]
|
|
2252
2264
|
}), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
|
|
2253
2265
|
let o = this.callManager ?? this.createCallManager(r, t, a);
|
|
2254
2266
|
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);
|
|
2255
2267
|
} catch (n) {
|
|
2256
2268
|
if (await this.rollbackConnect(t, r, i), this.disposed) throw this.disposedError();
|
|
2257
2269
|
if (e !== this.lifecycleGeneration) throw n;
|
|
2258
|
-
let a =
|
|
2270
|
+
let a = Z(n, "REGISTRATION_FAILED", "registration", !0);
|
|
2259
2271
|
throw this.setConnectionState("failed"), this.events.emit("connection.failed", { error: a }), a;
|
|
2260
2272
|
}
|
|
2261
2273
|
}
|
|
@@ -2299,7 +2311,7 @@ var fe = class {
|
|
|
2299
2311
|
if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
|
|
2300
2312
|
}
|
|
2301
2313
|
createCallManager(e, t, n) {
|
|
2302
|
-
let r = new
|
|
2314
|
+
let r = new x({
|
|
2303
2315
|
sip: e,
|
|
2304
2316
|
platform: n,
|
|
2305
2317
|
session: t,
|
|
@@ -2354,7 +2366,7 @@ var fe = class {
|
|
|
2354
2366
|
try {
|
|
2355
2367
|
await this.media.releaseAll();
|
|
2356
2368
|
} catch (t) {
|
|
2357
|
-
|
|
2369
|
+
ye(t) || (e ??= t);
|
|
2358
2370
|
}
|
|
2359
2371
|
try {
|
|
2360
2372
|
await this.mediaBridge.dispose();
|
|
@@ -2432,21 +2444,27 @@ var fe = class {
|
|
|
2432
2444
|
let n = this.mediaBridge.releaseCall(e).then(() => {
|
|
2433
2445
|
this.terminalReleaseOperations.get(e) === n && this.terminalReleaseOperations.delete(e);
|
|
2434
2446
|
}).catch((t) => {
|
|
2435
|
-
throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error:
|
|
2447
|
+
throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: Z(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
|
|
2436
2448
|
});
|
|
2437
2449
|
return this.terminalReleaseOperations.set(e, n), n;
|
|
2438
2450
|
}
|
|
2439
2451
|
async startDeferredRecovery() {
|
|
2440
2452
|
try {
|
|
2441
|
-
await this.awaitMediaReleaseBarriers(), this.deferredRebuild && !this.hasNonTerminalCalls() && !this.disposed
|
|
2453
|
+
if (await this.awaitMediaReleaseBarriers(), this.deferredRebuild && !this.hasNonTerminalCalls() && !this.disposed) {
|
|
2454
|
+
if (this.sessionRecoveryPending) {
|
|
2455
|
+
this.recoverInvalidSession();
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
this.deferredRebuild = !1, this.clearRefreshTimer(), this.reconnect.start();
|
|
2459
|
+
}
|
|
2442
2460
|
} catch {
|
|
2443
|
-
this.disposed
|
|
2461
|
+
!this.disposed && !this.sessionRecoveryPending && this.reconnect.start();
|
|
2444
2462
|
}
|
|
2445
2463
|
}
|
|
2446
2464
|
async refreshAndRebuild() {
|
|
2447
2465
|
if (this.refreshOperation !== void 0) return this.refreshOperation;
|
|
2448
2466
|
let e = this.performRefreshAndRebuild().finally(() => {
|
|
2449
|
-
this.refreshOperation === e && (this.refreshOperation = void 0);
|
|
2467
|
+
this.refreshOperation === e && (this.refreshOperation = void 0), this.sessionRecoveryPending && !this.hasNonTerminalCalls() && !this.disposed && this.recoverInvalidSession();
|
|
2450
2468
|
});
|
|
2451
2469
|
return this.refreshOperation = e, e;
|
|
2452
2470
|
}
|
|
@@ -2470,8 +2488,28 @@ var fe = class {
|
|
|
2470
2488
|
}
|
|
2471
2489
|
handleRefreshFailure(e, t) {
|
|
2472
2490
|
if (this.disposed) return;
|
|
2473
|
-
let n =
|
|
2474
|
-
this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }),
|
|
2491
|
+
let n = Z(t, "NETWORK_OFFLINE", "network", !0);
|
|
2492
|
+
if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), Q(t)) {
|
|
2493
|
+
this.clearRefreshTimer(), this.reconnect.cancel(), this.deletedSessions.add(e.sessionId), this.sessionRecoveryPending = !0, this.deferredRebuild = !0, (n.code === "AUTH_TOKEN_UNAVAILABLE" || n.code === "AUTH_TOKEN_EXPIRED") && this.api.invalidateToken?.();
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
this.deferredRebuild = !0, this.hasNonTerminalCalls() || this.reconnect.start();
|
|
2497
|
+
}
|
|
2498
|
+
async recoverInvalidSession() {
|
|
2499
|
+
if (!(!this.sessionRecoveryPending || this.disposed || this.hasNonTerminalCalls())) {
|
|
2500
|
+
this.sessionRecoveryPending = !1, this.deferredRebuild = !1;
|
|
2501
|
+
try {
|
|
2502
|
+
await this.performDisconnect();
|
|
2503
|
+
} catch (e) {
|
|
2504
|
+
this.disposed || this.events.emit("error", { error: Z(e, "SDK_INTERNAL_ERROR", "internal", !0) });
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
if (!this.disposed) try {
|
|
2508
|
+
await this.performConnect(this.lifecycleGeneration);
|
|
2509
|
+
} catch {
|
|
2510
|
+
this.reconnect.cancel();
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2475
2513
|
}
|
|
2476
2514
|
scheduleRefresh(e) {
|
|
2477
2515
|
this.clearRefreshTimer();
|
|
@@ -2486,7 +2524,7 @@ var fe = class {
|
|
|
2486
2524
|
async getSip() {
|
|
2487
2525
|
if (this.sip !== void 0) return this.sip;
|
|
2488
2526
|
if (this.suppliedSip !== void 0) return this.sip = this.suppliedSip, this.sip;
|
|
2489
|
-
let [e, t] = await Promise.all([import("./createJsSipFactory-
|
|
2527
|
+
let [e, t] = await Promise.all([import("./createJsSipFactory-9CPsweDR.js"), import("./JsSipAdapter-Bke1Qjfe.js")]);
|
|
2490
2528
|
return this.sip = new t.JsSipAdapter(e.createJsSipFactory(), this.options.baseUrl), this.sip;
|
|
2491
2529
|
}
|
|
2492
2530
|
attachSipListener(e) {
|
|
@@ -2496,7 +2534,7 @@ var fe = class {
|
|
|
2496
2534
|
this.setConnectionState("connected");
|
|
2497
2535
|
return;
|
|
2498
2536
|
}
|
|
2499
|
-
this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error:
|
|
2537
|
+
this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: Z(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
|
|
2500
2538
|
}
|
|
2501
2539
|
}));
|
|
2502
2540
|
}
|
|
@@ -2528,7 +2566,7 @@ var fe = class {
|
|
|
2528
2566
|
destination: e.destination
|
|
2529
2567
|
})),
|
|
2530
2568
|
permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
|
|
2531
|
-
ice:
|
|
2569
|
+
ice: he(e),
|
|
2532
2570
|
wss: {
|
|
2533
2571
|
configured: e !== void 0,
|
|
2534
2572
|
secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
|
|
@@ -2567,6 +2605,12 @@ var fe = class {
|
|
|
2567
2605
|
if (t !== void 0) return t;
|
|
2568
2606
|
let n = this.api.deleteSession(e).then(() => {
|
|
2569
2607
|
this.deletedSessions.add(e);
|
|
2608
|
+
}).catch((t) => {
|
|
2609
|
+
if (Q(t)) {
|
|
2610
|
+
this.deletedSessions.add(e);
|
|
2611
|
+
return;
|
|
2612
|
+
}
|
|
2613
|
+
throw t;
|
|
2570
2614
|
}).finally(() => {
|
|
2571
2615
|
this.sessionDeleteOperations.get(e) === n && this.sessionDeleteOperations.delete(e);
|
|
2572
2616
|
});
|
|
@@ -2639,7 +2683,7 @@ var fe = class {
|
|
|
2639
2683
|
return new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
2640
2684
|
}
|
|
2641
2685
|
};
|
|
2642
|
-
function
|
|
2686
|
+
function he(e) {
|
|
2643
2687
|
if (e === void 0) return {
|
|
2644
2688
|
configured: !1,
|
|
2645
2689
|
serverCount: 0,
|
|
@@ -2657,34 +2701,53 @@ function me(e) {
|
|
|
2657
2701
|
turnServerCount: n
|
|
2658
2702
|
};
|
|
2659
2703
|
}
|
|
2660
|
-
function
|
|
2704
|
+
function ge(e) {
|
|
2661
2705
|
return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
|
|
2662
2706
|
}
|
|
2663
|
-
function
|
|
2707
|
+
function X(t) {
|
|
2664
2708
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2665
2709
|
return t;
|
|
2666
2710
|
}
|
|
2667
|
-
function
|
|
2711
|
+
function _e(t) {
|
|
2712
|
+
let r = {
|
|
2713
|
+
createSession: (e) => t.createSession(e),
|
|
2714
|
+
refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
|
|
2715
|
+
sdkVersion: n,
|
|
2716
|
+
platform: "web"
|
|
2717
|
+
}) : t.refreshSession(e),
|
|
2718
|
+
deleteSession: async (e) => {
|
|
2719
|
+
t.deleteSession !== void 0 && await t.deleteSession(e);
|
|
2720
|
+
},
|
|
2721
|
+
setAgentStatus: (n) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n)
|
|
2722
|
+
}, i = t.invalidateToken;
|
|
2723
|
+
return i !== void 0 && (r.invalidateToken = () => i()), r;
|
|
2724
|
+
}
|
|
2725
|
+
function ve(t) {
|
|
2668
2726
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2669
2727
|
return t;
|
|
2670
2728
|
}
|
|
2671
|
-
function
|
|
2729
|
+
function Z(t, n, r, i, a) {
|
|
2672
2730
|
return t instanceof e ? new e(t.code, t.category, t.retryable, {
|
|
2673
2731
|
requestId: t.requestId,
|
|
2674
2732
|
callId: a ?? t.callId,
|
|
2675
|
-
cause: t.cause ?? t
|
|
2733
|
+
cause: t.cause ?? t,
|
|
2734
|
+
serverCode: t.serverCode,
|
|
2735
|
+
status: t.status
|
|
2676
2736
|
}) : new e(n, r, i, {
|
|
2677
2737
|
callId: a,
|
|
2678
2738
|
cause: t
|
|
2679
2739
|
});
|
|
2680
2740
|
}
|
|
2681
|
-
function
|
|
2741
|
+
function Q(t) {
|
|
2742
|
+
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;
|
|
2743
|
+
}
|
|
2744
|
+
function ye(t) {
|
|
2682
2745
|
return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
|
|
2683
2746
|
}
|
|
2684
2747
|
function $(t) {
|
|
2685
2748
|
return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
|
|
2686
2749
|
}
|
|
2687
|
-
var
|
|
2750
|
+
var be = [
|
|
2688
2751
|
"outbound",
|
|
2689
2752
|
"inbound",
|
|
2690
2753
|
"mute",
|
|
@@ -2692,13 +2755,13 @@ var ve = [
|
|
|
2692
2755
|
"dtmf",
|
|
2693
2756
|
"blind_transfer",
|
|
2694
2757
|
"device_selection"
|
|
2695
|
-
],
|
|
2758
|
+
], xe = [
|
|
2696
2759
|
"outbound",
|
|
2697
2760
|
"mute",
|
|
2698
2761
|
"dtmf"
|
|
2699
2762
|
];
|
|
2700
|
-
function
|
|
2701
|
-
return e === "mobile-web" ?
|
|
2763
|
+
function Se(e) {
|
|
2764
|
+
return e === "mobile-web" ? xe : be;
|
|
2702
2765
|
}
|
|
2703
2766
|
//#endregion
|
|
2704
|
-
export {
|
|
2767
|
+
export { g as a, c, l as d, a as f, x as i, s as l, w as n, p as o, i as p, T as r, d as s, me as t, o as u };
|