@koi-design/callkit 2.3.0-beta.11 → 2.3.0-beta.12
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 +1 -7
- package/dist/index.global.js +20 -180
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +15 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -175
- 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:
|
|
75
|
+
data: params
|
|
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.12",
|
|
732
732
|
description: "callkit",
|
|
733
733
|
author: "koi",
|
|
734
734
|
license: "ISC",
|
|
@@ -16764,152 +16764,12 @@ 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
|
-
|
|
16907
16767
|
// core/socket.ts
|
|
16908
16768
|
var Socket = class {
|
|
16909
16769
|
callKit;
|
|
16910
16770
|
ws;
|
|
16911
16771
|
lastPingTime = void 0;
|
|
16912
|
-
|
|
16772
|
+
pingTimer;
|
|
16913
16773
|
/**
|
|
16914
16774
|
* @description reconnect timer
|
|
16915
16775
|
*/
|
|
@@ -16942,18 +16802,10 @@ var Socket = class {
|
|
|
16942
16802
|
}
|
|
16943
16803
|
constructor(callKit) {
|
|
16944
16804
|
this.callKit = callKit;
|
|
16945
|
-
this.heartbeatManager = new HeartbeatManager();
|
|
16946
16805
|
}
|
|
16947
16806
|
get reconnectConfig() {
|
|
16948
16807
|
return this.callKit.config.getReconnectConfig("incall");
|
|
16949
16808
|
}
|
|
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
|
-
}
|
|
16957
16809
|
isConnected() {
|
|
16958
16810
|
return this.connectAuthState.isConnected;
|
|
16959
16811
|
}
|
|
@@ -17310,8 +17162,8 @@ var Socket = class {
|
|
|
17310
17162
|
return;
|
|
17311
17163
|
this.send(SocketSendEvent.PING);
|
|
17312
17164
|
const now = Date.now();
|
|
17313
|
-
const { pingTimeout } = this.reconnectConfig;
|
|
17314
|
-
if (now - this.lastPingTime >
|
|
17165
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
17166
|
+
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17315
17167
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17316
17168
|
caller: "Socket.ping",
|
|
17317
17169
|
type: "INCALL",
|
|
@@ -17326,27 +17178,23 @@ var Socket = class {
|
|
|
17326
17178
|
}
|
|
17327
17179
|
}
|
|
17328
17180
|
checkPing() {
|
|
17329
|
-
|
|
17181
|
+
if (this.pingTimer) {
|
|
17182
|
+
clearInterval(this.pingTimer);
|
|
17183
|
+
}
|
|
17184
|
+
const { pingInterval } = this.reconnectConfig;
|
|
17185
|
+
this.pingTimer = setInterval(() => {
|
|
17330
17186
|
this.ping();
|
|
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
|
-
);
|
|
17187
|
+
}, pingInterval);
|
|
17343
17188
|
}
|
|
17344
17189
|
/**
|
|
17345
17190
|
* reset socket connection and all states
|
|
17346
17191
|
*/
|
|
17347
17192
|
async reset(config) {
|
|
17348
17193
|
const { force = false } = config || {};
|
|
17349
|
-
this.
|
|
17194
|
+
if (this.pingTimer) {
|
|
17195
|
+
clearInterval(this.pingTimer);
|
|
17196
|
+
this.pingTimer = void 0;
|
|
17197
|
+
}
|
|
17350
17198
|
if (force) {
|
|
17351
17199
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17352
17200
|
event: "INCALL_RESET"
|
|
@@ -17357,12 +17205,6 @@ var Socket = class {
|
|
|
17357
17205
|
this.setConnectAuthState("startConfirm", false);
|
|
17358
17206
|
this.clearWebSocket();
|
|
17359
17207
|
}
|
|
17360
|
-
/**
|
|
17361
|
-
* Destroy the heartbeat manager
|
|
17362
|
-
*/
|
|
17363
|
-
destroyHeartbeat() {
|
|
17364
|
-
this.heartbeatManager.destroy();
|
|
17365
|
-
}
|
|
17366
17208
|
attemptReconnect() {
|
|
17367
17209
|
if (this.reconnectTimer) {
|
|
17368
17210
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17488,7 +17330,6 @@ var CallKit = class {
|
|
|
17488
17330
|
content: {
|
|
17489
17331
|
username,
|
|
17490
17332
|
password,
|
|
17491
|
-
ua: navigator.userAgent,
|
|
17492
17333
|
encryptionMethod,
|
|
17493
17334
|
encryptionPassword
|
|
17494
17335
|
}
|
|
@@ -17522,7 +17363,6 @@ var CallKit = class {
|
|
|
17522
17363
|
iceInfo: user.iceInfo,
|
|
17523
17364
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17524
17365
|
logGather: user.logGather,
|
|
17525
|
-
keepaliveInterval: user.keepaliveInterval,
|
|
17526
17366
|
phoneType: user.phoneType,
|
|
17527
17367
|
// encryptionType is in extra
|
|
17528
17368
|
...extra
|