-
Notifications
You must be signed in to change notification settings - Fork 22
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
Understanding Django Channels setup #88
Comments
Hey @mgug01, thanks for the code. I have a few quick thoughts
|
Hi there @zswaff! Thanks so much- really appreciate the reply on this!
Tried this and unfortunately the document will still occasionally "reconnect" without reason after every 30 sec-1 min
This is an interesting idea- I didn't quite understand what Though I suppose we wouldn't need to receive these message types if we could load database data within
The client side is using ReactJS, Quill, y-websocket and y-quill. To save the document, I am calling To load the document, I do pretty much the same but reversed. My client-side sends a request_type of Does this make sense? Thanks again for the time. |
Cool, happy to help! I want to come back to this
Did you try it? Like if you literally take out all of your overriding code, does it work to sync data between tabs?
This sounds like it might be a general websocket timeout. I think websockets need a keepalive every min or so. Usually frontends are responsible I believe. Next steps here really depend on the first test above. If the two tabs are working, then it seems like perhaps the changes to
Makes sense, maybe one or the other of us can improve the documentation for this when we get the chance.
I think the latter is the intended approach if possible!
OK this is simpler/easier to handle than I expected I think. A lot of this will change when you are using this lib but the basic principles would be the same. I guess you would
|
Hey @zswaff! I know it’s an old issue, but may be you can help me! I am using this recommendation:
But because each client is associated with a specific consumer, every YDoc is different (only has updates from the connected client), so the document is not really the same as the Yjs Room document. Do I missing something? Is my setup wrong? Also, do you use this in production? how do you debounce the saves to the database? I can see this Django Channels implementation doesn’t use YStore or YRoom from this library. Thank you very much! |
Hey @cacosandon, happy to help. This is actually timely because I'm about to kick off a project on our team to improve some of this stuff internally, which may involve some changes here if we find my old work lacking haha. We're not using it in production yet but we plan to be once we make these improvements. You're absolutely right that each client has its own YDoc with this setup--you're not missing anything. We will probably need to configure everything more like the way you described before it's ready. Let me know if there's other stuff I can help with or if you want to collaborate on any of these improvements! |
Amazing @zswaff! I already edited some of the code so all consumers have the same YDoc. I have replaced the + async def process_sync_update_message(self, message_wrapper: dict) -> None:
+ logger.info("Receiving SYNC UPDATE from %s", self.ydoc.client_id)
+
+ await process_sync_message(
+ message_wrapper["update"],
+ self.ydoc,
+ self._websocket_shim,
+ logger,
+ )
+ # We save the document with debounce strategy
+ if time.time() - self.last_change_timestamp > self.seconds_between_saves:
+ logger.info("Saving document from %s", self.ydoc.client_id)
+ await YDocUpdate.objects.asave_snapshot(
+ self.room_name,
+ y_py.encode_state_as_update(self.ydoc),
+ )
+ self.last_change_timestamp = time.time()
async def receive(self, text_data=None, bytes_data=None): # noqa: ARG002
if bytes_data is None:
return
await self.group_send_message(bytes_data)
if bytes_data[0] != YMessageType.SYNC:
return
+ if bytes_data[1] == YSyncMessageType.SYNC_UPDATE:
+ logger.info("Sending SYNC UPDATE from %s", self.ydoc.client_id)
+ await self.channel_layer.group_send(
+ self.room_name,
+ {"type": "process_sync_update_message", "update": bytes_data[1:]},
+ )
+ return
await process_sync_message(
bytes_data[1:],
self.ydoc,
self._websocket_shim,
logger,
) This way, every "update" message (not sync protocol, not awareness) is sent to every consumer connected, and then process that message via So every client has their own debounced save to the database with the most recent YDoc, and also all have the same doc. This works well, at least locally. Don't know if we need all the complexity of Haven't tested this in production yet. Do you see any flaws? Maybe when receiving offline updates or updates coming with different Would love to talk! We are using Slack in our company, just in case you want to create a shared channel, or maybe a Discord channel :) |
@cacosandon I'll take a look at that code as soon as I can. I agree with you in principle that this should be pretty straightforward. If you want to join my company's discord we could start there, or we can chat on linkedin and set up a shared slack channel! |
Hey there-
I really appreciate the hard work that has gone into this repo thus far.
I'm trying to refactor my
ypy-websocket
setup with the new Django Channels consumer within my ReactJS + Django application but am having trouble getting things running.Aside from the initial "connect" I'm unsure if my implementation is correct, how to save an load documents, and it for some reason I am seeing quite a few "disconnect" errors:
Here's what I have so far from the Django side:
For further context on the data we want to retrieve/save from/to the database, we use
Y.encodeStateAsUpdate(doc)
on the JS client side, and save as JSON to our Postgres database.Thanks for your time!!
The text was updated successfully, but these errors were encountered: