Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions package/lib/src/flet_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FletServer {
final Store<AppState> _store;
late FletServerProtocol _clientProtocol;
String _address = "";
bool _connected = false;
String _pageName = "";
String _pageHash = "";
String _pageWidth = "";
Expand All @@ -52,22 +51,20 @@ class FletServer {
onDisconnect: _onDisconnect,
onMessage: _onMessage);
await _clientProtocol.connect();
_connected = true;
registerWebClientInternal();
} catch (e) {
debugPrint("Error connecting to Flet server: $e");
_onDisconnect();
}
}

_onDisconnect() {
if (_connected) {
_store.dispatch(PageReconnectingAction());
debugPrint("Reconnect in ${_store.state.reconnectingTimeout} seconds");
Future.delayed(Duration(seconds: _store.state.reconnectingTimeout))
.then((value) {
connect(address: _address);
registerWebClientInternal();
});
}
_store.dispatch(PageReconnectingAction());
debugPrint("Reconnect in ${_store.state.reconnectingTimeout} seconds");
Future.delayed(Duration(seconds: _store.state.reconnectingTimeout))
.then((value) async {
await connect(address: _address);
});
}

registerWebClient({
Expand All @@ -83,7 +80,6 @@ class FletServer {
required String isWeb,
required String platform,
}) {
bool firstCall = _pageName == "";
_pageName = pageName;
_pageHash = pageRoute;
_pageWidth = pageWidth;
Expand All @@ -95,10 +91,6 @@ class FletServer {
_isPWA = isPWA;
_isWeb = isWeb;
_platform = platform;

if (firstCall) {
registerWebClientInternal();
}
}

registerWebClientInternal() {
Expand Down
1 change: 1 addition & 0 deletions package/lib/src/flet_server_protocol_tcp_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class FletTcpSocketServerProtocol implements FletServerProtocol {
onDone: () {
debugPrint('Server left.');
_socket?.destroy();
onDisconnect();
},
);
}
Expand Down
28 changes: 14 additions & 14 deletions package/lib/src/reducers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ AppState appReducer(AppState state, dynamic action) {
String pageName = getWebPageName(state.pageUri!);

getWindowMediaData().then((wmd) {
action.server.connect(address: state.pageUri!.toString()).then((s) {
action.server.registerWebClient(
pageName: pageName,
pageRoute: action.route,
pageWidth: state.size.width.toString(),
pageHeight: state.size.height.toString(),
windowWidth: wmd.width != null ? wmd.width.toString() : "",
windowHeight: wmd.height != null ? wmd.height.toString() : "",
windowTop: wmd.top != null ? wmd.top.toString() : "",
windowLeft: wmd.left != null ? wmd.left.toString() : "",
isPWA: isProgressiveWebApp().toString(),
isWeb: kIsWeb.toString(),
platform: defaultTargetPlatform.name.toLowerCase());
});
action.server.registerWebClient(
pageName: pageName,
pageRoute: action.route,
pageWidth: state.size.width.toString(),
pageHeight: state.size.height.toString(),
windowWidth: wmd.width != null ? wmd.width.toString() : "",
windowHeight: wmd.height != null ? wmd.height.toString() : "",
windowTop: wmd.top != null ? wmd.top.toString() : "",
windowLeft: wmd.left != null ? wmd.left.toString() : "",
isPWA: isProgressiveWebApp().toString(),
isWeb: kIsWeb.toString(),
platform: defaultTargetPlatform.name.toLowerCase());

action.server.connect(address: state.pageUri!.toString());
});
} else {
// existing route change
Expand Down
15 changes: 10 additions & 5 deletions sdk/python/packages/flet/src/flet/flet.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ def __connect_internal_sync(
web_renderer=None,
route_url_strategy=None,
):

env_port = os.getenv("FLET_SERVER_PORT")
if env_port is not None and env_port:
port = int(env_port)

is_desktop = view == FLET_APP or view == FLET_APP_HIDDEN
if server is None and not is_desktop:
server = __start_flet_server(
Expand Down Expand Up @@ -332,6 +337,11 @@ async def __connect_internal_async(
web_renderer=None,
route_url_strategy=None,
):

env_port = os.getenv("FLET_SERVER_PORT")
if env_port is not None and env_port:
port = int(env_port)

is_desktop = view == FLET_APP or view == FLET_APP_HIDDEN
if server is None and not is_desktop:
server = __start_flet_server(
Expand Down Expand Up @@ -391,11 +401,6 @@ async def on_session_created(session_data):
def __start_flet_server(
host, port, assets_dir, upload_dir, web_renderer, route_url_strategy
):
# local mode
env_port = os.getenv("FLET_SERVER_PORT")
if env_port is not None and env_port:
port = env_port

server_ip = host if host not in [None, "", "*"] else "127.0.0.1"

if port == 0:
Expand Down