bind static method
Future<BrowserTerminalHostServer>
bind({
- InternetAddress? address,
- int port = 8080,
- String pagePath = '/',
- String webSocketPath = '/ws',
- String title = 'Artisanal Browser Host',
- String? pageHtml,
- 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;
}