@posthog/rrweb-player 0.0.25 → 0.0.27

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