mirror of
https://github.com/rustdesk/hbb_common.git
synced 2025-07-01 15:36:53 +00:00
[enhance] test ver. Add text for test.
This commit is contained in:
parent
29a322e6e3
commit
7d5cc2ed47
22
src/lib.rs
22
src/lib.rs
@ -117,23 +117,6 @@ impl Stream {
|
||||
Stream::Tcp(s) => s.next_timeout(timeout).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream {
|
||||
/// establish connect from tcp.
|
||||
pub async fn from_tcp(
|
||||
stream: tokio::net::TcpStream,
|
||||
addr: SocketAddr,
|
||||
is_websocket: bool,
|
||||
) -> ResultType<Self> {
|
||||
if is_websocket {
|
||||
Ok(Self::WebSocket(
|
||||
websocket::WsFramedStream::from(stream, addr).await,
|
||||
))
|
||||
} else {
|
||||
Ok(Self::Tcp(tcp::FramedStream::from(stream, addr)))
|
||||
}
|
||||
}
|
||||
|
||||
/// establish connect from websocket
|
||||
pub async fn connect_websocket(
|
||||
@ -144,6 +127,7 @@ impl Stream {
|
||||
) -> ResultType<Self> {
|
||||
let ws_stream =
|
||||
websocket::WsFramedStream::new(url, local_addr, proxy_conf, timeout_ms).await?;
|
||||
log::debug!("WebSocket connection established");
|
||||
Ok(Self::WebSocket(ws_stream))
|
||||
}
|
||||
|
||||
@ -169,10 +153,6 @@ impl Stream {
|
||||
Self::Tcp(tcp) => tcp.local_addr(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_websocket(&self) -> bool {
|
||||
matches!(self, Self::WebSocket(_))
|
||||
}
|
||||
}
|
||||
|
||||
pub type SessionID = uuid::Uuid;
|
||||
|
@ -112,19 +112,6 @@ impl WsFramedStream {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn from(stream: TcpStream, addr: SocketAddr) -> Self {
|
||||
let ws_stream =
|
||||
WebSocketStream::from_raw_socket(MaybeTlsStream::Plain(stream), Role::Client, None)
|
||||
.await;
|
||||
|
||||
Self {
|
||||
stream: ws_stream,
|
||||
addr,
|
||||
encrypt: None,
|
||||
send_timeout: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn local_addr(&self) -> SocketAddr {
|
||||
self.addr
|
||||
}
|
||||
@ -202,6 +189,11 @@ impl WsFramedStream {
|
||||
}
|
||||
return Some(Ok(bytes));
|
||||
}
|
||||
WsMessage::Text(text) => {
|
||||
log::debug!("Received text message, converting to binary");
|
||||
let bytes = BytesMut::from(text.as_bytes());
|
||||
return Some(Ok(bytes));
|
||||
}
|
||||
WsMessage::Close(_) => {
|
||||
log::info!("Received close frame");
|
||||
return None;
|
||||
|
Loading…
x
Reference in New Issue
Block a user