Skip to content

Commit

Permalink
refactor(web): use gloo-net provided AsyncRead/Write impl (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit authored Feb 13, 2024
1 parent abe90e4 commit 0cd612b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 119 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/ironrdp-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ["HtmlCanvasElement"] }
js-sys = "0.3"
gloo-net = { version = "0.5", default-features = false, features = ["websocket", "http"] }
gloo-net = { version = "0.5", default-features = false, features = ["websocket", "http", "io-util"] }
gloo-timers = { version = "0.3", default-features = false, features = ["futures"] }
tracing-web = "0.1"

Expand Down
1 change: 0 additions & 1 deletion crates/ironrdp-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod image;
mod input;
mod network_client;
mod session;
mod websocket;

use wasm_bindgen::prelude::*;

Expand Down
17 changes: 7 additions & 10 deletions crates/ironrdp-web/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::Context as _;
use base64::Engine as _;
use futures_channel::mpsc;
use futures_util::io::{ReadHalf, WriteHalf};
use futures_util::{select, AsyncReadExt as _, AsyncWriteExt as _, FutureExt as _, StreamExt as _};
use futures_util::{select, AsyncWriteExt as _, FutureExt as _, StreamExt as _};
use gloo_net::websocket;
use gloo_net::websocket::futures::WebSocket;
use ironrdp::cliprdr::backend::ClipboardMessage;
Expand All @@ -31,7 +31,6 @@ use crate::error::{IronRdpError, IronRdpErrorKind};
use crate::image::extract_partial_image;
use crate::input::InputTransaction;
use crate::network_client::WasmNetworkClient;
use crate::websocket::WebSocketCompat;
use crate::{clipboard, DesktopSize};

const DEFAULT_WIDTH: u16 = 1280;
Expand Down Expand Up @@ -296,8 +295,6 @@ impl SessionBuilder {
}
}

let ws = WebSocketCompat::new(ws);

let (connection_result, ws) = connect(
ws,
config,
Expand All @@ -311,7 +308,7 @@ impl SessionBuilder {

info!("Connected!");

let (rdp_reader, rdp_writer) = ws.split();
let (rdp_reader, rdp_writer) = futures_util::AsyncReadExt::split(ws);

let (writer_tx, writer_rx) = mpsc::unbounded();

Expand Down Expand Up @@ -381,7 +378,7 @@ pub struct Session {
// Consumed when `run` is called
input_events_rx: RefCell<Option<mpsc::UnboundedReceiver<RdpInputEvent>>>,
connection_result: RefCell<Option<connector::ConnectionResult>>,
rdp_reader: RefCell<Option<ReadHalf<WebSocketCompat>>>,
rdp_reader: RefCell<Option<ReadHalf<WebSocket>>>,
clipboard: RefCell<Option<Option<WasmClipboard>>>,
}

Expand Down Expand Up @@ -759,12 +756,12 @@ fn build_config(
}
}

async fn writer_task(rx: mpsc::UnboundedReceiver<Vec<u8>>, rdp_writer: WriteHalf<WebSocketCompat>) {
async fn writer_task(rx: mpsc::UnboundedReceiver<Vec<u8>>, rdp_writer: WriteHalf<WebSocket>) {
debug!("writer task started");

async fn inner(
mut rx: mpsc::UnboundedReceiver<Vec<u8>>,
mut rdp_writer: WriteHalf<WebSocketCompat>,
mut rdp_writer: WriteHalf<WebSocket>,
) -> anyhow::Result<()> {
while let Some(frame) = rx.next().await {
rdp_writer.write_all(&frame).await.context("Couldn’t write frame")?;
Expand All @@ -781,14 +778,14 @@ async fn writer_task(rx: mpsc::UnboundedReceiver<Vec<u8>>, rdp_writer: WriteHalf
}

async fn connect(
ws: WebSocketCompat,
ws: WebSocket,
config: connector::Config,
proxy_auth_token: String,
destination: String,
pcb: Option<String>,
kdc_proxy_url: Option<String>,
clipboard_backend: Option<WasmClipboardBackend>,
) -> Result<(connector::ConnectionResult, WebSocketCompat), IronRdpError> {
) -> Result<(connector::ConnectionResult, WebSocket), IronRdpError> {
let mut framed = ironrdp_futures::SingleThreadedFuturesFramed::new(ws);

let mut connector = connector::ClientConnector::new(config);
Expand Down
107 changes: 0 additions & 107 deletions crates/ironrdp-web/src/websocket.rs

This file was deleted.

0 comments on commit 0cd612b

Please sign in to comment.