Skip to content

Commit 4e16783

Browse files
committed
remove dummy webrtc stream,
add api to get webrtc stream
1 parent e4224a1 commit 4e16783

3 files changed

Lines changed: 12 additions & 54 deletions

File tree

examples/webrtc.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@ extern crate hbb_common;
22

33
#[cfg(feature = "webrtc")]
44
use hbb_common::webrtc::WebRTCStream;
5-
#[cfg(not(feature = "webrtc"))]
6-
mod webrtc_dummy;
7-
#[cfg(not(feature = "webrtc"))]
8-
use crate::webrtc_dummy::WebRTCStream;
95

106
use std::io::Write;
11-
127
use anyhow::Result;
138
use bytes::Bytes;
149
use clap::{Arg, Command};
1510
use tokio::time::Duration;
1611

17-
#[cfg(feature = "webrtc")]
18-
use webrtc::peer_connection::math_rand_alpha;
19-
2012
#[cfg(not(feature = "webrtc"))]
2113
#[tokio::main]
2214
async fn main() -> Result<()> {
@@ -121,6 +113,7 @@ async fn main() -> Result<()> {
121113
}
122114

123115
// read_loop shows how to read from the datachannel directly
116+
#[cfg(feature = "webrtc")]
124117
async fn read_loop(mut stream: WebRTCStream) -> Result<()> {
125118
loop {
126119
let Some(res) = stream.next().await else {
@@ -140,6 +133,7 @@ async fn read_loop(mut stream: WebRTCStream) -> Result<()> {
140133
}
141134

142135
// write_loop shows how to write to the webrtc stream directly
136+
#[cfg(feature = "webrtc")]
143137
async fn write_loop(mut stream: WebRTCStream) -> Result<()> {
144138
let mut result = Result::<()>::Ok(());
145139
while result.is_ok() {
@@ -148,7 +142,7 @@ async fn write_loop(mut stream: WebRTCStream) -> Result<()> {
148142

149143
tokio::select! {
150144
_ = timeout.as_mut() =>{
151-
let message = math_rand_alpha(15);
145+
let message = webrtc::peer_connection::math_rand_alpha(15);
152146
result = stream.send_bytes(Bytes::from(message.clone())).await;
153147
println!("Sent '{message}' {}", result.is_ok());
154148
}

examples/webrtc_dummy.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/stream.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,13 @@ impl Stream {
137137
pub fn from(stream: TcpStream, stream_addr: SocketAddr) -> Self {
138138
Self::Tcp(tcp::FramedStream::from(stream, stream_addr))
139139
}
140+
141+
#[inline]
142+
#[cfg(feature = "webrtc")]
143+
pub fn get_webrtc_stream(&self) -> Option<webrtc::WebRTCStream> {
144+
match self {
145+
Self::WebRTC(s) => Some(s.clone()),
146+
_ => None,
147+
}
148+
}
140149
}

0 commit comments

Comments
 (0)