2019-07-24 13:17:16 +00:00
|
|
|
from tfw.internals.networking import Scope
|
2019-05-26 16:26:33 +00:00
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
from .message_storage import FrontendMessageStorage
|
2019-06-27 12:36:18 +00:00
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
|
2019-08-15 08:43:30 +00:00
|
|
|
class FrontendProxyHandler:
|
2019-08-28 12:56:31 +00:00
|
|
|
keys = ['console', 'dashboard', 'frontend', 'message', 'ide.read', 'deploy.finish']
|
2019-08-30 12:45:53 +00:00
|
|
|
type_id = 'ControlEventHandler'
|
2019-05-26 16:26:33 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2019-07-30 13:17:29 +00:00
|
|
|
self.connector = None
|
2019-08-08 13:05:37 +00:00
|
|
|
self._frontend_message_storage = FrontendMessageStorage()
|
2019-05-26 16:26:33 +00:00
|
|
|
|
2019-07-12 21:25:16 +00:00
|
|
|
def send_message(self, message):
|
2019-07-30 13:17:29 +00:00
|
|
|
self.connector.send_message(message, scope=Scope.WEBSOCKET)
|
2019-07-12 21:25:16 +00:00
|
|
|
|
|
|
|
def handle_event(self, message, _):
|
2019-05-26 16:26:33 +00:00
|
|
|
self._frontend_message_storage.save_message(message)
|
2019-08-15 13:36:57 +00:00
|
|
|
if message['key'] == 'frontend.ready':
|
2019-05-26 16:26:33 +00:00
|
|
|
self.recover_frontend()
|
2019-08-28 13:04:58 +00:00
|
|
|
return
|
2019-08-08 13:05:37 +00:00
|
|
|
if self._filter_message(message):
|
|
|
|
self.send_message(message)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _filter_message(message):
|
2019-08-28 12:56:31 +00:00
|
|
|
return not message['key'].startswith((
|
|
|
|
'ide',
|
|
|
|
'message.queue'
|
|
|
|
))
|
2019-05-26 16:26:33 +00:00
|
|
|
|
|
|
|
def recover_frontend(self):
|
|
|
|
for message in self._frontend_message_storage.messages:
|
|
|
|
self.send_message(message)
|