Skip to content
Snippets Groups Projects
Verified Commit 0e8152f6 authored by Louis's avatar Louis :fire:
Browse files

Update README.md examples

parent 6a7fceeb
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ This library is quite immature; many features still need to be added for it to b ...@@ -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: `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 ```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 ## Usage
...@@ -32,9 +32,10 @@ remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events" ...@@ -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. 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. 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 `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).
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://`). 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 ```rust
use remote_events::events::{FromSocketMessage, SocketControlEvent, ToSocketMessage}; use remote_events::events::{FromSocketMessage, SocketControlEvent, ToSocketMessage};
...@@ -71,6 +72,10 @@ impl FromSocketMessage for ReceivedEvents { ...@@ -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)] #[derive(Default, Clone, Debug, Serialize)]
pub enum SentEvents { pub enum SentEvents {
ButtonClicked, ButtonClicked,
...@@ -88,6 +93,7 @@ impl ToSocketMessage for ReceivedEvents { ...@@ -88,6 +93,7 @@ impl ToSocketMessage for ReceivedEvents {
pub fn main() { pub fn main() {
App::new() App::new()
// .. Other plugins .. // .. Other plugins ..
.add_startup_system(connect_to_server)
.add_plugin( .add_plugin(
RemoteEventPlugin::<SentEvents, ReceivedEvents>::new() RemoteEventPlugin::<SentEvents, ReceivedEvents>::new()
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment