use crate::desktop_protocol::{DesktopProtocol, FrameUpdate, RdpConfig};
use anyhow::Result;
use async_trait::async_trait;
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
pub struct RdpClient {
config: RdpConfig,
desktop_width: u16,
desktop_height: u16,
connected: bool,
}
impl RdpClient {
pub async fn connect(config: &RdpConfig) -> Result<Self> {
if config.host.is_empty() {
return Err(anyhow::anyhow!("RDP host cannot be empty"));
}
if config.username.is_empty() {
return Err(anyhow::anyhow!(
"RDP username is required for NLA authentication"
));
}
Err(anyhow::anyhow!(
"RDP protocol support is not yet implemented. \
Connection to {}:{} cannot be established.",
config.host,
config.port
))
}
#[allow(dead_code)]
fn new_disconnected(config: RdpConfig) -> Self {
Self {
desktop_width: config.width,
desktop_height: config.height,
config,
connected: false,
}
}
}
#[async_trait]
impl DesktopProtocol for RdpClient {
async fn start_frame_loop(
&self,
_frame_tx: mpsc::UnboundedSender<FrameUpdate>,
_cancel: CancellationToken,
) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
Ok(())
}
async fn send_key(&self, _key_code: u32, _down: bool) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
Ok(())
}
async fn send_pointer(&self, _x: u16, _y: u16, _button_mask: u8) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
Ok(())
}
async fn request_full_frame(&self) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
Ok(())
}
async fn set_clipboard(&self, _text: String) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
Ok(())
}
fn desktop_size(&self) -> (u16, u16) {
(self.desktop_width, self.desktop_height)
}
async fn resize(&mut self, width: u16, height: u16) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("RDP client is not connected"));
}
self.desktop_width = width;
self.desktop_height = height;
Ok(())
}
async fn disconnect(&mut self) -> Result<()> {
if self.connected {
self.connected = false;
tracing::info!(
"RDP disconnected from {}:{}",
self.config.host,
self.config.port
);
}
Ok(())
}
}