@koi-design/callkit 1.0.26 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +52 -105
- package/dist/index.global.js +1133 -1116
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1135 -1118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1135 -1118
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -67,42 +67,98 @@ instance.interceptors.response.use(
|
|
|
67
67
|
var request = (config) => instance.request(config);
|
|
68
68
|
var axios_default = request;
|
|
69
69
|
|
|
70
|
-
// package/
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
// package/api.ts
|
|
71
|
+
var Api = class {
|
|
72
|
+
callKit;
|
|
73
|
+
constructor(callKit) {
|
|
74
|
+
this.callKit = callKit;
|
|
75
|
+
}
|
|
76
|
+
async login(params) {
|
|
77
|
+
return this.post({
|
|
78
|
+
url: "/auth/agentUser/login",
|
|
79
|
+
method: "post",
|
|
80
|
+
data: params
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async loginOut(params) {
|
|
84
|
+
return this.post({
|
|
85
|
+
url: "/auth/agentUser/loginOut",
|
|
86
|
+
method: "post",
|
|
87
|
+
data: params
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async trackLogs(log) {
|
|
91
|
+
return this.post(
|
|
92
|
+
{ url: "/agent/user/sdkLog", method: "post", data: { content: [log] } },
|
|
93
|
+
{
|
|
94
|
+
useFormData: true
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
92
98
|
/**
|
|
93
|
-
*
|
|
99
|
+
*
|
|
100
|
+
* @param params agentId status
|
|
101
|
+
* @returns
|
|
94
102
|
*/
|
|
95
|
-
|
|
103
|
+
async updateUserStatus(params) {
|
|
104
|
+
return this.post({
|
|
105
|
+
url: "/agent/user/changeStatus",
|
|
106
|
+
method: "post",
|
|
107
|
+
data: params
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async post(config, extra = {}) {
|
|
111
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
112
|
+
const { sessionId } = userInfo;
|
|
113
|
+
config.url = `${host}${config.url}`;
|
|
114
|
+
config.headers = {
|
|
115
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
116
|
+
...config.headers
|
|
117
|
+
};
|
|
118
|
+
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded" && extra.useFormData) {
|
|
119
|
+
const formData = new FormData();
|
|
120
|
+
const data2 = config.data || {};
|
|
121
|
+
for (const key in data2) {
|
|
122
|
+
if (Object.prototype.hasOwnProperty.call(data2, key)) {
|
|
123
|
+
formData.append(key, data2[key]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
config.data = formData;
|
|
127
|
+
} else {
|
|
128
|
+
config.data = new URLSearchParams(config.data).toString();
|
|
129
|
+
}
|
|
130
|
+
if (sessionId) {
|
|
131
|
+
config.headers.sessionId = sessionId;
|
|
132
|
+
}
|
|
133
|
+
const res = await axios_default(config).catch(() => {
|
|
134
|
+
this.callKit.config.reset();
|
|
135
|
+
});
|
|
136
|
+
if (!res) {
|
|
137
|
+
this.callKit.config.reset();
|
|
138
|
+
throw new Error("Network error");
|
|
139
|
+
}
|
|
140
|
+
const { code, data, message } = res;
|
|
141
|
+
if (code === "000000") {
|
|
142
|
+
return data;
|
|
143
|
+
}
|
|
144
|
+
if (code === "100013") {
|
|
145
|
+
this.callKit.config.reset();
|
|
146
|
+
}
|
|
147
|
+
throw new Error(message ?? "Request failed");
|
|
148
|
+
}
|
|
96
149
|
};
|
|
150
|
+
|
|
151
|
+
// package/const.ts
|
|
97
152
|
var CallStatus = {
|
|
98
153
|
/**
|
|
99
154
|
* Initial state/Hang up
|
|
100
155
|
*/
|
|
101
156
|
init: 0,
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
157
|
+
// /**
|
|
158
|
+
// * @deprecated Deprecated
|
|
159
|
+
// * Registered
|
|
160
|
+
// */
|
|
161
|
+
// registered: 1,
|
|
106
162
|
/**
|
|
107
163
|
* Connecting
|
|
108
164
|
*/
|
|
@@ -121,6 +177,10 @@ var CallStatus = {
|
|
|
121
177
|
calling: 5
|
|
122
178
|
};
|
|
123
179
|
var KitEvent = {
|
|
180
|
+
/**
|
|
181
|
+
* Log
|
|
182
|
+
*/
|
|
183
|
+
KIT_LOG: "log",
|
|
124
184
|
/**
|
|
125
185
|
* User status change
|
|
126
186
|
*/
|
|
@@ -203,8 +263,7 @@ var KitEvent = {
|
|
|
203
263
|
USER_STATUS_CHANGE: "userStatusChange",
|
|
204
264
|
CONNECT_EVENT: "CONNECT_EVENT",
|
|
205
265
|
SIP_REGISTERER_EVENT: "sipRegistererEvent",
|
|
206
|
-
SIP_SESSION_EVENT: "sipSessionEvent"
|
|
207
|
-
USER_STATUS_CHANGE_STEP: "userStatusChangeStep"
|
|
266
|
+
SIP_SESSION_EVENT: "sipSessionEvent"
|
|
208
267
|
};
|
|
209
268
|
var ErrorCode = {
|
|
210
269
|
/**
|
|
@@ -293,8 +352,8 @@ var ErrorCode = {
|
|
|
293
352
|
SOCKET_RECONNECT_FAILED: 3000005
|
|
294
353
|
};
|
|
295
354
|
var LoggerLevelMap = {
|
|
296
|
-
|
|
297
|
-
|
|
355
|
+
info: 9,
|
|
356
|
+
success: 4,
|
|
298
357
|
warn: 3,
|
|
299
358
|
error: 2,
|
|
300
359
|
silent: 1
|
|
@@ -340,8 +399,7 @@ var SocketSendEvent = {
|
|
|
340
399
|
* AGENT_TRANSFER
|
|
341
400
|
*/
|
|
342
401
|
HANG_UP_REASON: "HANG_UP_REASON",
|
|
343
|
-
ACK: "ACK"
|
|
344
|
-
SDK_LOG: "SDK_LOG"
|
|
402
|
+
ACK: "ACK"
|
|
345
403
|
};
|
|
346
404
|
var SocketReceiveEvent = {
|
|
347
405
|
/**
|
|
@@ -405,10 +463,6 @@ var EncryptionMethod = {
|
|
|
405
463
|
NONE: "NONE",
|
|
406
464
|
INTERNAL: "INTERNAL"
|
|
407
465
|
};
|
|
408
|
-
var LogGatherEnum = {
|
|
409
|
-
ENABLE: 1,
|
|
410
|
-
DISABLE: 2
|
|
411
|
-
};
|
|
412
466
|
var constrainsDefault = {
|
|
413
467
|
audio: {
|
|
414
468
|
autoGainControl: true,
|
|
@@ -419,338 +473,10 @@ var constrainsDefault = {
|
|
|
419
473
|
},
|
|
420
474
|
video: false
|
|
421
475
|
};
|
|
422
|
-
var isAutoUpdateUserStatusDefault = true;
|
|
423
476
|
var CallSourceType = {
|
|
424
477
|
phoneNum: 1,
|
|
425
478
|
workOrderId: 2
|
|
426
479
|
};
|
|
427
|
-
var ConnectEvent = {
|
|
428
|
-
SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
|
|
429
|
-
SIP_RECONNECT_START: "SIP_RECONNECT_START",
|
|
430
|
-
SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
|
|
431
|
-
SIP_RECONNECT_SUCCESS: "SIP_RECONNECT_SUCCESS",
|
|
432
|
-
SIP_RECONNECTING: "SIP_RECONNECTING",
|
|
433
|
-
INCALL_NOT_CONNECTED: "INCALL_NOT_CONNECTED",
|
|
434
|
-
INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
|
|
435
|
-
INCALL_RECONNECT_START: "INCALL_RECONNECT_START",
|
|
436
|
-
INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR",
|
|
437
|
-
INCALL_RECONNECT_SUCCESS: "INCALL_RECONNECT_SUCCESS",
|
|
438
|
-
INCALL_RECONNECTING: "INCALL_RECONNECTING",
|
|
439
|
-
OPTIONS_HEARTBEAT_EXPIRED: "OPTIONS_HEARTBEAT_EXPIRED",
|
|
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"
|
|
474
|
-
};
|
|
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
|
-
}
|
|
753
|
-
};
|
|
754
480
|
|
|
755
481
|
// package/call.ts
|
|
756
482
|
var Call = class {
|
|
@@ -761,9 +487,19 @@ var Call = class {
|
|
|
761
487
|
async callStart() {
|
|
762
488
|
if (!this.callKit.config.check())
|
|
763
489
|
return;
|
|
764
|
-
this.callKit.logger.
|
|
490
|
+
this.callKit.logger.info("callStart", {
|
|
491
|
+
caller: "Call.callStart",
|
|
492
|
+
content: {
|
|
493
|
+
startConfirm: this.callKit.socket.satrtConfirm
|
|
494
|
+
}
|
|
495
|
+
});
|
|
765
496
|
if (!this.callKit.socket.satrtConfirm) {
|
|
766
|
-
this.callKit.logger.warn("server not confirm start"
|
|
497
|
+
this.callKit.logger.warn("server not confirm start", {
|
|
498
|
+
caller: "Call.callStart",
|
|
499
|
+
content: {
|
|
500
|
+
startConfirm: this.callKit.socket.satrtConfirm
|
|
501
|
+
}
|
|
502
|
+
});
|
|
767
503
|
return;
|
|
768
504
|
}
|
|
769
505
|
this.callKit.connect.call(async (user) => {
|
|
@@ -792,7 +528,13 @@ var Call = class {
|
|
|
792
528
|
async callRefer(referTo, options) {
|
|
793
529
|
if (!this.callKit.config.check())
|
|
794
530
|
return;
|
|
795
|
-
this.callKit.logger.
|
|
531
|
+
this.callKit.logger.info("callRefer", {
|
|
532
|
+
caller: "Call.callRefer",
|
|
533
|
+
content: {
|
|
534
|
+
referTo,
|
|
535
|
+
options
|
|
536
|
+
}
|
|
537
|
+
});
|
|
796
538
|
this.callKit.connect.refer(referTo, options);
|
|
797
539
|
}
|
|
798
540
|
/**
|
|
@@ -802,7 +544,7 @@ var Call = class {
|
|
|
802
544
|
* @returns
|
|
803
545
|
*/
|
|
804
546
|
async callEnd(isUnprompted = false, isError = false) {
|
|
805
|
-
if (this.callKit.connect.connectStatus === CallStatus.init
|
|
547
|
+
if (this.callKit.connect.connectStatus === CallStatus.init)
|
|
806
548
|
return;
|
|
807
549
|
if (!this.callKit.config.check())
|
|
808
550
|
return;
|
|
@@ -812,10 +554,14 @@ var Call = class {
|
|
|
812
554
|
if (!this.callKit.config.check())
|
|
813
555
|
return;
|
|
814
556
|
if (!this.callKit.connect.isCalling()) {
|
|
815
|
-
this.callKit.logger.warn("Current state cannot be held"
|
|
557
|
+
this.callKit.logger.warn("Current state cannot be held", {
|
|
558
|
+
caller: "Call.callHold",
|
|
559
|
+
content: {
|
|
560
|
+
isCalling: this.callKit.connect.isCalling()
|
|
561
|
+
}
|
|
562
|
+
});
|
|
816
563
|
return;
|
|
817
564
|
}
|
|
818
|
-
this.callKit.connect.hold();
|
|
819
565
|
this.callKit.socket.send(SocketSendEvent.HOLD);
|
|
820
566
|
this.callKit.connect.setConnectStatus(CallStatus.holding);
|
|
821
567
|
}
|
|
@@ -823,10 +569,14 @@ var Call = class {
|
|
|
823
569
|
if (!this.callKit.config.check())
|
|
824
570
|
return;
|
|
825
571
|
if (!this.callKit.connect.isHolding()) {
|
|
826
|
-
this.callKit.logger.warn("Current state cannot unhold"
|
|
572
|
+
this.callKit.logger.warn("Current state cannot unhold", {
|
|
573
|
+
caller: "Call.callUnhold",
|
|
574
|
+
content: {
|
|
575
|
+
isHolding: this.callKit.connect.isHolding()
|
|
576
|
+
}
|
|
577
|
+
});
|
|
827
578
|
return;
|
|
828
579
|
}
|
|
829
|
-
this.callKit.connect.unhold();
|
|
830
580
|
this.callKit.socket.send(SocketSendEvent.UNHOLD);
|
|
831
581
|
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
832
582
|
}
|
|
@@ -839,9 +589,10 @@ var Config = class {
|
|
|
839
589
|
this.callKit = callKit;
|
|
840
590
|
}
|
|
841
591
|
config = {
|
|
842
|
-
version: "1.0.
|
|
592
|
+
version: "1.0.27",
|
|
843
593
|
host: "",
|
|
844
|
-
log: "
|
|
594
|
+
log: "info",
|
|
595
|
+
trackLogs: false,
|
|
845
596
|
audioRef: void 0,
|
|
846
597
|
constrains: constrainsDefault,
|
|
847
598
|
socket: "",
|
|
@@ -865,11 +616,8 @@ var Config = class {
|
|
|
865
616
|
fsPort: "",
|
|
866
617
|
iceInfo: [],
|
|
867
618
|
iceGatheringTimeout: 0,
|
|
868
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
869
|
-
|
|
870
|
-
},
|
|
871
|
-
// EXECUTE setUserStatus
|
|
872
|
-
isAutoUpdateUserStatus: true
|
|
619
|
+
encryptionMethod: EncryptionMethod.INTERNAL
|
|
620
|
+
}
|
|
873
621
|
};
|
|
874
622
|
getConfig = () => this.config;
|
|
875
623
|
setConfig = async (key, value) => {
|
|
@@ -877,7 +625,13 @@ var Config = class {
|
|
|
877
625
|
};
|
|
878
626
|
setUserInfo = async (key, value) => {
|
|
879
627
|
this.config.userInfo[key] = value;
|
|
880
|
-
this.callKit.logger.
|
|
628
|
+
this.callKit.logger.info("setUserInfo", {
|
|
629
|
+
caller: "Config.setUserInfo",
|
|
630
|
+
content: {
|
|
631
|
+
key,
|
|
632
|
+
value
|
|
633
|
+
}
|
|
634
|
+
});
|
|
881
635
|
};
|
|
882
636
|
reset = () => {
|
|
883
637
|
if (this.isLogin()) {
|
|
@@ -898,8 +652,7 @@ var Config = class {
|
|
|
898
652
|
fsPort: "",
|
|
899
653
|
iceInfo: [],
|
|
900
654
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
901
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
902
|
-
logGather: LogGatherEnum.DISABLE
|
|
655
|
+
encryptionMethod: EncryptionMethod.INTERNAL
|
|
903
656
|
};
|
|
904
657
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
905
658
|
}
|
|
@@ -912,11 +665,13 @@ var Config = class {
|
|
|
912
665
|
return true;
|
|
913
666
|
};
|
|
914
667
|
isLogin = () => this.validate();
|
|
915
|
-
isLogGatherEnable = () => this.config.userInfo.logGather === LogGatherEnum.ENABLE;
|
|
916
668
|
check() {
|
|
917
669
|
if (!this.isLogin()) {
|
|
918
|
-
this.callKit.logger.
|
|
919
|
-
|
|
670
|
+
this.callKit.logger.warn("User not logged in", {
|
|
671
|
+
caller: "Config.check",
|
|
672
|
+
content: {
|
|
673
|
+
errCode: ErrorCode.USER_NOT_LOGIN
|
|
674
|
+
}
|
|
920
675
|
});
|
|
921
676
|
return false;
|
|
922
677
|
}
|
|
@@ -924,12 +679,149 @@ var Config = class {
|
|
|
924
679
|
}
|
|
925
680
|
};
|
|
926
681
|
|
|
927
|
-
// package/
|
|
928
|
-
var
|
|
929
|
-
|
|
682
|
+
// package/logger.ts
|
|
683
|
+
var import_json_stringify_safe = __toESM(require("json-stringify-safe"));
|
|
684
|
+
function getLevel(level) {
|
|
685
|
+
return LoggerLevelMap[level];
|
|
686
|
+
}
|
|
687
|
+
function transformLog(log) {
|
|
688
|
+
const { timestamp, level, type = "OTHER", message, caller, content } = log;
|
|
689
|
+
const logLevel = String(level).toUpperCase();
|
|
690
|
+
return `${timestamp} [${logLevel}] [${type}] [${caller ?? "unknown"}] [${message}] ${(0, import_json_stringify_safe.default)(content)}`.trim();
|
|
691
|
+
}
|
|
692
|
+
var MAX_SIZE = 8192;
|
|
693
|
+
var FLUSH_INTERVAL = 5e3;
|
|
694
|
+
function getByteSize(str) {
|
|
695
|
+
return new Blob([str]).size;
|
|
696
|
+
}
|
|
697
|
+
var Logger = class {
|
|
698
|
+
prefix = "CallKit";
|
|
699
|
+
level = "info";
|
|
700
|
+
pendingTrackLogs = [];
|
|
701
|
+
trackLogsTimer = null;
|
|
702
|
+
callKit;
|
|
703
|
+
constructor(callKit, level) {
|
|
704
|
+
this.callKit = callKit;
|
|
705
|
+
this.level = level || "info";
|
|
706
|
+
this.startTrackLogsTimer();
|
|
707
|
+
}
|
|
708
|
+
startTrackLogsTimer() {
|
|
709
|
+
if (this.trackLogsTimer) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
this.trackLogsTimer = setInterval(() => {
|
|
713
|
+
this.flushTrackLogs();
|
|
714
|
+
}, FLUSH_INTERVAL);
|
|
715
|
+
}
|
|
716
|
+
flushTrackLogs() {
|
|
717
|
+
if (this.pendingTrackLogs.length === 0) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const { trackLogs } = this.callKit.config.getConfig();
|
|
721
|
+
if (trackLogs) {
|
|
722
|
+
try {
|
|
723
|
+
const chunks = [];
|
|
724
|
+
let currentChunk = [];
|
|
725
|
+
let currentSize = 0;
|
|
726
|
+
for (const log of this.pendingTrackLogs) {
|
|
727
|
+
const logSize = getByteSize(log);
|
|
728
|
+
const separator = currentChunk.length > 0 ? "\n" : "";
|
|
729
|
+
const separatorSize = getByteSize(separator);
|
|
730
|
+
if (currentSize + logSize + separatorSize > MAX_SIZE && currentChunk.length > 0) {
|
|
731
|
+
chunks.push(currentChunk.join("\n"));
|
|
732
|
+
currentChunk = [log];
|
|
733
|
+
currentSize = logSize;
|
|
734
|
+
} else {
|
|
735
|
+
currentChunk.push(log);
|
|
736
|
+
currentSize += logSize + separatorSize;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (currentChunk.length > 0) {
|
|
740
|
+
chunks.push(currentChunk.join("\n"));
|
|
741
|
+
}
|
|
742
|
+
for (const chunk of chunks) {
|
|
743
|
+
this.callKit.api.trackLogs(chunk);
|
|
744
|
+
}
|
|
745
|
+
this.pendingTrackLogs = [];
|
|
746
|
+
} catch (error) {
|
|
747
|
+
console.error(error);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
destroy() {
|
|
752
|
+
if (this.trackLogsTimer) {
|
|
753
|
+
clearInterval(this.trackLogsTimer);
|
|
754
|
+
this.trackLogsTimer = null;
|
|
755
|
+
}
|
|
756
|
+
this.flushTrackLogs();
|
|
757
|
+
}
|
|
758
|
+
setLevel(level) {
|
|
759
|
+
this.level = level;
|
|
760
|
+
}
|
|
761
|
+
info(msg, extra) {
|
|
762
|
+
const logString = this.catchLog(msg, extra, "info");
|
|
763
|
+
if (getLevel(this.level) >= getLevel("info")) {
|
|
764
|
+
console.log(`%c${logString}`, `color: gray;`);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
success(msg, extra) {
|
|
768
|
+
const logString = this.catchLog(msg, extra, "success");
|
|
769
|
+
if (getLevel(this.level) >= getLevel("success")) {
|
|
770
|
+
console.log(`%c${logString}`, `color: green;`);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
warn(msg, extra) {
|
|
774
|
+
const logString = this.catchLog(msg, extra, "warn");
|
|
775
|
+
if (getLevel(this.level) >= getLevel("warn")) {
|
|
776
|
+
console.log(`%c${logString}`, `color: orange;`);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
error(msg, extra) {
|
|
780
|
+
const errorMsg = msg instanceof Error ? msg.message : msg;
|
|
781
|
+
const logString = this.catchLog(errorMsg, extra, "error");
|
|
782
|
+
if (getLevel(this.level) >= getLevel("error")) {
|
|
783
|
+
console.log(`%c${logString}`, `color: red;`);
|
|
784
|
+
}
|
|
785
|
+
const { errCode, ...rest } = extra?.content ?? {};
|
|
786
|
+
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
787
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
788
|
+
code: errorCode,
|
|
789
|
+
msg: errorMsg,
|
|
790
|
+
data: rest
|
|
791
|
+
});
|
|
792
|
+
const error = new Error(errorMsg);
|
|
793
|
+
error.name = "CallKitError";
|
|
794
|
+
error.code = errorCode;
|
|
795
|
+
error.data = rest;
|
|
796
|
+
throw error;
|
|
797
|
+
}
|
|
798
|
+
catchLog(msg, extra, level) {
|
|
799
|
+
const now = /* @__PURE__ */ new Date();
|
|
800
|
+
const log = {
|
|
801
|
+
timestamp: now.toLocaleString().replace("T", " ").replace(".000Z", ""),
|
|
802
|
+
level,
|
|
803
|
+
message: msg,
|
|
804
|
+
caller: extra?.caller,
|
|
805
|
+
type: extra?.type,
|
|
806
|
+
content: extra?.content ?? {}
|
|
807
|
+
};
|
|
808
|
+
const logString = transformLog(log);
|
|
809
|
+
const { trackLogs } = this.callKit.config.getConfig();
|
|
810
|
+
if (trackLogs) {
|
|
811
|
+
this.pendingTrackLogs.push(logString);
|
|
812
|
+
}
|
|
813
|
+
this.callKit.trigger(KitEvent.KIT_LOG, logString);
|
|
814
|
+
return logString;
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// package/connect.ts
|
|
819
|
+
var import_sip = require("sip.js");
|
|
820
|
+
var DEFAULT_RECONNECT_CONFIG = {
|
|
930
821
|
maxAttempts: 3,
|
|
931
822
|
delay: 500
|
|
932
823
|
};
|
|
824
|
+
var MAX_HEARTBEAT_COUNT = 6;
|
|
933
825
|
function convertObjectStringToJSON(input) {
|
|
934
826
|
const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
|
|
935
827
|
return corrected;
|
|
@@ -968,7 +860,12 @@ var Connect = class {
|
|
|
968
860
|
mediaStream;
|
|
969
861
|
userAgent;
|
|
970
862
|
registerer;
|
|
971
|
-
|
|
863
|
+
// current call id for invite data
|
|
864
|
+
currentCallId;
|
|
865
|
+
/**
|
|
866
|
+
* Whether it's a re-connected
|
|
867
|
+
*/
|
|
868
|
+
isReConnected = false;
|
|
972
869
|
observeOptionsHeartbeatHandler = null;
|
|
973
870
|
// sipConnected = false;
|
|
974
871
|
/**
|
|
@@ -981,23 +878,14 @@ var Connect = class {
|
|
|
981
878
|
isUnprompted = false;
|
|
982
879
|
isCurrentSessionInvited = false;
|
|
983
880
|
reconnectConfig;
|
|
984
|
-
/**
|
|
985
|
-
* Whether registered
|
|
986
|
-
* @param
|
|
987
|
-
* @deprecated Deprecated, please use isRegistered method
|
|
988
|
-
*/
|
|
989
|
-
get isRegister() {
|
|
990
|
-
return this.isRegistered();
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Call hold
|
|
994
|
-
* @param isHold
|
|
995
|
-
*/
|
|
996
|
-
isHold = false;
|
|
997
881
|
/**
|
|
998
882
|
* Whether muted
|
|
999
883
|
*/
|
|
1000
884
|
isMute = false;
|
|
885
|
+
/**
|
|
886
|
+
* Whether registered
|
|
887
|
+
*/
|
|
888
|
+
isRegistered = false;
|
|
1001
889
|
constructor(callKit) {
|
|
1002
890
|
this.callKit = callKit;
|
|
1003
891
|
const { reconnect = {} } = this.callKit.config.getConfig();
|
|
@@ -1007,10 +895,13 @@ var Connect = class {
|
|
|
1007
895
|
};
|
|
1008
896
|
}
|
|
1009
897
|
reset() {
|
|
898
|
+
if (this.isHolding()) {
|
|
899
|
+
this.setHoldStatus(false);
|
|
900
|
+
}
|
|
1010
901
|
if (this.connectStatus !== CallStatus.init) {
|
|
1011
902
|
this.setConnectStatus(CallStatus.init);
|
|
1012
903
|
}
|
|
1013
|
-
if (this.isRegistered
|
|
904
|
+
if (this.isRegistered) {
|
|
1014
905
|
this.unregister();
|
|
1015
906
|
}
|
|
1016
907
|
this.currentSession = void 0;
|
|
@@ -1019,10 +910,23 @@ var Connect = class {
|
|
|
1019
910
|
this.registerer = void 0;
|
|
1020
911
|
this.isOutgoing = false;
|
|
1021
912
|
this.isUnprompted = false;
|
|
1022
|
-
this.
|
|
1023
|
-
|
|
1024
|
-
|
|
913
|
+
if (this.mediaStream) {
|
|
914
|
+
try {
|
|
915
|
+
closeStream(this.mediaStream);
|
|
916
|
+
const audioRef = this.getAduioReference();
|
|
917
|
+
if (audioRef) {
|
|
918
|
+
audioRef.pause();
|
|
919
|
+
audioRef.srcObject = null;
|
|
920
|
+
}
|
|
921
|
+
} catch (error) {
|
|
922
|
+
this.callKit.logger.error(error, {
|
|
923
|
+
caller: "Connect.reset",
|
|
924
|
+
content: {}
|
|
925
|
+
});
|
|
926
|
+
}
|
|
1025
927
|
}
|
|
928
|
+
this.setConnectStatus(CallStatus.init);
|
|
929
|
+
this.clearObserveOptionsHeartbeatInterval();
|
|
1026
930
|
}
|
|
1027
931
|
getAduioReference() {
|
|
1028
932
|
const { audioRef } = this.callKit.config.getConfig();
|
|
@@ -1032,20 +936,16 @@ var Connect = class {
|
|
|
1032
936
|
return audioRef;
|
|
1033
937
|
}
|
|
1034
938
|
async permission() {
|
|
1035
|
-
this.callKit.logger.
|
|
939
|
+
this.callKit.logger.info("permission", {
|
|
940
|
+
caller: "Connect.permission",
|
|
941
|
+
content: {
|
|
942
|
+
permission: true
|
|
943
|
+
}
|
|
944
|
+
});
|
|
1036
945
|
initUserMedia();
|
|
1037
946
|
const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1038
947
|
closeStream(_stream);
|
|
1039
948
|
}
|
|
1040
|
-
isRegistered() {
|
|
1041
|
-
return [
|
|
1042
|
-
CallStatus.registered,
|
|
1043
|
-
CallStatus.connecting,
|
|
1044
|
-
CallStatus.ringing,
|
|
1045
|
-
CallStatus.calling,
|
|
1046
|
-
CallStatus.holding
|
|
1047
|
-
].includes(this.connectStatus);
|
|
1048
|
-
}
|
|
1049
949
|
/**
|
|
1050
950
|
* Making connection
|
|
1051
951
|
* @returns
|
|
@@ -1079,33 +979,59 @@ var Connect = class {
|
|
|
1079
979
|
isInit() {
|
|
1080
980
|
return this.connectStatus === CallStatus.init;
|
|
1081
981
|
}
|
|
1082
|
-
isExecuting() {
|
|
1083
|
-
return this.callKit.user.getUserChangeStatusExecuting();
|
|
1084
|
-
}
|
|
1085
982
|
clearObserveOptionsHeartbeatInterval() {
|
|
1086
983
|
if (this.observeOptionsHeartbeatHandler !== null) {
|
|
1087
984
|
clearInterval(this.observeOptionsHeartbeatHandler);
|
|
1088
985
|
this.observeOptionsHeartbeatHandler = null;
|
|
1089
986
|
}
|
|
1090
|
-
|
|
987
|
+
}
|
|
988
|
+
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
989
|
+
startHeartbeat() {
|
|
990
|
+
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
991
|
+
setTimeout(() => {
|
|
992
|
+
this.heartbeatFlag -= 1;
|
|
993
|
+
if (this.heartbeatFlag <= 0) {
|
|
994
|
+
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
995
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
996
|
+
event: "OPTIONS_HEARTBEAT_EXPIRED"
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
}, 1e3);
|
|
1091
1000
|
}
|
|
1092
1001
|
async register() {
|
|
1093
1002
|
if (this.connectStatus !== CallStatus.init) {
|
|
1094
|
-
if (this.
|
|
1095
|
-
this.callKit.logger.warn("connectStatus is registered"
|
|
1003
|
+
if (this.isRegistered) {
|
|
1004
|
+
this.callKit.logger.warn("connectStatus is registered", {
|
|
1005
|
+
caller: "Connect.register",
|
|
1006
|
+
content: {
|
|
1007
|
+
errCode: ErrorCode.CONNECT_CALL_STATUS_ERROR
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1096
1010
|
return;
|
|
1097
1011
|
}
|
|
1098
1012
|
this.callKit.logger.error("connectStatus is not init", {
|
|
1099
|
-
|
|
1013
|
+
caller: "Connect.register",
|
|
1014
|
+
content: {
|
|
1015
|
+
errCode: ErrorCode.CONNECT_CALL_STATUS_ERROR
|
|
1016
|
+
}
|
|
1100
1017
|
});
|
|
1101
|
-
this.callKit.
|
|
1018
|
+
this.callKit.reset();
|
|
1102
1019
|
return;
|
|
1103
1020
|
}
|
|
1104
|
-
this.callKit.logger.
|
|
1021
|
+
this.callKit.logger.info("connect register", {
|
|
1022
|
+
caller: "Connect.register",
|
|
1023
|
+
content: {
|
|
1024
|
+
connectStatus: this.connectStatus
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1105
1027
|
await this.permission().catch((err) => {
|
|
1106
1028
|
this.callKit.logger.error(err, {
|
|
1107
|
-
|
|
1029
|
+
caller: "Connect.register",
|
|
1030
|
+
content: {
|
|
1031
|
+
errCode: ErrorCode.WEBRTC_USER_MEDIA_ERROR
|
|
1032
|
+
}
|
|
1108
1033
|
});
|
|
1034
|
+
this.callKit.reset();
|
|
1109
1035
|
});
|
|
1110
1036
|
const { userInfo, constrains } = this.callKit.config.getConfig();
|
|
1111
1037
|
const localStreamFactory = async () => {
|
|
@@ -1132,12 +1058,18 @@ var Connect = class {
|
|
|
1132
1058
|
}
|
|
1133
1059
|
}
|
|
1134
1060
|
};
|
|
1135
|
-
this.callKit.logger.
|
|
1061
|
+
this.callKit.logger.info("connect connectConfig", {
|
|
1062
|
+
caller: "Connect.register",
|
|
1063
|
+
content: connectConfig
|
|
1064
|
+
});
|
|
1136
1065
|
this.userAgent = new import_sip.UserAgent(connectConfig);
|
|
1137
1066
|
const remoteStream = new MediaStream();
|
|
1138
1067
|
const setupRemoteMedia = (session) => {
|
|
1139
1068
|
const audioRef = this.getAduioReference();
|
|
1140
|
-
this.callKit.logger.
|
|
1069
|
+
this.callKit.logger.info("connect setupRemoteMedia", {
|
|
1070
|
+
caller: "Connect.register.setupRemoteMedia",
|
|
1071
|
+
content: audioRef
|
|
1072
|
+
});
|
|
1141
1073
|
session.sessionDescriptionHandler.peerConnection.getReceivers().forEach((receiver) => {
|
|
1142
1074
|
if (receiver.track) {
|
|
1143
1075
|
remoteStream.addTrack(receiver.track);
|
|
@@ -1147,125 +1079,119 @@ var Connect = class {
|
|
|
1147
1079
|
audioRef.srcObject = remoteStream;
|
|
1148
1080
|
audioRef.play().catch((error) => {
|
|
1149
1081
|
this.callKit.logger.error(error.message, {
|
|
1150
|
-
|
|
1082
|
+
caller: "Connect.register.setupRemoteMedia",
|
|
1083
|
+
content: {
|
|
1084
|
+
errCode: ErrorCode.WEBRTC_AUDIO_PLAY_ERROR
|
|
1085
|
+
}
|
|
1151
1086
|
});
|
|
1152
1087
|
});
|
|
1153
1088
|
} else {
|
|
1154
1089
|
this.callKit.logger.error("video is not exist", {
|
|
1155
|
-
|
|
1090
|
+
caller: "Connect.register",
|
|
1091
|
+
content: {
|
|
1092
|
+
errCode: ErrorCode.WEBRTC_AUDIO_PLAYER_ERROR
|
|
1093
|
+
}
|
|
1156
1094
|
});
|
|
1157
1095
|
}
|
|
1158
1096
|
};
|
|
1159
1097
|
const observeSocketStatus = (userAgent, extra) => {
|
|
1160
1098
|
const { that = this } = extra;
|
|
1161
|
-
that.userAgent.transport.onDisconnect = (error) => {
|
|
1162
|
-
if (error) {
|
|
1163
|
-
that.callKit.logger.debug("connect onDisconnect");
|
|
1164
|
-
if (that.isRegistered() && !// that.sipConnected ||
|
|
1165
|
-
(that.isRinging() || that.isCalling() || that.isHolding())) {
|
|
1166
|
-
that.reconnect();
|
|
1167
|
-
} else {
|
|
1168
|
-
that.callKit.logger.debug("SIP WebSocket closed with error", {
|
|
1169
|
-
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1170
|
-
err: error
|
|
1171
|
-
});
|
|
1172
|
-
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1173
|
-
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1174
|
-
err: error
|
|
1175
|
-
});
|
|
1176
|
-
that.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1177
|
-
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1178
|
-
err: error
|
|
1179
|
-
});
|
|
1180
|
-
that.callKit.user.sendHangUpReason({
|
|
1181
|
-
eventType: ConnectEvent.SIP_CONNECT_ERROR,
|
|
1182
|
-
err: error
|
|
1183
|
-
});
|
|
1184
|
-
that.callKit.callCenter.callEnd();
|
|
1185
|
-
}
|
|
1186
|
-
} else {
|
|
1187
|
-
that.callKit.logger.debug("SIP WebSocket closed normally");
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
that.clearObserveOptionsHeartbeatInterval();
|
|
1191
|
-
that.observeOptionsHeartbeatHandler = setInterval(() => {
|
|
1192
|
-
if (that.lastOptionsUpdateTime !== 0) {
|
|
1193
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1194
|
-
const diff = now - that.lastOptionsUpdateTime;
|
|
1195
|
-
if (diff > 6e4) {
|
|
1196
|
-
that.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1197
|
-
event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
1198
|
-
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1199
|
-
now
|
|
1200
|
-
});
|
|
1201
|
-
that.callKit.user.sendHangUpReason({
|
|
1202
|
-
eventType: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
1203
|
-
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1204
|
-
now
|
|
1205
|
-
});
|
|
1206
|
-
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1207
|
-
event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
1208
|
-
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
1209
|
-
now
|
|
1210
|
-
});
|
|
1211
|
-
that.clearObserveOptionsHeartbeatInterval();
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
}, 6e4);
|
|
1215
|
-
that.lastOptionsUpdateTime = 0;
|
|
1216
1099
|
const core = userAgent.userAgentCore;
|
|
1217
1100
|
const originalReceiveRequest = core.receiveRequest.bind(core);
|
|
1218
|
-
core.receiveRequest =
|
|
1101
|
+
core.receiveRequest = (request2) => {
|
|
1219
1102
|
if (request2.method === "OPTIONS") {
|
|
1220
|
-
that.
|
|
1103
|
+
that.startHeartbeat();
|
|
1221
1104
|
}
|
|
1222
|
-
that.callKit.logger.
|
|
1105
|
+
that.callKit.logger.info(`SIP Receive Request: ${request2.method}`, {
|
|
1106
|
+
caller: "Connect.register.observeSocketStatus",
|
|
1107
|
+
type: "SIP",
|
|
1108
|
+
content: {
|
|
1109
|
+
request: request2
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1223
1112
|
return originalReceiveRequest(request2);
|
|
1224
1113
|
};
|
|
1114
|
+
const { transport } = userAgent;
|
|
1115
|
+
if (transport) {
|
|
1116
|
+
const originalSend = transport.send.bind(transport);
|
|
1117
|
+
transport.send = (message) => {
|
|
1118
|
+
that.callKit.logger.info(`SIP send message`, {
|
|
1119
|
+
caller: "Connect.register.observeSocketStatus",
|
|
1120
|
+
type: "SIP",
|
|
1121
|
+
content: {
|
|
1122
|
+
message: message.toString()
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
return originalSend(message);
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1225
1128
|
};
|
|
1226
1129
|
const registererOptions = {};
|
|
1227
1130
|
this.registerer = new import_sip.Registerer(this.userAgent, registererOptions);
|
|
1228
1131
|
this.registerer.stateChange.addListener((state) => {
|
|
1229
1132
|
switch (state) {
|
|
1230
1133
|
case import_sip.RegistererState.Initial:
|
|
1231
|
-
this.callKit.logger.
|
|
1134
|
+
this.callKit.logger.info("registerer stateChange Initial", {
|
|
1135
|
+
caller: "Connect.register.registererStateChange",
|
|
1136
|
+
type: "SIP",
|
|
1137
|
+
content: {
|
|
1138
|
+
registererState: state,
|
|
1139
|
+
isRegistered: this.isRegistered
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1232
1142
|
this.setRegister(false);
|
|
1233
1143
|
this.setConnectStatus(CallStatus.init);
|
|
1234
|
-
this.callKit.
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
);
|
|
1144
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
1145
|
+
registererState: state,
|
|
1146
|
+
isRegistered: this.isRegistered
|
|
1147
|
+
});
|
|
1239
1148
|
break;
|
|
1240
1149
|
case import_sip.RegistererState.Registered:
|
|
1241
|
-
this.callKit.logger.
|
|
1150
|
+
this.callKit.logger.info("registerer stateChange Registered", {
|
|
1151
|
+
caller: "Connect.register.registererStateChange",
|
|
1152
|
+
type: "SIP",
|
|
1153
|
+
content: {
|
|
1154
|
+
registererState: state,
|
|
1155
|
+
isRegistered: this.isRegistered
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1242
1158
|
this.setRegister(true);
|
|
1243
|
-
this.
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
SipRegistererEvent.Registered
|
|
1248
|
-
);
|
|
1159
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
1160
|
+
registererState: state,
|
|
1161
|
+
isRegistered: this.isRegistered
|
|
1162
|
+
});
|
|
1249
1163
|
break;
|
|
1250
1164
|
case import_sip.RegistererState.Terminated:
|
|
1251
|
-
this.callKit.logger.
|
|
1165
|
+
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
1166
|
+
caller: "Connect.register.registererStateChange",
|
|
1167
|
+
type: "SIP",
|
|
1168
|
+
content: {
|
|
1169
|
+
registererState: state,
|
|
1170
|
+
isRegistered: this.isRegistered
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1252
1173
|
this.setRegister(false);
|
|
1253
1174
|
this.setConnectStatus(CallStatus.init);
|
|
1254
|
-
this.callKit.
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
);
|
|
1175
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
1176
|
+
isRegistered: this.isRegistered,
|
|
1177
|
+
registererState: state
|
|
1178
|
+
});
|
|
1259
1179
|
break;
|
|
1260
1180
|
case import_sip.RegistererState.Unregistered:
|
|
1261
|
-
this.callKit.logger.
|
|
1181
|
+
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
1182
|
+
caller: "Connect.register.registererStateChange",
|
|
1183
|
+
type: "SIP",
|
|
1184
|
+
content: {
|
|
1185
|
+
isRegistered: this.isRegistered,
|
|
1186
|
+
registererState: state
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1262
1189
|
this.setRegister(false);
|
|
1263
1190
|
this.setConnectStatus(CallStatus.init);
|
|
1264
|
-
this.callKit.
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
);
|
|
1191
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
1192
|
+
isRegistered: this.isRegistered,
|
|
1193
|
+
registererState: state
|
|
1194
|
+
});
|
|
1269
1195
|
break;
|
|
1270
1196
|
default:
|
|
1271
1197
|
break;
|
|
@@ -1273,64 +1199,75 @@ var Connect = class {
|
|
|
1273
1199
|
});
|
|
1274
1200
|
this.userAgent.delegate = {
|
|
1275
1201
|
onInvite: (invite) => {
|
|
1276
|
-
this.callKit.logger.
|
|
1202
|
+
this.callKit.logger.info("connect onInvite", {
|
|
1203
|
+
type: "SIP",
|
|
1204
|
+
caller: "Connect.register.onInvite",
|
|
1205
|
+
content: {
|
|
1206
|
+
invite,
|
|
1207
|
+
isRegistered: this.isRegistered
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1277
1210
|
this.currentSession = invite;
|
|
1278
1211
|
if (this.isOutgoing) {
|
|
1279
1212
|
this.isCurrentSessionInvited = false;
|
|
1280
1213
|
}
|
|
1281
1214
|
this.currentSession.stateChange.addListener((state) => {
|
|
1282
|
-
const isExecuting = this.isExecuting();
|
|
1283
1215
|
switch (state) {
|
|
1284
1216
|
case import_sip.SessionState.Establishing:
|
|
1285
|
-
this.callKit.logger.
|
|
1217
|
+
this.callKit.logger.info("connect Establishing", {
|
|
1218
|
+
caller: "Connect.register.onInvite",
|
|
1219
|
+
type: "SIP",
|
|
1220
|
+
content: {
|
|
1221
|
+
sessionState: state
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1286
1224
|
this.setConnectStatus(CallStatus.ringing);
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
this.
|
|
1290
|
-
|
|
1291
|
-
SipSessionEvent.Establishing
|
|
1292
|
-
);
|
|
1293
|
-
}
|
|
1225
|
+
this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
|
|
1226
|
+
sessionState: state,
|
|
1227
|
+
isRegistered: this.isRegistered
|
|
1228
|
+
});
|
|
1294
1229
|
break;
|
|
1295
1230
|
case import_sip.SessionState.Established:
|
|
1296
|
-
this.callKit.logger.
|
|
1231
|
+
this.callKit.logger.info("connect Established", {
|
|
1232
|
+
caller: "Connect.register.onInvite",
|
|
1233
|
+
type: "SIP",
|
|
1234
|
+
content: {
|
|
1235
|
+
sessionState: state
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1297
1238
|
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
setupRemoteMedia(this.currentSession);
|
|
1304
|
-
}
|
|
1239
|
+
this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
|
|
1240
|
+
sessionState: state,
|
|
1241
|
+
isRegistered: this.isRegistered
|
|
1242
|
+
});
|
|
1243
|
+
setupRemoteMedia(this.currentSession);
|
|
1305
1244
|
break;
|
|
1306
1245
|
case import_sip.SessionState.Terminating:
|
|
1307
|
-
this.callKit.
|
|
1308
|
-
|
|
1309
|
-
this.
|
|
1310
|
-
|
|
1311
|
-
SipSessionEvent.Terminating
|
|
1312
|
-
);
|
|
1313
|
-
}
|
|
1246
|
+
this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
|
|
1247
|
+
sessionState: state,
|
|
1248
|
+
isRegistered: this.isRegistered
|
|
1249
|
+
});
|
|
1314
1250
|
break;
|
|
1315
1251
|
case import_sip.SessionState.Terminated:
|
|
1316
|
-
this.callKit.logger.
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1252
|
+
this.callKit.logger.info("connect Terminated", {
|
|
1253
|
+
caller: "Connect.register.onInvite",
|
|
1254
|
+
type: "SIP",
|
|
1255
|
+
content: {
|
|
1256
|
+
sessionState: state
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
if (this.isUnprompted) {
|
|
1320
1260
|
if (this.isCurrentSessionInvited) {
|
|
1321
1261
|
this.currentSession.reject();
|
|
1322
1262
|
}
|
|
1323
|
-
|
|
1263
|
+
} else {
|
|
1264
|
+
this.callKit.callCenter.callEnd();
|
|
1324
1265
|
}
|
|
1325
1266
|
this.isUnprompted = false;
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
this.
|
|
1329
|
-
|
|
1330
|
-
KitEvent.SIP_SESSION_EVENT,
|
|
1331
|
-
SipSessionEvent.Terminated
|
|
1332
|
-
);
|
|
1333
|
-
}
|
|
1267
|
+
this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
|
|
1268
|
+
sessionState: state,
|
|
1269
|
+
isRegistered: this.isRegistered
|
|
1270
|
+
});
|
|
1334
1271
|
break;
|
|
1335
1272
|
default:
|
|
1336
1273
|
break;
|
|
@@ -1344,6 +1281,7 @@ var Connect = class {
|
|
|
1344
1281
|
};
|
|
1345
1282
|
if (this.isOutgoing) {
|
|
1346
1283
|
this.currentSession.accept(options);
|
|
1284
|
+
this.setConnectStatus(CallStatus.connecting);
|
|
1347
1285
|
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
1348
1286
|
getInviteData: () => {
|
|
1349
1287
|
const { request: request2 } = this.currentSession;
|
|
@@ -1354,20 +1292,18 @@ var Connect = class {
|
|
|
1354
1292
|
).forEach((name) => {
|
|
1355
1293
|
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
1356
1294
|
});
|
|
1357
|
-
this.callKit.logger.
|
|
1295
|
+
this.callKit.logger.info("get invite data", {
|
|
1296
|
+
caller: "Connect.register.onInvite",
|
|
1297
|
+
content: xHeaders
|
|
1298
|
+
});
|
|
1358
1299
|
return xHeaders;
|
|
1359
1300
|
}
|
|
1360
1301
|
});
|
|
1361
1302
|
} else {
|
|
1362
|
-
const isExecuting = this.isExecuting();
|
|
1363
1303
|
const reject = () => {
|
|
1364
1304
|
this.currentSession.reject();
|
|
1365
1305
|
this.callKit.callCenter.callEnd(true, false);
|
|
1366
1306
|
};
|
|
1367
|
-
if (isExecuting) {
|
|
1368
|
-
reject();
|
|
1369
|
-
return;
|
|
1370
|
-
}
|
|
1371
1307
|
this.callKit.trigger(KitEvent.KIT_INVITE, {
|
|
1372
1308
|
accept: () => {
|
|
1373
1309
|
this.isCurrentSessionInvited = true;
|
|
@@ -1384,14 +1320,25 @@ var Connect = class {
|
|
|
1384
1320
|
).forEach((name) => {
|
|
1385
1321
|
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
1386
1322
|
});
|
|
1387
|
-
this.callKit.logger.
|
|
1323
|
+
this.callKit.logger.info("get invite data", {
|
|
1324
|
+
caller: "Connect.register",
|
|
1325
|
+
content: xHeaders
|
|
1326
|
+
});
|
|
1388
1327
|
return xHeaders;
|
|
1389
1328
|
}
|
|
1390
1329
|
});
|
|
1391
1330
|
}
|
|
1392
1331
|
},
|
|
1393
1332
|
onConnect: async () => {
|
|
1394
|
-
this.
|
|
1333
|
+
this.reconnectAttempts = 0;
|
|
1334
|
+
this.reconnectTimer = null;
|
|
1335
|
+
this.callKit.logger.info("connect onConnect", {
|
|
1336
|
+
caller: "Connect.register",
|
|
1337
|
+
type: "SIP",
|
|
1338
|
+
content: {
|
|
1339
|
+
version: `V${this.callKit.config.getConfig().version}`
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1395
1342
|
const version = `V${this.callKit.config.getConfig().version}`;
|
|
1396
1343
|
await this.registerer.register().then(() => {
|
|
1397
1344
|
this.callKit.socket.send(SocketSendEvent.START, {
|
|
@@ -1399,132 +1346,148 @@ var Connect = class {
|
|
|
1399
1346
|
});
|
|
1400
1347
|
}).catch(async (err) => {
|
|
1401
1348
|
this.callKit.logger.error(err?.message, {
|
|
1402
|
-
|
|
1349
|
+
caller: "Connect.register",
|
|
1350
|
+
type: "SIP",
|
|
1351
|
+
content: {
|
|
1352
|
+
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
1353
|
+
}
|
|
1403
1354
|
});
|
|
1355
|
+
this.callKit.reset();
|
|
1404
1356
|
});
|
|
1405
1357
|
},
|
|
1406
1358
|
onDisconnect: (error) => {
|
|
1407
|
-
|
|
1408
|
-
if (
|
|
1409
|
-
|
|
1410
|
-
this.reconnect();
|
|
1359
|
+
console.log("onDisconnect", error);
|
|
1360
|
+
if (error) {
|
|
1361
|
+
this.startReconnectTimer();
|
|
1411
1362
|
} else {
|
|
1412
|
-
this.callKit.
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
});
|
|
1420
|
-
this.callKit.user.sendHangUpReason({
|
|
1421
|
-
eventType: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
1422
|
-
err: error
|
|
1363
|
+
this.callKit.logger.info("SIP User Agent Disconnected", {
|
|
1364
|
+
caller: "Connect.register",
|
|
1365
|
+
type: "SIP",
|
|
1366
|
+
content: {
|
|
1367
|
+
err: error.message,
|
|
1368
|
+
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
1369
|
+
}
|
|
1423
1370
|
});
|
|
1424
|
-
this.callKit.callCenter.callEnd();
|
|
1425
1371
|
}
|
|
1426
1372
|
},
|
|
1427
1373
|
onRegister: () => {
|
|
1428
|
-
this.callKit.logger.
|
|
1374
|
+
this.callKit.logger.info("connect onRegister", {
|
|
1375
|
+
caller: "Connect.register",
|
|
1376
|
+
type: "SIP",
|
|
1377
|
+
content: {
|
|
1378
|
+
version: `V${this.callKit.config.getConfig().version}`
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1429
1381
|
}
|
|
1430
|
-
// onRefer: (referral) => {
|
|
1431
|
-
// this.callKit.trigger(KitEvent.KIT_REFER, {
|
|
1432
|
-
// referAccept: () => {
|
|
1433
|
-
// this.setConnectStatus(CallStatus.connecting);
|
|
1434
|
-
// referral.accept().then(() => {
|
|
1435
|
-
// referral.makeInviter().invite();
|
|
1436
|
-
// });
|
|
1437
|
-
// },
|
|
1438
|
-
// referReject: () => {
|
|
1439
|
-
// referral.reject();
|
|
1440
|
-
// this.callKit.callCenter.callEnd(true, false);
|
|
1441
|
-
// }
|
|
1442
|
-
// });
|
|
1443
|
-
// }
|
|
1444
1382
|
};
|
|
1445
1383
|
observeSocketStatus(this.userAgent, {
|
|
1446
1384
|
that: this
|
|
1447
1385
|
});
|
|
1448
1386
|
await this.userAgent.start().catch((err) => {
|
|
1449
|
-
this.callKit.callCenter.callEnd(false, true);
|
|
1450
|
-
this.callKit.user.sendHangUpReason({
|
|
1451
|
-
eventType: ConnectEvent.USER_AGENT_START_ERROR,
|
|
1452
|
-
err
|
|
1453
|
-
});
|
|
1454
1387
|
this.callKit.logger.error(err, {
|
|
1455
|
-
|
|
1388
|
+
caller: "Connect.register",
|
|
1389
|
+
type: "SIP",
|
|
1390
|
+
content: {
|
|
1391
|
+
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
1392
|
+
}
|
|
1456
1393
|
});
|
|
1394
|
+
this.callKit.reset();
|
|
1457
1395
|
});
|
|
1458
1396
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1397
|
+
reconnectTimer;
|
|
1398
|
+
reconnectAttempts = 0;
|
|
1399
|
+
startReconnectTimer() {
|
|
1400
|
+
if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts) {
|
|
1401
|
+
this.callKit.logger.error("Reconnect failed max attempts", {
|
|
1402
|
+
caller: "Connect.startReconnectTimer",
|
|
1403
|
+
type: "SIP",
|
|
1404
|
+
content: {
|
|
1405
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
1406
|
+
maxAttempts: this.reconnectConfig.maxAttempts,
|
|
1407
|
+
delay: this.reconnectConfig.delay
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
this.callKit.reset();
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
this.callKit.logger.info("Reconnect timer started", {
|
|
1414
|
+
caller: "Connect.startReconnectTimer",
|
|
1415
|
+
type: "SIP",
|
|
1416
|
+
content: {
|
|
1417
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
1418
|
+
maxAttempts: this.reconnectConfig.maxAttempts,
|
|
1419
|
+
delay: this.reconnectConfig.delay
|
|
1466
1420
|
}
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1421
|
+
});
|
|
1422
|
+
this.reconnectAttempts += 1;
|
|
1423
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1424
|
+
if (this.reconnectTimer) {
|
|
1425
|
+
this.userAgent.reconnect();
|
|
1426
|
+
this.callKit.logger.info("Reconnect attempt", {
|
|
1427
|
+
caller: "Connect.startReconnectTimer",
|
|
1428
|
+
type: "SIP",
|
|
1429
|
+
content: {
|
|
1430
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
1431
|
+
maxAttempts: this.reconnectConfig.maxAttempts,
|
|
1432
|
+
delay: this.reconnectConfig.delay
|
|
1475
1433
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
event: ConnectEvent.SIP_RECONNECT_SUCCESS
|
|
1486
|
-
});
|
|
1487
|
-
reconnectTimer = null;
|
|
1488
|
-
} catch (err) {
|
|
1489
|
-
this.callKit.logger.debug("Reconnection failed:", err);
|
|
1490
|
-
reconnectTimer = null;
|
|
1491
|
-
if (currentRetry < this.reconnectConfig.maxAttempts) {
|
|
1492
|
-
await scheduleReconnect();
|
|
1493
|
-
} else {
|
|
1494
|
-
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1495
|
-
event: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
1496
|
-
error: err
|
|
1497
|
-
});
|
|
1498
|
-
this.callKit.user.sendHangUpReason({
|
|
1499
|
-
eventType: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
1500
|
-
error: err
|
|
1501
|
-
});
|
|
1502
|
-
this.callKit.logger.error("No registerer to unregister.");
|
|
1434
|
+
});
|
|
1435
|
+
} else {
|
|
1436
|
+
this.callKit.logger.info("Reconnect timer already expired", {
|
|
1437
|
+
caller: "Connect.startReconnectTimer",
|
|
1438
|
+
type: "SIP",
|
|
1439
|
+
content: {
|
|
1440
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
1441
|
+
maxAttempts: this.reconnectConfig.maxAttempts,
|
|
1442
|
+
delay: this.reconnectConfig.delay
|
|
1503
1443
|
}
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
};
|
|
1507
|
-
await scheduleReconnect();
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
}, this.reconnectConfig.delay);
|
|
1508
1447
|
}
|
|
1509
1448
|
async stop() {
|
|
1510
1449
|
await this.userAgent.stop();
|
|
1511
1450
|
}
|
|
1512
1451
|
async unregister() {
|
|
1513
|
-
this.callKit.logger.
|
|
1514
|
-
|
|
1515
|
-
|
|
1452
|
+
this.callKit.logger.info("connect unregister", {
|
|
1453
|
+
caller: "Connect.unregister",
|
|
1454
|
+
type: "SIP",
|
|
1455
|
+
content: {
|
|
1456
|
+
isRegistered: this.isRegistered,
|
|
1457
|
+
registerer: this.registerer
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
if (!this.isRegistered || !this.registerer) {
|
|
1461
|
+
this.callKit.logger.warn("No registerer to unregister.", {
|
|
1462
|
+
caller: "Connect.unregister",
|
|
1463
|
+
type: "SIP",
|
|
1464
|
+
content: {
|
|
1465
|
+
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1516
1468
|
return;
|
|
1517
1469
|
}
|
|
1518
1470
|
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
1519
1471
|
this.callKit.logger.error(err, {
|
|
1520
|
-
|
|
1472
|
+
caller: "Connect.unregister",
|
|
1473
|
+
type: "SIP",
|
|
1474
|
+
content: {
|
|
1475
|
+
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
1476
|
+
}
|
|
1521
1477
|
});
|
|
1478
|
+
this.callKit.reset();
|
|
1522
1479
|
});
|
|
1523
1480
|
}
|
|
1524
1481
|
async call(callback) {
|
|
1525
|
-
this.callKit.logger.
|
|
1482
|
+
this.callKit.logger.info("connect call", {
|
|
1483
|
+
caller: "Connect.call",
|
|
1484
|
+
type: "SIP",
|
|
1485
|
+
content: {
|
|
1486
|
+
callback
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1526
1489
|
this.isOutgoing = true;
|
|
1527
|
-
if (!this.isRegistered
|
|
1490
|
+
if (!this.isRegistered) {
|
|
1528
1491
|
await this.register();
|
|
1529
1492
|
}
|
|
1530
1493
|
this.setConnectStatus(CallStatus.connecting);
|
|
@@ -1537,7 +1500,14 @@ var Connect = class {
|
|
|
1537
1500
|
* @param register
|
|
1538
1501
|
*/
|
|
1539
1502
|
setRegister(register) {
|
|
1540
|
-
this.callKit.logger.
|
|
1503
|
+
this.callKit.logger.info("connect setRegister", {
|
|
1504
|
+
caller: "Connect.setRegister",
|
|
1505
|
+
type: "SIP",
|
|
1506
|
+
content: {
|
|
1507
|
+
register
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
this.isRegistered = register;
|
|
1541
1511
|
this.callKit.trigger(KitEvent.KIT_REGISTER_CHANGE, register);
|
|
1542
1512
|
}
|
|
1543
1513
|
/**
|
|
@@ -1545,7 +1515,13 @@ var Connect = class {
|
|
|
1545
1515
|
* @param status
|
|
1546
1516
|
*/
|
|
1547
1517
|
setConnectStatus(status) {
|
|
1548
|
-
this.callKit.logger.
|
|
1518
|
+
this.callKit.logger.info("connect setConnectStatus", {
|
|
1519
|
+
caller: "Connect.setConnectStatus",
|
|
1520
|
+
type: "SIP",
|
|
1521
|
+
content: {
|
|
1522
|
+
status
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1549
1525
|
this.connectStatus = status;
|
|
1550
1526
|
this.callKit.trigger(KitEvent.KIT_CALL_STATUS_CHANGE, status);
|
|
1551
1527
|
}
|
|
@@ -1556,8 +1532,16 @@ var Connect = class {
|
|
|
1556
1532
|
* @returns
|
|
1557
1533
|
*/
|
|
1558
1534
|
async hangup(isUnprompted = false, isError = false) {
|
|
1559
|
-
this.callKit.logger.
|
|
1560
|
-
|
|
1535
|
+
this.callKit.logger.info("connect hangup", {
|
|
1536
|
+
caller: "Connect.hangup",
|
|
1537
|
+
type: "SIP",
|
|
1538
|
+
content: {
|
|
1539
|
+
isUnprompted,
|
|
1540
|
+
isError,
|
|
1541
|
+
connectStatus: this.connectStatus
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
if (this.connectStatus === CallStatus.init)
|
|
1561
1545
|
return;
|
|
1562
1546
|
this.isOutgoing = false;
|
|
1563
1547
|
this.isUnprompted = isUnprompted;
|
|
@@ -1577,12 +1561,20 @@ var Connect = class {
|
|
|
1577
1561
|
audioRef.pause();
|
|
1578
1562
|
audioRef.srcObject = null;
|
|
1579
1563
|
}
|
|
1580
|
-
|
|
1581
|
-
this.setConnectStatus(CallStatus.init);
|
|
1582
|
-
}
|
|
1564
|
+
this.setConnectStatus(CallStatus.init);
|
|
1583
1565
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
1584
1566
|
} catch (err) {
|
|
1567
|
+
this.callKit.logger.error(err, {
|
|
1568
|
+
caller: "Connect.hangup",
|
|
1569
|
+
type: "SIP",
|
|
1570
|
+
content: {
|
|
1571
|
+
connectStatus: this.connectStatus,
|
|
1572
|
+
isError,
|
|
1573
|
+
isUnprompted
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1585
1576
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
1577
|
+
this.callKit.reset();
|
|
1586
1578
|
}
|
|
1587
1579
|
}
|
|
1588
1580
|
/**
|
|
@@ -1590,7 +1582,13 @@ var Connect = class {
|
|
|
1590
1582
|
* @param session - Session to get the media stream from.
|
|
1591
1583
|
*/
|
|
1592
1584
|
getRemoteMediaStream(session) {
|
|
1593
|
-
this.callKit.logger.
|
|
1585
|
+
this.callKit.logger.info("connect getRemoteMediaStream", {
|
|
1586
|
+
caller: "Connect.getRemoteMediaStream",
|
|
1587
|
+
type: "SIP",
|
|
1588
|
+
content: {
|
|
1589
|
+
session
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1594
1592
|
const sdh = session.sessionDescriptionHandler;
|
|
1595
1593
|
if (!sdh) {
|
|
1596
1594
|
return void 0;
|
|
@@ -1598,7 +1596,13 @@ var Connect = class {
|
|
|
1598
1596
|
return sdh.remoteMediaStream;
|
|
1599
1597
|
}
|
|
1600
1598
|
setupRemoteMedia(session) {
|
|
1601
|
-
this.callKit.logger.
|
|
1599
|
+
this.callKit.logger.info("connect setupRemoteMedia", {
|
|
1600
|
+
caller: "Connect.setupRemoteMedia",
|
|
1601
|
+
type: "SIP",
|
|
1602
|
+
content: {
|
|
1603
|
+
session
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1602
1606
|
const remoteStream = this.getRemoteMediaStream(session);
|
|
1603
1607
|
const audioRef = this.getAduioReference();
|
|
1604
1608
|
if (audioRef) {
|
|
@@ -1606,21 +1610,39 @@ var Connect = class {
|
|
|
1606
1610
|
audioRef.srcObject = remoteStream;
|
|
1607
1611
|
audioRef.play().catch((error) => {
|
|
1608
1612
|
this.callKit.logger.error(error.message, {
|
|
1609
|
-
|
|
1613
|
+
caller: "Connect.setupRemoteMedia",
|
|
1614
|
+
type: "SIP",
|
|
1615
|
+
content: {
|
|
1616
|
+
errCode: ErrorCode.WEBRTC_AUDIO_PLAY_ERROR
|
|
1617
|
+
}
|
|
1610
1618
|
});
|
|
1611
1619
|
});
|
|
1612
1620
|
remoteStream.onaddtrack = () => {
|
|
1613
|
-
this.callKit.logger.
|
|
1621
|
+
this.callKit.logger.info("Remote media onaddtrack", {
|
|
1622
|
+
caller: "Connect.setupRemoteMedia",
|
|
1623
|
+
type: "SIP",
|
|
1624
|
+
content: {
|
|
1625
|
+
session
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1614
1628
|
audioRef.load();
|
|
1615
1629
|
audioRef.play().catch((error) => {
|
|
1616
1630
|
this.callKit.logger.error(error.message, {
|
|
1617
|
-
|
|
1631
|
+
caller: "Connect.setupRemoteMedia",
|
|
1632
|
+
type: "SIP",
|
|
1633
|
+
content: {
|
|
1634
|
+
errCode: ErrorCode.WEBRTC_AUDIO_PLAY_ERROR
|
|
1635
|
+
}
|
|
1618
1636
|
});
|
|
1619
1637
|
});
|
|
1620
1638
|
};
|
|
1621
1639
|
} else {
|
|
1622
1640
|
this.callKit.logger.error("video is not exist", {
|
|
1623
|
-
|
|
1641
|
+
caller: "Connect.setupRemoteMedia",
|
|
1642
|
+
type: "SIP",
|
|
1643
|
+
content: {
|
|
1644
|
+
errCode: ErrorCode.WEBRTC_AUDIO_PLAYER_ERROR
|
|
1645
|
+
}
|
|
1624
1646
|
});
|
|
1625
1647
|
}
|
|
1626
1648
|
}
|
|
@@ -1629,33 +1651,62 @@ var Connect = class {
|
|
|
1629
1651
|
* @param hold
|
|
1630
1652
|
*/
|
|
1631
1653
|
setHoldStatus(hold) {
|
|
1632
|
-
this.callKit.logger.
|
|
1633
|
-
|
|
1654
|
+
this.callKit.logger.info("connect setHold", {
|
|
1655
|
+
caller: "Connect.setHoldStatus",
|
|
1656
|
+
type: "SIP",
|
|
1657
|
+
content: {
|
|
1658
|
+
hold
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1634
1661
|
this.callKit.trigger(KitEvent.KIT_SET_HOLD, hold);
|
|
1635
1662
|
}
|
|
1636
1663
|
async setHold(hold) {
|
|
1637
1664
|
this.setHoldStatus(hold);
|
|
1638
1665
|
}
|
|
1639
1666
|
async hold() {
|
|
1640
|
-
this.callKit.logger.
|
|
1667
|
+
this.callKit.logger.info("connect hold", {
|
|
1668
|
+
caller: "Connect.hold",
|
|
1669
|
+
type: "SIP",
|
|
1670
|
+
content: {
|
|
1671
|
+
hold: true
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1641
1674
|
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
1642
1675
|
this.callKit.logger.error("Current status is not in call", {
|
|
1643
|
-
|
|
1676
|
+
caller: "Connect.hold",
|
|
1677
|
+
type: "SIP",
|
|
1678
|
+
content: {
|
|
1679
|
+
errCode: ErrorCode.WEBRTC_HOLE_STATUS_ERROR
|
|
1680
|
+
}
|
|
1644
1681
|
});
|
|
1645
|
-
return;
|
|
1646
1682
|
}
|
|
1647
|
-
await this.setHold(true);
|
|
1648
1683
|
}
|
|
1649
1684
|
async unhold() {
|
|
1650
|
-
this.callKit.logger.
|
|
1651
|
-
|
|
1685
|
+
this.callKit.logger.info("connect unhold", {
|
|
1686
|
+
caller: "Connect.unhold",
|
|
1687
|
+
type: "SIP",
|
|
1688
|
+
content: {
|
|
1689
|
+
hold: false
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1652
1692
|
}
|
|
1653
1693
|
async setMute(mute) {
|
|
1654
|
-
this.callKit.logger.
|
|
1694
|
+
this.callKit.logger.info("connect setMute", {
|
|
1695
|
+
caller: "Connect.setMute",
|
|
1696
|
+
type: "SIP",
|
|
1697
|
+
content: {
|
|
1698
|
+
mute
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1655
1701
|
if (!this.currentSession) {
|
|
1656
1702
|
this.callKit.logger.error("No active session", {
|
|
1657
|
-
|
|
1703
|
+
caller: "Connect.setMute",
|
|
1704
|
+
type: "SIP",
|
|
1705
|
+
content: {
|
|
1706
|
+
errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
1707
|
+
}
|
|
1658
1708
|
});
|
|
1709
|
+
this.callKit.reset();
|
|
1659
1710
|
return;
|
|
1660
1711
|
}
|
|
1661
1712
|
try {
|
|
@@ -1674,33 +1725,64 @@ var Connect = class {
|
|
|
1674
1725
|
}
|
|
1675
1726
|
} catch (error) {
|
|
1676
1727
|
this.callKit.logger.error("Failed to set mute state", {
|
|
1677
|
-
|
|
1678
|
-
|
|
1728
|
+
caller: "Connect.setMute",
|
|
1729
|
+
type: "SIP",
|
|
1730
|
+
content: {
|
|
1731
|
+
err: error.message,
|
|
1732
|
+
errCode: ErrorCode.WEBRTC_MUTE_ERROR
|
|
1733
|
+
}
|
|
1679
1734
|
});
|
|
1680
1735
|
}
|
|
1681
1736
|
}
|
|
1682
1737
|
async mute() {
|
|
1683
|
-
this.callKit.logger.
|
|
1738
|
+
this.callKit.logger.info("connect mute", {
|
|
1739
|
+
caller: "Connect.mute",
|
|
1740
|
+
type: "SIP",
|
|
1741
|
+
content: {
|
|
1742
|
+
mute: true
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1684
1745
|
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
1685
|
-
this.callKit.logger.
|
|
1686
|
-
|
|
1746
|
+
this.callKit.logger.warn("Current status is not in call", {
|
|
1747
|
+
caller: "Connect.mute",
|
|
1748
|
+
type: "SIP",
|
|
1749
|
+
content: {
|
|
1750
|
+
errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
1751
|
+
}
|
|
1687
1752
|
});
|
|
1688
1753
|
return;
|
|
1689
1754
|
}
|
|
1690
1755
|
await this.setMute(true);
|
|
1691
1756
|
}
|
|
1692
1757
|
async unmute() {
|
|
1693
|
-
this.callKit.logger.
|
|
1758
|
+
this.callKit.logger.info("connect unmute", {
|
|
1759
|
+
caller: "Connect.unmute",
|
|
1760
|
+
type: "SIP",
|
|
1761
|
+
content: {
|
|
1762
|
+
mute: false
|
|
1763
|
+
}
|
|
1764
|
+
});
|
|
1694
1765
|
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
1695
|
-
this.callKit.logger.
|
|
1696
|
-
|
|
1766
|
+
this.callKit.logger.warn("Current status is not in call", {
|
|
1767
|
+
caller: "Connect.unmute",
|
|
1768
|
+
type: "SIP",
|
|
1769
|
+
content: {
|
|
1770
|
+
errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
1771
|
+
}
|
|
1697
1772
|
});
|
|
1698
1773
|
return;
|
|
1699
1774
|
}
|
|
1700
1775
|
await this.setMute(false);
|
|
1701
1776
|
}
|
|
1702
1777
|
async refer(referTo, extra) {
|
|
1703
|
-
this.callKit.logger.
|
|
1778
|
+
this.callKit.logger.info("connect refer", {
|
|
1779
|
+
caller: "Connect.refer",
|
|
1780
|
+
type: "SIP",
|
|
1781
|
+
content: {
|
|
1782
|
+
referTo,
|
|
1783
|
+
extra
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1704
1786
|
let target;
|
|
1705
1787
|
if (referTo) {
|
|
1706
1788
|
target = import_sip.UserAgent.makeURI(referTo);
|
|
@@ -1725,8 +1807,6 @@ var Socket = class {
|
|
|
1725
1807
|
lastPingTime = void 0;
|
|
1726
1808
|
isConnected = false;
|
|
1727
1809
|
pingTimer;
|
|
1728
|
-
// Whether received server hangup confirmation
|
|
1729
|
-
recivedClose = false;
|
|
1730
1810
|
// Whether received start confirmation
|
|
1731
1811
|
satrtConfirm = false;
|
|
1732
1812
|
reconnectTimer;
|
|
@@ -1742,48 +1822,25 @@ var Socket = class {
|
|
|
1742
1822
|
}
|
|
1743
1823
|
init() {
|
|
1744
1824
|
const { socket } = this.callKit.config.getConfig();
|
|
1745
|
-
this.callKit.logger.
|
|
1825
|
+
this.callKit.logger.info(`socket init: ${socket}`, {
|
|
1826
|
+
caller: "Socket.init",
|
|
1827
|
+
type: "INCALL",
|
|
1828
|
+
content: {
|
|
1829
|
+
socket
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1746
1832
|
this.connect(socket);
|
|
1747
1833
|
}
|
|
1748
|
-
|
|
1749
|
-
// startConfirm(status: boolean) {
|
|
1750
|
-
// this.callKit.logger.debug('register success');
|
|
1751
|
-
// this.satrtConfirm = status;
|
|
1752
|
-
// }
|
|
1753
|
-
setRecivedClose(status) {
|
|
1754
|
-
this.recivedClose = status;
|
|
1755
|
-
}
|
|
1756
|
-
reconnect(ev) {
|
|
1757
|
-
this.callKit.logger.debug("socket reconnect", ev);
|
|
1834
|
+
handleDisconnect() {
|
|
1758
1835
|
this.isConnected = false;
|
|
1759
|
-
if (!this.
|
|
1760
|
-
this.
|
|
1761
|
-
"socket reconnect times",
|
|
1762
|
-
this.socketConfig.maxAttempts
|
|
1763
|
-
);
|
|
1764
|
-
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
1765
|
-
event: ConnectEvent.INCALL_RECONNECTING,
|
|
1766
|
-
attempts: this.reconnectAttempts,
|
|
1767
|
-
err: ev
|
|
1768
|
-
});
|
|
1769
|
-
this.attemptReconnect();
|
|
1770
|
-
} else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
1836
|
+
if (!this.callKit.config.isLogin() || !this.socketConfig.enabled) {
|
|
1837
|
+
this.reset();
|
|
1771
1838
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1772
|
-
event:
|
|
1773
|
-
err: ev
|
|
1839
|
+
event: "INCALL_NOT_CONNECTED"
|
|
1774
1840
|
});
|
|
1775
|
-
|
|
1776
|
-
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
1777
|
-
err: ev
|
|
1778
|
-
});
|
|
1779
|
-
this.reset();
|
|
1780
|
-
this.callKit.logger.error(
|
|
1781
|
-
"Reconnection failed, maximum retry attempts reached",
|
|
1782
|
-
{
|
|
1783
|
-
errCode: ErrorCode.SOCKET_RECONNECT_FAILED
|
|
1784
|
-
}
|
|
1785
|
-
);
|
|
1841
|
+
return;
|
|
1786
1842
|
}
|
|
1843
|
+
this.attemptReconnect();
|
|
1787
1844
|
}
|
|
1788
1845
|
connect(socketUrl) {
|
|
1789
1846
|
this.ws = new WebSocket(socketUrl);
|
|
@@ -1793,86 +1850,76 @@ var Socket = class {
|
|
|
1793
1850
|
this.ws.onmessage = (ev) => this.onMessage(ev);
|
|
1794
1851
|
}
|
|
1795
1852
|
onOpen(ev) {
|
|
1796
|
-
this.callKit.logger.
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
ev
|
|
1853
|
+
this.callKit.logger.info("socket onOpen", {
|
|
1854
|
+
caller: "Socket.onOpen",
|
|
1855
|
+
type: "INCALL",
|
|
1856
|
+
content: { ev }
|
|
1800
1857
|
});
|
|
1801
1858
|
this.isConnected = true;
|
|
1802
1859
|
this.lastPingTime = Date.now();
|
|
1803
1860
|
this.checkPing();
|
|
1804
1861
|
if (this.isReconnecting) {
|
|
1805
|
-
this.callKit.logger.
|
|
1862
|
+
this.callKit.logger.info("reconnect success", {
|
|
1863
|
+
caller: "Socket.onOpen",
|
|
1864
|
+
type: "INCALL",
|
|
1865
|
+
content: {
|
|
1866
|
+
event: "INCALL_RECONNECT_SUCCESS",
|
|
1867
|
+
reconnectAttempts: this.reconnectAttempts
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1806
1870
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1807
|
-
event:
|
|
1871
|
+
event: "INCALL_RECONNECT_SUCCESS"
|
|
1808
1872
|
});
|
|
1809
|
-
this.isReconnecting = false;
|
|
1810
|
-
if (this.reconnectTimer) {
|
|
1811
|
-
clearTimeout(this.reconnectTimer);
|
|
1812
|
-
this.reconnectTimer = void 0;
|
|
1813
|
-
}
|
|
1814
1873
|
}
|
|
1874
|
+
this.resetReconnectState();
|
|
1875
|
+
}
|
|
1876
|
+
resetReconnectState() {
|
|
1877
|
+
this.isReconnecting = false;
|
|
1815
1878
|
this.reconnectAttempts = 0;
|
|
1879
|
+
if (this.reconnectTimer) {
|
|
1880
|
+
clearTimeout(this.reconnectTimer);
|
|
1881
|
+
this.reconnectTimer = void 0;
|
|
1882
|
+
}
|
|
1816
1883
|
}
|
|
1817
1884
|
onClose(ev) {
|
|
1818
|
-
this.callKit.logger.
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
ev
|
|
1885
|
+
this.callKit.logger.info("socket onClose", {
|
|
1886
|
+
caller: "Socket.onClose",
|
|
1887
|
+
type: "INCALL",
|
|
1888
|
+
content: { ev }
|
|
1822
1889
|
});
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
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
|
-
});
|
|
1836
|
-
this.reconnect(ev);
|
|
1837
|
-
} else {
|
|
1838
|
-
this.isConnected = false;
|
|
1839
|
-
this.satrtConfirm = false;
|
|
1840
|
-
if (this.pingTimer) {
|
|
1841
|
-
clearInterval(this.pingTimer);
|
|
1842
|
-
this.pingTimer = void 0;
|
|
1843
|
-
}
|
|
1844
|
-
this.callKit.connect.hangup();
|
|
1845
|
-
this.reset();
|
|
1846
|
-
}
|
|
1890
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1891
|
+
event: "INCALL_CONNECT_ERROR",
|
|
1892
|
+
err: ev
|
|
1893
|
+
});
|
|
1894
|
+
this.handleDisconnect();
|
|
1847
1895
|
}
|
|
1848
1896
|
onError(ev) {
|
|
1849
|
-
this.callKit.logger.
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1897
|
+
this.callKit.logger.error("socket onError", {
|
|
1898
|
+
caller: "Socket.onError",
|
|
1899
|
+
type: "INCALL",
|
|
1900
|
+
content: {
|
|
1901
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
1902
|
+
data: ev
|
|
1903
|
+
}
|
|
1856
1904
|
});
|
|
1857
|
-
if (this.isReconnecting) {
|
|
1858
|
-
this.attemptReconnect();
|
|
1859
|
-
}
|
|
1860
1905
|
}
|
|
1861
1906
|
confirmAck(data) {
|
|
1862
1907
|
const { ack, messageId } = data;
|
|
1863
1908
|
if (ack) {
|
|
1864
1909
|
this.send(SocketSendEvent.ACK, {
|
|
1865
1910
|
messageId
|
|
1866
|
-
// sessionId
|
|
1867
1911
|
});
|
|
1868
1912
|
}
|
|
1869
1913
|
}
|
|
1870
1914
|
onMessage(ev) {
|
|
1871
1915
|
const data = JSON.parse(ev.data);
|
|
1872
|
-
this.callKit.logger.
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1916
|
+
this.callKit.logger.info("socket onMessage", {
|
|
1917
|
+
caller: "Socket.onMessage",
|
|
1918
|
+
type: "INCALL",
|
|
1919
|
+
content: {
|
|
1920
|
+
data: data.data,
|
|
1921
|
+
event: data.event
|
|
1922
|
+
}
|
|
1876
1923
|
});
|
|
1877
1924
|
this.confirmAck(data);
|
|
1878
1925
|
if (data.event === SocketReceiveEvent.PONG) {
|
|
@@ -1880,69 +1927,147 @@ var Socket = class {
|
|
|
1880
1927
|
return;
|
|
1881
1928
|
}
|
|
1882
1929
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
1883
|
-
this.callKit.logger.
|
|
1930
|
+
this.callKit.logger.info("start confirm success", {
|
|
1931
|
+
caller: "Socket.onMessage",
|
|
1932
|
+
type: "INCALL",
|
|
1933
|
+
content: {
|
|
1934
|
+
data: data.data,
|
|
1935
|
+
event: SocketReceiveEvent.START_CONFIRM
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1884
1938
|
this.satrtConfirm = true;
|
|
1885
1939
|
}
|
|
1886
1940
|
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
1887
|
-
this.
|
|
1941
|
+
this.callKit.logger.info("call success", {
|
|
1942
|
+
caller: "Socket.onMessage",
|
|
1943
|
+
type: "INCALL",
|
|
1944
|
+
content: {
|
|
1945
|
+
data: data.data,
|
|
1946
|
+
event: SocketReceiveEvent.CALL_SUCCESS
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1888
1949
|
}
|
|
1889
1950
|
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
1890
|
-
this.callKit.logger.
|
|
1891
|
-
|
|
1951
|
+
this.callKit.logger.info(data.msg, {
|
|
1952
|
+
caller: "Socket.onMessage",
|
|
1953
|
+
type: "INCALL",
|
|
1954
|
+
content: {
|
|
1955
|
+
data: data.data,
|
|
1956
|
+
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
1957
|
+
}
|
|
1892
1958
|
});
|
|
1893
1959
|
}
|
|
1894
1960
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
1895
1961
|
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
1896
1962
|
}
|
|
1897
1963
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
1898
|
-
this.callKit.logger.
|
|
1964
|
+
this.callKit.logger.info(data.msg, {
|
|
1965
|
+
caller: "Socket.onMessage",
|
|
1966
|
+
type: "INCALL",
|
|
1967
|
+
content: {
|
|
1968
|
+
data: data.data,
|
|
1969
|
+
event: SocketReceiveEvent.CUSTOMER_PICK_UP
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1899
1972
|
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
1900
1973
|
}
|
|
1901
1974
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
1902
|
-
this.callKit.logger.
|
|
1975
|
+
this.callKit.logger.info(data.msg, {
|
|
1976
|
+
caller: "Socket.onMessage",
|
|
1977
|
+
type: "INCALL",
|
|
1978
|
+
content: {
|
|
1979
|
+
data: data.data,
|
|
1980
|
+
event: SocketReceiveEvent.AGENT_PICK_UP
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1903
1983
|
this.callKit.trigger(KitEvent.AGENT_PICK_UP, /* @__PURE__ */ new Date());
|
|
1904
1984
|
}
|
|
1905
1985
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
1906
|
-
this.callKit.logger.
|
|
1986
|
+
this.callKit.logger.info(data.msg, {
|
|
1987
|
+
caller: "Socket.onMessage",
|
|
1988
|
+
type: "INCALL",
|
|
1989
|
+
content: {
|
|
1990
|
+
data: data.data,
|
|
1991
|
+
event: SocketReceiveEvent.CUSTOMER_HANG_UP
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1907
1994
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
1908
1995
|
}
|
|
1909
1996
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
1910
|
-
this.callKit.logger.
|
|
1997
|
+
this.callKit.logger.info(data.msg, {
|
|
1998
|
+
caller: "Socket.onMessage",
|
|
1999
|
+
type: "INCALL",
|
|
2000
|
+
content: {
|
|
2001
|
+
data: data.data,
|
|
2002
|
+
event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
|
|
2003
|
+
}
|
|
2004
|
+
});
|
|
1911
2005
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
1912
2006
|
}
|
|
1913
2007
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
1914
|
-
this.callKit.logger.
|
|
2008
|
+
this.callKit.logger.info(data.msg, {
|
|
2009
|
+
caller: "Socket.onMessage",
|
|
2010
|
+
content: {
|
|
2011
|
+
data: data.data,
|
|
2012
|
+
event: SocketReceiveEvent.CALL_CDR
|
|
2013
|
+
}
|
|
2014
|
+
});
|
|
1915
2015
|
this.callKit.trigger(KitEvent.CALL_CDR, data.data);
|
|
1916
2016
|
}
|
|
1917
2017
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
1918
|
-
this.callKit.logger.
|
|
1919
|
-
|
|
2018
|
+
this.callKit.logger.info(data.msg, {
|
|
2019
|
+
caller: "Socket.onMessage",
|
|
2020
|
+
content: {
|
|
2021
|
+
data: data.data,
|
|
2022
|
+
event: SocketReceiveEvent.STOP_CONFIRM
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
1920
2025
|
}
|
|
1921
2026
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
1922
2027
|
const { userInfo } = this.callKit.config.getConfig();
|
|
1923
|
-
this.callKit.logger.
|
|
2028
|
+
this.callKit.logger.info(data.msg, {
|
|
2029
|
+
caller: "Socket.onMessage",
|
|
2030
|
+
content: {
|
|
2031
|
+
data: data.data,
|
|
2032
|
+
event: SocketReceiveEvent.CLOSE
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
1924
2035
|
this.send(SocketSendEvent.END, {
|
|
1925
2036
|
agentId: userInfo.agentId
|
|
1926
2037
|
});
|
|
1927
2038
|
}
|
|
1928
2039
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
1929
|
-
this.callKit.
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2040
|
+
this.callKit.logger.error(data.msg, {
|
|
2041
|
+
caller: "Socket.onMessage",
|
|
2042
|
+
content: {
|
|
2043
|
+
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
2044
|
+
data: data.data
|
|
2045
|
+
}
|
|
1933
2046
|
});
|
|
2047
|
+
this.callKit.reset();
|
|
1934
2048
|
}
|
|
1935
2049
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
2050
|
+
this.callKit.logger.info(data.msg, {
|
|
2051
|
+
caller: "Socket.onMessage",
|
|
2052
|
+
content: {
|
|
2053
|
+
data: data.data,
|
|
2054
|
+
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
1936
2057
|
}
|
|
1937
2058
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
1938
2059
|
}
|
|
1939
2060
|
send(event, message) {
|
|
1940
2061
|
if (!this.isConnected) {
|
|
1941
2062
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1942
|
-
event:
|
|
2063
|
+
event: "INCALL_NOT_CONNECTED"
|
|
1943
2064
|
});
|
|
1944
2065
|
this.callKit.logger.error("socket not connected", {
|
|
1945
|
-
|
|
2066
|
+
caller: "Socket.send",
|
|
2067
|
+
type: "INCALL",
|
|
2068
|
+
content: {
|
|
2069
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
2070
|
+
}
|
|
1946
2071
|
});
|
|
1947
2072
|
this.callKit.config.reset();
|
|
1948
2073
|
this.callKit.reset();
|
|
@@ -1952,7 +2077,11 @@ var Socket = class {
|
|
|
1952
2077
|
const { sessionId, extno, agentId } = userInfo;
|
|
1953
2078
|
if (!sessionId) {
|
|
1954
2079
|
this.callKit.logger.error("sessionId is empty", {
|
|
1955
|
-
|
|
2080
|
+
caller: "Socket.send",
|
|
2081
|
+
type: "INCALL",
|
|
2082
|
+
content: {
|
|
2083
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
2084
|
+
}
|
|
1956
2085
|
});
|
|
1957
2086
|
return;
|
|
1958
2087
|
}
|
|
@@ -1970,7 +2099,14 @@ var Socket = class {
|
|
|
1970
2099
|
delete msg.phoneNum;
|
|
1971
2100
|
}
|
|
1972
2101
|
}
|
|
1973
|
-
this.callKit.logger.
|
|
2102
|
+
this.callKit.logger.info("socket send", {
|
|
2103
|
+
caller: "Socket.send",
|
|
2104
|
+
type: "INCALL",
|
|
2105
|
+
content: {
|
|
2106
|
+
event,
|
|
2107
|
+
message
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
1974
2110
|
switch (event) {
|
|
1975
2111
|
case SocketSendEvent.PING:
|
|
1976
2112
|
this.lastPingTime = Date.now();
|
|
@@ -1984,10 +2120,14 @@ var Socket = class {
|
|
|
1984
2120
|
async sendMessage(event, message) {
|
|
1985
2121
|
if (!this.isConnected) {
|
|
1986
2122
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
1987
|
-
event:
|
|
2123
|
+
event: "INCALL_NOT_CONNECTED"
|
|
1988
2124
|
});
|
|
1989
2125
|
this.callKit.logger.error("socket not connected", {
|
|
1990
|
-
|
|
2126
|
+
caller: "Socket.sendMessage",
|
|
2127
|
+
type: "INCALL",
|
|
2128
|
+
content: {
|
|
2129
|
+
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
2130
|
+
}
|
|
1991
2131
|
});
|
|
1992
2132
|
return;
|
|
1993
2133
|
}
|
|
@@ -1995,32 +2135,26 @@ var Socket = class {
|
|
|
1995
2135
|
const { sessionId } = userInfo;
|
|
1996
2136
|
this.ws?.send(JSON.stringify({ event, sessionId, ...message }));
|
|
1997
2137
|
}
|
|
1998
|
-
/**
|
|
1999
|
-
* Attempt to close socket, need to wait for server confirmation
|
|
2000
|
-
* @returns
|
|
2001
|
-
*/
|
|
2002
|
-
async requestClose() {
|
|
2003
|
-
return new Promise((resolve) => {
|
|
2004
|
-
let remainingTime = 5;
|
|
2005
|
-
const interval = setInterval(() => {
|
|
2006
|
-
remainingTime -= 1;
|
|
2007
|
-
if (this.recivedClose || remainingTime <= 0) {
|
|
2008
|
-
clearInterval(interval);
|
|
2009
|
-
resolve(this.recivedClose);
|
|
2010
|
-
}
|
|
2011
|
-
}, 1e3);
|
|
2012
|
-
});
|
|
2013
|
-
}
|
|
2014
2138
|
ping() {
|
|
2015
2139
|
if (!this.isConnected)
|
|
2016
2140
|
return;
|
|
2017
2141
|
this.send(SocketSendEvent.PING);
|
|
2142
|
+
this.callKit.logger.info(`socket ping`, {
|
|
2143
|
+
caller: "Socket.ping",
|
|
2144
|
+
type: "INCALL",
|
|
2145
|
+
content: {
|
|
2146
|
+
lastPingTime: this.lastPingTime
|
|
2147
|
+
}
|
|
2148
|
+
});
|
|
2018
2149
|
const now = Date.now();
|
|
2019
|
-
this.callKit.logger.debug(`socket ping: ${now - this.lastPingTime}ms`);
|
|
2020
2150
|
const { pingInterval, pingTimeout } = this.socketConfig;
|
|
2021
2151
|
if (now - this.lastPingTime > pingInterval + pingTimeout) {
|
|
2022
2152
|
this.callKit.logger.error("socket ping timeout", {
|
|
2023
|
-
|
|
2153
|
+
caller: "Socket.ping",
|
|
2154
|
+
type: "INCALL",
|
|
2155
|
+
content: {
|
|
2156
|
+
errCode: ErrorCode.SOCKET_PING_TIMEOUT
|
|
2157
|
+
}
|
|
2024
2158
|
});
|
|
2025
2159
|
if (this.ws && this.isConnected) {
|
|
2026
2160
|
this.ws.close(4001, "ping timeout");
|
|
@@ -2039,257 +2173,72 @@ var Socket = class {
|
|
|
2039
2173
|
}, this.socketConfig.pingInterval);
|
|
2040
2174
|
}
|
|
2041
2175
|
/**
|
|
2042
|
-
*
|
|
2176
|
+
* 重置 socket 连接和所有状态
|
|
2043
2177
|
* @param isWaitConfirm Whether need to wait for close confirmation
|
|
2044
2178
|
*/
|
|
2045
2179
|
async reset(isWaitConfirm = true) {
|
|
2046
2180
|
if (this.pingTimer) {
|
|
2047
2181
|
clearInterval(this.pingTimer);
|
|
2182
|
+
this.pingTimer = void 0;
|
|
2048
2183
|
}
|
|
2049
|
-
|
|
2050
|
-
clearTimeout(this.reconnectTimer);
|
|
2051
|
-
}
|
|
2184
|
+
this.resetReconnectState();
|
|
2052
2185
|
this.lastPingTime = void 0;
|
|
2053
|
-
this.pingTimer = void 0;
|
|
2054
2186
|
this.satrtConfirm = false;
|
|
2055
|
-
this.isReconnecting = false;
|
|
2056
|
-
this.reconnectAttempts = 0;
|
|
2057
2187
|
if (this.ws && this.isConnected) {
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2188
|
+
this.callKit.logger.info("Closing socket connection", {
|
|
2189
|
+
caller: "Socket.reset",
|
|
2190
|
+
type: "INCALL",
|
|
2191
|
+
content: {
|
|
2192
|
+
isWaitConfirm
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2063
2195
|
this.ws.close();
|
|
2064
2196
|
this.isConnected = false;
|
|
2065
2197
|
}
|
|
2066
2198
|
}
|
|
2067
2199
|
attemptReconnect() {
|
|
2068
|
-
if (this.reconnectAttempts
|
|
2069
|
-
this.callKit.
|
|
2070
|
-
|
|
2200
|
+
if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
2201
|
+
this.callKit.logger.error("Maximum reconnection attempts reached", {
|
|
2202
|
+
caller: "Socket.attemptReconnect",
|
|
2203
|
+
type: "INCALL",
|
|
2204
|
+
content: {
|
|
2205
|
+
errCode: ErrorCode.SOCKET_RECONNECT_FAILED,
|
|
2206
|
+
reconnectAttempts: this.reconnectAttempts
|
|
2207
|
+
}
|
|
2071
2208
|
});
|
|
2072
|
-
}
|
|
2073
|
-
if (this.isReconnecting && this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
2074
2209
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
2075
|
-
event:
|
|
2210
|
+
event: "INCALL_RECONNECT_ERROR"
|
|
2076
2211
|
});
|
|
2077
|
-
this.isReconnecting = false;
|
|
2078
2212
|
this.reset();
|
|
2079
2213
|
return;
|
|
2080
2214
|
}
|
|
2215
|
+
if (this.reconnectAttempts === 0) {
|
|
2216
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
2217
|
+
event: "INCALL_RECONNECT_START"
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2081
2220
|
this.isReconnecting = true;
|
|
2082
2221
|
this.reconnectAttempts += 1;
|
|
2083
2222
|
const { delay } = this.socketConfig;
|
|
2084
|
-
this.callKit.logger.
|
|
2085
|
-
`Preparing reconnection attempt ${this.reconnectAttempts}/${this.socketConfig.maxAttempts}, delay: ${delay}ms
|
|
2223
|
+
this.callKit.logger.info(
|
|
2224
|
+
`Preparing reconnection attempt ${this.reconnectAttempts}/${this.socketConfig.maxAttempts}, delay: ${delay}ms`,
|
|
2225
|
+
{
|
|
2226
|
+
caller: "Socket.attemptReconnect",
|
|
2227
|
+
type: "INCALL",
|
|
2228
|
+
content: {
|
|
2229
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
2230
|
+
maxAttempts: this.socketConfig.maxAttempts,
|
|
2231
|
+
delay
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2086
2234
|
);
|
|
2087
2235
|
this.reconnectTimer = setTimeout(() => {
|
|
2088
2236
|
const { socket } = this.callKit.config.getConfig();
|
|
2089
2237
|
this.connect(socket);
|
|
2090
|
-
this.callKit.logger.debug("Reconnection attempt failed");
|
|
2091
|
-
if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
2092
|
-
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
2093
|
-
event: ConnectEvent.INCALL_RECONNECT_ERROR
|
|
2094
|
-
});
|
|
2095
|
-
this.isReconnecting = false;
|
|
2096
|
-
this.reset();
|
|
2097
|
-
}
|
|
2098
2238
|
}, delay);
|
|
2099
2239
|
}
|
|
2100
2240
|
};
|
|
2101
2241
|
|
|
2102
|
-
// package/user.ts
|
|
2103
|
-
var User = class {
|
|
2104
|
-
callKit;
|
|
2105
|
-
userStatus;
|
|
2106
|
-
// logout(1, "unregistered"), idle(2, "free"), break(3, "nap"), busy(4, "busy")
|
|
2107
|
-
userChangeStatusExecuting;
|
|
2108
|
-
constructor(callKit) {
|
|
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
|
-
});
|
|
2203
|
-
}
|
|
2204
|
-
/**
|
|
2205
|
-
*
|
|
2206
|
-
* @param status logout(1, "unregistered"), idle(2, "free"), break(3, "nap"), busy(4, "busy")
|
|
2207
|
-
*/
|
|
2208
|
-
async setUserStatus(status) {
|
|
2209
|
-
const { isAutoUpdateUserStatus } = this.callKit.config.getConfig();
|
|
2210
|
-
if (status === this.userStatus || !isAutoUpdateUserStatus)
|
|
2211
|
-
return;
|
|
2212
|
-
return this.updateUserStatus(status);
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Update user status
|
|
2216
|
-
* @param status
|
|
2217
|
-
*/
|
|
2218
|
-
async updateUserStatus(status) {
|
|
2219
|
-
if (this.userChangeStatusExecuting)
|
|
2220
|
-
return;
|
|
2221
|
-
const { agentId } = this.callKit.config.getConfig().userInfo;
|
|
2222
|
-
this.setUserChangeStatusExecuting(true);
|
|
2223
|
-
const postData = {
|
|
2224
|
-
agentId,
|
|
2225
|
-
userStatus: status
|
|
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);
|
|
2240
|
-
this.userStatus = status;
|
|
2241
|
-
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
2242
|
-
event: UserStatusChangeStepEnum.UserStatusChangeEnd
|
|
2243
|
-
});
|
|
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
|
-
});
|
|
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
|
-
);
|
|
2270
|
-
this.callKit.logger.error(err, {
|
|
2271
|
-
errCode: ErrorCode.API_USER_STATUS_UPDATE_ERROR
|
|
2272
|
-
});
|
|
2273
|
-
});
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* @description sdkLog
|
|
2277
|
-
* @param params
|
|
2278
|
-
* @returns
|
|
2279
|
-
*/
|
|
2280
|
-
async sendSdkLog(data) {
|
|
2281
|
-
return this.callKit.api.sdkLog(data);
|
|
2282
|
-
}
|
|
2283
|
-
async sendHangUpReason(data) {
|
|
2284
|
-
try {
|
|
2285
|
-
const sendData = data || {};
|
|
2286
|
-
this.callKit.socket.sendMessage(SocketSendEvent.HANG_UP_REASON, sendData);
|
|
2287
|
-
} catch (error) {
|
|
2288
|
-
this.callKit.logger.debug(error);
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
|
|
2293
2242
|
// package/index.ts
|
|
2294
2243
|
var CallKit = class {
|
|
2295
2244
|
api;
|
|
@@ -2298,11 +2247,15 @@ var CallKit = class {
|
|
|
2298
2247
|
callCenter;
|
|
2299
2248
|
connect;
|
|
2300
2249
|
socket;
|
|
2301
|
-
user;
|
|
2302
2250
|
listener = [];
|
|
2303
2251
|
constructor(options) {
|
|
2304
2252
|
this.config = new Config(this);
|
|
2253
|
+
this.api = new Api(this);
|
|
2254
|
+
this.connect = new Connect(this);
|
|
2255
|
+
this.callCenter = new Call(this);
|
|
2256
|
+
this.socket = new Socket(this);
|
|
2305
2257
|
this.config.setConfig("log", options.log);
|
|
2258
|
+
this.config.setConfig("trackLogs", options.trackLogs);
|
|
2306
2259
|
this.config.setConfig("audioRef", options.audioRef);
|
|
2307
2260
|
this.config.setConfig("host", options.host);
|
|
2308
2261
|
this.config.setConfig(
|
|
@@ -2310,24 +2263,21 @@ var CallKit = class {
|
|
|
2310
2263
|
options.constrains || constrainsDefault
|
|
2311
2264
|
);
|
|
2312
2265
|
this.config.setConfig("socket", options.socket);
|
|
2313
|
-
this.config.setConfig(
|
|
2314
|
-
"isAutoUpdateUserStatus",
|
|
2315
|
-
options.isAutoUpdateUserStatus === void 0 ? isAutoUpdateUserStatusDefault : options.isAutoUpdateUserStatus
|
|
2316
|
-
);
|
|
2317
2266
|
this.config.setConfig("reconnect", options.reconnect);
|
|
2318
2267
|
this.logger = new Logger(this, options.log);
|
|
2319
|
-
this.logger.
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
this.socket = new Socket(this);
|
|
2324
|
-
this.user = new User(this);
|
|
2268
|
+
this.logger.info("callKit init", {
|
|
2269
|
+
caller: "CallKit.init",
|
|
2270
|
+
content: options
|
|
2271
|
+
});
|
|
2325
2272
|
}
|
|
2326
2273
|
async login(username, password, extra = {
|
|
2327
2274
|
encryptionMethod: EncryptionMethod.INTERNAL
|
|
2328
2275
|
}) {
|
|
2329
2276
|
if (this.config.isLogin()) {
|
|
2330
|
-
this.logger.warn("already login"
|
|
2277
|
+
this.logger.warn("already login", {
|
|
2278
|
+
caller: "CallKit.login",
|
|
2279
|
+
content: { username, password, extra }
|
|
2280
|
+
});
|
|
2331
2281
|
return;
|
|
2332
2282
|
}
|
|
2333
2283
|
let encryptionPassword = "";
|
|
@@ -2343,48 +2293,73 @@ var CallKit = class {
|
|
|
2343
2293
|
encryptionPassword = (0, import_blueimp_md5.default)(username + (0, import_blueimp_md5.default)(password));
|
|
2344
2294
|
break;
|
|
2345
2295
|
}
|
|
2346
|
-
this.logger.
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
encryptionMethod,
|
|
2350
|
-
encryptionPassword
|
|
2351
|
-
});
|
|
2352
|
-
const user = await this.user.login({
|
|
2353
|
-
userName: username,
|
|
2354
|
-
password: encryptionPassword
|
|
2355
|
-
});
|
|
2356
|
-
if (user) {
|
|
2357
|
-
this.config.setConfig("userInfo", {
|
|
2358
|
-
wsUrl: `wss://${user.wsUrl}`,
|
|
2359
|
-
sessionId: user.sessionId,
|
|
2296
|
+
this.logger.info("login info:", {
|
|
2297
|
+
caller: "CallKit.login",
|
|
2298
|
+
content: {
|
|
2360
2299
|
username,
|
|
2361
|
-
password
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2300
|
+
password,
|
|
2301
|
+
encryptionMethod,
|
|
2302
|
+
encryptionPassword
|
|
2303
|
+
}
|
|
2304
|
+
});
|
|
2305
|
+
try {
|
|
2306
|
+
const user = await this.api.login({
|
|
2307
|
+
userName: username,
|
|
2308
|
+
password: encryptionPassword
|
|
2309
|
+
});
|
|
2310
|
+
if (user) {
|
|
2311
|
+
this.config.setConfig("userInfo", {
|
|
2312
|
+
wsUrl: `wss://${user.wsUrl}`,
|
|
2313
|
+
sessionId: user.sessionId,
|
|
2314
|
+
username,
|
|
2315
|
+
password: encryptionPassword,
|
|
2316
|
+
encryptionPassword,
|
|
2317
|
+
agentId: user.agentId,
|
|
2318
|
+
fsUserId: user.fsUserId,
|
|
2319
|
+
userPart: user.userPart,
|
|
2320
|
+
fsPassword: user.fsPassword,
|
|
2321
|
+
fsIp: user.fsIp,
|
|
2322
|
+
fsPort: user.fsPort,
|
|
2323
|
+
iceInfo: user.iceInfo,
|
|
2324
|
+
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
2325
|
+
logGather: user.logGather,
|
|
2326
|
+
// encryptionType is in extra
|
|
2327
|
+
...extra
|
|
2328
|
+
});
|
|
2329
|
+
this.socket.init();
|
|
2330
|
+
this.trigger(KitEvent.KIT_LOGIN_CHANGE, true);
|
|
2331
|
+
}
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
this.logger.error(error, {
|
|
2334
|
+
caller: "CallKit.login",
|
|
2335
|
+
content: {
|
|
2336
|
+
errCode: ErrorCode.API_USER_LOGIN_ERROR
|
|
2337
|
+
}
|
|
2374
2338
|
});
|
|
2375
|
-
this.socket.init();
|
|
2376
|
-
this.trigger(KitEvent.KIT_LOGIN_CHANGE, true);
|
|
2377
|
-
this.user.setUserStatus(UserStatus.offline);
|
|
2378
2339
|
}
|
|
2379
2340
|
}
|
|
2380
2341
|
async logout() {
|
|
2381
2342
|
if (!this.config.check())
|
|
2382
2343
|
return;
|
|
2383
|
-
this.
|
|
2384
|
-
|
|
2344
|
+
const { userInfo } = this.config.getConfig();
|
|
2345
|
+
this.logger.info("logout", {
|
|
2346
|
+
caller: "CallKit.logout",
|
|
2347
|
+
content: {
|
|
2348
|
+
sessionId: userInfo.sessionId
|
|
2349
|
+
}
|
|
2350
|
+
});
|
|
2385
2351
|
if (this.config.isLogin()) {
|
|
2386
|
-
const { sessionId } =
|
|
2387
|
-
|
|
2352
|
+
const { sessionId } = userInfo;
|
|
2353
|
+
try {
|
|
2354
|
+
await this.api.loginOut({ sessionId });
|
|
2355
|
+
} catch (error) {
|
|
2356
|
+
this.logger.error(error, {
|
|
2357
|
+
caller: "CallKit.logout",
|
|
2358
|
+
content: {
|
|
2359
|
+
errCode: ErrorCode.API_USER_LOGOUT_ERROR
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2388
2363
|
}
|
|
2389
2364
|
await this.hangup();
|
|
2390
2365
|
this.socket.reset(false);
|
|
@@ -2398,8 +2373,11 @@ var CallKit = class {
|
|
|
2398
2373
|
}) {
|
|
2399
2374
|
if (!this.config.check())
|
|
2400
2375
|
return;
|
|
2401
|
-
if (!this.connect.isRegistered
|
|
2402
|
-
this.logger.warn("Currently not registered"
|
|
2376
|
+
if (!this.connect.isRegistered) {
|
|
2377
|
+
this.logger.warn("Currently not registered", {
|
|
2378
|
+
caller: "CallKit.call",
|
|
2379
|
+
content: { extno, options }
|
|
2380
|
+
});
|
|
2403
2381
|
return;
|
|
2404
2382
|
}
|
|
2405
2383
|
const { sourceType, workOrderId } = options;
|
|
@@ -2413,25 +2391,43 @@ var CallKit = class {
|
|
|
2413
2391
|
this.config.setUserInfo("workOrderId", workOrderId);
|
|
2414
2392
|
}
|
|
2415
2393
|
}
|
|
2416
|
-
this.logger.
|
|
2394
|
+
this.logger.info("call", {
|
|
2395
|
+
caller: "CallKit.call",
|
|
2396
|
+
content: {
|
|
2397
|
+
extno,
|
|
2398
|
+
options
|
|
2399
|
+
}
|
|
2400
|
+
});
|
|
2417
2401
|
this.callCenter.callStart();
|
|
2418
2402
|
}
|
|
2419
2403
|
async refer(uri, options) {
|
|
2420
2404
|
if (!this.config.check())
|
|
2421
2405
|
return;
|
|
2422
|
-
this.logger.
|
|
2406
|
+
this.logger.info("refer", {
|
|
2407
|
+
caller: "CallKit.refer",
|
|
2408
|
+
content: {
|
|
2409
|
+
uri,
|
|
2410
|
+
options
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2423
2413
|
this.callCenter.callRefer(uri, options);
|
|
2424
2414
|
}
|
|
2425
2415
|
async register() {
|
|
2426
2416
|
if (!this.config.check())
|
|
2427
2417
|
return;
|
|
2428
|
-
this.logger.
|
|
2418
|
+
this.logger.info("register", {
|
|
2419
|
+
caller: "CallKit.register",
|
|
2420
|
+
content: {}
|
|
2421
|
+
});
|
|
2429
2422
|
this.connect.register();
|
|
2430
2423
|
}
|
|
2431
2424
|
async unregister() {
|
|
2432
2425
|
if (!this.config.check())
|
|
2433
2426
|
return;
|
|
2434
|
-
this.logger.
|
|
2427
|
+
this.logger.info("unregister", {
|
|
2428
|
+
caller: "CallKit.unregister",
|
|
2429
|
+
content: {}
|
|
2430
|
+
});
|
|
2435
2431
|
this.connect.unregister();
|
|
2436
2432
|
}
|
|
2437
2433
|
async stop() {
|
|
@@ -2440,9 +2436,19 @@ var CallKit = class {
|
|
|
2440
2436
|
async hangup() {
|
|
2441
2437
|
if (!this.config.check())
|
|
2442
2438
|
return;
|
|
2443
|
-
this.logger.
|
|
2439
|
+
this.logger.info("hangup", {
|
|
2440
|
+
caller: "CallKit.hangup",
|
|
2441
|
+
content: {
|
|
2442
|
+
connectStatus: this.connect.connectStatus
|
|
2443
|
+
}
|
|
2444
|
+
});
|
|
2444
2445
|
if (!this.connect.isConnecting() && !this.connect.isRinging() && !this.connect.isCalling() && !this.connect.isHolding()) {
|
|
2445
|
-
this.logger.warn("Currently not in a call"
|
|
2446
|
+
this.logger.warn("Currently not in a call", {
|
|
2447
|
+
caller: "CallKit.hangup",
|
|
2448
|
+
content: {
|
|
2449
|
+
connectStatus: this.connect.connectStatus
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2446
2452
|
return;
|
|
2447
2453
|
}
|
|
2448
2454
|
await this.callCenter.callEnd(true);
|
|
@@ -2450,51 +2456,58 @@ var CallKit = class {
|
|
|
2450
2456
|
hold() {
|
|
2451
2457
|
if (!this.config.check())
|
|
2452
2458
|
return;
|
|
2453
|
-
this.logger.
|
|
2459
|
+
this.logger.info("hold", {
|
|
2460
|
+
caller: "CallKit.hold",
|
|
2461
|
+
content: {
|
|
2462
|
+
connectStatus: this.connect.connectStatus
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2454
2465
|
this.callCenter.callHold();
|
|
2455
2466
|
}
|
|
2456
2467
|
unhold() {
|
|
2457
2468
|
if (!this.config.check())
|
|
2458
2469
|
return;
|
|
2459
|
-
this.logger.
|
|
2470
|
+
this.logger.info("unhold", {
|
|
2471
|
+
caller: "CallKit.unhold",
|
|
2472
|
+
content: {
|
|
2473
|
+
connectStatus: this.connect.connectStatus
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2460
2476
|
this.callCenter.callUnhold();
|
|
2461
2477
|
}
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
await this.user.setUserStatus(UserStatus.catNap);
|
|
2473
|
-
}
|
|
2474
|
-
async setBusy() {
|
|
2475
|
-
if (!this.config.check())
|
|
2476
|
-
return;
|
|
2477
|
-
this.logger.debug("setBusy");
|
|
2478
|
-
await this.user.setUserStatus(UserStatus.busy);
|
|
2478
|
+
/**
|
|
2479
|
+
* set userstatus
|
|
2480
|
+
* @param status
|
|
2481
|
+
*/
|
|
2482
|
+
setUserStatus(status) {
|
|
2483
|
+
const { agentId } = this.config.getConfig().userInfo;
|
|
2484
|
+
this.api.updateUserStatus({
|
|
2485
|
+
agentId,
|
|
2486
|
+
status
|
|
2487
|
+
});
|
|
2479
2488
|
}
|
|
2480
2489
|
async reset() {
|
|
2481
|
-
this.logger.
|
|
2490
|
+
this.logger.info("reset", {
|
|
2491
|
+
caller: "CallKit.reset",
|
|
2492
|
+
content: {
|
|
2493
|
+
connectStatus: this.connect.connectStatus
|
|
2494
|
+
}
|
|
2495
|
+
});
|
|
2482
2496
|
this.connect.reset();
|
|
2483
|
-
if (this.config.isLogin()) {
|
|
2484
|
-
await this.user.setUserStatus(UserStatus.online);
|
|
2485
|
-
} else {
|
|
2486
|
-
await this.user.setUserStatus(UserStatus.offline);
|
|
2487
|
-
}
|
|
2488
2497
|
}
|
|
2489
2498
|
on(event, callback) {
|
|
2490
|
-
this.logger.debug(`on ${event}`);
|
|
2491
2499
|
this.listener.push({
|
|
2492
2500
|
event,
|
|
2493
2501
|
callback
|
|
2494
2502
|
});
|
|
2495
2503
|
}
|
|
2496
2504
|
off(event, callback) {
|
|
2497
|
-
this.logger.
|
|
2505
|
+
this.logger.info(`off ${event}`, {
|
|
2506
|
+
caller: "CallKit.off",
|
|
2507
|
+
content: {
|
|
2508
|
+
event
|
|
2509
|
+
}
|
|
2510
|
+
});
|
|
2498
2511
|
if (callback) {
|
|
2499
2512
|
this.listener = this.listener.filter(
|
|
2500
2513
|
(item) => !(item.event === event && item.callback === callback)
|
|
@@ -2505,10 +2518,14 @@ var CallKit = class {
|
|
|
2505
2518
|
}
|
|
2506
2519
|
removeAllListeners() {
|
|
2507
2520
|
this.listener = this.listener.splice(0, this.listener.length);
|
|
2508
|
-
this.logger.
|
|
2521
|
+
this.logger.info("removeAllListeners", {
|
|
2522
|
+
caller: "CallKit.removeAllListeners",
|
|
2523
|
+
content: {
|
|
2524
|
+
listener: this.listener
|
|
2525
|
+
}
|
|
2526
|
+
});
|
|
2509
2527
|
}
|
|
2510
2528
|
trigger(event, data) {
|
|
2511
|
-
this.logger.debug(`trigger ${event}`, { data });
|
|
2512
2529
|
this.listener.forEach((item) => {
|
|
2513
2530
|
if (item.event === event) {
|
|
2514
2531
|
try {
|