From a4a306374d4e904217cb0196bad96ddf38c6b064 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 1 Jul 2019 16:49:39 +0200 Subject: [PATCH] add some map basics --- htdocs/map.html | 12 ++++++++++++ htdocs/map.js | 30 ++++++++++++++++++++++++++++++ owrx/controllers.py | 4 ++++ owrx/http.py | 5 +++-- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 htdocs/map.html create mode 100644 htdocs/map.js diff --git a/htdocs/map.html b/htdocs/map.html new file mode 100644 index 0000000..272207d --- /dev/null +++ b/htdocs/map.html @@ -0,0 +1,12 @@ + + + + OpenWebRX | Open Source SDR Web App for Everyone! + + + + + + + + diff --git a/htdocs/map.js b/htdocs/map.js new file mode 100644 index 0000000..c47935a --- /dev/null +++ b/htdocs/map.js @@ -0,0 +1,30 @@ +(function(){ + var protocol = 'ws'; + if (window.location.toString().startsWith('https://')) { + protocol = 'wss'; + } + + var ws_url = protocol + "://" + (window.location.origin.split("://")[1]) + "/ws/"; + if (!("WebSocket" in window)) return; + + var ws = new WebSocket(ws_url); + ws.onopen = function(){ + console.info("onopen"); + ws.send("SERVER DE CLIENT client=map.js type=map"); + }; + ws.onmessage = function(){ + console.info("onmessage"); + }; + ws.onclose = function(){ + console.info("onclose"); + }; + + window.onbeforeunload = function() { //http://stackoverflow.com/questions/4812686/closing-websocket-correctly-html5-javascript + ws.onclose = function () {}; + ws.close(); + }; + ws.onerror = function(){ + console.info("onerror"); + }; + +})(); \ No newline at end of file diff --git a/owrx/controllers.py b/owrx/controllers.py index 75c2758..883a403 100644 --- a/owrx/controllers.py +++ b/owrx/controllers.py @@ -79,6 +79,10 @@ class IndexController(AssetsController): def handle_request(self): self.serve_file("index.html", content_type = "text/html") +class MapController(AssetsController): + def handle_request(self): + self.serve_file("map.html", content_type = "text/html") + class WebSocketController(Controller): def handle_request(self): conn = WebSocketConnection(self.handler, WebSocketMessageHandler()) diff --git a/owrx/http.py b/owrx/http.py index ca7d357..b449fab 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -1,4 +1,4 @@ -from owrx.controllers import StatusController, IndexController, AssetsController, WebSocketController +from owrx.controllers import StatusController, IndexController, AssetsController, WebSocketController, MapController from http.server import BaseHTTPRequestHandler import re @@ -20,7 +20,8 @@ class Router(object): {"route": "/ws/", "controller": WebSocketController}, {"regex": "(/favicon.ico)", "controller": AssetsController}, # backwards compatibility for the sdr.hu portal - {"regex": "/(gfx/openwebrx-avatar.png)", "controller": AssetsController} + {"regex": "/(gfx/openwebrx-avatar.png)", "controller": AssetsController}, + {"route": "/map", "controller": MapController} ] def find_controller(self, path): for m in Router.mappings: