@koi-design/callkit 2.2.0-beta.4 → 2.3.0-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 +604 -600
- package/dist/index.global.js +31 -182
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +26 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -177
- 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 {
|
|
@@ -528,6 +528,12 @@ var CallSourceType = {
|
|
|
528
528
|
phoneNum: 1,
|
|
529
529
|
workOrderId: 2
|
|
530
530
|
};
|
|
531
|
+
var PhoneTypeEnum = {
|
|
532
|
+
SIP: 0,
|
|
533
|
+
TEL: 1,
|
|
534
|
+
OUT: 2,
|
|
535
|
+
SP: 5
|
|
536
|
+
};
|
|
531
537
|
var trackLogsDefaultConfig = {
|
|
532
538
|
enabled: false,
|
|
533
539
|
interval: 5e3,
|
|
@@ -691,7 +697,7 @@ var Call = class {
|
|
|
691
697
|
// package.json
|
|
692
698
|
var package_default = {
|
|
693
699
|
name: "@koi-design/callkit",
|
|
694
|
-
version: "2.
|
|
700
|
+
version: "2.3.0-beta.1",
|
|
695
701
|
description: "callkit",
|
|
696
702
|
author: "koi",
|
|
697
703
|
license: "ISC",
|
|
@@ -768,6 +774,7 @@ var Config = class {
|
|
|
768
774
|
password: "",
|
|
769
775
|
encryptionPassword: EncryptionMethod.INTERNAL,
|
|
770
776
|
sourceType: CallSourceType.phoneNum,
|
|
777
|
+
phoneType: PhoneTypeEnum.SIP,
|
|
771
778
|
// Extension number
|
|
772
779
|
extno: "",
|
|
773
780
|
workOrderId: "",
|
|
@@ -811,6 +818,7 @@ var Config = class {
|
|
|
811
818
|
encryptionPassword: "",
|
|
812
819
|
userPart: "",
|
|
813
820
|
sourceType: CallSourceType.phoneNum,
|
|
821
|
+
phoneType: PhoneTypeEnum.SIP,
|
|
814
822
|
extno: "",
|
|
815
823
|
workOrderId: "",
|
|
816
824
|
agentId: "",
|
|
@@ -16675,152 +16683,12 @@ var Connect = class {
|
|
|
16675
16683
|
}
|
|
16676
16684
|
};
|
|
16677
16685
|
|
|
16678
|
-
// core/heartbeat-worker.ts
|
|
16679
|
-
var workerCode = `
|
|
16680
|
-
let timer = null;
|
|
16681
|
-
let interval = 30000;
|
|
16682
|
-
|
|
16683
|
-
self.onmessage = function(e) {
|
|
16684
|
-
const { type, interval: newInterval } = e.data;
|
|
16685
|
-
|
|
16686
|
-
if (type === 'start') {
|
|
16687
|
-
if (timer) {
|
|
16688
|
-
clearInterval(timer);
|
|
16689
|
-
}
|
|
16690
|
-
interval = newInterval || interval;
|
|
16691
|
-
timer = setInterval(() => {
|
|
16692
|
-
self.postMessage({ type: 'tick' });
|
|
16693
|
-
}, interval);
|
|
16694
|
-
}
|
|
16695
|
-
|
|
16696
|
-
if (type === 'stop') {
|
|
16697
|
-
if (timer) {
|
|
16698
|
-
clearInterval(timer);
|
|
16699
|
-
timer = null;
|
|
16700
|
-
}
|
|
16701
|
-
}
|
|
16702
|
-
|
|
16703
|
-
if (type === 'updateInterval') {
|
|
16704
|
-
interval = newInterval;
|
|
16705
|
-
if (timer) {
|
|
16706
|
-
clearInterval(timer);
|
|
16707
|
-
timer = setInterval(() => {
|
|
16708
|
-
self.postMessage({ type: 'tick' });
|
|
16709
|
-
}, interval);
|
|
16710
|
-
}
|
|
16711
|
-
}
|
|
16712
|
-
};
|
|
16713
|
-
`;
|
|
16714
|
-
function createHeartbeatWorker() {
|
|
16715
|
-
try {
|
|
16716
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
16717
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
16718
|
-
const worker = new Worker(workerUrl);
|
|
16719
|
-
URL.revokeObjectURL(workerUrl);
|
|
16720
|
-
return worker;
|
|
16721
|
-
} catch {
|
|
16722
|
-
return null;
|
|
16723
|
-
}
|
|
16724
|
-
}
|
|
16725
|
-
var HeartbeatManager = class {
|
|
16726
|
-
worker = null;
|
|
16727
|
-
fallbackTimer = null;
|
|
16728
|
-
interval = 3e4;
|
|
16729
|
-
onTick = null;
|
|
16730
|
-
isRunning = false;
|
|
16731
|
-
constructor() {
|
|
16732
|
-
this.worker = createHeartbeatWorker();
|
|
16733
|
-
if (this.worker) {
|
|
16734
|
-
this.worker.onmessage = (e) => {
|
|
16735
|
-
if (e.data.type === "tick" && this.onTick) {
|
|
16736
|
-
this.onTick();
|
|
16737
|
-
}
|
|
16738
|
-
};
|
|
16739
|
-
}
|
|
16740
|
-
}
|
|
16741
|
-
/**
|
|
16742
|
-
* Start the heartbeat
|
|
16743
|
-
* @param interval - Interval in milliseconds
|
|
16744
|
-
* @param onTick - Callback function to execute on each tick
|
|
16745
|
-
*/
|
|
16746
|
-
start(interval, onTick) {
|
|
16747
|
-
this.stop();
|
|
16748
|
-
this.interval = interval;
|
|
16749
|
-
this.onTick = onTick;
|
|
16750
|
-
this.isRunning = true;
|
|
16751
|
-
if (this.worker) {
|
|
16752
|
-
this.worker.postMessage({
|
|
16753
|
-
type: "start",
|
|
16754
|
-
interval
|
|
16755
|
-
});
|
|
16756
|
-
} else {
|
|
16757
|
-
this.fallbackTimer = setInterval(() => {
|
|
16758
|
-
if (this.onTick) {
|
|
16759
|
-
this.onTick();
|
|
16760
|
-
}
|
|
16761
|
-
}, interval);
|
|
16762
|
-
}
|
|
16763
|
-
}
|
|
16764
|
-
/**
|
|
16765
|
-
* Stop the heartbeat
|
|
16766
|
-
*/
|
|
16767
|
-
stop() {
|
|
16768
|
-
this.isRunning = false;
|
|
16769
|
-
this.onTick = null;
|
|
16770
|
-
if (this.worker) {
|
|
16771
|
-
this.worker.postMessage({ type: "stop" });
|
|
16772
|
-
}
|
|
16773
|
-
if (this.fallbackTimer) {
|
|
16774
|
-
clearInterval(this.fallbackTimer);
|
|
16775
|
-
this.fallbackTimer = null;
|
|
16776
|
-
}
|
|
16777
|
-
}
|
|
16778
|
-
/**
|
|
16779
|
-
* Update the heartbeat interval
|
|
16780
|
-
* @param interval - New interval in milliseconds
|
|
16781
|
-
*/
|
|
16782
|
-
updateInterval(interval) {
|
|
16783
|
-
this.interval = interval;
|
|
16784
|
-
if (!this.isRunning)
|
|
16785
|
-
return;
|
|
16786
|
-
if (this.worker) {
|
|
16787
|
-
this.worker.postMessage({
|
|
16788
|
-
type: "updateInterval",
|
|
16789
|
-
interval
|
|
16790
|
-
});
|
|
16791
|
-
} else if (this.fallbackTimer && this.onTick) {
|
|
16792
|
-
clearInterval(this.fallbackTimer);
|
|
16793
|
-
this.fallbackTimer = setInterval(() => {
|
|
16794
|
-
if (this.onTick) {
|
|
16795
|
-
this.onTick();
|
|
16796
|
-
}
|
|
16797
|
-
}, interval);
|
|
16798
|
-
}
|
|
16799
|
-
}
|
|
16800
|
-
/**
|
|
16801
|
-
* Destroy the heartbeat manager and release resources
|
|
16802
|
-
*/
|
|
16803
|
-
destroy() {
|
|
16804
|
-
this.stop();
|
|
16805
|
-
if (this.worker) {
|
|
16806
|
-
this.worker.terminate();
|
|
16807
|
-
this.worker = null;
|
|
16808
|
-
}
|
|
16809
|
-
}
|
|
16810
|
-
/**
|
|
16811
|
-
* Check if using Web Worker
|
|
16812
|
-
*/
|
|
16813
|
-
isUsingWorker() {
|
|
16814
|
-
return this.worker !== null;
|
|
16815
|
-
}
|
|
16816
|
-
};
|
|
16817
|
-
|
|
16818
16686
|
// core/socket.ts
|
|
16819
16687
|
var Socket = class {
|
|
16820
16688
|
callKit;
|
|
16821
16689
|
ws;
|
|
16822
16690
|
lastPingTime = void 0;
|
|
16823
|
-
|
|
16691
|
+
pingTimer;
|
|
16824
16692
|
/**
|
|
16825
16693
|
* @description reconnect timer
|
|
16826
16694
|
*/
|
|
@@ -16853,18 +16721,10 @@ var Socket = class {
|
|
|
16853
16721
|
}
|
|
16854
16722
|
constructor(callKit) {
|
|
16855
16723
|
this.callKit = callKit;
|
|
16856
|
-
this.heartbeatManager = new HeartbeatManager();
|
|
16857
16724
|
}
|
|
16858
16725
|
get reconnectConfig() {
|
|
16859
16726
|
return this.callKit.config.getReconnectConfig("incall");
|
|
16860
16727
|
}
|
|
16861
|
-
get pingInterval() {
|
|
16862
|
-
const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
|
|
16863
|
-
if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
|
|
16864
|
-
return keepaliveInterval * 1e3;
|
|
16865
|
-
}
|
|
16866
|
-
return this.reconnectConfig.pingInterval;
|
|
16867
|
-
}
|
|
16868
16728
|
isConnected() {
|
|
16869
16729
|
return this.connectAuthState.isConnected;
|
|
16870
16730
|
}
|
|
@@ -17158,7 +17018,7 @@ var Socket = class {
|
|
|
17158
17018
|
return;
|
|
17159
17019
|
}
|
|
17160
17020
|
const { userInfo, version } = this.callKit.config.getConfig();
|
|
17161
|
-
const { sessionId, extno, agentId } = userInfo;
|
|
17021
|
+
const { sessionId, extno, agentId, phoneType } = userInfo;
|
|
17162
17022
|
if (!sessionId) {
|
|
17163
17023
|
this.callKit.logger.error("sessionId is empty", {
|
|
17164
17024
|
caller: "Socket.send",
|
|
@@ -17178,6 +17038,7 @@ var Socket = class {
|
|
|
17178
17038
|
if (SocketSendEvent.CALL === event) {
|
|
17179
17039
|
msg.phoneNum = extno;
|
|
17180
17040
|
msg.agentId = agentId;
|
|
17041
|
+
msg.phoneType = phoneType;
|
|
17181
17042
|
if (message?.sourceType === CallSourceType.phoneNum) {
|
|
17182
17043
|
delete msg.workOrderId;
|
|
17183
17044
|
} else if (message?.sourceType === CallSourceType.workOrderId) {
|
|
@@ -17199,8 +17060,8 @@ var Socket = class {
|
|
|
17199
17060
|
return;
|
|
17200
17061
|
this.send(SocketSendEvent.PING);
|
|
17201
17062
|
const now = Date.now();
|
|
17202
|
-
const { pingTimeout } = this.reconnectConfig;
|
|
17203
|
-
if (now - this.lastPingTime >
|
|
17063
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
17064
|
+
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
17204
17065
|
this.callKit.logger.warn("Ping timeout not connected", {
|
|
17205
17066
|
caller: "Socket.ping",
|
|
17206
17067
|
type: "INCALL",
|
|
@@ -17215,27 +17076,23 @@ var Socket = class {
|
|
|
17215
17076
|
}
|
|
17216
17077
|
}
|
|
17217
17078
|
checkPing() {
|
|
17218
|
-
|
|
17079
|
+
if (this.pingTimer) {
|
|
17080
|
+
clearInterval(this.pingTimer);
|
|
17081
|
+
}
|
|
17082
|
+
const { pingInterval } = this.reconnectConfig;
|
|
17083
|
+
this.pingTimer = setInterval(() => {
|
|
17219
17084
|
this.ping();
|
|
17220
|
-
});
|
|
17221
|
-
this.callKit.logger.info(
|
|
17222
|
-
`Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
|
|
17223
|
-
{
|
|
17224
|
-
caller: "Socket.checkPing",
|
|
17225
|
-
type: "INCALL",
|
|
17226
|
-
content: {
|
|
17227
|
-
pingInterval: this.pingInterval,
|
|
17228
|
-
usingWorker: this.heartbeatManager.isUsingWorker()
|
|
17229
|
-
}
|
|
17230
|
-
}
|
|
17231
|
-
);
|
|
17085
|
+
}, pingInterval);
|
|
17232
17086
|
}
|
|
17233
17087
|
/**
|
|
17234
17088
|
* reset socket connection and all states
|
|
17235
17089
|
*/
|
|
17236
17090
|
async reset(config) {
|
|
17237
17091
|
const { force = false } = config || {};
|
|
17238
|
-
this.
|
|
17092
|
+
if (this.pingTimer) {
|
|
17093
|
+
clearInterval(this.pingTimer);
|
|
17094
|
+
this.pingTimer = void 0;
|
|
17095
|
+
}
|
|
17239
17096
|
if (force) {
|
|
17240
17097
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
17241
17098
|
event: "INCALL_RESET"
|
|
@@ -17246,12 +17103,6 @@ var Socket = class {
|
|
|
17246
17103
|
this.setConnectAuthState("startConfirm", false);
|
|
17247
17104
|
this.clearWebSocket();
|
|
17248
17105
|
}
|
|
17249
|
-
/**
|
|
17250
|
-
* Destroy the heartbeat manager
|
|
17251
|
-
*/
|
|
17252
|
-
destroyHeartbeat() {
|
|
17253
|
-
this.heartbeatManager.destroy();
|
|
17254
|
-
}
|
|
17255
17106
|
attemptReconnect() {
|
|
17256
17107
|
if (this.reconnectTimer) {
|
|
17257
17108
|
clearTimeout(this.reconnectTimer);
|
|
@@ -17377,7 +17228,6 @@ var CallKit = class {
|
|
|
17377
17228
|
content: {
|
|
17378
17229
|
username,
|
|
17379
17230
|
password,
|
|
17380
|
-
ua: navigator.userAgent,
|
|
17381
17231
|
encryptionMethod,
|
|
17382
17232
|
encryptionPassword
|
|
17383
17233
|
}
|
|
@@ -17395,7 +17245,6 @@ var CallKit = class {
|
|
|
17395
17245
|
password: encryptionPassword,
|
|
17396
17246
|
timestamp: Date.now()
|
|
17397
17247
|
});
|
|
17398
|
-
console.log("user", user);
|
|
17399
17248
|
if (user) {
|
|
17400
17249
|
this.config.setConfig("userInfo", {
|
|
17401
17250
|
wsUrl: `wss://${user.wsUrl}`,
|
|
@@ -17412,7 +17261,7 @@ var CallKit = class {
|
|
|
17412
17261
|
iceInfo: user.iceInfo,
|
|
17413
17262
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
17414
17263
|
logGather: user.logGather,
|
|
17415
|
-
|
|
17264
|
+
phoneType: user.phoneType,
|
|
17416
17265
|
// encryptionType is in extra
|
|
17417
17266
|
...extra
|
|
17418
17267
|
});
|