Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See [How it works → Video](docs/architecture.md#video) for details.
- **Remote terminal**: when you only want to run command-line programs such as `claude`, `codex` or `pi` on the other computer, open just a terminal there instead of the screen (Windows / macOS / Linux hosts, running as the signed-in user), from the desktop app or from a phone (Android / iOS): next to no bandwidth, and after a dropped connection you get the same terminal back with its programs still running. [Details](docs/usage.md#remote-terminal)
- **Android**: control computers and phones from a phone as a trackpad or touchscreen, or share your own screen to get help (a device needs the pairing code shown on the phone the first time, and you're notified whenever one connects); watch on a TV with the remote
- **iPhone / iPad**: the same remote control as on Android (trackpad / touch gestures, keyboard, mouse with pointer lock on iPad, game controls), or share the screen through the system screen broadcast (view only: iOS doesn't let apps be controlled)
- **Audio**: the host's system audio plays on the controller (Opus + adaptive jitter buffer), with optional A/V sync for watching videos. The other way, the controller can send its microphone to meeting apps and voice typing on Windows, macOS 14.2+ and Linux (PipeWire) hosts. Mac and Linux hosts publish **Airhand Microphone** while forwarding is on
- **Audio**: the host's system audio plays on the controller (Opus + adaptive jitter buffer), with optional A/V sync for watching videos. The other way, the controller can send its microphone to meeting apps and voice typing on Windows, macOS 14.2+ and Linux (PipeWire) hosts, where it's the recording device **Airhand Microphone**: on Windows a virtual USB microphone plugged through [airhand-dock](https://github.com/sqlpxc/airhand-dock) and usbip-win2, like gamepads. [Details](docs/usage.md#microphone)
- **Gamepads**: gamepads on the controller (desktop and web consoles, Android phones and TVs, iPhone / iPad) are plugged into Windows and Linux hosts as wired Xbox 360 controllers through [airhand-dock](https://github.com/sqlpxc/airhand-dock), so every game sees a real gamepad, and games make your gamepad vibrate. Game keys on phones can be an on-screen gamepad too. Windows hosts need the [usbip-win2](https://github.com/vadimgrn/usbip-win2) driver, which the Airhand installer includes and offers to install. [Details](docs/usage.md#gamepads)
- **Handy tools**: two-way clipboard sync (text, plus files and folders, sent when you paste), typing the clipboard as keystrokes, system shortcuts (Win, Alt+Tab, Ctrl+Shift+Esc…), multiple monitors (switch between them, show and control several at once, or give each its own window to put on your own screens in full screen), keyboard lock in fullscreen, quality presets
- **Secure by default**: sessions are end-to-end encrypted, so the relay server can't see the screen or keystrokes; the first connection needs the pairing code from the other computer's tray (it never goes through the server), and its identity is recognized afterwards; TLS 1.3 with certificate pinning, brute-force protection for control codes; the host always sees who is connected and can disconnect them with one click
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Airhand 是一个**高性能、低延迟**的远程桌面:画面用 GPU 硬件
- **远程终端**:只想在对方电脑上跑 `claude`、`codex`、`pi` 这类命令行程序时,不传画面、只开一个终端(Windows / macOS / Linux 被控端,以登录的用户的身份运行),电脑和手机(Android / iOS)上都能开:几乎不占带宽,断线重连后接回原来的终端,里面的程序一直在跑。[详细说明](docs/usage.zh-CN.md#远程终端)
- **Android**:在手机上用触控板或触屏的方式控制电脑、手机,也能共享自己的屏幕让别人协助(对方第一次连接时要输入手机上显示的配对码,有设备连上来时会提醒你);在电视上用遥控器看画面
- **iPhone / iPad**:和 Android 一样控制电脑、手机(触控板 / 触屏手势、键盘、外接鼠标,iPad 上可以锁定指针、游戏按键),也能用系统的屏幕广播共享自己的屏幕(只能被看:iOS 不允许别的应用操作本机)
- **声音**:被控端的系统声音同步到控制端(Opus + 自适应抖动缓冲),看视频时可以打开音画同步。反过来,控制端的麦克风可以转发给 Windows、macOS 14.2+ 和 Linux(PipeWire)被控端,供那里的会议软件和语音输入使用。Mac 和 Linux 会在转发期间提供一个 **Airhand Microphone** 录音设备
- **声音**:被控端的系统声音同步到控制端(Opus + 自适应抖动缓冲),看视频时可以打开音画同步。反过来,控制端的麦克风可以转发给 Windows、macOS 14.2+ 和 Linux(PipeWire)被控端,在那里是录音设备 **Airhand Microphone**,供会议软件和语音输入使用:Windows 上是和手柄一样经 [airhand-dock](https://github.com/sqlpxc/airhand-dock) 和 usbip-win2 插上的虚拟 USB 麦克风。[详情](docs/usage.zh-CN.md#麦克风)
- **手柄**:控制端接着的手柄(桌面和网页控制台、Android 手机和电视、iPhone / iPad)经 [airhand-dock](https://github.com/sqlpxc/airhand-dock) 作为有线 Xbox 360 手柄插到 Windows、Linux 被控端上,所有游戏看到的都是真手柄,游戏的震动也传回你的手柄。手机上的游戏按键也可以是屏幕上的手柄。Windows 被控端要用 [usbip-win2](https://github.com/vadimgrn/usbip-win2) 驱动,Airhand 的安装包里带着,安装时会问要不要装。[详情](docs/usage.zh-CN.md#手柄)
- **实用工具**:剪贴板双向同步(文字,以及文件、文件夹:粘贴时才传)、以键盘输入方式发送剪贴板、系统快捷键(Win、Alt+Tab、Ctrl+Shift+Esc……)、多显示器(可以同时显示、同时操作对方的几个显示器,也可以每个显示器单独一个窗口,放到本机的各个显示器上全屏)、全屏时锁定键盘、画质预设
- **默认安全**:会话端到端加密,中转服务器看不到画面和键盘输入;第一次连接要输入对方托盘里的配对码(不经过服务器),之后认得出对方的身份;TLS 1.3 + 证书指纹固定,控制码防暴力猜测;被控端随时能看到谁连着,一键断开
Expand Down
2 changes: 1 addition & 1 deletion client/scripts/fetch-usbip-win2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ main().catch((e) => {
}
console.warn(
`warning: usbip-win2 couldn't be downloaded (${e.message ?? e}).\n` +
"The Windows installer is built without it and won't offer to install the gamepad driver.",
"The Windows installer is built without it and won't offer to install the gamepad and microphone driver.",
);
});
53 changes: 10 additions & 43 deletions client/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions client/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ semver = "1"
sha2 = "0.10"

[target.'cfg(windows)'.dependencies]
# 从本机 Steam 的安装目录或自解压 ZIP 读取虚拟麦克风驱动
# 注册表:虚拟显示器驱动的设置(src/host/virtual_display/device.rs)、登录的用户的设置(src/winsvc/user.rs)
winreg = "0.56"
# 自动更新:Windows 上按系统的代理设置(Internet 选项)连 GitHub
ureq = { version = "3", default-features = false, features = ["win-system-proxy"] }
zip = { version = "9", default-features = false, features = ["deflate-flate2-zlib-rs"] }
tempfile = "3"
# #[implement] 展开的代码直接引用 windows_core(剪贴板里的文件:自己实现的 IDataObject、IStream)
windows-core = "0.62"
windows = { version = "0.62", features = [
Expand Down Expand Up @@ -104,7 +102,7 @@ windows = { version = "0.62", features = [
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_WindowsAndMessaging",
"Win32_UI_HiDpi",
# 声音设备的属性(控制端的麦克风:按接口名找 Steam Streaming Microphone、读它的设备格式)
# 声音设备的属性(控制端的麦克风:按接口名找 Airhand Microphone 的录音设备)
"Win32_UI_Shell_PropertiesSystem",
# 剪贴板里的文件:对方复制的文件以"虚拟文件"放进本机剪贴板(FILEDESCRIPTORW / FILECONTENTS,见 src/clipfiles/windows.rs)
"Win32_UI_Shell",
Expand All @@ -116,9 +114,10 @@ windows = { version = "0.62", features = [
[target.'cfg(not(windows))'.dependencies]
dirs = "7"

# 控制端的手柄插成本机的虚拟 Xbox 360 手柄(见 src/host/gamepad.rs):Windows 经 usbip-win2,Linux 经 vhci-hcd 或 uinput
# 控制端的手柄插成本机的虚拟 Xbox 360 手柄(见 src/host/gamepad.rs):Windows 经 usbip-win2,Linux 经 vhci-hcd 或 uinput。
# Windows 上控制端的麦克风也是经 usbip-win2 插上的 USB 麦克风(见 src/host/mic/usb.rs)
[target.'cfg(any(windows, target_os = "linux"))'.dependencies]
airhand-dock = { git = "https://github.com/sqlpxc/airhand-dock", tag = "v0.2.0" }
airhand-dock = { git = "https://github.com/sqlpxc/airhand-dock", tag = "v0.3.0" }

# Linux 被控端:X11(MIT-SHM 采集 + DAMAGE 变化检测 + XFIXES 光标/剪贴板 + XTEST 注入),
# 声音用 PulseAudio(PipeWire 的 pipewire-pulse 同样适用)监听默认输出设备。
Expand Down
19 changes: 7 additions & 12 deletions client/src-tauri/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ async fn e2e_roundtrip() {
}
assert!(rep.hello, "没有收到 Hello");
assert!(rep.pongs >= 3, "Ping/Pong 不工作");
// 同一个版本的两端都懂麦克风:被控端会说它能不能接(Windows 看有没有 Steam Streaming Microphone)
// 同一个版本的两端都懂麦克风:被控端会说它能不能接(Windows 看有没有 usbip-win2)
let mic = rep.mic.expect("被控端没有说麦克风的状态");
assert_eq!(mic, crate::host::mic::probe(0).await.0);
// 手柄也是:被控端会说它能不能接(Windows 看有没有 usbip-win2,Linux 看 vhci-hcd / uinput)
Expand Down Expand Up @@ -738,7 +738,7 @@ async fn e2e_multi_display() {
/// 控制端的麦克风,从协议级的控制端一直到系统录音设备。每 20 ms 发一包 1 kHz 的声音,
/// 故意丢一部分数据报,再通过独立的录音客户端检查频率和连续性。先启动中转服务器。
#[tokio::test(flavor = "multi_thread")]
#[ignore = "requires a relay and the system audio server; on Windows may install the Steam driver"]
#[ignore = "requires a relay and the system audio server; on Windows plugs a USB microphone through usbip-win2"]
async fn e2e_mic() {
use crate::host::mic::tests::goertzel;
#[cfg(not(windows))]
Expand Down Expand Up @@ -787,24 +787,19 @@ async fn e2e_mic() {
continue;
};
println!("麦克风: {state:?} {detail:?}");
if state == MicState::SteamMissing && !enabled {
println!("这台电脑上没有 Steam,跳过声音的检查");
if state == MicState::NoDriver && !enabled {
println!("这台电脑上没有 usbip-win2,跳过声音的检查");
return;
}
assert!(
matches!(
state,
MicState::Ready | MicState::NoDevice | MicState::Preparing
),
matches!(state, MicState::Ready | MicState::Preparing),
"{state:?}: {detail:?}"
);
if !enabled {
ctl.send(&ControllerMsg::Mic { enabled: true }).await;
enabled = true;
// Unix publishes its device on demand. Wait for the live lease's Ready.
if !cfg!(windows) {
continue;
}
// 打开之后才插上 / 发布设备:等它说 ready
continue;
}
if state == MicState::Ready {
break;
Expand Down
24 changes: 24 additions & 0 deletions client/src-tauri/src/host/dock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! [airhand-dock](https://github.com/sqlpxc/airhand-dock) 的 [`Dock`]:整个进程一个,控制端的手柄(见 [`super::gamepad`])
//! 和 Windows 上控制端的麦克风(见 `super::mic`)都插在它上面:一个本机回环的 USB/IP 服务器,一套线程。
//!
//! 第一次插设备时打开(Windows 上会顺便拔掉之前崩溃的进程留下的设备),之后一直留着;打不开(例如还没装 usbip-win2)
//! 就不留,下次再试。打开会阻塞:只在插拔设备的线程上调用。

use std::sync::Mutex;

use airhand_dock::Dock;
use tracing::info;

static DOCK: Mutex<Option<Dock>> = Mutex::new(None);

/// 这个进程的 [`Dock`],还没有就打开它
pub(crate) fn get() -> airhand_dock::Result<Dock> {
let mut dock = DOCK.lock().unwrap_or_else(|e| e.into_inner());
if let Some(d) = &*dock {
return Ok(d.clone());
}
let d = Dock::new()?;
info!(backend = %d.backend(), "opened the virtual device dock");
*dock = Some(d.clone());
Ok(d)
}
14 changes: 3 additions & 11 deletions client/src-tauri/src/host/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ mod imp {
}
}

/// 插拔线程:整个进程一个,插拔都在这里一个一个做。airhand-dock 的 [`Dock`] 也在这里,第一次插手柄时打开
/// (Windows 上会顺便拔掉之前崩溃的进程留下的),之后一直留着
/// 插拔线程:整个进程一个,插拔都在这里一个一个做。手柄插在整个进程共用的 airhand-dock 的 [`Dock`] 上
/// (见 [`crate::host::dock`]:第一次插手柄时打开,之后一直留着)
fn worker(rx: mpsc::Receiver<Job>) {
let mut dock: Option<Dock> = None;
for job in rx {
match job {
Job::Plug {
Expand All @@ -256,14 +255,7 @@ mod imp {
generation,
device,
} => {
let result = match &dock {
Some(d) => Ok(d.clone()),
None => Dock::new().inspect(|d| {
info!(backend = %d.backend(), "opened the gamepad dock");
dock = Some(d.clone());
}),
}
.and_then(|d| d.plug(&device));
let result = crate::host::dock::get().and_then(|d| d.plug(&device));
let mut owners = owners();
let pad = owners
.get_mut(&controller)
Expand Down
Loading