use crate::desktop_protocol::{DesktopProtocol, FrameUpdate, VncConfig};
use anyhow::Result;
use async_trait::async_trait;
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
pub struct VncClient {
config: VncConfig,
desktop_width: u16,
desktop_height: u16,
connected: bool,
}
impl VncClient {
pub async fn connect(config: &VncConfig) -> Result<Self> {
if config.host.is_empty() {
return Err(anyhow::anyhow!("VNC host cannot be empty"));
}
Err(anyhow::anyhow!(
"VNC protocol support is not yet implemented. \
Connection to {}:{} cannot be established.",
config.host,
config.port
))
}
#[allow(dead_code)]
fn new_disconnected(config: VncConfig) -> Self {
Self {
desktop_width: 1024,
desktop_height: 768,
config,
connected: false,
}
}
}
#[async_trait]
impl DesktopProtocol for VncClient {
async fn start_frame_loop(
&self,
_frame_tx: mpsc::UnboundedSender<FrameUpdate>,
_cancel: CancellationToken,
) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("VNC client is not connected"));
}
Ok(())
}
async fn send_key(&self, _key_code: u32, _down: bool) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("VNC 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!("VNC client is not connected"));
}
Ok(())
}
async fn request_full_frame(&self) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("VNC client is not connected"));
}
Ok(())
}
async fn set_clipboard(&self, _text: String) -> Result<()> {
if !self.connected {
return Err(anyhow::anyhow!("VNC 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<()> {
Ok(())
}
async fn disconnect(&mut self) -> Result<()> {
if self.connected {
self.connected = false;
tracing::info!(
"VNC disconnected from {}:{}",
self.config.host,
self.config.port
);
}
Ok(())
}
}