Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Best way to show others people cursor on the screen without affecting resources too much

I wonder how some apps can display collaborators’ cursors on the screen and update their position in real time without affecting too much the resource of the client.

I tried to do that with websocket/onmousemove: when I move my mouse I send info to the server which send it to others clients and update my position with JS/CSS on their screen.

Is there a better solution?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Regards,

>Solution :

What you can do to get better performance would probably be to send / receive fewer packets, and calculate most of the mouse movement.

I mean, instead of sending every mouse move, you could send them once in a while (like 500ms), and then on the client receiving those moves, animate the cursor to the new position with an animation duration of the same length (500ms in this example).

In order to do so, in your onmousemove event you can use a global variable, like lastPacketTime, if the current timestamp Date.now() is below lastPacketTime + 500ms, return. Otherwise, send the packet, and update lastPacketTime

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading