Rename newstate to stateupdate
This commit is contained in:
parent
2232ee62a7
commit
ec03b72c7e
|
@ -68,8 +68,8 @@ impl<T: Adaptor, U: Driver> Server<T, U> {
|
|||
},
|
||||
recv(rx) -> state => {
|
||||
let thestate = state.unwrap();
|
||||
tx.send(thestate).unwrap();
|
||||
ws_tx_wait.send(web::websocket::NewState::from(thestate)).expect("Error sending to websocket channel");
|
||||
tx.send(thestate).unwrap(); // Send update to driver
|
||||
ws_tx_wait.send(web::websocket::StateUpdate::from(thestate)).expect("Error sending to websocket channel"); // And to web interface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ const INDEX: &'static [u8] = include_bytes!("static/index.html");
|
|||
impl WebServer {
|
||||
pub fn run(
|
||||
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 (shutdown_tx, shutdown_rx) = mpsc::channel();
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
|
|
@ -17,25 +17,25 @@ pub struct Disconnect {
|
|||
}
|
||||
|
||||
#[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
|
||||
impl From<TallyState> for NewState {
|
||||
// Basically just convenience so you don't have to construct a StateUpdate with an Ok all the time
|
||||
impl From<TallyState> for StateUpdate {
|
||||
fn from(state: TallyState) -> Self {
|
||||
NewState(Ok(state))
|
||||
StateUpdate(Ok(state))
|
||||
}
|
||||
}
|
||||
|
||||
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>, ()>,
|
||||
}
|
||||
|
||||
// This lets the WSServer act as a futures channel reciever, with incoming NewStates being handled like actix messages
|
||||
impl StreamHandler<NewState, ()> for WSServer {
|
||||
fn handle(&mut self, item: NewState, _: &mut Context<WSServer>) {
|
||||
// This lets the WSServer act as a futures channel reciever, with incoming StateUpdates being handled like actix messages
|
||||
impl StreamHandler<StateUpdate, ()> for WSServer {
|
||||
fn handle(&mut self, item: StateUpdate, _: &mut Context<WSServer>) {
|
||||
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) {
|
||||
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.state_tx_tx.send(tx).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
state_tx_tx,
|
||||
clients: HashMap::new(),
|
||||
|
|
Loading…
Reference in New Issue