@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.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:
|
|
48
|
+
data: params
|
|
49
49
|
});
|
|
50
50
|
return res;
|
|
51
51
|
} finally {
|
|
@@ -701,7 +701,7 @@ var Call = class {
|
|
|
701
701
|
// package.json
|
|
702
702
|
var package_default = {
|
|
703
703
|
name: "@koi-design/callkit",
|
|
704
|
-
version: "2.3.0-beta.
|
|
704
|
+
version: "2.3.0-beta.12",
|
|
705
705
|
description: "callkit",
|
|
706
706
|
author: "koi",
|
|
707
707
|
license: "ISC",
|
|
@@ -16737,152 +16737,12 @@ var Connect = class {
|
|
|
16737
16737
|
}
|
|
16738
16738
|
};
|
|
16739
16739
|
|
|
16740
|
-
// core/heartbeat-worker.ts
|
|
16741
|
-
var workerCode = `
|
|
16742
|
-
let timer = null;
|
|
16743
|
-
let interval = 30000;
|
|
16744
|
-
|
|
16745
|
-
self.onmessage = function(e) {
|
|
16746
|
-
const { type, interval: newInterval } = e.data;
|
|
16747
|
-
|
|
16748
|
-
if (type === 'start') {
|
|
16749
|
-
if (timer) {
|
|
16750
|
-
clearInterval(timer);
|
|
16751
|
-
}
|
|
16752
|
-
interval = newInterval || interval;
|
|
16753
|
-
timer = setInterval(() => {
|
|
16754
|
-
self.postMessage({ type: 'tick' });
|
|
16755
|
-
}, interval);
|
|
16756
|
-
}
|
|
16757
|
-
|
|
16758
|
-
if (type === 'stop') {
|
|
16759
|
-
if (timer) {
|
|
16760
|
-
clearInterval(timer);
|
|
16761
|
-
timer = null;
|
|
16762
|
-
}
|
|
16763
|
-
}
|
|
16764
|
-
|
|
16765
|
-
if (type === 'updateInterval') {
|
|
16766
|
-
interval = newInterval;
|
|
16767
|
-
if (timer) {
|
|
16768
|
-
clearInterval(timer);
|
|
16769
|
-
timer = setInterval(() => {
|
|
16770
|
-
self.postMessage({ type: 'tick' });
|
|
16771
|
-
}, interval);
|
|
16772
|
-
}
|
|
16773
|
-
}
|
|
16774
|
-
};
|
|
16775
|
-
`;
|
|
16776
|
-
function createHeartbeatWorker() {
|
|
16777
|
-
try {
|
|
16778
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
16779
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
16780
|
-
const worker = new Worker(workerUrl);
|
|
16781
|
-
URL.revokeObjectURL(workerUrl);
|
|
16782
|
-
return worker;
|
|
16783
|
-
} catch {
|
|
16784
|
-
return null;
|
|
16785
|
-
}
|
|
16786
|
-
}
|
|
16787
|
-
var HeartbeatManager = class {
|
|
16788
|
-
worker = null;
|
|
16789
|
-
fallbackTimer = null;
|
|
16790
|
-
interval = 3e4;
|
|
16791
|
-
onTick = null;
|
|
16792
|
-
isRunning = false;
|
|
16793
|
-
constructor() {
|
|
16794
|
-
this.worker = createHeartbeatWorker();
|
|
16795
|
-
if (this.worker) {
|
|
16796
|
-
this.worker.onmessage = (e) => {
|
|
16797
|
-
if (e.data.type === "tick" && this.onTick) {
|
|
16798
|
-
this.onTick();
|
|
16799
|
-
}
|
|
16800
|
-
};
|
|
16801
|
-
}
|
|
16802
|
-
}
|
|
16803
|
-
/**
|
|
16804
|
-
* Start the heartbeat
|
|
16805
|
-
* @param interval - Interval in milliseconds
|
|
16806
|
-
* @param onTick - Callback function to execute on each tick
|
|
16807
|
-
*/
|
|
16808
|
-
start(interval, onTick) {
|
|
16809
|
-
this.stop();
|
|
16810
|
-
this.interval = interval;
|
|
16811
|
-
this.onTick = onTick;
|
|
16812
|
-
this.isRunning = true;
|
|
16813
|
-
if (this.worker) {
|
|
16814
|
-
this.worker.postMessage({
|
|
16815
|
-
type: "start",
|
|
16816
|
-
interval
|
|
16817
|
-
});
|
|
16818
|
-
} else {
|
|
16819
|
-
this.fallbackTimer = setInterval(() => {
|
|
16820
|
-
if (this.onTick) {
|
|
16821
|
-
this.onTick();
|
|
16822
|
-
}
|
|
16823
|
-
}, interval);
|
|
16824
|
-
}
|
|
16825
|
-
}
|
|
16826
|
-
/**
|
|
16827
|
-
* Stop the heartbeat
|
|
16828
|
-
*/
|
|
16829
|
-
stop() {
|
|
16830
|
-
this.isRunning = false;
|
|
16831
|
-
this.onTick = null;
|
|
16832
|
-
if (this.worker) {
|
|
16833
|
-
this.worker.postMessage({ type: "stop" });
|
|
16834
|
-
}
|
|
16835
|
-
if (this.fallbackTimer) {
|
|
16836
|
-
clearInterval(this.fallbackTimer);
|
|
16837
|
-
this.fallbackTimer = null;
|
|
16838
|
-
}
|
|
16839
|
-
}
|
|
16840
|
-
/**
|
|
16841
|
-
* Update the heartbeat interval
|
|
16842
|
-
* @param interval - New interval in milliseconds
|
|
16843
|
-
*/
|
|
16844
|
-
updateInterval(interval) {
|
|
16845
|
-
this.interval = interval;
|
|
16846
|
-
if (!this.isRunning)
|
|
16847
|
-
return;
|
|
16848
|
-
if (this.worker) {
|
|
16849
|
-
this.worker.postMessage({
|
|
16850
|
-
type: "updateInterval",
|
|
16851
|
-
interval
|
|
16852
|
-
});
|
|
16853
|
-
} else if (this.fallbackTimer && this.onTick) {
|
|
16854
|
-
clearInterval(this.fallbackTimer);
|
|
16855
|
-
this.fallbackTimer = setInterval(() => {
|
|
16856
|
-
if (this.onTick) {
|
|
16857
|
-
this.onTick();
|
|
16858
|
-
}
|
|
16859
|
-
}, interval);
|
|
16860
|
-
}
|
|
16861
|
-
}
|
|
16862
|
-
/**
|
|
16863
|
-
* Destroy the heartbeat manager and release resources
|
|
16864
|
-
*/
|
|
16865
|
-
destroy() {
|
|
16866
|
-
this.stop();
|
|
16867
|
-
if (this.worker) {
|
|
16868
|
-
this.worker.terminate();
|
|
16869
|
-
this.worker = null;
|
|
16870
|
-
}
|
|
16871
|
-
}
|
|
16872
|
-
/**
|
|
16873
|
-
* Check if using Web Worker
|
|
16874
|
-
*/
|
|
16875
|
-
isUsingWorker() {
|
|
16876
|
-
return this.worker !== null;
|
|
16877
|
-
}
|
|
16878
|
-
};
|
|
16879
|
-
|
|
16880
16740
|
// core/socket.ts
|
|
16881
16741
|
var Socket = class {
|
|
16882
16742
|
callKit;
|
|
16883
16743
|
ws;
|
|
16884
16744
|
lastPingTime = void 0;
|
|
16885
|
-
|
|
16745
|
+
pingTimer;
|
|
16886
16746
|
/**
|
|
16887
16747
|
* @description reconnect timer
|
|
16888
16748
|
*/
|
|
@@ -16915,18 +16775,10 @@ var Socket = class {
|
|
|
16915
16775
|
}
|
|
16916
16776
|
constructor(callKit) {
|
|
16917
16777
|
this.callKit = callKit;
|
|
16918
|
-
this.heartbeatManager = new HeartbeatManager();
|
|
16919
16778
|
}
|
|
16920
16779
|
get reconnectConfig() {
|
|
16921
16780
|
return this.callKit.config.getReconnectConfig("incall");
|
|
16922
16781
|
}
|
|
16923
|
-
get pingInterval() {
|
|
16924
|
-
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
16925
|
-
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
16926
|
-
return keepaliveInterval * 1e3;
|
|
16927
|
-
}
|
|
16928
|
-
return this.reconnectConfig.pingInterval;
|
|
16929
|
-
}
|
|
16930
16782
|
isConnected() {
|
|
16931
16783
|
return this.connectAuthState.isConnected;
|
|
16932
16784
|
}
|
|
@@ -17283,8 +17135,8 @@ var Socket = class {
|
|
|
17283
17135
|
return;
|
|
17284
17136
|
this.send(SocketSendEvent.PING);
|
|
17285
17137
|
const now = Date.now();
|
|
17286
|
-
const { pingTimeout } = this.reconnectConfig;
|
|
17287
|
-
if (now - this.lastPingTime >
|
|
17138
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
17139
|
+
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17288
17140
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17289
17141
|
caller: "Socket.ping",
|
|
17290
17142
|
type: "INCALL",
|
|
@@ -17299,27 +17151,23 @@ var Socket = class {
|
|
|
17299
17151
|
}
|
|
17300
17152
|
}
|
|
17301
17153
|
checkPing() {
|
|
17302
|
-
|
|
17154
|
+
if (this.pingTimer) {
|
|
17155
|
+
clearInterval(this.pingTimer);
|
|
17156
|
+
}
|
|
17157
|
+
const { pingInterval } = this.reconnectConfig;
|
|
17158
|
+
this.pingTimer = setInterval(() => {
|
|
17303
17159
|
this.ping();
|
|
17304
|
-
});
|
|
17305
|
-
this.callKit.logger.info(
|
|
17306
|
-
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
17307
|
-
{
|
|
17308
|
-
caller: "Socket.checkPing",
|
|
17309
|
-
type: "INCALL",
|
|
17310
|
-
content: {
|
|
17311
|
-
pingInterval: this.pingInterval,
|
|
17312
|
-
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
17313
|
-
}
|
|
17314
|
-
}
|
|
17315
|
-
);
|
|
17160
|
+
}, pingInterval);
|
|
17316
17161
|
}
|
|
17317
17162
|
/**
|
|
17318
17163
|
* reset socket connection and all states
|
|
17319
17164
|
*/
|
|
17320
17165
|
async reset(config) {
|
|
17321
17166
|
const { force = false } = config || {};
|
|
17322
|
-
this.
|
|
17167
|
+
if (this.pingTimer) {
|
|
17168
|
+
clearInterval(this.pingTimer);
|
|
17169
|
+
this.pingTimer = void 0;
|
|
17170
|
+
}
|
|
17323
17171
|
if (force) {
|
|
17324
17172
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17325
17173
|
event: "INCALL_RESET"
|
|
@@ -17330,12 +17178,6 @@ var Socket = class {
|
|
|
17330
17178
|
this.setConnectAuthState("startConfirm", false);
|
|
17331
17179
|
this.clearWebSocket();
|
|
17332
17180
|
}
|
|
17333
|
-
/**
|
|
17334
|
-
* Destroy the heartbeat manager
|
|
17335
|
-
*/
|
|
17336
|
-
destroyHeartbeat() {
|
|
17337
|
-
this.heartbeatManager.destroy();
|
|
17338
|
-
}
|
|
17339
17181
|
attemptReconnect() {
|
|
17340
17182
|
if (this.reconnectTimer) {
|
|
17341
17183
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17461,7 +17303,6 @@ var CallKit = class {
|
|
|
17461
17303
|
content: {
|
|
17462
17304
|
username,
|
|
17463
17305
|
password,
|
|
17464
|
-
ua: navigator.userAgent,
|
|
17465
17306
|
encryptionMethod,
|
|
17466
17307
|
encryptionPassword
|
|
17467
17308
|
}
|
|
@@ -17495,7 +17336,6 @@ var CallKit = class {
|
|
|
17495
17336
|
iceInfo: user.iceInfo,
|
|
17496
17337
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17497
17338
|
logGather: user.logGather,
|
|
17498
|
-
keepaliveInterval: user.keepaliveInterval,
|
|
17499
17339
|
phoneType: user.phoneType,
|
|
17500
17340
|
// encryptionType is in extra
|
|
17501
17341
|
...extra
|