@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.mjs CHANGED
@@ -435,6 +435,11 @@ var CallSourceType = {
435
435
  phoneNum: 1,
436
436
  workOrderId: 2
437
437
  };
438
+ var trackLogsDefaultConfig = {
439
+ enabled: false,
440
+ interval: 5e3,
441
+ maxSize: 8192
442
+ };
438
443
 
439
444
  // package/call.ts
440
445
  var Call = class {
@@ -576,7 +581,7 @@ var Config = class {
576
581
  version: "1.0.27",
577
582
  host: "",
578
583
  log: "info",
579
- trackLogs: false,
584
+ trackLogs: trackLogsDefaultConfig,
580
585
  audioRef: void 0,
581
586
  constrains: constrainsDefault,
582
587
  socket: "",
@@ -661,6 +666,12 @@ var Config = class {
661
666
  }
662
667
  return true;
663
668
  }
669
+ getTrackLogsConfig() {
670
+ return this.getConfig().trackLogs ?? trackLogsDefaultConfig;
671
+ }
672
+ enableTrackLogs(enabled) {
673
+ this.config.trackLogs.enabled = enabled;
674
+ }
664
675
  };
665
676
 
666
677
  // package/logger.ts
@@ -673,8 +684,6 @@ function transformLog(log) {
673
684
  const logLevel = String(level).toUpperCase();
674
685
  return `${timestamp} [${logLevel}] [${type}] [${caller ?? "unknown"}] [${message}] ${stringify(content)}`.trim();
675
686
  }
676
- var MAX_SIZE = 8192;
677
- var FLUSH_INTERVAL = 5e3;
678
687
  function getByteSize(str) {
679
688
  return new Blob([str]).size;
680
689
  }
@@ -690,19 +699,20 @@ var Logger = class {
690
699
  this.startTrackLogsTimer();
691
700
  }
692
701
  startTrackLogsTimer() {
693
- if (this.trackLogsTimer) {
702
+ const { interval, enabled } = this.callKit.config.getConfig().trackLogs;
703
+ if (!enabled || this.trackLogsTimer) {
694
704
  return;
695
705
  }
696
706
  this.trackLogsTimer = setInterval(() => {
697
707
  this.flushTrackLogs();
698
- }, FLUSH_INTERVAL);
708
+ }, interval);
699
709
  }
700
710
  flushTrackLogs() {
701
711
  if (this.pendingTrackLogs.length === 0) {
702
712
  return;
703
713
  }
704
- const { trackLogs } = this.callKit.config.getConfig();
705
- if (trackLogs) {
714
+ const { enabled, maxSize } = this.callKit.config.getTrackLogsConfig();
715
+ if (enabled) {
706
716
  try {
707
717
  const chunks = [];
708
718
  let currentChunk = [];
@@ -711,7 +721,7 @@ var Logger = class {
711
721
  const logSize = getByteSize(log);
712
722
  const separator = currentChunk.length > 0 ? "\n" : "";
713
723
  const separatorSize = getByteSize(separator);
714
- if (currentSize + logSize + separatorSize > MAX_SIZE && currentChunk.length > 0) {
724
+ if (currentSize + logSize + separatorSize > maxSize && currentChunk.length > 0) {
715
725
  chunks.push(currentChunk.join("\n"));
716
726
  currentChunk = [log];
717
727
  currentSize = logSize;
@@ -790,8 +800,8 @@ var Logger = class {
790
800
  content: extra?.content ?? {}
791
801
  };
792
802
  const logString = transformLog(log);
793
- const { trackLogs } = this.callKit.config.getConfig();
794
- if (trackLogs) {
803
+ const { enabled } = this.callKit.config.getTrackLogsConfig();
804
+ if (enabled) {
795
805
  this.pendingTrackLogs.push(logString);
796
806
  }
797
807
  this.callKit.trigger(KitEvent.KIT_LOG, logString);