first work on the websocket connection

This commit is contained in:
Jakob Ketterl
2019-05-04 16:56:23 +02:00
parent bd8e665198
commit 89690d214d
7 changed files with 158 additions and 33 deletions

View File

@ -1,4 +1,6 @@
import mimetypes
from owrx.websocket import WebSocketConnection
from owrx.config import PropertyManager
class Controller(object):
def __init__(self, handler, matches):
@ -12,16 +14,6 @@ class Controller(object):
if (type(content) == str):
content = content.encode()
self.handler.wfile.write(content)
def serve_file(self, file):
try:
f = open('htdocs/' + file, 'rb')
data = f.read()
f.close()
(content_type, encoding) = mimetypes.MimeTypes().guess_type(file)
self.send_response(data, content_type = content_type)
except FileNotFoundError:
self.send_response("file not found", code = 404)
def render_template(self, template, **variables):
f = open('htdocs/' + template)
data = f.read()
@ -38,6 +30,33 @@ class IndexController(Controller):
self.render_template("index.wrx")
class AssetsController(Controller):
def serve_file(self, file):
try:
f = open('htdocs/' + file, 'rb')
data = f.read()
f.close()
(content_type, encoding) = mimetypes.MimeTypes().guess_type(file)
self.send_response(data, content_type = content_type)
except FileNotFoundError:
self.send_response("file not found", code = 404)
def handle_request(self):
filename = self.matches.group(1)
self.serve_file(filename)
self.serve_file(filename)
class WebSocketController(Controller):
def handle_request(self):
conn = WebSocketConnection(self.handler)
conn.send("CLIENT DE SERVER openwebrx.py")
config = {}
pm = PropertyManager.getSharedInstance()
for key in ["waterfall_colors", "waterfall_min_level", "waterfall_max_level", "waterfall_auto_level_margin",
"shown_center_freq", "samp_rate", "fft_size", "fft_fps", "audio_compression", "fft_compression",
"max_clients"]:
config[key] = pm.getProperty(key).getValue()
conn.send({"type":"config","value":config})