@16x/webphone-sdk 3.1.10 → 3.2.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 +181 -206
- package/LICENSE +1 -1
- package/README.md +211 -214
- package/dist/{Diagnostics-WkQagE6_.js → Diagnostics-8hQAQglO.js} +1 -1
- package/dist/Diagnostics-DF_5kd8L.cjs +1 -0
- package/dist/{JsSipAdapter-BN9BAFHr.cjs → JsSipAdapter-D_Ozsugr.cjs} +1 -1
- package/dist/createJsSipFactory-B1ORbJiP.cjs +22 -0
- package/dist/createJsSipFactory-CoWZN-BC.js +7410 -0
- package/dist/crypto/legacySipTicket.d.ts +40 -0
- package/dist/diagnostics/index.cjs +1 -1
- package/dist/diagnostics/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -7
- package/dist/index.umd.js +16 -69
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.js +9 -275
- package/dist/legacy/legacySessionProvider.d.ts +20 -9
- package/dist/legacySessionProvider-BPVOuiwr.cjs +1 -0
- package/dist/{CCBarClient-Sr_zlDBu.js → legacySessionProvider-D9q2coUM.js} +436 -164
- package/dist/shared-worker.cjs +1 -1
- package/dist/styles.css +7 -7
- package/dist/ui/index.cjs +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +112 -109
- package/dist/CCBarClient-z-TFUjTB.cjs +0 -1
- package/dist/Diagnostics-x4G0ho6W.cjs +0 -1
- package/dist/createJsSipFactory-9CPsweDR.js +0 -9665
- package/dist/createJsSipFactory-Dr8HbLl-.cjs +0 -75
|
@@ -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-
|
|
2
|
+
import { r as n, t as r } from "./Diagnostics-8hQAQglO.js";
|
|
3
3
|
//#region src/events/TypedEventBus.ts
|
|
4
4
|
var i = class {
|
|
5
5
|
handlers = /* @__PURE__ */ new Map();
|
|
@@ -390,18 +390,18 @@ function g() {
|
|
|
390
390
|
}
|
|
391
391
|
//#endregion
|
|
392
392
|
//#region src/core/userData.ts
|
|
393
|
-
var
|
|
394
|
-
function
|
|
393
|
+
var _ = "X-User-Data", v = /[^\x20-\x7E]/, y = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
|
|
394
|
+
function b(t) {
|
|
395
395
|
if (typeof t != "string") return [];
|
|
396
396
|
let n = t.trim();
|
|
397
397
|
if (n === "") return [];
|
|
398
|
-
if (
|
|
399
|
-
return [`${
|
|
398
|
+
if (v.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: y });
|
|
399
|
+
return [`${_}: ${n}`];
|
|
400
400
|
}
|
|
401
401
|
//#endregion
|
|
402
402
|
//#region src/core/CallManager.ts
|
|
403
|
-
var
|
|
404
|
-
events = new
|
|
403
|
+
var x = class {
|
|
404
|
+
events = new ee();
|
|
405
405
|
calls = /* @__PURE__ */ new Map();
|
|
406
406
|
options;
|
|
407
407
|
incomingUnsubscribe;
|
|
@@ -434,7 +434,7 @@ var v = class {
|
|
|
434
434
|
this.assertNotDisposed();
|
|
435
435
|
let r = this.operationGeneration, i = t.destination.trim();
|
|
436
436
|
if (i === "") throw new e("CALL_INVALID_DESTINATION", "call", !1);
|
|
437
|
-
let a =
|
|
437
|
+
let a = b(t.userdata);
|
|
438
438
|
this.requireCapability(n, "outbound");
|
|
439
439
|
let o = this.callLimit(n);
|
|
440
440
|
if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= o) throw this.capabilityError();
|
|
@@ -634,10 +634,10 @@ var v = class {
|
|
|
634
634
|
}
|
|
635
635
|
t.to === "held" && this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), (t.to === "ended" || t.to === "failed") && (this.calls.delete(e.id), this.callSessions.delete(e.id), this.callOwners.delete(e.id), this.ownerLostCalls.delete(e.id), this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), this.notifyCallTerminal(e.id), t.to === "ended" ? this.events.emit("call.ended", {
|
|
636
636
|
callId: e.id,
|
|
637
|
-
reason:
|
|
637
|
+
reason: te(n)
|
|
638
638
|
}) : this.events.emit("call.failed", {
|
|
639
639
|
callId: e.id,
|
|
640
|
-
error:
|
|
640
|
+
error: ne(n, e.id)
|
|
641
641
|
}));
|
|
642
642
|
}
|
|
643
643
|
async switchAutomaticActiveCall(e, t, n) {
|
|
@@ -844,7 +844,7 @@ var v = class {
|
|
|
844
844
|
cause: t
|
|
845
845
|
});
|
|
846
846
|
}
|
|
847
|
-
},
|
|
847
|
+
}, ee = class {
|
|
848
848
|
handlers = /* @__PURE__ */ new Map();
|
|
849
849
|
on(e, t) {
|
|
850
850
|
let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
|
|
@@ -869,12 +869,12 @@ var v = class {
|
|
|
869
869
|
this.handlers.clear();
|
|
870
870
|
}
|
|
871
871
|
};
|
|
872
|
-
function
|
|
872
|
+
function te(e) {
|
|
873
873
|
if (typeof e != "object" || !e || !("reason" in e)) return "ended";
|
|
874
874
|
let t = e.reason;
|
|
875
875
|
return typeof t == "string" && t !== "" ? t : "ended";
|
|
876
876
|
}
|
|
877
|
-
function
|
|
877
|
+
function ne(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,
|
|
@@ -899,49 +899,49 @@ function re(t, n) {
|
|
|
899
899
|
}
|
|
900
900
|
//#endregion
|
|
901
901
|
//#region src/crypto/legacySipTicket.ts
|
|
902
|
-
var
|
|
903
|
-
function
|
|
902
|
+
var re = "q7X4p6MvK1z8Lb3A", ie = "W9e2T4mN0aQ7Ru6C", ae = 16, S = "�";
|
|
903
|
+
function oe(e) {
|
|
904
904
|
for (let t of e) {
|
|
905
905
|
let e = t.codePointAt(0) ?? 0;
|
|
906
906
|
if (e === 127 || e < 32 && e !== 9) return !0;
|
|
907
907
|
}
|
|
908
908
|
return !1;
|
|
909
909
|
}
|
|
910
|
-
async function
|
|
910
|
+
async function C(t, n = {}) {
|
|
911
911
|
let r = String(t ?? "").replace(/\s+/g, "");
|
|
912
912
|
if (!r) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
|
|
913
913
|
let i = n.subtle ?? globalThis.crypto?.subtle;
|
|
914
914
|
if (i === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
|
|
915
|
-
let a =
|
|
915
|
+
let a = w(r);
|
|
916
916
|
if (a === void 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
|
|
917
|
-
let o = await i.importKey("raw",
|
|
917
|
+
let o = await i.importKey("raw", T(n.key ?? re), "AES-CBC", !1, ["decrypt"]);
|
|
918
918
|
try {
|
|
919
919
|
let e = await i.decrypt({
|
|
920
920
|
name: "AES-CBC",
|
|
921
|
-
iv:
|
|
921
|
+
iv: T(n.iv ?? ie)
|
|
922
922
|
}, o, a);
|
|
923
923
|
return new TextDecoder("utf-8").decode(e).trim();
|
|
924
924
|
} catch (t) {
|
|
925
925
|
throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: `SIP 密码解密失败(检查 key/iv 与该环境是否一致):${t instanceof Error ? t.message : String(t)}` });
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
-
async function
|
|
928
|
+
async function se(e, t = {}) {
|
|
929
929
|
let n = String(e ?? "").replace(/\s+/g, "");
|
|
930
|
-
if (
|
|
931
|
-
let e = await
|
|
932
|
-
return
|
|
930
|
+
if (ce(n)) try {
|
|
931
|
+
let e = await C(n, t);
|
|
932
|
+
return le(e) ? e : void 0;
|
|
933
933
|
} catch {
|
|
934
934
|
return;
|
|
935
935
|
}
|
|
936
936
|
}
|
|
937
|
-
function
|
|
938
|
-
let t =
|
|
939
|
-
return t !== void 0 && t.byteLength > 0 && t.byteLength %
|
|
937
|
+
function ce(e) {
|
|
938
|
+
let t = w(e);
|
|
939
|
+
return t !== void 0 && t.byteLength > 0 && t.byteLength % ae === 0;
|
|
940
940
|
}
|
|
941
|
-
function
|
|
942
|
-
return e.length === 0 || e.includes(
|
|
941
|
+
function le(e) {
|
|
942
|
+
return e.length === 0 || e.includes(S) ? !1 : !oe(e);
|
|
943
943
|
}
|
|
944
|
-
function
|
|
944
|
+
function w(e) {
|
|
945
945
|
if (e.length !== 0 && e.length % 4 == 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(e)) try {
|
|
946
946
|
let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length));
|
|
947
947
|
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
@@ -950,13 +950,13 @@ function S(e) {
|
|
|
950
950
|
return;
|
|
951
951
|
}
|
|
952
952
|
}
|
|
953
|
-
function
|
|
953
|
+
function T(e) {
|
|
954
954
|
let t = new TextEncoder().encode(e), n = new Uint8Array(new ArrayBuffer(t.byteLength));
|
|
955
955
|
return n.set(t), n;
|
|
956
956
|
}
|
|
957
957
|
//#endregion
|
|
958
958
|
//#region src/shared/SharedWorkerClient.ts
|
|
959
|
-
var
|
|
959
|
+
var ue = class {
|
|
960
960
|
port;
|
|
961
961
|
timeoutMs;
|
|
962
962
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -993,13 +993,13 @@ var fe = class {
|
|
|
993
993
|
try {
|
|
994
994
|
let n = t(e);
|
|
995
995
|
if (n.type === "event") {
|
|
996
|
-
n.event === "connection.stateChanged" &&
|
|
996
|
+
n.event === "connection.stateChanged" && de(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
|
|
997
997
|
return;
|
|
998
998
|
}
|
|
999
999
|
if (n.type !== "response") return;
|
|
1000
1000
|
let r = this.pending.get(n.requestId);
|
|
1001
1001
|
if (r === void 0) return;
|
|
1002
|
-
this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(
|
|
1002
|
+
this.pending.delete(n.requestId), clearTimeout(r.timer), n.ok ? r.resolve(n.result) : r.reject(fe(n));
|
|
1003
1003
|
} catch (e) {
|
|
1004
1004
|
this.pending.forEach((t) => {
|
|
1005
1005
|
clearTimeout(t.timer), t.reject(e);
|
|
@@ -1007,10 +1007,10 @@ var fe = class {
|
|
|
1007
1007
|
}
|
|
1008
1008
|
}
|
|
1009
1009
|
};
|
|
1010
|
-
function
|
|
1010
|
+
function de(e) {
|
|
1011
1011
|
return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
|
|
1012
1012
|
}
|
|
1013
|
-
function
|
|
1013
|
+
function fe(t) {
|
|
1014
1014
|
let n = t.error;
|
|
1015
1015
|
return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
|
|
1016
1016
|
requestId: t.requestId,
|
|
@@ -1021,12 +1021,12 @@ function me(t) {
|
|
|
1021
1021
|
}
|
|
1022
1022
|
//#endregion
|
|
1023
1023
|
//#region src/shared/SharedWorkerFactory.ts
|
|
1024
|
-
function
|
|
1024
|
+
function E(t = {}) {
|
|
1025
1025
|
if ((t.enabled ?? "auto") === !1) return {
|
|
1026
1026
|
mode: "single-tab",
|
|
1027
1027
|
reason: "disabled"
|
|
1028
1028
|
};
|
|
1029
|
-
let n = t.locationHref ??
|
|
1029
|
+
let n = t.locationHref ?? O(), r = D(t.url, n), i = (n) => {
|
|
1030
1030
|
if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
|
|
1031
1031
|
return {
|
|
1032
1032
|
mode: "single-tab",
|
|
@@ -1034,8 +1034,8 @@ function w(t = {}) {
|
|
|
1034
1034
|
};
|
|
1035
1035
|
};
|
|
1036
1036
|
if (r === void 0) return i("SharedWorker URL is unavailable");
|
|
1037
|
-
if (!
|
|
1038
|
-
let a = t.workerCtor ??
|
|
1037
|
+
if (!me(r, n)) return i("SharedWorker URL must be same-origin");
|
|
1038
|
+
let a = t.workerCtor ?? pe();
|
|
1039
1039
|
if (a === void 0) return i("SharedWorker is not supported");
|
|
1040
1040
|
let o;
|
|
1041
1041
|
try {
|
|
@@ -1043,10 +1043,10 @@ function w(t = {}) {
|
|
|
1043
1043
|
} catch (e) {
|
|
1044
1044
|
return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
1045
1045
|
}
|
|
1046
|
-
let s = t.tabId ??
|
|
1046
|
+
let s = t.tabId ?? he(), c = new ue(o.port), l = {
|
|
1047
1047
|
version: 1,
|
|
1048
1048
|
type: "attach",
|
|
1049
|
-
requestId:
|
|
1049
|
+
requestId: ge(),
|
|
1050
1050
|
tabId: s
|
|
1051
1051
|
}, u = c.request(l).then(() => void 0).catch((e) => {
|
|
1052
1052
|
throw c.close(), e;
|
|
@@ -1060,20 +1060,20 @@ function w(t = {}) {
|
|
|
1060
1060
|
ready: u
|
|
1061
1061
|
};
|
|
1062
1062
|
}
|
|
1063
|
-
function
|
|
1063
|
+
function D(e, t = O()) {
|
|
1064
1064
|
try {
|
|
1065
1065
|
return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
|
|
1066
1066
|
} catch {
|
|
1067
1067
|
return;
|
|
1068
1068
|
}
|
|
1069
1069
|
}
|
|
1070
|
-
function
|
|
1070
|
+
function O() {
|
|
1071
1071
|
return typeof location > "u" ? void 0 : location.href;
|
|
1072
1072
|
}
|
|
1073
|
-
function
|
|
1073
|
+
function pe() {
|
|
1074
1074
|
if (typeof SharedWorker == "function") return SharedWorker;
|
|
1075
1075
|
}
|
|
1076
|
-
function
|
|
1076
|
+
function me(e, t) {
|
|
1077
1077
|
if (t === void 0) return !0;
|
|
1078
1078
|
try {
|
|
1079
1079
|
return new URL(e, t).origin === new URL(t).origin;
|
|
@@ -1081,15 +1081,15 @@ function O(e, t) {
|
|
|
1081
1081
|
return !1;
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
|
-
function
|
|
1084
|
+
function he() {
|
|
1085
1085
|
return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
|
|
1086
1086
|
}
|
|
1087
|
-
function
|
|
1087
|
+
function ge() {
|
|
1088
1088
|
return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1089
1089
|
}
|
|
1090
1090
|
//#endregion
|
|
1091
1091
|
//#region src/media/DeviceManager.ts
|
|
1092
|
-
var
|
|
1092
|
+
var _e = class {
|
|
1093
1093
|
mediaDevices;
|
|
1094
1094
|
createAudioElement;
|
|
1095
1095
|
outputCapability;
|
|
@@ -1097,23 +1097,23 @@ var j = class {
|
|
|
1097
1097
|
outputGeneration = 0;
|
|
1098
1098
|
outputTail;
|
|
1099
1099
|
constructor(e = {}) {
|
|
1100
|
-
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ??
|
|
1100
|
+
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? ve(), this.createAudioElement = e.createAudioElement;
|
|
1101
1101
|
}
|
|
1102
1102
|
async requestPermission(e = {}) {
|
|
1103
1103
|
let t = this.requireMediaDevices(), n;
|
|
1104
1104
|
try {
|
|
1105
1105
|
n = await t.getUserMedia({ audio: e });
|
|
1106
1106
|
} catch (e) {
|
|
1107
|
-
throw
|
|
1107
|
+
throw k(e);
|
|
1108
1108
|
}
|
|
1109
|
-
|
|
1109
|
+
ye(n);
|
|
1110
1110
|
}
|
|
1111
1111
|
async getDevices() {
|
|
1112
1112
|
if (this.mediaDevices === void 0) return [];
|
|
1113
1113
|
try {
|
|
1114
1114
|
return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
|
|
1115
1115
|
} catch (e) {
|
|
1116
|
-
throw
|
|
1116
|
+
throw A(e);
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
1119
1119
|
getCapabilities() {
|
|
@@ -1151,7 +1151,7 @@ var j = class {
|
|
|
1151
1151
|
try {
|
|
1152
1152
|
await r.setSinkId(t);
|
|
1153
1153
|
} catch (e) {
|
|
1154
|
-
throw
|
|
1154
|
+
throw j(e);
|
|
1155
1155
|
}
|
|
1156
1156
|
}
|
|
1157
1157
|
enqueueOutput(e) {
|
|
@@ -1165,7 +1165,7 @@ var j = class {
|
|
|
1165
1165
|
try {
|
|
1166
1166
|
return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
|
|
1167
1167
|
} catch (e) {
|
|
1168
|
-
throw
|
|
1168
|
+
throw be(e);
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
requireMediaDevices() {
|
|
@@ -1185,10 +1185,10 @@ var j = class {
|
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
1187
1187
|
};
|
|
1188
|
-
function
|
|
1188
|
+
function ve() {
|
|
1189
1189
|
return globalThis.navigator?.mediaDevices;
|
|
1190
1190
|
}
|
|
1191
|
-
function
|
|
1191
|
+
function ye(e) {
|
|
1192
1192
|
let t;
|
|
1193
1193
|
try {
|
|
1194
1194
|
t = e.getTracks();
|
|
@@ -1201,57 +1201,57 @@ function N(e) {
|
|
|
1201
1201
|
} catch {}
|
|
1202
1202
|
});
|
|
1203
1203
|
}
|
|
1204
|
-
function
|
|
1205
|
-
let n =
|
|
1204
|
+
function be(t) {
|
|
1205
|
+
let n = M(t);
|
|
1206
1206
|
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
1207
|
}
|
|
1208
|
-
function
|
|
1209
|
-
let n =
|
|
1208
|
+
function k(t) {
|
|
1209
|
+
let n = M(t);
|
|
1210
1210
|
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
1211
|
}
|
|
1212
|
-
function
|
|
1213
|
-
let n =
|
|
1212
|
+
function A(t) {
|
|
1213
|
+
let n = M(t);
|
|
1214
1214
|
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
1215
|
}
|
|
1216
|
-
function
|
|
1217
|
-
let n =
|
|
1216
|
+
function j(t) {
|
|
1217
|
+
let n = M(t);
|
|
1218
1218
|
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
1219
|
}
|
|
1220
|
-
function
|
|
1220
|
+
function M(e) {
|
|
1221
1221
|
if (typeof e != "object" || !e || !("name" in e)) return;
|
|
1222
1222
|
let t = e.name;
|
|
1223
1223
|
return typeof t == "string" ? t : void 0;
|
|
1224
1224
|
}
|
|
1225
1225
|
//#endregion
|
|
1226
1226
|
//#region src/media/RemoteAudio.ts
|
|
1227
|
-
var
|
|
1227
|
+
var N = class {
|
|
1228
1228
|
createAudioElement;
|
|
1229
1229
|
bindings = /* @__PURE__ */ new Map();
|
|
1230
1230
|
audioOwners = /* @__PURE__ */ new Map();
|
|
1231
1231
|
trackOwners = /* @__PURE__ */ new Map();
|
|
1232
1232
|
generations = /* @__PURE__ */ new Map();
|
|
1233
1233
|
pendingPlays = /* @__PURE__ */ new Map();
|
|
1234
|
-
constructor(e =
|
|
1234
|
+
constructor(e = xe) {
|
|
1235
1235
|
this.createAudioElement = e;
|
|
1236
1236
|
}
|
|
1237
1237
|
async bind(t, n) {
|
|
1238
1238
|
let r = this.bindings.get(t);
|
|
1239
1239
|
if (r?.stream === n) return;
|
|
1240
|
-
let i =
|
|
1240
|
+
let i = Se(t, n), a;
|
|
1241
1241
|
try {
|
|
1242
1242
|
a = this.createAudioElement();
|
|
1243
1243
|
} catch (n) {
|
|
1244
|
-
throw
|
|
1244
|
+
throw P(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
|
|
1245
1245
|
callId: t,
|
|
1246
1246
|
cause: n
|
|
1247
1247
|
});
|
|
1248
1248
|
}
|
|
1249
1249
|
let o = this.audioOwners.get(a);
|
|
1250
|
-
if (o !== void 0 && o !== t) throw
|
|
1250
|
+
if (o !== void 0 && o !== t) throw P(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
|
|
1251
1251
|
try {
|
|
1252
1252
|
a.autoplay = !0, a.playsInline = !0;
|
|
1253
1253
|
} catch (n) {
|
|
1254
|
-
throw
|
|
1254
|
+
throw P(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1255
1255
|
callId: t,
|
|
1256
1256
|
cause: n
|
|
1257
1257
|
});
|
|
@@ -1259,7 +1259,7 @@ var z = class {
|
|
|
1259
1259
|
try {
|
|
1260
1260
|
a.srcObject = n;
|
|
1261
1261
|
} catch (n) {
|
|
1262
|
-
throw
|
|
1262
|
+
throw P(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1263
1263
|
callId: t,
|
|
1264
1264
|
cause: n
|
|
1265
1265
|
});
|
|
@@ -1335,7 +1335,7 @@ var z = class {
|
|
|
1335
1335
|
releaseTrack(e) {
|
|
1336
1336
|
let t = this.trackOwners.get(e);
|
|
1337
1337
|
if (t === void 0 || t <= 1) {
|
|
1338
|
-
this.trackOwners.delete(e),
|
|
1338
|
+
this.trackOwners.delete(e), F(e);
|
|
1339
1339
|
return;
|
|
1340
1340
|
}
|
|
1341
1341
|
this.trackOwners.set(e, t - 1);
|
|
@@ -1358,42 +1358,42 @@ var z = class {
|
|
|
1358
1358
|
return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
|
|
1359
1359
|
}
|
|
1360
1360
|
};
|
|
1361
|
-
function
|
|
1361
|
+
function xe() {
|
|
1362
1362
|
if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
|
|
1363
1363
|
return document.createElement("audio");
|
|
1364
1364
|
}
|
|
1365
|
-
function
|
|
1365
|
+
function Se(t, n) {
|
|
1366
1366
|
try {
|
|
1367
1367
|
return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
|
|
1368
1368
|
} catch (r) {
|
|
1369
1369
|
try {
|
|
1370
1370
|
return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
|
|
1371
1371
|
} catch (i) {
|
|
1372
|
-
throw
|
|
1372
|
+
throw Ce(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1373
1373
|
callId: t,
|
|
1374
1374
|
cause: r ?? i
|
|
1375
1375
|
});
|
|
1376
1376
|
}
|
|
1377
1377
|
}
|
|
1378
1378
|
}
|
|
1379
|
-
function
|
|
1379
|
+
function P(e, t) {
|
|
1380
1380
|
e.forEach((e) => {
|
|
1381
|
-
(t.get(e) ?? 0) === 0 &&
|
|
1381
|
+
(t.get(e) ?? 0) === 0 && F(e);
|
|
1382
1382
|
});
|
|
1383
1383
|
}
|
|
1384
|
-
function
|
|
1384
|
+
function Ce(e) {
|
|
1385
1385
|
try {
|
|
1386
|
-
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(
|
|
1386
|
+
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(F);
|
|
1387
1387
|
} catch {}
|
|
1388
1388
|
}
|
|
1389
|
-
function
|
|
1389
|
+
function F(e) {
|
|
1390
1390
|
try {
|
|
1391
1391
|
e.stop();
|
|
1392
1392
|
} catch {}
|
|
1393
1393
|
}
|
|
1394
1394
|
//#endregion
|
|
1395
1395
|
//#region src/media/MediaManager.ts
|
|
1396
|
-
var
|
|
1396
|
+
var we = class {
|
|
1397
1397
|
deviceManager;
|
|
1398
1398
|
remoteAudio;
|
|
1399
1399
|
getActiveCall;
|
|
@@ -1414,7 +1414,7 @@ var ve = class {
|
|
|
1414
1414
|
mediaDevices: e.mediaDevices,
|
|
1415
1415
|
createAudioElement: e.createAudioElement
|
|
1416
1416
|
};
|
|
1417
|
-
this.deviceManager = new
|
|
1417
|
+
this.deviceManager = new _e(t), this.remoteAudio = new N(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? De;
|
|
1418
1418
|
}
|
|
1419
1419
|
requestPermission(e) {
|
|
1420
1420
|
return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
|
|
@@ -1434,7 +1434,7 @@ var ve = class {
|
|
|
1434
1434
|
n !== void 0 && this.releaseResource(n).catch((e) => {
|
|
1435
1435
|
this.releaseErrors.set(n, e);
|
|
1436
1436
|
});
|
|
1437
|
-
let r =
|
|
1437
|
+
let r = Te(t) ? t : { peerConnection: t }, i = {
|
|
1438
1438
|
callId: e,
|
|
1439
1439
|
peerConnection: r.peerConnection,
|
|
1440
1440
|
senders: /* @__PURE__ */ new Map(),
|
|
@@ -1516,7 +1516,7 @@ var ve = class {
|
|
|
1516
1516
|
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
1517
|
let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
|
|
1518
1518
|
senderResource: e,
|
|
1519
|
-
promise: this.enqueueSender(t, e, () =>
|
|
1519
|
+
promise: this.enqueueSender(t, e, () => R(e.sender), !0)
|
|
1520
1520
|
})), o = Promise.all(a.map(async (e) => {
|
|
1521
1521
|
try {
|
|
1522
1522
|
return await e.promise, {
|
|
@@ -1534,14 +1534,14 @@ var ve = class {
|
|
|
1534
1534
|
if (n.forEach((e) => {
|
|
1535
1535
|
if (e.cause !== void 0) {
|
|
1536
1536
|
o.push(e.cause);
|
|
1537
|
-
let t =
|
|
1537
|
+
let t = I(e.senderResource.sender);
|
|
1538
1538
|
t?.kind === "audio" && a.add(t);
|
|
1539
1539
|
return;
|
|
1540
1540
|
}
|
|
1541
|
-
let t =
|
|
1541
|
+
let t = I(e.senderResource.sender);
|
|
1542
1542
|
t?.kind === "audio" && i.add(t);
|
|
1543
1543
|
}), i.forEach((e) => {
|
|
1544
|
-
a.has(e) ||
|
|
1544
|
+
a.has(e) || B(e);
|
|
1545
1545
|
}), 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
1546
|
callId: r,
|
|
1547
1547
|
cause: o[0]
|
|
@@ -1549,7 +1549,7 @@ var ve = class {
|
|
|
1549
1549
|
if (!t.peerClosed && t.peerConnection.close !== void 0) try {
|
|
1550
1550
|
await t.peerConnection.close(), t.peerClosed = !0;
|
|
1551
1551
|
} catch (n) {
|
|
1552
|
-
let i = [...t.senders.values()].map((e) =>
|
|
1552
|
+
let i = [...t.senders.values()].map((e) => I(e.sender)).find((e) => e?.kind === "audio");
|
|
1553
1553
|
throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1554
1554
|
callId: r,
|
|
1555
1555
|
cause: n
|
|
@@ -1617,11 +1617,11 @@ var ve = class {
|
|
|
1617
1617
|
}
|
|
1618
1618
|
async performInputSwitch(t, n, r) {
|
|
1619
1619
|
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 =
|
|
1620
|
+
let i = this.findAudioSender(r), a = I(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
|
|
1621
1621
|
try {
|
|
1622
1622
|
c = s.getTracks();
|
|
1623
1623
|
} catch (t) {
|
|
1624
|
-
throw
|
|
1624
|
+
throw Ee(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1625
1625
|
callId: n.callId,
|
|
1626
1626
|
cause: t
|
|
1627
1627
|
});
|
|
@@ -1630,26 +1630,26 @@ var ve = class {
|
|
|
1630
1630
|
try {
|
|
1631
1631
|
l = s.getAudioTracks();
|
|
1632
1632
|
} catch (t) {
|
|
1633
|
-
throw
|
|
1633
|
+
throw z(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1634
1634
|
callId: n.callId,
|
|
1635
1635
|
cause: t
|
|
1636
1636
|
});
|
|
1637
1637
|
}
|
|
1638
1638
|
let u = l[0];
|
|
1639
|
-
if (u === void 0) throw
|
|
1640
|
-
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw
|
|
1639
|
+
if (u === void 0) throw z(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
|
|
1640
|
+
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw z(c), this.callOperationError(n.callId);
|
|
1641
1641
|
c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
|
|
1642
1642
|
try {
|
|
1643
1643
|
await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
|
|
1644
1644
|
} 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),
|
|
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), z(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
|
|
1646
1646
|
callId: n.callId,
|
|
1647
1647
|
cause: t
|
|
1648
1648
|
}));
|
|
1649
1649
|
}
|
|
1650
1650
|
if (!this.canCommitInputSwitch(n, r, i, u, o)) {
|
|
1651
1651
|
if (!r.released) try {
|
|
1652
|
-
await this.enqueueSender(r, i, () =>
|
|
1652
|
+
await this.enqueueSender(r, i, () => I(i.sender) === u ? R(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), z(c);
|
|
1653
1653
|
} catch (t) {
|
|
1654
1654
|
throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1655
1655
|
callId: n.callId,
|
|
@@ -1658,8 +1658,8 @@ var ve = class {
|
|
|
1658
1658
|
}
|
|
1659
1659
|
throw this.callOperationError(n.callId);
|
|
1660
1660
|
}
|
|
1661
|
-
c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a),
|
|
1662
|
-
e !== u &&
|
|
1661
|
+
c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a), B(a)), c.forEach((e) => {
|
|
1662
|
+
e !== u && B(e);
|
|
1663
1663
|
});
|
|
1664
1664
|
}
|
|
1665
1665
|
ensureCallMedia(e) {
|
|
@@ -1682,7 +1682,7 @@ var ve = class {
|
|
|
1682
1682
|
});
|
|
1683
1683
|
}
|
|
1684
1684
|
r.forEach((r) => {
|
|
1685
|
-
let i =
|
|
1685
|
+
let i = I(r), a;
|
|
1686
1686
|
try {
|
|
1687
1687
|
a = n?.(r) ?? r.senderKind ?? r.kind;
|
|
1688
1688
|
} catch (n) {
|
|
@@ -1699,7 +1699,7 @@ var ve = class {
|
|
|
1699
1699
|
});
|
|
1700
1700
|
}
|
|
1701
1701
|
findAudioSender(e) {
|
|
1702
|
-
let t = [...e.senders.values()].find((e) => e.audio && (
|
|
1702
|
+
let t = [...e.senders.values()].find((e) => e.audio && (I(e.sender)?.kind === "audio" || I(e.sender) === null));
|
|
1703
1703
|
if (t === void 0) throw this.capabilityError(e.callId);
|
|
1704
1704
|
return t;
|
|
1705
1705
|
}
|
|
@@ -1715,7 +1715,7 @@ var ve = class {
|
|
|
1715
1715
|
} catch {
|
|
1716
1716
|
return !1;
|
|
1717
1717
|
}
|
|
1718
|
-
return
|
|
1718
|
+
return I(n.sender) === r;
|
|
1719
1719
|
}
|
|
1720
1720
|
enqueueSender(e, t, n, r = !1) {
|
|
1721
1721
|
t.queue.pending += 1;
|
|
@@ -1744,7 +1744,7 @@ var ve = class {
|
|
|
1744
1744
|
});
|
|
1745
1745
|
}
|
|
1746
1746
|
async rollbackSender(e, t, n, r) {
|
|
1747
|
-
e.released ||
|
|
1747
|
+
e.released || I(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
|
|
1748
1748
|
}
|
|
1749
1749
|
isCurrentResource(e, t = e.generation) {
|
|
1750
1750
|
return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
|
|
@@ -1771,42 +1771,42 @@ var ve = class {
|
|
|
1771
1771
|
if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
1772
1772
|
}
|
|
1773
1773
|
};
|
|
1774
|
-
function
|
|
1774
|
+
function Te(e) {
|
|
1775
1775
|
return "peerConnection" in e;
|
|
1776
1776
|
}
|
|
1777
|
-
function
|
|
1777
|
+
function I(e) {
|
|
1778
1778
|
try {
|
|
1779
1779
|
return e.track;
|
|
1780
1780
|
} catch {
|
|
1781
1781
|
return null;
|
|
1782
1782
|
}
|
|
1783
1783
|
}
|
|
1784
|
-
function
|
|
1784
|
+
function L(e) {
|
|
1785
1785
|
return typeof e == "object" && !!e && e.name === "InvalidStateError";
|
|
1786
1786
|
}
|
|
1787
|
-
function
|
|
1787
|
+
function R(e) {
|
|
1788
1788
|
try {
|
|
1789
1789
|
return e.replaceTrack(null).catch((e) => {
|
|
1790
|
-
if (!
|
|
1790
|
+
if (!L(e)) throw e;
|
|
1791
1791
|
});
|
|
1792
1792
|
} catch (e) {
|
|
1793
|
-
return
|
|
1793
|
+
return L(e) ? Promise.resolve() : Promise.reject(e);
|
|
1794
1794
|
}
|
|
1795
1795
|
}
|
|
1796
|
-
function
|
|
1796
|
+
function Ee(e) {
|
|
1797
1797
|
try {
|
|
1798
|
-
|
|
1798
|
+
z(e.getTracks());
|
|
1799
1799
|
} catch {}
|
|
1800
1800
|
}
|
|
1801
|
-
function
|
|
1802
|
-
e.forEach(
|
|
1801
|
+
function z(e) {
|
|
1802
|
+
e.forEach(B);
|
|
1803
1803
|
}
|
|
1804
|
-
function
|
|
1804
|
+
function B(e) {
|
|
1805
1805
|
try {
|
|
1806
1806
|
e.stop();
|
|
1807
1807
|
} catch {}
|
|
1808
1808
|
}
|
|
1809
|
-
function
|
|
1809
|
+
function De(e) {
|
|
1810
1810
|
if (typeof MediaStream < "u") try {
|
|
1811
1811
|
return new MediaStream([e]);
|
|
1812
1812
|
} catch {
|
|
@@ -1815,8 +1815,8 @@ function xe(e) {
|
|
|
1815
1815
|
}
|
|
1816
1816
|
//#endregion
|
|
1817
1817
|
//#region src/core/mediaBridge.ts
|
|
1818
|
-
function
|
|
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
|
|
1818
|
+
function Oe(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 we({ getActiveCall: u });
|
|
1820
1820
|
return {
|
|
1821
1821
|
publicMedia: {
|
|
1822
1822
|
requestPermission: () => (f(), d.requestPermission()),
|
|
@@ -1829,7 +1829,7 @@ function Se(t, n = {}) {
|
|
|
1829
1829
|
releaseAll: () => (f(), d.releaseAll())
|
|
1830
1830
|
},
|
|
1831
1831
|
registerCall(e, t) {
|
|
1832
|
-
s || c || !
|
|
1832
|
+
s || c || !V(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
|
|
1833
1833
|
},
|
|
1834
1834
|
async setCallOwnership(e, t) {
|
|
1835
1835
|
if (s) return;
|
|
@@ -1872,9 +1872,9 @@ function Se(t, n = {}) {
|
|
|
1872
1872
|
if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
1873
1873
|
}
|
|
1874
1874
|
function p(e, t) {
|
|
1875
|
-
if (!
|
|
1875
|
+
if (!V(t) || typeof t.getMediaRegistration != "function") return;
|
|
1876
1876
|
let n = t.getMediaRegistration();
|
|
1877
|
-
if (
|
|
1877
|
+
if (ke(n) && r.get(e)?.peerConnection !== n.peerConnection) {
|
|
1878
1878
|
r.set(e, n);
|
|
1879
1879
|
try {
|
|
1880
1880
|
d.registerCallMedia(e, n);
|
|
@@ -1884,22 +1884,22 @@ function Se(t, n = {}) {
|
|
|
1884
1884
|
}
|
|
1885
1885
|
}
|
|
1886
1886
|
}
|
|
1887
|
-
function
|
|
1887
|
+
function V(e) {
|
|
1888
1888
|
return typeof e == "object" && !!e;
|
|
1889
1889
|
}
|
|
1890
|
-
function
|
|
1890
|
+
function ke(e) {
|
|
1891
1891
|
return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
|
|
1892
1892
|
}
|
|
1893
1893
|
//#endregion
|
|
1894
1894
|
//#region src/reconnect/backoff.ts
|
|
1895
|
-
var
|
|
1896
|
-
function
|
|
1897
|
-
let n = Math.min(
|
|
1895
|
+
var Ae = 1e3, je = 3e4;
|
|
1896
|
+
function Me(e, t = Math.random) {
|
|
1897
|
+
let n = Math.min(je, Ae * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
|
|
1898
1898
|
return Math.round(n * (1 + r * .2));
|
|
1899
1899
|
}
|
|
1900
1900
|
//#endregion
|
|
1901
1901
|
//#region src/reconnect/ReconnectManager.ts
|
|
1902
|
-
var
|
|
1902
|
+
var Ne = class {
|
|
1903
1903
|
recover;
|
|
1904
1904
|
random;
|
|
1905
1905
|
isOnline;
|
|
@@ -1916,7 +1916,7 @@ var De = class {
|
|
|
1916
1916
|
}
|
|
1917
1917
|
start() {
|
|
1918
1918
|
if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
|
|
1919
|
-
let e = this.generation, t =
|
|
1919
|
+
let e = this.generation, t = Me(this.attempt, this.random);
|
|
1920
1920
|
this.pendingTimer = setTimeout(() => {
|
|
1921
1921
|
this.pendingTimer = void 0, this.run(e);
|
|
1922
1922
|
}, t);
|
|
@@ -1958,7 +1958,7 @@ var De = class {
|
|
|
1958
1958
|
clearPendingTimer() {
|
|
1959
1959
|
this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
|
|
1960
1960
|
}
|
|
1961
|
-
},
|
|
1961
|
+
}, Pe = class t {
|
|
1962
1962
|
media;
|
|
1963
1963
|
options;
|
|
1964
1964
|
api;
|
|
@@ -1995,7 +1995,7 @@ var De = class {
|
|
|
1995
1995
|
sharedWorkerSelection;
|
|
1996
1996
|
constructor(t) {
|
|
1997
1997
|
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 ?
|
|
1998
|
+
this.api = t.api === void 0 ? H(Le(t.sessionProvider)) : H(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : Re(t.sip), this.mediaBridge = Oe(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new Ne({
|
|
1999
1999
|
recover: () => this.recoverConnection(),
|
|
2000
2000
|
onAttempt: (e) => {
|
|
2001
2001
|
this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
|
|
@@ -2007,13 +2007,13 @@ var De = class {
|
|
|
2007
2007
|
}), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
|
|
2008
2008
|
mode: "single-tab",
|
|
2009
2009
|
reason: "disabled"
|
|
2010
|
-
} :
|
|
2010
|
+
} : E({
|
|
2011
2011
|
...t.sharedWorker,
|
|
2012
2012
|
...t.sharedWorkerHost ?? {}
|
|
2013
2013
|
});
|
|
2014
2014
|
}
|
|
2015
2015
|
static async checkSupport() {
|
|
2016
|
-
let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n =
|
|
2016
|
+
let e = typeof navigator < "u" && navigator.mediaDevices !== void 0, t = typeof WebSocket < "u", n = Ie(typeof navigator < "u" ? navigator.userAgent : "");
|
|
2017
2017
|
return {
|
|
2018
2018
|
supported: e && t,
|
|
2019
2019
|
platform: n,
|
|
@@ -2028,8 +2028,9 @@ var De = class {
|
|
|
2028
2028
|
this.support = e, this.options.platform === void 0 && (e.platform === "web" || e.platform === "mobile-web") && (this.detectedPlatform = e.platform), await this.awaitSharedWorkerReady(), this.assertNotDisposed(), this.initialized = !0;
|
|
2029
2029
|
}
|
|
2030
2030
|
connect() {
|
|
2031
|
-
if (this.assertNotDisposed(), this.
|
|
2031
|
+
if (this.assertNotDisposed(), this.connectOperation !== void 0) return this.connectOperation;
|
|
2032
2032
|
if (this.state === "connected") return Promise.resolve();
|
|
2033
|
+
this.api.invalidateToken?.();
|
|
2033
2034
|
let e = this.lifecycleGeneration, t = this.performConnect(e).finally(() => {
|
|
2034
2035
|
this.connectOperation === t && (this.connectOperation = void 0);
|
|
2035
2036
|
});
|
|
@@ -2120,14 +2121,14 @@ var De = class {
|
|
|
2120
2121
|
sdkVersion: n,
|
|
2121
2122
|
platform: a === "mobile-web" ? "mobile_web" : "web",
|
|
2122
2123
|
...this.options.locale === void 0 ? {} : { locale: this.options.locale },
|
|
2123
|
-
requestedCapabilities: [...this.options.requestedCapabilities ??
|
|
2124
|
+
requestedCapabilities: [...this.options.requestedCapabilities ?? He(a)]
|
|
2124
2125
|
}), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
|
|
2125
2126
|
let o = this.callManager ?? this.createCallManager(r, t, a);
|
|
2126
2127
|
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);
|
|
2127
2128
|
} catch (n) {
|
|
2128
2129
|
if (await this.rollbackConnect(t, r, i), this.disposed) throw this.disposedError();
|
|
2129
2130
|
if (e !== this.lifecycleGeneration) throw n;
|
|
2130
|
-
let a =
|
|
2131
|
+
let a = W(n, "REGISTRATION_FAILED", "registration", !0);
|
|
2131
2132
|
throw this.setConnectionState("failed"), this.events.emit("connection.failed", { error: a }), a;
|
|
2132
2133
|
}
|
|
2133
2134
|
}
|
|
@@ -2136,13 +2137,13 @@ var De = class {
|
|
|
2136
2137
|
if (t !== void 0) try {
|
|
2137
2138
|
await t;
|
|
2138
2139
|
} catch (t) {
|
|
2139
|
-
|
|
2140
|
+
K(t) || (e ??= t);
|
|
2140
2141
|
}
|
|
2141
2142
|
let n = this.refreshOperation;
|
|
2142
2143
|
if (n !== void 0) try {
|
|
2143
2144
|
await n;
|
|
2144
2145
|
} catch (t) {
|
|
2145
|
-
|
|
2146
|
+
K(t) || (e ??= t);
|
|
2146
2147
|
}
|
|
2147
2148
|
this.reconnect.cancel(), this.clearRefreshTimer(), this.intentionalDisconnect = !0, this.detachNetworkListeners(), this.detachSipListener(), this.detachManagerListeners();
|
|
2148
2149
|
let r = this.callManager, i = this.sip;
|
|
@@ -2171,7 +2172,7 @@ var De = class {
|
|
|
2171
2172
|
if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
|
|
2172
2173
|
}
|
|
2173
2174
|
createCallManager(e, t, n) {
|
|
2174
|
-
let r = new
|
|
2175
|
+
let r = new x({
|
|
2175
2176
|
sip: e,
|
|
2176
2177
|
platform: n,
|
|
2177
2178
|
session: t,
|
|
@@ -2209,7 +2210,7 @@ var De = class {
|
|
|
2209
2210
|
for (let n of t) try {
|
|
2210
2211
|
await n;
|
|
2211
2212
|
} catch (t) {
|
|
2212
|
-
|
|
2213
|
+
K(t) || (e ??= t);
|
|
2213
2214
|
}
|
|
2214
2215
|
let n = this.callManager;
|
|
2215
2216
|
this.callManager = void 0;
|
|
@@ -2226,7 +2227,7 @@ var De = class {
|
|
|
2226
2227
|
try {
|
|
2227
2228
|
await this.media.releaseAll();
|
|
2228
2229
|
} catch (t) {
|
|
2229
|
-
|
|
2230
|
+
ze(t) || (e ??= t);
|
|
2230
2231
|
}
|
|
2231
2232
|
try {
|
|
2232
2233
|
await this.mediaBridge.dispose();
|
|
@@ -2304,7 +2305,7 @@ var De = class {
|
|
|
2304
2305
|
let n = this.mediaBridge.releaseCall(e).then(() => {
|
|
2305
2306
|
this.terminalReleaseOperations.get(e) === n && this.terminalReleaseOperations.delete(e);
|
|
2306
2307
|
}).catch((t) => {
|
|
2307
|
-
throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error:
|
|
2308
|
+
throw this.acceptingEvents && !this.disposed && this.events.emit("error", { error: W(t, "SDK_INTERNAL_ERROR", "internal", !0, e) }), t;
|
|
2308
2309
|
});
|
|
2309
2310
|
return this.terminalReleaseOperations.set(e, n), n;
|
|
2310
2311
|
}
|
|
@@ -2348,8 +2349,8 @@ var De = class {
|
|
|
2348
2349
|
}
|
|
2349
2350
|
handleRefreshFailure(e, t) {
|
|
2350
2351
|
if (this.disposed) return;
|
|
2351
|
-
let n =
|
|
2352
|
-
if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }),
|
|
2352
|
+
let n = W(t, "NETWORK_OFFLINE", "network", !0);
|
|
2353
|
+
if (this.events.emit("token.expiring", { expiresAt: e.expiresAt }), this.events.emit("error", { error: n }), G(t)) {
|
|
2353
2354
|
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?.();
|
|
2354
2355
|
return;
|
|
2355
2356
|
}
|
|
@@ -2361,7 +2362,7 @@ var De = class {
|
|
|
2361
2362
|
try {
|
|
2362
2363
|
await this.performDisconnect();
|
|
2363
2364
|
} catch (e) {
|
|
2364
|
-
this.disposed || this.events.emit("error", { error:
|
|
2365
|
+
this.disposed || this.events.emit("error", { error: W(e, "SDK_INTERNAL_ERROR", "internal", !0) });
|
|
2365
2366
|
return;
|
|
2366
2367
|
}
|
|
2367
2368
|
if (!this.disposed) try {
|
|
@@ -2384,7 +2385,7 @@ var De = class {
|
|
|
2384
2385
|
async getSip() {
|
|
2385
2386
|
if (this.sip !== void 0) return this.sip;
|
|
2386
2387
|
if (this.suppliedSip !== void 0) return this.sip = this.suppliedSip, this.sip;
|
|
2387
|
-
let [e, t] = await Promise.all([import("./createJsSipFactory-
|
|
2388
|
+
let [e, t] = await Promise.all([import("./createJsSipFactory-CoWZN-BC.js"), import("./JsSipAdapter-CwDotPN2.js")]);
|
|
2388
2389
|
return this.sip = new t.JsSipAdapter(e.createJsSipFactory(), this.options.baseUrl, this.options.sipKeepaliveSeconds, this.options.agentTerminal, this.options.sipSessionTimers ?? !1), this.sip;
|
|
2389
2390
|
}
|
|
2390
2391
|
attachSipListener(e) {
|
|
@@ -2394,7 +2395,7 @@ var De = class {
|
|
|
2394
2395
|
this.setConnectionState("connected");
|
|
2395
2396
|
return;
|
|
2396
2397
|
}
|
|
2397
|
-
this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error:
|
|
2398
|
+
this.state === "connected" && (this.setConnectionState("reconnecting"), this.reconnect.start(), t !== void 0 && this.events.emit("error", { error: W(t, "SIP_WS_UNAVAILABLE", "registration", !0) }));
|
|
2398
2399
|
}
|
|
2399
2400
|
}));
|
|
2400
2401
|
}
|
|
@@ -2426,7 +2427,7 @@ var De = class {
|
|
|
2426
2427
|
destination: e.destination
|
|
2427
2428
|
})),
|
|
2428
2429
|
permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
|
|
2429
|
-
ice:
|
|
2430
|
+
ice: Fe(e),
|
|
2430
2431
|
wss: {
|
|
2431
2432
|
configured: e !== void 0,
|
|
2432
2433
|
secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
|
|
@@ -2466,7 +2467,7 @@ var De = class {
|
|
|
2466
2467
|
let n = this.api.deleteSession(e).then(() => {
|
|
2467
2468
|
this.deletedSessions.add(e);
|
|
2468
2469
|
}).catch((t) => {
|
|
2469
|
-
if (
|
|
2470
|
+
if (G(t)) {
|
|
2470
2471
|
this.deletedSessions.add(e);
|
|
2471
2472
|
return;
|
|
2472
2473
|
}
|
|
@@ -2543,7 +2544,7 @@ var De = class {
|
|
|
2543
2544
|
return new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
2544
2545
|
}
|
|
2545
2546
|
};
|
|
2546
|
-
function
|
|
2547
|
+
function Fe(e) {
|
|
2547
2548
|
if (e === void 0) return {
|
|
2548
2549
|
configured: !1,
|
|
2549
2550
|
serverCount: 0,
|
|
@@ -2561,17 +2562,17 @@ function ke(e) {
|
|
|
2561
2562
|
turnServerCount: n
|
|
2562
2563
|
};
|
|
2563
2564
|
}
|
|
2564
|
-
function
|
|
2565
|
+
function Ie(e) {
|
|
2565
2566
|
return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
|
|
2566
2567
|
}
|
|
2567
|
-
function
|
|
2568
|
+
function H(t) {
|
|
2568
2569
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2569
2570
|
return t;
|
|
2570
2571
|
}
|
|
2571
|
-
async function
|
|
2572
|
+
async function U(e) {
|
|
2572
2573
|
let t = e.sip?.registerTicket;
|
|
2573
2574
|
if (typeof t != "string" || t === "") return e;
|
|
2574
|
-
let n = await
|
|
2575
|
+
let n = await se(t);
|
|
2575
2576
|
return n === void 0 || n === t ? e : {
|
|
2576
2577
|
...e,
|
|
2577
2578
|
sip: {
|
|
@@ -2580,10 +2581,10 @@ async function Y(e) {
|
|
|
2580
2581
|
}
|
|
2581
2582
|
};
|
|
2582
2583
|
}
|
|
2583
|
-
function
|
|
2584
|
+
function Le(t) {
|
|
2584
2585
|
let r = {
|
|
2585
|
-
createSession: async (e) =>
|
|
2586
|
-
refreshSession: async (e) =>
|
|
2586
|
+
createSession: async (e) => U(await t.createSession(e)),
|
|
2587
|
+
refreshSession: async (e) => U(t.refreshSession === void 0 ? await t.createSession({
|
|
2587
2588
|
sdkVersion: n,
|
|
2588
2589
|
platform: "web"
|
|
2589
2590
|
}) : await t.refreshSession(e)),
|
|
@@ -2594,11 +2595,11 @@ function X(t) {
|
|
|
2594
2595
|
}, i = t.invalidateToken;
|
|
2595
2596
|
return i !== void 0 && (r.invalidateToken = () => i()), r;
|
|
2596
2597
|
}
|
|
2597
|
-
function
|
|
2598
|
+
function Re(t) {
|
|
2598
2599
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2599
2600
|
return t;
|
|
2600
2601
|
}
|
|
2601
|
-
function
|
|
2602
|
+
function W(t, n, r, i, a) {
|
|
2602
2603
|
return t instanceof e ? new e(t.code, t.category, t.retryable, {
|
|
2603
2604
|
requestId: t.requestId,
|
|
2604
2605
|
callId: a ?? t.callId,
|
|
@@ -2610,16 +2611,16 @@ function Z(t, n, r, i, a) {
|
|
|
2610
2611
|
cause: t
|
|
2611
2612
|
});
|
|
2612
2613
|
}
|
|
2613
|
-
function
|
|
2614
|
+
function G(t) {
|
|
2614
2615
|
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
2616
|
}
|
|
2616
|
-
function
|
|
2617
|
+
function ze(t) {
|
|
2617
2618
|
return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
|
|
2618
2619
|
}
|
|
2619
|
-
function
|
|
2620
|
+
function K(t) {
|
|
2620
2621
|
return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
|
|
2621
2622
|
}
|
|
2622
|
-
var
|
|
2623
|
+
var Be = [
|
|
2623
2624
|
"outbound",
|
|
2624
2625
|
"inbound",
|
|
2625
2626
|
"mute",
|
|
@@ -2627,13 +2628,284 @@ var Ne = [
|
|
|
2627
2628
|
"dtmf",
|
|
2628
2629
|
"blind_transfer",
|
|
2629
2630
|
"device_selection"
|
|
2630
|
-
],
|
|
2631
|
+
], Ve = [
|
|
2631
2632
|
"outbound",
|
|
2632
2633
|
"mute",
|
|
2633
2634
|
"dtmf"
|
|
2634
2635
|
];
|
|
2635
|
-
function
|
|
2636
|
-
return e === "mobile-web" ?
|
|
2636
|
+
function He(e) {
|
|
2637
|
+
return e === "mobile-web" ? Ve : Be;
|
|
2638
|
+
}
|
|
2639
|
+
//#endregion
|
|
2640
|
+
//#region src/legacy/legacySessionProvider.ts
|
|
2641
|
+
var Ue = "/openapi/token/v1", We = "/seat/account/get", Ge = "/seats/set-status", Ke = 3478, qe = 600, q = 600, Je = 180, J = 60, Ye = 5e3, Y = 2e4, Xe = [
|
|
2642
|
+
"outbound",
|
|
2643
|
+
"inbound",
|
|
2644
|
+
"mute",
|
|
2645
|
+
"dtmf",
|
|
2646
|
+
"hold",
|
|
2647
|
+
"blind_transfer"
|
|
2648
|
+
], Ze = {
|
|
2649
|
+
available: {
|
|
2650
|
+
status: "Available",
|
|
2651
|
+
reason: "空闲"
|
|
2652
|
+
},
|
|
2653
|
+
break: {
|
|
2654
|
+
status: "On Break",
|
|
2655
|
+
reason: "休息"
|
|
2656
|
+
},
|
|
2657
|
+
offline: {
|
|
2658
|
+
status: "Logged Out",
|
|
2659
|
+
reason: ""
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
function X(t) {
|
|
2663
|
+
let n = $e(t.host), r = et(t.pathPrefix ?? Ue), i = `${n}${r}${Z(t.accountPath ?? We)}`, a = `${n}${r}${Z(t.statusPath ?? Ge)}`, o = {
|
|
2664
|
+
...t.aesKey ? { key: t.aesKey } : {},
|
|
2665
|
+
...t.aesIv ? { iv: t.aesIv } : {}
|
|
2666
|
+
}, s = Math.max(0, t.refreshBufferSeconds ?? Je), c = t.fetchImpl ?? globalThis.fetch, l, u, d = "";
|
|
2667
|
+
async function f() {
|
|
2668
|
+
if (t.getToken !== void 0) return t.getToken();
|
|
2669
|
+
if (t.tokenUrl !== void 0) {
|
|
2670
|
+
let n = t.tokenMethod ?? "POST", r = {
|
|
2671
|
+
method: n,
|
|
2672
|
+
headers: {
|
|
2673
|
+
Accept: "application/json",
|
|
2674
|
+
...t.tokenHeaders ?? {}
|
|
2675
|
+
},
|
|
2676
|
+
credentials: "include"
|
|
2677
|
+
};
|
|
2678
|
+
n === "POST" && (r.headers = {
|
|
2679
|
+
"Content-Type": "application/json",
|
|
2680
|
+
...r.headers
|
|
2681
|
+
}, r.body = JSON.stringify(t.tokenBody ?? {}));
|
|
2682
|
+
let i = await $(c, t.tokenUrl, r, "取 token"), a = await i.text();
|
|
2683
|
+
try {
|
|
2684
|
+
return JSON.parse(a);
|
|
2685
|
+
} catch {
|
|
2686
|
+
throw new e("AUTH_TOKEN_UNAVAILABLE", "auth", !0, {
|
|
2687
|
+
status: i.status,
|
|
2688
|
+
cause: `取 token 的接口返回了非 JSON 响应(HTTP ${i.status}):${a.trim().slice(0, 120)}`
|
|
2689
|
+
});
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
throw new e("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 getToken 或 tokenUrl;坐席状态也可以直接用会话软电话地址里的 token(setAgentStatus 的 context.wssUrl),但这次调用没有会话可用" });
|
|
2693
|
+
}
|
|
2694
|
+
async function p() {
|
|
2695
|
+
if (l && l.expiresAtMs - Date.now() > Ye) return l.token;
|
|
2696
|
+
let t;
|
|
2697
|
+
try {
|
|
2698
|
+
t = await f();
|
|
2699
|
+
} catch (t) {
|
|
2700
|
+
throw t instanceof e ? t : new e("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: t });
|
|
2701
|
+
}
|
|
2702
|
+
let n = nt(t);
|
|
2703
|
+
if (!n.token) throw new e("AUTH_TOKEN_UNAVAILABLE", "auth", !0, { cause: "取 token 的返回里没有 token(支持 {token}、{accessToken}、{data:{token}} 或裸字符串)" });
|
|
2704
|
+
let r = Q(n.expires, 3600);
|
|
2705
|
+
return l = {
|
|
2706
|
+
token: n.token,
|
|
2707
|
+
expiresAtMs: Date.now() + r * 1e3
|
|
2708
|
+
}, l.token;
|
|
2709
|
+
}
|
|
2710
|
+
function m(e) {
|
|
2711
|
+
if (!e) return "";
|
|
2712
|
+
try {
|
|
2713
|
+
return String(new URL(e).searchParams.get("token") ?? "").trim();
|
|
2714
|
+
} catch {
|
|
2715
|
+
return "";
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
async function h(e) {
|
|
2719
|
+
let t = m(e?.wssUrl);
|
|
2720
|
+
return t ? (d = t, t) : d || p();
|
|
2721
|
+
}
|
|
2722
|
+
async function g(t) {
|
|
2723
|
+
let n = t || await p(), r = await $(c, i, {
|
|
2724
|
+
method: "POST",
|
|
2725
|
+
headers: {
|
|
2726
|
+
Authorization: n,
|
|
2727
|
+
"Content-Type": "application/json",
|
|
2728
|
+
Accept: "application/json"
|
|
2729
|
+
},
|
|
2730
|
+
body: "{}"
|
|
2731
|
+
}, "取坐席账号"), a = await r.text(), o;
|
|
2732
|
+
try {
|
|
2733
|
+
o = JSON.parse(a);
|
|
2734
|
+
} catch {
|
|
2735
|
+
throw new e("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
|
|
2736
|
+
status: r.status,
|
|
2737
|
+
cause: `${i} 返回了非 JSON 响应(HTTP ${r.status});请确认 host 填的是接口网关(不是文档站)`
|
|
2738
|
+
});
|
|
2739
|
+
}
|
|
2740
|
+
let s = Number(o.code ?? NaN);
|
|
2741
|
+
if (!r.ok || s !== 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", s === 50, {
|
|
2742
|
+
status: r.status,
|
|
2743
|
+
serverCode: Number.isFinite(s) ? String(s) : void 0,
|
|
2744
|
+
cause: o.message || `取坐席账号失败(HTTP ${r.status})`
|
|
2745
|
+
});
|
|
2746
|
+
if (!o.data) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号接口没有返回 data" });
|
|
2747
|
+
return u = o.data, u;
|
|
2748
|
+
}
|
|
2749
|
+
let _ = (e) => C(e, o);
|
|
2750
|
+
function v(n) {
|
|
2751
|
+
let r = String(t.sipWsUrl ?? "").trim();
|
|
2752
|
+
if (!r) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 sipWsUrl:软电话 WSS 地址由接入方提供(wss:// 或 ws:// 开头的完整地址)" });
|
|
2753
|
+
let i;
|
|
2754
|
+
try {
|
|
2755
|
+
i = new URL(r);
|
|
2756
|
+
} catch {
|
|
2757
|
+
throw new e("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 不是完整地址(需要 wss:// 或 ws:// 开头):${r}` });
|
|
2758
|
+
}
|
|
2759
|
+
if (i.protocol !== "wss:" && i.protocol !== "ws:") throw new e("CONFIG_INVALID", "configuration", !1, { cause: `sipWsUrl 需要 wss:// 或 ws:// 开头:${r}` });
|
|
2760
|
+
return (t.attachTokenToWss ?? !0) && n && i.searchParams.set("token", n), i.toString();
|
|
2761
|
+
}
|
|
2762
|
+
function y(e) {
|
|
2763
|
+
let t = (Array.isArray(e.iceServers) ? e.iceServers : []).map((e) => {
|
|
2764
|
+
let t = (Array.isArray(e?.urls) ? e.urls : typeof e?.urls == "string" ? [e.urls] : []).map((e) => String(e ?? "").trim()).filter(Boolean);
|
|
2765
|
+
if (t.length !== 0) return {
|
|
2766
|
+
urls: t,
|
|
2767
|
+
...e?.username ? { username: String(e.username) } : {},
|
|
2768
|
+
...e?.credential ? { credential: String(e.credential) } : {}
|
|
2769
|
+
};
|
|
2770
|
+
}).filter((e) => e !== void 0);
|
|
2771
|
+
if (t.length > 0) return t;
|
|
2772
|
+
let n = String(e.turnIp ?? "").trim();
|
|
2773
|
+
return n ? [{ urls: [`stun:${n}:${Number(e.turnPort) || Ke}`] }] : [];
|
|
2774
|
+
}
|
|
2775
|
+
async function b() {
|
|
2776
|
+
let r = await p(), i = await g(), a = String(i.username ?? i.account ?? "").trim();
|
|
2777
|
+
if (!a) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
2778
|
+
let o = String(i.registerPassword ?? i.password ?? ""), c = o ? await _(o) : "";
|
|
2779
|
+
if (!c) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 password/registerPassword,或解密后为空" });
|
|
2780
|
+
let u = Q(i.expiresIn ?? i.expires_in, q), f = Math.max(0, Math.round((l.expiresAtMs - Date.now()) / 1e3)), m = Math.max(J, Math.min(f || u, u) - s), h = String(i.domain ?? "").trim() || tt(n), b = v(r);
|
|
2781
|
+
return r && (d = r), {
|
|
2782
|
+
sessionId: `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
2783
|
+
expiresAt: Math.floor(Date.now() / 1e3) + m,
|
|
2784
|
+
agent: {
|
|
2785
|
+
id: a,
|
|
2786
|
+
externalUserId: a,
|
|
2787
|
+
displayName: a,
|
|
2788
|
+
extension: a,
|
|
2789
|
+
status: "Available"
|
|
2790
|
+
},
|
|
2791
|
+
sip: {
|
|
2792
|
+
uri: `sip:${a}@${h}`,
|
|
2793
|
+
registrar: h,
|
|
2794
|
+
registerTicket: c,
|
|
2795
|
+
registerExpires: Number(t.registerExpires) > 0 ? Number(t.registerExpires) : qe,
|
|
2796
|
+
ticketExpiresIn: m
|
|
2797
|
+
},
|
|
2798
|
+
transport: {
|
|
2799
|
+
wssUrl: b,
|
|
2800
|
+
ticket: "",
|
|
2801
|
+
ticketExpiresIn: m
|
|
2802
|
+
},
|
|
2803
|
+
iceServers: y(i),
|
|
2804
|
+
policy: {
|
|
2805
|
+
maxConcurrentCalls: Number(t.maxConcurrentCalls) > 0 ? Number(t.maxConcurrentCalls) : 2,
|
|
2806
|
+
incomingEnabled: t.incomingEnabled ?? !0,
|
|
2807
|
+
mobileIncomingEnabled: t.mobileIncomingEnabled ?? !0,
|
|
2808
|
+
backgroundCallingSupported: !1
|
|
2809
|
+
},
|
|
2810
|
+
capabilities: [...t.capabilities ?? Xe]
|
|
2811
|
+
};
|
|
2812
|
+
}
|
|
2813
|
+
return {
|
|
2814
|
+
createSession: b,
|
|
2815
|
+
refreshSession: b,
|
|
2816
|
+
setAgentStatus: async ({ status: t, reason: n }, r) => {
|
|
2817
|
+
let i = await h(r), o = u ?? await g(i), s = String(o.username ?? o.account ?? "").trim();
|
|
2818
|
+
if (!s) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "坐席账号里没有 username" });
|
|
2819
|
+
let l = Ze[t], d = await $(c, a, {
|
|
2820
|
+
method: "POST",
|
|
2821
|
+
headers: {
|
|
2822
|
+
Authorization: i,
|
|
2823
|
+
"Content-Type": "application/json",
|
|
2824
|
+
Accept: "application/json"
|
|
2825
|
+
},
|
|
2826
|
+
body: JSON.stringify({
|
|
2827
|
+
extension: s,
|
|
2828
|
+
status: l.status,
|
|
2829
|
+
reason: n || l.reason
|
|
2830
|
+
})
|
|
2831
|
+
}, "设置坐席状态"), f = await d.text(), p;
|
|
2832
|
+
try {
|
|
2833
|
+
p = JSON.parse(f);
|
|
2834
|
+
} catch {
|
|
2835
|
+
throw new e("LEGACY_PLATFORM_UNREACHABLE", "network", !0, {
|
|
2836
|
+
status: d.status,
|
|
2837
|
+
cause: `${a} 返回了非 JSON 响应(HTTP ${d.status})`
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
let m = Number(p.code ?? NaN);
|
|
2841
|
+
if (!d.ok || m !== 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", m === 50, {
|
|
2842
|
+
status: d.status,
|
|
2843
|
+
serverCode: Number.isFinite(m) ? String(m) : void 0,
|
|
2844
|
+
cause: p.message || `设置坐席状态失败(HTTP ${d.status})`
|
|
2845
|
+
});
|
|
2846
|
+
},
|
|
2847
|
+
invalidateToken: () => {
|
|
2848
|
+
l = void 0, d = "";
|
|
2849
|
+
},
|
|
2850
|
+
getSeatAccount: async () => u ?? g()
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
function Qe(e) {
|
|
2854
|
+
return X(e);
|
|
2855
|
+
}
|
|
2856
|
+
function $e(t) {
|
|
2857
|
+
let n = String(t ?? "").trim().replace(/\/+$/, "");
|
|
2858
|
+
if (!n) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "createLegacySessionProvider 需要 host" });
|
|
2859
|
+
return /^https?:\/\//i.test(n) ? n : `https://${n}`;
|
|
2860
|
+
}
|
|
2861
|
+
function et(e) {
|
|
2862
|
+
let t = String(e ?? "").trim();
|
|
2863
|
+
return !t || t === "/" ? "" : `/${t.replace(/^\/+|\/+$/g, "")}`;
|
|
2864
|
+
}
|
|
2865
|
+
function Z(e) {
|
|
2866
|
+
let t = String(e ?? "").trim();
|
|
2867
|
+
return t.startsWith("/") ? t : `/${t}`;
|
|
2868
|
+
}
|
|
2869
|
+
function tt(e) {
|
|
2870
|
+
try {
|
|
2871
|
+
return new URL(e).hostname;
|
|
2872
|
+
} catch {
|
|
2873
|
+
return "";
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
function Q(e, t) {
|
|
2877
|
+
let n = Number(e);
|
|
2878
|
+
return !Number.isFinite(n) || n <= 0 ? t : (n > 86400 && (n /= 1e3), Math.min(Math.max(Math.floor(n), J), 86400));
|
|
2879
|
+
}
|
|
2880
|
+
function nt(e) {
|
|
2881
|
+
if (typeof e == "string") return { token: e.trim() };
|
|
2882
|
+
let t = e ?? {}, n = typeof t.data == "object" && t.data !== null ? t.data : void 0;
|
|
2883
|
+
for (let e of [t, n]) {
|
|
2884
|
+
if (e === void 0) continue;
|
|
2885
|
+
let t = e.token ?? e.accessToken;
|
|
2886
|
+
if (typeof t == "string" && t.trim()) {
|
|
2887
|
+
let n = Number(e.expires ?? e.expiresIn ?? e.expires_at);
|
|
2888
|
+
return {
|
|
2889
|
+
token: t.trim(),
|
|
2890
|
+
...Number.isFinite(n) && n > 0 ? { expires: n } : {}
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
return { token: "" };
|
|
2895
|
+
}
|
|
2896
|
+
async function $(t, n, r, i) {
|
|
2897
|
+
let a = new AbortController(), o = setTimeout(() => a.abort(), Y);
|
|
2898
|
+
try {
|
|
2899
|
+
return await t(n, {
|
|
2900
|
+
...r,
|
|
2901
|
+
signal: a.signal
|
|
2902
|
+
});
|
|
2903
|
+
} catch (t) {
|
|
2904
|
+
let r = a.signal.aborted;
|
|
2905
|
+
throw new e(r ? "NETWORK_TIMEOUT" : "LEGACY_PLATFORM_UNREACHABLE", "network", !0, { cause: r ? `${i}超时(${Y / 1e3} 秒):POST ${n}` : `${i}失败:无法请求 ${n}(${t instanceof Error ? t.message : String(t)})` });
|
|
2906
|
+
} finally {
|
|
2907
|
+
clearTimeout(o);
|
|
2908
|
+
}
|
|
2637
2909
|
}
|
|
2638
2910
|
//#endregion
|
|
2639
|
-
export {
|
|
2911
|
+
export { D as a, f as c, o as d, l as f, E as i, c as l, i as m, X as n, C as o, a as p, Pe as r, x as s, Qe as t, s as u };
|