diff --git a/eventbus/src/client.rs b/eventbus/src/client.rs index 6cf6bb1..e408edf 100644 --- a/eventbus/src/client.rs +++ b/eventbus/src/client.rs @@ -25,7 +25,7 @@ impl WSClient { Self { events: eb } } - fn handle_text(&self, text: String) { + fn handle_text(&self, text: String, ctx: &::Context) { let command = serde_json::from_str::(&text); match command { @@ -34,6 +34,12 @@ impl WSClient { match c { crate::Command::Subscribe { client, channel } => { info!("Subscribing {} to {}", client, channel); + // Sent it along to the bus + // TODO: This should not use do_send which ignores errors + self.events.do_send(crate::bus::Subscribe { + to: channel, + addr: ctx.address(), + }); } _ => (), } @@ -95,7 +101,7 @@ impl StreamHandler> for WSClient { info!("WebSocket received: {:?}", msg); match msg { ws::Message::Ping(msg) => ctx.pong(&msg), - ws::Message::Text(text) => self.handle_text(text), + ws::Message::Text(text) => self.handle_text(text, ctx), ws::Message::Binary(bin) => ctx.binary(bin), _ => (), } diff --git a/eventbus/src/lib.rs b/eventbus/src/lib.rs index c59ae13..c77ad8f 100644 --- a/eventbus/src/lib.rs +++ b/eventbus/src/lib.rs @@ -26,4 +26,14 @@ pub enum Command { */ channel: String, }, + Unsubscribe { + /** + * The client's UUID + */ + client: String, + /** + * The channel the client wishes to unsubscribe from + */ + channel: String, + } }