@koi-design/callkit 2.0.5 → 2.1.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/README.md +281 -57
- package/dist/index.d.ts +65 -23
- package/dist/index.global.js +520 -396
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +520 -396
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +520 -396
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -3225,6 +3225,11 @@ var WebCall = (() => {
|
|
|
3225
3225
|
isLoginOuting = false;
|
|
3226
3226
|
async login(params) {
|
|
3227
3227
|
if (this.isLogining) {
|
|
3228
|
+
this.callKit.logger.info("login is already in progress cancel", {
|
|
3229
|
+
caller: "Api.login",
|
|
3230
|
+
type: "API",
|
|
3231
|
+
content: { userName: params.userName, timestamp: params.timestamp }
|
|
3232
|
+
});
|
|
3228
3233
|
return;
|
|
3229
3234
|
}
|
|
3230
3235
|
this.isLogining = true;
|
|
@@ -3234,15 +3239,18 @@ var WebCall = (() => {
|
|
|
3234
3239
|
method: "post",
|
|
3235
3240
|
data: params
|
|
3236
3241
|
});
|
|
3237
|
-
this.isLogining = false;
|
|
3238
3242
|
return res;
|
|
3239
|
-
}
|
|
3243
|
+
} finally {
|
|
3240
3244
|
this.isLogining = false;
|
|
3241
|
-
throw error;
|
|
3242
3245
|
}
|
|
3243
3246
|
}
|
|
3244
3247
|
async loginOut(params) {
|
|
3245
3248
|
if (this.isLoginOuting) {
|
|
3249
|
+
this.callKit.logger.info("loginOut is already in progress cancel", {
|
|
3250
|
+
type: "API",
|
|
3251
|
+
caller: "Api.loginOut",
|
|
3252
|
+
content: { sessionId: params.sessionId, timestamp: params.timestamp }
|
|
3253
|
+
});
|
|
3246
3254
|
return;
|
|
3247
3255
|
}
|
|
3248
3256
|
this.isLoginOuting = true;
|
|
@@ -3252,20 +3260,29 @@ var WebCall = (() => {
|
|
|
3252
3260
|
method: "post",
|
|
3253
3261
|
data: params
|
|
3254
3262
|
});
|
|
3255
|
-
this.isLoginOuting = false;
|
|
3256
3263
|
return res;
|
|
3257
|
-
}
|
|
3264
|
+
} finally {
|
|
3258
3265
|
this.isLoginOuting = false;
|
|
3259
|
-
throw error;
|
|
3260
3266
|
}
|
|
3261
3267
|
}
|
|
3262
3268
|
async trackLogs(log) {
|
|
3263
|
-
|
|
3264
|
-
{
|
|
3265
|
-
{
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
+
try {
|
|
3270
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
3271
|
+
const { sessionId } = userInfo;
|
|
3272
|
+
const formData = new FormData();
|
|
3273
|
+
formData.append("content", JSON.stringify([log]));
|
|
3274
|
+
const config = {
|
|
3275
|
+
url: `${host}/agent/user/sdkLog`,
|
|
3276
|
+
method: "post",
|
|
3277
|
+
data: formData,
|
|
3278
|
+
headers: {
|
|
3279
|
+
...sessionId ? { sessionId } : {}
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
await axios_default(config).catch(() => {
|
|
3283
|
+
});
|
|
3284
|
+
} catch (error) {
|
|
3285
|
+
}
|
|
3269
3286
|
}
|
|
3270
3287
|
/**
|
|
3271
3288
|
*
|
|
@@ -3279,7 +3296,7 @@ var WebCall = (() => {
|
|
|
3279
3296
|
data: params
|
|
3280
3297
|
});
|
|
3281
3298
|
}
|
|
3282
|
-
async post(config, extra = {}) {
|
|
3299
|
+
async post(config, extra = { skipLog: false }) {
|
|
3283
3300
|
const { userInfo, host } = this.callKit.config.getConfig();
|
|
3284
3301
|
const { sessionId } = userInfo;
|
|
3285
3302
|
config.url = `${host}${config.url}`;
|
|
@@ -3302,11 +3319,37 @@ var WebCall = (() => {
|
|
|
3302
3319
|
if (sessionId) {
|
|
3303
3320
|
config.headers.sessionId = sessionId;
|
|
3304
3321
|
}
|
|
3322
|
+
const startTime = Date.now();
|
|
3323
|
+
if (!extra.skipLog) {
|
|
3324
|
+
this.callKit.logger.info("API Request Start", {
|
|
3325
|
+
type: "API",
|
|
3326
|
+
caller: "API.Request",
|
|
3327
|
+
content: {
|
|
3328
|
+
url: config.url,
|
|
3329
|
+
headers: config.headers,
|
|
3330
|
+
data: config.data,
|
|
3331
|
+
extra,
|
|
3332
|
+
startTime
|
|
3333
|
+
}
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3305
3336
|
const res = await axios_default(config).catch(() => {
|
|
3306
|
-
this.callKit.config.reset();
|
|
3337
|
+
this.callKit.config.reset("api request error");
|
|
3307
3338
|
});
|
|
3339
|
+
const endTime = Date.now();
|
|
3340
|
+
if (!extra.skipLog) {
|
|
3341
|
+
this.callKit.logger.info("API Request Finish", {
|
|
3342
|
+
type: "API",
|
|
3343
|
+
caller: "API.Request",
|
|
3344
|
+
content: {
|
|
3345
|
+
url: config.url,
|
|
3346
|
+
duration: `${endTime - startTime}ms`,
|
|
3347
|
+
response: res
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3308
3351
|
if (!res) {
|
|
3309
|
-
this.callKit.
|
|
3352
|
+
this.callKit.reset();
|
|
3310
3353
|
throw new Error("Network error");
|
|
3311
3354
|
}
|
|
3312
3355
|
const { code, data, message } = res;
|
|
@@ -3314,7 +3357,7 @@ var WebCall = (() => {
|
|
|
3314
3357
|
return data;
|
|
3315
3358
|
}
|
|
3316
3359
|
if (code === "100013") {
|
|
3317
|
-
this.callKit.config.reset();
|
|
3360
|
+
this.callKit.config.reset("api request error");
|
|
3318
3361
|
}
|
|
3319
3362
|
throw new Error(message ?? "Request failed");
|
|
3320
3363
|
}
|
|
@@ -3627,6 +3670,10 @@ var WebCall = (() => {
|
|
|
3627
3670
|
* Agent no answer
|
|
3628
3671
|
*/
|
|
3629
3672
|
AGENT_NO_ANSWER: "AGENT_NO_ANSWER",
|
|
3673
|
+
/**
|
|
3674
|
+
* Agent hang up
|
|
3675
|
+
*/
|
|
3676
|
+
AGENT_HANG_UP: "AGENT_HANG_UP",
|
|
3630
3677
|
/**
|
|
3631
3678
|
* Call detail record push
|
|
3632
3679
|
*/
|
|
@@ -3643,7 +3690,8 @@ var WebCall = (() => {
|
|
|
3643
3690
|
* Error
|
|
3644
3691
|
*/
|
|
3645
3692
|
ERROR: "ERROR",
|
|
3646
|
-
SESSION_ERROR: "SESSION_ERROR"
|
|
3693
|
+
SESSION_ERROR: "SESSION_ERROR",
|
|
3694
|
+
WAITING_QUEUE: "WAITING_QUEUE"
|
|
3647
3695
|
};
|
|
3648
3696
|
var EncryptionMethod = {
|
|
3649
3697
|
NONE: "NONE",
|
|
@@ -3666,7 +3714,19 @@ var WebCall = (() => {
|
|
|
3666
3714
|
var trackLogsDefaultConfig = {
|
|
3667
3715
|
enabled: false,
|
|
3668
3716
|
interval: 5e3,
|
|
3669
|
-
maxSize:
|
|
3717
|
+
maxSize: 4096
|
|
3718
|
+
};
|
|
3719
|
+
var SOCKET_RECONNECT_CONFIG = {
|
|
3720
|
+
enabled: true,
|
|
3721
|
+
maxAttempts: 3,
|
|
3722
|
+
delay: 1e3,
|
|
3723
|
+
pingInterval: 3e4,
|
|
3724
|
+
pingTimeout: 5e3
|
|
3725
|
+
};
|
|
3726
|
+
var SIP_RECONNECT_CONFIG = {
|
|
3727
|
+
enabled: true,
|
|
3728
|
+
maxAttempts: 3,
|
|
3729
|
+
delay: 1e3
|
|
3670
3730
|
};
|
|
3671
3731
|
|
|
3672
3732
|
// core/call.ts
|
|
@@ -3681,14 +3741,14 @@ var WebCall = (() => {
|
|
|
3681
3741
|
this.callKit.logger.info("callStart", {
|
|
3682
3742
|
caller: "Call.callStart",
|
|
3683
3743
|
content: {
|
|
3684
|
-
startConfirm: this.callKit.socket.
|
|
3744
|
+
startConfirm: this.callKit.socket.startConfirm
|
|
3685
3745
|
}
|
|
3686
3746
|
});
|
|
3687
|
-
if (!this.callKit.socket.
|
|
3747
|
+
if (!this.callKit.socket.startConfirm) {
|
|
3688
3748
|
this.callKit.logger.warn("server not confirm start", {
|
|
3689
3749
|
caller: "Call.callStart",
|
|
3690
3750
|
content: {
|
|
3691
|
-
startConfirm: this.callKit.socket.
|
|
3751
|
+
startConfirm: this.callKit.socket.startConfirm
|
|
3692
3752
|
}
|
|
3693
3753
|
});
|
|
3694
3754
|
return;
|
|
@@ -3810,14 +3870,14 @@ var WebCall = (() => {
|
|
|
3810
3870
|
// package.json
|
|
3811
3871
|
var package_default = {
|
|
3812
3872
|
name: "@koi-design/callkit",
|
|
3813
|
-
version: "2.0.
|
|
3873
|
+
version: "2.1.0-beta.1",
|
|
3814
3874
|
description: "callkit",
|
|
3815
3875
|
author: "koi",
|
|
3816
3876
|
license: "ISC",
|
|
3817
3877
|
scripts: {
|
|
3818
3878
|
build: "tsup",
|
|
3819
|
-
|
|
3820
|
-
dev: "
|
|
3879
|
+
start: "vite",
|
|
3880
|
+
dev: "tsup --watch",
|
|
3821
3881
|
lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
3822
3882
|
release: "tsup && node scripts/pkg.js"
|
|
3823
3883
|
},
|
|
@@ -3874,6 +3934,10 @@ var WebCall = (() => {
|
|
|
3874
3934
|
audioRef: void 0,
|
|
3875
3935
|
constrains: constrainsDefault,
|
|
3876
3936
|
socket: "",
|
|
3937
|
+
reconnect: {
|
|
3938
|
+
sip: SIP_RECONNECT_CONFIG,
|
|
3939
|
+
incall: SOCKET_RECONNECT_CONFIG
|
|
3940
|
+
},
|
|
3877
3941
|
userInfo: {
|
|
3878
3942
|
wsUrl: "",
|
|
3879
3943
|
logGather: false,
|
|
@@ -3912,7 +3976,12 @@ var WebCall = (() => {
|
|
|
3912
3976
|
}
|
|
3913
3977
|
});
|
|
3914
3978
|
};
|
|
3915
|
-
reset = async () => {
|
|
3979
|
+
reset = async (form) => {
|
|
3980
|
+
this.callKit.logger.info(`Reset User Info ${form}`, {
|
|
3981
|
+
caller: "Config.reset",
|
|
3982
|
+
type: "OTHER",
|
|
3983
|
+
content: {}
|
|
3984
|
+
});
|
|
3916
3985
|
if (this.isLogin()) {
|
|
3917
3986
|
this.config.userInfo = {
|
|
3918
3987
|
wsUrl: "",
|
|
@@ -3958,7 +4027,16 @@ var WebCall = (() => {
|
|
|
3958
4027
|
return true;
|
|
3959
4028
|
}
|
|
3960
4029
|
getTrackLogsConfig() {
|
|
3961
|
-
return
|
|
4030
|
+
return {
|
|
4031
|
+
...trackLogsDefaultConfig,
|
|
4032
|
+
...this.config?.trackLogs
|
|
4033
|
+
};
|
|
4034
|
+
}
|
|
4035
|
+
getReconnectConfig(type) {
|
|
4036
|
+
const config = this.config?.reconnect?.[type] ?? (type === "sip" ? SIP_RECONNECT_CONFIG : SOCKET_RECONNECT_CONFIG);
|
|
4037
|
+
return {
|
|
4038
|
+
...config
|
|
4039
|
+
};
|
|
3962
4040
|
}
|
|
3963
4041
|
enableTrackLogs(enabled) {
|
|
3964
4042
|
this.config.trackLogs.enabled = enabled;
|
|
@@ -3998,7 +4076,7 @@ var WebCall = (() => {
|
|
|
3998
4076
|
this.flushTrackLogs();
|
|
3999
4077
|
}, interval);
|
|
4000
4078
|
}
|
|
4001
|
-
flushTrackLogs() {
|
|
4079
|
+
async flushTrackLogs() {
|
|
4002
4080
|
if (this.pendingTrackLogs.length === 0) {
|
|
4003
4081
|
return;
|
|
4004
4082
|
}
|
|
@@ -4007,26 +4085,29 @@ var WebCall = (() => {
|
|
|
4007
4085
|
try {
|
|
4008
4086
|
const chunks = [];
|
|
4009
4087
|
let currentChunk = [];
|
|
4010
|
-
let currentSize = 0;
|
|
4011
4088
|
for (const log of this.pendingTrackLogs) {
|
|
4012
|
-
const
|
|
4013
|
-
|
|
4014
|
-
const
|
|
4015
|
-
if (
|
|
4089
|
+
const testChunk = currentChunk.length > 0 ? `${currentChunk.join("\n")}
|
|
4090
|
+
${log}` : log;
|
|
4091
|
+
const actualSize = getByteSize(JSON.stringify([testChunk]));
|
|
4092
|
+
if (actualSize > maxSize && currentChunk.length > 0) {
|
|
4016
4093
|
chunks.push(currentChunk.join("\n"));
|
|
4017
4094
|
currentChunk = [log];
|
|
4018
|
-
currentSize = logSize;
|
|
4019
4095
|
} else {
|
|
4020
4096
|
currentChunk.push(log);
|
|
4021
|
-
currentSize += logSize + separatorSize;
|
|
4022
4097
|
}
|
|
4023
4098
|
}
|
|
4024
4099
|
if (currentChunk.length > 0) {
|
|
4025
4100
|
chunks.push(currentChunk.join("\n"));
|
|
4026
4101
|
}
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4102
|
+
await chunks.reduce(async (previousPromise, chunk, index) => {
|
|
4103
|
+
await previousPromise;
|
|
4104
|
+
if (index > 0) {
|
|
4105
|
+
await new Promise((resolve) => {
|
|
4106
|
+
setTimeout(resolve, 1e3);
|
|
4107
|
+
});
|
|
4108
|
+
}
|
|
4109
|
+
await this.callKit.api.trackLogs(chunk);
|
|
4110
|
+
}, Promise.resolve());
|
|
4030
4111
|
this.pendingTrackLogs = [];
|
|
4031
4112
|
} catch (error) {
|
|
4032
4113
|
console.error(error);
|
|
@@ -4084,16 +4165,22 @@ var WebCall = (() => {
|
|
|
4084
4165
|
}
|
|
4085
4166
|
catchLog(msg, extra, level) {
|
|
4086
4167
|
const now = /* @__PURE__ */ new Date();
|
|
4168
|
+
const { enabled } = this.callKit.config.getTrackLogsConfig();
|
|
4169
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
4170
|
+
const content = {
|
|
4171
|
+
...extra?.content ?? {},
|
|
4172
|
+
agentId: userInfo?.agentId,
|
|
4173
|
+
sessionId: userInfo?.sessionId
|
|
4174
|
+
};
|
|
4087
4175
|
const log = {
|
|
4088
4176
|
timestamp: now.toLocaleString().replace("T", " ").replace(".000Z", ""),
|
|
4089
4177
|
level,
|
|
4090
4178
|
message: msg,
|
|
4091
4179
|
caller: extra?.caller,
|
|
4092
4180
|
type: extra?.type,
|
|
4093
|
-
content
|
|
4181
|
+
content
|
|
4094
4182
|
};
|
|
4095
4183
|
const logString = transformLog(log);
|
|
4096
|
-
const { enabled } = this.callKit.config.getTrackLogsConfig();
|
|
4097
4184
|
if (enabled) {
|
|
4098
4185
|
this.pendingTrackLogs.push(logString);
|
|
4099
4186
|
}
|
|
@@ -18519,11 +18606,6 @@ var WebCall = (() => {
|
|
|
18519
18606
|
};
|
|
18520
18607
|
|
|
18521
18608
|
// core/connect.ts
|
|
18522
|
-
var DEFAULT_RECONNECT_CONFIG = {
|
|
18523
|
-
maxAttempts: 3,
|
|
18524
|
-
delay: 500
|
|
18525
|
-
};
|
|
18526
|
-
var MAX_HEARTBEAT_COUNT = 6;
|
|
18527
18609
|
function convertObjectStringToJSON(input) {
|
|
18528
18610
|
const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
|
|
18529
18611
|
return corrected;
|
|
@@ -18554,10 +18636,6 @@ var WebCall = (() => {
|
|
|
18554
18636
|
};
|
|
18555
18637
|
var Connect = class {
|
|
18556
18638
|
callKit;
|
|
18557
|
-
/**
|
|
18558
|
-
*@description Reconnect config
|
|
18559
|
-
*/
|
|
18560
|
-
reconnectConfig;
|
|
18561
18639
|
/**
|
|
18562
18640
|
*@description Whether muted
|
|
18563
18641
|
*/
|
|
@@ -18582,6 +18660,10 @@ var WebCall = (() => {
|
|
|
18582
18660
|
*@description Whether it's a re-connected
|
|
18583
18661
|
*/
|
|
18584
18662
|
isReConnected = false;
|
|
18663
|
+
/**
|
|
18664
|
+
*@description Whether it's a referring
|
|
18665
|
+
*/
|
|
18666
|
+
isRefering = false;
|
|
18585
18667
|
// sipConnected = false;
|
|
18586
18668
|
/**
|
|
18587
18669
|
*@description Whether it's an outgoing call
|
|
@@ -18597,14 +18679,48 @@ var WebCall = (() => {
|
|
|
18597
18679
|
hasInvite = false;
|
|
18598
18680
|
constructor(callKit) {
|
|
18599
18681
|
this.callKit = callKit;
|
|
18600
|
-
|
|
18601
|
-
|
|
18602
|
-
|
|
18603
|
-
...reconnect
|
|
18604
|
-
};
|
|
18682
|
+
}
|
|
18683
|
+
get reconnectConfig() {
|
|
18684
|
+
return this.callKit.config.getReconnectConfig("sip");
|
|
18605
18685
|
}
|
|
18606
18686
|
// current call id for invite data
|
|
18607
18687
|
currentCallId = null;
|
|
18688
|
+
getCurrentCallId() {
|
|
18689
|
+
return this.currentCallId;
|
|
18690
|
+
}
|
|
18691
|
+
setRefering(refering) {
|
|
18692
|
+
if (this.isRefering === refering)
|
|
18693
|
+
return;
|
|
18694
|
+
this.callKit.logger.info("setRefering", {
|
|
18695
|
+
caller: "Connect.setRefering",
|
|
18696
|
+
content: {
|
|
18697
|
+
refering
|
|
18698
|
+
}
|
|
18699
|
+
});
|
|
18700
|
+
this.isRefering = refering;
|
|
18701
|
+
}
|
|
18702
|
+
setIsReConnected(isReConnected) {
|
|
18703
|
+
if (this.isReConnected === isReConnected)
|
|
18704
|
+
return;
|
|
18705
|
+
this.callKit.logger.info("setIsReConnected", {
|
|
18706
|
+
caller: "Connect.setIsReConnected",
|
|
18707
|
+
content: {
|
|
18708
|
+
isReConnected
|
|
18709
|
+
}
|
|
18710
|
+
});
|
|
18711
|
+
this.isReConnected = isReConnected;
|
|
18712
|
+
}
|
|
18713
|
+
setOutgoing(outgoing) {
|
|
18714
|
+
if (this.isOutgoing === outgoing)
|
|
18715
|
+
return;
|
|
18716
|
+
this.callKit.logger.info("setOutgoing", {
|
|
18717
|
+
caller: "Connect.setOutgoing",
|
|
18718
|
+
content: {
|
|
18719
|
+
outgoing
|
|
18720
|
+
}
|
|
18721
|
+
});
|
|
18722
|
+
this.isOutgoing = outgoing;
|
|
18723
|
+
}
|
|
18608
18724
|
setCallId(callId) {
|
|
18609
18725
|
this.callKit.logger.info("setCallId", {
|
|
18610
18726
|
caller: "Connect.setCallId",
|
|
@@ -18616,6 +18732,15 @@ var WebCall = (() => {
|
|
|
18616
18732
|
this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
|
|
18617
18733
|
}
|
|
18618
18734
|
async reset() {
|
|
18735
|
+
this.setOutgoing(false);
|
|
18736
|
+
this.isUnprompted = false;
|
|
18737
|
+
this.hasInvite = false;
|
|
18738
|
+
if (this.isRefering) {
|
|
18739
|
+
this.setRefering(false);
|
|
18740
|
+
}
|
|
18741
|
+
if (this.isReConnected) {
|
|
18742
|
+
this.setIsReConnected(false);
|
|
18743
|
+
}
|
|
18619
18744
|
if (this.isHolding()) {
|
|
18620
18745
|
await this.setHold(false);
|
|
18621
18746
|
}
|
|
@@ -18635,9 +18760,6 @@ var WebCall = (() => {
|
|
|
18635
18760
|
this.mediaStream = void 0;
|
|
18636
18761
|
this.userAgent = void 0;
|
|
18637
18762
|
this.registerer = void 0;
|
|
18638
|
-
this.isOutgoing = false;
|
|
18639
|
-
this.isUnprompted = false;
|
|
18640
|
-
this.hasInvite = false;
|
|
18641
18763
|
if (this.mediaStream) {
|
|
18642
18764
|
try {
|
|
18643
18765
|
closeStream(this.mediaStream);
|
|
@@ -18654,7 +18776,6 @@ var WebCall = (() => {
|
|
|
18654
18776
|
}
|
|
18655
18777
|
}
|
|
18656
18778
|
this.setConnectStatus(CallStatus.init);
|
|
18657
|
-
this.clearHeartbeat();
|
|
18658
18779
|
}
|
|
18659
18780
|
getAduioReference() {
|
|
18660
18781
|
const { audioRef } = this.callKit.config.getConfig();
|
|
@@ -18719,28 +18840,6 @@ var WebCall = (() => {
|
|
|
18719
18840
|
isInit() {
|
|
18720
18841
|
return this.connectStatus === CallStatus.init;
|
|
18721
18842
|
}
|
|
18722
|
-
heartbeatInterval;
|
|
18723
|
-
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18724
|
-
clearHeartbeat() {
|
|
18725
|
-
if (this.heartbeatInterval) {
|
|
18726
|
-
clearInterval(this.heartbeatInterval);
|
|
18727
|
-
this.heartbeatInterval = null;
|
|
18728
|
-
}
|
|
18729
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18730
|
-
}
|
|
18731
|
-
startHeartbeat() {
|
|
18732
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18733
|
-
this.clearHeartbeat();
|
|
18734
|
-
this.heartbeatInterval = setInterval(() => {
|
|
18735
|
-
this.heartbeatFlag -= 1;
|
|
18736
|
-
if (this.heartbeatFlag <= 0) {
|
|
18737
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18738
|
-
this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
|
|
18739
|
-
event: "OPTIONS_HEARTBEAT_EXPIRED"
|
|
18740
|
-
});
|
|
18741
|
-
}
|
|
18742
|
-
}, 1e3);
|
|
18743
|
-
}
|
|
18744
18843
|
socketTriggerHangup(callId) {
|
|
18745
18844
|
if (!this.isCalling() || callId !== this.currentCallId)
|
|
18746
18845
|
return;
|
|
@@ -18753,6 +18852,136 @@ var WebCall = (() => {
|
|
|
18753
18852
|
});
|
|
18754
18853
|
this.callKit.hangup();
|
|
18755
18854
|
}
|
|
18855
|
+
/**
|
|
18856
|
+
* Setup registerer and bind stateChange listener
|
|
18857
|
+
* @private
|
|
18858
|
+
*/
|
|
18859
|
+
setupRegisterer() {
|
|
18860
|
+
if (!this.userAgent) {
|
|
18861
|
+
this.callKit.logger.warn("userAgent is not initialized", {
|
|
18862
|
+
caller: "Connect.setupRegisterer",
|
|
18863
|
+
content: {
|
|
18864
|
+
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
18865
|
+
}
|
|
18866
|
+
});
|
|
18867
|
+
return;
|
|
18868
|
+
}
|
|
18869
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
18870
|
+
const { userPart, fsIp, fsPort } = userInfo;
|
|
18871
|
+
const registererOptions = {};
|
|
18872
|
+
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
18873
|
+
this.registerer.stateChange.addListener((state) => {
|
|
18874
|
+
switch (state) {
|
|
18875
|
+
case RegistererState.Initial:
|
|
18876
|
+
this.callKit.logger.info("registerer stateChange Initial", {
|
|
18877
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18878
|
+
type: "SIP",
|
|
18879
|
+
content: {
|
|
18880
|
+
registererState: state,
|
|
18881
|
+
isRegistered: this.isRegistered()
|
|
18882
|
+
}
|
|
18883
|
+
});
|
|
18884
|
+
this.setRegister(false);
|
|
18885
|
+
this.setConnectStatus(CallStatus.init);
|
|
18886
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18887
|
+
registererState: state,
|
|
18888
|
+
isRegistered: this.isRegistered()
|
|
18889
|
+
});
|
|
18890
|
+
break;
|
|
18891
|
+
case RegistererState.Registered:
|
|
18892
|
+
this.callKit.logger.info("registerer stateChange Registered", {
|
|
18893
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18894
|
+
type: "SIP",
|
|
18895
|
+
content: {
|
|
18896
|
+
registererState: state,
|
|
18897
|
+
isRegistered: this.isRegistered()
|
|
18898
|
+
}
|
|
18899
|
+
});
|
|
18900
|
+
this.setRegister(true);
|
|
18901
|
+
if (this.isReConnected) {
|
|
18902
|
+
if (this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling()) {
|
|
18903
|
+
const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
18904
|
+
this.callKit.logger.info(
|
|
18905
|
+
"Reconnected, referring active session to self",
|
|
18906
|
+
{
|
|
18907
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18908
|
+
type: "SIP",
|
|
18909
|
+
content: {
|
|
18910
|
+
selfUri,
|
|
18911
|
+
sessionState: this.currentSession.state,
|
|
18912
|
+
connectStatus: this.connectStatus
|
|
18913
|
+
}
|
|
18914
|
+
}
|
|
18915
|
+
);
|
|
18916
|
+
this.refer(selfUri).catch((err) => {
|
|
18917
|
+
this.callKit.logger.error(err, {
|
|
18918
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18919
|
+
type: "SIP",
|
|
18920
|
+
content: {
|
|
18921
|
+
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
18922
|
+
selfUri
|
|
18923
|
+
}
|
|
18924
|
+
});
|
|
18925
|
+
});
|
|
18926
|
+
} else {
|
|
18927
|
+
this.callKit.logger.warn(
|
|
18928
|
+
"Reconnected but no active session to refer",
|
|
18929
|
+
{
|
|
18930
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18931
|
+
type: "SIP",
|
|
18932
|
+
content: {
|
|
18933
|
+
hasCurrentSession: !!this.currentSession,
|
|
18934
|
+
sessionState: this.currentSession?.state,
|
|
18935
|
+
connectStatus: this.connectStatus,
|
|
18936
|
+
isCalling: this.isCalling()
|
|
18937
|
+
}
|
|
18938
|
+
}
|
|
18939
|
+
);
|
|
18940
|
+
}
|
|
18941
|
+
this.setIsReConnected(false);
|
|
18942
|
+
}
|
|
18943
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18944
|
+
registererState: state,
|
|
18945
|
+
isRegistered: this.isRegistered()
|
|
18946
|
+
});
|
|
18947
|
+
break;
|
|
18948
|
+
case RegistererState.Terminated:
|
|
18949
|
+
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
18950
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18951
|
+
type: "SIP",
|
|
18952
|
+
content: {
|
|
18953
|
+
registererState: state,
|
|
18954
|
+
isRegistered: this.isRegistered()
|
|
18955
|
+
}
|
|
18956
|
+
});
|
|
18957
|
+
this.setRegister(false);
|
|
18958
|
+
this.setConnectStatus(CallStatus.init);
|
|
18959
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18960
|
+
registererState: state,
|
|
18961
|
+
isRegistered: this.isRegistered()
|
|
18962
|
+
});
|
|
18963
|
+
break;
|
|
18964
|
+
case RegistererState.Unregistered:
|
|
18965
|
+
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
18966
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18967
|
+
type: "SIP",
|
|
18968
|
+
content: {
|
|
18969
|
+
isRegistered: this.isRegistered(),
|
|
18970
|
+
registererState: state
|
|
18971
|
+
}
|
|
18972
|
+
});
|
|
18973
|
+
this.setRegister(false);
|
|
18974
|
+
this.setConnectStatus(CallStatus.init);
|
|
18975
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18976
|
+
registererState: state,
|
|
18977
|
+
isRegistered: this.isRegistered()
|
|
18978
|
+
});
|
|
18979
|
+
break;
|
|
18980
|
+
default:
|
|
18981
|
+
break;
|
|
18982
|
+
}
|
|
18983
|
+
});
|
|
18984
|
+
}
|
|
18756
18985
|
async register() {
|
|
18757
18986
|
if (this.connectStatus !== CallStatus.init) {
|
|
18758
18987
|
if (this.isRegistered()) {
|
|
@@ -18854,9 +19083,6 @@ var WebCall = (() => {
|
|
|
18854
19083
|
const core = userAgent.userAgentCore;
|
|
18855
19084
|
const originalReceiveIncomingRequestFromTransport = core.receiveIncomingRequestFromTransport.bind(core);
|
|
18856
19085
|
core.receiveIncomingRequestFromTransport = (request2) => {
|
|
18857
|
-
if (request2.method === "OPTIONS") {
|
|
18858
|
-
that.startHeartbeat();
|
|
18859
|
-
}
|
|
18860
19086
|
that.callKit.logger.info(`SIP Receive: ${request2?.method}`, {
|
|
18861
19087
|
caller: "Connect.register.observeSocketStatus.receiveRequest",
|
|
18862
19088
|
type: "SIP",
|
|
@@ -18866,6 +19092,20 @@ var WebCall = (() => {
|
|
|
18866
19092
|
});
|
|
18867
19093
|
return originalReceiveIncomingRequestFromTransport(request2);
|
|
18868
19094
|
};
|
|
19095
|
+
const originalReceiveIncomingResponseFromTransport = core.receiveIncomingResponseFromTransport.bind(core);
|
|
19096
|
+
core.receiveIncomingResponseFromTransport = (response) => {
|
|
19097
|
+
that.callKit.logger.info(
|
|
19098
|
+
`SIP Receive Response: ${response?.statusCode} ${response?.reasonPhrase}`,
|
|
19099
|
+
{
|
|
19100
|
+
caller: "Connect.register.observeSocketStatus.receiveResponse",
|
|
19101
|
+
type: "SIP",
|
|
19102
|
+
content: {
|
|
19103
|
+
response
|
|
19104
|
+
}
|
|
19105
|
+
}
|
|
19106
|
+
);
|
|
19107
|
+
return originalReceiveIncomingResponseFromTransport(response);
|
|
19108
|
+
};
|
|
18869
19109
|
const { transport } = userAgent;
|
|
18870
19110
|
if (transport) {
|
|
18871
19111
|
const originalSend = transport.send.bind(transport);
|
|
@@ -18881,77 +19121,7 @@ var WebCall = (() => {
|
|
|
18881
19121
|
};
|
|
18882
19122
|
}
|
|
18883
19123
|
};
|
|
18884
|
-
|
|
18885
|
-
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
18886
|
-
this.registerer.stateChange.addListener((state) => {
|
|
18887
|
-
switch (state) {
|
|
18888
|
-
case RegistererState.Initial:
|
|
18889
|
-
this.callKit.logger.info("registerer stateChange Initial", {
|
|
18890
|
-
caller: "Connect.register.registererStateChange",
|
|
18891
|
-
type: "SIP",
|
|
18892
|
-
content: {
|
|
18893
|
-
registererState: state,
|
|
18894
|
-
isRegistered: this.isRegistered()
|
|
18895
|
-
}
|
|
18896
|
-
});
|
|
18897
|
-
this.setRegister(false);
|
|
18898
|
-
this.setConnectStatus(CallStatus.init);
|
|
18899
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18900
|
-
registererState: state,
|
|
18901
|
-
isRegistered: this.isRegistered()
|
|
18902
|
-
});
|
|
18903
|
-
break;
|
|
18904
|
-
case RegistererState.Registered:
|
|
18905
|
-
this.callKit.logger.info("registerer stateChange Registered", {
|
|
18906
|
-
caller: "Connect.register.registererStateChange",
|
|
18907
|
-
type: "SIP",
|
|
18908
|
-
content: {
|
|
18909
|
-
registererState: state,
|
|
18910
|
-
isRegistered: this.isRegistered()
|
|
18911
|
-
}
|
|
18912
|
-
});
|
|
18913
|
-
this.setRegister(true);
|
|
18914
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18915
|
-
registererState: state,
|
|
18916
|
-
isRegistered: this.isRegistered()
|
|
18917
|
-
});
|
|
18918
|
-
break;
|
|
18919
|
-
case RegistererState.Terminated:
|
|
18920
|
-
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
18921
|
-
caller: "Connect.register.registererStateChange",
|
|
18922
|
-
type: "SIP",
|
|
18923
|
-
content: {
|
|
18924
|
-
registererState: state,
|
|
18925
|
-
isRegistered: this.isRegistered()
|
|
18926
|
-
}
|
|
18927
|
-
});
|
|
18928
|
-
this.setRegister(false);
|
|
18929
|
-
this.setConnectStatus(CallStatus.init);
|
|
18930
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18931
|
-
registererState: state,
|
|
18932
|
-
isRegistered: this.isRegistered()
|
|
18933
|
-
});
|
|
18934
|
-
break;
|
|
18935
|
-
case RegistererState.Unregistered:
|
|
18936
|
-
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
18937
|
-
caller: "Connect.register.registererStateChange",
|
|
18938
|
-
type: "SIP",
|
|
18939
|
-
content: {
|
|
18940
|
-
isRegistered: this.isRegistered(),
|
|
18941
|
-
registererState: state
|
|
18942
|
-
}
|
|
18943
|
-
});
|
|
18944
|
-
this.setRegister(false);
|
|
18945
|
-
this.setConnectStatus(CallStatus.init);
|
|
18946
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18947
|
-
registererState: state,
|
|
18948
|
-
isRegistered: this.isRegistered()
|
|
18949
|
-
});
|
|
18950
|
-
break;
|
|
18951
|
-
default:
|
|
18952
|
-
break;
|
|
18953
|
-
}
|
|
18954
|
-
});
|
|
19124
|
+
this.setupRegisterer();
|
|
18955
19125
|
this.userAgent.delegate = {
|
|
18956
19126
|
onInvite: (invite) => {
|
|
18957
19127
|
this.callKit.logger.info("connect onInvite", {
|
|
@@ -18959,7 +19129,8 @@ var WebCall = (() => {
|
|
|
18959
19129
|
caller: "Connect.register.onInvite",
|
|
18960
19130
|
content: {
|
|
18961
19131
|
invite,
|
|
18962
|
-
isRegistered: this.isRegistered()
|
|
19132
|
+
isRegistered: this.isRegistered(),
|
|
19133
|
+
isOutgoing: this.isOutgoing
|
|
18963
19134
|
}
|
|
18964
19135
|
});
|
|
18965
19136
|
this.currentSession = invite;
|
|
@@ -19037,7 +19208,9 @@ var WebCall = (() => {
|
|
|
19037
19208
|
});
|
|
19038
19209
|
this.callKit.logger.info("get invite data", {
|
|
19039
19210
|
caller: "Connect.register.onInvite",
|
|
19040
|
-
content:
|
|
19211
|
+
content: {
|
|
19212
|
+
headers: xHeaders
|
|
19213
|
+
}
|
|
19041
19214
|
});
|
|
19042
19215
|
return xHeaders;
|
|
19043
19216
|
};
|
|
@@ -19058,9 +19231,16 @@ var WebCall = (() => {
|
|
|
19058
19231
|
} catch (error) {
|
|
19059
19232
|
this.callKit.logger.info(error, {
|
|
19060
19233
|
caller: "Connect.register.onInvite",
|
|
19061
|
-
content:
|
|
19234
|
+
content: {
|
|
19235
|
+
headers: info
|
|
19236
|
+
}
|
|
19062
19237
|
});
|
|
19063
19238
|
}
|
|
19239
|
+
if (this.isRefering) {
|
|
19240
|
+
this.currentSession.accept(options);
|
|
19241
|
+
this.setRefering(false);
|
|
19242
|
+
return;
|
|
19243
|
+
}
|
|
19064
19244
|
if (this.isOutgoing) {
|
|
19065
19245
|
this.currentSession.accept(options);
|
|
19066
19246
|
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
@@ -19096,9 +19276,8 @@ var WebCall = (() => {
|
|
|
19096
19276
|
version: `${this.callKit.config.getConfig().version}`
|
|
19097
19277
|
}
|
|
19098
19278
|
});
|
|
19099
|
-
|
|
19100
|
-
|
|
19101
|
-
}).catch(async (err) => {
|
|
19279
|
+
this.setupRegisterer();
|
|
19280
|
+
await this.registerer.register().catch(async (err) => {
|
|
19102
19281
|
this.callKit.reset();
|
|
19103
19282
|
this.callKit.logger.error(err?.message, {
|
|
19104
19283
|
caller: "Connect.register",
|
|
@@ -19110,9 +19289,8 @@ var WebCall = (() => {
|
|
|
19110
19289
|
});
|
|
19111
19290
|
},
|
|
19112
19291
|
onDisconnect: (error) => {
|
|
19113
|
-
console.log("onDisconnect", error);
|
|
19114
19292
|
if (error) {
|
|
19115
|
-
this.callKit.logger.
|
|
19293
|
+
this.callKit.logger.warn("SIP User Agent Disconnected with error", {
|
|
19116
19294
|
caller: "Connect.register",
|
|
19117
19295
|
type: "SIP",
|
|
19118
19296
|
content: {
|
|
@@ -19122,21 +19300,12 @@ var WebCall = (() => {
|
|
|
19122
19300
|
});
|
|
19123
19301
|
this.startReconnectTimer();
|
|
19124
19302
|
} else {
|
|
19125
|
-
this.callKit.logger.
|
|
19303
|
+
this.callKit.logger.warn("SIP User Agent Disconnected", {
|
|
19126
19304
|
caller: "Connect.register",
|
|
19127
19305
|
type: "SIP",
|
|
19128
19306
|
content: {}
|
|
19129
19307
|
});
|
|
19130
19308
|
}
|
|
19131
|
-
},
|
|
19132
|
-
onRegister: () => {
|
|
19133
|
-
this.callKit.logger.info("connect onRegister", {
|
|
19134
|
-
caller: "Connect.register",
|
|
19135
|
-
type: "SIP",
|
|
19136
|
-
content: {
|
|
19137
|
-
version: `V${this.callKit.config.getConfig().version}`
|
|
19138
|
-
}
|
|
19139
|
-
});
|
|
19140
19309
|
}
|
|
19141
19310
|
};
|
|
19142
19311
|
observeSocketStatus(this.userAgent, {
|
|
@@ -19182,6 +19351,7 @@ var WebCall = (() => {
|
|
|
19182
19351
|
this.reconnectTimer = setTimeout(() => {
|
|
19183
19352
|
if (this.reconnectTimer && this.callKit.config.isLogin()) {
|
|
19184
19353
|
this.userAgent?.reconnect();
|
|
19354
|
+
this.setIsReConnected(true);
|
|
19185
19355
|
this.callKit.logger.info("Reconnect attempt", {
|
|
19186
19356
|
caller: "Connect.startReconnectTimer",
|
|
19187
19357
|
type: "SIP",
|
|
@@ -19226,14 +19396,15 @@ var WebCall = (() => {
|
|
|
19226
19396
|
return;
|
|
19227
19397
|
}
|
|
19228
19398
|
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
19229
|
-
this.callKit.
|
|
19230
|
-
this.callKit.logger.error(err, {
|
|
19399
|
+
this.callKit.logger.warn(err, {
|
|
19231
19400
|
caller: "Connect.unregister",
|
|
19232
19401
|
type: "SIP",
|
|
19233
19402
|
content: {
|
|
19234
19403
|
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
19235
19404
|
}
|
|
19236
19405
|
});
|
|
19406
|
+
}).finally(() => {
|
|
19407
|
+
this.setRegister(false);
|
|
19237
19408
|
});
|
|
19238
19409
|
await this.userAgent?.stop().catch((err) => {
|
|
19239
19410
|
this.callKit.logger.warn(err, {
|
|
@@ -19246,20 +19417,20 @@ var WebCall = (() => {
|
|
|
19246
19417
|
});
|
|
19247
19418
|
}
|
|
19248
19419
|
async call(callback) {
|
|
19249
|
-
this.
|
|
19250
|
-
caller: "Connect.call",
|
|
19251
|
-
type: "SIP",
|
|
19252
|
-
content: {
|
|
19253
|
-
callback
|
|
19254
|
-
}
|
|
19255
|
-
});
|
|
19256
|
-
this.isOutgoing = true;
|
|
19420
|
+
this.setOutgoing(true);
|
|
19257
19421
|
if (!this.isRegistered()) {
|
|
19258
19422
|
await this.register();
|
|
19259
19423
|
}
|
|
19260
19424
|
this.setConnectStatus(CallStatus.connecting);
|
|
19261
19425
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
19262
19426
|
const { userInfo } = this.callKit.config.getConfig();
|
|
19427
|
+
this.callKit.logger.info("connect call", {
|
|
19428
|
+
caller: "Connect.call",
|
|
19429
|
+
type: "SIP",
|
|
19430
|
+
content: {
|
|
19431
|
+
userInfo
|
|
19432
|
+
}
|
|
19433
|
+
});
|
|
19263
19434
|
callback(userInfo);
|
|
19264
19435
|
}
|
|
19265
19436
|
/**
|
|
@@ -19267,6 +19438,8 @@ var WebCall = (() => {
|
|
|
19267
19438
|
* @param register
|
|
19268
19439
|
*/
|
|
19269
19440
|
setRegister(register) {
|
|
19441
|
+
if (this.isRegister === register)
|
|
19442
|
+
return;
|
|
19270
19443
|
this.callKit.logger.info("connect setRegister", {
|
|
19271
19444
|
caller: "Connect.setRegister",
|
|
19272
19445
|
type: "SIP",
|
|
@@ -19308,7 +19481,7 @@ var WebCall = (() => {
|
|
|
19308
19481
|
connectStatus: this.connectStatus
|
|
19309
19482
|
}
|
|
19310
19483
|
});
|
|
19311
|
-
this.
|
|
19484
|
+
this.setOutgoing(false);
|
|
19312
19485
|
this.isUnprompted = isUnprompted;
|
|
19313
19486
|
this.setHold(false);
|
|
19314
19487
|
this.setMute(false);
|
|
@@ -19336,6 +19509,7 @@ var WebCall = (() => {
|
|
|
19336
19509
|
}
|
|
19337
19510
|
this.setConnectStatus(CallStatus.init);
|
|
19338
19511
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19512
|
+
this.setCallId(null);
|
|
19339
19513
|
} catch (err) {
|
|
19340
19514
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19341
19515
|
this.callKit.reset();
|
|
@@ -19462,12 +19636,26 @@ var WebCall = (() => {
|
|
|
19462
19636
|
this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19463
19637
|
}
|
|
19464
19638
|
async refer(referTo, extra) {
|
|
19639
|
+
if (!this.currentSession) {
|
|
19640
|
+
const errorMsg = "Cannot refer: currentSession is not available";
|
|
19641
|
+
this.callKit.logger.warn(errorMsg, {
|
|
19642
|
+
caller: "Connect.refer",
|
|
19643
|
+
type: "SIP",
|
|
19644
|
+
content: {
|
|
19645
|
+
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
19646
|
+
referTo
|
|
19647
|
+
}
|
|
19648
|
+
});
|
|
19649
|
+
return;
|
|
19650
|
+
}
|
|
19651
|
+
this.setRefering(true);
|
|
19465
19652
|
this.callKit.logger.info("connect refer", {
|
|
19466
19653
|
caller: "Connect.refer",
|
|
19467
19654
|
type: "SIP",
|
|
19468
19655
|
content: {
|
|
19469
19656
|
referTo,
|
|
19470
|
-
extra
|
|
19657
|
+
extra,
|
|
19658
|
+
sessionState: this.currentSession.state
|
|
19471
19659
|
}
|
|
19472
19660
|
});
|
|
19473
19661
|
let target;
|
|
@@ -19479,13 +19667,7 @@ var WebCall = (() => {
|
|
|
19479
19667
|
};
|
|
19480
19668
|
|
|
19481
19669
|
// core/socket.ts
|
|
19482
|
-
var
|
|
19483
|
-
enabled: true,
|
|
19484
|
-
maxAttempts: 3,
|
|
19485
|
-
delay: 1e3,
|
|
19486
|
-
pingInterval: 3e4,
|
|
19487
|
-
pingTimeout: 5e3
|
|
19488
|
-
};
|
|
19670
|
+
var EXCLUDE_LOG_EVENTS = [SocketReceiveEvent.WAITING_QUEUE];
|
|
19489
19671
|
var Socket = class {
|
|
19490
19672
|
callKit;
|
|
19491
19673
|
ws;
|
|
@@ -19502,7 +19684,7 @@ var WebCall = (() => {
|
|
|
19502
19684
|
/**
|
|
19503
19685
|
* @description connect auth state
|
|
19504
19686
|
* @default {
|
|
19505
|
-
*
|
|
19687
|
+
* startConfirm: false,
|
|
19506
19688
|
* isConnected: false,
|
|
19507
19689
|
* isReconnecting: false,
|
|
19508
19690
|
* isAuthenticated: false,
|
|
@@ -19510,14 +19692,13 @@ var WebCall = (() => {
|
|
|
19510
19692
|
* }
|
|
19511
19693
|
*/
|
|
19512
19694
|
connectAuthState = {
|
|
19513
|
-
|
|
19695
|
+
startConfirm: false,
|
|
19514
19696
|
isConnected: false,
|
|
19515
19697
|
isReconnecting: false,
|
|
19516
|
-
isAuthenticated: false,
|
|
19517
19698
|
isError: false
|
|
19518
19699
|
};
|
|
19519
|
-
get
|
|
19520
|
-
return this.connectAuthState.
|
|
19700
|
+
get startConfirm() {
|
|
19701
|
+
return this.connectAuthState.startConfirm;
|
|
19521
19702
|
}
|
|
19522
19703
|
get isError() {
|
|
19523
19704
|
return this.connectAuthState.isError;
|
|
@@ -19525,6 +19706,9 @@ var WebCall = (() => {
|
|
|
19525
19706
|
constructor(callKit) {
|
|
19526
19707
|
this.callKit = callKit;
|
|
19527
19708
|
}
|
|
19709
|
+
get reconnectConfig() {
|
|
19710
|
+
return this.callKit.config.getReconnectConfig("incall");
|
|
19711
|
+
}
|
|
19528
19712
|
init() {
|
|
19529
19713
|
const { socket } = this.callKit.config.getConfig();
|
|
19530
19714
|
this.callKit.logger.info(`socket init: ${socket}`, {
|
|
@@ -19536,13 +19720,6 @@ var WebCall = (() => {
|
|
|
19536
19720
|
});
|
|
19537
19721
|
this.connect(socket);
|
|
19538
19722
|
}
|
|
19539
|
-
getSocketConfig() {
|
|
19540
|
-
const { reconnect } = this.callKit.config.getConfig();
|
|
19541
|
-
return {
|
|
19542
|
-
...RECONNECT_CONFIG,
|
|
19543
|
-
...reconnect
|
|
19544
|
-
};
|
|
19545
|
-
}
|
|
19546
19723
|
setConnectAuthState(key, value) {
|
|
19547
19724
|
if (this.connectAuthState[key] === value)
|
|
19548
19725
|
return;
|
|
@@ -19550,7 +19727,7 @@ var WebCall = (() => {
|
|
|
19550
19727
|
}
|
|
19551
19728
|
handleDisconnect() {
|
|
19552
19729
|
this.setConnectAuthState("isConnected", false);
|
|
19553
|
-
const { enabled } = this.
|
|
19730
|
+
const { enabled } = this.reconnectConfig;
|
|
19554
19731
|
if (!this.callKit.config.isLogin() || !enabled) {
|
|
19555
19732
|
this.callKit.reset();
|
|
19556
19733
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
@@ -19561,6 +19738,9 @@ var WebCall = (() => {
|
|
|
19561
19738
|
if (this.connectAuthState.isReconnecting) {
|
|
19562
19739
|
return;
|
|
19563
19740
|
}
|
|
19741
|
+
if (this.connectAuthState.isError) {
|
|
19742
|
+
return;
|
|
19743
|
+
}
|
|
19564
19744
|
this.attemptReconnect();
|
|
19565
19745
|
}
|
|
19566
19746
|
clearWebSocket() {
|
|
@@ -19600,6 +19780,7 @@ var WebCall = (() => {
|
|
|
19600
19780
|
this.setConnectAuthState("isConnected", true);
|
|
19601
19781
|
this.lastPingTime = Date.now();
|
|
19602
19782
|
this.checkPing();
|
|
19783
|
+
this.send(SocketSendEvent.START);
|
|
19603
19784
|
if (this.connectAuthState.isReconnecting) {
|
|
19604
19785
|
this.setConnectAuthState("isReconnecting", false);
|
|
19605
19786
|
this.callKit.logger.info("reconnect success", {
|
|
@@ -19615,19 +19796,31 @@ var WebCall = (() => {
|
|
|
19615
19796
|
});
|
|
19616
19797
|
}
|
|
19617
19798
|
}
|
|
19799
|
+
cleanReconnectState() {
|
|
19800
|
+
this.reconnectAttempts = 0;
|
|
19801
|
+
if (this.reconnectTimer) {
|
|
19802
|
+
clearTimeout(this.reconnectTimer);
|
|
19803
|
+
this.reconnectTimer = void 0;
|
|
19804
|
+
}
|
|
19805
|
+
this.setConnectAuthState("isReconnecting", false);
|
|
19806
|
+
this.setConnectAuthState("isError", false);
|
|
19807
|
+
}
|
|
19618
19808
|
resetConnectState() {
|
|
19619
19809
|
this.connectAuthState = {
|
|
19620
|
-
|
|
19810
|
+
startConfirm: false,
|
|
19621
19811
|
isConnected: false,
|
|
19622
19812
|
isReconnecting: false,
|
|
19623
|
-
isAuthenticated: false,
|
|
19624
19813
|
isError: false
|
|
19625
19814
|
};
|
|
19626
|
-
this.
|
|
19627
|
-
|
|
19628
|
-
|
|
19629
|
-
|
|
19630
|
-
|
|
19815
|
+
this.cleanReconnectState();
|
|
19816
|
+
this.callKit.logger.info("reset connect state", {
|
|
19817
|
+
caller: "Socket.resetConnectState",
|
|
19818
|
+
type: "INCALL",
|
|
19819
|
+
content: {
|
|
19820
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
19821
|
+
connectAuthState: this.connectAuthState
|
|
19822
|
+
}
|
|
19823
|
+
});
|
|
19631
19824
|
}
|
|
19632
19825
|
onClose(ev) {
|
|
19633
19826
|
this.callKit.logger.info("socket onClose", {
|
|
@@ -19661,9 +19854,9 @@ var WebCall = (() => {
|
|
|
19661
19854
|
}
|
|
19662
19855
|
onMessage(ev) {
|
|
19663
19856
|
const data = JSON.parse(ev.data);
|
|
19664
|
-
let content =
|
|
19857
|
+
let content = data.data;
|
|
19665
19858
|
try {
|
|
19666
|
-
if (data.data) {
|
|
19859
|
+
if (typeof data.data === "string" && data.data) {
|
|
19667
19860
|
content = JSON.parse(data.data);
|
|
19668
19861
|
}
|
|
19669
19862
|
} catch (error) {
|
|
@@ -19674,159 +19867,73 @@ var WebCall = (() => {
|
|
|
19674
19867
|
data: data.data
|
|
19675
19868
|
}
|
|
19676
19869
|
});
|
|
19677
|
-
content = data.data;
|
|
19678
19870
|
}
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
type: "INCALL",
|
|
19682
|
-
content: {
|
|
19683
|
-
data: content,
|
|
19684
|
-
event: data.event
|
|
19685
|
-
}
|
|
19686
|
-
});
|
|
19687
|
-
this.confirmAck(data);
|
|
19688
|
-
if (data.event === SocketReceiveEvent.PONG) {
|
|
19689
|
-
this.lastPingTime = Date.now();
|
|
19690
|
-
this.setConnectAuthState("isAuthenticated", true);
|
|
19691
|
-
this.callKit.logger.info("socket onMessage pong Authenticated", {
|
|
19871
|
+
if (!EXCLUDE_LOG_EVENTS.includes(data.event)) {
|
|
19872
|
+
this.callKit.logger.info(`socket onMessage: ${data.event}`, {
|
|
19692
19873
|
caller: "Socket.onMessage",
|
|
19693
19874
|
type: "INCALL",
|
|
19694
19875
|
content: {
|
|
19695
19876
|
data: content,
|
|
19696
|
-
event:
|
|
19697
|
-
isAuthenticated: true
|
|
19877
|
+
event: data.event
|
|
19698
19878
|
}
|
|
19699
19879
|
});
|
|
19700
|
-
|
|
19701
|
-
|
|
19702
|
-
|
|
19703
|
-
|
|
19880
|
+
}
|
|
19881
|
+
this.confirmAck(data);
|
|
19882
|
+
const callUuid = content?.callUuid || "";
|
|
19883
|
+
if (data.event === SocketReceiveEvent.PONG) {
|
|
19884
|
+
this.lastPingTime = Date.now();
|
|
19704
19885
|
return;
|
|
19705
19886
|
}
|
|
19706
19887
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
19707
|
-
this.
|
|
19708
|
-
|
|
19709
|
-
type: "INCALL",
|
|
19710
|
-
content: {
|
|
19711
|
-
data: content,
|
|
19712
|
-
event: SocketReceiveEvent.START_CONFIRM
|
|
19713
|
-
}
|
|
19714
|
-
});
|
|
19715
|
-
this.setConnectAuthState("satrtConfirm", true);
|
|
19716
|
-
}
|
|
19717
|
-
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
19718
|
-
this.callKit.logger.info("call success", {
|
|
19719
|
-
caller: "Socket.onMessage",
|
|
19720
|
-
type: "INCALL",
|
|
19721
|
-
content: {
|
|
19722
|
-
data: content,
|
|
19723
|
-
event: SocketReceiveEvent.CALL_SUCCESS
|
|
19724
|
-
}
|
|
19725
|
-
});
|
|
19726
|
-
}
|
|
19727
|
-
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
19728
|
-
this.callKit.logger.info(data.msg, {
|
|
19729
|
-
caller: "Socket.onMessage",
|
|
19730
|
-
type: "INCALL",
|
|
19731
|
-
content: {
|
|
19732
|
-
data: content,
|
|
19733
|
-
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
19734
|
-
}
|
|
19735
|
-
});
|
|
19888
|
+
this.setConnectAuthState("startConfirm", true);
|
|
19889
|
+
this.cleanReconnectState();
|
|
19736
19890
|
}
|
|
19737
19891
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
19738
|
-
this.callKit.trigger(KitEvent.CALL_RINGING,
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
type: "INCALL",
|
|
19742
|
-
content: {
|
|
19743
|
-
data: content,
|
|
19744
|
-
event: SocketReceiveEvent.CUSTOMER_RINGING
|
|
19745
|
-
}
|
|
19892
|
+
this.callKit.trigger(KitEvent.CALL_RINGING, {
|
|
19893
|
+
time: /* @__PURE__ */ new Date(),
|
|
19894
|
+
callUuid
|
|
19746
19895
|
});
|
|
19747
19896
|
}
|
|
19748
19897
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
19749
|
-
this.callKit.
|
|
19750
|
-
|
|
19751
|
-
|
|
19752
|
-
content: {
|
|
19753
|
-
data: content,
|
|
19754
|
-
event: SocketReceiveEvent.CUSTOMER_PICK_UP
|
|
19755
|
-
}
|
|
19898
|
+
this.callKit.trigger(KitEvent.CALL_PICK_UP, {
|
|
19899
|
+
time: /* @__PURE__ */ new Date(),
|
|
19900
|
+
callUuid
|
|
19756
19901
|
});
|
|
19757
|
-
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
19758
19902
|
}
|
|
19759
19903
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
19760
|
-
this.callKit.
|
|
19761
|
-
|
|
19762
|
-
|
|
19763
|
-
content: {
|
|
19764
|
-
data: content,
|
|
19765
|
-
event: SocketReceiveEvent.AGENT_PICK_UP
|
|
19766
|
-
}
|
|
19904
|
+
this.callKit.trigger(KitEvent.AGENT_PICK_UP, {
|
|
19905
|
+
time: /* @__PURE__ */ new Date(),
|
|
19906
|
+
callUuid
|
|
19767
19907
|
});
|
|
19768
|
-
this.callKit.trigger(KitEvent.AGENT_PICK_UP, /* @__PURE__ */ new Date());
|
|
19769
19908
|
}
|
|
19770
19909
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
19771
|
-
this.callKit.
|
|
19772
|
-
|
|
19773
|
-
|
|
19774
|
-
content: {
|
|
19775
|
-
data: content,
|
|
19776
|
-
event: SocketReceiveEvent.CUSTOMER_HANG_UP
|
|
19777
|
-
}
|
|
19910
|
+
this.callKit.trigger(KitEvent.CALL_HANG_UP, {
|
|
19911
|
+
time: /* @__PURE__ */ new Date(),
|
|
19912
|
+
callUuid
|
|
19778
19913
|
});
|
|
19779
|
-
|
|
19780
|
-
|
|
19781
|
-
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19914
|
+
if (callUuid) {
|
|
19915
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19782
19916
|
}
|
|
19783
19917
|
}
|
|
19784
19918
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
19785
|
-
this.callKit.
|
|
19786
|
-
|
|
19787
|
-
|
|
19788
|
-
content: {
|
|
19789
|
-
data: content,
|
|
19790
|
-
event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
|
|
19791
|
-
}
|
|
19919
|
+
this.callKit.trigger(KitEvent.CALL_NO_ANSWER, {
|
|
19920
|
+
time: /* @__PURE__ */ new Date(),
|
|
19921
|
+
callUuid
|
|
19792
19922
|
});
|
|
19793
|
-
|
|
19794
|
-
|
|
19795
|
-
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19923
|
+
if (callUuid) {
|
|
19924
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19796
19925
|
}
|
|
19797
19926
|
}
|
|
19798
19927
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
19799
|
-
this.callKit.
|
|
19800
|
-
|
|
19801
|
-
|
|
19802
|
-
content
|
|
19803
|
-
data: content,
|
|
19804
|
-
event: SocketReceiveEvent.CALL_CDR
|
|
19805
|
-
}
|
|
19806
|
-
});
|
|
19807
|
-
this.callKit.trigger(KitEvent.CALL_CDR, content);
|
|
19808
|
-
}
|
|
19809
|
-
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
19810
|
-
this.callKit.logger.info(data.msg, {
|
|
19811
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
19812
|
-
type: "INCALL",
|
|
19813
|
-
content: {
|
|
19814
|
-
data: content,
|
|
19815
|
-
event: SocketReceiveEvent.STOP_CONFIRM
|
|
19816
|
-
}
|
|
19928
|
+
this.callKit.trigger(KitEvent.CALL_CDR, {
|
|
19929
|
+
time: /* @__PURE__ */ new Date(),
|
|
19930
|
+
callUuid,
|
|
19931
|
+
...content
|
|
19817
19932
|
});
|
|
19818
19933
|
}
|
|
19819
19934
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
19820
19935
|
const { userInfo } = this.callKit.config.getConfig();
|
|
19821
|
-
this.
|
|
19822
|
-
caller: `Socket.onMessage:${data.event}`,
|
|
19823
|
-
type: "INCALL",
|
|
19824
|
-
content: {
|
|
19825
|
-
data: content,
|
|
19826
|
-
event: SocketReceiveEvent.CLOSE
|
|
19827
|
-
}
|
|
19828
|
-
});
|
|
19829
|
-
this.send(SocketSendEvent.END, { agentId: userInfo.agentId });
|
|
19936
|
+
this.send(SocketSendEvent.END, { agentId: userInfo.agentId, callUuid });
|
|
19830
19937
|
}
|
|
19831
19938
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
19832
19939
|
this.setConnectAuthState("isError", true);
|
|
@@ -19836,7 +19943,8 @@ var WebCall = (() => {
|
|
|
19836
19943
|
type: "INCALL",
|
|
19837
19944
|
content: {
|
|
19838
19945
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
19839
|
-
data: content
|
|
19946
|
+
data: content,
|
|
19947
|
+
callUuid
|
|
19840
19948
|
}
|
|
19841
19949
|
});
|
|
19842
19950
|
}
|
|
@@ -19848,24 +19956,29 @@ var WebCall = (() => {
|
|
|
19848
19956
|
type: "INCALL",
|
|
19849
19957
|
content: {
|
|
19850
19958
|
data: content,
|
|
19851
|
-
event: SocketReceiveEvent.SESSION_ERROR
|
|
19959
|
+
event: SocketReceiveEvent.SESSION_ERROR,
|
|
19960
|
+
callUuid
|
|
19852
19961
|
}
|
|
19853
19962
|
});
|
|
19854
19963
|
}
|
|
19855
19964
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
19856
|
-
|
|
19857
|
-
|
|
19858
|
-
type: "INCALL",
|
|
19859
|
-
content: {
|
|
19860
|
-
data: content,
|
|
19861
|
-
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
19862
|
-
}
|
|
19863
|
-
});
|
|
19864
|
-
if (content?.callUuid) {
|
|
19865
|
-
this.callKit.connect.socketTriggerHangup(content.callUuid);
|
|
19965
|
+
if (callUuid) {
|
|
19966
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19866
19967
|
}
|
|
19867
19968
|
}
|
|
19868
|
-
|
|
19969
|
+
if (data.event === SocketReceiveEvent.AGENT_HANG_UP) {
|
|
19970
|
+
if (callUuid) {
|
|
19971
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19972
|
+
}
|
|
19973
|
+
}
|
|
19974
|
+
this.callKit.trigger(
|
|
19975
|
+
KitEvent.SERVER_SOCKET_EVENT,
|
|
19976
|
+
{
|
|
19977
|
+
...data,
|
|
19978
|
+
callUuid
|
|
19979
|
+
},
|
|
19980
|
+
true
|
|
19981
|
+
);
|
|
19869
19982
|
}
|
|
19870
19983
|
send(event, message) {
|
|
19871
19984
|
if (!this.connectAuthState.isConnected) {
|
|
@@ -19913,32 +20026,18 @@ var WebCall = (() => {
|
|
|
19913
20026
|
caller: "Socket.send",
|
|
19914
20027
|
type: "INCALL",
|
|
19915
20028
|
content: {
|
|
19916
|
-
...msg
|
|
20029
|
+
...msg,
|
|
20030
|
+
userInfo
|
|
19917
20031
|
}
|
|
19918
20032
|
});
|
|
19919
|
-
|
|
19920
|
-
case SocketSendEvent.PING:
|
|
19921
|
-
this.lastPingTime = Date.now();
|
|
19922
|
-
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19923
|
-
break;
|
|
19924
|
-
default:
|
|
19925
|
-
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19926
|
-
break;
|
|
19927
|
-
}
|
|
20033
|
+
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19928
20034
|
}
|
|
19929
20035
|
ping() {
|
|
19930
20036
|
if (!this.connectAuthState.isConnected)
|
|
19931
20037
|
return;
|
|
19932
20038
|
this.send(SocketSendEvent.PING);
|
|
19933
|
-
this.callKit.logger.info(`socket ping`, {
|
|
19934
|
-
caller: "Socket.ping",
|
|
19935
|
-
type: "INCALL",
|
|
19936
|
-
content: {
|
|
19937
|
-
lastPingTime: this.lastPingTime
|
|
19938
|
-
}
|
|
19939
|
-
});
|
|
19940
20039
|
const now = Date.now();
|
|
19941
|
-
const { pingInterval, pingTimeout } = this.
|
|
20040
|
+
const { pingInterval, pingTimeout } = this.reconnectConfig;
|
|
19942
20041
|
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
19943
20042
|
if (this.ws && this.connectAuthState.isConnected) {
|
|
19944
20043
|
this.ws.close(4001, "ping timeout");
|
|
@@ -19952,14 +20051,16 @@ var WebCall = (() => {
|
|
|
19952
20051
|
errCode: ErrorCode.SOCKET_PING_TIMEOUT
|
|
19953
20052
|
}
|
|
19954
20053
|
});
|
|
20054
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20055
|
+
event: "INCALL_PING_TIMEOUT"
|
|
20056
|
+
});
|
|
19955
20057
|
}
|
|
19956
20058
|
}
|
|
19957
20059
|
checkPing() {
|
|
19958
20060
|
if (this.pingTimer) {
|
|
19959
20061
|
clearInterval(this.pingTimer);
|
|
19960
20062
|
}
|
|
19961
|
-
this.
|
|
19962
|
-
const { pingInterval } = this.getSocketConfig();
|
|
20063
|
+
const { pingInterval } = this.reconnectConfig;
|
|
19963
20064
|
this.pingTimer = setInterval(() => {
|
|
19964
20065
|
this.ping();
|
|
19965
20066
|
}, pingInterval);
|
|
@@ -19968,20 +20069,19 @@ var WebCall = (() => {
|
|
|
19968
20069
|
* reset socket connection and all states
|
|
19969
20070
|
*/
|
|
19970
20071
|
async reset(config) {
|
|
19971
|
-
const {
|
|
20072
|
+
const { force = false } = config || {};
|
|
19972
20073
|
if (this.pingTimer) {
|
|
19973
20074
|
clearInterval(this.pingTimer);
|
|
19974
20075
|
this.pingTimer = void 0;
|
|
19975
20076
|
}
|
|
19976
|
-
if (
|
|
20077
|
+
if (force) {
|
|
19977
20078
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19978
20079
|
event: "INCALL_RESET"
|
|
19979
20080
|
});
|
|
19980
20081
|
this.resetConnectState();
|
|
19981
|
-
this.setConnectAuthState("isConnected", false);
|
|
19982
20082
|
}
|
|
19983
20083
|
this.lastPingTime = void 0;
|
|
19984
|
-
this.setConnectAuthState("
|
|
20084
|
+
this.setConnectAuthState("startConfirm", false);
|
|
19985
20085
|
this.clearWebSocket();
|
|
19986
20086
|
}
|
|
19987
20087
|
attemptReconnect() {
|
|
@@ -19989,11 +20089,12 @@ var WebCall = (() => {
|
|
|
19989
20089
|
clearTimeout(this.reconnectTimer);
|
|
19990
20090
|
this.reconnectTimer = void 0;
|
|
19991
20091
|
}
|
|
19992
|
-
const { maxAttempts } = this.
|
|
20092
|
+
const { maxAttempts } = this.reconnectConfig;
|
|
19993
20093
|
if (this.reconnectAttempts >= maxAttempts) {
|
|
19994
20094
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19995
20095
|
event: "INCALL_RECONNECT_ERROR"
|
|
19996
20096
|
});
|
|
20097
|
+
this.setConnectAuthState("isError", true);
|
|
19997
20098
|
this.callKit.reset();
|
|
19998
20099
|
this.callKit.logger.error("Maximum reconnection attempts reached", {
|
|
19999
20100
|
caller: "Socket.attemptReconnect",
|
|
@@ -20012,7 +20113,7 @@ var WebCall = (() => {
|
|
|
20012
20113
|
}
|
|
20013
20114
|
this.setConnectAuthState("isReconnecting", true);
|
|
20014
20115
|
this.reconnectAttempts += 1;
|
|
20015
|
-
const { delay } = this.
|
|
20116
|
+
const { delay } = this.reconnectConfig;
|
|
20016
20117
|
this.callKit.logger.info(
|
|
20017
20118
|
`Preparing reconnection attempt ${this.reconnectAttempts}/${maxAttempts}, delay: ${delay}ms`,
|
|
20018
20119
|
{
|
|
@@ -20047,17 +20148,34 @@ var WebCall = (() => {
|
|
|
20047
20148
|
this.connect = new Connect(this);
|
|
20048
20149
|
this.callCenter = new Call(this);
|
|
20049
20150
|
this.socket = new Socket(this);
|
|
20050
|
-
this.
|
|
20051
|
-
|
|
20052
|
-
|
|
20053
|
-
|
|
20151
|
+
this.logger = new Logger(this, options.log);
|
|
20152
|
+
if (options.log) {
|
|
20153
|
+
this.config.setConfig("log", options.log);
|
|
20154
|
+
}
|
|
20155
|
+
if (options.trackLogs) {
|
|
20156
|
+
this.config.setConfig("trackLogs", {
|
|
20157
|
+
...trackLogsDefaultConfig,
|
|
20158
|
+
...options.trackLogs
|
|
20159
|
+
});
|
|
20160
|
+
}
|
|
20161
|
+
if (options.audioRef) {
|
|
20162
|
+
this.config.setConfig("audioRef", options.audioRef);
|
|
20163
|
+
}
|
|
20164
|
+
if (options.host) {
|
|
20165
|
+
this.config.setConfig("host", options.host);
|
|
20166
|
+
}
|
|
20054
20167
|
this.config.setConfig(
|
|
20055
20168
|
"constrains",
|
|
20056
20169
|
options.constrains || constrainsDefault
|
|
20057
20170
|
);
|
|
20058
20171
|
this.config.setConfig("socket", options.socket);
|
|
20059
|
-
this.config.setConfig("reconnect",
|
|
20060
|
-
|
|
20172
|
+
this.config.setConfig("reconnect", {
|
|
20173
|
+
sip: { ...SIP_RECONNECT_CONFIG, ...options.reconnect?.sip || {} },
|
|
20174
|
+
incall: {
|
|
20175
|
+
...SOCKET_RECONNECT_CONFIG,
|
|
20176
|
+
...options.reconnect?.incall || {}
|
|
20177
|
+
}
|
|
20178
|
+
});
|
|
20061
20179
|
this.logger.info("callKit init", {
|
|
20062
20180
|
caller: "CallKit.init",
|
|
20063
20181
|
content: options
|
|
@@ -20105,7 +20223,8 @@ var WebCall = (() => {
|
|
|
20105
20223
|
try {
|
|
20106
20224
|
const user = await this.api.login({
|
|
20107
20225
|
userName: username,
|
|
20108
|
-
password: encryptionPassword
|
|
20226
|
+
password: encryptionPassword,
|
|
20227
|
+
timestamp: Date.now()
|
|
20109
20228
|
});
|
|
20110
20229
|
if (user) {
|
|
20111
20230
|
this.config.setConfig("userInfo", {
|
|
@@ -20151,7 +20270,7 @@ var WebCall = (() => {
|
|
|
20151
20270
|
if (this.config.isLogin()) {
|
|
20152
20271
|
const { sessionId } = userInfo;
|
|
20153
20272
|
try {
|
|
20154
|
-
await this.api.loginOut({ sessionId });
|
|
20273
|
+
await this.api.loginOut({ sessionId, timestamp: Date.now() });
|
|
20155
20274
|
} catch (error) {
|
|
20156
20275
|
this.logger.warn(error, {
|
|
20157
20276
|
caller: "CallKit.logout",
|
|
@@ -20163,8 +20282,9 @@ var WebCall = (() => {
|
|
|
20163
20282
|
}
|
|
20164
20283
|
if (isReset) {
|
|
20165
20284
|
await this.reset();
|
|
20285
|
+
} else {
|
|
20286
|
+
this.config.reset("logout");
|
|
20166
20287
|
}
|
|
20167
|
-
this.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
20168
20288
|
}
|
|
20169
20289
|
async call(extno = "", options = {
|
|
20170
20290
|
sourceType: CallSourceType.phoneNum,
|
|
@@ -20297,7 +20417,7 @@ var WebCall = (() => {
|
|
|
20297
20417
|
* set userstatus
|
|
20298
20418
|
* @param status
|
|
20299
20419
|
*/
|
|
20300
|
-
async setUserStatus(status) {
|
|
20420
|
+
async setUserStatus(status, extra = {}) {
|
|
20301
20421
|
const { agentId } = this.config.getConfig().userInfo;
|
|
20302
20422
|
this.logger.info("setUserStatus", {
|
|
20303
20423
|
caller: "CallKit.setUserStatus",
|
|
@@ -20308,16 +20428,24 @@ var WebCall = (() => {
|
|
|
20308
20428
|
});
|
|
20309
20429
|
await this.api.updateUserStatus({
|
|
20310
20430
|
agentId,
|
|
20311
|
-
userStatus: status
|
|
20431
|
+
userStatus: status,
|
|
20432
|
+
timestamp: Date.now(),
|
|
20433
|
+
...extra
|
|
20312
20434
|
});
|
|
20313
20435
|
}
|
|
20314
|
-
|
|
20315
|
-
|
|
20436
|
+
/**
|
|
20437
|
+
* reset callkit
|
|
20438
|
+
* @description recover the callkit to the initial state
|
|
20439
|
+
* @default force is false
|
|
20440
|
+
* @param config.force is true, the callkit reset socket connection and all states
|
|
20441
|
+
*/
|
|
20442
|
+
async reset(config) {
|
|
20443
|
+
const { force = false } = config || {};
|
|
20316
20444
|
this.logger.info("reset", {
|
|
20317
20445
|
caller: "CallKit.reset",
|
|
20318
20446
|
content: {
|
|
20319
20447
|
connectStatus: this.connect.connectStatus,
|
|
20320
|
-
|
|
20448
|
+
force
|
|
20321
20449
|
}
|
|
20322
20450
|
});
|
|
20323
20451
|
if (this.connect.isCalling()) {
|
|
@@ -20326,16 +20454,10 @@ var WebCall = (() => {
|
|
|
20326
20454
|
await this.connect.reset();
|
|
20327
20455
|
if (this.config.isLogin()) {
|
|
20328
20456
|
await this.logout({ isReset: false });
|
|
20457
|
+
} else {
|
|
20458
|
+
await this.config.reset("reset");
|
|
20329
20459
|
}
|
|
20330
|
-
await this.
|
|
20331
|
-
await this.socket.reset({ focus });
|
|
20332
|
-
}
|
|
20333
|
-
/**
|
|
20334
|
-
* reset callkit
|
|
20335
|
-
* @description recover the callkit to the initial state
|
|
20336
|
-
*/
|
|
20337
|
-
async reset() {
|
|
20338
|
-
await this._reset({ focus: true });
|
|
20460
|
+
await this.socket.reset({ force });
|
|
20339
20461
|
}
|
|
20340
20462
|
on(event, callback) {
|
|
20341
20463
|
this.listener.push({
|
|
@@ -20371,7 +20493,9 @@ var WebCall = (() => {
|
|
|
20371
20493
|
if (!noLog) {
|
|
20372
20494
|
this.logger.info(`Trigger Event: ${event}`, {
|
|
20373
20495
|
caller: "CallKit.trigger",
|
|
20374
|
-
content:
|
|
20496
|
+
content: {
|
|
20497
|
+
data
|
|
20498
|
+
}
|
|
20375
20499
|
});
|
|
20376
20500
|
}
|
|
20377
20501
|
this.listener.forEach((item) => {
|
|
@@ -20379,7 +20503,7 @@ var WebCall = (() => {
|
|
|
20379
20503
|
try {
|
|
20380
20504
|
item.callback(data);
|
|
20381
20505
|
} catch (err) {
|
|
20382
|
-
this.logger.error(
|
|
20506
|
+
this.logger.error(`Event callback error: ${event}`, err, true);
|
|
20383
20507
|
}
|
|
20384
20508
|
}
|
|
20385
20509
|
});
|