feat(input): Migrate to moq for input transmission (#38)

## Description

**What issue are you solving (or what feature are you adding) and how
are you doing it?**

We cannot use golang for our input binary as we will be redoing the
Webtransport stack, plus we will have to use CGO in-order to hook into
X11. Like what [neko](https://github.com/m1k1o/neko) does.

However, we could go down the Rust route, where X11 mouse/keyboard
drivers are in pretty, and moq-rs (the MoQ library using Webtransport)
works really well. So, that is what am trying to do here; implement
input using rust.
This commit is contained in:
Wanjohi
2024-05-18 01:51:35 +03:00
committed by GitHub
parent 3a7d404a26
commit c0f573599f
10 changed files with 2265 additions and 10 deletions

76
bin/input/src/main.rs Normal file
View File

@@ -0,0 +1,76 @@
use moq_transport::{serve, session::Subscriber};
use moq_native::quic;
use std::net;
use url::Url;
use anyhow::Context;
use clap::Parser;
mod input;
#[derive(Parser, Clone)]
pub struct Cli {
/// Listen for UDP packets on the given address.
#[arg(long, default_value = "[::]:0")]
pub bind: net::SocketAddr,
/// Connect to the given URL starting with https://
#[arg()]
pub url: Url,
/// The TLS configuration.
#[command(flatten)]
pub tls: moq_native::tls::Cli,
// /// Publish the current time to the relay, otherwise only subscribe.
// #[arg(long)]
// pub publish: bool,
/// The name of the input track.
#[arg(long, default_value = "netris")]
pub namespace: String,
/// The name of the input track.
#[arg(long, default_value = ".catalog")]
pub track: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
// Disable tracing so we don't get a bunch of Quinn spam.
let tracer = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::WARN)
.finish();
tracing::subscriber::set_global_default(tracer).unwrap();
let config = Cli::parse();
let tls = config.tls.load()?;
let quic = quic::Endpoint::new(quic::Config {
bind: config.bind,
tls,
})?;
log::info!("connecting to server: url={}", config.url);
let session = quic.client.connect(&config.url).await?;
let (session, mut subscriber) = Subscriber::connect(session)
.await
.context("failed to create MoQ Transport session")?;
let (prod, sub) = serve::Track::new(config.namespace, config.track).produce();
let input = input::Subscriber::new(sub);
//TODO: Make sure to retry until the input server comes [Use Supervisord for now]
tokio::select! {
res = session.run() => res.context("session error")?,
res = input.run() => res.context("input error")?,
res = subscriber.subscribe(prod) => res.context("failed to subscribe to track")?,
}
Ok(())
}