Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Legend-State Enable Peer-to-Peer Sync in an Offline-First Electron App? #478

Open
RattyJhay opened this issue Feb 21, 2025 · 1 comment

Comments

@RattyJhay
Copy link

RattyJhay commented Feb 21, 2025

I’m building an offline-first Electron app and using Legend-State for state management. I need to sync state changes between multiple Electron instances over a local network (LAN) without internet.

For example, if John updates inventory on one PC, Sarah's PC should reflect the change automatically over LAN.

Questions:

  • Can Legend-State handle peer-to-peer sync over LAN?
  • If not, what’s the best way to combine it with WebRTC or WebSockets?
  • How would Legend-State handle conflicts if multiple users update the same state?
@jmeistrich
Copy link
Contributor

Yes, Legend State is totally agnostic to your sync system. You can build a custom plugin on top of synced that fetches from whatever you want - it just needs to return a Promise. It could be a remote server, or a server on a LAN, or even call a function through Electron. See this whole page but especially this last section: https://legendapp.com/open-source/state/v3/sync/persist-sync/#making-a-sync-plugin.

If your sync system would have multiple rows, you might want to build on top of the crud plugin rather than the raw synced.

For conflicts, there's not a specific conflict resolution system at the moment, though that's planned soon. For now it's basically just last write wins.

I'm very aware that the documentation for building custom plugins is quite lacking! So please feel free to ask a lot of questions - I'm happy to answer them and that would help with knowing what to add to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants