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

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
@@ -576,7 +576,11 @@ var Config = class {
576
576
  version: "1.0.27",
577
577
  host: "",
578
578
  log: "info",
579
- trackLogs: false,
579
+ trackLogs: {
580
+ enabled: false,
581
+ interval: 5e3,
582
+ maxSize: 8192
583
+ },
580
584
  audioRef: void 0,
581
585
  constrains: constrainsDefault,
582
586
  socket: "",
@@ -661,6 +665,10 @@ var Config = class {
661
665
  }
662
666
  return true;
663
667
  }
668
+ isLogsEnabled() {
669
+ const { trackLogs } = this.getConfig();
670
+ return trackLogs?.enabled ?? false;
671
+ }
664
672
  };
665
673
 
666
674
  // package/logger.ts
@@ -673,8 +681,6 @@ function transformLog(log) {
673
681
  const logLevel = String(level).toUpperCase();
674
682
  return `${timestamp} [${logLevel}] [${type}] [${caller ?? "unknown"}] [${message}] ${stringify(content)}`.trim();
675
683
  }
676
- var MAX_SIZE = 8192;
677
- var FLUSH_INTERVAL = 5e3;
678
684
  function getByteSize(str) {
679
685
  return new Blob([str]).size;
680
686
  }
@@ -690,28 +696,35 @@ var Logger = class {
690
696
  this.startTrackLogsTimer();
691
697
  }
692
698
  startTrackLogsTimer() {
699
+ const { trackLogs } = this.callKit.config.getConfig();
700
+ if (!trackLogs.enabled) {
701
+ return;
702
+ }
703
+ const { interval } = trackLogs;
693
704
  if (this.trackLogsTimer) {
694
705
  return;
695
706
  }
696
707
  this.trackLogsTimer = setInterval(() => {
697
708
  this.flushTrackLogs();
698
- }, FLUSH_INTERVAL);
709
+ }, interval);
699
710
  }
700
711
  flushTrackLogs() {
701
712
  if (this.pendingTrackLogs.length === 0) {
702
713
  return;
703
714
  }
704
- const { trackLogs } = this.callKit.config.getConfig();
705
- if (trackLogs) {
715
+ const isLogsEnabled = this.callKit.config.isLogsEnabled();
716
+ if (isLogsEnabled) {
706
717
  try {
707
718
  const chunks = [];
708
719
  let currentChunk = [];
709
720
  let currentSize = 0;
721
+ const { trackLogs } = this.callKit.config.getConfig();
722
+ const { maxSize } = trackLogs;
710
723
  for (const log of this.pendingTrackLogs) {
711
724
  const logSize = getByteSize(log);
712
725
  const separator = currentChunk.length > 0 ? "\n" : "";
713
726
  const separatorSize = getByteSize(separator);
714
- if (currentSize + logSize + separatorSize > MAX_SIZE && currentChunk.length > 0) {
727
+ if (currentSize + logSize + separatorSize > maxSize && currentChunk.length > 0) {
715
728
  chunks.push(currentChunk.join("\n"));
716
729
  currentChunk = [log];
717
730
  currentSize = logSize;
@@ -790,8 +803,8 @@ var Logger = class {
790
803
  content: extra?.content ?? {}
791
804
  };
792
805
  const logString = transformLog(log);
793
- const { trackLogs } = this.callKit.config.getConfig();
794
- if (trackLogs) {
806
+ const isLogsEnabled = this.callKit.config.isLogsEnabled();
807
+ if (isLogsEnabled) {
795
808
  this.pendingTrackLogs.push(logString);
796
809
  }
797
810
  this.callKit.trigger(KitEvent.KIT_LOG, logString);