Ensure video stream correctly scales to window container size
Summary
Added a window resize event listener in use-container-size to properly track dimensions. The resize observer alone doesn't trigger accurately on initial render when children elements like videos or canvases are styled with relative dimensions (100%).
Closes:#6843
How to test
- Start the application backend and frontend.
- In the UI, set up an IP camera or video input source.
- Select a model, start the pipeline, and start the stream.
- Observe the inference on the running source. The stream video should immediately scale correctly to fill the available window area without needing a page refresh (F5).
- Resize your browser window. The video feed should react seamlessly and adjust to the new window dimension immediately.
Checklist
- [x] The PR title and description are clear and descriptive
- [x] I have manually tested the changes
- [x] All changes are covered by automated tests
- [x] All related issues are linked to this PR (if applicable)
- [ ] Documentation has been updated (if applicable)
@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use
const updateSizeFromVideo = (video: HTMLVideoElement) => {
const { videoWidth, videoHeight } = video;
if (videoWidth && videoHeight) {
setVideoSize((prev) =>
prev.width === videoWidth && prev.height === videoHeight
? prev
: { width: videoWidth, height: videoHeight }
);
}
};
and add this to the onResize
@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use
const updateSizeFromVideo = (video: HTMLVideoElement) => { const { videoWidth, videoHeight } = video; if (videoWidth && videoHeight) { setVideoSize((prev) => prev.width === videoWidth && prev.height === videoHeight ? prev : { width: videoWidth, height: videoHeight } ); } };and add this to the onResize
Thank you for the suggestion will work on it and will revert
@andersendsa instead of changing the zoom which affects everything else, we should target the video stream instead. On stream.tsx you can leverage video's "onResize" method to accomplish this. You can for instance use
const updateSizeFromVideo = (video: HTMLVideoElement) => { const { videoWidth, videoHeight } = video; if (videoWidth && videoHeight) { setVideoSize((prev) => prev.width === videoWidth && prev.height === videoHeight ? prev : { width: videoWidth, height: videoHeight } ); } };and add this to the onResize
Hi @jpggvilaca i have implemented the changes the pr is ready for review
Hi @jpggvilaca could you pls let me know if this pr needs any changes or if it is good to merge