Skip to content

Commit fe676ee

Browse files
refactor(web): follow-up to #722 (#747)
1 parent cc3dbf1 commit fe676ee

18 files changed

Lines changed: 72 additions & 73 deletions

File tree

crates/ironrdp-server/src/encoder/fast_path.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use core::{cmp, fmt};
22

3-
use ironrdp_pdu::{
4-
fast_path::{EncryptionFlags, FastPathHeader, FastPathUpdatePdu, Fragmentation, UpdateCode},
5-
Encode, WriteCursor,
6-
};
3+
use ironrdp_pdu::fast_path::{EncryptionFlags, FastPathHeader, FastPathUpdatePdu, Fragmentation, UpdateCode};
4+
use ironrdp_pdu::{Encode, WriteCursor};
75

86
// this is the maximum amount of data (not including headers) we can send in a single TS_FP_UPDATE_PDU
97
const MAX_FASTPATH_UPDATE_SIZE: usize = 16_374;
@@ -100,9 +98,10 @@ impl UpdateFragmenter {
10098

10199
#[cfg(test)]
102100
mod tests {
103-
use super::*;
104101
use ironrdp_core::{decode_cursor, ReadCursor};
105102

103+
use super::*;
104+
106105
#[test]
107106
fn test_single_fragment() {
108107
let data = vec![1, 2, 3, 4];

crates/ironrdp-web/src/clipboard/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl WasmClipboard {
137137
pub(crate) fn new(message_proxy: WasmClipboardMessageProxy, js_callbacks: JsClipboardCallbacks) -> Self {
138138
Self {
139139
local_clipboard: None,
140-
remote_clipboard: ClipboardTransaction::construct(),
140+
remote_clipboard: ClipboardTransaction::init(),
141141
proxy: message_proxy,
142142
js_callbacks,
143143

@@ -505,7 +505,7 @@ impl WasmClipboard {
505505
} else {
506506
// If no initial clipboard callback was set, send empty format list instead
507507
return self.process_event(WasmClipboardBackendMessage::LocalClipboardChanged(
508-
ClipboardTransaction::construct(),
508+
ClipboardTransaction::init(),
509509
));
510510
}
511511
}

crates/ironrdp-web/src/clipboard/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl ClipboardTransaction {
1919

2020
#[wasm_bindgen]
2121
impl ClipboardTransaction {
22-
pub fn construct() -> Self {
22+
pub fn init() -> Self {
2323
Self { contents: Vec::new() }
2424
}
2525

crates/ironrdp-web/src/error.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use wasm_bindgen::prelude::*;
33

44
#[wasm_bindgen]
55
#[derive(Clone, Copy)]
6-
pub enum RemoteDesktopErrorKind {
6+
pub enum IronErrorKind {
77
/// Catch-all error kind
88
General,
99
/// Incorrect password used
@@ -19,44 +19,44 @@ pub enum RemoteDesktopErrorKind {
1919
}
2020

2121
#[wasm_bindgen]
22-
pub struct RemoteDesktopError {
23-
kind: RemoteDesktopErrorKind,
22+
pub struct IronError {
23+
kind: IronErrorKind,
2424
source: anyhow::Error,
2525
}
2626

27-
impl RemoteDesktopError {
28-
pub fn with_kind(mut self, kind: RemoteDesktopErrorKind) -> Self {
27+
impl IronError {
28+
pub fn with_kind(mut self, kind: IronErrorKind) -> Self {
2929
self.kind = kind;
3030
self
3131
}
3232
}
3333

3434
#[wasm_bindgen]
35-
impl RemoteDesktopError {
35+
impl IronError {
3636
pub fn backtrace(&self) -> String {
3737
format!("{:?}", self.source)
3838
}
3939

40-
pub fn kind(&self) -> RemoteDesktopErrorKind {
40+
pub fn kind(&self) -> IronErrorKind {
4141
self.kind
4242
}
4343
}
4444

45-
impl From<connector::ConnectorError> for RemoteDesktopError {
45+
impl From<connector::ConnectorError> for IronError {
4646
fn from(e: connector::ConnectorError) -> Self {
4747
use sspi::credssp::NStatusCode;
4848

4949
let kind = match e.kind {
5050
ConnectorErrorKind::Credssp(sspi::Error {
5151
nstatus: Some(NStatusCode::WRONG_PASSWORD),
5252
..
53-
}) => RemoteDesktopErrorKind::WrongPassword,
53+
}) => IronErrorKind::WrongPassword,
5454
ConnectorErrorKind::Credssp(sspi::Error {
5555
nstatus: Some(NStatusCode::LOGON_FAILURE),
5656
..
57-
}) => RemoteDesktopErrorKind::LogonFailure,
58-
ConnectorErrorKind::AccessDenied => RemoteDesktopErrorKind::AccessDenied,
59-
_ => RemoteDesktopErrorKind::General,
57+
}) => IronErrorKind::LogonFailure,
58+
ConnectorErrorKind::AccessDenied => IronErrorKind::AccessDenied,
59+
_ => IronErrorKind::General,
6060
};
6161

6262
Self {
@@ -66,19 +66,19 @@ impl From<connector::ConnectorError> for RemoteDesktopError {
6666
}
6767
}
6868

69-
impl From<ironrdp::session::SessionError> for RemoteDesktopError {
69+
impl From<ironrdp::session::SessionError> for IronError {
7070
fn from(e: ironrdp::session::SessionError) -> Self {
7171
Self {
72-
kind: RemoteDesktopErrorKind::General,
72+
kind: IronErrorKind::General,
7373
source: anyhow::Error::new(e),
7474
}
7575
}
7676
}
7777

78-
impl From<anyhow::Error> for RemoteDesktopError {
78+
impl From<anyhow::Error> for IronError {
7979
fn from(e: anyhow::Error) -> Self {
8080
Self {
81-
kind: RemoteDesktopErrorKind::General,
81+
kind: IronErrorKind::General,
8282
source: e,
8383
}
8484
}

crates/ironrdp-web/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct InputTransaction(pub(crate) SmallVec<[Operation; 3]>);
6161

6262
#[wasm_bindgen]
6363
impl InputTransaction {
64-
pub fn construct() -> Self {
64+
pub fn init() -> Self {
6565
Self(SmallVec::new())
6666
}
6767

crates/ironrdp-web/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct DesktopSize {
6969

7070
#[wasm_bindgen]
7171
impl DesktopSize {
72-
pub fn construct(width: u16, height: u16) -> Self {
72+
pub fn init(width: u16, height: u16) -> Self {
7373
DesktopSize { width, height }
7474
}
7575
}

crates/ironrdp-web/src/session.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use web_sys::HtmlCanvasElement;
3737

3838
use crate::canvas::Canvas;
3939
use crate::clipboard::{ClipboardTransaction, WasmClipboard, WasmClipboardBackend, WasmClipboardBackendMessage};
40-
use crate::error::{RemoteDesktopError, RemoteDesktopErrorKind};
40+
use crate::error::{IronError, IronErrorKind};
4141
use crate::image::extract_partial_image;
4242
use crate::input::InputTransaction;
4343
use crate::network_client::WasmNetworkClient;
@@ -103,7 +103,7 @@ impl Default for SessionBuilderInner {
103103

104104
#[wasm_bindgen]
105105
impl SessionBuilder {
106-
pub fn construct() -> SessionBuilder {
106+
pub fn init() -> SessionBuilder {
107107
Self(Rc::new(RefCell::new(SessionBuilderInner::default())))
108108
}
109109

@@ -220,7 +220,7 @@ impl SessionBuilder {
220220
self.clone()
221221
}
222222

223-
pub async fn connect(&self) -> Result<Session, RemoteDesktopError> {
223+
pub async fn connect(&self) -> Result<Session, IronError> {
224224
let (
225225
username,
226226
destination,
@@ -295,11 +295,11 @@ impl SessionBuilder {
295295
loop {
296296
match ws.state() {
297297
websocket::State::Closing | websocket::State::Closed => {
298-
return Err(RemoteDesktopError::from(anyhow::anyhow!(
298+
return Err(IronError::from(anyhow::anyhow!(
299299
"failed to connect to {proxy_address} (WebSocket is `{:?}`)",
300300
ws.state()
301301
))
302-
.with_kind(RemoteDesktopErrorKind::ProxyConnect));
302+
.with_kind(IronErrorKind::ProxyConnect));
303303
}
304304
websocket::State::Connecting => {
305305
trace!("WebSocket is connecting to proxy at {proxy_address}...");
@@ -417,7 +417,7 @@ pub struct Session {
417417

418418
#[wasm_bindgen]
419419
impl Session {
420-
pub async fn run(&self) -> Result<SessionTerminationInfo, RemoteDesktopError> {
420+
pub async fn run(&self) -> Result<SessionTerminationInfo, IronError> {
421421
let rdp_reader = self
422422
.rdp_reader
423423
.borrow_mut()
@@ -712,17 +712,17 @@ impl Session {
712712
}
713713
}
714714

715-
pub fn apply_inputs(&self, transaction: InputTransaction) -> Result<(), RemoteDesktopError> {
715+
pub fn apply_inputs(&self, transaction: InputTransaction) -> Result<(), IronError> {
716716
let inputs = self.input_database.borrow_mut().apply(transaction);
717717
self.h_send_inputs(inputs)
718718
}
719719

720-
pub fn release_all_inputs(&self) -> Result<(), RemoteDesktopError> {
720+
pub fn release_all_inputs(&self) -> Result<(), IronError> {
721721
let inputs = self.input_database.borrow_mut().release_all();
722722
self.h_send_inputs(inputs)
723723
}
724724

725-
fn h_send_inputs(&self, inputs: smallvec::SmallVec<[FastPathInputEvent; 2]>) -> Result<(), RemoteDesktopError> {
725+
fn h_send_inputs(&self, inputs: smallvec::SmallVec<[FastPathInputEvent; 2]>) -> Result<(), IronError> {
726726
if !inputs.is_empty() {
727727
trace!("Inputs: {inputs:?}");
728728

@@ -740,7 +740,7 @@ impl Session {
740740
num_lock: bool,
741741
caps_lock: bool,
742742
kana_lock: bool,
743-
) -> Result<(), RemoteDesktopError> {
743+
) -> Result<(), IronError> {
744744
use ironrdp::pdu::input::fast_path::FastPathInput;
745745

746746
let event = ironrdp::input::synchronize_event(scroll_lock, num_lock, caps_lock, kana_lock);
@@ -755,15 +755,15 @@ impl Session {
755755
Ok(())
756756
}
757757

758-
pub fn shutdown(&self) -> Result<(), RemoteDesktopError> {
758+
pub fn shutdown(&self) -> Result<(), IronError> {
759759
self.input_events_tx
760760
.unbounded_send(RdpInputEvent::TerminateSession)
761761
.context("failed to send terminate session event to writer task")?;
762762

763763
Ok(())
764764
}
765765

766-
pub async fn on_clipboard_paste(&self, content: ClipboardTransaction) -> Result<(), RemoteDesktopError> {
766+
pub async fn on_clipboard_paste(&self, content: ClipboardTransaction) -> Result<(), IronError> {
767767
self.input_events_tx
768768
.unbounded_send(RdpInputEvent::ClipboardBackend(
769769
WasmClipboardBackendMessage::LocalClipboardChanged(content),
@@ -773,7 +773,7 @@ impl Session {
773773
Ok(())
774774
}
775775

776-
fn set_cursor_style(&self, style: CursorStyle) -> Result<(), RemoteDesktopError> {
776+
fn set_cursor_style(&self, style: CursorStyle) -> Result<(), IronError> {
777777
let (kind, data, hotspot_x, hotspot_y) = match style {
778778
CursorStyle::Default => ("default", None, None, None),
779779
CursorStyle::Hidden => ("hidden", None, None, None),
@@ -824,7 +824,7 @@ impl Session {
824824
false
825825
}
826826

827-
pub fn extension_call(_value: JsValue) -> Result<JsValue, RemoteDesktopError> {
827+
pub fn extension_call(_value: JsValue) -> Result<JsValue, IronError> {
828828
Ok(JsValue::null())
829829
}
830830
}
@@ -922,7 +922,7 @@ async fn connect(
922922
clipboard_backend,
923923
use_display_control,
924924
}: ConnectParams,
925-
) -> Result<(connector::ConnectionResult, WebSocket), RemoteDesktopError> {
925+
) -> Result<(connector::ConnectionResult, WebSocket), IronError> {
926926
let mut framed = ironrdp_futures::LocalFuturesFramed::new(ws);
927927

928928
let mut connector = ClientConnector::new(config);
@@ -969,7 +969,7 @@ async fn connect_rdcleanpath<S>(
969969
destination: String,
970970
proxy_auth_token: String,
971971
pcb: Option<String>,
972-
) -> Result<(ironrdp_futures::Upgraded, Vec<u8>), RemoteDesktopError>
972+
) -> Result<(ironrdp_futures::Upgraded, Vec<u8>), IronError>
973973
where
974974
S: ironrdp_futures::FramedRead + FramedWrite,
975975
{
@@ -1048,10 +1048,10 @@ where
10481048
server_addr,
10491049
} => (x224_connection_response, server_cert_chain, server_addr),
10501050
ironrdp_rdcleanpath::RDCleanPath::Err(error) => {
1051-
return Err(RemoteDesktopError::from(
1052-
anyhow::Error::new(error).context("received an RDCleanPath error"),
1053-
)
1054-
.with_kind(RemoteDesktopErrorKind::RDCleanPath));
1051+
return Err(
1052+
IronError::from(anyhow::Error::new(error).context("received an RDCleanPath error"))
1053+
.with_kind(IronErrorKind::RDCleanPath),
1054+
);
10551055
}
10561056
};
10571057

web-client/iron-remote-desktop-rdp/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import init, {
33
DesktopSize,
44
DeviceEvent,
55
InputTransaction,
6-
RemoteDesktopError,
6+
IronError,
77
Session,
88
SessionBuilder,
99
SessionTerminationInfo,
@@ -17,7 +17,7 @@ export default {
1717
DesktopSize,
1818
DeviceEvent,
1919
InputTransaction,
20-
RemoteDesktopError,
20+
IronError,
2121
SessionBuilder,
2222
ClipboardTransaction,
2323
ClipboardContent,

web-client/iron-remote-desktop/src/interfaces/ClipboardTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ClipboardContent } from './ClipboardContent';
22

33
export interface ClipboardTransaction {
4-
construct(): ClipboardTransaction;
4+
init(): ClipboardTransaction;
55
add_content(content: ClipboardContent): void;
66
is_empty(): boolean;
77
content(): Array<ClipboardContent>;

web-client/iron-remote-desktop/src/interfaces/DesktopSize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
width: number;
33
height: number;
44

5-
construct(width: number, height: number): DesktopSize;
5+
init(width: number, height: number): DesktopSize;
66
}

0 commit comments

Comments
 (0)