WebHost: make a fresh Room reload page once if port is not assigned yet

This commit is contained in:
Fabian Dill 2022-08-12 04:55:40 +02:00 committed by Fabian Dill
parent 2e428f906c
commit 9bd035a19d
2 changed files with 7 additions and 3 deletions

View File

@ -124,7 +124,7 @@ def display_log(room: UUID):
@app.route('/room/<suuid:room>', methods=['GET', 'POST']) @app.route('/room/<suuid:room>', methods=['GET', 'POST'])
def host_room(room: UUID): def host_room(room: UUID):
room = Room.get(id=room) room: Room = Room.get(id=room)
if room is None: if room is None:
return abort(404) return abort(404)
if request.method == "POST": if request.method == "POST":
@ -134,10 +134,13 @@ def host_room(room: UUID):
Command(room=room, commandtext=cmd) Command(room=room, commandtext=cmd)
commit() 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: 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') @app.route('/favicon.ico')

View File

@ -2,6 +2,7 @@
{% import "macros.html" as macros %} {% import "macros.html" as macros %}
{% block head %} {% block head %}
<title>Multiworld {{ room.id|suuid }}</title> <title>Multiworld {{ room.id|suuid }}</title>
{% if should_refresh %}<meta http-equiv="refresh" content="2">{% endif %}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/hostRoom.css") }}"/> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/hostRoom.css") }}"/>
{% endblock %} {% endblock %}