@koi-design/callkit 2.0.1 → 2.0.3
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 +8 -1
- package/dist/index.global.js +316 -226
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +135 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +47 -48
package/dist/index.js
CHANGED
|
@@ -26,20 +26,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
|
|
29
|
-
//
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
29
|
+
// core/index.ts
|
|
30
|
+
var core_exports = {};
|
|
31
|
+
__export(core_exports, {
|
|
32
32
|
CallKit: () => CallKit
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(core_exports);
|
|
35
35
|
var import_blueimp_md5 = __toESM(require("blueimp-md5"));
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// core/axios.ts
|
|
38
38
|
var import_axios = __toESM(require("axios"));
|
|
39
39
|
var instance = import_axios.default.create({
|
|
40
40
|
headers: {
|
|
41
41
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
42
|
-
}
|
|
42
|
+
},
|
|
43
|
+
timeout: 6e4
|
|
43
44
|
});
|
|
44
45
|
instance.interceptors.request.use((config) => config);
|
|
45
46
|
instance.interceptors.response.use(
|
|
@@ -49,25 +50,49 @@ instance.interceptors.response.use(
|
|
|
49
50
|
var request = (config) => instance.request(config);
|
|
50
51
|
var axios_default = request;
|
|
51
52
|
|
|
52
|
-
//
|
|
53
|
+
// core/api.ts
|
|
53
54
|
var Api = class {
|
|
54
55
|
callKit;
|
|
55
56
|
constructor(callKit) {
|
|
56
57
|
this.callKit = callKit;
|
|
57
58
|
}
|
|
59
|
+
isLogining = false;
|
|
60
|
+
isLoginOuting = false;
|
|
58
61
|
async login(params) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
if (this.isLogining) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.isLogining = true;
|
|
66
|
+
try {
|
|
67
|
+
const res = await this.post({
|
|
68
|
+
url: "/auth/agentUser/login",
|
|
69
|
+
method: "post",
|
|
70
|
+
data: params
|
|
71
|
+
});
|
|
72
|
+
this.isLogining = false;
|
|
73
|
+
return res;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
this.isLogining = false;
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
64
78
|
}
|
|
65
79
|
async loginOut(params) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
if (this.isLoginOuting) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.isLoginOuting = true;
|
|
84
|
+
try {
|
|
85
|
+
const res = await this.post({
|
|
86
|
+
url: "/auth/agentUser/loginOut",
|
|
87
|
+
method: "post",
|
|
88
|
+
data: params
|
|
89
|
+
});
|
|
90
|
+
this.isLoginOuting = false;
|
|
91
|
+
return res;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.isLoginOuting = false;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
71
96
|
}
|
|
72
97
|
async trackLogs(log) {
|
|
73
98
|
return this.post(
|
|
@@ -130,7 +155,7 @@ var Api = class {
|
|
|
130
155
|
}
|
|
131
156
|
};
|
|
132
157
|
|
|
133
|
-
//
|
|
158
|
+
// core/const.ts
|
|
134
159
|
var CallStatus = {
|
|
135
160
|
/**
|
|
136
161
|
* Initial state/Hang up
|
|
@@ -479,7 +504,7 @@ var trackLogsDefaultConfig = {
|
|
|
479
504
|
maxSize: 8192
|
|
480
505
|
};
|
|
481
506
|
|
|
482
|
-
//
|
|
507
|
+
// core/call.ts
|
|
483
508
|
var Call = class {
|
|
484
509
|
callKit;
|
|
485
510
|
constructor(callKit) {
|
|
@@ -620,20 +645,19 @@ var Call = class {
|
|
|
620
645
|
// package.json
|
|
621
646
|
var package_default = {
|
|
622
647
|
name: "@koi-design/callkit",
|
|
623
|
-
version: "2.0.
|
|
648
|
+
version: "2.0.3",
|
|
624
649
|
description: "callkit",
|
|
625
650
|
author: "koi",
|
|
626
651
|
license: "ISC",
|
|
627
652
|
scripts: {
|
|
628
653
|
build: "tsup",
|
|
629
|
-
start: "tsup --watch",
|
|
630
654
|
dev: "vite",
|
|
631
|
-
lint: "eslint -c
|
|
632
|
-
prepare: "husky install",
|
|
655
|
+
lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
633
656
|
release: "tsup && node scripts/pkg.js"
|
|
634
657
|
},
|
|
635
658
|
exports: {
|
|
636
659
|
".": {
|
|
660
|
+
types: "./dist/index.d.ts",
|
|
637
661
|
require: "./dist/index.js",
|
|
638
662
|
import: "./dist/index.mjs"
|
|
639
663
|
}
|
|
@@ -670,7 +694,7 @@ var package_default = {
|
|
|
670
694
|
}
|
|
671
695
|
};
|
|
672
696
|
|
|
673
|
-
//
|
|
697
|
+
// core/config.ts
|
|
674
698
|
var Config = class {
|
|
675
699
|
callKit;
|
|
676
700
|
constructor(callKit) {
|
|
@@ -686,6 +710,7 @@ var Config = class {
|
|
|
686
710
|
socket: "",
|
|
687
711
|
userInfo: {
|
|
688
712
|
wsUrl: "",
|
|
713
|
+
logGather: false,
|
|
689
714
|
sessionId: "",
|
|
690
715
|
// User
|
|
691
716
|
username: "",
|
|
@@ -740,7 +765,8 @@ var Config = class {
|
|
|
740
765
|
fsPort: "",
|
|
741
766
|
iceInfo: [],
|
|
742
767
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
743
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
768
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
769
|
+
logGather: false
|
|
744
770
|
};
|
|
745
771
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
746
772
|
}
|
|
@@ -773,7 +799,7 @@ var Config = class {
|
|
|
773
799
|
}
|
|
774
800
|
};
|
|
775
801
|
|
|
776
|
-
//
|
|
802
|
+
// core/logger.ts
|
|
777
803
|
var import_json_stringify_safe = __toESM(require("json-stringify-safe"));
|
|
778
804
|
function getLevel(level) {
|
|
779
805
|
return LoggerLevelMap[level];
|
|
@@ -910,10 +936,10 @@ var Logger = class {
|
|
|
910
936
|
}
|
|
911
937
|
};
|
|
912
938
|
|
|
913
|
-
//
|
|
939
|
+
// core/connect.ts
|
|
914
940
|
var import_sip = require("sip.js");
|
|
915
941
|
|
|
916
|
-
//
|
|
942
|
+
// core/utils.ts
|
|
917
943
|
var formatGetInviteData = (inviteData) => {
|
|
918
944
|
const extendInfoStr = inviteData["x-antaios-manual-extend_info"] || inviteData["x-antaios-manual-extend-info"];
|
|
919
945
|
let extendInfoObj = null;
|
|
@@ -928,7 +954,7 @@ var formatGetInviteData = (inviteData) => {
|
|
|
928
954
|
}
|
|
929
955
|
};
|
|
930
956
|
|
|
931
|
-
//
|
|
957
|
+
// core/connect.ts
|
|
932
958
|
var DEFAULT_RECONNECT_CONFIG = {
|
|
933
959
|
maxAttempts: 3,
|
|
934
960
|
delay: 500
|
|
@@ -1458,7 +1484,7 @@ var Connect = class {
|
|
|
1458
1484
|
this.setCallId(inviteData.callUuid);
|
|
1459
1485
|
} else {
|
|
1460
1486
|
this.setCallId(null);
|
|
1461
|
-
this.callKit.logger.
|
|
1487
|
+
this.callKit.logger.warn("call id is not exist", {
|
|
1462
1488
|
caller: "Connect.register.onInvite",
|
|
1463
1489
|
content: {
|
|
1464
1490
|
inviteData
|
|
@@ -1522,9 +1548,7 @@ var Connect = class {
|
|
|
1522
1548
|
onDisconnect: (error) => {
|
|
1523
1549
|
console.log("onDisconnect", error);
|
|
1524
1550
|
if (error) {
|
|
1525
|
-
this.
|
|
1526
|
-
} else {
|
|
1527
|
-
this.callKit.logger.info("SIP User Agent Disconnected", {
|
|
1551
|
+
this.callKit.logger.info("SIP User Agent Disconnected with error", {
|
|
1528
1552
|
caller: "Connect.register",
|
|
1529
1553
|
type: "SIP",
|
|
1530
1554
|
content: {
|
|
@@ -1532,6 +1556,13 @@ var Connect = class {
|
|
|
1532
1556
|
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
1533
1557
|
}
|
|
1534
1558
|
});
|
|
1559
|
+
this.startReconnectTimer();
|
|
1560
|
+
} else {
|
|
1561
|
+
this.callKit.logger.info("SIP User Agent Disconnected", {
|
|
1562
|
+
caller: "Connect.register",
|
|
1563
|
+
type: "SIP",
|
|
1564
|
+
content: {}
|
|
1565
|
+
});
|
|
1535
1566
|
}
|
|
1536
1567
|
},
|
|
1537
1568
|
onRegister: () => {
|
|
@@ -1640,6 +1671,15 @@ var Connect = class {
|
|
|
1640
1671
|
}
|
|
1641
1672
|
});
|
|
1642
1673
|
});
|
|
1674
|
+
await this.userAgent?.stop().catch((err) => {
|
|
1675
|
+
this.callKit.logger.warn(err, {
|
|
1676
|
+
caller: "Connect.unregister",
|
|
1677
|
+
type: "SIP",
|
|
1678
|
+
content: {
|
|
1679
|
+
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1643
1683
|
}
|
|
1644
1684
|
async call(callback) {
|
|
1645
1685
|
this.callKit.logger.info("connect call", {
|
|
@@ -1874,14 +1914,17 @@ var Connect = class {
|
|
|
1874
1914
|
}
|
|
1875
1915
|
};
|
|
1876
1916
|
|
|
1877
|
-
//
|
|
1917
|
+
// core/socket.ts
|
|
1878
1918
|
var RECONNECT_CONFIG = {
|
|
1879
1919
|
enabled: true,
|
|
1880
1920
|
maxAttempts: 3,
|
|
1881
1921
|
delay: 500,
|
|
1882
1922
|
backoffMultiplier: 1.5,
|
|
1883
1923
|
pingInterval: 3e4,
|
|
1884
|
-
pingTimeout: 5e3
|
|
1924
|
+
pingTimeout: 5e3,
|
|
1925
|
+
maxConnectsPerWindow: 5,
|
|
1926
|
+
timeWindow: 6e4
|
|
1927
|
+
// 60 seconds
|
|
1885
1928
|
};
|
|
1886
1929
|
var Socket = class {
|
|
1887
1930
|
callKit;
|
|
@@ -1896,6 +1939,8 @@ var Socket = class {
|
|
|
1896
1939
|
isReconnecting = false;
|
|
1897
1940
|
reconnectAttempts = 0;
|
|
1898
1941
|
socketError = false;
|
|
1942
|
+
// Track connection attempts for rate limiting
|
|
1943
|
+
connectAttemptTimes = [];
|
|
1899
1944
|
constructor(callKit) {
|
|
1900
1945
|
this.callKit = callKit;
|
|
1901
1946
|
const { reconnect } = this.callKit.config.getConfig();
|
|
@@ -1924,9 +1969,34 @@ var Socket = class {
|
|
|
1924
1969
|
});
|
|
1925
1970
|
return;
|
|
1926
1971
|
}
|
|
1972
|
+
if (this.isReconnecting) {
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1927
1975
|
this.attemptReconnect();
|
|
1928
1976
|
}
|
|
1977
|
+
clearWebSocket() {
|
|
1978
|
+
if (this.ws) {
|
|
1979
|
+
this.ws.onopen = null;
|
|
1980
|
+
this.ws.onclose = null;
|
|
1981
|
+
this.ws.onerror = null;
|
|
1982
|
+
this.ws.onmessage = null;
|
|
1983
|
+
}
|
|
1984
|
+
if (this.ws?.readyState === WebSocket.CONNECTING || this.ws?.readyState === WebSocket.OPEN) {
|
|
1985
|
+
this.ws?.close(1e3, "socket close");
|
|
1986
|
+
this.callKit.logger.info("socket clear", {
|
|
1987
|
+
caller: "Socket.clearWebSocket",
|
|
1988
|
+
type: "INCALL",
|
|
1989
|
+
content: {}
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
this.ws = void 0;
|
|
1993
|
+
this.isConnected = false;
|
|
1994
|
+
}
|
|
1929
1995
|
connect(socketUrl) {
|
|
1996
|
+
if (this.ws) {
|
|
1997
|
+
this.clearWebSocket();
|
|
1998
|
+
}
|
|
1999
|
+
this.connectAttemptTimes.push(Date.now());
|
|
1930
2000
|
this.ws = new WebSocket(socketUrl);
|
|
1931
2001
|
this.ws.onopen = (ev) => this.onOpen(ev);
|
|
1932
2002
|
this.ws.onclose = (ev) => this.onClose(ev);
|
|
@@ -2304,17 +2374,37 @@ var Socket = class {
|
|
|
2304
2374
|
this.lastPingTime = void 0;
|
|
2305
2375
|
this.satrtConfirm = false;
|
|
2306
2376
|
this.socketError = false;
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
caller: "Socket.reset",
|
|
2310
|
-
type: "INCALL",
|
|
2311
|
-
content: {}
|
|
2312
|
-
});
|
|
2313
|
-
this.ws.close();
|
|
2314
|
-
this.isConnected = false;
|
|
2315
|
-
}
|
|
2377
|
+
this.connectAttemptTimes = [];
|
|
2378
|
+
this.clearWebSocket();
|
|
2316
2379
|
}
|
|
2317
2380
|
attemptReconnect() {
|
|
2381
|
+
if (this.reconnectTimer) {
|
|
2382
|
+
clearTimeout(this.reconnectTimer);
|
|
2383
|
+
this.reconnectTimer = void 0;
|
|
2384
|
+
}
|
|
2385
|
+
const { maxConnectsPerWindow, timeWindow } = this.socketConfig;
|
|
2386
|
+
if (maxConnectsPerWindow && timeWindow) {
|
|
2387
|
+
const now = Date.now();
|
|
2388
|
+
this.connectAttemptTimes = this.connectAttemptTimes.filter(
|
|
2389
|
+
(time) => now - time < timeWindow
|
|
2390
|
+
);
|
|
2391
|
+
if (this.connectAttemptTimes.length >= maxConnectsPerWindow) {
|
|
2392
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2393
|
+
event: "INCALL_RECONNECT_ERROR"
|
|
2394
|
+
});
|
|
2395
|
+
this.callKit.logger.warn("Connection rate limit exceeded", {
|
|
2396
|
+
caller: "Socket.attemptReconnect",
|
|
2397
|
+
type: "INCALL",
|
|
2398
|
+
content: {
|
|
2399
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
2400
|
+
attempts: this.connectAttemptTimes.length,
|
|
2401
|
+
maxConnectsPerWindow,
|
|
2402
|
+
timeWindow
|
|
2403
|
+
}
|
|
2404
|
+
});
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2318
2408
|
if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
2319
2409
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2320
2410
|
event: "INCALL_RECONNECT_ERROR"
|
|
@@ -2357,7 +2447,7 @@ var Socket = class {
|
|
|
2357
2447
|
}
|
|
2358
2448
|
};
|
|
2359
2449
|
|
|
2360
|
-
//
|
|
2450
|
+
// core/index.ts
|
|
2361
2451
|
var CallKit = class {
|
|
2362
2452
|
api;
|
|
2363
2453
|
config;
|