livereload library

API for the livereload server, designed with the need of customization in mind.

In most case, this is not necessary. Please consider using the CLI instead.

I will use the implementation of the CLI as an example of how this API is used.

import 'dart:async';

import 'package:logging/logging.dart';

import 'package:livereload/livereload.dart';

Future<int> main(List<String> args) async {
 Logger.root.onRecord.listen(stdIOLogListener);

 final parser = defaultArgParser();
 final parsedArgs = new ParsedArgs.from(parser.parse(args));
 if (parsedArgs.help) {
   print(helpMessage(parser));
   return 0;
 }

 final succeededBuildNotifier = new StreamController<Null>(sync: true);
 final buildRunnerServed = new Completer<Null>();
 final exitCode = buildRunnerServe(parsedArgs.buildRunnerServeArgs,
     succeededBuildNotifier, buildRunnerServed);
 await buildRunnerServed.future;

 startLiveReloadProxyServer(parsedArgs.proxyUri, parsedArgs.directory,
     parsedArgs.buildRunnerUri, parsedArgs.webSocketUri, parsedArgs.spa);

 startLiveReloadWebSocketServer(
     parsedArgs.webSocketUri, succeededBuildNotifier.stream);

 return await exitCode;
}

Classes

CliOption
Options avaliable in the CLI.
ParsedArgs
An object which represents the parsed arguments of the defaultArgParser.

Constants

defaultDirectory → const String
'web'
defaultPorts → const dynamic
const <String, String> {CliOption.buildRunnerPort : '8080', CliOption.proxyPort : '8000', CliOption.webSocketPort : '4242'}
reloadSignal → const String
A message send through the WebSocket signaling the browser to reload. [...]
'AmakiSally'

Functions

buildRunnerServe(List<String> args, Sink<Null> buildSucceededSink, Completer<Null> served) → Future<int>
Runs pub run build_runner serve with args. [...]
defaultArgParser() → ArgParser
Returns the default parser which is used to parse raw arguments given by users. [...]
helpMessage(ArgParser parser) → String
Returns a usage information of the CLI wrapped around parser.usage.
injectJavaScript(String script) → Middleware
Creates a Middleware that injects a script into every html response. [...]
rewriteAs(String responseBody) → Middleware
Creates a Middleware that returns a html response with responseBody if the requestedUri doesn't have a MIME type. [...]
startLiveReloadProxyServer(Uri uri, String directory, Uri buildRunnerUri, Uri webSocketUri, bool spa, [ Pipeline pipeline = const Pipeline() ]) → void
Starts a proxy server at uri proxying requests to buildRunnerUri and injects a script listening for a reloadSignal. [...]
startLiveReloadWebSocketServer(Uri uri, Stream<Null> succeededBuild) → void
Starts a WebSocket server which will send a reloadSignal to all of its client when succeededBuild emits. [...]
startProxyServer(Uri uri, Uri buildRunnerUri, [ Pipeline pipeline = const Pipeline() ]) → Future<Null>
Starts a server at uri proxying requests to buildRunnerUri. [...]
startWebSocketServer(Uri uri) → Stream<WebSocketChannel>
Starts a WebSocket server at uri. [...]
stdIOLogListener(LogRecord rec) → void
A listener that output log records to stdout and stderr. [...]