@koi-design/callkit 2.0.0-beta.7 → 2.0.0-beta.9

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 CHANGED
@@ -102,7 +102,7 @@ interface IConfig {
102
102
  version: string;
103
103
  host: string;
104
104
  log: LoggerLevel;
105
- trackLogs: boolean;
105
+ trackLogs: TrackLogsConfig;
106
106
  audioRef?: HTMLAudioElement | (() => HTMLAudioElement);
107
107
  constrains: WebrtcConstranis;
108
108
  socket: string;
@@ -138,6 +138,8 @@ declare class Config {
138
138
  validate: () => boolean;
139
139
  isLogin: () => boolean;
140
140
  check(): boolean;
141
+ getTrackLogsConfig(): TrackLogsConfig;
142
+ enableTrackLogs(enabled: boolean): void;
141
143
  }
142
144
 
143
145
  declare const CallStatus: {
@@ -303,7 +305,12 @@ type EncryptionMethodType = (typeof EncryptionMethod)[keyof typeof EncryptionMet
303
305
  declare const CallSourceType: {
304
306
  phoneNum: number;
305
307
  workOrderId: number;
306
- };
308
+ };
309
+ interface TrackLogsConfig {
310
+ enabled: boolean;
311
+ interval: number;
312
+ maxSize: number;
313
+ }
307
314
 
308
315
  interface CallParams {
309
316
  agentId: string;
@@ -3633,6 +3633,11 @@ var WebCall = (() => {
3633
3633
  phoneNum: 1,
3634
3634
  workOrderId: 2
3635
3635
  };
3636
+ var trackLogsDefaultConfig = {
3637
+ enabled: false,
3638
+ interval: 5e3,
3639
+ maxSize: 8192
3640
+ };
3636
3641
 
3637
3642
  // package/call.ts
3638
3643
  var Call = class {
@@ -3774,7 +3779,7 @@ var WebCall = (() => {
3774
3779
  version: "1.0.27",
3775
3780
  host: "",
3776
3781
  log: "info",
3777
- trackLogs: false,
3782
+ trackLogs: trackLogsDefaultConfig,
3778
3783
  audioRef: void 0,
3779
3784
  constrains: constrainsDefault,
3780
3785
  socket: "",
@@ -3859,6 +3864,12 @@ var WebCall = (() => {
3859
3864
  }
3860
3865
  return true;
3861
3866
  }
3867
+ getTrackLogsConfig() {
3868
+ return this.getConfig().trackLogs ?? trackLogsDefaultConfig;
3869
+ }
3870
+ enableTrackLogs(enabled) {
3871
+ this.config.trackLogs.enabled = enabled;
3872
+ }
3862
3873
  };
3863
3874
 
3864
3875
  // package/logger.ts
@@ -3871,8 +3882,6 @@ var WebCall = (() => {
3871
3882
  const logLevel = String(level).toUpperCase();
3872
3883
  return `${timestamp} [${logLevel}] [${type}] [${caller ?? "unknown"}] [${message}] ${(0, import_json_stringify_safe.default)(content)}`.trim();
3873
3884
  }
3874
- var MAX_SIZE = 8192;
3875
- var FLUSH_INTERVAL = 5e3;
3876
3885
  function getByteSize(str) {
3877
3886
  return new Blob([str]).size;
3878
3887
  }
@@ -3888,19 +3897,20 @@ var WebCall = (() => {
3888
3897
  this.startTrackLogsTimer();
3889
3898
  }
3890
3899
  startTrackLogsTimer() {
3891
- if (this.trackLogsTimer) {
3900
+ const { interval, enabled } = this.callKit.config.getConfig().trackLogs;
3901
+ if (!enabled || this.trackLogsTimer) {
3892
3902
  return;
3893
3903
  }
3894
3904
  this.trackLogsTimer = setInterval(() => {
3895
3905
  this.flushTrackLogs();
3896
- }, FLUSH_INTERVAL);
3906
+ }, interval);
3897
3907
  }
3898
3908
  flushTrackLogs() {
3899
3909
  if (this.pendingTrackLogs.length === 0) {
3900
3910
  return;
3901
3911
  }
3902
- const { trackLogs } = this.callKit.config.getConfig();
3903
- if (trackLogs) {
3912
+ const { enabled, maxSize } = this.callKit.config.getTrackLogsConfig();
3913
+ if (enabled) {
3904
3914
  try {
3905
3915
  const chunks = [];
3906
3916
  let currentChunk = [];
@@ -3909,7 +3919,7 @@ var WebCall = (() => {
3909
3919
  const logSize = getByteSize(log);
3910
3920
  const separator = currentChunk.length > 0 ? "\n" : "";
3911
3921
  const separatorSize = getByteSize(separator);
3912
- if (currentSize + logSize + separatorSize > MAX_SIZE && currentChunk.length > 0) {
3922
+ if (currentSize + logSize + separatorSize > maxSize && currentChunk.length > 0) {
3913
3923
  chunks.push(currentChunk.join("\n"));
3914
3924
  currentChunk = [log];
3915
3925
  currentSize = logSize;
@@ -3988,8 +3998,8 @@ var WebCall = (() => {
3988
3998
  content: extra?.content ?? {}
3989
3999
  };
3990
4000
  const logString = transformLog(log);
3991
- const { trackLogs } = this.callKit.config.getConfig();
3992
- if (trackLogs) {
4001
+ const { enabled } = this.callKit.config.getTrackLogsConfig();
4002
+ if (enabled) {
3993
4003
  this.pendingTrackLogs.push(logString);
3994
4004
  }
3995
4005
  this.callKit.trigger(KitEvent.KIT_LOG, logString);