remove dummy webrtc stream,
add api to get webrtc stream
This commit is contained in:
@@ -2,21 +2,13 @@ extern crate hbb_common;
|
|||||||
|
|
||||||
#[cfg(feature = "webrtc")]
|
#[cfg(feature = "webrtc")]
|
||||||
use hbb_common::webrtc::WebRTCStream;
|
use hbb_common::webrtc::WebRTCStream;
|
||||||
#[cfg(not(feature = "webrtc"))]
|
|
||||||
mod webrtc_dummy;
|
|
||||||
#[cfg(not(feature = "webrtc"))]
|
|
||||||
use crate::webrtc_dummy::WebRTCStream;
|
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
|
|
||||||
#[cfg(feature = "webrtc")]
|
|
||||||
use webrtc::peer_connection::math_rand_alpha;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "webrtc"))]
|
#[cfg(not(feature = "webrtc"))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -121,6 +113,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read_loop shows how to read from the datachannel directly
|
// read_loop shows how to read from the datachannel directly
|
||||||
|
#[cfg(feature = "webrtc")]
|
||||||
async fn read_loop(mut stream: WebRTCStream) -> Result<()> {
|
async fn read_loop(mut stream: WebRTCStream) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
let Some(res) = stream.next().await else {
|
let Some(res) = stream.next().await else {
|
||||||
@@ -140,6 +133,7 @@ async fn read_loop(mut stream: WebRTCStream) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write_loop shows how to write to the webrtc stream directly
|
// write_loop shows how to write to the webrtc stream directly
|
||||||
|
#[cfg(feature = "webrtc")]
|
||||||
async fn write_loop(mut stream: WebRTCStream) -> Result<()> {
|
async fn write_loop(mut stream: WebRTCStream) -> Result<()> {
|
||||||
let mut result = Result::<()>::Ok(());
|
let mut result = Result::<()>::Ok(());
|
||||||
while result.is_ok() {
|
while result.is_ok() {
|
||||||
@@ -148,7 +142,7 @@ async fn write_loop(mut stream: WebRTCStream) -> Result<()> {
|
|||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = timeout.as_mut() =>{
|
_ = timeout.as_mut() =>{
|
||||||
let message = math_rand_alpha(15);
|
let message = webrtc::peer_connection::math_rand_alpha(15);
|
||||||
result = stream.send_bytes(Bytes::from(message.clone())).await;
|
result = stream.send_bytes(Bytes::from(message.clone())).await;
|
||||||
println!("Sent '{message}' {}", result.is_ok());
|
println!("Sent '{message}' {}", result.is_ok());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
use std::io::Error;
|
|
||||||
|
|
||||||
use bytes::BytesMut;
|
|
||||||
|
|
||||||
use hbb_common::ResultType;
|
|
||||||
|
|
||||||
/// Dummy implementation of WebRTCStream used when the `webrtc` feature is disabled.
|
|
||||||
/// This struct allows the code to compile and run without actual WebRTC functionality.
|
|
||||||
pub struct WebRTCStream {
|
|
||||||
// mock struct
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for WebRTCStream {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
WebRTCStream {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WebRTCStream {
|
|
||||||
pub async fn new(_: &str, _: bool, _: u64) -> ResultType<Self> {
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get_local_endpoint(&self) -> ResultType<String> {
|
|
||||||
Ok(String::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn set_remote_endpoint(&self, _: &str) -> ResultType<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn send_bytes(&mut self, _: bytes::Bytes) -> ResultType<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn next(&mut self) -> Option<Result<BytesMut, Error>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -137,4 +137,13 @@ impl Stream {
|
|||||||
pub fn from(stream: TcpStream, stream_addr: SocketAddr) -> Self {
|
pub fn from(stream: TcpStream, stream_addr: SocketAddr) -> Self {
|
||||||
Self::Tcp(tcp::FramedStream::from(stream, stream_addr))
|
Self::Tcp(tcp::FramedStream::from(stream, stream_addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[cfg(feature = "webrtc")]
|
||||||
|
pub fn get_webrtc_stream(&self) -> Option<webrtc::WebRTCStream> {
|
||||||
|
match self {
|
||||||
|
Self::WebRTC(s) => Some(s.clone()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user