Skip to content

Commit

Permalink
Adds watermark and disable context menu access in camera feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed May 23, 2024
1 parent a9530a9 commit c615480
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Components/CameraFeed/CameraFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FeedNetworkSignal from "./FeedNetworkSignal";
import NoFeedAvailable from "./NoFeedAvailable";
import FeedControls from "./FeedControls";
import Fullscreen from "../../CAREUI/misc/Fullscreen";
import FeedWatermark from "./FeedWatermark";

interface Props {
children?: React.ReactNode;
Expand Down Expand Up @@ -87,6 +88,8 @@ export default function CameraFeed(props: Props) {
initializeStream();
};

console.log({ isIOS });

return (
<Fullscreen fullscreen={isFullscreen} onExit={() => setFullscreen(false)}>
<div
Expand Down Expand Up @@ -115,6 +118,7 @@ export default function CameraFeed(props: Props) {
<div className="group relative aspect-video">
{/* Notifications */}
<FeedAlert state={state} />
{player.status === "playing" && <FeedWatermark />}

{/* No Feed informations */}
{state === "host_unreachable" && (
Expand Down Expand Up @@ -145,6 +149,7 @@ export default function CameraFeed(props: Props) {
url={streamUrl}
ref={playerRef.current as LegacyRef<ReactPlayer>}
controls={false}
pip={false}
playsinline
playing
muted
Expand All @@ -162,10 +167,12 @@ export default function CameraFeed(props: Props) {
</div>
) : (
<video
onContextMenu={(e) => e.preventDefault()}
className="absolute inset-0 w-full"
id="mse-video"
autoPlay
muted
disablePictureInPicture
playsInline
onPlay={player.onPlayCB}
onEnded={() => player.setStatus("stop")}
Expand Down
55 changes: 55 additions & 0 deletions src/Components/CameraFeed/FeedWatermark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useEffect, useRef } from "react";
import useAuthUser from "../../Common/hooks/useAuthUser";

export default function FeedWatermark() {
const me = useAuthUser();
return (
<>
<Watermark className="left-1/3 top-1/3 -translate-x-1/2 -translate-y-1/2">
{me.username}
</Watermark>
<Watermark className="right-1/3 top-1/3 -translate-y-1/2 translate-x-1/2">
{me.username}
</Watermark>
<Watermark className="bottom-1/3 left-1/3 -translate-x-1/2 translate-y-1/2">
{me.username}
</Watermark>
<Watermark className="bottom-1/3 right-1/3 translate-x-1/2 translate-y-1/2">
{me.username}
</Watermark>
</>
);
}

const Watermark = (props: { children: string; className: string }) => {
const ref = useRef<HTMLSpanElement>(null);
const parentRef = useRef<HTMLElement | null>(null);

// This adds the element back if the element was removed from the DOM
useEffect(() => {
parentRef.current = ref.current?.parentElement || null;
let animationFrameId: number;

const checkWatermark = () => {
const watermark = ref.current;
const parent = parentRef.current;
if (watermark && parent && !parent.contains(watermark)) {
parent.appendChild(watermark);
}
animationFrameId = requestAnimationFrame(checkWatermark);
};

animationFrameId = requestAnimationFrame(checkWatermark);

return () => cancelAnimationFrame(animationFrameId);
}, []);

return (
<span
ref={ref}
className={`absolute z-10 text-2xl font-bold text-white/30 ${props.className}`}
>
{props.children}
</span>
);
};

0 comments on commit c615480

Please sign in to comment.