@glimt/record 0.0.71 → 0.0.72

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/record.cjs CHANGED
@@ -10281,52 +10281,6 @@ const debugLog = (...args) => {
10281
10281
  if (!isDebug()) return;
10282
10282
  console.log("[recapt:rrweb]", ...args);
10283
10283
  };
10284
- const _StormSnapshotManager = class _StormSnapshotManager2 {
10285
- constructor() {
10286
- __publicField(this, "lastFullSnapshot", -1);
10287
- __publicField(this, "intervalBetweenSnapshots", 150);
10288
- __publicField(this, "debounceTimeout", null);
10289
- __publicField(this, "debounceTime", 10);
10290
- if (_StormSnapshotManager2.instance) {
10291
- return _StormSnapshotManager2.instance;
10292
- }
10293
- _StormSnapshotManager2.instance = this;
10294
- }
10295
- //we're debouncing here because of how mutation buffers work.
10296
- //multiple observers create their own mutation buffer, and
10297
- //each buffer will handle mutations storms, so multiple buffers
10298
- //will probably request a full snapshot at (basically) the same time.
10299
- //we want to ensure all buffers have requested a full snapshot
10300
- //(so we can be sure that all mutations have been made)
10301
- //before we actually take a full snapshot.
10302
- //also, we want a low debounceTime, bc if theres multiple, distinctive mutation storms,
10303
- //in a somewhat quick succession, we want to record activity between them
10304
- //not just one full snapshot after all the storms:
10305
- //[mutation storm] [full snapshot] [mutation storm] [full snapshot]
10306
- //NOT
10307
- //[mutation storm] [timeout] [mutation storm] [full snapshot] (in this case, we probably miss all events which fired during the timeout)
10308
- requestFullSnapshot() {
10309
- if (this.debounceTimeout) {
10310
- clearTimeout(this.debounceTimeout);
10311
- }
10312
- this.debounceTimeout = setTimeout(() => {
10313
- this.debounceTimeout = null;
10314
- this.takeSnapshot();
10315
- }, this.debounceTime);
10316
- }
10317
- takeSnapshot() {
10318
- if (Date.now() - this.lastFullSnapshot < this.intervalBetweenSnapshots) {
10319
- debugLog("StormSnapshotManager, takeSnapshot: too soon");
10320
- return;
10321
- }
10322
- debugLog("StormSnapshotManager, takeSnapshot: taking full snapshot");
10323
- takeFullSnapshot();
10324
- this.lastFullSnapshot = Date.now();
10325
- }
10326
- };
10327
- __publicField(_StormSnapshotManager, "instance");
10328
- let StormSnapshotManager = _StormSnapshotManager;
10329
- const stormSnapshotManager = new StormSnapshotManager();
10330
10284
  const _MutationRateLimiter = class _MutationRateLimiter2 {
10331
10285
  constructor() {
10332
10286
  __publicField(this, "mutTracker");
@@ -10337,6 +10291,9 @@ const _MutationRateLimiter = class _MutationRateLimiter2 {
10337
10291
  __publicField(this, "inGlobalStorm", false);
10338
10292
  __publicField(this, "currentStormStartedAt", -1);
10339
10293
  __publicField(this, "stormTimeLimit", 5e3);
10294
+ __publicField(this, "debounceTimeout", null);
10295
+ __publicField(this, "debounceTimeoutMs", 250);
10296
+ __publicField(this, "handleStormFinishMethods", {});
10340
10297
  if (_MutationRateLimiter2.instance) {
10341
10298
  return _MutationRateLimiter2.instance;
10342
10299
  }
@@ -10361,11 +10318,19 @@ const _MutationRateLimiter = class _MutationRateLimiter2 {
10361
10318
  this.resetExitTracker();
10362
10319
  this.currentStormStartedAt = -1;
10363
10320
  }
10364
- stormStopped() {
10321
+ stormStopped(stoppedByBuffer) {
10322
+ if (this.debounceTimeout) clearTimeout(this.debounceTimeout);
10365
10323
  this.inGlobalStorm = false;
10366
10324
  this.reset();
10325
+ for (const [bufId, method] of Object.entries(
10326
+ this.handleStormFinishMethods
10327
+ )) {
10328
+ if (bufId === stoppedByBuffer) continue;
10329
+ method();
10330
+ }
10331
+ this.handleStormFinishMethods = {};
10367
10332
  }
10368
- handleStormExit(muts) {
10333
+ handleStormExit(muts, bufId) {
10369
10334
  const now = Date.now();
10370
10335
  if (this.exitMutTracker.requested === -1) {
10371
10336
  this.exitMutTracker = {
@@ -10392,29 +10357,40 @@ const _MutationRateLimiter = class _MutationRateLimiter2 {
10392
10357
  mutTracker: this.mutTracker,
10393
10358
  exitMutTracker: this.exitMutTracker
10394
10359
  });
10395
- this.stormStopped();
10360
+ this.stormStopped(bufId);
10396
10361
  return false;
10397
10362
  }
10398
10363
  }
10399
10364
  }
10400
10365
  return true;
10401
10366
  }
10402
- canMutationBufferExitMutationStorm() {
10403
- return !this.inGlobalStorm;
10367
+ isInGlobalStorm() {
10368
+ return this.inGlobalStorm;
10369
+ }
10370
+ doDebounce() {
10371
+ if (this.debounceTimeout) clearTimeout(this.debounceTimeout);
10372
+ if (!this.inGlobalStorm) return;
10373
+ this.debounceTimeout = setTimeout(() => {
10374
+ this.debounceTimeout = null;
10375
+ this.stormStopped();
10376
+ }, this.debounceTimeoutMs);
10404
10377
  }
10405
- isStorming(muts) {
10378
+ isStorming(muts, buffer) {
10379
+ if (!(buffer.bufId in this.handleStormFinishMethods)) {
10380
+ this.handleStormFinishMethods[buffer.bufId] = buffer.handleStormFinish.bind(buffer);
10381
+ }
10406
10382
  const now = Date.now();
10407
10383
  if (this.inGlobalStorm) {
10384
+ this.doDebounce();
10408
10385
  if (now - this.currentStormStartedAt > this.stormTimeLimit) {
10409
10386
  debugLog(
10410
10387
  `MutationRateLimiter, storm time limit reached, stopping storm`
10411
10388
  );
10412
- this.stormStopped();
10389
+ this.stormStopped(buffer.bufId);
10413
10390
  return false;
10414
10391
  }
10415
- if (now - this.mutTracker.ts > this.interval) {
10416
- return this.handleStormExit(muts);
10417
- }
10392
+ if (now - this.mutTracker.ts > this.interval)
10393
+ return this.handleStormExit(muts, buffer.bufId);
10418
10394
  this.mutTracker.muts += muts;
10419
10395
  this.mutTracker.ts = now;
10420
10396
  return true;
@@ -10428,6 +10404,7 @@ const _MutationRateLimiter = class _MutationRateLimiter2 {
10428
10404
  this.inGlobalStorm = true;
10429
10405
  debugLog(`MutationRateLimiter, detected global rolling storm`);
10430
10406
  this.currentStormStartedAt = now;
10407
+ this.doDebounce();
10431
10408
  return true;
10432
10409
  }
10433
10410
  }
@@ -10439,6 +10416,52 @@ const _MutationRateLimiter = class _MutationRateLimiter2 {
10439
10416
  __publicField(_MutationRateLimiter, "instance");
10440
10417
  let MutationRateLimiter = _MutationRateLimiter;
10441
10418
  const mutationRateLimiter = new MutationRateLimiter();
10419
+ const _StormSnapshotManager = class _StormSnapshotManager2 {
10420
+ constructor() {
10421
+ __publicField(this, "lastFullSnapshot", -1);
10422
+ __publicField(this, "intervalBetweenSnapshots", 150);
10423
+ __publicField(this, "debounceTimeout", null);
10424
+ __publicField(this, "debounceTime", 10);
10425
+ if (_StormSnapshotManager2.instance) {
10426
+ return _StormSnapshotManager2.instance;
10427
+ }
10428
+ _StormSnapshotManager2.instance = this;
10429
+ }
10430
+ //we're debouncing here because of how mutation buffers work.
10431
+ //multiple observers create their own mutation buffer, and
10432
+ //each buffer will handle mutations storms, so multiple buffers
10433
+ //will probably request a full snapshot at (basically) the same time.
10434
+ //we want to ensure all buffers have requested a full snapshot
10435
+ //(so we can be sure that all mutations have been made)
10436
+ //before we actually take a full snapshot.
10437
+ //also, we want a low debounceTime, bc if theres multiple, distinctive mutation storms,
10438
+ //in a somewhat quick succession, we want to record activity between them
10439
+ //not just one full snapshot after all the storms:
10440
+ //[mutation storm] [full snapshot] [mutation storm] [full snapshot]
10441
+ //NOT
10442
+ //[mutation storm] [timeout] [mutation storm] [full snapshot] (in this case, we probably miss all events which fired during the timeout)
10443
+ requestFullSnapshot() {
10444
+ if (this.debounceTimeout) {
10445
+ clearTimeout(this.debounceTimeout);
10446
+ }
10447
+ this.debounceTimeout = setTimeout(() => {
10448
+ this.debounceTimeout = null;
10449
+ this.takeSnapshot();
10450
+ }, this.debounceTime);
10451
+ }
10452
+ takeSnapshot() {
10453
+ if (Date.now() - this.lastFullSnapshot < this.intervalBetweenSnapshots) {
10454
+ debugLog("StormSnapshotManager, takeSnapshot: too soon");
10455
+ return;
10456
+ }
10457
+ debugLog("StormSnapshotManager, takeSnapshot: taking full snapshot");
10458
+ takeFullSnapshot();
10459
+ this.lastFullSnapshot = Date.now();
10460
+ }
10461
+ };
10462
+ __publicField(_StormSnapshotManager, "instance");
10463
+ let StormSnapshotManager = _StormSnapshotManager;
10464
+ const stormSnapshotManager = new StormSnapshotManager();
10442
10465
  function isNodeInLinkedList(n2) {
10443
10466
  return "__ln" in n2;
10444
10467
  }
@@ -10564,7 +10587,7 @@ class MutationBuffer {
10564
10587
  __publicField(this, "canvasManager");
10565
10588
  __publicField(this, "processedNodeManager");
10566
10589
  __publicField(this, "unattachedDoc");
10567
- __publicField(this, "bufId", isDebug() ? makeid() : "");
10590
+ __publicField(this, "bufId", makeid());
10568
10591
  __publicField(this, "stormBatches", []);
10569
10592
  __publicField(this, "stormInfo", null);
10570
10593
  __publicField(this, "stormSettings", {
@@ -10577,6 +10600,7 @@ class MutationBuffer {
10577
10600
  });
10578
10601
  __publicField(this, "debounceStormFinish", () => {
10579
10602
  if (!this.stormInfo) return;
10603
+ if (mutationRateLimiter.isInGlobalStorm()) return;
10580
10604
  this.stormInfo.timeout = setTimeout(
10581
10605
  this.handleStormFinish,
10582
10606
  this.stormSettings.timeout
@@ -10593,9 +10617,9 @@ class MutationBuffer {
10593
10617
  this.stormInfo = {
10594
10618
  startedAt: time,
10595
10619
  totalMutations: 0,
10596
- timeout: setTimeout(this.handleStormFinish, this.stormSettings.timeout),
10597
10620
  stormExceededLimit: false
10598
10621
  };
10622
+ if (canFinishStorm) this.debounceStormFinish();
10599
10623
  }
10600
10624
  this.stormInfo.totalMutations += muts.length;
10601
10625
  if (this.stormInfo.totalMutations >= this.stormSettings.mutationLimit) {
@@ -10616,10 +10640,6 @@ class MutationBuffer {
10616
10640
  });
10617
10641
  __publicField(this, "handleStormFinish", () => {
10618
10642
  if (!this.stormInfo) return;
10619
- if (!mutationRateLimiter.canMutationBufferExitMutationStorm()) {
10620
- this.debounceStormFinish();
10621
- return;
10622
- }
10623
10643
  const { stormExceededLimit } = this.stormInfo;
10624
10644
  debugLog(
10625
10645
  "mutation storm finished",
@@ -10649,7 +10669,7 @@ class MutationBuffer {
10649
10669
  });
10650
10670
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
10651
10671
  if (!overrideStorm) {
10652
- const isStorming = mutationRateLimiter.isStorming(muts.length);
10672
+ const isStorming = mutationRateLimiter.isStorming(muts.length, this);
10653
10673
  if (isStorming) {
10654
10674
  this.handleStormMutations(muts, false);
10655
10675
  return;