Skip to content

Commit 0697950

Browse files
committed
Fixing #253 . The problem seems to be caused by the page structure. The page header, containing the js code required for the websocket communication was created at first user connection. The subsequent connection were using an already created page with a wrong client ip/host. Now, the js code gets updated each connection/page-reload with the correct ip/host.
1 parent 5b97d51 commit 0697950

5 files changed

Lines changed: 26 additions & 15 deletions

File tree

editor/prototypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#main program code prototype
55
proto_code_program = """
6-
# -*- coding: utf8 -*-
6+
# -*- coding: utf-8 -*-
77
88
import remi.gui as gui
99
from remi.gui import *

examples/minefield_app.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
from remi import start, App
2121

2222

23-
class Cell(gui.Widget):
23+
class Cell(gui.TableItem):
2424
"""
2525
Represent a cell in the minefield map
2626
"""
2727

2828
def __init__(self, width, height, x, y, game):
29-
super(Cell, self).__init__()
29+
super(Cell, self).__init__('')
3030
self.set_size(width, height)
3131
self.x = x
3232
self.y = y
@@ -75,7 +75,7 @@ def set_icon(self):
7575
self.style['background-image'] = "url('/my_resources:mine.png')"
7676
else:
7777
if self.nearest_mine > 0:
78-
self.add_child('nearestbomb', "%s" % self.nearest_mine)
78+
self.set_text(str(self.nearest_mine))
7979
else:
8080
self.style['background-color'] = 'rgb(200,255,100)'
8181
return
@@ -167,7 +167,16 @@ def new_game(self, widget):
167167
self.mine_table = gui.Table(margin='0px auto')#900, 450
168168
self.mine_matrix = self.build_mine_matrix(8, 8, 5)
169169
self.mine_table.empty()
170-
self.mine_table.append_from_list(self.mine_matrix, False)
170+
171+
172+
for x in range(0, len(self.mine_matrix[0])):
173+
row = gui.TableRow()
174+
for y in range(0, len(self.mine_matrix)):
175+
row.append(self.mine_matrix[y][x])
176+
self.mine_matrix[y][x].onclick.connect(self.mine_matrix[y][x].check_mine)
177+
self.mine_table.append(row)
178+
179+
#self.mine_table.append_from_list(self.mine_matrix, False)
171180
self.main_container.append(self.mine_table, key="mine_table")
172181
self.check_if_win()
173182
self.set_root_widget(self.main_container)

examples/widgets_overview_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,4 @@ def on_close(self):
326326
# optional parameters
327327
# start(MyApp,address='127.0.0.1', port=8081, multiple_instance=False,enable_file_cache=True, update_interval=0.1, start_browser=True)
328328
import ssl
329-
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, multiple_instance=False)
329+
start(MyApp, debug=True, address='0.0.0.0', port=8081, start_browser=True, multiple_instance=False)

remi/gui.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,13 +966,17 @@ def repr(self, changed_widgets=None):
966966

967967

968968
class HEAD(Tag):
969-
def __init__(self, title, net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms, *args, **kwargs):
969+
def __init__(self, title, *args, **kwargs):
970970
super(HEAD, self).__init__(*args, _type='head', **kwargs)
971971
self.add_child('meta',
972972
"""<meta content='text/html;charset=utf-8' http-equiv='Content-Type'>
973973
<meta content='utf-8' http-equiv='encoding'>
974974
<meta name="viewport" content="width=device-width, initial-scale=1.0">""")
975975

976+
self._classes = []
977+
self.set_title(title)
978+
979+
def set_internal_js(self, net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms):
976980
self.add_child('internal_js',
977981
"""
978982
<script>
@@ -1223,8 +1227,6 @@ def __init__(self, title, net_interface_ip, pending_messages_queue_length, webso
12231227
</script>""" % {'host':net_interface_ip,
12241228
'max_pending_messages':pending_messages_queue_length,
12251229
'messaging_timeout':websocket_timeout_timer_ms})
1226-
self._classes = []
1227-
self.set_title(title)
12281230

12291231
def set_title(self, title):
12301232
self.add_child('title', "<title>%s</title>" % title)

remi/server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,11 @@ def _instance(self):
343343

344344
#if the client instance doesn't exist
345345
if not(self.session in clients):
346-
net_interface_ip = self.headers.get('Host', "%s:%s"%(self.connection.getsockname()[0],self.server.server_address[1]))
347-
348-
websocket_timeout_timer_ms = str(self.server.websocket_timeout_timer_ms)
349-
pending_messages_queue_length = str(self.server.pending_messages_queue_length)
350346
self.update_interval = self.server.update_interval
351347

352348
from remi import gui
353349

354-
head = gui.HEAD(self.server.title,
355-
net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms)
350+
head = gui.HEAD(self.server.title)
356351
# use the default css, but append a version based on its hash, to stop browser caching
357352
head.add_child('internal_css', "<link href='/res:style.css' rel='stylesheet' />\n")
358353

@@ -395,6 +390,11 @@ def _instance(self):
395390
self._need_update_flag = client._need_update_flag
396391
if hasattr(client, '_update_thread'):
397392
self._update_thread = client._update_thread
393+
394+
net_interface_ip = self.headers.get('Host', "%s:%s"%(self.connection.getsockname()[0],self.server.server_address[1]))
395+
websocket_timeout_timer_ms = str(self.server.websocket_timeout_timer_ms)
396+
pending_messages_queue_length = str(self.server.pending_messages_queue_length)
397+
self.page.children['head'].set_internal_js(net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms)
398398

399399
def main(self, *_):
400400
""" Subclasses of App class *must* declare a main function

0 commit comments

Comments
 (0)