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 library is used.

import 'dart:async';
import 'dart:io';

import 'package:logging/logging.dart';

import 'package:livereload/livereload.dart';

Future<Null> main(List<String> args) async {
  logger.onRecord.listen(stdIOLogListener);

  final results = liveReloadArgParser.parse(args);
  if (results[CliOption.help] == true) {
    print(liveReloadHelpMessage);
    exit(0);
  }

  final buildRunner = new BuildRunnerServeProcess.fromParsed(results)..start();

  final webSocket =
      new LiveReloadWebSocketServer.fromParsed(results, buildRunner.onBuild)
        ..serve();

  final proxy =
      new LiveReloadProxyServer.fromParsed(results, buildRunner, webSocket)
        ..serve();

  ProcessSignal.SIGINT.watch().take(1).listen((_) {
    buildRunner.kill();
    proxy.forceClose();
    webSocket.forceClose();
  });
}

Classes

BuildRunnerServeProcess
An interface to interact with the build_runner serve process. [...]
CliOption
Options avaliable in the CLI.
LiveReloadProxyServer
A livereload proxy server. [...]
LiveReloadWebSocketServer
A WebSocket server which will send reloadSignal to all of the connected clients when onBuild emits. [...]
ProxyServer
A simple shelf server which will proxy requests to to. [...]
RecordPrefix
A set of prefixes for indicating the level of each log record. [...]
WebSocketServer
A simple WebSocket server. [...]

Constants

disconnectSignal → const String
A message sent from the browser signaling disconnection.
'LelouchViBritannia'
reloadSignal → const String
A message sent through the WebSocket signaling the browser to reload. [...]
'AmakiSally'

Properties

liveReloadArgParser → dynamic
The default parser which is used to parse raw arguments given by users. [...]
final
liveReloadHelpMessage → dynamic
final
logger → dynamic
A global logger for the livereload package. [...]
final

Functions

injectJavaScript(String script) → Middleware
Creates a Middleware that injects a script into every html response. [...]
reloadOn(Uri webSocketUri, String message) → String
Generates a JavaScript which will reload the browser on receiving a message from webSocketUri.
rewriteTo(String absolutePath, bool shouldBeRewritten(Request request, Response response)) → Middleware
Creates a Middleware that will replace the path of requestedUri with absolutePath if the request shouldBeRewritten. [...]
stdIOLogListener(LogRecord rec) → void
A listener that output log records to stdout and stderr. [...]