-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add BRP watch_id
and bevy/unwatch
#16407
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
base: main
Are you sure you want to change the base?
Conversation
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.
LGTM, but if you have time swapping to a named struct to avoid the complex tuples would be nice.
@@ -348,7 +364,7 @@ pub fn process_remote_get_request(In(params): In<Option<Value>>, world: &World) | |||
|
|||
/// Handles a `bevy/get+watch` request coming from a client. | |||
pub fn process_remote_get_watching_request( | |||
In(params): In<Option<Value>>, | |||
In((_, params)): In<RemoteWatchingSystemParams>, |
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.
Why are we providing the watch_id
if they are not used anywhere in the watch systems?
In case they might be used in the future?
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 idea is to give watch handlers a way to identify which watcher it is handling, giving them a unique key for use with any needed state/cache that needs to be handled on watcher level, rather than method level.
As you’ve noticed it is not used by any of the built in methods, as they are not stateful. But I have encountered the need for watcher state while building some custom methods.
I’m not completely certain this is the best solution though. There are other ways. For example each watcher could have their own SystemState, allowing use of Local instead of managing state using ids and hash maps. Another benefit is cleanup would be automatic.
} | ||
} | ||
|
||
Ok(Value::Null) |
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.
We might want to return an error if a watch_id
is provided that doesn't exist
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! That makes sense.
//! `params`: | ||
//! - `watch_id`: The ID of request to unwatch. | ||
//! | ||
//! `result`: null. |
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.
We might want to return an error if a watch_id is provided that doesn't exist
Since in-engine websocket transport might be off the table, this companion PR may seem unnecessary as well. However I believe this functionality is still useful, for any third-party stream-based transports, as well as a potential future binary TCP transport. While trying to think about ways to solve the connection limit issue with SSE, I realized one way could be to re-design watchers a bit by using a single SSE endpoint as a stream for all watcher responses. This would ensure any number of watchers can be used even from a web browser. With the above in mind, as well as the state stuff, I think we should hold off a bit on this PR and try to figure out a better watcher design in general. |
Objective
BRP supports watching requests by using the
+watch
-suffix. But it has some limitations:Solution
watch_id
(RemoteWatchingRequestId = u32
) used to uniquely identify a specific watcher.id
field in JSON RPC 2.0, which is a client owned id that may or may not exist and might not be unique.+watch
-request handling to always send an initial response with thewatch_id
of that request.In
-param for the watching request handlers to also include thewatch_id
.bevy/unwatch
-method which can be used to close a current watcher (or all watchers).Testing
bevy_remote_inspector
, where I use the watch_id to detect closed watchers and perform cleanup in a separate system.