Use Websockets if it's just two people.
edit: This is server-mediated. For true P2P you could use WebRTC.
how do you get websockets to work p2p? afaik websockets needs a dedicated server to relay messages.
WebRTC will also require having TURN servers to relay messages if you want to be compatible with everyone on internet. True P2P is pretty much impossible in a way that works in 100% of the networks.
You can use my project p2pcf [1] to do WebRTC signalling and then sync the cursors by just blasting datachannel messages to all your connected peers. For a project I made that uses this to do far more than cursor syncing, but syncs an entire 3d world with voip, checkout https://webspaces.space
Has anyone figured out a nice way to do the partykit-like cursor stuff [0] that doesn't need a database/intermediary? It would be so nice to be able to ship a p2p presence-enabled static site without a dedicated server. Looks like partykit has a generous free tier but we all know those only last so long.
Oh and while I'm here I'll plug my friend's project that this reminded me of! StreetPass is a browser extension that helps you find your people on Mastodon by checking for social metadata tags on the sites you visit [1].
[0]: https://blog.partykit.io/posts/cursor-party
[1]: https://streetpass.social