mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Start work on iOS rppairing
This commit is contained in:
644
Cargo.lock
generated
644
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -168,7 +168,7 @@ plist = { version = "1.7" }
|
|||||||
ns-keyed-archive = "0.1.2"
|
ns-keyed-archive = "0.1.2"
|
||||||
uuid = "1.16"
|
uuid = "1.16"
|
||||||
futures-util = { version = "0.3" }
|
futures-util = { version = "0.3" }
|
||||||
mdns = { version = "3" }
|
zeroconf = { version = "0.17" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["aws-lc"]
|
default = ["aws-lc"]
|
||||||
|
|||||||
@@ -4,18 +4,22 @@
|
|||||||
|
|
||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
use std::{io::Write, net::IpAddr, str::FromStr, time::Duration};
|
use std::{any::Any, io::Write, net::IpAddr, str::FromStr, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use futures_util::{StreamExt, pin_mut};
|
use futures_util::{StreamExt, pin_mut};
|
||||||
use idevice::remote_pairing::{RemotePairingClient, RpPairingFile};
|
use idevice::remote_pairing::{RemotePairingClient, RpPairingFile};
|
||||||
use mdns::{Record, RecordKind};
|
use zeroconf::{
|
||||||
|
BrowserEvent, MdnsBrowser, ServiceDiscovery, ServiceType,
|
||||||
|
prelude::{TEventLoop, TMdnsBrowser},
|
||||||
|
};
|
||||||
|
|
||||||
const SERVICE_NAME: &'static str = "ncm._remoted._tcp.local.";
|
const SERVICE_NAME: &str = "remoted";
|
||||||
|
const SERVICE_PROTOCOL: &str = "tcp";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let matches = Command::new("pair")
|
let matches = Command::new("pair")
|
||||||
.about("Pair with the device")
|
.about("Pair with the device")
|
||||||
@@ -33,26 +37,26 @@ async fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = mdns::discover::all(SERVICE_NAME, Duration::from_secs(1))
|
let mut browser = MdnsBrowser::new(
|
||||||
.unwrap()
|
ServiceType::new(SERVICE_NAME, SERVICE_PROTOCOL).expect("Unable to start mDNS browse"),
|
||||||
.listen();
|
);
|
||||||
pin_mut!(stream);
|
browser.set_service_callback(Box::new(on_service_discovered));
|
||||||
|
|
||||||
while let Some(Ok(response)) = stream.next().await {
|
let event_loop = browser.browse_services().unwrap();
|
||||||
let addr = response.records().filter_map(self::to_ip_addr).next();
|
|
||||||
|
|
||||||
if let Some(addr) = addr {
|
loop {
|
||||||
println!("found cast device at {}", addr);
|
// calling `poll()` will keep this browser alive
|
||||||
} else {
|
event_loop.poll(Duration::from_secs(0)).unwrap();
|
||||||
println!("cast device does not advertise address");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_ip_addr(record: &Record) -> Option<IpAddr> {
|
fn on_service_discovered(
|
||||||
match record.kind {
|
result: zeroconf::Result<BrowserEvent>,
|
||||||
RecordKind::A(addr) => Some(addr.into()),
|
_context: Option<Arc<dyn Any + Send + Sync>>,
|
||||||
RecordKind::AAAA(addr) => Some(addr.into()),
|
) {
|
||||||
_ => None,
|
if let Ok(BrowserEvent::Add(result)) = result {
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
println!("{result:?}");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user