mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-12 19:37:16 +00:00
25 lines
832 B
Python
25 lines
832 B
Python
from tfw.networking import Scope
|
|
from tfw.components import FrontendMessageStorage
|
|
|
|
|
|
class FrontendEventHandler:
|
|
keys = ['message', 'queueMessages', 'dashboard', 'console']
|
|
|
|
def __init__(self):
|
|
self.server_connector = None
|
|
self.keys = [*type(self).keys, 'recover']
|
|
self._frontend_message_storage = FrontendMessageStorage(type(self).keys)
|
|
|
|
def send_message(self, message):
|
|
self.server_connector.send_message(message, scope=Scope.WEBSOCKET)
|
|
|
|
def handle_event(self, message, _):
|
|
self._frontend_message_storage.save_message(message)
|
|
if message['key'] == 'recover':
|
|
self.recover_frontend()
|
|
self.send_message(message)
|
|
|
|
def recover_frontend(self):
|
|
for message in self._frontend_message_storage.messages:
|
|
self.send_message(message)
|