hello static method

XmlDocument hello({
  1. required List<String> xAddrs,
  2. required int messageNumber,
  3. String? messageId,
  4. String? address,
  5. List<String> scopes = const ['onvif://www.onvif.org/location/country/US'],
})

Creates a Hello message for WS-Discovery.

Implementation

static XmlDocument hello({
  required List<String> xAddrs,
  required int messageNumber,
  String? messageId,
  String? address,
  List<String> scopes = const ['onvif://www.onvif.org/location/country/US'],
}) {
  builder.declaration(encoding: 'UTF-8');

  builder.element(
    'Envelope',
    namespace: 'http://www.w3.org/2003/05/soap-envelope',
    nest: () {
      builder.namespace('http://www.w3.org/2003/05/soap-envelope', 's');
      builder.namespace(
        'http://schemas.xmlsoap.org/ws/2004/08/addressing',
        'a',
      );
      builder.namespace(
        'http://schemas.xmlsoap.org/ws/2005/04/discovery',
        'd',
      );

      builder.element(
        'Header',
        // namespace: 'http://www.w3.org/2003/05/soap-envelope',
        nest: () {
          builder.element(
            'Action',
            namespace: 'http://schemas.xmlsoap.org/ws/2004/08/addressing',
            nest: 'http://schemas.xmlsoap.org/ws/2005/04/discovery/Hello',
          );

          builder.element(
            'MessageID',
            namespace: 'http://schemas.xmlsoap.org/ws/2004/08/addressing',
            nest: 'uuid:${messageId ?? uuid}',
          );

          builder.element(
            'AppSequence',
            namespace: 'http://schemas.xmlsoap.org/ws/2005/04/discovery',
            nest: () {
              builder.attribute('InstanceId', '1');

              builder.attribute('SequenceId', 'urn:uuid:$uuid');

              builder.attribute('MessageNumber', '$messageNumber');
            },
          );
        },
      );

      builder.element(
        'Body',
        // namespace: 'http://www.w3.org/2003/05/soap-envelope',
        nest: () {
          builder.element(
            'Hello',
            namespace: 'http://schemas.xmlsoap.org/ws/2005/04/discovery',
            nest: () {
              builder.element(
                'EndpointReference',
                namespace: 'http://schemas.xmlsoap.org/ws/2004/08/addressing',
                nest: () {
                  builder.element(
                    'Address',
                    // namespace:
                    //     'http://schemas.xmlsoap.org/ws/2004/08/addressing',
                    nest: 'urn:uuid:$address',
                  );
                },
              );

              builder.element('Types', nest: 'dn:NetworkVideoTransmitter');

              for (var scope in scopes) {
                builder.element('Scopes', nest: scope);
              }

              for (var xAddr in xAddrs) {
                builder.element('XAddrs', nest: xAddr);
              }

              builder.element('MetadataVersion', nest: '1');
            },
          );
        },
      );
    },
  );

  return builder.buildDocument();
}