@koi-design/callkit 2.0.2 → 2.0.4
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 +4 -2
- package/dist/index.global.js +263 -224
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +82 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +48 -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,20 @@ 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.4",
|
|
624
649
|
description: "callkit",
|
|
625
650
|
author: "koi",
|
|
626
651
|
license: "ISC",
|
|
627
652
|
scripts: {
|
|
628
653
|
build: "tsup",
|
|
629
|
-
|
|
654
|
+
"build:watch": "tsup --watch",
|
|
630
655
|
dev: "vite",
|
|
631
|
-
lint: "eslint -c
|
|
632
|
-
prepare: "husky install",
|
|
656
|
+
lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
633
657
|
release: "tsup && node scripts/pkg.js"
|
|
634
658
|
},
|
|
635
659
|
exports: {
|
|
636
660
|
".": {
|
|
661
|
+
types: "./dist/index.d.ts",
|
|
637
662
|
require: "./dist/index.js",
|
|
638
663
|
import: "./dist/index.mjs"
|
|
639
664
|
}
|
|
@@ -670,7 +695,7 @@ var package_default = {
|
|
|
670
695
|
}
|
|
671
696
|
};
|
|
672
697
|
|
|
673
|
-
//
|
|
698
|
+
// core/config.ts
|
|
674
699
|
var Config = class {
|
|
675
700
|
callKit;
|
|
676
701
|
constructor(callKit) {
|
|
@@ -686,6 +711,7 @@ var Config = class {
|
|
|
686
711
|
socket: "",
|
|
687
712
|
userInfo: {
|
|
688
713
|
wsUrl: "",
|
|
714
|
+
logGather: false,
|
|
689
715
|
sessionId: "",
|
|
690
716
|
// User
|
|
691
717
|
username: "",
|
|
@@ -740,7 +766,8 @@ var Config = class {
|
|
|
740
766
|
fsPort: "",
|
|
741
767
|
iceInfo: [],
|
|
742
768
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
743
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
769
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
770
|
+
logGather: false
|
|
744
771
|
};
|
|
745
772
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
746
773
|
}
|
|
@@ -773,7 +800,7 @@ var Config = class {
|
|
|
773
800
|
}
|
|
774
801
|
};
|
|
775
802
|
|
|
776
|
-
//
|
|
803
|
+
// core/logger.ts
|
|
777
804
|
var import_json_stringify_safe = __toESM(require("json-stringify-safe"));
|
|
778
805
|
function getLevel(level) {
|
|
779
806
|
return LoggerLevelMap[level];
|
|
@@ -910,10 +937,10 @@ var Logger = class {
|
|
|
910
937
|
}
|
|
911
938
|
};
|
|
912
939
|
|
|
913
|
-
//
|
|
940
|
+
// core/connect.ts
|
|
914
941
|
var import_sip = require("sip.js");
|
|
915
942
|
|
|
916
|
-
//
|
|
943
|
+
// core/utils.ts
|
|
917
944
|
var formatGetInviteData = (inviteData) => {
|
|
918
945
|
const extendInfoStr = inviteData["x-antaios-manual-extend_info"] || inviteData["x-antaios-manual-extend-info"];
|
|
919
946
|
let extendInfoObj = null;
|
|
@@ -928,7 +955,7 @@ var formatGetInviteData = (inviteData) => {
|
|
|
928
955
|
}
|
|
929
956
|
};
|
|
930
957
|
|
|
931
|
-
//
|
|
958
|
+
// core/connect.ts
|
|
932
959
|
var DEFAULT_RECONNECT_CONFIG = {
|
|
933
960
|
maxAttempts: 3,
|
|
934
961
|
delay: 500
|
|
@@ -1458,7 +1485,7 @@ var Connect = class {
|
|
|
1458
1485
|
this.setCallId(inviteData.callUuid);
|
|
1459
1486
|
} else {
|
|
1460
1487
|
this.setCallId(null);
|
|
1461
|
-
this.callKit.logger.
|
|
1488
|
+
this.callKit.logger.warn("call id is not exist", {
|
|
1462
1489
|
caller: "Connect.register.onInvite",
|
|
1463
1490
|
content: {
|
|
1464
1491
|
inviteData
|
|
@@ -1522,9 +1549,7 @@ var Connect = class {
|
|
|
1522
1549
|
onDisconnect: (error) => {
|
|
1523
1550
|
console.log("onDisconnect", error);
|
|
1524
1551
|
if (error) {
|
|
1525
|
-
this.
|
|
1526
|
-
} else {
|
|
1527
|
-
this.callKit.logger.info("SIP User Agent Disconnected", {
|
|
1552
|
+
this.callKit.logger.info("SIP User Agent Disconnected with error", {
|
|
1528
1553
|
caller: "Connect.register",
|
|
1529
1554
|
type: "SIP",
|
|
1530
1555
|
content: {
|
|
@@ -1532,6 +1557,13 @@ var Connect = class {
|
|
|
1532
1557
|
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
1533
1558
|
}
|
|
1534
1559
|
});
|
|
1560
|
+
this.startReconnectTimer();
|
|
1561
|
+
} else {
|
|
1562
|
+
this.callKit.logger.info("SIP User Agent Disconnected", {
|
|
1563
|
+
caller: "Connect.register",
|
|
1564
|
+
type: "SIP",
|
|
1565
|
+
content: {}
|
|
1566
|
+
});
|
|
1535
1567
|
}
|
|
1536
1568
|
},
|
|
1537
1569
|
onRegister: () => {
|
|
@@ -1640,6 +1672,15 @@ var Connect = class {
|
|
|
1640
1672
|
}
|
|
1641
1673
|
});
|
|
1642
1674
|
});
|
|
1675
|
+
await this.userAgent?.stop().catch((err) => {
|
|
1676
|
+
this.callKit.logger.warn(err, {
|
|
1677
|
+
caller: "Connect.unregister",
|
|
1678
|
+
type: "SIP",
|
|
1679
|
+
content: {
|
|
1680
|
+
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
});
|
|
1643
1684
|
}
|
|
1644
1685
|
async call(callback) {
|
|
1645
1686
|
this.callKit.logger.info("connect call", {
|
|
@@ -1874,12 +1915,11 @@ var Connect = class {
|
|
|
1874
1915
|
}
|
|
1875
1916
|
};
|
|
1876
1917
|
|
|
1877
|
-
//
|
|
1918
|
+
// core/socket.ts
|
|
1878
1919
|
var RECONNECT_CONFIG = {
|
|
1879
1920
|
enabled: true,
|
|
1880
1921
|
maxAttempts: 3,
|
|
1881
|
-
delay:
|
|
1882
|
-
backoffMultiplier: 1.5,
|
|
1922
|
+
delay: 1e3,
|
|
1883
1923
|
pingInterval: 3e4,
|
|
1884
1924
|
pingTimeout: 5e3
|
|
1885
1925
|
};
|
|
@@ -1924,6 +1964,9 @@ var Socket = class {
|
|
|
1924
1964
|
});
|
|
1925
1965
|
return;
|
|
1926
1966
|
}
|
|
1967
|
+
if (this.socketError) {
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1927
1970
|
if (this.isReconnecting) {
|
|
1928
1971
|
return;
|
|
1929
1972
|
}
|
|
@@ -1936,8 +1979,8 @@ var Socket = class {
|
|
|
1936
1979
|
this.ws.onerror = null;
|
|
1937
1980
|
this.ws.onmessage = null;
|
|
1938
1981
|
}
|
|
1939
|
-
if (this.ws
|
|
1940
|
-
this.ws
|
|
1982
|
+
if (this.ws?.readyState === WebSocket.CONNECTING || this.ws?.readyState === WebSocket.OPEN) {
|
|
1983
|
+
this.ws?.close(1e3, "socket close");
|
|
1941
1984
|
this.callKit.logger.info("socket clear", {
|
|
1942
1985
|
caller: "Socket.clearWebSocket",
|
|
1943
1986
|
type: "INCALL",
|
|
@@ -1996,9 +2039,6 @@ var Socket = class {
|
|
|
1996
2039
|
type: "INCALL",
|
|
1997
2040
|
content: { ev }
|
|
1998
2041
|
});
|
|
1999
|
-
if (this.socketError) {
|
|
2000
|
-
return;
|
|
2001
|
-
}
|
|
2002
2042
|
this.handleDisconnect();
|
|
2003
2043
|
}
|
|
2004
2044
|
onError(ev) {
|
|
@@ -2327,7 +2367,6 @@ var Socket = class {
|
|
|
2327
2367
|
this.resetReconnectState();
|
|
2328
2368
|
this.lastPingTime = void 0;
|
|
2329
2369
|
this.satrtConfirm = false;
|
|
2330
|
-
this.socketError = false;
|
|
2331
2370
|
this.clearWebSocket();
|
|
2332
2371
|
}
|
|
2333
2372
|
attemptReconnect() {
|
|
@@ -2377,7 +2416,7 @@ var Socket = class {
|
|
|
2377
2416
|
}
|
|
2378
2417
|
};
|
|
2379
2418
|
|
|
2380
|
-
//
|
|
2419
|
+
// core/index.ts
|
|
2381
2420
|
var CallKit = class {
|
|
2382
2421
|
api;
|
|
2383
2422
|
config;
|