@koi-design/callkit 2.0.6-beta.1 → 2.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.ts +103 -83
- package/dist/index.global.js +392 -283
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +392 -283
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +393 -285
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -156
package/dist/index.global.js
CHANGED
|
@@ -3227,7 +3227,8 @@ var WebCall = (() => {
|
|
|
3227
3227
|
if (this.isLogining) {
|
|
3228
3228
|
this.callKit.logger.info("login is already in progress cancel", {
|
|
3229
3229
|
caller: "Api.login",
|
|
3230
|
-
|
|
3230
|
+
type: "API",
|
|
3231
|
+
content: { userName: params.userName, timestamp: params.timestamp }
|
|
3231
3232
|
});
|
|
3232
3233
|
return;
|
|
3233
3234
|
}
|
|
@@ -3246,8 +3247,9 @@ var WebCall = (() => {
|
|
|
3246
3247
|
async loginOut(params) {
|
|
3247
3248
|
if (this.isLoginOuting) {
|
|
3248
3249
|
this.callKit.logger.info("loginOut is already in progress cancel", {
|
|
3250
|
+
type: "API",
|
|
3249
3251
|
caller: "Api.loginOut",
|
|
3250
|
-
content: { sessionId: params.sessionId }
|
|
3252
|
+
content: { sessionId: params.sessionId, timestamp: params.timestamp }
|
|
3251
3253
|
});
|
|
3252
3254
|
return;
|
|
3253
3255
|
}
|
|
@@ -3264,12 +3266,23 @@ var WebCall = (() => {
|
|
|
3264
3266
|
}
|
|
3265
3267
|
}
|
|
3266
3268
|
async trackLogs(log) {
|
|
3267
|
-
|
|
3268
|
-
{
|
|
3269
|
-
{
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3269
|
+
try {
|
|
3270
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
3271
|
+
const { sessionId } = userInfo;
|
|
3272
|
+
const formData = new FormData();
|
|
3273
|
+
formData.append("content", JSON.stringify([log]));
|
|
3274
|
+
const config = {
|
|
3275
|
+
url: `${host}/agent/user/sdkLog`,
|
|
3276
|
+
method: "post",
|
|
3277
|
+
data: formData,
|
|
3278
|
+
headers: {
|
|
3279
|
+
...sessionId ? { sessionId } : {}
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
await axios_default(config).catch(() => {
|
|
3283
|
+
});
|
|
3284
|
+
} catch (error) {
|
|
3285
|
+
}
|
|
3273
3286
|
}
|
|
3274
3287
|
/**
|
|
3275
3288
|
*
|
|
@@ -3283,7 +3296,7 @@ var WebCall = (() => {
|
|
|
3283
3296
|
data: params
|
|
3284
3297
|
});
|
|
3285
3298
|
}
|
|
3286
|
-
async post(config, extra = {}) {
|
|
3299
|
+
async post(config, extra = { skipLog: false }) {
|
|
3287
3300
|
const { userInfo, host } = this.callKit.config.getConfig();
|
|
3288
3301
|
const { sessionId } = userInfo;
|
|
3289
3302
|
config.url = `${host}${config.url}`;
|
|
@@ -3307,30 +3320,34 @@ var WebCall = (() => {
|
|
|
3307
3320
|
config.headers.sessionId = sessionId;
|
|
3308
3321
|
}
|
|
3309
3322
|
const startTime = Date.now();
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3323
|
+
if (!extra.skipLog) {
|
|
3324
|
+
this.callKit.logger.info("API Request Start", {
|
|
3325
|
+
type: "API",
|
|
3326
|
+
caller: "API.Request",
|
|
3327
|
+
content: {
|
|
3328
|
+
url: config.url,
|
|
3329
|
+
headers: config.headers,
|
|
3330
|
+
data: config.data,
|
|
3331
|
+
extra,
|
|
3332
|
+
startTime
|
|
3333
|
+
}
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3321
3336
|
const res = await axios_default(config).catch(() => {
|
|
3322
|
-
this.callKit.config.reset();
|
|
3337
|
+
this.callKit.config.reset("api request error");
|
|
3323
3338
|
});
|
|
3324
3339
|
const endTime = Date.now();
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3340
|
+
if (!extra.skipLog) {
|
|
3341
|
+
this.callKit.logger.info("API Request Finish", {
|
|
3342
|
+
type: "API",
|
|
3343
|
+
caller: "API.Request",
|
|
3344
|
+
content: {
|
|
3345
|
+
url: config.url,
|
|
3346
|
+
duration: `${endTime - startTime}ms`,
|
|
3347
|
+
response: res
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3334
3351
|
if (!res) {
|
|
3335
3352
|
this.callKit.reset();
|
|
3336
3353
|
throw new Error("Network error");
|
|
@@ -3340,7 +3357,7 @@ var WebCall = (() => {
|
|
|
3340
3357
|
return data;
|
|
3341
3358
|
}
|
|
3342
3359
|
if (code === "100013") {
|
|
3343
|
-
this.callKit.config.reset();
|
|
3360
|
+
this.callKit.config.reset("api request error");
|
|
3344
3361
|
}
|
|
3345
3362
|
throw new Error(message ?? "Request failed");
|
|
3346
3363
|
}
|
|
@@ -3673,7 +3690,8 @@ var WebCall = (() => {
|
|
|
3673
3690
|
* Error
|
|
3674
3691
|
*/
|
|
3675
3692
|
ERROR: "ERROR",
|
|
3676
|
-
SESSION_ERROR: "SESSION_ERROR"
|
|
3693
|
+
SESSION_ERROR: "SESSION_ERROR",
|
|
3694
|
+
WAITING_QUEUE: "WAITING_QUEUE"
|
|
3677
3695
|
};
|
|
3678
3696
|
var EncryptionMethod = {
|
|
3679
3697
|
NONE: "NONE",
|
|
@@ -3696,7 +3714,7 @@ var WebCall = (() => {
|
|
|
3696
3714
|
var trackLogsDefaultConfig = {
|
|
3697
3715
|
enabled: false,
|
|
3698
3716
|
interval: 5e3,
|
|
3699
|
-
maxSize:
|
|
3717
|
+
maxSize: 4096
|
|
3700
3718
|
};
|
|
3701
3719
|
var SOCKET_RECONNECT_CONFIG = {
|
|
3702
3720
|
enabled: true,
|
|
@@ -3708,9 +3726,7 @@ var WebCall = (() => {
|
|
|
3708
3726
|
var SIP_RECONNECT_CONFIG = {
|
|
3709
3727
|
enabled: true,
|
|
3710
3728
|
maxAttempts: 3,
|
|
3711
|
-
delay: 1e3
|
|
3712
|
-
enableMessageKeepalive: false,
|
|
3713
|
-
messageKeepaliveInterval: 3e4
|
|
3729
|
+
delay: 1e3
|
|
3714
3730
|
};
|
|
3715
3731
|
|
|
3716
3732
|
// core/call.ts
|
|
@@ -3854,13 +3870,13 @@ var WebCall = (() => {
|
|
|
3854
3870
|
// package.json
|
|
3855
3871
|
var package_default = {
|
|
3856
3872
|
name: "@koi-design/callkit",
|
|
3857
|
-
version: "2.0
|
|
3873
|
+
version: "2.1.0-beta.2",
|
|
3858
3874
|
description: "callkit",
|
|
3859
3875
|
author: "koi",
|
|
3860
3876
|
license: "ISC",
|
|
3861
3877
|
scripts: {
|
|
3862
3878
|
build: "tsup",
|
|
3863
|
-
|
|
3879
|
+
start: "vite",
|
|
3864
3880
|
dev: "tsup --watch",
|
|
3865
3881
|
lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
|
|
3866
3882
|
release: "tsup && node scripts/pkg.js"
|
|
@@ -3960,7 +3976,12 @@ var WebCall = (() => {
|
|
|
3960
3976
|
}
|
|
3961
3977
|
});
|
|
3962
3978
|
};
|
|
3963
|
-
reset = async () => {
|
|
3979
|
+
reset = async (form) => {
|
|
3980
|
+
this.callKit.logger.info(`Reset User Info ${form}`, {
|
|
3981
|
+
caller: "Config.reset",
|
|
3982
|
+
type: "OTHER",
|
|
3983
|
+
content: {}
|
|
3984
|
+
});
|
|
3964
3985
|
if (this.isLogin()) {
|
|
3965
3986
|
this.config.userInfo = {
|
|
3966
3987
|
wsUrl: "",
|
|
@@ -4055,7 +4076,7 @@ var WebCall = (() => {
|
|
|
4055
4076
|
this.flushTrackLogs();
|
|
4056
4077
|
}, interval);
|
|
4057
4078
|
}
|
|
4058
|
-
flushTrackLogs() {
|
|
4079
|
+
async flushTrackLogs() {
|
|
4059
4080
|
if (this.pendingTrackLogs.length === 0) {
|
|
4060
4081
|
return;
|
|
4061
4082
|
}
|
|
@@ -4064,25 +4085,22 @@ var WebCall = (() => {
|
|
|
4064
4085
|
try {
|
|
4065
4086
|
const chunks = [];
|
|
4066
4087
|
let currentChunk = [];
|
|
4067
|
-
let currentSize = 0;
|
|
4068
4088
|
for (const log of this.pendingTrackLogs) {
|
|
4069
|
-
const
|
|
4070
|
-
|
|
4071
|
-
const
|
|
4072
|
-
if (
|
|
4089
|
+
const testChunk = currentChunk.length > 0 ? `${currentChunk.join("\n")}
|
|
4090
|
+
${log}` : log;
|
|
4091
|
+
const actualSize = getByteSize(JSON.stringify([testChunk]));
|
|
4092
|
+
if (actualSize > maxSize && currentChunk.length > 0) {
|
|
4073
4093
|
chunks.push(currentChunk.join("\n"));
|
|
4074
4094
|
currentChunk = [log];
|
|
4075
|
-
currentSize = logSize;
|
|
4076
4095
|
} else {
|
|
4077
4096
|
currentChunk.push(log);
|
|
4078
|
-
currentSize += logSize + separatorSize;
|
|
4079
4097
|
}
|
|
4080
4098
|
}
|
|
4081
4099
|
if (currentChunk.length > 0) {
|
|
4082
4100
|
chunks.push(currentChunk.join("\n"));
|
|
4083
4101
|
}
|
|
4084
4102
|
for (const chunk of chunks) {
|
|
4085
|
-
this.callKit.api.trackLogs(chunk);
|
|
4103
|
+
await this.callKit.api.trackLogs(chunk);
|
|
4086
4104
|
}
|
|
4087
4105
|
this.pendingTrackLogs = [];
|
|
4088
4106
|
} catch (error) {
|
|
@@ -4141,16 +4159,22 @@ var WebCall = (() => {
|
|
|
4141
4159
|
}
|
|
4142
4160
|
catchLog(msg, extra, level) {
|
|
4143
4161
|
const now = /* @__PURE__ */ new Date();
|
|
4162
|
+
const { enabled } = this.callKit.config.getTrackLogsConfig();
|
|
4163
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
4164
|
+
const content = {
|
|
4165
|
+
...extra?.content ?? {},
|
|
4166
|
+
agentId: userInfo?.agentId,
|
|
4167
|
+
sessionId: userInfo?.sessionId
|
|
4168
|
+
};
|
|
4144
4169
|
const log = {
|
|
4145
4170
|
timestamp: now.toLocaleString().replace("T", " ").replace(".000Z", ""),
|
|
4146
4171
|
level,
|
|
4147
4172
|
message: msg,
|
|
4148
4173
|
caller: extra?.caller,
|
|
4149
4174
|
type: extra?.type,
|
|
4150
|
-
content
|
|
4175
|
+
content
|
|
4151
4176
|
};
|
|
4152
4177
|
const logString = transformLog(log);
|
|
4153
|
-
const { enabled } = this.callKit.config.getTrackLogsConfig();
|
|
4154
4178
|
if (enabled) {
|
|
4155
4179
|
this.pendingTrackLogs.push(logString);
|
|
4156
4180
|
}
|
|
@@ -18576,7 +18600,6 @@ var WebCall = (() => {
|
|
|
18576
18600
|
};
|
|
18577
18601
|
|
|
18578
18602
|
// core/connect.ts
|
|
18579
|
-
var MAX_HEARTBEAT_COUNT = 6;
|
|
18580
18603
|
function convertObjectStringToJSON(input) {
|
|
18581
18604
|
const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
|
|
18582
18605
|
return corrected;
|
|
@@ -18631,6 +18654,10 @@ var WebCall = (() => {
|
|
|
18631
18654
|
*@description Whether it's a re-connected
|
|
18632
18655
|
*/
|
|
18633
18656
|
isReConnected = false;
|
|
18657
|
+
/**
|
|
18658
|
+
*@description Whether it's a referring
|
|
18659
|
+
*/
|
|
18660
|
+
isRefering = false;
|
|
18634
18661
|
// sipConnected = false;
|
|
18635
18662
|
/**
|
|
18636
18663
|
*@description Whether it's an outgoing call
|
|
@@ -18652,6 +18679,42 @@ var WebCall = (() => {
|
|
|
18652
18679
|
}
|
|
18653
18680
|
// current call id for invite data
|
|
18654
18681
|
currentCallId = null;
|
|
18682
|
+
getCurrentCallId() {
|
|
18683
|
+
return this.currentCallId;
|
|
18684
|
+
}
|
|
18685
|
+
setRefering(refering) {
|
|
18686
|
+
if (this.isRefering === refering)
|
|
18687
|
+
return;
|
|
18688
|
+
this.callKit.logger.info("setRefering", {
|
|
18689
|
+
caller: "Connect.setRefering",
|
|
18690
|
+
content: {
|
|
18691
|
+
refering
|
|
18692
|
+
}
|
|
18693
|
+
});
|
|
18694
|
+
this.isRefering = refering;
|
|
18695
|
+
}
|
|
18696
|
+
setIsReConnected(isReConnected) {
|
|
18697
|
+
if (this.isReConnected === isReConnected)
|
|
18698
|
+
return;
|
|
18699
|
+
this.callKit.logger.info("setIsReConnected", {
|
|
18700
|
+
caller: "Connect.setIsReConnected",
|
|
18701
|
+
content: {
|
|
18702
|
+
isReConnected
|
|
18703
|
+
}
|
|
18704
|
+
});
|
|
18705
|
+
this.isReConnected = isReConnected;
|
|
18706
|
+
}
|
|
18707
|
+
setOutgoing(outgoing) {
|
|
18708
|
+
if (this.isOutgoing === outgoing)
|
|
18709
|
+
return;
|
|
18710
|
+
this.callKit.logger.info("setOutgoing", {
|
|
18711
|
+
caller: "Connect.setOutgoing",
|
|
18712
|
+
content: {
|
|
18713
|
+
outgoing
|
|
18714
|
+
}
|
|
18715
|
+
});
|
|
18716
|
+
this.isOutgoing = outgoing;
|
|
18717
|
+
}
|
|
18655
18718
|
setCallId(callId) {
|
|
18656
18719
|
this.callKit.logger.info("setCallId", {
|
|
18657
18720
|
caller: "Connect.setCallId",
|
|
@@ -18663,9 +18726,15 @@ var WebCall = (() => {
|
|
|
18663
18726
|
this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
|
|
18664
18727
|
}
|
|
18665
18728
|
async reset() {
|
|
18666
|
-
this.
|
|
18729
|
+
this.setOutgoing(false);
|
|
18667
18730
|
this.isUnprompted = false;
|
|
18668
18731
|
this.hasInvite = false;
|
|
18732
|
+
if (this.isRefering) {
|
|
18733
|
+
this.setRefering(false);
|
|
18734
|
+
}
|
|
18735
|
+
if (this.isReConnected) {
|
|
18736
|
+
this.setIsReConnected(false);
|
|
18737
|
+
}
|
|
18669
18738
|
if (this.isHolding()) {
|
|
18670
18739
|
await this.setHold(false);
|
|
18671
18740
|
}
|
|
@@ -18701,8 +18770,6 @@ var WebCall = (() => {
|
|
|
18701
18770
|
}
|
|
18702
18771
|
}
|
|
18703
18772
|
this.setConnectStatus(CallStatus.init);
|
|
18704
|
-
this.clearHeartbeat();
|
|
18705
|
-
this.stopMessageKeepalive();
|
|
18706
18773
|
}
|
|
18707
18774
|
getAduioReference() {
|
|
18708
18775
|
const { audioRef } = this.callKit.config.getConfig();
|
|
@@ -18767,73 +18834,6 @@ var WebCall = (() => {
|
|
|
18767
18834
|
isInit() {
|
|
18768
18835
|
return this.connectStatus === CallStatus.init;
|
|
18769
18836
|
}
|
|
18770
|
-
heartbeatInterval;
|
|
18771
|
-
heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18772
|
-
messageKeepaliveTimer;
|
|
18773
|
-
clearHeartbeat() {
|
|
18774
|
-
if (this.heartbeatInterval) {
|
|
18775
|
-
clearInterval(this.heartbeatInterval);
|
|
18776
|
-
this.heartbeatInterval = null;
|
|
18777
|
-
}
|
|
18778
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18779
|
-
}
|
|
18780
|
-
startHeartbeat() {
|
|
18781
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18782
|
-
this.clearHeartbeat();
|
|
18783
|
-
this.heartbeatInterval = setInterval(() => {
|
|
18784
|
-
this.heartbeatFlag -= 1;
|
|
18785
|
-
if (this.heartbeatFlag <= 0) {
|
|
18786
|
-
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18787
|
-
this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
|
|
18788
|
-
event: "OPTIONS_HEARTBEAT_EXPIRED"
|
|
18789
|
-
});
|
|
18790
|
-
}
|
|
18791
|
-
}, 1e3);
|
|
18792
|
-
}
|
|
18793
|
-
stopMessageKeepalive() {
|
|
18794
|
-
if (this.messageKeepaliveTimer) {
|
|
18795
|
-
clearInterval(this.messageKeepaliveTimer);
|
|
18796
|
-
this.messageKeepaliveTimer = void 0;
|
|
18797
|
-
}
|
|
18798
|
-
}
|
|
18799
|
-
startMessageKeepalive() {
|
|
18800
|
-
const { enableMessageKeepalive, messageKeepaliveInterval } = this.reconnectConfig;
|
|
18801
|
-
if (!enableMessageKeepalive)
|
|
18802
|
-
return;
|
|
18803
|
-
this.stopMessageKeepalive();
|
|
18804
|
-
this.messageKeepaliveTimer = setInterval(() => {
|
|
18805
|
-
this.sendKeepaliveMessage();
|
|
18806
|
-
}, messageKeepaliveInterval);
|
|
18807
|
-
}
|
|
18808
|
-
async sendKeepaliveMessage() {
|
|
18809
|
-
try {
|
|
18810
|
-
if (!this.isRegistered() || !this.userAgent)
|
|
18811
|
-
return;
|
|
18812
|
-
const { userInfo } = this.callKit.config.getConfig();
|
|
18813
|
-
const { userPart, fsIp, fsPort } = userInfo || {};
|
|
18814
|
-
const target = UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`);
|
|
18815
|
-
if (!target)
|
|
18816
|
-
return;
|
|
18817
|
-
const messager = new Messager(this.userAgent, target, "");
|
|
18818
|
-
await messager.message();
|
|
18819
|
-
this.callKit.logger.info("MESSAGE keepalive ok", {
|
|
18820
|
-
caller: "Connect.sendKeepaliveMessage",
|
|
18821
|
-
type: "SIP",
|
|
18822
|
-
content: {}
|
|
18823
|
-
});
|
|
18824
|
-
} catch (err) {
|
|
18825
|
-
this.callKit.logger.error(err, {
|
|
18826
|
-
caller: "Connect.sendKeepaliveMessage",
|
|
18827
|
-
type: "SIP",
|
|
18828
|
-
content: {}
|
|
18829
|
-
});
|
|
18830
|
-
this.stopMessageKeepalive();
|
|
18831
|
-
this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
|
|
18832
|
-
event: "MESSAGE_KEEPALIVE_FAILED"
|
|
18833
|
-
});
|
|
18834
|
-
this.startReconnectTimer();
|
|
18835
|
-
}
|
|
18836
|
-
}
|
|
18837
18837
|
socketTriggerHangup(callId) {
|
|
18838
18838
|
if (!this.isCalling() || callId !== this.currentCallId)
|
|
18839
18839
|
return;
|
|
@@ -18846,6 +18846,136 @@ var WebCall = (() => {
|
|
|
18846
18846
|
});
|
|
18847
18847
|
this.callKit.hangup();
|
|
18848
18848
|
}
|
|
18849
|
+
/**
|
|
18850
|
+
* Setup registerer and bind stateChange listener
|
|
18851
|
+
* @private
|
|
18852
|
+
*/
|
|
18853
|
+
setupRegisterer() {
|
|
18854
|
+
if (!this.userAgent) {
|
|
18855
|
+
this.callKit.logger.warn("userAgent is not initialized", {
|
|
18856
|
+
caller: "Connect.setupRegisterer",
|
|
18857
|
+
content: {
|
|
18858
|
+
errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
|
|
18859
|
+
}
|
|
18860
|
+
});
|
|
18861
|
+
return;
|
|
18862
|
+
}
|
|
18863
|
+
const { userInfo } = this.callKit.config.getConfig();
|
|
18864
|
+
const { userPart, fsIp, fsPort } = userInfo;
|
|
18865
|
+
const registererOptions = {};
|
|
18866
|
+
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
18867
|
+
this.registerer.stateChange.addListener((state) => {
|
|
18868
|
+
switch (state) {
|
|
18869
|
+
case RegistererState.Initial:
|
|
18870
|
+
this.callKit.logger.info("registerer stateChange Initial", {
|
|
18871
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18872
|
+
type: "SIP",
|
|
18873
|
+
content: {
|
|
18874
|
+
registererState: state,
|
|
18875
|
+
isRegistered: this.isRegistered()
|
|
18876
|
+
}
|
|
18877
|
+
});
|
|
18878
|
+
this.setRegister(false);
|
|
18879
|
+
this.setConnectStatus(CallStatus.init);
|
|
18880
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18881
|
+
registererState: state,
|
|
18882
|
+
isRegistered: this.isRegistered()
|
|
18883
|
+
});
|
|
18884
|
+
break;
|
|
18885
|
+
case RegistererState.Registered:
|
|
18886
|
+
this.callKit.logger.info("registerer stateChange Registered", {
|
|
18887
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18888
|
+
type: "SIP",
|
|
18889
|
+
content: {
|
|
18890
|
+
registererState: state,
|
|
18891
|
+
isRegistered: this.isRegistered()
|
|
18892
|
+
}
|
|
18893
|
+
});
|
|
18894
|
+
this.setRegister(true);
|
|
18895
|
+
if (this.isReConnected) {
|
|
18896
|
+
if (this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling()) {
|
|
18897
|
+
const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
|
|
18898
|
+
this.callKit.logger.info(
|
|
18899
|
+
"Reconnected, referring active session to self",
|
|
18900
|
+
{
|
|
18901
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18902
|
+
type: "SIP",
|
|
18903
|
+
content: {
|
|
18904
|
+
selfUri,
|
|
18905
|
+
sessionState: this.currentSession.state,
|
|
18906
|
+
connectStatus: this.connectStatus
|
|
18907
|
+
}
|
|
18908
|
+
}
|
|
18909
|
+
);
|
|
18910
|
+
this.refer(selfUri).catch((err) => {
|
|
18911
|
+
this.callKit.logger.error(err, {
|
|
18912
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18913
|
+
type: "SIP",
|
|
18914
|
+
content: {
|
|
18915
|
+
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
18916
|
+
selfUri
|
|
18917
|
+
}
|
|
18918
|
+
});
|
|
18919
|
+
});
|
|
18920
|
+
} else {
|
|
18921
|
+
this.callKit.logger.warn(
|
|
18922
|
+
"Reconnected but no active session to refer",
|
|
18923
|
+
{
|
|
18924
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18925
|
+
type: "SIP",
|
|
18926
|
+
content: {
|
|
18927
|
+
hasCurrentSession: !!this.currentSession,
|
|
18928
|
+
sessionState: this.currentSession?.state,
|
|
18929
|
+
connectStatus: this.connectStatus,
|
|
18930
|
+
isCalling: this.isCalling()
|
|
18931
|
+
}
|
|
18932
|
+
}
|
|
18933
|
+
);
|
|
18934
|
+
}
|
|
18935
|
+
this.setIsReConnected(false);
|
|
18936
|
+
}
|
|
18937
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18938
|
+
registererState: state,
|
|
18939
|
+
isRegistered: this.isRegistered()
|
|
18940
|
+
});
|
|
18941
|
+
break;
|
|
18942
|
+
case RegistererState.Terminated:
|
|
18943
|
+
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
18944
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18945
|
+
type: "SIP",
|
|
18946
|
+
content: {
|
|
18947
|
+
registererState: state,
|
|
18948
|
+
isRegistered: this.isRegistered()
|
|
18949
|
+
}
|
|
18950
|
+
});
|
|
18951
|
+
this.setRegister(false);
|
|
18952
|
+
this.setConnectStatus(CallStatus.init);
|
|
18953
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18954
|
+
registererState: state,
|
|
18955
|
+
isRegistered: this.isRegistered()
|
|
18956
|
+
});
|
|
18957
|
+
break;
|
|
18958
|
+
case RegistererState.Unregistered:
|
|
18959
|
+
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
18960
|
+
caller: "Connect.setupRegisterer.registererStateChange",
|
|
18961
|
+
type: "SIP",
|
|
18962
|
+
content: {
|
|
18963
|
+
isRegistered: this.isRegistered(),
|
|
18964
|
+
registererState: state
|
|
18965
|
+
}
|
|
18966
|
+
});
|
|
18967
|
+
this.setRegister(false);
|
|
18968
|
+
this.setConnectStatus(CallStatus.init);
|
|
18969
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18970
|
+
registererState: state,
|
|
18971
|
+
isRegistered: this.isRegistered()
|
|
18972
|
+
});
|
|
18973
|
+
break;
|
|
18974
|
+
default:
|
|
18975
|
+
break;
|
|
18976
|
+
}
|
|
18977
|
+
});
|
|
18978
|
+
}
|
|
18849
18979
|
async register() {
|
|
18850
18980
|
if (this.connectStatus !== CallStatus.init) {
|
|
18851
18981
|
if (this.isRegistered()) {
|
|
@@ -18886,7 +19016,7 @@ var WebCall = (() => {
|
|
|
18886
19016
|
this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);
|
|
18887
19017
|
return this.mediaStream;
|
|
18888
19018
|
};
|
|
18889
|
-
const { userPart, fsIp, fsPort, iceInfo, wsUrl
|
|
19019
|
+
const { userPart, fsIp, fsPort, iceInfo, wsUrl } = userInfo;
|
|
18890
19020
|
const connectConfig = {
|
|
18891
19021
|
uri: UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`),
|
|
18892
19022
|
displayName: userPart,
|
|
@@ -18904,9 +19034,7 @@ var WebCall = (() => {
|
|
|
18904
19034
|
peerConnectionConfiguration: {
|
|
18905
19035
|
iceServers: JSON.parse(convertObjectStringToJSON(iceInfo))
|
|
18906
19036
|
}
|
|
18907
|
-
}
|
|
18908
|
-
authorizationUsername: fsUserId || userPart,
|
|
18909
|
-
authorizationPassword: fsPassword
|
|
19037
|
+
}
|
|
18910
19038
|
};
|
|
18911
19039
|
this.callKit.logger.info("connect connectConfig", {
|
|
18912
19040
|
caller: "Connect.register",
|
|
@@ -18949,9 +19077,6 @@ var WebCall = (() => {
|
|
|
18949
19077
|
const core = userAgent.userAgentCore;
|
|
18950
19078
|
const originalReceiveIncomingRequestFromTransport = core.receiveIncomingRequestFromTransport.bind(core);
|
|
18951
19079
|
core.receiveIncomingRequestFromTransport = (request2) => {
|
|
18952
|
-
if (request2.method === "OPTIONS") {
|
|
18953
|
-
that.startHeartbeat();
|
|
18954
|
-
}
|
|
18955
19080
|
that.callKit.logger.info(`SIP Receive: ${request2?.method}`, {
|
|
18956
19081
|
caller: "Connect.register.observeSocketStatus.receiveRequest",
|
|
18957
19082
|
type: "SIP",
|
|
@@ -18961,6 +19086,20 @@ var WebCall = (() => {
|
|
|
18961
19086
|
});
|
|
18962
19087
|
return originalReceiveIncomingRequestFromTransport(request2);
|
|
18963
19088
|
};
|
|
19089
|
+
const originalReceiveIncomingResponseFromTransport = core.receiveIncomingResponseFromTransport.bind(core);
|
|
19090
|
+
core.receiveIncomingResponseFromTransport = (response) => {
|
|
19091
|
+
that.callKit.logger.info(
|
|
19092
|
+
`SIP Receive Response: ${response?.statusCode} ${response?.reasonPhrase}`,
|
|
19093
|
+
{
|
|
19094
|
+
caller: "Connect.register.observeSocketStatus.receiveResponse",
|
|
19095
|
+
type: "SIP",
|
|
19096
|
+
content: {
|
|
19097
|
+
response
|
|
19098
|
+
}
|
|
19099
|
+
}
|
|
19100
|
+
);
|
|
19101
|
+
return originalReceiveIncomingResponseFromTransport(response);
|
|
19102
|
+
};
|
|
18964
19103
|
const { transport } = userAgent;
|
|
18965
19104
|
if (transport) {
|
|
18966
19105
|
const originalSend = transport.send.bind(transport);
|
|
@@ -18976,81 +19115,7 @@ var WebCall = (() => {
|
|
|
18976
19115
|
};
|
|
18977
19116
|
}
|
|
18978
19117
|
};
|
|
18979
|
-
|
|
18980
|
-
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
18981
|
-
this.registerer.stateChange.addListener((state) => {
|
|
18982
|
-
switch (state) {
|
|
18983
|
-
case RegistererState.Initial:
|
|
18984
|
-
this.callKit.logger.info("registerer stateChange Initial", {
|
|
18985
|
-
caller: "Connect.register.registererStateChange",
|
|
18986
|
-
type: "SIP",
|
|
18987
|
-
content: {
|
|
18988
|
-
registererState: state,
|
|
18989
|
-
isRegistered: this.isRegistered()
|
|
18990
|
-
}
|
|
18991
|
-
});
|
|
18992
|
-
this.setRegister(false);
|
|
18993
|
-
this.setConnectStatus(CallStatus.init);
|
|
18994
|
-
this.stopMessageKeepalive();
|
|
18995
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18996
|
-
registererState: state,
|
|
18997
|
-
isRegistered: this.isRegistered()
|
|
18998
|
-
});
|
|
18999
|
-
break;
|
|
19000
|
-
case RegistererState.Registered:
|
|
19001
|
-
this.callKit.logger.info("registerer stateChange Registered", {
|
|
19002
|
-
caller: "Connect.register.registererStateChange",
|
|
19003
|
-
type: "SIP",
|
|
19004
|
-
content: {
|
|
19005
|
-
registererState: state,
|
|
19006
|
-
isRegistered: this.isRegistered()
|
|
19007
|
-
}
|
|
19008
|
-
});
|
|
19009
|
-
this.setRegister(true);
|
|
19010
|
-
this.startMessageKeepalive();
|
|
19011
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
19012
|
-
registererState: state,
|
|
19013
|
-
isRegistered: this.isRegistered()
|
|
19014
|
-
});
|
|
19015
|
-
break;
|
|
19016
|
-
case RegistererState.Terminated:
|
|
19017
|
-
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
19018
|
-
caller: "Connect.register.registererStateChange",
|
|
19019
|
-
type: "SIP",
|
|
19020
|
-
content: {
|
|
19021
|
-
registererState: state,
|
|
19022
|
-
isRegistered: this.isRegistered()
|
|
19023
|
-
}
|
|
19024
|
-
});
|
|
19025
|
-
this.setRegister(false);
|
|
19026
|
-
this.setConnectStatus(CallStatus.init);
|
|
19027
|
-
this.stopMessageKeepalive();
|
|
19028
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
19029
|
-
registererState: state,
|
|
19030
|
-
isRegistered: this.isRegistered()
|
|
19031
|
-
});
|
|
19032
|
-
break;
|
|
19033
|
-
case RegistererState.Unregistered:
|
|
19034
|
-
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
19035
|
-
caller: "Connect.register.registererStateChange",
|
|
19036
|
-
type: "SIP",
|
|
19037
|
-
content: {
|
|
19038
|
-
isRegistered: this.isRegistered(),
|
|
19039
|
-
registererState: state
|
|
19040
|
-
}
|
|
19041
|
-
});
|
|
19042
|
-
this.setRegister(false);
|
|
19043
|
-
this.setConnectStatus(CallStatus.init);
|
|
19044
|
-
this.stopMessageKeepalive();
|
|
19045
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
19046
|
-
registererState: state,
|
|
19047
|
-
isRegistered: this.isRegistered()
|
|
19048
|
-
});
|
|
19049
|
-
break;
|
|
19050
|
-
default:
|
|
19051
|
-
break;
|
|
19052
|
-
}
|
|
19053
|
-
});
|
|
19118
|
+
this.setupRegisterer();
|
|
19054
19119
|
this.userAgent.delegate = {
|
|
19055
19120
|
onInvite: (invite) => {
|
|
19056
19121
|
this.callKit.logger.info("connect onInvite", {
|
|
@@ -19058,7 +19123,8 @@ var WebCall = (() => {
|
|
|
19058
19123
|
caller: "Connect.register.onInvite",
|
|
19059
19124
|
content: {
|
|
19060
19125
|
invite,
|
|
19061
|
-
isRegistered: this.isRegistered()
|
|
19126
|
+
isRegistered: this.isRegistered(),
|
|
19127
|
+
isOutgoing: this.isOutgoing
|
|
19062
19128
|
}
|
|
19063
19129
|
});
|
|
19064
19130
|
this.currentSession = invite;
|
|
@@ -19136,7 +19202,9 @@ var WebCall = (() => {
|
|
|
19136
19202
|
});
|
|
19137
19203
|
this.callKit.logger.info("get invite data", {
|
|
19138
19204
|
caller: "Connect.register.onInvite",
|
|
19139
|
-
content:
|
|
19205
|
+
content: {
|
|
19206
|
+
headers: xHeaders
|
|
19207
|
+
}
|
|
19140
19208
|
});
|
|
19141
19209
|
return xHeaders;
|
|
19142
19210
|
};
|
|
@@ -19157,9 +19225,16 @@ var WebCall = (() => {
|
|
|
19157
19225
|
} catch (error) {
|
|
19158
19226
|
this.callKit.logger.info(error, {
|
|
19159
19227
|
caller: "Connect.register.onInvite",
|
|
19160
|
-
content:
|
|
19228
|
+
content: {
|
|
19229
|
+
headers: info
|
|
19230
|
+
}
|
|
19161
19231
|
});
|
|
19162
19232
|
}
|
|
19233
|
+
if (this.isRefering) {
|
|
19234
|
+
this.currentSession.accept(options);
|
|
19235
|
+
this.setRefering(false);
|
|
19236
|
+
return;
|
|
19237
|
+
}
|
|
19163
19238
|
if (this.isOutgoing) {
|
|
19164
19239
|
this.currentSession.accept(options);
|
|
19165
19240
|
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
@@ -19195,10 +19270,8 @@ var WebCall = (() => {
|
|
|
19195
19270
|
version: `${this.callKit.config.getConfig().version}`
|
|
19196
19271
|
}
|
|
19197
19272
|
});
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
this.startMessageKeepalive();
|
|
19201
|
-
} catch (err) {
|
|
19273
|
+
this.setupRegisterer();
|
|
19274
|
+
await this.registerer.register().catch(async (err) => {
|
|
19202
19275
|
this.callKit.reset();
|
|
19203
19276
|
this.callKit.logger.error(err?.message, {
|
|
19204
19277
|
caller: "Connect.register",
|
|
@@ -19207,12 +19280,11 @@ var WebCall = (() => {
|
|
|
19207
19280
|
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
19208
19281
|
}
|
|
19209
19282
|
});
|
|
19210
|
-
}
|
|
19283
|
+
});
|
|
19211
19284
|
},
|
|
19212
19285
|
onDisconnect: (error) => {
|
|
19213
|
-
this.stopMessageKeepalive();
|
|
19214
19286
|
if (error) {
|
|
19215
|
-
this.callKit.logger.
|
|
19287
|
+
this.callKit.logger.warn("SIP User Agent Disconnected with error", {
|
|
19216
19288
|
caller: "Connect.register",
|
|
19217
19289
|
type: "SIP",
|
|
19218
19290
|
content: {
|
|
@@ -19222,21 +19294,12 @@ var WebCall = (() => {
|
|
|
19222
19294
|
});
|
|
19223
19295
|
this.startReconnectTimer();
|
|
19224
19296
|
} else {
|
|
19225
|
-
this.callKit.logger.
|
|
19297
|
+
this.callKit.logger.warn("SIP User Agent Disconnected", {
|
|
19226
19298
|
caller: "Connect.register",
|
|
19227
19299
|
type: "SIP",
|
|
19228
19300
|
content: {}
|
|
19229
19301
|
});
|
|
19230
19302
|
}
|
|
19231
|
-
},
|
|
19232
|
-
onRegister: () => {
|
|
19233
|
-
this.callKit.logger.info("connect onRegister", {
|
|
19234
|
-
caller: "Connect.register",
|
|
19235
|
-
type: "SIP",
|
|
19236
|
-
content: {
|
|
19237
|
-
version: `V${this.callKit.config.getConfig().version}`
|
|
19238
|
-
}
|
|
19239
|
-
});
|
|
19240
19303
|
}
|
|
19241
19304
|
};
|
|
19242
19305
|
observeSocketStatus(this.userAgent, {
|
|
@@ -19282,6 +19345,7 @@ var WebCall = (() => {
|
|
|
19282
19345
|
this.reconnectTimer = setTimeout(() => {
|
|
19283
19346
|
if (this.reconnectTimer && this.callKit.config.isLogin()) {
|
|
19284
19347
|
this.userAgent?.reconnect();
|
|
19348
|
+
this.setIsReConnected(true);
|
|
19285
19349
|
this.callKit.logger.info("Reconnect attempt", {
|
|
19286
19350
|
caller: "Connect.startReconnectTimer",
|
|
19287
19351
|
type: "SIP",
|
|
@@ -19306,7 +19370,6 @@ var WebCall = (() => {
|
|
|
19306
19370
|
}
|
|
19307
19371
|
async stop() {
|
|
19308
19372
|
await this.userAgent.stop();
|
|
19309
|
-
this.stopMessageKeepalive();
|
|
19310
19373
|
}
|
|
19311
19374
|
async unregister() {
|
|
19312
19375
|
this.callKit.logger.info("connect unregister", {
|
|
@@ -19316,7 +19379,6 @@ var WebCall = (() => {
|
|
|
19316
19379
|
isRegistered: this.isRegistered()
|
|
19317
19380
|
}
|
|
19318
19381
|
});
|
|
19319
|
-
this.stopMessageKeepalive();
|
|
19320
19382
|
if (!this.isRegistered() || !this.registerer) {
|
|
19321
19383
|
this.callKit.logger.warn("No registerer to unregister.", {
|
|
19322
19384
|
caller: "Connect.unregister",
|
|
@@ -19349,20 +19411,20 @@ var WebCall = (() => {
|
|
|
19349
19411
|
});
|
|
19350
19412
|
}
|
|
19351
19413
|
async call(callback) {
|
|
19352
|
-
this.
|
|
19353
|
-
caller: "Connect.call",
|
|
19354
|
-
type: "SIP",
|
|
19355
|
-
content: {
|
|
19356
|
-
callback
|
|
19357
|
-
}
|
|
19358
|
-
});
|
|
19359
|
-
this.isOutgoing = true;
|
|
19414
|
+
this.setOutgoing(true);
|
|
19360
19415
|
if (!this.isRegistered()) {
|
|
19361
19416
|
await this.register();
|
|
19362
19417
|
}
|
|
19363
19418
|
this.setConnectStatus(CallStatus.connecting);
|
|
19364
19419
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
19365
19420
|
const { userInfo } = this.callKit.config.getConfig();
|
|
19421
|
+
this.callKit.logger.info("connect call", {
|
|
19422
|
+
caller: "Connect.call",
|
|
19423
|
+
type: "SIP",
|
|
19424
|
+
content: {
|
|
19425
|
+
userInfo
|
|
19426
|
+
}
|
|
19427
|
+
});
|
|
19366
19428
|
callback(userInfo);
|
|
19367
19429
|
}
|
|
19368
19430
|
/**
|
|
@@ -19413,7 +19475,7 @@ var WebCall = (() => {
|
|
|
19413
19475
|
connectStatus: this.connectStatus
|
|
19414
19476
|
}
|
|
19415
19477
|
});
|
|
19416
|
-
this.
|
|
19478
|
+
this.setOutgoing(false);
|
|
19417
19479
|
this.isUnprompted = isUnprompted;
|
|
19418
19480
|
this.setHold(false);
|
|
19419
19481
|
this.setMute(false);
|
|
@@ -19441,6 +19503,7 @@ var WebCall = (() => {
|
|
|
19441
19503
|
}
|
|
19442
19504
|
this.setConnectStatus(CallStatus.init);
|
|
19443
19505
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19506
|
+
this.setCallId(null);
|
|
19444
19507
|
} catch (err) {
|
|
19445
19508
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
19446
19509
|
this.callKit.reset();
|
|
@@ -19567,12 +19630,26 @@ var WebCall = (() => {
|
|
|
19567
19630
|
this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19568
19631
|
}
|
|
19569
19632
|
async refer(referTo, extra) {
|
|
19633
|
+
if (!this.currentSession) {
|
|
19634
|
+
const errorMsg = "Cannot refer: currentSession is not available";
|
|
19635
|
+
this.callKit.logger.warn(errorMsg, {
|
|
19636
|
+
caller: "Connect.refer",
|
|
19637
|
+
type: "SIP",
|
|
19638
|
+
content: {
|
|
19639
|
+
errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
|
|
19640
|
+
referTo
|
|
19641
|
+
}
|
|
19642
|
+
});
|
|
19643
|
+
return;
|
|
19644
|
+
}
|
|
19645
|
+
this.setRefering(true);
|
|
19570
19646
|
this.callKit.logger.info("connect refer", {
|
|
19571
19647
|
caller: "Connect.refer",
|
|
19572
19648
|
type: "SIP",
|
|
19573
19649
|
content: {
|
|
19574
19650
|
referTo,
|
|
19575
|
-
extra
|
|
19651
|
+
extra,
|
|
19652
|
+
sessionState: this.currentSession.state
|
|
19576
19653
|
}
|
|
19577
19654
|
});
|
|
19578
19655
|
let target;
|
|
@@ -19584,6 +19661,7 @@ var WebCall = (() => {
|
|
|
19584
19661
|
};
|
|
19585
19662
|
|
|
19586
19663
|
// core/socket.ts
|
|
19664
|
+
var EXCLUDE_LOG_EVENTS = [SocketReceiveEvent.WAITING_QUEUE];
|
|
19587
19665
|
var Socket = class {
|
|
19588
19666
|
callKit;
|
|
19589
19667
|
ws;
|
|
@@ -19770,9 +19848,9 @@ var WebCall = (() => {
|
|
|
19770
19848
|
}
|
|
19771
19849
|
onMessage(ev) {
|
|
19772
19850
|
const data = JSON.parse(ev.data);
|
|
19773
|
-
let content =
|
|
19851
|
+
let content = data.data;
|
|
19774
19852
|
try {
|
|
19775
|
-
if (data.data) {
|
|
19853
|
+
if (typeof data.data === "string" && data.data) {
|
|
19776
19854
|
content = JSON.parse(data.data);
|
|
19777
19855
|
}
|
|
19778
19856
|
} catch (error) {
|
|
@@ -19783,17 +19861,19 @@ var WebCall = (() => {
|
|
|
19783
19861
|
data: data.data
|
|
19784
19862
|
}
|
|
19785
19863
|
});
|
|
19786
|
-
content = data.data;
|
|
19787
19864
|
}
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
|
|
19791
|
-
|
|
19792
|
-
|
|
19793
|
-
|
|
19794
|
-
|
|
19795
|
-
|
|
19865
|
+
if (!EXCLUDE_LOG_EVENTS.includes(data.event)) {
|
|
19866
|
+
this.callKit.logger.info(`socket onMessage: ${data.event}`, {
|
|
19867
|
+
caller: "Socket.onMessage",
|
|
19868
|
+
type: "INCALL",
|
|
19869
|
+
content: {
|
|
19870
|
+
data: content,
|
|
19871
|
+
event: data.event
|
|
19872
|
+
}
|
|
19873
|
+
});
|
|
19874
|
+
}
|
|
19796
19875
|
this.confirmAck(data);
|
|
19876
|
+
const callUuid = content?.callUuid || "";
|
|
19797
19877
|
if (data.event === SocketReceiveEvent.PONG) {
|
|
19798
19878
|
this.lastPingTime = Date.now();
|
|
19799
19879
|
return;
|
|
@@ -19803,32 +19883,51 @@ var WebCall = (() => {
|
|
|
19803
19883
|
this.cleanReconnectState();
|
|
19804
19884
|
}
|
|
19805
19885
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
19806
|
-
this.callKit.trigger(KitEvent.CALL_RINGING,
|
|
19886
|
+
this.callKit.trigger(KitEvent.CALL_RINGING, {
|
|
19887
|
+
time: /* @__PURE__ */ new Date(),
|
|
19888
|
+
callUuid
|
|
19889
|
+
});
|
|
19807
19890
|
}
|
|
19808
19891
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
19809
|
-
this.callKit.trigger(KitEvent.CALL_PICK_UP,
|
|
19892
|
+
this.callKit.trigger(KitEvent.CALL_PICK_UP, {
|
|
19893
|
+
time: /* @__PURE__ */ new Date(),
|
|
19894
|
+
callUuid
|
|
19895
|
+
});
|
|
19810
19896
|
}
|
|
19811
19897
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
19812
|
-
this.callKit.trigger(KitEvent.AGENT_PICK_UP,
|
|
19898
|
+
this.callKit.trigger(KitEvent.AGENT_PICK_UP, {
|
|
19899
|
+
time: /* @__PURE__ */ new Date(),
|
|
19900
|
+
callUuid
|
|
19901
|
+
});
|
|
19813
19902
|
}
|
|
19814
19903
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
19815
|
-
this.callKit.trigger(KitEvent.CALL_HANG_UP,
|
|
19816
|
-
|
|
19817
|
-
|
|
19904
|
+
this.callKit.trigger(KitEvent.CALL_HANG_UP, {
|
|
19905
|
+
time: /* @__PURE__ */ new Date(),
|
|
19906
|
+
callUuid
|
|
19907
|
+
});
|
|
19908
|
+
if (callUuid) {
|
|
19909
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19818
19910
|
}
|
|
19819
19911
|
}
|
|
19820
19912
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
19821
|
-
this.callKit.trigger(KitEvent.CALL_NO_ANSWER
|
|
19822
|
-
|
|
19823
|
-
|
|
19913
|
+
this.callKit.trigger(KitEvent.CALL_NO_ANSWER, {
|
|
19914
|
+
time: /* @__PURE__ */ new Date(),
|
|
19915
|
+
callUuid
|
|
19916
|
+
});
|
|
19917
|
+
if (callUuid) {
|
|
19918
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19824
19919
|
}
|
|
19825
19920
|
}
|
|
19826
19921
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
19827
|
-
this.callKit.trigger(KitEvent.CALL_CDR,
|
|
19922
|
+
this.callKit.trigger(KitEvent.CALL_CDR, {
|
|
19923
|
+
time: /* @__PURE__ */ new Date(),
|
|
19924
|
+
callUuid,
|
|
19925
|
+
...content
|
|
19926
|
+
});
|
|
19828
19927
|
}
|
|
19829
19928
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
19830
19929
|
const { userInfo } = this.callKit.config.getConfig();
|
|
19831
|
-
this.send(SocketSendEvent.END, { agentId: userInfo.agentId });
|
|
19930
|
+
this.send(SocketSendEvent.END, { agentId: userInfo.agentId, callUuid });
|
|
19832
19931
|
}
|
|
19833
19932
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
19834
19933
|
this.setConnectAuthState("isError", true);
|
|
@@ -19838,7 +19937,8 @@ var WebCall = (() => {
|
|
|
19838
19937
|
type: "INCALL",
|
|
19839
19938
|
content: {
|
|
19840
19939
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
19841
|
-
data: content
|
|
19940
|
+
data: content,
|
|
19941
|
+
callUuid
|
|
19842
19942
|
}
|
|
19843
19943
|
});
|
|
19844
19944
|
}
|
|
@@ -19850,21 +19950,29 @@ var WebCall = (() => {
|
|
|
19850
19950
|
type: "INCALL",
|
|
19851
19951
|
content: {
|
|
19852
19952
|
data: content,
|
|
19853
|
-
event: SocketReceiveEvent.SESSION_ERROR
|
|
19953
|
+
event: SocketReceiveEvent.SESSION_ERROR,
|
|
19954
|
+
callUuid
|
|
19854
19955
|
}
|
|
19855
19956
|
});
|
|
19856
19957
|
}
|
|
19857
19958
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
19858
|
-
if (
|
|
19859
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19959
|
+
if (callUuid) {
|
|
19960
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19860
19961
|
}
|
|
19861
19962
|
}
|
|
19862
19963
|
if (data.event === SocketReceiveEvent.AGENT_HANG_UP) {
|
|
19863
|
-
if (
|
|
19864
|
-
this.callKit.connect.socketTriggerHangup(
|
|
19964
|
+
if (callUuid) {
|
|
19965
|
+
this.callKit.connect.socketTriggerHangup(callUuid);
|
|
19865
19966
|
}
|
|
19866
19967
|
}
|
|
19867
|
-
this.callKit.trigger(
|
|
19968
|
+
this.callKit.trigger(
|
|
19969
|
+
KitEvent.SERVER_SOCKET_EVENT,
|
|
19970
|
+
{
|
|
19971
|
+
...data,
|
|
19972
|
+
callUuid
|
|
19973
|
+
},
|
|
19974
|
+
true
|
|
19975
|
+
);
|
|
19868
19976
|
}
|
|
19869
19977
|
send(event, message) {
|
|
19870
19978
|
if (!this.connectAuthState.isConnected) {
|
|
@@ -19912,18 +20020,11 @@ var WebCall = (() => {
|
|
|
19912
20020
|
caller: "Socket.send",
|
|
19913
20021
|
type: "INCALL",
|
|
19914
20022
|
content: {
|
|
19915
|
-
...msg
|
|
20023
|
+
...msg,
|
|
20024
|
+
userInfo
|
|
19916
20025
|
}
|
|
19917
20026
|
});
|
|
19918
|
-
|
|
19919
|
-
case SocketSendEvent.PING:
|
|
19920
|
-
this.lastPingTime = Date.now();
|
|
19921
|
-
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19922
|
-
break;
|
|
19923
|
-
default:
|
|
19924
|
-
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19925
|
-
break;
|
|
19926
|
-
}
|
|
20027
|
+
this.ws?.send(JSON.stringify({ event, ...msg }));
|
|
19927
20028
|
}
|
|
19928
20029
|
ping() {
|
|
19929
20030
|
if (!this.connectAuthState.isConnected)
|
|
@@ -19944,13 +20045,15 @@ var WebCall = (() => {
|
|
|
19944
20045
|
errCode: ErrorCode.SOCKET_PING_TIMEOUT
|
|
19945
20046
|
}
|
|
19946
20047
|
});
|
|
20048
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
20049
|
+
event: "INCALL_PING_TIMEOUT"
|
|
20050
|
+
});
|
|
19947
20051
|
}
|
|
19948
20052
|
}
|
|
19949
20053
|
checkPing() {
|
|
19950
20054
|
if (this.pingTimer) {
|
|
19951
20055
|
clearInterval(this.pingTimer);
|
|
19952
20056
|
}
|
|
19953
|
-
this.ping();
|
|
19954
20057
|
const { pingInterval } = this.reconnectConfig;
|
|
19955
20058
|
this.pingTimer = setInterval(() => {
|
|
19956
20059
|
this.ping();
|
|
@@ -19985,6 +20088,7 @@ var WebCall = (() => {
|
|
|
19985
20088
|
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19986
20089
|
event: "INCALL_RECONNECT_ERROR"
|
|
19987
20090
|
});
|
|
20091
|
+
this.setConnectAuthState("isError", true);
|
|
19988
20092
|
this.callKit.reset();
|
|
19989
20093
|
this.callKit.logger.error("Maximum reconnection attempts reached", {
|
|
19990
20094
|
caller: "Socket.attemptReconnect",
|
|
@@ -20113,7 +20217,8 @@ var WebCall = (() => {
|
|
|
20113
20217
|
try {
|
|
20114
20218
|
const user = await this.api.login({
|
|
20115
20219
|
userName: username,
|
|
20116
|
-
password: encryptionPassword
|
|
20220
|
+
password: encryptionPassword,
|
|
20221
|
+
timestamp: Date.now()
|
|
20117
20222
|
});
|
|
20118
20223
|
if (user) {
|
|
20119
20224
|
this.config.setConfig("userInfo", {
|
|
@@ -20159,7 +20264,7 @@ var WebCall = (() => {
|
|
|
20159
20264
|
if (this.config.isLogin()) {
|
|
20160
20265
|
const { sessionId } = userInfo;
|
|
20161
20266
|
try {
|
|
20162
|
-
await this.api.loginOut({ sessionId });
|
|
20267
|
+
await this.api.loginOut({ sessionId, timestamp: Date.now() });
|
|
20163
20268
|
} catch (error) {
|
|
20164
20269
|
this.logger.warn(error, {
|
|
20165
20270
|
caller: "CallKit.logout",
|
|
@@ -20172,7 +20277,7 @@ var WebCall = (() => {
|
|
|
20172
20277
|
if (isReset) {
|
|
20173
20278
|
await this.reset();
|
|
20174
20279
|
} else {
|
|
20175
|
-
this.config.reset();
|
|
20280
|
+
this.config.reset("logout");
|
|
20176
20281
|
}
|
|
20177
20282
|
}
|
|
20178
20283
|
async call(extno = "", options = {
|
|
@@ -20306,7 +20411,7 @@ var WebCall = (() => {
|
|
|
20306
20411
|
* set userstatus
|
|
20307
20412
|
* @param status
|
|
20308
20413
|
*/
|
|
20309
|
-
async setUserStatus(status) {
|
|
20414
|
+
async setUserStatus(status, extra = {}) {
|
|
20310
20415
|
const { agentId } = this.config.getConfig().userInfo;
|
|
20311
20416
|
this.logger.info("setUserStatus", {
|
|
20312
20417
|
caller: "CallKit.setUserStatus",
|
|
@@ -20317,7 +20422,9 @@ var WebCall = (() => {
|
|
|
20317
20422
|
});
|
|
20318
20423
|
await this.api.updateUserStatus({
|
|
20319
20424
|
agentId,
|
|
20320
|
-
userStatus: status
|
|
20425
|
+
userStatus: status,
|
|
20426
|
+
timestamp: Date.now(),
|
|
20427
|
+
...extra
|
|
20321
20428
|
});
|
|
20322
20429
|
}
|
|
20323
20430
|
/**
|
|
@@ -20342,7 +20449,7 @@ var WebCall = (() => {
|
|
|
20342
20449
|
if (this.config.isLogin()) {
|
|
20343
20450
|
await this.logout({ isReset: false });
|
|
20344
20451
|
} else {
|
|
20345
|
-
await this.config.reset();
|
|
20452
|
+
await this.config.reset("reset");
|
|
20346
20453
|
}
|
|
20347
20454
|
await this.socket.reset({ force });
|
|
20348
20455
|
}
|
|
@@ -20380,7 +20487,9 @@ var WebCall = (() => {
|
|
|
20380
20487
|
if (!noLog) {
|
|
20381
20488
|
this.logger.info(`Trigger Event: ${event}`, {
|
|
20382
20489
|
caller: "CallKit.trigger",
|
|
20383
|
-
content:
|
|
20490
|
+
content: {
|
|
20491
|
+
data
|
|
20492
|
+
}
|
|
20384
20493
|
});
|
|
20385
20494
|
}
|
|
20386
20495
|
this.listener.forEach((item) => {
|
|
@@ -20388,7 +20497,7 @@ var WebCall = (() => {
|
|
|
20388
20497
|
try {
|
|
20389
20498
|
item.callback(data);
|
|
20390
20499
|
} catch (err) {
|
|
20391
|
-
this.logger.error(
|
|
20500
|
+
this.logger.error(`Event callback error: ${event}`, err, true);
|
|
20392
20501
|
}
|
|
20393
20502
|
}
|
|
20394
20503
|
});
|