Rename newstate to stateupdate

This commit is contained in:
Sam W 2019-03-16 12:05:15 +00:00
parent 2232ee62a7
commit ec03b72c7e
3 changed files with 14 additions and 14 deletions

View File

@ -68,8 +68,8 @@ impl<T: Adaptor, U: Driver> Server<T, U> {
}, },
recv(rx) -> state => { recv(rx) -> state => {
let thestate = state.unwrap(); let thestate = state.unwrap();
tx.send(thestate).unwrap(); tx.send(thestate).unwrap(); // Send update to driver
ws_tx_wait.send(web::websocket::NewState::from(thestate)).expect("Error sending to websocket channel"); ws_tx_wait.send(web::websocket::StateUpdate::from(thestate)).expect("Error sending to websocket channel"); // And to web interface
} }
} }
} }

View File

@ -17,7 +17,7 @@ const INDEX: &'static [u8] = include_bytes!("static/index.html");
impl WebServer { impl WebServer {
pub fn run( pub fn run(
addr: std::net::SocketAddr, addr: std::net::SocketAddr,
) -> (WebServer, futures::sync::mpsc::Sender<websocket::NewState>) { ) -> (WebServer, futures::sync::mpsc::Sender<websocket::StateUpdate>) {
let (ws_tx_tx, ws_tx_rx) = mpsc::channel(); // Channel the websocket sender will be sent on let (ws_tx_tx, ws_tx_rx) = mpsc::channel(); // Channel the websocket sender will be sent on
let (shutdown_tx, shutdown_rx) = mpsc::channel(); let (shutdown_tx, shutdown_rx) = mpsc::channel();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();

View File

@ -17,25 +17,25 @@ pub struct Disconnect {
} }
#[derive(Message)] #[derive(Message)]
pub struct NewState(Result<TallyState, ()>); pub struct StateUpdate(Result<TallyState, ()>);
// Basically just convenience so you don't have to construct a NewState with an Ok all the time // Basically just convenience so you don't have to construct a StateUpdate with an Ok all the time
impl From<TallyState> for NewState { impl From<TallyState> for StateUpdate {
fn from(state: TallyState) -> Self { fn from(state: TallyState) -> Self {
NewState(Ok(state)) StateUpdate(Ok(state))
} }
} }
pub struct WSServer { pub struct WSServer {
state_tx_tx: std::sync::mpsc::Sender<Sender<NewState>>, state_tx_tx: std::sync::mpsc::Sender<Sender<StateUpdate>>,
clients: HashMap<Recipient<Message>, ()>, clients: HashMap<Recipient<Message>, ()>,
} }
// This lets the WSServer act as a futures channel reciever, with incoming NewStates being handled like actix messages // This lets the WSServer act as a futures channel reciever, with incoming StateUpdates being handled like actix messages
impl StreamHandler<NewState, ()> for WSServer { impl StreamHandler<StateUpdate, ()> for WSServer {
fn handle(&mut self, item: NewState, _: &mut Context<WSServer>) { fn handle(&mut self, item: StateUpdate, _: &mut Context<WSServer>) {
if let Ok(state) = item.0 { if let Ok(state) = item.0 {
self.broadcast(serde_json::to_string(&state).unwrap()) self.broadcast(serde_json::to_string(&state).unwrap());
} }
} }
} }
@ -45,14 +45,14 @@ impl Actor for WSServer {
fn started(&mut self, ctx: &mut Self::Context) { fn started(&mut self, ctx: &mut Self::Context) {
log::info!("Websocket started"); log::info!("Websocket started");
let (tx, rx) = futures::sync::mpsc::channel::<NewState>(10); let (tx, rx) = futures::sync::mpsc::channel::<StateUpdate>(10);
Self::add_stream(rx, ctx); Self::add_stream(rx, ctx);
self.state_tx_tx.send(tx).unwrap(); self.state_tx_tx.send(tx).unwrap();
} }
} }
impl WSServer { impl WSServer {
pub fn new(state_tx_tx: std::sync::mpsc::Sender<Sender<NewState>>) -> WSServer { pub fn new(state_tx_tx: std::sync::mpsc::Sender<Sender<StateUpdate>>) -> WSServer {
WSServer { WSServer {
state_tx_tx, state_tx_tx,
clients: HashMap::new(), clients: HashMap::new(),