Add a simple eventbus CLI for testing
This commit is contained in:
parent
f347234c05
commit
8d520a156d
|
@ -1307,6 +1307,8 @@ dependencies = [
|
|||
"rust-embed 5.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -8,6 +8,10 @@ edition = "2018"
|
|||
name = "otto-eventbus"
|
||||
path = "src/server/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "otto-ebc"
|
||||
path = "src/cli.rs"
|
||||
|
||||
[dependencies]
|
||||
# Actix provides the web and websocket basis we sit on top of
|
||||
actix = "~0.9.0"
|
||||
|
@ -34,3 +38,7 @@ pretty_env_logger = "~0.3.1"
|
|||
# Adding the "rc" feature so we can serialize/deserialize Arc<T> and Rc<T>
|
||||
serde = { version = "~1.0.103", features = ["rc"] }
|
||||
serde_json = "~1.0.0"
|
||||
|
||||
# Needed for websockets in cli.rs
|
||||
tungstenite = "~0.9.2"
|
||||
url = "~2.1.0"
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* The CLI is meant to be used for manual testing and verification of the eventbus only.
|
||||
*/
|
||||
|
||||
use std::io::{stdin,stdout,Write};
|
||||
use tungstenite::*;
|
||||
use url::Url;
|
||||
|
||||
fn main() {
|
||||
let (mut socket, response) = connect(Url::parse("ws://localhost:8000/ws/").unwrap()).expect("Failed to connect");
|
||||
println!("Connected to the server");
|
||||
|
||||
loop {
|
||||
let mut message = String::new();
|
||||
print!("> ");
|
||||
let _ = stdout().flush();
|
||||
|
||||
let _ = stdin().read_line(&mut message).unwrap();
|
||||
|
||||
|
||||
if let Some('\n') = message.chars().next() {
|
||||
let msg = socket.read_message().expect("Failed to read message");
|
||||
println!("Received: {}", msg);
|
||||
}
|
||||
else {
|
||||
socket.write_message(Message::Text(message));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -150,6 +150,10 @@ impl Handler<Event> for EventBus {
|
|||
* eventbus
|
||||
*/
|
||||
for client in clients {
|
||||
/*
|
||||
* TODO: cloning this is probably not necessary but I do not currently
|
||||
* understand how to pass references to Actors in actix.
|
||||
*/
|
||||
client.do_send(ev.clone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue