-
Notifications
You must be signed in to change notification settings - Fork 205
refactor: rework extension API for iron-remote-desktop #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| use wasm_bindgen::prelude::wasm_bindgen; | ||
|
|
||
| #[wasm_bindgen] | ||
| #[derive(Clone, Copy)] | ||
| pub struct DesktopSize { | ||
| pub width: u16, | ||
| pub height: u16, | ||
| } | ||
|
|
||
| #[wasm_bindgen] | ||
| impl DesktopSize { | ||
| pub fn init(width: u16, height: u16) -> Self { | ||
| DesktopSize { width, height } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| use wasm_bindgen::prelude::wasm_bindgen; | ||
| use wasm_bindgen::JsValue; | ||
|
|
||
| #[macro_export] | ||
| macro_rules! extension_match { | ||
| ( @ $jsval:expr, $value:ident, String, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_string() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, f64, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_f64() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, bool, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_bool() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, JsValue, $operation:block ) => {{ | ||
| let $value = $jsval; | ||
| $operation | ||
| }}; | ||
|
|
||
| ( match $ext:ident ; $( | $value:ident : $ty:ident | $operation:block ; )* ) => { | ||
| let ident = $ext.ident(); | ||
|
|
||
| match ident { | ||
| $( stringify!($value) => $crate::extension_match!( @ $ext.into_value(), $value, $ty, $operation ), )* | ||
| unknown_extension => ::tracing::warn!("Unknown extension: {unknown_extension}"), | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| #[wasm_bindgen] | ||
| pub struct Extension { | ||
| ident: String, | ||
| value: JsValue, | ||
| } | ||
|
|
||
| #[wasm_bindgen] | ||
| impl Extension { | ||
| #[wasm_bindgen(constructor)] | ||
| pub fn new(ident: String, value: JsValue) -> Self { | ||
| Self { ident, value } | ||
| } | ||
| } | ||
|
|
||
| impl Extension { | ||
| pub fn ident(&self) -> &str { | ||
| self.ident.as_str() | ||
| } | ||
|
|
||
| pub fn value(&self) -> &JsValue { | ||
| &self.value | ||
| } | ||
|
|
||
| pub fn into_value(self) -> JsValue { | ||
| self.value | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| // https://github.com/rustwasm/wasm-bindgen/issues/4080 | ||
| #![allow(non_snake_case)] | ||
|
|
||
| use core::cell::RefCell; | ||
| use core::num::NonZeroU32; | ||
| use core::time::Duration; | ||
|
|
@@ -14,7 +11,7 @@ use futures_util::io::{ReadHalf, WriteHalf}; | |
| use futures_util::{select, AsyncWriteExt as _, FutureExt as _, StreamExt as _}; | ||
| use gloo_net::websocket; | ||
| use gloo_net::websocket::futures::WebSocket; | ||
| use iron_remote_desktop::{CursorStyle, DesktopSize, IronErrorKind}; | ||
| use iron_remote_desktop::{CursorStyle, DesktopSize, Extension, IronErrorKind}; | ||
| use ironrdp::cliprdr::backend::ClipboardMessage; | ||
| use ironrdp::cliprdr::CliprdrClient; | ||
| use ironrdp::connector::connection_activation::ConnectionActivationState; | ||
|
|
@@ -30,7 +27,6 @@ use ironrdp::session::{fast_path, ActiveStage, ActiveStageOutput, GracefulDiscon | |
| use ironrdp_core::WriteBuf; | ||
| use ironrdp_futures::{single_sequence_step_read, FramedWrite}; | ||
| use rgb::AsPixels as _; | ||
| use serde::{Deserialize, Serialize}; | ||
| use tap::prelude::*; | ||
| use wasm_bindgen::JsValue; | ||
| use wasm_bindgen_futures::spawn_local; | ||
|
|
@@ -207,16 +203,12 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder { | |
| self.clone() | ||
| } | ||
|
|
||
| fn extension(&self, value: JsValue) -> Self { | ||
| match serde_wasm_bindgen::from_value::<Extension>(value) { | ||
| Ok(value) => match value { | ||
| Extension::KdcProxyUrl(kdc_proxy_url) => self.0.borrow_mut().kdc_proxy_url = Some(kdc_proxy_url), | ||
| Extension::Pcb(pcb) => self.0.borrow_mut().pcb = Some(pcb), | ||
| Extension::DisplayControl(use_display_control) => { | ||
| self.0.borrow_mut().use_display_control = use_display_control | ||
| } | ||
| }, | ||
| Err(error) => error!(%error, "Unsupported extension value"), | ||
| fn extension(&self, ext: Extension) -> Self { | ||
| iron_remote_desktop::extension_match! { | ||
| match ext; | ||
| |pcb: String| { self.0.borrow_mut().pcb = Some(pcb) }; | ||
| |kdc_proxy_url: String| { self.0.borrow_mut().kdc_proxy_url = Some(kdc_proxy_url) }; | ||
| |display_control: bool| { self.0.borrow_mut().use_display_control = display_control }; | ||
| } | ||
|
Comment on lines
+207
to
212
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We directly use |
||
|
|
||
| self.clone() | ||
|
|
@@ -354,13 +346,6 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| enum Extension { | ||
| KdcProxyUrl(String), | ||
| Pcb(String), | ||
| DisplayControl(bool), | ||
| } | ||
|
|
||
| pub(crate) type FastPathInputEvents = smallvec::SmallVec<[FastPathInputEvent; 2]>; | ||
|
|
||
| #[derive(Debug)] | ||
|
|
@@ -813,13 +798,16 @@ impl iron_remote_desktop::Session for Session { | |
| } | ||
|
|
||
| fn supports_unicode_keyboard_shortcuts(&self) -> bool { | ||
| // RDP does not support Unicode keyboard shortcuts (When key combinations are executed, only | ||
| // plain scancode events are allowed to function correctly). | ||
| // RDP does not support Unicode keyboard shortcuts. | ||
| // When key combinations are executed, only plain scancode events are allowed to function correctly. | ||
| false | ||
| } | ||
|
|
||
| fn extension_call(_value: JsValue) -> Result<JsValue, Self::Error> { | ||
| Ok(JsValue::null()) | ||
| fn extension_call(ext: Extension) -> Result<JsValue, Self::Error> { | ||
| Err( | ||
| IronError::from(anyhow::Error::msg(format!("unknown extension: {}", ext.ident()))) | ||
| .with_kind(IronErrorKind::General), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1 @@ | ||
| import type { ExtensionValue } from './ExtensionValue'; | ||
|
|
||
| export interface Extension { | ||
| init(ident: string, value: unknown): ExtensionValue; | ||
| } | ||
| export type Extension = unknown; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper macro to extract extension values. This is not strictly needed, but it’s less boilerplate in the consumer code.