Skip to content

Commit

Permalink
Move to vm_service_lib-provided helper
Browse files Browse the repository at this point in the history
Removes both copies of `getVmServiceUriFromObservatoryUri` and calls the shared `convertToWebSocketUrl` method.
  • Loading branch information
DanTup committed Apr 24, 2019
1 parent 2697b27 commit 1890569
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 40 deletions.
4 changes: 2 additions & 2 deletions packages/devtools/lib/src/framework/framework_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions packages/devtools/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ class Property<T> {
Stream<T> 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();
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools/test/support/cli_test_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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()));
Expand Down
5 changes: 3 additions & 2 deletions packages/devtools/test/support/flutter_test_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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()),
Expand Down
20 changes: 2 additions & 18 deletions packages/devtools_server/lib/src/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -235,7 +236,7 @@ Future<void> registerLaunchDevToolsService(

Future<VmService> _connectToVmService(Uri uri) async {
// Fix up the various acceptable URI formats into a WebSocket URI to connect.
uri = getVmServiceUriFromObservatoryUri(uri);
uri = convertToWebSocketUrl(serviceProtocolUrl: uri);

final WebSocket ws = await WebSocket.connect(uri.toString());

Expand Down Expand Up @@ -269,20 +270,3 @@ void printOutput(
}) {
print(machineMode ? jsonEncode(json) : message);
}

/// 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) {
// TODO(dantup): We have two copies of this and should move it to vm_service_lib
// then switch to that.
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);
}
2 changes: 1 addition & 1 deletion packages/devtools_server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1890569

Please sign in to comment.