@koi-design/callkit 2.0.5-beta.1 → 2.0.5-beta.2
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 +7 -6
- package/dist/index.global.js +44 -35
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +44 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -27,6 +27,10 @@ var Api = class {
|
|
|
27
27
|
isLoginOuting = false;
|
|
28
28
|
async login(params) {
|
|
29
29
|
if (this.isLogining) {
|
|
30
|
+
this.callKit.logger.info("login is already in progress cancel", {
|
|
31
|
+
caller: "Api.login",
|
|
32
|
+
content: { userName: params.userName }
|
|
33
|
+
});
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
36
|
this.isLogining = true;
|
|
@@ -36,15 +40,17 @@ var Api = class {
|
|
|
36
40
|
method: "post",
|
|
37
41
|
data: params
|
|
38
42
|
});
|
|
39
|
-
this.isLogining = false;
|
|
40
43
|
return res;
|
|
41
|
-
}
|
|
44
|
+
} finally {
|
|
42
45
|
this.isLogining = false;
|
|
43
|
-
throw error;
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
async loginOut(params) {
|
|
47
49
|
if (this.isLoginOuting) {
|
|
50
|
+
this.callKit.logger.info("loginOut is already in progress cancel", {
|
|
51
|
+
caller: "Api.loginOut",
|
|
52
|
+
content: { sessionId: params.sessionId }
|
|
53
|
+
});
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
56
|
this.isLoginOuting = true;
|
|
@@ -54,11 +60,9 @@ var Api = class {
|
|
|
54
60
|
method: "post",
|
|
55
61
|
data: params
|
|
56
62
|
});
|
|
57
|
-
this.isLoginOuting = false;
|
|
58
63
|
return res;
|
|
59
|
-
}
|
|
64
|
+
} finally {
|
|
60
65
|
this.isLoginOuting = false;
|
|
61
|
-
throw error;
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
async trackLogs(log) {
|
|
@@ -495,14 +499,14 @@ var Call = class {
|
|
|
495
499
|
this.callKit.logger.info("callStart", {
|
|
496
500
|
caller: "Call.callStart",
|
|
497
501
|
content: {
|
|
498
|
-
startConfirm: this.callKit.socket.
|
|
502
|
+
startConfirm: this.callKit.socket.startConfirm
|
|
499
503
|
}
|
|
500
504
|
});
|
|
501
|
-
if (!this.callKit.socket.
|
|
505
|
+
if (!this.callKit.socket.startConfirm) {
|
|
502
506
|
this.callKit.logger.warn("server not confirm start", {
|
|
503
507
|
caller: "Call.callStart",
|
|
504
508
|
content: {
|
|
505
|
-
startConfirm: this.callKit.socket.
|
|
509
|
+
startConfirm: this.callKit.socket.startConfirm
|
|
506
510
|
}
|
|
507
511
|
});
|
|
508
512
|
return;
|
|
@@ -624,7 +628,7 @@ var Call = class {
|
|
|
624
628
|
// package.json
|
|
625
629
|
var package_default = {
|
|
626
630
|
name: "@koi-design/callkit",
|
|
627
|
-
version: "2.0.5-beta.
|
|
631
|
+
version: "2.0.5-beta.2",
|
|
628
632
|
description: "callkit",
|
|
629
633
|
author: "koi",
|
|
630
634
|
license: "ISC",
|
|
@@ -1521,9 +1525,7 @@ var Connect = class {
|
|
|
1521
1525
|
version: `${this.callKit.config.getConfig().version}`
|
|
1522
1526
|
}
|
|
1523
1527
|
});
|
|
1524
|
-
await this.registerer.register().
|
|
1525
|
-
this.callKit.socket.send(SocketSendEvent.START);
|
|
1526
|
-
}).catch(async (err) => {
|
|
1528
|
+
await this.registerer.register().catch(async (err) => {
|
|
1527
1529
|
this.callKit.reset();
|
|
1528
1530
|
this.callKit.logger.error(err?.message, {
|
|
1529
1531
|
caller: "Connect.register",
|
|
@@ -1922,7 +1924,7 @@ var Socket = class {
|
|
|
1922
1924
|
/**
|
|
1923
1925
|
* @description connect auth state
|
|
1924
1926
|
* @default {
|
|
1925
|
-
*
|
|
1927
|
+
* startConfirm: false,
|
|
1926
1928
|
* isConnected: false,
|
|
1927
1929
|
* isReconnecting: false,
|
|
1928
1930
|
* isAuthenticated: false,
|
|
@@ -1930,14 +1932,13 @@ var Socket = class {
|
|
|
1930
1932
|
* }
|
|
1931
1933
|
*/
|
|
1932
1934
|
connectAuthState = {
|
|
1933
|
-
|
|
1935
|
+
startConfirm: false,
|
|
1934
1936
|
isConnected: false,
|
|
1935
1937
|
isReconnecting: false,
|
|
1936
|
-
isAuthenticated: false,
|
|
1937
1938
|
isError: false
|
|
1938
1939
|
};
|
|
1939
|
-
get
|
|
1940
|
-
return this.connectAuthState.
|
|
1940
|
+
get startConfirm() {
|
|
1941
|
+
return this.connectAuthState.startConfirm;
|
|
1941
1942
|
}
|
|
1942
1943
|
get isError() {
|
|
1943
1944
|
return this.connectAuthState.isError;
|
|
@@ -1977,6 +1978,9 @@ var Socket = class {
|
|
|
1977
1978
|
if (this.connectAuthState.isReconnecting) {
|
|
1978
1979
|
return;
|
|
1979
1980
|
}
|
|
1981
|
+
if (this.connectAuthState.isError) {
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1980
1984
|
this.attemptReconnect();
|
|
1981
1985
|
}
|
|
1982
1986
|
clearWebSocket() {
|
|
@@ -2016,6 +2020,7 @@ var Socket = class {
|
|
|
2016
2020
|
this.setConnectAuthState("isConnected", true);
|
|
2017
2021
|
this.lastPingTime = Date.now();
|
|
2018
2022
|
this.checkPing();
|
|
2023
|
+
this.send(SocketSendEvent.START);
|
|
2019
2024
|
if (this.connectAuthState.isReconnecting) {
|
|
2020
2025
|
this.setConnectAuthState("isReconnecting", false);
|
|
2021
2026
|
this.callKit.logger.info("reconnect success", {
|
|
@@ -2031,19 +2036,23 @@ var Socket = class {
|
|
|
2031
2036
|
});
|
|
2032
2037
|
}
|
|
2033
2038
|
}
|
|
2039
|
+
cleanReconnectState() {
|
|
2040
|
+
this.reconnectAttempts = 0;
|
|
2041
|
+
if (this.reconnectTimer) {
|
|
2042
|
+
clearTimeout(this.reconnectTimer);
|
|
2043
|
+
this.reconnectTimer = void 0;
|
|
2044
|
+
}
|
|
2045
|
+
this.setConnectAuthState("isReconnecting", false);
|
|
2046
|
+
this.setConnectAuthState("isError", false);
|
|
2047
|
+
}
|
|
2034
2048
|
resetConnectState() {
|
|
2035
2049
|
this.connectAuthState = {
|
|
2036
|
-
|
|
2050
|
+
startConfirm: false,
|
|
2037
2051
|
isConnected: false,
|
|
2038
2052
|
isReconnecting: false,
|
|
2039
|
-
isAuthenticated: false,
|
|
2040
2053
|
isError: false
|
|
2041
2054
|
};
|
|
2042
|
-
this.
|
|
2043
|
-
if (this.reconnectTimer) {
|
|
2044
|
-
clearTimeout(this.reconnectTimer);
|
|
2045
|
-
this.reconnectTimer = void 0;
|
|
2046
|
-
}
|
|
2055
|
+
this.cleanReconnectState();
|
|
2047
2056
|
this.callKit.logger.info("reset connect state", {
|
|
2048
2057
|
caller: "Socket.resetConnectState",
|
|
2049
2058
|
type: "INCALL",
|
|
@@ -2114,7 +2123,8 @@ var Socket = class {
|
|
|
2114
2123
|
return;
|
|
2115
2124
|
}
|
|
2116
2125
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
2117
|
-
this.setConnectAuthState("
|
|
2126
|
+
this.setConnectAuthState("startConfirm", true);
|
|
2127
|
+
this.cleanReconnectState();
|
|
2118
2128
|
}
|
|
2119
2129
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
2120
2130
|
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
@@ -2269,20 +2279,19 @@ var Socket = class {
|
|
|
2269
2279
|
* reset socket connection and all states
|
|
2270
2280
|
*/
|
|
2271
2281
|
async reset(config) {
|
|
2272
|
-
const {
|
|
2282
|
+
const { force = false } = config || {};
|
|
2273
2283
|
if (this.pingTimer) {
|
|
2274
2284
|
clearInterval(this.pingTimer);
|
|
2275
2285
|
this.pingTimer = void 0;
|
|
2276
2286
|
}
|
|
2277
|
-
if (
|
|
2287
|
+
if (force) {
|
|
2278
2288
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
2279
2289
|
event: "INCALL_RESET"
|
|
2280
2290
|
});
|
|
2281
2291
|
this.resetConnectState();
|
|
2282
|
-
this.setConnectAuthState("isConnected", false);
|
|
2283
2292
|
}
|
|
2284
2293
|
this.lastPingTime = void 0;
|
|
2285
|
-
this.setConnectAuthState("
|
|
2294
|
+
this.setConnectAuthState("startConfirm", false);
|
|
2286
2295
|
this.clearWebSocket();
|
|
2287
2296
|
}
|
|
2288
2297
|
attemptReconnect() {
|
|
@@ -2633,16 +2642,16 @@ var CallKit = class {
|
|
|
2633
2642
|
/**
|
|
2634
2643
|
* reset callkit
|
|
2635
2644
|
* @description recover the callkit to the initial state
|
|
2636
|
-
* @default
|
|
2637
|
-
* @param config.
|
|
2645
|
+
* @default force is false
|
|
2646
|
+
* @param config.force is true, the callkit reset socket connection and all states
|
|
2638
2647
|
*/
|
|
2639
2648
|
async reset(config) {
|
|
2640
|
-
const {
|
|
2649
|
+
const { force = false } = config || {};
|
|
2641
2650
|
this.logger.info("reset", {
|
|
2642
2651
|
caller: "CallKit.reset",
|
|
2643
2652
|
content: {
|
|
2644
2653
|
connectStatus: this.connect.connectStatus,
|
|
2645
|
-
|
|
2654
|
+
force
|
|
2646
2655
|
}
|
|
2647
2656
|
});
|
|
2648
2657
|
if (this.connect.isCalling()) {
|
|
@@ -2654,7 +2663,7 @@ var CallKit = class {
|
|
|
2654
2663
|
} else {
|
|
2655
2664
|
await this.config.reset();
|
|
2656
2665
|
}
|
|
2657
|
-
await this.socket.reset({
|
|
2666
|
+
await this.socket.reset({ force });
|
|
2658
2667
|
}
|
|
2659
2668
|
on(event, callback) {
|
|
2660
2669
|
this.listener.push({
|