-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds watermark to Camera Feed and disables access to context menu. (#…
…7885) * Adds watermark and disable context menu access in camera feed * Update src/Components/CameraFeed/CameraFeed.tsx
- Loading branch information
1 parent
828cd50
commit 3e12e19
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |