@koi-design/callkit 2.3.0-beta.8 → 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 +383 -45
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +378 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -45,7 +45,7 @@ var Api = class {
|
|
|
45
45
|
const res = await this.post({
|
|
46
46
|
url: "/auth/agentUser/login",
|
|
47
47
|
method: "post",
|
|
48
|
-
data: params
|
|
48
|
+
data: { ...params, browserVersion: navigator.userAgent }
|
|
49
49
|
});
|
|
50
50
|
return res;
|
|
51
51
|
} finally {
|
|
@@ -508,7 +508,11 @@ var SocketReceiveEvent = {
|
|
|
508
508
|
ERROR: "ERROR",
|
|
509
509
|
SESSION_ERROR: "SESSION_ERROR",
|
|
510
510
|
WAITING_QUEUE: "WAITING_QUEUE",
|
|
511
|
-
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE"
|
|
511
|
+
CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE",
|
|
512
|
+
/**
|
|
513
|
+
* Agent RTP loss
|
|
514
|
+
*/
|
|
515
|
+
AGENT_RTP_LOSS: "AGENT_RTP_LOSS"
|
|
512
516
|
};
|
|
513
517
|
var EncryptionMethod = {
|
|
514
518
|
NONE: "NONE",
|
|
@@ -697,7 +701,7 @@ var Call = class {
|
|
|
697
701
|
// package.json
|
|
698
702
|
var package_default = {
|
|
699
703
|
name: "@koi-design/callkit",
|
|
700
|
-
version: "2.3.
|
|
704
|
+
version: "2.3.1-beta.1",
|
|
701
705
|
description: "callkit",
|
|
702
706
|
author: "koi",
|
|
703
707
|
license: "ISC",
|
|
@@ -15797,8 +15801,6 @@ var Connect = class {
|
|
|
15797
15801
|
});
|
|
15798
15802
|
return;
|
|
15799
15803
|
}
|
|
15800
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
15801
|
-
const { userPart, fsIp, fsPort } = userInfo;
|
|
15802
15804
|
const { registererOptions = {} } = this.reconnectConfig;
|
|
15803
15805
|
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
15804
15806
|
this.registerer.stateChange.addListener((state) => {
|
|
@@ -15832,27 +15834,26 @@ var Connect = class {
|
|
|
15832
15834
|
});
|
|
15833
15835
|
this.setRegister(true);
|
|
15834
15836
|
if (this.isReConnected) {
|
|
15835
|
-
if (this.
|
|
15836
|
-
const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
15837
|
+
if (this.canReferInCallToSelf()) {
|
|
15837
15838
|
this.callKit.logger.info(
|
|
15838
15839
|
"Reconnected, referring active session to self",
|
|
15839
15840
|
{
|
|
15840
15841
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
15841
15842
|
type: "SIP",
|
|
15842
15843
|
content: {
|
|
15843
|
-
selfUri,
|
|
15844
|
+
selfUri: this.getSelfReferUri(),
|
|
15844
15845
|
sessionState: this.currentSession.state,
|
|
15845
15846
|
connectStatus: this.connectStatus
|
|
15846
15847
|
}
|
|
15847
15848
|
}
|
|
15848
15849
|
);
|
|
15849
|
-
this.
|
|
15850
|
+
this.referInCallToSelf().catch((err) => {
|
|
15850
15851
|
this.callKit.logger.error(err, {
|
|
15851
15852
|
caller: "Connect.setupRegisterer.registererStateChange",
|
|
15852
15853
|
type: "SIP",
|
|
15853
15854
|
content: {
|
|
15854
15855
|
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
15855
|
-
selfUri
|
|
15856
|
+
selfUri: this.getSelfReferUri()
|
|
15856
15857
|
}
|
|
15857
15858
|
});
|
|
15858
15859
|
});
|
|
@@ -15958,7 +15959,7 @@ var Connect = class {
|
|
|
15958
15959
|
this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);
|
|
15959
15960
|
return this.mediaStream;
|
|
15960
15961
|
};
|
|
15961
|
-
const { userPart, fsIp, fsPort, iceInfo, wsUrl } = userInfo;
|
|
15962
|
+
const { userPart, fsIp, fsPort, fsPassword, iceInfo, wsUrl } = userInfo;
|
|
15962
15963
|
const connectConfig = {
|
|
15963
15964
|
uri: UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`),
|
|
15964
15965
|
displayName: userPart,
|
|
@@ -15968,6 +15969,8 @@ var Connect = class {
|
|
|
15968
15969
|
},
|
|
15969
15970
|
logLevel: "error",
|
|
15970
15971
|
allowLegacyNotifications: true,
|
|
15972
|
+
authorizationPassword: fsPassword,
|
|
15973
|
+
authorizationUsername: userPart,
|
|
15971
15974
|
contactName: userPart,
|
|
15972
15975
|
contactParams: { transport: "wss" },
|
|
15973
15976
|
sessionDescriptionHandlerFactory: web_exports.defaultSessionDescriptionHandlerFactory(localStreamFactory),
|
|
@@ -16681,6 +16684,199 @@ var Connect = class {
|
|
|
16681
16684
|
}
|
|
16682
16685
|
this.currentSession.refer(target, extra?.sessionReferOptions);
|
|
16683
16686
|
}
|
|
16687
|
+
/**
|
|
16688
|
+
* Get the SIP URI for "refer to self" (same as reconnection refer logic).
|
|
16689
|
+
* Shared by referInCallToSelf and internal reconnection refer.
|
|
16690
|
+
*/
|
|
16691
|
+
getSelfReferUri() {
|
|
16692
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16693
|
+
const { userPart, fsIp, fsPort } = userInfo;
|
|
16694
|
+
return `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
16695
|
+
}
|
|
16696
|
+
/**
|
|
16697
|
+
* Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
|
|
16698
|
+
* Shared by reconnection logic and referInCallToSelf.
|
|
16699
|
+
*/
|
|
16700
|
+
canReferInCallToSelf() {
|
|
16701
|
+
return !!this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling();
|
|
16702
|
+
}
|
|
16703
|
+
/**
|
|
16704
|
+
* Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
|
|
16705
|
+
* Socket and other callers can use this without constructing referTo.
|
|
16706
|
+
*/
|
|
16707
|
+
async referInCallToSelf(callUuid, extra) {
|
|
16708
|
+
if (callUuid && this.currentCallId !== callUuid) {
|
|
16709
|
+
this.callKit.logger.warn(
|
|
16710
|
+
"Cannot refer in call to self: callUuid mismatch",
|
|
16711
|
+
{
|
|
16712
|
+
caller: "Connect.referInCallToSelf",
|
|
16713
|
+
type: "SIP",
|
|
16714
|
+
content: {
|
|
16715
|
+
currentCallId: this.currentCallId,
|
|
16716
|
+
callUuid
|
|
16717
|
+
}
|
|
16718
|
+
}
|
|
16719
|
+
);
|
|
16720
|
+
return;
|
|
16721
|
+
}
|
|
16722
|
+
if (!this.canReferInCallToSelf()) {
|
|
16723
|
+
this.callKit.logger.warn(
|
|
16724
|
+
"Cannot refer in call to self: preconditions not met",
|
|
16725
|
+
{
|
|
16726
|
+
caller: "Connect.referInCallToSelf",
|
|
16727
|
+
type: "SIP",
|
|
16728
|
+
content: {
|
|
16729
|
+
hasCurrentSession: !!this.currentSession,
|
|
16730
|
+
sessionState: this.currentSession?.state,
|
|
16731
|
+
isCalling: this.isCalling()
|
|
16732
|
+
}
|
|
16733
|
+
}
|
|
16734
|
+
);
|
|
16735
|
+
return;
|
|
16736
|
+
}
|
|
16737
|
+
const selfUri = this.getSelfReferUri();
|
|
16738
|
+
return this.referInCall(selfUri, extra);
|
|
16739
|
+
}
|
|
16740
|
+
};
|
|
16741
|
+
|
|
16742
|
+
// core/heartbeat-worker.ts
|
|
16743
|
+
var workerCode = `
|
|
16744
|
+
let timer = null;
|
|
16745
|
+
let interval = 30000;
|
|
16746
|
+
|
|
16747
|
+
self.onmessage = function(e) {
|
|
16748
|
+
const { type, interval: newInterval } = e.data;
|
|
16749
|
+
|
|
16750
|
+
if (type === 'start') {
|
|
16751
|
+
if (timer) {
|
|
16752
|
+
clearInterval(timer);
|
|
16753
|
+
}
|
|
16754
|
+
interval = newInterval || interval;
|
|
16755
|
+
timer = setInterval(() => {
|
|
16756
|
+
self.postMessage({ type: 'tick' });
|
|
16757
|
+
}, interval);
|
|
16758
|
+
}
|
|
16759
|
+
|
|
16760
|
+
if (type === 'stop') {
|
|
16761
|
+
if (timer) {
|
|
16762
|
+
clearInterval(timer);
|
|
16763
|
+
timer = null;
|
|
16764
|
+
}
|
|
16765
|
+
}
|
|
16766
|
+
|
|
16767
|
+
if (type === 'updateInterval') {
|
|
16768
|
+
interval = newInterval;
|
|
16769
|
+
if (timer) {
|
|
16770
|
+
clearInterval(timer);
|
|
16771
|
+
timer = setInterval(() => {
|
|
16772
|
+
self.postMessage({ type: 'tick' });
|
|
16773
|
+
}, interval);
|
|
16774
|
+
}
|
|
16775
|
+
}
|
|
16776
|
+
};
|
|
16777
|
+
`;
|
|
16778
|
+
function createHeartbeatWorker() {
|
|
16779
|
+
try {
|
|
16780
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
16781
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
16782
|
+
const worker = new Worker(workerUrl);
|
|
16783
|
+
URL.revokeObjectURL(workerUrl);
|
|
16784
|
+
return worker;
|
|
16785
|
+
} catch {
|
|
16786
|
+
return null;
|
|
16787
|
+
}
|
|
16788
|
+
}
|
|
16789
|
+
var HeartbeatManager = class {
|
|
16790
|
+
worker = null;
|
|
16791
|
+
fallbackTimer = null;
|
|
16792
|
+
interval = 3e4;
|
|
16793
|
+
onTick = null;
|
|
16794
|
+
isRunning = false;
|
|
16795
|
+
constructor() {
|
|
16796
|
+
this.worker = createHeartbeatWorker();
|
|
16797
|
+
if (this.worker) {
|
|
16798
|
+
this.worker.onmessage = (e) => {
|
|
16799
|
+
if (e.data.type === "tick" && this.onTick) {
|
|
16800
|
+
this.onTick();
|
|
16801
|
+
}
|
|
16802
|
+
};
|
|
16803
|
+
}
|
|
16804
|
+
}
|
|
16805
|
+
/**
|
|
16806
|
+
* Start the heartbeat
|
|
16807
|
+
* @param interval - Interval in milliseconds
|
|
16808
|
+
* @param onTick - Callback function to execute on each tick
|
|
16809
|
+
*/
|
|
16810
|
+
start(interval, onTick) {
|
|
16811
|
+
this.stop();
|
|
16812
|
+
this.interval = interval;
|
|
16813
|
+
this.onTick = onTick;
|
|
16814
|
+
this.isRunning = true;
|
|
16815
|
+
if (this.worker) {
|
|
16816
|
+
this.worker.postMessage({
|
|
16817
|
+
type: "start",
|
|
16818
|
+
interval
|
|
16819
|
+
});
|
|
16820
|
+
} else {
|
|
16821
|
+
this.fallbackTimer = setInterval(() => {
|
|
16822
|
+
if (this.onTick) {
|
|
16823
|
+
this.onTick();
|
|
16824
|
+
}
|
|
16825
|
+
}, interval);
|
|
16826
|
+
}
|
|
16827
|
+
}
|
|
16828
|
+
/**
|
|
16829
|
+
* Stop the heartbeat
|
|
16830
|
+
*/
|
|
16831
|
+
stop() {
|
|
16832
|
+
this.isRunning = false;
|
|
16833
|
+
this.onTick = null;
|
|
16834
|
+
if (this.worker) {
|
|
16835
|
+
this.worker.postMessage({ type: "stop" });
|
|
16836
|
+
}
|
|
16837
|
+
if (this.fallbackTimer) {
|
|
16838
|
+
clearInterval(this.fallbackTimer);
|
|
16839
|
+
this.fallbackTimer = null;
|
|
16840
|
+
}
|
|
16841
|
+
}
|
|
16842
|
+
/**
|
|
16843
|
+
* Update the heartbeat interval
|
|
16844
|
+
* @param interval - New interval in milliseconds
|
|
16845
|
+
*/
|
|
16846
|
+
updateInterval(interval) {
|
|
16847
|
+
this.interval = interval;
|
|
16848
|
+
if (!this.isRunning)
|
|
16849
|
+
return;
|
|
16850
|
+
if (this.worker) {
|
|
16851
|
+
this.worker.postMessage({
|
|
16852
|
+
type: "updateInterval",
|
|
16853
|
+
interval
|
|
16854
|
+
});
|
|
16855
|
+
} else if (this.fallbackTimer && this.onTick) {
|
|
16856
|
+
clearInterval(this.fallbackTimer);
|
|
16857
|
+
this.fallbackTimer = setInterval(() => {
|
|
16858
|
+
if (this.onTick) {
|
|
16859
|
+
this.onTick();
|
|
16860
|
+
}
|
|
16861
|
+
}, interval);
|
|
16862
|
+
}
|
|
16863
|
+
}
|
|
16864
|
+
/**
|
|
16865
|
+
* Destroy the heartbeat manager and release resources
|
|
16866
|
+
*/
|
|
16867
|
+
destroy() {
|
|
16868
|
+
this.stop();
|
|
16869
|
+
if (this.worker) {
|
|
16870
|
+
this.worker.terminate();
|
|
16871
|
+
this.worker = null;
|
|
16872
|
+
}
|
|
16873
|
+
}
|
|
16874
|
+
/**
|
|
16875
|
+
* Check if using Web Worker
|
|
16876
|
+
*/
|
|
16877
|
+
isUsingWorker() {
|
|
16878
|
+
return this.worker !== null;
|
|
16879
|
+
}
|
|
16684
16880
|
};
|
|
16685
16881
|
|
|
16686
16882
|
// core/socket.ts
|
|
@@ -16688,7 +16884,7 @@ var Socket = class {
|
|
|
16688
16884
|
callKit;
|
|
16689
16885
|
ws;
|
|
16690
16886
|
lastPingTime = void 0;
|
|
16691
|
-
|
|
16887
|
+
heartbeatManager;
|
|
16692
16888
|
/**
|
|
16693
16889
|
* @description reconnect timer
|
|
16694
16890
|
*/
|
|
@@ -16721,9 +16917,32 @@ var Socket = class {
|
|
|
16721
16917
|
}
|
|
16722
16918
|
constructor(callKit) {
|
|
16723
16919
|
this.callKit = callKit;
|
|
16920
|
+
this.heartbeatManager = new HeartbeatManager();
|
|
16921
|
+
}
|
|
16922
|
+
get isUserSetPingTryCount() {
|
|
16923
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16924
|
+
const { pingTryCount } = userInfo;
|
|
16925
|
+
return Number.isInteger(pingTryCount) && pingTryCount > 0;
|
|
16724
16926
|
}
|
|
16725
16927
|
get reconnectConfig() {
|
|
16726
|
-
|
|
16928
|
+
const incallConfig = this.callKit.config.getReconnectConfig("incall");
|
|
16929
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
16930
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
16931
|
+
if (pingTryCount > 0) {
|
|
16932
|
+
return {
|
|
16933
|
+
...incallConfig,
|
|
16934
|
+
maxAttempts: pingTryCount,
|
|
16935
|
+
interval: pingTryCountInterval * 1e3
|
|
16936
|
+
};
|
|
16937
|
+
}
|
|
16938
|
+
return incallConfig;
|
|
16939
|
+
}
|
|
16940
|
+
get pingInterval() {
|
|
16941
|
+
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
16942
|
+
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
16943
|
+
return keepaliveInterval * 1e3;
|
|
16944
|
+
}
|
|
16945
|
+
return this.reconnectConfig.pingInterval;
|
|
16727
16946
|
}
|
|
16728
16947
|
isConnected() {
|
|
16729
16948
|
return this.connectAuthState.isConnected;
|
|
@@ -16748,7 +16967,17 @@ var Socket = class {
|
|
|
16748
16967
|
this.setConnectAuthState("isConnected", false);
|
|
16749
16968
|
const { enabled } = this.reconnectConfig;
|
|
16750
16969
|
if (!this.callKit.config.isLogin() || !enabled) {
|
|
16751
|
-
this.callKit.
|
|
16970
|
+
if (this.callKit.connect.isCalling()) {
|
|
16971
|
+
this.callKit.logger.warn("Disconnect during call, delay reset", {
|
|
16972
|
+
caller: "Socket.handleDisconnect",
|
|
16973
|
+
type: "INCALL",
|
|
16974
|
+
content: {
|
|
16975
|
+
connectStatus: this.callKit.connect.connectStatus
|
|
16976
|
+
}
|
|
16977
|
+
});
|
|
16978
|
+
} else {
|
|
16979
|
+
this.callKit.reset();
|
|
16980
|
+
}
|
|
16752
16981
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
16753
16982
|
event: "INCALL_NOT_CONNECTED"
|
|
16754
16983
|
});
|
|
@@ -16906,6 +17135,28 @@ var Socket = class {
|
|
|
16906
17135
|
this.setConnectAuthState("startConfirm", true);
|
|
16907
17136
|
this.cleanReconnectState();
|
|
16908
17137
|
}
|
|
17138
|
+
if (data.event === SocketReceiveEvent.AGENT_RTP_LOSS) {
|
|
17139
|
+
this.callKit.logger.warn("Agent RTP loss", {
|
|
17140
|
+
caller: "Socket.onMessage",
|
|
17141
|
+
type: "INCALL",
|
|
17142
|
+
content: {
|
|
17143
|
+
data: {
|
|
17144
|
+
callUuid,
|
|
17145
|
+
...content
|
|
17146
|
+
},
|
|
17147
|
+
event: SocketReceiveEvent.AGENT_RTP_LOSS
|
|
17148
|
+
}
|
|
17149
|
+
});
|
|
17150
|
+
if (callUuid) {
|
|
17151
|
+
this.callKit.connect.referInCallToSelf(callUuid).catch((err) => {
|
|
17152
|
+
this.callKit.logger.error(err, {
|
|
17153
|
+
caller: "Socket.onMessage:AGENT_RTP_LOSS",
|
|
17154
|
+
type: "INCALL",
|
|
17155
|
+
content: { callUuid, event: SocketReceiveEvent.AGENT_RTP_LOSS }
|
|
17156
|
+
});
|
|
17157
|
+
});
|
|
17158
|
+
}
|
|
17159
|
+
}
|
|
16909
17160
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
16910
17161
|
this.callKit.trigger(KitEvent.CALL_RINGING, {
|
|
16911
17162
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -16954,6 +17205,18 @@ var Socket = class {
|
|
|
16954
17205
|
this.send(SocketSendEvent.END, { agentId: userInfo.agentId, callUuid });
|
|
16955
17206
|
}
|
|
16956
17207
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
17208
|
+
if (this.callKit.connect.isCalling()) {
|
|
17209
|
+
this.callKit.logger.warn("socket onMessage error during call, ignore", {
|
|
17210
|
+
caller: "Socket.onMessage",
|
|
17211
|
+
type: "INCALL",
|
|
17212
|
+
content: {
|
|
17213
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
17214
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17215
|
+
data: content
|
|
17216
|
+
}
|
|
17217
|
+
});
|
|
17218
|
+
return;
|
|
17219
|
+
}
|
|
16957
17220
|
this.setConnectAuthState("isError", true);
|
|
16958
17221
|
this.callKit.reset();
|
|
16959
17222
|
this.callKit.logger.error(data.msg, {
|
|
@@ -16962,20 +17225,24 @@ var Socket = class {
|
|
|
16962
17225
|
content: {
|
|
16963
17226
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
16964
17227
|
data: content,
|
|
16965
|
-
callUuid
|
|
17228
|
+
callUuid,
|
|
17229
|
+
delayReset: this.callKit.connect.isCalling()
|
|
16966
17230
|
}
|
|
16967
17231
|
});
|
|
16968
17232
|
}
|
|
16969
17233
|
if (data.event === SocketReceiveEvent.SESSION_ERROR) {
|
|
16970
17234
|
this.setConnectAuthState("isError", true);
|
|
16971
|
-
this.callKit.
|
|
17235
|
+
if (!this.callKit.connect.isCalling()) {
|
|
17236
|
+
this.callKit.reset();
|
|
17237
|
+
}
|
|
16972
17238
|
this.callKit.logger.error(data.msg, {
|
|
16973
17239
|
caller: `Socket.onMessage:${data.event}`,
|
|
16974
17240
|
type: "INCALL",
|
|
16975
17241
|
content: {
|
|
16976
17242
|
data: content,
|
|
16977
17243
|
event: SocketReceiveEvent.SESSION_ERROR,
|
|
16978
|
-
callUuid
|
|
17244
|
+
callUuid,
|
|
17245
|
+
delayReset: this.callKit.connect.isCalling()
|
|
16979
17246
|
}
|
|
16980
17247
|
});
|
|
16981
17248
|
}
|
|
@@ -17007,6 +17274,18 @@ var Socket = class {
|
|
|
17007
17274
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17008
17275
|
event: "INCALL_NOT_CONNECTED"
|
|
17009
17276
|
});
|
|
17277
|
+
if (this.callKit.connect.isCalling()) {
|
|
17278
|
+
this.callKit.logger.warn("socket send during call, ignore", {
|
|
17279
|
+
caller: "Socket.onMessage",
|
|
17280
|
+
type: "INCALL",
|
|
17281
|
+
content: {
|
|
17282
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
17283
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17284
|
+
data: message
|
|
17285
|
+
}
|
|
17286
|
+
});
|
|
17287
|
+
return;
|
|
17288
|
+
}
|
|
17010
17289
|
this.callKit.reset();
|
|
17011
17290
|
this.callKit.logger.error("socket not connected", {
|
|
17012
17291
|
caller: "Socket.send",
|
|
@@ -17059,8 +17338,8 @@ var Socket = class {
|
|
|
17059
17338
|
return;
|
|
17060
17339
|
this.send(SocketSendEvent.PING);
|
|
17061
17340
|
const now = Date.now();
|
|
17062
|
-
const {
|
|
17063
|
-
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17341
|
+
const { pingTimeout } = this.reconnectConfig;
|
|
17342
|
+
if (now - this.lastPingTime > this.pingInterval + pingTimeout) {
|
|
17064
17343
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17065
17344
|
caller: "Socket.ping",
|
|
17066
17345
|
type: "INCALL",
|
|
@@ -17072,26 +17351,48 @@ var Socket = class {
|
|
|
17072
17351
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17073
17352
|
event: "INCALL_PING_TIMEOUT"
|
|
17074
17353
|
});
|
|
17354
|
+
if (this.isUserSetPingTryCount) {
|
|
17355
|
+
this.handlePingTimeout();
|
|
17356
|
+
}
|
|
17075
17357
|
}
|
|
17076
17358
|
}
|
|
17359
|
+
handlePingTimeout() {
|
|
17360
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
17361
|
+
const { pingTryCount, pingTryCountInterval } = userInfo;
|
|
17362
|
+
this.callKit.logger.warn("Ping timeout, user set ping try count", {
|
|
17363
|
+
caller: "Socket.handlePingTimeout",
|
|
17364
|
+
type: "INCALL",
|
|
17365
|
+
content: {
|
|
17366
|
+
errCode: ErrorCode.SOCKET_PING_TIMEOUT,
|
|
17367
|
+
isUserSetPingTryCount: this.isUserSetPingTryCount,
|
|
17368
|
+
pingTryCount,
|
|
17369
|
+
pingTryCountInterval
|
|
17370
|
+
}
|
|
17371
|
+
});
|
|
17372
|
+
this.attemptReconnect();
|
|
17373
|
+
}
|
|
17077
17374
|
checkPing() {
|
|
17078
|
-
|
|
17079
|
-
clearInterval(this.pingTimer);
|
|
17080
|
-
}
|
|
17081
|
-
const { pingInterval } = this.reconnectConfig;
|
|
17082
|
-
this.pingTimer = setInterval(() => {
|
|
17375
|
+
this.heartbeatManager.start(this.pingInterval, () => {
|
|
17083
17376
|
this.ping();
|
|
17084
|
-
}
|
|
17377
|
+
});
|
|
17378
|
+
this.callKit.logger.info(
|
|
17379
|
+
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
17380
|
+
{
|
|
17381
|
+
caller: "Socket.checkPing",
|
|
17382
|
+
type: "INCALL",
|
|
17383
|
+
content: {
|
|
17384
|
+
pingInterval: this.pingInterval,
|
|
17385
|
+
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
17386
|
+
}
|
|
17387
|
+
}
|
|
17388
|
+
);
|
|
17085
17389
|
}
|
|
17086
17390
|
/**
|
|
17087
17391
|
* reset socket connection and all states
|
|
17088
17392
|
*/
|
|
17089
17393
|
async reset(config) {
|
|
17090
17394
|
const { force = false } = config || {};
|
|
17091
|
-
|
|
17092
|
-
clearInterval(this.pingTimer);
|
|
17093
|
-
this.pingTimer = void 0;
|
|
17094
|
-
}
|
|
17395
|
+
this.heartbeatManager.stop();
|
|
17095
17396
|
if (force) {
|
|
17096
17397
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17097
17398
|
event: "INCALL_RESET"
|
|
@@ -17102,6 +17403,12 @@ var Socket = class {
|
|
|
17102
17403
|
this.setConnectAuthState("startConfirm", false);
|
|
17103
17404
|
this.clearWebSocket();
|
|
17104
17405
|
}
|
|
17406
|
+
/**
|
|
17407
|
+
* Destroy the heartbeat manager
|
|
17408
|
+
*/
|
|
17409
|
+
destroyHeartbeat() {
|
|
17410
|
+
this.heartbeatManager.destroy();
|
|
17411
|
+
}
|
|
17105
17412
|
attemptReconnect() {
|
|
17106
17413
|
if (this.reconnectTimer) {
|
|
17107
17414
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17109,19 +17416,40 @@ var Socket = class {
|
|
|
17109
17416
|
}
|
|
17110
17417
|
const { maxAttempts } = this.reconnectConfig;
|
|
17111
17418
|
if (this.reconnectAttempts >= maxAttempts) {
|
|
17419
|
+
if (this.callKit.connect.isCalling()) {
|
|
17420
|
+
this.callKit.logger.warn("reconnect during call, ignore", {
|
|
17421
|
+
caller: "Socket.attemptReconnect",
|
|
17422
|
+
type: "INCALL",
|
|
17423
|
+
content: {
|
|
17424
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
17425
|
+
isCalling: this.callKit.connect.isCalling(),
|
|
17426
|
+
reconnectAttempts: this.reconnectAttempts
|
|
17427
|
+
}
|
|
17428
|
+
});
|
|
17429
|
+
return;
|
|
17430
|
+
}
|
|
17431
|
+
if (this.isUserSetPingTryCount) {
|
|
17432
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17433
|
+
event: "INCALL_PING_TIMEOUT_RECONNECT_FAILED_MAX_ATTEMPTS"
|
|
17434
|
+
});
|
|
17435
|
+
}
|
|
17112
17436
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17113
17437
|
event: "INCALL_RECONNECT_ERROR"
|
|
17114
17438
|
});
|
|
17115
17439
|
this.setConnectAuthState("isError", true);
|
|
17116
17440
|
this.callKit.reset();
|
|
17117
|
-
this.callKit.logger.
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
17441
|
+
this.callKit.logger.warn(
|
|
17442
|
+
"Maximum reconnection attempts reached, trigger reset",
|
|
17443
|
+
{
|
|
17444
|
+
caller: "Socket.attemptReconnect",
|
|
17445
|
+
type: "INCALL",
|
|
17446
|
+
content: {
|
|
17447
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
17448
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
17449
|
+
delayReset: this.callKit.connect.isCalling()
|
|
17450
|
+
}
|
|
17123
17451
|
}
|
|
17124
|
-
|
|
17452
|
+
);
|
|
17125
17453
|
return;
|
|
17126
17454
|
}
|
|
17127
17455
|
if (this.reconnectAttempts === 0) {
|
|
@@ -17227,6 +17555,7 @@ var CallKit = class {
|
|
|
17227
17555
|
content: {
|
|
17228
17556
|
username,
|
|
17229
17557
|
password,
|
|
17558
|
+
ua: navigator.userAgent,
|
|
17230
17559
|
encryptionMethod,
|
|
17231
17560
|
encryptionPassword
|
|
17232
17561
|
}
|
|
@@ -17260,6 +17589,9 @@ var CallKit = class {
|
|
|
17260
17589
|
iceInfo: user.iceInfo,
|
|
17261
17590
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17262
17591
|
logGather: user.logGather,
|
|
17592
|
+
keepaliveInterval: user.keepaliveInterval,
|
|
17593
|
+
pingTryCount: user?.pingTryCount,
|
|
17594
|
+
pingTryCountInterval: user?.pingTryCountInterval,
|
|
17263
17595
|
phoneType: user.phoneType,
|
|
17264
17596
|
// encryptionType is in extra
|
|
17265
17597
|
...extra
|
|
@@ -17357,7 +17689,10 @@ var CallKit = class {
|
|
|
17357
17689
|
caller: "CallKit.register",
|
|
17358
17690
|
content: {}
|
|
17359
17691
|
});
|
|
17360
|
-
this.
|
|
17692
|
+
const { userInfo } = this.config.getConfig();
|
|
17693
|
+
if (userInfo.phoneType === PhoneTypeEnum.SIP) {
|
|
17694
|
+
this.connect.register();
|
|
17695
|
+
}
|
|
17361
17696
|
}
|
|
17362
17697
|
async unregister() {
|
|
17363
17698
|
if (!this.config.check())
|
|
@@ -17467,10 +17802,13 @@ var CallKit = class {
|
|
|
17467
17802
|
force
|
|
17468
17803
|
}
|
|
17469
17804
|
});
|
|
17470
|
-
|
|
17471
|
-
|
|
17805
|
+
const { userInfo } = this.config.getConfig();
|
|
17806
|
+
if (userInfo.phoneType === PhoneTypeEnum.SIP) {
|
|
17807
|
+
if (this.connect.isCalling()) {
|
|
17808
|
+
await this.hangup();
|
|
17809
|
+
}
|
|
17810
|
+
await this.connect.reset({ force });
|
|
17472
17811
|
}
|
|
17473
|
-
await this.connect.reset({ force });
|
|
17474
17812
|
if (this.config.isLogin()) {
|
|
17475
17813
|
await this.logout({ isReset: false });
|
|
17476
17814
|
} else {
|