hocuspocus
hocuspocus copied to clipboard
Conditionally filter transactions
The problem I am facing Our application at Pivot Interactives has functionality that would benefit from being able to conditionally block transactions. For example, we have a series of questions that can be submitted to the server for grading. Occasionally, we get race conditions on slow networks where two clients aren't aware that the other is using the last submission, so the second one generates an error and gets the ydoc into a bad state. It would be great if we could prevent the second transaction from even being applied and sent to other clients.
The solution I would like I have no idea what is feasible here, we are new to Yjs and Hocuspocus so this could be a ridiculous request. One idea is to filter transactions from clients in a hook of some sort before they are applied to the server copy of the ydoc. Another idea is to be able to modify the ydoc and merge those changes into the existing transaction before it is sent to the other clients.
Alternatives I have considered Of course we can always listen for updates and then correct the ydoc if changes are made from clients that are not allowed. I'm not sure this is ideal because it will send out two transactions to all clients. One for the bad update, and then one to correct.
Additional context The other issue here is that if transactions are ignored, we would need to be able to tell the original client that their transaction was not accepted. If there is a technical solution within Hocuspocus, I'm willing to contribute with maybe a little help.