Skip to content

Commit

Permalink
Exposed shared property of HttpServer bind method to support more use…
Browse files Browse the repository at this point in the history
…-cases.
  • Loading branch information
pichillilorenzo committed Oct 24, 2022
1 parent a90c5a8 commit 33e42bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.7.1

- Exposed "shared" property of HttpServer bind method to support more use-cases. (thanks to [LugonjaAleksandar](https://github.com/LugonjaAleksandar))

## 5.7.0

- Added `PlatformViewsService.initExpensiveAndroidView` for Android
Expand Down
12 changes: 11 additions & 1 deletion lib/src/in_app_localhost_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class InAppLocalhostServer {
bool _started = false;
HttpServer? _server;
int _port = 8080;
bool _shared = false;
String _directoryIndex = 'index.html';
String _documentRoot = './';

Expand All @@ -20,15 +21,24 @@ class InAppLocalhostServer {
///- [directoryIndex] represents the index file to use. The default value is `index.html`.
///
///- [documentRoot] represents the document root path to serve. The default value is `./`.
///
///- The optional argument [shared] specifies whether additional `HttpServer`
/// objects can bind to the same combination of `address`, `port` and `v6Only`.
/// If `shared` is `true` and more `HttpServer`s from this isolate or other
/// isolates are bound to the port, then the incoming connections will be
/// distributed among all the bound `HttpServer`s. Connections can be
/// distributed over multiple isolates this way.
InAppLocalhostServer({
int port = 8080,
String directoryIndex = 'index.html',
String documentRoot = './',
bool shared = false,
}) {
this._port = port;
this._directoryIndex = directoryIndex;
this._documentRoot =
(documentRoot.endsWith('/')) ? documentRoot : '$documentRoot/';
this._shared = shared;
}

///Starts the server on `http://localhost:[port]/`.
Expand All @@ -52,7 +62,7 @@ class InAppLocalhostServer {
var completer = Completer();

runZonedGuarded(() {
HttpServer.bind('127.0.0.1', _port).then((server) {
HttpServer.bind('127.0.0.1', _port, shared: _shared).then((server) {
print('Server running on http://localhost:' + _port.toString());

this._server = server;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_inappwebview
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
version: 5.7.0
version: 5.7.1
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
Expand Down

0 comments on commit 33e42bb

Please sign in to comment.