aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client-native-lib/src/lib.rs2
-rw-r--r--client-native-rift/src/main.rs32
2 files changed, 26 insertions, 8 deletions
diff --git a/client-native-lib/src/lib.rs b/client-native-lib/src/lib.rs
index 7a0d0d0..a10a20a 100644
--- a/client-native-lib/src/lib.rs
+++ b/client-native-lib/src/lib.rs
@@ -47,12 +47,10 @@ pub(crate) fn build_api() -> webrtc::api::API {
}
pub type DynFut<T> = Pin<Box<dyn Future<Output = T> + Send>>;
-
pub trait LocalResource: Send + Sync + 'static {
fn info(&self) -> ProvideInfo;
fn on_request(&self, peer: Arc<Peer>) -> DynFut<()>;
}
-
pub trait EventHandler: Send + Sync + 'static {
fn peer_join(&self, peer: Arc<Peer>) -> DynFut<()>;
fn peer_leave(&self, peer: Arc<Peer>) -> DynFut<()>;
diff --git a/client-native-rift/src/main.rs b/client-native-rift/src/main.rs
index 8ccb7d8..7176290 100644
--- a/client-native-rift/src/main.rs
+++ b/client-native-rift/src/main.rs
@@ -90,7 +90,14 @@ impl EventHandler for Handler {
) -> DynFut<()> {
let id = info.id.clone();
Box::pin(async move {
- peer.request_resource(id).await;
+ match self.args.action {
+ Action::Send { filename } => {}
+ Action::Receive { filename } => {
+ if info.kind == "file" {
+ peer.request_resource(id).await;
+ }
+ }
+ }
})
}
fn resource_removed(&self, peer: Arc<Peer>, id: String) -> DynFut<()> {
@@ -112,7 +119,8 @@ impl EventHandler for Handler {
if resource.kind != "file" {
return error!("we got a non-file resource for some reason…");
}
- let writer = Arc::new(RwLock::new(None));
+ let writer: Arc<RwLock<Option<Pin<Box<dyn AsyncWrite + Send + Sync>>>>> =
+ Arc::new(RwLock::new(None));
{
let writer = writer.clone();
dc.on_open(box move || {
@@ -136,11 +144,23 @@ impl EventHandler for Handler {
})
.await;
}
- dc.on_message(box move |mesg| {
- Box::pin(async move {
- info!("{:?} bytes of data", mesg.data.len());
+ {
+ let writer = writer.clone();
+ dc.on_message(box move |mesg| {
+ let writer = writer.clone();
+ Box::pin(async move {
+ info!("{:?} bytes of data", mesg.data.len());
+ writer
+ .write()
+ .await
+ .as_mut()
+ .unwrap()
+ .write(&mesg.data)
+ .await
+ .unwrap();
+ })
})
- })
+ }
.await;
dc.on_error(box move |err| {
Box::pin(async move {