@koi-design/callkit 2.3.0-beta.10 → 2.3.0-beta.11
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 -1
- package/dist/index.global.js +180 -20
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +175 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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 {
|
|
@@ -728,7 +728,7 @@ var Call = class {
|
|
|
728
728
|
// package.json
|
|
729
729
|
var package_default = {
|
|
730
730
|
name: "@koi-design/callkit",
|
|
731
|
-
version: "2.3.0-beta.
|
|
731
|
+
version: "2.3.0-beta.11",
|
|
732
732
|
description: "callkit",
|
|
733
733
|
author: "koi",
|
|
734
734
|
license: "ISC",
|
|
@@ -16764,12 +16764,152 @@ var Connect = class {
|
|
|
16764
16764
|
}
|
|
16765
16765
|
};
|
|
16766
16766
|
|
|
16767
|
+
// core/heartbeat-worker.ts
|
|
16768
|
+
var workerCode = `
|
|
16769
|
+
let timer = null;
|
|
16770
|
+
let interval = 30000;
|
|
16771
|
+
|
|
16772
|
+
self.onmessage = function(e) {
|
|
16773
|
+
const { type, interval: newInterval } = e.data;
|
|
16774
|
+
|
|
16775
|
+
if (type === 'start') {
|
|
16776
|
+
if (timer) {
|
|
16777
|
+
clearInterval(timer);
|
|
16778
|
+
}
|
|
16779
|
+
interval = newInterval || interval;
|
|
16780
|
+
timer = setInterval(() => {
|
|
16781
|
+
self.postMessage({ type: 'tick' });
|
|
16782
|
+
}, interval);
|
|
16783
|
+
}
|
|
16784
|
+
|
|
16785
|
+
if (type === 'stop') {
|
|
16786
|
+
if (timer) {
|
|
16787
|
+
clearInterval(timer);
|
|
16788
|
+
timer = null;
|
|
16789
|
+
}
|
|
16790
|
+
}
|
|
16791
|
+
|
|
16792
|
+
if (type === 'updateInterval') {
|
|
16793
|
+
interval = newInterval;
|
|
16794
|
+
if (timer) {
|
|
16795
|
+
clearInterval(timer);
|
|
16796
|
+
timer = setInterval(() => {
|
|
16797
|
+
self.postMessage({ type: 'tick' });
|
|
16798
|
+
}, interval);
|
|
16799
|
+
}
|
|
16800
|
+
}
|
|
16801
|
+
};
|
|
16802
|
+
`;
|
|
16803
|
+
function createHeartbeatWorker() {
|
|
16804
|
+
try {
|
|
16805
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
16806
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
16807
|
+
const worker = new Worker(workerUrl);
|
|
16808
|
+
URL.revokeObjectURL(workerUrl);
|
|
16809
|
+
return worker;
|
|
16810
|
+
} catch {
|
|
16811
|
+
return null;
|
|
16812
|
+
}
|
|
16813
|
+
}
|
|
16814
|
+
var HeartbeatManager = class {
|
|
16815
|
+
worker = null;
|
|
16816
|
+
fallbackTimer = null;
|
|
16817
|
+
interval = 3e4;
|
|
16818
|
+
onTick = null;
|
|
16819
|
+
isRunning = false;
|
|
16820
|
+
constructor() {
|
|
16821
|
+
this.worker = createHeartbeatWorker();
|
|
16822
|
+
if (this.worker) {
|
|
16823
|
+
this.worker.onmessage = (e) => {
|
|
16824
|
+
if (e.data.type === "tick" && this.onTick) {
|
|
16825
|
+
this.onTick();
|
|
16826
|
+
}
|
|
16827
|
+
};
|
|
16828
|
+
}
|
|
16829
|
+
}
|
|
16830
|
+
/**
|
|
16831
|
+
* Start the heartbeat
|
|
16832
|
+
* @param interval - Interval in milliseconds
|
|
16833
|
+
* @param onTick - Callback function to execute on each tick
|
|
16834
|
+
*/
|
|
16835
|
+
start(interval, onTick) {
|
|
16836
|
+
this.stop();
|
|
16837
|
+
this.interval = interval;
|
|
16838
|
+
this.onTick = onTick;
|
|
16839
|
+
this.isRunning = true;
|
|
16840
|
+
if (this.worker) {
|
|
16841
|
+
this.worker.postMessage({
|
|
16842
|
+
type: "start",
|
|
16843
|
+
interval
|
|
16844
|
+
});
|
|
16845
|
+
} else {
|
|
16846
|
+
this.fallbackTimer = setInterval(() => {
|
|
16847
|
+
if (this.onTick) {
|
|
16848
|
+
this.onTick();
|
|
16849
|
+
}
|
|
16850
|
+
}, interval);
|
|
16851
|
+
}
|
|
16852
|
+
}
|
|
16853
|
+
/**
|
|
16854
|
+
* Stop the heartbeat
|
|
16855
|
+
*/
|
|
16856
|
+
stop() {
|
|
16857
|
+
this.isRunning = false;
|
|
16858
|
+
this.onTick = null;
|
|
16859
|
+
if (this.worker) {
|
|
16860
|
+
this.worker.postMessage({ type: "stop" });
|
|
16861
|
+
}
|
|
16862
|
+
if (this.fallbackTimer) {
|
|
16863
|
+
clearInterval(this.fallbackTimer);
|
|
16864
|
+
this.fallbackTimer = null;
|
|
16865
|
+
}
|
|
16866
|
+
}
|
|
16867
|
+
/**
|
|
16868
|
+
* Update the heartbeat interval
|
|
16869
|
+
* @param interval - New interval in milliseconds
|
|
16870
|
+
*/
|
|
16871
|
+
updateInterval(interval) {
|
|
16872
|
+
this.interval = interval;
|
|
16873
|
+
if (!this.isRunning)
|
|
16874
|
+
return;
|
|
16875
|
+
if (this.worker) {
|
|
16876
|
+
this.worker.postMessage({
|
|
16877
|
+
type: "updateInterval",
|
|
16878
|
+
interval
|
|
16879
|
+
});
|
|
16880
|
+
} else if (this.fallbackTimer && this.onTick) {
|
|
16881
|
+
clearInterval(this.fallbackTimer);
|
|
16882
|
+
this.fallbackTimer = setInterval(() => {
|
|
16883
|
+
if (this.onTick) {
|
|
16884
|
+
this.onTick();
|
|
16885
|
+
}
|
|
16886
|
+
}, interval);
|
|
16887
|
+
}
|
|
16888
|
+
}
|
|
16889
|
+
/**
|
|
16890
|
+
* Destroy the heartbeat manager and release resources
|
|
16891
|
+
*/
|
|
16892
|
+
destroy() {
|
|
16893
|
+
this.stop();
|
|
16894
|
+
if (this.worker) {
|
|
16895
|
+
this.worker.terminate();
|
|
16896
|
+
this.worker = null;
|
|
16897
|
+
}
|
|
16898
|
+
}
|
|
16899
|
+
/**
|
|
16900
|
+
* Check if using Web Worker
|
|
16901
|
+
*/
|
|
16902
|
+
isUsingWorker() {
|
|
16903
|
+
return this.worker !== null;
|
|
16904
|
+
}
|
|
16905
|
+
};
|
|
16906
|
+
|
|
16767
16907
|
// core/socket.ts
|
|
16768
16908
|
var Socket = class {
|
|
16769
16909
|
callKit;
|
|
16770
16910
|
ws;
|
|
16771
16911
|
lastPingTime = void 0;
|
|
16772
|
-
|
|
16912
|
+
heartbeatManager;
|
|
16773
16913
|
/**
|
|
16774
16914
|
* @description reconnect timer
|
|
16775
16915
|
*/
|
|
@@ -16802,10 +16942,18 @@ var Socket = class {
|
|
|
16802
16942
|
}
|
|
16803
16943
|
constructor(callKit) {
|
|
16804
16944
|
this.callKit = callKit;
|
|
16945
|
+
this.heartbeatManager = new HeartbeatManager();
|
|
16805
16946
|
}
|
|
16806
16947
|
get reconnectConfig() {
|
|
16807
16948
|
return this.callKit.config.getReconnectConfig("incall");
|
|
16808
16949
|
}
|
|
16950
|
+
get pingInterval() {
|
|
16951
|
+
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
16952
|
+
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
16953
|
+
return keepaliveInterval * 1e3;
|
|
16954
|
+
}
|
|
16955
|
+
return this.reconnectConfig.pingInterval;
|
|
16956
|
+
}
|
|
16809
16957
|
isConnected() {
|
|
16810
16958
|
return this.connectAuthState.isConnected;
|
|
16811
16959
|
}
|
|
@@ -17162,8 +17310,8 @@ var Socket = class {
|
|
|
17162
17310
|
return;
|
|
17163
17311
|
this.send(SocketSendEvent.PING);
|
|
17164
17312
|
const now = Date.now();
|
|
17165
|
-
const {
|
|
17166
|
-
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17313
|
+
const { pingTimeout } = this.reconnectConfig;
|
|
17314
|
+
if (now - this.lastPingTime > this.pingInterval + pingTimeout) {
|
|
17167
17315
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17168
17316
|
caller: "Socket.ping",
|
|
17169
17317
|
type: "INCALL",
|
|
@@ -17178,23 +17326,27 @@ var Socket = class {
|
|
|
17178
17326
|
}
|
|
17179
17327
|
}
|
|
17180
17328
|
checkPing() {
|
|
17181
|
-
|
|
17182
|
-
clearInterval(this.pingTimer);
|
|
17183
|
-
}
|
|
17184
|
-
const { pingInterval } = this.reconnectConfig;
|
|
17185
|
-
this.pingTimer = setInterval(() => {
|
|
17329
|
+
this.heartbeatManager.start(this.pingInterval, () => {
|
|
17186
17330
|
this.ping();
|
|
17187
|
-
}
|
|
17331
|
+
});
|
|
17332
|
+
this.callKit.logger.info(
|
|
17333
|
+
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
17334
|
+
{
|
|
17335
|
+
caller: "Socket.checkPing",
|
|
17336
|
+
type: "INCALL",
|
|
17337
|
+
content: {
|
|
17338
|
+
pingInterval: this.pingInterval,
|
|
17339
|
+
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
17340
|
+
}
|
|
17341
|
+
}
|
|
17342
|
+
);
|
|
17188
17343
|
}
|
|
17189
17344
|
/**
|
|
17190
17345
|
* reset socket connection and all states
|
|
17191
17346
|
*/
|
|
17192
17347
|
async reset(config) {
|
|
17193
17348
|
const { force = false } = config || {};
|
|
17194
|
-
|
|
17195
|
-
clearInterval(this.pingTimer);
|
|
17196
|
-
this.pingTimer = void 0;
|
|
17197
|
-
}
|
|
17349
|
+
this.heartbeatManager.stop();
|
|
17198
17350
|
if (force) {
|
|
17199
17351
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17200
17352
|
event: "INCALL_RESET"
|
|
@@ -17205,6 +17357,12 @@ var Socket = class {
|
|
|
17205
17357
|
this.setConnectAuthState("startConfirm", false);
|
|
17206
17358
|
this.clearWebSocket();
|
|
17207
17359
|
}
|
|
17360
|
+
/**
|
|
17361
|
+
* Destroy the heartbeat manager
|
|
17362
|
+
*/
|
|
17363
|
+
destroyHeartbeat() {
|
|
17364
|
+
this.heartbeatManager.destroy();
|
|
17365
|
+
}
|
|
17208
17366
|
attemptReconnect() {
|
|
17209
17367
|
if (this.reconnectTimer) {
|
|
17210
17368
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17330,6 +17488,7 @@ var CallKit = class {
|
|
|
17330
17488
|
content: {
|
|
17331
17489
|
username,
|
|
17332
17490
|
password,
|
|
17491
|
+
ua: navigator.userAgent,
|
|
17333
17492
|
encryptionMethod,
|
|
17334
17493
|
encryptionPassword
|
|
17335
17494
|
}
|
|
@@ -17363,6 +17522,7 @@ var CallKit = class {
|
|
|
17363
17522
|
iceInfo: user.iceInfo,
|
|
17364
17523
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17365
17524
|
logGather: user.logGather,
|
|
17525
|
+
keepaliveInterval: user.keepaliveInterval,
|
|
17366
17526
|
phoneType: user.phoneType,
|
|
17367
17527
|
// encryptionType is in extra
|
|
17368
17528
|
...extra
|