mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-08 20:07:16 +00:00
22 lines
771 B
Python
22 lines
771 B
Python
from tfw.networking import Scope
|
|
from tfw.components import FrontendMessageStorage
|
|
|
|
from .event_handler import EventHandler
|
|
|
|
|
|
class FrontendEventHandler(EventHandler):
|
|
def __init__(self):
|
|
frontend_keys = ('message', 'queueMessages', 'dashboard', 'console')
|
|
self._frontend_message_storage = FrontendMessageStorage(frontend_keys)
|
|
super().__init__((*frontend_keys, 'recover'), 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)
|