Add Engine.send_file(name, mime, data) and MessageHandler.on_file. Files stream over each open RTC data channel as binary frames — M<json meta> · C<16-byte id><16KB chunk>… · E<id> — and reassemble on the receiver in arrival order (the channel is reliable+ordered). The data channel now distinguishes string (clipboard) from binary (file) messages. Files are direct-only — never relayed, matching prefer-direct. Transport trait gains start(...files) + a default-noop send_file (only RTC implements it). The agent saves received files to ~/Downloads; the apps stub on_file (receive UI is a follow-up). All MessageHandler impls updated. Proven by examples/file_demo.rs: A sends a 50KB blob (4 chunks), B reassembles it to identical bytes over RTC. Follow-ups: file transfer over LAN (same-network without RTC); attach/preview UI; progress + size cap. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1.2 KiB
Rust
34 lines
1.2 KiB
Rust
//! A controllable LAN peer for verifying the agent's serverless sync, without a
|
|
//! second clipboard-touching process. Dead server → only the LAN transport can
|
|
//! move data.
|
|
//! cargo run --example lan_peer -- <room> <text-to-send>
|
|
//! Prints `RECV <text>` for anything received; sends <text-to-send> once after
|
|
//! discovery settles.
|
|
|
|
use std::time::Duration;
|
|
|
|
use tethercore::{Engine, Message, MessageHandler};
|
|
|
|
struct Printer;
|
|
impl MessageHandler for Printer {
|
|
fn on_message(&self, msg: Message) {
|
|
println!("RECV {}", msg.text);
|
|
}
|
|
fn on_status(&self, _connected: bool) {}
|
|
fn on_file(&self, _name: String, _mime: String, _data: Vec<u8>) {}
|
|
}
|
|
|
|
fn main() {
|
|
let room = std::env::args().nth(1).unwrap_or_else(|| "lan-verify".into());
|
|
let send = std::env::args().nth(2);
|
|
// High `from` so it accepts the agent's dial (lower id dials).
|
|
let e = Engine::new("http://127.0.0.1:1".into(), room, "zzz-peer".into(), "peer".into(), "Rust LAN Peer".into(), "".into());
|
|
e.start(Box::new(Printer));
|
|
|
|
std::thread::sleep(Duration::from_secs(6)); // let mDNS discover + TCP connect
|
|
if let Some(s) = send {
|
|
e.send(s);
|
|
}
|
|
std::thread::sleep(Duration::from_secs(8));
|
|
}
|