p-stream/src/components/player/internals/WatchPartyResetter.tsx
Pas fb3bc161ce Merge: Add Watch Party
commit 6034a1ebeaa97a97552dc249f97cc935dcbd1cd6
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 20:02:36 2025 -0600

    update stuff

commit 91d1370668a3e05fed3687ffef697a96c28a0b2c
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 19:47:34 2025 -0600

    Update Downloads.tsx

commit 1c25c88175abebe761d27194f22eec9fd3bcf2e1
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 19:46:27 2025 -0600

    clean some more stuff

commit d6c24e76348c135f3c1ae0444491ff0b302eca2e
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 19:38:07 2025 -0600

    clean this again

commit 6511de68a1b1397e4884dfc6e6f0599497b9afee
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 19:30:08 2025 -0600

    clean up a bit

commit 467358c1f50c1555b42f9ae8d22f955ebc9bba1b
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 17:45:04 2025 -0600

    validate content

commit 59d4a1665b32bdf4ca453859816a2245b184b025
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 17:35:22 2025 -0600

    add auto join link

commit 6f3c334d2157f1c82f9d26e9a7db49371e6a2b5e
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 17:08:35 2025 -0600

    watch partyyyy

commit 1497377692fba86ea1ef40191dbaa648abc38e2e
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 13:56:04 2025 -0600

    add watch party view stuff

commit 80003f78d0adf6071d4f2c6b6a6d8fdcb2aa204a
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 13:14:07 2025 -0600

    init sending webhooks

    testing on a discord hook

commit f5293c2eae5d5a12be6153ab37e50214289e20b6
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 12:31:41 2025 -0600

    remove duplicate class

commit 7871162e6b2c580eb2bcb9c8abc5ecc19d706a06
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 12:25:49 2025 -0600

    update legacy button

commit a2948f3aa1b7481a3ac5b69e2e4dab71552816de
Author: Pas <74743263+Pasithea0@users.noreply.github.com>
Date:   Sat May 17 12:21:52 2025 -0600

    move watchparty to new atoms menu
2025-05-17 20:04:40 -06:00

51 lines
1.4 KiB
TypeScript

import { useEffect, useMemo, useRef } from "react";
import { usePlayerStore } from "@/stores/player/store";
import { useWatchPartyStore } from "@/stores/watchParty";
/**
* Component that detects when the player exits or media changes
* and resets the watch party state
*/
export function WatchPartyResetter() {
const meta = usePlayerStore((s) => s.meta);
const { disable } = useWatchPartyStore();
// Store the current meta to track changes
const previousMetaRef = useRef<string | null>(null);
// Memoize the metaId calculation
const metaId = useMemo(() => {
if (!meta) return null;
return meta.type === "show"
? `${meta.type}-${meta.tmdbId}-s${meta.season?.tmdbId || "0"}-e${meta.episode?.tmdbId || "0"}`
: `${meta.type}-${meta.tmdbId}`;
}, [meta]);
useEffect(() => {
// If meta exists but has changed, reset watch party
if (
metaId &&
previousMetaRef.current &&
metaId !== previousMetaRef.current
) {
// eslint-disable-next-line no-console
console.log("Media changed, disabling watch party:", {
previous: previousMetaRef.current,
current: metaId,
});
disable();
}
// Update the ref with current meta
previousMetaRef.current = metaId;
// Also reset when component unmounts (player exited)
return () => {
disable();
};
}, [metaId, disable]);
return null; // This component doesn't render anything
}