Skip to content

Commit

Permalink
fixing video cam different width values
Browse files Browse the repository at this point in the history
  • Loading branch information
imrany committed Oct 15, 2024
1 parent f5d4212 commit d06e941
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

.App-header {
background-color: #252525;
min-height: 100vh;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import { GlobalContext } from "./context";
export default function App(){
const API_URL=`http://127.0.0.1:5000`
const [videoConstraints, setVideoConstraints]=useState<any>({
/*width: 1280,*/
width: screen.width-400,
height: 720,
facingMode: "user"
})

window.onresize=function(){
screen.width>1080?"":setVideoConstraints({height:720, facingMode:"environment"})
screen.width>1080?"":setVideoConstraints({height:screen.height, width:screen.width, facingMode:"environment"})
}

useEffect(()=>{
screen.width>1080?"":setVideoConstraints({height:720, facingMode:"environment"})
screen.width>1080?"":setVideoConstraints({height:screen.height, width:screen.width, facingMode:"environment"})
},[screen.width])
return(
<BrowserRouter>
Expand Down
6 changes: 3 additions & 3 deletions src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { createContext } from 'react'
type ContextType={
videoConstraints:{
height?:number,
weigth?:number,
width?:number,
facingMode:string
},
API_URL:string
}

export const GlobalContext=createContext<ContextType>({
videoConstraints:{
/*width: 1280,*/
height: 720,
width: screen.width-400,
height: screen.height,
facingMode: "user"
},
API_URL:""
Expand Down
27 changes: 13 additions & 14 deletions src/pages/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function MainPage() {
webcamRef.current.video.readyState === 4
) {
// Get Video Properties
const video:any = webcamRef.current.video;
const video:any = webcamRef.current.video;
const videoWidth = webcamRef.current.video.videoWidth;
const videoHeight = webcamRef.current.video.videoHeight;

Expand All @@ -60,12 +60,12 @@ export default function MainPage() {
},[]);

return (
<>
{isLoading&&isLoading?(
<div style={{display:"flex",justifyContent:"center", background:"#252525", alignItems:"center", height:"100vh"}}>
<p style={{fontSize:14, color:"white"}}>Loading, please wait...</p>
</div>
):(
<>
{isLoading&&isLoading?(
<div style={{display:"flex",justifyContent:"center", background:"#252525", alignItems:"center", height:"100vh"}}>
<p style={{fontSize:14, color:"white", textAlign:"center"}}>Loading, please wait...</p>
</div>
):(
<div className="App">
<header className="App-header">
<Webcam
Expand All @@ -78,11 +78,10 @@ export default function MainPage() {
left: 0,
right: 0,
textAlign: "center",
zIndex: 9,
width: "100vw",
height: "100vh",
zIndex: 9
}}
height={720}
height={videoConstraints.height}
width={videoConstraints.width}
videoConstraints={videoConstraints}
/>

Expand All @@ -95,10 +94,10 @@ export default function MainPage() {
left: 0,
right: 0,
textAlign: "center",
zIndex: 10,
width: "100vw",
height: "100vh",
zIndex: 10
}}
height={videoConstraints.height}
width={videoConstraints.width}
/>
</header>
</div>
Expand Down

0 comments on commit d06e941

Please sign in to comment.