mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
fix(embed): implement robust EmbedPlayerModal and guard resetTorrentStats
- Add `js/ui/components/EmbedPlayerModal.js` to implement the `VideoModal` interface for embed contexts (including `resetStats`). - Update `js/ui/ModalManager.js` to detect embed mode and use `EmbedPlayerModal`. - Clean up `js/embed.js` to remove local modal definition and add `postMessage` diagnostic logging. - Update `js/app.js` `resetTorrentStats` log message and verify guard. - Add unit tests for `EmbedPlayerModal` and `resetTorrentStats` logic. - Add E2E reproduction script `tests/e2e/repro_issue.spec.ts`.
This commit is contained in:
1 parent
d71d2812f4
commit
981fac785a
7 files changed
+379
-117
No files matched your search
@@ -0,0 +1,106 @@
|
||||
export class EmbedPlayerModal {
|
||||
constructor({ document: doc, logger } = {}) {
|
||||
this.document = doc || (typeof document !== "undefined" ? document : null);
|
||||
this.logger = logger || console;
|
||||
this.root = null;
|
||||
this.video = null;
|
||||
this.status = null;
|
||||
this.eventTarget = new EventTarget();
|
||||
|
||||
this.toneClasses = {
|
||||
default: "text-muted",
|
||||
error: "text-danger",
|
||||
success: "text-success",
|
||||
};
|
||||
}
|
||||
|
||||
load() {
|
||||
if (this.document) {
|
||||
this.root = this.document.getElementById("embedRoot");
|
||||
this.video = this.document.getElementById("embedVideo");
|
||||
this.status = this.document.getElementById("embedStatus");
|
||||
}
|
||||
return Promise.resolve(this.root);
|
||||
}
|
||||
|
||||
getRoot() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
getVideoElement() {
|
||||
return this.video;
|
||||
}
|
||||
|
||||
setVideoElement(videoElement) {
|
||||
if (videoElement) {
|
||||
this.video = videoElement;
|
||||
}
|
||||
return this.video;
|
||||
}
|
||||
|
||||
resetStats() {
|
||||
// no-op for embed view
|
||||
}
|
||||
|
||||
setStatus(message, tone = "default") {
|
||||
if (!this.status) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedMessage = typeof message === "string" ? message.trim() : "";
|
||||
this.status.textContent = normalizedMessage;
|
||||
|
||||
Object.values(this.toneClasses).forEach((className) => {
|
||||
if (className) {
|
||||
this.status.classList.remove(className);
|
||||
}
|
||||
});
|
||||
|
||||
const toneClass = this.toneClasses[tone] || this.toneClasses.default;
|
||||
if (toneClass) {
|
||||
this.status.classList.add(toneClass);
|
||||
}
|
||||
}
|
||||
|
||||
updateStatus(message) {
|
||||
this.setStatus(message, "default");
|
||||
}
|
||||
|
||||
applyLoadingPoster() {
|
||||
this.setStatus("Preparing playback…", "default");
|
||||
}
|
||||
|
||||
forceRemovePoster() {
|
||||
return false;
|
||||
}
|
||||
|
||||
clearPosterCleanup() {}
|
||||
|
||||
setTorrentStatsVisibility(isVisible) {
|
||||
if (!this.root) {
|
||||
return;
|
||||
}
|
||||
this.root.dataset.torrentStats = isVisible ? "true" : "false";
|
||||
}
|
||||
|
||||
open() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
close() {}
|
||||
|
||||
updateMetadata() {}
|
||||
setShareEnabled() {}
|
||||
|
||||
addEventListener(type, listener, options) {
|
||||
this.eventTarget.addEventListener(type, listener, options);
|
||||
}
|
||||
|
||||
removeEventListener(type, listener, options) {
|
||||
this.eventTarget.removeEventListener(type, listener, options);
|
||||
}
|
||||
|
||||
dispatch(type, detail) {
|
||||
return this.eventTarget.dispatchEvent(new CustomEvent(type, { detail }));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user