@koi-design/callkit 1.0.26-beta.2 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +56 -35
- package/dist/index.global.js +1004 -345
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +725 -320
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +732 -321
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.global.js
CHANGED
|
@@ -1083,16 +1083,16 @@ var WebCall = (() => {
|
|
|
1083
1083
|
createDebug.names = [];
|
|
1084
1084
|
createDebug.skips = [];
|
|
1085
1085
|
createDebug.formatters = {};
|
|
1086
|
-
function selectColor(
|
|
1086
|
+
function selectColor(namespace2) {
|
|
1087
1087
|
let hash = 0;
|
|
1088
|
-
for (let i = 0; i <
|
|
1089
|
-
hash = (hash << 5) - hash +
|
|
1088
|
+
for (let i = 0; i < namespace2.length; i++) {
|
|
1089
|
+
hash = (hash << 5) - hash + namespace2.charCodeAt(i);
|
|
1090
1090
|
hash |= 0;
|
|
1091
1091
|
}
|
|
1092
1092
|
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1093
1093
|
}
|
|
1094
1094
|
createDebug.selectColor = selectColor;
|
|
1095
|
-
function createDebug(
|
|
1095
|
+
function createDebug(namespace2) {
|
|
1096
1096
|
let prevTime;
|
|
1097
1097
|
let enableOverride = null;
|
|
1098
1098
|
let namespacesCache;
|
|
@@ -1131,9 +1131,9 @@ var WebCall = (() => {
|
|
|
1131
1131
|
const logFn = self.log || createDebug.log;
|
|
1132
1132
|
logFn.apply(self, args);
|
|
1133
1133
|
}
|
|
1134
|
-
debug.namespace =
|
|
1134
|
+
debug.namespace = namespace2;
|
|
1135
1135
|
debug.useColors = createDebug.useColors();
|
|
1136
|
-
debug.color = createDebug.selectColor(
|
|
1136
|
+
debug.color = createDebug.selectColor(namespace2);
|
|
1137
1137
|
debug.extend = extend;
|
|
1138
1138
|
debug.destroy = createDebug.destroy;
|
|
1139
1139
|
Object.defineProperty(debug, "enabled", {
|
|
@@ -1145,7 +1145,7 @@ var WebCall = (() => {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
if (namespacesCache !== createDebug.namespaces) {
|
|
1147
1147
|
namespacesCache = createDebug.namespaces;
|
|
1148
|
-
enabledCache = createDebug.enabled(
|
|
1148
|
+
enabledCache = createDebug.enabled(namespace2);
|
|
1149
1149
|
}
|
|
1150
1150
|
return enabledCache;
|
|
1151
1151
|
},
|
|
@@ -1158,8 +1158,8 @@ var WebCall = (() => {
|
|
|
1158
1158
|
}
|
|
1159
1159
|
return debug;
|
|
1160
1160
|
}
|
|
1161
|
-
function extend(
|
|
1162
|
-
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) +
|
|
1161
|
+
function extend(namespace2, delimiter) {
|
|
1162
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace2);
|
|
1163
1163
|
newDebug.log = this.log;
|
|
1164
1164
|
return newDebug;
|
|
1165
1165
|
}
|
|
@@ -1208,7 +1208,7 @@ var WebCall = (() => {
|
|
|
1208
1208
|
function disable() {
|
|
1209
1209
|
const namespaces = [
|
|
1210
1210
|
...createDebug.names,
|
|
1211
|
-
...createDebug.skips.map((
|
|
1211
|
+
...createDebug.skips.map((namespace2) => "-" + namespace2)
|
|
1212
1212
|
].join(",");
|
|
1213
1213
|
createDebug.enable("");
|
|
1214
1214
|
return namespaces;
|
|
@@ -3128,29 +3128,29 @@ var WebCall = (() => {
|
|
|
3128
3128
|
var Axios = require_Axios();
|
|
3129
3129
|
var mergeConfig = require_mergeConfig();
|
|
3130
3130
|
var defaults = require_defaults();
|
|
3131
|
-
function createInstance(
|
|
3132
|
-
var context = new Axios(
|
|
3131
|
+
function createInstance(defaultConfig) {
|
|
3132
|
+
var context = new Axios(defaultConfig);
|
|
3133
3133
|
var instance2 = bind(Axios.prototype.request, context);
|
|
3134
3134
|
utils.extend(instance2, Axios.prototype, context);
|
|
3135
3135
|
utils.extend(instance2, context);
|
|
3136
3136
|
instance2.create = function create(instanceConfig) {
|
|
3137
|
-
return createInstance(mergeConfig(
|
|
3137
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
3138
3138
|
};
|
|
3139
3139
|
return instance2;
|
|
3140
3140
|
}
|
|
3141
|
-
var
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3141
|
+
var axios2 = createInstance(defaults);
|
|
3142
|
+
axios2.Axios = Axios;
|
|
3143
|
+
axios2.Cancel = require_Cancel();
|
|
3144
|
+
axios2.CancelToken = require_CancelToken();
|
|
3145
|
+
axios2.isCancel = require_isCancel();
|
|
3146
|
+
axios2.VERSION = require_data().version;
|
|
3147
|
+
axios2.all = function all(promises) {
|
|
3148
3148
|
return Promise.all(promises);
|
|
3149
3149
|
};
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
module.exports =
|
|
3153
|
-
module.exports.default =
|
|
3150
|
+
axios2.spread = require_spread();
|
|
3151
|
+
axios2.isAxiosError = require_isAxiosError();
|
|
3152
|
+
module.exports = axios2;
|
|
3153
|
+
module.exports.default = axios2;
|
|
3154
3154
|
}
|
|
3155
3155
|
});
|
|
3156
3156
|
|
|
@@ -3161,6 +3161,78 @@ var WebCall = (() => {
|
|
|
3161
3161
|
}
|
|
3162
3162
|
});
|
|
3163
3163
|
|
|
3164
|
+
// node_modules/.pnpm/is-retry-allowed@2.2.0/node_modules/is-retry-allowed/index.js
|
|
3165
|
+
var require_is_retry_allowed = __commonJS({
|
|
3166
|
+
"node_modules/.pnpm/is-retry-allowed@2.2.0/node_modules/is-retry-allowed/index.js"(exports, module) {
|
|
3167
|
+
"use strict";
|
|
3168
|
+
var denyList = /* @__PURE__ */ new Set([
|
|
3169
|
+
"ENOTFOUND",
|
|
3170
|
+
"ENETUNREACH",
|
|
3171
|
+
// SSL errors from https://github.com/nodejs/node/blob/fc8e3e2cdc521978351de257030db0076d79e0ab/src/crypto/crypto_common.cc#L301-L328
|
|
3172
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
3173
|
+
"UNABLE_TO_GET_CRL",
|
|
3174
|
+
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
3175
|
+
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
3176
|
+
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
3177
|
+
"CERT_SIGNATURE_FAILURE",
|
|
3178
|
+
"CRL_SIGNATURE_FAILURE",
|
|
3179
|
+
"CERT_NOT_YET_VALID",
|
|
3180
|
+
"CERT_HAS_EXPIRED",
|
|
3181
|
+
"CRL_NOT_YET_VALID",
|
|
3182
|
+
"CRL_HAS_EXPIRED",
|
|
3183
|
+
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
3184
|
+
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
3185
|
+
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
3186
|
+
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
3187
|
+
"OUT_OF_MEM",
|
|
3188
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
3189
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
3190
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
3191
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
3192
|
+
"CERT_CHAIN_TOO_LONG",
|
|
3193
|
+
"CERT_REVOKED",
|
|
3194
|
+
"INVALID_CA",
|
|
3195
|
+
"PATH_LENGTH_EXCEEDED",
|
|
3196
|
+
"INVALID_PURPOSE",
|
|
3197
|
+
"CERT_UNTRUSTED",
|
|
3198
|
+
"CERT_REJECTED",
|
|
3199
|
+
"HOSTNAME_MISMATCH"
|
|
3200
|
+
]);
|
|
3201
|
+
module.exports = (error) => !denyList.has(error && error.code);
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
|
|
3205
|
+
// node_modules/.pnpm/json-stringify-safe@5.0.1/node_modules/json-stringify-safe/stringify.js
|
|
3206
|
+
var require_stringify = __commonJS({
|
|
3207
|
+
"node_modules/.pnpm/json-stringify-safe@5.0.1/node_modules/json-stringify-safe/stringify.js"(exports, module) {
|
|
3208
|
+
exports = module.exports = stringify2;
|
|
3209
|
+
exports.getSerialize = serializer;
|
|
3210
|
+
function stringify2(obj, replacer, spaces, cycleReplacer) {
|
|
3211
|
+
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
|
|
3212
|
+
}
|
|
3213
|
+
function serializer(replacer, cycleReplacer) {
|
|
3214
|
+
var stack = [], keys = [];
|
|
3215
|
+
if (cycleReplacer == null)
|
|
3216
|
+
cycleReplacer = function(key, value) {
|
|
3217
|
+
if (stack[0] === value)
|
|
3218
|
+
return "[Circular ~]";
|
|
3219
|
+
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
|
3220
|
+
};
|
|
3221
|
+
return function(key, value) {
|
|
3222
|
+
if (stack.length > 0) {
|
|
3223
|
+
var thisPos = stack.indexOf(this);
|
|
3224
|
+
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
3225
|
+
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
3226
|
+
if (~stack.indexOf(value))
|
|
3227
|
+
value = cycleReplacer.call(this, key, value);
|
|
3228
|
+
} else
|
|
3229
|
+
stack.push(value);
|
|
3230
|
+
return replacer == null ? value : replacer.call(this, key, value);
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
});
|
|
3235
|
+
|
|
3164
3236
|
// package/index.ts
|
|
3165
3237
|
var package_exports = {};
|
|
3166
3238
|
__export(package_exports, {
|
|
@@ -3170,94 +3242,218 @@ var WebCall = (() => {
|
|
|
3170
3242
|
|
|
3171
3243
|
// package/axios.ts
|
|
3172
3244
|
var import_axios = __toESM(require_axios2());
|
|
3173
|
-
var instance = import_axios.default.create({
|
|
3174
|
-
headers: {
|
|
3175
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
3176
|
-
}
|
|
3177
|
-
});
|
|
3178
|
-
instance.interceptors.request.use((config) => config);
|
|
3179
|
-
instance.interceptors.response.use(
|
|
3180
|
-
(response) => response.data,
|
|
3181
|
-
(error) => Promise.reject(error)
|
|
3182
|
-
);
|
|
3183
|
-
var request = (config) => instance.request(config);
|
|
3184
|
-
var axios_default = request;
|
|
3185
3245
|
|
|
3186
|
-
//
|
|
3187
|
-
var
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3246
|
+
// node_modules/.pnpm/axios-retry@4.5.0_axios@0.26.1/node_modules/axios-retry/dist/esm/index.js
|
|
3247
|
+
var import_is_retry_allowed = __toESM(require_is_retry_allowed(), 1);
|
|
3248
|
+
var namespace = "axios-retry";
|
|
3249
|
+
function isNetworkError(error) {
|
|
3250
|
+
const CODE_EXCLUDE_LIST = ["ERR_CANCELED", "ECONNABORTED"];
|
|
3251
|
+
if (error.response) {
|
|
3252
|
+
return false;
|
|
3191
3253
|
}
|
|
3192
|
-
|
|
3193
|
-
return
|
|
3194
|
-
url: "/auth/agentUser/login",
|
|
3195
|
-
method: "post",
|
|
3196
|
-
data: params
|
|
3197
|
-
});
|
|
3254
|
+
if (!error.code) {
|
|
3255
|
+
return false;
|
|
3198
3256
|
}
|
|
3199
|
-
|
|
3200
|
-
return
|
|
3201
|
-
url: "/auth/agentUser/loginOut",
|
|
3202
|
-
method: "post",
|
|
3203
|
-
data: params
|
|
3204
|
-
});
|
|
3257
|
+
if (CODE_EXCLUDE_LIST.includes(error.code)) {
|
|
3258
|
+
return false;
|
|
3205
3259
|
}
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
data: params
|
|
3217
|
-
});
|
|
3260
|
+
return (0, import_is_retry_allowed.default)(error);
|
|
3261
|
+
}
|
|
3262
|
+
var SAFE_HTTP_METHODS = ["get", "head", "options"];
|
|
3263
|
+
var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(["put", "delete"]);
|
|
3264
|
+
function isRetryableError(error) {
|
|
3265
|
+
return error.code !== "ECONNABORTED" && (!error.response || error.response.status === 429 || error.response.status >= 500 && error.response.status <= 599);
|
|
3266
|
+
}
|
|
3267
|
+
function isSafeRequestError(error) {
|
|
3268
|
+
if (!error.config?.method) {
|
|
3269
|
+
return false;
|
|
3218
3270
|
}
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3271
|
+
return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
|
|
3272
|
+
}
|
|
3273
|
+
function isIdempotentRequestError(error) {
|
|
3274
|
+
if (!error.config?.method) {
|
|
3275
|
+
return false;
|
|
3222
3276
|
}
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3277
|
+
return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
|
|
3278
|
+
}
|
|
3279
|
+
function isNetworkOrIdempotentRequestError(error) {
|
|
3280
|
+
return isNetworkError(error) || isIdempotentRequestError(error);
|
|
3281
|
+
}
|
|
3282
|
+
function retryAfter(error = void 0) {
|
|
3283
|
+
const retryAfterHeader = error?.response?.headers["retry-after"];
|
|
3284
|
+
if (!retryAfterHeader) {
|
|
3285
|
+
return 0;
|
|
3286
|
+
}
|
|
3287
|
+
let retryAfterMs = (Number(retryAfterHeader) || 0) * 1e3;
|
|
3288
|
+
if (retryAfterMs === 0) {
|
|
3289
|
+
retryAfterMs = (new Date(retryAfterHeader).valueOf() || 0) - Date.now();
|
|
3290
|
+
}
|
|
3291
|
+
return Math.max(0, retryAfterMs);
|
|
3292
|
+
}
|
|
3293
|
+
function noDelay(_retryNumber = 0, error = void 0) {
|
|
3294
|
+
return Math.max(0, retryAfter(error));
|
|
3295
|
+
}
|
|
3296
|
+
function exponentialDelay(retryNumber = 0, error = void 0, delayFactor = 100) {
|
|
3297
|
+
const calculatedDelay = 2 ** retryNumber * delayFactor;
|
|
3298
|
+
const delay = Math.max(calculatedDelay, retryAfter(error));
|
|
3299
|
+
const randomSum = delay * 0.2 * Math.random();
|
|
3300
|
+
return delay + randomSum;
|
|
3301
|
+
}
|
|
3302
|
+
function linearDelay(delayFactor = 100) {
|
|
3303
|
+
return (retryNumber = 0, error = void 0) => {
|
|
3304
|
+
const delay = retryNumber * delayFactor;
|
|
3305
|
+
return Math.max(delay, retryAfter(error));
|
|
3306
|
+
};
|
|
3307
|
+
}
|
|
3308
|
+
var DEFAULT_OPTIONS = {
|
|
3309
|
+
retries: 3,
|
|
3310
|
+
retryCondition: isNetworkOrIdempotentRequestError,
|
|
3311
|
+
retryDelay: noDelay,
|
|
3312
|
+
shouldResetTimeout: false,
|
|
3313
|
+
onRetry: () => {
|
|
3314
|
+
},
|
|
3315
|
+
onMaxRetryTimesExceeded: () => {
|
|
3316
|
+
},
|
|
3317
|
+
validateResponse: null
|
|
3318
|
+
};
|
|
3319
|
+
function getRequestOptions(config, defaultOptions) {
|
|
3320
|
+
return { ...DEFAULT_OPTIONS, ...defaultOptions, ...config[namespace] };
|
|
3321
|
+
}
|
|
3322
|
+
function setCurrentState(config, defaultOptions, resetLastRequestTime = false) {
|
|
3323
|
+
const currentState = getRequestOptions(config, defaultOptions || {});
|
|
3324
|
+
currentState.retryCount = currentState.retryCount || 0;
|
|
3325
|
+
if (!currentState.lastRequestTime || resetLastRequestTime) {
|
|
3326
|
+
currentState.lastRequestTime = Date.now();
|
|
3327
|
+
}
|
|
3328
|
+
config[namespace] = currentState;
|
|
3329
|
+
return currentState;
|
|
3330
|
+
}
|
|
3331
|
+
function fixConfig(axiosInstance, config) {
|
|
3332
|
+
if (axiosInstance.defaults.agent === config.agent) {
|
|
3333
|
+
delete config.agent;
|
|
3334
|
+
}
|
|
3335
|
+
if (axiosInstance.defaults.httpAgent === config.httpAgent) {
|
|
3336
|
+
delete config.httpAgent;
|
|
3337
|
+
}
|
|
3338
|
+
if (axiosInstance.defaults.httpsAgent === config.httpsAgent) {
|
|
3339
|
+
delete config.httpsAgent;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
async function shouldRetry(currentState, error) {
|
|
3343
|
+
const { retries, retryCondition } = currentState;
|
|
3344
|
+
const shouldRetryOrPromise = (currentState.retryCount || 0) < retries && retryCondition(error);
|
|
3345
|
+
if (typeof shouldRetryOrPromise === "object") {
|
|
3346
|
+
try {
|
|
3347
|
+
const shouldRetryPromiseResult = await shouldRetryOrPromise;
|
|
3348
|
+
return shouldRetryPromiseResult !== false;
|
|
3349
|
+
} catch (_err) {
|
|
3350
|
+
return false;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
return shouldRetryOrPromise;
|
|
3354
|
+
}
|
|
3355
|
+
async function handleRetry(axiosInstance, currentState, error, config) {
|
|
3356
|
+
currentState.retryCount += 1;
|
|
3357
|
+
const { retryDelay, shouldResetTimeout, onRetry } = currentState;
|
|
3358
|
+
const delay = retryDelay(currentState.retryCount, error);
|
|
3359
|
+
fixConfig(axiosInstance, config);
|
|
3360
|
+
if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
|
|
3361
|
+
const lastRequestDuration = Date.now() - currentState.lastRequestTime;
|
|
3362
|
+
const timeout = config.timeout - lastRequestDuration - delay;
|
|
3363
|
+
if (timeout <= 0) {
|
|
3364
|
+
return Promise.reject(error);
|
|
3365
|
+
}
|
|
3366
|
+
config.timeout = timeout;
|
|
3367
|
+
}
|
|
3368
|
+
config.transformRequest = [(data) => data];
|
|
3369
|
+
await onRetry(currentState.retryCount, error, config);
|
|
3370
|
+
if (config.signal?.aborted) {
|
|
3371
|
+
return Promise.resolve(axiosInstance(config));
|
|
3372
|
+
}
|
|
3373
|
+
return new Promise((resolve) => {
|
|
3374
|
+
const abortListener = () => {
|
|
3375
|
+
clearTimeout(timeout);
|
|
3376
|
+
resolve(axiosInstance(config));
|
|
3231
3377
|
};
|
|
3232
|
-
|
|
3233
|
-
|
|
3378
|
+
const timeout = setTimeout(() => {
|
|
3379
|
+
resolve(axiosInstance(config));
|
|
3380
|
+
if (config.signal?.removeEventListener) {
|
|
3381
|
+
config.signal.removeEventListener("abort", abortListener);
|
|
3382
|
+
}
|
|
3383
|
+
}, delay);
|
|
3384
|
+
if (config.signal?.addEventListener) {
|
|
3385
|
+
config.signal.addEventListener("abort", abortListener, { once: true });
|
|
3234
3386
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3387
|
+
});
|
|
3388
|
+
}
|
|
3389
|
+
async function handleMaxRetryTimesExceeded(currentState, error) {
|
|
3390
|
+
if (currentState.retryCount >= currentState.retries)
|
|
3391
|
+
await currentState.onMaxRetryTimesExceeded(error, currentState.retryCount);
|
|
3392
|
+
}
|
|
3393
|
+
var axiosRetry = (axiosInstance, defaultOptions) => {
|
|
3394
|
+
const requestInterceptorId = axiosInstance.interceptors.request.use((config) => {
|
|
3395
|
+
setCurrentState(config, defaultOptions, true);
|
|
3396
|
+
if (config[namespace]?.validateResponse) {
|
|
3397
|
+
config.validateStatus = () => false;
|
|
3237
3398
|
}
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3399
|
+
return config;
|
|
3400
|
+
});
|
|
3401
|
+
const responseInterceptorId = axiosInstance.interceptors.response.use(null, async (error) => {
|
|
3402
|
+
const { config } = error;
|
|
3403
|
+
if (!config) {
|
|
3404
|
+
return Promise.reject(error);
|
|
3244
3405
|
}
|
|
3245
|
-
const
|
|
3246
|
-
if (
|
|
3247
|
-
return
|
|
3406
|
+
const currentState = setCurrentState(config, defaultOptions);
|
|
3407
|
+
if (error.response && currentState.validateResponse?.(error.response)) {
|
|
3408
|
+
return error.response;
|
|
3248
3409
|
}
|
|
3249
|
-
if (
|
|
3250
|
-
|
|
3410
|
+
if (await shouldRetry(currentState, error)) {
|
|
3411
|
+
return handleRetry(axiosInstance, currentState, error, config);
|
|
3251
3412
|
}
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
...config,
|
|
3257
|
-
method: "get"
|
|
3258
|
-
});
|
|
3259
|
-
}
|
|
3413
|
+
await handleMaxRetryTimesExceeded(currentState, error);
|
|
3414
|
+
return Promise.reject(error);
|
|
3415
|
+
});
|
|
3416
|
+
return { requestInterceptorId, responseInterceptorId };
|
|
3260
3417
|
};
|
|
3418
|
+
axiosRetry.isNetworkError = isNetworkError;
|
|
3419
|
+
axiosRetry.isSafeRequestError = isSafeRequestError;
|
|
3420
|
+
axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
|
|
3421
|
+
axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
|
|
3422
|
+
axiosRetry.exponentialDelay = exponentialDelay;
|
|
3423
|
+
axiosRetry.linearDelay = linearDelay;
|
|
3424
|
+
axiosRetry.isRetryableError = isRetryableError;
|
|
3425
|
+
var esm_default = axiosRetry;
|
|
3426
|
+
|
|
3427
|
+
// package/axios.ts
|
|
3428
|
+
var instance = import_axios.default.create({
|
|
3429
|
+
headers: {
|
|
3430
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
3431
|
+
}
|
|
3432
|
+
});
|
|
3433
|
+
instance.interceptors.request.use((config) => config);
|
|
3434
|
+
instance.interceptors.response.use(
|
|
3435
|
+
(response) => response.data,
|
|
3436
|
+
(error) => Promise.reject(error)
|
|
3437
|
+
);
|
|
3438
|
+
esm_default(instance, {
|
|
3439
|
+
retries: 3,
|
|
3440
|
+
// Maximum number of retries, default is 3
|
|
3441
|
+
retryDelay: (retryCount, error) => {
|
|
3442
|
+
console.log(
|
|
3443
|
+
`AJAX Retrying attempt ${retryCount}, error: ${error?.message}`
|
|
3444
|
+
);
|
|
3445
|
+
return retryCount * 1e3;
|
|
3446
|
+
},
|
|
3447
|
+
retryCondition: (error) => {
|
|
3448
|
+
if (!error.response)
|
|
3449
|
+
return true;
|
|
3450
|
+
return error.response.status < 200 || error.response.status >= 300;
|
|
3451
|
+
},
|
|
3452
|
+
shouldResetTimeout: true
|
|
3453
|
+
// Whether to reset axios timeout on retry
|
|
3454
|
+
});
|
|
3455
|
+
var request = (config) => instance.request(config);
|
|
3456
|
+
var axios_default = request;
|
|
3261
3457
|
|
|
3262
3458
|
// package/const.ts
|
|
3263
3459
|
var UserStatus = {
|
|
@@ -3345,6 +3541,10 @@ var WebCall = (() => {
|
|
|
3345
3541
|
* Server initiated call
|
|
3346
3542
|
*/
|
|
3347
3543
|
KIT_INVITE: "invite",
|
|
3544
|
+
/**
|
|
3545
|
+
* Server outgoing initiated call
|
|
3546
|
+
*/
|
|
3547
|
+
KIT_OUTGOING_INVITE: "outgoingInvite",
|
|
3348
3548
|
// /**
|
|
3349
3549
|
// * Referral
|
|
3350
3550
|
// */
|
|
@@ -3389,14 +3589,10 @@ var WebCall = (() => {
|
|
|
3389
3589
|
* User status change
|
|
3390
3590
|
*/
|
|
3391
3591
|
USER_STATUS_CHANGE: "userStatusChange",
|
|
3392
|
-
/**
|
|
3393
|
-
* SOCKET CONNECT EVENT
|
|
3394
|
-
*/
|
|
3395
3592
|
CONNECT_EVENT: "CONNECT_EVENT",
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
NETWORK_EVENT: "NETWORK_EVENT"
|
|
3593
|
+
SIP_REGISTERER_EVENT: "sipRegistererEvent",
|
|
3594
|
+
SIP_SESSION_EVENT: "sipSessionEvent",
|
|
3595
|
+
USER_STATUS_CHANGE_STEP: "userStatusChangeStep"
|
|
3400
3596
|
};
|
|
3401
3597
|
var ErrorCode = {
|
|
3402
3598
|
/**
|
|
@@ -3531,7 +3727,9 @@ var WebCall = (() => {
|
|
|
3531
3727
|
/**
|
|
3532
3728
|
* AGENT_TRANSFER
|
|
3533
3729
|
*/
|
|
3534
|
-
HANG_UP_REASON: "HANG_UP_REASON"
|
|
3730
|
+
HANG_UP_REASON: "HANG_UP_REASON",
|
|
3731
|
+
ACK: "ACK",
|
|
3732
|
+
SDK_LOG: "SDK_LOG"
|
|
3535
3733
|
};
|
|
3536
3734
|
var SocketReceiveEvent = {
|
|
3537
3735
|
/**
|
|
@@ -3595,6 +3793,10 @@ var WebCall = (() => {
|
|
|
3595
3793
|
NONE: "NONE",
|
|
3596
3794
|
INTERNAL: "INTERNAL"
|
|
3597
3795
|
};
|
|
3796
|
+
var LogGatherEnum = {
|
|
3797
|
+
ENABLE: 1,
|
|
3798
|
+
DISABLE: 2
|
|
3799
|
+
};
|
|
3598
3800
|
var constrainsDefault = {
|
|
3599
3801
|
audio: {
|
|
3600
3802
|
autoGainControl: true,
|
|
@@ -3612,19 +3814,330 @@ var WebCall = (() => {
|
|
|
3612
3814
|
};
|
|
3613
3815
|
var ConnectEvent = {
|
|
3614
3816
|
SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
|
|
3817
|
+
SIP_RECONNECT_START: "SIP_RECONNECT_START",
|
|
3615
3818
|
SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
|
|
3616
3819
|
SIP_RECONNECT_SUCCESS: "SIP_RECONNECT_SUCCESS",
|
|
3820
|
+
SIP_RECONNECTING: "SIP_RECONNECTING",
|
|
3821
|
+
INCALL_NOT_CONNECTED: "INCALL_NOT_CONNECTED",
|
|
3617
3822
|
INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
|
|
3823
|
+
INCALL_RECONNECT_START: "INCALL_RECONNECT_START",
|
|
3618
3824
|
INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR",
|
|
3619
3825
|
INCALL_RECONNECT_SUCCESS: "INCALL_RECONNECT_SUCCESS",
|
|
3826
|
+
INCALL_RECONNECTING: "INCALL_RECONNECTING",
|
|
3620
3827
|
OPTIONS_HEARTBEAT_EXPIRED: "OPTIONS_HEARTBEAT_EXPIRED",
|
|
3621
|
-
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
3622
|
-
|
|
3623
|
-
|
|
3828
|
+
USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
|
|
3829
|
+
};
|
|
3830
|
+
var SipRegistererEvent = {
|
|
3831
|
+
Initial: "Initial",
|
|
3832
|
+
Registered: "Registered",
|
|
3833
|
+
Unregistered: "Unregistered",
|
|
3834
|
+
Terminated: "Terminated"
|
|
3835
|
+
};
|
|
3836
|
+
var SipSessionEvent = {
|
|
3837
|
+
Establishing: "Establishing",
|
|
3838
|
+
Established: "Established",
|
|
3839
|
+
Terminating: "Terminating",
|
|
3840
|
+
Terminated: "Terminated"
|
|
3624
3841
|
};
|
|
3625
|
-
var
|
|
3626
|
-
|
|
3627
|
-
|
|
3842
|
+
var UserStatusChangeStepEnum = {
|
|
3843
|
+
UserStatusChangeStart: "UserStatusChangeStart",
|
|
3844
|
+
UserStatusChangeEnd: "UserStatusChangeEnd",
|
|
3845
|
+
UserStatusChangeError: "UserStatusChangeError",
|
|
3846
|
+
// login
|
|
3847
|
+
UserStatusChangeLoginStart: "UserStatusChangeLoginStart",
|
|
3848
|
+
UserStatusChangeLoginEnd: "UserStatusChangeLoginEnd",
|
|
3849
|
+
UserStatusChangeLoginError: "UserStatusChangeLoginError",
|
|
3850
|
+
// logout
|
|
3851
|
+
UserStatusChangeLoginOutStart: "UserStatusChangeLoginOutStart",
|
|
3852
|
+
UserStatusChangeLoginOutEnd: "UserStatusChangeLoginOutEnd",
|
|
3853
|
+
UserStatusChangeLoginOutError: "UserStatusChangeLoginOutError"
|
|
3854
|
+
};
|
|
3855
|
+
var LogDataEnum = {
|
|
3856
|
+
SIP: "sip",
|
|
3857
|
+
INCALL: "incall",
|
|
3858
|
+
AJAX: "ajax",
|
|
3859
|
+
ERROR: "error",
|
|
3860
|
+
RECONNECT: "reconnect",
|
|
3861
|
+
ALL: "all"
|
|
3862
|
+
};
|
|
3863
|
+
|
|
3864
|
+
// package/logger.ts
|
|
3865
|
+
var import_json_stringify_safe = __toESM(require_stringify());
|
|
3866
|
+
function getLevel(level) {
|
|
3867
|
+
return LoggerLevelMap[level];
|
|
3868
|
+
}
|
|
3869
|
+
var Logger = class {
|
|
3870
|
+
prefix = "CallKit";
|
|
3871
|
+
level = "debug";
|
|
3872
|
+
logData = {
|
|
3873
|
+
sip: [],
|
|
3874
|
+
incall: [],
|
|
3875
|
+
ajax: [],
|
|
3876
|
+
error: [],
|
|
3877
|
+
reconnect: [],
|
|
3878
|
+
all: []
|
|
3879
|
+
};
|
|
3880
|
+
sendSdkLogData = [];
|
|
3881
|
+
callKit;
|
|
3882
|
+
constructor(callKit, level) {
|
|
3883
|
+
this.callKit = callKit;
|
|
3884
|
+
this.level = level || "debug";
|
|
3885
|
+
this.logData = {
|
|
3886
|
+
sip: [],
|
|
3887
|
+
incall: [],
|
|
3888
|
+
ajax: [],
|
|
3889
|
+
error: [],
|
|
3890
|
+
reconnect: [],
|
|
3891
|
+
all: []
|
|
3892
|
+
};
|
|
3893
|
+
this.sendSdkLogData = [];
|
|
3894
|
+
}
|
|
3895
|
+
static formatStrLog(logObj) {
|
|
3896
|
+
const {
|
|
3897
|
+
type = "info"
|
|
3898
|
+
// 默认等级
|
|
3899
|
+
} = logObj;
|
|
3900
|
+
const time = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
3901
|
+
const level = String(type).toUpperCase().padEnd(5, " ");
|
|
3902
|
+
const tagStr = logObj.typeag ? `[${logObj.type}]` : "";
|
|
3903
|
+
const msg = JSON.stringify(logObj);
|
|
3904
|
+
return `${time} [${level}] ${tagStr} ${msg}`.trim();
|
|
3905
|
+
}
|
|
3906
|
+
setLevel(level) {
|
|
3907
|
+
this.level = level;
|
|
3908
|
+
}
|
|
3909
|
+
debug(msg, extra) {
|
|
3910
|
+
if (getLevel(this.level) >= getLevel("debug")) {
|
|
3911
|
+
this.output("blue")(msg, extra);
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
log(msg, extra) {
|
|
3915
|
+
if (getLevel(this.level) >= getLevel("log")) {
|
|
3916
|
+
this.output("green")(msg, extra);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
warn(msg, extra) {
|
|
3920
|
+
if (getLevel(this.level) >= getLevel("warn")) {
|
|
3921
|
+
this.output("orange")(msg, extra);
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
error(msg, extra) {
|
|
3925
|
+
const message = msg?.message ?? msg;
|
|
3926
|
+
if (getLevel(this.level) >= getLevel("error")) {
|
|
3927
|
+
this.output("red")(message, extra);
|
|
3928
|
+
}
|
|
3929
|
+
const { errCode, ...rest } = extra;
|
|
3930
|
+
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
3931
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
3932
|
+
code: errorCode,
|
|
3933
|
+
msg: message,
|
|
3934
|
+
data: rest
|
|
3935
|
+
});
|
|
3936
|
+
this.callKit.reset();
|
|
3937
|
+
const error = new Error(message);
|
|
3938
|
+
error.name = "CallKitError";
|
|
3939
|
+
error.code = errorCode;
|
|
3940
|
+
error.data = rest;
|
|
3941
|
+
throw error;
|
|
3942
|
+
}
|
|
3943
|
+
addLogData(type, data = {}) {
|
|
3944
|
+
this.callKit.user.sendSdkLog({
|
|
3945
|
+
...data,
|
|
3946
|
+
type,
|
|
3947
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
3948
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
3949
|
+
});
|
|
3950
|
+
if (!this.callKit.config.isLogGatherEnable()) {
|
|
3951
|
+
return;
|
|
3952
|
+
}
|
|
3953
|
+
let logData = {
|
|
3954
|
+
type,
|
|
3955
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
3956
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
3957
|
+
data: ""
|
|
3958
|
+
};
|
|
3959
|
+
if (type === LogDataEnum.INCALL) {
|
|
3960
|
+
logData.data = (0, import_json_stringify_safe.default)({
|
|
3961
|
+
// customField
|
|
3962
|
+
callKitSocketFrom: data?.callKitSocketFrom,
|
|
3963
|
+
type: data?.ev.type || data?.type,
|
|
3964
|
+
data: data?.ev.data || data?.data,
|
|
3965
|
+
// message
|
|
3966
|
+
origin: data?.ev.origin || data?.origin,
|
|
3967
|
+
lastEventId: data?.ev.lastEventId || data?.lastEventId,
|
|
3968
|
+
isTrusted: data?.ev.isTrusted || data?.isTrusted,
|
|
3969
|
+
// close
|
|
3970
|
+
code: data?.ev.code || data?.code,
|
|
3971
|
+
reason: data?.ev.reason || data?.reason,
|
|
3972
|
+
wasClean: data?.ev.wasClean || data?.wasClean
|
|
3973
|
+
});
|
|
3974
|
+
} else {
|
|
3975
|
+
logData = (0, import_json_stringify_safe.default)(data);
|
|
3976
|
+
}
|
|
3977
|
+
switch (type) {
|
|
3978
|
+
case LogDataEnum.SIP:
|
|
3979
|
+
this.logData.sip.push(logData);
|
|
3980
|
+
this.logData.all.push(logData);
|
|
3981
|
+
break;
|
|
3982
|
+
case LogDataEnum.INCALL:
|
|
3983
|
+
this.logData.incall.push(logData);
|
|
3984
|
+
this.logData.all.push(logData);
|
|
3985
|
+
break;
|
|
3986
|
+
case LogDataEnum.AJAX:
|
|
3987
|
+
this.logData.ajax.push(logData);
|
|
3988
|
+
this.logData.all.push(logData);
|
|
3989
|
+
break;
|
|
3990
|
+
case LogDataEnum.RECONNECT:
|
|
3991
|
+
this.logData.reconnect.push(logData);
|
|
3992
|
+
this.logData.all.push(logData);
|
|
3993
|
+
break;
|
|
3994
|
+
case LogDataEnum.ERROR:
|
|
3995
|
+
this.logData.error.push(logData);
|
|
3996
|
+
this.logData.all.push(logData);
|
|
3997
|
+
break;
|
|
3998
|
+
default:
|
|
3999
|
+
this.logData.all.push(logData);
|
|
4000
|
+
break;
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
output(color) {
|
|
4004
|
+
return (msg, extra = {}) => {
|
|
4005
|
+
const now = /* @__PURE__ */ new Date();
|
|
4006
|
+
if (Object.keys(extra).length > 0) {
|
|
4007
|
+
console.log(
|
|
4008
|
+
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
4009
|
+
`color: ${color};`,
|
|
4010
|
+
"color:block;",
|
|
4011
|
+
extra,
|
|
4012
|
+
"color:#999;"
|
|
4013
|
+
);
|
|
4014
|
+
} else {
|
|
4015
|
+
console.log(
|
|
4016
|
+
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
4017
|
+
`color: ${color};`,
|
|
4018
|
+
"color:block;",
|
|
4019
|
+
"color:#999;"
|
|
4020
|
+
);
|
|
4021
|
+
}
|
|
4022
|
+
};
|
|
4023
|
+
}
|
|
4024
|
+
};
|
|
4025
|
+
|
|
4026
|
+
// package/api.ts
|
|
4027
|
+
var Api = class {
|
|
4028
|
+
callKit;
|
|
4029
|
+
constructor(callKit) {
|
|
4030
|
+
this.callKit = callKit;
|
|
4031
|
+
}
|
|
4032
|
+
async login(params) {
|
|
4033
|
+
return this.post({
|
|
4034
|
+
url: "/auth/agentUser/login",
|
|
4035
|
+
method: "post",
|
|
4036
|
+
data: params
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
async loginOut(params) {
|
|
4040
|
+
return this.post({
|
|
4041
|
+
url: "/auth/agentUser/loginOut",
|
|
4042
|
+
method: "post",
|
|
4043
|
+
data: params
|
|
4044
|
+
});
|
|
4045
|
+
}
|
|
4046
|
+
/**
|
|
4047
|
+
* @description sdkLog
|
|
4048
|
+
* @param params
|
|
4049
|
+
* @returns
|
|
4050
|
+
*/
|
|
4051
|
+
async sdkLog(data) {
|
|
4052
|
+
const strLog = Logger.formatStrLog(data);
|
|
4053
|
+
const allData = [this.callKit.logger.sendSdkLogData, strLog].join(",");
|
|
4054
|
+
const encoder = new TextEncoder();
|
|
4055
|
+
const size = encoder.encode(allData).length;
|
|
4056
|
+
if (size < 8192) {
|
|
4057
|
+
this.callKit.logger.sendSdkLogData.push(strLog);
|
|
4058
|
+
} else {
|
|
4059
|
+
const logsToSend = this.callKit.logger.sendSdkLogData.slice();
|
|
4060
|
+
this.callKit.logger.sendSdkLogData = [strLog];
|
|
4061
|
+
return this.post(
|
|
4062
|
+
{
|
|
4063
|
+
url: "/agent/user/sdkLog",
|
|
4064
|
+
method: "post",
|
|
4065
|
+
data: {
|
|
4066
|
+
content: logsToSend
|
|
4067
|
+
}
|
|
4068
|
+
},
|
|
4069
|
+
{
|
|
4070
|
+
useFormData: true
|
|
4071
|
+
}
|
|
4072
|
+
);
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
/**
|
|
4076
|
+
*
|
|
4077
|
+
* @param params agentId userStatus
|
|
4078
|
+
* @description userStatus: Logout(1, "unregistered"), Free(2, "free"), Break(3, "nap"), Busy(4, "busy")
|
|
4079
|
+
* @returns
|
|
4080
|
+
*/
|
|
4081
|
+
async setUserStatus(params) {
|
|
4082
|
+
return this.post({
|
|
4083
|
+
url: "/agent/user/changeStatus",
|
|
4084
|
+
method: "post",
|
|
4085
|
+
data: params
|
|
4086
|
+
});
|
|
4087
|
+
}
|
|
4088
|
+
async post(config, extra = {}) {
|
|
4089
|
+
this.callKit.logger.debug(`Request ${config.url}:`, config.data);
|
|
4090
|
+
const { userInfo, host } = this.callKit.config.getConfig();
|
|
4091
|
+
const { sessionId } = userInfo;
|
|
4092
|
+
config.url = `${host}${config.url}`;
|
|
4093
|
+
config.headers = {
|
|
4094
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
4095
|
+
...config.headers
|
|
4096
|
+
};
|
|
4097
|
+
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded" && extra.useFormData) {
|
|
4098
|
+
const formData = new FormData();
|
|
4099
|
+
const data2 = config.data || {};
|
|
4100
|
+
for (const key in data2) {
|
|
4101
|
+
if (Object.prototype.hasOwnProperty.call(data2, key)) {
|
|
4102
|
+
formData.append(key, data2[key]);
|
|
4103
|
+
}
|
|
4104
|
+
}
|
|
4105
|
+
config.data = formData;
|
|
4106
|
+
} else {
|
|
4107
|
+
config.data = new URLSearchParams(config.data).toString();
|
|
4108
|
+
}
|
|
4109
|
+
if (sessionId) {
|
|
4110
|
+
config.headers.sessionId = sessionId;
|
|
4111
|
+
}
|
|
4112
|
+
const res = await axios_default(config).catch(() => {
|
|
4113
|
+
this.callKit.config.reset();
|
|
4114
|
+
});
|
|
4115
|
+
if (!res) {
|
|
4116
|
+
this.callKit.config.reset();
|
|
4117
|
+
throw new Error("Network error");
|
|
4118
|
+
} else {
|
|
4119
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
4120
|
+
...config,
|
|
4121
|
+
status: "success",
|
|
4122
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
4123
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
4124
|
+
});
|
|
4125
|
+
}
|
|
4126
|
+
const { code, data, message } = res;
|
|
4127
|
+
if (code === "000000") {
|
|
4128
|
+
return data;
|
|
4129
|
+
}
|
|
4130
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
4131
|
+
...config,
|
|
4132
|
+
status: "error",
|
|
4133
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
4134
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
4135
|
+
});
|
|
4136
|
+
if (code === "100013") {
|
|
4137
|
+
this.callKit.config.reset();
|
|
4138
|
+
}
|
|
4139
|
+
throw new Error(message ?? "Request failed");
|
|
4140
|
+
}
|
|
3628
4141
|
};
|
|
3629
4142
|
|
|
3630
4143
|
// package/call.ts
|
|
@@ -3668,12 +4181,6 @@ var WebCall = (() => {
|
|
|
3668
4181
|
if (!this.callKit.config.check())
|
|
3669
4182
|
return;
|
|
3670
4183
|
this.callKit.logger.debug("callRefer");
|
|
3671
|
-
const { toAgentId, workOrderId } = options;
|
|
3672
|
-
const queryTrain = {
|
|
3673
|
-
toAgentId,
|
|
3674
|
-
workOrderId
|
|
3675
|
-
};
|
|
3676
|
-
this.callKit.socket.send(SocketSendEvent.AGENT_TRANSFER, queryTrain);
|
|
3677
4184
|
this.callKit.connect.refer(referTo, options);
|
|
3678
4185
|
}
|
|
3679
4186
|
/**
|
|
@@ -3720,7 +4227,7 @@ var WebCall = (() => {
|
|
|
3720
4227
|
this.callKit = callKit;
|
|
3721
4228
|
}
|
|
3722
4229
|
config = {
|
|
3723
|
-
version: "1.0.
|
|
4230
|
+
version: "1.0.24-beta.30",
|
|
3724
4231
|
host: "",
|
|
3725
4232
|
log: "debug",
|
|
3726
4233
|
audioRef: void 0,
|
|
@@ -3746,7 +4253,8 @@ var WebCall = (() => {
|
|
|
3746
4253
|
fsPort: "",
|
|
3747
4254
|
iceInfo: [],
|
|
3748
4255
|
iceGatheringTimeout: 0,
|
|
3749
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
4256
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
4257
|
+
logGather: LogGatherEnum.DISABLE
|
|
3750
4258
|
},
|
|
3751
4259
|
// EXECUTE setUserStatus
|
|
3752
4260
|
isAutoUpdateUserStatus: true
|
|
@@ -3778,7 +4286,8 @@ var WebCall = (() => {
|
|
|
3778
4286
|
fsPort: "",
|
|
3779
4287
|
iceInfo: [],
|
|
3780
4288
|
iceGatheringTimeout: this.config.userInfo.iceGatheringTimeout,
|
|
3781
|
-
encryptionMethod: EncryptionMethod.INTERNAL
|
|
4289
|
+
encryptionMethod: EncryptionMethod.INTERNAL,
|
|
4290
|
+
logGather: LogGatherEnum.DISABLE
|
|
3782
4291
|
};
|
|
3783
4292
|
this.callKit.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
|
|
3784
4293
|
}
|
|
@@ -3791,6 +4300,7 @@ var WebCall = (() => {
|
|
|
3791
4300
|
return true;
|
|
3792
4301
|
};
|
|
3793
4302
|
isLogin = () => this.validate();
|
|
4303
|
+
isLogGatherEnable = () => this.config.userInfo.logGather === LogGatherEnum.ENABLE;
|
|
3794
4304
|
check() {
|
|
3795
4305
|
if (!this.isLogin()) {
|
|
3796
4306
|
this.callKit.logger.error("User not logged in", {
|
|
@@ -3802,78 +4312,6 @@ var WebCall = (() => {
|
|
|
3802
4312
|
}
|
|
3803
4313
|
};
|
|
3804
4314
|
|
|
3805
|
-
// package/logger.ts
|
|
3806
|
-
function getLevel(level) {
|
|
3807
|
-
return LoggerLevelMap[level];
|
|
3808
|
-
}
|
|
3809
|
-
var Logger = class {
|
|
3810
|
-
prefix = "CallKit";
|
|
3811
|
-
level = "debug";
|
|
3812
|
-
callKit;
|
|
3813
|
-
constructor(callKit, level) {
|
|
3814
|
-
this.callKit = callKit;
|
|
3815
|
-
this.level = level || "debug";
|
|
3816
|
-
}
|
|
3817
|
-
setLevel(level) {
|
|
3818
|
-
this.level = level;
|
|
3819
|
-
}
|
|
3820
|
-
debug(msg, extra) {
|
|
3821
|
-
if (getLevel(this.level) >= getLevel("debug")) {
|
|
3822
|
-
this.output("blue")(msg, extra);
|
|
3823
|
-
}
|
|
3824
|
-
}
|
|
3825
|
-
log(msg, extra) {
|
|
3826
|
-
if (getLevel(this.level) >= getLevel("log")) {
|
|
3827
|
-
this.output("green")(msg, extra);
|
|
3828
|
-
}
|
|
3829
|
-
}
|
|
3830
|
-
warn(msg, extra) {
|
|
3831
|
-
if (getLevel(this.level) >= getLevel("warn")) {
|
|
3832
|
-
this.output("orange")(msg, extra);
|
|
3833
|
-
}
|
|
3834
|
-
}
|
|
3835
|
-
error(msg, extra) {
|
|
3836
|
-
const message = msg?.message ?? msg;
|
|
3837
|
-
if (getLevel(this.level) >= getLevel("error")) {
|
|
3838
|
-
this.output("red")(message, extra);
|
|
3839
|
-
}
|
|
3840
|
-
const { errCode, ...rest } = extra;
|
|
3841
|
-
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
3842
|
-
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
3843
|
-
code: errorCode,
|
|
3844
|
-
msg: message,
|
|
3845
|
-
data: rest
|
|
3846
|
-
});
|
|
3847
|
-
this.callKit.reset();
|
|
3848
|
-
const error = new Error(message);
|
|
3849
|
-
error.name = "CallKitError";
|
|
3850
|
-
error.code = errorCode;
|
|
3851
|
-
error.data = rest;
|
|
3852
|
-
throw error;
|
|
3853
|
-
}
|
|
3854
|
-
output(color) {
|
|
3855
|
-
return (msg, extra = {}) => {
|
|
3856
|
-
const now = /* @__PURE__ */ new Date();
|
|
3857
|
-
if (Object.keys(extra).length > 0) {
|
|
3858
|
-
console.log(
|
|
3859
|
-
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
3860
|
-
`color: ${color};`,
|
|
3861
|
-
"color:block;",
|
|
3862
|
-
extra,
|
|
3863
|
-
"color:#999;"
|
|
3864
|
-
);
|
|
3865
|
-
} else {
|
|
3866
|
-
console.log(
|
|
3867
|
-
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
3868
|
-
`color: ${color};`,
|
|
3869
|
-
"color:block;",
|
|
3870
|
-
"color:#999;"
|
|
3871
|
-
);
|
|
3872
|
-
}
|
|
3873
|
-
};
|
|
3874
|
-
}
|
|
3875
|
-
};
|
|
3876
|
-
|
|
3877
4315
|
// node_modules/.pnpm/sip.js@0.21.2/node_modules/sip.js/lib/version.js
|
|
3878
4316
|
var LIBRARY_VERSION = "0.21.1";
|
|
3879
4317
|
|
|
@@ -12875,8 +13313,8 @@ var WebCall = (() => {
|
|
|
12875
13313
|
this.logger.warn(msg);
|
|
12876
13314
|
return;
|
|
12877
13315
|
};
|
|
12878
|
-
const
|
|
12879
|
-
const extraHeaders = [`Retry-After: ${
|
|
13316
|
+
const retryAfter2 = Math.floor(Math.random() * 10) + 1;
|
|
13317
|
+
const extraHeaders = [`Retry-After: ${retryAfter2}`];
|
|
12880
13318
|
if (this.ackProcessing) {
|
|
12881
13319
|
this.core.replyStateless(message, { statusCode: 500, extraHeaders });
|
|
12882
13320
|
warning();
|
|
@@ -18297,7 +18735,9 @@ var WebCall = (() => {
|
|
|
18297
18735
|
const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
|
18298
18736
|
if (!getUserMedia) {
|
|
18299
18737
|
return Promise.reject(
|
|
18300
|
-
new Error(
|
|
18738
|
+
new Error(
|
|
18739
|
+
"Unable to obtain device permissions. Please check your browser settings or device permissions."
|
|
18740
|
+
)
|
|
18301
18741
|
);
|
|
18302
18742
|
}
|
|
18303
18743
|
return new Promise((resolve, reject) => {
|
|
@@ -18318,7 +18758,7 @@ var WebCall = (() => {
|
|
|
18318
18758
|
registerer;
|
|
18319
18759
|
lastOptionsUpdateTime = 0;
|
|
18320
18760
|
observeOptionsHeartbeatHandler = null;
|
|
18321
|
-
sipConnected = false;
|
|
18761
|
+
// sipConnected = false;
|
|
18322
18762
|
/**
|
|
18323
18763
|
* Whether it's an outgoing call
|
|
18324
18764
|
*/
|
|
@@ -18327,6 +18767,7 @@ var WebCall = (() => {
|
|
|
18327
18767
|
* Whether it's an active hangup
|
|
18328
18768
|
*/
|
|
18329
18769
|
isUnprompted = false;
|
|
18770
|
+
isCurrentSessionInvited = false;
|
|
18330
18771
|
reconnectConfig;
|
|
18331
18772
|
/**
|
|
18332
18773
|
* Whether registered
|
|
@@ -18366,7 +18807,6 @@ var WebCall = (() => {
|
|
|
18366
18807
|
this.registerer = void 0;
|
|
18367
18808
|
this.isOutgoing = false;
|
|
18368
18809
|
this.isUnprompted = false;
|
|
18369
|
-
this.sipConnected = false;
|
|
18370
18810
|
this.clearObserveOptionsHeartbeatInterval();
|
|
18371
18811
|
if (this.isHold) {
|
|
18372
18812
|
this.setHoldStatus(false);
|
|
@@ -18380,7 +18820,7 @@ var WebCall = (() => {
|
|
|
18380
18820
|
return audioRef;
|
|
18381
18821
|
}
|
|
18382
18822
|
async permission() {
|
|
18383
|
-
this.callKit.logger.debug("
|
|
18823
|
+
this.callKit.logger.debug("ssion");
|
|
18384
18824
|
initUserMedia();
|
|
18385
18825
|
const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
18386
18826
|
closeStream(_stream);
|
|
@@ -18427,6 +18867,9 @@ var WebCall = (() => {
|
|
|
18427
18867
|
isInit() {
|
|
18428
18868
|
return this.connectStatus === CallStatus.init;
|
|
18429
18869
|
}
|
|
18870
|
+
isExecuting() {
|
|
18871
|
+
return this.callKit.user.getUserChangeStatusExecuting();
|
|
18872
|
+
}
|
|
18430
18873
|
clearObserveOptionsHeartbeatInterval() {
|
|
18431
18874
|
if (this.observeOptionsHeartbeatHandler !== null) {
|
|
18432
18875
|
clearInterval(this.observeOptionsHeartbeatHandler);
|
|
@@ -18506,13 +18949,18 @@ var WebCall = (() => {
|
|
|
18506
18949
|
that.userAgent.transport.onDisconnect = (error) => {
|
|
18507
18950
|
if (error) {
|
|
18508
18951
|
that.callKit.logger.debug("connect onDisconnect");
|
|
18509
|
-
if (that.isRegistered() &&
|
|
18952
|
+
if (that.isRegistered() && !// that.sipConnected ||
|
|
18953
|
+
(that.isRinging() || that.isCalling() || that.isHolding())) {
|
|
18510
18954
|
that.reconnect();
|
|
18511
18955
|
} else {
|
|
18512
18956
|
that.callKit.logger.debug("SIP WebSocket closed with error", {
|
|
18513
18957
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
18514
18958
|
err: error
|
|
18515
18959
|
});
|
|
18960
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
18961
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
18962
|
+
err: error
|
|
18963
|
+
});
|
|
18516
18964
|
that.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
18517
18965
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
18518
18966
|
err: error
|
|
@@ -18528,7 +18976,7 @@ var WebCall = (() => {
|
|
|
18528
18976
|
}
|
|
18529
18977
|
};
|
|
18530
18978
|
that.clearObserveOptionsHeartbeatInterval();
|
|
18531
|
-
setInterval(() => {
|
|
18979
|
+
that.observeOptionsHeartbeatHandler = setInterval(() => {
|
|
18532
18980
|
if (that.lastOptionsUpdateTime !== 0) {
|
|
18533
18981
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
18534
18982
|
const diff = now - that.lastOptionsUpdateTime;
|
|
@@ -18543,6 +18991,11 @@ var WebCall = (() => {
|
|
|
18543
18991
|
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
18544
18992
|
now
|
|
18545
18993
|
});
|
|
18994
|
+
that.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
18995
|
+
event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
|
|
18996
|
+
lastOptionsUpdateTime: that.lastOptionsUpdateTime,
|
|
18997
|
+
now
|
|
18998
|
+
});
|
|
18546
18999
|
that.clearObserveOptionsHeartbeatInterval();
|
|
18547
19000
|
}
|
|
18548
19001
|
}
|
|
@@ -18554,38 +19007,118 @@ var WebCall = (() => {
|
|
|
18554
19007
|
if (request2.method === "OPTIONS") {
|
|
18555
19008
|
that.lastOptionsUpdateTime = (/* @__PURE__ */ new Date()).getTime();
|
|
18556
19009
|
}
|
|
19010
|
+
that.callKit.logger.addLogData(LogDataEnum.SIP, request2);
|
|
18557
19011
|
return originalReceiveRequest(request2);
|
|
18558
19012
|
};
|
|
18559
19013
|
};
|
|
18560
19014
|
const registererOptions = {};
|
|
18561
19015
|
this.registerer = new Registerer(this.userAgent, registererOptions);
|
|
19016
|
+
this.registerer.stateChange.addListener((state) => {
|
|
19017
|
+
switch (state) {
|
|
19018
|
+
case RegistererState.Initial:
|
|
19019
|
+
this.callKit.logger.debug("registerer stateChange Initial");
|
|
19020
|
+
this.setRegister(false);
|
|
19021
|
+
this.setConnectStatus(CallStatus.init);
|
|
19022
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
19023
|
+
this.callKit.trigger(
|
|
19024
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
19025
|
+
SipRegistererEvent.Initial
|
|
19026
|
+
);
|
|
19027
|
+
break;
|
|
19028
|
+
case RegistererState.Registered:
|
|
19029
|
+
this.callKit.logger.debug("registerer stateChange Registered");
|
|
19030
|
+
this.setRegister(true);
|
|
19031
|
+
this.setConnectStatus(CallStatus.registered);
|
|
19032
|
+
this.callKit.user.setUserStatus(UserStatus.online);
|
|
19033
|
+
this.callKit.trigger(
|
|
19034
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
19035
|
+
SipRegistererEvent.Registered
|
|
19036
|
+
);
|
|
19037
|
+
break;
|
|
19038
|
+
case RegistererState.Terminated:
|
|
19039
|
+
this.callKit.logger.debug("registerer stateChange Terminated");
|
|
19040
|
+
this.setRegister(false);
|
|
19041
|
+
this.setConnectStatus(CallStatus.init);
|
|
19042
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
19043
|
+
this.callKit.trigger(
|
|
19044
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
19045
|
+
SipRegistererEvent.Terminated
|
|
19046
|
+
);
|
|
19047
|
+
break;
|
|
19048
|
+
case RegistererState.Unregistered:
|
|
19049
|
+
this.callKit.logger.debug("registerer stateChange Unregistered");
|
|
19050
|
+
this.setRegister(false);
|
|
19051
|
+
this.setConnectStatus(CallStatus.init);
|
|
19052
|
+
this.callKit.user.setUserStatus(UserStatus.offline);
|
|
19053
|
+
this.callKit.trigger(
|
|
19054
|
+
KitEvent.SIP_REGISTERER_EVENT,
|
|
19055
|
+
SipRegistererEvent.Unregistered
|
|
19056
|
+
);
|
|
19057
|
+
break;
|
|
19058
|
+
default:
|
|
19059
|
+
break;
|
|
19060
|
+
}
|
|
19061
|
+
});
|
|
18562
19062
|
this.userAgent.delegate = {
|
|
18563
19063
|
onInvite: (invite) => {
|
|
18564
19064
|
this.callKit.logger.debug("connect onInvite");
|
|
18565
19065
|
this.currentSession = invite;
|
|
19066
|
+
if (this.isOutgoing) {
|
|
19067
|
+
this.isCurrentSessionInvited = false;
|
|
19068
|
+
}
|
|
18566
19069
|
this.currentSession.stateChange.addListener((state) => {
|
|
19070
|
+
const isExecuting = this.isExecuting();
|
|
18567
19071
|
switch (state) {
|
|
18568
19072
|
case SessionState2.Establishing:
|
|
18569
19073
|
this.callKit.logger.debug("connect Establishing");
|
|
19074
|
+
this.setConnectStatus(CallStatus.ringing);
|
|
19075
|
+
if (!isExecuting) {
|
|
19076
|
+
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
19077
|
+
this.callKit.trigger(
|
|
19078
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
19079
|
+
SipSessionEvent.Establishing
|
|
19080
|
+
);
|
|
19081
|
+
}
|
|
18570
19082
|
break;
|
|
18571
19083
|
case SessionState2.Established:
|
|
18572
19084
|
this.callKit.logger.debug("connect Established");
|
|
18573
|
-
|
|
18574
|
-
|
|
18575
|
-
|
|
19085
|
+
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
19086
|
+
if (!isExecuting) {
|
|
19087
|
+
this.callKit.trigger(
|
|
19088
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
19089
|
+
SipSessionEvent.Established
|
|
19090
|
+
);
|
|
19091
|
+
setupRemoteMedia(this.currentSession);
|
|
18576
19092
|
}
|
|
18577
|
-
this.sipConnected = true;
|
|
18578
|
-
setupRemoteMedia(this.currentSession);
|
|
18579
19093
|
break;
|
|
18580
19094
|
case SessionState2.Terminating:
|
|
18581
19095
|
this.callKit.logger.debug("connect Terminating");
|
|
19096
|
+
if (!isExecuting) {
|
|
19097
|
+
this.callKit.trigger(
|
|
19098
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
19099
|
+
SipSessionEvent.Terminating
|
|
19100
|
+
);
|
|
19101
|
+
}
|
|
18582
19102
|
break;
|
|
18583
19103
|
case SessionState2.Terminated:
|
|
18584
19104
|
this.callKit.logger.debug("connect Terminated");
|
|
18585
19105
|
if (!this.isUnprompted) {
|
|
18586
19106
|
this.callKit.callCenter.callEnd();
|
|
19107
|
+
} else if (this.isCalling()) {
|
|
19108
|
+
if (this.isCurrentSessionInvited) {
|
|
19109
|
+
this.currentSession.reject();
|
|
19110
|
+
}
|
|
19111
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
18587
19112
|
}
|
|
18588
19113
|
this.isUnprompted = false;
|
|
19114
|
+
if (!isExecuting) {
|
|
19115
|
+
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
19116
|
+
this.setConnectStatus(CallStatus.registered);
|
|
19117
|
+
this.callKit.trigger(
|
|
19118
|
+
KitEvent.SIP_SESSION_EVENT,
|
|
19119
|
+
SipSessionEvent.Terminated
|
|
19120
|
+
);
|
|
19121
|
+
}
|
|
18589
19122
|
break;
|
|
18590
19123
|
default:
|
|
18591
19124
|
break;
|
|
@@ -18599,17 +19132,37 @@ var WebCall = (() => {
|
|
|
18599
19132
|
};
|
|
18600
19133
|
if (this.isOutgoing) {
|
|
18601
19134
|
this.currentSession.accept(options);
|
|
19135
|
+
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
19136
|
+
getInviteData: () => {
|
|
19137
|
+
const { request: request2 } = this.currentSession;
|
|
19138
|
+
const headerNames = Object.keys(request2.headers);
|
|
19139
|
+
const xHeaders = {};
|
|
19140
|
+
headerNames.filter(
|
|
19141
|
+
(name) => name.toLocaleLowerCase().startsWith("x-antaios")
|
|
19142
|
+
).forEach((name) => {
|
|
19143
|
+
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
19144
|
+
});
|
|
19145
|
+
this.callKit.logger.debug("get invite data", xHeaders);
|
|
19146
|
+
return xHeaders;
|
|
19147
|
+
}
|
|
19148
|
+
});
|
|
18602
19149
|
} else {
|
|
19150
|
+
const isExecuting = this.isExecuting();
|
|
19151
|
+
const reject = () => {
|
|
19152
|
+
this.currentSession.reject();
|
|
19153
|
+
this.callKit.callCenter.callEnd(true, false);
|
|
19154
|
+
};
|
|
19155
|
+
if (isExecuting) {
|
|
19156
|
+
reject();
|
|
19157
|
+
return;
|
|
19158
|
+
}
|
|
18603
19159
|
this.callKit.trigger(KitEvent.KIT_INVITE, {
|
|
18604
19160
|
accept: () => {
|
|
18605
|
-
this.
|
|
19161
|
+
this.isCurrentSessionInvited = true;
|
|
18606
19162
|
this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
|
|
18607
19163
|
this.currentSession.accept(options);
|
|
18608
19164
|
},
|
|
18609
|
-
reject
|
|
18610
|
-
this.currentSession.reject();
|
|
18611
|
-
this.callKit.callCenter.callEnd(true, false);
|
|
18612
|
-
},
|
|
19165
|
+
reject,
|
|
18613
19166
|
getInviteData: () => {
|
|
18614
19167
|
const { request: request2 } = this.currentSession;
|
|
18615
19168
|
const headerNames = Object.keys(request2.headers);
|
|
@@ -18627,9 +19180,12 @@ var WebCall = (() => {
|
|
|
18627
19180
|
},
|
|
18628
19181
|
onConnect: async () => {
|
|
18629
19182
|
this.callKit.logger.debug("connect onConnect");
|
|
19183
|
+
const version = `V${this.callKit.config.getConfig().version}`;
|
|
18630
19184
|
await this.registerer.register().then(() => {
|
|
18631
|
-
this.callKit.socket.send(SocketSendEvent.START
|
|
18632
|
-
|
|
19185
|
+
this.callKit.socket.send(SocketSendEvent.START, {
|
|
19186
|
+
version
|
|
19187
|
+
});
|
|
19188
|
+
}).catch(async (err) => {
|
|
18633
19189
|
this.callKit.logger.error(err?.message, {
|
|
18634
19190
|
errCode: ErrorCode.WEBRTC_REGISTER_ERROR
|
|
18635
19191
|
});
|
|
@@ -18637,13 +19193,18 @@ var WebCall = (() => {
|
|
|
18637
19193
|
},
|
|
18638
19194
|
onDisconnect: (error) => {
|
|
18639
19195
|
this.callKit.logger.debug("connect onDisconnect");
|
|
18640
|
-
if (this.isRegistered() &&
|
|
19196
|
+
if (this.isRegistered() && !// this.sipConnected ||
|
|
19197
|
+
(this.isRinging() || this.isCalling() || this.isHolding())) {
|
|
18641
19198
|
this.reconnect();
|
|
18642
19199
|
} else {
|
|
18643
19200
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
18644
19201
|
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
18645
19202
|
err: error
|
|
18646
19203
|
});
|
|
19204
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
19205
|
+
event: ConnectEvent.SIP_CONNECT_ERROR,
|
|
19206
|
+
err: error
|
|
19207
|
+
});
|
|
18647
19208
|
this.callKit.user.sendHangUpReason({
|
|
18648
19209
|
eventType: ConnectEvent.SIP_RECONNECT_ERROR,
|
|
18649
19210
|
err: error
|
|
@@ -18695,6 +19256,11 @@ var WebCall = (() => {
|
|
|
18695
19256
|
return;
|
|
18696
19257
|
reconnectTimer = setTimeout(async () => {
|
|
18697
19258
|
try {
|
|
19259
|
+
if (currentRetry === 0) {
|
|
19260
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19261
|
+
event: ConnectEvent.SIP_RECONNECT_START
|
|
19262
|
+
});
|
|
19263
|
+
}
|
|
18698
19264
|
currentRetry += 1;
|
|
18699
19265
|
this.callKit.logger.debug(
|
|
18700
19266
|
`Attempting to reconnect SIP... (Attempt ${currentRetry}/${this.reconnectConfig.maxAttempts})`
|
|
@@ -18737,9 +19303,7 @@ var WebCall = (() => {
|
|
|
18737
19303
|
this.callKit.logger.warn("No registerer to unregister.");
|
|
18738
19304
|
return;
|
|
18739
19305
|
}
|
|
18740
|
-
await this.registerer.unregister({ all: true }).
|
|
18741
|
-
this.setConnectStatus(CallStatus.init);
|
|
18742
|
-
}).catch((err) => {
|
|
19306
|
+
await this.registerer.unregister({ all: true }).catch((err) => {
|
|
18743
19307
|
this.callKit.logger.error(err, {
|
|
18744
19308
|
errCode: ErrorCode.WEBRTC_CANCEL_REGISTER_ERROR
|
|
18745
19309
|
});
|
|
@@ -18770,12 +19334,6 @@ var WebCall = (() => {
|
|
|
18770
19334
|
*/
|
|
18771
19335
|
setConnectStatus(status) {
|
|
18772
19336
|
this.callKit.logger.debug(`connect setConnectStatus: ${status}`);
|
|
18773
|
-
if (this.isRegistered() && status === CallStatus.init) {
|
|
18774
|
-
this.setRegister(false);
|
|
18775
|
-
}
|
|
18776
|
-
if (!this.isRegistered() && status !== CallStatus.init) {
|
|
18777
|
-
this.setRegister(true);
|
|
18778
|
-
}
|
|
18779
19337
|
this.connectStatus = status;
|
|
18780
19338
|
this.callKit.trigger(KitEvent.KIT_CALL_STATUS_CHANGE, status);
|
|
18781
19339
|
}
|
|
@@ -18793,13 +19351,14 @@ var WebCall = (() => {
|
|
|
18793
19351
|
this.isUnprompted = isUnprompted;
|
|
18794
19352
|
try {
|
|
18795
19353
|
if (isUnprompted) {
|
|
18796
|
-
|
|
18797
|
-
|
|
19354
|
+
const shouldSendBye = (
|
|
19355
|
+
// this.sipConnected ||
|
|
19356
|
+
this.isRinging() || this.isCalling() || this.isHolding()
|
|
19357
|
+
);
|
|
18798
19358
|
if (shouldSendBye) {
|
|
18799
19359
|
await this.currentSession?.bye();
|
|
18800
19360
|
}
|
|
18801
19361
|
}
|
|
18802
|
-
this.sipConnected = false;
|
|
18803
19362
|
closeStream(this.mediaStream);
|
|
18804
19363
|
const audioRef = this.getAduioReference();
|
|
18805
19364
|
if (audioRef) {
|
|
@@ -18808,8 +19367,6 @@ var WebCall = (() => {
|
|
|
18808
19367
|
}
|
|
18809
19368
|
if (isError) {
|
|
18810
19369
|
this.setConnectStatus(CallStatus.init);
|
|
18811
|
-
} else {
|
|
18812
|
-
this.setConnectStatus(CallStatus.registered);
|
|
18813
19370
|
}
|
|
18814
19371
|
this.callKit.trigger(KitEvent.CALL_END, /* @__PURE__ */ new Date());
|
|
18815
19372
|
} catch (err) {
|
|
@@ -18940,59 +19497,6 @@ var WebCall = (() => {
|
|
|
18940
19497
|
}
|
|
18941
19498
|
};
|
|
18942
19499
|
|
|
18943
|
-
// package/monitor.ts
|
|
18944
|
-
var import_axios3 = __toESM(require_axios2());
|
|
18945
|
-
var defaultConfig = {
|
|
18946
|
-
interval: 5e3,
|
|
18947
|
-
apiEndpoint: "/livez"
|
|
18948
|
-
};
|
|
18949
|
-
var Monitor = class {
|
|
18950
|
-
callKit;
|
|
18951
|
-
interval = defaultConfig.interval;
|
|
18952
|
-
apiEndpoint = defaultConfig.apiEndpoint;
|
|
18953
|
-
monitorIntervalHandler = null;
|
|
18954
|
-
constructor(callKit) {
|
|
18955
|
-
this.callKit = callKit;
|
|
18956
|
-
const { monitor } = this.callKit.config.getConfig();
|
|
18957
|
-
this.interval = monitor?.interval ?? defaultConfig.interval;
|
|
18958
|
-
this.apiEndpoint = monitor?.apiEndpoint ?? defaultConfig.apiEndpoint;
|
|
18959
|
-
this.monitorIntervalHandler = null;
|
|
18960
|
-
}
|
|
18961
|
-
getEndPointPath = () => {
|
|
18962
|
-
const config = this.callKit.config.getConfig();
|
|
18963
|
-
const defaultPath = `${config.host}${this.apiEndpoint}`;
|
|
18964
|
-
const endPointPath = config.monitor?.apiEndpoint ?? defaultPath;
|
|
18965
|
-
return endPointPath;
|
|
18966
|
-
};
|
|
18967
|
-
measureRTT = async () => {
|
|
18968
|
-
try {
|
|
18969
|
-
const endPoint = this.getEndPointPath();
|
|
18970
|
-
const startTime = performance.now();
|
|
18971
|
-
await import_axios3.default.get(endPoint);
|
|
18972
|
-
const endTime = performance.now();
|
|
18973
|
-
const rtt = Math.round(endTime - startTime);
|
|
18974
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
18975
|
-
event: NetWorkEvent.RTT_MEASURE_SUCCESS,
|
|
18976
|
-
rtt
|
|
18977
|
-
});
|
|
18978
|
-
} catch (error) {
|
|
18979
|
-
this.callKit.trigger(KitEvent.NETWORK_EVENT, {
|
|
18980
|
-
event: NetWorkEvent.RTT_MEASURE_FAILED,
|
|
18981
|
-
rtt: 0
|
|
18982
|
-
});
|
|
18983
|
-
}
|
|
18984
|
-
};
|
|
18985
|
-
stopRTTMonitoring() {
|
|
18986
|
-
if (this.monitorIntervalHandler) {
|
|
18987
|
-
clearInterval(this.monitorIntervalHandler);
|
|
18988
|
-
}
|
|
18989
|
-
}
|
|
18990
|
-
startRTTMonitoring() {
|
|
18991
|
-
this.stopRTTMonitoring();
|
|
18992
|
-
this.monitorIntervalHandler = setInterval(this.measureRTT, this.interval);
|
|
18993
|
-
}
|
|
18994
|
-
};
|
|
18995
|
-
|
|
18996
19500
|
// package/socket.ts
|
|
18997
19501
|
var RECONNECT_CONFIG = {
|
|
18998
19502
|
enabled: true,
|
|
@@ -19016,7 +19520,6 @@ var WebCall = (() => {
|
|
|
19016
19520
|
reconnectTimer;
|
|
19017
19521
|
isReconnecting = false;
|
|
19018
19522
|
reconnectAttempts = 0;
|
|
19019
|
-
closing = false;
|
|
19020
19523
|
constructor(callKit) {
|
|
19021
19524
|
this.callKit = callKit;
|
|
19022
19525
|
const { reconnect } = this.callKit.config.getConfig();
|
|
@@ -19030,15 +19533,13 @@ var WebCall = (() => {
|
|
|
19030
19533
|
this.callKit.logger.debug(`socket init: ${socket}`);
|
|
19031
19534
|
this.connect(socket);
|
|
19032
19535
|
}
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
19039
|
-
|
|
19040
|
-
});
|
|
19041
|
-
this.close(1e3, "normal");
|
|
19536
|
+
// confirm from connect startConfirm
|
|
19537
|
+
// startConfirm(status: boolean) {
|
|
19538
|
+
// this.callKit.logger.debug('register success');
|
|
19539
|
+
// this.satrtConfirm = status;
|
|
19540
|
+
// }
|
|
19541
|
+
setRecivedClose(status) {
|
|
19542
|
+
this.recivedClose = status;
|
|
19042
19543
|
}
|
|
19043
19544
|
reconnect(ev) {
|
|
19044
19545
|
this.callKit.logger.debug("socket reconnect", ev);
|
|
@@ -19048,12 +19549,21 @@ var WebCall = (() => {
|
|
|
19048
19549
|
"socket reconnect times",
|
|
19049
19550
|
this.socketConfig.maxAttempts
|
|
19050
19551
|
);
|
|
19552
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
19553
|
+
event: ConnectEvent.INCALL_RECONNECTING,
|
|
19554
|
+
attempts: this.reconnectAttempts,
|
|
19555
|
+
err: ev
|
|
19556
|
+
});
|
|
19051
19557
|
this.attemptReconnect();
|
|
19052
19558
|
} else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
19053
19559
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19054
19560
|
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
19055
19561
|
err: ev
|
|
19056
19562
|
});
|
|
19563
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
19564
|
+
event: ConnectEvent.INCALL_RECONNECT_ERROR,
|
|
19565
|
+
err: ev
|
|
19566
|
+
});
|
|
19057
19567
|
this.reset();
|
|
19058
19568
|
this.callKit.logger.error(
|
|
19059
19569
|
"Reconnection failed, maximum retry attempts reached",
|
|
@@ -19072,6 +19582,10 @@ var WebCall = (() => {
|
|
|
19072
19582
|
}
|
|
19073
19583
|
onOpen(ev) {
|
|
19074
19584
|
this.callKit.logger.debug("socket onOpen", ev);
|
|
19585
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
19586
|
+
callKitSocketFrom: "onOpen",
|
|
19587
|
+
ev
|
|
19588
|
+
});
|
|
19075
19589
|
this.isConnected = true;
|
|
19076
19590
|
this.lastPingTime = Date.now();
|
|
19077
19591
|
this.checkPing();
|
|
@@ -19090,11 +19604,23 @@ var WebCall = (() => {
|
|
|
19090
19604
|
}
|
|
19091
19605
|
onClose(ev) {
|
|
19092
19606
|
this.callKit.logger.debug("socket onClose", ev);
|
|
19607
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
19608
|
+
callKitSocketFrom: "onClose",
|
|
19609
|
+
ev
|
|
19610
|
+
});
|
|
19093
19611
|
if ((ev.code !== 1e3 || !ev.wasClean) && this.callKit.connect.isRegistered()) {
|
|
19094
19612
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19095
19613
|
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
19096
19614
|
err: ev
|
|
19097
19615
|
});
|
|
19616
|
+
this.callKit.logger.addLogData(LogDataEnum.ERROR, {
|
|
19617
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
19618
|
+
err: ev
|
|
19619
|
+
});
|
|
19620
|
+
this.callKit.logger.addLogData(LogDataEnum.RECONNECT, {
|
|
19621
|
+
event: ConnectEvent.INCALL_CONNECT_ERROR,
|
|
19622
|
+
err: ev
|
|
19623
|
+
});
|
|
19098
19624
|
this.reconnect(ev);
|
|
19099
19625
|
} else {
|
|
19100
19626
|
this.isConnected = false;
|
|
@@ -19105,10 +19631,6 @@ var WebCall = (() => {
|
|
|
19105
19631
|
}
|
|
19106
19632
|
this.callKit.connect.hangup();
|
|
19107
19633
|
this.reset();
|
|
19108
|
-
this.closing = false;
|
|
19109
|
-
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19110
|
-
event: ConnectEvent.CONNECT_CLOSING_END
|
|
19111
|
-
});
|
|
19112
19634
|
}
|
|
19113
19635
|
}
|
|
19114
19636
|
onError(ev) {
|
|
@@ -19116,46 +19638,53 @@ var WebCall = (() => {
|
|
|
19116
19638
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR,
|
|
19117
19639
|
data: ev
|
|
19118
19640
|
});
|
|
19641
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
19642
|
+
callKitSocketFrom: "onError",
|
|
19643
|
+
ev
|
|
19644
|
+
});
|
|
19119
19645
|
if (this.isReconnecting) {
|
|
19120
19646
|
this.attemptReconnect();
|
|
19121
19647
|
}
|
|
19122
19648
|
}
|
|
19649
|
+
confirmAck(data) {
|
|
19650
|
+
const { ack, messageId } = data;
|
|
19651
|
+
if (ack) {
|
|
19652
|
+
this.send(SocketSendEvent.ACK, {
|
|
19653
|
+
messageId
|
|
19654
|
+
// sessionId
|
|
19655
|
+
});
|
|
19656
|
+
}
|
|
19657
|
+
}
|
|
19123
19658
|
onMessage(ev) {
|
|
19124
19659
|
const data = JSON.parse(ev.data);
|
|
19125
19660
|
this.callKit.logger.debug("socket onMessage", data);
|
|
19661
|
+
this.callKit.logger.addLogData(LogDataEnum.INCALL, {
|
|
19662
|
+
callKitSocketFrom: "onMessage",
|
|
19663
|
+
ev
|
|
19664
|
+
});
|
|
19665
|
+
this.confirmAck(data);
|
|
19126
19666
|
if (data.event === SocketReceiveEvent.PONG) {
|
|
19127
19667
|
this.lastPingTime = Date.now();
|
|
19128
19668
|
return;
|
|
19129
19669
|
}
|
|
19130
19670
|
if (data.event === SocketReceiveEvent.START_CONFIRM) {
|
|
19131
|
-
this.callKit.logger.debug("
|
|
19671
|
+
this.callKit.logger.debug("start confirm success");
|
|
19132
19672
|
this.satrtConfirm = true;
|
|
19133
|
-
this.callKit.connect.setConnectStatus(CallStatus.registered);
|
|
19134
19673
|
}
|
|
19135
19674
|
if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
|
|
19136
19675
|
this.recivedClose = false;
|
|
19137
|
-
this.callKit.logger.debug("callStart");
|
|
19138
|
-
this.callKit.user.setUserStatus(UserStatus.busy);
|
|
19139
19676
|
}
|
|
19140
19677
|
if (data.event === SocketReceiveEvent.CALL_FAILED) {
|
|
19141
19678
|
this.callKit.logger.debug(data.msg, {
|
|
19142
19679
|
errCode: ErrorCode.SOCKET_CALL_ERROR
|
|
19143
19680
|
});
|
|
19144
|
-
this.callKit.user.setUserStatus(UserStatus.online);
|
|
19145
19681
|
}
|
|
19146
19682
|
if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
|
|
19147
|
-
this.callKit.
|
|
19148
|
-
if (this.callKit.connect.isConnecting()) {
|
|
19149
|
-
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
19150
|
-
this.callKit.connect.setConnectStatus(CallStatus.ringing);
|
|
19151
|
-
}
|
|
19683
|
+
this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
|
|
19152
19684
|
}
|
|
19153
19685
|
if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
|
|
19154
19686
|
this.callKit.logger.debug(data.msg);
|
|
19155
|
-
|
|
19156
|
-
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
19157
|
-
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
19158
|
-
}
|
|
19687
|
+
this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
|
|
19159
19688
|
}
|
|
19160
19689
|
if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
|
|
19161
19690
|
this.callKit.logger.debug(data.msg);
|
|
@@ -19164,12 +19693,10 @@ var WebCall = (() => {
|
|
|
19164
19693
|
if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
|
|
19165
19694
|
this.callKit.logger.debug(data.msg);
|
|
19166
19695
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
19167
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
19168
19696
|
}
|
|
19169
19697
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
19170
19698
|
this.callKit.logger.debug(data.msg);
|
|
19171
19699
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
19172
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
19173
19700
|
}
|
|
19174
19701
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
19175
19702
|
this.callKit.logger.debug(data.msg);
|
|
@@ -19177,7 +19704,7 @@ var WebCall = (() => {
|
|
|
19177
19704
|
}
|
|
19178
19705
|
if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
|
|
19179
19706
|
this.callKit.logger.debug(data.msg);
|
|
19180
|
-
this.
|
|
19707
|
+
this.setRecivedClose(true);
|
|
19181
19708
|
}
|
|
19182
19709
|
if (data.event === SocketReceiveEvent.CLOSE) {
|
|
19183
19710
|
const { userInfo } = this.callKit.config.getConfig();
|
|
@@ -19187,19 +19714,21 @@ var WebCall = (() => {
|
|
|
19187
19714
|
});
|
|
19188
19715
|
}
|
|
19189
19716
|
if (data.event === SocketReceiveEvent.ERROR) {
|
|
19190
|
-
this.callKit.
|
|
19717
|
+
this.callKit.unregister();
|
|
19718
|
+
this.callKit.logger.debug(data.msg, {
|
|
19191
19719
|
errCode: ErrorCode.SOKET_SERVER_ERROR,
|
|
19192
19720
|
data
|
|
19193
19721
|
});
|
|
19194
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
19195
19722
|
}
|
|
19196
19723
|
if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
|
|
19197
|
-
this.callKit.user.setUserStatus(UserStatus.catNap);
|
|
19198
19724
|
}
|
|
19199
19725
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
19200
19726
|
}
|
|
19201
19727
|
send(event, message) {
|
|
19202
19728
|
if (!this.isConnected) {
|
|
19729
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19730
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
19731
|
+
});
|
|
19203
19732
|
this.callKit.logger.error("socket not connected", {
|
|
19204
19733
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
19205
19734
|
});
|
|
@@ -19242,6 +19771,9 @@ var WebCall = (() => {
|
|
|
19242
19771
|
}
|
|
19243
19772
|
async sendMessage(event, message) {
|
|
19244
19773
|
if (!this.isConnected) {
|
|
19774
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19775
|
+
event: ConnectEvent.INCALL_NOT_CONNECTED
|
|
19776
|
+
});
|
|
19245
19777
|
this.callKit.logger.error("socket not connected", {
|
|
19246
19778
|
errCode: ErrorCode.SOCKET_CONNECT_ERROR
|
|
19247
19779
|
});
|
|
@@ -19316,11 +19848,16 @@ var WebCall = (() => {
|
|
|
19316
19848
|
}
|
|
19317
19849
|
this.recivedClose = false;
|
|
19318
19850
|
this.callKit.logger.debug("socket destroy");
|
|
19319
|
-
this.ws.close(
|
|
19851
|
+
this.ws.close();
|
|
19320
19852
|
this.isConnected = false;
|
|
19321
19853
|
}
|
|
19322
19854
|
}
|
|
19323
19855
|
attemptReconnect() {
|
|
19856
|
+
if (this.reconnectAttempts === 0) {
|
|
19857
|
+
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19858
|
+
event: ConnectEvent.INCALL_RECONNECT_START
|
|
19859
|
+
});
|
|
19860
|
+
}
|
|
19324
19861
|
if (this.isReconnecting && this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
19325
19862
|
this.callKit.trigger(KitEvent.CONNECT_EVENT, {
|
|
19326
19863
|
event: ConnectEvent.INCALL_RECONNECT_ERROR
|
|
@@ -19355,8 +19892,102 @@ var WebCall = (() => {
|
|
|
19355
19892
|
callKit;
|
|
19356
19893
|
userStatus;
|
|
19357
19894
|
// logout(1, "unregistered"), idle(2, "free"), break(3, "nap"), busy(4, "busy")
|
|
19895
|
+
userChangeStatusExecuting;
|
|
19358
19896
|
constructor(callKit) {
|
|
19359
19897
|
this.callKit = callKit;
|
|
19898
|
+
this.userChangeStatusExecuting = false;
|
|
19899
|
+
}
|
|
19900
|
+
setUserChangeStatusExecuting(state) {
|
|
19901
|
+
this.userChangeStatusExecuting = state;
|
|
19902
|
+
}
|
|
19903
|
+
getUserChangeStatusExecuting() {
|
|
19904
|
+
return this.userChangeStatusExecuting;
|
|
19905
|
+
}
|
|
19906
|
+
async login(params) {
|
|
19907
|
+
const postData = {
|
|
19908
|
+
userName: params.userName,
|
|
19909
|
+
password: params.password
|
|
19910
|
+
};
|
|
19911
|
+
const logData = {
|
|
19912
|
+
postData,
|
|
19913
|
+
url: "/auth/agentUser/login",
|
|
19914
|
+
status: "send",
|
|
19915
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19916
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19917
|
+
};
|
|
19918
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
19919
|
+
this.setUserChangeStatusExecuting(true);
|
|
19920
|
+
return this.callKit.api.login(params).then((user) => {
|
|
19921
|
+
this.setUserChangeStatusExecuting(false);
|
|
19922
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
19923
|
+
...logData,
|
|
19924
|
+
status: "success",
|
|
19925
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19926
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19927
|
+
});
|
|
19928
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
19929
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginEnd
|
|
19930
|
+
});
|
|
19931
|
+
return user;
|
|
19932
|
+
}).catch((err) => {
|
|
19933
|
+
this.setUserChangeStatusExecuting(false);
|
|
19934
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
19935
|
+
...logData,
|
|
19936
|
+
status: "error",
|
|
19937
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19938
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19939
|
+
});
|
|
19940
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
19941
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginError
|
|
19942
|
+
});
|
|
19943
|
+
this.callKit.logger.error(err, {
|
|
19944
|
+
errCode: ErrorCode.API_USER_LOGIN_ERROR
|
|
19945
|
+
});
|
|
19946
|
+
});
|
|
19947
|
+
}
|
|
19948
|
+
async loginOut(params) {
|
|
19949
|
+
const postData = {
|
|
19950
|
+
sessionId: params.sessionId
|
|
19951
|
+
};
|
|
19952
|
+
const logData = {
|
|
19953
|
+
postData,
|
|
19954
|
+
url: "/auth/agentUser/loginOut",
|
|
19955
|
+
status: "send",
|
|
19956
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19957
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19958
|
+
};
|
|
19959
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
19960
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
19961
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutStart
|
|
19962
|
+
});
|
|
19963
|
+
this.setUserChangeStatusExecuting(true);
|
|
19964
|
+
return this.callKit.api.loginOut(postData).then((res) => {
|
|
19965
|
+
this.setUserChangeStatusExecuting(false);
|
|
19966
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
19967
|
+
...logData,
|
|
19968
|
+
status: "success",
|
|
19969
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19970
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19971
|
+
});
|
|
19972
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
19973
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutEnd
|
|
19974
|
+
});
|
|
19975
|
+
return res;
|
|
19976
|
+
}).catch((err) => {
|
|
19977
|
+
this.setUserChangeStatusExecuting(false);
|
|
19978
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
19979
|
+
...logData,
|
|
19980
|
+
status: "error",
|
|
19981
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
19982
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
19983
|
+
});
|
|
19984
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
19985
|
+
event: UserStatusChangeStepEnum.UserStatusChangeLoginOutError
|
|
19986
|
+
});
|
|
19987
|
+
this.callKit.logger.error(err, {
|
|
19988
|
+
errCode: ErrorCode.API_USER_LOGOUT_ERROR
|
|
19989
|
+
});
|
|
19990
|
+
});
|
|
19360
19991
|
}
|
|
19361
19992
|
/**
|
|
19362
19993
|
*
|
|
@@ -19373,24 +20004,70 @@ var WebCall = (() => {
|
|
|
19373
20004
|
* @param status
|
|
19374
20005
|
*/
|
|
19375
20006
|
async updateUserStatus(status) {
|
|
19376
|
-
|
|
19377
|
-
if (!this.callKit.config.isLogin()) {
|
|
19378
|
-
this.userStatus = UserStatus.offline;
|
|
19379
|
-
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, UserStatus.offline);
|
|
20007
|
+
if (this.userChangeStatusExecuting)
|
|
19380
20008
|
return;
|
|
19381
|
-
}
|
|
19382
|
-
|
|
20009
|
+
const { agentId } = this.callKit.config.getConfig().userInfo;
|
|
20010
|
+
this.setUserChangeStatusExecuting(true);
|
|
20011
|
+
const postData = {
|
|
19383
20012
|
agentId,
|
|
19384
20013
|
userStatus: status
|
|
19385
|
-
}
|
|
20014
|
+
};
|
|
20015
|
+
const logData = {
|
|
20016
|
+
postData,
|
|
20017
|
+
url: "/agent/user/changeStatus",
|
|
20018
|
+
status: "send",
|
|
20019
|
+
startTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
20020
|
+
startTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
20021
|
+
};
|
|
20022
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, logData);
|
|
20023
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
20024
|
+
event: UserStatusChangeStepEnum.UserStatusChangeStart
|
|
20025
|
+
});
|
|
20026
|
+
await this.callKit.api.setUserStatus(postData).then(() => {
|
|
20027
|
+
this.setUserChangeStatusExecuting(false);
|
|
19386
20028
|
this.userStatus = status;
|
|
20029
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
20030
|
+
event: UserStatusChangeStepEnum.UserStatusChangeEnd
|
|
20031
|
+
});
|
|
19387
20032
|
this.callKit.trigger(KitEvent.KIT_USER_STATUS_CHANGE, status);
|
|
20033
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
20034
|
+
...logData,
|
|
20035
|
+
status: "success",
|
|
20036
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
20037
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
20038
|
+
});
|
|
19388
20039
|
}).catch((err) => {
|
|
20040
|
+
this.setUserChangeStatusExecuting(false);
|
|
20041
|
+
this.callKit.logger.addLogData(LogDataEnum.AJAX, {
|
|
20042
|
+
...logData,
|
|
20043
|
+
status: "error",
|
|
20044
|
+
endTimeStamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
20045
|
+
endTime: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
20046
|
+
});
|
|
20047
|
+
this.callKit.trigger(KitEvent.USER_STATUS_CHANGE_STEP, {
|
|
20048
|
+
event: UserStatusChangeStepEnum.UserStatusChangeError
|
|
20049
|
+
});
|
|
20050
|
+
this.setUserChangeStatusExecuting(false);
|
|
20051
|
+
if (this.callKit.connect.isRegistered()) {
|
|
20052
|
+
this.callKit.unregister();
|
|
20053
|
+
}
|
|
20054
|
+
this.callKit.trigger(
|
|
20055
|
+
KitEvent.KIT_USER_STATUS_CHANGE,
|
|
20056
|
+
UserStatus.offline
|
|
20057
|
+
);
|
|
19389
20058
|
this.callKit.logger.error(err, {
|
|
19390
20059
|
errCode: ErrorCode.API_USER_STATUS_UPDATE_ERROR
|
|
19391
20060
|
});
|
|
19392
20061
|
});
|
|
19393
20062
|
}
|
|
20063
|
+
/**
|
|
20064
|
+
* @description sdkLog
|
|
20065
|
+
* @param params
|
|
20066
|
+
* @returns
|
|
20067
|
+
*/
|
|
20068
|
+
async sendSdkLog(data) {
|
|
20069
|
+
return this.callKit.api.sdkLog(data);
|
|
20070
|
+
}
|
|
19394
20071
|
async sendHangUpReason(data) {
|
|
19395
20072
|
try {
|
|
19396
20073
|
const sendData = data || {};
|
|
@@ -19410,7 +20087,6 @@ var WebCall = (() => {
|
|
|
19410
20087
|
connect;
|
|
19411
20088
|
socket;
|
|
19412
20089
|
user;
|
|
19413
|
-
monitor;
|
|
19414
20090
|
listener = [];
|
|
19415
20091
|
constructor(options) {
|
|
19416
20092
|
this.config = new Config(this);
|
|
@@ -19428,8 +20104,6 @@ var WebCall = (() => {
|
|
|
19428
20104
|
);
|
|
19429
20105
|
this.config.setConfig("reconnect", options.reconnect);
|
|
19430
20106
|
this.logger = new Logger(this, options.log);
|
|
19431
|
-
this.config.setConfig("monitor", options.monitor);
|
|
19432
|
-
this.monitor = new Monitor(this);
|
|
19433
20107
|
this.logger.debug("callKit init", options);
|
|
19434
20108
|
this.api = new Api(this);
|
|
19435
20109
|
this.connect = new Connect(this);
|
|
@@ -19463,11 +20137,9 @@ var WebCall = (() => {
|
|
|
19463
20137
|
encryptionMethod,
|
|
19464
20138
|
encryptionPassword
|
|
19465
20139
|
});
|
|
19466
|
-
const user = await this.
|
|
20140
|
+
const user = await this.user.login({
|
|
19467
20141
|
userName: username,
|
|
19468
20142
|
password: encryptionPassword
|
|
19469
|
-
}).catch((err) => {
|
|
19470
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGIN_ERROR });
|
|
19471
20143
|
});
|
|
19472
20144
|
if (user) {
|
|
19473
20145
|
this.config.setConfig("userInfo", {
|
|
@@ -19484,6 +20156,7 @@ var WebCall = (() => {
|
|
|
19484
20156
|
fsPort: user.fsPort,
|
|
19485
20157
|
iceInfo: user.iceInfo,
|
|
19486
20158
|
iceGatheringTimeout: user.iceGatheringTimeout,
|
|
20159
|
+
logGather: user.logGather,
|
|
19487
20160
|
// encryptionType is in extra
|
|
19488
20161
|
...extra
|
|
19489
20162
|
});
|
|
@@ -19499,12 +20172,7 @@ var WebCall = (() => {
|
|
|
19499
20172
|
await this.user.setUserStatus(UserStatus.offline);
|
|
19500
20173
|
if (this.config.isLogin()) {
|
|
19501
20174
|
const { sessionId } = this.config.getConfig().userInfo;
|
|
19502
|
-
this.
|
|
19503
|
-
this.stop();
|
|
19504
|
-
this.socket.gracefulClose();
|
|
19505
|
-
this.api.loginOut({ sessionId }).catch((err) => {
|
|
19506
|
-
this.logger.error(err, { errCode: ErrorCode.API_USER_LOGOUT_ERROR });
|
|
19507
|
-
});
|
|
20175
|
+
this.user.loginOut({ sessionId });
|
|
19508
20176
|
}
|
|
19509
20177
|
await this.hangup();
|
|
19510
20178
|
this.socket.reset(false);
|
|
@@ -19547,14 +20215,12 @@ var WebCall = (() => {
|
|
|
19547
20215
|
return;
|
|
19548
20216
|
this.logger.debug("register");
|
|
19549
20217
|
this.connect.register();
|
|
19550
|
-
await this.user.setUserStatus(UserStatus.online);
|
|
19551
20218
|
}
|
|
19552
20219
|
async unregister() {
|
|
19553
20220
|
if (!this.config.check())
|
|
19554
20221
|
return;
|
|
19555
20222
|
this.logger.debug("unregister");
|
|
19556
20223
|
this.connect.unregister();
|
|
19557
|
-
await this.user.setUserStatus(UserStatus.offline);
|
|
19558
20224
|
}
|
|
19559
20225
|
async stop() {
|
|
19560
20226
|
await this.connect.stop();
|
|
@@ -19568,7 +20234,6 @@ var WebCall = (() => {
|
|
|
19568
20234
|
return;
|
|
19569
20235
|
}
|
|
19570
20236
|
await this.callCenter.callEnd(true);
|
|
19571
|
-
this.user.setUserStatus(UserStatus.catNap);
|
|
19572
20237
|
}
|
|
19573
20238
|
hold() {
|
|
19574
20239
|
if (!this.config.check())
|
|
@@ -19609,12 +20274,6 @@ var WebCall = (() => {
|
|
|
19609
20274
|
await this.user.setUserStatus(UserStatus.offline);
|
|
19610
20275
|
}
|
|
19611
20276
|
}
|
|
19612
|
-
startRTTMonitoring() {
|
|
19613
|
-
this.monitor.startRTTMonitoring();
|
|
19614
|
-
}
|
|
19615
|
-
stopRTTMonitoring() {
|
|
19616
|
-
this.monitor.stopRTTMonitoring();
|
|
19617
|
-
}
|
|
19618
20277
|
on(event, callback) {
|
|
19619
20278
|
this.logger.debug(`on ${event}`);
|
|
19620
20279
|
this.listener.push({
|