mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-07-07 17:45:01 +00:00
refactor(web): consolidate WASM object constructors as create (#776)
This commit is contained in:
parent
aef4b924aa
commit
24e64d7589
25 changed files with 174 additions and 192 deletions
|
@ -3,7 +3,7 @@ use wasm_bindgen::JsValue;
|
|||
pub trait ClipboardData {
|
||||
type Item: ClipboardItem;
|
||||
|
||||
fn init() -> Self;
|
||||
fn create() -> Self;
|
||||
fn add_text(&mut self, mime_type: &str, text: &str);
|
||||
fn add_binary(&mut self, mime_type: &str, binary: &[u8]);
|
||||
fn items(&self) -> &[Self::Item];
|
||||
|
|
|
@ -9,7 +9,8 @@ pub struct DesktopSize {
|
|||
|
||||
#[wasm_bindgen]
|
||||
impl DesktopSize {
|
||||
pub fn init(width: u16, height: u16) -> Self {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn create(width: u16, height: u16) -> Self {
|
||||
DesktopSize { width, height }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub struct Extension {
|
|||
#[wasm_bindgen]
|
||||
impl Extension {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(ident: String, value: JsValue) -> Self {
|
||||
pub fn create(ident: String, value: JsValue) -> Self {
|
||||
Self { ident, value }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ pub trait DeviceEvent {
|
|||
pub trait InputTransaction {
|
||||
type DeviceEvent: DeviceEvent;
|
||||
|
||||
fn init() -> Self;
|
||||
fn create() -> Self;
|
||||
fn add_event(&mut self, event: Self::DeviceEvent);
|
||||
}
|
||||
|
|
|
@ -129,18 +129,22 @@ macro_rules! make_bridge {
|
|||
self.0.run().await.map(SessionTerminationInfo).map_err(IronError)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = desktopSize)]
|
||||
pub fn desktop_size(&self) -> $crate::DesktopSize {
|
||||
self.0.desktop_size()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = applyInputs)]
|
||||
pub fn apply_inputs(&self, transaction: InputTransaction) -> Result<(), IronError> {
|
||||
self.0.apply_inputs(transaction.0).map_err(IronError)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = releaseAllInputs)]
|
||||
pub fn release_all_inputs(&self) -> Result<(), IronError> {
|
||||
self.0.release_all_inputs().map_err(IronError)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = synchronizeLockKeys)]
|
||||
pub fn synchronize_lock_keys(
|
||||
&self,
|
||||
scroll_lock: bool,
|
||||
|
@ -157,6 +161,7 @@ macro_rules! make_bridge {
|
|||
self.0.shutdown().map_err(IronError)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = onClipboardPaste)]
|
||||
pub async fn on_clipboard_paste(&self, content: ClipboardData) -> Result<(), IronError> {
|
||||
self.0.on_clipboard_paste(content.0).await.map_err(IronError)
|
||||
}
|
||||
|
@ -173,10 +178,12 @@ macro_rules! make_bridge {
|
|||
.resize(width, height, scale_factor, physical_width, physical_height);
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = supportsUnicodeKeyboardShortcuts)]
|
||||
pub fn supports_unicode_keyboard_shortcuts(&self) -> bool {
|
||||
self.0.supports_unicode_keyboard_shortcuts()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = extensionCall)]
|
||||
pub fn extension_call(
|
||||
ext: $crate::Extension,
|
||||
) -> Result<$crate::internal::wasm_bindgen::JsValue, IronError> {
|
||||
|
@ -187,8 +194,9 @@ macro_rules! make_bridge {
|
|||
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
|
||||
#[doc(hidden)]
|
||||
impl SessionBuilder {
|
||||
pub fn init() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::SessionBuilder>::init())
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn create() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::SessionBuilder>::create())
|
||||
}
|
||||
|
||||
pub fn username(&self, username: String) -> Self {
|
||||
|
@ -199,6 +207,7 @@ macro_rules! make_bridge {
|
|||
Self(self.0.destination(destination))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = serverDomain)]
|
||||
pub fn server_domain(&self, server_domain: String) -> Self {
|
||||
Self(self.0.server_domain(server_domain))
|
||||
}
|
||||
|
@ -207,30 +216,37 @@ macro_rules! make_bridge {
|
|||
Self(self.0.password(password))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = proxyAddress)]
|
||||
pub fn proxy_address(&self, address: String) -> Self {
|
||||
Self(self.0.proxy_address(address))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = authToken)]
|
||||
pub fn auth_token(&self, token: String) -> Self {
|
||||
Self(self.0.auth_token(token))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = desktopSize)]
|
||||
pub fn desktop_size(&self, desktop_size: $crate::DesktopSize) -> Self {
|
||||
Self(self.0.desktop_size(desktop_size))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = renderCanvas)]
|
||||
pub fn render_canvas(&self, canvas: $crate::internal::web_sys::HtmlCanvasElement) -> Self {
|
||||
Self(self.0.render_canvas(canvas))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = setCursorStyleCallback)]
|
||||
pub fn set_cursor_style_callback(&self, callback: $crate::internal::web_sys::js_sys::Function) -> Self {
|
||||
Self(self.0.set_cursor_style_callback(callback))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = setCursorStyleCallbackContext)]
|
||||
pub fn set_cursor_style_callback_context(&self, context: $crate::internal::wasm_bindgen::JsValue) -> Self {
|
||||
Self(self.0.set_cursor_style_callback_context(context))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = remoteClipboardChangedCallback)]
|
||||
pub fn remote_clipboard_changed_callback(
|
||||
&self,
|
||||
callback: $crate::internal::web_sys::js_sys::Function,
|
||||
|
@ -238,6 +254,7 @@ macro_rules! make_bridge {
|
|||
Self(self.0.remote_clipboard_changed_callback(callback))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = remoteReceivedFormatListCallback)]
|
||||
pub fn remote_received_format_list_callback(
|
||||
&self,
|
||||
callback: $crate::internal::web_sys::js_sys::Function,
|
||||
|
@ -245,6 +262,7 @@ macro_rules! make_bridge {
|
|||
Self(self.0.remote_received_format_list_callback(callback))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = forceClipboardUpdateCallback)]
|
||||
pub fn force_clipboard_update_callback(
|
||||
&self,
|
||||
callback: $crate::internal::web_sys::js_sys::Function,
|
||||
|
@ -272,40 +290,48 @@ macro_rules! make_bridge {
|
|||
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
|
||||
#[doc(hidden)]
|
||||
impl DeviceEvent {
|
||||
#[wasm_bindgen(js_name = mouseButtonPressed)]
|
||||
pub fn mouse_button_pressed(button: u8) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_button_pressed(button))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = mouseButtonReleased)]
|
||||
pub fn mouse_button_released(button: u8) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_button_released(button))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = mouseMove)]
|
||||
pub fn mouse_move(x: u16, y: u16) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::mouse_move(
|
||||
x, y,
|
||||
))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = wheelRotations)]
|
||||
pub fn wheel_rotations(vertical: bool, rotation_units: i16) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::wheel_rotations(vertical, rotation_units))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = keyPressed)]
|
||||
pub fn key_pressed(scancode: u16) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::key_pressed(
|
||||
scancode,
|
||||
))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = keyReleased)]
|
||||
pub fn key_released(scancode: u16) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::key_released(
|
||||
scancode,
|
||||
))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = unicodePressed)]
|
||||
pub fn unicode_pressed(unicode: char) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::unicode_pressed(unicode))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = unicodeReleased)]
|
||||
pub fn unicode_released(unicode: char) -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::DeviceEvent>::unicode_released(unicode))
|
||||
}
|
||||
|
@ -314,10 +340,12 @@ macro_rules! make_bridge {
|
|||
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
|
||||
#[doc(hidden)]
|
||||
impl InputTransaction {
|
||||
pub fn init() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::InputTransaction>::init())
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn create() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::InputTransaction>::create())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = addEvent)]
|
||||
pub fn add_event(&mut self, event: DeviceEvent) {
|
||||
self.0.add_event(event.0);
|
||||
}
|
||||
|
@ -326,14 +354,17 @@ macro_rules! make_bridge {
|
|||
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
|
||||
#[doc(hidden)]
|
||||
impl ClipboardData {
|
||||
pub fn init() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::ClipboardData>::init())
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn create() -> Self {
|
||||
Self(<<$api as $crate::RemoteDesktopApi>::ClipboardData>::create())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = addText)]
|
||||
pub fn add_text(&mut self, mime_type: &str, text: &str) {
|
||||
self.0.add_text(mime_type, text);
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = addBinary)]
|
||||
pub fn add_binary(&mut self, mime_type: &str, binary: &[u8]) {
|
||||
self.0.add_binary(mime_type, binary);
|
||||
}
|
||||
|
@ -342,6 +373,7 @@ macro_rules! make_bridge {
|
|||
self.0.items().into_iter().cloned().map(ClipboardItem).collect()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = isEmpty)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
@ -350,6 +382,7 @@ macro_rules! make_bridge {
|
|||
#[$crate::internal::wasm_bindgen::prelude::wasm_bindgen]
|
||||
#[doc(hidden)]
|
||||
impl ClipboardItem {
|
||||
#[wasm_bindgen(js_name = mimeType)]
|
||||
pub fn mime_type(&self) -> String {
|
||||
self.0.mime_type().to_owned()
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub trait SessionBuilder {
|
|||
type Session: Session;
|
||||
type Error: IronError;
|
||||
|
||||
fn init() -> Self;
|
||||
fn create() -> Self;
|
||||
#[must_use]
|
||||
fn username(&self, username: String) -> Self;
|
||||
#[must_use]
|
||||
|
|
|
@ -613,7 +613,7 @@ impl ClipboardData {
|
|||
impl iron_remote_desktop::ClipboardData for ClipboardData {
|
||||
type Item = ClipboardItem;
|
||||
|
||||
fn init() -> Self {
|
||||
fn create() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ pub(crate) struct InputTransaction(pub(crate) SmallVec<[Operation; 3]>);
|
|||
impl iron_remote_desktop::InputTransaction for InputTransaction {
|
||||
type DeviceEvent = DeviceEvent;
|
||||
|
||||
fn init() -> Self {
|
||||
fn create() -> Self {
|
||||
Self(SmallVec::new())
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
|
|||
type Session = Session;
|
||||
type Error = IronError;
|
||||
|
||||
fn init() -> Self {
|
||||
fn create() -> Self {
|
||||
Self(Rc::new(RefCell::new(SessionBuilderInner::default())))
|
||||
}
|
||||
|
||||
|
|
|
@ -14,18 +14,11 @@ export async function init(log_level: string) {
|
|||
}
|
||||
|
||||
export const Backend = {
|
||||
createDesktopSize: DesktopSize.init,
|
||||
createMouseButtonPressed: DeviceEvent.mouse_button_pressed,
|
||||
createMouseButtonReleased: DeviceEvent.mouse_button_released,
|
||||
createMouseMove: DeviceEvent.mouse_move,
|
||||
createWheelRotations: DeviceEvent.wheel_rotations,
|
||||
createKeyPressed: DeviceEvent.key_pressed,
|
||||
createKeyReleased: DeviceEvent.key_released,
|
||||
createUnicodePressed: DeviceEvent.unicode_pressed,
|
||||
createUnicodeReleased: DeviceEvent.unicode_released,
|
||||
createInputTransaction: InputTransaction.init,
|
||||
createSessionBuilder: SessionBuilder.init,
|
||||
createClipboardData: ClipboardData.init,
|
||||
DesktopSize: DesktopSize,
|
||||
InputTransaction: InputTransaction,
|
||||
SessionBuilder: SessionBuilder,
|
||||
ClipboardData: ClipboardData,
|
||||
DeviceEvent: DeviceEvent,
|
||||
};
|
||||
|
||||
export function preConnectionBlob(pcb: string): Extension {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import type { ClipboardItem } from './ClipboardItem';
|
||||
|
||||
export interface ClipboardData {
|
||||
add_text(mime_type: string, text: string): void;
|
||||
add_binary(mime_type: string, binary: Uint8Array): void;
|
||||
addText(mimeType: string, text: string): void;
|
||||
addBinary(mimeType: string, binary: Uint8Array): void;
|
||||
items(): ClipboardItem[];
|
||||
is_empty(): boolean;
|
||||
isEmpty(): boolean;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export interface ClipboardItem {
|
||||
mime_type(): string;
|
||||
mimeType(): string;
|
||||
value(): string | Uint8Array;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import type { DeviceEvent } from './DeviceEvent';
|
||||
|
||||
export interface InputTransaction {
|
||||
init(): InputTransaction;
|
||||
add_event(event: DeviceEvent): void;
|
||||
addEvent(event: DeviceEvent): void;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { DesktopSize } from './DesktopSize';
|
||||
|
||||
export interface NewSessionInfo {
|
||||
session_id: number;
|
||||
websocket_port: number;
|
||||
initial_desktop_size: DesktopSize;
|
||||
sessionId: number;
|
||||
websocketPort: number;
|
||||
initialDesktopSize: DesktopSize;
|
||||
}
|
||||
|
|
|
@ -5,16 +5,18 @@ import type { SessionBuilder } from './SessionBuilder';
|
|||
import type { ClipboardData } from './ClipboardData';
|
||||
|
||||
export interface RemoteDesktopModule {
|
||||
createDesktopSize(width: number, height: number): DesktopSize;
|
||||
createMouseButtonPressed(button: number): DeviceEvent;
|
||||
createMouseButtonReleased(button: number): DeviceEvent;
|
||||
createMouseMove(x: number, y: number): DeviceEvent;
|
||||
createWheelRotations(vertical: boolean, rotation_units: number): DeviceEvent;
|
||||
createKeyPressed(scancode: number): DeviceEvent;
|
||||
createKeyReleased(scancode: number): DeviceEvent;
|
||||
createUnicodePressed(unicode: string): DeviceEvent;
|
||||
createUnicodeReleased(unicode: string): DeviceEvent;
|
||||
createInputTransaction(): InputTransaction;
|
||||
createSessionBuilder(): SessionBuilder;
|
||||
createClipboardData(): ClipboardData;
|
||||
DesktopSize: { new (width: number, height: number): DesktopSize };
|
||||
InputTransaction: { new (): InputTransaction };
|
||||
SessionBuilder: { new (): SessionBuilder };
|
||||
ClipboardData: { new (): ClipboardData };
|
||||
DeviceEvent: {
|
||||
mouseButtonPressed(button: number): DeviceEvent;
|
||||
mouseButtonReleased(button: number): DeviceEvent;
|
||||
mouseMove(x: number, y: number): DeviceEvent;
|
||||
wheelRotations(vertical: boolean, rotationUnits: number): DeviceEvent;
|
||||
keyPressed(scancode: number): DeviceEvent;
|
||||
keyReleased(scancode: number): DeviceEvent;
|
||||
unicodePressed(unicode: string): DeviceEvent;
|
||||
unicodeReleased(unicode: string): DeviceEvent;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { DesktopSize } from './DesktopSize';
|
||||
|
||||
export interface ResizeEvent {
|
||||
session_id: number;
|
||||
desktop_size: DesktopSize;
|
||||
sessionId: number;
|
||||
desktopSize: DesktopSize;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
export interface ServerRect {
|
||||
bottom: number;
|
||||
left: number;
|
||||
right: number;
|
||||
top: number;
|
||||
|
||||
clone_buffer(): Uint8Array;
|
||||
}
|
|
@ -5,19 +5,19 @@ import type { ClipboardData } from './ClipboardData';
|
|||
|
||||
export interface Session {
|
||||
run(): Promise<SessionTerminationInfo>;
|
||||
desktop_size(): DesktopSize;
|
||||
apply_inputs(transaction: InputTransaction): void;
|
||||
release_all_inputs(): void;
|
||||
synchronize_lock_keys(scroll_lock: boolean, num_lock: boolean, caps_lock: boolean, kana_lock: boolean): void;
|
||||
extension_call(value: unknown): unknown;
|
||||
desktopSize(): DesktopSize;
|
||||
applyInputs(transaction: InputTransaction): void;
|
||||
releaseAllInputs(): void;
|
||||
synchronizeLockKeys(scrollLock: boolean, numLock: boolean, capsLock: boolean, kanaLock: boolean): void;
|
||||
extensionCall(value: unknown): unknown;
|
||||
shutdown(): void;
|
||||
on_clipboard_paste(data: ClipboardData): Promise<void>;
|
||||
onClipboardPaste(data: ClipboardData): Promise<void>;
|
||||
resize(
|
||||
width: number,
|
||||
height: number,
|
||||
scale_factor?: number | null,
|
||||
physical_width?: number | null,
|
||||
physical_height?: number | null,
|
||||
scaleFactor?: number | null,
|
||||
physicalWidth?: number | null,
|
||||
physicalHeight?: number | null,
|
||||
): void;
|
||||
supports_unicode_keyboard_shortcuts(): boolean;
|
||||
supportsUnicodeKeyboardShortcuts(): boolean;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export interface SessionBuilder {
|
|||
/**
|
||||
* Optional
|
||||
*/
|
||||
server_domain(server_domain: string): SessionBuilder;
|
||||
serverDomain(serverDomain: string): SessionBuilder;
|
||||
/**
|
||||
* Required
|
||||
*/
|
||||
|
@ -22,19 +22,19 @@ export interface SessionBuilder {
|
|||
/**
|
||||
* Required
|
||||
*/
|
||||
proxy_address(address: string): SessionBuilder;
|
||||
proxyAddress(address: string): SessionBuilder;
|
||||
/**
|
||||
* Required
|
||||
*/
|
||||
auth_token(token: string): SessionBuilder;
|
||||
authToken(token: string): SessionBuilder;
|
||||
/**
|
||||
* Optional
|
||||
*/
|
||||
desktop_size(desktop_size: DesktopSize): SessionBuilder;
|
||||
desktopSize(desktopSize: DesktopSize): SessionBuilder;
|
||||
/**
|
||||
* Optional
|
||||
*/
|
||||
render_canvas(canvas: HTMLCanvasElement): SessionBuilder;
|
||||
renderCanvas(canvas: HTMLCanvasElement): SessionBuilder;
|
||||
/**
|
||||
* Required.
|
||||
*
|
||||
|
@ -44,33 +44,33 @@ export interface SessionBuilder {
|
|||
* - `url` (custom cursor data URL); `cursor_data` contains the data URL with Base64-encoded
|
||||
* cursor bitmap; `hotspot_x` and `hotspot_y` are set to the cursor hotspot coordinates.
|
||||
*/
|
||||
set_cursor_style_callback(callback: SetCursorStyleCallback): SessionBuilder;
|
||||
setCursorStyleCallback(callback: SetCursorStyleCallback): SessionBuilder;
|
||||
/**
|
||||
* Required.
|
||||
*/
|
||||
set_cursor_style_callback_context(context: unknown): SessionBuilder;
|
||||
setCursorStyleCallbackContext(context: unknown): SessionBuilder;
|
||||
/**
|
||||
* Optional
|
||||
*/
|
||||
remote_clipboard_changed_callback(callback: RemoteClipboardChangedCallback): SessionBuilder;
|
||||
remoteClipboardChangedCallback(callback: RemoteClipboardChangedCallback): SessionBuilder;
|
||||
/**
|
||||
* Optional
|
||||
*/
|
||||
remote_received_format_list_callback(callback: RemoteReceiveForwardListCallback): SessionBuilder;
|
||||
remoteReceivedFormatListCallback(callback: RemoteReceiveForwardListCallback): SessionBuilder;
|
||||
/**
|
||||
* Optional
|
||||
*/
|
||||
force_clipboard_update_callback(callback: ForceClipboardUpdateCallback): SessionBuilder;
|
||||
forceClipboardUpdateCallback(callback: ForceClipboardUpdateCallback): SessionBuilder;
|
||||
extension(value: unknown): SessionBuilder;
|
||||
connect(): Promise<Session>;
|
||||
}
|
||||
|
||||
interface SetCursorStyleCallback {
|
||||
(
|
||||
cursor_kind: string,
|
||||
cursor_data: string | undefined,
|
||||
hotspot_x: number | undefined,
|
||||
hotspot_y: number | undefined,
|
||||
cursorKind: string,
|
||||
cursorData: string | undefined,
|
||||
hotspotX: number | undefined,
|
||||
hotspotY: number | undefined,
|
||||
): void;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface UserInteraction {
|
|||
|
||||
connect(config: Config): Promise<NewSessionInfo>;
|
||||
|
||||
setKeyboardUnicodeMode(use_unicode: boolean): void;
|
||||
setKeyboardUnicodeMode(useUnicode: boolean): void;
|
||||
|
||||
ctrlAltDel(): void;
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@
|
|||
let result = {} as Record<string, Blob>;
|
||||
|
||||
for (const item of data.items()) {
|
||||
let mime = item.mime_type();
|
||||
let mime = item.mimeType();
|
||||
let value = new Blob([item.value()], { type: mime });
|
||||
|
||||
result[mime] = value;
|
||||
|
@ -233,7 +233,7 @@
|
|||
if (!sameValue) {
|
||||
lastClientClipboardItems = values;
|
||||
|
||||
let data = remoteDesktopService.createClipboardData();
|
||||
let clipboardData = new module.ClipboardData();
|
||||
|
||||
// Iterate over `Record` type
|
||||
values.forEach((value: string | Uint8Array, key: string) => {
|
||||
|
@ -243,15 +243,15 @@
|
|||
}
|
||||
|
||||
if (key.startsWith('text/') && typeof value === 'string') {
|
||||
data.add_text(key, value);
|
||||
clipboardData.addText(key, value);
|
||||
} else if (key.startsWith('image/') && value instanceof Uint8Array) {
|
||||
data.add_binary(key, value);
|
||||
clipboardData.addBinary(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
if (!data.is_empty()) {
|
||||
lastClientClipboardData = data;
|
||||
remoteDesktopService.onClipboardChanged(data);
|
||||
if (!clipboardData.isEmpty()) {
|
||||
lastClientClipboardData = clipboardData;
|
||||
remoteDesktopService.onClipboardChanged(clipboardData);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -294,7 +294,7 @@
|
|||
ffRemoteClipboardData = null;
|
||||
for (const item of clipboard_data.items()) {
|
||||
// Firefox only supports text/plain mime type for clipboard writes :(
|
||||
if (item.mime_type() === 'text/plain') {
|
||||
if (item.mimeType() === 'text/plain') {
|
||||
const value = item.value();
|
||||
|
||||
if (typeof value === 'string') {
|
||||
|
@ -338,7 +338,7 @@
|
|||
}
|
||||
|
||||
try {
|
||||
let clipboard_data = remoteDesktopService.createClipboardData();
|
||||
let clipboardData = new module.ClipboardData();
|
||||
|
||||
if (evt.clipboardData == null) {
|
||||
return;
|
||||
|
@ -349,10 +349,10 @@
|
|||
|
||||
if (mime.startsWith('text/')) {
|
||||
clipItem.getAsString((str: string) => {
|
||||
clipboard_data.add_text(mime, str);
|
||||
clipboardData.addText(mime, str);
|
||||
|
||||
if (!clipboard_data.is_empty()) {
|
||||
remoteDesktopService.onClipboardChanged(clipboard_data);
|
||||
if (!clipboardData.isEmpty()) {
|
||||
remoteDesktopService.onClipboardChanged(clipboardData);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -367,10 +367,10 @@
|
|||
file.arrayBuffer().then((buffer: ArrayBuffer) => {
|
||||
const strict_buffer = new Uint8Array(buffer);
|
||||
|
||||
clipboard_data.add_binary(mime, strict_buffer);
|
||||
clipboardData.addBinary(mime, strict_buffer);
|
||||
|
||||
if (!clipboard_data.is_empty()) {
|
||||
remoteDesktopService.onClipboardChanged(clipboard_data);
|
||||
if (!clipboardData.isEmpty()) {
|
||||
remoteDesktopService.onClipboardChanged(clipboardData);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -457,9 +457,9 @@
|
|||
|
||||
function serverBridgeListeners() {
|
||||
remoteDesktopService.resize.subscribe((evt: ResizeEvent) => {
|
||||
loggingService.info(`Resize canvas to: ${evt.desktop_size.width}x${evt.desktop_size.height}`);
|
||||
canvas.width = evt.desktop_size.width;
|
||||
canvas.height = evt.desktop_size.height;
|
||||
loggingService.info(`Resize canvas to: ${evt.desktopSize.width}x${evt.desktopSize.height}`);
|
||||
canvas.width = evt.desktopSize.width;
|
||||
canvas.height = evt.desktopSize.height;
|
||||
scaleSession(scale);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
export * as default from './iron-remote-desktop.svelte';
|
||||
export type { ResizeEvent } from './interfaces/ResizeEvent';
|
||||
export type { NewSessionInfo } from './interfaces/NewSessionInfo';
|
||||
export type { ServerRect } from './interfaces/ServerRect';
|
||||
export type { SessionEvent, IronError, IronErrorKind } from './interfaces/session-event';
|
||||
export type { SessionEventType } from './enums/SessionEventType';
|
||||
export type { SessionTerminationInfo } from './interfaces/SessionTerminationInfo';
|
||||
|
|
|
@ -63,10 +63,6 @@ export class RemoteDesktopService {
|
|||
loggingService.info('Web bridge initialized.');
|
||||
}
|
||||
|
||||
createClipboardData(): ClipboardData {
|
||||
return this.module.createClipboardData();
|
||||
}
|
||||
|
||||
// If set to false, the clipboard will not be enabled and the callbacks will not be registered to the Rust side
|
||||
setEnableClipboard(enable: boolean) {
|
||||
this.enableClipboard = enable;
|
||||
|
@ -108,12 +104,14 @@ export class RemoteDesktopService {
|
|||
if (preventDefault) {
|
||||
event.preventDefault(); // prevent default behavior (context menu, etc)
|
||||
}
|
||||
const mouseFnc = isDown ? this.module.createMouseButtonPressed : this.module.createMouseButtonReleased;
|
||||
const mouseFnc = isDown
|
||||
? this.module.DeviceEvent.mouseButtonPressed
|
||||
: this.module.DeviceEvent.mouseButtonReleased;
|
||||
this.doTransactionFromDeviceEvents([mouseFnc(event.button)]);
|
||||
}
|
||||
|
||||
updateMousePosition(position: MousePosition) {
|
||||
this.doTransactionFromDeviceEvents([this.module.createMouseMove(position.x, position.y)]);
|
||||
this.doTransactionFromDeviceEvents([this.module.DeviceEvent.mouseMove(position.x, position.y)]);
|
||||
this.mousePosition.next(position);
|
||||
}
|
||||
|
||||
|
@ -122,35 +120,35 @@ export class RemoteDesktopService {
|
|||
}
|
||||
|
||||
connect(config: Config): Observable<NewSessionInfo> {
|
||||
const sessionBuilder = this.module.createSessionBuilder();
|
||||
const sessionBuilder = new this.module.SessionBuilder();
|
||||
|
||||
sessionBuilder.proxy_address(config.proxyAddress);
|
||||
sessionBuilder.proxyAddress(config.proxyAddress);
|
||||
sessionBuilder.destination(config.destination);
|
||||
sessionBuilder.server_domain(config.serverDomain);
|
||||
sessionBuilder.serverDomain(config.serverDomain);
|
||||
sessionBuilder.password(config.password);
|
||||
sessionBuilder.auth_token(config.authToken);
|
||||
sessionBuilder.authToken(config.authToken);
|
||||
sessionBuilder.username(config.username);
|
||||
sessionBuilder.render_canvas(this.canvas!);
|
||||
sessionBuilder.set_cursor_style_callback_context(this);
|
||||
sessionBuilder.set_cursor_style_callback(this.setCursorStyleCallback);
|
||||
sessionBuilder.renderCanvas(this.canvas!);
|
||||
sessionBuilder.setCursorStyleCallbackContext(this);
|
||||
sessionBuilder.setCursorStyleCallback(this.setCursorStyleCallback);
|
||||
|
||||
config.extensions.forEach((extension) => {
|
||||
sessionBuilder.extension(extension);
|
||||
});
|
||||
|
||||
if (this.onRemoteClipboardChanged != null && this.enableClipboard) {
|
||||
sessionBuilder.remote_clipboard_changed_callback(this.onRemoteClipboardChanged);
|
||||
sessionBuilder.remoteClipboardChangedCallback(this.onRemoteClipboardChanged);
|
||||
}
|
||||
if (this.onRemoteReceivedFormatList != null && this.enableClipboard) {
|
||||
sessionBuilder.remote_received_format_list_callback(this.onRemoteReceivedFormatList);
|
||||
sessionBuilder.remoteReceivedFormatListCallback(this.onRemoteReceivedFormatList);
|
||||
}
|
||||
if (this.onForceClipboardUpdate != null && this.enableClipboard) {
|
||||
sessionBuilder.force_clipboard_update_callback(this.onForceClipboardUpdate);
|
||||
sessionBuilder.forceClipboardUpdateCallback(this.onForceClipboardUpdate);
|
||||
}
|
||||
|
||||
if (config.desktopSize != null) {
|
||||
sessionBuilder.desktop_size(
|
||||
this.module.createDesktopSize(config.desktopSize.width, config.desktopSize.height),
|
||||
sessionBuilder.desktopSize(
|
||||
new this.module.DesktopSize(config.desktopSize.width, config.desktopSize.height),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -202,17 +200,17 @@ export class RemoteDesktopService {
|
|||
loggingService.info('Session started.');
|
||||
this.session = session;
|
||||
this._resize.next({
|
||||
desktop_size: session.desktop_size(),
|
||||
session_id: 0,
|
||||
desktopSize: session.desktopSize(),
|
||||
sessionId: 0,
|
||||
});
|
||||
this.raiseSessionEvent({
|
||||
type: SessionEventType.STARTED,
|
||||
data: 'Session started',
|
||||
});
|
||||
return {
|
||||
session_id: 0,
|
||||
initial_desktop_size: session.desktop_size(),
|
||||
websocket_port: 0,
|
||||
sessionId: 0,
|
||||
initialDesktopSize: session.desktopSize(),
|
||||
websocketPort: 0,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
@ -232,7 +230,7 @@ export class RemoteDesktopService {
|
|||
mouseWheel(event: WheelEvent) {
|
||||
const vertical = event.deltaY !== 0;
|
||||
const rotation = vertical ? event.deltaY : event.deltaX;
|
||||
this.doTransactionFromDeviceEvents([this.module.createWheelRotations(vertical, -rotation)]);
|
||||
this.doTransactionFromDeviceEvents([this.module.DeviceEvent.wheelRotations(vertical, -rotation)]);
|
||||
}
|
||||
|
||||
setVisibility(state: boolean) {
|
||||
|
@ -256,14 +254,14 @@ export class RemoteDesktopService {
|
|||
/// cache the content and send it to the server when it is requested.
|
||||
onClipboardChanged(data: ClipboardData): Promise<void> {
|
||||
const onClipboardChangedPromise = async () => {
|
||||
await this.session?.on_clipboard_paste(data);
|
||||
await this.session?.onClipboardPaste(data);
|
||||
};
|
||||
return onClipboardChangedPromise();
|
||||
}
|
||||
|
||||
onClipboardChangedEmpty(): Promise<void> {
|
||||
const onClipboardChangedPromise = async () => {
|
||||
await this.session?.on_clipboard_paste(this.module.createClipboardData());
|
||||
await this.session?.onClipboardPaste(new this.module.ClipboardData());
|
||||
};
|
||||
return onClipboardChangedPromise();
|
||||
}
|
||||
|
@ -283,7 +281,7 @@ export class RemoteDesktopService {
|
|||
}
|
||||
|
||||
private releaseAllInputs() {
|
||||
this.session?.release_all_inputs();
|
||||
this.session?.releaseAllInputs();
|
||||
}
|
||||
|
||||
private supportsUnicodeKeyboardShortcuts(): boolean {
|
||||
|
@ -292,8 +290,8 @@ export class RemoteDesktopService {
|
|||
return this.backendSupportsUnicodeKeyboardShortcuts;
|
||||
}
|
||||
|
||||
if (this.session?.supports_unicode_keyboard_shortcuts) {
|
||||
this.backendSupportsUnicodeKeyboardShortcuts = this.session?.supports_unicode_keyboard_shortcuts();
|
||||
if (this.session?.supportsUnicodeKeyboardShortcuts) {
|
||||
this.backendSupportsUnicodeKeyboardShortcuts = this.session?.supportsUnicodeKeyboardShortcuts();
|
||||
return this.backendSupportsUnicodeKeyboardShortcuts;
|
||||
}
|
||||
|
||||
|
@ -308,11 +306,11 @@ export class RemoteDesktopService {
|
|||
let unicodeEvent;
|
||||
|
||||
if (evt.type === 'keydown') {
|
||||
keyEvent = this.module.createKeyPressed;
|
||||
unicodeEvent = this.module.createUnicodePressed;
|
||||
keyEvent = this.module.DeviceEvent.keyPressed;
|
||||
unicodeEvent = this.module.DeviceEvent.unicodePressed;
|
||||
} else if (evt.type === 'keyup') {
|
||||
keyEvent = this.module.createKeyReleased;
|
||||
unicodeEvent = this.module.createUnicodeReleased;
|
||||
keyEvent = this.module.DeviceEvent.keyReleased;
|
||||
unicodeEvent = this.module.DeviceEvent.unicodeReleased;
|
||||
}
|
||||
|
||||
let sendAsUnicode = true;
|
||||
|
@ -369,8 +367,8 @@ export class RemoteDesktopService {
|
|||
private setCursorStyleCallback(
|
||||
style: string,
|
||||
data: string | undefined,
|
||||
hotspot_x: number | undefined,
|
||||
hotspot_y: number | undefined,
|
||||
hotspotX: number | undefined,
|
||||
hotspotY: number | undefined,
|
||||
) {
|
||||
let cssStyle;
|
||||
|
||||
|
@ -384,7 +382,7 @@ export class RemoteDesktopService {
|
|||
break;
|
||||
}
|
||||
case 'url': {
|
||||
if (data == undefined || hotspot_x == undefined || hotspot_y == undefined) {
|
||||
if (data == undefined || hotspotX == undefined || hotspotY == undefined) {
|
||||
console.error('Invalid custom cursor parameters.');
|
||||
return;
|
||||
}
|
||||
|
@ -394,8 +392,8 @@ export class RemoteDesktopService {
|
|||
const image = new Image();
|
||||
image.src = data;
|
||||
|
||||
const rounded_hotspot_x = Math.round(hotspot_x);
|
||||
const rounded_hotspot_y = Math.round(hotspot_y);
|
||||
const rounded_hotspot_x = Math.round(hotspotX);
|
||||
const rounded_hotspot_y = Math.round(hotspotY);
|
||||
|
||||
cssStyle = `url(${data}) ${rounded_hotspot_x} ${rounded_hotspot_y}, default`;
|
||||
|
||||
|
@ -420,7 +418,7 @@ export class RemoteDesktopService {
|
|||
const syncScrollLockActive = evt.getModifierState(LockKey.SCROLL_LOCK);
|
||||
const syncKanaModeActive = evt.getModifierState(LockKey.KANA_MODE);
|
||||
|
||||
this.session?.synchronize_lock_keys(
|
||||
this.session?.synchronizeLockKeys(
|
||||
syncScrollLockActive,
|
||||
syncNumsLockActive,
|
||||
syncCapsLockActive,
|
||||
|
@ -443,9 +441,9 @@ export class RemoteDesktopService {
|
|||
}
|
||||
|
||||
private doTransactionFromDeviceEvents(deviceEvents: DeviceEvent[]) {
|
||||
const transaction = this.module.createInputTransaction();
|
||||
deviceEvents.forEach((event) => transaction.add_event(event));
|
||||
this.session?.apply_inputs(transaction);
|
||||
const transaction = new this.module.InputTransaction();
|
||||
deviceEvents.forEach((event) => transaction.addEvent(event));
|
||||
this.session?.applyInputs(transaction);
|
||||
}
|
||||
|
||||
private ctrlAltDel() {
|
||||
|
@ -454,18 +452,21 @@ export class RemoteDesktopService {
|
|||
const suppr = parseInt('0xE053', 16);
|
||||
|
||||
this.doTransactionFromDeviceEvents([
|
||||
this.module.createKeyPressed(ctrl),
|
||||
this.module.createKeyPressed(alt),
|
||||
this.module.createKeyPressed(suppr),
|
||||
this.module.createKeyReleased(ctrl),
|
||||
this.module.createKeyReleased(alt),
|
||||
this.module.createKeyReleased(suppr),
|
||||
this.module.DeviceEvent.keyPressed(ctrl),
|
||||
this.module.DeviceEvent.keyPressed(alt),
|
||||
this.module.DeviceEvent.keyPressed(suppr),
|
||||
this.module.DeviceEvent.keyReleased(ctrl),
|
||||
this.module.DeviceEvent.keyReleased(alt),
|
||||
this.module.DeviceEvent.keyReleased(suppr),
|
||||
]);
|
||||
}
|
||||
|
||||
private sendMeta() {
|
||||
const meta = parseInt('0xE05B', 16);
|
||||
|
||||
this.doTransactionFromDeviceEvents([this.module.createKeyPressed(meta), this.module.createKeyReleased(meta)]);
|
||||
this.doTransactionFromDeviceEvents([
|
||||
this.module.DeviceEvent.keyPressed(meta),
|
||||
this.module.DeviceEvent.keyReleased(meta),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,16 +149,16 @@
|
|||
}),
|
||||
filter((result) => result !== null && result !== undefined), // Explicitly checking for null/undefined
|
||||
)
|
||||
.subscribe((start_info: NewSessionInfo | null) => {
|
||||
if (start_info != null && start_info.initial_desktop_size !== null) {
|
||||
.subscribe((info: NewSessionInfo | null) => {
|
||||
if (info != null && info.initialDesktopSize !== null) {
|
||||
toast.set({
|
||||
type: 'info',
|
||||
message: 'Success',
|
||||
});
|
||||
currentSession.update((session) =>
|
||||
Object.assign(session, {
|
||||
sessionId: start_info.session_id,
|
||||
desktopSize: start_info.initial_desktop_size,
|
||||
sessionId: info.sessionId,
|
||||
desktopSize: info.initialDesktopSize,
|
||||
active: true,
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import type { Observable } from 'rxjs';
|
||||
|
||||
export interface ServerRect {
|
||||
free(): void;
|
||||
|
||||
clone_buffer(): Uint8Array;
|
||||
|
||||
bottom: number;
|
||||
left: number;
|
||||
right: number;
|
||||
top: number;
|
||||
}
|
||||
|
||||
export interface NewSessionInfo {
|
||||
session_id: number;
|
||||
websocket_port: number;
|
||||
initial_desktop_size: DesktopSize;
|
||||
}
|
||||
|
||||
export interface DesktopSize {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface ResizeEvent {
|
||||
session_id: number;
|
||||
desktop_size: DesktopSize;
|
||||
}
|
||||
|
||||
export abstract class ServerBridgeService {
|
||||
abstract init(): void;
|
||||
|
||||
abstract connect(username: string, password: string, address: string): Observable<NewSessionInfo>;
|
||||
|
||||
abstract resize: Observable<ResizeEvent>;
|
||||
|
||||
abstract updateMouse(mouse_x: number, mouse_y: number, click_state: number): void;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue