2019-06-28 13:11:02 +00:00
|
|
|
from tfw.networking import Scope
|
2019-07-05 13:25:59 +00:00
|
|
|
from tfw.components import FrontendMessageStorage
|
2019-05-26 16:26:33 +00:00
|
|
|
|
2019-06-28 13:11:02 +00:00
|
|
|
from .event_handler import EventHandler
|
2019-06-27 12:36:18 +00:00
|
|
|
|
2019-05-26 16:26:33 +00:00
|
|
|
|
2019-06-28 13:11:02 +00:00
|
|
|
class FrontendEventHandler(EventHandler):
|
2019-05-26 16:26:33 +00:00
|
|
|
def __init__(self):
|
|
|
|
frontend_keys = ('message', 'queueMessages', 'dashboard', 'console')
|
|
|
|
self._frontend_message_storage = FrontendMessageStorage(frontend_keys)
|
2019-06-28 13:11:02 +00:00
|
|
|
super().__init__((*frontend_keys, 'recover'), scope=Scope.WEBSOCKET)
|
2019-05-26 16:26:33 +00:00
|
|
|
|
|
|
|
def handle_event(self, message):
|
|
|
|
self._frontend_message_storage.save_message(message)
|
|
|
|
if message['key'] == 'recover':
|
|
|
|
self.recover_frontend()
|
2019-06-28 14:50:36 +00:00
|
|
|
self.send_message(message)
|
2019-05-26 16:26:33 +00:00
|
|
|
|
|
|
|
def recover_frontend(self):
|
|
|
|
for message in self._frontend_message_storage.messages:
|
|
|
|
self.send_message(message)
|