I want to add zoom-in/zoom-out logic for my web camera, with this version it works only via input onChange, but I need to remove the input…do you have a suggestion on how can I make it without input? It doesn’t work not in useEffect and not even on button onClick.
const handleZoomChange = useCallback(
async (zoomValue: number) => {
// @ts-ignore
const video = ref.current;
if (video && video.srcObject) {
const videoTracks = video.srcObject.getVideoTracks();
if (videoTracks.length > 0) {
const track = videoTracks[0];
const constraints = { advanced: [{ zoom: zoomValue }] };
try {
await track.applyConstraints(constraints);
} catch (error) {
console.error('Failed to apply constraints:', error);
}
}
}
},
[ref]
);
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setInputZoom(value);
if (value !== '') {
const zoomValue = Math.max(1, Number(value));
handleZoomChange(zoomValue);
}
};
<input
type="number"
min={1}
value={inputZoom}
onChange={handleInputChange}
/>
New contributor
Emili is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.