mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-08 20:07:16 +00:00
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
import logging
|
|
|
|
from tornado.web import Application
|
|
|
|
from tfw.networking import EventHandlerConnector
|
|
from tfw.config import TFWENV
|
|
|
|
from .zmq_websocket_router import ZMQWebSocketRouter
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class TFWServer:
|
|
"""
|
|
This class handles the proxying of messages between the frontend and event handers.
|
|
It proxies messages from the "/ws" route to all event handlers subscribed to a ZMQ
|
|
SUB socket.
|
|
"""
|
|
def __init__(self):
|
|
self._event_handler_connector = EventHandlerConnector(
|
|
downlink_bind_addr=f'tcp://*:{TFWENV.PULL_PORT}',
|
|
uplink_bind_addr=f'tcp://*:{TFWENV.PUB_PORT}'
|
|
)
|
|
self.application = Application([(
|
|
r'/ws', ZMQWebSocketRouter, {
|
|
'event_handler_connector': self._event_handler_connector,
|
|
}
|
|
)])
|
|
|
|
def listen(self):
|
|
self.application.listen(TFWENV.WEB_PORT)
|