@koi-design/callkit 2.0.4 → 2.0.5-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 +69 -17
- package/dist/index.global.js +172 -197
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +172 -197
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -503,6 +503,18 @@ var trackLogsDefaultConfig = {
|
|
|
503
503
|
interval: 5e3,
|
|
504
504
|
maxSize: 8192
|
|
505
505
|
};
|
|
506
|
+
var SOCKET_RECONNECT_CONFIG = {
|
|
507
|
+
enabled: true,
|
|
508
|
+
maxAttempts: 3,
|
|
509
|
+
delay: 1e3,
|
|
510
|
+
pingInterval: 3e4,
|
|
511
|
+
pingTimeout: 5e3
|
|
512
|
+
};
|
|
513
|
+
var SIP_RECONNECT_CONFIG = {
|
|
514
|
+
enabled: true,
|
|
515
|
+
maxAttempts: 3,
|
|
516
|
+
delay: 1e3
|
|
517
|
+
};
|
|
506
518
|
|
|
507
519
|
// core/call.ts
|
|
508
520
|
var Call = class {
|
|
@@ -645,14 +657,14 @@ var Call = class {
|
|
|
645
657
|
// package.json
|
|
646
658
|
var package_default = {
|
|
647
659
|
name: "@koi-design/callkit",
|
|
648
|
-
version: "2.0.
|
|
660
|
+
version: "2.0.5-beta.1",
|
|
649
661
|
description: "callkit",
|
|
650
662
|
author: "koi",
|
|
651
663
|
license: "ISC",
|
|
652
664
|
scripts: {
|
|
653
665
|
build: "tsup",
|
|
654
|
-
|
|
655
|
-
dev: "
|
|
666
|
+
sraet: "vite",
|
|
667
|
+
dev: "tsup --watch",
|
|
656
668
|
lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
657
669
|
release: "tsup && node scripts/pkg.js"
|
|
658
670
|
},
|
|
@@ -709,6 +721,10 @@ var Config = class {
|
|
|
709
721
|
audioRef: void 0,
|
|
710
722
|
constrains: constrainsDefault,
|
|
711
723
|
socket: "",
|
|
724
|
+
reconnect: {
|
|
725
|
+
sip: SIP_RECONNECT_CONFIG,
|
|
726
|
+
incall: SOCKET_RECONNECT_CONFIG
|
|
727
|
+
},
|
|
712
728
|
userInfo: {
|
|
713
729
|
wsUrl: "",
|
|
714
730
|
logGather: false,
|
|
@@ -793,7 +809,16 @@ var Config = class {
|
|
|
793
809
|
return true;
|
|
794
810
|
}
|
|
795
811
|
getTrackLogsConfig() {
|
|
796
|
-
return
|
|
812
|
+
return {
|
|
813
|
+
...trackLogsDefaultConfig,
|
|
814
|
+
...this.config?.trackLogs
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
getReconnectConfig(type) {
|
|
818
|
+
const config = this.config?.reconnect?.[type] ?? (type === "sip" ? SIP_RECONNECT_CONFIG : SOCKET_RECONNECT_CONFIG);
|
|
819
|
+
return {
|
|
820
|
+
...config
|
|
821
|
+
};
|
|
797
822
|
}
|
|
798
823
|
enableTrackLogs(enabled) {
|
|
799
824
|
this.config.trackLogs.enabled = enabled;
|
|
@@ -956,10 +981,6 @@ var formatGetInviteData = (inviteData) => {
|
|
|
956
981
|
};
|
|
957
982
|
|
|
958
983
|
// core/connect.ts
|
|
959
|
-
var DEFAULT_RECONNECT_CONFIG = {
|
|
960
|
-
maxAttempts: 3,
|
|
961
|
-
delay: 500
|
|
962
|
-
};
|
|
963
984
|
var MAX_HEARTBEAT_COUNT = 6;
|
|
964
985
|
function convertObjectStringToJSON(input) {
|
|
965
986
|
const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
|
|
@@ -991,10 +1012,6 @@ var initUserMedia = () => {
|
|
|
991
1012
|
};
|
|
992
1013
|
var Connect = class {
|
|
993
1014
|
callKit;
|
|
994
|
-
/**
|
|
995
|
-
*@description Reconnect config
|
|
996
|
-
*/
|
|
997
|
-
reconnectConfig;
|
|
998
1015
|
/**
|
|
999
1016
|
*@description Whether muted
|
|
1000
1017
|
*/
|
|
@@ -1034,11 +1051,9 @@ var Connect = class {
|
|
|
1034
1051
|
hasInvite = false;
|
|
1035
1052
|
constructor(callKit) {
|
|
1036
1053
|
this.callKit = callKit;
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
...reconnect
|
|
1041
|
-
};
|
|
1054
|
+
}
|
|
1055
|
+
get reconnectConfig() {
|
|
1056
|
+
return this.callKit.config.getReconnectConfig("sip");
|
|
1042
1057
|
}
|
|
1043
1058
|
// current call id for invite data
|
|
1044
1059
|
currentCallId = null;
|
|
@@ -1547,7 +1562,6 @@ var Connect = class {
|
|
|
1547
1562
|
});
|
|
1548
1563
|
},
|
|
1549
1564
|
onDisconnect: (error) => {
|
|
1550
|
-
console.log("onDisconnect", error);
|
|
1551
1565
|
if (error) {
|
|
1552
1566
|
this.callKit.logger.info("SIP User Agent Disconnected with error", {
|
|
1553
1567
|
caller: "Connect.register",
|
|
@@ -1681,6 +1695,7 @@ var Connect = class {
|
|
|
1681
1695
|
}
|
|
1682
1696
|
});
|
|
1683
1697
|
});
|
|
1698
|
+
this.setRegister(false);
|
|
1684
1699
|
}
|
|
1685
1700
|
async call(callback) {
|
|
1686
1701
|
this.callKit.logger.info("connect call", {
|
|
@@ -1704,6 +1719,8 @@ var Connect = class {
|
|
|
1704
1719
|
* @param register
|
|
1705
1720
|
*/
|
|
1706
1721
|
setRegister(register) {
|
|
1722
|
+
if (this.isRegister === register)
|
|
1723
|
+
return;
|
|
1707
1724
|
this.callKit.logger.info("connect setRegister", {
|
|
1708
1725
|
caller: "Connect.setRegister",
|
|
1709
1726
|
type: "SIP",
|
|
@@ -1916,33 +1933,47 @@ var Connect = class {
|
|
|
1916
1933
|
};
|
|
1917
1934
|
|
|
1918
1935
|
// core/socket.ts
|
|
1919
|
-
var RECONNECT_CONFIG = {
|
|
1920
|
-
enabled: true,
|
|
1921
|
-
maxAttempts: 3,
|
|
1922
|
-
delay: 1e3,
|
|
1923
|
-
pingInterval: 3e4,
|
|
1924
|
-
pingTimeout: 5e3
|
|
1925
|
-
};
|
|
1926
1936
|
var Socket = class {
|
|
1927
1937
|
callKit;
|
|
1928
1938
|
ws;
|
|
1929
|
-
socketConfig;
|
|
1930
1939
|
lastPingTime = void 0;
|
|
1931
|
-
isConnected = false;
|
|
1932
1940
|
pingTimer;
|
|
1933
|
-
|
|
1934
|
-
|
|
1941
|
+
/**
|
|
1942
|
+
* @description reconnect timer
|
|
1943
|
+
*/
|
|
1935
1944
|
reconnectTimer;
|
|
1936
|
-
|
|
1945
|
+
/**
|
|
1946
|
+
* @description reconnect attempts
|
|
1947
|
+
*/
|
|
1937
1948
|
reconnectAttempts = 0;
|
|
1938
|
-
|
|
1949
|
+
/**
|
|
1950
|
+
* @description connect auth state
|
|
1951
|
+
* @default {
|
|
1952
|
+
* satrtConfirm: false,
|
|
1953
|
+
* isConnected: false,
|
|
1954
|
+
* isReconnecting: false,
|
|
1955
|
+
* isAuthenticated: false,
|
|
1956
|
+
* isError: false
|
|
1957
|
+
* }
|
|
1958
|
+
*/
|
|
1959
|
+
connectAuthState = {
|
|
1960
|
+
satrtConfirm: false,
|
|
1961
|
+
isConnected: false,
|
|
1962
|
+
isReconnecting: false,
|
|
1963
|
+
isAuthenticated: false,
|
|
1964
|
+
isError: false
|
|
1965
|
+
};
|
|
1966
|
+
get satrtConfirm() {
|
|
1967
|
+
return this.connectAuthState.satrtConfirm;
|
|
1968
|
+
}
|
|
1969
|
+
get isError() {
|
|
1970
|
+
return this.connectAuthState.isError;
|
|
1971
|
+
}
|
|
1939
1972
|
constructor(callKit) {
|
|
1940
1973
|
this.callKit = callKit;
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
...reconnect
|
|
1945
|
-
};
|
|
1974
|
+
}
|
|
1975
|
+
get reconnectConfig() {
|
|
1976
|
+
return this.callKit.config.getReconnectConfig("incall");
|
|
1946
1977
|
}
|
|
1947
1978
|
init() {
|
|
1948
1979
|
const { socket } = this.callKit.config.getConfig();
|
|
@@ -1955,19 +1986,22 @@ var Socket = class {
|
|
|
1955
1986
|
});
|
|
1956
1987
|
this.connect(socket);
|
|
1957
1988
|
}
|
|
1989
|
+
setConnectAuthState(key, value) {
|
|
1990
|
+
if (this.connectAuthState[key] === value)
|
|
1991
|
+
return;
|
|
1992
|
+
this.connectAuthState[key] = value;
|
|
1993
|
+
}
|
|
1958
1994
|
handleDisconnect() {
|
|
1959
|
-
this.isConnected
|
|
1960
|
-
|
|
1961
|
-
|
|
1995
|
+
this.setConnectAuthState("isConnected", false);
|
|
1996
|
+
const { enabled } = this.reconnectConfig;
|
|
1997
|
+
if (!this.callKit.config.isLogin() || !enabled) {
|
|
1998
|
+
this.callKit.reset();
|
|
1962
1999
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
1963
2000
|
event: "INCALL_NOT_CONNECTED"
|
|
1964
2001
|
});
|
|
1965
2002
|
return;
|
|
1966
2003
|
}
|
|
1967
|
-
if (this.
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1970
|
-
if (this.isReconnecting) {
|
|
2004
|
+
if (this.connectAuthState.isReconnecting) {
|
|
1971
2005
|
return;
|
|
1972
2006
|
}
|
|
1973
2007
|
this.attemptReconnect();
|
|
@@ -1988,7 +2022,7 @@ var Socket = class {
|
|
|
1988
2022
|
});
|
|
1989
2023
|
}
|
|
1990
2024
|
this.ws = void 0;
|
|
1991
|
-
this.isConnected
|
|
2025
|
+
this.setConnectAuthState("isConnected", false);
|
|
1992
2026
|
}
|
|
1993
2027
|
connect(socketUrl) {
|
|
1994
2028
|
if (this.ws) {
|
|
@@ -2006,11 +2040,11 @@ var Socket = class {
|
|
|
2006
2040
|
type: "INCALL",
|
|
2007
2041
|
content: { ev }
|
|
2008
2042
|
});
|
|
2009
|
-
this.
|
|
2010
|
-
this.isConnected = true;
|
|
2043
|
+
this.setConnectAuthState("isConnected", true);
|
|
2011
2044
|
this.lastPingTime = Date.now();
|
|
2012
2045
|
this.checkPing();
|
|
2013
|
-
if (this.isReconnecting) {
|
|
2046
|
+
if (this.connectAuthState.isReconnecting) {
|
|
2047
|
+
this.setConnectAuthState("isReconnecting", false);
|
|
2014
2048
|
this.callKit.logger.info("reconnect success", {
|
|
2015
2049
|
caller: "Socket.onOpen",
|
|
2016
2050
|
type: "INCALL",
|
|
@@ -2023,15 +2057,28 @@ var Socket = class {
|
|
|
2023
2057
|
event: "INCALL_RECONNECT_SUCCESS"
|
|
2024
2058
|
});
|
|
2025
2059
|
}
|
|
2026
|
-
this.resetReconnectState();
|
|
2027
2060
|
}
|
|
2028
|
-
|
|
2029
|
-
this.
|
|
2061
|
+
resetConnectState() {
|
|
2062
|
+
this.connectAuthState = {
|
|
2063
|
+
satrtConfirm: false,
|
|
2064
|
+
isConnected: false,
|
|
2065
|
+
isReconnecting: false,
|
|
2066
|
+
isAuthenticated: false,
|
|
2067
|
+
isError: false
|
|
2068
|
+
};
|
|
2030
2069
|
this.reconnectAttempts = 0;
|
|
2031
2070
|
if (this.reconnectTimer) {
|
|
2032
2071
|
clearTimeout(this.reconnectTimer);
|
|
2033
2072
|
this.reconnectTimer = void 0;
|
|
2034
2073
|
}
|
|
2074
|
+
this.callKit.logger.info("reset connect state", {
|
|
2075
|
+
caller: "Socket.resetConnectState",
|
|
2076
|
+
type: "INCALL",
|
|
2077
|
+
content: {
|
|
2078
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
2079
|
+
connectAuthState: this.connectAuthState
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2035
2082
|
}
|
|
2036
2083
|
onClose(ev) {
|
|
2037
2084
|
this.callKit.logger.info("socket onClose", {
|
|
@@ -2042,7 +2089,6 @@ var Socket = class {
|
|
|
2042
2089
|
this.handleDisconnect();
|
|
2043
2090
|
}
|
|
2044
2091
|
onError(ev) {
|
|
2045
|
-
this.socketError = true;
|
|
2046
2092
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2047
2093
|
event: "INCALL_CONNECT_ERROR",
|
|
2048
2094
|
err: ev
|
|
@@ -2081,7 +2127,7 @@ var Socket = class {
|
|
|
2081
2127
|
});
|
|
2082
2128
|
content = data.data;
|
|
2083
2129
|
}
|
|
2084
|
-
this.callKit.logger.info(
|
|
2130
|
+
this.callKit.logger.info(`socket onMessage: ${data.event}`, {
|
|
2085
2131
|
caller: "Socket.onMessage",
|
|
2086
2132
|
type: "INCALL",
|
|
2087
2133
|
content: {
|
|
@@ -2095,134 +2141,38 @@ var Socket = class {
|
|
|
2095
2141
|
return;
|
|
2096
2142
|
}
|
|
2097
2143
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
2098
|
-
this.
|
|
2099
|
-
caller: "Socket.onMessage",
|
|
2100
|
-
type: "INCALL",
|
|
2101
|
-
content: {
|
|
2102
|
-
data: content,
|
|
2103
|
-
event: SocketReceiveEvent.START_CONFIRM
|
|
2104
|
-
}
|
|
2105
|
-
});
|
|
2106
|
-
this.satrtConfirm = true;
|
|
2107
|
-
}
|
|
2108
|
-
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
2109
|
-
this.callKit.logger.info("call success", {
|
|
2110
|
-
caller: "Socket.onMessage",
|
|
2111
|
-
type: "INCALL",
|
|
2112
|
-
content: {
|
|
2113
|
-
data: content,
|
|
2114
|
-
event: SocketReceiveEvent.CALL_SUCCESS
|
|
2115
|
-
}
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
2119
|
-
this.callKit.logger.info(data.msg, {
|
|
2120
|
-
caller: "Socket.onMessage",
|
|
2121
|
-
type: "INCALL",
|
|
2122
|
-
content: {
|
|
2123
|
-
data: content,
|
|
2124
|
-
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
2125
|
-
}
|
|
2126
|
-
});
|
|
2144
|
+
this.setConnectAuthState("satrtConfirm", true);
|
|
2127
2145
|
}
|
|
2128
2146
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
2129
2147
|
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
2130
|
-
this.callKit.logger.info(data.msg, {
|
|
2131
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2132
|
-
type: "INCALL",
|
|
2133
|
-
content: {
|
|
2134
|
-
data: content,
|
|
2135
|
-
event: SocketReceiveEvent.CUSTOMER_RINGING
|
|
2136
|
-
}
|
|
2137
|
-
});
|
|
2138
2148
|
}
|
|
2139
2149
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
2140
|
-
this.callKit.logger.info(data.msg, {
|
|
2141
|
-
caller: "Socket.onMessage",
|
|
2142
|
-
type: "INCALL",
|
|
2143
|
-
content: {
|
|
2144
|
-
data: content,
|
|
2145
|
-
event: SocketReceiveEvent.CUSTOMER_PICK_UP
|
|
2146
|
-
}
|
|
2147
|
-
});
|
|
2148
2150
|
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
2149
2151
|
}
|
|
2150
2152
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
2151
|
-
this.callKit.logger.info(data.msg, {
|
|
2152
|
-
caller: "Socket.onMessage",
|
|
2153
|
-
type: "INCALL",
|
|
2154
|
-
content: {
|
|
2155
|
-
data: content,
|
|
2156
|
-
event: SocketReceiveEvent.AGENT_PICK_UP
|
|
2157
|
-
}
|
|
2158
|
-
});
|
|
2159
2153
|
this.callKit.trigger(KitEvent.AGENT_PICK_UP, /* @__PURE__ */ new Date());
|
|
2160
2154
|
}
|
|
2161
2155
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
2162
|
-
this.callKit.logger.info(data.msg, {
|
|
2163
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2164
|
-
type: "INCALL",
|
|
2165
|
-
content: {
|
|
2166
|
-
data: content,
|
|
2167
|
-
event: SocketReceiveEvent.CUSTOMER_HANG_UP
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
2156
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
2171
2157
|
if (content?.callUuid) {
|
|
2172
2158
|
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
2173
2159
|
}
|
|
2174
2160
|
}
|
|
2175
2161
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
2176
|
-
this.callKit.logger.info(data.msg, {
|
|
2177
|
-
caller: "Socket.onMessage",
|
|
2178
|
-
type: "INCALL",
|
|
2179
|
-
content: {
|
|
2180
|
-
data: content,
|
|
2181
|
-
event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
|
|
2182
|
-
}
|
|
2183
|
-
});
|
|
2184
2162
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
2185
2163
|
if (content?.callUuid) {
|
|
2186
2164
|
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
2187
2165
|
}
|
|
2188
2166
|
}
|
|
2189
2167
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
2190
|
-
this.callKit.logger.info(data.msg, {
|
|
2191
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2192
|
-
type: "INCALL",
|
|
2193
|
-
content: {
|
|
2194
|
-
data: content,
|
|
2195
|
-
event: SocketReceiveEvent.CALL_CDR
|
|
2196
|
-
}
|
|
2197
|
-
});
|
|
2198
2168
|
this.callKit.trigger(KitEvent.CALL_CDR, content);
|
|
2199
2169
|
}
|
|
2200
|
-
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
2201
|
-
this.callKit.logger.info(data.msg, {
|
|
2202
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2203
|
-
type: "INCALL",
|
|
2204
|
-
content: {
|
|
2205
|
-
data: content,
|
|
2206
|
-
event: SocketReceiveEvent.STOP_CONFIRM
|
|
2207
|
-
}
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
2170
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
2211
2171
|
const { userInfo } = this.callKit.config.getConfig();
|
|
2212
|
-
this.
|
|
2213
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2214
|
-
type: "INCALL",
|
|
2215
|
-
content: {
|
|
2216
|
-
data: content,
|
|
2217
|
-
event: SocketReceiveEvent.CLOSE
|
|
2218
|
-
}
|
|
2219
|
-
});
|
|
2220
|
-
this.send(SocketSendEvent.END, {
|
|
2221
|
-
agentId: userInfo.agentId
|
|
2222
|
-
});
|
|
2172
|
+
this.send(SocketSendEvent.END, { agentId: userInfo.agentId });
|
|
2223
2173
|
}
|
|
2224
2174
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
2225
|
-
this.
|
|
2175
|
+
this.setConnectAuthState("isError", true);
|
|
2226
2176
|
this.callKit.reset();
|
|
2227
2177
|
this.callKit.logger.error(data.msg, {
|
|
2228
2178
|
caller: `Socket.onMessage:${data.event}`,
|
|
@@ -2234,7 +2184,7 @@ var Socket = class {
|
|
|
2234
2184
|
});
|
|
2235
2185
|
}
|
|
2236
2186
|
if (data.event === SocketReceiveEvent.SESSION_ERROR) {
|
|
2237
|
-
this.
|
|
2187
|
+
this.setConnectAuthState("isError", true);
|
|
2238
2188
|
this.callKit.reset();
|
|
2239
2189
|
this.callKit.logger.error(data.msg, {
|
|
2240
2190
|
caller: `Socket.onMessage:${data.event}`,
|
|
@@ -2246,14 +2196,6 @@ var Socket = class {
|
|
|
2246
2196
|
});
|
|
2247
2197
|
}
|
|
2248
2198
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
2249
|
-
this.callKit.logger.info(data.msg, {
|
|
2250
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
2251
|
-
type: "INCALL",
|
|
2252
|
-
content: {
|
|
2253
|
-
data: content,
|
|
2254
|
-
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
2255
|
-
}
|
|
2256
|
-
});
|
|
2257
2199
|
if (content?.callUuid) {
|
|
2258
2200
|
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
2259
2201
|
}
|
|
@@ -2261,7 +2203,7 @@ var Socket = class {
|
|
|
2261
2203
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
2262
2204
|
}
|
|
2263
2205
|
send(event, message) {
|
|
2264
|
-
if (!this.isConnected) {
|
|
2206
|
+
if (!this.connectAuthState.isConnected) {
|
|
2265
2207
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2266
2208
|
event: "INCALL_NOT_CONNECTED"
|
|
2267
2209
|
});
|
|
@@ -2320,23 +2262,16 @@ var Socket = class {
|
|
|
2320
2262
|
}
|
|
2321
2263
|
}
|
|
2322
2264
|
ping() {
|
|
2323
|
-
if (!this.isConnected)
|
|
2265
|
+
if (!this.connectAuthState.isConnected)
|
|
2324
2266
|
return;
|
|
2325
2267
|
this.send(SocketSendEvent.PING);
|
|
2326
|
-
this.callKit.logger.info(`socket ping`, {
|
|
2327
|
-
caller: "Socket.ping",
|
|
2328
|
-
type: "INCALL",
|
|
2329
|
-
content: {
|
|
2330
|
-
lastPingTime: this.lastPingTime
|
|
2331
|
-
}
|
|
2332
|
-
});
|
|
2333
2268
|
const now = Date.now();
|
|
2334
|
-
const { pingInterval, pingTimeout } = this.
|
|
2269
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
2335
2270
|
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
2336
|
-
if (this.ws && this.isConnected) {
|
|
2271
|
+
if (this.ws && this.connectAuthState.isConnected) {
|
|
2337
2272
|
this.ws.close(4001, "ping timeout");
|
|
2338
2273
|
} else {
|
|
2339
|
-
this.reset();
|
|
2274
|
+
this.callKit.reset();
|
|
2340
2275
|
}
|
|
2341
2276
|
this.callKit.logger.error("socket ping timeout", {
|
|
2342
2277
|
caller: "Socket.ping",
|
|
@@ -2352,21 +2287,29 @@ var Socket = class {
|
|
|
2352
2287
|
clearInterval(this.pingTimer);
|
|
2353
2288
|
}
|
|
2354
2289
|
this.ping();
|
|
2290
|
+
const { pingInterval } = this.reconnectConfig;
|
|
2355
2291
|
this.pingTimer = setInterval(() => {
|
|
2356
2292
|
this.ping();
|
|
2357
|
-
},
|
|
2293
|
+
}, pingInterval);
|
|
2358
2294
|
}
|
|
2359
2295
|
/**
|
|
2360
2296
|
* reset socket connection and all states
|
|
2361
2297
|
*/
|
|
2362
|
-
async reset() {
|
|
2298
|
+
async reset(config) {
|
|
2299
|
+
const { focus = false } = config || {};
|
|
2363
2300
|
if (this.pingTimer) {
|
|
2364
2301
|
clearInterval(this.pingTimer);
|
|
2365
2302
|
this.pingTimer = void 0;
|
|
2366
2303
|
}
|
|
2367
|
-
|
|
2304
|
+
if (focus) {
|
|
2305
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2306
|
+
event: "INCALL_RESET"
|
|
2307
|
+
});
|
|
2308
|
+
this.resetConnectState();
|
|
2309
|
+
this.setConnectAuthState("isConnected", false);
|
|
2310
|
+
}
|
|
2368
2311
|
this.lastPingTime = void 0;
|
|
2369
|
-
this.satrtConfirm
|
|
2312
|
+
this.setConnectAuthState("satrtConfirm", false);
|
|
2370
2313
|
this.clearWebSocket();
|
|
2371
2314
|
}
|
|
2372
2315
|
attemptReconnect() {
|
|
@@ -2374,11 +2317,12 @@ var Socket = class {
|
|
|
2374
2317
|
clearTimeout(this.reconnectTimer);
|
|
2375
2318
|
this.reconnectTimer = void 0;
|
|
2376
2319
|
}
|
|
2377
|
-
|
|
2320
|
+
const { maxAttempts } = this.reconnectConfig;
|
|
2321
|
+
if (this.reconnectAttempts >= maxAttempts) {
|
|
2378
2322
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2379
2323
|
event: "INCALL_RECONNECT_ERROR"
|
|
2380
2324
|
});
|
|
2381
|
-
this.reset();
|
|
2325
|
+
this.callKit.reset();
|
|
2382
2326
|
this.callKit.logger.error("Maximum reconnection attempts reached", {
|
|
2383
2327
|
caller: "Socket.attemptReconnect",
|
|
2384
2328
|
type: "INCALL",
|
|
@@ -2394,17 +2338,17 @@ var Socket = class {
|
|
|
2394
2338
|
event: "INCALL_RECONNECT_START"
|
|
2395
2339
|
});
|
|
2396
2340
|
}
|
|
2397
|
-
this.isReconnecting
|
|
2341
|
+
this.setConnectAuthState("isReconnecting", true);
|
|
2398
2342
|
this.reconnectAttempts += 1;
|
|
2399
|
-
const { delay } = this.
|
|
2343
|
+
const { delay } = this.reconnectConfig;
|
|
2400
2344
|
this.callKit.logger.info(
|
|
2401
|
-
`Preparing reconnection attempt ${this.reconnectAttempts}/${
|
|
2345
|
+
`Preparing reconnection attempt ${this.reconnectAttempts}/${maxAttempts}, delay: ${delay}ms`,
|
|
2402
2346
|
{
|
|
2403
2347
|
caller: "Socket.attemptReconnect",
|
|
2404
2348
|
type: "INCALL",
|
|
2405
2349
|
content: {
|
|
2406
2350
|
reconnectAttempts: this.reconnectAttempts,
|
|
2407
|
-
maxAttempts
|
|
2351
|
+
maxAttempts,
|
|
2408
2352
|
delay
|
|
2409
2353
|
}
|
|
2410
2354
|
}
|
|
@@ -2431,17 +2375,34 @@ var CallKit = class {
|
|
|
2431
2375
|
this.connect = new Connect(this);
|
|
2432
2376
|
this.callCenter = new Call(this);
|
|
2433
2377
|
this.socket = new Socket(this);
|
|
2434
|
-
this.
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2378
|
+
this.logger = new Logger(this, options.log);
|
|
2379
|
+
if (options.log) {
|
|
2380
|
+
this.config.setConfig("log", options.log);
|
|
2381
|
+
}
|
|
2382
|
+
if (options.trackLogs) {
|
|
2383
|
+
this.config.setConfig("trackLogs", {
|
|
2384
|
+
...trackLogsDefaultConfig,
|
|
2385
|
+
...options.trackLogs
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
if (options.audioRef) {
|
|
2389
|
+
this.config.setConfig("audioRef", options.audioRef);
|
|
2390
|
+
}
|
|
2391
|
+
if (options.host) {
|
|
2392
|
+
this.config.setConfig("host", options.host);
|
|
2393
|
+
}
|
|
2438
2394
|
this.config.setConfig(
|
|
2439
2395
|
"constrains",
|
|
2440
2396
|
options.constrains || constrainsDefault
|
|
2441
2397
|
);
|
|
2442
2398
|
this.config.setConfig("socket", options.socket);
|
|
2443
|
-
this.config.setConfig("reconnect",
|
|
2444
|
-
|
|
2399
|
+
this.config.setConfig("reconnect", {
|
|
2400
|
+
sip: { ...SIP_RECONNECT_CONFIG, ...options.reconnect?.sip || {} },
|
|
2401
|
+
incall: {
|
|
2402
|
+
...SOCKET_RECONNECT_CONFIG,
|
|
2403
|
+
...options.reconnect?.incall || {}
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2445
2406
|
this.logger.info("callKit init", {
|
|
2446
2407
|
caller: "CallKit.init",
|
|
2447
2408
|
content: options
|
|
@@ -2479,6 +2440,13 @@ var CallKit = class {
|
|
|
2479
2440
|
encryptionPassword
|
|
2480
2441
|
}
|
|
2481
2442
|
});
|
|
2443
|
+
if (this.socket.isError) {
|
|
2444
|
+
this.logger.warn("socket is error", {
|
|
2445
|
+
caller: "CallKit.login",
|
|
2446
|
+
content: { username, password, extra, socketError: this.socket.isError }
|
|
2447
|
+
});
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2482
2450
|
try {
|
|
2483
2451
|
const user = await this.api.login({
|
|
2484
2452
|
userName: username,
|
|
@@ -2530,7 +2498,7 @@ var CallKit = class {
|
|
|
2530
2498
|
try {
|
|
2531
2499
|
await this.api.loginOut({ sessionId });
|
|
2532
2500
|
} catch (error) {
|
|
2533
|
-
this.logger.
|
|
2501
|
+
this.logger.warn(error, {
|
|
2534
2502
|
caller: "CallKit.logout",
|
|
2535
2503
|
content: {
|
|
2536
2504
|
errCode: ErrorCode.API_USER_LOGOUT_ERROR
|
|
@@ -2540,8 +2508,9 @@ var CallKit = class {
|
|
|
2540
2508
|
}
|
|
2541
2509
|
if (isReset) {
|
|
2542
2510
|
await this.reset();
|
|
2511
|
+
} else {
|
|
2512
|
+
this.config.reset();
|
|
2543
2513
|
}
|
|
2544
|
-
this.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
2545
2514
|
}
|
|
2546
2515
|
async call(extno = "", options = {
|
|
2547
2516
|
sourceType: CallSourceType.phoneNum,
|
|
@@ -2606,9 +2575,6 @@ var CallKit = class {
|
|
|
2606
2575
|
});
|
|
2607
2576
|
this.connect.unregister();
|
|
2608
2577
|
}
|
|
2609
|
-
async stop() {
|
|
2610
|
-
await this.connect.stop();
|
|
2611
|
-
}
|
|
2612
2578
|
async hangup() {
|
|
2613
2579
|
if (!this.config.check())
|
|
2614
2580
|
return;
|
|
@@ -2691,11 +2657,19 @@ var CallKit = class {
|
|
|
2691
2657
|
userStatus: status
|
|
2692
2658
|
});
|
|
2693
2659
|
}
|
|
2694
|
-
|
|
2660
|
+
/**
|
|
2661
|
+
* reset callkit
|
|
2662
|
+
* @description recover the callkit to the initial state
|
|
2663
|
+
* @default focus is false
|
|
2664
|
+
* @param config.focus is true, the callkit reset socket connection and all states
|
|
2665
|
+
*/
|
|
2666
|
+
async reset(config) {
|
|
2667
|
+
const { focus = false } = config || {};
|
|
2695
2668
|
this.logger.info("reset", {
|
|
2696
2669
|
caller: "CallKit.reset",
|
|
2697
2670
|
content: {
|
|
2698
|
-
connectStatus: this.connect.connectStatus
|
|
2671
|
+
connectStatus: this.connect.connectStatus,
|
|
2672
|
+
focus
|
|
2699
2673
|
}
|
|
2700
2674
|
});
|
|
2701
2675
|
if (this.connect.isCalling()) {
|
|
@@ -2704,9 +2678,10 @@ var CallKit = class {
|
|
|
2704
2678
|
await this.connect.reset();
|
|
2705
2679
|
if (this.config.isLogin()) {
|
|
2706
2680
|
await this.logout({ isReset: false });
|
|
2681
|
+
} else {
|
|
2682
|
+
await this.config.reset();
|
|
2707
2683
|
}
|
|
2708
|
-
await this.
|
|
2709
|
-
await this.socket.reset();
|
|
2684
|
+
await this.socket.reset({ focus });
|
|
2710
2685
|
}
|
|
2711
2686
|
on(event, callback) {
|
|
2712
2687
|
this.listener.push({
|