diff --git a/src/bin.rs b/src/bin.rs index cc75796..86816d8 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -26,7 +26,7 @@ async fn main() -> Result<()> { async fn client_a() -> Result<()> { let mut p2p = P2P::new(None).await?; - let code = p2p.create_code("http://localhost:3000").await?; + let code = p2p.create_code("https://signaling.mii.dev").await?; println!("{code}"); @@ -34,45 +34,36 @@ async fn client_a() -> Result<()> { println!("Connected!"); - tokio::spawn({ - let receive = p2p.receive_data.clone(); - - async move { - let mut receive = receive.lock().await; - while let Some(data) = receive.recv().await { - println!("{}", String::from_utf8(data.to_vec()).unwrap()); - } - } - }); - - loop { - let line = read_line(); - p2p.send_text(&line).await?; - } + chat(p2p).await } async fn client_b(code: &str) -> Result<()> { let mut p2p = P2P::new(None).await?; - p2p.connect_with_code("http://localhost:3000", code).await?; + p2p.connect_with_code("https://signaling.mii.dev", code).await?; p2p.wait_open().await; println!("Connected!"); + chat(p2p).await +} + +async fn chat(mut p2p: P2P) -> Result<()> { tokio::spawn({ let receive = p2p.receive_data.clone(); async move { let mut receive = receive.lock().await; while let Some(data) = receive.recv().await { - println!("Received: {}", String::from_utf8(data.to_vec()).unwrap()); + print!("Received: {}\n", String::from_utf8(data.to_vec()).unwrap()); + std::io::stdout().flush().unwrap(); } } }); loop { let line = read_line(); - p2p.send_text(&line).await?; + p2p.send_text(&format!("{line}\n")).await?; } -} +} \ No newline at end of file diff --git a/src/p2p.rs b/src/p2p.rs index b1816e0..e199da4 100644 --- a/src/p2p.rs +++ b/src/p2p.rs @@ -94,6 +94,7 @@ impl P2P { let data = String::from_utf8_lossy(&chunk); for line in data.lines() { + println!("{line}"); if line.starts_with("data:") { let value = line.trim_start_matches("data:").trim(); if connection_code_received {