Skip to content

Commit

Permalink
ferat: stasrt integrating into torii-client & message channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 18, 2024
1 parent 3fb4d41 commit 79a5b01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions crates/torii/client-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures.workspace = true
tokio.workspace = true
serde_json.workspace = true
torii-client = { version = "0.5.1-alpha.0", path = "../client" }
torii-libp2p = { version = "0.5.1-alpha.0", path = "../libp2p" }
libp2p = { version = "0.53.2", features = ["gossipsub"] }
25 changes: 19 additions & 6 deletions crates/torii/client-bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::{error::Error};
use std::error::Error;

use futures::pin_mut;
use futures::StreamExt;
use libp2p::gossipsub;
use tokio::{io, io::AsyncBufReadExt, select};
use torii_libp2p::client::{RelayClient};
use torii_libp2p::{
client::{events::ClientEvent, Libp2pClient},
types::ClientMessage,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let relay_server_addr = "/ip6/::1/tcp/1010".parse()?;
let mut client = RelayClient::new(relay_server_addr)?;
let mut client = Libp2pClient::new(relay_server_addr)?;

// subscribe to topic
client.subscribe("mimi")?;
Expand All @@ -18,11 +24,18 @@ async fn main() -> Result<(), Box<dyn Error>> {

// select that client is running and we have a line from stdin
loop {

select! {
_ = client.run() => {},
_ = client.run_message_listener() => {},
Ok(Some(line)) = stdin.next_line() => {
client.publish("mimi", &line)?;
client.publish(&ClientMessage{
topic: "mimi".to_string(),
data: line.as_bytes().to_vec(),
})?;
}
Some(event) = client.receiver.next() => {
println!("Received message: {:?}", event);
}
}
}
}
}

0 comments on commit 79a5b01

Please sign in to comment.