From 0e8152f64bfdcf85eb396bab3c642261825c178f Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Sat, 30 Jul 2022 00:28:26 +0100 Subject: [PATCH] Update README.md examples --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b3463ac..a4ba0e0 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This library is quite immature; many features still need to be added for it to b `remote_events` is not currently available on Cargo; instead, you need to use a Git dependency. Add the following to your project's `Cargo.toml` file: ```toml -remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events", branch="trunk" } +remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events", branch = "trunk" } ``` ## Usage @@ -32,9 +32,10 @@ remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events" You need to define two event types; one for events you expect to send to the remote server, and one for events you expect to receive. Typically this will be an `enum` type. These types need to implement `ToSocketMessage` and `FromSocketMessage` respectively. -`remote_events` expects every received event to be mapped to a type within your project; this might require a custom `None` type added to your event `enum` (see below). A -client will only be created when you emit a lifecycle event containing the URL of the remote host to connect to. The `Desktop` target can only handle insecure websocket -connections (`ws://`, not `wss://`). +`remote_events` expects every received event to be mapped to a type within your project; this might require a custom `None` type added to your event `enum` (see below). + +A client will only be created when you emit a `SocketControlEvent::Connect(String)` event containing the URL of the remote host to connect to. +The `Desktop` target can only handle insecure websocket connections (`ws://`, not `wss://`). ```rust use remote_events::events::{FromSocketMessage, SocketControlEvent, ToSocketMessage}; @@ -71,6 +72,10 @@ impl FromSocketMessage for ReceivedEvents { } } +pub fn connect_to_server(mut events: EventWriter<SocketControlEvent>) { + events.send(SocketControlEvent::Connect(String::from("ws://localhost:3000"))); +} + #[derive(Default, Clone, Debug, Serialize)] pub enum SentEvents { ButtonClicked, @@ -88,6 +93,7 @@ impl ToSocketMessage for ReceivedEvents { pub fn main() { App::new() // .. Other plugins .. + .add_startup_system(connect_to_server) .add_plugin( RemoteEventPlugin::<SentEvents, ReceivedEvents>::new() ); -- GitLab