initialize method
Connect to the Onvif device and retrieve its capabilities
Implementation
Future<void> initialize() async {
loggy.info('initializing ...');
Media1? media1;
Media2? media2;
soap.Transport.timeDelta = await getTimeDelta();
try {
final serviceList = await deviceManagement.getServices(
includeCapability: true,
);
serviceMap.addAll(
{for (var service in serviceList) service.nameSpace: service.xAddr});
if (serviceMap.containsKey(soap.Xmlns.timg)) {
_imaging = Imaging(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.timg]!));
}
if (serviceMap.containsKey(soap.Xmlns.trt)) {
media1 = Media1(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.trt]!));
}
if (serviceMap.containsKey(soap.Xmlns.tr2)) {
media2 = Media2(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.tr2]!));
}
if (serviceMap.containsKey(soap.Xmlns.tptz)) {
_ptz = Ptz(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.tptz]!));
}
if (serviceMap.containsKey(soap.Xmlns.trc)) {
_recordings = Recordings(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.trc]!));
}
if (serviceMap.containsKey(soap.Xmlns.trp)) {
_replay = Replay(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.trp]!));
}
if (serviceMap.containsKey(soap.Xmlns.tse)) {
_search = Search(
transport: transport,
uri: _serviceUriOfHost(serviceMap[soap.Xmlns.tse]!));
}
if (media1 != null || media2 != null) {
_media = Media(
transport: transport,
media1: media1,
media2: media2,
);
}
} catch (e) {
loggy.warning('GetServices command not supported');
} finally {
if (serviceMap.isEmpty) {
final capabilities = await deviceManagement.getCapabilities();
if (_imaging == null && capabilities.imaging?.xAddr != null) {
_imaging = Imaging(
transport: transport,
uri: _serviceUriOfHost(capabilities.imaging!.xAddr));
}
if (_media == null && capabilities.media?.xAddr != null) {
_media = Media(
transport: transport,
media1: Media1(
transport: transport,
uri: _serviceUriOfHost(capabilities.media!.xAddr)),
);
}
if (_ptz == null && capabilities.ptz?.xAddr != null) {
_ptz = Ptz(
transport: transport,
uri: _serviceUriOfHost(capabilities.ptz!.xAddr));
}
}
}
loggy.info('initialization complete');
}