Fixed Moveable

This commit is contained in:
James Ketr 2025-09-14 14:47:05 -07:00
parent a65f46a818
commit 18a31704e8
2 changed files with 201 additions and 167 deletions

View File

@ -7,6 +7,13 @@
opacity: 1; opacity: 1;
} }
.MediaControlContainer {
position: relative; /* CRITICAL: This creates the positioning context */
display: inline-block;
width: max-content; /* Ensure container sizes to content */
height: max-content;
}
.MediaControlSpacer { .MediaControlSpacer {
display: flex; display: flex;
position: relative; position: relative;
@ -30,25 +37,34 @@
.MediaControl { .MediaControl {
display: flex; display: flex;
position: absolute; position: absolute; /* Out of flow */
align-items: center; top: 0; /* Start at top of container */
left: 0; /* Start at left of container */
width: 5rem; width: 5rem;
height: 3.75rem; height: 3.75rem;
min-width: 5rem; min-width: 5rem;
min-height: 3.75rem; min-height: 3.75rem;
z-index: 50000; z-index: 50000;
border-radius: 0.25rem; border-radius: 0.25rem;
border: 1px solid green;
} }
.MediaControl .Video { .MediaControl .Video {
position: relative; display: flex;
width: 100%; width: 100%;
height: 100%; height: 100%;
position: relative;
top: 0;
left: 0;
background-color: #444; background-color: #444;
border-radius: 0.25rem; border-radius: 0.25rem;
border: 1px solid black; border: 1px solid black;
} }
video {
border: 5px solid purple;
}
.MediaControl.Medium { .MediaControl.Medium {
width: 11.5em; width: 11.5em;
height: 8.625em; height: 8.625em;
@ -56,37 +72,25 @@
min-height: 8.625em; min-height: 8.625em;
} }
.MediaControl > div {
display: flex;
position: absolute;
top: 0;
left: 0;
display: flex;
flex-direction: column;
align-items: center;
margin-right: 0.25rem;
}
.MediaControl .Controls { .MediaControl .Controls {
display: flex; display: flex;
position: absolute; position: absolute;
left: 0.5em; gap: 0;
bottom: 0.5em; left: 0;
justify-content: flex-end; bottom: 0;
flex-direction: column;
z-index: 1; z-index: 1;
align-items: center;
justify-content: center
} }
.MediaControl.Small .Controls { .MediaControl.Small .Controls {
left: 0;
bottom: unset;
justify-content: center; justify-content: center;
} }
.MediaControl .Controls > div { .MediaControl .Controls > div {
display: flex;
border-radius: 0.25em; border-radius: 0.25em;
cursor: pointer; cursor: pointer;
padding: 0.25em;
} }
.MediaControl .Controls > div:hover { .MediaControl .Controls > div:hover {

View File

@ -1308,6 +1308,7 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
width?: number; width?: number;
height?: number; height?: number;
}>({ translate: [0, 0] }); }>({ translate: [0, 0] });
const containerRef = useRef<HTMLDivElement>(null);
const targetRef = useRef<HTMLDivElement>(null); const targetRef = useRef<HTMLDivElement>(null);
const spacerRef = useRef<HTMLDivElement>(null); const spacerRef = useRef<HTMLDivElement>(null);
const moveableRef = useRef<any>(null); const moveableRef = useRef<any>(null);
@ -1319,6 +1320,15 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
setVideoOn(peer.video_on); setVideoOn(peer.video_on);
}, [peer]); }, [peer]);
// Initialize size to match spacer
useEffect(() => {
if (spacerRef.current && targetRef.current && !frame.width) {
const spacerRect = spacerRef.current.getBoundingClientRect();
targetRef.current.style.width = `${spacerRect.width}px`;
targetRef.current.style.height = `${spacerRect.height}px`;
}
}, [frame.width]);
useEffect(() => { useEffect(() => {
if (!peer || peer.dead || !peer.attributes?.srcObject) { if (!peer || peer.dead || !peer.attributes?.srcObject) {
console.log( console.log(
@ -1457,13 +1467,30 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
const colorVideo = isValid ? "primary" : "disabled"; const colorVideo = isValid ? "primary" : "disabled";
return ( return (
<div className="MediaControlContainer"> <Box
{/* Drop target / spacer that stays in place */} sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
minWidth: "200px",
minHeight: "100px",
}}
>
<div
ref={containerRef}
className="MediaControlContainer"
style={{
position: "relative", // Ensure this is set inline too
width: "max-content",
height: "max-content",
}}
>
{/* Drop target spacer */}
<div <div
ref={spacerRef} ref={spacerRef}
className={`MediaControlSpacer ${className}`} className={`MediaControlSpacer ${className}`}
style={{ style={{
opacity: isDragging ? 1 : 0.3, // Make more visible when dragging opacity: isDragging ? 1 : 0.3,
transition: "opacity 0.2s", transition: "opacity 0.2s",
}} }}
> >
@ -1476,6 +1503,7 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
transform: "translate(-50%, -50%)", transform: "translate(-50%, -50%)",
fontSize: "0.7em", fontSize: "0.7em",
color: "#888", color: "#888",
pointerEvents: "none",
}} }}
> >
Drop here Drop here
@ -1483,36 +1511,36 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
)} )}
</div> </div>
{/* Moveable element - now absolute positioned */} {/* Moveable element - positioned absolute relative to container */}
<div <div
ref={targetRef} ref={targetRef}
className={`MediaControl ${className}`} className={`MediaControl ${className}`}
data-peer={peer.session_id} data-peer={peer.session_id}
style={{ style={{
left: "0px", position: "absolute", // Ensure this is set
top: "0px", top: "0px",
left: "0px",
width: frame.width ? `${frame.width}px` : undefined, width: frame.width ? `${frame.width}px` : undefined,
height: frame.height ? `${frame.height}px` : undefined, height: frame.height ? `${frame.height}px` : undefined,
transform: `translate(${frame.translate[0]}px, ${frame.translate[1]}px)`, transform: `translate(${frame.translate[0]}px, ${frame.translate[1]}px)`,
}} }}
> >
<div className="Controls"> <Box className="Controls">
{isSelf ? ( {isSelf ? (
<div onTouchStart={toggleMute} onClick={toggleMute}> // onTouchStart={toggleMute}
{muted ? <MicOff color={colorAudio} /> : <Mic color={colorAudio} />} <div onClick={toggleMute}>{muted ? <MicOff color={colorAudio} /> : <Mic color={colorAudio} />}</div>
</div>
) : ( ) : (
<div onTouchStart={toggleMute} onClick={toggleMute}> <div onClick={toggleMute}>
{muted ? <VolumeOff color={colorAudio} /> : <VolumeUp color={colorAudio} />} {muted ? <VolumeOff color={colorAudio} /> : <VolumeUp color={colorAudio} />}
</div> </div>
)} )}
<div onTouchStart={toggleVideo} onClick={toggleVideo}> <div onClick={toggleVideo}>
{videoOn ? <Videocam color={colorVideo} /> : <VideocamOff color={colorVideo} />} {videoOn ? <Videocam color={colorVideo} /> : <VideocamOff color={colorVideo} />}
</div> </div>
</div> </Box>
{isValid ? ( {isValid ? (
peer.attributes?.srcObject && ( peer.attributes?.srcObject && (
<Box sx={{ position: "relative" }}> <>
<Video <Video
key={`video-${peer.session_id}-${peer.attributes.srcObject.id}`} key={`video-${peer.session_id}-${peer.attributes.srcObject.id}`}
className="Video" className="Video"
@ -1523,19 +1551,20 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
muted={peer.local || muted} muted={peer.local || muted}
/> />
<WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} /> <WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} />
</Box> </>
) )
) : ( ) : (
<Box sx={{ position: "relative" }}> <>
<div className="Video">Waiting for media</div> <div className="Video">Waiting for media</div>
<WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} /> <WebRTCStatus isNegotiating={peer.isNegotiating || false} connectionState={peer.connectionState} />
</Box> </>
)} )}
</div> </div>
<Moveable <Moveable
ref={moveableRef} ref={moveableRef}
flushSync={flushSync} flushSync={flushSync}
container={containerRef.current} // Constrain to container if needed
pinchable={true} pinchable={true}
draggable={true} draggable={true}
target={targetRef.current} target={targetRef.current}
@ -1622,6 +1651,7 @@ const MediaControl: React.FC<MediaControlProps> = ({ isSelf, peer, className })
}} }}
/> />
</div> </div>
</Box>
); );
}; };