@ -77,17 +77,15 @@ export const Stream = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO instead of logging, send use `socket` to send to server, maybe something like?:
|
const debounceSocketSend = throttle((message) => {
|
||||||
// const debounceLog = throttle((xy) => {
|
socket.send(JSON.stringify(message))
|
||||||
// socket.send(JSON.stringify({ type: 'mouse', xy }))
|
}, 100)
|
||||||
// }, 100)
|
|
||||||
const debounceLog = throttle(console.log, 100)
|
|
||||||
const handleMouseMove = ({ clientX, clientY }: MouseEvent) => {
|
const handleMouseMove = ({ clientX, clientY }: MouseEvent) => {
|
||||||
if (!videoRef.current) return
|
if (!videoRef.current) return
|
||||||
const { left, top } = videoRef.current.getBoundingClientRect()
|
const { left, top } = videoRef.current.getBoundingClientRect()
|
||||||
const x = clientX - left
|
const x = clientX - left
|
||||||
const y = clientY - top
|
const y = clientY - top
|
||||||
debounceLog([x, y])
|
debounceSocketSend({ type: 'MouseMove', x: x, y: y })
|
||||||
}
|
}
|
||||||
if (videoRef.current) {
|
if (videoRef.current) {
|
||||||
videoRef.current.addEventListener('mousemove', handleMouseMove)
|
videoRef.current.addEventListener('mousemove', handleMouseMove)
|
||||||
|
Reference in New Issue
Block a user