controlWebServer static method
Control the web server that the service protocol is accessed through.
enable
is used as a toggle to enable or disable the web server
servicing requests. If silenceOutput
is provided and is true,
the server will not output information to the console.
Implementation
static Future<ServiceProtocolInfo> controlWebServer(
{bool enable = false, bool? silenceOutput}) async {
// TODO: When NNBD is complete, delete the following line.
ArgumentError.checkNotNull(enable, 'enable');
// Port to receive response from service isolate.
final RawReceivePort receivePort =
new RawReceivePort(null, 'Service.controlWebServer');
final Completer<String?> completer = new Completer<String?>();
receivePort.handler = (String? uriString) => completer.complete(uriString);
// Request the information from the service isolate.
_webServerControl(receivePort.sendPort, enable, silenceOutput);
// Await the response from the service isolate.
String? uriString = await completer.future;
Uri? uri = uriString == null ? null : Uri.parse(uriString);
// Close the port.
receivePort.close();
return new ServiceProtocolInfo(uri);
}