diff --git a/htdocs/lib/settings/ClientList.js b/htdocs/lib/settings/ClientList.js
index e1f091f1..ef875ece 100644
--- a/htdocs/lib/settings/ClientList.js
+++ b/htdocs/lib/settings/ClientList.js
@@ -23,4 +23,18 @@ $.fn.clientList = function() {
return false;
});
});
+
+ $('#broadcast-send').on('click', function(e) {
+ var text = $('#broadcast-text').val();
+ if (text.length > 0) {
+ $.ajax("/broadcast", {
+ data: JSON.stringify({ text: text }),
+ contentType: 'application/json',
+ method: 'POST'
+ }).done(function() {
+ $('#broadcast-text').val('');
+ });
+ }
+ return false;
+ });
}
diff --git a/htdocs/settings.html b/htdocs/settings.html
index 7effe03f..bdade22d 100644
--- a/htdocs/settings.html
+++ b/htdocs/settings.html
@@ -40,6 +40,11 @@ ${header}
Clients
+
+ Broadcast message to all users
+
+
+
${clients}
diff --git a/owrx/client.py b/owrx/client.py
index 84c5e8f0..1e0d93aa 100644
--- a/owrx/client.py
+++ b/owrx/client.py
@@ -103,6 +103,11 @@ class ClientRegistry(object):
for c in self.clients:
c.write_chat_message(name, text, color)
+ # Broadcast administrative message to all connected clients.
+ def broadcastAdminMessage(self, text: str):
+ for c in self.clients:
+ c.write_log_message(text)
+
# Get client IP address from the handler.
def getIp(self, handler):
ip = handler.client_address[0]
diff --git a/owrx/controllers/clients.py b/owrx/controllers/clients.py
index d1c8f0cc..fd930fe0 100644
--- a/owrx/controllers/clients.py
+++ b/owrx/controllers/clients.py
@@ -97,3 +97,15 @@ class ClientController(AuthorizationMixin, WebpageController):
except Exception as e:
logger.debug("unban(): " + str(e))
self.send_response("{}", content_type="application/json", code=400)
+
+ def broadcast(self):
+ try:
+ data = json.loads(self.get_body().decode("utf-8"))
+ text = data["text"].strip() if "text" in data else ""
+ if len(text) > 0:
+ logger.info("Broadcasting '{0}' to all clients".format(text))
+ ClientRegistry.getSharedInstance().broadcastAdminMessage(text)
+ self.send_response("{}", content_type="application/json", code=200)
+ except Exception as e:
+ logger.debug("broadcast(): " + str(e))
+ self.send_response("{}", content_type="application/json", code=400)
diff --git a/owrx/http.py b/owrx/http.py
index cc2eea94..9d1f9d35 100644
--- a/owrx/http.py
+++ b/owrx/http.py
@@ -163,6 +163,7 @@ class Router(object):
StaticRoute("/clients", ClientController),
StaticRoute("/ban", ClientController, method="POST", options={"action": "ban"}),
StaticRoute("/unban", ClientController, method="POST", options={"action": "unban"}),
+ StaticRoute("/broadcast", ClientController, method="POST", options={"action": "broadcast"}),
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),