@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.d.ts
CHANGED
|
@@ -4805,7 +4805,7 @@ declare class Socket {
|
|
|
4805
4805
|
private callKit;
|
|
4806
4806
|
private ws?;
|
|
4807
4807
|
lastPingTime: any;
|
|
4808
|
-
|
|
4808
|
+
pingTimer?: ReturnType<typeof setInterval>;
|
|
4809
4809
|
/**
|
|
4810
4810
|
* @description reconnect timer
|
|
4811
4811
|
*/
|
|
@@ -4829,7 +4829,6 @@ declare class Socket {
|
|
|
4829
4829
|
get isError(): boolean;
|
|
4830
4830
|
constructor(callKit: CallKit);
|
|
4831
4831
|
get reconnectConfig(): IncallConfig;
|
|
4832
|
-
get pingInterval(): number;
|
|
4833
4832
|
isConnected(): boolean;
|
|
4834
4833
|
init(): void;
|
|
4835
4834
|
private setConnectAuthState;
|
|
@@ -4852,10 +4851,6 @@ declare class Socket {
|
|
|
4852
4851
|
reset(config?: {
|
|
4853
4852
|
force?: boolean;
|
|
4854
4853
|
}): Promise<void>;
|
|
4855
|
-
/**
|
|
4856
|
-
* Destroy the heartbeat manager
|
|
4857
|
-
*/
|
|
4858
|
-
destroyHeartbeat(): void;
|
|
4859
4854
|
private attemptReconnect;
|
|
4860
4855
|
}
|
|
4861
4856
|
|
|
@@ -4900,7 +4895,6 @@ interface IConfig {
|
|
|
4900
4895
|
iceGatheringTimeout: number;
|
|
4901
4896
|
encryptionMethod: EncryptionMethodType;
|
|
4902
4897
|
logGather: boolean;
|
|
4903
|
-
keepaliveInterval?: number;
|
|
4904
4898
|
};
|
|
4905
4899
|
}
|
|
4906
4900
|
declare class Config {
|
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 URL = 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 URL(""));
|
|
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 URL(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 URL(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 URL && value instanceof URL;
|
|
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:
|
|
3240
|
+
data: params
|
|
3241
3241
|
});
|
|
3242
3242
|
return res;
|
|
3243
3243
|
} finally {
|
|
@@ -3893,7 +3893,7 @@ var WebCall = (() => {
|
|
|
3893
3893
|
// package.json
|
|
3894
3894
|
var package_default = {
|
|
3895
3895
|
name: "@koi-design/callkit",
|
|
3896
|
-
version: "2.3.0-beta.
|
|
3896
|
+
version: "2.3.0-beta.12",
|
|
3897
3897
|
description: "callkit",
|
|
3898
3898
|
author: "koi",
|
|
3899
3899
|
license: "ISC",
|
|
@@ -19929,152 +19929,12 @@ ${log}` : log;
|
|
|
19929
19929
|
}
|
|
19930
19930
|
};
|
|
19931
19931
|
|
|
19932
|
-
// core/heartbeat-worker.ts
|
|
19933
|
-
var workerCode = `
|
|
19934
|
-
let timer = null;
|
|
19935
|
-
let interval = 30000;
|
|
19936
|
-
|
|
19937
|
-
self.onmessage = function(e) {
|
|
19938
|
-
const { type, interval: newInterval } = e.data;
|
|
19939
|
-
|
|
19940
|
-
if (type === 'start') {
|
|
19941
|
-
if (timer) {
|
|
19942
|
-
clearInterval(timer);
|
|
19943
|
-
}
|
|
19944
|
-
interval = newInterval || interval;
|
|
19945
|
-
timer = setInterval(() => {
|
|
19946
|
-
self.postMessage({ type: 'tick' });
|
|
19947
|
-
}, interval);
|
|
19948
|
-
}
|
|
19949
|
-
|
|
19950
|
-
if (type === 'stop') {
|
|
19951
|
-
if (timer) {
|
|
19952
|
-
clearInterval(timer);
|
|
19953
|
-
timer = null;
|
|
19954
|
-
}
|
|
19955
|
-
}
|
|
19956
|
-
|
|
19957
|
-
if (type === 'updateInterval') {
|
|
19958
|
-
interval = newInterval;
|
|
19959
|
-
if (timer) {
|
|
19960
|
-
clearInterval(timer);
|
|
19961
|
-
timer = setInterval(() => {
|
|
19962
|
-
self.postMessage({ type: 'tick' });
|
|
19963
|
-
}, interval);
|
|
19964
|
-
}
|
|
19965
|
-
}
|
|
19966
|
-
};
|
|
19967
|
-
`;
|
|
19968
|
-
function createHeartbeatWorker() {
|
|
19969
|
-
try {
|
|
19970
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
19971
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
19972
|
-
const worker = new Worker(workerUrl);
|
|
19973
|
-
URL.revokeObjectURL(workerUrl);
|
|
19974
|
-
return worker;
|
|
19975
|
-
} catch {
|
|
19976
|
-
return null;
|
|
19977
|
-
}
|
|
19978
|
-
}
|
|
19979
|
-
var HeartbeatManager = class {
|
|
19980
|
-
worker = null;
|
|
19981
|
-
fallbackTimer = null;
|
|
19982
|
-
interval = 3e4;
|
|
19983
|
-
onTick = null;
|
|
19984
|
-
isRunning = false;
|
|
19985
|
-
constructor() {
|
|
19986
|
-
this.worker = createHeartbeatWorker();
|
|
19987
|
-
if (this.worker) {
|
|
19988
|
-
this.worker.onmessage = (e) => {
|
|
19989
|
-
if (e.data.type === "tick" && this.onTick) {
|
|
19990
|
-
this.onTick();
|
|
19991
|
-
}
|
|
19992
|
-
};
|
|
19993
|
-
}
|
|
19994
|
-
}
|
|
19995
|
-
/**
|
|
19996
|
-
* Start the heartbeat
|
|
19997
|
-
* @param interval - Interval in milliseconds
|
|
19998
|
-
* @param onTick - Callback function to execute on each tick
|
|
19999
|
-
*/
|
|
20000
|
-
start(interval, onTick) {
|
|
20001
|
-
this.stop();
|
|
20002
|
-
this.interval = interval;
|
|
20003
|
-
this.onTick = onTick;
|
|
20004
|
-
this.isRunning = true;
|
|
20005
|
-
if (this.worker) {
|
|
20006
|
-
this.worker.postMessage({
|
|
20007
|
-
type: "start",
|
|
20008
|
-
interval
|
|
20009
|
-
});
|
|
20010
|
-
} else {
|
|
20011
|
-
this.fallbackTimer = setInterval(() => {
|
|
20012
|
-
if (this.onTick) {
|
|
20013
|
-
this.onTick();
|
|
20014
|
-
}
|
|
20015
|
-
}, interval);
|
|
20016
|
-
}
|
|
20017
|
-
}
|
|
20018
|
-
/**
|
|
20019
|
-
* Stop the heartbeat
|
|
20020
|
-
*/
|
|
20021
|
-
stop() {
|
|
20022
|
-
this.isRunning = false;
|
|
20023
|
-
this.onTick = null;
|
|
20024
|
-
if (this.worker) {
|
|
20025
|
-
this.worker.postMessage({ type: "stop" });
|
|
20026
|
-
}
|
|
20027
|
-
if (this.fallbackTimer) {
|
|
20028
|
-
clearInterval(this.fallbackTimer);
|
|
20029
|
-
this.fallbackTimer = null;
|
|
20030
|
-
}
|
|
20031
|
-
}
|
|
20032
|
-
/**
|
|
20033
|
-
* Update the heartbeat interval
|
|
20034
|
-
* @param interval - New interval in milliseconds
|
|
20035
|
-
*/
|
|
20036
|
-
updateInterval(interval) {
|
|
20037
|
-
this.interval = interval;
|
|
20038
|
-
if (!this.isRunning)
|
|
20039
|
-
return;
|
|
20040
|
-
if (this.worker) {
|
|
20041
|
-
this.worker.postMessage({
|
|
20042
|
-
type: "updateInterval",
|
|
20043
|
-
interval
|
|
20044
|
-
});
|
|
20045
|
-
} else if (this.fallbackTimer && this.onTick) {
|
|
20046
|
-
clearInterval(this.fallbackTimer);
|
|
20047
|
-
this.fallbackTimer = setInterval(() => {
|
|
20048
|
-
if (this.onTick) {
|
|
20049
|
-
this.onTick();
|
|
20050
|
-
}
|
|
20051
|
-
}, interval);
|
|
20052
|
-
}
|
|
20053
|
-
}
|
|
20054
|
-
/**
|
|
20055
|
-
* Destroy the heartbeat manager and release resources
|
|
20056
|
-
*/
|
|
20057
|
-
destroy() {
|
|
20058
|
-
this.stop();
|
|
20059
|
-
if (this.worker) {
|
|
20060
|
-
this.worker.terminate();
|
|
20061
|
-
this.worker = null;
|
|
20062
|
-
}
|
|
20063
|
-
}
|
|
20064
|
-
/**
|
|
20065
|
-
* Check if using Web Worker
|
|
20066
|
-
*/
|
|
20067
|
-
isUsingWorker() {
|
|
20068
|
-
return this.worker !== null;
|
|
20069
|
-
}
|
|
20070
|
-
};
|
|
20071
|
-
|
|
20072
19932
|
// core/socket.ts
|
|
20073
19933
|
var Socket = class {
|
|
20074
19934
|
callKit;
|
|
20075
19935
|
ws;
|
|
20076
19936
|
lastPingTime = void 0;
|
|
20077
|
-
|
|
19937
|
+
pingTimer;
|
|
20078
19938
|
/**
|
|
20079
19939
|
* @description reconnect timer
|
|
20080
19940
|
*/
|
|
@@ -20107,18 +19967,10 @@ self.onmessage = function(e) {
|
|
|
20107
19967
|
}
|
|
20108
19968
|
constructor(callKit) {
|
|
20109
19969
|
this.callKit = callKit;
|
|
20110
|
-
this.heartbeatManager = new HeartbeatManager();
|
|
20111
19970
|
}
|
|
20112
19971
|
get reconnectConfig() {
|
|
20113
19972
|
return this.callKit.config.getReconnectConfig("incall");
|
|
20114
19973
|
}
|
|
20115
|
-
get pingInterval() {
|
|
20116
|
-
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
20117
|
-
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
20118
|
-
return keepaliveInterval * 1e3;
|
|
20119
|
-
}
|
|
20120
|
-
return this.reconnectConfig.pingInterval;
|
|
20121
|
-
}
|
|
20122
19974
|
isConnected() {
|
|
20123
19975
|
return this.connectAuthState.isConnected;
|
|
20124
19976
|
}
|
|
@@ -20475,8 +20327,8 @@ self.onmessage = function(e) {
|
|
|
20475
20327
|
return;
|
|
20476
20328
|
this.send(SocketSendEvent.PING);
|
|
20477
20329
|
const now = Date.now();
|
|
20478
|
-
const { pingTimeout } = this.reconnectConfig;
|
|
20479
|
-
if (now - this.lastPingTime >
|
|
20330
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
20331
|
+
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
20480
20332
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
20481
20333
|
caller: "Socket.ping",
|
|
20482
20334
|
type: "INCALL",
|
|
@@ -20491,27 +20343,23 @@ self.onmessage = function(e) {
|
|
|
20491
20343
|
}
|
|
20492
20344
|
}
|
|
20493
20345
|
checkPing() {
|
|
20494
|
-
|
|
20346
|
+
if (this.pingTimer) {
|
|
20347
|
+
clearInterval(this.pingTimer);
|
|
20348
|
+
}
|
|
20349
|
+
const { pingInterval } = this.reconnectConfig;
|
|
20350
|
+
this.pingTimer = setInterval(() => {
|
|
20495
20351
|
this.ping();
|
|
20496
|
-
});
|
|
20497
|
-
this.callKit.logger.info(
|
|
20498
|
-
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
20499
|
-
{
|
|
20500
|
-
caller: "Socket.checkPing",
|
|
20501
|
-
type: "INCALL",
|
|
20502
|
-
content: {
|
|
20503
|
-
pingInterval: this.pingInterval,
|
|
20504
|
-
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
20505
|
-
}
|
|
20506
|
-
}
|
|
20507
|
-
);
|
|
20352
|
+
}, pingInterval);
|
|
20508
20353
|
}
|
|
20509
20354
|
/**
|
|
20510
20355
|
* reset socket connection and all states
|
|
20511
20356
|
*/
|
|
20512
20357
|
async reset(config) {
|
|
20513
20358
|
const { force = false } = config || {};
|
|
20514
|
-
this.
|
|
20359
|
+
if (this.pingTimer) {
|
|
20360
|
+
clearInterval(this.pingTimer);
|
|
20361
|
+
this.pingTimer = void 0;
|
|
20362
|
+
}
|
|
20515
20363
|
if (force) {
|
|
20516
20364
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20517
20365
|
event: "INCALL_RESET"
|
|
@@ -20522,12 +20370,6 @@ self.onmessage = function(e) {
|
|
|
20522
20370
|
this.setConnectAuthState("startConfirm", false);
|
|
20523
20371
|
this.clearWebSocket();
|
|
20524
20372
|
}
|
|
20525
|
-
/**
|
|
20526
|
-
* Destroy the heartbeat manager
|
|
20527
|
-
*/
|
|
20528
|
-
destroyHeartbeat() {
|
|
20529
|
-
this.heartbeatManager.destroy();
|
|
20530
|
-
}
|
|
20531
20373
|
attemptReconnect() {
|
|
20532
20374
|
if (this.reconnectTimer) {
|
|
20533
20375
|
clearTimeout(this.reconnectTimer);
|
|
@@ -20653,7 +20495,6 @@ self.onmessage = function(e) {
|
|
|
20653
20495
|
content: {
|
|
20654
20496
|
username,
|
|
20655
20497
|
password,
|
|
20656
|
-
ua: navigator.userAgent,
|
|
20657
20498
|
encryptionMethod,
|
|
20658
20499
|
encryptionPassword
|
|
20659
20500
|
}
|
|
@@ -20687,7 +20528,6 @@ self.onmessage = function(e) {
|
|
|
20687
20528
|
iceInfo: user.iceInfo,
|
|
20688
20529
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
20689
20530
|
logGather: user.logGather,
|
|
20690
|
-
keepaliveInterval: user.keepaliveInterval,
|
|
20691
20531
|
phoneType: user.phoneType,
|
|
20692
20532
|
// encryptionType is in extra
|
|
20693
20533
|
...extra
|