2018-04-03 12:49:14 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-01-30 16:24:17 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2018-04-06 13:21:45 +00:00
|
|
|
from tfw.networking.event_handlers import ServerUplinkConnector
|
2018-01-29 15:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MessageSender:
|
2018-04-18 17:44:26 +00:00
|
|
|
"""
|
|
|
|
Provides a mechanism to send messages to our frontend messaging component which
|
|
|
|
displays messages with the key "message".
|
|
|
|
"""
|
2018-02-21 14:28:16 +00:00
|
|
|
def __init__(self, custom_key: str = None):
|
2018-01-29 15:48:32 +00:00
|
|
|
self.server_connector = ServerUplinkConnector()
|
2018-02-21 14:28:16 +00:00
|
|
|
self.key = custom_key or 'message'
|
2018-01-29 15:48:32 +00:00
|
|
|
|
2018-01-30 16:24:17 +00:00
|
|
|
def send(self, originator, message):
|
2018-04-18 17:44:26 +00:00
|
|
|
"""
|
|
|
|
Sends a message to the key specified in __init__.
|
|
|
|
:param originator: name of sender to be displayed on the frontend
|
|
|
|
:param message: message to send
|
|
|
|
"""
|
2018-02-02 15:49:15 +00:00
|
|
|
data = {
|
2018-01-30 16:24:17 +00:00
|
|
|
'originator': originator,
|
|
|
|
'timestamp': datetime.now().isoformat(),
|
|
|
|
'message': message
|
|
|
|
}
|
2018-04-12 13:11:52 +00:00
|
|
|
self.server_connector.send({'key': self.key,
|
|
|
|
'data': data})
|