Skip to content

Commit aef4b92

Browse files
refactor(web-client): refactor WASM interfaces to remove static consructor functions (#775)
1 parent d8ab533 commit aef4b92

File tree

14 files changed

+63
-108
lines changed

14 files changed

+63
-108
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
import init, {
1+
import wasm_init, {
22
setup,
33
DesktopSize,
44
DeviceEvent,
55
InputTransaction,
6-
IronError,
7-
Session,
86
SessionBuilder,
9-
SessionTerminationInfo,
107
ClipboardData,
11-
ClipboardItem,
128
Extension,
139
} from '../../../crates/ironrdp-web/pkg/ironrdp_web';
1410

15-
export default {
16-
init,
17-
setup,
18-
DesktopSize,
19-
DeviceEvent,
20-
InputTransaction,
21-
IronError,
22-
SessionBuilder,
23-
ClipboardData,
24-
ClipboardItem,
25-
Session,
26-
SessionTerminationInfo,
27-
Extension,
11+
export async function init(log_level: string) {
12+
await wasm_init();
13+
setup(log_level);
14+
}
15+
16+
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,
2829
};
2930

3031
export function preConnectionBlob(pcb: string): Extension {

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

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

33
export interface ClipboardData {
4-
init(): ClipboardData;
54
add_text(mime_type: string, text: string): void;
65
add_binary(mime_type: string, binary: Uint8Array): void;
76
items(): ClipboardItem[];
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export interface DesktopSize {
22
width: number;
33
height: number;
4-
5-
init(width: number, height: number): DesktopSize;
64
}
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
export interface DeviceEvent {
2-
mouse_button_pressed(button: number): DeviceEvent;
3-
mouse_button_released(button: number): DeviceEvent;
4-
mouse_move(x: number, y: number): DeviceEvent;
5-
wheel_rotations(vertical: boolean, rotation_units: number): DeviceEvent;
6-
key_pressed(scancode: number): DeviceEvent;
7-
key_released(scancode: number): DeviceEvent;
8-
unicode_pressed(unicode: string): DeviceEvent;
9-
unicode_released(unicode: string): DeviceEvent;
10-
}
1+
export type DeviceEvent = unknown;
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import type { DesktopSize } from './DesktopSize';
22
import type { DeviceEvent } from './DeviceEvent';
33
import type { InputTransaction } from './InputTransaction';
4-
import type { IronError } from './session-event';
5-
import type { Session } from './Session';
64
import type { SessionBuilder } from './SessionBuilder';
7-
import type { SessionTerminationInfo } from './SessionTerminationInfo';
85
import type { ClipboardData } from './ClipboardData';
9-
import type { ClipboardItem } from './ClipboardItem';
106

117
export interface RemoteDesktopModule {
12-
init: () => Promise<unknown>;
13-
setup: (logLevel: string) => void;
14-
DesktopSize: DesktopSize;
15-
DeviceEvent: DeviceEvent;
16-
InputTransaction: InputTransaction;
17-
RemoteDesktopError: IronError;
18-
Session: Session;
19-
SessionBuilder: SessionBuilder;
20-
SessionTerminationInfo: SessionTerminationInfo;
21-
ClipboardData: ClipboardData;
22-
ClipboardItem: ClipboardItem;
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;
2320
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { DesktopSize } from './DesktopSize';
33
import type { ClipboardData } from './ClipboardData';
44

55
export interface SessionBuilder {
6-
init(): SessionBuilder;
76
/**
87
* Required
98
*/

web-client/iron-remote-desktop/src/iron-remote-desktop.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { onMount } from 'svelte';
1818
import { loggingService } from './services/logging.service';
1919
import { RemoteDesktopService } from './services/remote-desktop.service';
20-
import { LogType } from './enums/LogType';
2120
import type { ResizeEvent } from './interfaces/ResizeEvent';
2221
import { PublicAPI } from './services/PublicAPI';
2322
import { ScreenScale } from './enums/ScreenScale';
@@ -27,13 +26,11 @@
2726
let {
2827
scale,
2928
verbose,
30-
debugwasm,
3129
flexcenter,
3230
module,
3331
}: {
3432
scale: string;
3533
verbose: 'true' | 'false';
36-
debugwasm: 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'TRACE';
3734
flexcenter: string;
3835
module: RemoteDesktopModule;
3936
} = $props();
@@ -667,8 +664,6 @@
667664
canvas.width = 800;
668665
canvas.height = 600;
669666
670-
const logLevel = LogType[debugwasm] ?? LogType.INFO;
671-
await remoteDesktopService.init(logLevel);
672667
remoteDesktopService.setCanvas(canvas);
673668
674669
initListeners();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export * as default from './iron-remote-desktop.svelte';
22
export type { ResizeEvent } from './interfaces/ResizeEvent';
33
export type { NewSessionInfo } from './interfaces/NewSessionInfo';
44
export type { ServerRect } from './interfaces/ServerRect';
5-
export type { DesktopSize } from './interfaces/DesktopSize';
65
export type { SessionEvent, IronError, IronErrorKind } from './interfaces/session-event';
76
export type { SessionEventType } from './enums/SessionEventType';
87
export type { SessionTerminationInfo } from './interfaces/SessionTerminationInfo';

web-client/iron-remote-desktop/src/services/remote-desktop.service.ts

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { BehaviorSubject, from, Observable, of, Subject } from 'rxjs';
22
import { loggingService } from './logging.service';
33
import { catchError, filter, map } from 'rxjs/operators';
44
import { scanCode } from '../lib/scancodes';
5-
import { LogType } from '../enums/LogType';
65
import { OS } from '../enums/OS';
76
import { ModifierKey } from '../enums/ModifierKey';
87
import { LockKey } from '../enums/LockKey';
@@ -65,14 +64,7 @@ export class RemoteDesktopService {
6564
}
6665

6766
createClipboardData(): ClipboardData {
68-
return this.module.ClipboardData.init();
69-
}
70-
71-
async init(debug: LogType) {
72-
loggingService.info('Load wasm file...');
73-
await this.module.init();
74-
loggingService.info('Initialize the remote desktop module...');
75-
this.module.setup(LogType[debug]);
67+
return this.module.createClipboardData();
7668
}
7769

7870
// If set to false, the clipboard will not be enabled and the callbacks will not be registered to the Rust side
@@ -116,14 +108,12 @@ export class RemoteDesktopService {
116108
if (preventDefault) {
117109
event.preventDefault(); // prevent default behavior (context menu, etc)
118110
}
119-
const mouseFnc = isDown
120-
? this.module.DeviceEvent.mouse_button_pressed
121-
: this.module.DeviceEvent.mouse_button_released;
111+
const mouseFnc = isDown ? this.module.createMouseButtonPressed : this.module.createMouseButtonReleased;
122112
this.doTransactionFromDeviceEvents([mouseFnc(event.button)]);
123113
}
124114

125115
updateMousePosition(position: MousePosition) {
126-
this.doTransactionFromDeviceEvents([this.module.DeviceEvent.mouse_move(position.x, position.y)]);
116+
this.doTransactionFromDeviceEvents([this.module.createMouseMove(position.x, position.y)]);
127117
this.mousePosition.next(position);
128118
}
129119

@@ -132,7 +122,7 @@ export class RemoteDesktopService {
132122
}
133123

134124
connect(config: Config): Observable<NewSessionInfo> {
135-
const sessionBuilder = this.module.SessionBuilder.init();
125+
const sessionBuilder = this.module.createSessionBuilder();
136126

137127
sessionBuilder.proxy_address(config.proxyAddress);
138128
sessionBuilder.destination(config.destination);
@@ -160,7 +150,7 @@ export class RemoteDesktopService {
160150

161151
if (config.desktopSize != null) {
162152
sessionBuilder.desktop_size(
163-
this.module.DesktopSize.init(config.desktopSize.width, config.desktopSize.height),
153+
this.module.createDesktopSize(config.desktopSize.width, config.desktopSize.height),
164154
);
165155
}
166156

@@ -242,7 +232,7 @@ export class RemoteDesktopService {
242232
mouseWheel(event: WheelEvent) {
243233
const vertical = event.deltaY !== 0;
244234
const rotation = vertical ? event.deltaY : event.deltaX;
245-
this.doTransactionFromDeviceEvents([this.module.DeviceEvent.wheel_rotations(vertical, -rotation)]);
235+
this.doTransactionFromDeviceEvents([this.module.createWheelRotations(vertical, -rotation)]);
246236
}
247237

248238
setVisibility(state: boolean) {
@@ -273,7 +263,7 @@ export class RemoteDesktopService {
273263

274264
onClipboardChangedEmpty(): Promise<void> {
275265
const onClipboardChangedPromise = async () => {
276-
await this.session?.on_clipboard_paste(this.module.ClipboardData.init());
266+
await this.session?.on_clipboard_paste(this.module.createClipboardData());
277267
};
278268
return onClipboardChangedPromise();
279269
}
@@ -318,11 +308,11 @@ export class RemoteDesktopService {
318308
let unicodeEvent;
319309

320310
if (evt.type === 'keydown') {
321-
keyEvent = this.module.DeviceEvent.key_pressed;
322-
unicodeEvent = this.module.DeviceEvent.unicode_pressed;
311+
keyEvent = this.module.createKeyPressed;
312+
unicodeEvent = this.module.createUnicodePressed;
323313
} else if (evt.type === 'keyup') {
324-
keyEvent = this.module.DeviceEvent.key_released;
325-
unicodeEvent = this.module.DeviceEvent.unicode_released;
314+
keyEvent = this.module.createKeyReleased;
315+
unicodeEvent = this.module.createUnicodeReleased;
326316
}
327317

328318
let sendAsUnicode = true;
@@ -453,7 +443,7 @@ export class RemoteDesktopService {
453443
}
454444

455445
private doTransactionFromDeviceEvents(deviceEvents: DeviceEvent[]) {
456-
const transaction = this.module.InputTransaction.init();
446+
const transaction = this.module.createInputTransaction();
457447
deviceEvents.forEach((event) => transaction.add_event(event));
458448
this.session?.apply_inputs(transaction);
459449
}
@@ -464,21 +454,18 @@ export class RemoteDesktopService {
464454
const suppr = parseInt('0xE053', 16);
465455

466456
this.doTransactionFromDeviceEvents([
467-
this.module.DeviceEvent.key_pressed(ctrl),
468-
this.module.DeviceEvent.key_pressed(alt),
469-
this.module.DeviceEvent.key_pressed(suppr),
470-
this.module.DeviceEvent.key_released(ctrl),
471-
this.module.DeviceEvent.key_released(alt),
472-
this.module.DeviceEvent.key_released(suppr),
457+
this.module.createKeyPressed(ctrl),
458+
this.module.createKeyPressed(alt),
459+
this.module.createKeyPressed(suppr),
460+
this.module.createKeyReleased(ctrl),
461+
this.module.createKeyReleased(alt),
462+
this.module.createKeyReleased(suppr),
473463
]);
474464
}
475465

476466
private sendMeta() {
477467
const meta = parseInt('0xE05B', 16);
478468

479-
this.doTransactionFromDeviceEvents([
480-
this.module.DeviceEvent.key_pressed(meta),
481-
this.module.DeviceEvent.key_released(meta),
482-
]);
469+
this.doTransactionFromDeviceEvents([this.module.createKeyPressed(meta), this.module.createKeyReleased(meta)]);
483470
}
484471
}

web-client/iron-svelte-client/src/lib/login/login.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { currentSession, userInteractionService } from '../../services/session.service';
33
import { catchError, filter } from 'rxjs/operators';
44
import type { UserInteraction, NewSessionInfo } from '../../../static/iron-remote-desktop';
5-
import { preConnectionBlob, displayControl, kdcProxyUrl } from '../../../static/iron-remote-desktop-rdp';
5+
import { preConnectionBlob, displayControl, kdcProxyUrl, init } from '../../../static/iron-remote-desktop-rdp';
66
import { from, of } from 'rxjs';
77
import { toast } from '$lib/messages/message-store';
88
import { showLogin } from '$lib/login/login-store';
9-
import { DesktopSize } from '../../models/desktop-size';
9+
import { onMount } from 'svelte';
1010
1111
let username = 'Administrator';
1212
let password = 'DevoLabs123!';
@@ -15,7 +15,7 @@
1515
let domain = '';
1616
let authtoken = '';
1717
let kdc_proxy_url = '';
18-
let desktopSize = new DesktopSize(1280, 768);
18+
let desktopSize = { width: 1280, height: 720 };
1919
let pcb = '';
2020
let pop_up = false;
2121
let enable_clipboard = true;
@@ -171,6 +171,10 @@
171171
}
172172
});
173173
};
174+
175+
onMount(async () => {
176+
await init('INFO');
177+
});
174178
</script>
175179

176180
<main class="responsive login-container">

web-client/iron-svelte-client/src/lib/popup-screen/popup-screen.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onMount } from 'svelte';
33
import { setCurrentSessionActive, userInteractionService } from '../../services/session.service';
44
import type { UserInteraction } from '../../../static/iron-remote-desktop';
5-
import IronRdp from '../../../static/iron-remote-desktop-rdp';
5+
import { Backend } from '../../../static/iron-remote-desktop-rdp';
66
import { preConnectionBlob, displayControl, kdcProxyUrl } from '../../../static/iron-remote-desktop-rdp';
77
88
let userInteraction: UserInteraction;
@@ -146,7 +146,7 @@
146146
</label>
147147
</div>
148148
</div>
149-
<iron-remote-desktop debugwasm="INFO" verbose="true" scale="fit" flexcenter="true" module={IronRdp} />
149+
<iron-remote-desktop verbose="true" scale="fit" flexcenter="true" module={Backend} />
150150
</div>
151151

152152
<style>

web-client/iron-svelte-client/src/lib/remote-screen/remote-screen.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { setCurrentSessionActive, userInteractionService } from '../../services/session.service';
44
import { showLogin } from '$lib/login/login-store';
55
import type { UserInteraction } from '../../../static/iron-remote-desktop';
6-
import IronRdp from '../../../static/iron-remote-desktop-rdp';
6+
import { Backend } from '../../../static/iron-remote-desktop-rdp';
77
88
let uiService: UserInteraction;
99
let cursorOverrideActive = false;
@@ -101,7 +101,7 @@
101101
</div>
102102
{/if}
103103
</div>
104-
<iron-remote-desktop debugwasm="INFO" verbose="true" scale="fit" flexcenter="true" module={IronRdp} />
104+
<iron-remote-desktop verbose="true" scale="fit" flexcenter="true" module={Backend} />
105105
</div>
106106

107107
<style>

web-client/iron-svelte-client/src/models/desktop-size.ts

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

web-client/iron-svelte-client/src/models/session.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Guid } from 'guid-typescript';
2-
import type { DesktopSize } from './desktop-size';
32

43
export class Session {
54
id: Guid;
65
sessionId!: number;
76
name?: string;
87
active!: boolean;
9-
desktopSize!: DesktopSize;
8+
desktopSize!: { width: number; height: number };
109

1110
constructor(name?: string) {
1211
this.id = Guid.create();

0 commit comments

Comments
 (0)