@koi-design/callkit 2.0.0-beta.16 → 2.0.0-beta.18
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 +3 -4
- package/dist/index.global.js +120 -58
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +120 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,6 @@ declare class Socket {
|
|
|
80
80
|
private confirmAck;
|
|
81
81
|
private onMessage;
|
|
82
82
|
send(event: SocketSendEventType, message?: any): void;
|
|
83
|
-
sendMessage(event: SocketSendEventType, message?: any): Promise<void>;
|
|
84
83
|
private ping;
|
|
85
84
|
private checkPing;
|
|
86
85
|
/**
|
|
@@ -377,7 +376,6 @@ declare class Connect {
|
|
|
377
376
|
*@description Whether it's a re-connected
|
|
378
377
|
*/
|
|
379
378
|
isReConnected: boolean;
|
|
380
|
-
observeOptionsHeartbeatHandler: ReturnType<typeof setTimeout> | null;
|
|
381
379
|
/**
|
|
382
380
|
*@description Whether it's an outgoing call
|
|
383
381
|
*/
|
|
@@ -427,8 +425,9 @@ declare class Connect {
|
|
|
427
425
|
* @returns
|
|
428
426
|
*/
|
|
429
427
|
isInit(): boolean;
|
|
430
|
-
|
|
431
|
-
heartbeatFlag
|
|
428
|
+
private heartbeatInterval?;
|
|
429
|
+
private heartbeatFlag;
|
|
430
|
+
clearHeartbeat(): void;
|
|
432
431
|
startHeartbeat(): void;
|
|
433
432
|
socketTriggerHangup(callId: string): void;
|
|
434
433
|
register(): Promise<void>;
|
package/dist/index.global.js
CHANGED
|
@@ -3774,6 +3774,59 @@ var WebCall = (() => {
|
|
|
3774
3774
|
}
|
|
3775
3775
|
};
|
|
3776
3776
|
|
|
3777
|
+
// package.json
|
|
3778
|
+
var package_default = {
|
|
3779
|
+
name: "@koi-design/callkit",
|
|
3780
|
+
version: "2.0.0-beta.18",
|
|
3781
|
+
description: "callkit",
|
|
3782
|
+
author: "koi",
|
|
3783
|
+
license: "ISC",
|
|
3784
|
+
scripts: {
|
|
3785
|
+
build: "tsup",
|
|
3786
|
+
start: "tsup --watch",
|
|
3787
|
+
dev: "vite",
|
|
3788
|
+
lint: "eslint -c .eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
3789
|
+
prepare: "husky install",
|
|
3790
|
+
release: "tsup && node scripts/pkg.js"
|
|
3791
|
+
},
|
|
3792
|
+
exports: {
|
|
3793
|
+
".": {
|
|
3794
|
+
require: "./dist/index.js",
|
|
3795
|
+
import: "./dist/index.mjs"
|
|
3796
|
+
}
|
|
3797
|
+
},
|
|
3798
|
+
main: "./dist/index.js",
|
|
3799
|
+
module: "./dist/index.mjs",
|
|
3800
|
+
types: "./dist/index.d.ts",
|
|
3801
|
+
files: [
|
|
3802
|
+
"dist"
|
|
3803
|
+
],
|
|
3804
|
+
dependencies: {
|
|
3805
|
+
axios: "~0.26.1",
|
|
3806
|
+
"blueimp-md5": "^2.12.0",
|
|
3807
|
+
"eslint-plugin-jsonc": "^2.21.0",
|
|
3808
|
+
"json-stringify-safe": "^5.0.1",
|
|
3809
|
+
"sip.js": "^0.21.2"
|
|
3810
|
+
},
|
|
3811
|
+
devDependencies: {
|
|
3812
|
+
"@commitlint/cli": "^9.1.2",
|
|
3813
|
+
"@commitlint/config-conventional": "^9.1.2",
|
|
3814
|
+
"@koi-design/eslint-config-ts": "^0.0.14",
|
|
3815
|
+
"@types/blueimp-md5": "^2.18.2",
|
|
3816
|
+
archiver: "^5.3.1",
|
|
3817
|
+
consola: "^3.4.2",
|
|
3818
|
+
eslint: "~8.29.0",
|
|
3819
|
+
"eslint-config-prettier": "^10.1.5",
|
|
3820
|
+
"eslint-plugin-prettier": "^5.5.0",
|
|
3821
|
+
husky: "^8.0.3",
|
|
3822
|
+
"lint-staged": "^10.5.4",
|
|
3823
|
+
prettier: "^2.6.2",
|
|
3824
|
+
tsup: "6.6.3",
|
|
3825
|
+
typescript: "^4.6.3",
|
|
3826
|
+
vite: "^4"
|
|
3827
|
+
}
|
|
3828
|
+
};
|
|
3829
|
+
|
|
3777
3830
|
// package/config.ts
|
|
3778
3831
|
var Config = class {
|
|
3779
3832
|
callKit;
|
|
@@ -3781,7 +3834,7 @@ var WebCall = (() => {
|
|
|
3781
3834
|
this.callKit = callKit;
|
|
3782
3835
|
}
|
|
3783
3836
|
config = {
|
|
3784
|
-
version:
|
|
3837
|
+
version: package_default.version,
|
|
3785
3838
|
host: "",
|
|
3786
3839
|
log: "info",
|
|
3787
3840
|
trackLogs: trackLogsDefaultConfig,
|
|
@@ -18492,7 +18545,6 @@ var WebCall = (() => {
|
|
|
18492
18545
|
*@description Whether it's a re-connected
|
|
18493
18546
|
*/
|
|
18494
18547
|
isReConnected = false;
|
|
18495
|
-
observeOptionsHeartbeatHandler = null;
|
|
18496
18548
|
// sipConnected = false;
|
|
18497
18549
|
/**
|
|
18498
18550
|
*@description Whether it's an outgoing call
|
|
@@ -18565,7 +18617,7 @@ var WebCall = (() => {
|
|
|
18565
18617
|
}
|
|
18566
18618
|
}
|
|
18567
18619
|
this.setConnectStatus(CallStatus.init);
|
|
18568
|
-
this.
|
|
18620
|
+
this.clearHeartbeat();
|
|
18569
18621
|
}
|
|
18570
18622
|
getAduioReference() {
|
|
18571
18623
|
const { audioRef } = this.callKit.config.getConfig();
|
|
@@ -18630,16 +18682,19 @@ var WebCall = (() => {
|
|
|
18630
18682
|
isInit() {
|
|
18631
18683
|
return this.connectStatus === CallStatus.init;
|
|
18632
18684
|
}
|
|
18633
|
-
|
|
18634
|
-
|
|
18635
|
-
|
|
18636
|
-
|
|
18685
|
+
heartbeatInterval;
|
|
18686
|
+
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18687
|
+
clearHeartbeat() {
|
|
18688
|
+
if (this.heartbeatInterval) {
|
|
18689
|
+
clearInterval(this.heartbeatInterval);
|
|
18690
|
+
this.heartbeatInterval = null;
|
|
18637
18691
|
}
|
|
18692
|
+
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18638
18693
|
}
|
|
18639
|
-
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18640
18694
|
startHeartbeat() {
|
|
18641
18695
|
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18642
|
-
|
|
18696
|
+
this.clearHeartbeat();
|
|
18697
|
+
this.heartbeatInterval = setInterval(() => {
|
|
18643
18698
|
this.heartbeatFlag -= 1;
|
|
18644
18699
|
if (this.heartbeatFlag <= 0) {
|
|
18645
18700
|
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
@@ -18916,10 +18971,8 @@ var WebCall = (() => {
|
|
|
18916
18971
|
sessionState: state
|
|
18917
18972
|
}
|
|
18918
18973
|
});
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
this.hasInvite = false;
|
|
18922
|
-
} else if (!this.isUnprompted) {
|
|
18974
|
+
this.hasInvite = false;
|
|
18975
|
+
if (!this.isUnprompted) {
|
|
18923
18976
|
this.callKit.callCenter.callEnd();
|
|
18924
18977
|
}
|
|
18925
18978
|
this.isUnprompted = false;
|
|
@@ -18956,6 +19009,14 @@ var WebCall = (() => {
|
|
|
18956
19009
|
const inviteData = formatGetInviteData(info);
|
|
18957
19010
|
if (inviteData?.callUuid) {
|
|
18958
19011
|
this.setCallId(inviteData.callUuid);
|
|
19012
|
+
} else {
|
|
19013
|
+
this.setCallId(null);
|
|
19014
|
+
this.callKit.logger.error("call id is not exist", {
|
|
19015
|
+
caller: "Connect.register.onInvite",
|
|
19016
|
+
content: {
|
|
19017
|
+
inviteData
|
|
19018
|
+
}
|
|
19019
|
+
});
|
|
18959
19020
|
}
|
|
18960
19021
|
} catch (error) {
|
|
18961
19022
|
this.callKit.logger.info(error, {
|
|
@@ -18971,7 +19032,9 @@ var WebCall = (() => {
|
|
|
18971
19032
|
} else {
|
|
18972
19033
|
this.hasInvite = true;
|
|
18973
19034
|
const reject = () => {
|
|
18974
|
-
this.currentSession.
|
|
19035
|
+
if (this.currentSession?.state !== SessionState2.Terminated && this.currentSession?.state !== SessionState2.Terminating) {
|
|
19036
|
+
this.currentSession.reject();
|
|
19037
|
+
}
|
|
18975
19038
|
this.hasInvite = false;
|
|
18976
19039
|
this.callKit.callCenter.callEnd(true, false);
|
|
18977
19040
|
};
|
|
@@ -19054,7 +19117,7 @@ var WebCall = (() => {
|
|
|
19054
19117
|
reconnectTimer;
|
|
19055
19118
|
reconnectAttempts = 0;
|
|
19056
19119
|
startReconnectTimer() {
|
|
19057
|
-
if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts) {
|
|
19120
|
+
if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts && this.callKit.config.isLogin()) {
|
|
19058
19121
|
this.callKit.reset();
|
|
19059
19122
|
this.callKit.logger.error("Reconnect failed max attempts", {
|
|
19060
19123
|
caller: "Connect.startReconnectTimer",
|
|
@@ -19208,7 +19271,9 @@ var WebCall = (() => {
|
|
|
19208
19271
|
const shouldSendBye = this.isRinging() || this.isCalling();
|
|
19209
19272
|
if (shouldSendBye) {
|
|
19210
19273
|
if (this.hasInvite) {
|
|
19211
|
-
this.currentSession?.
|
|
19274
|
+
if (this.currentSession?.state !== SessionState2.Terminated && this.currentSession?.state !== SessionState2.Terminating) {
|
|
19275
|
+
this.currentSession.reject();
|
|
19276
|
+
}
|
|
19212
19277
|
this.hasInvite = false;
|
|
19213
19278
|
} else {
|
|
19214
19279
|
await this.currentSession?.bye();
|
|
@@ -19493,11 +19558,26 @@ var WebCall = (() => {
|
|
|
19493
19558
|
}
|
|
19494
19559
|
onMessage(ev) {
|
|
19495
19560
|
const data = JSON.parse(ev.data);
|
|
19561
|
+
let content = {};
|
|
19562
|
+
try {
|
|
19563
|
+
if (data.data) {
|
|
19564
|
+
content = JSON.parse(data.data);
|
|
19565
|
+
}
|
|
19566
|
+
} catch (error) {
|
|
19567
|
+
this.callKit.logger.info("socket onMessage parse error", {
|
|
19568
|
+
caller: "Socket.onMessage",
|
|
19569
|
+
type: "INCALL",
|
|
19570
|
+
content: {
|
|
19571
|
+
data: data.data
|
|
19572
|
+
}
|
|
19573
|
+
});
|
|
19574
|
+
content = data.data;
|
|
19575
|
+
}
|
|
19496
19576
|
this.callKit.logger.info("socket onMessage", {
|
|
19497
19577
|
caller: "Socket.onMessage",
|
|
19498
19578
|
type: "INCALL",
|
|
19499
19579
|
content: {
|
|
19500
|
-
data:
|
|
19580
|
+
data: content,
|
|
19501
19581
|
event: data.event
|
|
19502
19582
|
}
|
|
19503
19583
|
});
|
|
@@ -19511,7 +19591,7 @@ var WebCall = (() => {
|
|
|
19511
19591
|
caller: "Socket.onMessage",
|
|
19512
19592
|
type: "INCALL",
|
|
19513
19593
|
content: {
|
|
19514
|
-
data:
|
|
19594
|
+
data: content,
|
|
19515
19595
|
event: SocketReceiveEvent.START_CONFIRM
|
|
19516
19596
|
}
|
|
19517
19597
|
});
|
|
@@ -19522,7 +19602,7 @@ var WebCall = (() => {
|
|
|
19522
19602
|
caller: "Socket.onMessage",
|
|
19523
19603
|
type: "INCALL",
|
|
19524
19604
|
content: {
|
|
19525
|
-
data:
|
|
19605
|
+
data: content,
|
|
19526
19606
|
event: SocketReceiveEvent.CALL_SUCCESS
|
|
19527
19607
|
}
|
|
19528
19608
|
});
|
|
@@ -19532,7 +19612,7 @@ var WebCall = (() => {
|
|
|
19532
19612
|
caller: "Socket.onMessage",
|
|
19533
19613
|
type: "INCALL",
|
|
19534
19614
|
content: {
|
|
19535
|
-
data:
|
|
19615
|
+
data: content,
|
|
19536
19616
|
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
19537
19617
|
}
|
|
19538
19618
|
});
|
|
@@ -19543,7 +19623,7 @@ var WebCall = (() => {
|
|
|
19543
19623
|
caller: `Socket.onMessage:${data.event}`,
|
|
19544
19624
|
type: "INCALL",
|
|
19545
19625
|
content: {
|
|
19546
|
-
data:
|
|
19626
|
+
data: content,
|
|
19547
19627
|
event: SocketReceiveEvent.CUSTOMER_RINGING
|
|
19548
19628
|
}
|
|
19549
19629
|
});
|
|
@@ -19553,7 +19633,7 @@ var WebCall = (() => {
|
|
|
19553
19633
|
caller: "Socket.onMessage",
|
|
19554
19634
|
type: "INCALL",
|
|
19555
19635
|
content: {
|
|
19556
|
-
data:
|
|
19636
|
+
data: content,
|
|
19557
19637
|
event: SocketReceiveEvent.CUSTOMER_PICK_UP
|
|
19558
19638
|
}
|
|
19559
19639
|
});
|
|
@@ -19564,7 +19644,7 @@ var WebCall = (() => {
|
|
|
19564
19644
|
caller: "Socket.onMessage",
|
|
19565
19645
|
type: "INCALL",
|
|
19566
19646
|
content: {
|
|
19567
|
-
data:
|
|
19647
|
+
data: content,
|
|
19568
19648
|
event: SocketReceiveEvent.AGENT_PICK_UP
|
|
19569
19649
|
}
|
|
19570
19650
|
});
|
|
@@ -19575,13 +19655,13 @@ var WebCall = (() => {
|
|
|
19575
19655
|
caller: `Socket.onMessage:${data.event}`,
|
|
19576
19656
|
type: "INCALL",
|
|
19577
19657
|
content: {
|
|
19578
|
-
data:
|
|
19658
|
+
data: content,
|
|
19579
19659
|
event: SocketReceiveEvent.CUSTOMER_HANG_UP
|
|
19580
19660
|
}
|
|
19581
19661
|
});
|
|
19582
19662
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
19583
|
-
if (
|
|
19584
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19663
|
+
if (content?.callUuid) {
|
|
19664
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19585
19665
|
}
|
|
19586
19666
|
}
|
|
19587
19667
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
@@ -19589,13 +19669,13 @@ var WebCall = (() => {
|
|
|
19589
19669
|
caller: "Socket.onMessage",
|
|
19590
19670
|
type: "INCALL",
|
|
19591
19671
|
content: {
|
|
19592
|
-
data:
|
|
19672
|
+
data: content,
|
|
19593
19673
|
event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
|
|
19594
19674
|
}
|
|
19595
19675
|
});
|
|
19596
19676
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
19597
|
-
if (
|
|
19598
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19677
|
+
if (content?.callUuid) {
|
|
19678
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19599
19679
|
}
|
|
19600
19680
|
}
|
|
19601
19681
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
@@ -19603,18 +19683,18 @@ var WebCall = (() => {
|
|
|
19603
19683
|
caller: `Socket.onMessage:${data.event}`,
|
|
19604
19684
|
type: "INCALL",
|
|
19605
19685
|
content: {
|
|
19606
|
-
data:
|
|
19686
|
+
data: content,
|
|
19607
19687
|
event: SocketReceiveEvent.CALL_CDR
|
|
19608
19688
|
}
|
|
19609
19689
|
});
|
|
19610
|
-
this.callKit.trigger(KitEvent.CALL_CDR,
|
|
19690
|
+
this.callKit.trigger(KitEvent.CALL_CDR, content);
|
|
19611
19691
|
}
|
|
19612
19692
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
19613
19693
|
this.callKit.logger.info(data.msg, {
|
|
19614
19694
|
caller: `Socket.onMessage:${data.event}`,
|
|
19615
19695
|
type: "INCALL",
|
|
19616
19696
|
content: {
|
|
19617
|
-
data:
|
|
19697
|
+
data: content,
|
|
19618
19698
|
event: SocketReceiveEvent.STOP_CONFIRM
|
|
19619
19699
|
}
|
|
19620
19700
|
});
|
|
@@ -19625,7 +19705,7 @@ var WebCall = (() => {
|
|
|
19625
19705
|
caller: `Socket.onMessage:${data.event}`,
|
|
19626
19706
|
type: "INCALL",
|
|
19627
19707
|
content: {
|
|
19628
|
-
data:
|
|
19708
|
+
data: content,
|
|
19629
19709
|
event: SocketReceiveEvent.CLOSE
|
|
19630
19710
|
}
|
|
19631
19711
|
});
|
|
@@ -19641,7 +19721,7 @@ var WebCall = (() => {
|
|
|
19641
19721
|
type: "INCALL",
|
|
19642
19722
|
content: {
|
|
19643
19723
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
19644
|
-
data:
|
|
19724
|
+
data: content
|
|
19645
19725
|
}
|
|
19646
19726
|
});
|
|
19647
19727
|
}
|
|
@@ -19652,7 +19732,7 @@ var WebCall = (() => {
|
|
|
19652
19732
|
caller: `Socket.onMessage:${data.event}`,
|
|
19653
19733
|
type: "INCALL",
|
|
19654
19734
|
content: {
|
|
19655
|
-
data:
|
|
19735
|
+
data: content,
|
|
19656
19736
|
event: SocketReceiveEvent.SESSION_ERROR
|
|
19657
19737
|
}
|
|
19658
19738
|
});
|
|
@@ -19662,12 +19742,12 @@ var WebCall = (() => {
|
|
|
19662
19742
|
caller: `Socket.onMessage:${data.event}`,
|
|
19663
19743
|
type: "INCALL",
|
|
19664
19744
|
content: {
|
|
19665
|
-
data:
|
|
19745
|
+
data: content,
|
|
19666
19746
|
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
19667
19747
|
}
|
|
19668
19748
|
});
|
|
19669
|
-
if (
|
|
19670
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19749
|
+
if (content?.callUuid) {
|
|
19750
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19671
19751
|
}
|
|
19672
19752
|
}
|
|
19673
19753
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
@@ -19687,7 +19767,7 @@ var WebCall = (() => {
|
|
|
19687
19767
|
});
|
|
19688
19768
|
return;
|
|
19689
19769
|
}
|
|
19690
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
19770
|
+
const { userInfo, version } = this.callKit.config.getConfig();
|
|
19691
19771
|
const { sessionId, extno, agentId } = userInfo;
|
|
19692
19772
|
if (!sessionId) {
|
|
19693
19773
|
this.callKit.logger.error("sessionId is empty", {
|
|
@@ -19702,6 +19782,7 @@ var WebCall = (() => {
|
|
|
19702
19782
|
const msg = {
|
|
19703
19783
|
event,
|
|
19704
19784
|
sessionId,
|
|
19785
|
+
version,
|
|
19705
19786
|
...message
|
|
19706
19787
|
};
|
|
19707
19788
|
if (SocketSendEvent.CALL === event) {
|
|
@@ -19730,25 +19811,6 @@ var WebCall = (() => {
|
|
|
19730
19811
|
break;
|
|
19731
19812
|
}
|
|
19732
19813
|
}
|
|
19733
|
-
async sendMessage(event, message) {
|
|
19734
|
-
if (!this.isConnected) {
|
|
19735
|
-
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19736
|
-
event: "INCALL_NOT_CONNECTED"
|
|
19737
|
-
});
|
|
19738
|
-
this.callKit.logger.error("socket not connected", {
|
|
19739
|
-
caller: "Socket.sendMessage",
|
|
19740
|
-
type: "INCALL",
|
|
19741
|
-
content: {
|
|
19742
|
-
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
19743
|
-
message
|
|
19744
|
-
}
|
|
19745
|
-
});
|
|
19746
|
-
return;
|
|
19747
|
-
}
|
|
19748
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
19749
|
-
const { sessionId } = userInfo;
|
|
19750
|
-
this.ws?.send(JSON.stringify({ event, sessionId, ...message }));
|
|
19751
|
-
}
|
|
19752
19814
|
ping() {
|
|
19753
19815
|
if (!this.isConnected)
|
|
19754
19816
|
return;
|