@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.js CHANGED
@@ -609,7 +609,11 @@ var Config = class {
609
609
  version: "1.0.27",
610
610
  host: "",
611
611
  log: "info",
612
- trackLogs: false,
612
+ trackLogs: {
613
+ enabled: false,
614
+ interval: 5e3,
615
+ maxSize: 8192
616
+ },
613
617
  audioRef: void 0,
614
618
  constrains: constrainsDefault,
615
619
  socket: "",
@@ -694,6 +698,10 @@ var Config = class {
694
698
  }
695
699
  return true;
696
700
  }
701
+ isLogsEnabled() {
702
+ const { trackLogs } = this.getConfig();
703
+ return trackLogs?.enabled ?? false;
704
+ }
697
705
  };
698
706
 
699
707
  // package/logger.ts
@@ -706,8 +714,6 @@ function transformLog(log) {
706
714
  const logLevel = String(level).toUpperCase();
707
715
  return `${timestamp} [${logLevel}] [${type}] [${caller ?? "unknown"}] [${message}] ${(0, import_json_stringify_safe.default)(content)}`.trim();
708
716
  }
709
- var MAX_SIZE = 8192;
710
- var FLUSH_INTERVAL = 5e3;
711
717
  function getByteSize(str) {
712
718
  return new Blob([str]).size;
713
719
  }
@@ -723,28 +729,35 @@ var Logger = class {
723
729
  this.startTrackLogsTimer();
724
730
  }
725
731
  startTrackLogsTimer() {
732
+ const { trackLogs } = this.callKit.config.getConfig();
733
+ if (!trackLogs.enabled) {
734
+ return;
735
+ }
736
+ const { interval } = trackLogs;
726
737
  if (this.trackLogsTimer) {
727
738
  return;
728
739
  }
729
740
  this.trackLogsTimer = setInterval(() => {
730
741
  this.flushTrackLogs();
731
- }, FLUSH_INTERVAL);
742
+ }, interval);
732
743
  }
733
744
  flushTrackLogs() {
734
745
  if (this.pendingTrackLogs.length === 0) {
735
746
  return;
736
747
  }
737
- const { trackLogs } = this.callKit.config.getConfig();
738
- if (trackLogs) {
748
+ const isLogsEnabled = this.callKit.config.isLogsEnabled();
749
+ if (isLogsEnabled) {
739
750
  try {
740
751
  const chunks = [];
741
752
  let currentChunk = [];
742
753
  let currentSize = 0;
754
+ const { trackLogs } = this.callKit.config.getConfig();
755
+ const { maxSize } = trackLogs;
743
756
  for (const log of this.pendingTrackLogs) {
744
757
  const logSize = getByteSize(log);
745
758
  const separator = currentChunk.length > 0 ? "\n" : "";
746
759
  const separatorSize = getByteSize(separator);
747
- if (currentSize + logSize + separatorSize > MAX_SIZE && currentChunk.length > 0) {
760
+ if (currentSize + logSize + separatorSize > maxSize && currentChunk.length > 0) {
748
761
  chunks.push(currentChunk.join("\n"));
749
762
  currentChunk = [log];
750
763
  currentSize = logSize;
@@ -823,8 +836,8 @@ var Logger = class {
823
836
  content: extra?.content ?? {}
824
837
  };
825
838
  const logString = transformLog(log);
826
- const { trackLogs } = this.callKit.config.getConfig();
827
- if (trackLogs) {
839
+ const isLogsEnabled = this.callKit.config.isLogsEnabled();
840
+ if (isLogsEnabled) {
828
841
  this.pendingTrackLogs.push(logString);
829
842
  }
830
843
  this.callKit.trigger(KitEvent.KIT_LOG, logString);