@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.global.js
CHANGED
|
@@ -1736,7 +1736,7 @@ var WebCall = (() => {
|
|
|
1736
1736
|
var require_follow_redirects = __commonJS({
|
|
1737
1737
|
"../../node_modules/.pnpm/follow-redirects@1.15.9/node_modules/follow-redirects/index.js"(exports, module) {
|
|
1738
1738
|
var url = __require("url");
|
|
1739
|
-
var
|
|
1739
|
+
var URL2 = url.URL;
|
|
1740
1740
|
var http = __require("http");
|
|
1741
1741
|
var https = __require("https");
|
|
1742
1742
|
var Writable = __require("stream").Writable;
|
|
@@ -1752,7 +1752,7 @@ var WebCall = (() => {
|
|
|
1752
1752
|
})();
|
|
1753
1753
|
var useNativeURL = false;
|
|
1754
1754
|
try {
|
|
1755
|
-
assert(new
|
|
1755
|
+
assert(new URL2(""));
|
|
1756
1756
|
} catch (error) {
|
|
1757
1757
|
useNativeURL = error.code === "ERR_INVALID_URL";
|
|
1758
1758
|
}
|
|
@@ -2132,7 +2132,7 @@ var WebCall = (() => {
|
|
|
2132
2132
|
function parseUrl(input) {
|
|
2133
2133
|
var parsed;
|
|
2134
2134
|
if (useNativeURL) {
|
|
2135
|
-
parsed = new
|
|
2135
|
+
parsed = new URL2(input);
|
|
2136
2136
|
} else {
|
|
2137
2137
|
parsed = validateUrl(url.parse(input));
|
|
2138
2138
|
if (!isString(parsed.protocol)) {
|
|
@@ -2142,7 +2142,7 @@ var WebCall = (() => {
|
|
|
2142
2142
|
return parsed;
|
|
2143
2143
|
}
|
|
2144
2144
|
function resolveUrl(relative, base) {
|
|
2145
|
-
return useNativeURL ? new
|
|
2145
|
+
return useNativeURL ? new URL2(relative, base) : parseUrl(url.resolve(base, relative));
|
|
2146
2146
|
}
|
|
2147
2147
|
function validateUrl(input) {
|
|
2148
2148
|
if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
|
|
@@ -2221,7 +2221,7 @@ var WebCall = (() => {
|
|
|
2221
2221
|
return typeof value === "object" && "length" in value;
|
|
2222
2222
|
}
|
|
2223
2223
|
function isURL(value) {
|
|
2224
|
-
return
|
|
2224
|
+
return URL2 && value instanceof URL2;
|
|
2225
2225
|
}
|
|
2226
2226
|
module.exports = wrap({ http, https });
|
|
2227
2227
|
module.exports.wrap = wrap;
|
|
@@ -3237,7 +3237,7 @@ var WebCall = (() => {
|
|
|
3237
3237
|
const res = await this.post({
|
|
3238
3238
|
url: "/auth/agentUser/login",
|
|
3239
3239
|
method: "post",
|
|
3240
|
-
data: params
|
|
3240
|
+
data: { ...params, browserVersion: navigator.userAgent }
|
|
3241
3241
|
});
|
|
3242
3242
|
return res;
|
|
3243
3243
|
} finally {
|
|
@@ -3700,7 +3700,11 @@ var WebCall = (() => {
|
|
|
3700
3700
|
ERROR: "ERROR",
|
|
3701
3701
|
SESSION_ERROR: "SESSION_ERROR",
|
|
3702
3702
|
WAITING_QUEUE: "WAITING_QUEUE",
|
|
3703
|
-
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE"
|
|
3703
|
+
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE",
|
|
3704
|
+
/**
|
|
3705
|
+
* Agent RTP loss
|
|
3706
|
+
*/
|
|
3707
|
+
AGENT_RTP_LOSS: "AGENT_RTP_LOSS"
|
|
3704
3708
|
};
|
|
3705
3709
|
var EncryptionMethod = {
|
|
3706
3710
|
NONE: "NONE",
|
|
@@ -3889,7 +3893,7 @@ var WebCall = (() => {
|
|
|
3889
3893
|
// package.json
|
|
3890
3894
|
var package_default = {
|
|
3891
3895
|
name: "@koi-design/callkit",
|
|
3892
|
-
version: "2.3.
|
|
3896
|
+
version: "2.3.1-beta.1",
|
|
3893
3897
|
description: "callkit",
|
|
3894
3898
|
author: "koi",
|
|
3895
3899
|
license: "ISC",
|
|
@@ -18989,8 +18993,6 @@ ${log}` : log;
|
|
|
18989
18993
|
});
|
|
18990
18994
|
return;
|
|
18991
18995
|
}
|
|
18992
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
18993
|
-
const { userPart, fsIp, fsPort } = userInfo;
|
|
18994
18996
|
const { registererOptions = {} } = this.reconnectConfig;
|
|
18995
18997
|
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
18996
18998
|
this.registerer.stateChange.addListener((state) => {
|
|
@@ -19024,27 +19026,26 @@ ${log}` : log;
|
|
|
19024
19026
|
});
|
|
19025
19027
|
this.setRegister(true);
|
|
19026
19028
|
if (this.isReConnected) {
|
|
19027
|
-
if (this.
|
|
19028
|
-
const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
19029
|
+
if (this.canReferInCallToSelf()) {
|
|
19029
19030
|
this.callKit.logger.info(
|
|
19030
19031
|
"Reconnected, referring active session to self",
|
|
19031
19032
|
{
|
|
19032
19033
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
19033
19034
|
type: "SIP",
|
|
19034
19035
|
content: {
|
|
19035
|
-
selfUri,
|
|
19036
|
+
selfUri: this.getSelfReferUri(),
|
|
19036
19037
|
sessionState: this.currentSession.state,
|
|
19037
19038
|
connectStatus: this.connectStatus
|
|
19038
19039
|
}
|
|
19039
19040
|
}
|
|
19040
19041
|
);
|
|
19041
|
-
this.
|
|
19042
|
+
this.referInCallToSelf().catch((err) => {
|
|
19042
19043
|
this.callKit.logger.error(err, {
|
|
19043
19044
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
19044
19045
|
type: "SIP",
|
|
19045
19046
|
content: {
|
|
19046
19047
|
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
19047
|
-
selfUri
|
|
19048
|
+
selfUri: this.getSelfReferUri()
|
|
19048
19049
|
}
|
|
19049
19050
|
});
|
|
19050
19051
|
});
|
|
@@ -19150,7 +19151,7 @@ ${log}` : log;
|
|
|
19150
19151
|
this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);
|
|
19151
19152
|
return this.mediaStream;
|
|
19152
19153
|
};
|
|
19153
|
-
const { userPart, fsIp, fsPort, iceInfo, wsUrl } = userInfo;
|
|
19154
|
+
const { userPart, fsIp, fsPort, fsPassword, iceInfo, wsUrl } = userInfo;
|
|
19154
19155
|
const connectConfig = {
|
|
19155
19156
|
uri: UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`),
|
|
19156
19157
|
displayName: userPart,
|
|
@@ -19160,6 +19161,8 @@ ${log}` : log;
|
|
|
19160
19161
|
},
|
|
19161
19162
|
logLevel: "error",
|
|
19162
19163
|
allowLegacyNotifications: true,
|
|
19164
|
+
authorizationPassword: fsPassword,
|
|
19165
|
+
authorizationUsername: userPart,
|
|
19163
19166
|
contactName: userPart,
|
|
19164
19167
|
contactParams: { transport: "wss" },
|
|
19165
19168
|
sessionDescriptionHandlerFactory: web_exports.defaultSessionDescriptionHandlerFactory(localStreamFactory),
|
|
@@ -19873,6 +19876,199 @@ ${log}` : log;
|
|
|
19873
19876
|
}
|
|
19874
19877
|
this.currentSession.refer(target, extra?.sessionReferOptions);
|
|
19875
19878
|
}
|
|
19879
|
+
/**
|
|
19880
|
+
* Get the SIP URI for "refer to self" (same as reconnection refer logic).
|
|
19881
|
+
* Shared by referInCallToSelf and internal reconnection refer.
|
|
19882
|
+
*/
|
|
19883
|
+
getSelfReferUri() {
|
|
19884
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
19885
|
+
const { userPart, fsIp, fsPort } = userInfo;
|
|
19886
|
+
return `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
19887
|
+
}
|
|
19888
|
+
/**
|
|
19889
|
+
* Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
|
|
19890
|
+
* Shared by reconnection logic and referInCallToSelf.
|
|
19891
|
+
*/
|
|
19892
|
+
canReferInCallToSelf() {
|
|
19893
|
+
return !!this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling();
|
|
19894
|
+
}
|
|
19895
|
+
/**
|
|
19896
|
+
* Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
|
|
19897
|
+
* Socket and other callers can use this without constructing referTo.
|
|
19898
|
+
*/
|
|
19899
|
+
async referInCallToSelf(callUuid, extra) {
|
|
19900
|
+
if (callUuid && this.currentCallId !== callUuid) {
|
|
19901
|
+
this.callKit.logger.warn(
|
|
19902
|
+
"Cannot refer in call to self: callUuid mismatch",
|
|
19903
|
+
{
|
|
19904
|
+
caller: "Connect.referInCallToSelf",
|
|
19905
|
+
type: "SIP",
|
|
19906
|
+
content: {
|
|
19907
|
+
currentCallId: this.currentCallId,
|
|
19908
|
+
callUuid
|
|
19909
|
+
}
|
|
19910
|
+
}
|
|
19911
|
+
);
|
|
19912
|
+
return;
|
|
19913
|
+
}
|
|
19914
|
+
if (!this.canReferInCallToSelf()) {
|
|
19915
|
+
this.callKit.logger.warn(
|
|
19916
|
+
"Cannot refer in call to self: preconditions not met",
|
|
19917
|
+
{
|
|
19918
|
+
caller: "Connect.referInCallToSelf",
|
|
19919
|
+
type: "SIP",
|
|
19920
|
+
content: {
|
|
19921
|
+
hasCurrentSession: !!this.currentSession,
|
|
19922
|
+
sessionState: this.currentSession?.state,
|
|
19923
|
+
isCalling: this.isCalling()
|
|
19924
|
+
}
|
|
19925
|
+
}
|
|
19926
|
+
);
|
|
19927
|
+
return;
|
|
19928
|
+
}
|
|
19929
|
+
const selfUri = this.getSelfReferUri();
|
|
19930
|
+
return this.referInCall(selfUri, extra);
|
|
19931
|
+
}
|
|
19932
|
+
};
|
|
19933
|
+
|
|
19934
|
+
// core/heartbeat-worker.ts
|
|
19935
|
+
var workerCode = `
|
|
19936
|
+
let timer = null;
|
|
19937
|
+
let interval = 30000;
|
|
19938
|
+
|
|
19939
|
+
self.onmessage = function(e) {
|
|
19940
|
+
const { type, interval: newInterval } = e.data;
|
|
19941
|
+
|
|
19942
|
+
if (type === 'start') {
|
|
19943
|
+
if (timer) {
|
|
19944
|
+
clearInterval(timer);
|
|
19945
|
+
}
|
|
19946
|
+
interval = newInterval || interval;
|
|
19947
|
+
timer = setInterval(() => {
|
|
19948
|
+
self.postMessage({ type: 'tick' });
|
|
19949
|
+
}, interval);
|
|
19950
|
+
}
|
|
19951
|
+
|
|
19952
|
+
if (type === 'stop') {
|
|
19953
|
+
if (timer) {
|
|
19954
|
+
clearInterval(timer);
|
|
19955
|
+
timer = null;
|
|
19956
|
+
}
|
|
19957
|
+
}
|
|
19958
|
+
|
|
19959
|
+
if (type === 'updateInterval') {
|
|
19960
|
+
interval = newInterval;
|
|
19961
|
+
if (timer) {
|
|
19962
|
+
clearInterval(timer);
|
|
19963
|
+
timer = setInterval(() => {
|
|
19964
|
+
self.postMessage({ type: 'tick' });
|
|
19965
|
+
}, interval);
|
|
19966
|
+
}
|
|
19967
|
+
}
|
|
19968
|
+
};
|
|
19969
|
+
`;
|
|
19970
|
+
function createHeartbeatWorker() {
|
|
19971
|
+
try {
|
|
19972
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
19973
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
19974
|
+
const worker = new Worker(workerUrl);
|
|
19975
|
+
URL.revokeObjectURL(workerUrl);
|
|
19976
|
+
return worker;
|
|
19977
|
+
} catch {
|
|
19978
|
+
return null;
|
|
19979
|
+
}
|
|
19980
|
+
}
|
|
19981
|
+
var HeartbeatManager = class {
|
|
19982
|
+
worker = null;
|
|
19983
|
+
fallbackTimer = null;
|
|
19984
|
+
interval = 3e4;
|
|
19985
|
+
onTick = null;
|
|
19986
|
+
isRunning = false;
|
|
19987
|
+
constructor() {
|
|
19988
|
+
this.worker = createHeartbeatWorker();
|
|
19989
|
+
if (this.worker) {
|
|
19990
|
+
this.worker.onmessage = (e) => {
|
|
19991
|
+
if (e.data.type === "tick" && this.onTick) {
|
|
19992
|
+
this.onTick();
|
|
19993
|
+
}
|
|
19994
|
+
};
|
|
19995
|
+
}
|
|
19996
|
+
}
|
|
19997
|
+
/**
|
|
19998
|
+
* Start the heartbeat
|
|
19999
|
+
* @param interval - Interval in milliseconds
|
|
20000
|
+
* @param onTick - Callback function to execute on each tick
|
|
20001
|
+
*/
|
|
20002
|
+
start(interval, onTick) {
|
|
20003
|
+
this.stop();
|
|
20004
|
+
this.interval = interval;
|
|
20005
|
+
this.onTick = onTick;
|
|
20006
|
+
this.isRunning = true;
|
|
20007
|
+
if (this.worker) {
|
|
20008
|
+
this.worker.postMessage({
|
|
20009
|
+
type: "start",
|
|
20010
|
+
interval
|
|
20011
|
+
});
|
|
20012
|
+
} else {
|
|
20013
|
+
this.fallbackTimer = setInterval(() => {
|
|
20014
|
+
if (this.onTick) {
|
|
20015
|
+
this.onTick();
|
|
20016
|
+
}
|
|
20017
|
+
}, interval);
|
|
20018
|
+
}
|
|
20019
|
+
}
|
|
20020
|
+
/**
|
|
20021
|
+
* Stop the heartbeat
|
|
20022
|
+
*/
|
|
20023
|
+
stop() {
|
|
20024
|
+
this.isRunning = false;
|
|
20025
|
+
this.onTick = null;
|
|
20026
|
+
if (this.worker) {
|
|
20027
|
+
this.worker.postMessage({ type: "stop" });
|
|
20028
|
+
}
|
|
20029
|
+
if (this.fallbackTimer) {
|
|
20030
|
+
clearInterval(this.fallbackTimer);
|
|
20031
|
+
this.fallbackTimer = null;
|
|
20032
|
+
}
|
|
20033
|
+
}
|
|
20034
|
+
/**
|
|
20035
|
+
* Update the heartbeat interval
|
|
20036
|
+
* @param interval - New interval in milliseconds
|
|
20037
|
+
*/
|
|
20038
|
+
updateInterval(interval) {
|
|
20039
|
+
this.interval = interval;
|
|
20040
|
+
if (!this.isRunning)
|
|
20041
|
+
return;
|
|
20042
|
+
if (this.worker) {
|
|
20043
|
+
this.worker.postMessage({
|
|
20044
|
+
type: "updateInterval",
|
|
20045
|
+
interval
|
|
20046
|
+
});
|
|
20047
|
+
} else if (this.fallbackTimer && this.onTick) {
|
|
20048
|
+
clearInterval(this.fallbackTimer);
|
|
20049
|
+
this.fallbackTimer = setInterval(() => {
|
|
20050
|
+
if (this.onTick) {
|
|
20051
|
+
this.onTick();
|
|
20052
|
+
}
|
|
20053
|
+
}, interval);
|
|
20054
|
+
}
|
|
20055
|
+
}
|
|
20056
|
+
/**
|
|
20057
|
+
* Destroy the heartbeat manager and release resources
|
|
20058
|
+
*/
|
|
20059
|
+
destroy() {
|
|
20060
|
+
this.stop();
|
|
20061
|
+
if (this.worker) {
|
|
20062
|
+
this.worker.terminate();
|
|
20063
|
+
this.worker = null;
|
|
20064
|
+
}
|
|
20065
|
+
}
|
|
20066
|
+
/**
|
|
20067
|
+
* Check if using Web Worker
|
|
20068
|
+
*/
|
|
20069
|
+
isUsingWorker() {
|
|
20070
|
+
return this.worker !== null;
|
|
20071
|
+
}
|
|
19876
20072
|
};
|
|
19877
20073
|
|
|
19878
20074
|
// core/socket.ts
|
|
@@ -19880,7 +20076,7 @@ ${log}` : log;
|
|
|
19880
20076
|
callKit;
|
|
19881
20077
|
ws;
|
|
19882
20078
|
lastPingTime = void 0;
|
|
19883
|
-
|
|
20079
|
+
heartbeatManager;
|
|
19884
20080
|
/**
|
|
19885
20081
|
* @description reconnect timer
|
|
19886
20082
|
*/
|
|
@@ -19913,9 +20109,32 @@ ${log}` : log;
|
|
|
19913
20109
|
}
|
|
19914
20110
|
constructor(callKit) {
|
|
19915
20111
|
this.callKit = callKit;
|
|
20112
|
+
this.heartbeatManager = new HeartbeatManager();
|
|
20113
|
+
}
|
|
20114
|
+
get isUserSetPingTryCount() {
|
|
20115
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
20116
|
+
const { pingTryCount } = userInfo;
|
|
20117
|
+
return Number.isInteger(pingTryCount) && pingTryCount > 0;
|
|
19916
20118
|
}
|
|
19917
20119
|
get reconnectConfig() {
|
|
19918
|
-
|
|
20120
|
+
const incallConfig = this.callKit.config.getReconnectConfig("incall");
|
|
20121
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
20122
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
20123
|
+
if (pingTryCount > 0) {
|
|
20124
|
+
return {
|
|
20125
|
+
...incallConfig,
|
|
20126
|
+
maxAttempts: pingTryCount,
|
|
20127
|
+
interval: pingTryCountInterval * 1e3
|
|
20128
|
+
};
|
|
20129
|
+
}
|
|
20130
|
+
return incallConfig;
|
|
20131
|
+
}
|
|
20132
|
+
get pingInterval() {
|
|
20133
|
+
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
20134
|
+
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
20135
|
+
return keepaliveInterval * 1e3;
|
|
20136
|
+
}
|
|
20137
|
+
return this.reconnectConfig.pingInterval;
|
|
19919
20138
|
}
|
|
19920
20139
|
isConnected() {
|
|
19921
20140
|
return this.connectAuthState.isConnected;
|
|
@@ -19940,7 +20159,17 @@ ${log}` : log;
|
|
|
19940
20159
|
this.setConnectAuthState("isConnected", false);
|
|
19941
20160
|
const { enabled } = this.reconnectConfig;
|
|
19942
20161
|
if (!this.callKit.config.isLogin() || !enabled) {
|
|
19943
|
-
this.callKit.
|
|
20162
|
+
if (this.callKit.connect.isCalling()) {
|
|
20163
|
+
this.callKit.logger.warn("Disconnect during call, delay reset", {
|
|
20164
|
+
caller: "Socket.handleDisconnect",
|
|
20165
|
+
type: "INCALL",
|
|
20166
|
+
content: {
|
|
20167
|
+
connectStatus: this.callKit.connect.connectStatus
|
|
20168
|
+
}
|
|
20169
|
+
});
|
|
20170
|
+
} else {
|
|
20171
|
+
this.callKit.reset();
|
|
20172
|
+
}
|
|
19944
20173
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19945
20174
|
event: "INCALL_NOT_CONNECTED"
|
|
19946
20175
|
});
|
|
@@ -20098,6 +20327,28 @@ ${log}` : log;
|
|
|
20098
20327
|
this.setConnectAuthState("startConfirm", true);
|
|
20099
20328
|
this.cleanReconnectState();
|
|
20100
20329
|
}
|
|
20330
|
+
if (data.event === SocketReceiveEvent.AGENT_RTP_LOSS) {
|
|
20331
|
+
this.callKit.logger.warn("Agent RTP loss", {
|
|
20332
|
+
caller: "Socket.onMessage",
|
|
20333
|
+
type: "INCALL",
|
|
20334
|
+
content: {
|
|
20335
|
+
data: {
|
|
20336
|
+
callUuid,
|
|
20337
|
+
...content
|
|
20338
|
+
},
|
|
20339
|
+
event: SocketReceiveEvent.AGENT_RTP_LOSS
|
|
20340
|
+
}
|
|
20341
|
+
});
|
|
20342
|
+
if (callUuid) {
|
|
20343
|
+
this.callKit.connect.referInCallToSelf(callUuid).catch((err) => {
|
|
20344
|
+
this.callKit.logger.error(err, {
|
|
20345
|
+
caller: "Socket.onMessage:AGENT_RTP_LOSS",
|
|
20346
|
+
type: "INCALL",
|
|
20347
|
+
content: { callUuid, event: SocketReceiveEvent.AGENT_RTP_LOSS }
|
|
20348
|
+
});
|
|
20349
|
+
});
|
|
20350
|
+
}
|
|
20351
|
+
}
|
|
20101
20352
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
20102
20353
|
this.callKit.trigger(KitEvent.CALL_RINGING, {
|
|
20103
20354
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -20146,6 +20397,18 @@ ${log}` : log;
|
|
|
20146
20397
|
this.send(SocketSendEvent.END, { agentId: userInfo.agentId, callUuid });
|
|
20147
20398
|
}
|
|
20148
20399
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
20400
|
+
if (this.callKit.connect.isCalling()) {
|
|
20401
|
+
this.callKit.logger.warn("socket onMessage error during call, ignore", {
|
|
20402
|
+
caller: "Socket.onMessage",
|
|
20403
|
+
type: "INCALL",
|
|
20404
|
+
content: {
|
|
20405
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
20406
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
20407
|
+
data: content
|
|
20408
|
+
}
|
|
20409
|
+
});
|
|
20410
|
+
return;
|
|
20411
|
+
}
|
|
20149
20412
|
this.setConnectAuthState("isError", true);
|
|
20150
20413
|
this.callKit.reset();
|
|
20151
20414
|
this.callKit.logger.error(data.msg, {
|
|
@@ -20154,20 +20417,24 @@ ${log}` : log;
|
|
|
20154
20417
|
content: {
|
|
20155
20418
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
20156
20419
|
data: content,
|
|
20157
|
-
callUuid
|
|
20420
|
+
callUuid,
|
|
20421
|
+
delayReset: this.callKit.connect.isCalling()
|
|
20158
20422
|
}
|
|
20159
20423
|
});
|
|
20160
20424
|
}
|
|
20161
20425
|
if (data.event === SocketReceiveEvent.SESSION_ERROR) {
|
|
20162
20426
|
this.setConnectAuthState("isError", true);
|
|
20163
|
-
this.callKit.
|
|
20427
|
+
if (!this.callKit.connect.isCalling()) {
|
|
20428
|
+
this.callKit.reset();
|
|
20429
|
+
}
|
|
20164
20430
|
this.callKit.logger.error(data.msg, {
|
|
20165
20431
|
caller: `Socket.onMessage:${data.event}`,
|
|
20166
20432
|
type: "INCALL",
|
|
20167
20433
|
content: {
|
|
20168
20434
|
data: content,
|
|
20169
20435
|
event: SocketReceiveEvent.SESSION_ERROR,
|
|
20170
|
-
callUuid
|
|
20436
|
+
callUuid,
|
|
20437
|
+
delayReset: this.callKit.connect.isCalling()
|
|
20171
20438
|
}
|
|
20172
20439
|
});
|
|
20173
20440
|
}
|
|
@@ -20199,6 +20466,18 @@ ${log}` : log;
|
|
|
20199
20466
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20200
20467
|
event: "INCALL_NOT_CONNECTED"
|
|
20201
20468
|
});
|
|
20469
|
+
if (this.callKit.connect.isCalling()) {
|
|
20470
|
+
this.callKit.logger.warn("socket send during call, ignore", {
|
|
20471
|
+
caller: "Socket.onMessage",
|
|
20472
|
+
type: "INCALL",
|
|
20473
|
+
content: {
|
|
20474
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
20475
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
20476
|
+
data: message
|
|
20477
|
+
}
|
|
20478
|
+
});
|
|
20479
|
+
return;
|
|
20480
|
+
}
|
|
20202
20481
|
this.callKit.reset();
|
|
20203
20482
|
this.callKit.logger.error("socket not connected", {
|
|
20204
20483
|
caller: "Socket.send",
|
|
@@ -20251,8 +20530,8 @@ ${log}` : log;
|
|
|
20251
20530
|
return;
|
|
20252
20531
|
this.send(SocketSendEvent.PING);
|
|
20253
20532
|
const now = Date.now();
|
|
20254
|
-
const {
|
|
20255
|
-
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
20533
|
+
const { pingTimeout } = this.reconnectConfig;
|
|
20534
|
+
if (now - this.lastPingTime > this.pingInterval + pingTimeout) {
|
|
20256
20535
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
20257
20536
|
caller: "Socket.ping",
|
|
20258
20537
|
type: "INCALL",
|
|
@@ -20264,26 +20543,48 @@ ${log}` : log;
|
|
|
20264
20543
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20265
20544
|
event: "INCALL_PING_TIMEOUT"
|
|
20266
20545
|
});
|
|
20546
|
+
if (this.isUserSetPingTryCount) {
|
|
20547
|
+
this.handlePingTimeout();
|
|
20548
|
+
}
|
|
20267
20549
|
}
|
|
20268
20550
|
}
|
|
20551
|
+
handlePingTimeout() {
|
|
20552
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
20553
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
20554
|
+
this.callKit.logger.warn("Ping timeout, user set ping try count", {
|
|
20555
|
+
caller: "Socket.handlePingTimeout",
|
|
20556
|
+
type: "INCALL",
|
|
20557
|
+
content: {
|
|
20558
|
+
errCode: ErrorCode.SOCKET_PING_TIMEOUT,
|
|
20559
|
+
isUserSetPingTryCount: this.isUserSetPingTryCount,
|
|
20560
|
+
pingTryCount,
|
|
20561
|
+
pingTryCountInterval
|
|
20562
|
+
}
|
|
20563
|
+
});
|
|
20564
|
+
this.attemptReconnect();
|
|
20565
|
+
}
|
|
20269
20566
|
checkPing() {
|
|
20270
|
-
|
|
20271
|
-
clearInterval(this.pingTimer);
|
|
20272
|
-
}
|
|
20273
|
-
const { pingInterval } = this.reconnectConfig;
|
|
20274
|
-
this.pingTimer = setInterval(() => {
|
|
20567
|
+
this.heartbeatManager.start(this.pingInterval, () => {
|
|
20275
20568
|
this.ping();
|
|
20276
|
-
}
|
|
20569
|
+
});
|
|
20570
|
+
this.callKit.logger.info(
|
|
20571
|
+
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
20572
|
+
{
|
|
20573
|
+
caller: "Socket.checkPing",
|
|
20574
|
+
type: "INCALL",
|
|
20575
|
+
content: {
|
|
20576
|
+
pingInterval: this.pingInterval,
|
|
20577
|
+
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
20578
|
+
}
|
|
20579
|
+
}
|
|
20580
|
+
);
|
|
20277
20581
|
}
|
|
20278
20582
|
/**
|
|
20279
20583
|
* reset socket connection and all states
|
|
20280
20584
|
*/
|
|
20281
20585
|
async reset(config) {
|
|
20282
20586
|
const { force = false } = config || {};
|
|
20283
|
-
|
|
20284
|
-
clearInterval(this.pingTimer);
|
|
20285
|
-
this.pingTimer = void 0;
|
|
20286
|
-
}
|
|
20587
|
+
this.heartbeatManager.stop();
|
|
20287
20588
|
if (force) {
|
|
20288
20589
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20289
20590
|
event: "INCALL_RESET"
|
|
@@ -20294,6 +20595,12 @@ ${log}` : log;
|
|
|
20294
20595
|
this.setConnectAuthState("startConfirm", false);
|
|
20295
20596
|
this.clearWebSocket();
|
|
20296
20597
|
}
|
|
20598
|
+
/**
|
|
20599
|
+
* Destroy the heartbeat manager
|
|
20600
|
+
*/
|
|
20601
|
+
destroyHeartbeat() {
|
|
20602
|
+
this.heartbeatManager.destroy();
|
|
20603
|
+
}
|
|
20297
20604
|
attemptReconnect() {
|
|
20298
20605
|
if (this.reconnectTimer) {
|
|
20299
20606
|
clearTimeout(this.reconnectTimer);
|
|
@@ -20301,19 +20608,40 @@ ${log}` : log;
|
|
|
20301
20608
|
}
|
|
20302
20609
|
const { maxAttempts } = this.reconnectConfig;
|
|
20303
20610
|
if (this.reconnectAttempts >= maxAttempts) {
|
|
20611
|
+
if (this.callKit.connect.isCalling()) {
|
|
20612
|
+
this.callKit.logger.warn("reconnect during call, ignore", {
|
|
20613
|
+
caller: "Socket.attemptReconnect",
|
|
20614
|
+
type: "INCALL",
|
|
20615
|
+
content: {
|
|
20616
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
20617
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
20618
|
+
reconnectAttempts: this.reconnectAttempts
|
|
20619
|
+
}
|
|
20620
|
+
});
|
|
20621
|
+
return;
|
|
20622
|
+
}
|
|
20623
|
+
if (this.isUserSetPingTryCount) {
|
|
20624
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20625
|
+
event: "INCALL_PING_TIMEOUT_RECONNECT_FAILED_MAX_ATTEMPTS"
|
|
20626
|
+
});
|
|
20627
|
+
}
|
|
20304
20628
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20305
20629
|
event: "INCALL_RECONNECT_ERROR"
|
|
20306
20630
|
});
|
|
20307
20631
|
this.setConnectAuthState("isError", true);
|
|
20308
20632
|
this.callKit.reset();
|
|
20309
|
-
this.callKit.logger.
|
|
20310
|
-
|
|
20311
|
-
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
|
|
20633
|
+
this.callKit.logger.warn(
|
|
20634
|
+
"Maximum reconnection attempts reached, trigger reset",
|
|
20635
|
+
{
|
|
20636
|
+
caller: "Socket.attemptReconnect",
|
|
20637
|
+
type: "INCALL",
|
|
20638
|
+
content: {
|
|
20639
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
20640
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
20641
|
+
delayReset: this.callKit.connect.isCalling()
|
|
20642
|
+
}
|
|
20315
20643
|
}
|
|
20316
|
-
|
|
20644
|
+
);
|
|
20317
20645
|
return;
|
|
20318
20646
|
}
|
|
20319
20647
|
if (this.reconnectAttempts === 0) {
|
|
@@ -20419,6 +20747,7 @@ ${log}` : log;
|
|
|
20419
20747
|
content: {
|
|
20420
20748
|
username,
|
|
20421
20749
|
password,
|
|
20750
|
+
ua: navigator.userAgent,
|
|
20422
20751
|
encryptionMethod,
|
|
20423
20752
|
encryptionPassword
|
|
20424
20753
|
}
|
|
@@ -20452,6 +20781,9 @@ ${log}` : log;
|
|
|
20452
20781
|
iceInfo: user.iceInfo,
|
|
20453
20782
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
20454
20783
|
logGather: user.logGather,
|
|
20784
|
+
keepaliveInterval: user.keepaliveInterval,
|
|
20785
|
+
pingTryCount: user?.pingTryCount,
|
|
20786
|
+
pingTryCountInterval: user?.pingTryCountInterval,
|
|
20455
20787
|
phoneType: user.phoneType,
|
|
20456
20788
|
// encryptionType is in extra
|
|
20457
20789
|
...extra
|