@koi-design/callkit 2.2.0-beta.4 → 2.3.0-beta.1
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/dist/index.d.ts +604 -600
- package/dist/index.global.js +31 -182
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +26 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -177
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.global.js
CHANGED
|
@@ -1736,7 +1736,7 @@ var WebCall = (() => {
|
|
|
1736
1736
|
var require_follow_redirects = __commonJS({
|
|
1737
1737
|
"../../node_modules/.pnpm/follow-redirects@1.15.9/node_modules/follow-redirects/index.js"(exports, module) {
|
|
1738
1738
|
var url = __require("url");
|
|
1739
|
-
var
|
|
1739
|
+
var URL = url.URL;
|
|
1740
1740
|
var http = __require("http");
|
|
1741
1741
|
var https = __require("https");
|
|
1742
1742
|
var Writable = __require("stream").Writable;
|
|
@@ -1752,7 +1752,7 @@ var WebCall = (() => {
|
|
|
1752
1752
|
})();
|
|
1753
1753
|
var useNativeURL = false;
|
|
1754
1754
|
try {
|
|
1755
|
-
assert(new
|
|
1755
|
+
assert(new URL(""));
|
|
1756
1756
|
} catch (error) {
|
|
1757
1757
|
useNativeURL = error.code === "ERR_INVALID_URL";
|
|
1758
1758
|
}
|
|
@@ -2132,7 +2132,7 @@ var WebCall = (() => {
|
|
|
2132
2132
|
function parseUrl(input) {
|
|
2133
2133
|
var parsed;
|
|
2134
2134
|
if (useNativeURL) {
|
|
2135
|
-
parsed = new
|
|
2135
|
+
parsed = new URL(input);
|
|
2136
2136
|
} else {
|
|
2137
2137
|
parsed = validateUrl(url.parse(input));
|
|
2138
2138
|
if (!isString(parsed.protocol)) {
|
|
@@ -2142,7 +2142,7 @@ var WebCall = (() => {
|
|
|
2142
2142
|
return parsed;
|
|
2143
2143
|
}
|
|
2144
2144
|
function resolveUrl(relative, base) {
|
|
2145
|
-
return useNativeURL ? new
|
|
2145
|
+
return useNativeURL ? new URL(relative, base) : parseUrl(url.resolve(base, relative));
|
|
2146
2146
|
}
|
|
2147
2147
|
function validateUrl(input) {
|
|
2148
2148
|
if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
|
|
@@ -2221,7 +2221,7 @@ var WebCall = (() => {
|
|
|
2221
2221
|
return typeof value === "object" && "length" in value;
|
|
2222
2222
|
}
|
|
2223
2223
|
function isURL(value) {
|
|
2224
|
-
return
|
|
2224
|
+
return URL && value instanceof URL;
|
|
2225
2225
|
}
|
|
2226
2226
|
module.exports = wrap({ http, https });
|
|
2227
2227
|
module.exports.wrap = wrap;
|
|
@@ -3237,7 +3237,7 @@ var WebCall = (() => {
|
|
|
3237
3237
|
const res = await this.post({
|
|
3238
3238
|
url: "/auth/agentUser/login",
|
|
3239
3239
|
method: "post",
|
|
3240
|
-
data:
|
|
3240
|
+
data: params
|
|
3241
3241
|
});
|
|
3242
3242
|
return res;
|
|
3243
3243
|
} finally {
|
|
@@ -3720,6 +3720,12 @@ var WebCall = (() => {
|
|
|
3720
3720
|
phoneNum: 1,
|
|
3721
3721
|
workOrderId: 2
|
|
3722
3722
|
};
|
|
3723
|
+
var PhoneTypeEnum = {
|
|
3724
|
+
SIP: 0,
|
|
3725
|
+
TEL: 1,
|
|
3726
|
+
OUT: 2,
|
|
3727
|
+
SP: 5
|
|
3728
|
+
};
|
|
3723
3729
|
var trackLogsDefaultConfig = {
|
|
3724
3730
|
enabled: false,
|
|
3725
3731
|
interval: 5e3,
|
|
@@ -3883,7 +3889,7 @@ var WebCall = (() => {
|
|
|
3883
3889
|
// package.json
|
|
3884
3890
|
var package_default = {
|
|
3885
3891
|
name: "@koi-design/callkit",
|
|
3886
|
-
version: "2.
|
|
3892
|
+
version: "2.3.0-beta.1",
|
|
3887
3893
|
description: "callkit",
|
|
3888
3894
|
author: "koi",
|
|
3889
3895
|
license: "ISC",
|
|
@@ -3960,6 +3966,7 @@ var WebCall = (() => {
|
|
|
3960
3966
|
password: "",
|
|
3961
3967
|
encryptionPassword: EncryptionMethod.INTERNAL,
|
|
3962
3968
|
sourceType: CallSourceType.phoneNum,
|
|
3969
|
+
phoneType: PhoneTypeEnum.SIP,
|
|
3963
3970
|
// Extension number
|
|
3964
3971
|
extno: "",
|
|
3965
3972
|
workOrderId: "",
|
|
@@ -4003,6 +4010,7 @@ var WebCall = (() => {
|
|
|
4003
4010
|
encryptionPassword: "",
|
|
4004
4011
|
userPart: "",
|
|
4005
4012
|
sourceType: CallSourceType.phoneNum,
|
|
4013
|
+
phoneType: PhoneTypeEnum.SIP,
|
|
4006
4014
|
extno: "",
|
|
4007
4015
|
workOrderId: "",
|
|
4008
4016
|
agentId: "",
|
|
@@ -19867,152 +19875,12 @@ ${log}` : log;
|
|
|
19867
19875
|
}
|
|
19868
19876
|
};
|
|
19869
19877
|
|
|
19870
|
-
// core/heartbeat-worker.ts
|
|
19871
|
-
var workerCode = `
|
|
19872
|
-
let timer = null;
|
|
19873
|
-
let interval = 30000;
|
|
19874
|
-
|
|
19875
|
-
self.onmessage = function(e) {
|
|
19876
|
-
const { type, interval: newInterval } = e.data;
|
|
19877
|
-
|
|
19878
|
-
if (type === 'start') {
|
|
19879
|
-
if (timer) {
|
|
19880
|
-
clearInterval(timer);
|
|
19881
|
-
}
|
|
19882
|
-
interval = newInterval || interval;
|
|
19883
|
-
timer = setInterval(() => {
|
|
19884
|
-
self.postMessage({ type: 'tick' });
|
|
19885
|
-
}, interval);
|
|
19886
|
-
}
|
|
19887
|
-
|
|
19888
|
-
if (type === 'stop') {
|
|
19889
|
-
if (timer) {
|
|
19890
|
-
clearInterval(timer);
|
|
19891
|
-
timer = null;
|
|
19892
|
-
}
|
|
19893
|
-
}
|
|
19894
|
-
|
|
19895
|
-
if (type === 'updateInterval') {
|
|
19896
|
-
interval = newInterval;
|
|
19897
|
-
if (timer) {
|
|
19898
|
-
clearInterval(timer);
|
|
19899
|
-
timer = setInterval(() => {
|
|
19900
|
-
self.postMessage({ type: 'tick' });
|
|
19901
|
-
}, interval);
|
|
19902
|
-
}
|
|
19903
|
-
}
|
|
19904
|
-
};
|
|
19905
|
-
`;
|
|
19906
|
-
function createHeartbeatWorker() {
|
|
19907
|
-
try {
|
|
19908
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
19909
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
19910
|
-
const worker = new Worker(workerUrl);
|
|
19911
|
-
URL.revokeObjectURL(workerUrl);
|
|
19912
|
-
return worker;
|
|
19913
|
-
} catch {
|
|
19914
|
-
return null;
|
|
19915
|
-
}
|
|
19916
|
-
}
|
|
19917
|
-
var HeartbeatManager = class {
|
|
19918
|
-
worker = null;
|
|
19919
|
-
fallbackTimer = null;
|
|
19920
|
-
interval = 3e4;
|
|
19921
|
-
onTick = null;
|
|
19922
|
-
isRunning = false;
|
|
19923
|
-
constructor() {
|
|
19924
|
-
this.worker = createHeartbeatWorker();
|
|
19925
|
-
if (this.worker) {
|
|
19926
|
-
this.worker.onmessage = (e) => {
|
|
19927
|
-
if (e.data.type === "tick" && this.onTick) {
|
|
19928
|
-
this.onTick();
|
|
19929
|
-
}
|
|
19930
|
-
};
|
|
19931
|
-
}
|
|
19932
|
-
}
|
|
19933
|
-
/**
|
|
19934
|
-
* Start the heartbeat
|
|
19935
|
-
* @param interval - Interval in milliseconds
|
|
19936
|
-
* @param onTick - Callback function to execute on each tick
|
|
19937
|
-
*/
|
|
19938
|
-
start(interval, onTick) {
|
|
19939
|
-
this.stop();
|
|
19940
|
-
this.interval = interval;
|
|
19941
|
-
this.onTick = onTick;
|
|
19942
|
-
this.isRunning = true;
|
|
19943
|
-
if (this.worker) {
|
|
19944
|
-
this.worker.postMessage({
|
|
19945
|
-
type: "start",
|
|
19946
|
-
interval
|
|
19947
|
-
});
|
|
19948
|
-
} else {
|
|
19949
|
-
this.fallbackTimer = setInterval(() => {
|
|
19950
|
-
if (this.onTick) {
|
|
19951
|
-
this.onTick();
|
|
19952
|
-
}
|
|
19953
|
-
}, interval);
|
|
19954
|
-
}
|
|
19955
|
-
}
|
|
19956
|
-
/**
|
|
19957
|
-
* Stop the heartbeat
|
|
19958
|
-
*/
|
|
19959
|
-
stop() {
|
|
19960
|
-
this.isRunning = false;
|
|
19961
|
-
this.onTick = null;
|
|
19962
|
-
if (this.worker) {
|
|
19963
|
-
this.worker.postMessage({ type: "stop" });
|
|
19964
|
-
}
|
|
19965
|
-
if (this.fallbackTimer) {
|
|
19966
|
-
clearInterval(this.fallbackTimer);
|
|
19967
|
-
this.fallbackTimer = null;
|
|
19968
|
-
}
|
|
19969
|
-
}
|
|
19970
|
-
/**
|
|
19971
|
-
* Update the heartbeat interval
|
|
19972
|
-
* @param interval - New interval in milliseconds
|
|
19973
|
-
*/
|
|
19974
|
-
updateInterval(interval) {
|
|
19975
|
-
this.interval = interval;
|
|
19976
|
-
if (!this.isRunning)
|
|
19977
|
-
return;
|
|
19978
|
-
if (this.worker) {
|
|
19979
|
-
this.worker.postMessage({
|
|
19980
|
-
type: "updateInterval",
|
|
19981
|
-
interval
|
|
19982
|
-
});
|
|
19983
|
-
} else if (this.fallbackTimer && this.onTick) {
|
|
19984
|
-
clearInterval(this.fallbackTimer);
|
|
19985
|
-
this.fallbackTimer = setInterval(() => {
|
|
19986
|
-
if (this.onTick) {
|
|
19987
|
-
this.onTick();
|
|
19988
|
-
}
|
|
19989
|
-
}, interval);
|
|
19990
|
-
}
|
|
19991
|
-
}
|
|
19992
|
-
/**
|
|
19993
|
-
* Destroy the heartbeat manager and release resources
|
|
19994
|
-
*/
|
|
19995
|
-
destroy() {
|
|
19996
|
-
this.stop();
|
|
19997
|
-
if (this.worker) {
|
|
19998
|
-
this.worker.terminate();
|
|
19999
|
-
this.worker = null;
|
|
20000
|
-
}
|
|
20001
|
-
}
|
|
20002
|
-
/**
|
|
20003
|
-
* Check if using Web Worker
|
|
20004
|
-
*/
|
|
20005
|
-
isUsingWorker() {
|
|
20006
|
-
return this.worker !== null;
|
|
20007
|
-
}
|
|
20008
|
-
};
|
|
20009
|
-
|
|
20010
19878
|
// core/socket.ts
|
|
20011
19879
|
var Socket = class {
|
|
20012
19880
|
callKit;
|
|
20013
19881
|
ws;
|
|
20014
19882
|
lastPingTime = void 0;
|
|
20015
|
-
|
|
19883
|
+
pingTimer;
|
|
20016
19884
|
/**
|
|
20017
19885
|
* @description reconnect timer
|
|
20018
19886
|
*/
|
|
@@ -20045,18 +19913,10 @@ self.onmessage = function(e) {
|
|
|
20045
19913
|
}
|
|
20046
19914
|
constructor(callKit) {
|
|
20047
19915
|
this.callKit = callKit;
|
|
20048
|
-
this.heartbeatManager = new HeartbeatManager();
|
|
20049
19916
|
}
|
|
20050
19917
|
get reconnectConfig() {
|
|
20051
19918
|
return this.callKit.config.getReconnectConfig("incall");
|
|
20052
19919
|
}
|
|
20053
|
-
get pingInterval() {
|
|
20054
|
-
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
20055
|
-
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
20056
|
-
return keepaliveInterval * 1e3;
|
|
20057
|
-
}
|
|
20058
|
-
return this.reconnectConfig.pingInterval;
|
|
20059
|
-
}
|
|
20060
19920
|
isConnected() {
|
|
20061
19921
|
return this.connectAuthState.isConnected;
|
|
20062
19922
|
}
|
|
@@ -20350,7 +20210,7 @@ self.onmessage = function(e) {
|
|
|
20350
20210
|
return;
|
|
20351
20211
|
}
|
|
20352
20212
|
const { userInfo, version } = this.callKit.config.getConfig();
|
|
20353
|
-
const { sessionId, extno, agentId } = userInfo;
|
|
20213
|
+
const { sessionId, extno, agentId, phoneType } = userInfo;
|
|
20354
20214
|
if (!sessionId) {
|
|
20355
20215
|
this.callKit.logger.error("sessionId is empty", {
|
|
20356
20216
|
caller: "Socket.send",
|
|
@@ -20370,6 +20230,7 @@ self.onmessage = function(e) {
|
|
|
20370
20230
|
if (SocketSendEvent.CALL === event) {
|
|
20371
20231
|
msg.phoneNum = extno;
|
|
20372
20232
|
msg.agentId = agentId;
|
|
20233
|
+
msg.phoneType = phoneType;
|
|
20373
20234
|
if (message?.sourceType === CallSourceType.phoneNum) {
|
|
20374
20235
|
delete msg.workOrderId;
|
|
20375
20236
|
} else if (message?.sourceType === CallSourceType.workOrderId) {
|
|
@@ -20391,8 +20252,8 @@ self.onmessage = function(e) {
|
|
|
20391
20252
|
return;
|
|
20392
20253
|
this.send(SocketSendEvent.PING);
|
|
20393
20254
|
const now = Date.now();
|
|
20394
|
-
const { pingTimeout } = this.reconnectConfig;
|
|
20395
|
-
if (now - this.lastPingTime >
|
|
20255
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
20256
|
+
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
20396
20257
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
20397
20258
|
caller: "Socket.ping",
|
|
20398
20259
|
type: "INCALL",
|
|
@@ -20407,27 +20268,23 @@ self.onmessage = function(e) {
|
|
|
20407
20268
|
}
|
|
20408
20269
|
}
|
|
20409
20270
|
checkPing() {
|
|
20410
|
-
|
|
20271
|
+
if (this.pingTimer) {
|
|
20272
|
+
clearInterval(this.pingTimer);
|
|
20273
|
+
}
|
|
20274
|
+
const { pingInterval } = this.reconnectConfig;
|
|
20275
|
+
this.pingTimer = setInterval(() => {
|
|
20411
20276
|
this.ping();
|
|
20412
|
-
});
|
|
20413
|
-
this.callKit.logger.info(
|
|
20414
|
-
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
20415
|
-
{
|
|
20416
|
-
caller: "Socket.checkPing",
|
|
20417
|
-
type: "INCALL",
|
|
20418
|
-
content: {
|
|
20419
|
-
pingInterval: this.pingInterval,
|
|
20420
|
-
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
20421
|
-
}
|
|
20422
|
-
}
|
|
20423
|
-
);
|
|
20277
|
+
}, pingInterval);
|
|
20424
20278
|
}
|
|
20425
20279
|
/**
|
|
20426
20280
|
* reset socket connection and all states
|
|
20427
20281
|
*/
|
|
20428
20282
|
async reset(config) {
|
|
20429
20283
|
const { force = false } = config || {};
|
|
20430
|
-
this.
|
|
20284
|
+
if (this.pingTimer) {
|
|
20285
|
+
clearInterval(this.pingTimer);
|
|
20286
|
+
this.pingTimer = void 0;
|
|
20287
|
+
}
|
|
20431
20288
|
if (force) {
|
|
20432
20289
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20433
20290
|
event: "INCALL_RESET"
|
|
@@ -20438,12 +20295,6 @@ self.onmessage = function(e) {
|
|
|
20438
20295
|
this.setConnectAuthState("startConfirm", false);
|
|
20439
20296
|
this.clearWebSocket();
|
|
20440
20297
|
}
|
|
20441
|
-
/**
|
|
20442
|
-
* Destroy the heartbeat manager
|
|
20443
|
-
*/
|
|
20444
|
-
destroyHeartbeat() {
|
|
20445
|
-
this.heartbeatManager.destroy();
|
|
20446
|
-
}
|
|
20447
20298
|
attemptReconnect() {
|
|
20448
20299
|
if (this.reconnectTimer) {
|
|
20449
20300
|
clearTimeout(this.reconnectTimer);
|
|
@@ -20569,7 +20420,6 @@ self.onmessage = function(e) {
|
|
|
20569
20420
|
content: {
|
|
20570
20421
|
username,
|
|
20571
20422
|
password,
|
|
20572
|
-
ua: navigator.userAgent,
|
|
20573
20423
|
encryptionMethod,
|
|
20574
20424
|
encryptionPassword
|
|
20575
20425
|
}
|
|
@@ -20587,7 +20437,6 @@ self.onmessage = function(e) {
|
|
|
20587
20437
|
password: encryptionPassword,
|
|
20588
20438
|
timestamp: Date.now()
|
|
20589
20439
|
});
|
|
20590
|
-
console.log("user", user);
|
|
20591
20440
|
if (user) {
|
|
20592
20441
|
this.config.setConfig("userInfo", {
|
|
20593
20442
|
wsUrl: `wss://${user.wsUrl}`,
|
|
@@ -20604,7 +20453,7 @@ self.onmessage = function(e) {
|
|
|
20604
20453
|
iceInfo: user.iceInfo,
|
|
20605
20454
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
20606
20455
|
logGather: user.logGather,
|
|
20607
|
-
|
|
20456
|
+
phoneType: user.phoneType,
|
|
20608
20457
|
// encryptionType is in extra
|
|
20609
20458
|
...extra
|
|
20610
20459
|
});
|