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