bind static method

Future<BrowserTerminalHostServer> bind({
  1. InternetAddress? address,
  2. int port = 8080,
  3. String pagePath = '/',
  4. String webSocketPath = '/ws',
  5. String title = 'Artisanal Browser Host',
  6. String? pageHtml,
  7. required BrowserTerminalSessionHandler onSession,
})

Binds a browser host server.

Implementation

static Future<BrowserTerminalHostServer> bind({
  io.InternetAddress? address,
  int port = 8080,
  String pagePath = '/',
  String webSocketPath = '/ws',
  String title = 'Artisanal Browser Host',
  String? pageHtml,
  required BrowserTerminalSessionHandler onSession,
}) async {
  final normalizedPagePath = _normalizePath(pagePath, allowRoot: true);
  final normalizedWebSocketPath = _normalizePath(webSocketPath);
  final server = await io.HttpServer.bind(
    address ?? io.InternetAddress.loopbackIPv4,
    port,
  );
  final host = BrowserTerminalHostServer._(
    server: server,
    pagePath: normalizedPagePath,
    webSocketPath: normalizedWebSocketPath,
    pageHtml:
        pageHtml ??
        defaultPageHtml(title: title, webSocketPath: normalizedWebSocketPath),
    onSession: onSession,
  );
  host._subscription = server.listen((request) {
    unawaited(host._handleRequestSafely(request));
  }, cancelOnError: false);
  return host;
}