casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
48 stars 9 forks source link

Add a function to get a YJS document that is shared #526

Open KallynGowdy opened 1 month ago

KallynGowdy commented 1 month ago

It would be very useful for users if they could get direct access into the shared updates system. In particular, if they could get a YJS document that is already hooked up to a branch inside of an inst (public or private). This would make it easy to skip using the bots system (and therefore skip potential code injection, etc.) but still have a robust mechanism for sharing CRDT updates across instances.

There should be a function, os.getSharedDocument(recordName, inst, documentName) that connects to the given branch and provides a YJS document that syncs updates to it. Then the document should be returned to the user so that they can use it (watch for updates, change things, etc.). If there is already a connection to the document, then it should just be reused.