Add ControllerWsAction
This commit is contained in:
		
							parent
							
								
									cb47dcda5c
								
							
						
					
					
						commit
						3b596de06f
					
				
					 10 changed files with 134 additions and 34 deletions
				
			
		| 
						 | 
				
			
			@ -3,6 +3,7 @@ use std::str;
 | 
			
		|||
use crate::relay_loop::run_relay_loop;
 | 
			
		||||
use crate::settings::Settings;
 | 
			
		||||
use emgauwa_lib::db::{DbController, DbRelay};
 | 
			
		||||
use emgauwa_lib::handlers::v1::ws::controllers::ControllerWsAction;
 | 
			
		||||
use emgauwa_lib::models::convert_db_list;
 | 
			
		||||
use emgauwa_lib::types::ControllerUid;
 | 
			
		||||
use emgauwa_lib::{db, models};
 | 
			
		||||
| 
						 | 
				
			
			@ -96,10 +97,6 @@ async fn main() {
 | 
			
		|||
		relays,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	let this_json = serde_json::to_string(&this).unwrap();
 | 
			
		||||
 | 
			
		||||
	println!("{}", this_json);
 | 
			
		||||
 | 
			
		||||
	let url = format!(
 | 
			
		||||
		"ws://{}:{}/api/v1/ws/controllers",
 | 
			
		||||
		settings.core.host, settings.core.port
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +109,11 @@ async fn main() {
 | 
			
		|||
 | 
			
		||||
	let (mut write, read) = ws_stream.split();
 | 
			
		||||
 | 
			
		||||
	write.send(Message::text(this_json)).await.unwrap();
 | 
			
		||||
	let ws_action = ControllerWsAction::Register(this);
 | 
			
		||||
	println!("Sending action: {:?}", ws_action);
 | 
			
		||||
	let ws_action_json = serde_json::to_string(&ws_action).unwrap();
 | 
			
		||||
	println!("Sending json: {}", ws_action_json);
 | 
			
		||||
	write.send(Message::text(ws_action_json)).await.unwrap();
 | 
			
		||||
	let ws_to_stdout = read.for_each(handle_message);
 | 
			
		||||
	let stdin_to_ws = stdin_rx.map(Ok).forward(write);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,6 @@ use tokio::time;
 | 
			
		|||
pub async fn run_relay_loop(settings: Settings) {
 | 
			
		||||
	let default_duration = Duration::from_millis(1000);
 | 
			
		||||
	loop {
 | 
			
		||||
		// naivetime timestamp for now
 | 
			
		||||
		let next_timestamp = Local::now().naive_local().time() + default_duration;
 | 
			
		||||
		time::sleep(default_duration).await;
 | 
			
		||||
		println!("Relay loop: {}", next_timestamp)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue