mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-11 06:10:52 +00:00
Refactor XPrime ad injection so it loads when the source changes
This commit is contained in:
parent
d4ef4f6c6b
commit
233e601f19
2 changed files with 39 additions and 23 deletions
|
|
@ -7,13 +7,18 @@ import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { usePreferencesStore } from "@/stores/preferences";
|
import { usePreferencesStore } from "@/stores/preferences";
|
||||||
|
|
||||||
export function XPrimeAdOverlay() {
|
export function XPrimeAdOverlay() {
|
||||||
const sourceId = usePlayerStore((s) => s.sourceId);
|
const { sourceId, status } = usePlayerStore((s) => ({
|
||||||
const status = usePlayerStore((s) => s.status);
|
sourceId: s.sourceId,
|
||||||
|
status: s.status,
|
||||||
|
}));
|
||||||
const disableXPrimeAds = usePreferencesStore((s) => s.disableXPrimeAds);
|
const disableXPrimeAds = usePreferencesStore((s) => s.disableXPrimeAds);
|
||||||
const [show, setShow] = useState(false);
|
const [show, setShow] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sourceId === "xprime" && status === "playing" && !disableXPrimeAds) {
|
// Only show overlay when all conditions are met
|
||||||
|
const shouldShow =
|
||||||
|
sourceId === "xprimetv" && status === "playing" && !disableXPrimeAds;
|
||||||
|
if (shouldShow && !show) {
|
||||||
setShow(true);
|
setShow(true);
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setShow(false);
|
setShow(false);
|
||||||
|
|
@ -21,8 +26,10 @@ export function XPrimeAdOverlay() {
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
setShow(false);
|
if (!shouldShow && show) {
|
||||||
}, [sourceId, status, disableXPrimeAds]);
|
setShow(false);
|
||||||
|
}
|
||||||
|
}, [sourceId, status, disableXPrimeAds, show]);
|
||||||
|
|
||||||
if (!show) {
|
if (!show) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
import fscreen from "fscreen";
|
import fscreen from "fscreen";
|
||||||
import Hls, { Level } from "hls.js";
|
import Hls, { Level } from "hls.js";
|
||||||
|
|
||||||
|
|
@ -105,6 +106,27 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
||||||
(value: void | PromiseLike<void>) => void
|
(value: void | PromiseLike<void>) => void
|
||||||
>();
|
>();
|
||||||
|
|
||||||
|
function injectXPrimeAd(sourceId?: string | null) {
|
||||||
|
const currentSourceId = sourceId ?? usePlayerStore.getState().sourceId;
|
||||||
|
console.log("currentSourceId", currentSourceId);
|
||||||
|
const disableXPrimeAds = usePreferencesStore.getState().disableXPrimeAds;
|
||||||
|
if (
|
||||||
|
currentSourceId === "xprimetv" &&
|
||||||
|
!disableXPrimeAds &&
|
||||||
|
!document.querySelector(
|
||||||
|
'script[data-cfasync="false"][src*="jg.prisagedibbuk.com"]',
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
console.log("injecting XPrime ad");
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.setAttribute("data-cfasync", "false");
|
||||||
|
script.async = true;
|
||||||
|
script.type = "text/javascript";
|
||||||
|
script.src = "//jg.prisagedibbuk.com/r47OViiCQMeGnyQ/131974";
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function reportLevels() {
|
function reportLevels() {
|
||||||
if (!hls) return;
|
if (!hls) return;
|
||||||
const levels = hls.levels;
|
const levels = hls.levels;
|
||||||
|
|
@ -356,6 +378,7 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
||||||
videoElement.addEventListener("play", () => {
|
videoElement.addEventListener("play", () => {
|
||||||
emit("play", undefined);
|
emit("play", undefined);
|
||||||
emit("loading", false);
|
emit("loading", false);
|
||||||
|
injectXPrimeAd();
|
||||||
});
|
});
|
||||||
videoElement.addEventListener("error", () => {
|
videoElement.addEventListener("error", () => {
|
||||||
const err = videoElement?.error ?? null;
|
const err = videoElement?.error ?? null;
|
||||||
|
|
@ -383,24 +406,6 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject popup ad for xprime sources
|
|
||||||
const sourceId = usePlayerStore.getState().sourceId;
|
|
||||||
const disableXPrimeAds = usePreferencesStore.getState().disableXPrimeAds;
|
|
||||||
if (
|
|
||||||
sourceId === "xprime" &&
|
|
||||||
!disableXPrimeAds &&
|
|
||||||
!document.querySelector(
|
|
||||||
'script[data-cfasync="false"][src*="jg.prisagedibbuk.com"]',
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
const script = document.createElement("script");
|
|
||||||
script.setAttribute("data-cfasync", "false");
|
|
||||||
script.async = true;
|
|
||||||
script.type = "text/javascript";
|
|
||||||
script.src = "//jg.prisagedibbuk.com/r47OViiCQMeGnyQ/131974";
|
|
||||||
document.head.appendChild(script);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
videoElement.addEventListener("waiting", () => emit("loading", true));
|
videoElement.addEventListener("waiting", () => emit("loading", true));
|
||||||
videoElement.addEventListener("volumechange", () =>
|
videoElement.addEventListener("volumechange", () =>
|
||||||
|
|
@ -578,6 +583,10 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
||||||
// Set autoplay flag if starting from beginning (indicates autoplay transition)
|
// Set autoplay flag if starting from beginning (indicates autoplay transition)
|
||||||
shouldAutoplayAfterLoad = ops.startAt === 0;
|
shouldAutoplayAfterLoad = ops.startAt === 0;
|
||||||
setSource();
|
setSource();
|
||||||
|
// Inject ads after source change if conditions are met
|
||||||
|
if (ops.source) {
|
||||||
|
injectXPrimeAd();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
changeQuality(newAutomaticQuality, newPreferredQuality) {
|
changeQuality(newAutomaticQuality, newPreferredQuality) {
|
||||||
if (source?.type !== "hls") return;
|
if (source?.type !== "hls") return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue