startDartDevelopmentService static method

Future<DartDevelopmentService> startDartDevelopmentService(
  1. Uri remoteVmServiceUri, {
  2. Uri serviceUri,
  3. bool enableAuthCodes = true,
  4. bool ipv6 = false,
  5. DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration(),
  6. bool logRequests = false,
})

Creates a DartDevelopmentService instance which will communicate with a VM service. Requires the target VM service to have no other connected clients.

remoteVmServiceUri is the address of the VM service that this development service will communicate with.

If provided, serviceUri will determine the address and port of the spawned Dart Development Service. The format of serviceUri must be consistent with the protocol determined by ipv6.

enableAuthCodes controls whether or not an authentication code must be provided by clients when communicating with this instance of DartDevelopmentService. Authentication codes take the form of a base64 encoded string provided as the first element of the DDS path and is meant to make it more difficult for unintended clients to connect to this service. Authentication codes are enabled by default.

ipv6 controls whether or not DDS is served via IPv6. IPv4 is enabled by default.

Implementation

static Future<DartDevelopmentService> startDartDevelopmentService(
  Uri remoteVmServiceUri, {
  Uri serviceUri,
  bool enableAuthCodes = true,
  bool ipv6 = false,
  DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration(),
  bool logRequests = false,
}) async {
  if (remoteVmServiceUri == null) {
    throw ArgumentError.notNull('remoteVmServiceUri');
  }
  if (remoteVmServiceUri.scheme != 'http') {
    throw ArgumentError(
      'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
    );
  }
  if (serviceUri != null) {
    if (serviceUri.scheme != 'http') {
      throw ArgumentError(
        'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
      );
    }

    // If provided an address to bind to, ensure it uses a protocol consistent
    // with that used to spawn DDS.
    final addresses = await InternetAddress.lookup(serviceUri.host);
    final address = addresses.firstWhere(
      (a) => (a.type ==
          (ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
      orElse: () => null,
    );
    if (address == null) {
      throw ArgumentError(
        "serviceUri '$serviceUri' is not an IPv${ipv6 ? "6" : "4"} address.",
      );
    }
  }

  final service = DartDevelopmentServiceImpl(
    remoteVmServiceUri,
    serviceUri,
    enableAuthCodes,
    ipv6,
    devToolsConfiguration,
    logRequests,
  );
  await service.startService();
  return service;
}