From 9bd035a19d9667cebec3090a7c57dc58b5f9cacc Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 12 Aug 2022 04:55:40 +0200 Subject: [PATCH] WebHost: make a fresh Room reload page once if port is not assigned yet --- WebHostLib/misc.py | 9 ++++++--- WebHostLib/templates/hostRoom.html | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/WebHostLib/misc.py b/WebHostLib/misc.py index 44377cf4..03cd03b6 100644 --- a/WebHostLib/misc.py +++ b/WebHostLib/misc.py @@ -124,7 +124,7 @@ def display_log(room: UUID): @app.route('/room/', methods=['GET', 'POST']) def host_room(room: UUID): - room = Room.get(id=room) + room: Room = Room.get(id=room) if room is None: return abort(404) if request.method == "POST": @@ -134,10 +134,13 @@ def host_room(room: UUID): Command(room=room, commandtext=cmd) commit() + now = datetime.datetime.utcnow() + # indicate that the page should reload to get the assigned port + should_refresh = not room.last_port and now - room.creation_time < datetime.timedelta(seconds=3) with db_session: - room.last_activity = datetime.utcnow() # will trigger a spinup, if it's not already running + room.last_activity = now # will trigger a spinup, if it's not already running - return render_template("hostRoom.html", room=room) + return render_template("hostRoom.html", room=room, should_refresh=should_refresh) @app.route('/favicon.ico') diff --git a/WebHostLib/templates/hostRoom.html b/WebHostLib/templates/hostRoom.html index 15429e7f..8981de9b 100644 --- a/WebHostLib/templates/hostRoom.html +++ b/WebHostLib/templates/hostRoom.html @@ -2,6 +2,7 @@ {% import "macros.html" as macros %} {% block head %} Multiworld {{ room.id|suuid }} + {% if should_refresh %}{% endif %} {% endblock %}