rustvncserver/lib.rs
1// Copyright 2025 Dustin McAfee
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! # rustvncserver
16//!
17//! A pure Rust implementation of a VNC (Virtual Network Computing) server.
18//!
19//! This library provides a complete VNC server implementation following the RFB
20//! (Remote Framebuffer) protocol specification (RFC 6143). It supports all major
21//! VNC encodings and pixel formats, with 100% wire-format compatibility with
22//! standard VNC protocol.
23//!
24//! ## Features
25//!
26//! - **11 encoding types**: Raw, `CopyRect`, RRE, `CoRRE`, Hextile, Zlib, `ZlibHex`,
27//! Tight, `TightPng`, ZRLE, ZYWRLE
28//! - **All pixel formats**: 8/16/24/32-bit color depths
29//! - **Tight encoding**: All 5 production modes (solid fill, mono rect, indexed
30//! palette, full-color zlib, JPEG)
31//! - **Async I/O**: Built on Tokio for efficient concurrent client handling
32//! - **Memory safe**: Pure Rust with zero unsafe code in core logic
33//! - **Optional `TurboJPEG`**: Hardware-accelerated JPEG compression via feature flag
34//!
35//! ## Quick Start
36//!
37//! ```no_run
38//! use rustvncserver::VncServer;
39//! use rustvncserver::server::ServerEvent;
40//!
41//! #[tokio::main]
42//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
43//! // Create a VNC server with 1920x1080 framebuffer
44//! let (server, mut event_rx) = VncServer::new(
45//! 1920,
46//! 1080,
47//! "My Desktop".to_string(),
48//! Some("secret".to_string()), // Optional password
49//! );
50//!
51//! // Handle events from clients in a background task
52//! tokio::spawn(async move {
53//! while let Some(event) = event_rx.recv().await {
54//! match event {
55//! ServerEvent::ClientConnected { client_id } => {
56//! println!("Client {} connected", client_id);
57//! }
58//! ServerEvent::ClientDisconnected { client_id } => {
59//! println!("Client {} disconnected", client_id);
60//! }
61//! _ => {}
62//! }
63//! }
64//! });
65//!
66//! // Start listening on port 5900 (blocks until server stops)
67//! server.listen(5900).await?;
68//! Ok(())
69//! }
70//! ```
71//!
72//! ## Architecture
73//!
74//! ```text
75//! ┌─────────────────────────────────────────┐
76//! │ Your Application │
77//! │ │
78//! │ • Provide framebuffer data │
79//! │ • Receive input events │
80//! │ • Control server lifecycle │
81//! └──────────────────┬──────────────────────┘
82//! │
83//! ▼
84//! ┌─────────────────────────────────────────┐
85//! │ VncServer (Public) │
86//! │ │
87//! │ • TCP listener │
88//! │ • Client management │
89//! │ • Event distribution │
90//! └──────────────────┬──────────────────────┘
91//! │
92//! ┌───────────┼───────────┐
93//! ▼ ▼ ▼
94//! ┌────────┐ ┌────────┐ ┌────────┐
95//! │Client 1│ │Client 2│ │Client N│
96//! └────────┘ └────────┘ └────────┘
97//! │ │ │
98//! └───────────┴───────────┘
99//! │
100//! ▼
101//! ┌─────────────────────────────────────────┐
102//! │ Framebuffer (Thread-safe) │
103//! │ │
104//! │ • RGBA32 pixel storage │
105//! │ • Region tracking │
106//! │ • CopyRect operations │
107//! └─────────────────────────────────────────┘
108//! ```
109
110#![deny(missing_docs)]
111#![warn(clippy::all)]
112#![warn(clippy::pedantic)]
113
114pub mod error;
115pub mod events;
116pub mod framebuffer;
117pub mod protocol;
118pub mod server;
119
120// Internal modules
121mod auth;
122mod client;
123mod repeater;
124
125// Re-export encodings from rfb-encodings crate
126pub use rfb_encodings as encoding;
127
128// Re-exports
129pub use encoding::Encoding;
130pub use error::{Result, VncError};
131pub use events::ServerEvent;
132pub use framebuffer::Framebuffer;
133pub use protocol::PixelFormat;
134pub use server::VncServer;
135
136#[cfg(feature = "turbojpeg")]
137pub use encoding::jpeg::TurboJpegEncoder;
138
139/// VNC protocol version.
140pub const PROTOCOL_VERSION: &str = "RFB 003.008\n";
141
142/// Default VNC port.
143pub const DEFAULT_PORT: u16 = 5900;