getServiceUrls method

Future<Map<String, String>> getServiceUrls()

Returns service URLs extracted from GetCapabilities. Keys: 'Device', 'Events', 'Imaging', 'Media', 'PTZ', 'DeviceIO', etc.

Implementation

Future<Map<String, String>> getServiceUrls() async {
  const String body =
      '<tds:GetCapabilities>'
      '<tds:Category>All</tds:Category>'
      '</tds:GetCapabilities>';
  final response = await client.soapRequest(
    body,
    action: 'http://www.onvif.org/ver10/device/wsdl/GetCapabilities',
  );

  final document = XmlDocument.parse(response);
  const ttNs = 'http://www.onvif.org/ver10/schema';
  final result = <String, String>{};

  for (final name in ['Device', 'Events', 'Imaging', 'Media', 'PTZ', 'Analytics']) {
    final el = document.findAllElements(name, namespace: ttNs).firstOrNull;
    final xaddr = el?.findElements('XAddr', namespace: ttNs).firstOrNull;
    if (xaddr != null) result[name] = xaddr.innerText.trim();
  }

  for (final name in ['DeviceIO', 'Recording', 'Search', 'Replay', 'Receiver']) {
    final el = document.findAllElements(name, namespace: ttNs).firstOrNull;
    final xaddr = el?.findElements('XAddr', namespace: ttNs).firstOrNull;
    if (xaddr != null) result[name] = xaddr.innerText.trim();
  }

  OnvifLogger.instance.log(
    'GetCapabilities services=${result.keys.join(',')}',
    name: _tag,
  );
  return result;
}