@16x/webphone-sdk 3.1.8 → 3.1.10
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 +67 -0
- package/README.md +64 -17
- package/dist/{CCBarClient-DdxjJrdT.js → CCBarClient-Sr_zlDBu.js} +232 -380
- package/dist/CCBarClient-z-TFUjTB.cjs +1 -0
- package/dist/{Diagnostics-BaGHYBAX.js → Diagnostics-WkQagE6_.js} +1 -1
- package/dist/Diagnostics-x4G0ho6W.cjs +1 -0
- package/dist/api/contracts.d.ts +11 -6
- package/dist/core/CCBarClient.d.ts +11 -14
- 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 +0 -2
- package/dist/index.js +7 -7
- package/dist/index.umd.js +16 -16
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.d.ts +2 -0
- package/dist/legacy/index.js +276 -10
- package/dist/legacy/legacyAes.d.ts +7 -0
- package/dist/legacy/legacySessionProvider.d.ts +79 -0
- package/dist/types.d.ts +5 -1
- package/dist/ui/index.cjs +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -4
- package/dist/CCBarClient-BqMNSIu-.cjs +0 -1
- package/dist/Diagnostics-LQAtyhLu.cjs +0 -1
- package/dist/api/WebPhoneApi.d.ts +0 -28
- package/dist/auth/TokenManager.d.ts +0 -22
|
@@ -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-WkQagE6_.js";
|
|
3
3
|
//#region src/events/TypedEventBus.ts
|
|
4
4
|
var i = class {
|
|
5
5
|
handlers = /* @__PURE__ */ new Map();
|
|
@@ -73,216 +73,7 @@ var c = class extends e {
|
|
|
73
73
|
to: t
|
|
74
74
|
} });
|
|
75
75
|
}
|
|
76
|
-
}, l = s, u =
|
|
77
|
-
tokenProvider;
|
|
78
|
-
cachedToken;
|
|
79
|
-
cachedRequestKey = "";
|
|
80
|
-
refreshing;
|
|
81
|
-
generation = 0;
|
|
82
|
-
constructor(e) {
|
|
83
|
-
this.tokenProvider = e;
|
|
84
|
-
}
|
|
85
|
-
getValidToken(e) {
|
|
86
|
-
let t = e?.extension?.trim() ?? "";
|
|
87
|
-
if (this.cachedToken && this.cachedRequestKey === t && !this.needsRefresh(this.cachedToken)) return Promise.resolve(this.cachedToken.accessToken);
|
|
88
|
-
if (!this.refreshing) {
|
|
89
|
-
let n = this.generation, r = this.refresh(e, t, n);
|
|
90
|
-
this.refreshing = r, r.then(() => this.clearRefresh(r), () => this.clearRefresh(r));
|
|
91
|
-
}
|
|
92
|
-
return this.refreshing;
|
|
93
|
-
}
|
|
94
|
-
invalidate() {
|
|
95
|
-
this.generation += 1, this.cachedToken = void 0, this.cachedRequestKey = "", this.refreshing = void 0;
|
|
96
|
-
}
|
|
97
|
-
needsRefresh(e) {
|
|
98
|
-
return e.expiresAt !== void 0 && e.expiresAt <= Math.floor(Date.now() / 1e3) + u;
|
|
99
|
-
}
|
|
100
|
-
async refresh(e, t, n) {
|
|
101
|
-
let r = await this.tokenProvider(e), i = typeof r == "string" ? { accessToken: r } : r;
|
|
102
|
-
return n === this.generation && (this.cachedToken = i, this.cachedRequestKey = t), i.accessToken;
|
|
103
|
-
}
|
|
104
|
-
clearRefresh(e) {
|
|
105
|
-
this.refreshing === e && (this.refreshing = void 0);
|
|
106
|
-
}
|
|
107
|
-
}, f = {
|
|
108
|
-
ORIGIN_NOT_ALLOWED: {
|
|
109
|
-
code: "CONFIG_ORIGIN_NOT_ALLOWED",
|
|
110
|
-
category: "configuration",
|
|
111
|
-
retryable: !1
|
|
112
|
-
},
|
|
113
|
-
CAPABILITY_DENIED: {
|
|
114
|
-
code: "CAPABILITY_NOT_SUPPORTED",
|
|
115
|
-
category: "capability",
|
|
116
|
-
retryable: !1
|
|
117
|
-
},
|
|
118
|
-
TOKEN_INVALID: {
|
|
119
|
-
code: "AUTH_TOKEN_UNAVAILABLE",
|
|
120
|
-
category: "auth",
|
|
121
|
-
retryable: !1
|
|
122
|
-
},
|
|
123
|
-
TOKEN_EXPIRED: {
|
|
124
|
-
code: "AUTH_TOKEN_EXPIRED",
|
|
125
|
-
category: "auth",
|
|
126
|
-
retryable: !1
|
|
127
|
-
},
|
|
128
|
-
INVALID_ARGUMENT: {
|
|
129
|
-
code: "CONFIG_INVALID",
|
|
130
|
-
category: "configuration",
|
|
131
|
-
retryable: !1
|
|
132
|
-
},
|
|
133
|
-
INVALID_EXTENSION: {
|
|
134
|
-
code: "CONFIG_INVALID",
|
|
135
|
-
category: "configuration",
|
|
136
|
-
retryable: !1
|
|
137
|
-
},
|
|
138
|
-
SEAT_NOT_FOUND: {
|
|
139
|
-
code: "AUTH_PERMISSION_DENIED",
|
|
140
|
-
category: "auth",
|
|
141
|
-
retryable: !1
|
|
142
|
-
},
|
|
143
|
-
SESSION_NOT_FOUND: {
|
|
144
|
-
code: "CALL_NOT_CONNECTED",
|
|
145
|
-
category: "call",
|
|
146
|
-
retryable: !1
|
|
147
|
-
},
|
|
148
|
-
SESSION_EXPIRED: {
|
|
149
|
-
code: "CALL_NOT_CONNECTED",
|
|
150
|
-
category: "call",
|
|
151
|
-
retryable: !1
|
|
152
|
-
},
|
|
153
|
-
SEAT_IN_USE: {
|
|
154
|
-
code: "CALL_ALREADY_EXISTS",
|
|
155
|
-
category: "call",
|
|
156
|
-
retryable: !1
|
|
157
|
-
},
|
|
158
|
-
SESSION_CONFLICT: {
|
|
159
|
-
code: "CALL_ALREADY_EXISTS",
|
|
160
|
-
category: "call",
|
|
161
|
-
retryable: !1
|
|
162
|
-
},
|
|
163
|
-
SEAT_NOT_ASSIGNED: {
|
|
164
|
-
code: "AUTH_PERMISSION_DENIED",
|
|
165
|
-
category: "auth",
|
|
166
|
-
retryable: !1
|
|
167
|
-
},
|
|
168
|
-
QUEUE_NOT_ASSIGNED: {
|
|
169
|
-
code: "CAPABILITY_NOT_SUPPORTED",
|
|
170
|
-
category: "capability",
|
|
171
|
-
retryable: !1
|
|
172
|
-
},
|
|
173
|
-
RATE_LIMITED: {
|
|
174
|
-
code: "NETWORK_OFFLINE",
|
|
175
|
-
category: "network",
|
|
176
|
-
retryable: !0
|
|
177
|
-
},
|
|
178
|
-
SIP_GATEWAY_UNAVAILABLE: {
|
|
179
|
-
code: "SIP_WS_UNAVAILABLE",
|
|
180
|
-
category: "registration",
|
|
181
|
-
retryable: !0
|
|
182
|
-
},
|
|
183
|
-
SERVICE_UNAVAILABLE: {
|
|
184
|
-
code: "NETWORK_OFFLINE",
|
|
185
|
-
category: "network",
|
|
186
|
-
retryable: !0
|
|
187
|
-
},
|
|
188
|
-
INTERNAL_ERROR: {
|
|
189
|
-
code: "SDK_INTERNAL_ERROR",
|
|
190
|
-
category: "internal",
|
|
191
|
-
retryable: !0
|
|
192
|
-
}
|
|
193
|
-
}, p = class {
|
|
194
|
-
tokenManager;
|
|
195
|
-
fetcher;
|
|
196
|
-
baseUrl;
|
|
197
|
-
timeoutMs;
|
|
198
|
-
constructor(e) {
|
|
199
|
-
this.tokenManager = new d(e.tokenProvider), this.fetcher = e.fetcher ?? fetch.bind(globalThis), this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.timeoutMs = e.timeoutMs ?? 1e4;
|
|
200
|
-
}
|
|
201
|
-
invalidateToken() {
|
|
202
|
-
this.tokenManager.invalidate();
|
|
203
|
-
}
|
|
204
|
-
createSession(e) {
|
|
205
|
-
return this.request("POST", "/webphone/v1/sessions", e).then((e) => this.requireData(e));
|
|
206
|
-
}
|
|
207
|
-
refreshSession(e, t = { refresh: [
|
|
208
|
-
"sip_register_ticket",
|
|
209
|
-
"wss_ticket",
|
|
210
|
-
"turn_credentials"
|
|
211
|
-
] }) {
|
|
212
|
-
return this.request("POST", `/webphone/v1/sessions/${encodeURIComponent(e)}/refresh`, t).then((e) => this.requireData(e));
|
|
213
|
-
}
|
|
214
|
-
deleteSession(e) {
|
|
215
|
-
return this.request("DELETE", `/webphone/v1/sessions/${encodeURIComponent(e)}`).then(() => void 0);
|
|
216
|
-
}
|
|
217
|
-
setAgentStatus(e) {
|
|
218
|
-
return this.request("PUT", "/webphone/v1/agents/me/status", e).then(() => void 0);
|
|
219
|
-
}
|
|
220
|
-
getCapabilities() {
|
|
221
|
-
return this.request("GET", "/webphone/v1/capabilities").then((e) => this.requireData(e));
|
|
222
|
-
}
|
|
223
|
-
async request(t, n, r) {
|
|
224
|
-
let i = new AbortController(), a = setTimeout(() => i.abort(), this.timeoutMs);
|
|
225
|
-
try {
|
|
226
|
-
let e = await this.tokenManager.getValidToken(), a = await this.fetcher(`${this.baseUrl}${n}`, {
|
|
227
|
-
method: t,
|
|
228
|
-
credentials: "omit",
|
|
229
|
-
headers: {
|
|
230
|
-
Authorization: `Bearer ${e}`,
|
|
231
|
-
...r === void 0 ? {} : { "Content-Type": "application/json" }
|
|
232
|
-
},
|
|
233
|
-
...r === void 0 ? {} : { body: JSON.stringify(r) },
|
|
234
|
-
signal: i.signal
|
|
235
|
-
}), o = await this.parseResponse(a);
|
|
236
|
-
if (!a.ok || o.code !== "OK") throw this.toCCBarError(a.status, o);
|
|
237
|
-
return {
|
|
238
|
-
data: o.data,
|
|
239
|
-
requestId: o.requestId
|
|
240
|
-
};
|
|
241
|
-
} catch (t) {
|
|
242
|
-
throw t instanceof e ? t : t instanceof DOMException && t.name === "AbortError" ? new e("NETWORK_TIMEOUT", "network", !0, { cause: t }) : new e("NETWORK_OFFLINE", "network", !0, { cause: t });
|
|
243
|
-
} finally {
|
|
244
|
-
clearTimeout(a);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
requireData(t) {
|
|
248
|
-
if (t.data === void 0 || t.data === null) throw new e("SDK_INTERNAL_ERROR", "internal", !1, { requestId: t.requestId });
|
|
249
|
-
return t.data;
|
|
250
|
-
}
|
|
251
|
-
async parseResponse(t) {
|
|
252
|
-
try {
|
|
253
|
-
return await t.json();
|
|
254
|
-
} catch (n) {
|
|
255
|
-
throw new e("SDK_INTERNAL_ERROR", "internal", t.status >= 500, { cause: n });
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
toCCBarError(t, n) {
|
|
259
|
-
let r = f[n.code ?? ""] ?? this.mapStatus(t);
|
|
260
|
-
return new e(r.code, r.category, r.retryable, {
|
|
261
|
-
requestId: n.requestId,
|
|
262
|
-
serverCode: n.code,
|
|
263
|
-
status: t
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
mapStatus(e) {
|
|
267
|
-
return e === 401 ? {
|
|
268
|
-
code: "AUTH_TOKEN_EXPIRED",
|
|
269
|
-
category: "auth",
|
|
270
|
-
retryable: !1
|
|
271
|
-
} : e === 403 ? {
|
|
272
|
-
code: "AUTH_PERMISSION_DENIED",
|
|
273
|
-
category: "auth",
|
|
274
|
-
retryable: !1
|
|
275
|
-
} : e >= 500 ? {
|
|
276
|
-
code: "SDK_INTERNAL_ERROR",
|
|
277
|
-
category: "internal",
|
|
278
|
-
retryable: !0
|
|
279
|
-
} : {
|
|
280
|
-
code: "SDK_INTERNAL_ERROR",
|
|
281
|
-
category: "internal",
|
|
282
|
-
retryable: !1
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}, ee = [
|
|
76
|
+
}, l = s, u = [
|
|
286
77
|
"progress",
|
|
287
78
|
"accepted",
|
|
288
79
|
"confirmed",
|
|
@@ -291,7 +82,7 @@ var c = class extends e {
|
|
|
291
82
|
"hold",
|
|
292
83
|
"unhold",
|
|
293
84
|
"mediaConnected"
|
|
294
|
-
],
|
|
85
|
+
], d = 3e4, f = class {
|
|
295
86
|
options;
|
|
296
87
|
currentState = "new";
|
|
297
88
|
sessionUnsubscribers = [];
|
|
@@ -307,7 +98,7 @@ var c = class extends e {
|
|
|
307
98
|
constructor(t) {
|
|
308
99
|
this.options = t, this.id = t.id, this.destination = t.destination, this.platform = t.platform, this.capabilities = t.capabilities ?? /* @__PURE__ */ new Set();
|
|
309
100
|
try {
|
|
310
|
-
|
|
101
|
+
u.forEach((e) => {
|
|
311
102
|
this.sessionUnsubscribers.push(t.session.on(e, (t) => this.handleSessionEvent(e, t)));
|
|
312
103
|
});
|
|
313
104
|
} catch (n) {
|
|
@@ -368,13 +159,13 @@ var c = class extends e {
|
|
|
368
159
|
this.assertState("active"), this.assertCapability("dtmf"), this.invoke(() => this.options.session.sendDtmf(e));
|
|
369
160
|
}
|
|
370
161
|
async transfer(e, t) {
|
|
371
|
-
if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !
|
|
162
|
+
if (this.assertNotDisposed(), this.assertOwner(t), this.assertTransferCapability(), this.assertState("active"), this.assertCapability("blind_transfer"), !m(e) || e.target.trim() === "") throw this.operationError();
|
|
372
163
|
this.invoke(() => this.options.session.refer(e.target.trim()));
|
|
373
164
|
}
|
|
374
165
|
async hangup(e) {
|
|
375
|
-
if (this.assertNotDisposed(), this.assertOwner(e),
|
|
166
|
+
if (this.assertNotDisposed(), this.assertOwner(e), p(this.currentState)) throw this.operationError();
|
|
376
167
|
try {
|
|
377
|
-
this.options.session.terminate(),
|
|
168
|
+
this.options.session.terminate(), p(this.currentState) || this.transitionTo("ended");
|
|
378
169
|
} catch (e) {
|
|
379
170
|
throw this.operationError(e);
|
|
380
171
|
}
|
|
@@ -402,7 +193,7 @@ var c = class extends e {
|
|
|
402
193
|
}
|
|
403
194
|
dispose() {
|
|
404
195
|
if (!this.disposed) {
|
|
405
|
-
if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !
|
|
196
|
+
if (this.rejectPendingOperation(), this.incomingOperation = void 0, this.disposed = !0, !p(this.currentState)) try {
|
|
406
197
|
this.options.session.terminate();
|
|
407
198
|
} catch (e) {
|
|
408
199
|
this.reportOperationError(e);
|
|
@@ -414,7 +205,7 @@ var c = class extends e {
|
|
|
414
205
|
}
|
|
415
206
|
}
|
|
416
207
|
handleSessionEvent(e, t) {
|
|
417
|
-
if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed ||
|
|
208
|
+
if ((e === "accepted" || e === "confirmed" || e === "ended" || e === "failed") && (this.incomingOperation = void 0), !(this.disposed || p(this.currentState))) switch (e) {
|
|
418
209
|
case "progress":
|
|
419
210
|
this.transitionIfAllowed("ringing", t, e);
|
|
420
211
|
break;
|
|
@@ -452,7 +243,7 @@ var c = class extends e {
|
|
|
452
243
|
if (this.currentState === e) return;
|
|
453
244
|
if (!o(this.currentState, e)) throw this.operationError();
|
|
454
245
|
let n = this.currentState;
|
|
455
|
-
this.currentState = e,
|
|
246
|
+
this.currentState = e, p(e) && this.rejectPendingOperation();
|
|
456
247
|
try {
|
|
457
248
|
this.options.onStateChanged?.({
|
|
458
249
|
callId: this.id,
|
|
@@ -460,7 +251,7 @@ var c = class extends e {
|
|
|
460
251
|
to: e
|
|
461
252
|
}, t);
|
|
462
253
|
} catch {} finally {
|
|
463
|
-
|
|
254
|
+
p(e) && this.dispose();
|
|
464
255
|
}
|
|
465
256
|
}
|
|
466
257
|
startPendingOperation(e, t, n) {
|
|
@@ -472,7 +263,7 @@ var c = class extends e {
|
|
|
472
263
|
resolve: r,
|
|
473
264
|
reject: i
|
|
474
265
|
};
|
|
475
|
-
this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a),
|
|
266
|
+
this.pendingOperation = a, a.timer = setTimeout(() => this.timeoutPendingOperation(a), d);
|
|
476
267
|
let o;
|
|
477
268
|
try {
|
|
478
269
|
o = n();
|
|
@@ -485,7 +276,7 @@ var c = class extends e {
|
|
|
485
276
|
}
|
|
486
277
|
resolvePendingOperation(e) {
|
|
487
278
|
if (this.pendingOperation === e) {
|
|
488
|
-
if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed ||
|
|
279
|
+
if (this.clearPendingTimer(e), this.pendingOperation = void 0, this.disposed || p(this.currentState)) {
|
|
489
280
|
e.reject(this.operationError());
|
|
490
281
|
return;
|
|
491
282
|
}
|
|
@@ -585,32 +376,32 @@ var c = class extends e {
|
|
|
585
376
|
});
|
|
586
377
|
}
|
|
587
378
|
};
|
|
588
|
-
function
|
|
379
|
+
function p(e) {
|
|
589
380
|
return e === "ended" || e === "failed";
|
|
590
381
|
}
|
|
591
|
-
function
|
|
382
|
+
function m(e) {
|
|
592
383
|
return typeof e == "object" && !!e && e.type === "blind" && typeof e.target == "string";
|
|
593
384
|
}
|
|
594
385
|
//#endregion
|
|
595
386
|
//#region src/core/callId.ts
|
|
596
|
-
var
|
|
597
|
-
function
|
|
598
|
-
return
|
|
387
|
+
var h = 0;
|
|
388
|
+
function g() {
|
|
389
|
+
return h += 1, `call_${Date.now().toString(36)}_${h.toString(36)}`;
|
|
599
390
|
}
|
|
600
391
|
//#endregion
|
|
601
392
|
//#region src/core/userData.ts
|
|
602
|
-
var
|
|
603
|
-
function
|
|
393
|
+
var ee = "X-User-Data", te = /[^\x20-\x7E]/, ne = "userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来";
|
|
394
|
+
function _(t) {
|
|
604
395
|
if (typeof t != "string") return [];
|
|
605
396
|
let n = t.trim();
|
|
606
397
|
if (n === "") return [];
|
|
607
|
-
if (
|
|
608
|
-
return [`${
|
|
398
|
+
if (te.test(n)) throw new e("CALL_INVALID_USERDATA", "call", !1, { cause: ne });
|
|
399
|
+
return [`${ee}: ${n}`];
|
|
609
400
|
}
|
|
610
401
|
//#endregion
|
|
611
402
|
//#region src/core/CallManager.ts
|
|
612
|
-
var
|
|
613
|
-
events = new
|
|
403
|
+
var v = class {
|
|
404
|
+
events = new y();
|
|
614
405
|
calls = /* @__PURE__ */ new Map();
|
|
615
406
|
options;
|
|
616
407
|
incomingUnsubscribe;
|
|
@@ -643,13 +434,13 @@ var x = class {
|
|
|
643
434
|
this.assertNotDisposed();
|
|
644
435
|
let r = this.operationGeneration, i = t.destination.trim();
|
|
645
436
|
if (i === "") throw new e("CALL_INVALID_DESTINATION", "call", !1);
|
|
646
|
-
let a =
|
|
437
|
+
let a = _(t.userdata);
|
|
647
438
|
this.requireCapability(n, "outbound");
|
|
648
439
|
let o = this.callLimit(n);
|
|
649
440
|
if (this.options.platform === "mobile-web" && this.calls.size + this.pendingDialCount >= o) throw this.capabilityError();
|
|
650
441
|
if (this.calls.size + this.pendingDialCount >= o || this.pendingDestinations.has(i) || [...this.calls.values()].some((e) => e.destination === i)) throw new e("CALL_ALREADY_EXISTS", "call", !1);
|
|
651
442
|
this.pendingDialCount += 1, this.pendingDestinations.add(i);
|
|
652
|
-
let s =
|
|
443
|
+
let s = g(), c;
|
|
653
444
|
try {
|
|
654
445
|
c = await this.holdActiveCallForNewCall(), this.assertGeneration(r, s);
|
|
655
446
|
let e;
|
|
@@ -661,7 +452,7 @@ var x = class {
|
|
|
661
452
|
this.assertGeneration(r, s);
|
|
662
453
|
let o;
|
|
663
454
|
try {
|
|
664
|
-
o = new
|
|
455
|
+
o = new f({
|
|
665
456
|
id: s,
|
|
666
457
|
destination: i,
|
|
667
458
|
platform: this.options.platform,
|
|
@@ -843,10 +634,10 @@ var x = class {
|
|
|
843
634
|
}
|
|
844
635
|
t.to === "held" && this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), (t.to === "ended" || t.to === "failed") && (this.calls.delete(e.id), this.callSessions.delete(e.id), this.callOwners.delete(e.id), this.ownerLostCalls.delete(e.id), this.activeCallId === e.id && this.automaticActiveTransition?.previous.id !== e.id && (this.activeCallId = null, this.events.emit("call.activeChanged", { callId: null })), this.notifyCallTerminal(e.id), t.to === "ended" ? this.events.emit("call.ended", {
|
|
845
636
|
callId: e.id,
|
|
846
|
-
reason:
|
|
637
|
+
reason: b(n)
|
|
847
638
|
}) : this.events.emit("call.failed", {
|
|
848
639
|
callId: e.id,
|
|
849
|
-
error:
|
|
640
|
+
error: re(n, e.id)
|
|
850
641
|
}));
|
|
851
642
|
}
|
|
852
643
|
async switchAutomaticActiveCall(e, t, n) {
|
|
@@ -912,7 +703,7 @@ var x = class {
|
|
|
912
703
|
}
|
|
913
704
|
handleIncoming(t) {
|
|
914
705
|
if (this.disposed) return;
|
|
915
|
-
let n =
|
|
706
|
+
let n = g(), r = this.incomingSessionSnapshot;
|
|
916
707
|
if (r === void 0 || !r.policy.incomingEnabled || !this.effectiveCapabilities(r).has("inbound")) {
|
|
917
708
|
this.terminateUnsupportedIncoming(t), this.events.emit("error", { error: this.capabilityError(n) });
|
|
918
709
|
return;
|
|
@@ -924,7 +715,7 @@ var x = class {
|
|
|
924
715
|
}
|
|
925
716
|
let a;
|
|
926
717
|
try {
|
|
927
|
-
a = new
|
|
718
|
+
a = new f({
|
|
928
719
|
id: n,
|
|
929
720
|
destination: i,
|
|
930
721
|
platform: this.options.platform,
|
|
@@ -1053,7 +844,7 @@ var x = class {
|
|
|
1053
844
|
cause: t
|
|
1054
845
|
});
|
|
1055
846
|
}
|
|
1056
|
-
},
|
|
847
|
+
}, y = class {
|
|
1057
848
|
handlers = /* @__PURE__ */ new Map();
|
|
1058
849
|
on(e, t) {
|
|
1059
850
|
let n = this.handlers.get(e) ?? /* @__PURE__ */ new Set(), r = t;
|
|
@@ -1078,12 +869,12 @@ var x = class {
|
|
|
1078
869
|
this.handlers.clear();
|
|
1079
870
|
}
|
|
1080
871
|
};
|
|
1081
|
-
function
|
|
872
|
+
function b(e) {
|
|
1082
873
|
if (typeof e != "object" || !e || !("reason" in e)) return "ended";
|
|
1083
874
|
let t = e.reason;
|
|
1084
875
|
return typeof t == "string" && t !== "" ? t : "ended";
|
|
1085
876
|
}
|
|
1086
|
-
function
|
|
877
|
+
function re(t, n) {
|
|
1087
878
|
if (t instanceof e) return new e(t.code, t.category, t.retryable, {
|
|
1088
879
|
requestId: t.requestId,
|
|
1089
880
|
callId: n,
|
|
@@ -1107,8 +898,65 @@ function oe(t, n) {
|
|
|
1107
898
|
});
|
|
1108
899
|
}
|
|
1109
900
|
//#endregion
|
|
901
|
+
//#region src/crypto/legacySipTicket.ts
|
|
902
|
+
var ie = "q7X4p6MvK1z8Lb3A", ae = "W9e2T4mN0aQ7Ru6C", oe = 16, se = "�";
|
|
903
|
+
function ce(e) {
|
|
904
|
+
for (let t of e) {
|
|
905
|
+
let e = t.codePointAt(0) ?? 0;
|
|
906
|
+
if (e === 127 || e < 32 && e !== 9) return !0;
|
|
907
|
+
}
|
|
908
|
+
return !1;
|
|
909
|
+
}
|
|
910
|
+
async function x(t, n = {}) {
|
|
911
|
+
let r = String(t ?? "").replace(/\s+/g, "");
|
|
912
|
+
if (!r) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "解密的密文为空:坐席账号里没有 password/registerPassword" });
|
|
913
|
+
let i = n.subtle ?? globalThis.crypto?.subtle;
|
|
914
|
+
if (i === void 0) throw new e("CONFIG_INVALID", "configuration", !1, { cause: "需要 WebCrypto 才能解 SIP 密码:请在安全上下文(https / localhost)或 Node 18+ 里运行" });
|
|
915
|
+
let a = S(r);
|
|
916
|
+
if (a === void 0) throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: "密文不是合法的 Base64:确认取的是 password/registerPassword 原值,没有被截断或转义" });
|
|
917
|
+
let o = await i.importKey("raw", C(n.key ?? ie), "AES-CBC", !1, ["decrypt"]);
|
|
918
|
+
try {
|
|
919
|
+
let e = await i.decrypt({
|
|
920
|
+
name: "AES-CBC",
|
|
921
|
+
iv: C(n.iv ?? ae)
|
|
922
|
+
}, o, a);
|
|
923
|
+
return new TextDecoder("utf-8").decode(e).trim();
|
|
924
|
+
} catch (t) {
|
|
925
|
+
throw new e("LEGACY_PLATFORM_REJECTED", "auth", !1, { cause: `SIP 密码解密失败(检查 key/iv 与该环境是否一致):${t instanceof Error ? t.message : String(t)}` });
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
async function le(e, t = {}) {
|
|
929
|
+
let n = String(e ?? "").replace(/\s+/g, "");
|
|
930
|
+
if (ue(n)) try {
|
|
931
|
+
let e = await x(n, t);
|
|
932
|
+
return de(e) ? e : void 0;
|
|
933
|
+
} catch {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function ue(e) {
|
|
938
|
+
let t = S(e);
|
|
939
|
+
return t !== void 0 && t.byteLength > 0 && t.byteLength % oe === 0;
|
|
940
|
+
}
|
|
941
|
+
function de(e) {
|
|
942
|
+
return e.length === 0 || e.includes(se) ? !1 : !ce(e);
|
|
943
|
+
}
|
|
944
|
+
function S(e) {
|
|
945
|
+
if (e.length !== 0 && e.length % 4 == 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(e)) try {
|
|
946
|
+
let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length));
|
|
947
|
+
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
948
|
+
return n;
|
|
949
|
+
} catch {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
function C(e) {
|
|
954
|
+
let t = new TextEncoder().encode(e), n = new Uint8Array(new ArrayBuffer(t.byteLength));
|
|
955
|
+
return n.set(t), n;
|
|
956
|
+
}
|
|
957
|
+
//#endregion
|
|
1110
958
|
//#region src/shared/SharedWorkerClient.ts
|
|
1111
|
-
var
|
|
959
|
+
var fe = class {
|
|
1112
960
|
port;
|
|
1113
961
|
timeoutMs;
|
|
1114
962
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -1145,13 +993,13 @@ var se = class {
|
|
|
1145
993
|
try {
|
|
1146
994
|
let n = t(e);
|
|
1147
995
|
if (n.type === "event") {
|
|
1148
|
-
n.event === "connection.stateChanged" &&
|
|
996
|
+
n.event === "connection.stateChanged" && pe(n.payload) && (this.lifecycleState = n.payload.state), this.eventHandlers.forEach((e) => e(n));
|
|
1149
997
|
return;
|
|
1150
998
|
}
|
|
1151
999
|
if (n.type !== "response") return;
|
|
1152
1000
|
let r = this.pending.get(n.requestId);
|
|
1153
1001
|
if (r === void 0) return;
|
|
1154
|
-
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(me(n));
|
|
1155
1003
|
} catch (e) {
|
|
1156
1004
|
this.pending.forEach((t) => {
|
|
1157
1005
|
clearTimeout(t.timer), t.reject(e);
|
|
@@ -1159,10 +1007,10 @@ var se = class {
|
|
|
1159
1007
|
}
|
|
1160
1008
|
}
|
|
1161
1009
|
};
|
|
1162
|
-
function
|
|
1010
|
+
function pe(e) {
|
|
1163
1011
|
return typeof e == "object" && !!e && "state" in e && (e.state === "connected" || e.state === "reconnecting");
|
|
1164
1012
|
}
|
|
1165
|
-
function
|
|
1013
|
+
function me(t) {
|
|
1166
1014
|
let n = t.error;
|
|
1167
1015
|
return new e(n?.code ?? "SDK_INTERNAL_ERROR", n?.category ?? "internal", n?.retryable ?? !1, {
|
|
1168
1016
|
requestId: t.requestId,
|
|
@@ -1173,12 +1021,12 @@ function le(t) {
|
|
|
1173
1021
|
}
|
|
1174
1022
|
//#endregion
|
|
1175
1023
|
//#region src/shared/SharedWorkerFactory.ts
|
|
1176
|
-
function
|
|
1024
|
+
function w(t = {}) {
|
|
1177
1025
|
if ((t.enabled ?? "auto") === !1) return {
|
|
1178
1026
|
mode: "single-tab",
|
|
1179
1027
|
reason: "disabled"
|
|
1180
1028
|
};
|
|
1181
|
-
let n = t.locationHref ??
|
|
1029
|
+
let n = t.locationHref ?? E(), r = T(t.url, n), i = (n) => {
|
|
1182
1030
|
if (t.fallback === "error") throw new e("CONFIG_INVALID", "configuration", !1, { cause: n });
|
|
1183
1031
|
return {
|
|
1184
1032
|
mode: "single-tab",
|
|
@@ -1186,8 +1034,8 @@ function S(t = {}) {
|
|
|
1186
1034
|
};
|
|
1187
1035
|
};
|
|
1188
1036
|
if (r === void 0) return i("SharedWorker URL is unavailable");
|
|
1189
|
-
if (!
|
|
1190
|
-
let a = t.workerCtor ??
|
|
1037
|
+
if (!O(r, n)) return i("SharedWorker URL must be same-origin");
|
|
1038
|
+
let a = t.workerCtor ?? D();
|
|
1191
1039
|
if (a === void 0) return i("SharedWorker is not supported");
|
|
1192
1040
|
let o;
|
|
1193
1041
|
try {
|
|
@@ -1195,10 +1043,10 @@ function S(t = {}) {
|
|
|
1195
1043
|
} catch (e) {
|
|
1196
1044
|
return i(`SharedWorker construction failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
1197
1045
|
}
|
|
1198
|
-
let s = t.tabId ??
|
|
1046
|
+
let s = t.tabId ?? k(), c = new fe(o.port), l = {
|
|
1199
1047
|
version: 1,
|
|
1200
1048
|
type: "attach",
|
|
1201
|
-
requestId:
|
|
1049
|
+
requestId: A(),
|
|
1202
1050
|
tabId: s
|
|
1203
1051
|
}, u = c.request(l).then(() => void 0).catch((e) => {
|
|
1204
1052
|
throw c.close(), e;
|
|
@@ -1212,20 +1060,20 @@ function S(t = {}) {
|
|
|
1212
1060
|
ready: u
|
|
1213
1061
|
};
|
|
1214
1062
|
}
|
|
1215
|
-
function
|
|
1063
|
+
function T(e, t = E()) {
|
|
1216
1064
|
try {
|
|
1217
1065
|
return t === void 0 ? void 0 : new URL(e ?? "./shared-worker.js", t).toString();
|
|
1218
1066
|
} catch {
|
|
1219
1067
|
return;
|
|
1220
1068
|
}
|
|
1221
1069
|
}
|
|
1222
|
-
function
|
|
1070
|
+
function E() {
|
|
1223
1071
|
return typeof location > "u" ? void 0 : location.href;
|
|
1224
1072
|
}
|
|
1225
|
-
function
|
|
1073
|
+
function D() {
|
|
1226
1074
|
if (typeof SharedWorker == "function") return SharedWorker;
|
|
1227
1075
|
}
|
|
1228
|
-
function
|
|
1076
|
+
function O(e, t) {
|
|
1229
1077
|
if (t === void 0) return !0;
|
|
1230
1078
|
try {
|
|
1231
1079
|
return new URL(e, t).origin === new URL(t).origin;
|
|
@@ -1233,15 +1081,15 @@ function de(e, t) {
|
|
|
1233
1081
|
return !1;
|
|
1234
1082
|
}
|
|
1235
1083
|
}
|
|
1236
|
-
function
|
|
1084
|
+
function k() {
|
|
1237
1085
|
return `tab-${typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`;
|
|
1238
1086
|
}
|
|
1239
|
-
function
|
|
1087
|
+
function A() {
|
|
1240
1088
|
return `attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1241
1089
|
}
|
|
1242
1090
|
//#endregion
|
|
1243
1091
|
//#region src/media/DeviceManager.ts
|
|
1244
|
-
var
|
|
1092
|
+
var j = class {
|
|
1245
1093
|
mediaDevices;
|
|
1246
1094
|
createAudioElement;
|
|
1247
1095
|
outputCapability;
|
|
@@ -1249,23 +1097,23 @@ var D = class {
|
|
|
1249
1097
|
outputGeneration = 0;
|
|
1250
1098
|
outputTail;
|
|
1251
1099
|
constructor(e = {}) {
|
|
1252
|
-
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ??
|
|
1100
|
+
this.mediaDevices = e.mediaDevices === null ? void 0 : e.mediaDevices ?? M(), this.createAudioElement = e.createAudioElement;
|
|
1253
1101
|
}
|
|
1254
1102
|
async requestPermission(e = {}) {
|
|
1255
1103
|
let t = this.requireMediaDevices(), n;
|
|
1256
1104
|
try {
|
|
1257
1105
|
n = await t.getUserMedia({ audio: e });
|
|
1258
1106
|
} catch (e) {
|
|
1259
|
-
throw
|
|
1107
|
+
throw F(e);
|
|
1260
1108
|
}
|
|
1261
|
-
|
|
1109
|
+
N(n);
|
|
1262
1110
|
}
|
|
1263
1111
|
async getDevices() {
|
|
1264
1112
|
if (this.mediaDevices === void 0) return [];
|
|
1265
1113
|
try {
|
|
1266
1114
|
return (await this.mediaDevices.enumerateDevices()).filter((e) => e.kind === "audioinput" || e.kind === "audiooutput" && this.supportsOutputSelection());
|
|
1267
1115
|
} catch (e) {
|
|
1268
|
-
throw
|
|
1116
|
+
throw I(e);
|
|
1269
1117
|
}
|
|
1270
1118
|
}
|
|
1271
1119
|
getCapabilities() {
|
|
@@ -1303,7 +1151,7 @@ var D = class {
|
|
|
1303
1151
|
try {
|
|
1304
1152
|
await r.setSinkId(t);
|
|
1305
1153
|
} catch (e) {
|
|
1306
|
-
throw
|
|
1154
|
+
throw L(e);
|
|
1307
1155
|
}
|
|
1308
1156
|
}
|
|
1309
1157
|
enqueueOutput(e) {
|
|
@@ -1317,7 +1165,7 @@ var D = class {
|
|
|
1317
1165
|
try {
|
|
1318
1166
|
return await t.getUserMedia({ audio: { deviceId: { exact: e } } });
|
|
1319
1167
|
} catch (e) {
|
|
1320
|
-
throw
|
|
1168
|
+
throw P(e);
|
|
1321
1169
|
}
|
|
1322
1170
|
}
|
|
1323
1171
|
requireMediaDevices() {
|
|
@@ -1337,10 +1185,10 @@ var D = class {
|
|
|
1337
1185
|
}
|
|
1338
1186
|
}
|
|
1339
1187
|
};
|
|
1340
|
-
function
|
|
1188
|
+
function M() {
|
|
1341
1189
|
return globalThis.navigator?.mediaDevices;
|
|
1342
1190
|
}
|
|
1343
|
-
function
|
|
1191
|
+
function N(e) {
|
|
1344
1192
|
let t;
|
|
1345
1193
|
try {
|
|
1346
1194
|
t = e.getTracks();
|
|
@@ -1353,57 +1201,57 @@ function k(e) {
|
|
|
1353
1201
|
} catch {}
|
|
1354
1202
|
});
|
|
1355
1203
|
}
|
|
1356
|
-
function
|
|
1357
|
-
let n =
|
|
1204
|
+
function P(t) {
|
|
1205
|
+
let n = R(t);
|
|
1358
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 });
|
|
1359
1207
|
}
|
|
1360
|
-
function
|
|
1361
|
-
let n =
|
|
1208
|
+
function F(t) {
|
|
1209
|
+
let n = R(t);
|
|
1362
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 });
|
|
1363
1211
|
}
|
|
1364
|
-
function
|
|
1365
|
-
let n =
|
|
1212
|
+
function I(t) {
|
|
1213
|
+
let n = R(t);
|
|
1366
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 });
|
|
1367
1215
|
}
|
|
1368
|
-
function
|
|
1369
|
-
let n =
|
|
1216
|
+
function L(t) {
|
|
1217
|
+
let n = R(t);
|
|
1370
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 });
|
|
1371
1219
|
}
|
|
1372
|
-
function
|
|
1220
|
+
function R(e) {
|
|
1373
1221
|
if (typeof e != "object" || !e || !("name" in e)) return;
|
|
1374
1222
|
let t = e.name;
|
|
1375
1223
|
return typeof t == "string" ? t : void 0;
|
|
1376
1224
|
}
|
|
1377
1225
|
//#endregion
|
|
1378
1226
|
//#region src/media/RemoteAudio.ts
|
|
1379
|
-
var
|
|
1227
|
+
var z = class {
|
|
1380
1228
|
createAudioElement;
|
|
1381
1229
|
bindings = /* @__PURE__ */ new Map();
|
|
1382
1230
|
audioOwners = /* @__PURE__ */ new Map();
|
|
1383
1231
|
trackOwners = /* @__PURE__ */ new Map();
|
|
1384
1232
|
generations = /* @__PURE__ */ new Map();
|
|
1385
1233
|
pendingPlays = /* @__PURE__ */ new Map();
|
|
1386
|
-
constructor(e =
|
|
1234
|
+
constructor(e = he) {
|
|
1387
1235
|
this.createAudioElement = e;
|
|
1388
1236
|
}
|
|
1389
1237
|
async bind(t, n) {
|
|
1390
1238
|
let r = this.bindings.get(t);
|
|
1391
1239
|
if (r?.stream === n) return;
|
|
1392
|
-
let i =
|
|
1240
|
+
let i = ge(t, n), a;
|
|
1393
1241
|
try {
|
|
1394
1242
|
a = this.createAudioElement();
|
|
1395
1243
|
} catch (n) {
|
|
1396
|
-
throw
|
|
1244
|
+
throw B(i, this.trackOwners), new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, {
|
|
1397
1245
|
callId: t,
|
|
1398
1246
|
cause: n
|
|
1399
1247
|
});
|
|
1400
1248
|
}
|
|
1401
1249
|
let o = this.audioOwners.get(a);
|
|
1402
|
-
if (o !== void 0 && o !== t) throw
|
|
1250
|
+
if (o !== void 0 && o !== t) throw B(i, this.trackOwners), new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { callId: t });
|
|
1403
1251
|
try {
|
|
1404
1252
|
a.autoplay = !0, a.playsInline = !0;
|
|
1405
1253
|
} catch (n) {
|
|
1406
|
-
throw
|
|
1254
|
+
throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1407
1255
|
callId: t,
|
|
1408
1256
|
cause: n
|
|
1409
1257
|
});
|
|
@@ -1411,7 +1259,7 @@ var F = class {
|
|
|
1411
1259
|
try {
|
|
1412
1260
|
a.srcObject = n;
|
|
1413
1261
|
} catch (n) {
|
|
1414
|
-
throw
|
|
1262
|
+
throw B(i, this.trackOwners), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1415
1263
|
callId: t,
|
|
1416
1264
|
cause: n
|
|
1417
1265
|
});
|
|
@@ -1487,7 +1335,7 @@ var F = class {
|
|
|
1487
1335
|
releaseTrack(e) {
|
|
1488
1336
|
let t = this.trackOwners.get(e);
|
|
1489
1337
|
if (t === void 0 || t <= 1) {
|
|
1490
|
-
this.trackOwners.delete(e),
|
|
1338
|
+
this.trackOwners.delete(e), V(e);
|
|
1491
1339
|
return;
|
|
1492
1340
|
}
|
|
1493
1341
|
this.trackOwners.set(e, t - 1);
|
|
@@ -1510,42 +1358,42 @@ var F = class {
|
|
|
1510
1358
|
return this.generations.get(e) === t && this.bindings.get(e)?.generation === t;
|
|
1511
1359
|
}
|
|
1512
1360
|
};
|
|
1513
|
-
function
|
|
1361
|
+
function he() {
|
|
1514
1362
|
if (typeof document > "u") throw new e("CAPABILITY_NOT_SUPPORTED", "capability", !1);
|
|
1515
1363
|
return document.createElement("audio");
|
|
1516
1364
|
}
|
|
1517
|
-
function
|
|
1365
|
+
function ge(t, n) {
|
|
1518
1366
|
try {
|
|
1519
1367
|
return [...new Set(n.getAudioTracks())].filter((e) => e.kind === "audio");
|
|
1520
1368
|
} catch (r) {
|
|
1521
1369
|
try {
|
|
1522
1370
|
return [...new Set(n.getTracks())].filter((e) => e.kind === "audio");
|
|
1523
1371
|
} catch (i) {
|
|
1524
|
-
throw
|
|
1372
|
+
throw _e(n), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1525
1373
|
callId: t,
|
|
1526
1374
|
cause: r ?? i
|
|
1527
1375
|
});
|
|
1528
1376
|
}
|
|
1529
1377
|
}
|
|
1530
1378
|
}
|
|
1531
|
-
function
|
|
1379
|
+
function B(e, t) {
|
|
1532
1380
|
e.forEach((e) => {
|
|
1533
|
-
(t.get(e) ?? 0) === 0 &&
|
|
1381
|
+
(t.get(e) ?? 0) === 0 && V(e);
|
|
1534
1382
|
});
|
|
1535
1383
|
}
|
|
1536
|
-
function
|
|
1384
|
+
function _e(e) {
|
|
1537
1385
|
try {
|
|
1538
|
-
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(
|
|
1386
|
+
[...new Set(e.getTracks())].filter((e) => e.kind === "audio").forEach(V);
|
|
1539
1387
|
} catch {}
|
|
1540
1388
|
}
|
|
1541
|
-
function
|
|
1389
|
+
function V(e) {
|
|
1542
1390
|
try {
|
|
1543
1391
|
e.stop();
|
|
1544
1392
|
} catch {}
|
|
1545
1393
|
}
|
|
1546
1394
|
//#endregion
|
|
1547
1395
|
//#region src/media/MediaManager.ts
|
|
1548
|
-
var
|
|
1396
|
+
var ve = class {
|
|
1549
1397
|
deviceManager;
|
|
1550
1398
|
remoteAudio;
|
|
1551
1399
|
getActiveCall;
|
|
@@ -1566,7 +1414,7 @@ var V = class {
|
|
|
1566
1414
|
mediaDevices: e.mediaDevices,
|
|
1567
1415
|
createAudioElement: e.createAudioElement
|
|
1568
1416
|
};
|
|
1569
|
-
this.deviceManager = new
|
|
1417
|
+
this.deviceManager = new j(t), this.remoteAudio = new z(e.createAudioElement), this.getActiveCall = e.getActiveCall, this.createRemoteStream = e.createRemoteStream ?? xe;
|
|
1570
1418
|
}
|
|
1571
1419
|
requestPermission(e) {
|
|
1572
1420
|
return this.assertNotDisposed(), this.deviceManager.requestPermission(e);
|
|
@@ -1586,7 +1434,7 @@ var V = class {
|
|
|
1586
1434
|
n !== void 0 && this.releaseResource(n).catch((e) => {
|
|
1587
1435
|
this.releaseErrors.set(n, e);
|
|
1588
1436
|
});
|
|
1589
|
-
let r =
|
|
1437
|
+
let r = ye(t) ? t : { peerConnection: t }, i = {
|
|
1590
1438
|
callId: e,
|
|
1591
1439
|
peerConnection: r.peerConnection,
|
|
1592
1440
|
senders: /* @__PURE__ */ new Map(),
|
|
@@ -1668,7 +1516,7 @@ var V = class {
|
|
|
1668
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);
|
|
1669
1517
|
let i = /* @__PURE__ */ new Set([...t.localTracks, ...t.pendingTracks]), a = [...t.senders.values()].filter((e) => e.audio).map((e) => ({
|
|
1670
1518
|
senderResource: e,
|
|
1671
|
-
promise: this.enqueueSender(t, e, () =>
|
|
1519
|
+
promise: this.enqueueSender(t, e, () => W(e.sender), !0)
|
|
1672
1520
|
})), o = Promise.all(a.map(async (e) => {
|
|
1673
1521
|
try {
|
|
1674
1522
|
return await e.promise, {
|
|
@@ -1686,14 +1534,14 @@ var V = class {
|
|
|
1686
1534
|
if (n.forEach((e) => {
|
|
1687
1535
|
if (e.cause !== void 0) {
|
|
1688
1536
|
o.push(e.cause);
|
|
1689
|
-
let t =
|
|
1537
|
+
let t = H(e.senderResource.sender);
|
|
1690
1538
|
t?.kind === "audio" && a.add(t);
|
|
1691
1539
|
return;
|
|
1692
1540
|
}
|
|
1693
|
-
let t =
|
|
1541
|
+
let t = H(e.senderResource.sender);
|
|
1694
1542
|
t?.kind === "audio" && i.add(t);
|
|
1695
1543
|
}), i.forEach((e) => {
|
|
1696
|
-
a.has(e) ||
|
|
1544
|
+
a.has(e) || K(e);
|
|
1697
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, {
|
|
1698
1546
|
callId: r,
|
|
1699
1547
|
cause: o[0]
|
|
@@ -1701,7 +1549,7 @@ var V = class {
|
|
|
1701
1549
|
if (!t.peerClosed && t.peerConnection.close !== void 0) try {
|
|
1702
1550
|
await t.peerConnection.close(), t.peerClosed = !0;
|
|
1703
1551
|
} catch (n) {
|
|
1704
|
-
let i = [...t.senders.values()].map((e) =>
|
|
1552
|
+
let i = [...t.senders.values()].map((e) => H(e.sender)).find((e) => e?.kind === "audio");
|
|
1705
1553
|
throw t.localTracks.clear(), t.pendingTracks.clear(), i != null && t.localTracks.add(i), new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1706
1554
|
callId: r,
|
|
1707
1555
|
cause: n
|
|
@@ -1769,11 +1617,11 @@ var V = class {
|
|
|
1769
1617
|
}
|
|
1770
1618
|
async performInputSwitch(t, n, r) {
|
|
1771
1619
|
if (this.assertActiveCall(n), this.assertDeviceSelectionCapability(n), !this.isCurrentResource(r) || n.peerConnection !== r.peerConnection) throw this.callOperationError(n.callId);
|
|
1772
|
-
let i = this.findAudioSender(r), a =
|
|
1620
|
+
let i = this.findAudioSender(r), a = H(i.sender), o = r.generation, s = await this.deviceManager.openInputStream(t), c;
|
|
1773
1621
|
try {
|
|
1774
1622
|
c = s.getTracks();
|
|
1775
1623
|
} catch (t) {
|
|
1776
|
-
throw
|
|
1624
|
+
throw be(s), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1777
1625
|
callId: n.callId,
|
|
1778
1626
|
cause: t
|
|
1779
1627
|
});
|
|
@@ -1782,26 +1630,26 @@ var V = class {
|
|
|
1782
1630
|
try {
|
|
1783
1631
|
l = s.getAudioTracks();
|
|
1784
1632
|
} catch (t) {
|
|
1785
|
-
throw
|
|
1633
|
+
throw G(c), new e("SDK_INTERNAL_ERROR", "internal", !1, {
|
|
1786
1634
|
callId: n.callId,
|
|
1787
1635
|
cause: t
|
|
1788
1636
|
});
|
|
1789
1637
|
}
|
|
1790
1638
|
let u = l[0];
|
|
1791
|
-
if (u === void 0) throw
|
|
1792
|
-
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw
|
|
1639
|
+
if (u === void 0) throw G(c), new e("MEDIA_DEVICE_NOT_FOUND", "media", !1, { callId: n.callId });
|
|
1640
|
+
if (!this.canCommitInputSwitch(n, r, i, a, o)) throw G(c), this.callOperationError(n.callId);
|
|
1793
1641
|
c.forEach((e) => r.pendingTracks.add(e)), r.pendingTracks.add(u);
|
|
1794
1642
|
try {
|
|
1795
1643
|
await this.enqueueSender(r, i, () => i.sender.replaceTrack(u));
|
|
1796
1644
|
} catch (t) {
|
|
1797
|
-
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), G(c)), new e("MEDIA_DEVICE_IN_USE", "media", !0, {
|
|
1798
1646
|
callId: n.callId,
|
|
1799
1647
|
cause: t
|
|
1800
1648
|
}));
|
|
1801
1649
|
}
|
|
1802
1650
|
if (!this.canCommitInputSwitch(n, r, i, u, o)) {
|
|
1803
1651
|
if (!r.released) try {
|
|
1804
|
-
await this.enqueueSender(r, i, () =>
|
|
1652
|
+
await this.enqueueSender(r, i, () => H(i.sender) === u ? W(i.sender) : Promise.resolve()), c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), G(c);
|
|
1805
1653
|
} catch (t) {
|
|
1806
1654
|
throw new e("SDK_INTERNAL_ERROR", "internal", !0, {
|
|
1807
1655
|
callId: n.callId,
|
|
@@ -1810,8 +1658,8 @@ var V = class {
|
|
|
1810
1658
|
}
|
|
1811
1659
|
throw this.callOperationError(n.callId);
|
|
1812
1660
|
}
|
|
1813
|
-
c.forEach((e) => r.pendingTracks.delete(e)), r.pendingTracks.delete(u), r.localTracks.add(u), a !== null && a !== u && (r.localTracks.delete(a),
|
|
1814
|
-
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), K(a)), c.forEach((e) => {
|
|
1662
|
+
e !== u && K(e);
|
|
1815
1663
|
});
|
|
1816
1664
|
}
|
|
1817
1665
|
ensureCallMedia(e) {
|
|
@@ -1834,7 +1682,7 @@ var V = class {
|
|
|
1834
1682
|
});
|
|
1835
1683
|
}
|
|
1836
1684
|
r.forEach((r) => {
|
|
1837
|
-
let i =
|
|
1685
|
+
let i = H(r), a;
|
|
1838
1686
|
try {
|
|
1839
1687
|
a = n?.(r) ?? r.senderKind ?? r.kind;
|
|
1840
1688
|
} catch (n) {
|
|
@@ -1851,7 +1699,7 @@ var V = class {
|
|
|
1851
1699
|
});
|
|
1852
1700
|
}
|
|
1853
1701
|
findAudioSender(e) {
|
|
1854
|
-
let t = [...e.senders.values()].find((e) => e.audio && (
|
|
1702
|
+
let t = [...e.senders.values()].find((e) => e.audio && (H(e.sender)?.kind === "audio" || H(e.sender) === null));
|
|
1855
1703
|
if (t === void 0) throw this.capabilityError(e.callId);
|
|
1856
1704
|
return t;
|
|
1857
1705
|
}
|
|
@@ -1867,7 +1715,7 @@ var V = class {
|
|
|
1867
1715
|
} catch {
|
|
1868
1716
|
return !1;
|
|
1869
1717
|
}
|
|
1870
|
-
return
|
|
1718
|
+
return H(n.sender) === r;
|
|
1871
1719
|
}
|
|
1872
1720
|
enqueueSender(e, t, n, r = !1) {
|
|
1873
1721
|
t.queue.pending += 1;
|
|
@@ -1896,7 +1744,7 @@ var V = class {
|
|
|
1896
1744
|
});
|
|
1897
1745
|
}
|
|
1898
1746
|
async rollbackSender(e, t, n, r) {
|
|
1899
|
-
e.released ||
|
|
1747
|
+
e.released || H(t.sender) !== r || await this.enqueueSender(e, t, () => t.sender.replaceTrack(n)).catch(() => void 0);
|
|
1900
1748
|
}
|
|
1901
1749
|
isCurrentResource(e, t = e.generation) {
|
|
1902
1750
|
return !this.disposed && this.calls.get(e.callId) === e && e.generation === t;
|
|
@@ -1923,42 +1771,42 @@ var V = class {
|
|
|
1923
1771
|
if (this.disposed || this.disposing) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
1924
1772
|
}
|
|
1925
1773
|
};
|
|
1926
|
-
function
|
|
1774
|
+
function ye(e) {
|
|
1927
1775
|
return "peerConnection" in e;
|
|
1928
1776
|
}
|
|
1929
|
-
function
|
|
1777
|
+
function H(e) {
|
|
1930
1778
|
try {
|
|
1931
1779
|
return e.track;
|
|
1932
1780
|
} catch {
|
|
1933
1781
|
return null;
|
|
1934
1782
|
}
|
|
1935
1783
|
}
|
|
1936
|
-
function
|
|
1784
|
+
function U(e) {
|
|
1937
1785
|
return typeof e == "object" && !!e && e.name === "InvalidStateError";
|
|
1938
1786
|
}
|
|
1939
|
-
function
|
|
1787
|
+
function W(e) {
|
|
1940
1788
|
try {
|
|
1941
1789
|
return e.replaceTrack(null).catch((e) => {
|
|
1942
|
-
if (!
|
|
1790
|
+
if (!U(e)) throw e;
|
|
1943
1791
|
});
|
|
1944
1792
|
} catch (e) {
|
|
1945
|
-
return
|
|
1793
|
+
return U(e) ? Promise.resolve() : Promise.reject(e);
|
|
1946
1794
|
}
|
|
1947
1795
|
}
|
|
1948
|
-
function
|
|
1796
|
+
function be(e) {
|
|
1949
1797
|
try {
|
|
1950
|
-
|
|
1798
|
+
G(e.getTracks());
|
|
1951
1799
|
} catch {}
|
|
1952
1800
|
}
|
|
1953
|
-
function
|
|
1954
|
-
e.forEach(
|
|
1801
|
+
function G(e) {
|
|
1802
|
+
e.forEach(K);
|
|
1955
1803
|
}
|
|
1956
|
-
function
|
|
1804
|
+
function K(e) {
|
|
1957
1805
|
try {
|
|
1958
1806
|
e.stop();
|
|
1959
1807
|
} catch {}
|
|
1960
1808
|
}
|
|
1961
|
-
function
|
|
1809
|
+
function xe(e) {
|
|
1962
1810
|
if (typeof MediaStream < "u") try {
|
|
1963
1811
|
return new MediaStream([e]);
|
|
1964
1812
|
} catch {
|
|
@@ -1967,8 +1815,8 @@ function pe(e) {
|
|
|
1967
1815
|
}
|
|
1968
1816
|
//#endregion
|
|
1969
1817
|
//#region src/core/mediaBridge.ts
|
|
1970
|
-
function
|
|
1971
|
-
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 Se(t, n = {}) {
|
|
1819
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = n.ownershipRequired === !0, s = !1, c = !1, l, u = () => t(), d = new ve({ getActiveCall: u });
|
|
1972
1820
|
return {
|
|
1973
1821
|
publicMedia: {
|
|
1974
1822
|
requestPermission: () => (f(), d.requestPermission()),
|
|
@@ -1981,7 +1829,7 @@ function me(t, n = {}) {
|
|
|
1981
1829
|
releaseAll: () => (f(), d.releaseAll())
|
|
1982
1830
|
},
|
|
1983
1831
|
registerCall(e, t) {
|
|
1984
|
-
s || c || !
|
|
1832
|
+
s || c || !q(t) || (i.set(e, t), (!o || a.has(e)) && p(e, t));
|
|
1985
1833
|
},
|
|
1986
1834
|
async setCallOwnership(e, t) {
|
|
1987
1835
|
if (s) return;
|
|
@@ -2024,9 +1872,9 @@ function me(t, n = {}) {
|
|
|
2024
1872
|
if (s) throw new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
2025
1873
|
}
|
|
2026
1874
|
function p(e, t) {
|
|
2027
|
-
if (!
|
|
1875
|
+
if (!q(t) || typeof t.getMediaRegistration != "function") return;
|
|
2028
1876
|
let n = t.getMediaRegistration();
|
|
2029
|
-
if (
|
|
1877
|
+
if (Ce(n) && r.get(e)?.peerConnection !== n.peerConnection) {
|
|
2030
1878
|
r.set(e, n);
|
|
2031
1879
|
try {
|
|
2032
1880
|
d.registerCallMedia(e, n);
|
|
@@ -2036,22 +1884,22 @@ function me(t, n = {}) {
|
|
|
2036
1884
|
}
|
|
2037
1885
|
}
|
|
2038
1886
|
}
|
|
2039
|
-
function
|
|
1887
|
+
function q(e) {
|
|
2040
1888
|
return typeof e == "object" && !!e;
|
|
2041
1889
|
}
|
|
2042
|
-
function
|
|
1890
|
+
function Ce(e) {
|
|
2043
1891
|
return typeof e == "object" && !!e && "peerConnection" in e && typeof e.peerConnection == "object" && e.peerConnection !== null;
|
|
2044
1892
|
}
|
|
2045
1893
|
//#endregion
|
|
2046
1894
|
//#region src/reconnect/backoff.ts
|
|
2047
|
-
var
|
|
2048
|
-
function
|
|
2049
|
-
let n = Math.min(
|
|
1895
|
+
var we = 1e3, Te = 3e4;
|
|
1896
|
+
function Ee(e, t = Math.random) {
|
|
1897
|
+
let n = Math.min(Te, we * 2 ** Math.max(0, Math.floor(e))), r = Math.min(1, Math.max(0, t()));
|
|
2050
1898
|
return Math.round(n * (1 + r * .2));
|
|
2051
1899
|
}
|
|
2052
1900
|
//#endregion
|
|
2053
1901
|
//#region src/reconnect/ReconnectManager.ts
|
|
2054
|
-
var
|
|
1902
|
+
var De = class {
|
|
2055
1903
|
recover;
|
|
2056
1904
|
random;
|
|
2057
1905
|
isOnline;
|
|
@@ -2068,7 +1916,7 @@ var ye = class {
|
|
|
2068
1916
|
}
|
|
2069
1917
|
start() {
|
|
2070
1918
|
if (this.disposed || !this.online || !this.isOnline() || this.pendingTimer !== void 0 || this.running) return;
|
|
2071
|
-
let e = this.generation, t =
|
|
1919
|
+
let e = this.generation, t = Ee(this.attempt, this.random);
|
|
2072
1920
|
this.pendingTimer = setTimeout(() => {
|
|
2073
1921
|
this.pendingTimer = void 0, this.run(e);
|
|
2074
1922
|
}, t);
|
|
@@ -2110,7 +1958,7 @@ var ye = class {
|
|
|
2110
1958
|
clearPendingTimer() {
|
|
2111
1959
|
this.pendingTimer !== void 0 && (clearTimeout(this.pendingTimer), this.pendingTimer = void 0);
|
|
2112
1960
|
}
|
|
2113
|
-
},
|
|
1961
|
+
}, Oe = class t {
|
|
2114
1962
|
media;
|
|
2115
1963
|
options;
|
|
2116
1964
|
api;
|
|
@@ -2144,18 +1992,10 @@ var ye = class {
|
|
|
2144
1992
|
deletedSessions = /* @__PURE__ */ new Set();
|
|
2145
1993
|
ownedSessionIds = /* @__PURE__ */ new Set();
|
|
2146
1994
|
terminalReleaseOperations = /* @__PURE__ */ new Map();
|
|
2147
|
-
tokenRequest = {};
|
|
2148
1995
|
sharedWorkerSelection;
|
|
2149
1996
|
constructor(t) {
|
|
2150
|
-
if (this.options = t, t.api === void 0 && t.sessionProvider === void 0
|
|
2151
|
-
|
|
2152
|
-
...t,
|
|
2153
|
-
...this.tokenRequest
|
|
2154
|
-
});
|
|
2155
|
-
this.api = t.api === void 0 ? t.sessionProvider === void 0 ? new p({
|
|
2156
|
-
baseUrl: t.baseUrl ?? "",
|
|
2157
|
-
tokenProvider: i
|
|
2158
|
-
}) : Y(Ce(t.sessionProvider)) : Y(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : X(t.sip), this.mediaBridge = me(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new ye({
|
|
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 ? J(X(t.sessionProvider)) : J(t.api), this.suppliedSip = t.sip === void 0 ? void 0 : je(t.sip), this.mediaBridge = Se(() => this.getActiveMediaContext()), this.media = this.mediaBridge.publicMedia, this.reconnect = new De({
|
|
2159
1999
|
recover: () => this.recoverConnection(),
|
|
2160
2000
|
onAttempt: (e) => {
|
|
2161
2001
|
this.disposed || this.events.emit("connection.reconnecting", { attempt: e });
|
|
@@ -2167,13 +2007,13 @@ var ye = class {
|
|
|
2167
2007
|
}), this.sharedWorkerSelection = t.sharedWorker === void 0 ? {
|
|
2168
2008
|
mode: "single-tab",
|
|
2169
2009
|
reason: "disabled"
|
|
2170
|
-
} :
|
|
2010
|
+
} : w({
|
|
2171
2011
|
...t.sharedWorker,
|
|
2172
2012
|
...t.sharedWorkerHost ?? {}
|
|
2173
2013
|
});
|
|
2174
2014
|
}
|
|
2175
2015
|
static async checkSupport() {
|
|
2176
|
-
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 = Ae(typeof navigator < "u" ? navigator.userAgent : "");
|
|
2177
2017
|
return {
|
|
2178
2018
|
supported: e && t,
|
|
2179
2019
|
platform: n,
|
|
@@ -2187,15 +2027,13 @@ var ye = class {
|
|
|
2187
2027
|
let e = await t.checkSupport();
|
|
2188
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;
|
|
2189
2029
|
}
|
|
2190
|
-
connect(
|
|
2191
|
-
this.assertNotDisposed();
|
|
2192
|
-
let t = e?.extension?.trim();
|
|
2193
|
-
if (this.tokenRequest = t === void 0 || t === "" ? {} : { extension: t }, this.api.invalidateToken?.(), this.connectOperation !== void 0) return this.connectOperation;
|
|
2030
|
+
connect() {
|
|
2031
|
+
if (this.assertNotDisposed(), this.api.invalidateToken?.(), this.connectOperation !== void 0) return this.connectOperation;
|
|
2194
2032
|
if (this.state === "connected") return Promise.resolve();
|
|
2195
|
-
let
|
|
2196
|
-
this.connectOperation ===
|
|
2033
|
+
let e = this.lifecycleGeneration, t = this.performConnect(e).finally(() => {
|
|
2034
|
+
this.connectOperation === t && (this.connectOperation = void 0);
|
|
2197
2035
|
});
|
|
2198
|
-
return this.connectOperation =
|
|
2036
|
+
return this.connectOperation = t, t;
|
|
2199
2037
|
}
|
|
2200
2038
|
disconnect() {
|
|
2201
2039
|
if (this.assertNotDisposed(), this.disconnectOperation !== void 0) return this.disconnectOperation;
|
|
@@ -2260,10 +2098,12 @@ var ye = class {
|
|
|
2260
2098
|
return this.diagnostics.getReport(e);
|
|
2261
2099
|
}
|
|
2262
2100
|
async setAgentStatus(e) {
|
|
2263
|
-
this.assertNotDisposed()
|
|
2101
|
+
this.assertNotDisposed();
|
|
2102
|
+
let t = this.session?.transport.wssUrl;
|
|
2103
|
+
await this.api.setAgentStatus({
|
|
2264
2104
|
status: e,
|
|
2265
2105
|
reason: ""
|
|
2266
|
-
}), this.disposed || this.events.emit("agent.statusChanged", { status: e });
|
|
2106
|
+
}, t === void 0 ? void 0 : { wssUrl: t }), this.disposed || this.events.emit("agent.statusChanged", { status: e });
|
|
2267
2107
|
}
|
|
2268
2108
|
on(e, t) {
|
|
2269
2109
|
return this.disposed ? () => void 0 : this.events.on(e, t);
|
|
@@ -2280,7 +2120,7 @@ var ye = class {
|
|
|
2280
2120
|
sdkVersion: n,
|
|
2281
2121
|
platform: a === "mobile-web" ? "mobile_web" : "web",
|
|
2282
2122
|
...this.options.locale === void 0 ? {} : { locale: this.options.locale },
|
|
2283
|
-
requestedCapabilities: [...this.options.requestedCapabilities ??
|
|
2123
|
+
requestedCapabilities: [...this.options.requestedCapabilities ?? Fe(a)]
|
|
2284
2124
|
}), this.ownedSessionIds.add(t.sessionId), this.assertGeneration(e), r = await this.getSip(), this.assertGeneration(e), this.session = t;
|
|
2285
2125
|
let o = this.callManager ?? this.createCallManager(r, t, a);
|
|
2286
2126
|
this.callManager === void 0 && (i = o), o.updateSession(t), this.callManager = o, this.attachSipListener(r), this.attachNetworkListeners(), await r.connect(t), this.assertGeneration(e), this.setConnectionState("connected"), this.events.emit("connection.registered", { registered: !0 }), this.scheduleRefresh(t);
|
|
@@ -2331,7 +2171,7 @@ var ye = class {
|
|
|
2331
2171
|
if (this.pruneDeletedSessionTombstones(), this.disposed || (this.acceptingEvents = !0, this.setConnectionState("disconnected")), e !== void 0) throw e;
|
|
2332
2172
|
}
|
|
2333
2173
|
createCallManager(e, t, n) {
|
|
2334
|
-
let r = new
|
|
2174
|
+
let r = new v({
|
|
2335
2175
|
sip: e,
|
|
2336
2176
|
platform: n,
|
|
2337
2177
|
session: t,
|
|
@@ -2386,7 +2226,7 @@ var ye = class {
|
|
|
2386
2226
|
try {
|
|
2387
2227
|
await this.media.releaseAll();
|
|
2388
2228
|
} catch (t) {
|
|
2389
|
-
|
|
2229
|
+
Me(t) || (e ??= t);
|
|
2390
2230
|
}
|
|
2391
2231
|
try {
|
|
2392
2232
|
await this.mediaBridge.dispose();
|
|
@@ -2586,7 +2426,7 @@ var ye = class {
|
|
|
2586
2426
|
destination: e.destination
|
|
2587
2427
|
})),
|
|
2588
2428
|
permission: this.support?.hasMediaDevices === !1 ? "unsupported" : "unknown",
|
|
2589
|
-
ice:
|
|
2429
|
+
ice: ke(e),
|
|
2590
2430
|
wss: {
|
|
2591
2431
|
configured: e !== void 0,
|
|
2592
2432
|
secure: e?.transport.wssUrl.toLowerCase().startsWith("wss://") ?? !1,
|
|
@@ -2703,7 +2543,7 @@ var ye = class {
|
|
|
2703
2543
|
return new e("SDK_ALREADY_DISPOSED", "internal", !1);
|
|
2704
2544
|
}
|
|
2705
2545
|
};
|
|
2706
|
-
function
|
|
2546
|
+
function ke(e) {
|
|
2707
2547
|
if (e === void 0) return {
|
|
2708
2548
|
configured: !1,
|
|
2709
2549
|
serverCount: 0,
|
|
@@ -2721,28 +2561,40 @@ function xe(e) {
|
|
|
2721
2561
|
turnServerCount: n
|
|
2722
2562
|
};
|
|
2723
2563
|
}
|
|
2724
|
-
function
|
|
2564
|
+
function Ae(e) {
|
|
2725
2565
|
return e === "" ? "unknown" : /iPhone|iPad|Android/i.test(e) ? "mobile-web" : "web";
|
|
2726
2566
|
}
|
|
2727
|
-
function
|
|
2567
|
+
function J(t) {
|
|
2728
2568
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2729
2569
|
return t;
|
|
2730
2570
|
}
|
|
2731
|
-
function
|
|
2571
|
+
async function Y(e) {
|
|
2572
|
+
let t = e.sip?.registerTicket;
|
|
2573
|
+
if (typeof t != "string" || t === "") return e;
|
|
2574
|
+
let n = await le(t);
|
|
2575
|
+
return n === void 0 || n === t ? e : {
|
|
2576
|
+
...e,
|
|
2577
|
+
sip: {
|
|
2578
|
+
...e.sip,
|
|
2579
|
+
registerTicket: n
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2583
|
+
function X(t) {
|
|
2732
2584
|
let r = {
|
|
2733
|
-
createSession: (e) => t.createSession(e),
|
|
2734
|
-
refreshSession: (e) => t.refreshSession === void 0 ? t.createSession({
|
|
2585
|
+
createSession: async (e) => Y(await t.createSession(e)),
|
|
2586
|
+
refreshSession: async (e) => Y(t.refreshSession === void 0 ? await t.createSession({
|
|
2735
2587
|
sdkVersion: n,
|
|
2736
2588
|
platform: "web"
|
|
2737
|
-
}) : t.refreshSession(e),
|
|
2589
|
+
}) : await t.refreshSession(e)),
|
|
2738
2590
|
deleteSession: async (e) => {
|
|
2739
2591
|
t.deleteSession !== void 0 && await t.deleteSession(e);
|
|
2740
2592
|
},
|
|
2741
|
-
setAgentStatus: (n) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n)
|
|
2593
|
+
setAgentStatus: (n, r) => t.setAgentStatus === void 0 ? Promise.reject(new e("CAPABILITY_NOT_SUPPORTED", "capability", !1, { cause: "当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)" })) : t.setAgentStatus(n, r)
|
|
2742
2594
|
}, i = t.invalidateToken;
|
|
2743
2595
|
return i !== void 0 && (r.invalidateToken = () => i()), r;
|
|
2744
2596
|
}
|
|
2745
|
-
function
|
|
2597
|
+
function je(t) {
|
|
2746
2598
|
if (typeof t != "object" || !t) throw new e("CONFIG_INVALID", "configuration", !1);
|
|
2747
2599
|
return t;
|
|
2748
2600
|
}
|
|
@@ -2761,13 +2613,13 @@ function Z(t, n, r, i, a) {
|
|
|
2761
2613
|
function Q(t) {
|
|
2762
2614
|
return t instanceof e ? t.status !== void 0 && t.status >= 400 && t.status < 500 || t.serverCode === "SESSION_NOT_FOUND" || t.serverCode === "SESSION_EXPIRED" || t.serverCode === "TOKEN_INVALID" || t.serverCode === "TOKEN_EXPIRED" || t.code === "AUTH_TOKEN_UNAVAILABLE" || t.code === "AUTH_TOKEN_EXPIRED" : !1;
|
|
2763
2615
|
}
|
|
2764
|
-
function
|
|
2616
|
+
function Me(t) {
|
|
2765
2617
|
return t instanceof e && t.code === "SDK_ALREADY_DISPOSED";
|
|
2766
2618
|
}
|
|
2767
2619
|
function $(t) {
|
|
2768
2620
|
return t instanceof e && (t.code === "SDK_ALREADY_DISPOSED" || t.code === "CALL_NOT_CONNECTED");
|
|
2769
2621
|
}
|
|
2770
|
-
var
|
|
2622
|
+
var Ne = [
|
|
2771
2623
|
"outbound",
|
|
2772
2624
|
"inbound",
|
|
2773
2625
|
"mute",
|
|
@@ -2775,13 +2627,13 @@ var Te = [
|
|
|
2775
2627
|
"dtmf",
|
|
2776
2628
|
"blind_transfer",
|
|
2777
2629
|
"device_selection"
|
|
2778
|
-
],
|
|
2630
|
+
], Pe = [
|
|
2779
2631
|
"outbound",
|
|
2780
2632
|
"mute",
|
|
2781
2633
|
"dtmf"
|
|
2782
2634
|
];
|
|
2783
|
-
function
|
|
2784
|
-
return e === "mobile-web" ?
|
|
2635
|
+
function Fe(e) {
|
|
2636
|
+
return e === "mobile-web" ? Pe : Ne;
|
|
2785
2637
|
}
|
|
2786
2638
|
//#endregion
|
|
2787
|
-
export {
|
|
2639
|
+
export { v as a, s as c, a as d, i as f, x as i, o as l, w as n, f as o, T as r, c as s, Oe as t, l as u };
|