start static method
Future<Dwds>
start({
- required AssetReader assetReader,
- required Stream<
BuildResult> buildResults, - required ConnectionProvider chromeConnection,
- required LoadStrategy loadStrategy,
- required bool enableDebugging,
- ExpressionCompiler? expressionCompiler,
- bool enableDebugExtension = false,
- String hostname = 'localhost',
- bool useSseForDebugProxy = true,
- bool useSseForDebugBackend = true,
- bool useSseForInjectedClient = true,
- UrlEncoder? urlEncoder,
- bool spawnDds = true,
- bool enableDevtoolsLaunch = true,
- DevtoolsLauncher? devtoolsLauncher,
- bool launchDevToolsInNewWindow = true,
- bool emitDebugEvents = true,
- bool isInternalBuild = false,
- Future<
bool> isFlutterApp()?,
Implementation
static Future<Dwds> start({
required AssetReader assetReader,
required Stream<BuildResult> buildResults,
required ConnectionProvider chromeConnection,
required LoadStrategy loadStrategy,
required bool enableDebugging,
// TODO(annagrin): make expressionCompiler argument required
// [issue 881](https://github.com/dart-lang/webdev/issues/881)
ExpressionCompiler? expressionCompiler,
bool enableDebugExtension = false,
String hostname = 'localhost',
bool useSseForDebugProxy = true,
bool useSseForDebugBackend = true,
bool useSseForInjectedClient = true,
UrlEncoder? urlEncoder,
bool spawnDds = true,
// TODO(elliette): DevTools is inconsistently capitalized throughout this
// file. Change all occurrences of devtools/Devtools to devTools/DevTools.
bool enableDevtoolsLaunch = true,
DevtoolsLauncher? devtoolsLauncher,
bool launchDevToolsInNewWindow = true,
bool emitDebugEvents = true,
bool isInternalBuild = false,
Future<bool> Function()? isFlutterApp,
}) async {
globalLoadStrategy = loadStrategy;
isFlutterApp ??= () => Future.value(true);
DevTools? devTools;
Future<String>? extensionUri;
ExtensionBackend? extensionBackend;
if (enableDebugExtension) {
final handler = useSseForDebugBackend
? SseSocketHandler(
SseHandler(
Uri.parse('/\$debug'),
// Proxy servers may actively kill long standing connections.
// Allow for clients to reconnect in a short window. Making the
// window too long may cause issues if the user closes a debug
// session and initiates a new one during the keepAlive window.
keepAlive: const Duration(seconds: 5),
),
)
: WebSocketSocketHandler();
extensionBackend = await ExtensionBackend.start(handler, hostname);
extensionUri = Future.value(
Uri(
scheme: useSseForDebugBackend ? 'http' : 'ws',
host: extensionBackend.hostname,
port: extensionBackend.port,
path: r'$debug',
).toString(),
);
if (urlEncoder != null) extensionUri = urlEncoder(await extensionUri);
}
final serveDevTools = devtoolsLauncher != null;
if (serveDevTools) {
devTools = await devtoolsLauncher(hostname);
final uri =
Uri(scheme: 'http', host: devTools.hostname, port: devTools.port);
_logger.info('Serving DevTools at $uri\n');
}
final injected = DwdsInjector(
loadStrategy,
useSseForInjectedClient: useSseForInjectedClient,
extensionUri: extensionUri,
enableDevtoolsLaunch: enableDevtoolsLaunch,
emitDebugEvents: emitDebugEvents,
isInternalBuild: isInternalBuild,
isFlutterApp: isFlutterApp,
);
final devHandler = DevHandler(
chromeConnection,
buildResults,
devTools,
assetReader,
hostname,
extensionBackend,
urlEncoder,
useSseForDebugProxy,
useSseForInjectedClient,
expressionCompiler,
injected,
spawnDds,
launchDevToolsInNewWindow,
);
return Dwds._(
injected.middleware,
devTools,
devHandler,
assetReader,
enableDebugging,
);
}