wip
This commit is contained in:
parent
43a0b1c1d1
commit
7304b33b7c
5 changed files with 312 additions and 27 deletions
30
src/lib.rs
30
src/lib.rs
|
|
@ -1,4 +1,19 @@
|
|||
use futures_util::StreamExt;
|
||||
use futures_util::stream::SplitSink;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tokio::{net::TcpStream, sync::Mutex};
|
||||
use tokio_tungstenite::tungstenite::protocol::Message;
|
||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
|
||||
|
||||
pub const WS_URL: &str = "ws://127.0.0.1:8080";
|
||||
pub const LOG_PATH: &str = "test.txt";
|
||||
|
||||
pub mod lib {
|
||||
pub mod logger;
|
||||
}
|
||||
|
||||
pub type WsTx = Arc<Mutex<Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>>;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum PayloadType {
|
||||
|
|
@ -26,3 +41,18 @@ pub enum Command<'a> {
|
|||
Dnx { params: DnxParams<'a> },
|
||||
Screenshot,
|
||||
}
|
||||
|
||||
pub async fn reconnect_websocket(ws: WsTx) {
|
||||
let mut lock = ws.lock().await;
|
||||
loop {
|
||||
if let Ok(connection) = connect_async(WS_URL).await {
|
||||
let (ws_conn, _) = connection;
|
||||
let (ws_trx, _) = ws_conn.split();
|
||||
*lock = Some(ws_trx);
|
||||
break;
|
||||
}
|
||||
println!("reconnect slp");
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
println!("reconnect out");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue