@koi-design/callkit 1.0.24-beta.41 → 1.0.24-beta.43
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 +3 -2
- package/dist/index.global.js +171 -153
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +171 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -153
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare class Api {
|
|
|
15
15
|
* @param params
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
sdkLog(
|
|
18
|
+
sdkLog(data: any): Promise<any>;
|
|
19
19
|
/**
|
|
20
20
|
*
|
|
21
21
|
* @param params agentId userStatus
|
|
@@ -230,6 +230,7 @@ declare class Logger {
|
|
|
230
230
|
logData: Record<LogDataType, any[]>;
|
|
231
231
|
private callKit;
|
|
232
232
|
constructor(callKit: CallKit, level?: LoggerLevel);
|
|
233
|
+
static formatStrLog(logObj: any): string;
|
|
233
234
|
setLevel(level: LoggerLevel): void;
|
|
234
235
|
debug(msg: any, extra?: Object): void;
|
|
235
236
|
log(msg: any, extra?: Object): void;
|
|
@@ -478,7 +479,7 @@ declare class User {
|
|
|
478
479
|
* @param params
|
|
479
480
|
* @returns
|
|
480
481
|
*/
|
|
481
|
-
sendSdkLog(
|
|
482
|
+
sendSdkLog(data: any): Promise<any>;
|
|
482
483
|
sendHangUpReason(data: any): Promise<void>;
|
|
483
484
|
}
|
|
484
485
|
|
package/dist/index.global.js
CHANGED
|
@@ -3861,6 +3861,167 @@ var WebCall = (() => {
|
|
|
3861
3861
|
ALL: "all"
|
|
3862
3862
|
};
|
|
3863
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
|
+
callKit;
|
|
3881
|
+
constructor(callKit, level) {
|
|
3882
|
+
this.callKit = callKit;
|
|
3883
|
+
this.level = level || "debug";
|
|
3884
|
+
this.logData = {
|
|
3885
|
+
sip: [],
|
|
3886
|
+
incall: [],
|
|
3887
|
+
ajax: [],
|
|
3888
|
+
error: [],
|
|
3889
|
+
reconnect: [],
|
|
3890
|
+
all: []
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
static formatStrLog(logObj) {
|
|
3894
|
+
const {
|
|
3895
|
+
type = "info"
|
|
3896
|
+
// 默认等级
|
|
3897
|
+
} = logObj;
|
|
3898
|
+
const time = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
3899
|
+
const level = String(type).toUpperCase().padEnd(5, " ");
|
|
3900
|
+
const tagStr = logObj.typeag ? `[${logObj.type}]` : "";
|
|
3901
|
+
const msg = JSON.stringify(logObj);
|
|
3902
|
+
return `${time} [${level}] ${tagStr} ${msg}`.trim();
|
|
3903
|
+
}
|
|
3904
|
+
setLevel(level) {
|
|
3905
|
+
this.level = level;
|
|
3906
|
+
}
|
|
3907
|
+
debug(msg, extra) {
|
|
3908
|
+
if (getLevel(this.level) >= getLevel("debug")) {
|
|
3909
|
+
this.output("blue")(msg, extra);
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
log(msg, extra) {
|
|
3913
|
+
if (getLevel(this.level) >= getLevel("log")) {
|
|
3914
|
+
this.output("green")(msg, extra);
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
warn(msg, extra) {
|
|
3918
|
+
if (getLevel(this.level) >= getLevel("warn")) {
|
|
3919
|
+
this.output("orange")(msg, extra);
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
error(msg, extra) {
|
|
3923
|
+
const message = msg?.message ?? msg;
|
|
3924
|
+
if (getLevel(this.level) >= getLevel("error")) {
|
|
3925
|
+
this.output("red")(message, extra);
|
|
3926
|
+
}
|
|
3927
|
+
const { errCode, ...rest } = extra;
|
|
3928
|
+
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
3929
|
+
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
3930
|
+
code: errorCode,
|
|
3931
|
+
msg: message,
|
|
3932
|
+
data: rest
|
|
3933
|
+
});
|
|
3934
|
+
this.callKit.reset();
|
|
3935
|
+
const error = new Error(message);
|
|
3936
|
+
error.name = "CallKitError";
|
|
3937
|
+
error.code = errorCode;
|
|
3938
|
+
error.data = rest;
|
|
3939
|
+
throw error;
|
|
3940
|
+
}
|
|
3941
|
+
addLogData(type, data) {
|
|
3942
|
+
this.callKit.user.sendSdkLog({
|
|
3943
|
+
...data,
|
|
3944
|
+
type,
|
|
3945
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
3946
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
3947
|
+
});
|
|
3948
|
+
if (!this.callKit.config.isLogGatherEnable()) {
|
|
3949
|
+
return;
|
|
3950
|
+
}
|
|
3951
|
+
let logData = {
|
|
3952
|
+
type,
|
|
3953
|
+
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
3954
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
3955
|
+
data: ""
|
|
3956
|
+
};
|
|
3957
|
+
if (type === LogDataEnum.INCALL) {
|
|
3958
|
+
logData.data = (0, import_json_stringify_safe.default)({
|
|
3959
|
+
// customField
|
|
3960
|
+
callKitSocketFrom: data?.callKitSocketFrom,
|
|
3961
|
+
type: data?.ev.type || data?.type,
|
|
3962
|
+
data: data?.ev.data || data?.data,
|
|
3963
|
+
// message
|
|
3964
|
+
origin: data?.ev.origin || data?.origin,
|
|
3965
|
+
lastEventId: data?.ev.lastEventId || data?.lastEventId,
|
|
3966
|
+
isTrusted: data?.ev.isTrusted || data?.isTrusted,
|
|
3967
|
+
// close
|
|
3968
|
+
code: data?.ev.code || data?.code,
|
|
3969
|
+
reason: data?.ev.reason || data?.reason,
|
|
3970
|
+
wasClean: data?.ev.wasClean || data?.wasClean
|
|
3971
|
+
});
|
|
3972
|
+
} else {
|
|
3973
|
+
logData = (0, import_json_stringify_safe.default)(data);
|
|
3974
|
+
}
|
|
3975
|
+
switch (type) {
|
|
3976
|
+
case LogDataEnum.SIP:
|
|
3977
|
+
this.logData.sip.push(logData);
|
|
3978
|
+
this.logData.all.push(logData);
|
|
3979
|
+
break;
|
|
3980
|
+
case LogDataEnum.INCALL:
|
|
3981
|
+
this.logData.incall.push(logData);
|
|
3982
|
+
this.logData.all.push(logData);
|
|
3983
|
+
break;
|
|
3984
|
+
case LogDataEnum.AJAX:
|
|
3985
|
+
this.logData.ajax.push(logData);
|
|
3986
|
+
this.logData.all.push(logData);
|
|
3987
|
+
break;
|
|
3988
|
+
case LogDataEnum.RECONNECT:
|
|
3989
|
+
this.logData.reconnect.push(logData);
|
|
3990
|
+
this.logData.all.push(logData);
|
|
3991
|
+
break;
|
|
3992
|
+
case LogDataEnum.ERROR:
|
|
3993
|
+
this.logData.error.push(logData);
|
|
3994
|
+
this.logData.all.push(logData);
|
|
3995
|
+
break;
|
|
3996
|
+
default:
|
|
3997
|
+
this.logData.all.push(logData);
|
|
3998
|
+
break;
|
|
3999
|
+
}
|
|
4000
|
+
this.callKit.socket.sendMessage(SocketSendEvent.SDK_LOG, logData);
|
|
4001
|
+
}
|
|
4002
|
+
output(color) {
|
|
4003
|
+
return (msg, extra = {}) => {
|
|
4004
|
+
const now = /* @__PURE__ */ new Date();
|
|
4005
|
+
if (Object.keys(extra).length > 0) {
|
|
4006
|
+
console.log(
|
|
4007
|
+
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
4008
|
+
`color: ${color};`,
|
|
4009
|
+
"color:block;",
|
|
4010
|
+
extra,
|
|
4011
|
+
"color:#999;"
|
|
4012
|
+
);
|
|
4013
|
+
} else {
|
|
4014
|
+
console.log(
|
|
4015
|
+
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
4016
|
+
`color: ${color};`,
|
|
4017
|
+
"color:block;",
|
|
4018
|
+
"color:#999;"
|
|
4019
|
+
);
|
|
4020
|
+
}
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
|
|
3864
4025
|
// package/api.ts
|
|
3865
4026
|
var Api = class {
|
|
3866
4027
|
callKit;
|
|
@@ -3886,11 +4047,15 @@ var WebCall = (() => {
|
|
|
3886
4047
|
* @param params
|
|
3887
4048
|
* @returns
|
|
3888
4049
|
*/
|
|
3889
|
-
async sdkLog(
|
|
4050
|
+
async sdkLog(data) {
|
|
4051
|
+
const strLog = Logger.formatStrLog(data);
|
|
3890
4052
|
return this.post({
|
|
4053
|
+
// headers: {
|
|
4054
|
+
// 'Content-Type': 'application/json'
|
|
4055
|
+
// },
|
|
3891
4056
|
url: "/agent/user/sdkLog",
|
|
3892
4057
|
method: "post",
|
|
3893
|
-
data:
|
|
4058
|
+
data: strLog
|
|
3894
4059
|
});
|
|
3895
4060
|
}
|
|
3896
4061
|
/**
|
|
@@ -3912,8 +4077,8 @@ var WebCall = (() => {
|
|
|
3912
4077
|
const { sessionId } = userInfo;
|
|
3913
4078
|
config.url = `${host}${config.url}`;
|
|
3914
4079
|
config.headers = {
|
|
3915
|
-
|
|
3916
|
-
|
|
4080
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
4081
|
+
...config.headers
|
|
3917
4082
|
};
|
|
3918
4083
|
if (config.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
3919
4084
|
config.data = new URLSearchParams(config.data).toString();
|
|
@@ -4124,153 +4289,6 @@ var WebCall = (() => {
|
|
|
4124
4289
|
}
|
|
4125
4290
|
};
|
|
4126
4291
|
|
|
4127
|
-
// package/logger.ts
|
|
4128
|
-
var import_json_stringify_safe = __toESM(require_stringify());
|
|
4129
|
-
function getLevel(level) {
|
|
4130
|
-
return LoggerLevelMap[level];
|
|
4131
|
-
}
|
|
4132
|
-
var Logger = class {
|
|
4133
|
-
prefix = "CallKit";
|
|
4134
|
-
level = "debug";
|
|
4135
|
-
logData = {
|
|
4136
|
-
sip: [],
|
|
4137
|
-
incall: [],
|
|
4138
|
-
ajax: [],
|
|
4139
|
-
error: [],
|
|
4140
|
-
reconnect: [],
|
|
4141
|
-
all: []
|
|
4142
|
-
};
|
|
4143
|
-
callKit;
|
|
4144
|
-
constructor(callKit, level) {
|
|
4145
|
-
this.callKit = callKit;
|
|
4146
|
-
this.level = level || "debug";
|
|
4147
|
-
this.logData = {
|
|
4148
|
-
sip: [],
|
|
4149
|
-
incall: [],
|
|
4150
|
-
ajax: [],
|
|
4151
|
-
error: [],
|
|
4152
|
-
reconnect: [],
|
|
4153
|
-
all: []
|
|
4154
|
-
};
|
|
4155
|
-
}
|
|
4156
|
-
setLevel(level) {
|
|
4157
|
-
this.level = level;
|
|
4158
|
-
}
|
|
4159
|
-
debug(msg, extra) {
|
|
4160
|
-
if (getLevel(this.level) >= getLevel("debug")) {
|
|
4161
|
-
this.output("blue")(msg, extra);
|
|
4162
|
-
}
|
|
4163
|
-
}
|
|
4164
|
-
log(msg, extra) {
|
|
4165
|
-
if (getLevel(this.level) >= getLevel("log")) {
|
|
4166
|
-
this.output("green")(msg, extra);
|
|
4167
|
-
}
|
|
4168
|
-
}
|
|
4169
|
-
warn(msg, extra) {
|
|
4170
|
-
if (getLevel(this.level) >= getLevel("warn")) {
|
|
4171
|
-
this.output("orange")(msg, extra);
|
|
4172
|
-
}
|
|
4173
|
-
}
|
|
4174
|
-
error(msg, extra) {
|
|
4175
|
-
const message = msg?.message ?? msg;
|
|
4176
|
-
if (getLevel(this.level) >= getLevel("error")) {
|
|
4177
|
-
this.output("red")(message, extra);
|
|
4178
|
-
}
|
|
4179
|
-
const { errCode, ...rest } = extra;
|
|
4180
|
-
const errorCode = errCode ?? ErrorCode.UNKNOWN_ERROR;
|
|
4181
|
-
this.callKit.trigger(KitEvent.KIT_ERROR, {
|
|
4182
|
-
code: errorCode,
|
|
4183
|
-
msg: message,
|
|
4184
|
-
data: rest
|
|
4185
|
-
});
|
|
4186
|
-
this.callKit.reset();
|
|
4187
|
-
const error = new Error(message);
|
|
4188
|
-
error.name = "CallKitError";
|
|
4189
|
-
error.code = errorCode;
|
|
4190
|
-
error.data = rest;
|
|
4191
|
-
throw error;
|
|
4192
|
-
}
|
|
4193
|
-
addLogData(type, data) {
|
|
4194
|
-
this.callKit.user.sendSdkLog({
|
|
4195
|
-
content: data || {}
|
|
4196
|
-
});
|
|
4197
|
-
if (!this.callKit.config.isLogGatherEnable()) {
|
|
4198
|
-
return;
|
|
4199
|
-
}
|
|
4200
|
-
let logData = {
|
|
4201
|
-
type,
|
|
4202
|
-
timestamp: (/* @__PURE__ */ new Date()).valueOf(),
|
|
4203
|
-
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
4204
|
-
data: ""
|
|
4205
|
-
};
|
|
4206
|
-
if (type === LogDataEnum.INCALL) {
|
|
4207
|
-
logData.data = (0, import_json_stringify_safe.default)({
|
|
4208
|
-
// customField
|
|
4209
|
-
callKitSocketFrom: data?.callKitSocketFrom,
|
|
4210
|
-
type: data?.ev.type || data?.type,
|
|
4211
|
-
data: data?.ev.data || data?.data,
|
|
4212
|
-
// message
|
|
4213
|
-
origin: data?.ev.origin || data?.origin,
|
|
4214
|
-
lastEventId: data?.ev.lastEventId || data?.lastEventId,
|
|
4215
|
-
isTrusted: data?.ev.isTrusted || data?.isTrusted,
|
|
4216
|
-
// close
|
|
4217
|
-
code: data?.ev.code || data?.code,
|
|
4218
|
-
reason: data?.ev.reason || data?.reason,
|
|
4219
|
-
wasClean: data?.ev.wasClean || data?.wasClean
|
|
4220
|
-
});
|
|
4221
|
-
} else {
|
|
4222
|
-
logData = (0, import_json_stringify_safe.default)(data);
|
|
4223
|
-
}
|
|
4224
|
-
switch (type) {
|
|
4225
|
-
case LogDataEnum.SIP:
|
|
4226
|
-
this.logData.sip.push(logData);
|
|
4227
|
-
this.logData.all.push(logData);
|
|
4228
|
-
break;
|
|
4229
|
-
case LogDataEnum.INCALL:
|
|
4230
|
-
this.logData.incall.push(logData);
|
|
4231
|
-
this.logData.all.push(logData);
|
|
4232
|
-
break;
|
|
4233
|
-
case LogDataEnum.AJAX:
|
|
4234
|
-
this.logData.ajax.push(logData);
|
|
4235
|
-
this.logData.all.push(logData);
|
|
4236
|
-
break;
|
|
4237
|
-
case LogDataEnum.RECONNECT:
|
|
4238
|
-
this.logData.reconnect.push(logData);
|
|
4239
|
-
this.logData.all.push(logData);
|
|
4240
|
-
break;
|
|
4241
|
-
case LogDataEnum.ERROR:
|
|
4242
|
-
this.logData.error.push(logData);
|
|
4243
|
-
this.logData.all.push(logData);
|
|
4244
|
-
break;
|
|
4245
|
-
default:
|
|
4246
|
-
this.logData.all.push(logData);
|
|
4247
|
-
break;
|
|
4248
|
-
}
|
|
4249
|
-
this.callKit.socket.sendMessage(SocketSendEvent.SDK_LOG, logData);
|
|
4250
|
-
}
|
|
4251
|
-
output(color) {
|
|
4252
|
-
return (msg, extra = {}) => {
|
|
4253
|
-
const now = /* @__PURE__ */ new Date();
|
|
4254
|
-
if (Object.keys(extra).length > 0) {
|
|
4255
|
-
console.log(
|
|
4256
|
-
`%c[${this.prefix}] %c ${msg} %o %c ${now.toLocaleString()}`,
|
|
4257
|
-
`color: ${color};`,
|
|
4258
|
-
"color:block;",
|
|
4259
|
-
extra,
|
|
4260
|
-
"color:#999;"
|
|
4261
|
-
);
|
|
4262
|
-
} else {
|
|
4263
|
-
console.log(
|
|
4264
|
-
`%c[${this.prefix}] %c ${msg} %c ${now.toLocaleString()}`,
|
|
4265
|
-
`color: ${color};`,
|
|
4266
|
-
"color:block;",
|
|
4267
|
-
"color:#999;"
|
|
4268
|
-
);
|
|
4269
|
-
}
|
|
4270
|
-
};
|
|
4271
|
-
}
|
|
4272
|
-
};
|
|
4273
|
-
|
|
4274
4292
|
// node_modules/.pnpm/sip.js@0.21.2/node_modules/sip.js/lib/version.js
|
|
4275
4293
|
var LIBRARY_VERSION = "0.21.1";
|
|
4276
4294
|
|
|
@@ -20012,8 +20030,8 @@ var WebCall = (() => {
|
|
|
20012
20030
|
* @param params
|
|
20013
20031
|
* @returns
|
|
20014
20032
|
*/
|
|
20015
|
-
async sendSdkLog(
|
|
20016
|
-
return this.callKit.api.sdkLog(
|
|
20033
|
+
async sendSdkLog(data) {
|
|
20034
|
+
return this.callKit.api.sdkLog(data);
|
|
20017
20035
|
}
|
|
20018
20036
|
async sendHangUpReason(data) {
|
|
20019
20037
|
try {
|