@koi-design/callkit 2.0.0-beta.9 → 2.0.0
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 +33 -23
- package/dist/index.global.js +277 -198
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +277 -198
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -198
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -3352,6 +3352,10 @@ var WebCall = (() => {
|
|
|
3352
3352
|
* Mute status change
|
|
3353
3353
|
*/
|
|
3354
3354
|
KIT_SET_MUTE: "muteChange",
|
|
3355
|
+
/**
|
|
3356
|
+
* Call id change
|
|
3357
|
+
*/
|
|
3358
|
+
KIT_CALL_ID_CHANGE: "callIdChange",
|
|
3355
3359
|
/**
|
|
3356
3360
|
* Error
|
|
3357
3361
|
*/
|
|
@@ -3613,7 +3617,8 @@ var WebCall = (() => {
|
|
|
3613
3617
|
/**
|
|
3614
3618
|
* Error
|
|
3615
3619
|
*/
|
|
3616
|
-
ERROR: "ERROR"
|
|
3620
|
+
ERROR: "ERROR",
|
|
3621
|
+
SESSION_ERROR: "SESSION_ERROR"
|
|
3617
3622
|
};
|
|
3618
3623
|
var EncryptionMethod = {
|
|
3619
3624
|
NONE: "NONE",
|
|
@@ -3705,6 +3710,14 @@ var WebCall = (() => {
|
|
|
3705
3710
|
return;
|
|
3706
3711
|
if (!this.callKit.config.check())
|
|
3707
3712
|
return;
|
|
3713
|
+
this.callKit.logger.info("callEnd", {
|
|
3714
|
+
caller: "Call.callEnd",
|
|
3715
|
+
content: {
|
|
3716
|
+
isUnprompted,
|
|
3717
|
+
isError,
|
|
3718
|
+
connectStatus: this.callKit.connect.connectStatus
|
|
3719
|
+
}
|
|
3720
|
+
});
|
|
3708
3721
|
this.callKit.connect.hangup(isUnprompted, isError);
|
|
3709
3722
|
}
|
|
3710
3723
|
async callHold() {
|
|
@@ -3769,6 +3782,59 @@ var WebCall = (() => {
|
|
|
3769
3782
|
}
|
|
3770
3783
|
};
|
|
3771
3784
|
|
|
3785
|
+
// package.json
|
|
3786
|
+
var package_default = {
|
|
3787
|
+
name: "@koi-design/callkit",
|
|
3788
|
+
version: "2.0.0",
|
|
3789
|
+
description: "callkit",
|
|
3790
|
+
author: "koi",
|
|
3791
|
+
license: "ISC",
|
|
3792
|
+
scripts: {
|
|
3793
|
+
build: "tsup",
|
|
3794
|
+
start: "tsup --watch",
|
|
3795
|
+
dev: "vite",
|
|
3796
|
+
lint: "eslint -c .eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
3797
|
+
prepare: "husky install",
|
|
3798
|
+
release: "tsup && node scripts/pkg.js"
|
|
3799
|
+
},
|
|
3800
|
+
exports: {
|
|
3801
|
+
".": {
|
|
3802
|
+
require: "./dist/index.js",
|
|
3803
|
+
import: "./dist/index.mjs"
|
|
3804
|
+
}
|
|
3805
|
+
},
|
|
3806
|
+
main: "./dist/index.js",
|
|
3807
|
+
module: "./dist/index.mjs",
|
|
3808
|
+
types: "./dist/index.d.ts",
|
|
3809
|
+
files: [
|
|
3810
|
+
"dist"
|
|
3811
|
+
],
|
|
3812
|
+
dependencies: {
|
|
3813
|
+
axios: "~0.26.1",
|
|
3814
|
+
"blueimp-md5": "^2.12.0",
|
|
3815
|
+
"eslint-plugin-jsonc": "^2.21.0",
|
|
3816
|
+
"json-stringify-safe": "^5.0.1",
|
|
3817
|
+
"sip.js": "^0.21.2"
|
|
3818
|
+
},
|
|
3819
|
+
devDependencies: {
|
|
3820
|
+
"@commitlint/cli": "^9.1.2",
|
|
3821
|
+
"@commitlint/config-conventional": "^9.1.2",
|
|
3822
|
+
"@koi-design/eslint-config-ts": "^0.0.14",
|
|
3823
|
+
"@types/blueimp-md5": "^2.18.2",
|
|
3824
|
+
archiver: "^5.3.1",
|
|
3825
|
+
consola: "^3.4.2",
|
|
3826
|
+
eslint: "~8.29.0",
|
|
3827
|
+
"eslint-config-prettier": "^10.1.5",
|
|
3828
|
+
"eslint-plugin-prettier": "^5.5.0",
|
|
3829
|
+
husky: "^8.0.3",
|
|
3830
|
+
"lint-staged": "^10.5.4",
|
|
3831
|
+
prettier: "^2.6.2",
|
|
3832
|
+
tsup: "6.6.3",
|
|
3833
|
+
typescript: "^4.6.3",
|
|
3834
|
+
vite: "^4"
|
|
3835
|
+
}
|
|
3836
|
+
};
|
|
3837
|
+
|
|
3772
3838
|
// package/config.ts
|
|
3773
3839
|
var Config = class {
|
|
3774
3840
|
callKit;
|
|
@@ -3776,7 +3842,7 @@ var WebCall = (() => {
|
|
|
3776
3842
|
this.callKit = callKit;
|
|
3777
3843
|
}
|
|
3778
3844
|
config = {
|
|
3779
|
-
version:
|
|
3845
|
+
version: `v${package_default.version}`,
|
|
3780
3846
|
host: "",
|
|
3781
3847
|
log: "info",
|
|
3782
3848
|
trackLogs: trackLogsDefaultConfig,
|
|
@@ -3865,7 +3931,7 @@ var WebCall = (() => {
|
|
|
3865
3931
|
return true;
|
|
3866
3932
|
}
|
|
3867
3933
|
getTrackLogsConfig() {
|
|
3868
|
-
return this.
|
|
3934
|
+
return this.config?.trackLogs ?? trackLogsDefaultConfig;
|
|
3869
3935
|
}
|
|
3870
3936
|
enableTrackLogs(enabled) {
|
|
3871
3937
|
this.config.trackLogs.enabled = enabled;
|
|
@@ -3897,8 +3963,8 @@ var WebCall = (() => {
|
|
|
3897
3963
|
this.startTrackLogsTimer();
|
|
3898
3964
|
}
|
|
3899
3965
|
startTrackLogsTimer() {
|
|
3900
|
-
const { interval
|
|
3901
|
-
if (
|
|
3966
|
+
const { interval } = this.callKit.config.getTrackLogsConfig();
|
|
3967
|
+
if (this.trackLogsTimer) {
|
|
3902
3968
|
return;
|
|
3903
3969
|
}
|
|
3904
3970
|
this.trackLogsTimer = setInterval(() => {
|
|
@@ -3968,7 +4034,7 @@ var WebCall = (() => {
|
|
|
3968
4034
|
console.log(`%c${logString}`, `color: orange;`);
|
|
3969
4035
|
}
|
|
3970
4036
|
}
|
|
3971
|
-
error(msg, extra) {
|
|
4037
|
+
error(msg, extra, noTrigger = false) {
|
|
3972
4038
|
const errorMsg = msg instanceof Error ? msg.message : msg;
|
|
3973
4039
|
const logString = this.catchLog(errorMsg, extra, "error");
|
|
3974
4040
|
if (getLevel(this.level) >= getLevel("error")) {
|
|
@@ -3976,11 +4042,13 @@ var WebCall = (() => {
|
|
|
3976
4042
|
}
|
|
3977
4043
|
const { errCode, ...rest } = extra?.content ?? {};
|
|
3978
4044
|
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
4045
|
+
if (!noTrigger) {
|
|
4046
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
4047
|
+
code: errorCode,
|
|
4048
|
+
msg: errorMsg,
|
|
4049
|
+
data: rest
|
|
4050
|
+
});
|
|
4051
|
+
}
|
|
3984
4052
|
const error = new Error(errorMsg);
|
|
3985
4053
|
error.name = "CallKitError";
|
|
3986
4054
|
error.code = errorCode;
|
|
@@ -4002,7 +4070,7 @@ var WebCall = (() => {
|
|
|
4002
4070
|
if (enabled) {
|
|
4003
4071
|
this.pendingTrackLogs.push(logString);
|
|
4004
4072
|
}
|
|
4005
|
-
this.callKit.trigger(KitEvent.KIT_LOG, logString);
|
|
4073
|
+
this.callKit.trigger(KitEvent.KIT_LOG, logString, true);
|
|
4006
4074
|
return logString;
|
|
4007
4075
|
}
|
|
4008
4076
|
};
|
|
@@ -18460,43 +18528,46 @@ var WebCall = (() => {
|
|
|
18460
18528
|
var Connect = class {
|
|
18461
18529
|
callKit;
|
|
18462
18530
|
/**
|
|
18463
|
-
|
|
18531
|
+
*@description Reconnect config
|
|
18532
|
+
*/
|
|
18533
|
+
reconnectConfig;
|
|
18534
|
+
/**
|
|
18535
|
+
*@description Whether muted
|
|
18536
|
+
*/
|
|
18537
|
+
isMute = false;
|
|
18538
|
+
/**
|
|
18539
|
+
*@description Whether registered
|
|
18540
|
+
*/
|
|
18541
|
+
isRegister = false;
|
|
18542
|
+
/**
|
|
18543
|
+
*@description Whether holding
|
|
18544
|
+
*/
|
|
18545
|
+
isHold = false;
|
|
18546
|
+
/**
|
|
18547
|
+
*@description Connect status: init registered connecting calling
|
|
18464
18548
|
*/
|
|
18465
18549
|
connectStatus = CallStatus.init;
|
|
18466
18550
|
currentSession;
|
|
18467
18551
|
mediaStream;
|
|
18468
18552
|
userAgent;
|
|
18469
18553
|
registerer;
|
|
18470
|
-
// current call id for invite data
|
|
18471
|
-
currentCallId;
|
|
18472
18554
|
/**
|
|
18473
|
-
|
|
18555
|
+
*@description Whether it's a re-connected
|
|
18474
18556
|
*/
|
|
18475
18557
|
isReConnected = false;
|
|
18476
|
-
observeOptionsHeartbeatHandler = null;
|
|
18477
18558
|
// sipConnected = false;
|
|
18478
18559
|
/**
|
|
18479
|
-
|
|
18560
|
+
*@description Whether it's an outgoing call
|
|
18480
18561
|
*/
|
|
18481
18562
|
isOutgoing = false;
|
|
18482
18563
|
/**
|
|
18483
|
-
|
|
18564
|
+
*@description Whether it's an active hangup
|
|
18484
18565
|
*/
|
|
18485
18566
|
isUnprompted = false;
|
|
18486
|
-
isCurrentSessionInvited = false;
|
|
18487
|
-
reconnectConfig;
|
|
18488
18567
|
/**
|
|
18489
|
-
|
|
18568
|
+
*@description Whether the current session is invited
|
|
18490
18569
|
*/
|
|
18491
|
-
|
|
18492
|
-
/**
|
|
18493
|
-
* Whether registered
|
|
18494
|
-
*/
|
|
18495
|
-
isRegister = false;
|
|
18496
|
-
/**
|
|
18497
|
-
* Whether holding
|
|
18498
|
-
*/
|
|
18499
|
-
isHold = false;
|
|
18570
|
+
hasInvite = false;
|
|
18500
18571
|
constructor(callKit) {
|
|
18501
18572
|
this.callKit = callKit;
|
|
18502
18573
|
const { reconnect = {} } = this.callKit.config.getConfig();
|
|
@@ -18505,15 +18576,33 @@ var WebCall = (() => {
|
|
|
18505
18576
|
...reconnect
|
|
18506
18577
|
};
|
|
18507
18578
|
}
|
|
18579
|
+
// current call id for invite data
|
|
18580
|
+
currentCallId = null;
|
|
18581
|
+
setCallId(callId) {
|
|
18582
|
+
this.callKit.logger.info("setCallId", {
|
|
18583
|
+
caller: "Connect.setCallId",
|
|
18584
|
+
content: {
|
|
18585
|
+
callId
|
|
18586
|
+
}
|
|
18587
|
+
});
|
|
18588
|
+
this.currentCallId = callId;
|
|
18589
|
+
this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
|
|
18590
|
+
}
|
|
18508
18591
|
async reset() {
|
|
18509
18592
|
if (this.isHolding()) {
|
|
18510
|
-
this.setHold(false);
|
|
18593
|
+
await this.setHold(false);
|
|
18594
|
+
}
|
|
18595
|
+
if (this.isMuted()) {
|
|
18596
|
+
await this.setMute(false);
|
|
18511
18597
|
}
|
|
18512
18598
|
if (this.connectStatus !== CallStatus.init) {
|
|
18513
18599
|
this.setConnectStatus(CallStatus.init);
|
|
18514
18600
|
}
|
|
18515
18601
|
if (this.isRegistered()) {
|
|
18516
|
-
this.unregister();
|
|
18602
|
+
await this.unregister();
|
|
18603
|
+
}
|
|
18604
|
+
if (this.currentCallId) {
|
|
18605
|
+
this.setCallId(null);
|
|
18517
18606
|
}
|
|
18518
18607
|
this.currentSession = void 0;
|
|
18519
18608
|
this.mediaStream = void 0;
|
|
@@ -18521,7 +18610,7 @@ var WebCall = (() => {
|
|
|
18521
18610
|
this.registerer = void 0;
|
|
18522
18611
|
this.isOutgoing = false;
|
|
18523
18612
|
this.isUnprompted = false;
|
|
18524
|
-
this.
|
|
18613
|
+
this.hasInvite = false;
|
|
18525
18614
|
if (this.mediaStream) {
|
|
18526
18615
|
try {
|
|
18527
18616
|
closeStream(this.mediaStream);
|
|
@@ -18538,7 +18627,7 @@ var WebCall = (() => {
|
|
|
18538
18627
|
}
|
|
18539
18628
|
}
|
|
18540
18629
|
this.setConnectStatus(CallStatus.init);
|
|
18541
|
-
this.
|
|
18630
|
+
this.clearHeartbeat();
|
|
18542
18631
|
}
|
|
18543
18632
|
getAduioReference() {
|
|
18544
18633
|
const { audioRef } = this.callKit.config.getConfig();
|
|
@@ -18603,16 +18692,19 @@ var WebCall = (() => {
|
|
|
18603
18692
|
isInit() {
|
|
18604
18693
|
return this.connectStatus === CallStatus.init;
|
|
18605
18694
|
}
|
|
18606
|
-
|
|
18607
|
-
|
|
18608
|
-
|
|
18609
|
-
|
|
18695
|
+
heartbeatInterval;
|
|
18696
|
+
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18697
|
+
clearHeartbeat() {
|
|
18698
|
+
if (this.heartbeatInterval) {
|
|
18699
|
+
clearInterval(this.heartbeatInterval);
|
|
18700
|
+
this.heartbeatInterval = null;
|
|
18610
18701
|
}
|
|
18702
|
+
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18611
18703
|
}
|
|
18612
|
-
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18613
18704
|
startHeartbeat() {
|
|
18614
18705
|
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18615
|
-
|
|
18706
|
+
this.clearHeartbeat();
|
|
18707
|
+
this.heartbeatInterval = setInterval(() => {
|
|
18616
18708
|
this.heartbeatFlag -= 1;
|
|
18617
18709
|
if (this.heartbeatFlag <= 0) {
|
|
18618
18710
|
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
@@ -18645,13 +18737,13 @@ var WebCall = (() => {
|
|
|
18645
18737
|
});
|
|
18646
18738
|
return;
|
|
18647
18739
|
}
|
|
18740
|
+
this.callKit.reset();
|
|
18648
18741
|
this.callKit.logger.error("connectStatus is not init", {
|
|
18649
18742
|
caller: "Connect.register",
|
|
18650
18743
|
content: {
|
|
18651
18744
|
errCode: ErrorCode.CONNECT_CALL_STATUS_ERROR
|
|
18652
18745
|
}
|
|
18653
18746
|
});
|
|
18654
|
-
this.callKit.reset();
|
|
18655
18747
|
return;
|
|
18656
18748
|
}
|
|
18657
18749
|
this.callKit.logger.info("connect register", {
|
|
@@ -18661,13 +18753,13 @@ var WebCall = (() => {
|
|
|
18661
18753
|
}
|
|
18662
18754
|
});
|
|
18663
18755
|
await this.permission().catch((err) => {
|
|
18756
|
+
this.callKit.reset();
|
|
18664
18757
|
this.callKit.logger.error(err, {
|
|
18665
18758
|
caller: "Connect.register",
|
|
18666
18759
|
content: {
|
|
18667
18760
|
errCode: ErrorCode.WEBRTC_USER_MEDIA_ERROR
|
|
18668
18761
|
}
|
|
18669
18762
|
});
|
|
18670
|
-
this.callKit.reset();
|
|
18671
18763
|
});
|
|
18672
18764
|
const { userInfo, constrains } = this.callKit.config.getConfig();
|
|
18673
18765
|
const localStreamFactory = async () => {
|
|
@@ -18733,19 +18825,19 @@ var WebCall = (() => {
|
|
|
18733
18825
|
const observeSocketStatus = (userAgent, extra) => {
|
|
18734
18826
|
const { that = this } = extra;
|
|
18735
18827
|
const core = userAgent.userAgentCore;
|
|
18736
|
-
const
|
|
18737
|
-
core.
|
|
18828
|
+
const originalReceiveIncomingRequestFromTransport = core.receiveIncomingRequestFromTransport.bind(core);
|
|
18829
|
+
core.receiveIncomingRequestFromTransport = (request2) => {
|
|
18738
18830
|
if (request2.method === "OPTIONS") {
|
|
18739
18831
|
that.startHeartbeat();
|
|
18740
18832
|
}
|
|
18741
|
-
that.callKit.logger.info(`SIP Receive
|
|
18742
|
-
caller: "Connect.register.observeSocketStatus",
|
|
18833
|
+
that.callKit.logger.info(`SIP Receive: ${request2?.method}`, {
|
|
18834
|
+
caller: "Connect.register.observeSocketStatus.receiveRequest",
|
|
18743
18835
|
type: "SIP",
|
|
18744
18836
|
content: {
|
|
18745
18837
|
request: request2
|
|
18746
18838
|
}
|
|
18747
18839
|
});
|
|
18748
|
-
return
|
|
18840
|
+
return originalReceiveIncomingRequestFromTransport(request2);
|
|
18749
18841
|
};
|
|
18750
18842
|
const { transport } = userAgent;
|
|
18751
18843
|
if (transport) {
|
|
@@ -18844,9 +18936,6 @@ var WebCall = (() => {
|
|
|
18844
18936
|
}
|
|
18845
18937
|
});
|
|
18846
18938
|
this.currentSession = invite;
|
|
18847
|
-
if (this.isOutgoing) {
|
|
18848
|
-
this.isCurrentSessionInvited = false;
|
|
18849
|
-
}
|
|
18850
18939
|
this.currentSession.stateChange.addListener((state) => {
|
|
18851
18940
|
switch (state) {
|
|
18852
18941
|
case SessionState2.Establishing:
|
|
@@ -18892,11 +18981,8 @@ var WebCall = (() => {
|
|
|
18892
18981
|
sessionState: state
|
|
18893
18982
|
}
|
|
18894
18983
|
});
|
|
18895
|
-
|
|
18896
|
-
|
|
18897
|
-
this.currentSession.reject();
|
|
18898
|
-
}
|
|
18899
|
-
} else {
|
|
18984
|
+
this.hasInvite = false;
|
|
18985
|
+
if (!this.isUnprompted) {
|
|
18900
18986
|
this.callKit.callCenter.callEnd();
|
|
18901
18987
|
}
|
|
18902
18988
|
this.isUnprompted = false;
|
|
@@ -18931,14 +19017,17 @@ var WebCall = (() => {
|
|
|
18931
19017
|
const info = getInviteData();
|
|
18932
19018
|
try {
|
|
18933
19019
|
const inviteData = formatGetInviteData(info);
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
19020
|
+
if (inviteData?.callUuid) {
|
|
19021
|
+
this.setCallId(inviteData.callUuid);
|
|
19022
|
+
} else {
|
|
19023
|
+
this.setCallId(null);
|
|
19024
|
+
this.callKit.logger.error("call id is not exist", {
|
|
19025
|
+
caller: "Connect.register.onInvite",
|
|
19026
|
+
content: {
|
|
19027
|
+
inviteData
|
|
19028
|
+
}
|
|
19029
|
+
});
|
|
19030
|
+
}
|
|
18942
19031
|
} catch (error) {
|
|
18943
19032
|
this.callKit.logger.info(error, {
|
|
18944
19033
|
caller: "Connect.register.onInvite",
|
|
@@ -18951,14 +19040,18 @@ var WebCall = (() => {
|
|
|
18951
19040
|
getInviteData
|
|
18952
19041
|
});
|
|
18953
19042
|
} else {
|
|
19043
|
+
this.hasInvite = true;
|
|
18954
19044
|
const reject = () => {
|
|
18955
|
-
this.currentSession.
|
|
19045
|
+
if (this.currentSession?.state !== SessionState2.Terminated && this.currentSession?.state !== SessionState2.Terminating) {
|
|
19046
|
+
this.currentSession.reject();
|
|
19047
|
+
}
|
|
19048
|
+
this.hasInvite = false;
|
|
18956
19049
|
this.callKit.callCenter.callEnd(true, false);
|
|
18957
19050
|
};
|
|
18958
19051
|
this.callKit.trigger(KitEvent.KIT_INVITE, {
|
|
18959
19052
|
accept: () => {
|
|
18960
|
-
this.isCurrentSessionInvited = true;
|
|
18961
19053
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
19054
|
+
this.hasInvite = false;
|
|
18962
19055
|
this.currentSession.accept(options);
|
|
18963
19056
|
},
|
|
18964
19057
|
reject,
|
|
@@ -18982,6 +19075,7 @@ var WebCall = (() => {
|
|
|
18982
19075
|
version
|
|
18983
19076
|
});
|
|
18984
19077
|
}).catch(async (err) => {
|
|
19078
|
+
this.callKit.reset();
|
|
18985
19079
|
this.callKit.logger.error(err?.message, {
|
|
18986
19080
|
caller: "Connect.register",
|
|
18987
19081
|
type: "SIP",
|
|
@@ -18989,7 +19083,6 @@ var WebCall = (() => {
|
|
|
18989
19083
|
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
18990
19084
|
}
|
|
18991
19085
|
});
|
|
18992
|
-
this.callKit.reset();
|
|
18993
19086
|
});
|
|
18994
19087
|
},
|
|
18995
19088
|
onDisconnect: (error) => {
|
|
@@ -19021,6 +19114,7 @@ var WebCall = (() => {
|
|
|
19021
19114
|
that: this
|
|
19022
19115
|
});
|
|
19023
19116
|
await this.userAgent.start().catch((err) => {
|
|
19117
|
+
this.callKit.reset();
|
|
19024
19118
|
this.callKit.logger.error(err, {
|
|
19025
19119
|
caller: "Connect.register",
|
|
19026
19120
|
type: "SIP",
|
|
@@ -19028,13 +19122,13 @@ var WebCall = (() => {
|
|
|
19028
19122
|
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
19029
19123
|
}
|
|
19030
19124
|
});
|
|
19031
|
-
this.callKit.reset();
|
|
19032
19125
|
});
|
|
19033
19126
|
}
|
|
19034
19127
|
reconnectTimer;
|
|
19035
19128
|
reconnectAttempts = 0;
|
|
19036
19129
|
startReconnectTimer() {
|
|
19037
|
-
if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts) {
|
|
19130
|
+
if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts && this.callKit.config.isLogin()) {
|
|
19131
|
+
this.callKit.reset();
|
|
19038
19132
|
this.callKit.logger.error("Reconnect failed max attempts", {
|
|
19039
19133
|
caller: "Connect.startReconnectTimer",
|
|
19040
19134
|
type: "SIP",
|
|
@@ -19044,7 +19138,6 @@ var WebCall = (() => {
|
|
|
19044
19138
|
delay: this.reconnectConfig.delay
|
|
19045
19139
|
}
|
|
19046
19140
|
});
|
|
19047
|
-
this.callKit.reset();
|
|
19048
19141
|
return;
|
|
19049
19142
|
}
|
|
19050
19143
|
this.callKit.logger.info("Reconnect timer started", {
|
|
@@ -19058,8 +19151,8 @@ var WebCall = (() => {
|
|
|
19058
19151
|
});
|
|
19059
19152
|
this.reconnectAttempts += 1;
|
|
19060
19153
|
this.reconnectTimer = setTimeout(() => {
|
|
19061
|
-
if (this.reconnectTimer) {
|
|
19062
|
-
this.userAgent
|
|
19154
|
+
if (this.reconnectTimer && this.callKit.config.isLogin()) {
|
|
19155
|
+
this.userAgent?.reconnect();
|
|
19063
19156
|
this.callKit.logger.info("Reconnect attempt", {
|
|
19064
19157
|
caller: "Connect.startReconnectTimer",
|
|
19065
19158
|
type: "SIP",
|
|
@@ -19104,6 +19197,7 @@ var WebCall = (() => {
|
|
|
19104
19197
|
return;
|
|
19105
19198
|
}
|
|
19106
19199
|
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
19200
|
+
this.callKit.reset();
|
|
19107
19201
|
this.callKit.logger.error(err, {
|
|
19108
19202
|
caller: "Connect.unregister",
|
|
19109
19203
|
type: "SIP",
|
|
@@ -19111,7 +19205,6 @@ var WebCall = (() => {
|
|
|
19111
19205
|
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
19112
19206
|
}
|
|
19113
19207
|
});
|
|
19114
|
-
this.callKit.reset();
|
|
19115
19208
|
});
|
|
19116
19209
|
}
|
|
19117
19210
|
async call(callback) {
|
|
@@ -19177,18 +19270,24 @@ var WebCall = (() => {
|
|
|
19177
19270
|
connectStatus: this.connectStatus
|
|
19178
19271
|
}
|
|
19179
19272
|
});
|
|
19180
|
-
if (this.connectStatus === CallStatus.init)
|
|
19181
|
-
return;
|
|
19182
19273
|
this.isOutgoing = false;
|
|
19183
19274
|
this.isUnprompted = isUnprompted;
|
|
19275
|
+
this.setHold(false);
|
|
19276
|
+
this.setMute(false);
|
|
19277
|
+
if (this.connectStatus === CallStatus.init)
|
|
19278
|
+
return;
|
|
19184
19279
|
try {
|
|
19185
19280
|
if (isUnprompted) {
|
|
19186
|
-
const shouldSendBye = (
|
|
19187
|
-
// this.sipConnected ||
|
|
19188
|
-
this.isRinging() || this.isCalling() || this.isHolding()
|
|
19189
|
-
);
|
|
19281
|
+
const shouldSendBye = this.isRinging() || this.isCalling();
|
|
19190
19282
|
if (shouldSendBye) {
|
|
19191
|
-
|
|
19283
|
+
if (this.hasInvite) {
|
|
19284
|
+
if (this.currentSession?.state !== SessionState2.Terminated && this.currentSession?.state !== SessionState2.Terminating) {
|
|
19285
|
+
this.currentSession.reject();
|
|
19286
|
+
}
|
|
19287
|
+
this.hasInvite = false;
|
|
19288
|
+
} else {
|
|
19289
|
+
await this.currentSession?.bye();
|
|
19290
|
+
}
|
|
19192
19291
|
}
|
|
19193
19292
|
}
|
|
19194
19293
|
closeStream(this.mediaStream);
|
|
@@ -19200,6 +19299,8 @@ var WebCall = (() => {
|
|
|
19200
19299
|
this.setConnectStatus(CallStatus.init);
|
|
19201
19300
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19202
19301
|
} catch (err) {
|
|
19302
|
+
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19303
|
+
this.callKit.reset();
|
|
19203
19304
|
this.callKit.logger.error(err, {
|
|
19204
19305
|
caller: "Connect.hangup",
|
|
19205
19306
|
type: "SIP",
|
|
@@ -19209,8 +19310,6 @@ var WebCall = (() => {
|
|
|
19209
19310
|
isUnprompted
|
|
19210
19311
|
}
|
|
19211
19312
|
});
|
|
19212
|
-
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19213
|
-
this.callKit.reset();
|
|
19214
19313
|
}
|
|
19215
19314
|
}
|
|
19216
19315
|
/**
|
|
@@ -19306,61 +19405,6 @@ var WebCall = (() => {
|
|
|
19306
19405
|
});
|
|
19307
19406
|
this.callKit.trigger(KitEvent.KIT_SET_HOLD, hold);
|
|
19308
19407
|
}
|
|
19309
|
-
// /**
|
|
19310
|
-
// * Set mute
|
|
19311
|
-
// * @param mute Whether to mute
|
|
19312
|
-
// * @deprecated just send socket event to server to mute or unmute
|
|
19313
|
-
// */
|
|
19314
|
-
// async setMute(mute: boolean) {
|
|
19315
|
-
// this.callKit.logger.info('connect setMute', {
|
|
19316
|
-
// caller: 'Connect.setMute',
|
|
19317
|
-
// type: 'SIP',
|
|
19318
|
-
// content: {
|
|
19319
|
-
// mute
|
|
19320
|
-
// }
|
|
19321
|
-
// });
|
|
19322
|
-
// if (!this.currentSession) {
|
|
19323
|
-
// this.callKit.logger.error('No active session', {
|
|
19324
|
-
// caller: 'Connect.setMute',
|
|
19325
|
-
// type: 'SIP',
|
|
19326
|
-
// content: {
|
|
19327
|
-
// errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
19328
|
-
// }
|
|
19329
|
-
// });
|
|
19330
|
-
// this.callKit.reset();
|
|
19331
|
-
// return;
|
|
19332
|
-
// }
|
|
19333
|
-
// try {
|
|
19334
|
-
// // Get SessionDescriptionHandler
|
|
19335
|
-
// const sdh = this.currentSession.sessionDescriptionHandler;
|
|
19336
|
-
// if (!sdh || !('peerConnection' in sdh)) {
|
|
19337
|
-
// throw new Error('Invalid session description handler');
|
|
19338
|
-
// }
|
|
19339
|
-
// // Get PeerConnection
|
|
19340
|
-
// const pc = (sdh as any).peerConnection as RTCPeerConnection;
|
|
19341
|
-
// // Get local audio track and set status
|
|
19342
|
-
// const audioSender = pc
|
|
19343
|
-
// .getSenders()
|
|
19344
|
-
// .find((sender) => sender.track?.kind === 'audio');
|
|
19345
|
-
// if (audioSender && audioSender.track) {
|
|
19346
|
-
// audioSender.track.enabled = !mute;
|
|
19347
|
-
// // Update status and trigger event
|
|
19348
|
-
// this.isMute = mute;
|
|
19349
|
-
// this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19350
|
-
// } else {
|
|
19351
|
-
// throw new Error('No audio track found');
|
|
19352
|
-
// }
|
|
19353
|
-
// } catch (error) {
|
|
19354
|
-
// this.callKit.logger.error('Failed to set mute state', {
|
|
19355
|
-
// caller: 'Connect.setMute',
|
|
19356
|
-
// type: 'SIP',
|
|
19357
|
-
// content: {
|
|
19358
|
-
// err: error.message,
|
|
19359
|
-
// errCode: ErrorCode.WEBRTC_MUTE_ERROR
|
|
19360
|
-
// }
|
|
19361
|
-
// });
|
|
19362
|
-
// }
|
|
19363
|
-
// }
|
|
19364
19408
|
async setMute(mute) {
|
|
19365
19409
|
if (this.isMute === mute) {
|
|
19366
19410
|
this.callKit.logger.warn("Already muted", {
|
|
@@ -19504,6 +19548,7 @@ var WebCall = (() => {
|
|
|
19504
19548
|
this.handleDisconnect();
|
|
19505
19549
|
}
|
|
19506
19550
|
onError(ev) {
|
|
19551
|
+
this.socketError = true;
|
|
19507
19552
|
this.callKit.logger.error("socket onError", {
|
|
19508
19553
|
caller: "Socket.onError",
|
|
19509
19554
|
type: "INCALL",
|
|
@@ -19512,7 +19557,6 @@ var WebCall = (() => {
|
|
|
19512
19557
|
data: ev
|
|
19513
19558
|
}
|
|
19514
19559
|
});
|
|
19515
|
-
this.socketError = true;
|
|
19516
19560
|
}
|
|
19517
19561
|
confirmAck(data) {
|
|
19518
19562
|
const { ack, messageId } = data;
|
|
@@ -19524,11 +19568,26 @@ var WebCall = (() => {
|
|
|
19524
19568
|
}
|
|
19525
19569
|
onMessage(ev) {
|
|
19526
19570
|
const data = JSON.parse(ev.data);
|
|
19571
|
+
let content = {};
|
|
19572
|
+
try {
|
|
19573
|
+
if (data.data) {
|
|
19574
|
+
content = JSON.parse(data.data);
|
|
19575
|
+
}
|
|
19576
|
+
} catch (error) {
|
|
19577
|
+
this.callKit.logger.info("socket onMessage parse error", {
|
|
19578
|
+
caller: "Socket.onMessage",
|
|
19579
|
+
type: "INCALL",
|
|
19580
|
+
content: {
|
|
19581
|
+
data: data.data
|
|
19582
|
+
}
|
|
19583
|
+
});
|
|
19584
|
+
content = data.data;
|
|
19585
|
+
}
|
|
19527
19586
|
this.callKit.logger.info("socket onMessage", {
|
|
19528
19587
|
caller: "Socket.onMessage",
|
|
19529
19588
|
type: "INCALL",
|
|
19530
19589
|
content: {
|
|
19531
|
-
data:
|
|
19590
|
+
data: content,
|
|
19532
19591
|
event: data.event
|
|
19533
19592
|
}
|
|
19534
19593
|
});
|
|
@@ -19542,7 +19601,7 @@ var WebCall = (() => {
|
|
|
19542
19601
|
caller: "Socket.onMessage",
|
|
19543
19602
|
type: "INCALL",
|
|
19544
19603
|
content: {
|
|
19545
|
-
data:
|
|
19604
|
+
data: content,
|
|
19546
19605
|
event: SocketReceiveEvent.START_CONFIRM
|
|
19547
19606
|
}
|
|
19548
19607
|
});
|
|
@@ -19553,7 +19612,7 @@ var WebCall = (() => {
|
|
|
19553
19612
|
caller: "Socket.onMessage",
|
|
19554
19613
|
type: "INCALL",
|
|
19555
19614
|
content: {
|
|
19556
|
-
data:
|
|
19615
|
+
data: content,
|
|
19557
19616
|
event: SocketReceiveEvent.CALL_SUCCESS
|
|
19558
19617
|
}
|
|
19559
19618
|
});
|
|
@@ -19563,20 +19622,28 @@ var WebCall = (() => {
|
|
|
19563
19622
|
caller: "Socket.onMessage",
|
|
19564
19623
|
type: "INCALL",
|
|
19565
19624
|
content: {
|
|
19566
|
-
data:
|
|
19625
|
+
data: content,
|
|
19567
19626
|
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
19568
19627
|
}
|
|
19569
19628
|
});
|
|
19570
19629
|
}
|
|
19571
19630
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
19572
19631
|
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
19632
|
+
this.callKit.logger.info(data.msg, {
|
|
19633
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19634
|
+
type: "INCALL",
|
|
19635
|
+
content: {
|
|
19636
|
+
data: content,
|
|
19637
|
+
event: SocketReceiveEvent.CUSTOMER_RINGING
|
|
19638
|
+
}
|
|
19639
|
+
});
|
|
19573
19640
|
}
|
|
19574
19641
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
19575
19642
|
this.callKit.logger.info(data.msg, {
|
|
19576
19643
|
caller: "Socket.onMessage",
|
|
19577
19644
|
type: "INCALL",
|
|
19578
19645
|
content: {
|
|
19579
|
-
data:
|
|
19646
|
+
data: content,
|
|
19580
19647
|
event: SocketReceiveEvent.CUSTOMER_PICK_UP
|
|
19581
19648
|
}
|
|
19582
19649
|
});
|
|
@@ -19587,7 +19654,7 @@ var WebCall = (() => {
|
|
|
19587
19654
|
caller: "Socket.onMessage",
|
|
19588
19655
|
type: "INCALL",
|
|
19589
19656
|
content: {
|
|
19590
|
-
data:
|
|
19657
|
+
data: content,
|
|
19591
19658
|
event: SocketReceiveEvent.AGENT_PICK_UP
|
|
19592
19659
|
}
|
|
19593
19660
|
});
|
|
@@ -19595,16 +19662,16 @@ var WebCall = (() => {
|
|
|
19595
19662
|
}
|
|
19596
19663
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
19597
19664
|
this.callKit.logger.info(data.msg, {
|
|
19598
|
-
caller:
|
|
19665
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19599
19666
|
type: "INCALL",
|
|
19600
19667
|
content: {
|
|
19601
|
-
data:
|
|
19668
|
+
data: content,
|
|
19602
19669
|
event: SocketReceiveEvent.CUSTOMER_HANG_UP
|
|
19603
19670
|
}
|
|
19604
19671
|
});
|
|
19605
19672
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
19606
|
-
if (
|
|
19607
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19673
|
+
if (content?.callUuid) {
|
|
19674
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19608
19675
|
}
|
|
19609
19676
|
}
|
|
19610
19677
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
@@ -19612,30 +19679,32 @@ var WebCall = (() => {
|
|
|
19612
19679
|
caller: "Socket.onMessage",
|
|
19613
19680
|
type: "INCALL",
|
|
19614
19681
|
content: {
|
|
19615
|
-
data:
|
|
19682
|
+
data: content,
|
|
19616
19683
|
event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
|
|
19617
19684
|
}
|
|
19618
19685
|
});
|
|
19619
19686
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
19620
|
-
if (
|
|
19621
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19687
|
+
if (content?.callUuid) {
|
|
19688
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19622
19689
|
}
|
|
19623
19690
|
}
|
|
19624
19691
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
19625
19692
|
this.callKit.logger.info(data.msg, {
|
|
19626
|
-
caller:
|
|
19693
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19694
|
+
type: "INCALL",
|
|
19627
19695
|
content: {
|
|
19628
|
-
data:
|
|
19696
|
+
data: content,
|
|
19629
19697
|
event: SocketReceiveEvent.CALL_CDR
|
|
19630
19698
|
}
|
|
19631
19699
|
});
|
|
19632
|
-
this.callKit.trigger(KitEvent.CALL_CDR,
|
|
19700
|
+
this.callKit.trigger(KitEvent.CALL_CDR, content);
|
|
19633
19701
|
}
|
|
19634
19702
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
19635
19703
|
this.callKit.logger.info(data.msg, {
|
|
19636
|
-
caller:
|
|
19704
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19705
|
+
type: "INCALL",
|
|
19637
19706
|
content: {
|
|
19638
|
-
data:
|
|
19707
|
+
data: content,
|
|
19639
19708
|
event: SocketReceiveEvent.STOP_CONFIRM
|
|
19640
19709
|
}
|
|
19641
19710
|
});
|
|
@@ -19643,9 +19712,10 @@ var WebCall = (() => {
|
|
|
19643
19712
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
19644
19713
|
const { userInfo } = this.callKit.config.getConfig();
|
|
19645
19714
|
this.callKit.logger.info(data.msg, {
|
|
19646
|
-
caller:
|
|
19715
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19716
|
+
type: "INCALL",
|
|
19647
19717
|
content: {
|
|
19648
|
-
data:
|
|
19718
|
+
data: content,
|
|
19649
19719
|
event: SocketReceiveEvent.CLOSE
|
|
19650
19720
|
}
|
|
19651
19721
|
});
|
|
@@ -19654,26 +19724,40 @@ var WebCall = (() => {
|
|
|
19654
19724
|
});
|
|
19655
19725
|
}
|
|
19656
19726
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
19727
|
+
this.socketError = true;
|
|
19728
|
+
this.callKit.reset();
|
|
19657
19729
|
this.callKit.logger.error(data.msg, {
|
|
19658
|
-
caller:
|
|
19730
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19731
|
+
type: "INCALL",
|
|
19659
19732
|
content: {
|
|
19660
19733
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
19661
|
-
data:
|
|
19734
|
+
data: content
|
|
19662
19735
|
}
|
|
19663
19736
|
});
|
|
19737
|
+
}
|
|
19738
|
+
if (data.event === SocketReceiveEvent.SESSION_ERROR) {
|
|
19664
19739
|
this.socketError = true;
|
|
19665
19740
|
this.callKit.reset();
|
|
19741
|
+
this.callKit.logger.error(data.msg, {
|
|
19742
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19743
|
+
type: "INCALL",
|
|
19744
|
+
content: {
|
|
19745
|
+
data: content,
|
|
19746
|
+
event: SocketReceiveEvent.SESSION_ERROR
|
|
19747
|
+
}
|
|
19748
|
+
});
|
|
19666
19749
|
}
|
|
19667
19750
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
19668
19751
|
this.callKit.logger.info(data.msg, {
|
|
19669
|
-
caller:
|
|
19752
|
+
caller: `Socket.onMessage:${data.event}`,
|
|
19753
|
+
type: "INCALL",
|
|
19670
19754
|
content: {
|
|
19671
|
-
data:
|
|
19755
|
+
data: content,
|
|
19672
19756
|
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
19673
19757
|
}
|
|
19674
19758
|
});
|
|
19675
|
-
if (
|
|
19676
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19759
|
+
if (content?.callUuid) {
|
|
19760
|
+
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19677
19761
|
}
|
|
19678
19762
|
}
|
|
19679
19763
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
@@ -19683,6 +19767,7 @@ var WebCall = (() => {
|
|
|
19683
19767
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19684
19768
|
event: "INCALL_NOT_CONNECTED"
|
|
19685
19769
|
});
|
|
19770
|
+
this.callKit.reset();
|
|
19686
19771
|
this.callKit.logger.error("socket not connected", {
|
|
19687
19772
|
caller: "Socket.send",
|
|
19688
19773
|
type: "INCALL",
|
|
@@ -19690,10 +19775,9 @@ var WebCall = (() => {
|
|
|
19690
19775
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
19691
19776
|
}
|
|
19692
19777
|
});
|
|
19693
|
-
this.callKit.reset();
|
|
19694
19778
|
return;
|
|
19695
19779
|
}
|
|
19696
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
19780
|
+
const { userInfo, version } = this.callKit.config.getConfig();
|
|
19697
19781
|
const { sessionId, extno, agentId } = userInfo;
|
|
19698
19782
|
if (!sessionId) {
|
|
19699
19783
|
this.callKit.logger.error("sessionId is empty", {
|
|
@@ -19708,6 +19792,7 @@ var WebCall = (() => {
|
|
|
19708
19792
|
const msg = {
|
|
19709
19793
|
event,
|
|
19710
19794
|
sessionId,
|
|
19795
|
+
version,
|
|
19711
19796
|
...message
|
|
19712
19797
|
};
|
|
19713
19798
|
if (SocketSendEvent.CALL === event) {
|
|
@@ -19723,8 +19808,7 @@ var WebCall = (() => {
|
|
|
19723
19808
|
caller: "Socket.send",
|
|
19724
19809
|
type: "INCALL",
|
|
19725
19810
|
content: {
|
|
19726
|
-
|
|
19727
|
-
message
|
|
19811
|
+
...msg
|
|
19728
19812
|
}
|
|
19729
19813
|
});
|
|
19730
19814
|
switch (event) {
|
|
@@ -19737,24 +19821,6 @@ var WebCall = (() => {
|
|
|
19737
19821
|
break;
|
|
19738
19822
|
}
|
|
19739
19823
|
}
|
|
19740
|
-
async sendMessage(event, message) {
|
|
19741
|
-
if (!this.isConnected) {
|
|
19742
|
-
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19743
|
-
event: "INCALL_NOT_CONNECTED"
|
|
19744
|
-
});
|
|
19745
|
-
this.callKit.logger.error("socket not connected", {
|
|
19746
|
-
caller: "Socket.sendMessage",
|
|
19747
|
-
type: "INCALL",
|
|
19748
|
-
content: {
|
|
19749
|
-
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
19750
|
-
}
|
|
19751
|
-
});
|
|
19752
|
-
return;
|
|
19753
|
-
}
|
|
19754
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
19755
|
-
const { sessionId } = userInfo;
|
|
19756
|
-
this.ws?.send(JSON.stringify({ event, sessionId, ...message }));
|
|
19757
|
-
}
|
|
19758
19824
|
ping() {
|
|
19759
19825
|
if (!this.isConnected)
|
|
19760
19826
|
return;
|
|
@@ -19769,6 +19835,11 @@ var WebCall = (() => {
|
|
|
19769
19835
|
const now = Date.now();
|
|
19770
19836
|
const { pingInterval, pingTimeout } = this.socketConfig;
|
|
19771
19837
|
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
19838
|
+
if (this.ws && this.isConnected) {
|
|
19839
|
+
this.ws.close(4001, "ping timeout");
|
|
19840
|
+
} else {
|
|
19841
|
+
this.reset();
|
|
19842
|
+
}
|
|
19772
19843
|
this.callKit.logger.error("socket ping timeout", {
|
|
19773
19844
|
caller: "Socket.ping",
|
|
19774
19845
|
type: "INCALL",
|
|
@@ -19776,11 +19847,6 @@ var WebCall = (() => {
|
|
|
19776
19847
|
errCode: ErrorCode.SOCKET_PING_TIMEOUT
|
|
19777
19848
|
}
|
|
19778
19849
|
});
|
|
19779
|
-
if (this.ws && this.isConnected) {
|
|
19780
|
-
this.ws.close(4001, "ping timeout");
|
|
19781
|
-
} else {
|
|
19782
|
-
this.reset();
|
|
19783
|
-
}
|
|
19784
19850
|
}
|
|
19785
19851
|
}
|
|
19786
19852
|
checkPing() {
|
|
@@ -19816,6 +19882,10 @@ var WebCall = (() => {
|
|
|
19816
19882
|
}
|
|
19817
19883
|
attemptReconnect() {
|
|
19818
19884
|
if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
19885
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19886
|
+
event: "INCALL_RECONNECT_ERROR"
|
|
19887
|
+
});
|
|
19888
|
+
this.reset();
|
|
19819
19889
|
this.callKit.logger.error("Maximum reconnection attempts reached", {
|
|
19820
19890
|
caller: "Socket.attemptReconnect",
|
|
19821
19891
|
type: "INCALL",
|
|
@@ -19824,10 +19894,6 @@ var WebCall = (() => {
|
|
|
19824
19894
|
reconnectAttempts: this.reconnectAttempts
|
|
19825
19895
|
}
|
|
19826
19896
|
});
|
|
19827
|
-
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19828
|
-
event: "INCALL_RECONNECT_ERROR"
|
|
19829
|
-
});
|
|
19830
|
-
this.reset();
|
|
19831
19897
|
return;
|
|
19832
19898
|
}
|
|
19833
19899
|
if (this.reconnectAttempts === 0) {
|
|
@@ -20120,9 +20186,16 @@ var WebCall = (() => {
|
|
|
20120
20186
|
*/
|
|
20121
20187
|
async setUserStatus(status) {
|
|
20122
20188
|
const { agentId } = this.config.getConfig().userInfo;
|
|
20189
|
+
this.logger.info("setUserStatus", {
|
|
20190
|
+
caller: "CallKit.setUserStatus",
|
|
20191
|
+
content: {
|
|
20192
|
+
status,
|
|
20193
|
+
agentId
|
|
20194
|
+
}
|
|
20195
|
+
});
|
|
20123
20196
|
await this.api.updateUserStatus({
|
|
20124
20197
|
agentId,
|
|
20125
|
-
status
|
|
20198
|
+
userStatus: status
|
|
20126
20199
|
});
|
|
20127
20200
|
}
|
|
20128
20201
|
async reset() {
|
|
@@ -20172,13 +20245,19 @@ var WebCall = (() => {
|
|
|
20172
20245
|
}
|
|
20173
20246
|
});
|
|
20174
20247
|
}
|
|
20175
|
-
trigger(event, data) {
|
|
20248
|
+
trigger(event, data, noLog = false) {
|
|
20249
|
+
if (!noLog) {
|
|
20250
|
+
this.logger.info(`Trigger Event: ${event}`, {
|
|
20251
|
+
caller: "CallKit.trigger",
|
|
20252
|
+
content: data
|
|
20253
|
+
});
|
|
20254
|
+
}
|
|
20176
20255
|
this.listener.forEach((item) => {
|
|
20177
20256
|
if (item.event === event) {
|
|
20178
20257
|
try {
|
|
20179
20258
|
item.callback(data);
|
|
20180
20259
|
} catch (err) {
|
|
20181
|
-
this.logger.error("Event callback error:", err);
|
|
20260
|
+
this.logger.error("Event callback error:", err, true);
|
|
20182
20261
|
}
|
|
20183
20262
|
}
|
|
20184
20263
|
});
|