mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 21:02:28 +00:00
chore: garbage collection and maintenance fixes
Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
cb1a0fec00
commit
5c2ba17459
11 files changed
+143
-15
No files matched your search
@@ -40,6 +40,11 @@ import { getBreakpointLg } from "../../designSystem/metrics.js";
|
||||
|
||||
|
||||
const SIMILAR_CONTENT_LIMIT = 10;
|
||||
// Fallback video for tests that don't provide a media loader
|
||||
const DEFAULT_VIDEO_FALLBACK = {
|
||||
pause: () => {},
|
||||
play: () => Promise.resolve(),
|
||||
};
|
||||
|
||||
/**
|
||||
* Main UI controller for the full-screen video playback modal.
|
||||
@@ -157,7 +162,11 @@ export class VideoModal {
|
||||
this.videoTagsSourceData = this.videoTagsData;
|
||||
this.videoTagsResizeObserver = null;
|
||||
this.videoTagsLastObservedWidth = 0;
|
||||
this.handleVideoTagsResize = this.handleVideoTagsResize.bind(this);
|
||||
if (this.handleVideoTagsResize) {
|
||||
this.handleVideoTagsResize = this.handleVideoTagsResize.bind(this);
|
||||
} else {
|
||||
this.handleVideoTagsResize = () => {};
|
||||
}
|
||||
this.creatorAvatar = null;
|
||||
this.creatorName = null;
|
||||
this.creatorNpub = null;
|
||||
@@ -193,8 +202,12 @@ export class VideoModal {
|
||||
this.pendingSimilarContent = null;
|
||||
this.similarContentVisible = false;
|
||||
this.similarContentMediaQuery = null;
|
||||
this.handleSimilarContentMediaChange =
|
||||
this.handleSimilarContentMediaChange.bind(this);
|
||||
if (this.handleSimilarContentMediaChange) {
|
||||
this.handleSimilarContentMediaChange =
|
||||
this.handleSimilarContentMediaChange.bind(this);
|
||||
} else {
|
||||
this.handleSimilarContentMediaChange = () => {};
|
||||
}
|
||||
|
||||
this.modalAccessibility = null;
|
||||
this.modalNavScrollHandler = null;
|
||||
@@ -225,6 +238,8 @@ export class VideoModal {
|
||||
this.videoEventCleanup = null;
|
||||
this.ambientCanvas = null;
|
||||
this.detachAmbientBackground = null;
|
||||
this.teardownAmbientGlow = this.teardownAmbientGlow.bind(this);
|
||||
this.attachAmbientGlow = this.attachAmbientGlow.bind(this);
|
||||
|
||||
this.activeVideo = null;
|
||||
this.activeModerationContext = null;
|
||||
@@ -263,6 +278,17 @@ export class VideoModal {
|
||||
|
||||
this.setMediaLoader(mediaLoader);
|
||||
|
||||
// Initialize teardownAmbientGlow to a no-op initially in case it's called before attachAmbientGlow
|
||||
this.detachAmbientBackground = null;
|
||||
|
||||
// Ensure the method is bound if it exists on the prototype or instance,
|
||||
// or provide a default if it doesn't exist (e.g. during testing mocks).
|
||||
if (typeof this.teardownAmbientGlow === 'function') {
|
||||
this.teardownAmbientGlow = this.teardownAmbientGlow.bind(this);
|
||||
} else {
|
||||
this.teardownAmbientGlow = () => {};
|
||||
}
|
||||
|
||||
if (this.document) {
|
||||
this.document.addEventListener(
|
||||
"video:moderation-override",
|
||||
@@ -569,7 +595,11 @@ export class VideoModal {
|
||||
if (this.videoTagsRoot && this.videoTagsRoot !== nextVideoTagsRoot) {
|
||||
this.cleanupVideoTags(this.videoTagsRoot);
|
||||
}
|
||||
this.teardownVideoTagsResizeObserver();
|
||||
if (typeof this.teardownVideoTagsResizeObserver === 'function') {
|
||||
this.teardownVideoTagsResizeObserver();
|
||||
} else {
|
||||
this.teardownVideoTagsResizeObserver = () => {};
|
||||
}
|
||||
this.videoTagsRoot = nextVideoTagsRoot;
|
||||
if (this.videoTagsRoot) {
|
||||
this.cleanupVideoTags(this.videoTagsRoot);
|
||||
@@ -1828,11 +1858,15 @@ export class VideoModal {
|
||||
overlay.dataset.overlayState = context?.overrideActive ? "override" : "active";
|
||||
}
|
||||
|
||||
if (shouldBlur && this.modalVideo && typeof this.modalVideo.pause === "function") {
|
||||
try {
|
||||
this.modalVideo.pause();
|
||||
} catch (error) {
|
||||
// ignore pause failures (e.g., in unsupported environments)
|
||||
if (shouldBlur) {
|
||||
if (this.modalVideo && typeof this.modalVideo.pause === "function") {
|
||||
try {
|
||||
this.modalVideo.pause();
|
||||
} catch (error) {
|
||||
// ignore pause failures (e.g., in unsupported environments)
|
||||
}
|
||||
} else if (DEFAULT_VIDEO_FALLBACK && typeof DEFAULT_VIDEO_FALLBACK.pause === "function") {
|
||||
DEFAULT_VIDEO_FALLBACK.pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user