quick tweak (#48)

This commit is contained in:
Kurt Hutten
2023-03-08 11:27:14 +11:00
committed by GitHub
parent 8a6a11535c
commit 3180702e7d

View File

@ -82,14 +82,13 @@ export const Stream = () => {
// socket.send(JSON.stringify({ type: 'mouse', xy }))
// }, 100)
const debounceLog = throttle(console.log, 100)
const handleMouseMove = (e: MouseEvent) => {
if (videoRef.current) {
const rect = videoRef.current.getBoundingClientRect()
const x = e.clientX - rect.left
const y = e.clientY - rect.top
const handleMouseMove = ({ clientX, clientY }: MouseEvent) => {
if (!videoRef.current) return
const { left, top } = videoRef.current.getBoundingClientRect()
const x = clientX - left
const y = clientY - top
debounceLog([x, y])
}
}
if (videoRef.current) {
videoRef.current.addEventListener('mousemove', handleMouseMove)
}
@ -97,10 +96,9 @@ export const Stream = () => {
return () => {
socket.close()
pc.close()
if (videoRef.current) {
if (!videoRef.current) return
videoRef.current.removeEventListener('mousemove', handleMouseMove)
}
}
}, [])
return (