Reporting RX startup, client connections, and chat messages via MQTT.
This commit is contained in:
parent
2bdcdc034d
commit
3825d86732
|
|
@ -20,8 +20,10 @@ from owrx.reporting import ReportingEngine
|
|||
from owrx.version import openwebrx_version
|
||||
from owrx.audio.queue import DecoderQueue
|
||||
from owrx.admin import add_admin_parser, run_admin_action
|
||||
from owrx.reporting import ReportingEngine
|
||||
from owrx.markers import Markers
|
||||
from owrx.gps import GpsUpdater
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import signal
|
||||
import argparse
|
||||
|
|
@ -29,6 +31,7 @@ import socket
|
|||
import ssl
|
||||
import os.path
|
||||
|
||||
|
||||
class ThreadedHttpServer(ThreadingMixIn, HTTPServer):
|
||||
def __init__(self, web_port, RequestHandlerClass, use_ipv6, bind_address=None):
|
||||
if bind_address is None:
|
||||
|
|
@ -143,6 +146,14 @@ Support and info: https://groups.io/g/openwebrx
|
|||
# Instantiate and refresh marker database
|
||||
Markers.start()
|
||||
|
||||
# Report receiver started
|
||||
ReportingEngine.getSharedInstance().spot({
|
||||
"mode" : "RX",
|
||||
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||
"version" : openwebrx_version,
|
||||
"state" : "ReceiverStarted"
|
||||
})
|
||||
|
||||
try:
|
||||
# This is our HTTP server
|
||||
server = ThreadedHttpServer(coreConfig.get_web_port(), RequestHandler, coreConfig.get_web_ipv6(), coreConfig.get_web_bind_address())
|
||||
|
|
@ -170,7 +181,17 @@ Support and info: https://groups.io/g/openwebrx
|
|||
GpsUpdater.stop()
|
||||
Services.stop()
|
||||
SdrService.stopAllSources()
|
||||
ReportingEngine.stopAll()
|
||||
DecoderQueue.stopAll()
|
||||
|
||||
# Report receiver stopped
|
||||
ReportingEngine.getSharedInstance().spot({
|
||||
"mode" : "RX",
|
||||
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||
"version" : openwebrx_version,
|
||||
"state" : "ReceiverStopped"
|
||||
})
|
||||
|
||||
# Done with reporting now
|
||||
ReportingEngine.stopAll()
|
||||
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from owrx.config import Config
|
||||
from owrx.color import ColorCache
|
||||
from owrx.reporting import ReportingEngine
|
||||
from datetime import datetime, timedelta
|
||||
from ipaddress import ip_address
|
||||
import threading
|
||||
|
|
@ -53,11 +52,13 @@ class ClientRegistry(object):
|
|||
raise TooManyClientsException()
|
||||
self.clients.append(client)
|
||||
self.broadcast()
|
||||
self.reportClient(client, { "state":"CONNECTED" })
|
||||
|
||||
def clientCount(self):
|
||||
return len(self.clients)
|
||||
|
||||
def removeClient(self, client):
|
||||
self.reportClient(client, { "state":"DISCONNECTED" })
|
||||
try:
|
||||
if client in self.chat:
|
||||
del self.chat[client]
|
||||
|
|
@ -71,6 +72,26 @@ class ClientRegistry(object):
|
|||
logger.debug("closing one connection...")
|
||||
client.close()
|
||||
|
||||
# Report client events
|
||||
def reportClient(self, client, data):
|
||||
from owrx.reporting import ReportingEngine
|
||||
data.update({
|
||||
"mode" : "CLIENT",
|
||||
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||
"ip" : self.getIp(client.conn.handler),
|
||||
"banned" : self.isBanned(client.conn.handler)
|
||||
})
|
||||
ReportingEngine.getSharedInstance().spot(data)
|
||||
|
||||
# Report chat message from a client
|
||||
def reportChatMessage(self, client, text: str):
|
||||
name = self.chat[client]["name"] if client in self.chat else "???"
|
||||
self.reportClient(client, {
|
||||
"state" : "CHAT",
|
||||
"name" : name,
|
||||
"message" : text
|
||||
})
|
||||
|
||||
# Broadcast chat message to all connected clients.
|
||||
def broadcastChatMessage(self, client, text: str, name: str = None):
|
||||
# If chat disabled, ignore messages
|
||||
|
|
@ -105,18 +126,13 @@ class ClientRegistry(object):
|
|||
self.chat[client] = { "name": name, "color": color }
|
||||
self.chatCount = self.chatCount + 1
|
||||
|
||||
# Report message
|
||||
ReportingEngine.getSharedInstance().spot({
|
||||
"mode" : "CHAT",
|
||||
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||
"name" : name,
|
||||
"message" : text
|
||||
})
|
||||
|
||||
# Broadcast message to all clients
|
||||
for c in self.clients:
|
||||
c.write_chat_message(name, text, color)
|
||||
|
||||
# Report message
|
||||
self.reportChatMessage(client, text)
|
||||
|
||||
# Broadcast administrative message to all connected clients.
|
||||
def broadcastAdminMessage(self, text: str):
|
||||
for c in self.clients:
|
||||
|
|
|
|||
Loading…
Reference in New Issue