-
Notifications
You must be signed in to change notification settings - Fork 11
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
Broadcast server awareness to all clients #73
Conversation
Thanks @davidbrochart for the review and live debugging. As suggested in jupyter-server/jupyter_ydoc#277 (comment) I moved the |
Co-authored-by: David Brochart <[email protected]>
Co-authored-by: David Brochart <[email protected]>
for more information, see https://pre-commit.ci
5411d4d
to
52c80ed
Compare
Finally that's a lot of commits and comments for minimal changes 😄 |
for more information, see https://pre-commit.ci
pycrdt_websocket/yroom.py
Outdated
""" | ||
Callback to broadcast the server awareness to clients. | ||
""" | ||
if not changes[1] == "local": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not changes[1] == "local": | |
if changes[1] != "local": |
pycrdt_websocket/yroom.py
Outdated
self.ready_event = Event() | ||
self.ready = ready | ||
self.ystore = ystore | ||
self.log = log or getLogger(__name__) | ||
self.awareness = Awareness(self.ydoc) | ||
self.awareness.observe(self.local_update_awareness) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the callback name local_update_awareness
, maybe send_server_awareness
?
pycrdt_websocket/yroom.py
Outdated
updated_clients = [ | ||
*changes[0].get("added", []), | ||
*changes[0].get("filtered_updated", []), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes consist of "added"
, "updated"
and "removed"
entries only, not "filtered_updates"
. Should we include "removed"
?
updated_clients = [ | |
*changes[0].get("added", []), | |
*changes[0].get("filtered_updated", []), | |
] | |
updated_clients = [v for value in changes[0].values() for v in value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I added a test to broadcast only if there is an effective change (not 'update').
Co-authored-by: David Brochart <[email protected]>
pycrdt_websocket/yroom.py
Outdated
""" | ||
Callback to broadcast the server awareness to clients. | ||
""" | ||
if type != "change" or changes[1] != "local": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we actually broadcast every update?
if type != "change" or changes[1] != "local": | |
if type != "update" or changes[1] != "local": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right, we should broadcast all events.
Currently the update
event is triggered only when the change
event is triggered.
Should we trigger an update every X sec ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need this logic in pycrdt. I'll work on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I meant.
Co-authored-by: David Brochart <[email protected]>
Co-authored-by: David Brochart <[email protected]>
pyproject.toml
Outdated
@@ -30,7 +30,7 @@ classifiers = [ | |||
dependencies = [ | |||
"anyio >=3.6.2,<5", | |||
"sqlite-anyio >=0.2.3,<0.3.0", | |||
"pycrdt >=0.9.16,<0.10.0", | |||
"pycrdt >=0.10.0,<0.11.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take the latest bugfix.
I'm also wondering if we should wait for the implementation of periodic awareness updates in pycrdt?
"pycrdt >=0.10.0,<0.11.0", | |
"pycrdt >=0.10.1,<0.11.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is required for this change.
But we should probably remove the type != "update"
condition to broadcast all the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But an "update"
change is sent for all events, right? So we should keep it, to deduplicate "change"
events. Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, sorry again for the confusion. The change
event is only for observers, but not for clients...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll merge then.
Co-authored-by: David Brochart <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brichet!
This PR remove the Awareness to use the one from pycrdt (jupyter-server/pycrdt#170)This PR add broadcasting changes of state in the local awareness.
Draft until jupyter-server/pycrdt#170 is merged and released.