use async_trait::async_trait;
use onvif_server::{DeviceInfo, DeviceService, MediaService, OnvifError, OnvifServer};
#[derive(Clone)]
struct MinimalCamera {
media_host: String,
}
#[async_trait]
impl DeviceService for MinimalCamera {
async fn get_device_information(&self) -> Result<DeviceInfo, OnvifError> {
Ok(DeviceInfo {
manufacturer: "Example Corp".to_string(),
model: "Minimal-1".to_string(),
firmware_version: "1.0.0".to_string(),
serial_number: "SN-0001".to_string(),
hardware_id: "minimal-hw-1".to_string(),
})
}
}
#[async_trait]
impl MediaService for MinimalCamera {
async fn get_stream_uri(&self, _profile_token: &str) -> Result<String, OnvifError> {
Ok(format!("rtsp://{}:8554/stream", self.media_host))
}
async fn get_snapshot_uri(&self, _profile_token: &str) -> Result<String, OnvifError> {
Ok(format!("http://{}:8080/snapshot.jpg", self.media_host))
}
}
#[tokio::main]
async fn main() {
let host = "127.0.0.1";
let cam = MinimalCamera {
media_host: host.to_string(),
};
println!("Minimal ONVIF device on :8080");
println!(" Device service: http://{host}:8080/onvif/device_service");
println!(" Media service: http://{host}:8080/onvif/media_service");
println!(" Credentials: admin / password");
OnvifServer::builder()
.port(8080)
.advertised_host(host)
.device_service(cam.clone())
.media_service(cam)
.auth("admin", "password")
.build()
.expect("build failed")
.run()
.await
.expect("server error");
}