@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.js
CHANGED
|
@@ -36,6 +36,7 @@ var import_blueimp_md5 = __toESM(require("blueimp-md5"));
|
|
|
36
36
|
|
|
37
37
|
// package/axios.ts
|
|
38
38
|
var import_axios = __toESM(require("axios"));
|
|
39
|
+
var import_axios_retry = __toESM(require("axios-retry"));
|
|
39
40
|
var instance = import_axios.default.create({
|
|
40
41
|
headers: {
|
|
41
42
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -46,85 +47,26 @@ instance.interceptors.response.use(
|
|
|
46
47
|
(response) => response.data,
|
|
47
48
|
(error) => Promise.reject(error)
|
|
48
49
|
);
|
|
50
|
+
(0, import_axios_retry.default)(instance, {
|
|
51
|
+
retries: 3,
|
|
52
|
+
// Maximum number of retries, default is 3
|
|
53
|
+
retryDelay: (retryCount, error) => {
|
|
54
|
+
console.log(
|
|
55
|
+
`AJAX Retrying attempt ${retryCount}, error: ${error?.message}`
|
|
56
|
+
);
|
|
57
|
+
return retryCount * 1e3;
|
|
58
|
+
},
|
|
59
|
+
retryCondition: (error) => {
|
|
60
|
+
if (!error.response)
|
|
61
|
+
return true;
|
|
62
|
+
return error.response.status < 200 || error.response.status >= 300;
|
|
63
|
+
},
|
|
64
|
+
shouldResetTimeout: true
|
|
65
|
+
// Whether to reset axios timeout on retry
|
|
66
|
+
});
|
|
49
67
|
var request = (config) => instance.request(config);
|
|
50
68
|
var axios_default = request;
|
|
51
69
|
|
|
52
|
-
// package/api.ts
|
|
53
|
-
var Api = class {
|
|
54
|
-
callKit;
|
|
55
|
-
constructor(callKit) {
|
|
56
|
-
this.callKit = callKit;
|
|
57
|
-
}
|
|
58
|
-
async login(params) {
|
|
59
|
-
return this.post({
|
|
60
|
-
url: "/auth/agentUser/login",
|
|
61
|
-
method: "post",
|
|
62
|
-
data: params
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async loginOut(params) {
|
|
66
|
-
return this.post({
|
|
67
|
-
url: "/auth/agentUser/loginOut",
|
|
68
|
-
method: "post",
|
|
69
|
-
data: params
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
* @param params agentId userStatus
|
|
75
|
-
* @description userStatus: Logout(1, "unregistered"), Free(2, "free"), Break(3, "nap"), Busy(4, "busy")
|
|
76
|
-
* @returns
|
|
77
|
-
*/
|
|
78
|
-
async setUserStatus(params) {
|
|
79
|
-
return this.post({
|
|
80
|
-
url: "/agent/user/changeStatus",
|
|
81
|
-
method: "post",
|
|
82
|
-
data: params
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
async measureRTT(config) {
|
|
86
|
-
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
87
|
-
return axios_default(config);
|
|
88
|
-
}
|
|
89
|
-
async post(config) {
|
|
90
|
-
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
91
|
-
const { userInfo, host } = this.callKit.config.getConfig();
|
|
92
|
-
const { sessionId } = userInfo;
|
|
93
|
-
config.url = `${host}${config.url}`;
|
|
94
|
-
config.headers = {
|
|
95
|
-
...config.headers,
|
|
96
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
97
|
-
};
|
|
98
|
-
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
99
|
-
config.data = new URLSearchParams(config.data).toString();
|
|
100
|
-
}
|
|
101
|
-
if (sessionId) {
|
|
102
|
-
config.headers.sessionId = sessionId;
|
|
103
|
-
}
|
|
104
|
-
const res = await axios_default(config).catch(() => {
|
|
105
|
-
this.callKit.config.reset();
|
|
106
|
-
});
|
|
107
|
-
if (!res) {
|
|
108
|
-
this.callKit.config.reset();
|
|
109
|
-
throw new Error("Network error");
|
|
110
|
-
}
|
|
111
|
-
const { code, data, message } = res;
|
|
112
|
-
if (code === "000000") {
|
|
113
|
-
return data;
|
|
114
|
-
}
|
|
115
|
-
if (code === "100013") {
|
|
116
|
-
this.callKit.config.reset();
|
|
117
|
-
}
|
|
118
|
-
throw new Error(message ?? "Request failed");
|
|
119
|
-
}
|
|
120
|
-
async get(config) {
|
|
121
|
-
return this.post({
|
|
122
|
-
...config,
|
|
123
|
-
method: "get"
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
70
|
// package/const.ts
|
|
129
71
|
var UserStatus = {
|
|
130
72
|
/**
|
|
@@ -211,6 +153,10 @@ var KitEvent = {
|
|
|
211
153
|
* Server initiated call
|
|
212
154
|
*/
|
|
213
155
|
KIT_INVITE: "invite",
|
|
156
|
+
/**
|
|
157
|
+
* Server outgoing initiated call
|
|
158
|
+
*/
|
|
159
|
+
KIT_OUTGOING_INVITE: "outgoingInvite",
|
|
214
160
|
// /**
|
|
215
161
|
// * Referral
|
|
216
162
|
// */
|
|
@@ -255,14 +201,10 @@ var KitEvent = {
|
|
|
255
201
|
* User status change
|
|
256
202
|
*/
|
|
257
203
|
USER_STATUS_CHANGE: "userStatusChange",
|
|
258
|
-
/**
|
|
259
|
-
* SOCKET CONNECT EVENT
|
|
260
|
-
*/
|
|
261
204
|
CONNECT_EVENT: "CONNECT_EVENT",
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
NETWORK_EVENT: "NETWORK_EVENT"
|
|
205
|
+
SIP_REGISTERER_EVENT: "sipRegistererEvent",
|
|
206
|
+
SIP_SESSION_EVENT: "sipSessionEvent",
|
|
207
|
+
USER_STATUS_CHANGE_STEP: "userStatusChangeStep"
|
|
266
208
|
};
|
|
267
209
|
var ErrorCode = {
|
|
268
210
|
/**
|
|
@@ -397,7 +339,9 @@ var SocketSendEvent = {
|
|
|
397
339
|
/**
|
|
398
340
|
* AGENT_TRANSFER
|
|
399
341
|
*/
|
|
400
|
-
HANG_UP_REASON: "HANG_UP_REASON"
|
|
342
|
+
HANG_UP_REASON: "HANG_UP_REASON",
|
|
343
|
+
ACK: "ACK",
|
|
344
|
+
SDK_LOG: "SDK_LOG"
|
|
401
345
|
};
|
|
402
346
|
var SocketReceiveEvent = {
|
|
403
347
|
/**
|
|
@@ -461,6 +405,10 @@ var EncryptionMethod = {
|
|
|
461
405
|
NONE: "NONE",
|
|
462
406
|
INTERNAL: "INTERNAL"
|
|
463
407
|
};
|
|
408
|
+
var LogGatherEnum = {
|
|
409
|
+
ENABLE: 1,
|
|
410
|
+
DISABLE: 2
|
|
411
|
+
};
|
|
464
412
|
var constrainsDefault = {
|
|
465
413
|
audio: {
|
|
466
414
|
autoGainControl: true,
|
|
@@ -478,19 +426,330 @@ var CallSourceType = {
|
|
|
478
426
|
};
|
|
479
427
|
var ConnectEvent = {
|
|
480
428
|
SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
|
|
429
|
+
SIP_RECONNECT_START: "SIP_RECONNECT_START",
|
|
481
430
|
SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
|
|
482
431
|
SIP_RECONNECT_SUCCESS: "SIP_RECONNECT_SUCCESS",
|
|
432
|
+
SIP_RECONNECTING: "SIP_RECONNECTING",
|
|
433
|
+
INCALL_NOT_CONNECTED: "INCALL_NOT_CONNECTED",
|
|
483
434
|
INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
|
|
435
|
+
INCALL_RECONNECT_START: "INCALL_RECONNECT_START",
|
|
484
436
|
INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR",
|
|
485
437
|
INCALL_RECONNECT_SUCCESS: "INCALL_RECONNECT_SUCCESS",
|
|
438
|
+
INCALL_RECONNECTING: "INCALL_RECONNECTING",
|
|
486
439
|
OPTIONS_HEARTBEAT_EXPIRED: "OPTIONS_HEARTBEAT_EXPIRED",
|
|
487
|
-
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
488
|
-
|
|
489
|
-
|
|
440
|
+
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
441
|
+
};
|
|
442
|
+
var SipRegistererEvent = {
|
|
443
|
+
Initial: "Initial",
|
|
444
|
+
Registered: "Registered",
|
|
445
|
+
Unregistered: "Unregistered",
|
|
446
|
+
Terminated: "Terminated"
|
|
447
|
+
};
|
|
448
|
+
var SipSessionEvent = {
|
|
449
|
+
Establishing: "Establishing",
|
|
450
|
+
Established: "Established",
|
|
451
|
+
Terminating: "Terminating",
|
|
452
|
+
Terminated: "Terminated"
|
|
453
|
+
};
|
|
454
|
+
var UserStatusChangeStepEnum = {
|
|
455
|
+
UserStatusChangeStart: "UserStatusChangeStart",
|
|
456
|
+
UserStatusChangeEnd: "UserStatusChangeEnd",
|
|
457
|
+
UserStatusChangeError: "UserStatusChangeError",
|
|
458
|
+
// login
|
|
459
|
+
UserStatusChangeLoginStart: "UserStatusChangeLoginStart",
|
|
460
|
+
UserStatusChangeLoginEnd: "UserStatusChangeLoginEnd",
|
|
461
|
+
UserStatusChangeLoginError: "UserStatusChangeLoginError",
|
|
462
|
+
// logout
|
|
463
|
+
UserStatusChangeLoginOutStart: "UserStatusChangeLoginOutStart",
|
|
464
|
+
UserStatusChangeLoginOutEnd: "UserStatusChangeLoginOutEnd",
|
|
465
|
+
UserStatusChangeLoginOutError: "UserStatusChangeLoginOutError"
|
|
466
|
+
};
|
|
467
|
+
var LogDataEnum = {
|
|
468
|
+
SIP: "sip",
|
|
469
|
+
INCALL: "incall",
|
|
470
|
+
AJAX: "ajax",
|
|
471
|
+
ERROR: "error",
|
|
472
|
+
RECONNECT: "reconnect",
|
|
473
|
+
ALL: "all"
|
|
490
474
|
};
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
475
|
+
|
|
476
|
+
// package/logger.ts
|
|
477
|
+
var import_json_stringify_safe = __toESM(require("json-stringify-safe"));
|
|
478
|
+
function getLevel(level) {
|
|
479
|
+
return LoggerLevelMap[level];
|
|
480
|
+
}
|
|
481
|
+
var Logger = class {
|
|
482
|
+
prefix = "CallKit";
|
|
483
|
+
level = "debug";
|
|
484
|
+
logData = {
|
|
485
|
+
sip: [],
|
|
486
|
+
incall: [],
|
|
487
|
+
ajax: [],
|
|
488
|
+
error: [],
|
|
489
|
+
reconnect: [],
|
|
490
|
+
all: []
|
|
491
|
+
};
|
|
492
|
+
sendSdkLogData = [];
|
|
493
|
+
callKit;
|
|
494
|
+
constructor(callKit, level) {
|
|
495
|
+
this.callKit = callKit;
|
|
496
|
+
this.level = level || "debug";
|
|
497
|
+
this.logData = {
|
|
498
|
+
sip: [],
|
|
499
|
+
incall: [],
|
|
500
|
+
ajax: [],
|
|
501
|
+
error: [],
|
|
502
|
+
reconnect: [],
|
|
503
|
+
all: []
|
|
504
|
+
};
|
|
505
|
+
this.sendSdkLogData = [];
|
|
506
|
+
}
|
|
507
|
+
static formatStrLog(logObj) {
|
|
508
|
+
const {
|
|
509
|
+
type = "info"
|
|
510
|
+
// 默认等级
|
|
511
|
+
} = logObj;
|
|
512
|
+
const time = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
513
|
+
const level = String(type).toUpperCase().padEnd(5, " ");
|
|
514
|
+
const tagStr = logObj.typeag ? `[${logObj.type}]` : "";
|
|
515
|
+
const msg = JSON.stringify(logObj);
|
|
516
|
+
return `${time} [${level}] ${tagStr} ${msg}`.trim();
|
|
517
|
+
}
|
|
518
|
+
setLevel(level) {
|
|
519
|
+
this.level = level;
|
|
520
|
+
}
|
|
521
|
+
debug(msg, extra) {
|
|
522
|
+
if (getLevel(this.level) >= getLevel("debug")) {
|
|
523
|
+
this.output("blue")(msg, extra);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
log(msg, extra) {
|
|
527
|
+
if (getLevel(this.level) >= getLevel("log")) {
|
|
528
|
+
this.output("green")(msg, extra);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
warn(msg, extra) {
|
|
532
|
+
if (getLevel(this.level) >= getLevel("warn")) {
|
|
533
|
+
this.output("orange")(msg, extra);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
error(msg, extra) {
|
|
537
|
+
const message = msg?.message ?? msg;
|
|
538
|
+
if (getLevel(this.level) >= getLevel("error")) {
|
|
539
|
+
this.output("red")(message, extra);
|
|
540
|
+
}
|
|
541
|
+
const { errCode, ...rest } = extra;
|
|
542
|
+
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
543
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
544
|
+
code: errorCode,
|
|
545
|
+
msg: message,
|
|
546
|
+
data: rest
|
|
547
|
+
});
|
|
548
|
+
this.callKit.reset();
|
|
549
|
+
const error = new Error(message);
|
|
550
|
+
error.name = "CallKitError";
|
|
551
|
+
error.code = errorCode;
|
|
552
|
+
error.data = rest;
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
addLogData(type, data = {}) {
|
|
556
|
+
this.callKit.user.sendSdkLog({
|
|
557
|
+
...data,
|
|
558
|
+
type,
|
|
559
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
560
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
561
|
+
});
|
|
562
|
+
if (!this.callKit.config.isLogGatherEnable()) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
let logData = {
|
|
566
|
+
type,
|
|
567
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
568
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
569
|
+
data: ""
|
|
570
|
+
};
|
|
571
|
+
if (type === LogDataEnum.INCALL) {
|
|
572
|
+
logData.data = (0, import_json_stringify_safe.default)({
|
|
573
|
+
// customField
|
|
574
|
+
callKitSocketFrom: data?.callKitSocketFrom,
|
|
575
|
+
type: data?.ev.type || data?.type,
|
|
576
|
+
data: data?.ev.data || data?.data,
|
|
577
|
+
// message
|
|
578
|
+
origin: data?.ev.origin || data?.origin,
|
|
579
|
+
lastEventId: data?.ev.lastEventId || data?.lastEventId,
|
|
580
|
+
isTrusted: data?.ev.isTrusted || data?.isTrusted,
|
|
581
|
+
// close
|
|
582
|
+
code: data?.ev.code || data?.code,
|
|
583
|
+
reason: data?.ev.reason || data?.reason,
|
|
584
|
+
wasClean: data?.ev.wasClean || data?.wasClean
|
|
585
|
+
});
|
|
586
|
+
} else {
|
|
587
|
+
logData = (0, import_json_stringify_safe.default)(data);
|
|
588
|
+
}
|
|
589
|
+
switch (type) {
|
|
590
|
+
case LogDataEnum.SIP:
|
|
591
|
+
this.logData.sip.push(logData);
|
|
592
|
+
this.logData.all.push(logData);
|
|
593
|
+
break;
|
|
594
|
+
case LogDataEnum.INCALL:
|
|
595
|
+
this.logData.incall.push(logData);
|
|
596
|
+
this.logData.all.push(logData);
|
|
597
|
+
break;
|
|
598
|
+
case LogDataEnum.AJAX:
|
|
599
|
+
this.logData.ajax.push(logData);
|
|
600
|
+
this.logData.all.push(logData);
|
|
601
|
+
break;
|
|
602
|
+
case LogDataEnum.RECONNECT:
|
|
603
|
+
this.logData.reconnect.push(logData);
|
|
604
|
+
this.logData.all.push(logData);
|
|
605
|
+
break;
|
|
606
|
+
case LogDataEnum.ERROR:
|
|
607
|
+
this.logData.error.push(logData);
|
|
608
|
+
this.logData.all.push(logData);
|
|
609
|
+
break;
|
|
610
|
+
default:
|
|
611
|
+
this.logData.all.push(logData);
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
output(color) {
|
|
616
|
+
return (msg, extra = {}) => {
|
|
617
|
+
const now = /* @__PURE__ */ new Date();
|
|
618
|
+
if (Object.keys(extra).length > 0) {
|
|
619
|
+
console.log(
|
|
620
|
+
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
621
|
+
`color: ${color};`,
|
|
622
|
+
"color:block;",
|
|
623
|
+
extra,
|
|
624
|
+
"color:#999;"
|
|
625
|
+
);
|
|
626
|
+
} else {
|
|
627
|
+
console.log(
|
|
628
|
+
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
629
|
+
`color: ${color};`,
|
|
630
|
+
"color:block;",
|
|
631
|
+
"color:#999;"
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// package/api.ts
|
|
639
|
+
var Api = class {
|
|
640
|
+
callKit;
|
|
641
|
+
constructor(callKit) {
|
|
642
|
+
this.callKit = callKit;
|
|
643
|
+
}
|
|
644
|
+
async login(params) {
|
|
645
|
+
return this.post({
|
|
646
|
+
url: "/auth/agentUser/login",
|
|
647
|
+
method: "post",
|
|
648
|
+
data: params
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
async loginOut(params) {
|
|
652
|
+
return this.post({
|
|
653
|
+
url: "/auth/agentUser/loginOut",
|
|
654
|
+
method: "post",
|
|
655
|
+
data: params
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* @description sdkLog
|
|
660
|
+
* @param params
|
|
661
|
+
* @returns
|
|
662
|
+
*/
|
|
663
|
+
async sdkLog(data) {
|
|
664
|
+
const strLog = Logger.formatStrLog(data);
|
|
665
|
+
const allData = [this.callKit.logger.sendSdkLogData, strLog].join(",");
|
|
666
|
+
const encoder = new TextEncoder();
|
|
667
|
+
const size = encoder.encode(allData).length;
|
|
668
|
+
if (size < 8192) {
|
|
669
|
+
this.callKit.logger.sendSdkLogData.push(strLog);
|
|
670
|
+
} else {
|
|
671
|
+
const logsToSend = this.callKit.logger.sendSdkLogData.slice();
|
|
672
|
+
this.callKit.logger.sendSdkLogData = [strLog];
|
|
673
|
+
return this.post(
|
|
674
|
+
{
|
|
675
|
+
url: "/agent/user/sdkLog",
|
|
676
|
+
method: "post",
|
|
677
|
+
data: {
|
|
678
|
+
content: logsToSend
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
useFormData: true
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
*
|
|
689
|
+
* @param params agentId userStatus
|
|
690
|
+
* @description userStatus: Logout(1, "unregistered"), Free(2, "free"), Break(3, "nap"), Busy(4, "busy")
|
|
691
|
+
* @returns
|
|
692
|
+
*/
|
|
693
|
+
async setUserStatus(params) {
|
|
694
|
+
return this.post({
|
|
695
|
+
url: "/agent/user/changeStatus",
|
|
696
|
+
method: "post",
|
|
697
|
+
data: params
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
async post(config, extra = {}) {
|
|
701
|
+
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
702
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
703
|
+
const { sessionId } = userInfo;
|
|
704
|
+
config.url = `${host}${config.url}`;
|
|
705
|
+
config.headers = {
|
|
706
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
707
|
+
...config.headers
|
|
708
|
+
};
|
|
709
|
+
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded" && extra.useFormData) {
|
|
710
|
+
const formData = new FormData();
|
|
711
|
+
const data2 = config.data || {};
|
|
712
|
+
for (const key in data2) {
|
|
713
|
+
if (Object.prototype.hasOwnProperty.call(data2, key)) {
|
|
714
|
+
formData.append(key, data2[key]);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
config.data = formData;
|
|
718
|
+
} else {
|
|
719
|
+
config.data = new URLSearchParams(config.data).toString();
|
|
720
|
+
}
|
|
721
|
+
if (sessionId) {
|
|
722
|
+
config.headers.sessionId = sessionId;
|
|
723
|
+
}
|
|
724
|
+
const res = await axios_default(config).catch(() => {
|
|
725
|
+
this.callKit.config.reset();
|
|
726
|
+
});
|
|
727
|
+
if (!res) {
|
|
728
|
+
this.callKit.config.reset();
|
|
729
|
+
throw new Error("Network error");
|
|
730
|
+
} else {
|
|
731
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
732
|
+
...config,
|
|
733
|
+
status: "success",
|
|
734
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
735
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
const { code, data, message } = res;
|
|
739
|
+
if (code === "000000") {
|
|
740
|
+
return data;
|
|
741
|
+
}
|
|
742
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
743
|
+
...config,
|
|
744
|
+
status: "error",
|
|
745
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
746
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
747
|
+
});
|
|
748
|
+
if (code === "100013") {
|
|
749
|
+
this.callKit.config.reset();
|
|
750
|
+
}
|
|
751
|
+
throw new Error(message ?? "Request failed");
|
|
752
|
+
}
|
|
494
753
|
};
|
|
495
754
|
|
|
496
755
|
// package/call.ts
|
|
@@ -534,12 +793,6 @@ var Call = class {
|
|
|
534
793
|
if (!this.callKit.config.check())
|
|
535
794
|
return;
|
|
536
795
|
this.callKit.logger.debug("callRefer");
|
|
537
|
-
const { toAgentId, workOrderId } = options;
|
|
538
|
-
const queryTrain = {
|
|
539
|
-
toAgentId,
|
|
540
|
-
workOrderId
|
|
541
|
-
};
|
|
542
|
-
this.callKit.socket.send(SocketSendEvent.AGENT_TRANSFER, queryTrain);
|
|
543
796
|
this.callKit.connect.refer(referTo, options);
|
|
544
797
|
}
|
|
545
798
|
/**
|
|
@@ -586,7 +839,7 @@ var Config = class {
|
|
|
586
839
|
this.callKit = callKit;
|
|
587
840
|
}
|
|
588
841
|
config = {
|
|
589
|
-
version: "1.0.
|
|
842
|
+
version: "1.0.24-beta.30",
|
|
590
843
|
host: "",
|
|
591
844
|
log: "debug",
|
|
592
845
|
audioRef: void 0,
|
|
@@ -612,7 +865,8 @@ var Config = class {
|
|
|
612
865
|
fsPort: "",
|
|
613
866
|
iceInfo: [],
|
|
614
867
|
iceGatheringTimeout: 0,
|
|
615
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
868
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
869
|
+
logGather: LogGatherEnum.DISABLE
|
|
616
870
|
},
|
|
617
871
|
// EXECUTE setUserStatus
|
|
618
872
|
isAutoUpdateUserStatus: true
|
|
@@ -644,7 +898,8 @@ var Config = class {
|
|
|
644
898
|
fsPort: "",
|
|
645
899
|
iceInfo: [],
|
|
646
900
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
647
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
901
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
902
|
+
logGather: LogGatherEnum.DISABLE
|
|
648
903
|
};
|
|
649
904
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
650
905
|
}
|
|
@@ -657,6 +912,7 @@ var Config = class {
|
|
|
657
912
|
return true;
|
|
658
913
|
};
|
|
659
914
|
isLogin = () => this.validate();
|
|
915
|
+
isLogGatherEnable = () => this.config.userInfo.logGather === LogGatherEnum.ENABLE;
|
|
660
916
|
check() {
|
|
661
917
|
if (!this.isLogin()) {
|
|
662
918
|
this.callKit.logger.error("User not logged in", {
|
|
@@ -668,78 +924,6 @@ var Config = class {
|
|
|
668
924
|
}
|
|
669
925
|
};
|
|
670
926
|
|
|
671
|
-
// package/logger.ts
|
|
672
|
-
function getLevel(level) {
|
|
673
|
-
return LoggerLevelMap[level];
|
|
674
|
-
}
|
|
675
|
-
var Logger = class {
|
|
676
|
-
prefix = "CallKit";
|
|
677
|
-
level = "debug";
|
|
678
|
-
callKit;
|
|
679
|
-
constructor(callKit, level) {
|
|
680
|
-
this.callKit = callKit;
|
|
681
|
-
this.level = level || "debug";
|
|
682
|
-
}
|
|
683
|
-
setLevel(level) {
|
|
684
|
-
this.level = level;
|
|
685
|
-
}
|
|
686
|
-
debug(msg, extra) {
|
|
687
|
-
if (getLevel(this.level) >= getLevel("debug")) {
|
|
688
|
-
this.output("blue")(msg, extra);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
log(msg, extra) {
|
|
692
|
-
if (getLevel(this.level) >= getLevel("log")) {
|
|
693
|
-
this.output("green")(msg, extra);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
warn(msg, extra) {
|
|
697
|
-
if (getLevel(this.level) >= getLevel("warn")) {
|
|
698
|
-
this.output("orange")(msg, extra);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
error(msg, extra) {
|
|
702
|
-
const message = msg?.message ?? msg;
|
|
703
|
-
if (getLevel(this.level) >= getLevel("error")) {
|
|
704
|
-
this.output("red")(message, extra);
|
|
705
|
-
}
|
|
706
|
-
const { errCode, ...rest } = extra;
|
|
707
|
-
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
708
|
-
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
709
|
-
code: errorCode,
|
|
710
|
-
msg: message,
|
|
711
|
-
data: rest
|
|
712
|
-
});
|
|
713
|
-
this.callKit.reset();
|
|
714
|
-
const error = new Error(message);
|
|
715
|
-
error.name = "CallKitError";
|
|
716
|
-
error.code = errorCode;
|
|
717
|
-
error.data = rest;
|
|
718
|
-
throw error;
|
|
719
|
-
}
|
|
720
|
-
output(color) {
|
|
721
|
-
return (msg, extra = {}) => {
|
|
722
|
-
const now = /* @__PURE__ */ new Date();
|
|
723
|
-
if (Object.keys(extra).length > 0) {
|
|
724
|
-
console.log(
|
|
725
|
-
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
726
|
-
`color: ${color};`,
|
|
727
|
-
"color:block;",
|
|
728
|
-
extra,
|
|
729
|
-
"color:#999;"
|
|
730
|
-
);
|
|
731
|
-
} else {
|
|
732
|
-
console.log(
|
|
733
|
-
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
734
|
-
`color: ${color};`,
|
|
735
|
-
"color:block;",
|
|
736
|
-
"color:#999;"
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
|
|
743
927
|
// package/connect.ts
|
|
744
928
|
var import_sip = require("sip.js");
|
|
745
929
|
var DEFAULT_RECONNECT_CONFIG = {
|
|
@@ -763,7 +947,9 @@ var initUserMedia = () => {
|
|
|
763
947
|
const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
|
764
948
|
if (!getUserMedia) {
|
|
765
949
|
return Promise.reject(
|
|
766
|
-
new Error(
|
|
950
|
+
new Error(
|
|
951
|
+
"Unable to obtain device permissions. Please check your browser settings or device permissions."
|
|
952
|
+
)
|
|
767
953
|
);
|
|
768
954
|
}
|
|
769
955
|
return new Promise((resolve, reject) => {
|
|
@@ -784,7 +970,7 @@ var Connect = class {
|
|
|
784
970
|
registerer;
|
|
785
971
|
lastOptionsUpdateTime = 0;
|
|
786
972
|
observeOptionsHeartbeatHandler = null;
|
|
787
|
-
sipConnected = false;
|
|
973
|
+
// sipConnected = false;
|
|
788
974
|
/**
|
|
789
975
|
* Whether it's an outgoing call
|
|
790
976
|
*/
|
|
@@ -793,6 +979,7 @@ var Connect = class {
|
|
|
793
979
|
* Whether it's an active hangup
|
|
794
980
|
*/
|
|
795
981
|
isUnprompted = false;
|
|
982
|
+
isCurrentSessionInvited = false;
|
|
796
983
|
reconnectConfig;
|
|
797
984
|
/**
|
|
798
985
|
* Whether registered
|
|
@@ -832,7 +1019,6 @@ var Connect = class {
|
|
|
832
1019
|
this.registerer = void 0;
|
|
833
1020
|
this.isOutgoing = false;
|
|
834
1021
|
this.isUnprompted = false;
|
|
835
|
-
this.sipConnected = false;
|
|
836
1022
|
this.clearObserveOptionsHeartbeatInterval();
|
|
837
1023
|
if (this.isHold) {
|
|
838
1024
|
this.setHoldStatus(false);
|
|
@@ -846,7 +1032,7 @@ var Connect = class {
|
|
|
846
1032
|
return audioRef;
|
|
847
1033
|
}
|
|
848
1034
|
async permission() {
|
|
849
|
-
this.callKit.logger.debug("
|
|
1035
|
+
this.callKit.logger.debug("ssion");
|
|
850
1036
|
initUserMedia();
|
|
851
1037
|
const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
852
1038
|
closeStream(_stream);
|
|
@@ -893,6 +1079,9 @@ var Connect = class {
|
|
|
893
1079
|
isInit() {
|
|
894
1080
|
return this.connectStatus === CallStatus.init;
|
|
895
1081
|
}
|
|
1082
|
+
isExecuting() {
|
|
1083
|
+
return this.callKit.user.getUserChangeStatusExecuting();
|
|
1084
|
+
}
|
|
896
1085
|
clearObserveOptionsHeartbeatInterval() {
|
|
897
1086
|
if (this.observeOptionsHeartbeatHandler !== null) {
|
|
898
1087
|
clearInterval(this.observeOptionsHeartbeatHandler);
|
|
@@ -972,13 +1161,18 @@ var Connect = class {
|
|
|
972
1161
|
that.userAgent.transport.onDisconnect = (error) => {
|
|
973
1162
|
if (error) {
|
|
974
1163
|
that.callKit.logger.debug("connect onDisconnect");
|
|
975
|
-
if (that.isRegistered() &&
|
|
1164
|
+
if (that.isRegistered() && !// that.sipConnected ||
|
|
1165
|
+
(that.isRinging() || that.isCalling() || that.isHolding())) {
|
|
976
1166
|
that.reconnect();
|
|
977
1167
|
} else {
|
|
978
1168
|
that.callKit.logger.debug("SIP WebSocket closed with error", {
|
|
979
1169
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
980
1170
|
err: error
|
|
981
1171
|
});
|
|
1172
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1173
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1174
|
+
err: error
|
|
1175
|
+
});
|
|
982
1176
|
that.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
983
1177
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
984
1178
|
err: error
|
|
@@ -994,7 +1188,7 @@ var Connect = class {
|
|
|
994
1188
|
}
|
|
995
1189
|
};
|
|
996
1190
|
that.clearObserveOptionsHeartbeatInterval();
|
|
997
|
-
setInterval(() => {
|
|
1191
|
+
that.observeOptionsHeartbeatHandler = setInterval(() => {
|
|
998
1192
|
if (that.lastOptionsUpdateTime !== 0) {
|
|
999
1193
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1000
1194
|
const diff = now - that.lastOptionsUpdateTime;
|
|
@@ -1009,6 +1203,11 @@ var Connect = class {
|
|
|
1009
1203
|
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1010
1204
|
now
|
|
1011
1205
|
});
|
|
1206
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1207
|
+
event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
1208
|
+
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1209
|
+
now
|
|
1210
|
+
});
|
|
1012
1211
|
that.clearObserveOptionsHeartbeatInterval();
|
|
1013
1212
|
}
|
|
1014
1213
|
}
|
|
@@ -1020,38 +1219,118 @@ var Connect = class {
|
|
|
1020
1219
|
if (request2.method === "OPTIONS") {
|
|
1021
1220
|
that.lastOptionsUpdateTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1022
1221
|
}
|
|
1222
|
+
that.callKit.logger.addLogData(LogDataEnum.SIP, request2);
|
|
1023
1223
|
return originalReceiveRequest(request2);
|
|
1024
1224
|
};
|
|
1025
1225
|
};
|
|
1026
1226
|
const registererOptions = {};
|
|
1027
1227
|
this.registerer = new import_sip.Registerer(this.userAgent, registererOptions);
|
|
1228
|
+
this.registerer.stateChange.addListener((state) => {
|
|
1229
|
+
switch (state) {
|
|
1230
|
+
case import_sip.RegistererState.Initial:
|
|
1231
|
+
this.callKit.logger.debug("registerer stateChange Initial");
|
|
1232
|
+
this.setRegister(false);
|
|
1233
|
+
this.setConnectStatus(CallStatus.init);
|
|
1234
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1235
|
+
this.callKit.trigger(
|
|
1236
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1237
|
+
SipRegistererEvent.Initial
|
|
1238
|
+
);
|
|
1239
|
+
break;
|
|
1240
|
+
case import_sip.RegistererState.Registered:
|
|
1241
|
+
this.callKit.logger.debug("registerer stateChange Registered");
|
|
1242
|
+
this.setRegister(true);
|
|
1243
|
+
this.setConnectStatus(CallStatus.registered);
|
|
1244
|
+
this.callKit.user.setUserStatus(UserStatus.online);
|
|
1245
|
+
this.callKit.trigger(
|
|
1246
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1247
|
+
SipRegistererEvent.Registered
|
|
1248
|
+
);
|
|
1249
|
+
break;
|
|
1250
|
+
case import_sip.RegistererState.Terminated:
|
|
1251
|
+
this.callKit.logger.debug("registerer stateChange Terminated");
|
|
1252
|
+
this.setRegister(false);
|
|
1253
|
+
this.setConnectStatus(CallStatus.init);
|
|
1254
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1255
|
+
this.callKit.trigger(
|
|
1256
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1257
|
+
SipRegistererEvent.Terminated
|
|
1258
|
+
);
|
|
1259
|
+
break;
|
|
1260
|
+
case import_sip.RegistererState.Unregistered:
|
|
1261
|
+
this.callKit.logger.debug("registerer stateChange Unregistered");
|
|
1262
|
+
this.setRegister(false);
|
|
1263
|
+
this.setConnectStatus(CallStatus.init);
|
|
1264
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
1265
|
+
this.callKit.trigger(
|
|
1266
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
1267
|
+
SipRegistererEvent.Unregistered
|
|
1268
|
+
);
|
|
1269
|
+
break;
|
|
1270
|
+
default:
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1028
1274
|
this.userAgent.delegate = {
|
|
1029
1275
|
onInvite: (invite) => {
|
|
1030
1276
|
this.callKit.logger.debug("connect onInvite");
|
|
1031
1277
|
this.currentSession = invite;
|
|
1278
|
+
if (this.isOutgoing) {
|
|
1279
|
+
this.isCurrentSessionInvited = false;
|
|
1280
|
+
}
|
|
1032
1281
|
this.currentSession.stateChange.addListener((state) => {
|
|
1282
|
+
const isExecuting = this.isExecuting();
|
|
1033
1283
|
switch (state) {
|
|
1034
1284
|
case import_sip.SessionState.Establishing:
|
|
1035
1285
|
this.callKit.logger.debug("connect Establishing");
|
|
1286
|
+
this.setConnectStatus(CallStatus.ringing);
|
|
1287
|
+
if (!isExecuting) {
|
|
1288
|
+
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
1289
|
+
this.callKit.trigger(
|
|
1290
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1291
|
+
SipSessionEvent.Establishing
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1036
1294
|
break;
|
|
1037
1295
|
case import_sip.SessionState.Established:
|
|
1038
1296
|
this.callKit.logger.debug("connect Established");
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1297
|
+
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
1298
|
+
if (!isExecuting) {
|
|
1299
|
+
this.callKit.trigger(
|
|
1300
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1301
|
+
SipSessionEvent.Established
|
|
1302
|
+
);
|
|
1303
|
+
setupRemoteMedia(this.currentSession);
|
|
1042
1304
|
}
|
|
1043
|
-
this.sipConnected = true;
|
|
1044
|
-
setupRemoteMedia(this.currentSession);
|
|
1045
1305
|
break;
|
|
1046
1306
|
case import_sip.SessionState.Terminating:
|
|
1047
1307
|
this.callKit.logger.debug("connect Terminating");
|
|
1308
|
+
if (!isExecuting) {
|
|
1309
|
+
this.callKit.trigger(
|
|
1310
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1311
|
+
SipSessionEvent.Terminating
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1048
1314
|
break;
|
|
1049
1315
|
case import_sip.SessionState.Terminated:
|
|
1050
1316
|
this.callKit.logger.debug("connect Terminated");
|
|
1051
1317
|
if (!this.isUnprompted) {
|
|
1052
1318
|
this.callKit.callCenter.callEnd();
|
|
1319
|
+
} else if (this.isCalling()) {
|
|
1320
|
+
if (this.isCurrentSessionInvited) {
|
|
1321
|
+
this.currentSession.reject();
|
|
1322
|
+
}
|
|
1323
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
1053
1324
|
}
|
|
1054
1325
|
this.isUnprompted = false;
|
|
1326
|
+
if (!isExecuting) {
|
|
1327
|
+
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1328
|
+
this.setConnectStatus(CallStatus.registered);
|
|
1329
|
+
this.callKit.trigger(
|
|
1330
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
1331
|
+
SipSessionEvent.Terminated
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1055
1334
|
break;
|
|
1056
1335
|
default:
|
|
1057
1336
|
break;
|
|
@@ -1065,17 +1344,37 @@ var Connect = class {
|
|
|
1065
1344
|
};
|
|
1066
1345
|
if (this.isOutgoing) {
|
|
1067
1346
|
this.currentSession.accept(options);
|
|
1347
|
+
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
1348
|
+
getInviteData: () => {
|
|
1349
|
+
const { request: request2 } = this.currentSession;
|
|
1350
|
+
const headerNames = Object.keys(request2.headers);
|
|
1351
|
+
const xHeaders = {};
|
|
1352
|
+
headerNames.filter(
|
|
1353
|
+
(name) => name.toLocaleLowerCase().startsWith("x-antaios")
|
|
1354
|
+
).forEach((name) => {
|
|
1355
|
+
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
1356
|
+
});
|
|
1357
|
+
this.callKit.logger.debug("get invite data", xHeaders);
|
|
1358
|
+
return xHeaders;
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1068
1361
|
} else {
|
|
1362
|
+
const isExecuting = this.isExecuting();
|
|
1363
|
+
const reject = () => {
|
|
1364
|
+
this.currentSession.reject();
|
|
1365
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
1366
|
+
};
|
|
1367
|
+
if (isExecuting) {
|
|
1368
|
+
reject();
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1069
1371
|
this.callKit.trigger(KitEvent.KIT_INVITE, {
|
|
1070
1372
|
accept: () => {
|
|
1071
|
-
this.
|
|
1373
|
+
this.isCurrentSessionInvited = true;
|
|
1072
1374
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
1073
1375
|
this.currentSession.accept(options);
|
|
1074
1376
|
},
|
|
1075
|
-
reject
|
|
1076
|
-
this.currentSession.reject();
|
|
1077
|
-
this.callKit.callCenter.callEnd(true, false);
|
|
1078
|
-
},
|
|
1377
|
+
reject,
|
|
1079
1378
|
getInviteData: () => {
|
|
1080
1379
|
const { request: request2 } = this.currentSession;
|
|
1081
1380
|
const headerNames = Object.keys(request2.headers);
|
|
@@ -1093,9 +1392,12 @@ var Connect = class {
|
|
|
1093
1392
|
},
|
|
1094
1393
|
onConnect: async () => {
|
|
1095
1394
|
this.callKit.logger.debug("connect onConnect");
|
|
1395
|
+
const version = `V${this.callKit.config.getConfig().version}`;
|
|
1096
1396
|
await this.registerer.register().then(() => {
|
|
1097
|
-
this.callKit.socket.send(SocketSendEvent.START
|
|
1098
|
-
|
|
1397
|
+
this.callKit.socket.send(SocketSendEvent.START, {
|
|
1398
|
+
version
|
|
1399
|
+
});
|
|
1400
|
+
}).catch(async (err) => {
|
|
1099
1401
|
this.callKit.logger.error(err?.message, {
|
|
1100
1402
|
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
1101
1403
|
});
|
|
@@ -1103,13 +1405,18 @@ var Connect = class {
|
|
|
1103
1405
|
},
|
|
1104
1406
|
onDisconnect: (error) => {
|
|
1105
1407
|
this.callKit.logger.debug("connect onDisconnect");
|
|
1106
|
-
if (this.isRegistered() &&
|
|
1408
|
+
if (this.isRegistered() && !// this.sipConnected ||
|
|
1409
|
+
(this.isRinging() || this.isCalling() || this.isHolding())) {
|
|
1107
1410
|
this.reconnect();
|
|
1108
1411
|
} else {
|
|
1109
1412
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1110
1413
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1111
1414
|
err: error
|
|
1112
1415
|
});
|
|
1416
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
1417
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1418
|
+
err: error
|
|
1419
|
+
});
|
|
1113
1420
|
this.callKit.user.sendHangUpReason({
|
|
1114
1421
|
eventType: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
1115
1422
|
err: error
|
|
@@ -1161,6 +1468,11 @@ var Connect = class {
|
|
|
1161
1468
|
return;
|
|
1162
1469
|
reconnectTimer = setTimeout(async () => {
|
|
1163
1470
|
try {
|
|
1471
|
+
if (currentRetry === 0) {
|
|
1472
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1473
|
+
event: ConnectEvent.SIP_RECONNECT_START
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1164
1476
|
currentRetry += 1;
|
|
1165
1477
|
this.callKit.logger.debug(
|
|
1166
1478
|
`Attempting to reconnect SIP... (Attempt ${currentRetry}/${this.reconnectConfig.maxAttempts})`
|
|
@@ -1203,9 +1515,7 @@ var Connect = class {
|
|
|
1203
1515
|
this.callKit.logger.warn("No registerer to unregister.");
|
|
1204
1516
|
return;
|
|
1205
1517
|
}
|
|
1206
|
-
await this.registerer.unregister({ all: true }).
|
|
1207
|
-
this.setConnectStatus(CallStatus.init);
|
|
1208
|
-
}).catch((err) => {
|
|
1518
|
+
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
1209
1519
|
this.callKit.logger.error(err, {
|
|
1210
1520
|
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1211
1521
|
});
|
|
@@ -1236,12 +1546,6 @@ var Connect = class {
|
|
|
1236
1546
|
*/
|
|
1237
1547
|
setConnectStatus(status) {
|
|
1238
1548
|
this.callKit.logger.debug(`connect setConnectStatus: ${status}`);
|
|
1239
|
-
if (this.isRegistered() && status === CallStatus.init) {
|
|
1240
|
-
this.setRegister(false);
|
|
1241
|
-
}
|
|
1242
|
-
if (!this.isRegistered() && status !== CallStatus.init) {
|
|
1243
|
-
this.setRegister(true);
|
|
1244
|
-
}
|
|
1245
1549
|
this.connectStatus = status;
|
|
1246
1550
|
this.callKit.trigger(KitEvent.KIT_CALL_STATUS_CHANGE, status);
|
|
1247
1551
|
}
|
|
@@ -1259,13 +1563,14 @@ var Connect = class {
|
|
|
1259
1563
|
this.isUnprompted = isUnprompted;
|
|
1260
1564
|
try {
|
|
1261
1565
|
if (isUnprompted) {
|
|
1262
|
-
|
|
1263
|
-
|
|
1566
|
+
const shouldSendBye = (
|
|
1567
|
+
// this.sipConnected ||
|
|
1568
|
+
this.isRinging() || this.isCalling() || this.isHolding()
|
|
1569
|
+
);
|
|
1264
1570
|
if (shouldSendBye) {
|
|
1265
1571
|
await this.currentSession?.bye();
|
|
1266
1572
|
}
|
|
1267
1573
|
}
|
|
1268
|
-
this.sipConnected = false;
|
|
1269
1574
|
closeStream(this.mediaStream);
|
|
1270
1575
|
const audioRef = this.getAduioReference();
|
|
1271
1576
|
if (audioRef) {
|
|
@@ -1274,8 +1579,6 @@ var Connect = class {
|
|
|
1274
1579
|
}
|
|
1275
1580
|
if (isError) {
|
|
1276
1581
|
this.setConnectStatus(CallStatus.init);
|
|
1277
|
-
} else {
|
|
1278
|
-
this.setConnectStatus(CallStatus.registered);
|
|
1279
1582
|
}
|
|
1280
1583
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
1281
1584
|
} catch (err) {
|
|
@@ -1406,59 +1709,6 @@ var Connect = class {
|
|
|
1406
1709
|
}
|
|
1407
1710
|
};
|
|
1408
1711
|
|
|
1409
|
-
// package/monitor.ts
|
|
1410
|
-
var import_axios3 = __toESM(require("axios"));
|
|
1411
|
-
var defaultConfig = {
|
|
1412
|
-
interval: 5e3,
|
|
1413
|
-
apiEndpoint: "/livez"
|
|
1414
|
-
};
|
|
1415
|
-
var Monitor = class {
|
|
1416
|
-
callKit;
|
|
1417
|
-
interval = defaultConfig.interval;
|
|
1418
|
-
apiEndpoint = defaultConfig.apiEndpoint;
|
|
1419
|
-
monitorIntervalHandler = null;
|
|
1420
|
-
constructor(callKit) {
|
|
1421
|
-
this.callKit = callKit;
|
|
1422
|
-
const { monitor } = this.callKit.config.getConfig();
|
|
1423
|
-
this.interval = monitor?.interval ?? defaultConfig.interval;
|
|
1424
|
-
this.apiEndpoint = monitor?.apiEndpoint ?? defaultConfig.apiEndpoint;
|
|
1425
|
-
this.monitorIntervalHandler = null;
|
|
1426
|
-
}
|
|
1427
|
-
getEndPointPath = () => {
|
|
1428
|
-
const config = this.callKit.config.getConfig();
|
|
1429
|
-
const defaultPath = `${config.host}${this.apiEndpoint}`;
|
|
1430
|
-
const endPointPath = config.monitor?.apiEndpoint ?? defaultPath;
|
|
1431
|
-
return endPointPath;
|
|
1432
|
-
};
|
|
1433
|
-
measureRTT = async () => {
|
|
1434
|
-
try {
|
|
1435
|
-
const endPoint = this.getEndPointPath();
|
|
1436
|
-
const startTime = performance.now();
|
|
1437
|
-
await import_axios3.default.get(endPoint);
|
|
1438
|
-
const endTime = performance.now();
|
|
1439
|
-
const rtt = Math.round(endTime - startTime);
|
|
1440
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
1441
|
-
event: NetWorkEvent.RTT_MEASURE_SUCCESS,
|
|
1442
|
-
rtt
|
|
1443
|
-
});
|
|
1444
|
-
} catch (error) {
|
|
1445
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
1446
|
-
event: NetWorkEvent.RTT_MEASURE_FAILED,
|
|
1447
|
-
rtt: 0
|
|
1448
|
-
});
|
|
1449
|
-
}
|
|
1450
|
-
};
|
|
1451
|
-
stopRTTMonitoring() {
|
|
1452
|
-
if (this.monitorIntervalHandler) {
|
|
1453
|
-
clearInterval(this.monitorIntervalHandler);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
startRTTMonitoring() {
|
|
1457
|
-
this.stopRTTMonitoring();
|
|
1458
|
-
this.monitorIntervalHandler = setInterval(this.measureRTT, this.interval);
|
|
1459
|
-
}
|
|
1460
|
-
};
|
|
1461
|
-
|
|
1462
1712
|
// package/socket.ts
|
|
1463
1713
|
var RECONNECT_CONFIG = {
|
|
1464
1714
|
enabled: true,
|
|
@@ -1482,7 +1732,6 @@ var Socket = class {
|
|
|
1482
1732
|
reconnectTimer;
|
|
1483
1733
|
isReconnecting = false;
|
|
1484
1734
|
reconnectAttempts = 0;
|
|
1485
|
-
closing = false;
|
|
1486
1735
|
constructor(callKit) {
|
|
1487
1736
|
this.callKit = callKit;
|
|
1488
1737
|
const { reconnect } = this.callKit.config.getConfig();
|
|
@@ -1496,15 +1745,13 @@ var Socket = class {
|
|
|
1496
1745
|
this.callKit.logger.debug(`socket init: ${socket}`);
|
|
1497
1746
|
this.connect(socket);
|
|
1498
1747
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
});
|
|
1507
|
-
this.close(1e3, "normal");
|
|
1748
|
+
// confirm from connect startConfirm
|
|
1749
|
+
// startConfirm(status: boolean) {
|
|
1750
|
+
// this.callKit.logger.debug('register success');
|
|
1751
|
+
// this.satrtConfirm = status;
|
|
1752
|
+
// }
|
|
1753
|
+
setRecivedClose(status) {
|
|
1754
|
+
this.recivedClose = status;
|
|
1508
1755
|
}
|
|
1509
1756
|
reconnect(ev) {
|
|
1510
1757
|
this.callKit.logger.debug("socket reconnect", ev);
|
|
@@ -1514,12 +1761,21 @@ var Socket = class {
|
|
|
1514
1761
|
"socket reconnect times",
|
|
1515
1762
|
this.socketConfig.maxAttempts
|
|
1516
1763
|
);
|
|
1764
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1765
|
+
event: ConnectEvent.INCALL_RECONNECTING,
|
|
1766
|
+
attempts: this.reconnectAttempts,
|
|
1767
|
+
err: ev
|
|
1768
|
+
});
|
|
1517
1769
|
this.attemptReconnect();
|
|
1518
1770
|
} else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
1519
1771
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1520
1772
|
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
1521
1773
|
err: ev
|
|
1522
1774
|
});
|
|
1775
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1776
|
+
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
1777
|
+
err: ev
|
|
1778
|
+
});
|
|
1523
1779
|
this.reset();
|
|
1524
1780
|
this.callKit.logger.error(
|
|
1525
1781
|
"Reconnection failed, maximum retry attempts reached",
|
|
@@ -1538,6 +1794,10 @@ var Socket = class {
|
|
|
1538
1794
|
}
|
|
1539
1795
|
onOpen(ev) {
|
|
1540
1796
|
this.callKit.logger.debug("socket onOpen", ev);
|
|
1797
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1798
|
+
callKitSocketFrom: "onOpen",
|
|
1799
|
+
ev
|
|
1800
|
+
});
|
|
1541
1801
|
this.isConnected = true;
|
|
1542
1802
|
this.lastPingTime = Date.now();
|
|
1543
1803
|
this.checkPing();
|
|
@@ -1556,14 +1816,23 @@ var Socket = class {
|
|
|
1556
1816
|
}
|
|
1557
1817
|
onClose(ev) {
|
|
1558
1818
|
this.callKit.logger.debug("socket onClose", ev);
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1819
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1820
|
+
callKitSocketFrom: "onClose",
|
|
1821
|
+
ev
|
|
1822
|
+
});
|
|
1823
|
+
if ((ev.code !== 1e3 || !ev.wasClean) && this.callKit.connect.isRegistered()) {
|
|
1563
1824
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1564
1825
|
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1565
1826
|
err: ev
|
|
1566
1827
|
});
|
|
1828
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
1829
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1830
|
+
err: ev
|
|
1831
|
+
});
|
|
1832
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1833
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
1834
|
+
err: ev
|
|
1835
|
+
});
|
|
1567
1836
|
this.reconnect(ev);
|
|
1568
1837
|
} else {
|
|
1569
1838
|
this.isConnected = false;
|
|
@@ -1574,10 +1843,6 @@ var Socket = class {
|
|
|
1574
1843
|
}
|
|
1575
1844
|
this.callKit.connect.hangup();
|
|
1576
1845
|
this.reset();
|
|
1577
|
-
this.closing = false;
|
|
1578
|
-
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1579
|
-
event: ConnectEvent.CONNECT_CLOSING_END
|
|
1580
|
-
});
|
|
1581
1846
|
}
|
|
1582
1847
|
}
|
|
1583
1848
|
onError(ev) {
|
|
@@ -1585,46 +1850,53 @@ var Socket = class {
|
|
|
1585
1850
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
1586
1851
|
data: ev
|
|
1587
1852
|
});
|
|
1853
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1854
|
+
callKitSocketFrom: "onError",
|
|
1855
|
+
ev
|
|
1856
|
+
});
|
|
1588
1857
|
if (this.isReconnecting) {
|
|
1589
1858
|
this.attemptReconnect();
|
|
1590
1859
|
}
|
|
1591
1860
|
}
|
|
1861
|
+
confirmAck(data) {
|
|
1862
|
+
const { ack, messageId } = data;
|
|
1863
|
+
if (ack) {
|
|
1864
|
+
this.send(SocketSendEvent.ACK, {
|
|
1865
|
+
messageId
|
|
1866
|
+
// sessionId
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1592
1870
|
onMessage(ev) {
|
|
1593
1871
|
const data = JSON.parse(ev.data);
|
|
1594
1872
|
this.callKit.logger.debug("socket onMessage", data);
|
|
1873
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
1874
|
+
callKitSocketFrom: "onMessage",
|
|
1875
|
+
ev
|
|
1876
|
+
});
|
|
1877
|
+
this.confirmAck(data);
|
|
1595
1878
|
if (data.event === SocketReceiveEvent.PONG) {
|
|
1596
1879
|
this.lastPingTime = Date.now();
|
|
1597
1880
|
return;
|
|
1598
1881
|
}
|
|
1599
1882
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
1600
|
-
this.callKit.logger.debug("
|
|
1883
|
+
this.callKit.logger.debug("start confirm success");
|
|
1601
1884
|
this.satrtConfirm = true;
|
|
1602
|
-
this.callKit.connect.setConnectStatus(CallStatus.registered);
|
|
1603
1885
|
}
|
|
1604
1886
|
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
1605
1887
|
this.recivedClose = false;
|
|
1606
|
-
this.callKit.logger.debug("callStart");
|
|
1607
|
-
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
1608
1888
|
}
|
|
1609
1889
|
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
1610
1890
|
this.callKit.logger.debug(data.msg, {
|
|
1611
1891
|
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
1612
1892
|
});
|
|
1613
|
-
this.callKit.user.setUserStatus(UserStatus.online);
|
|
1614
1893
|
}
|
|
1615
1894
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
1616
|
-
this.callKit.
|
|
1617
|
-
if (this.callKit.connect.isConnecting()) {
|
|
1618
|
-
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
1619
|
-
this.callKit.connect.setConnectStatus(CallStatus.ringing);
|
|
1620
|
-
}
|
|
1895
|
+
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
1621
1896
|
}
|
|
1622
1897
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
1623
1898
|
this.callKit.logger.debug(data.msg);
|
|
1624
|
-
|
|
1625
|
-
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
1626
|
-
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
1627
|
-
}
|
|
1899
|
+
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
1628
1900
|
}
|
|
1629
1901
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
1630
1902
|
this.callKit.logger.debug(data.msg);
|
|
@@ -1633,12 +1905,10 @@ var Socket = class {
|
|
|
1633
1905
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
1634
1906
|
this.callKit.logger.debug(data.msg);
|
|
1635
1907
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
1636
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1637
1908
|
}
|
|
1638
1909
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
1639
1910
|
this.callKit.logger.debug(data.msg);
|
|
1640
1911
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
1641
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1642
1912
|
}
|
|
1643
1913
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
1644
1914
|
this.callKit.logger.debug(data.msg);
|
|
@@ -1646,7 +1916,7 @@ var Socket = class {
|
|
|
1646
1916
|
}
|
|
1647
1917
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
1648
1918
|
this.callKit.logger.debug(data.msg);
|
|
1649
|
-
this.
|
|
1919
|
+
this.setRecivedClose(true);
|
|
1650
1920
|
}
|
|
1651
1921
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
1652
1922
|
const { userInfo } = this.callKit.config.getConfig();
|
|
@@ -1656,19 +1926,21 @@ var Socket = class {
|
|
|
1656
1926
|
});
|
|
1657
1927
|
}
|
|
1658
1928
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
1659
|
-
this.callKit.
|
|
1929
|
+
this.callKit.unregister();
|
|
1930
|
+
this.callKit.logger.debug(data.msg, {
|
|
1660
1931
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
1661
1932
|
data
|
|
1662
1933
|
});
|
|
1663
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1664
1934
|
}
|
|
1665
1935
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
1666
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
1667
1936
|
}
|
|
1668
1937
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
1669
1938
|
}
|
|
1670
1939
|
send(event, message) {
|
|
1671
1940
|
if (!this.isConnected) {
|
|
1941
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1942
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
1943
|
+
});
|
|
1672
1944
|
this.callKit.logger.error("socket not connected", {
|
|
1673
1945
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
1674
1946
|
});
|
|
@@ -1711,6 +1983,9 @@ var Socket = class {
|
|
|
1711
1983
|
}
|
|
1712
1984
|
async sendMessage(event, message) {
|
|
1713
1985
|
if (!this.isConnected) {
|
|
1986
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1987
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
1988
|
+
});
|
|
1714
1989
|
this.callKit.logger.error("socket not connected", {
|
|
1715
1990
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
1716
1991
|
});
|
|
@@ -1785,11 +2060,16 @@ var Socket = class {
|
|
|
1785
2060
|
}
|
|
1786
2061
|
this.recivedClose = false;
|
|
1787
2062
|
this.callKit.logger.debug("socket destroy");
|
|
1788
|
-
this.ws.close(
|
|
2063
|
+
this.ws.close();
|
|
1789
2064
|
this.isConnected = false;
|
|
1790
2065
|
}
|
|
1791
2066
|
}
|
|
1792
2067
|
attemptReconnect() {
|
|
2068
|
+
if (this.reconnectAttempts === 0) {
|
|
2069
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
2070
|
+
event: ConnectEvent.INCALL_RECONNECT_START
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
1793
2073
|
if (this.isReconnecting && this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
1794
2074
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1795
2075
|
event: ConnectEvent.INCALL_RECONNECT_ERROR
|
|
@@ -1824,8 +2104,102 @@ var User = class {
|
|
|
1824
2104
|
callKit;
|
|
1825
2105
|
userStatus;
|
|
1826
2106
|
// logout(1, "unregistered"), idle(2, "free"), break(3, "nap"), busy(4, "busy")
|
|
2107
|
+
userChangeStatusExecuting;
|
|
1827
2108
|
constructor(callKit) {
|
|
1828
2109
|
this.callKit = callKit;
|
|
2110
|
+
this.userChangeStatusExecuting = false;
|
|
2111
|
+
}
|
|
2112
|
+
setUserChangeStatusExecuting(state) {
|
|
2113
|
+
this.userChangeStatusExecuting = state;
|
|
2114
|
+
}
|
|
2115
|
+
getUserChangeStatusExecuting() {
|
|
2116
|
+
return this.userChangeStatusExecuting;
|
|
2117
|
+
}
|
|
2118
|
+
async login(params) {
|
|
2119
|
+
const postData = {
|
|
2120
|
+
userName: params.userName,
|
|
2121
|
+
password: params.password
|
|
2122
|
+
};
|
|
2123
|
+
const logData = {
|
|
2124
|
+
postData,
|
|
2125
|
+
url: "/auth/agentUser/login",
|
|
2126
|
+
status: "send",
|
|
2127
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2128
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2129
|
+
};
|
|
2130
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2131
|
+
this.setUserChangeStatusExecuting(true);
|
|
2132
|
+
return this.callKit.api.login(params).then((user) => {
|
|
2133
|
+
this.setUserChangeStatusExecuting(false);
|
|
2134
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2135
|
+
...logData,
|
|
2136
|
+
status: "success",
|
|
2137
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2138
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2139
|
+
});
|
|
2140
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2141
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginEnd
|
|
2142
|
+
});
|
|
2143
|
+
return user;
|
|
2144
|
+
}).catch((err) => {
|
|
2145
|
+
this.setUserChangeStatusExecuting(false);
|
|
2146
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2147
|
+
...logData,
|
|
2148
|
+
status: "error",
|
|
2149
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2150
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2151
|
+
});
|
|
2152
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2153
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginError
|
|
2154
|
+
});
|
|
2155
|
+
this.callKit.logger.error(err, {
|
|
2156
|
+
errCode: ErrorCode.API_USER_LOGIN_ERROR
|
|
2157
|
+
});
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
async loginOut(params) {
|
|
2161
|
+
const postData = {
|
|
2162
|
+
sessionId: params.sessionId
|
|
2163
|
+
};
|
|
2164
|
+
const logData = {
|
|
2165
|
+
postData,
|
|
2166
|
+
url: "/auth/agentUser/loginOut",
|
|
2167
|
+
status: "send",
|
|
2168
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2169
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2170
|
+
};
|
|
2171
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2172
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2173
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutStart
|
|
2174
|
+
});
|
|
2175
|
+
this.setUserChangeStatusExecuting(true);
|
|
2176
|
+
return this.callKit.api.loginOut(postData).then((res) => {
|
|
2177
|
+
this.setUserChangeStatusExecuting(false);
|
|
2178
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2179
|
+
...logData,
|
|
2180
|
+
status: "success",
|
|
2181
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2182
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2183
|
+
});
|
|
2184
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2185
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutEnd
|
|
2186
|
+
});
|
|
2187
|
+
return res;
|
|
2188
|
+
}).catch((err) => {
|
|
2189
|
+
this.setUserChangeStatusExecuting(false);
|
|
2190
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2191
|
+
...logData,
|
|
2192
|
+
status: "error",
|
|
2193
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2194
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2195
|
+
});
|
|
2196
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2197
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutError
|
|
2198
|
+
});
|
|
2199
|
+
this.callKit.logger.error(err, {
|
|
2200
|
+
errCode: ErrorCode.API_USER_LOGOUT_ERROR
|
|
2201
|
+
});
|
|
2202
|
+
});
|
|
1829
2203
|
}
|
|
1830
2204
|
/**
|
|
1831
2205
|
*
|
|
@@ -1842,24 +2216,70 @@ var User = class {
|
|
|
1842
2216
|
* @param status
|
|
1843
2217
|
*/
|
|
1844
2218
|
async updateUserStatus(status) {
|
|
1845
|
-
|
|
1846
|
-
if (!this.callKit.config.isLogin()) {
|
|
1847
|
-
this.userStatus = UserStatus.offline;
|
|
1848
|
-
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, UserStatus.offline);
|
|
2219
|
+
if (this.userChangeStatusExecuting)
|
|
1849
2220
|
return;
|
|
1850
|
-
}
|
|
1851
|
-
|
|
2221
|
+
const { agentId } = this.callKit.config.getConfig().userInfo;
|
|
2222
|
+
this.setUserChangeStatusExecuting(true);
|
|
2223
|
+
const postData = {
|
|
1852
2224
|
agentId,
|
|
1853
2225
|
userStatus: status
|
|
1854
|
-
}
|
|
2226
|
+
};
|
|
2227
|
+
const logData = {
|
|
2228
|
+
postData,
|
|
2229
|
+
url: "/agent/user/changeStatus",
|
|
2230
|
+
status: "send",
|
|
2231
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2232
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2233
|
+
};
|
|
2234
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
2235
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2236
|
+
event: UserStatusChangeStepEnum.UserStatusChangeStart
|
|
2237
|
+
});
|
|
2238
|
+
await this.callKit.api.setUserStatus(postData).then(() => {
|
|
2239
|
+
this.setUserChangeStatusExecuting(false);
|
|
1855
2240
|
this.userStatus = status;
|
|
2241
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2242
|
+
event: UserStatusChangeStepEnum.UserStatusChangeEnd
|
|
2243
|
+
});
|
|
1856
2244
|
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, status);
|
|
2245
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2246
|
+
...logData,
|
|
2247
|
+
status: "success",
|
|
2248
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2249
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2250
|
+
});
|
|
1857
2251
|
}).catch((err) => {
|
|
2252
|
+
this.setUserChangeStatusExecuting(false);
|
|
2253
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
2254
|
+
...logData,
|
|
2255
|
+
status: "error",
|
|
2256
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
2257
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
2258
|
+
});
|
|
2259
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2260
|
+
event: UserStatusChangeStepEnum.UserStatusChangeError
|
|
2261
|
+
});
|
|
2262
|
+
this.setUserChangeStatusExecuting(false);
|
|
2263
|
+
if (this.callKit.connect.isRegistered()) {
|
|
2264
|
+
this.callKit.unregister();
|
|
2265
|
+
}
|
|
2266
|
+
this.callKit.trigger(
|
|
2267
|
+
KitEvent.KIT_USER_STATUS_CHANGE,
|
|
2268
|
+
UserStatus.offline
|
|
2269
|
+
);
|
|
1858
2270
|
this.callKit.logger.error(err, {
|
|
1859
2271
|
errCode: ErrorCode.API_USER_STATUS_UPDATE_ERROR
|
|
1860
2272
|
});
|
|
1861
2273
|
});
|
|
1862
2274
|
}
|
|
2275
|
+
/**
|
|
2276
|
+
* @description sdkLog
|
|
2277
|
+
* @param params
|
|
2278
|
+
* @returns
|
|
2279
|
+
*/
|
|
2280
|
+
async sendSdkLog(data) {
|
|
2281
|
+
return this.callKit.api.sdkLog(data);
|
|
2282
|
+
}
|
|
1863
2283
|
async sendHangUpReason(data) {
|
|
1864
2284
|
try {
|
|
1865
2285
|
const sendData = data || {};
|
|
@@ -1879,7 +2299,6 @@ var CallKit = class {
|
|
|
1879
2299
|
connect;
|
|
1880
2300
|
socket;
|
|
1881
2301
|
user;
|
|
1882
|
-
monitor;
|
|
1883
2302
|
listener = [];
|
|
1884
2303
|
constructor(options) {
|
|
1885
2304
|
this.config = new Config(this);
|
|
@@ -1897,8 +2316,6 @@ var CallKit = class {
|
|
|
1897
2316
|
);
|
|
1898
2317
|
this.config.setConfig("reconnect", options.reconnect);
|
|
1899
2318
|
this.logger = new Logger(this, options.log);
|
|
1900
|
-
this.config.setConfig("monitor", options.monitor);
|
|
1901
|
-
this.monitor = new Monitor(this);
|
|
1902
2319
|
this.logger.debug("callKit init", options);
|
|
1903
2320
|
this.api = new Api(this);
|
|
1904
2321
|
this.connect = new Connect(this);
|
|
@@ -1932,11 +2349,9 @@ var CallKit = class {
|
|
|
1932
2349
|
encryptionMethod,
|
|
1933
2350
|
encryptionPassword
|
|
1934
2351
|
});
|
|
1935
|
-
const user = await this.
|
|
2352
|
+
const user = await this.user.login({
|
|
1936
2353
|
userName: username,
|
|
1937
2354
|
password: encryptionPassword
|
|
1938
|
-
}).catch((err) => {
|
|
1939
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGIN_ERROR });
|
|
1940
2355
|
});
|
|
1941
2356
|
if (user) {
|
|
1942
2357
|
this.config.setConfig("userInfo", {
|
|
@@ -1953,6 +2368,7 @@ var CallKit = class {
|
|
|
1953
2368
|
fsPort: user.fsPort,
|
|
1954
2369
|
iceInfo: user.iceInfo,
|
|
1955
2370
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
2371
|
+
logGather: user.logGather,
|
|
1956
2372
|
// encryptionType is in extra
|
|
1957
2373
|
...extra
|
|
1958
2374
|
});
|
|
@@ -1968,12 +2384,7 @@ var CallKit = class {
|
|
|
1968
2384
|
await this.user.setUserStatus(UserStatus.offline);
|
|
1969
2385
|
if (this.config.isLogin()) {
|
|
1970
2386
|
const { sessionId } = this.config.getConfig().userInfo;
|
|
1971
|
-
this.
|
|
1972
|
-
this.stop();
|
|
1973
|
-
this.socket.gracefulClose();
|
|
1974
|
-
this.api.loginOut({ sessionId }).catch((err) => {
|
|
1975
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGOUT_ERROR });
|
|
1976
|
-
});
|
|
2387
|
+
this.user.loginOut({ sessionId });
|
|
1977
2388
|
}
|
|
1978
2389
|
await this.hangup();
|
|
1979
2390
|
this.socket.reset(false);
|
|
@@ -2016,14 +2427,12 @@ var CallKit = class {
|
|
|
2016
2427
|
return;
|
|
2017
2428
|
this.logger.debug("register");
|
|
2018
2429
|
this.connect.register();
|
|
2019
|
-
await this.user.setUserStatus(UserStatus.online);
|
|
2020
2430
|
}
|
|
2021
2431
|
async unregister() {
|
|
2022
2432
|
if (!this.config.check())
|
|
2023
2433
|
return;
|
|
2024
2434
|
this.logger.debug("unregister");
|
|
2025
2435
|
this.connect.unregister();
|
|
2026
|
-
await this.user.setUserStatus(UserStatus.offline);
|
|
2027
2436
|
}
|
|
2028
2437
|
async stop() {
|
|
2029
2438
|
await this.connect.stop();
|
|
@@ -2037,7 +2446,6 @@ var CallKit = class {
|
|
|
2037
2446
|
return;
|
|
2038
2447
|
}
|
|
2039
2448
|
await this.callCenter.callEnd(true);
|
|
2040
|
-
this.user.setUserStatus(UserStatus.catNap);
|
|
2041
2449
|
}
|
|
2042
2450
|
hold() {
|
|
2043
2451
|
if (!this.config.check())
|
|
@@ -2078,12 +2486,6 @@ var CallKit = class {
|
|
|
2078
2486
|
await this.user.setUserStatus(UserStatus.offline);
|
|
2079
2487
|
}
|
|
2080
2488
|
}
|
|
2081
|
-
startRTTMonitoring() {
|
|
2082
|
-
this.monitor.startRTTMonitoring();
|
|
2083
|
-
}
|
|
2084
|
-
stopRTTMonitoring() {
|
|
2085
|
-
this.monitor.stopRTTMonitoring();
|
|
2086
|
-
}
|
|
2087
2489
|
on(event, callback) {
|
|
2088
2490
|
this.logger.debug(`on ${event}`);
|
|
2089
2491
|
this.listener.push({
|