@koi-design/callkit 2.3.0-beta.9 → 2.3.1-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 +37 -2
- package/dist/index.global.js +373 -41
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +368 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +368 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ var Api = class {
|
|
|
72
72
|
const res = await this.post({
|
|
73
73
|
url: "/auth/agentUser/login",
|
|
74
74
|
method: "post",
|
|
75
|
-
data: params
|
|
75
|
+
data: { ...params, browserVersion: navigator.userAgent }
|
|
76
76
|
});
|
|
77
77
|
return res;
|
|
78
78
|
} finally {
|
|
@@ -535,7 +535,11 @@ var SocketReceiveEvent = {
|
|
|
535
535
|
ERROR: "ERROR",
|
|
536
536
|
SESSION_ERROR: "SESSION_ERROR",
|
|
537
537
|
WAITING_QUEUE: "WAITING_QUEUE",
|
|
538
|
-
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE"
|
|
538
|
+
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE",
|
|
539
|
+
/**
|
|
540
|
+
* Agent RTP loss
|
|
541
|
+
*/
|
|
542
|
+
AGENT_RTP_LOSS: "AGENT_RTP_LOSS"
|
|
539
543
|
};
|
|
540
544
|
var EncryptionMethod = {
|
|
541
545
|
NONE: "NONE",
|
|
@@ -724,7 +728,7 @@ var Call = class {
|
|
|
724
728
|
// package.json
|
|
725
729
|
var package_default = {
|
|
726
730
|
name: "@koi-design/callkit",
|
|
727
|
-
version: "2.3.
|
|
731
|
+
version: "2.3.1-beta.1",
|
|
728
732
|
description: "callkit",
|
|
729
733
|
author: "koi",
|
|
730
734
|
license: "ISC",
|
|
@@ -15824,8 +15828,6 @@ var Connect = class {
|
|
|
15824
15828
|
});
|
|
15825
15829
|
return;
|
|
15826
15830
|
}
|
|
15827
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
15828
|
-
const { userPart, fsIp, fsPort } = userInfo;
|
|
15829
15831
|
const { registererOptions = {} } = this.reconnectConfig;
|
|
15830
15832
|
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
15831
15833
|
this.registerer.stateChange.addListener((state) => {
|
|
@@ -15859,27 +15861,26 @@ var Connect = class {
|
|
|
15859
15861
|
});
|
|
15860
15862
|
this.setRegister(true);
|
|
15861
15863
|
if (this.isReConnected) {
|
|
15862
|
-
if (this.
|
|
15863
|
-
const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
15864
|
+
if (this.canReferInCallToSelf()) {
|
|
15864
15865
|
this.callKit.logger.info(
|
|
15865
15866
|
"Reconnected, referring active session to self",
|
|
15866
15867
|
{
|
|
15867
15868
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
15868
15869
|
type: "SIP",
|
|
15869
15870
|
content: {
|
|
15870
|
-
selfUri,
|
|
15871
|
+
selfUri: this.getSelfReferUri(),
|
|
15871
15872
|
sessionState: this.currentSession.state,
|
|
15872
15873
|
connectStatus: this.connectStatus
|
|
15873
15874
|
}
|
|
15874
15875
|
}
|
|
15875
15876
|
);
|
|
15876
|
-
this.
|
|
15877
|
+
this.referInCallToSelf().catch((err) => {
|
|
15877
15878
|
this.callKit.logger.error(err, {
|
|
15878
15879
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
15879
15880
|
type: "SIP",
|
|
15880
15881
|
content: {
|
|
15881
15882
|
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
15882
|
-
selfUri
|
|
15883
|
+
selfUri: this.getSelfReferUri()
|
|
15883
15884
|
}
|
|
15884
15885
|
});
|
|
15885
15886
|
});
|
|
@@ -15985,7 +15986,7 @@ var Connect = class {
|
|
|
15985
15986
|
this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);
|
|
15986
15987
|
return this.mediaStream;
|
|
15987
15988
|
};
|
|
15988
|
-
const { userPart, fsIp, fsPort, iceInfo, wsUrl } = userInfo;
|
|
15989
|
+
const { userPart, fsIp, fsPort, fsPassword, iceInfo, wsUrl } = userInfo;
|
|
15989
15990
|
const connectConfig = {
|
|
15990
15991
|
uri: UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`),
|
|
15991
15992
|
displayName: userPart,
|
|
@@ -15995,6 +15996,8 @@ var Connect = class {
|
|
|
15995
15996
|
},
|
|
15996
15997
|
logLevel: "error",
|
|
15997
15998
|
allowLegacyNotifications: true,
|
|
15999
|
+
authorizationPassword: fsPassword,
|
|
16000
|
+
authorizationUsername: userPart,
|
|
15998
16001
|
contactName: userPart,
|
|
15999
16002
|
contactParams: { transport: "wss" },
|
|
16000
16003
|
sessionDescriptionHandlerFactory: web_exports.defaultSessionDescriptionHandlerFactory(localStreamFactory),
|
|
@@ -16708,6 +16711,199 @@ var Connect = class {
|
|
|
16708
16711
|
}
|
|
16709
16712
|
this.currentSession.refer(target, extra?.sessionReferOptions);
|
|
16710
16713
|
}
|
|
16714
|
+
/**
|
|
16715
|
+
* Get the SIP URI for "refer to self" (same as reconnection refer logic).
|
|
16716
|
+
* Shared by referInCallToSelf and internal reconnection refer.
|
|
16717
|
+
*/
|
|
16718
|
+
getSelfReferUri() {
|
|
16719
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16720
|
+
const { userPart, fsIp, fsPort } = userInfo;
|
|
16721
|
+
return `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
16722
|
+
}
|
|
16723
|
+
/**
|
|
16724
|
+
* Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
|
|
16725
|
+
* Shared by reconnection logic and referInCallToSelf.
|
|
16726
|
+
*/
|
|
16727
|
+
canReferInCallToSelf() {
|
|
16728
|
+
return !!this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling();
|
|
16729
|
+
}
|
|
16730
|
+
/**
|
|
16731
|
+
* Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
|
|
16732
|
+
* Socket and other callers can use this without constructing referTo.
|
|
16733
|
+
*/
|
|
16734
|
+
async referInCallToSelf(callUuid, extra) {
|
|
16735
|
+
if (callUuid && this.currentCallId !== callUuid) {
|
|
16736
|
+
this.callKit.logger.warn(
|
|
16737
|
+
"Cannot refer in call to self: callUuid mismatch",
|
|
16738
|
+
{
|
|
16739
|
+
caller: "Connect.referInCallToSelf",
|
|
16740
|
+
type: "SIP",
|
|
16741
|
+
content: {
|
|
16742
|
+
currentCallId: this.currentCallId,
|
|
16743
|
+
callUuid
|
|
16744
|
+
}
|
|
16745
|
+
}
|
|
16746
|
+
);
|
|
16747
|
+
return;
|
|
16748
|
+
}
|
|
16749
|
+
if (!this.canReferInCallToSelf()) {
|
|
16750
|
+
this.callKit.logger.warn(
|
|
16751
|
+
"Cannot refer in call to self: preconditions not met",
|
|
16752
|
+
{
|
|
16753
|
+
caller: "Connect.referInCallToSelf",
|
|
16754
|
+
type: "SIP",
|
|
16755
|
+
content: {
|
|
16756
|
+
hasCurrentSession: !!this.currentSession,
|
|
16757
|
+
sessionState: this.currentSession?.state,
|
|
16758
|
+
isCalling: this.isCalling()
|
|
16759
|
+
}
|
|
16760
|
+
}
|
|
16761
|
+
);
|
|
16762
|
+
return;
|
|
16763
|
+
}
|
|
16764
|
+
const selfUri = this.getSelfReferUri();
|
|
16765
|
+
return this.referInCall(selfUri, extra);
|
|
16766
|
+
}
|
|
16767
|
+
};
|
|
16768
|
+
|
|
16769
|
+
// core/heartbeat-worker.ts
|
|
16770
|
+
var workerCode = `
|
|
16771
|
+
let timer = null;
|
|
16772
|
+
let interval = 30000;
|
|
16773
|
+
|
|
16774
|
+
self.onmessage = function(e) {
|
|
16775
|
+
const { type, interval: newInterval } = e.data;
|
|
16776
|
+
|
|
16777
|
+
if (type === 'start') {
|
|
16778
|
+
if (timer) {
|
|
16779
|
+
clearInterval(timer);
|
|
16780
|
+
}
|
|
16781
|
+
interval = newInterval || interval;
|
|
16782
|
+
timer = setInterval(() => {
|
|
16783
|
+
self.postMessage({ type: 'tick' });
|
|
16784
|
+
}, interval);
|
|
16785
|
+
}
|
|
16786
|
+
|
|
16787
|
+
if (type === 'stop') {
|
|
16788
|
+
if (timer) {
|
|
16789
|
+
clearInterval(timer);
|
|
16790
|
+
timer = null;
|
|
16791
|
+
}
|
|
16792
|
+
}
|
|
16793
|
+
|
|
16794
|
+
if (type === 'updateInterval') {
|
|
16795
|
+
interval = newInterval;
|
|
16796
|
+
if (timer) {
|
|
16797
|
+
clearInterval(timer);
|
|
16798
|
+
timer = setInterval(() => {
|
|
16799
|
+
self.postMessage({ type: 'tick' });
|
|
16800
|
+
}, interval);
|
|
16801
|
+
}
|
|
16802
|
+
}
|
|
16803
|
+
};
|
|
16804
|
+
`;
|
|
16805
|
+
function createHeartbeatWorker() {
|
|
16806
|
+
try {
|
|
16807
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
16808
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
16809
|
+
const worker = new Worker(workerUrl);
|
|
16810
|
+
URL.revokeObjectURL(workerUrl);
|
|
16811
|
+
return worker;
|
|
16812
|
+
} catch {
|
|
16813
|
+
return null;
|
|
16814
|
+
}
|
|
16815
|
+
}
|
|
16816
|
+
var HeartbeatManager = class {
|
|
16817
|
+
worker = null;
|
|
16818
|
+
fallbackTimer = null;
|
|
16819
|
+
interval = 3e4;
|
|
16820
|
+
onTick = null;
|
|
16821
|
+
isRunning = false;
|
|
16822
|
+
constructor() {
|
|
16823
|
+
this.worker = createHeartbeatWorker();
|
|
16824
|
+
if (this.worker) {
|
|
16825
|
+
this.worker.onmessage = (e) => {
|
|
16826
|
+
if (e.data.type === "tick" && this.onTick) {
|
|
16827
|
+
this.onTick();
|
|
16828
|
+
}
|
|
16829
|
+
};
|
|
16830
|
+
}
|
|
16831
|
+
}
|
|
16832
|
+
/**
|
|
16833
|
+
* Start the heartbeat
|
|
16834
|
+
* @param interval - Interval in milliseconds
|
|
16835
|
+
* @param onTick - Callback function to execute on each tick
|
|
16836
|
+
*/
|
|
16837
|
+
start(interval, onTick) {
|
|
16838
|
+
this.stop();
|
|
16839
|
+
this.interval = interval;
|
|
16840
|
+
this.onTick = onTick;
|
|
16841
|
+
this.isRunning = true;
|
|
16842
|
+
if (this.worker) {
|
|
16843
|
+
this.worker.postMessage({
|
|
16844
|
+
type: "start",
|
|
16845
|
+
interval
|
|
16846
|
+
});
|
|
16847
|
+
} else {
|
|
16848
|
+
this.fallbackTimer = setInterval(() => {
|
|
16849
|
+
if (this.onTick) {
|
|
16850
|
+
this.onTick();
|
|
16851
|
+
}
|
|
16852
|
+
}, interval);
|
|
16853
|
+
}
|
|
16854
|
+
}
|
|
16855
|
+
/**
|
|
16856
|
+
* Stop the heartbeat
|
|
16857
|
+
*/
|
|
16858
|
+
stop() {
|
|
16859
|
+
this.isRunning = false;
|
|
16860
|
+
this.onTick = null;
|
|
16861
|
+
if (this.worker) {
|
|
16862
|
+
this.worker.postMessage({ type: "stop" });
|
|
16863
|
+
}
|
|
16864
|
+
if (this.fallbackTimer) {
|
|
16865
|
+
clearInterval(this.fallbackTimer);
|
|
16866
|
+
this.fallbackTimer = null;
|
|
16867
|
+
}
|
|
16868
|
+
}
|
|
16869
|
+
/**
|
|
16870
|
+
* Update the heartbeat interval
|
|
16871
|
+
* @param interval - New interval in milliseconds
|
|
16872
|
+
*/
|
|
16873
|
+
updateInterval(interval) {
|
|
16874
|
+
this.interval = interval;
|
|
16875
|
+
if (!this.isRunning)
|
|
16876
|
+
return;
|
|
16877
|
+
if (this.worker) {
|
|
16878
|
+
this.worker.postMessage({
|
|
16879
|
+
type: "updateInterval",
|
|
16880
|
+
interval
|
|
16881
|
+
});
|
|
16882
|
+
} else if (this.fallbackTimer && this.onTick) {
|
|
16883
|
+
clearInterval(this.fallbackTimer);
|
|
16884
|
+
this.fallbackTimer = setInterval(() => {
|
|
16885
|
+
if (this.onTick) {
|
|
16886
|
+
this.onTick();
|
|
16887
|
+
}
|
|
16888
|
+
}, interval);
|
|
16889
|
+
}
|
|
16890
|
+
}
|
|
16891
|
+
/**
|
|
16892
|
+
* Destroy the heartbeat manager and release resources
|
|
16893
|
+
*/
|
|
16894
|
+
destroy() {
|
|
16895
|
+
this.stop();
|
|
16896
|
+
if (this.worker) {
|
|
16897
|
+
this.worker.terminate();
|
|
16898
|
+
this.worker = null;
|
|
16899
|
+
}
|
|
16900
|
+
}
|
|
16901
|
+
/**
|
|
16902
|
+
* Check if using Web Worker
|
|
16903
|
+
*/
|
|
16904
|
+
isUsingWorker() {
|
|
16905
|
+
return this.worker !== null;
|
|
16906
|
+
}
|
|
16711
16907
|
};
|
|
16712
16908
|
|
|
16713
16909
|
// core/socket.ts
|
|
@@ -16715,7 +16911,7 @@ var Socket = class {
|
|
|
16715
16911
|
callKit;
|
|
16716
16912
|
ws;
|
|
16717
16913
|
lastPingTime = void 0;
|
|
16718
|
-
|
|
16914
|
+
heartbeatManager;
|
|
16719
16915
|
/**
|
|
16720
16916
|
* @description reconnect timer
|
|
16721
16917
|
*/
|
|
@@ -16748,9 +16944,32 @@ var Socket = class {
|
|
|
16748
16944
|
}
|
|
16749
16945
|
constructor(callKit) {
|
|
16750
16946
|
this.callKit = callKit;
|
|
16947
|
+
this.heartbeatManager = new HeartbeatManager();
|
|
16948
|
+
}
|
|
16949
|
+
get isUserSetPingTryCount() {
|
|
16950
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16951
|
+
const { pingTryCount } = userInfo;
|
|
16952
|
+
return Number.isInteger(pingTryCount) && pingTryCount > 0;
|
|
16751
16953
|
}
|
|
16752
16954
|
get reconnectConfig() {
|
|
16753
|
-
|
|
16955
|
+
const incallConfig = this.callKit.config.getReconnectConfig("incall");
|
|
16956
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16957
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
16958
|
+
if (pingTryCount > 0) {
|
|
16959
|
+
return {
|
|
16960
|
+
...incallConfig,
|
|
16961
|
+
maxAttempts: pingTryCount,
|
|
16962
|
+
interval: pingTryCountInterval * 1e3
|
|
16963
|
+
};
|
|
16964
|
+
}
|
|
16965
|
+
return incallConfig;
|
|
16966
|
+
}
|
|
16967
|
+
get pingInterval() {
|
|
16968
|
+
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
16969
|
+
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
16970
|
+
return keepaliveInterval * 1e3;
|
|
16971
|
+
}
|
|
16972
|
+
return this.reconnectConfig.pingInterval;
|
|
16754
16973
|
}
|
|
16755
16974
|
isConnected() {
|
|
16756
16975
|
return this.connectAuthState.isConnected;
|
|
@@ -16775,7 +16994,17 @@ var Socket = class {
|
|
|
16775
16994
|
this.setConnectAuthState("isConnected", false);
|
|
16776
16995
|
const { enabled } = this.reconnectConfig;
|
|
16777
16996
|
if (!this.callKit.config.isLogin() || !enabled) {
|
|
16778
|
-
this.callKit.
|
|
16997
|
+
if (this.callKit.connect.isCalling()) {
|
|
16998
|
+
this.callKit.logger.warn("Disconnect during call, delay reset", {
|
|
16999
|
+
caller: "Socket.handleDisconnect",
|
|
17000
|
+
type: "INCALL",
|
|
17001
|
+
content: {
|
|
17002
|
+
connectStatus: this.callKit.connect.connectStatus
|
|
17003
|
+
}
|
|
17004
|
+
});
|
|
17005
|
+
} else {
|
|
17006
|
+
this.callKit.reset();
|
|
17007
|
+
}
|
|
16779
17008
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
16780
17009
|
event: "INCALL_NOT_CONNECTED"
|
|
16781
17010
|
});
|
|
@@ -16933,6 +17162,28 @@ var Socket = class {
|
|
|
16933
17162
|
this.setConnectAuthState("startConfirm", true);
|
|
16934
17163
|
this.cleanReconnectState();
|
|
16935
17164
|
}
|
|
17165
|
+
if (data.event === SocketReceiveEvent.AGENT_RTP_LOSS) {
|
|
17166
|
+
this.callKit.logger.warn("Agent RTP loss", {
|
|
17167
|
+
caller: "Socket.onMessage",
|
|
17168
|
+
type: "INCALL",
|
|
17169
|
+
content: {
|
|
17170
|
+
data: {
|
|
17171
|
+
callUuid,
|
|
17172
|
+
...content
|
|
17173
|
+
},
|
|
17174
|
+
event: SocketReceiveEvent.AGENT_RTP_LOSS
|
|
17175
|
+
}
|
|
17176
|
+
});
|
|
17177
|
+
if (callUuid) {
|
|
17178
|
+
this.callKit.connect.referInCallToSelf(callUuid).catch((err) => {
|
|
17179
|
+
this.callKit.logger.error(err, {
|
|
17180
|
+
caller: "Socket.onMessage:AGENT_RTP_LOSS",
|
|
17181
|
+
type: "INCALL",
|
|
17182
|
+
content: { callUuid, event: SocketReceiveEvent.AGENT_RTP_LOSS }
|
|
17183
|
+
});
|
|
17184
|
+
});
|
|
17185
|
+
}
|
|
17186
|
+
}
|
|
16936
17187
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
16937
17188
|
this.callKit.trigger(KitEvent.CALL_RINGING, {
|
|
16938
17189
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -16981,6 +17232,18 @@ var Socket = class {
|
|
|
16981
17232
|
this.send(SocketSendEvent.END, { agentId: userInfo.agentId, callUuid });
|
|
16982
17233
|
}
|
|
16983
17234
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
17235
|
+
if (this.callKit.connect.isCalling()) {
|
|
17236
|
+
this.callKit.logger.warn("socket onMessage error during call, ignore", {
|
|
17237
|
+
caller: "Socket.onMessage",
|
|
17238
|
+
type: "INCALL",
|
|
17239
|
+
content: {
|
|
17240
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
17241
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17242
|
+
data: content
|
|
17243
|
+
}
|
|
17244
|
+
});
|
|
17245
|
+
return;
|
|
17246
|
+
}
|
|
16984
17247
|
this.setConnectAuthState("isError", true);
|
|
16985
17248
|
this.callKit.reset();
|
|
16986
17249
|
this.callKit.logger.error(data.msg, {
|
|
@@ -16989,20 +17252,24 @@ var Socket = class {
|
|
|
16989
17252
|
content: {
|
|
16990
17253
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
16991
17254
|
data: content,
|
|
16992
|
-
callUuid
|
|
17255
|
+
callUuid,
|
|
17256
|
+
delayReset: this.callKit.connect.isCalling()
|
|
16993
17257
|
}
|
|
16994
17258
|
});
|
|
16995
17259
|
}
|
|
16996
17260
|
if (data.event === SocketReceiveEvent.SESSION_ERROR) {
|
|
16997
17261
|
this.setConnectAuthState("isError", true);
|
|
16998
|
-
this.callKit.
|
|
17262
|
+
if (!this.callKit.connect.isCalling()) {
|
|
17263
|
+
this.callKit.reset();
|
|
17264
|
+
}
|
|
16999
17265
|
this.callKit.logger.error(data.msg, {
|
|
17000
17266
|
caller: `Socket.onMessage:${data.event}`,
|
|
17001
17267
|
type: "INCALL",
|
|
17002
17268
|
content: {
|
|
17003
17269
|
data: content,
|
|
17004
17270
|
event: SocketReceiveEvent.SESSION_ERROR,
|
|
17005
|
-
callUuid
|
|
17271
|
+
callUuid,
|
|
17272
|
+
delayReset: this.callKit.connect.isCalling()
|
|
17006
17273
|
}
|
|
17007
17274
|
});
|
|
17008
17275
|
}
|
|
@@ -17034,6 +17301,18 @@ var Socket = class {
|
|
|
17034
17301
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17035
17302
|
event: "INCALL_NOT_CONNECTED"
|
|
17036
17303
|
});
|
|
17304
|
+
if (this.callKit.connect.isCalling()) {
|
|
17305
|
+
this.callKit.logger.warn("socket send during call, ignore", {
|
|
17306
|
+
caller: "Socket.onMessage",
|
|
17307
|
+
type: "INCALL",
|
|
17308
|
+
content: {
|
|
17309
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
17310
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17311
|
+
data: message
|
|
17312
|
+
}
|
|
17313
|
+
});
|
|
17314
|
+
return;
|
|
17315
|
+
}
|
|
17037
17316
|
this.callKit.reset();
|
|
17038
17317
|
this.callKit.logger.error("socket not connected", {
|
|
17039
17318
|
caller: "Socket.send",
|
|
@@ -17086,8 +17365,8 @@ var Socket = class {
|
|
|
17086
17365
|
return;
|
|
17087
17366
|
this.send(SocketSendEvent.PING);
|
|
17088
17367
|
const now = Date.now();
|
|
17089
|
-
const {
|
|
17090
|
-
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17368
|
+
const { pingTimeout } = this.reconnectConfig;
|
|
17369
|
+
if (now - this.lastPingTime > this.pingInterval + pingTimeout) {
|
|
17091
17370
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17092
17371
|
caller: "Socket.ping",
|
|
17093
17372
|
type: "INCALL",
|
|
@@ -17099,26 +17378,48 @@ var Socket = class {
|
|
|
17099
17378
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17100
17379
|
event: "INCALL_PING_TIMEOUT"
|
|
17101
17380
|
});
|
|
17381
|
+
if (this.isUserSetPingTryCount) {
|
|
17382
|
+
this.handlePingTimeout();
|
|
17383
|
+
}
|
|
17102
17384
|
}
|
|
17103
17385
|
}
|
|
17386
|
+
handlePingTimeout() {
|
|
17387
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
17388
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
17389
|
+
this.callKit.logger.warn("Ping timeout, user set ping try count", {
|
|
17390
|
+
caller: "Socket.handlePingTimeout",
|
|
17391
|
+
type: "INCALL",
|
|
17392
|
+
content: {
|
|
17393
|
+
errCode: ErrorCode.SOCKET_PING_TIMEOUT,
|
|
17394
|
+
isUserSetPingTryCount: this.isUserSetPingTryCount,
|
|
17395
|
+
pingTryCount,
|
|
17396
|
+
pingTryCountInterval
|
|
17397
|
+
}
|
|
17398
|
+
});
|
|
17399
|
+
this.attemptReconnect();
|
|
17400
|
+
}
|
|
17104
17401
|
checkPing() {
|
|
17105
|
-
|
|
17106
|
-
clearInterval(this.pingTimer);
|
|
17107
|
-
}
|
|
17108
|
-
const { pingInterval } = this.reconnectConfig;
|
|
17109
|
-
this.pingTimer = setInterval(() => {
|
|
17402
|
+
this.heartbeatManager.start(this.pingInterval, () => {
|
|
17110
17403
|
this.ping();
|
|
17111
|
-
}
|
|
17404
|
+
});
|
|
17405
|
+
this.callKit.logger.info(
|
|
17406
|
+
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
17407
|
+
{
|
|
17408
|
+
caller: "Socket.checkPing",
|
|
17409
|
+
type: "INCALL",
|
|
17410
|
+
content: {
|
|
17411
|
+
pingInterval: this.pingInterval,
|
|
17412
|
+
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
17413
|
+
}
|
|
17414
|
+
}
|
|
17415
|
+
);
|
|
17112
17416
|
}
|
|
17113
17417
|
/**
|
|
17114
17418
|
* reset socket connection and all states
|
|
17115
17419
|
*/
|
|
17116
17420
|
async reset(config) {
|
|
17117
17421
|
const { force = false } = config || {};
|
|
17118
|
-
|
|
17119
|
-
clearInterval(this.pingTimer);
|
|
17120
|
-
this.pingTimer = void 0;
|
|
17121
|
-
}
|
|
17422
|
+
this.heartbeatManager.stop();
|
|
17122
17423
|
if (force) {
|
|
17123
17424
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17124
17425
|
event: "INCALL_RESET"
|
|
@@ -17129,6 +17430,12 @@ var Socket = class {
|
|
|
17129
17430
|
this.setConnectAuthState("startConfirm", false);
|
|
17130
17431
|
this.clearWebSocket();
|
|
17131
17432
|
}
|
|
17433
|
+
/**
|
|
17434
|
+
* Destroy the heartbeat manager
|
|
17435
|
+
*/
|
|
17436
|
+
destroyHeartbeat() {
|
|
17437
|
+
this.heartbeatManager.destroy();
|
|
17438
|
+
}
|
|
17132
17439
|
attemptReconnect() {
|
|
17133
17440
|
if (this.reconnectTimer) {
|
|
17134
17441
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17136,19 +17443,40 @@ var Socket = class {
|
|
|
17136
17443
|
}
|
|
17137
17444
|
const { maxAttempts } = this.reconnectConfig;
|
|
17138
17445
|
if (this.reconnectAttempts >= maxAttempts) {
|
|
17446
|
+
if (this.callKit.connect.isCalling()) {
|
|
17447
|
+
this.callKit.logger.warn("reconnect during call, ignore", {
|
|
17448
|
+
caller: "Socket.attemptReconnect",
|
|
17449
|
+
type: "INCALL",
|
|
17450
|
+
content: {
|
|
17451
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
17452
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17453
|
+
reconnectAttempts: this.reconnectAttempts
|
|
17454
|
+
}
|
|
17455
|
+
});
|
|
17456
|
+
return;
|
|
17457
|
+
}
|
|
17458
|
+
if (this.isUserSetPingTryCount) {
|
|
17459
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17460
|
+
event: "INCALL_PING_TIMEOUT_RECONNECT_FAILED_MAX_ATTEMPTS"
|
|
17461
|
+
});
|
|
17462
|
+
}
|
|
17139
17463
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17140
17464
|
event: "INCALL_RECONNECT_ERROR"
|
|
17141
17465
|
});
|
|
17142
17466
|
this.setConnectAuthState("isError", true);
|
|
17143
17467
|
this.callKit.reset();
|
|
17144
|
-
this.callKit.logger.
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17468
|
+
this.callKit.logger.warn(
|
|
17469
|
+
"Maximum reconnection attempts reached, trigger reset",
|
|
17470
|
+
{
|
|
17471
|
+
caller: "Socket.attemptReconnect",
|
|
17472
|
+
type: "INCALL",
|
|
17473
|
+
content: {
|
|
17474
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
17475
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
17476
|
+
delayReset: this.callKit.connect.isCalling()
|
|
17477
|
+
}
|
|
17150
17478
|
}
|
|
17151
|
-
|
|
17479
|
+
);
|
|
17152
17480
|
return;
|
|
17153
17481
|
}
|
|
17154
17482
|
if (this.reconnectAttempts === 0) {
|
|
@@ -17254,6 +17582,7 @@ var CallKit = class {
|
|
|
17254
17582
|
content: {
|
|
17255
17583
|
username,
|
|
17256
17584
|
password,
|
|
17585
|
+
ua: navigator.userAgent,
|
|
17257
17586
|
encryptionMethod,
|
|
17258
17587
|
encryptionPassword
|
|
17259
17588
|
}
|
|
@@ -17287,6 +17616,9 @@ var CallKit = class {
|
|
|
17287
17616
|
iceInfo: user.iceInfo,
|
|
17288
17617
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17289
17618
|
logGather: user.logGather,
|
|
17619
|
+
keepaliveInterval: user.keepaliveInterval,
|
|
17620
|
+
pingTryCount: user?.pingTryCount,
|
|
17621
|
+
pingTryCountInterval: user?.pingTryCountInterval,
|
|
17290
17622
|
phoneType: user.phoneType,
|
|
17291
17623
|
// encryptionType is in extra
|
|
17292
17624
|
...extra
|