From a8de400e17bd3eb7892cac5a0bef02b35482e946 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 14 Sep 2022 19:58:12 +0200 Subject: transmission successful! --- Cargo.lock | 1 + client-native-rift/Cargo.toml | 1 + client-native-rift/src/peer.rs | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f448a85..b3b3c3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,6 +427,7 @@ version = "0.1.0" dependencies = [ "aes-gcm 0.10.1", "base64", + "bytes", "clap", "env_logger", "fastpbkdf2", diff --git a/client-native-rift/Cargo.toml b/client-native-rift/Cargo.toml index 7e1911d..9030315 100644 --- a/client-native-rift/Cargo.toml +++ b/client-native-rift/Cargo.toml @@ -24,3 +24,4 @@ sha256 = "1.0.3" rand = "0.8.5" rand_chacha = "0.3.1" base64 = "0.13.0" +bytes = "1.2.1" diff --git a/client-native-rift/src/peer.rs b/client-native-rift/src/peer.rs index 22acffd..8402fc6 100644 --- a/client-native-rift/src/peer.rs +++ b/client-native-rift/src/peer.rs @@ -1,6 +1,5 @@ -use std::sync::Arc; - use log::info; +use std::sync::Arc; use webrtc::{ data_channel::data_channel_message::DataChannelMessage, ice_transport::{ice_candidate::RTCIceCandidate, ice_server::RTCIceServer}, @@ -71,6 +70,19 @@ impl Peer { .await; } + { + peer.peer_connection + .on_data_channel(box move |dc| { + Box::pin(async move { + dc.on_message(box move |message| { + Box::pin(async move { println!("{:?}", message.data) }) + }) + .await + }) + }) + .await; + } + if let Action::Send { .. } = &peer.state.args.action { peer.start_transfer().await } @@ -97,6 +109,23 @@ impl Peer { Box::pin(async {}) })) .await; + + { + let dc2 = data_channel.clone(); + data_channel + .on_open(box move || { + let data_channel = dc2.clone(); + Box::pin(async move { + loop { + data_channel + .send(&bytes::Bytes::from_static(b"test\n")) + .await + .unwrap(); + } + }) + }) + .await; + } } pub async fn on_relay(&self, p: RelayMessage) { -- cgit v1.2.3-70-g09d2