diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-07 11:51:40 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-07 11:51:40 +0100 |
| commit | 59f25f2e61a1a69b9cf6d4f3a5a90a9e62b430a8 (patch) | |
| tree | 5a67a4fd4823a7bf544922ea9c745351da0abe77 /desktop/modules/sonix | |
| parent | 4071b681a9b704c1970e4f2c65d7465012a18e62 (diff) | |
| download | quickshell-59f25f2e61a1a69b9cf6d4f3a5a90a9e62b430a8.tar.gz quickshell-59f25f2e61a1a69b9cf6d4f3a5a90a9e62b430a8.zip | |
sonix: relay the player's UDP beacon to stdout
Diffstat (limited to 'desktop/modules/sonix')
| -rwxr-xr-x | desktop/modules/sonix/sonix-beacon.py | 29 | ||||
| -rw-r--r-- | desktop/modules/sonix/test_sonix_beacon.py | 37 |
2 files changed, 66 insertions, 0 deletions
diff --git a/desktop/modules/sonix/sonix-beacon.py b/desktop/modules/sonix/sonix-beacon.py new file mode 100755 index 0000000..eb9bf42 --- /dev/null +++ b/desktop/modules/sonix/sonix-beacon.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +# Copyright (C) 2026 Danilo M. <danix@danix.xyz> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Relays the Sonix player's discovery beacon to stdout, one line per +# datagram: QML has no UDP socket. SonixLink broadcasts +# "SONIXLINK1 <ip> <port> <name>" to UDP 7801 every 2s; anything else on +# the port is dropped. The port is an argument only for the test. +import socket +import sys + +port = int(sys.argv[1]) if len(sys.argv) > 1 else 7801 +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +# Several listeners may share the port; each still gets the broadcast. +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +s.bind(("", port)) +while True: + data, _ = s.recvfrom(512) + line = data.decode("utf-8", "replace").strip() + if line.startswith("SONIXLINK1 "): + print(line, flush=True) diff --git a/desktop/modules/sonix/test_sonix_beacon.py b/desktop/modules/sonix/test_sonix_beacon.py new file mode 100644 index 0000000..ec93dfb --- /dev/null +++ b/desktop/modules/sonix/test_sonix_beacon.py @@ -0,0 +1,37 @@ +#!/usr/bin/python3 +# Copyright (C) 2026 Danilo M. <danix@danix.xyz> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Run: /usr/bin/python3 desktop/modules/sonix/test_sonix_beacon.py +# Starts the relay on a test port, sends a junk datagram and a beacon, and +# checks that only the beacon comes out. +import os +import select +import socket +import subprocess +import sys + +PORT = 47801 +here = os.path.dirname(os.path.abspath(__file__)) +relay = subprocess.Popen([sys.executable, "-u", os.path.join(here, "sonix-beacon.py"), str(PORT)], + stdout=subprocess.PIPE, text=True) +try: + out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + for _ in range(50): # until the relay is bound + out.sendto(b"not a beacon", ("127.0.0.1", PORT)) + out.sendto(b"SONIXLINK1 10.0.0.5 7800 HiBy R1", ("127.0.0.1", PORT)) + if select.select([relay.stdout], [], [], 0.1)[0]: + break + line = relay.stdout.readline().strip() + assert line == "SONIXLINK1 10.0.0.5 7800 HiBy R1", line +finally: + relay.kill() +print("ok") |
