Wire through the actual Subscribe command for the client onto the bus

This commit is contained in:
R Tyler Croy 2019-12-28 13:28:43 -08:00
parent 853966b4e1
commit e77182fe18
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
2 changed files with 18 additions and 2 deletions

View File

@ -25,7 +25,7 @@ impl WSClient {
Self { events: eb }
}
fn handle_text(&self, text: String) {
fn handle_text(&self, text: String, ctx: &<WSClient as Actor>::Context) {
let command = serde_json::from_str::<crate::Command>(&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<Result<ws::Message, ws::ProtocolError>> 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),
_ => (),
}

View File

@ -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,
}
}