-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add screen capture in frontend
- Loading branch information
Showing
10 changed files
with
378 additions
and
63 deletions.
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,37 @@ | ||
/* eslint-disable */ | ||
import { Tabs } from '@chakra-ui/react' | ||
import { FiCamera, FiMonitor } from 'react-icons/fi' | ||
import { sidebarStyles } from './sidebar-styles' | ||
import CameraPanel from './camera-panel' | ||
import ScreenPanel from './screen-panel' | ||
|
||
function BottomTab(): JSX.Element { | ||
return ( | ||
<Tabs.Root | ||
defaultValue="camera" | ||
variant="plain" | ||
{...sidebarStyles.bottomTab.container} | ||
> | ||
<Tabs.List {...sidebarStyles.bottomTab.list}> | ||
<Tabs.Trigger value="camera" {...sidebarStyles.bottomTab.trigger}> | ||
<FiCamera /> | ||
Camera | ||
</Tabs.Trigger> | ||
<Tabs.Trigger value="screen" {...sidebarStyles.bottomTab.trigger}> | ||
<FiMonitor /> | ||
Screen | ||
</Tabs.Trigger> | ||
</Tabs.List> | ||
|
||
<Tabs.Content value="camera"> | ||
<CameraPanel /> | ||
</Tabs.Content> | ||
|
||
<Tabs.Content value="screen"> | ||
<ScreenPanel /> | ||
</Tabs.Content> | ||
</Tabs.Root> | ||
); | ||
} | ||
|
||
export default BottomTab |
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,113 @@ | ||
/* eslint-disable */ | ||
import { Box, Text } from "@chakra-ui/react"; | ||
import { FiMonitor } from "react-icons/fi"; | ||
import { Tooltip } from "@/components/ui/tooltip"; | ||
import { sidebarStyles } from "./sidebar-styles"; | ||
import { useCaptureScreen } from "@/hooks/sidebar/use-capture-screen"; | ||
|
||
// Reusable components | ||
function ScreenIndicator() { | ||
return ( | ||
<Box color="red.500" display="flex" alignItems="center" gap={2}> | ||
<Box | ||
w="8px" | ||
h="8px" | ||
borderRadius="full" | ||
bg="red.500" | ||
animation="pulse 2s infinite" | ||
/> | ||
<Text fontSize="sm">Screen</Text> | ||
</Box> | ||
); | ||
} | ||
|
||
function ScreenPlaceholder() { | ||
return ( | ||
<Box | ||
position="absolute" | ||
display="flex" | ||
flexDirection="column" | ||
alignItems="center" | ||
gap={2} | ||
> | ||
<FiMonitor size={24} /> | ||
<Text color="whiteAlpha.600" fontSize="sm" textAlign="center"> | ||
Click to start screen capture | ||
</Text> | ||
</Box> | ||
); | ||
} | ||
|
||
function VideoStream({ | ||
videoRef, | ||
isStreaming, | ||
}: { | ||
videoRef: React.RefObject<HTMLVideoElement>; | ||
isStreaming: boolean; | ||
}) { | ||
return ( | ||
<video | ||
ref={videoRef} | ||
autoPlay | ||
playsInline | ||
muted | ||
style={sidebarStyles.screenPanel.video} | ||
{...(isStreaming ? {} : { display: "none" })} | ||
/> | ||
); | ||
} | ||
|
||
function ScreenPanel(): JSX.Element { | ||
const { | ||
videoRef, | ||
error, | ||
isHovering, | ||
isStreaming, | ||
toggleCapture, | ||
handleMouseEnter, | ||
handleMouseLeave, | ||
} = useCaptureScreen(); | ||
|
||
return ( | ||
<Box {...sidebarStyles.screenPanel.container}> | ||
<Box {...sidebarStyles.screenPanel.header}> | ||
{isStreaming && <ScreenIndicator />} | ||
</Box> | ||
|
||
<Tooltip | ||
showArrow | ||
content={ | ||
isStreaming | ||
? "Click to stop screen capture" | ||
: "Click to start screen capture" | ||
} | ||
open={isHovering && !error} | ||
> | ||
<Box | ||
{...sidebarStyles.screenPanel.screenContainer} | ||
onClick={toggleCapture} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
cursor="pointer" | ||
position="relative" | ||
_hover={{ | ||
bg: "whiteAlpha.100", | ||
}} | ||
> | ||
{error ? ( | ||
<Text color="red.300" fontSize="sm" textAlign="center"> | ||
{error} | ||
</Text> | ||
) : ( | ||
<> | ||
<VideoStream videoRef={videoRef} isStreaming={isStreaming} /> | ||
{!isStreaming && <ScreenPlaceholder />} | ||
</> | ||
)} | ||
</Box> | ||
</Tooltip> | ||
</Box> | ||
); | ||
} | ||
|
||
export default ScreenPanel; |
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
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
Oops, something went wrong.