Skip to content

Commit 24e64d7

Browse files
authored
refactor(web): consolidate WASM object constructors as create (#776)
1 parent aef4b92 commit 24e64d7

25 files changed

+174
-192
lines changed

crates/iron-remote-desktop/src/clipboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use wasm_bindgen::JsValue;
33
pub trait ClipboardData {
44
type Item: ClipboardItem;
55

6-
fn init() -> Self;
6+
fn create() -> Self;
77
fn add_text(&mut self, mime_type: &str, text: &str);
88
fn add_binary(&mut self, mime_type: &str, binary: &[u8]);
99
fn items(&self) -> &[Self::Item];

crates/iron-remote-desktop/src/desktop_size.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ pub struct DesktopSize {
99

1010
#[wasm_bindgen]
1111
impl DesktopSize {
12-
pub fn init(width: u16, height: u16) -> Self {
12+
#[wasm_bindgen(constructor)]
13+
pub fn create(width: u16, height: u16) -> Self {
1314
DesktopSize { width, height }
1415
}
1516
}

crates/iron-remote-desktop/src/extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct Extension {
4848
#[wasm_bindgen]
4949
impl Extension {
5050
#[wasm_bindgen(constructor)]
51-
pub fn new(ident: String, value: JsValue) -> Self {
51+
pub fn create(ident: String, value: JsValue) -> Self {
5252
Self { ident, value }
5353
}
5454
}

crates/iron-remote-desktop/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ pub trait DeviceEvent {
1212
pub trait InputTransaction {
1313
type DeviceEvent: DeviceEvent;
1414

15-
fn init() -> Self;
15+
fn create() -> Self;
1616
fn add_event(&mut self, event: Self::DeviceEvent);
1717
}

crates/iron-remote-desktop/src/lib.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,22 @@ macro_rules! make_bridge {
129129
self.0.run().await.map(SessionTerminationInfo).map_err(IronError)
130130
}
131131

132+
#[wasm_bindgen(js_name = desktopSize)]
132133
pub fn desktop_size(&self) -> $crate::DesktopSize {
133134
self.0.desktop_size()
134135
}
135136

137+
#[wasm_bindgen(js_name = applyInputs)]
136138
pub fn apply_inputs(&self, transaction: InputTransaction) -> Result<(), IronError> {
137139
self.0.apply_inputs(transaction.0).map_err(IronError)
138140
}
139141

142+
#[wasm_bindgen(js_name = releaseAllInputs)]
140143
pub fn release_all_inputs(&self) -> Result<(), IronError> {
141144
self.0.release_all_inputs().map_err(IronError)
142145
}
143146

147+
#[wasm_bindgen(js_name = synchronizeLockKeys)]
144148
pub fn synchronize_lock_keys(
145149
&self,
146150
scroll_lock: bool,
@@ -157,6 +161,7 @@ macro_rules! make_bridge {
157161
self.0.shutdown().map_err(IronError)
158162
}
159163

164+
#[wasm_bindgen(js_name = onClipboardPaste)]
160165
pub async fn on_clipboard_paste(&self, content: ClipboardData) -> Result<(), IronError> {
161166
self.0.on_clipboard_paste(content.0).await.map_err(IronError)
162167
}
@@ -173,10 +178,12 @@ macro_rules! make_bridge {
173178
.resize(width, height, scale_factor, physical_width, physical_height);
174179
}
175180

181+
#[wasm_bindgen(js_name = supportsUnicodeKeyboardShortcuts)]
176182
pub fn supports_unicode_keyboard_shortcuts(&self) -> bool {
177183
self.0.supports_unicode_keyboard_shortcuts()
178184
}
179185

186+
#[wasm_bindgen(js_name = extensionCall)]
180187
pub fn extension_call(
181188
ext: $crate::Extension,
182189
) -> Result<$crate::internal::wasm_bindgen::JsValue, IronError> {
@@ -187,8 +194,9 @@ macro_rules! make_bridge {
187194
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
188195
#[doc(hidden)]
189196
impl SessionBuilder {
190-
pub fn init() -> Self {
191-
Self(<<$api as $crate::RemoteDesktopApi>::SessionBuilder>::init())
197+
#[wasm_bindgen(constructor)]
198+
pub fn create() -> Self {
199+
Self(<<$api as $crate::RemoteDesktopApi>::SessionBuilder>::create())
192200
}
193201

194202
pub fn username(&self, username: String) -> Self {
@@ -199,6 +207,7 @@ macro_rules! make_bridge {
199207
Self(self.0.destination(destination))
200208
}
201209

210+
#[wasm_bindgen(js_name = serverDomain)]
202211
pub fn server_domain(&self, server_domain: String) -> Self {
203212
Self(self.0.server_domain(server_domain))
204213
}
@@ -207,44 +216,53 @@ macro_rules! make_bridge {
207216
Self(self.0.password(password))
208217
}
209218

219+
#[wasm_bindgen(js_name = proxyAddress)]
210220
pub fn proxy_address(&self, address: String) -> Self {
211221
Self(self.0.proxy_address(address))
212222
}
213223

224+
#[wasm_bindgen(js_name = authToken)]
214225
pub fn auth_token(&self, token: String) -> Self {
215226
Self(self.0.auth_token(token))
216227
}
217228

229+
#[wasm_bindgen(js_name = desktopSize)]
218230
pub fn desktop_size(&self, desktop_size: $crate::DesktopSize) -> Self {
219231
Self(self.0.desktop_size(desktop_size))
220232
}
221233

234+
#[wasm_bindgen(js_name = renderCanvas)]
222235
pub fn render_canvas(&self, canvas: $crate::internal::web_sys::HtmlCanvasElement) -> Self {
223236
Self(self.0.render_canvas(canvas))
224237
}
225238

239+
#[wasm_bindgen(js_name = setCursorStyleCallback)]
226240
pub fn set_cursor_style_callback(&self, callback: $crate::internal::web_sys::js_sys::Function) -> Self {
227241
Self(self.0.set_cursor_style_callback(callback))
228242
}
229243

244+
#[wasm_bindgen(js_name = setCursorStyleCallbackContext)]
230245
pub fn set_cursor_style_callback_context(&self, context: $crate::internal::wasm_bindgen::JsValue) -> Self {
231246
Self(self.0.set_cursor_style_callback_context(context))
232247
}
233248

249+
#[wasm_bindgen(js_name = remoteClipboardChangedCallback)]
234250
pub fn remote_clipboard_changed_callback(
235251
&self,
236252
callback: $crate::internal::web_sys::js_sys::Function,
237253
) -> Self {
238254
Self(self.0.remote_clipboard_changed_callback(callback))
239255
}
240256

257+
#[wasm_bindgen(js_name = remoteReceivedFormatListCallback)]
241258
pub fn remote_received_format_list_callback(
242259
&self,
243260
callback: $crate::internal::web_sys::js_sys::Function,
244261
) -> Self {
245262
Self(self.0.remote_received_format_list_callback(callback))
246263
}
247264

265+
#[wasm_bindgen(js_name = forceClipboardUpdateCallback)]
248266
pub fn force_clipboard_update_callback(
249267
&self,
250268
callback: $crate::internal::web_sys::js_sys::Function,
@@ -272,40 +290,48 @@ macro_rules! make_bridge {
272290
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
273291
#[doc(hidden)]
274292
impl DeviceEvent {
293+
#[wasm_bindgen(js_name = mouseButtonPressed)]
275294
pub fn mouse_button_pressed(button: u8) -> Self {
276295
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_button_pressed(button))
277296
}
278297

298+
#[wasm_bindgen(js_name = mouseButtonReleased)]
279299
pub fn mouse_button_released(button: u8) -> Self {
280300
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_button_released(button))
281301
}
282302

303+
#[wasm_bindgen(js_name = mouseMove)]
283304
pub fn mouse_move(x: u16, y: u16) -> Self {
284305
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_move(
285306
x, y,
286307
))
287308
}
288309

310+
#[wasm_bindgen(js_name = wheelRotations)]
289311
pub fn wheel_rotations(vertical: bool, rotation_units: i16) -> Self {
290312
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::wheel_rotations(vertical, rotation_units))
291313
}
292314

315+
#[wasm_bindgen(js_name = keyPressed)]
293316
pub fn key_pressed(scancode: u16) -> Self {
294317
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::key_pressed(
295318
scancode,
296319
))
297320
}
298321

322+
#[wasm_bindgen(js_name = keyReleased)]
299323
pub fn key_released(scancode: u16) -> Self {
300324
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::key_released(
301325
scancode,
302326
))
303327
}
304328

329+
#[wasm_bindgen(js_name = unicodePressed)]
305330
pub fn unicode_pressed(unicode: char) -> Self {
306331
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::unicode_pressed(unicode))
307332
}
308333

334+
#[wasm_bindgen(js_name = unicodeReleased)]
309335
pub fn unicode_released(unicode: char) -> Self {
310336
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::unicode_released(unicode))
311337
}
@@ -314,10 +340,12 @@ macro_rules! make_bridge {
314340
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
315341
#[doc(hidden)]
316342
impl InputTransaction {
317-
pub fn init() -> Self {
318-
Self(<<$api as $crate::RemoteDesktopApi>::InputTransaction>::init())
343+
#[wasm_bindgen(constructor)]
344+
pub fn create() -> Self {
345+
Self(<<$api as $crate::RemoteDesktopApi>::InputTransaction>::create())
319346
}
320347

348+
#[wasm_bindgen(js_name = addEvent)]
321349
pub fn add_event(&mut self, event: DeviceEvent) {
322350
self.0.add_event(event.0);
323351
}
@@ -326,14 +354,17 @@ macro_rules! make_bridge {
326354
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
327355
#[doc(hidden)]
328356
impl ClipboardData {
329-
pub fn init() -> Self {
330-
Self(<<$api as $crate::RemoteDesktopApi>::ClipboardData>::init())
357+
#[wasm_bindgen(constructor)]
358+
pub fn create() -> Self {
359+
Self(<<$api as $crate::RemoteDesktopApi>::ClipboardData>::create())
331360
}
332361

362+
#[wasm_bindgen(js_name = addText)]
333363
pub fn add_text(&mut self, mime_type: &str, text: &str) {
334364
self.0.add_text(mime_type, text);
335365
}
336366

367+
#[wasm_bindgen(js_name = addBinary)]
337368
pub fn add_binary(&mut self, mime_type: &str, binary: &[u8]) {
338369
self.0.add_binary(mime_type, binary);
339370
}
@@ -342,6 +373,7 @@ macro_rules! make_bridge {
342373
self.0.items().into_iter().cloned().map(ClipboardItem).collect()
343374
}
344375

376+
#[wasm_bindgen(js_name = isEmpty)]
345377
pub fn is_empty(&self) -> bool {
346378
self.0.is_empty()
347379
}
@@ -350,6 +382,7 @@ macro_rules! make_bridge {
350382
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
351383
#[doc(hidden)]
352384
impl ClipboardItem {
385+
#[wasm_bindgen(js_name = mimeType)]
353386
pub fn mime_type(&self) -> String {
354387
self.0.mime_type().to_owned()
355388
}

crates/iron-remote-desktop/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait SessionBuilder {
1010
type Session: Session;
1111
type Error: IronError;
1212

13-
fn init() -> Self;
13+
fn create() -> Self;
1414
#[must_use]
1515
fn username(&self, username: String) -> Self;
1616
#[must_use]

crates/ironrdp-web/src/clipboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ impl ClipboardData {
613613
impl iron_remote_desktop::ClipboardData for ClipboardData {
614614
type Item = ClipboardItem;
615615

616-
fn init() -> Self {
616+
fn create() -> Self {
617617
Self::new()
618618
}
619619

crates/ironrdp-web/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) struct InputTransaction(pub(crate) SmallVec<[Operation; 3]>);
5858
impl iron_remote_desktop::InputTransaction for InputTransaction {
5959
type DeviceEvent = DeviceEvent;
6060

61-
fn init() -> Self {
61+
fn create() -> Self {
6262
Self(SmallVec::new())
6363
}
6464

crates/ironrdp-web/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
102102
type Session = Session;
103103
type Error = IronError;
104104

105-
fn init() -> Self {
105+
fn create() -> Self {
106106
Self(Rc::new(RefCell::new(SessionBuilderInner::default())))
107107
}
108108

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ export async function init(log_level: string) {
1414
}
1515

1616
export const Backend = {
17-
createDesktopSize: DesktopSize.init,
18-
createMouseButtonPressed: DeviceEvent.mouse_button_pressed,
19-
createMouseButtonReleased: DeviceEvent.mouse_button_released,
20-
createMouseMove: DeviceEvent.mouse_move,
21-
createWheelRotations: DeviceEvent.wheel_rotations,
22-
createKeyPressed: DeviceEvent.key_pressed,
23-
createKeyReleased: DeviceEvent.key_released,
24-
createUnicodePressed: DeviceEvent.unicode_pressed,
25-
createUnicodeReleased: DeviceEvent.unicode_released,
26-
createInputTransaction: InputTransaction.init,
27-
createSessionBuilder: SessionBuilder.init,
28-
createClipboardData: ClipboardData.init,
17+
DesktopSize: DesktopSize,
18+
InputTransaction: InputTransaction,
19+
SessionBuilder: SessionBuilder,
20+
ClipboardData: ClipboardData,
21+
DeviceEvent: DeviceEvent,
2922
};
3023

3124
export function preConnectionBlob(pcb: string): Extension {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ClipboardItem } from './ClipboardItem';
22

33
export interface ClipboardData {
4-
add_text(mime_type: string, text: string): void;
5-
add_binary(mime_type: string, binary: Uint8Array): void;
4+
addText(mimeType: string, text: string): void;
5+
addBinary(mimeType: string, binary: Uint8Array): void;
66
items(): ClipboardItem[];
7-
is_empty(): boolean;
7+
isEmpty(): boolean;
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface ClipboardItem {
2-
mime_type(): string;
2+
mimeType(): string;
33
value(): string | Uint8Array;
44
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DeviceEvent } from './DeviceEvent';
22

33
export interface InputTransaction {
4-
init(): InputTransaction;
5-
add_event(event: DeviceEvent): void;
4+
addEvent(event: DeviceEvent): void;
65
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DesktopSize } from './DesktopSize';
22

33
export interface NewSessionInfo {
4-
session_id: number;
5-
websocket_port: number;
6-
initial_desktop_size: DesktopSize;
4+
sessionId: number;
5+
websocketPort: number;
6+
initialDesktopSize: DesktopSize;
77
}

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import type { SessionBuilder } from './SessionBuilder';
55
import type { ClipboardData } from './ClipboardData';
66

77
export interface RemoteDesktopModule {
8-
createDesktopSize(width: number, height: number): DesktopSize;
9-
createMouseButtonPressed(button: number): DeviceEvent;
10-
createMouseButtonReleased(button: number): DeviceEvent;
11-
createMouseMove(x: number, y: number): DeviceEvent;
12-
createWheelRotations(vertical: boolean, rotation_units: number): DeviceEvent;
13-
createKeyPressed(scancode: number): DeviceEvent;
14-
createKeyReleased(scancode: number): DeviceEvent;
15-
createUnicodePressed(unicode: string): DeviceEvent;
16-
createUnicodeReleased(unicode: string): DeviceEvent;
17-
createInputTransaction(): InputTransaction;
18-
createSessionBuilder(): SessionBuilder;
19-
createClipboardData(): ClipboardData;
8+
DesktopSize: { new (width: number, height: number): DesktopSize };
9+
InputTransaction: { new (): InputTransaction };
10+
SessionBuilder: { new (): SessionBuilder };
11+
ClipboardData: { new (): ClipboardData };
12+
DeviceEvent: {
13+
mouseButtonPressed(button: number): DeviceEvent;
14+
mouseButtonReleased(button: number): DeviceEvent;
15+
mouseMove(x: number, y: number): DeviceEvent;
16+
wheelRotations(vertical: boolean, rotationUnits: number): DeviceEvent;
17+
keyPressed(scancode: number): DeviceEvent;
18+
keyReleased(scancode: number): DeviceEvent;
19+
unicodePressed(unicode: string): DeviceEvent;
20+
unicodeReleased(unicode: string): DeviceEvent;
21+
};
2022
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DesktopSize } from './DesktopSize';
22

33
export interface ResizeEvent {
4-
session_id: number;
5-
desktop_size: DesktopSize;
4+
sessionId: number;
5+
desktopSize: DesktopSize;
66
}

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

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

0 commit comments

Comments
 (0)