|
@@ -6,10 +6,11 @@ use crate::environment::Environment;
|
|
|
|
|
|
|
|
mod routes;
|
|
mod routes;
|
|
|
mod controllers;
|
|
mod controllers;
|
|
|
-mod websocket;
|
|
|
|
|
|
|
+mod ha_websocket;
|
|
|
mod users;
|
|
mod users;
|
|
|
mod logic;
|
|
mod logic;
|
|
|
mod environment;
|
|
mod environment;
|
|
|
|
|
+mod ws_registry;
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
#[actix_web::main]
|
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
@@ -29,7 +30,10 @@ async fn main() -> Result<(), std::io::Error> {
|
|
|
//Connect to HA via websocket
|
|
//Connect to HA via websocket
|
|
|
let (outbound_tx, outbound_rx) = mpsc::unbounded_channel::<Message>();
|
|
let (outbound_tx, outbound_rx) = mpsc::unbounded_channel::<Message>();
|
|
|
let ha_sender = web::Data::new(outbound_tx);
|
|
let ha_sender = web::Data::new(outbound_tx);
|
|
|
- rt::spawn(websocket::listen(ha_ip, ha_token, outbound_rx));
|
|
|
|
|
|
|
+ rt::spawn(ha_websocket::listen(ha_ip, ha_token, outbound_rx));
|
|
|
|
|
+
|
|
|
|
|
+ //Create websocket server
|
|
|
|
|
+ let registry = web::Data::new(ws_registry::ClientRegistry::new());
|
|
|
|
|
|
|
|
//Create HTTP server
|
|
//Create HTTP server
|
|
|
HttpServer::new(move || {
|
|
HttpServer::new(move || {
|
|
@@ -37,6 +41,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|
|
.app_data(users_data.clone())
|
|
.app_data(users_data.clone())
|
|
|
.app_data(ha_sender.clone())
|
|
.app_data(ha_sender.clone())
|
|
|
.app_data(ae.clone())
|
|
.app_data(ae.clone())
|
|
|
|
|
+ .app_data(registry.clone())
|
|
|
.wrap(middleware::Compress::default())
|
|
.wrap(middleware::Compress::default())
|
|
|
.configure(routes::config)
|
|
.configure(routes::config)
|
|
|
})
|
|
})
|