diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe24ae734b..9dcfa0ffb7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,10 @@ *even if the set is empty* (in which case it just compares the element to itself). +#### `dart:developer` + +- Added `serverWebSocketUri` property to `ServiceProtocolInfo`. + ### Dart VM ### Tools diff --git a/runtime/observatory/tests/service/developer_server_control_test.dart b/runtime/observatory/tests/service/developer_server_control_test.dart index f599dc3bf88..18498f233b4 100644 --- a/runtime/observatory/tests/service/developer_server_control_test.dart +++ b/runtime/observatory/tests/service/developer_server_control_test.dart @@ -11,6 +11,7 @@ import 'test_helper.dart'; int? majorVersion; int? minorVersion; Uri? serverUri; +Uri? wsServerUri; Future testeeBefore() async { print('testee before'); @@ -20,8 +21,8 @@ Future testeeBefore() async { ServiceProtocolInfo info = await Service.getInfo(); majorVersion = info.majorVersion; minorVersion = info.minorVersion; - serverUri = info.serverUri; Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); { // Now, start the web server and store the URI which is expected to be // non NULL in the top level variable. @@ -30,7 +31,11 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.isNotNull(info.serverUri); + Expect.isNotNull(info.serverWebSocketUri); serverUri = info.serverUri; + wsServerUri = info.serverWebSocketUri; + Expect.equals(wsServerUri!.scheme, 'ws'); + Expect.isTrue(wsServerUri!.path.endsWith('ws')); } { // Now try starting the web server again, this should just return the @@ -39,6 +44,7 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.equals(info.serverUri, serverUri); + Expect.equals(info.serverWebSocketUri, wsServerUri); } { // Try turning off the web server, this should turn off the server and @@ -47,6 +53,7 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); } { // Try turning off the web server again, this should be a nop @@ -55,16 +62,17 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); } { // Start the web server again for the test below. ServiceProtocolInfo info = await Service.controlWebServer(enable: true); majorVersion = info.majorVersion; minorVersion = info.minorVersion; - serverUri = info.serverUri; Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); - Expect.equals(info.serverUri, serverUri); + Expect.isNotNull(info.serverUri); + Expect.isNotNull(info.serverWebSocketUri); } } diff --git a/runtime/observatory_2/tests/service_2/developer_server_control_test.dart b/runtime/observatory_2/tests/service_2/developer_server_control_test.dart index 62889e45dc5..c4a81392e9c 100644 --- a/runtime/observatory_2/tests/service_2/developer_server_control_test.dart +++ b/runtime/observatory_2/tests/service_2/developer_server_control_test.dart @@ -11,6 +11,7 @@ import 'test_helper.dart'; int majorVersion; int minorVersion; Uri serverUri; +Uri wsServerUri; Future testeeBefore() async { print('testee before'); @@ -20,8 +21,8 @@ Future testeeBefore() async { ServiceProtocolInfo info = await Service.getInfo(); majorVersion = info.majorVersion; minorVersion = info.minorVersion; - serverUri = info.serverUri; Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); { // Now, start the web server and store the URI which is expected to be // non NULL in the top level variable. @@ -31,6 +32,9 @@ Future testeeBefore() async { Expect.equals(info.minorVersion, minorVersion); Expect.isNotNull(info.serverUri); serverUri = info.serverUri; + wsServerUri = info.serverWebSocketUri; + Expect.equals(wsServerUri.scheme, 'ws'); + Expect.isTrue(wsServerUri.path.endsWith('ws')); } { // Now try starting the web server again, this should just return the @@ -39,6 +43,7 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.equals(info.serverUri, serverUri); + Expect.equals(info.serverWebSocketUri, wsServerUri); } { // Try turning off the web server, this should turn off the server and @@ -47,6 +52,7 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); } { // Try turning off the web server again, this should be a nop @@ -55,16 +61,17 @@ Future testeeBefore() async { Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); Expect.isNull(info.serverUri); + Expect.isNull(info.serverWebSocketUri); } { // Start the web server again for the test below. ServiceProtocolInfo info = await Service.controlWebServer(enable: true); majorVersion = info.majorVersion; minorVersion = info.minorVersion; - serverUri = info.serverUri; Expect.equals(info.majorVersion, majorVersion); Expect.equals(info.minorVersion, minorVersion); - Expect.equals(info.serverUri, serverUri); + Expect.isNotNull(info.serverUri); + Expect.isNotNull(info.serverWebSocketUri); } } diff --git a/sdk/lib/developer/service.dart b/sdk/lib/developer/service.dart index 6fd58c31c57..8715d25d2a0 100644 --- a/sdk/lib/developer/service.dart +++ b/sdk/lib/developer/service.dart @@ -17,10 +17,30 @@ class ServiceProtocolInfo { /// not support the service protocol, this is 0. final int minorVersion = _getServiceMinorVersion(); - /// The Uri to access the service. If the web server is not running, this - /// will be null. + /// The Uri to connect to the debugger client hosted by the service. If the + /// web server is not running, this will be null. final Uri? serverUri; + /// The Uri to connect to the service via web socket. If the web server is + /// not running, this will be null. + Uri? get serverWebSocketUri { + Uri? uri = serverUri; + if (uri != null) { + final pathSegments = []; + if (uri.pathSegments.isNotEmpty) { + pathSegments.addAll(uri.pathSegments.where( + // Strip out the empty string that appears at the end of path segments. + // Empty string elements will result in an extra '/' being added to the + // URI. + (s) => s.isNotEmpty, + )); + } + pathSegments.add('ws'); + uri = uri.replace(scheme: 'ws', pathSegments: pathSegments); + } + return uri; + } + ServiceProtocolInfo(this.serverUri); String toString() {