jtanadi / scotty

WebSocket-enabled PDF viewer
http://raa-scotty.herokuapp.com/
MIT License
15 stars 1 forks source link

Improve pointer sync #44

Closed jtanadi closed 4 years ago

jtanadi commented 4 years ago

Problem

When sending pointer info through ws, scotty currently sends pixel coordinates (window.clientX, window.clientY), but those values may be out of range for other clients.

Fix

Instead of sending absolute coordinates, send relative coordinates (like a percentage).

If one client sends something like:

{
  x: roundTo2(window.clientX / window.innerWidth),  // 0.42 
  y: roundTo2(window.clientY / window.innerHeight)  // 0.73
}

then other clients can consume that data like:

// example coordinates in px
const pointerX = window.innerWidth(mouseData.x)   // 853px
const pointerY = window.innerHeight(mouseData.y)  // 571px