-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Refactor BRP to allow for 3rd-party transports #15438
Refactor BRP to allow for 3rd-party transports #15438
Conversation
I think this is a good idea, but it's a non-trivial maintenance burden due to the addition of another language. Does it make more sense to maintain this out-of-tree for now until the protocol is stabilized further? |
I could edit this PR to only fix the building on WASM by extracting the HTTP in to its own module and then move the JS bindings in to my own crate. |
Let's do that! That seems like a nice refactor anyways, and will be able to be merged uncontroversially. |
Do you think the HTTP transport should have its own plugin rather than being so tied in with |
Yes, please split it out into its own plugin :) |
// Fetch the handler for the method. If there's no such handler | ||
// registered, return an error. | ||
let methods = world.resource::<RemoteMethods>(); | ||
|
||
let Some(handler) = methods.0.get(&message.method) else { | ||
let _ = message.sender.send_blocking(Err(BrpError { | ||
let _ = message.sender.force_send(Err(BrpError { |
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.
Can you explain the rationale for the change to force_send
?
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 this ensures errors are reported even if the queue is full. This will overwrite regular messages to ensure the error message is always sent. Did I get that right @LiamGallagher737 ?
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 previous send_blocking
is not available on WASM. Another option is to use try_send
but I don't think it is necessary as the channel is written to from in this function and only once. I could add some docs to support this.
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.
Just some minor doc stuff and a small question.
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.
Looks good, a few comments but nothing blocking.
crates/bevy_remote/src/http.rs
Outdated
|
||
impl Plugin for RemoteHttpPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.insert_resource(HostAddress(self.address)) |
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.
This overwrites any previous value. Should we insert only if the user didn't, to allow them to overwrite the default address and port?
I appreciate you can configure via the methods, but since world resources are "public", I think the more common pattern in Bevy is to let the user manually insert them before a plugin if they want to override any default. @alice-i-cecile any opinion on that?
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.
Yeah, I'd prefer a manual insertion with docs.
crates/bevy_remote/src/http.rs
Outdated
|
||
/// A resource containing the port number that Bevy will listen on. | ||
/// | ||
/// Currently, changing this while the application is running has no effect; this merely |
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.
Related to previous comment, why are we using a resource at all / why make the field public, if this has no effect? It feels users will get confused.
It's also arguable whether we need 2 separate resources for IP and port; we won't use one without the other.
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.
This is a good point, and I think it especially makes sense now that the transport has its own plugin.
Co-authored-by: Matty <[email protected]>
Head branch was pushed to by a user without write access
## Objective Closes bevyengine#15408 (somewhat) ## Solution - Moved the existing HTTP transport to its own module with its own plugin (`RemoteHttpPlugin`) (disabled on WASM) - Swapped out the `smol` crate for the smaller crates it re-exports to make it easier to keep out non-wasm code (HTTP transport needs `async-io` which can't build on WASM) - Added a new public `BrpSender` resource holding the matching sender for the `BrpReceiver`' (formally `BrpMailbox`). This allows other crates to send `BrpMessage`'s to the "mailbox". ## Testing TODO --------- Co-authored-by: Matty <[email protected]>
Objective
Closes #15408 (somewhat)
Solution
RemoteHttpPlugin
) (disabled on WASM)smol
crate for the smaller crates it re-exports to make it easier to keep out non-wasm code (HTTP transport needsasync-io
which can't build on WASM)BrpSender
resource holding the matching sender for theBrpReceiver
' (formallyBrpMailbox
). This allows other crates to sendBrpMessage
's to the "mailbox".Testing
TODO