diff --git a/README.md b/README.md index af2e82a..4a7fd01 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,11 @@ fn on_service_registered( use std::any::Any; use std::sync::Arc; use std::time::Duration; -use zeroconf::{MdnsBrowser, ServiceDiscovery}; use zeroconf::prelude::*; +use zeroconf::{MdnsBrowser, ServiceDiscovery, ServiceType}; fn main() { - let mut browser = MdnsBrowser::new("_http._tcp"); + let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap()); browser.set_service_discovered_callback(Box::new(on_service_discovered)); diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 7476f86..219b55b 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -502,7 +502,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "zeroconf" -version = "0.7.2" +version = "0.8.2" dependencies = [ "avahi-sys", "bonjour-sys", diff --git a/examples/browser/src/main.rs b/examples/browser/src/main.rs index 7248169..b62117c 100644 --- a/examples/browser/src/main.rs +++ b/examples/browser/src/main.rs @@ -1,11 +1,11 @@ use std::any::Any; use std::sync::Arc; use std::time::Duration; -use zeroconf::{MdnsBrowser, ServiceDiscovery}; use zeroconf::prelude::*; +use zeroconf::{MdnsBrowser, ServiceDiscovery, ServiceType}; fn main() { - let mut browser = MdnsBrowser::new("_http._tcp"); + let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap()); browser.set_service_discovered_callback(Box::new(on_service_discovered)); diff --git a/zeroconf/src/browser.rs b/zeroconf/src/browser.rs index 6b92524..0cf1bf9 100644 --- a/zeroconf/src/browser.rs +++ b/zeroconf/src/browser.rs @@ -1,13 +1,13 @@ //! Trait definition for cross-platform browser -use crate::{EventLoop, NetworkInterface, Result, TxtRecord}; +use crate::{EventLoop, NetworkInterface, Result, ServiceType, TxtRecord}; use std::any::Any; use std::sync::Arc; /// Interface for interacting with underlying mDNS implementation service browsing capabilities. pub trait TMdnsBrowser { /// Creates a new `MdnsBrowser` that browses for the specified `kind` (e.g. `_http._tcp`) - fn new(kind: &str) -> Self; + fn new(service_type: ServiceType) -> Self; /// Sets the network interface on which to browse for services on. /// @@ -49,7 +49,7 @@ pub type ServiceDiscoveredCallback = dyn Fn(Result, Option Self { + fn new(service_type: ServiceType) -> Self { Self { client: None, poll: None, browser: None, - kind: c_string!(kind.to_string()), + kind: c_string!(service_type.to_string()), context: Box::into_raw(Box::default()), interface_index: constants::AVAHI_IF_UNSPEC, } @@ -268,7 +272,7 @@ unsafe fn handle_resolver_found( let result = ServiceDiscovery::builder() .name(name.to_string()) - .kind(kind.to_string()) + .service_type(ServiceType::from_str(kind)?) .domain(domain.to_string()) .host_name(host_name.to_string()) .address(address) diff --git a/zeroconf/src/tests/service_test.rs b/zeroconf/src/tests/service_test.rs index 4b98230..14ef61b 100644 --- a/zeroconf/src/tests/service_test.rs +++ b/zeroconf/src/tests/service_test.rs @@ -25,7 +25,7 @@ fn service_register_is_browsable() { service.set_txt_record(txt.clone()); service.set_registered_callback(Box::new(|_, context| { - let mut browser = MdnsBrowser::new("_http._tcp"); + let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap()); let context = context .as_ref()