Files
sdk/pkg/dds/lib/dds.dart
T
Ben Konyi c97ed9cc11 [ package:dds / Service ] Add support for service extensions to DDS
With this change, DDS takes responsibility for service extension
registration via the service protocol in addition to handling service
extension request routing.

Service extensions registered through dart:developer will continue to
be handled by the VM service as those extensions live within the main
Dart process (this functionality already worked before this CL).

This change also includes a version bump for package:json_rpc_2 to pull
in a bug fix required for this change.

Change-Id: Idb6050058f7695d34276953be159419a5b1b9711
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144349
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-04-24 17:13:57 +00:00

110 lines
3.7 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// A library used to spawn the Dart Developer Service, used to communicate
/// with a Dart VM Service instance.
library dds;
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:async/async.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_proxy/shelf_proxy.dart';
import 'package:shelf_web_socket/shelf_web_socket.dart';
import 'package:stream_channel/stream_channel.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
part 'src/binary_compatible_peer.dart';
part 'src/client.dart';
part 'src/dds_impl.dart';
part 'src/named_lookup.dart';
part 'src/rpc_error_codes.dart';
part 'src/stream_manager.dart';
/// An intermediary between a Dart VM service and its clients that offers
/// additional functionality on top of the standard VM service protocol.
///
/// See the [Dart Development Service Protocol](https://github.com/dart-lang/sdk/blob/master/pkg/dds/dds_protocol.md)
/// for details.
abstract class DartDevelopmentService {
/// 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.
static Future<DartDevelopmentService> startDartDevelopmentService(
Uri remoteVmServiceUri, {
Uri serviceUri,
}) 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 && serviceUri.scheme != 'http') {
throw ArgumentError(
'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
);
}
final service = _DartDevelopmentService(remoteVmServiceUri, serviceUri);
await service.startService();
return service;
}
DartDevelopmentService._();
/// Stop accepting requests after gracefully handling existing requests.
Future<void> shutdown();
/// The HTTP [Uri] of the remote VM service instance that this service will
/// forward requests to.
Uri get remoteVmServiceUri;
/// The web socket [Uri] of the remote VM service instance that this service
/// will forward requests to.
///
/// Can be used with [WebSocket] to communicate directly with the VM service.
Uri get remoteVmServiceWsUri;
/// The [Uri] VM service clients can use to communicate with this
/// [DartDevelopmentService] via HTTP.
///
/// Returns `null` if the service is not running.
Uri get uri;
/// The [Uri] VM service clients can use to communicate with this
/// [DartDevelopmentService] via a [WebSocket].
///
/// Returns `null` if the service is not running.
Uri get wsUri;
/// Set to `true` if this instance of [DartDevelopmentService] is accepting
/// requests.
bool get isRunning;
}
class DartDevelopmentServiceException implements Exception {
DartDevelopmentServiceException._(this.message);
String toString() => 'DartDevelopmentServiceException: $message';
final String message;
}