@posthog/rrweb-player 0.0.25 → 0.0.26

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.
@@ -11741,6 +11741,11 @@ class Replayer {
11741
11741
  __publicField2(this, "lastSelectionData", null);
11742
11742
  __publicField2(this, "constructedStyleMutations", []);
11743
11743
  __publicField2(this, "adoptedStyleSheets", []);
11744
+ __publicField2(this, "emitterHandlers", []);
11745
+ __publicField2(this, "serviceSubscription");
11746
+ __publicField2(this, "speedServiceSubscription");
11747
+ __publicField2(this, "timeouts", /* @__PURE__ */ new Set());
11748
+ __publicField2(this, "styleSheetLoadListeners", /* @__PURE__ */ new Map());
11744
11749
  __publicField2(this, "handleResize", (dimension) => {
11745
11750
  this.iframe.style.display = "inherit";
11746
11751
  for (const el of [this.mouseTail, this.iframe]) {
@@ -11900,12 +11905,12 @@ class Replayer {
11900
11905
  this.handleResize = this.handleResize.bind(this);
11901
11906
  this.getCastFn = this.getCastFn.bind(this);
11902
11907
  this.applyEventsSynchronously = this.applyEventsSynchronously.bind(this);
11903
- this.emitter.on(ReplayerEvents.Resize, this.handleResize);
11908
+ this.addEmitterHandler(ReplayerEvents.Resize, this.handleResize);
11904
11909
  this.setupDom();
11905
11910
  for (const plugin of this.config.plugins || []) {
11906
11911
  if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
11907
11912
  }
11908
- this.emitter.on(ReplayerEvents.Flush, () => {
11913
+ const flushHandler = () => {
11909
11914
  if (this.usingVirtualDom) {
11910
11915
  const replayerHandler = {
11911
11916
  mirror: this.mirror,
@@ -12001,13 +12006,15 @@ class Replayer {
12001
12006
  this.applySelection(this.lastSelectionData);
12002
12007
  this.lastSelectionData = null;
12003
12008
  }
12004
- });
12005
- this.emitter.on(ReplayerEvents.PlayBack, () => {
12009
+ };
12010
+ this.addEmitterHandler(ReplayerEvents.Flush, flushHandler);
12011
+ const playBackHandler = () => {
12006
12012
  this.firstFullSnapshot = null;
12007
12013
  this.mirror.reset();
12008
12014
  this.styleMirror.reset();
12009
12015
  this.mediaManager.reset();
12010
- });
12016
+ };
12017
+ this.addEmitterHandler(ReplayerEvents.PlayBack, playBackHandler);
12011
12018
  const timer = new Timer([], {
12012
12019
  speed: this.config.speed
12013
12020
  });
@@ -12031,7 +12038,7 @@ class Replayer {
12031
12038
  }
12032
12039
  );
12033
12040
  this.service.start();
12034
- this.service.subscribe((state) => {
12041
+ this.serviceSubscription = this.service.subscribe((state) => {
12035
12042
  this.emitter.emit(ReplayerEvents.StateChange, {
12036
12043
  player: state
12037
12044
  });
@@ -12041,7 +12048,7 @@ class Replayer {
12041
12048
  timer
12042
12049
  });
12043
12050
  this.speedService.start();
12044
- this.speedService.subscribe((state) => {
12051
+ this.speedServiceSubscription = this.speedService.subscribe((state) => {
12045
12052
  this.emitter.emit(ReplayerEvents.StateChange, {
12046
12053
  speed: state
12047
12054
  });
@@ -12061,7 +12068,7 @@ class Replayer {
12061
12068
  );
12062
12069
  if (firstMeta) {
12063
12070
  const { width, height } = firstMeta.data;
12064
- setTimeout(() => {
12071
+ this.addTimeout(() => {
12065
12072
  this.emitter.emit(ReplayerEvents.Resize, {
12066
12073
  width,
12067
12074
  height
@@ -12069,7 +12076,7 @@ class Replayer {
12069
12076
  }, 0);
12070
12077
  }
12071
12078
  if (firstFullsnapshot) {
12072
- setTimeout(() => {
12079
+ this.addTimeout(() => {
12073
12080
  var _a2;
12074
12081
  if (this.firstFullSnapshot) {
12075
12082
  return;
@@ -12098,6 +12105,24 @@ class Replayer {
12098
12105
  this.emitter.off(event, handler);
12099
12106
  return this;
12100
12107
  }
12108
+ /**
12109
+ * Track emitter handlers for cleanup
12110
+ */
12111
+ addEmitterHandler(event, handler) {
12112
+ this.emitter.on(event, handler);
12113
+ this.emitterHandlers.push({ event, handler });
12114
+ }
12115
+ /**
12116
+ * Track timeouts for cleanup
12117
+ */
12118
+ addTimeout(callback, delay) {
12119
+ const timeout = setTimeout(() => {
12120
+ this.timeouts.delete(timeout);
12121
+ callback();
12122
+ }, delay);
12123
+ this.timeouts.add(timeout);
12124
+ return timeout;
12125
+ }
12101
12126
  setConfig(config) {
12102
12127
  Object.keys(config).forEach((key) => {
12103
12128
  config[key];
@@ -12200,10 +12225,31 @@ class Replayer {
12200
12225
  * Memory occupation can be released by removing all references to this replayer.
12201
12226
  */
12202
12227
  destroy() {
12228
+ var _a2, _b2;
12229
+ if (!this.wrapper || !this.wrapper.parentNode) {
12230
+ return;
12231
+ }
12203
12232
  this.pause();
12233
+ this.emitterHandlers.forEach(({ event, handler }) => {
12234
+ this.emitter.off(event, handler);
12235
+ });
12236
+ this.emitterHandlers = [];
12237
+ (_a2 = this.serviceSubscription) == null ? void 0 : _a2.unsubscribe();
12238
+ (_b2 = this.speedServiceSubscription) == null ? void 0 : _b2.unsubscribe();
12239
+ this.serviceSubscription = void 0;
12240
+ this.speedServiceSubscription = void 0;
12241
+ this.timeouts.forEach((timeout) => clearTimeout(timeout));
12242
+ this.timeouts.clear();
12243
+ this.styleSheetLoadListeners.forEach((handler, element2) => {
12244
+ element2.removeEventListener("load", handler);
12245
+ });
12246
+ this.styleSheetLoadListeners.clear();
12247
+ this.imageMap.clear();
12248
+ this.canvasEventMap.clear();
12204
12249
  this.mirror.reset();
12205
12250
  this.styleMirror.reset();
12206
12251
  this.mediaManager.reset();
12252
+ this.resetCache();
12207
12253
  this.config.root.removeChild(this.wrapper);
12208
12254
  this.emitter.emit(ReplayerEvents.Destroy);
12209
12255
  }