Skip to content

Commit

Permalink
Merge pull request #119 from SamuelYvon/main
Browse files Browse the repository at this point in the history
Expose hardware and device types in `discover`
  • Loading branch information
DmitrySamoylov authored Feb 28, 2024
2 parents 49c3f06 + 9f3508c commit c71e8cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions onvif/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ pub enum Error {
pub struct Device {
/// The WS-Discovery UUID / address reference
pub address: String,
pub hardware: Option<String>,
pub name: Option<String>,
pub types: Vec<String>,
pub urls: Vec<Url>,
}

Expand Down Expand Up @@ -229,12 +231,20 @@ fn device_from_envelope(envelope: probe_matches::Envelope) -> Option<Device> {

let name = onvif_probe_match.name();
let urls = onvif_probe_match.x_addrs();
let hardware = onvif_probe_match.hardware();
let address = onvif_probe_match.endpoint_reference_address();
let types = onvif_probe_match
.types()
.into_iter()
.map(Into::into)
.collect();

Some(Device {
name,
urls,
address,
hardware,
types,
})
}

Expand Down Expand Up @@ -315,7 +325,9 @@ fn test_xaddrs_extraction() {
Url::parse("http://addr_22").unwrap(),
],
name: Some("MyCamera2000".to_string()),
hardware: None,
address: DEVICE_ADDRESS.to_string(),
types: vec![]
}]
);
}
13 changes: 12 additions & 1 deletion wsdl_rs/ws_discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ pub mod probe_matches {

impl ProbeMatch {
pub fn types(&self) -> Vec<&str> {
self.types.split_whitespace().collect()
self.types
.split_whitespace()
.map(|t: &str| {
// Remove WSDL prefixes
match t.find(':') {
Some(idx) => t.split_at(idx + 1).1,
None => t,
}
})
.collect()
}

pub fn scopes(&self) -> Vec<Url> {
Expand Down Expand Up @@ -221,5 +230,7 @@ pub mod probe_matches {
Url::parse("http://10.0.0.200:80/onvif/device_service").unwrap(),
]
);

assert_eq!(de.types(), vec!["NetworkVideoTransmitter", "Device"]);
}
}

0 comments on commit c71e8cb

Please sign in to comment.