Skip to content

Commit 9b16bb2

Browse files
committed
Allow for setting custom DDS port
Related to flutter/flutter#159157
1 parent ab620d1 commit 9b16bb2

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

dwds/lib/dart_web_debug_service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Dwds {
128128
debugSettings.expressionCompiler,
129129
injected,
130130
debugSettings.spawnDds,
131+
debugSettings.ddsPort,
131132
debugSettings.launchDevToolsInNewWindow,
132133
);
133134

dwds/lib/src/config/tool_configuration.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DebugSettings {
6161
final bool useSseForDebugBackend;
6262
final bool useSseForInjectedClient;
6363
final bool spawnDds;
64+
final int? ddsPort;
6465
final bool enableDevToolsLaunch;
6566
final bool launchDevToolsInNewWindow;
6667
final bool emitDebugEvents;
@@ -75,6 +76,7 @@ class DebugSettings {
7576
this.useSseForDebugBackend = true,
7677
this.useSseForInjectedClient = true,
7778
this.spawnDds = true,
79+
this.ddsPort,
7880
this.enableDevToolsLaunch = true,
7981
this.launchDevToolsInNewWindow = true,
8082
this.emitDebugEvents = true,

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class DevHandler {
6666
final bool _useSseForDebugProxy;
6767
final bool _useSseForInjectedClient;
6868
final bool _spawnDds;
69+
final int? _ddsPort;
6970
final bool _launchDevToolsInNewWindow;
7071
final ExpressionCompiler? _expressionCompiler;
7172
final DwdsInjector _injected;
@@ -90,6 +91,7 @@ class DevHandler {
9091
this._expressionCompiler,
9192
this._injected,
9293
this._spawnDds,
94+
this._ddsPort,
9395
this._launchDevToolsInNewWindow,
9496
) {
9597
_subs.add(buildResults.listen(_emitBuildResults));
@@ -215,6 +217,7 @@ class DevHandler {
215217
useSse: false,
216218
expressionCompiler: _expressionCompiler,
217219
spawnDds: _spawnDds,
220+
ddsPort: _ddsPort,
218221
);
219222
}
220223

@@ -645,6 +648,7 @@ class DevHandler {
645648
useSse: _useSseForDebugProxy,
646649
expressionCompiler: _expressionCompiler,
647650
spawnDds: _spawnDds,
651+
ddsPort: _ddsPort,
648652
);
649653
appServices = await _createAppDebugServices(
650654
debugService,

dwds/lib/src/services/debug_service.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class DebugService {
137137
final HttpServer _server;
138138
final bool _useSse;
139139
final bool _spawnDds;
140+
final int? _ddsPort;
140141
final UrlEncoder? _urlEncoder;
141142
DartDevelopmentServiceLauncher? _dds;
142143

@@ -154,6 +155,7 @@ class DebugService {
154155
this._server,
155156
this._useSse,
156157
this._spawnDds,
158+
this._ddsPort,
157159
this._urlEncoder,
158160
);
159161

@@ -175,7 +177,7 @@ class DebugService {
175177
serviceUri: Uri(
176178
scheme: 'http',
177179
host: hostname,
178-
port: 0,
180+
port: _ddsPort ?? 0,
179181
),
180182
);
181183
return _dds!;
@@ -231,6 +233,7 @@ class DebugService {
231233
void Function(Map<String, Object>)? onRequest,
232234
void Function(Map<String, Object?>)? onResponse,
233235
bool spawnDds = true,
236+
int? ddsPort,
234237
bool useSse = false,
235238
ExpressionCompiler? expressionCompiler,
236239
}) async {
@@ -299,6 +302,7 @@ class DebugService {
299302
server,
300303
useSse,
301304
spawnDds,
305+
ddsPort,
302306
urlEncoder,
303307
);
304308
}

dwds/test/dds_port_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@TestOn('vm')
6+
@Timeout(Duration(minutes: 2))
7+
library;
8+
9+
import 'dart:io';
10+
11+
import 'package:test/test.dart';
12+
import 'package:test_common/test_sdk_configuration.dart';
13+
14+
import 'fixtures/context.dart';
15+
import 'fixtures/project.dart';
16+
import 'fixtures/utilities.dart';
17+
18+
void main() {
19+
late final TestSdkConfigurationProvider provider;
20+
21+
setUp(() {
22+
provider = TestSdkConfigurationProvider();
23+
});
24+
25+
tearDown(() {
26+
provider.dispose();
27+
});
28+
29+
test('DWDS starts DDS with a specified port', () async {
30+
final context = TestContext(TestProject.test, provider);
31+
32+
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
33+
final expectedPort = server.port;
34+
await server.close();
35+
36+
await context.setUp(
37+
debugSettings: TestDebugSettings.noDevTools().copyWith(
38+
ddsPort: expectedPort,
39+
),
40+
);
41+
expect(Uri.parse(context.debugConnection.ddsUri!).port, expectedPort);
42+
});
43+
}

dwds/test/fixtures/utilities.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class TestDebugSettings extends DebugSettings {
125125
required super.useSseForDebugProxy,
126126
required super.useSseForInjectedClient,
127127
required super.spawnDds,
128+
required super.ddsPort,
128129
required super.enableDevToolsLaunch,
129130
required super.launchDevToolsInNewWindow,
130131
required super.emitDebugEvents,
@@ -138,6 +139,7 @@ class TestDebugSettings extends DebugSettings {
138139
bool? enableDebugExtension,
139140
bool? useSse,
140141
bool? spawnDds,
142+
int? ddsPort,
141143
bool? enableDevToolsLaunch,
142144
bool? launchDevToolsInNewWindow,
143145
bool? emitDebugEvents,
@@ -152,6 +154,7 @@ class TestDebugSettings extends DebugSettings {
152154
useSseForDebugBackend: useSse ?? useSseForDebugBackend,
153155
useSseForInjectedClient: useSse ?? useSseForInjectedClient,
154156
spawnDds: spawnDds ?? this.spawnDds,
157+
ddsPort: ddsPort ?? this.ddsPort,
155158
enableDevToolsLaunch: enableDevToolsLaunch ?? this.enableDevToolsLaunch,
156159
launchDevToolsInNewWindow:
157160
launchDevToolsInNewWindow ?? this.launchDevToolsInNewWindow,

0 commit comments

Comments
 (0)