@koi-design/callkit 1.0.26-beta.1 → 1.0.26
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 +56 -35
- package/dist/index.global.js +1005 -349
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +726 -324
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +733 -325
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import md5 from "blueimp-md5";
|
|
|
3
3
|
|
|
4
4
|
// package/axios.ts
|
|
5
5
|
import axios from "axios";
|
|
6
|
+
import axiosRetry from "axios-retry";
|
|
6
7
|
var instance = axios.create({
|
|
7
8
|
headers: {
|
|
8
9
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -13,85 +14,26 @@ instance.interceptors.response.use(
|
|
|
13
14
|
(response) => response.data,
|
|
14
15
|
(error) => Promise.reject(error)
|
|
15
16
|
);
|
|
17
|
+
axiosRetry(instance, {
|
|
18
|
+
retries: 3,
|
|
19
|
+
// Maximum number of retries, default is 3
|
|
20
|
+
retryDelay: (retryCount, error) => {
|
|
21
|
+
console.log(
|
|
22
|
+
`AJAX Retrying attempt ${retryCount}, error: ${error?.message}`
|
|
23
|
+
);
|
|
24
|
+
return retryCount * 1e3;
|
|
25
|
+
},
|
|
26
|
+
retryCondition: (error) => {
|
|
27
|
+
if (!error.response)
|
|
28
|
+
return true;
|
|
29
|
+
return error.response.status < 200 || error.response.status >= 300;
|
|
30
|
+
},
|
|
31
|
+
shouldResetTimeout: true
|
|
32
|
+
// Whether to reset axios timeout on retry
|
|
33
|
+
});
|
|
16
34
|
var request = (config) => instance.request(config);
|
|
17
35
|
var axios_default = request;
|
|
18
36
|
|
|
19
|
-
// package/api.ts
|
|
20
|
-
var Api = class {
|
|
21
|
-
callKit;
|
|
22
|
-
constructor(callKit) {
|
|
23
|
-
this.callKit = callKit;
|
|
24
|
-
}
|
|
25
|
-
async login(params) {
|
|
26
|
-
return this.post({
|
|
27
|
-
url: "/auth/agentUser/login",
|
|
28
|
-
method: "post",
|
|
29
|
-
data: params
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
async loginOut(params) {
|
|
33
|
-
return this.post({
|
|
34
|
-
url: "/auth/agentUser/loginOut",
|
|
35
|
-
method: "post",
|
|
36
|
-
data: params
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param params agentId userStatus
|
|
42
|
-
* @description userStatus: Logout(1, "unregistered"), Free(2, "free"), Break(3, "nap"), Busy(4, "busy")
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
async setUserStatus(params) {
|
|
46
|
-
return this.post({
|
|
47
|
-
url: "/agent/user/changeStatus",
|
|
48
|
-
method: "post",
|
|
49
|
-
data: params
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async measureRTT(config) {
|
|
53
|
-
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
54
|
-
return axios_default(config);
|
|
55
|
-
}
|
|
56
|
-
async post(config) {
|
|
57
|
-
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
58
|
-
const { userInfo, host } = this.callKit.config.getConfig();
|
|
59
|
-
const { sessionId } = userInfo;
|
|
60
|
-
config.url = `${host}${config.url}`;
|
|
61
|
-
config.headers = {
|
|
62
|
-
...config.headers,
|
|
63
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
64
|
-
};
|
|
65
|
-
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
66
|
-
config.data = new URLSearchParams(config.data).toString();
|
|
67
|
-
}
|
|
68
|
-
if (sessionId) {
|
|
69
|
-
config.headers.sessionId = sessionId;
|
|
70
|
-
}
|
|
71
|
-
const res = await axios_default(config).catch(() => {
|
|
72
|
-
this.callKit.config.reset();
|
|
73
|
-
});
|
|
74
|
-
if (!res) {
|
|
75
|
-
this.callKit.config.reset();
|
|
76
|
-
throw new Error("Network error");
|
|
77
|
-
}
|
|
78
|
-
const { code, data, message } = res;
|
|
79
|
-
if (code === "000000") {
|
|
80
|
-
return data;
|
|
81
|
-
}
|
|
82
|
-
if (code === "100013") {
|
|
83
|
-
this.callKit.config.reset();
|
|
84
|
-
}
|
|
85
|
-
throw new Error(message ?? "Request failed");
|
|
86
|
-
}
|
|
87
|
-
async get(config) {
|
|
88
|
-
return this.post({
|
|
89
|
-
...config,
|
|
90
|
-
method: "get"
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
37
|
// package/const.ts
|
|
96
38
|
var UserStatus = {
|
|
97
39
|
/**
|
|
@@ -178,6 +120,10 @@ var KitEvent = {
|
|
|
178
120
|
* Server initiated call
|
|
179
121
|
*/
|
|
180
122
|
KIT_INVITE: "invite",
|
|
123
|
+
/**
|
|
124
|
+
* Server outgoing initiated call
|
|
125
|
+
*/
|
|
126
|
+
KIT_OUTGOING_INVITE: "outgoingInvite",
|
|
181
127
|
// /**
|
|
182
128
|
// * Referral
|
|
183
129
|
// */
|
|
@@ -222,14 +168,10 @@ var KitEvent = {
|
|
|
222
168
|
* User status change
|
|
223
169
|
*/
|
|
224
170
|
USER_STATUS_CHANGE: "userStatusChange",
|
|
225
|
-
/**
|
|
226
|
-
* SOCKET CONNECT EVENT
|
|
227
|
-
*/
|
|
228
171
|
CONNECT_EVENT: "CONNECT_EVENT",
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
NETWORK_EVENT: "NETWORK_EVENT"
|
|
172
|
+
SIP_REGISTERER_EVENT: "sipRegistererEvent",
|
|
173
|
+
SIP_SESSION_EVENT: "sipSessionEvent",
|
|
174
|
+
USER_STATUS_CHANGE_STEP: "userStatusChangeStep"
|
|
233
175
|
};
|
|
234
176
|
var ErrorCode = {
|
|
235
177
|
/**
|
|
@@ -364,7 +306,9 @@ var SocketSendEvent = {
|
|
|
364
306
|
/**
|
|
365
307
|
* AGENT_TRANSFER
|
|
366
308
|
*/
|
|
367
|
-
HANG_UP_REASON: "HANG_UP_REASON"
|
|
309
|
+
HANG_UP_REASON: "HANG_UP_REASON",
|
|
310
|
+
ACK: "ACK",
|
|
311
|
+
SDK_LOG: "SDK_LOG"
|
|
368
312
|
};
|
|
369
313
|
var SocketReceiveEvent = {
|
|
370
314
|
/**
|
|
@@ -428,6 +372,10 @@ var EncryptionMethod = {
|
|
|
428
372
|
NONE: "NONE",
|
|
429
373
|
INTERNAL: "INTERNAL"
|
|
430
374
|
};
|
|
375
|
+
var LogGatherEnum = {
|
|
376
|
+
ENABLE: 1,
|
|
377
|
+
DISABLE: 2
|
|
378
|
+
};
|
|
431
379
|
var constrainsDefault = {
|
|
432
380
|
audio: {
|
|
433
381
|
autoGainControl: true,
|
|
@@ -445,19 +393,330 @@ var CallSourceType = {
|
|
|
445
393
|
};
|
|
446
394
|
var ConnectEvent = {
|
|
447
395
|
SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
|
|
396
|
+
SIP_RECONNECT_START: "SIP_RECONNECT_START",
|
|
448
397
|
SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
|
|
449
398
|
SIP_RECONNECT_SUCCESS: "SIP_RECONNECT_SUCCESS",
|
|
399
|
+
SIP_RECONNECTING: "SIP_RECONNECTING",
|
|
400
|
+
INCALL_NOT_CONNECTED: "INCALL_NOT_CONNECTED",
|
|
450
401
|
INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
|
|
402
|
+
INCALL_RECONNECT_START: "INCALL_RECONNECT_START",
|
|
451
403
|
INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR",
|
|
452
404
|
INCALL_RECONNECT_SUCCESS: "INCALL_RECONNECT_SUCCESS",
|
|
405
|
+
INCALL_RECONNECTING: "INCALL_RECONNECTING",
|
|
453
406
|
OPTIONS_HEARTBEAT_EXPIRED: "OPTIONS_HEARTBEAT_EXPIRED",
|
|
454
|
-
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
455
|
-
|
|
456
|
-
|
|
407
|
+
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
408
|
+
};
|
|
409
|
+
var SipRegistererEvent = {
|
|
410
|
+
Initial: "Initial",
|
|
411
|
+
Registered: "Registered",
|
|
412
|
+
Unregistered: "Unregistered",
|
|
413
|
+
Terminated: "Terminated"
|
|
414
|
+
};
|
|
415
|
+
var SipSessionEvent = {
|
|
416
|
+
Establishing: "Establishing",
|
|
417
|
+
Established: "Established",
|
|
418
|
+
Terminating: "Terminating",
|
|
419
|
+
Terminated: "Terminated"
|
|
420
|
+
};
|
|
421
|
+
var UserStatusChangeStepEnum = {
|
|
422
|
+
UserStatusChangeStart: "UserStatusChangeStart",
|
|
423
|
+
UserStatusChangeEnd: "UserStatusChangeEnd",
|
|
424
|
+
UserStatusChangeError: "UserStatusChangeError",
|
|
425
|
+
// login
|
|
426
|
+
UserStatusChangeLoginStart: "UserStatusChangeLoginStart",
|
|
427
|
+
UserStatusChangeLoginEnd: "UserStatusChangeLoginEnd",
|
|
428
|
+
UserStatusChangeLoginError: "UserStatusChangeLoginError",
|
|
429
|
+
// logout
|
|
430
|
+
UserStatusChangeLoginOutStart: "UserStatusChangeLoginOutStart",
|
|
431
|
+
UserStatusChangeLoginOutEnd: "UserStatusChangeLoginOutEnd",
|
|
432
|
+
UserStatusChangeLoginOutError: "UserStatusChangeLoginOutError"
|
|
433
|
+
};
|
|
434
|
+
var LogDataEnum = {
|
|
435
|
+
SIP: "sip",
|
|
436
|
+
INCALL: "incall",
|
|
437
|
+
AJAX: "ajax",
|
|
438
|
+
ERROR: "error",
|
|
439
|
+
RECONNECT: "reconnect",
|
|
440
|
+
ALL: "all"
|
|
457
441
|
};
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
442
|
+
|
|
443
|
+
// package/logger.ts
|
|
444
|
+
import stringify from "json-stringify-safe";
|
|
445
|
+
function getLevel(level) {
|
|
446
|
+
return LoggerLevelMap[level];
|
|
447
|
+
}
|
|
448
|
+
var Logger = class {
|
|
449
|
+
prefix = "CallKit";
|
|
450
|
+
level = "debug";
|
|
451
|
+
logData = {
|
|
452
|
+
sip: [],
|
|
453
|
+
incall: [],
|
|
454
|
+
ajax: [],
|
|
455
|
+
error: [],
|
|
456
|
+
reconnect: [],
|
|
457
|
+
all: []
|
|
458
|
+
};
|
|
459
|
+
sendSdkLogData = [];
|
|
460
|
+
callKit;
|
|
461
|
+
constructor(callKit, level) {
|
|
462
|
+
this.callKit = callKit;
|
|
463
|
+
this.level = level || "debug";
|
|
464
|
+
this.logData = {
|
|
465
|
+
sip: [],
|
|
466
|
+
incall: [],
|
|
467
|
+
ajax: [],
|
|
468
|
+
error: [],
|
|
469
|
+
reconnect: [],
|
|
470
|
+
all: []
|
|
471
|
+
};
|
|
472
|
+
this.sendSdkLogData = [];
|
|
473
|
+
}
|
|
474
|
+
static formatStrLog(logObj) {
|
|
475
|
+
const {
|
|
476
|
+
type = "info"
|
|
477
|
+
// 默认等级
|
|
478
|
+
} = logObj;
|
|
479
|
+
const time = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
480
|
+
const level = String(type).toUpperCase().padEnd(5, " ");
|
|
481
|
+
const tagStr = logObj.typeag ? `[${logObj.type}]` : "";
|
|
482
|
+
const msg = JSON.stringify(logObj);
|
|
483
|
+
return `${time} [${level}] ${tagStr} ${msg}`.trim();
|
|
484
|
+
}
|
|
485
|
+
setLevel(level) {
|
|
486
|
+
this.level = level;
|
|
487
|
+
}
|
|
488
|
+
debug(msg, extra) {
|
|
489
|
+
if (getLevel(this.level) >= getLevel("debug")) {
|
|
490
|
+
this.output("blue")(msg, extra);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
log(msg, extra) {
|
|
494
|
+
if (getLevel(this.level) >= getLevel("log")) {
|
|
495
|
+
this.output("green")(msg, extra);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
warn(msg, extra) {
|
|
499
|
+
if (getLevel(this.level) >= getLevel("warn")) {
|
|
500
|
+
this.output("orange")(msg, extra);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
error(msg, extra) {
|
|
504
|
+
const message = msg?.message ?? msg;
|
|
505
|
+
if (getLevel(this.level) >= getLevel("error")) {
|
|
506
|
+
this.output("red")(message, extra);
|
|
507
|
+
}
|
|
508
|
+
const { errCode, ...rest } = extra;
|
|
509
|
+
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
510
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
511
|
+
code: errorCode,
|
|
512
|
+
msg: message,
|
|
513
|
+
data: rest
|
|
514
|
+
});
|
|
515
|
+
this.callKit.reset();
|
|
516
|
+
const error = new Error(message);
|
|
517
|
+
error.name = "CallKitError";
|
|
518
|
+
error.code = errorCode;
|
|
519
|
+
error.data = rest;
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
addLogData(type, data = {}) {
|
|
523
|
+
this.callKit.user.sendSdkLog({
|
|
524
|
+
...data,
|
|
525
|
+
type,
|
|
526
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
527
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
528
|
+
});
|
|
529
|
+
if (!this.callKit.config.isLogGatherEnable()) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
let logData = {
|
|
533
|
+
type,
|
|
534
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
535
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
536
|
+
data: ""
|
|
537
|
+
};
|
|
538
|
+
if (type === LogDataEnum.INCALL) {
|
|
539
|
+
logData.data = stringify({
|
|
540
|
+
// customField
|
|
541
|
+
callKitSocketFrom: data?.callKitSocketFrom,
|
|
542
|
+
type: data?.ev.type || data?.type,
|
|
543
|
+
data: data?.ev.data || data?.data,
|
|
544
|
+
// message
|
|
545
|
+
origin: data?.ev.origin || data?.origin,
|
|
546
|
+
lastEventId: data?.ev.lastEventId || data?.lastEventId,
|
|
547
|
+
isTrusted: data?.ev.isTrusted || data?.isTrusted,
|
|
548
|
+
// close
|
|
549
|
+
code: data?.ev.code || data?.code,
|
|
550
|
+
reason: data?.ev.reason || data?.reason,
|
|
551
|
+
wasClean: data?.ev.wasClean || data?.wasClean
|
|
552
|
+
});
|
|
553
|
+
} else {
|
|
554
|
+
logData = stringify(data);
|
|
555
|
+
}
|
|
556
|
+
switch (type) {
|
|
557
|
+
case LogDataEnum.SIP:
|
|
558
|
+
this.logData.sip.push(logData);
|
|
559
|
+
this.logData.all.push(logData);
|
|
560
|
+
break;
|
|
561
|
+
case LogDataEnum.INCALL:
|
|
562
|
+
this.logData.incall.push(logData);
|
|
563
|
+
this.logData.all.push(logData);
|
|
564
|
+
break;
|
|
565
|
+
case LogDataEnum.AJAX:
|
|
566
|
+
this.logData.ajax.push(logData);
|
|
567
|
+
this.logData.all.push(logData);
|
|
568
|
+
break;
|
|
569
|
+
case LogDataEnum.RECONNECT:
|
|
570
|
+
this.logData.reconnect.push(logData);
|
|
571
|
+
this.logData.all.push(logData);
|
|
572
|
+
break;
|
|
573
|
+
case LogDataEnum.ERROR:
|
|
574
|
+
this.logData.error.push(logData);
|
|
575
|
+
this.logData.all.push(logData);
|
|
576
|
+
break;
|
|
577
|
+
default:
|
|
578
|
+
this.logData.all.push(logData);
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
output(color) {
|
|
583
|
+
return (msg, extra = {}) => {
|
|
584
|
+
const now = /* @__PURE__ */ new Date();
|
|
585
|
+
if (Object.keys(extra).length > 0) {
|
|
586
|
+
console.log(
|
|
587
|
+
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
588
|
+
`color: ${color};`,
|
|
589
|
+
"color:block;",
|
|
590
|
+
extra,
|
|
591
|
+
"color:#999;"
|
|
592
|
+
);
|
|
593
|
+
} else {
|
|
594
|
+
console.log(
|
|
595
|
+
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
596
|
+
`color: ${color};`,
|
|
597
|
+
"color:block;",
|
|
598
|
+
"color:#999;"
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// package/api.ts
|
|
606
|
+
var Api = class {
|
|
607
|
+
callKit;
|
|
608
|
+
constructor(callKit) {
|
|
609
|
+
this.callKit = callKit;
|
|
610
|
+
}
|
|
611
|
+
async login(params) {
|
|
612
|
+
return this.post({
|
|
613
|
+
url: "/auth/agentUser/login",
|
|
614
|
+
method: "post",
|
|
615
|
+
data: params
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
async loginOut(params) {
|
|
619
|
+
return this.post({
|
|
620
|
+
url: "/auth/agentUser/loginOut",
|
|
621
|
+
method: "post",
|
|
622
|
+
data: params
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* @description sdkLog
|
|
627
|
+
* @param params
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
async sdkLog(data) {
|
|
631
|
+
const strLog = Logger.formatStrLog(data);
|
|
632
|
+
const allData = [this.callKit.logger.sendSdkLogData, strLog].join(",");
|
|
633
|
+
const encoder = new TextEncoder();
|
|
634
|
+
const size = encoder.encode(allData).length;
|
|
635
|
+
if (size < 8192) {
|
|
636
|
+
this.callKit.logger.sendSdkLogData.push(strLog);
|
|
637
|
+
} else {
|
|
638
|
+
const logsToSend = this.callKit.logger.sendSdkLogData.slice();
|
|
639
|
+
this.callKit.logger.sendSdkLogData = [strLog];
|
|
640
|
+
return this.post(
|
|
641
|
+
{
|
|
642
|
+
url: "/agent/user/sdkLog",
|
|
643
|
+
method: "post",
|
|
644
|
+
data: {
|
|
645
|
+
content: logsToSend
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
useFormData: true
|
|
650
|
+
}
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
*
|
|
656
|
+
* @param params agentId userStatus
|
|
657
|
+
* @description userStatus: Logout(1, "unregistered"), Free(2, "free"), Break(3, "nap"), Busy(4, "busy")
|
|
658
|
+
* @returns
|
|
659
|
+
*/
|
|
660
|
+
async setUserStatus(params) {
|
|
661
|
+
return this.post({
|
|
662
|
+
url: "/agent/user/changeStatus",
|
|
663
|
+
method: "post",
|
|
664
|
+
data: params
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
async post(config, extra = {}) {
|
|
668
|
+
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
669
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
670
|
+
const { sessionId } = userInfo;
|
|
671
|
+
config.url = `${host}${config.url}`;
|
|
672
|
+
config.headers = {
|
|
673
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
674
|
+
...config.headers
|
|
675
|
+
};
|
|
676
|
+
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded" && extra.useFormData) {
|
|
677
|
+
const formData = new FormData();
|
|
678
|
+
const data2 = config.data || {};
|
|
679
|
+
for (const key in data2) {
|
|
680
|
+
if (Object.prototype.hasOwnProperty.call(data2, key)) {
|
|
681
|
+
formData.append(key, data2[key]);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
config.data = formData;
|
|
685
|
+
} else {
|
|
686
|
+
config.data = new URLSearchParams(config.data).toString();
|
|
687
|
+
}
|
|
688
|
+
if (sessionId) {
|
|
689
|
+
config.headers.sessionId = sessionId;
|
|
690
|
+
}
|
|
691
|
+
const res = await axios_default(config).catch(() => {
|
|
692
|
+
this.callKit.config.reset();
|
|
693
|
+
});
|
|
694
|
+
if (!res) {
|
|
695
|
+
this.callKit.config.reset();
|
|
696
|
+
throw new Error("Network error");
|
|
697
|
+
} else {
|
|
698
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
699
|
+
...config,
|
|
700
|
+
status: "success",
|
|
701
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
702
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
const { code, data, message } = res;
|
|
706
|
+
if (code === "000000") {
|
|
707
|
+
return data;
|
|
708
|
+
}
|
|
709
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
710
|
+
...config,
|
|
711
|
+
status: "error",
|
|
712
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
713
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
714
|
+
});
|
|
715
|
+
if (code === "100013") {
|
|
716
|
+
this.callKit.config.reset();
|
|
717
|
+
}
|
|
718
|
+
throw new Error(message ?? "Request failed");
|
|
719
|
+
}
|
|
461
720
|
};
|
|
462
721
|
|
|
463
722
|
// package/call.ts
|
|
@@ -501,12 +760,6 @@ var Call = class {
|
|
|
501
760
|
if (!this.callKit.config.check())
|
|
502
761
|
return;
|
|
503
762
|
this.callKit.logger.debug("callRefer");
|
|
504
|
-
const { toAgentId, workOrderId } = options;
|
|
505
|
-
const queryTrain = {
|
|
506
|
-
toAgentId,
|
|
507
|
-
workOrderId
|
|
508
|
-
};
|
|
509
|
-
this.callKit.socket.send(SocketSendEvent.AGENT_TRANSFER, queryTrain);
|
|
510
763
|
this.callKit.connect.refer(referTo, options);
|
|
511
764
|
}
|
|
512
765
|
/**
|
|
@@ -553,7 +806,7 @@ var Config = class {
|
|
|
553
806
|
this.callKit = callKit;
|
|
554
807
|
}
|
|
555
808
|
config = {
|
|
556
|
-
version: "1.0.
|
|
809
|
+
version: "1.0.24-beta.30",
|
|
557
810
|
host: "",
|
|
558
811
|
log: "debug",
|
|
559
812
|
audioRef: void 0,
|
|
@@ -579,7 +832,8 @@ var Config = class {
|
|
|
579
832
|
fsPort: "",
|
|
580
833
|
iceInfo: [],
|
|
581
834
|
iceGatheringTimeout: 0,
|
|
582
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
835
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
836
|
+
logGather: LogGatherEnum.DISABLE
|
|
583
837
|
},
|
|
584
838
|
// EXECUTE setUserStatus
|
|
585
839
|
isAutoUpdateUserStatus: true
|
|
@@ -611,7 +865,8 @@ var Config = class {
|
|
|
611
865
|
fsPort: "",
|
|
612
866
|
iceInfo: [],
|
|
613
867
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
614
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
868
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
869
|
+
logGather: LogGatherEnum.DISABLE
|
|
615
870
|
};
|
|
616
871
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
617
872
|
}
|
|
@@ -624,6 +879,7 @@ var Config = class {
|
|
|
624
879
|
return true;
|
|
625
880
|
};
|
|
626
881
|
isLogin = () => this.validate();
|
|
882
|
+
isLogGatherEnable = () => this.config.userInfo.logGather === LogGatherEnum.ENABLE;
|
|
627
883
|
check() {
|
|
628
884
|
if (!this.isLogin()) {
|
|
629
885
|
this.callKit.logger.error("User not logged in", {
|
|
@@ -635,80 +891,14 @@ var Config = class {
|
|
|
635
891
|
}
|
|
636
892
|
};
|
|
637
893
|
|
|
638
|
-
// package/logger.ts
|
|
639
|
-
function getLevel(level) {
|
|
640
|
-
return LoggerLevelMap[level];
|
|
641
|
-
}
|
|
642
|
-
var Logger = class {
|
|
643
|
-
prefix = "CallKit";
|
|
644
|
-
level = "debug";
|
|
645
|
-
callKit;
|
|
646
|
-
constructor(callKit, level) {
|
|
647
|
-
this.callKit = callKit;
|
|
648
|
-
this.level = level || "debug";
|
|
649
|
-
}
|
|
650
|
-
setLevel(level) {
|
|
651
|
-
this.level = level;
|
|
652
|
-
}
|
|
653
|
-
debug(msg, extra) {
|
|
654
|
-
if (getLevel(this.level) >= getLevel("debug")) {
|
|
655
|
-
this.output("blue")(msg, extra);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
log(msg, extra) {
|
|
659
|
-
if (getLevel(this.level) >= getLevel("log")) {
|
|
660
|
-
this.output("green")(msg, extra);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
warn(msg, extra) {
|
|
664
|
-
if (getLevel(this.level) >= getLevel("warn")) {
|
|
665
|
-
this.output("orange")(msg, extra);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
error(msg, extra) {
|
|
669
|
-
const message = msg?.message ?? msg;
|
|
670
|
-
if (getLevel(this.level) >= getLevel("error")) {
|
|
671
|
-
this.output("red")(message, extra);
|
|
672
|
-
}
|
|
673
|
-
const { errCode, ...rest } = extra;
|
|
674
|
-
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
675
|
-
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
676
|
-
code: errorCode,
|
|
677
|
-
msg: message,
|
|
678
|
-
data: rest
|
|
679
|
-
});
|
|
680
|
-
this.callKit.reset();
|
|
681
|
-
const error = new Error(message);
|
|
682
|
-
error.name = "CallKitError";
|
|
683
|
-
error.code = errorCode;
|
|
684
|
-
error.data = rest;
|
|
685
|
-
throw error;
|
|
686
|
-
}
|
|
687
|
-
output(color) {
|
|
688
|
-
return (msg, extra = {}) => {
|
|
689
|
-
const now = /* @__PURE__ */ new Date();
|
|
690
|
-
if (Object.keys(extra).length > 0) {
|
|
691
|
-
console.log(
|
|
692
|
-
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
693
|
-
`color: ${color};`,
|
|
694
|
-
"color:block;",
|
|
695
|
-
extra,
|
|
696
|
-
"color:#999;"
|
|
697
|
-
);
|
|
698
|
-
} else {
|
|
699
|
-
console.log(
|
|
700
|
-
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
701
|
-
`color: ${color};`,
|
|
702
|
-
"color:block;",
|
|
703
|
-
"color:#999;"
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
|
|
710
894
|
// package/connect.ts
|
|
711
|
-
import {
|
|
895
|
+
import {
|
|
896
|
+
UserAgent,
|
|
897
|
+
Web,
|
|
898
|
+
Registerer,
|
|
899
|
+
SessionState,
|
|
900
|
+
RegistererState
|
|
901
|
+
} from "sip.js";
|
|
712
902
|
var DEFAULT_RECONNECT_CONFIG = {
|
|
713
903
|
maxAttempts: 3,
|
|
714
904
|
delay: 500
|
|
@@ -730,7 +920,9 @@ var initUserMedia = () => {
|
|
|
730
920
|
const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
|
731
921
|
if (!getUserMedia) {
|
|
732
922
|
return Promise.reject(
|
|
733
|
-
new Error(
|
|
923
|
+
new Error(
|
|
924
|
+
"Unable to obtain device permissions. Please check your browser settings or device permissions."
|
|
925
|
+
)
|
|
734
926
|
);
|
|
735
927
|
}
|
|
736
928
|
return new Promise((resolve, reject) => {
|
|
@@ -751,7 +943,7 @@ var Connect = class {
|
|
|
751
943
|
registerer;
|
|
752
944
|
lastOptionsUpdateTime = 0;
|
|
753
945
|
observeOptionsHeartbeatHandler = null;
|
|
754
|
-
sipConnected = false;
|
|
946
|
+
// sipConnected = false;
|
|
755
947
|
/**
|
|
756
948
|
* Whether it's an outgoing call
|
|
757
949
|
*/
|
|
@@ -760,6 +952,7 @@ var Connect = class {
|
|
|
760
952
|
* Whether it's an active hangup
|
|
761
953
|
*/
|
|
762
954
|
isUnprompted = false;
|
|
955
|
+
isCurrentSessionInvited = false;
|
|
763
956
|
reconnectConfig;
|
|
764
957
|
/**
|
|
765
958
|
* Whether registered
|
|
@@ -799,7 +992,6 @@ var Connect = class {
|
|
|
799
992
|
this.registerer = void 0;
|
|
800
993
|
this.isOutgoing = false;
|
|
801
994
|
this.isUnprompted = false;
|
|
802
|
-
this.sipConnected = false;
|
|
803
995
|
this.clearObserveOptionsHeartbeatInterval();
|
|
804
996
|
if (this.isHold) {
|
|
805
997
|
this.setHoldStatus(false);
|
|
@@ -813,7 +1005,7 @@ var Connect = class {
|
|
|
813
1005
|
return audioRef;
|
|
814
1006
|
}
|
|
815
1007
|
async permission() {
|
|
816
|
-
this.callKit.logger.debug("
|
|
1008
|
+
this.callKit.logger.debug("ssion");
|
|
817
1009
|
initUserMedia();
|
|
818
1010
|
const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
819
1011
|
closeStream(_stream);
|
|
@@ -860,6 +1052,9 @@ var Connect = class {
|
|
|
860
1052
|
isInit() {
|
|
861
1053
|
return this.connectStatus === CallStatus.init;
|
|
862
1054
|
}
|
|
1055
|
+
isExecuting() {
|
|
1056
|
+
return this.callKit.user.getUserChangeStatusExecuting();
|
|
1057
|
+
}
|
|
863
1058
|
clearObserveOptionsHeartbeatInterval() {
|
|
864
1059
|
if (this.observeOptionsHeartbeatHandler !== null) {
|
|
865
1060
|
clearInterval(this.observeOptionsHeartbeatHandler);
|
|
@@ -939,13 +1134,18 @@ var Connect = class {
|
|
|
939
1134
|
that.userAgent.transport.onDisconnect = (error) => {
|
|
940
1135
|
if (error) {
|
|
941
1136
|
that.callKit.logger.debug("connect onDisconnect");
|
|
942
|
-
if (that.isRegistered() &&
|
|
1137
|
+
if (that.isRegistered() && !// that.sipConnected ||
|
|
1138
|
+
(that.isRinging() || that.isCalling() || that.isHolding())) {
|
|
943
1139
|
that.reconnect();
|
|
944
1140
|
} else {
|
|
945
1141
|
that.callKit.logger.debug("SIP WebSocket closed with error", {
|
|
946
1142
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
947
1143
|
err: error
|
|
948
1144
|
});
|
|
1145
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1146
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1147
|
+
err: error
|
|
1148
|
+
});
|
|
949
1149
|
that.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
950
1150
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
951
1151
|
err: error
|
|
@@ -961,7 +1161,7 @@ var Connect = class {
|
|
|
961
1161
|
}
|
|
962
1162
|
};
|
|
963
1163
|
that.clearObserveOptionsHeartbeatInterval();
|
|
964
|
-
setInterval(() => {
|
|
1164
|
+
that.observeOptionsHeartbeatHandler = setInterval(() => {
|
|
965
1165
|
if (that.lastOptionsUpdateTime !== 0) {
|
|
966
1166
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
967
1167
|
const diff = now - that.lastOptionsUpdateTime;
|
|
@@ -976,6 +1176,11 @@ var Connect = class {
|
|
|
976
1176
|
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
977
1177
|
now
|
|
978
1178
|
});
|
|
1179
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1180
|
+
event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
1181
|
+
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1182
|
+
now
|
|
1183
|
+
});
|
|
979
1184
|
that.clearObserveOptionsHeartbeatInterval();
|
|
980
1185
|
}
|
|
981
1186
|
}
|
|
@@ -987,38 +1192,118 @@ var Connect = class {
|
|
|
987
1192
|
if (request2.method === "OPTIONS") {
|
|
988
1193
|
that.lastOptionsUpdateTime = (/* @__PURE__ */ new Date()).getTime();
|
|
989
1194
|
}
|
|
1195
|
+
that.callKit.logger.addLogData(LogDataEnum.SIP, request2);
|
|
990
1196
|
return originalReceiveRequest(request2);
|
|
991
1197
|
};
|
|
992
1198
|
};
|
|
993
1199
|
const registererOptions = {};
|
|
994
1200
|
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
1201
|
+
this.registerer.stateChange.addListener((state) => {
|
|
1202
|
+
switch (state) {
|
|
1203
|
+
case RegistererState.Initial:
|
|
1204
|
+
this.callKit.logger.debug("registerer stateChange Initial");
|
|
1205
|
+
this.setRegister(false);
|
|
1206
|
+
this.setConnectStatus(CallStatus.init);
|
|
1207
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1208
|
+
this.callKit.trigger(
|
|
1209
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1210
|
+
SipRegistererEvent.Initial
|
|
1211
|
+
);
|
|
1212
|
+
break;
|
|
1213
|
+
case RegistererState.Registered:
|
|
1214
|
+
this.callKit.logger.debug("registerer stateChange Registered");
|
|
1215
|
+
this.setRegister(true);
|
|
1216
|
+
this.setConnectStatus(CallStatus.registered);
|
|
1217
|
+
this.callKit.user.setUserStatus(UserStatus.online);
|
|
1218
|
+
this.callKit.trigger(
|
|
1219
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1220
|
+
SipRegistererEvent.Registered
|
|
1221
|
+
);
|
|
1222
|
+
break;
|
|
1223
|
+
case RegistererState.Terminated:
|
|
1224
|
+
this.callKit.logger.debug("registerer stateChange Terminated");
|
|
1225
|
+
this.setRegister(false);
|
|
1226
|
+
this.setConnectStatus(CallStatus.init);
|
|
1227
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1228
|
+
this.callKit.trigger(
|
|
1229
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1230
|
+
SipRegistererEvent.Terminated
|
|
1231
|
+
);
|
|
1232
|
+
break;
|
|
1233
|
+
case RegistererState.Unregistered:
|
|
1234
|
+
this.callKit.logger.debug("registerer stateChange Unregistered");
|
|
1235
|
+
this.setRegister(false);
|
|
1236
|
+
this.setConnectStatus(CallStatus.init);
|
|
1237
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1238
|
+
this.callKit.trigger(
|
|
1239
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1240
|
+
SipRegistererEvent.Unregistered
|
|
1241
|
+
);
|
|
1242
|
+
break;
|
|
1243
|
+
default:
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
995
1247
|
this.userAgent.delegate = {
|
|
996
1248
|
onInvite: (invite) => {
|
|
997
1249
|
this.callKit.logger.debug("connect onInvite");
|
|
998
1250
|
this.currentSession = invite;
|
|
1251
|
+
if (this.isOutgoing) {
|
|
1252
|
+
this.isCurrentSessionInvited = false;
|
|
1253
|
+
}
|
|
999
1254
|
this.currentSession.stateChange.addListener((state) => {
|
|
1255
|
+
const isExecuting = this.isExecuting();
|
|
1000
1256
|
switch (state) {
|
|
1001
1257
|
case SessionState.Establishing:
|
|
1002
1258
|
this.callKit.logger.debug("connect Establishing");
|
|
1259
|
+
this.setConnectStatus(CallStatus.ringing);
|
|
1260
|
+
if (!isExecuting) {
|
|
1261
|
+
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
1262
|
+
this.callKit.trigger(
|
|
1263
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1264
|
+
SipSessionEvent.Establishing
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1003
1267
|
break;
|
|
1004
1268
|
case SessionState.Established:
|
|
1005
1269
|
this.callKit.logger.debug("connect Established");
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1270
|
+
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
1271
|
+
if (!isExecuting) {
|
|
1272
|
+
this.callKit.trigger(
|
|
1273
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1274
|
+
SipSessionEvent.Established
|
|
1275
|
+
);
|
|
1276
|
+
setupRemoteMedia(this.currentSession);
|
|
1009
1277
|
}
|
|
1010
|
-
this.sipConnected = true;
|
|
1011
|
-
setupRemoteMedia(this.currentSession);
|
|
1012
1278
|
break;
|
|
1013
1279
|
case SessionState.Terminating:
|
|
1014
1280
|
this.callKit.logger.debug("connect Terminating");
|
|
1281
|
+
if (!isExecuting) {
|
|
1282
|
+
this.callKit.trigger(
|
|
1283
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1284
|
+
SipSessionEvent.Terminating
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1015
1287
|
break;
|
|
1016
1288
|
case SessionState.Terminated:
|
|
1017
1289
|
this.callKit.logger.debug("connect Terminated");
|
|
1018
1290
|
if (!this.isUnprompted) {
|
|
1019
1291
|
this.callKit.callCenter.callEnd();
|
|
1292
|
+
} else if (this.isCalling()) {
|
|
1293
|
+
if (this.isCurrentSessionInvited) {
|
|
1294
|
+
this.currentSession.reject();
|
|
1295
|
+
}
|
|
1296
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
1020
1297
|
}
|
|
1021
1298
|
this.isUnprompted = false;
|
|
1299
|
+
if (!isExecuting) {
|
|
1300
|
+
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1301
|
+
this.setConnectStatus(CallStatus.registered);
|
|
1302
|
+
this.callKit.trigger(
|
|
1303
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1304
|
+
SipSessionEvent.Terminated
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1022
1307
|
break;
|
|
1023
1308
|
default:
|
|
1024
1309
|
break;
|
|
@@ -1032,17 +1317,37 @@ var Connect = class {
|
|
|
1032
1317
|
};
|
|
1033
1318
|
if (this.isOutgoing) {
|
|
1034
1319
|
this.currentSession.accept(options);
|
|
1320
|
+
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
1321
|
+
getInviteData: () => {
|
|
1322
|
+
const { request: request2 } = this.currentSession;
|
|
1323
|
+
const headerNames = Object.keys(request2.headers);
|
|
1324
|
+
const xHeaders = {};
|
|
1325
|
+
headerNames.filter(
|
|
1326
|
+
(name) => name.toLocaleLowerCase().startsWith("x-antaios")
|
|
1327
|
+
).forEach((name) => {
|
|
1328
|
+
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
1329
|
+
});
|
|
1330
|
+
this.callKit.logger.debug("get invite data", xHeaders);
|
|
1331
|
+
return xHeaders;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1035
1334
|
} else {
|
|
1335
|
+
const isExecuting = this.isExecuting();
|
|
1336
|
+
const reject = () => {
|
|
1337
|
+
this.currentSession.reject();
|
|
1338
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
1339
|
+
};
|
|
1340
|
+
if (isExecuting) {
|
|
1341
|
+
reject();
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1036
1344
|
this.callKit.trigger(KitEvent.KIT_INVITE, {
|
|
1037
1345
|
accept: () => {
|
|
1038
|
-
this.
|
|
1346
|
+
this.isCurrentSessionInvited = true;
|
|
1039
1347
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
1040
1348
|
this.currentSession.accept(options);
|
|
1041
1349
|
},
|
|
1042
|
-
reject
|
|
1043
|
-
this.currentSession.reject();
|
|
1044
|
-
this.callKit.callCenter.callEnd(true, false);
|
|
1045
|
-
},
|
|
1350
|
+
reject,
|
|
1046
1351
|
getInviteData: () => {
|
|
1047
1352
|
const { request: request2 } = this.currentSession;
|
|
1048
1353
|
const headerNames = Object.keys(request2.headers);
|
|
@@ -1060,9 +1365,12 @@ var Connect = class {
|
|
|
1060
1365
|
},
|
|
1061
1366
|
onConnect: async () => {
|
|
1062
1367
|
this.callKit.logger.debug("connect onConnect");
|
|
1368
|
+
const version = `V${this.callKit.config.getConfig().version}`;
|
|
1063
1369
|
await this.registerer.register().then(() => {
|
|
1064
|
-
this.callKit.socket.send(SocketSendEvent.START
|
|
1065
|
-
|
|
1370
|
+
this.callKit.socket.send(SocketSendEvent.START, {
|
|
1371
|
+
version
|
|
1372
|
+
});
|
|
1373
|
+
}).catch(async (err) => {
|
|
1066
1374
|
this.callKit.logger.error(err?.message, {
|
|
1067
1375
|
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
1068
1376
|
});
|
|
@@ -1070,13 +1378,18 @@ var Connect = class {
|
|
|
1070
1378
|
},
|
|
1071
1379
|
onDisconnect: (error) => {
|
|
1072
1380
|
this.callKit.logger.debug("connect onDisconnect");
|
|
1073
|
-
if (this.isRegistered() &&
|
|
1381
|
+
if (this.isRegistered() && !// this.sipConnected ||
|
|
1382
|
+
(this.isRinging() || this.isCalling() || this.isHolding())) {
|
|
1074
1383
|
this.reconnect();
|
|
1075
1384
|
} else {
|
|
1076
1385
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1077
1386
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1078
1387
|
err: error
|
|
1079
1388
|
});
|
|
1389
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
1390
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1391
|
+
err: error
|
|
1392
|
+
});
|
|
1080
1393
|
this.callKit.user.sendHangUpReason({
|
|
1081
1394
|
eventType: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
1082
1395
|
err: error
|
|
@@ -1128,6 +1441,11 @@ var Connect = class {
|
|
|
1128
1441
|
return;
|
|
1129
1442
|
reconnectTimer = setTimeout(async () => {
|
|
1130
1443
|
try {
|
|
1444
|
+
if (currentRetry === 0) {
|
|
1445
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1446
|
+
event: ConnectEvent.SIP_RECONNECT_START
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1131
1449
|
currentRetry += 1;
|
|
1132
1450
|
this.callKit.logger.debug(
|
|
1133
1451
|
`Attempting to reconnect SIP... (Attempt ${currentRetry}/${this.reconnectConfig.maxAttempts})`
|
|
@@ -1170,9 +1488,7 @@ var Connect = class {
|
|
|
1170
1488
|
this.callKit.logger.warn("No registerer to unregister.");
|
|
1171
1489
|
return;
|
|
1172
1490
|
}
|
|
1173
|
-
await this.registerer.unregister({ all: true }).
|
|
1174
|
-
this.setConnectStatus(CallStatus.init);
|
|
1175
|
-
}).catch((err) => {
|
|
1491
|
+
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
1176
1492
|
this.callKit.logger.error(err, {
|
|
1177
1493
|
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1178
1494
|
});
|
|
@@ -1203,12 +1519,6 @@ var Connect = class {
|
|
|
1203
1519
|
*/
|
|
1204
1520
|
setConnectStatus(status) {
|
|
1205
1521
|
this.callKit.logger.debug(`connect setConnectStatus: ${status}`);
|
|
1206
|
-
if (this.isRegistered() && status === CallStatus.init) {
|
|
1207
|
-
this.setRegister(false);
|
|
1208
|
-
}
|
|
1209
|
-
if (!this.isRegistered() && status !== CallStatus.init) {
|
|
1210
|
-
this.setRegister(true);
|
|
1211
|
-
}
|
|
1212
1522
|
this.connectStatus = status;
|
|
1213
1523
|
this.callKit.trigger(KitEvent.KIT_CALL_STATUS_CHANGE, status);
|
|
1214
1524
|
}
|
|
@@ -1226,13 +1536,14 @@ var Connect = class {
|
|
|
1226
1536
|
this.isUnprompted = isUnprompted;
|
|
1227
1537
|
try {
|
|
1228
1538
|
if (isUnprompted) {
|
|
1229
|
-
|
|
1230
|
-
|
|
1539
|
+
const shouldSendBye = (
|
|
1540
|
+
// this.sipConnected ||
|
|
1541
|
+
this.isRinging() || this.isCalling() || this.isHolding()
|
|
1542
|
+
);
|
|
1231
1543
|
if (shouldSendBye) {
|
|
1232
1544
|
await this.currentSession?.bye();
|
|
1233
1545
|
}
|
|
1234
1546
|
}
|
|
1235
|
-
this.sipConnected = false;
|
|
1236
1547
|
closeStream(this.mediaStream);
|
|
1237
1548
|
const audioRef = this.getAduioReference();
|
|
1238
1549
|
if (audioRef) {
|
|
@@ -1241,8 +1552,6 @@ var Connect = class {
|
|
|
1241
1552
|
}
|
|
1242
1553
|
if (isError) {
|
|
1243
1554
|
this.setConnectStatus(CallStatus.init);
|
|
1244
|
-
} else {
|
|
1245
|
-
this.setConnectStatus(CallStatus.registered);
|
|
1246
1555
|
}
|
|
1247
1556
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
1248
1557
|
} catch (err) {
|
|
@@ -1373,59 +1682,6 @@ var Connect = class {
|
|
|
1373
1682
|
}
|
|
1374
1683
|
};
|
|
1375
1684
|
|
|
1376
|
-
// package/monitor.ts
|
|
1377
|
-
import axios2 from "axios";
|
|
1378
|
-
var defaultConfig = {
|
|
1379
|
-
interval: 5e3,
|
|
1380
|
-
apiEndpoint: "/livez"
|
|
1381
|
-
};
|
|
1382
|
-
var Monitor = class {
|
|
1383
|
-
callKit;
|
|
1384
|
-
interval = defaultConfig.interval;
|
|
1385
|
-
apiEndpoint = defaultConfig.apiEndpoint;
|
|
1386
|
-
monitorIntervalHandler = null;
|
|
1387
|
-
constructor(callKit) {
|
|
1388
|
-
this.callKit = callKit;
|
|
1389
|
-
const { monitor } = this.callKit.config.getConfig();
|
|
1390
|
-
this.interval = monitor?.interval ?? defaultConfig.interval;
|
|
1391
|
-
this.apiEndpoint = monitor?.apiEndpoint ?? defaultConfig.apiEndpoint;
|
|
1392
|
-
this.monitorIntervalHandler = null;
|
|
1393
|
-
}
|
|
1394
|
-
getEndPointPath = () => {
|
|
1395
|
-
const config = this.callKit.config.getConfig();
|
|
1396
|
-
const defaultPath = `${config.host}${this.apiEndpoint}`;
|
|
1397
|
-
const endPointPath = config.monitor?.apiEndpoint ?? defaultPath;
|
|
1398
|
-
return endPointPath;
|
|
1399
|
-
};
|
|
1400
|
-
measureRTT = async () => {
|
|
1401
|
-
try {
|
|
1402
|
-
const endPoint = this.getEndPointPath();
|
|
1403
|
-
const startTime = performance.now();
|
|
1404
|
-
await axios2.get(endPoint);
|
|
1405
|
-
const endTime = performance.now();
|
|
1406
|
-
const rtt = Math.round(endTime - startTime);
|
|
1407
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
1408
|
-
event: NetWorkEvent.RTT_MEASURE_SUCCESS,
|
|
1409
|
-
rtt
|
|
1410
|
-
});
|
|
1411
|
-
} catch (error) {
|
|
1412
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
1413
|
-
event: NetWorkEvent.RTT_MEASURE_FAILED,
|
|
1414
|
-
rtt: 0
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
};
|
|
1418
|
-
stopRTTMonitoring() {
|
|
1419
|
-
if (this.monitorIntervalHandler) {
|
|
1420
|
-
clearInterval(this.monitorIntervalHandler);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
startRTTMonitoring() {
|
|
1424
|
-
this.stopRTTMonitoring();
|
|
1425
|
-
this.monitorIntervalHandler = setInterval(this.measureRTT, this.interval);
|
|
1426
|
-
}
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
1685
|
// package/socket.ts
|
|
1430
1686
|
var RECONNECT_CONFIG = {
|
|
1431
1687
|
enabled: true,
|
|
@@ -1449,7 +1705,6 @@ var Socket = class {
|
|
|
1449
1705
|
reconnectTimer;
|
|
1450
1706
|
isReconnecting = false;
|
|
1451
1707
|
reconnectAttempts = 0;
|
|
1452
|
-
closing = false;
|
|
1453
1708
|
constructor(callKit) {
|
|
1454
1709
|
this.callKit = callKit;
|
|
1455
1710
|
const { reconnect } = this.callKit.config.getConfig();
|
|
@@ -1463,15 +1718,13 @@ var Socket = class {
|
|
|
1463
1718
|
this.callKit.logger.debug(`socket init: ${socket}`);
|
|
1464
1719
|
this.connect(socket);
|
|
1465
1720
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
});
|
|
1474
|
-
this.close(1e3, "normal");
|
|
1721
|
+
// confirm from connect startConfirm
|
|
1722
|
+
// startConfirm(status: boolean) {
|
|
1723
|
+
// this.callKit.logger.debug('register success');
|
|
1724
|
+
// this.satrtConfirm = status;
|
|
1725
|
+
// }
|
|
1726
|
+
setRecivedClose(status) {
|
|
1727
|
+
this.recivedClose = status;
|
|
1475
1728
|
}
|
|
1476
1729
|
reconnect(ev) {
|
|
1477
1730
|
this.callKit.logger.debug("socket reconnect", ev);
|
|
@@ -1481,12 +1734,21 @@ var Socket = class {
|
|
|
1481
1734
|
"socket reconnect times",
|
|
1482
1735
|
this.socketConfig.maxAttempts
|
|
1483
1736
|
);
|
|
1737
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1738
|
+
event: ConnectEvent.INCALL_RECONNECTING,
|
|
1739
|
+
attempts: this.reconnectAttempts,
|
|
1740
|
+
err: ev
|
|
1741
|
+
});
|
|
1484
1742
|
this.attemptReconnect();
|
|
1485
1743
|
} else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
1486
1744
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1487
1745
|
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
1488
1746
|
err: ev
|
|
1489
1747
|
});
|
|
1748
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1749
|
+
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
1750
|
+
err: ev
|
|
1751
|
+
});
|
|
1490
1752
|
this.reset();
|
|
1491
1753
|
this.callKit.logger.error(
|
|
1492
1754
|
"Reconnection failed, maximum retry attempts reached",
|
|
@@ -1505,6 +1767,10 @@ var Socket = class {
|
|
|
1505
1767
|
}
|
|
1506
1768
|
onOpen(ev) {
|
|
1507
1769
|
this.callKit.logger.debug("socket onOpen", ev);
|
|
1770
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1771
|
+
callKitSocketFrom: "onOpen",
|
|
1772
|
+
ev
|
|
1773
|
+
});
|
|
1508
1774
|
this.isConnected = true;
|
|
1509
1775
|
this.lastPingTime = Date.now();
|
|
1510
1776
|
this.checkPing();
|
|
@@ -1523,14 +1789,23 @@ var Socket = class {
|
|
|
1523
1789
|
}
|
|
1524
1790
|
onClose(ev) {
|
|
1525
1791
|
this.callKit.logger.debug("socket onClose", ev);
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1792
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1793
|
+
callKitSocketFrom: "onClose",
|
|
1794
|
+
ev
|
|
1795
|
+
});
|
|
1796
|
+
if ((ev.code !== 1e3 || !ev.wasClean) && this.callKit.connect.isRegistered()) {
|
|
1530
1797
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1531
1798
|
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1532
1799
|
err: ev
|
|
1533
1800
|
});
|
|
1801
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
1802
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1803
|
+
err: ev
|
|
1804
|
+
});
|
|
1805
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1806
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1807
|
+
err: ev
|
|
1808
|
+
});
|
|
1534
1809
|
this.reconnect(ev);
|
|
1535
1810
|
} else {
|
|
1536
1811
|
this.isConnected = false;
|
|
@@ -1541,10 +1816,6 @@ var Socket = class {
|
|
|
1541
1816
|
}
|
|
1542
1817
|
this.callKit.connect.hangup();
|
|
1543
1818
|
this.reset();
|
|
1544
|
-
this.closing = false;
|
|
1545
|
-
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1546
|
-
event: ConnectEvent.CONNECT_CLOSING_END
|
|
1547
|
-
});
|
|
1548
1819
|
}
|
|
1549
1820
|
}
|
|
1550
1821
|
onError(ev) {
|
|
@@ -1552,46 +1823,53 @@ var Socket = class {
|
|
|
1552
1823
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
1553
1824
|
data: ev
|
|
1554
1825
|
});
|
|
1826
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1827
|
+
callKitSocketFrom: "onError",
|
|
1828
|
+
ev
|
|
1829
|
+
});
|
|
1555
1830
|
if (this.isReconnecting) {
|
|
1556
1831
|
this.attemptReconnect();
|
|
1557
1832
|
}
|
|
1558
1833
|
}
|
|
1834
|
+
confirmAck(data) {
|
|
1835
|
+
const { ack, messageId } = data;
|
|
1836
|
+
if (ack) {
|
|
1837
|
+
this.send(SocketSendEvent.ACK, {
|
|
1838
|
+
messageId
|
|
1839
|
+
// sessionId
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1559
1843
|
onMessage(ev) {
|
|
1560
1844
|
const data = JSON.parse(ev.data);
|
|
1561
1845
|
this.callKit.logger.debug("socket onMessage", data);
|
|
1846
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1847
|
+
callKitSocketFrom: "onMessage",
|
|
1848
|
+
ev
|
|
1849
|
+
});
|
|
1850
|
+
this.confirmAck(data);
|
|
1562
1851
|
if (data.event === SocketReceiveEvent.PONG) {
|
|
1563
1852
|
this.lastPingTime = Date.now();
|
|
1564
1853
|
return;
|
|
1565
1854
|
}
|
|
1566
1855
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
1567
|
-
this.callKit.logger.debug("
|
|
1856
|
+
this.callKit.logger.debug("start confirm success");
|
|
1568
1857
|
this.satrtConfirm = true;
|
|
1569
|
-
this.callKit.connect.setConnectStatus(CallStatus.registered);
|
|
1570
1858
|
}
|
|
1571
1859
|
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
1572
1860
|
this.recivedClose = false;
|
|
1573
|
-
this.callKit.logger.debug("callStart");
|
|
1574
|
-
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
1575
1861
|
}
|
|
1576
1862
|
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
1577
1863
|
this.callKit.logger.debug(data.msg, {
|
|
1578
1864
|
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
1579
1865
|
});
|
|
1580
|
-
this.callKit.user.setUserStatus(UserStatus.online);
|
|
1581
1866
|
}
|
|
1582
1867
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
1583
|
-
this.callKit.
|
|
1584
|
-
if (this.callKit.connect.isConnecting()) {
|
|
1585
|
-
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
1586
|
-
this.callKit.connect.setConnectStatus(CallStatus.ringing);
|
|
1587
|
-
}
|
|
1868
|
+
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
1588
1869
|
}
|
|
1589
1870
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
1590
1871
|
this.callKit.logger.debug(data.msg);
|
|
1591
|
-
|
|
1592
|
-
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
1593
|
-
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
1594
|
-
}
|
|
1872
|
+
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
1595
1873
|
}
|
|
1596
1874
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
1597
1875
|
this.callKit.logger.debug(data.msg);
|
|
@@ -1600,12 +1878,10 @@ var Socket = class {
|
|
|
1600
1878
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
1601
1879
|
this.callKit.logger.debug(data.msg);
|
|
1602
1880
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
1603
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1604
1881
|
}
|
|
1605
1882
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
1606
1883
|
this.callKit.logger.debug(data.msg);
|
|
1607
1884
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
1608
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1609
1885
|
}
|
|
1610
1886
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
1611
1887
|
this.callKit.logger.debug(data.msg);
|
|
@@ -1613,7 +1889,7 @@ var Socket = class {
|
|
|
1613
1889
|
}
|
|
1614
1890
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
1615
1891
|
this.callKit.logger.debug(data.msg);
|
|
1616
|
-
this.
|
|
1892
|
+
this.setRecivedClose(true);
|
|
1617
1893
|
}
|
|
1618
1894
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
1619
1895
|
const { userInfo } = this.callKit.config.getConfig();
|
|
@@ -1623,19 +1899,21 @@ var Socket = class {
|
|
|
1623
1899
|
});
|
|
1624
1900
|
}
|
|
1625
1901
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
1626
|
-
this.callKit.
|
|
1902
|
+
this.callKit.unregister();
|
|
1903
|
+
this.callKit.logger.debug(data.msg, {
|
|
1627
1904
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
1628
1905
|
data
|
|
1629
1906
|
});
|
|
1630
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1631
1907
|
}
|
|
1632
1908
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
1633
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1634
1909
|
}
|
|
1635
1910
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
1636
1911
|
}
|
|
1637
1912
|
send(event, message) {
|
|
1638
1913
|
if (!this.isConnected) {
|
|
1914
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1915
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
1916
|
+
});
|
|
1639
1917
|
this.callKit.logger.error("socket not connected", {
|
|
1640
1918
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
1641
1919
|
});
|
|
@@ -1678,6 +1956,9 @@ var Socket = class {
|
|
|
1678
1956
|
}
|
|
1679
1957
|
async sendMessage(event, message) {
|
|
1680
1958
|
if (!this.isConnected) {
|
|
1959
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1960
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
1961
|
+
});
|
|
1681
1962
|
this.callKit.logger.error("socket not connected", {
|
|
1682
1963
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
1683
1964
|
});
|
|
@@ -1752,11 +2033,16 @@ var Socket = class {
|
|
|
1752
2033
|
}
|
|
1753
2034
|
this.recivedClose = false;
|
|
1754
2035
|
this.callKit.logger.debug("socket destroy");
|
|
1755
|
-
this.ws.close(
|
|
2036
|
+
this.ws.close();
|
|
1756
2037
|
this.isConnected = false;
|
|
1757
2038
|
}
|
|
1758
2039
|
}
|
|
1759
2040
|
attemptReconnect() {
|
|
2041
|
+
if (this.reconnectAttempts === 0) {
|
|
2042
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
2043
|
+
event: ConnectEvent.INCALL_RECONNECT_START
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
1760
2046
|
if (this.isReconnecting && this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
1761
2047
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1762
2048
|
event: ConnectEvent.INCALL_RECONNECT_ERROR
|
|
@@ -1791,8 +2077,102 @@ var User = class {
|
|
|
1791
2077
|
callKit;
|
|
1792
2078
|
userStatus;
|
|
1793
2079
|
// logout(1, "unregistered"), idle(2, "free"), break(3, "nap"), busy(4, "busy")
|
|
2080
|
+
userChangeStatusExecuting;
|
|
1794
2081
|
constructor(callKit) {
|
|
1795
2082
|
this.callKit = callKit;
|
|
2083
|
+
this.userChangeStatusExecuting = false;
|
|
2084
|
+
}
|
|
2085
|
+
setUserChangeStatusExecuting(state) {
|
|
2086
|
+
this.userChangeStatusExecuting = state;
|
|
2087
|
+
}
|
|
2088
|
+
getUserChangeStatusExecuting() {
|
|
2089
|
+
return this.userChangeStatusExecuting;
|
|
2090
|
+
}
|
|
2091
|
+
async login(params) {
|
|
2092
|
+
const postData = {
|
|
2093
|
+
userName: params.userName,
|
|
2094
|
+
password: params.password
|
|
2095
|
+
};
|
|
2096
|
+
const logData = {
|
|
2097
|
+
postData,
|
|
2098
|
+
url: "/auth/agentUser/login",
|
|
2099
|
+
status: "send",
|
|
2100
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2101
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2102
|
+
};
|
|
2103
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2104
|
+
this.setUserChangeStatusExecuting(true);
|
|
2105
|
+
return this.callKit.api.login(params).then((user) => {
|
|
2106
|
+
this.setUserChangeStatusExecuting(false);
|
|
2107
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2108
|
+
...logData,
|
|
2109
|
+
status: "success",
|
|
2110
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2111
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2112
|
+
});
|
|
2113
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2114
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginEnd
|
|
2115
|
+
});
|
|
2116
|
+
return user;
|
|
2117
|
+
}).catch((err) => {
|
|
2118
|
+
this.setUserChangeStatusExecuting(false);
|
|
2119
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2120
|
+
...logData,
|
|
2121
|
+
status: "error",
|
|
2122
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2123
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2124
|
+
});
|
|
2125
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2126
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginError
|
|
2127
|
+
});
|
|
2128
|
+
this.callKit.logger.error(err, {
|
|
2129
|
+
errCode: ErrorCode.API_USER_LOGIN_ERROR
|
|
2130
|
+
});
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
async loginOut(params) {
|
|
2134
|
+
const postData = {
|
|
2135
|
+
sessionId: params.sessionId
|
|
2136
|
+
};
|
|
2137
|
+
const logData = {
|
|
2138
|
+
postData,
|
|
2139
|
+
url: "/auth/agentUser/loginOut",
|
|
2140
|
+
status: "send",
|
|
2141
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2142
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2143
|
+
};
|
|
2144
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2145
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2146
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutStart
|
|
2147
|
+
});
|
|
2148
|
+
this.setUserChangeStatusExecuting(true);
|
|
2149
|
+
return this.callKit.api.loginOut(postData).then((res) => {
|
|
2150
|
+
this.setUserChangeStatusExecuting(false);
|
|
2151
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2152
|
+
...logData,
|
|
2153
|
+
status: "success",
|
|
2154
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2155
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2156
|
+
});
|
|
2157
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2158
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutEnd
|
|
2159
|
+
});
|
|
2160
|
+
return res;
|
|
2161
|
+
}).catch((err) => {
|
|
2162
|
+
this.setUserChangeStatusExecuting(false);
|
|
2163
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2164
|
+
...logData,
|
|
2165
|
+
status: "error",
|
|
2166
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2167
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2168
|
+
});
|
|
2169
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2170
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutError
|
|
2171
|
+
});
|
|
2172
|
+
this.callKit.logger.error(err, {
|
|
2173
|
+
errCode: ErrorCode.API_USER_LOGOUT_ERROR
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
1796
2176
|
}
|
|
1797
2177
|
/**
|
|
1798
2178
|
*
|
|
@@ -1809,24 +2189,70 @@ var User = class {
|
|
|
1809
2189
|
* @param status
|
|
1810
2190
|
*/
|
|
1811
2191
|
async updateUserStatus(status) {
|
|
1812
|
-
|
|
1813
|
-
if (!this.callKit.config.isLogin()) {
|
|
1814
|
-
this.userStatus = UserStatus.offline;
|
|
1815
|
-
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, UserStatus.offline);
|
|
2192
|
+
if (this.userChangeStatusExecuting)
|
|
1816
2193
|
return;
|
|
1817
|
-
}
|
|
1818
|
-
|
|
2194
|
+
const { agentId } = this.callKit.config.getConfig().userInfo;
|
|
2195
|
+
this.setUserChangeStatusExecuting(true);
|
|
2196
|
+
const postData = {
|
|
1819
2197
|
agentId,
|
|
1820
2198
|
userStatus: status
|
|
1821
|
-
}
|
|
2199
|
+
};
|
|
2200
|
+
const logData = {
|
|
2201
|
+
postData,
|
|
2202
|
+
url: "/agent/user/changeStatus",
|
|
2203
|
+
status: "send",
|
|
2204
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2205
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2206
|
+
};
|
|
2207
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2208
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2209
|
+
event: UserStatusChangeStepEnum.UserStatusChangeStart
|
|
2210
|
+
});
|
|
2211
|
+
await this.callKit.api.setUserStatus(postData).then(() => {
|
|
2212
|
+
this.setUserChangeStatusExecuting(false);
|
|
1822
2213
|
this.userStatus = status;
|
|
2214
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2215
|
+
event: UserStatusChangeStepEnum.UserStatusChangeEnd
|
|
2216
|
+
});
|
|
1823
2217
|
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, status);
|
|
2218
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2219
|
+
...logData,
|
|
2220
|
+
status: "success",
|
|
2221
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2222
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2223
|
+
});
|
|
1824
2224
|
}).catch((err) => {
|
|
2225
|
+
this.setUserChangeStatusExecuting(false);
|
|
2226
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2227
|
+
...logData,
|
|
2228
|
+
status: "error",
|
|
2229
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2230
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2231
|
+
});
|
|
2232
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2233
|
+
event: UserStatusChangeStepEnum.UserStatusChangeError
|
|
2234
|
+
});
|
|
2235
|
+
this.setUserChangeStatusExecuting(false);
|
|
2236
|
+
if (this.callKit.connect.isRegistered()) {
|
|
2237
|
+
this.callKit.unregister();
|
|
2238
|
+
}
|
|
2239
|
+
this.callKit.trigger(
|
|
2240
|
+
KitEvent.KIT_USER_STATUS_CHANGE,
|
|
2241
|
+
UserStatus.offline
|
|
2242
|
+
);
|
|
1825
2243
|
this.callKit.logger.error(err, {
|
|
1826
2244
|
errCode: ErrorCode.API_USER_STATUS_UPDATE_ERROR
|
|
1827
2245
|
});
|
|
1828
2246
|
});
|
|
1829
2247
|
}
|
|
2248
|
+
/**
|
|
2249
|
+
* @description sdkLog
|
|
2250
|
+
* @param params
|
|
2251
|
+
* @returns
|
|
2252
|
+
*/
|
|
2253
|
+
async sendSdkLog(data) {
|
|
2254
|
+
return this.callKit.api.sdkLog(data);
|
|
2255
|
+
}
|
|
1830
2256
|
async sendHangUpReason(data) {
|
|
1831
2257
|
try {
|
|
1832
2258
|
const sendData = data || {};
|
|
@@ -1846,7 +2272,6 @@ var CallKit = class {
|
|
|
1846
2272
|
connect;
|
|
1847
2273
|
socket;
|
|
1848
2274
|
user;
|
|
1849
|
-
monitor;
|
|
1850
2275
|
listener = [];
|
|
1851
2276
|
constructor(options) {
|
|
1852
2277
|
this.config = new Config(this);
|
|
@@ -1864,8 +2289,6 @@ var CallKit = class {
|
|
|
1864
2289
|
);
|
|
1865
2290
|
this.config.setConfig("reconnect", options.reconnect);
|
|
1866
2291
|
this.logger = new Logger(this, options.log);
|
|
1867
|
-
this.config.setConfig("monitor", options.monitor);
|
|
1868
|
-
this.monitor = new Monitor(this);
|
|
1869
2292
|
this.logger.debug("callKit init", options);
|
|
1870
2293
|
this.api = new Api(this);
|
|
1871
2294
|
this.connect = new Connect(this);
|
|
@@ -1899,11 +2322,9 @@ var CallKit = class {
|
|
|
1899
2322
|
encryptionMethod,
|
|
1900
2323
|
encryptionPassword
|
|
1901
2324
|
});
|
|
1902
|
-
const user = await this.
|
|
2325
|
+
const user = await this.user.login({
|
|
1903
2326
|
userName: username,
|
|
1904
2327
|
password: encryptionPassword
|
|
1905
|
-
}).catch((err) => {
|
|
1906
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGIN_ERROR });
|
|
1907
2328
|
});
|
|
1908
2329
|
if (user) {
|
|
1909
2330
|
this.config.setConfig("userInfo", {
|
|
@@ -1920,6 +2341,7 @@ var CallKit = class {
|
|
|
1920
2341
|
fsPort: user.fsPort,
|
|
1921
2342
|
iceInfo: user.iceInfo,
|
|
1922
2343
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
2344
|
+
logGather: user.logGather,
|
|
1923
2345
|
// encryptionType is in extra
|
|
1924
2346
|
...extra
|
|
1925
2347
|
});
|
|
@@ -1935,12 +2357,7 @@ var CallKit = class {
|
|
|
1935
2357
|
await this.user.setUserStatus(UserStatus.offline);
|
|
1936
2358
|
if (this.config.isLogin()) {
|
|
1937
2359
|
const { sessionId } = this.config.getConfig().userInfo;
|
|
1938
|
-
this.
|
|
1939
|
-
this.stop();
|
|
1940
|
-
this.socket.gracefulClose();
|
|
1941
|
-
this.api.loginOut({ sessionId }).catch((err) => {
|
|
1942
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGOUT_ERROR });
|
|
1943
|
-
});
|
|
2360
|
+
this.user.loginOut({ sessionId });
|
|
1944
2361
|
}
|
|
1945
2362
|
await this.hangup();
|
|
1946
2363
|
this.socket.reset(false);
|
|
@@ -1983,14 +2400,12 @@ var CallKit = class {
|
|
|
1983
2400
|
return;
|
|
1984
2401
|
this.logger.debug("register");
|
|
1985
2402
|
this.connect.register();
|
|
1986
|
-
await this.user.setUserStatus(UserStatus.online);
|
|
1987
2403
|
}
|
|
1988
2404
|
async unregister() {
|
|
1989
2405
|
if (!this.config.check())
|
|
1990
2406
|
return;
|
|
1991
2407
|
this.logger.debug("unregister");
|
|
1992
2408
|
this.connect.unregister();
|
|
1993
|
-
await this.user.setUserStatus(UserStatus.offline);
|
|
1994
2409
|
}
|
|
1995
2410
|
async stop() {
|
|
1996
2411
|
await this.connect.stop();
|
|
@@ -2004,7 +2419,6 @@ var CallKit = class {
|
|
|
2004
2419
|
return;
|
|
2005
2420
|
}
|
|
2006
2421
|
await this.callCenter.callEnd(true);
|
|
2007
|
-
this.user.setUserStatus(UserStatus.catNap);
|
|
2008
2422
|
}
|
|
2009
2423
|
hold() {
|
|
2010
2424
|
if (!this.config.check())
|
|
@@ -2045,12 +2459,6 @@ var CallKit = class {
|
|
|
2045
2459
|
await this.user.setUserStatus(UserStatus.offline);
|
|
2046
2460
|
}
|
|
2047
2461
|
}
|
|
2048
|
-
startRTTMonitoring() {
|
|
2049
|
-
this.monitor.startRTTMonitoring();
|
|
2050
|
-
}
|
|
2051
|
-
stopRTTMonitoring() {
|
|
2052
|
-
this.monitor.stopRTTMonitoring();
|
|
2053
|
-
}
|
|
2054
2462
|
on(event, callback) {
|
|
2055
2463
|
this.logger.debug(`on ${event}`);
|
|
2056
2464
|
this.listener.push({
|