@@ -25,24 +25,27 @@ import Webcam from "react-webcam"
2525import GetOutsideVisibilityColor from "../../helpers/outsideVisibility"
2626import {
2727 selectVideoMaximized ,
28+ selectVideoScale ,
2829 selectVideoSource ,
2930 setVideoMaximized ,
31+ setVideoScale ,
3032 setVideoSource ,
3133} from "../../redux/slices/droneConnectionSlice"
3234import VideoWidgetSourceSelectModal from "./videoWidgetSourceSelectModal"
3335
3436export default function VideoWidget ( { telemetryPanelWidth } ) {
3537 const videoSource = useSelector ( selectVideoSource )
3638 const isMaximized = useSelector ( selectVideoMaximized )
39+ const scale = useSelector ( selectVideoScale ) // Scale factor for resizing
3740 const dispatch = useDispatch ( )
3841
3942 const [ error , setError ] = useState ( null )
4043 const [ videoDimensions , setVideoDimensions ] = useState ( {
41- width : 350 ,
42- height : 197 ,
44+ width : 350 * scale ,
45+ height : 197 * scale ,
4346 } ) // Default 16:9 aspect ratio
47+
4448 const [ baseAspectRatio , setBaseAspectRatio ] = useState ( 16 / 9 ) // Track original aspect ratio
45- const [ scale , setScale ] = useState ( 1 ) // Scale factor for resizing
4649 const [ isPoppedOut , setIsPoppedOut ] = useState ( false ) // Track if video is popped out
4750
4851 const [
@@ -61,21 +64,6 @@ export default function VideoWidget({ telemetryPanelWidth }) {
6164 dispatch ( setVideoMaximized ( true ) )
6265 }
6366
64- function updateScale ( newScale ) {
65- const clampedScale = Math . max ( 1 , Math . min ( 3 , newScale ) ) // Clamp between 1x and 3x
66- setScale ( clampedScale )
67-
68- // Recalculate dimensions based on new scale
69- const baseWidth = 350
70- const newWidth = baseWidth * clampedScale
71- const newHeight = Math . round ( newWidth / baseAspectRatio )
72-
73- setVideoDimensions ( {
74- width : newWidth ,
75- height : newHeight ,
76- } )
77- }
78-
7967 function handleResizeStart ( e ) {
8068 const startX = e . clientX
8169 const startScale = scale
@@ -84,7 +72,8 @@ export default function VideoWidget({ telemetryPanelWidth }) {
8472 const deltaX = e . clientX - startX
8573 const scaleChange = deltaX / 200 // Adjust sensitivity
8674 const newScale = startScale + scaleChange
87- updateScale ( newScale )
75+ const clampedScale = Math . max ( 1 , Math . min ( 3 , newScale ) ) // Clamp between 1x and 3x
76+ dispatch ( setVideoScale ( clampedScale ) )
8877 }
8978
9079 const handleMouseUp = ( ) => {
@@ -250,6 +239,18 @@ export default function VideoWidget({ telemetryPanelWidth }) {
250239 }
251240 }
252241
242+ useEffect ( ( ) => {
243+ // Update video dimensions when scale changes
244+ const baseWidth = 350
245+ const newWidth = baseWidth * scale
246+ const newHeight = Math . round ( newWidth / baseAspectRatio )
247+
248+ setVideoDimensions ( {
249+ width : newWidth ,
250+ height : newHeight ,
251+ } )
252+ } , [ scale , baseAspectRatio ] )
253+
253254 useEffect ( ( ) => {
254255 // Listen for video window close events
255256 const handleVideoWindowClose = async ( ) => {
0 commit comments