diff --git a/packages/devtools/lib/src/framework/framework_core.dart b/packages/devtools/lib/src/framework/framework_core.dart index 2173086dcdb..8d4661b9b85 100644 --- a/packages/devtools/lib/src/framework/framework_core.dart +++ b/packages/devtools/lib/src/framework/framework_core.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:html' hide Screen; -import 'package:devtools/src/utils.dart'; +import 'package:vm_service_lib/utils.dart'; import '../../devtools.dart' as devtools show version; import '../core/message_bus.dart'; @@ -45,7 +45,7 @@ class FrameworkCore { // Map the URI (which may be Observatory web app) to a WebSocket URI for // the VM service. - uri = getVmServiceUriFromObservatoryUri(uri); + uri = convertToWebSocketUrl(serviceProtocolUrl: uri); try { final VmServiceWrapper service = await connect(uri, finishedCompleter); diff --git a/packages/devtools/lib/src/utils.dart b/packages/devtools/lib/src/utils.dart index 2a7614fd5b8..68265c19c26 100644 --- a/packages/devtools/lib/src/utils.dart +++ b/packages/devtools/lib/src/utils.dart @@ -163,20 +163,6 @@ class Property { Stream get onValueChange => _changeController.stream; } -/// Map the URI (which may already be Observatory web app) to a WebSocket URI -/// for the VM service. If the URI is already a VM Service WebSocket URI it -/// will not be modified. -Uri getVmServiceUriFromObservatoryUri(Uri uri) { - final isSecure = uri.isScheme('wss') || uri.isScheme('https'); - final scheme = isSecure ? 'wss' : 'ws'; - - final path = uri.path.endsWith('/ws') - ? uri.path - : (uri.path.endsWith('/') ? '${uri.path}ws' : '${uri.path}/ws'); - - return uri.replace(scheme: scheme, path: path); -} - /// A typedef to represent a function taking no arguments and with no return /// value. typedef VoidFunction = void Function(); diff --git a/packages/devtools/pubspec.yaml b/packages/devtools/pubspec.yaml index 3e9e88532f8..026bf6de5d5 100644 --- a/packages/devtools/pubspec.yaml +++ b/packages/devtools/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: pedantic: ^1.4.0 platform_detect: ^1.3.5 rxdart: ^0.21.0 - vm_service_lib: ^3.14.3-dev.4 + vm_service_lib: ^3.15.1+1 # We would use local dependencies for these packages if pub publish allowed it. octicons_css: ^0.0.1 diff --git a/packages/devtools/test/support/cli_test_driver.dart b/packages/devtools/test/support/cli_test_driver.dart index 20f842defd9..858960bf4f5 100644 --- a/packages/devtools/test/support/cli_test_driver.dart +++ b/packages/devtools/test/support/cli_test_driver.dart @@ -6,8 +6,8 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:devtools/src/utils.dart'; import 'package:devtools/src/vm_service_wrapper.dart'; +import 'package:vm_service_lib/utils.dart'; import 'package:vm_service_lib/vm_service_lib.dart'; import 'package:vm_service_lib/vm_service_lib_io.dart'; @@ -105,7 +105,7 @@ class CliAppFixture extends AppFixture { } // Map to WS URI. - uri = getVmServiceUriFromObservatoryUri(uri); + uri = convertToWebSocketUrl(serviceProtocolUrl: uri); final VmServiceWrapper serviceConnection = VmServiceWrapper(await vmServiceConnectUri(uri.toString())); diff --git a/packages/devtools/test/support/flutter_test_driver.dart b/packages/devtools/test/support/flutter_test_driver.dart index 448020ecc8d..9daa44450d0 100644 --- a/packages/devtools/test/support/flutter_test_driver.dart +++ b/packages/devtools/test/support/flutter_test_driver.dart @@ -6,9 +6,9 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:devtools/src/utils.dart'; import 'package:devtools/src/vm_service_wrapper.dart'; import 'package:pedantic/pedantic.dart'; +import 'package:vm_service_lib/utils.dart'; import 'package:vm_service_lib/vm_service_lib.dart'; import 'package:vm_service_lib/vm_service_lib_io.dart'; @@ -324,7 +324,8 @@ class FlutterRunTestDriver extends FlutterTestDriver { _vmServiceWsUri = Uri.parse(wsUriString); // Map to WS URI. - _vmServiceWsUri = getVmServiceUriFromObservatoryUri(_vmServiceWsUri); + _vmServiceWsUri = + convertToWebSocketUrl(serviceProtocolUrl: _vmServiceWsUri); vmService = VmServiceWrapper( await vmServiceConnectUri(_vmServiceWsUri.toString()), diff --git a/packages/devtools_server/lib/src/server.dart b/packages/devtools_server/lib/src/server.dart index 1b8397fdd73..e8978d6bac9 100644 --- a/packages/devtools_server/lib/src/server.dart +++ b/packages/devtools_server/lib/src/server.dart @@ -13,6 +13,7 @@ import 'package:path/path.dart' as path; import 'package:shelf/shelf.dart' as shelf; import 'package:shelf/shelf_io.dart' as shelf; import 'package:shelf_static/shelf_static.dart'; +import 'package:vm_service_lib/utils.dart'; import 'package:vm_service_lib/vm_service_lib.dart' hide Isolate; import 'chrome.dart'; @@ -102,6 +103,10 @@ void serveDevTools({ printOutput( 'Serving DevTools at $devToolsUrl', { + 'event': 'server.started', + // TODO(dantup): Remove this `method` field when we're sure VS Code users + // are all on a newer version that uses `event`. We incorrectly used + // `method` for the original releases. 'method': 'server.started', 'params': {'host': server.address.host, 'port': server.port, 'pid': pid} }, @@ -125,39 +130,68 @@ void serveDevTools({ // } // } _stdinCommandStream.listen((Map json) async { - final int id = json['id']; + // ID can be String, int or null + final dynamic id = json['id']; final Map params = json['params']; - if (!params.containsKey('uri')) { - printOutput( - 'Invalid input: $params does not contain the key \'uri\'', - { - 'id': id, - 'error': 'Invalid input: $params does not contain the key \'uri\'', - }, - machineMode: machineMode, - ); + switch (json['method']) { + case 'vm.register': + await _handleVmRegister(id, params, machineMode, devToolsUrl); + break; + default: + printOutput( + 'Unknown method ${json['method']}', + { + 'id': id, + 'error': 'Unknown method ${json['method']}', + }, + machineMode: machineMode, + ); } - - // json['uri'] should contain a vm service uri. - final uri = Uri.parse(params['uri']); - - // Lots of things are considered valid URIs (including empty strings - // and single letters) since they can be relative, so we need to do some - // extra checks. - if (uri != null && - uri.isAbsolute && - (uri.isScheme('ws') || - uri.isScheme('wss') || - uri.isScheme('http') || - uri.isScheme('https'))) - await registerLaunchDevToolsService(uri, id, devToolsUrl, machineMode); }); } +Future _handleVmRegister(dynamic id, Map params, + bool machineMode, String devToolsUrl) async { + if (!params.containsKey('uri')) { + printOutput( + 'Invalid input: $params does not contain the key \'uri\'', + { + 'id': id, + 'error': 'Invalid input: $params does not contain the key \'uri\'', + }, + machineMode: machineMode, + ); + } + + // json['uri'] should contain a vm service uri. + final uri = Uri.tryParse(params['uri']); + + // Lots of things are considered valid URIs (including empty strings + // and single letters) since they can be relative, so we need to do some + // extra checks. + if (uri != null && + uri.isAbsolute && + (uri.isScheme('ws') || + uri.isScheme('wss') || + uri.isScheme('http') || + uri.isScheme('https'))) { + await registerLaunchDevToolsService(uri, id, devToolsUrl, machineMode); + } else { + printOutput( + 'Uri must be absolute with a http, https, ws or wss scheme', + { + 'id': id, + 'error': 'Uri must be absolute with a http, https, ws or wss scheme', + }, + machineMode: machineMode, + ); + } +} + Future registerLaunchDevToolsService( Uri uri, - int id, + dynamic id, String devToolsUrl, bool machineMode, ) async { @@ -184,7 +218,7 @@ Future registerLaunchDevToolsService( 'Successfully registered launchDevTools service', { 'id': id, - 'result': Success().toJson(), + 'result': {'success': true}, }, machineMode: machineMode, ); @@ -201,6 +235,9 @@ Future registerLaunchDevToolsService( } Future _connectToVmService(Uri uri) async { + // Fix up the various acceptable URI formats into a WebSocket URI to connect. + uri = convertToWebSocketUrl(serviceProtocolUrl: uri); + final WebSocket ws = await WebSocket.connect(uri.toString()); final VmService service = VmService( diff --git a/packages/devtools_server/pubspec.yaml b/packages/devtools_server/pubspec.yaml index f38ed7bad60..13d4fdd90a2 100644 --- a/packages/devtools_server/pubspec.yaml +++ b/packages/devtools_server/pubspec.yaml @@ -16,5 +16,5 @@ dependencies: pedantic: ^1.4.0 shelf: ^0.7.4 shelf_static: ^0.2.8 - vm_service_lib: ^3.14.3-dev.4 + vm_service_lib: ^3.15.1+1 webkit_inspection_protocol: ^0.4.0