-
Notifications
You must be signed in to change notification settings - Fork 2
/
TeleopService.py
101 lines (77 loc) · 3.32 KB
/
TeleopService.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Twisted
from twisted.internet import reactor, defer
from twisted.python import log
import opentera.messages.python as messages
import sys
import uuid
import json
from json.decoder import JSONDecodeError
import Globals
from flask_babel import gettext
# Configuration
from ConfigManager import ConfigManager
from opentera.redis.RedisClient import RedisClient
from opentera.redis.RedisVars import RedisVars
# Modules
from FlaskModule import FlaskModule
# Local
from opentera.services.BaseWebRTCService import BaseWebRTCService
from TeleopServiceWebRTCModule import TeleopServiceWebRTCModule
from opentera.forms.TeraForm import TeraForm, TeraFormSection, TeraFormItem
class TeleopService(BaseWebRTCService):
def __init__(self, config_man: ConfigManager, service_info: dict):
BaseWebRTCService.__init__(self, config_man, service_info)
# Create REST backend
self.flaskModule = FlaskModule(config_man)
# Create twisted service
self.flaskModuleService = self.flaskModule.create_service()
# Create WebRTCModule
self.webRTCModule = TeleopServiceWebRTCModule(config_man, self)
# Override from ServiceOpenTera
def get_session_type_config_form(self, id_session_type: int) -> dict:
# Sections
form = TeraForm("session_type_config")
section = TeraFormSection("general", gettext("General configuration"))
form.add_section(section)
# Items
section.add_item(TeraFormItem("session_recordable", gettext("Allow session recording"),
"boolean", False, item_default=False))
return form.to_dict()
def notify_service_messages(self, pattern, channel, message):
pass
def setup_rpc_interface(self):
super().setup_rpc_interface()
# TODO ADD more rpc interface here
if __name__ == '__main__':
# Very first thing, log to stdout
log.startLogging(sys.stdout)
print('Starting TeleopService')
config_man = ConfigManager()
config_man.load_config('config/TeleopService.json')
# Retrieve configuration from redis
redis_client = RedisClient(config_man.redis_config)
# Get service UUID
service_info = redis_client.redisGet(RedisVars.RedisVar_ServicePrefixKey +
config_man.service_config['name'])
if service_info is None:
sys.stderr.write('Error: Unable to get service info from OpenTera Server - is the server running and config '
'correctly set in this service?')
exit(1)
# Get service UUID
try:
service_info = json.loads(service_info)
if 'service_uuid' not in service_info:
sys.stderr.write('OpenTera Server didn\'t return a valid service UUID - aborting.')
exit(1)
except JSONDecodeError as e:
sys.stderr.write('Invalid JSON for service configuration', e)
exit(1)
print('**************** service_info : ', service_info)
# Update service_info in configuration
config_man.service_config['ServiceUUID'] = service_info['service_uuid']
config_man.service_config['port'] = service_info['service_port']
config_man.service_config['hostname'] = service_info['service_hostname']
# Create the service
Globals.service = TeleopService(config_man, service_info)
# Start App/ reactor events
reactor.run()