From f283a1ad68eb9e2faa05f13abe6c449cf9da15f4 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 1 Jul 2019 11:47:07 +0200 Subject: [PATCH] prepare for different types of connections --- htdocs/openwebrx.js | 2 +- owrx/connection.py | 20 ++++++++++++++------ owrx/controllers.py | 1 - 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 27cc8fc..5297549 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1431,7 +1431,7 @@ function waterfall_dequeue() function on_ws_opened() { - ws.send("SERVER DE CLIENT openwebrx.js"); + ws.send("SERVER DE CLIENT client=openwebrx.js type=receiver"); divlog("WebSocket opened to "+ws_url); } diff --git a/owrx/connection.py b/owrx/connection.py index 67ee96b..a6d268a 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -1,12 +1,13 @@ from owrx.config import PropertyManager from owrx.source import DspManager, CpuUsageThread, SdrService, ClientRegistry from owrx.feature import FeatureDetector +from owrx.version import openwebrx_version import json import logging logger = logging.getLogger(__name__) -class OpenWebRxClient(object): +class OpenWebRxReceiverClient(object): config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level", "waterfall_auto_level_margin", "lfo_offset", "samp_rate", "fft_size", "fft_fps", "audio_compression", "fft_compression", "max_clients", "start_mod", @@ -53,10 +54,10 @@ class OpenWebRxClient(object): self.sdr = next # send initial config - configProps = self.sdr.getProps().collect(*OpenWebRxClient.config_keys).defaults(PropertyManager.getSharedInstance()) + configProps = self.sdr.getProps().collect(*OpenWebRxReceiverClient.config_keys).defaults(PropertyManager.getSharedInstance()) def sendConfig(key, value): - config = dict((key, configProps[key]) for key in OpenWebRxClient.config_keys) + config = dict((key, configProps[key]) for key in OpenWebRxReceiverClient.config_keys) # TODO mathematical properties? hmmmm config["start_offset_freq"] = configProps["start_freq"] - configProps["center_freq"] self.write_config(config) @@ -143,11 +144,18 @@ class WebSocketMessageHandler(object): def handleTextMessage(self, conn, message): if (message[:16] == "SERVER DE CLIENT"): - # maybe put some more info in there? nothing to store yet. - self.handshake = "completed" + meta = message[17:].split(" ") + self.handshake = {v[0]: "=".join(v[1:]) for v in map(lambda x: x.split("="), meta)} + + conn.send("CLIENT DE SERVER server=openwebrx version={version}".format(version = openwebrx_version)) logger.debug("client connection intitialized") - self.client = OpenWebRxClient(conn) + if "type" in self.handshake: + if self.handshake["type"] == "receiver": + self.client = OpenWebRxReceiverClient(conn) + # backwards compatibility + else: + self.client = OpenWebRxReceiverClient(conn) return diff --git a/owrx/controllers.py b/owrx/controllers.py index 774ba9b..75c2758 100644 --- a/owrx/controllers.py +++ b/owrx/controllers.py @@ -82,6 +82,5 @@ class IndexController(AssetsController): class WebSocketController(Controller): def handle_request(self): conn = WebSocketConnection(self.handler, WebSocketMessageHandler()) - conn.send("CLIENT DE SERVER openwebrx.py") # enter read loop conn.read_loop()