mirror of
https://github.com/markqvist/Sideband.git
synced 2025-04-19 15:15:57 -04:00
Compare commits
170 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9749147b34 | ||
![]() |
a97c6dc9bb | ||
![]() |
e8461b3f33 | ||
![]() |
6a56d02afb | ||
![]() |
1054ddf1c4 | ||
![]() |
a0a6b0fd55 | ||
![]() |
b2c3411c90 | ||
![]() |
f6d2325785 | ||
![]() |
e4bb1e17eb | ||
![]() |
41536eb25a | ||
![]() |
ff8b1d4c28 | ||
![]() |
45f5d3e9ad | ||
![]() |
fdb4003a17 | ||
![]() |
7b2745692d | ||
![]() |
1c855aa24b | ||
![]() |
999054ab34 | ||
![]() |
dd12a76bf9 | ||
![]() |
4d9bba3e4c | ||
![]() |
3d7e894a9d | ||
![]() |
86e68f0dba | ||
![]() |
5e749bc0c3 | ||
![]() |
a24f1f1073 | ||
![]() |
b1678a1532 | ||
![]() |
9e058cc12e | ||
![]() |
1c9342d772 | ||
![]() |
143f440df7 | ||
![]() |
a0a03c9eba | ||
![]() |
902e1c5451 | ||
![]() |
3faa7e2203 | ||
![]() |
fbd5896856 | ||
![]() |
88f427b97c | ||
![]() |
63030a6f48 | ||
![]() |
f006f0d71a | ||
![]() |
3d6d039a48 | ||
![]() |
4b5128f177 | ||
![]() |
3f9204e1e1 | ||
![]() |
9494ab8095 | ||
![]() |
03cc00483b | ||
![]() |
09db4a9328 | ||
![]() |
6b2cf01c69 | ||
![]() |
1bf11aca6f | ||
![]() |
587773ace4 | ||
![]() |
54000a72c7 | ||
![]() |
b4a063a4e7 | ||
![]() |
3b2e1adaf2 | ||
![]() |
2c25b75042 | ||
![]() |
fc5ffab9ce | ||
![]() |
5153a1178b | ||
![]() |
de125004e6 | ||
![]() |
e65b2306cc | ||
![]() |
329bf6f3e6 | ||
![]() |
e743493ffd | ||
![]() |
cbb388fb63 | ||
![]() |
c873b9fa33 | ||
![]() |
120d29db75 | ||
![]() |
0d548e4cbb | ||
![]() |
a812f0a589 | ||
![]() |
ebc4462a50 | ||
![]() |
b03d91d206 | ||
![]() |
cc87e8c109 | ||
![]() |
fc3e97b8fc | ||
![]() |
156c2d4bd2 | ||
![]() |
93aa17177b | ||
![]() |
d459780ed7 | ||
![]() |
c4cdd388b7 | ||
![]() |
4f201c5615 | ||
![]() |
23e0e2394e | ||
![]() |
17d4de36c4 | ||
![]() |
94809b0ec4 | ||
![]() |
cc722dec9f | ||
![]() |
be6a1de135 | ||
![]() |
9ef43ecef6 | ||
![]() |
8899d82031 | ||
![]() |
3441bd9dba | ||
![]() |
74ba296fa6 | ||
![]() |
9bb4f3cc8b | ||
![]() |
5def619930 | ||
![]() |
b3b5d607e0 | ||
![]() |
13071fd9d8 | ||
![]() |
0a28ec76f3 | ||
![]() |
033c3d6658 | ||
![]() |
84b214cb90 | ||
![]() |
a90a451865 | ||
![]() |
95fec8219b | ||
![]() |
1d438f925b | ||
![]() |
304469315d | ||
![]() |
d6f54a0df3 | ||
![]() |
ebaf66788b | ||
![]() |
56add0bc50 | ||
![]() |
dd1399d7ce | ||
![]() |
4d7cb57d38 | ||
![]() |
235bfa6459 | ||
![]() |
752c080d83 | ||
![]() |
3111f767f0 | ||
![]() |
4dfd423915 | ||
![]() |
60591d3f0d | ||
![]() |
b9e224579b | ||
![]() |
ad32349e2c | ||
![]() |
5b61885bea | ||
![]() |
e515889e21 | ||
![]() |
9f48fae6e8 | ||
![]() |
19e3364b7f | ||
![]() |
b80a42947b | ||
![]() |
0c062ee16b | ||
![]() |
f49019c93e | ||
![]() |
2ce03c1508 | ||
![]() |
ab5798d8de | ||
![]() |
c1f04e8e3e | ||
![]() |
9e6cdc859a | ||
![]() |
78f2b5de3b | ||
![]() |
e083fd2fb4 | ||
![]() |
426c9d9617 | ||
![]() |
bc8dcb82a3 | ||
![]() |
19cae41062 | ||
![]() |
15600d5172 | ||
![]() |
887c0a9a16 | ||
![]() |
a4e22c7868 | ||
![]() |
02aadc4442 | ||
![]() |
7d1de23ea9 | ||
![]() |
7759264b37 | ||
![]() |
cc1e42cc66 | ||
![]() |
443c8938be | ||
![]() |
c210754aa4 | ||
![]() |
b301dc569b | ||
![]() |
55baede2fc | ||
![]() |
79ad4bb353 | ||
![]() |
1989330d21 | ||
![]() |
79ba89373a | ||
![]() |
0573af2ba0 | ||
![]() |
fbb58eb7b9 | ||
![]() |
3b8700c197 | ||
![]() |
b2a5b8c193 | ||
![]() |
ad58ab335a | ||
![]() |
a2575559cb | ||
![]() |
d2efd8e91a | ||
![]() |
f71a3934d7 | ||
![]() |
2cc4182376 | ||
![]() |
401d152935 | ||
![]() |
afac322859 | ||
![]() |
9e992c83fd | ||
![]() |
922107df50 | ||
![]() |
83b8130311 | ||
![]() |
211a0ad16b | ||
![]() |
ba0c80dd80 | ||
![]() |
25e31d8d9d | ||
![]() |
dcfc76e459 | ||
![]() |
5d64fe1f8d | ||
![]() |
7f54cbfb17 | ||
![]() |
be8051240f | ||
![]() |
970ec7b3b3 | ||
![]() |
63a96dea37 | ||
![]() |
3979a806b0 | ||
![]() |
ee18dcab31 | ||
![]() |
2e5d557aa7 | ||
![]() |
364463c541 | ||
![]() |
32b6fd0a81 | ||
![]() |
10b073d1c2 | ||
![]() |
4004151f39 | ||
![]() |
7885f39708 | ||
![]() |
fe4c61880e | ||
![]() |
0cbd4c71ab | ||
![]() |
a9269f20d4 | ||
![]() |
bf8fbe5f86 | ||
![]() |
9f86c4130c | ||
![]() |
6fb9a94a43 | ||
![]() |
46450098b4 | ||
![]() |
c14699151d | ||
![]() |
293023be12 | ||
![]() |
91883a0510 | ||
![]() |
2221629315 |
10
.github/ISSUE_TEMPLATE/🐛-bug-report.md
vendored
10
.github/ISSUE_TEMPLATE/🐛-bug-report.md
vendored
@ -12,10 +12,14 @@ Before creating a bug report on this issue tracker, you **must** read the [Contr
|
||||
|
||||
- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**.
|
||||
- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**.
|
||||
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), delete this section from your bug report.
|
||||
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), **delete this section only** (*"Read the Contribution Guidelines"*) from your bug report, **and fill in all the other sections**.
|
||||
|
||||
**Describe the Bug**
|
||||
A clear and concise description of what the bug is.
|
||||
First of all: Is this really a bug? Is it reproducible?
|
||||
|
||||
If this is a request for help because something is not working as you expected, stop right here, and go to the [discussions](https://github.com/markqvist/Reticulum/discussions) instead, where you can post your questions and get help from other users.
|
||||
|
||||
If this really is a bug or issue with the software, remove this section of the template, and provide **a clear and concise description of what the bug is**.
|
||||
|
||||
**To Reproduce**
|
||||
Describe in detail how to reproduce the bug.
|
||||
@ -24,7 +28,7 @@ Describe in detail how to reproduce the bug.
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Logs & Screenshots**
|
||||
Please include any relevant log output. If applicable, also add screenshots to help explain your problem.
|
||||
Please include any relevant log output. If applicable, also add screenshots to help explain your problem. In most cases, without any relevant log output, we will not be able to determine the cause of the bug, or reproduce it.
|
||||
|
||||
**System Information**
|
||||
- OS and version
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ sbapp/bin
|
||||
sbapp/app_storage
|
||||
sbapp/RNS
|
||||
sbapp/LXMF
|
||||
sbapp/LXST
|
||||
sbapp/precompiled
|
||||
sbapp/*.DS_Store
|
||||
sbapp/*.pyc
|
||||
|
3
Makefile
3
Makefile
@ -31,6 +31,9 @@ preparewheel:
|
||||
build_wheel:
|
||||
python3 setup.py sdist bdist_wheel
|
||||
|
||||
build_win_exe:
|
||||
python -m PyInstaller sideband.spec --noconfirm
|
||||
|
||||
release: build_wheel apk fetchapk
|
||||
|
||||
upload:
|
||||
|
169
README.md
169
README.md
@ -1,7 +1,7 @@
|
||||
Sideband <img align="right" src="https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg"/>
|
||||
=========
|
||||
|
||||
Sideband is an extensible LXMF messaging client, situational awareness tracker and remote control and monitoring system for Android, Linux, macOS and Windows. It allows you to communicate with other people or LXMF-compatible systems over Reticulum networks using LoRa, Packet Radio, WiFi, I2P, Encrypted QR Paper Messages, or anything else Reticulum supports.
|
||||
Sideband is an extensible LXMF messaging and LXST telephony client, situational awareness tracker and remote control and monitoring system for Android, Linux, macOS and Windows. It allows you to communicate with other people or LXMF-compatible systems over Reticulum networks using LoRa, Packet Radio, WiFi, I2P, Encrypted QR Paper Messages, or anything else Reticulum supports.
|
||||
|
||||

|
||||
|
||||
@ -13,10 +13,11 @@ This also means that Sideband operates differently than what you might be used t
|
||||
|
||||
Sideband provides many useful and interesting functions, such as:
|
||||
|
||||
- **Secure** and **self-sovereign** messaging using the LXMF protocol over Reticulum.
|
||||
- **Secure** and **self-sovereign** messaging and voice calls using the LXMF and LXST protocols over Reticulum.
|
||||
- **Image** and **file transfers** over all supported mediums.
|
||||
- **Audio messages** that work even over **LoRa** and **radio links**, thanks to [Codec2](https://github.com/drowe67/codec2/) and [Opus](https://github.com/xiph/opus) encoding.
|
||||
- Secure and direct P2P **telemetry and location sharing**. No third parties or servers ever have your data.
|
||||
- The telemetry system is **completely extensible** via [simple plugins](#creating-plugins).
|
||||
- Situation display on both online and **locally stored offline maps**.
|
||||
- Geospatial awareness calculations.
|
||||
- Exchanging messages through **encrypted QR-codes on paper**, or through messages embedded directly in **lxm://** links.
|
||||
@ -39,7 +40,7 @@ Sideband can run on most computing devices, but installation methods vary by dev
|
||||
|
||||
## On Android
|
||||
|
||||
For your Android devices, you can install Sideband through F-Droid, by adding the [Between the Borders Repo](https://reticulum.betweentheborders.com/fdroid/repo/), or you can download an [APK on the latest release](https://github.com/markqvist/Sideband/releases/latest) page. Both sources are signed with the same release keys, and can be used interchangably.
|
||||
For your Android devices, you can download an [APK on the latest release page](https://github.com/markqvist/Sideband/releases/latest).
|
||||
|
||||
After the application is installed on your Android device, it is also possible to pull updates directly through the **Repository** section of the application.
|
||||
|
||||
@ -47,7 +48,8 @@ After the application is installed on your Android device, it is also possible t
|
||||
|
||||
On all Linux-based operating systems, Sideband is available as a `pipx`/`pip` package. This installation method **includes desktop integration**, so that Sideband will show up in your applications menu and launchers. Below are install steps for the most common recent Linux distros. For Debian 11, see the end of this section.
|
||||
|
||||
You will first need to install a few dependencies for audio messaging and Codec2 support to work:
|
||||
#### Basic Installation
|
||||
You will first need to install a few dependencies for voice calls, audio messaging and Codec2 support to work:
|
||||
|
||||
```bash
|
||||
# For Debian (12+), Ubuntu (22.04+) and derivatives
|
||||
@ -78,7 +80,10 @@ After installation, you can now run Sideband in a number of different ways:
|
||||
pipx ensurepath
|
||||
|
||||
# The first time you run Sideband, you will need to do it
|
||||
# from the terminal:
|
||||
# from the terminal, for the application launcher item to
|
||||
# show up. On some distros you may also need to log out
|
||||
# and back in again, or simply reboot the machine for the
|
||||
# application entry to show up in your menu.
|
||||
sideband
|
||||
|
||||
# At the first launch, it will add an application icon
|
||||
@ -95,6 +100,9 @@ sideband --daemon
|
||||
sideband -v
|
||||
```
|
||||
|
||||
If you do not already have Reticulum connectivity set up on your computer or local network, you will probably want to edit the Reticulum configuration file at `~/.reticulum/config` and [add any interfaces](https://reticulum.network/manual/interfaces.html) you need for connectivity.
|
||||
|
||||
#### Advanced Installation
|
||||
You can also install Sideband in various alternative ways:
|
||||
|
||||
```bash
|
||||
@ -109,8 +117,9 @@ pip install sbapp --break-system-packages
|
||||
# any of the normal UI dependencies:
|
||||
pip install sbapp --no-dependencies
|
||||
|
||||
# In the above case, you will still need to
|
||||
# manually install the RNS and LXMF dependencies:
|
||||
# In the case of using --no-dependencies, you
|
||||
# will still need to manually install the RNS
|
||||
# and LXMF dependencies:
|
||||
pip install rns lxmf
|
||||
|
||||
# Install Sideband on Debian 11 and derivatives:
|
||||
@ -128,17 +137,17 @@ You can install Sideband on all Raspberry Pi models that support 64-bit operatin
|
||||
|
||||
Aditionally, the `pycodec2` package needs to be installed manually. I have provided a pre-built version, that you can download and install with a single command, or if you don't want to trust my pre-built version, you can [build and install it from source yourself](https://github.com/gregorias/pycodec2/blob/main/DEV.md).
|
||||
|
||||
The install instructions below assume that you are installing Sideband on 64-bit Raspberry Pi OS (based on Debian Bookworm). If you're running something else on your Pi, you might need to modify some commands slightly. To install Sideband on Raspberry Pi, follow these steps:
|
||||
The install instructions below assume that you are installing Sideband on 64-bit Raspberry Pi OS (based on Debian Bookworm or later). If you're running something else on your Pi, you might need to modify some commands slightly. To install Sideband on Raspberry Pi with full support for voice calls, audio messages and Codec2, follow these steps:
|
||||
|
||||
```bash
|
||||
# First of all, install the required dependencies:
|
||||
sudo apt install python3-pip python3-pyaudio python3-dev python3-cryptography build-essential libopusfile0 libsdl2-dev libavcodec-dev libavdevice-dev libavfilter-dev portaudio19-dev codec2 libcodec2-1.0 xclip xsel
|
||||
|
||||
# If you don't want to compile pycodec2 yourself,
|
||||
# download the pre-compiled package provided here
|
||||
# download the pre-compiled package provided here:
|
||||
wget https://raw.githubusercontent.com/markqvist/Sideband/main/docs/utilities/pycodec2-3.0.1-cp311-cp311-linux_aarch64.whl
|
||||
|
||||
# Install it:
|
||||
# And install it:
|
||||
pip install ./pycodec2-3.0.1-cp311-cp311-linux_aarch64.whl --break-system-packages
|
||||
|
||||
# You can now install Sideband
|
||||
@ -152,46 +161,106 @@ sudo reboot
|
||||
sideband
|
||||
```
|
||||
|
||||
If you do not already have Reticulum connectivity set up on your computer or local network, you will probably want to edit the Reticulum configuration file at `~/.reticulum/config` and [add any interfaces](https://reticulum.network/manual/interfaces.html) you need for connectivity.
|
||||
|
||||
## On macOS
|
||||
|
||||
On macOS, you can install Sideband with `pip3` or `pipx`. Due to the many different potential Python versions and install paths across macOS versions, the easiest install method is to use `pipx`.
|
||||
To install Sideband on macOS, you have two options available:
|
||||
|
||||
If you don't already have the `pipx` package manager installed, it can be installed via [Homebrew](https://brew.sh/) with `brew install pipx`.
|
||||
1. An easy to install pre-built disk image package
|
||||
2. A source package install for more advanced setups
|
||||
|
||||
#### Prebuilt Executable
|
||||
|
||||
You can download a disk image with Sideband for macOS (ARM and Intel) from the [latest release page](https://github.com/markqvist/Sideband/releases/latest). Simply mount the downloaded disk image, drag `Sideband` to your applications folder, and run it.
|
||||
|
||||
**Please note!** If you have application install restrictions enabled on your macOS install, or have restricted your system to only allow installation of application from the Apple App Store, you will need to create an exception for Sideband. The Sideband application will *never* be distributed with an Apple-controlled digital signature, as this will allow Apple to simply disable Sideband from running on your system if they decide to do so, or are forced to by authorities or other circumstances.
|
||||
|
||||
If you install Sideband from the DMG file, it is still recommended to install the `rns` package via the `pip` or `pipx` package manager, so you can use the RNS utility programs, like `rnstatus` to see interface and connectivity status from the terminal. If you already have Python and `pip` installed on your system, simply open a terminal window and use one of the following commands:
|
||||
|
||||
```bash
|
||||
# Install Sideband and dependencies on macOS using pipx:
|
||||
pipx install sbapp
|
||||
pipx ensurepath
|
||||
# Install Reticulum and utilities with pip:
|
||||
pip3 install rns
|
||||
|
||||
# Run it
|
||||
sideband
|
||||
# On some versions, you may need to use the
|
||||
# flag --break-system-packages to install:
|
||||
pip3 install rns --break-system-packages
|
||||
```
|
||||
|
||||
Or, if you prefer to use `pip` directly, follow the instructions below. In this case, if you have not already installed Python and `pip3` on your macOS system, [download and install](https://www.python.org/downloads/) the latest version first.
|
||||
If you do not have Python and `pip` available, [download and install it](https://www.python.org/downloads/) first.
|
||||
|
||||
If you do not already have Reticulum connectivity set up on your computer or local network, you will probably want to edit the Reticulum configuration file at `~/.reticulum/config` and [add any interfaces](https://reticulum.network/manual/interfaces.html) you need for connectivity.
|
||||
|
||||
#### Source Package Install
|
||||
|
||||
For more advanced setups, including the ability to run Sideband in headless daemon mode, enable debug logging output, configuration import and export and more, you may want to install it from the source package via `pip` instead.
|
||||
|
||||
**Please note!** The very latest Python release, Python 3.13 is currently **not** compatible with the Kivy framework, that Sideband uses to render its user interface. If your version of macOS uses Python 3.13 as its default Python installation, you will need to install an earlier version as well. Using [the latest release of Python 3.12](https://www.python.org/downloads/release/python-3127/) is recommended.
|
||||
|
||||
To install Sideband via `pip`, follow these instructions:
|
||||
|
||||
```bash
|
||||
# Install Sideband and dependencies on macOS using pip:
|
||||
pip3 install sbapp --user --break-system-packages
|
||||
pip3 install sbapp
|
||||
|
||||
# Run it:
|
||||
# Run Sideband from the terminal:
|
||||
#################################
|
||||
sideband
|
||||
# or
|
||||
python3 -m sbapp.main
|
||||
|
||||
# If you add your pip install location to
|
||||
# the PATH environment variable, you can
|
||||
# also run Sideband simply using:
|
||||
sideband
|
||||
# Enable debug logging:
|
||||
#################################
|
||||
sideband -v
|
||||
# or
|
||||
python3 -m sbapp.main -v
|
||||
|
||||
# Start Sideband in daemon mode:
|
||||
#################################
|
||||
sideband -d
|
||||
# or
|
||||
python3 -m sbapp.main -d
|
||||
|
||||
# If Python and pip was installed correctly,
|
||||
# you can simply use the "sideband" command
|
||||
# directly. Otherwise, you will manually
|
||||
# need to add the pip binaries directory to
|
||||
# your PATH environment variable, or start
|
||||
# Sideband via the "python3 -m sbapp.main"
|
||||
# syntax.
|
||||
|
||||
```
|
||||
|
||||
## On Windows
|
||||
|
||||
Even though there is currently not an automated installer, or packaged `.exe` file for Sideband on Windows, you can still install it through `pip`. If you don't already have Python installed, [download and install](https://www.python.org/downloads/) the latest version of Python.
|
||||
To install Sideband on Windows, you have two options available:
|
||||
|
||||
Please note that audio messaging functionality isn't supported on Windows yet. Please support the development if you'd like to see this feature added faster.
|
||||
1. An easy to install pre-built executable package
|
||||
2. A source package install for more advanced setups
|
||||
|
||||
**Important!** When asked by the installer, make sure to add the Python program to your PATH environment variables. If you don't do this, you will not be able to use the `pip` installer, or run the `sideband` command.
|
||||
#### Prebuilt Executable
|
||||
|
||||
When Python has been installed, you can open a command prompt and install sideband via `pip`:
|
||||
Simply download the packaged Windows ZIP file from the [latest release page](https://github.com/markqvist/Sideband/releases/latest), unzip the file, and run `Sideband.exe` from the unzipped directory. You can create desktop or start menu shortcuts from this executable if needed.
|
||||
|
||||
When running Sideband for the first time, a default Reticulum configuration file will be created, if you don't already have one. If you don't have any existing Reticulum connectivity available locally, you may want to edit the file, located at `C:\Users\USERNAME\.reticulum\config` and manually add an interface that provides connectivity to a wider network. If you just want to connect over the Internet, you can add one of the public hubs on the [Reticulum Testnet](https://reticulum.network/connect.html).
|
||||
|
||||
#### Installing Reticulum Utilities
|
||||
|
||||
Though the ZIP file contains everything necessary to run Sideband, it is also recommended to install the Reticulum command line utilities separately, so that you can use commands like `rnstatus` and `rnsd` from the command line. This will make it easier to manage Reticulum connectivity on your system. If you do not already have Python installed on your system, [download and install it](https://www.python.org/downloads/) first.
|
||||
|
||||
**Important!** When asked by the installer, make sure to add the Python program to your `PATH` environment variables. If you don't do this, you will not be able to use the `pip` installer, or run any of the installed commands. When Python has been installed, you can open a command prompt and install the Reticulum package via `pip`:
|
||||
|
||||
```bash
|
||||
pip install rns
|
||||
```
|
||||
|
||||
#### Source Package Install
|
||||
|
||||
For more advanced setups, including the ability to run Sideband in headless daemon mode, enable debug logging output, configuration import and export and more, you may want to install it from the source package via `pip` instead.
|
||||
|
||||
In this case, you will need to [download and install the latest supported version of Python](https://www.python.org/downloads/release/python-3127/) (currently Python 3.12.7), since very latest Python release, Python 3.13 is currently **not** compatible with the Kivy framework, that Sideband uses to render its user interface. The binary package already includes a compatible Python version, so if you are running Sideband from that, there is no need to install a specific version of Python.
|
||||
|
||||
When Python has been installed, you can open a command prompt and install Sideband via `pip`:
|
||||
|
||||
```bash
|
||||
pip install sbapp
|
||||
@ -199,7 +268,29 @@ pip install sbapp
|
||||
|
||||
The Sideband application can now be launched by running the command `sideband` in the command prompt. If needed, you can create a shortcut for Sideband on your desktop or in the start menu.
|
||||
|
||||
When running Sideband for the first time, a default Reticulum configuration file will be created, if you don't already have one. If you don't have any existing Reticulum connectivity available locally, you may want to edit the file, located at `C:\Users\USERNAME\.reticulum\config` and manually add an interface that provides connectivity to a wider network. If you just want to connect over the Internet, you can add one of the public hubs on the [Reticulum Testnet](https://reticulum.network/connect.html).
|
||||
Since this installation method automatically installs the `rns` and `lxmf` packages as well, you will also have access to using all the included RNS and LXMF utilities like `rnstatus`, `rnsd` and `lxmd` on your system.
|
||||
|
||||
# Creating Plugins
|
||||
|
||||
Sideband features a flexible and extensible plugin system, that allows you to hook all kinds of control, status reporting, command execution and telemetry collection into the LXMF messaging system. Plugins can be created as either *Telemetry*, *Command* or *Service* plugins, for different use-cases.
|
||||
|
||||
To create plugins for Sideband, you can find a variety of [code examples](https://github.com/markqvist/Sideband/tree/main/docs/example_plugins) in this repository, that you can use as a basis for writing your own plugins. The example plugins include:
|
||||
|
||||
- [Custom telemetry](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/telemetry.py)
|
||||
- [Getting BME280 temperature, humidity and pressure](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/bme280_telemetry.py)
|
||||
- [Basic commands](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/basic.py)
|
||||
- [Location telemetry from GPSd on Linux](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/gpsd_location.py)
|
||||
- [Location telemetry from Windows Location Provider](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/windows_location.py)
|
||||
- [Getting statistics from your LXMF propagation node](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/lxmd_telemetry.py)
|
||||
- [Viewing cameras and streams](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/view.py)
|
||||
- [Fetching an XKCD comic](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/comic.py)
|
||||
- [Creating a service plugin](https://github.com/markqvist/Sideband/blob/main/docs/example_plugins/service.py)
|
||||
|
||||
For creating telemetry plugins, Sideband includes 20+ built-in sensor types to chose from, for representing all kinds telemetry data. If none of those fit your needs, there is a `Custom` sensor type, that can include any kind of data.
|
||||
|
||||
Command plugins allow you to define any kind of action or command to be run when receiving command messages from other LXMF clients. In the example directory, you will find various command plugin templates, for example for viewing security cameras or webcams through Sideband.
|
||||
|
||||
Service plugins allow you to integrate any kind of service, bridge or other system into Sideband, and have that react to events or state changes in Sideband itself.
|
||||
|
||||
# Paper Messaging Example
|
||||
|
||||
@ -236,26 +327,6 @@ You can help support the continued development of open, free and private communi
|
||||
|
||||
<br/>
|
||||
|
||||
# Development Roadmap
|
||||
|
||||
- <s>Secure and private location and telemetry sharing</s>
|
||||
- <s>Including images in messages</s>
|
||||
- <s>Sending file attachments</s>
|
||||
- <s>Offline and online maps</s>
|
||||
- <s>Paper messages</s>
|
||||
- <s>Using Sideband as a Reticulum Transport Instance</s>
|
||||
- <s>Encryption keys export and import</s>
|
||||
- <s>Plugin support for commands, services and telemetry</s>
|
||||
- <s>Adding Linux .desktop file integration</s>
|
||||
- <s>Sending voice messages (using Codec2 and Opus)</s>
|
||||
- Implementing the Local Broadcasts feature
|
||||
- LXMF sneakernet functionality
|
||||
- Network visualisation and test tools
|
||||
- A debug log viewer
|
||||
- Better message sorting mechanism
|
||||
- Fix I2P status not being displayed correctly when the I2P router disappears unexpectedly
|
||||
- Adding a Nomad Net page browser
|
||||
|
||||
# License
|
||||
Unless otherwise noted, this work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].
|
||||
|
||||
|
67
docs/example_plugins/bme280_telemetry.py
Normal file
67
docs/example_plugins/bme280_telemetry.py
Normal file
@ -0,0 +1,67 @@
|
||||
# This plugin provides temperature, humidity
|
||||
# and pressure data via a BME280 sensor
|
||||
# connected over I2C. The plugin requires
|
||||
# the "smbus2" and "RPi.bme280" modules to
|
||||
# be available on your system. These can be
|
||||
# installed with:
|
||||
#
|
||||
# pip install smbus2 RPi.bme280
|
||||
|
||||
import os
|
||||
import RNS
|
||||
from importlib.util import find_spec
|
||||
|
||||
class BME280Plugin(SidebandTelemetryPlugin):
|
||||
plugin_name = "telemetry_bme280"
|
||||
|
||||
I2C_ADDRESS = 0x76
|
||||
I2C_BUS = 1
|
||||
|
||||
# If your BME280 has an offset from the true
|
||||
# temperature, you can compensate for this
|
||||
# by modifying this parameter.
|
||||
TEMPERATURE_CORRECTION = 0.0
|
||||
|
||||
def start(self):
|
||||
RNS.log("BME280 telemetry plugin starting...")
|
||||
|
||||
if find_spec("smbus2"): import smbus2
|
||||
else: raise OSError(f"No smbus2 module available, cannot start BME280 telemetry plugin")
|
||||
|
||||
if find_spec("bme280"): import bme280
|
||||
else: raise OSError(f"No bme280 module available, cannot start BME280 telemetry plugin")
|
||||
|
||||
self.sensor_connected = False
|
||||
|
||||
try:
|
||||
self.bme280 = bme280
|
||||
self.address = self.I2C_ADDRESS
|
||||
self.bus = smbus2.SMBus(self.I2C_BUS)
|
||||
self.calibration = self.bme280.load_calibration_params(self.bus, self.address)
|
||||
self.sensor_connected = True
|
||||
self.tc = self.TEMPERATURE_CORRECTION
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"Could not connect to I2C device while starting BME280 telemetry plugin", RNS.LOG_ERROR)
|
||||
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
|
||||
|
||||
super().start()
|
||||
|
||||
def stop(self):
|
||||
self.bus.close()
|
||||
super().stop()
|
||||
|
||||
def update_telemetry(self, telemeter):
|
||||
if telemeter != None:
|
||||
if self.sensor_connected:
|
||||
try:
|
||||
sample = self.bme280.sample(self.bus, self.address, self.calibration); ts = telemeter.sensors
|
||||
telemeter.synthesize("temperature"); ts["temperature"].data = {"c": round(sample.temperature+self.tc,1)}
|
||||
telemeter.synthesize("humidity"); ts["humidity"].data = {"percent_relative": round(sample.humidity,1)}
|
||||
telemeter.synthesize("pressure"); ts["pressure"].data = {"mbar": round(sample.pressure,1)}
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("An error occurred while updating BME280 sensor data", RNS.LOG_ERROR)
|
||||
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
|
||||
|
||||
plugin_class = BME280Plugin
|
@ -67,7 +67,7 @@ class GpsdLocationPlugin(SidebandTelemetryPlugin):
|
||||
self.latitude = gpsd_latitude
|
||||
self.longitude = gpsd_longitude
|
||||
self.altitude = gpsd_altitude
|
||||
self.speed = gpsd_speed
|
||||
self.speed = gpsd_speed*3.6 # Convert from m/s to km/h
|
||||
self.bearing = gpsd_bearing
|
||||
|
||||
epx = result.get("epx", None); epy = result.get("epy", None)
|
||||
|
41
docs/example_plugins/lxmd_telemetry.py
Normal file
41
docs/example_plugins/lxmd_telemetry.py
Normal file
@ -0,0 +1,41 @@
|
||||
# This is an LXMd telemetry plugin that
|
||||
# queries a running LXMF Propagation Node
|
||||
# for status and statistics.
|
||||
|
||||
import RNS
|
||||
|
||||
class LXMdTelemetryPlugin(SidebandTelemetryPlugin):
|
||||
plugin_name = "lxmd_telemetry"
|
||||
|
||||
def start(self):
|
||||
# Do any initialisation work here
|
||||
RNS.log("LXMd telemetry plugin starting...")
|
||||
|
||||
# And finally call start on superclass
|
||||
super().start()
|
||||
|
||||
def stop(self):
|
||||
# Do any teardown work here
|
||||
pass
|
||||
|
||||
# And finally call stop on superclass
|
||||
super().stop()
|
||||
|
||||
def update_telemetry(self, telemeter):
|
||||
if telemeter != None:
|
||||
if not "lxmf_propagation" in telemeter.sensors:
|
||||
# Create lxmd status sensor if it is not already
|
||||
# enabled in the running telemeter instance
|
||||
telemeter.enable("lxmf_propagation")
|
||||
|
||||
# Set the identity file used to communicate with
|
||||
# the running LXMd instance.
|
||||
telemeter.sensors["lxmf_propagation"].set_identity("~/.lxmd/identity")
|
||||
|
||||
# You can also get LXMF Propagation Node stats
|
||||
# from an LXMd instance running inside nomadnet
|
||||
# telemeter.sensors["lxmf_propagation"].set_identity("~/.nomadnetwork/storage/identity")
|
||||
|
||||
# Finally, tell Sideband what class in this
|
||||
# file is the actual plugin class.
|
||||
plugin_class = LXMdTelemetryPlugin
|
@ -59,7 +59,8 @@ class BasicTelemetryPlugin(SidebandTelemetryPlugin):
|
||||
|
||||
# Create fuel sensor
|
||||
telemeter.synthesize("fuel")
|
||||
telemeter.sensors["fuel"].update_entry(capacity=75, level=61)
|
||||
telemeter.sensors["fuel"].update_entry(capacity=75, level=61, type_label="Main")
|
||||
telemeter.sensors["fuel"].update_entry(capacity=15, level=15, type_label="Reserve")
|
||||
|
||||
# Finally, tell Sideband what class in this
|
||||
# file is the actual plugin class.
|
||||
|
@ -310,7 +310,8 @@ class ViewCommandPlugin(SidebandCommandPlugin):
|
||||
else:
|
||||
image_field = self.sources[source].get_image_field(quality_preset)
|
||||
image_timestamp = self.timestamp_str(self.sources[source].last_update)
|
||||
message = f"Source [b]{source}[/b] at [b]{image_timestamp}[/b]"
|
||||
message = "#!md\n" # Tell sideband to format this message
|
||||
message += f"Source [b]{source}[/b] at [b]{image_timestamp}[/b]"
|
||||
|
||||
if image_field != None:
|
||||
self.image_response(message, image_field, requestor)
|
||||
|
88
docs/example_plugins/windows_location.py
Normal file
88
docs/example_plugins/windows_location.py
Normal file
@ -0,0 +1,88 @@
|
||||
# Windows Location Provider plugin example, provided by @haplo-dev
|
||||
|
||||
import RNS
|
||||
import time
|
||||
import threading
|
||||
import asyncio
|
||||
from winsdk.windows.devices import geolocation
|
||||
|
||||
class WindowsLocationPlugin(SidebandTelemetryPlugin):
|
||||
plugin_name = "windows_location"
|
||||
|
||||
def __init__(self, sideband_core):
|
||||
self.update_interval = 5.0
|
||||
self.should_run = False
|
||||
|
||||
self.latitude = None
|
||||
self.longitude = None
|
||||
self.altitude = None
|
||||
self.speed = None
|
||||
self.bearing = None
|
||||
self.accuracy = None
|
||||
self.last_update = None
|
||||
|
||||
super().__init__(sideband_core)
|
||||
|
||||
def start(self):
|
||||
RNS.log("Starting Windows Location provider plugin...")
|
||||
|
||||
self.should_run = True
|
||||
update_thread = threading.Thread(target=self.update_job, daemon=True)
|
||||
update_thread.start()
|
||||
|
||||
super().start()
|
||||
|
||||
def stop(self):
|
||||
self.should_run = False
|
||||
super().stop()
|
||||
|
||||
def update_job(self):
|
||||
while self.should_run:
|
||||
RNS.log("Updating location from Windows Geolocation...", RNS.LOG_DEBUG)
|
||||
try:
|
||||
asyncio.run(self.get_location())
|
||||
except Exception as e:
|
||||
RNS.log(f"Error getting location: {str(e)}", RNS.LOG_ERROR)
|
||||
|
||||
time.sleep(self.update_interval)
|
||||
|
||||
async def get_location(self):
|
||||
geolocator = geolocation.Geolocator()
|
||||
position = await geolocator.get_geoposition_async()
|
||||
|
||||
self.last_update = time.time()
|
||||
self.latitude = position.coordinate.latitude
|
||||
self.longitude = position.coordinate.longitude
|
||||
self.altitude = position.coordinate.altitude
|
||||
self.accuracy = position.coordinate.accuracy
|
||||
|
||||
# Note: Windows Geolocation doesn't provide speed and bearing directly
|
||||
# You might need to calculate these from successive position updates
|
||||
self.speed = None
|
||||
self.bearing = None
|
||||
|
||||
def has_location(self):
|
||||
return all([self.latitude, self.longitude, self.altitude, self.accuracy]) is not None
|
||||
|
||||
def update_telemetry(self, telemeter):
|
||||
if self.is_running() and telemeter is not None:
|
||||
if self.has_location():
|
||||
RNS.log("Updating location from Windows Geolocation", RNS.LOG_DEBUG)
|
||||
if "location" not in telemeter.sensors:
|
||||
telemeter.synthesize("location")
|
||||
|
||||
telemeter.sensors["location"].latitude = self.latitude
|
||||
telemeter.sensors["location"].longitude = self.longitude
|
||||
telemeter.sensors["location"].altitude = self.altitude
|
||||
telemeter.sensors["location"].speed = self.speed
|
||||
telemeter.sensors["location"].bearing = self.bearing
|
||||
telemeter.sensors["location"].accuracy = self.accuracy
|
||||
telemeter.sensors["location"].stale_time = 5
|
||||
telemeter.sensors["location"].set_update_time(self.last_update)
|
||||
|
||||
else:
|
||||
RNS.log("No location from Windows Geolocation yet", RNS.LOG_DEBUG)
|
||||
|
||||
# Finally, tell Sideband what class in this
|
||||
# file is the actual plugin class.
|
||||
plugin_class = WindowsLocationPlugin
|
@ -1,129 +0,0 @@
|
||||
import os
|
||||
import math
|
||||
import RNS
|
||||
import RNS.vendor.umsgpack as mp
|
||||
|
||||
def simulate(link_speed=9600, audio_slot_ms=70, codec_rate=1200, method="msgpack"):
|
||||
# Simulated on-air link speed
|
||||
LINK_SPEED = link_speed
|
||||
|
||||
# Packing method, can be "msgpack" or "protobuf"
|
||||
PACKING_METHOD = method
|
||||
|
||||
# The target audio slot time
|
||||
TARGET_MS = audio_slot_ms
|
||||
|
||||
# Packets needed per second for half-duplex audio
|
||||
PACKETS_PER_SECOND = 1000/TARGET_MS
|
||||
|
||||
# Effective audio encoder bitrate
|
||||
CODEC_RATE = codec_rate
|
||||
|
||||
# Maximum number of supported audio modes
|
||||
MAX_ENUM = 127
|
||||
|
||||
# Per-packet overhead on a established link is 19
|
||||
# bytes, 3 for header and context, 16 for link ID
|
||||
RNS_OVERHEAD = 19
|
||||
|
||||
# Physical-layer overhead. For RNode, this is 1
|
||||
# byte per RNS packet.
|
||||
PHY_OVERHEAD = 1
|
||||
|
||||
# Total transport overhead
|
||||
TRANSPORT_OVERHEAD = PHY_OVERHEAD+RNS_OVERHEAD
|
||||
|
||||
# Calculate parameters
|
||||
AUDIO_LEN = int(math.ceil(CODEC_RATE/(1000/TARGET_MS)/8))
|
||||
PER_BYTE_LATENCY_MS = 1000/(LINK_SPEED/8)
|
||||
|
||||
# Pack the message with msgpack to get real-
|
||||
# world packed message size
|
||||
|
||||
if PACKING_METHOD == "msgpack":
|
||||
# Calculate msgpack overhead
|
||||
PL_LEN = len(mp.packb([MAX_ENUM, os.urandom(AUDIO_LEN)]))
|
||||
PACKING_OVERHEAD = PL_LEN-AUDIO_LEN
|
||||
elif PACKING_METHOD == "protobuf":
|
||||
# For protobuf, assume the 8 bytes of stated overhead
|
||||
PACKING_OVERHEAD = 8
|
||||
PL_LEN = AUDIO_LEN+PACKING_OVERHEAD
|
||||
else:
|
||||
print("Unsupported packing method")
|
||||
exit(1)
|
||||
|
||||
# Calculate required encrypted token blocks
|
||||
BLOCKSIZE = 16
|
||||
REQUIRED_BLOCKS = math.ceil((PL_LEN+1)/BLOCKSIZE)
|
||||
ENCRYPTED_PAYLOAD_LEN = REQUIRED_BLOCKS*BLOCKSIZE
|
||||
BLOCK_HEADROOM = (REQUIRED_BLOCKS*BLOCKSIZE) - PL_LEN - 1
|
||||
|
||||
# The complete on-air packet length
|
||||
PACKET_LEN = PHY_OVERHEAD+RNS_OVERHEAD+ENCRYPTED_PAYLOAD_LEN
|
||||
PACKET_LATENCY = round(PACKET_LEN*PER_BYTE_LATENCY_MS, 1)
|
||||
|
||||
# TODO: This should include any additional
|
||||
# airtime consumption such as preamble and TX-tail.
|
||||
PACKET_AIRTIME = PACKET_LEN*PER_BYTE_LATENCY_MS
|
||||
AIRTIME_PCT = (PACKET_AIRTIME/TARGET_MS) * 100
|
||||
|
||||
# Maximum amount of concurrent full-duplex
|
||||
# calls that can coexist on the same channel
|
||||
CONCURRENT_CALLS = math.floor(100/AIRTIME_PCT)
|
||||
|
||||
# Calculate latencies
|
||||
TRANSPORT_LATENCY = round((PHY_OVERHEAD+RNS_OVERHEAD)*PER_BYTE_LATENCY_MS, 1)
|
||||
|
||||
PAYLOAD_LATENCY = round(ENCRYPTED_PAYLOAD_LEN*PER_BYTE_LATENCY_MS, 1)
|
||||
RAW_DATA_LATENCY = round(AUDIO_LEN*PER_BYTE_LATENCY_MS, 1)
|
||||
PACKING_LATENCY = round(PACKING_OVERHEAD*PER_BYTE_LATENCY_MS, 1)
|
||||
|
||||
DATA_LATENCY = round(ENCRYPTED_PAYLOAD_LEN*PER_BYTE_LATENCY_MS, 1)
|
||||
ENCRYPTION_LATENCY = round((ENCRYPTED_PAYLOAD_LEN-PL_LEN)*PER_BYTE_LATENCY_MS, 1)
|
||||
if ENCRYPTED_PAYLOAD_LEN-PL_LEN == 1:
|
||||
E_OPT_STR = "(optimal)"
|
||||
else:
|
||||
E_OPT_STR = "(sub-optimal)"
|
||||
|
||||
TOTAL_LATENCY = round(TARGET_MS+PACKET_LATENCY, 1)
|
||||
|
||||
print( "\n===== Simulation Parameters ===\n")
|
||||
print(f" Packing method : {method}")
|
||||
print(f" Sampling delay : {TARGET_MS}ms")
|
||||
print(f" Codec bitrate : {CODEC_RATE} bps")
|
||||
print(f" Audio data : {AUDIO_LEN} bytes")
|
||||
print(f" Packing overhead : {PACKING_OVERHEAD} bytes")
|
||||
print(f" Payload length : {PL_LEN} bytes")
|
||||
print(f" AES blocks needed : {REQUIRED_BLOCKS}")
|
||||
print(f" Encrypted payload : {ENCRYPTED_PAYLOAD_LEN} bytes")
|
||||
print(f" Transport overhead : {TRANSPORT_OVERHEAD} bytes ({RNS_OVERHEAD} from RNS, {PHY_OVERHEAD} from PHY)")
|
||||
print(f" On-air length : {PACKET_LEN} bytes")
|
||||
print(f" Packet airtime : {PACKET_AIRTIME}ms")
|
||||
|
||||
print( "\n===== Results for "+RNS.prettyspeed(LINK_SPEED)+" Link Speed ===\n")
|
||||
print(f" Final latency : {TOTAL_LATENCY}ms")
|
||||
print(f" Recording latency : contributes {TARGET_MS}ms")
|
||||
print(f" Packet transport : contributes {PACKET_LATENCY}ms")
|
||||
print(f" Payload : contributes {PAYLOAD_LATENCY}ms")
|
||||
print(f" Audio data : contributes {RAW_DATA_LATENCY}ms")
|
||||
print(f" Packing format : contributes {PACKING_LATENCY}ms")
|
||||
print(f" Encryption : contributes {ENCRYPTION_LATENCY}ms {E_OPT_STR}")
|
||||
print(f" RNS+PHY overhead : contributes {TRANSPORT_LATENCY}ms")
|
||||
print(f"")
|
||||
print(f" Half-duplex airtime : {round(AIRTIME_PCT, 2)}% of link capacity")
|
||||
print(f" Concurrent calls : {int(CONCURRENT_CALLS)}\n")
|
||||
print(f" Full-duplex airtime : {round(AIRTIME_PCT*2, 2)}% of link capacity")
|
||||
print(f" Concurrent calls : {int(CONCURRENT_CALLS/2)}")
|
||||
|
||||
if BLOCK_HEADROOM != 0:
|
||||
print("")
|
||||
print(f" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
print(f" Unaligned AES block! Each packet could fit")
|
||||
print(f" {BLOCK_HEADROOM} bytes of additional audio data")
|
||||
print(f" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
|
||||
print( "\n= With mspack =================")
|
||||
simulate(method="msgpack")
|
||||
|
||||
#print("\n\n= With protobuf ===============")
|
||||
#simulate(method="protobuf")
|
@ -7,7 +7,7 @@ clean:
|
||||
-(rm ./__pycache__ -r)
|
||||
-(rm ./app_storage -r)
|
||||
-(rm ./share/pkg/* -r)
|
||||
-(rm ./share/mirrors/* -r)
|
||||
-(rm ./share/mirrors/* -rf)
|
||||
-(rm ./bin -r)
|
||||
|
||||
cleanlibs:
|
||||
@ -64,13 +64,14 @@ fetchshare:
|
||||
cp ../../dist_archive/lxmf-*-py3-none-any.whl ./share/pkg/
|
||||
cp ../../dist_archive/nomadnet-*-py3-none-any.whl ./share/pkg/
|
||||
cp ../../dist_archive/rnsh-*-py3-none-any.whl ./share/pkg/
|
||||
# cp ../../dist_archive/sbapp-*-py3-none-any.whl ./share/pkg/
|
||||
cp ../../dist_archive/RNode_Firmware_*_Source.zip ./share/pkg/
|
||||
zip --junk-paths ./share/pkg/example_plugins.zip ../docs/example_plugins/*.py
|
||||
cp -r ../../dist_archive/reticulum.network ./share/mirrors/
|
||||
cp -r ../../dist_archive/unsigned.io ./share/mirrors/
|
||||
cp ../../dist_archive/Reticulum\ Manual.pdf ./share/mirrors/Reticulum_Manual.pdf
|
||||
cp ../../dist_archive/Reticulum\ Manual.epub ./share/mirrors/Reticulum_Manual.epub
|
||||
cp -r ../../rnode-flasher ./share/mirrors/
|
||||
-(rm ./share/mirrors/rnode-flasher/.git -rf)
|
||||
|
||||
release:
|
||||
buildozer android release
|
||||
@ -96,7 +97,11 @@ getrns:
|
||||
-(rm ./RNS/__pycache__ -r)
|
||||
(cp -rv ../../LXMF/LXMF ./;rm ./LXMF/Utilities/LXMF)
|
||||
-(rm ./LXMF/__pycache__ -r)
|
||||
(cp -rv ../../LXST/LXST ./;rm ./LXST/Utilities/LXST)
|
||||
-(rm ./LXST/__pycache__ -r)
|
||||
-(rm ./LXST/Utilities/__pycache__ -r)
|
||||
|
||||
cleanrns:
|
||||
-(rm ./RNS -r)
|
||||
-(rm ./LXMF -r)
|
||||
-(rm ./LXST -r)
|
||||
|
BIN
sbapp/assets/audio/notifications/ringer.opus
Normal file
BIN
sbapp/assets/audio/notifications/ringer.opus
Normal file
Binary file not shown.
BIN
sbapp/assets/audio/notifications/soft1.opus
Normal file
BIN
sbapp/assets/audio/notifications/soft1.opus
Normal file
Binary file not shown.
BIN
sbapp/assets/fonts/BigBlueTerm437NerdFont-Regular.ttf
Normal file
BIN
sbapp/assets/fonts/BigBlueTerm437NerdFont-Regular.ttf
Normal file
Binary file not shown.
BIN
sbapp/assets/fonts/RobotoMonoNerdFont-Regular.ttf
Normal file
BIN
sbapp/assets/fonts/RobotoMonoNerdFont-Regular.ttf
Normal file
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
# Entry version 20240630
|
||||
# Entry version 20241128
|
||||
[Desktop Entry]
|
||||
Comment[en_US]=Messaging, telemetry and remote control over LXMF
|
||||
Comment=Messaging, telemetry and remote control over LXMF
|
||||
@ -6,7 +6,7 @@ Encoding=UTF-8
|
||||
Exec=sideband
|
||||
GenericName[en_US]=LXMF client
|
||||
GenericName=LXMF client
|
||||
Icon=io.unsigned.sideband.png
|
||||
Icon=io.unsigned.sideband
|
||||
Categories=Utility
|
||||
MimeType=
|
||||
Name[en_US]=Sideband
|
||||
|
@ -10,9 +10,9 @@ source.exclude_patterns = app_storage/*,venv/*,Makefile,./Makefil*,requirements,
|
||||
|
||||
version.regex = __version__ = ['"](.*)['"]
|
||||
version.filename = %(source.dir)s/main.py
|
||||
android.numeric_version = 20241013
|
||||
android.numeric_version = 20250327
|
||||
|
||||
requirements = kivy==2.3.0,libbz2,pillow==10.2.0,qrcode==7.3.1,usb4a,usbserial4a,able_recipe,libwebp,libogg,libopus,opusfile,numpy,cryptography,ffpyplayer,codec2,pycodec2,sh,pynacl,typing-extensions
|
||||
requirements = kivy==2.3.0,libbz2,pillow==10.2.0,qrcode==7.3.1,usb4a,usbserial4a,able_recipe,libwebp,libogg,libopus,opusfile,numpy,cryptography,ffpyplayer,codec2,pycodec2,sh,pynacl,typing-extensions,mistune>=3.0.2,beautifulsoup4
|
||||
|
||||
android.gradle_dependencies = com.android.support:support-compat:28.0.0
|
||||
#android.enable_androidx = True
|
||||
|
@ -30,10 +30,13 @@ def get_variant() -> str:
|
||||
version = re.findall(version_regex, version_file_data, re.M)[0]
|
||||
return version
|
||||
except IndexError:
|
||||
raise ValueError(f"Unable to find version string in {version_file}.")
|
||||
return None
|
||||
|
||||
__version__ = get_version()
|
||||
__variant__ = get_variant()
|
||||
variant_str = ""
|
||||
if __variant__:
|
||||
variant_str = " "+__variant__
|
||||
|
||||
def glob_paths(pattern):
|
||||
out_files = []
|
||||
@ -60,14 +63,14 @@ package_data = {
|
||||
]
|
||||
}
|
||||
|
||||
print("Freezing Sideband "+__version__+" "+__variant__)
|
||||
print("Freezing Sideband "+__version__+" "+variant_str)
|
||||
|
||||
if build_appimage:
|
||||
global_excludes = [".buildozer", "build", "dist"]
|
||||
# Dependencies are automatically detected, but they might need fine-tuning.
|
||||
appimage_options = {
|
||||
"target_name": "Sideband",
|
||||
"target_version": __version__+" "+__variant__,
|
||||
"target_version": __version__+" "+variant_str,
|
||||
"include_files": [],
|
||||
"excludes": [],
|
||||
"packages": ["kivy"],
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 5.4 KiB |
BIN
sbapp/kivymd/images/folder_orange.png
Normal file
BIN
sbapp/kivymd/images/folder_orange.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
862
sbapp/main.py
862
sbapp/main.py
File diff suppressed because it is too large
Load Diff
1
sbapp/md/__init__.py
Normal file
1
sbapp/md/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .md import mdconv
|
110
sbapp/md/md.py
Normal file
110
sbapp/md/md.py
Normal file
@ -0,0 +1,110 @@
|
||||
import mistune
|
||||
from mistune.core import BaseRenderer
|
||||
from mistune.plugins.formatting import strikethrough, mark, superscript, subscript, insert
|
||||
from mistune.plugins.table import table, table_in_list
|
||||
from mistune.plugins.footnotes import footnotes
|
||||
from mistune.plugins.task_lists import task_lists
|
||||
from mistune.plugins.spoiler import spoiler
|
||||
from mistune.util import escape as escape_text, safe_entity
|
||||
|
||||
def mdconv(markdown_text, domain=None, debug=False):
|
||||
parser = mistune.create_markdown(renderer=BBRenderer(), plugins=[strikethrough, mark, superscript, subscript, insert, footnotes, task_lists, spoiler])
|
||||
return parser(markdown_text)
|
||||
|
||||
class BBRenderer(BaseRenderer):
|
||||
NAME = "bbcode"
|
||||
|
||||
def __init__(self, escape=False):
|
||||
super(BBRenderer, self).__init__()
|
||||
self._escape = escape
|
||||
|
||||
def render_token(self, token, state):
|
||||
func = self._get_method(token["type"])
|
||||
attrs = token.get("attrs")
|
||||
|
||||
if "raw" in token: text = token["raw"]
|
||||
elif "children" in token: text = self.render_tokens(token["children"], state)
|
||||
else:
|
||||
if attrs: return func(**attrs)
|
||||
else: return func()
|
||||
|
||||
if attrs: return func(text, **attrs)
|
||||
else: return func(text)
|
||||
|
||||
# Simple renderers
|
||||
def emphasis(self, text): return f"[i]{text}[/i]"
|
||||
def strong(self, text): return f"[b]{text}[/b]"
|
||||
def codespan(self, text): return f"[icode]{text}[/icode]"
|
||||
def linebreak(self): return "\n"
|
||||
def softbreak(self): return "\n"
|
||||
def list_item(self, text): return f"• {text}\n"
|
||||
def task_list_item(self, text, checked=False): e = "" if checked else ""; return f"{e} {text}\n"
|
||||
def strikethrough(self, text): return f"[s]{text}[/s]"
|
||||
def insert(self, text): return f"[u]{text}[/u]"
|
||||
def inline_spoiler(self, text): return f"[ISPOILER]{text}[/ISPOILER]"
|
||||
def block_spoiler(self, text): return f"[SPOILER]\n{text}\n[/SPOILER]"
|
||||
def block_error(self, text): return f"[color=red][icode]{text}[/icode][/color]\n"
|
||||
def block_html(self, html): return ""
|
||||
def link(self, text, url, title=None): return f"[u]{text}[/u] ({url})"
|
||||
def footnote_ref(self, key, index): return f"[sup][u]{index}[/u][/sup]"
|
||||
def footnotes(self, text): return f"[b]Footnotes[/b]\n{text}"
|
||||
def footnote_item(self, text, key, index): return f"[ANAME=footnote-{index}]{index}[/ANAME]. {text}"
|
||||
def superscript(self, text: str) -> str: return f"[sup]{text}[/sup]"
|
||||
def subscript(self, text): return f"[sub]{text}[/sub]"
|
||||
def block_quote(self, text: str) -> str: return f"| [i]{text}[/i]"
|
||||
def paragraph(self, text): return f"{text}\n\n"
|
||||
def blank_line(self): return ""
|
||||
def block_text(self, text): return text
|
||||
|
||||
# Renderers needing some logic
|
||||
def text(self, text):
|
||||
if self._escape: return escape_text(text)
|
||||
else: return text
|
||||
|
||||
def inline_html(self, html: str) -> str:
|
||||
if self._escape: return escape_text(html)
|
||||
else: return html
|
||||
|
||||
def heading(self, text, level, **attrs):
|
||||
if 1 <= level <= 3: return f"[HEADING={level}]{text}[/HEADING]\n"
|
||||
else: return f"[HEADING=3]{text}[/HEADING]\n"
|
||||
|
||||
def block_code(self, code: str, **attrs) -> str:
|
||||
special_cases = {"plaintext": None, "text": None, "txt": None}
|
||||
if "info" in attrs:
|
||||
lang_info = safe_entity(attrs["info"].strip())
|
||||
lang = lang_info.split(None, 1)[0].lower()
|
||||
bbcode_lang = special_cases.get(lang, lang)
|
||||
if bbcode_lang: return f"[CODE={bbcode_lang}]{escape_text(code)}[/CODE]\n"
|
||||
else: return f"[CODE]{escape_text(code)}[/CODE]\n"
|
||||
|
||||
else: return f"[CODE]{escape_text(code)}[/CODE]\n"
|
||||
|
||||
def list(self, text, ordered, **attrs):
|
||||
depth = 0; sln = ""; tli = ""
|
||||
if "depth" in attrs: depth = attrs["depth"]
|
||||
if depth != 0: sln = "\n"
|
||||
if depth == 0: tli = "\n"
|
||||
def remove_empty_lines(text):
|
||||
lines = text.split("\n")
|
||||
non_empty_lines = [line for line in lines if line.strip() != ""]
|
||||
nli = ""; dlm = "\n"+" "*depth
|
||||
if depth != 0: nli = dlm
|
||||
return nli+dlm.join(non_empty_lines)
|
||||
|
||||
text = remove_empty_lines(text)
|
||||
return sln+text+"\n"+tli
|
||||
|
||||
# TODO: Implement various table types and other special formatting
|
||||
def table(self, children, **attrs): return children
|
||||
def table_head(self, children, **attrs): return children
|
||||
def table_body(self, children, **attrs): return children
|
||||
def table_row(self, children, **attrs): return children
|
||||
def table_cell(self, text, align=None, head=False, **attrs): return f"{text}\n"
|
||||
def def_list(self, text): return f"{text}\n"
|
||||
def def_list_head(self, text): return f"{text}\n"
|
||||
def def_list_item(self, text): return f"{text}\n"
|
||||
def abbr(self, text, title): return text
|
||||
def mark(self, text): return text
|
||||
def image(self, text, url, title=None): return ""
|
||||
def thematic_break(self): return "-------------\n"
|
@ -13,11 +13,26 @@
|
||||
|
||||
<!-- This intent filter allows opening scanned LXM URLs directly in Sideband -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.WEB_SEARCH" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action android:name="android.intent.action.WEB_SEARCH" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="image/*" />
|
||||
<data android:mimeType="video/*" />
|
||||
<data android:mimeType="audio/*" />
|
||||
<data android:mimeType="text/*" />
|
||||
<data android:mimeType="application/*" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
||||
android:resource="@xml/device_filter" />
|
5
sbapp/pmqtt/__init__.py
Normal file
5
sbapp/pmqtt/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
__version__ = "2.1.1.dev0"
|
||||
|
||||
|
||||
class MQTTException(Exception):
|
||||
pass
|
4856
sbapp/pmqtt/client.py
Normal file
4856
sbapp/pmqtt/client.py
Normal file
File diff suppressed because it is too large
Load Diff
113
sbapp/pmqtt/enums.py
Normal file
113
sbapp/pmqtt/enums.py
Normal file
@ -0,0 +1,113 @@
|
||||
import enum
|
||||
|
||||
|
||||
class MQTTErrorCode(enum.IntEnum):
|
||||
MQTT_ERR_AGAIN = -1
|
||||
MQTT_ERR_SUCCESS = 0
|
||||
MQTT_ERR_NOMEM = 1
|
||||
MQTT_ERR_PROTOCOL = 2
|
||||
MQTT_ERR_INVAL = 3
|
||||
MQTT_ERR_NO_CONN = 4
|
||||
MQTT_ERR_CONN_REFUSED = 5
|
||||
MQTT_ERR_NOT_FOUND = 6
|
||||
MQTT_ERR_CONN_LOST = 7
|
||||
MQTT_ERR_TLS = 8
|
||||
MQTT_ERR_PAYLOAD_SIZE = 9
|
||||
MQTT_ERR_NOT_SUPPORTED = 10
|
||||
MQTT_ERR_AUTH = 11
|
||||
MQTT_ERR_ACL_DENIED = 12
|
||||
MQTT_ERR_UNKNOWN = 13
|
||||
MQTT_ERR_ERRNO = 14
|
||||
MQTT_ERR_QUEUE_SIZE = 15
|
||||
MQTT_ERR_KEEPALIVE = 16
|
||||
|
||||
|
||||
class MQTTProtocolVersion(enum.IntEnum):
|
||||
MQTTv31 = 3
|
||||
MQTTv311 = 4
|
||||
MQTTv5 = 5
|
||||
|
||||
|
||||
class CallbackAPIVersion(enum.Enum):
|
||||
"""Defined the arguments passed to all user-callback.
|
||||
|
||||
See each callbacks for details: `on_connect`, `on_connect_fail`, `on_disconnect`, `on_message`, `on_publish`,
|
||||
`on_subscribe`, `on_unsubscribe`, `on_log`, `on_socket_open`, `on_socket_close`,
|
||||
`on_socket_register_write`, `on_socket_unregister_write`
|
||||
"""
|
||||
VERSION1 = 1
|
||||
"""The version used with paho-mqtt 1.x before introducing CallbackAPIVersion.
|
||||
|
||||
This version had different arguments depending if MQTTv5 or MQTTv3 was used. `Properties` & `ReasonCode` were missing
|
||||
on some callback (apply only to MQTTv5).
|
||||
|
||||
This version is deprecated and will be removed in version 3.0.
|
||||
"""
|
||||
VERSION2 = 2
|
||||
""" This version fix some of the shortcoming of previous version.
|
||||
|
||||
Callback have the same signature if using MQTTv5 or MQTTv3. `ReasonCode` are used in MQTTv3.
|
||||
"""
|
||||
|
||||
|
||||
class MessageType(enum.IntEnum):
|
||||
CONNECT = 0x10
|
||||
CONNACK = 0x20
|
||||
PUBLISH = 0x30
|
||||
PUBACK = 0x40
|
||||
PUBREC = 0x50
|
||||
PUBREL = 0x60
|
||||
PUBCOMP = 0x70
|
||||
SUBSCRIBE = 0x80
|
||||
SUBACK = 0x90
|
||||
UNSUBSCRIBE = 0xA0
|
||||
UNSUBACK = 0xB0
|
||||
PINGREQ = 0xC0
|
||||
PINGRESP = 0xD0
|
||||
DISCONNECT = 0xE0
|
||||
AUTH = 0xF0
|
||||
|
||||
|
||||
class LogLevel(enum.IntEnum):
|
||||
MQTT_LOG_INFO = 0x01
|
||||
MQTT_LOG_NOTICE = 0x02
|
||||
MQTT_LOG_WARNING = 0x04
|
||||
MQTT_LOG_ERR = 0x08
|
||||
MQTT_LOG_DEBUG = 0x10
|
||||
|
||||
|
||||
class ConnackCode(enum.IntEnum):
|
||||
CONNACK_ACCEPTED = 0
|
||||
CONNACK_REFUSED_PROTOCOL_VERSION = 1
|
||||
CONNACK_REFUSED_IDENTIFIER_REJECTED = 2
|
||||
CONNACK_REFUSED_SERVER_UNAVAILABLE = 3
|
||||
CONNACK_REFUSED_BAD_USERNAME_PASSWORD = 4
|
||||
CONNACK_REFUSED_NOT_AUTHORIZED = 5
|
||||
|
||||
|
||||
class _ConnectionState(enum.Enum):
|
||||
MQTT_CS_NEW = enum.auto()
|
||||
MQTT_CS_CONNECT_ASYNC = enum.auto()
|
||||
MQTT_CS_CONNECTING = enum.auto()
|
||||
MQTT_CS_CONNECTED = enum.auto()
|
||||
MQTT_CS_CONNECTION_LOST = enum.auto()
|
||||
MQTT_CS_DISCONNECTING = enum.auto()
|
||||
MQTT_CS_DISCONNECTED = enum.auto()
|
||||
|
||||
|
||||
class MessageState(enum.IntEnum):
|
||||
MQTT_MS_INVALID = 0
|
||||
MQTT_MS_PUBLISH = 1
|
||||
MQTT_MS_WAIT_FOR_PUBACK = 2
|
||||
MQTT_MS_WAIT_FOR_PUBREC = 3
|
||||
MQTT_MS_RESEND_PUBREL = 4
|
||||
MQTT_MS_WAIT_FOR_PUBREL = 5
|
||||
MQTT_MS_RESEND_PUBCOMP = 6
|
||||
MQTT_MS_WAIT_FOR_PUBCOMP = 7
|
||||
MQTT_MS_SEND_PUBREC = 8
|
||||
MQTT_MS_QUEUED = 9
|
||||
|
||||
|
||||
class PahoClientMode(enum.IntEnum):
|
||||
MQTT_CLIENT = 0
|
||||
MQTT_BRIDGE = 1
|
78
sbapp/pmqtt/matcher.py
Normal file
78
sbapp/pmqtt/matcher.py
Normal file
@ -0,0 +1,78 @@
|
||||
class MQTTMatcher:
|
||||
"""Intended to manage topic filters including wildcards.
|
||||
|
||||
Internally, MQTTMatcher use a prefix tree (trie) to store
|
||||
values associated with filters, and has an iter_match()
|
||||
method to iterate efficiently over all filters that match
|
||||
some topic name."""
|
||||
|
||||
class Node:
|
||||
__slots__ = '_children', '_content'
|
||||
|
||||
def __init__(self):
|
||||
self._children = {}
|
||||
self._content = None
|
||||
|
||||
def __init__(self):
|
||||
self._root = self.Node()
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
"""Add a topic filter :key to the prefix tree
|
||||
and associate it to :value"""
|
||||
node = self._root
|
||||
for sym in key.split('/'):
|
||||
node = node._children.setdefault(sym, self.Node())
|
||||
node._content = value
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Retrieve the value associated with some topic filter :key"""
|
||||
try:
|
||||
node = self._root
|
||||
for sym in key.split('/'):
|
||||
node = node._children[sym]
|
||||
if node._content is None:
|
||||
raise KeyError(key)
|
||||
return node._content
|
||||
except KeyError as ke:
|
||||
raise KeyError(key) from ke
|
||||
|
||||
def __delitem__(self, key):
|
||||
"""Delete the value associated with some topic filter :key"""
|
||||
lst = []
|
||||
try:
|
||||
parent, node = None, self._root
|
||||
for k in key.split('/'):
|
||||
parent, node = node, node._children[k]
|
||||
lst.append((parent, k, node))
|
||||
# TODO
|
||||
node._content = None
|
||||
except KeyError as ke:
|
||||
raise KeyError(key) from ke
|
||||
else: # cleanup
|
||||
for parent, k, node in reversed(lst):
|
||||
if node._children or node._content is not None:
|
||||
break
|
||||
del parent._children[k]
|
||||
|
||||
def iter_match(self, topic):
|
||||
"""Return an iterator on all values associated with filters
|
||||
that match the :topic"""
|
||||
lst = topic.split('/')
|
||||
normal = not topic.startswith('$')
|
||||
def rec(node, i=0):
|
||||
if i == len(lst):
|
||||
if node._content is not None:
|
||||
yield node._content
|
||||
else:
|
||||
part = lst[i]
|
||||
if part in node._children:
|
||||
for content in rec(node._children[part], i + 1):
|
||||
yield content
|
||||
if '+' in node._children and (normal or i > 0):
|
||||
for content in rec(node._children['+'], i + 1):
|
||||
yield content
|
||||
if '#' in node._children and (normal or i > 0):
|
||||
content = node._children['#']._content
|
||||
if content is not None:
|
||||
yield content
|
||||
return rec(self._root)
|
43
sbapp/pmqtt/packettypes.py
Normal file
43
sbapp/pmqtt/packettypes.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""
|
||||
*******************************************************************
|
||||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
http://www.eclipse.org/legal/epl-v20.html
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
Contributors:
|
||||
Ian Craggs - initial implementation and/or documentation
|
||||
*******************************************************************
|
||||
"""
|
||||
|
||||
|
||||
class PacketTypes:
|
||||
|
||||
"""
|
||||
Packet types class. Includes the AUTH packet for MQTT v5.0.
|
||||
|
||||
Holds constants for each packet type such as PacketTypes.PUBLISH
|
||||
and packet name strings: PacketTypes.Names[PacketTypes.PUBLISH].
|
||||
|
||||
"""
|
||||
|
||||
indexes = range(1, 16)
|
||||
|
||||
# Packet types
|
||||
CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, \
|
||||
PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, \
|
||||
PINGREQ, PINGRESP, DISCONNECT, AUTH = indexes
|
||||
|
||||
# Dummy packet type for properties use - will delay only applies to will
|
||||
WILLMESSAGE = 99
|
||||
|
||||
Names = ( "reserved", \
|
||||
"Connect", "Connack", "Publish", "Puback", "Pubrec", "Pubrel", \
|
||||
"Pubcomp", "Subscribe", "Suback", "Unsubscribe", "Unsuback", \
|
||||
"Pingreq", "Pingresp", "Disconnect", "Auth")
|
421
sbapp/pmqtt/properties.py
Normal file
421
sbapp/pmqtt/properties.py
Normal file
@ -0,0 +1,421 @@
|
||||
# *******************************************************************
|
||||
# Copyright (c) 2017, 2019 IBM Corp.
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
# http://www.eclipse.org/legal/epl-v20.html
|
||||
# and the Eclipse Distribution License is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# Contributors:
|
||||
# Ian Craggs - initial implementation and/or documentation
|
||||
# *******************************************************************
|
||||
|
||||
import struct
|
||||
|
||||
from .packettypes import PacketTypes
|
||||
|
||||
|
||||
class MQTTException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MalformedPacket(MQTTException):
|
||||
pass
|
||||
|
||||
|
||||
def writeInt16(length):
|
||||
# serialize a 16 bit integer to network format
|
||||
return bytearray(struct.pack("!H", length))
|
||||
|
||||
|
||||
def readInt16(buf):
|
||||
# deserialize a 16 bit integer from network format
|
||||
return struct.unpack("!H", buf[:2])[0]
|
||||
|
||||
|
||||
def writeInt32(length):
|
||||
# serialize a 32 bit integer to network format
|
||||
return bytearray(struct.pack("!L", length))
|
||||
|
||||
|
||||
def readInt32(buf):
|
||||
# deserialize a 32 bit integer from network format
|
||||
return struct.unpack("!L", buf[:4])[0]
|
||||
|
||||
|
||||
def writeUTF(data):
|
||||
# data could be a string, or bytes. If string, encode into bytes with utf-8
|
||||
if not isinstance(data, bytes):
|
||||
data = bytes(data, "utf-8")
|
||||
return writeInt16(len(data)) + data
|
||||
|
||||
|
||||
def readUTF(buffer, maxlen):
|
||||
if maxlen >= 2:
|
||||
length = readInt16(buffer)
|
||||
else:
|
||||
raise MalformedPacket("Not enough data to read string length")
|
||||
maxlen -= 2
|
||||
if length > maxlen:
|
||||
raise MalformedPacket("Length delimited string too long")
|
||||
buf = buffer[2:2+length].decode("utf-8")
|
||||
# look for chars which are invalid for MQTT
|
||||
for c in buf: # look for D800-DFFF in the UTF string
|
||||
ord_c = ord(c)
|
||||
if ord_c >= 0xD800 and ord_c <= 0xDFFF:
|
||||
raise MalformedPacket("[MQTT-1.5.4-1] D800-DFFF found in UTF-8 data")
|
||||
if ord_c == 0x00: # look for null in the UTF string
|
||||
raise MalformedPacket("[MQTT-1.5.4-2] Null found in UTF-8 data")
|
||||
if ord_c == 0xFEFF:
|
||||
raise MalformedPacket("[MQTT-1.5.4-3] U+FEFF in UTF-8 data")
|
||||
return buf, length+2
|
||||
|
||||
|
||||
def writeBytes(buffer):
|
||||
return writeInt16(len(buffer)) + buffer
|
||||
|
||||
|
||||
def readBytes(buffer):
|
||||
length = readInt16(buffer)
|
||||
return buffer[2:2+length], length+2
|
||||
|
||||
|
||||
class VariableByteIntegers: # Variable Byte Integer
|
||||
"""
|
||||
MQTT variable byte integer helper class. Used
|
||||
in several places in MQTT v5.0 properties.
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def encode(x):
|
||||
"""
|
||||
Convert an integer 0 <= x <= 268435455 into multi-byte format.
|
||||
Returns the buffer converted from the integer.
|
||||
"""
|
||||
if not 0 <= x <= 268435455:
|
||||
raise ValueError(f"Value {x!r} must be in range 0-268435455")
|
||||
buffer = b''
|
||||
while 1:
|
||||
digit = x % 128
|
||||
x //= 128
|
||||
if x > 0:
|
||||
digit |= 0x80
|
||||
buffer += bytes([digit])
|
||||
if x == 0:
|
||||
break
|
||||
return buffer
|
||||
|
||||
@staticmethod
|
||||
def decode(buffer):
|
||||
"""
|
||||
Get the value of a multi-byte integer from a buffer
|
||||
Return the value, and the number of bytes used.
|
||||
|
||||
[MQTT-1.5.5-1] the encoded value MUST use the minimum number of bytes necessary to represent the value
|
||||
"""
|
||||
multiplier = 1
|
||||
value = 0
|
||||
bytes = 0
|
||||
while 1:
|
||||
bytes += 1
|
||||
digit = buffer[0]
|
||||
buffer = buffer[1:]
|
||||
value += (digit & 127) * multiplier
|
||||
if digit & 128 == 0:
|
||||
break
|
||||
multiplier *= 128
|
||||
return (value, bytes)
|
||||
|
||||
|
||||
class Properties:
|
||||
"""MQTT v5.0 properties class.
|
||||
|
||||
See Properties.names for a list of accepted property names along with their numeric values.
|
||||
|
||||
See Properties.properties for the data type of each property.
|
||||
|
||||
Example of use::
|
||||
|
||||
publish_properties = Properties(PacketTypes.PUBLISH)
|
||||
publish_properties.UserProperty = ("a", "2")
|
||||
publish_properties.UserProperty = ("c", "3")
|
||||
|
||||
First the object is created with packet type as argument, no properties will be present at
|
||||
this point. Then properties are added as attributes, the name of which is the string property
|
||||
name without the spaces.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, packetType):
|
||||
self.packetType = packetType
|
||||
self.types = ["Byte", "Two Byte Integer", "Four Byte Integer", "Variable Byte Integer",
|
||||
"Binary Data", "UTF-8 Encoded String", "UTF-8 String Pair"]
|
||||
|
||||
self.names = {
|
||||
"Payload Format Indicator": 1,
|
||||
"Message Expiry Interval": 2,
|
||||
"Content Type": 3,
|
||||
"Response Topic": 8,
|
||||
"Correlation Data": 9,
|
||||
"Subscription Identifier": 11,
|
||||
"Session Expiry Interval": 17,
|
||||
"Assigned Client Identifier": 18,
|
||||
"Server Keep Alive": 19,
|
||||
"Authentication Method": 21,
|
||||
"Authentication Data": 22,
|
||||
"Request Problem Information": 23,
|
||||
"Will Delay Interval": 24,
|
||||
"Request Response Information": 25,
|
||||
"Response Information": 26,
|
||||
"Server Reference": 28,
|
||||
"Reason String": 31,
|
||||
"Receive Maximum": 33,
|
||||
"Topic Alias Maximum": 34,
|
||||
"Topic Alias": 35,
|
||||
"Maximum QoS": 36,
|
||||
"Retain Available": 37,
|
||||
"User Property": 38,
|
||||
"Maximum Packet Size": 39,
|
||||
"Wildcard Subscription Available": 40,
|
||||
"Subscription Identifier Available": 41,
|
||||
"Shared Subscription Available": 42
|
||||
}
|
||||
|
||||
self.properties = {
|
||||
# id: type, packets
|
||||
# payload format indicator
|
||||
1: (self.types.index("Byte"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]),
|
||||
2: (self.types.index("Four Byte Integer"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]),
|
||||
3: (self.types.index("UTF-8 Encoded String"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]),
|
||||
8: (self.types.index("UTF-8 Encoded String"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]),
|
||||
9: (self.types.index("Binary Data"), [PacketTypes.PUBLISH, PacketTypes.WILLMESSAGE]),
|
||||
11: (self.types.index("Variable Byte Integer"),
|
||||
[PacketTypes.PUBLISH, PacketTypes.SUBSCRIBE]),
|
||||
17: (self.types.index("Four Byte Integer"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.DISCONNECT]),
|
||||
18: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK]),
|
||||
19: (self.types.index("Two Byte Integer"), [PacketTypes.CONNACK]),
|
||||
21: (self.types.index("UTF-8 Encoded String"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.AUTH]),
|
||||
22: (self.types.index("Binary Data"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK, PacketTypes.AUTH]),
|
||||
23: (self.types.index("Byte"),
|
||||
[PacketTypes.CONNECT]),
|
||||
24: (self.types.index("Four Byte Integer"), [PacketTypes.WILLMESSAGE]),
|
||||
25: (self.types.index("Byte"), [PacketTypes.CONNECT]),
|
||||
26: (self.types.index("UTF-8 Encoded String"), [PacketTypes.CONNACK]),
|
||||
28: (self.types.index("UTF-8 Encoded String"),
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]),
|
||||
31: (self.types.index("UTF-8 Encoded String"),
|
||||
[PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC,
|
||||
PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.SUBACK,
|
||||
PacketTypes.UNSUBACK, PacketTypes.DISCONNECT, PacketTypes.AUTH]),
|
||||
33: (self.types.index("Two Byte Integer"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK]),
|
||||
34: (self.types.index("Two Byte Integer"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK]),
|
||||
35: (self.types.index("Two Byte Integer"), [PacketTypes.PUBLISH]),
|
||||
36: (self.types.index("Byte"), [PacketTypes.CONNACK]),
|
||||
37: (self.types.index("Byte"), [PacketTypes.CONNACK]),
|
||||
38: (self.types.index("UTF-8 String Pair"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK,
|
||||
PacketTypes.PUBLISH, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.PUBREL, PacketTypes.PUBCOMP,
|
||||
PacketTypes.SUBSCRIBE, PacketTypes.SUBACK,
|
||||
PacketTypes.UNSUBSCRIBE, PacketTypes.UNSUBACK,
|
||||
PacketTypes.DISCONNECT, PacketTypes.AUTH, PacketTypes.WILLMESSAGE]),
|
||||
39: (self.types.index("Four Byte Integer"),
|
||||
[PacketTypes.CONNECT, PacketTypes.CONNACK]),
|
||||
40: (self.types.index("Byte"), [PacketTypes.CONNACK]),
|
||||
41: (self.types.index("Byte"), [PacketTypes.CONNACK]),
|
||||
42: (self.types.index("Byte"), [PacketTypes.CONNACK]),
|
||||
}
|
||||
|
||||
def allowsMultiple(self, compressedName):
|
||||
return self.getIdentFromName(compressedName) in [11, 38]
|
||||
|
||||
def getIdentFromName(self, compressedName):
|
||||
# return the identifier corresponding to the property name
|
||||
result = -1
|
||||
for name in self.names.keys():
|
||||
if compressedName == name.replace(' ', ''):
|
||||
result = self.names[name]
|
||||
break
|
||||
return result
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
name = name.replace(' ', '')
|
||||
privateVars = ["packetType", "types", "names", "properties"]
|
||||
if name in privateVars:
|
||||
object.__setattr__(self, name, value)
|
||||
else:
|
||||
# the name could have spaces in, or not. Remove spaces before assignment
|
||||
if name not in [aname.replace(' ', '') for aname in self.names.keys()]:
|
||||
raise MQTTException(
|
||||
f"Property name must be one of {self.names.keys()}")
|
||||
# check that this attribute applies to the packet type
|
||||
if self.packetType not in self.properties[self.getIdentFromName(name)][1]:
|
||||
raise MQTTException(f"Property {name} does not apply to packet type {PacketTypes.Names[self.packetType]}")
|
||||
|
||||
# Check for forbidden values
|
||||
if not isinstance(value, list):
|
||||
if name in ["ReceiveMaximum", "TopicAlias"] \
|
||||
and (value < 1 or value > 65535):
|
||||
|
||||
raise MQTTException(f"{name} property value must be in the range 1-65535")
|
||||
elif name in ["TopicAliasMaximum"] \
|
||||
and (value < 0 or value > 65535):
|
||||
|
||||
raise MQTTException(f"{name} property value must be in the range 0-65535")
|
||||
elif name in ["MaximumPacketSize", "SubscriptionIdentifier"] \
|
||||
and (value < 1 or value > 268435455):
|
||||
|
||||
raise MQTTException(f"{name} property value must be in the range 1-268435455")
|
||||
elif name in ["RequestResponseInformation", "RequestProblemInformation", "PayloadFormatIndicator"] \
|
||||
and (value != 0 and value != 1):
|
||||
|
||||
raise MQTTException(
|
||||
f"{name} property value must be 0 or 1")
|
||||
|
||||
if self.allowsMultiple(name):
|
||||
if not isinstance(value, list):
|
||||
value = [value]
|
||||
if hasattr(self, name):
|
||||
value = object.__getattribute__(self, name) + value
|
||||
object.__setattr__(self, name, value)
|
||||
|
||||
def __str__(self):
|
||||
buffer = "["
|
||||
first = True
|
||||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
if not first:
|
||||
buffer += ", "
|
||||
buffer += f"{compressedName} : {getattr(self, compressedName)}"
|
||||
first = False
|
||||
buffer += "]"
|
||||
return buffer
|
||||
|
||||
def json(self):
|
||||
data = {}
|
||||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
val = getattr(self, compressedName)
|
||||
if compressedName == 'CorrelationData' and isinstance(val, bytes):
|
||||
data[compressedName] = val.hex()
|
||||
else:
|
||||
data[compressedName] = val
|
||||
return data
|
||||
|
||||
def isEmpty(self):
|
||||
rc = True
|
||||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
rc = False
|
||||
break
|
||||
return rc
|
||||
|
||||
def clear(self):
|
||||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
delattr(self, compressedName)
|
||||
|
||||
def writeProperty(self, identifier, type, value):
|
||||
buffer = b""
|
||||
buffer += VariableByteIntegers.encode(identifier) # identifier
|
||||
if type == self.types.index("Byte"): # value
|
||||
buffer += bytes([value])
|
||||
elif type == self.types.index("Two Byte Integer"):
|
||||
buffer += writeInt16(value)
|
||||
elif type == self.types.index("Four Byte Integer"):
|
||||
buffer += writeInt32(value)
|
||||
elif type == self.types.index("Variable Byte Integer"):
|
||||
buffer += VariableByteIntegers.encode(value)
|
||||
elif type == self.types.index("Binary Data"):
|
||||
buffer += writeBytes(value)
|
||||
elif type == self.types.index("UTF-8 Encoded String"):
|
||||
buffer += writeUTF(value)
|
||||
elif type == self.types.index("UTF-8 String Pair"):
|
||||
buffer += writeUTF(value[0]) + writeUTF(value[1])
|
||||
return buffer
|
||||
|
||||
def pack(self):
|
||||
# serialize properties into buffer for sending over network
|
||||
buffer = b""
|
||||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
identifier = self.getIdentFromName(compressedName)
|
||||
attr_type = self.properties[identifier][0]
|
||||
if self.allowsMultiple(compressedName):
|
||||
for prop in getattr(self, compressedName):
|
||||
buffer += self.writeProperty(identifier,
|
||||
attr_type, prop)
|
||||
else:
|
||||
buffer += self.writeProperty(identifier, attr_type,
|
||||
getattr(self, compressedName))
|
||||
return VariableByteIntegers.encode(len(buffer)) + buffer
|
||||
|
||||
def readProperty(self, buffer, type, propslen):
|
||||
if type == self.types.index("Byte"):
|
||||
value = buffer[0]
|
||||
valuelen = 1
|
||||
elif type == self.types.index("Two Byte Integer"):
|
||||
value = readInt16(buffer)
|
||||
valuelen = 2
|
||||
elif type == self.types.index("Four Byte Integer"):
|
||||
value = readInt32(buffer)
|
||||
valuelen = 4
|
||||
elif type == self.types.index("Variable Byte Integer"):
|
||||
value, valuelen = VariableByteIntegers.decode(buffer)
|
||||
elif type == self.types.index("Binary Data"):
|
||||
value, valuelen = readBytes(buffer)
|
||||
elif type == self.types.index("UTF-8 Encoded String"):
|
||||
value, valuelen = readUTF(buffer, propslen)
|
||||
elif type == self.types.index("UTF-8 String Pair"):
|
||||
value, valuelen = readUTF(buffer, propslen)
|
||||
buffer = buffer[valuelen:] # strip the bytes used by the value
|
||||
value1, valuelen1 = readUTF(buffer, propslen - valuelen)
|
||||
value = (value, value1)
|
||||
valuelen += valuelen1
|
||||
return value, valuelen
|
||||
|
||||
def getNameFromIdent(self, identifier):
|
||||
rc = None
|
||||
for name in self.names:
|
||||
if self.names[name] == identifier:
|
||||
rc = name
|
||||
return rc
|
||||
|
||||
def unpack(self, buffer):
|
||||
self.clear()
|
||||
# deserialize properties into attributes from buffer received from network
|
||||
propslen, VBIlen = VariableByteIntegers.decode(buffer)
|
||||
buffer = buffer[VBIlen:] # strip the bytes used by the VBI
|
||||
propslenleft = propslen
|
||||
while propslenleft > 0: # properties length is 0 if there are none
|
||||
identifier, VBIlen2 = VariableByteIntegers.decode(
|
||||
buffer) # property identifier
|
||||
buffer = buffer[VBIlen2:] # strip the bytes used by the VBI
|
||||
propslenleft -= VBIlen2
|
||||
attr_type = self.properties[identifier][0]
|
||||
value, valuelen = self.readProperty(
|
||||
buffer, attr_type, propslenleft)
|
||||
buffer = buffer[valuelen:] # strip the bytes used by the value
|
||||
propslenleft -= valuelen
|
||||
propname = self.getNameFromIdent(identifier)
|
||||
compressedName = propname.replace(' ', '')
|
||||
if not self.allowsMultiple(compressedName) and hasattr(self, compressedName):
|
||||
raise MQTTException(
|
||||
f"Property '{property}' must not exist more than once")
|
||||
setattr(self, propname, value)
|
||||
return self, propslen + VBIlen
|
306
sbapp/pmqtt/publish.py
Normal file
306
sbapp/pmqtt/publish.py
Normal file
@ -0,0 +1,306 @@
|
||||
# Copyright (c) 2014 Roger Light <roger@atchoo.org>
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
# http://www.eclipse.org/legal/epl-v20.html
|
||||
# and the Eclipse Distribution License is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# Contributors:
|
||||
# Roger Light - initial API and implementation
|
||||
|
||||
"""
|
||||
This module provides some helper functions to allow straightforward publishing
|
||||
of messages in a one-shot manner. In other words, they are useful for the
|
||||
situation where you have a single/multiple messages you want to publish to a
|
||||
broker, then disconnect and nothing else is required.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import collections
|
||||
from collections.abc import Iterable
|
||||
from typing import TYPE_CHECKING, Any, List, Tuple, Union
|
||||
|
||||
from .enums import CallbackAPIVersion, MQTTProtocolVersion
|
||||
from .properties import Properties
|
||||
from .reasoncodes import ReasonCode
|
||||
|
||||
from .. import mqtt
|
||||
from . import client as paho
|
||||
|
||||
if TYPE_CHECKING:
|
||||
try:
|
||||
from typing import NotRequired, Required, TypedDict # type: ignore
|
||||
except ImportError:
|
||||
from typing_extensions import NotRequired, Required, TypedDict
|
||||
|
||||
try:
|
||||
from typing import Literal
|
||||
except ImportError:
|
||||
from typing_extensions import Literal # type: ignore
|
||||
|
||||
|
||||
|
||||
class AuthParameter(TypedDict, total=False):
|
||||
username: Required[str]
|
||||
password: NotRequired[str]
|
||||
|
||||
|
||||
class TLSParameter(TypedDict, total=False):
|
||||
ca_certs: Required[str]
|
||||
certfile: NotRequired[str]
|
||||
keyfile: NotRequired[str]
|
||||
tls_version: NotRequired[int]
|
||||
ciphers: NotRequired[str]
|
||||
insecure: NotRequired[bool]
|
||||
|
||||
|
||||
class MessageDict(TypedDict, total=False):
|
||||
topic: Required[str]
|
||||
payload: NotRequired[paho.PayloadType]
|
||||
qos: NotRequired[int]
|
||||
retain: NotRequired[bool]
|
||||
|
||||
MessageTuple = Tuple[str, paho.PayloadType, int, bool]
|
||||
|
||||
MessagesList = List[Union[MessageDict, MessageTuple]]
|
||||
|
||||
|
||||
def _do_publish(client: paho.Client):
|
||||
"""Internal function"""
|
||||
|
||||
message = client._userdata.popleft()
|
||||
|
||||
if isinstance(message, dict):
|
||||
client.publish(**message)
|
||||
elif isinstance(message, (tuple, list)):
|
||||
client.publish(*message)
|
||||
else:
|
||||
raise TypeError('message must be a dict, tuple, or list')
|
||||
|
||||
|
||||
def _on_connect(client: paho.Client, userdata: MessagesList, flags, reason_code, properties):
|
||||
"""Internal v5 callback"""
|
||||
if reason_code == 0:
|
||||
if len(userdata) > 0:
|
||||
_do_publish(client)
|
||||
else:
|
||||
raise mqtt.MQTTException(paho.connack_string(reason_code))
|
||||
|
||||
|
||||
def _on_publish(
|
||||
client: paho.Client, userdata: collections.deque[MessagesList], mid: int, reason_codes: ReasonCode, properties: Properties,
|
||||
) -> None:
|
||||
"""Internal callback"""
|
||||
#pylint: disable=unused-argument
|
||||
|
||||
if len(userdata) == 0:
|
||||
client.disconnect()
|
||||
else:
|
||||
_do_publish(client)
|
||||
|
||||
|
||||
def multiple(
|
||||
msgs: MessagesList,
|
||||
hostname: str = "localhost",
|
||||
port: int = 1883,
|
||||
client_id: str = "",
|
||||
keepalive: int = 60,
|
||||
will: MessageDict | None = None,
|
||||
auth: AuthParameter | None = None,
|
||||
tls: TLSParameter | None = None,
|
||||
protocol: MQTTProtocolVersion = paho.MQTTv311,
|
||||
transport: Literal["tcp", "websockets"] = "tcp",
|
||||
proxy_args: Any | None = None,
|
||||
) -> None:
|
||||
"""Publish multiple messages to a broker, then disconnect cleanly.
|
||||
|
||||
This function creates an MQTT client, connects to a broker and publishes a
|
||||
list of messages. Once the messages have been delivered, it disconnects
|
||||
cleanly from the broker.
|
||||
|
||||
:param msgs: a list of messages to publish. Each message is either a dict or a
|
||||
tuple.
|
||||
|
||||
If a dict, only the topic must be present. Default values will be
|
||||
used for any missing arguments. The dict must be of the form:
|
||||
|
||||
msg = {'topic':"<topic>", 'payload':"<payload>", 'qos':<qos>,
|
||||
'retain':<retain>}
|
||||
topic must be present and may not be empty.
|
||||
If payload is "", None or not present then a zero length payload
|
||||
will be published.
|
||||
If qos is not present, the default of 0 is used.
|
||||
If retain is not present, the default of False is used.
|
||||
|
||||
If a tuple, then it must be of the form:
|
||||
("<topic>", "<payload>", qos, retain)
|
||||
|
||||
:param str hostname: the address of the broker to connect to.
|
||||
Defaults to localhost.
|
||||
|
||||
:param int port: the port to connect to the broker on. Defaults to 1883.
|
||||
|
||||
:param str client_id: the MQTT client id to use. If "" or None, the Paho library will
|
||||
generate a client id automatically.
|
||||
|
||||
:param int keepalive: the keepalive timeout value for the client. Defaults to 60
|
||||
seconds.
|
||||
|
||||
:param will: a dict containing will parameters for the client: will = {'topic':
|
||||
"<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
|
||||
Topic is required, all other parameters are optional and will
|
||||
default to None, 0 and False respectively.
|
||||
Defaults to None, which indicates no will should be used.
|
||||
|
||||
:param auth: a dict containing authentication parameters for the client:
|
||||
auth = {'username':"<username>", 'password':"<password>"}
|
||||
Username is required, password is optional and will default to None
|
||||
if not provided.
|
||||
Defaults to None, which indicates no authentication is to be used.
|
||||
|
||||
:param tls: a dict containing TLS configuration parameters for the client:
|
||||
dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
|
||||
'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
|
||||
'ciphers':"<ciphers">, 'insecure':"<bool>"}
|
||||
ca_certs is required, all other parameters are optional and will
|
||||
default to None if not provided, which results in the client using
|
||||
the default behaviour - see the paho.mqtt.client documentation.
|
||||
Alternatively, tls input can be an SSLContext object, which will be
|
||||
processed using the tls_set_context method.
|
||||
Defaults to None, which indicates that TLS should not be used.
|
||||
|
||||
:param str transport: set to "tcp" to use the default setting of transport which is
|
||||
raw TCP. Set to "websockets" to use WebSockets as the transport.
|
||||
|
||||
:param proxy_args: a dictionary that will be given to the client.
|
||||
"""
|
||||
|
||||
if not isinstance(msgs, Iterable):
|
||||
raise TypeError('msgs must be an iterable')
|
||||
if len(msgs) == 0:
|
||||
raise ValueError('msgs is empty')
|
||||
|
||||
client = paho.Client(
|
||||
CallbackAPIVersion.VERSION2,
|
||||
client_id=client_id,
|
||||
userdata=collections.deque(msgs),
|
||||
protocol=protocol,
|
||||
transport=transport,
|
||||
)
|
||||
|
||||
client.enable_logger()
|
||||
client.on_publish = _on_publish
|
||||
client.on_connect = _on_connect # type: ignore
|
||||
|
||||
if proxy_args is not None:
|
||||
client.proxy_set(**proxy_args)
|
||||
|
||||
if auth:
|
||||
username = auth.get('username')
|
||||
if username:
|
||||
password = auth.get('password')
|
||||
client.username_pw_set(username, password)
|
||||
else:
|
||||
raise KeyError("The 'username' key was not found, this is "
|
||||
"required for auth")
|
||||
|
||||
if will is not None:
|
||||
client.will_set(**will)
|
||||
|
||||
if tls is not None:
|
||||
if isinstance(tls, dict):
|
||||
insecure = tls.pop('insecure', False)
|
||||
# mypy don't get that tls no longer contains the key insecure
|
||||
client.tls_set(**tls) # type: ignore[misc]
|
||||
if insecure:
|
||||
# Must be set *after* the `client.tls_set()` call since it sets
|
||||
# up the SSL context that `client.tls_insecure_set` alters.
|
||||
client.tls_insecure_set(insecure)
|
||||
else:
|
||||
# Assume input is SSLContext object
|
||||
client.tls_set_context(tls)
|
||||
|
||||
client.connect(hostname, port, keepalive)
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
def single(
|
||||
topic: str,
|
||||
payload: paho.PayloadType = None,
|
||||
qos: int = 0,
|
||||
retain: bool = False,
|
||||
hostname: str = "localhost",
|
||||
port: int = 1883,
|
||||
client_id: str = "",
|
||||
keepalive: int = 60,
|
||||
will: MessageDict | None = None,
|
||||
auth: AuthParameter | None = None,
|
||||
tls: TLSParameter | None = None,
|
||||
protocol: MQTTProtocolVersion = paho.MQTTv311,
|
||||
transport: Literal["tcp", "websockets"] = "tcp",
|
||||
proxy_args: Any | None = None,
|
||||
) -> None:
|
||||
"""Publish a single message to a broker, then disconnect cleanly.
|
||||
|
||||
This function creates an MQTT client, connects to a broker and publishes a
|
||||
single message. Once the message has been delivered, it disconnects cleanly
|
||||
from the broker.
|
||||
|
||||
:param str topic: the only required argument must be the topic string to which the
|
||||
payload will be published.
|
||||
|
||||
:param payload: the payload to be published. If "" or None, a zero length payload
|
||||
will be published.
|
||||
|
||||
:param int qos: the qos to use when publishing, default to 0.
|
||||
|
||||
:param bool retain: set the message to be retained (True) or not (False).
|
||||
|
||||
:param str hostname: the address of the broker to connect to.
|
||||
Defaults to localhost.
|
||||
|
||||
:param int port: the port to connect to the broker on. Defaults to 1883.
|
||||
|
||||
:param str client_id: the MQTT client id to use. If "" or None, the Paho library will
|
||||
generate a client id automatically.
|
||||
|
||||
:param int keepalive: the keepalive timeout value for the client. Defaults to 60
|
||||
seconds.
|
||||
|
||||
:param will: a dict containing will parameters for the client: will = {'topic':
|
||||
"<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
|
||||
Topic is required, all other parameters are optional and will
|
||||
default to None, 0 and False respectively.
|
||||
Defaults to None, which indicates no will should be used.
|
||||
|
||||
:param auth: a dict containing authentication parameters for the client:
|
||||
Username is required, password is optional and will default to None
|
||||
auth = {'username':"<username>", 'password':"<password>"}
|
||||
if not provided.
|
||||
Defaults to None, which indicates no authentication is to be used.
|
||||
|
||||
:param tls: a dict containing TLS configuration parameters for the client:
|
||||
dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
|
||||
'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
|
||||
'ciphers':"<ciphers">, 'insecure':"<bool>"}
|
||||
ca_certs is required, all other parameters are optional and will
|
||||
default to None if not provided, which results in the client using
|
||||
the default behaviour - see the paho.mqtt.client documentation.
|
||||
Defaults to None, which indicates that TLS should not be used.
|
||||
Alternatively, tls input can be an SSLContext object, which will be
|
||||
processed using the tls_set_context method.
|
||||
|
||||
:param transport: set to "tcp" to use the default setting of transport which is
|
||||
raw TCP. Set to "websockets" to use WebSockets as the transport.
|
||||
|
||||
:param proxy_args: a dictionary that will be given to the client.
|
||||
"""
|
||||
|
||||
msg: MessageDict = {'topic':topic, 'payload':payload, 'qos':qos, 'retain':retain}
|
||||
|
||||
multiple([msg], hostname, port, client_id, keepalive, will, auth, tls,
|
||||
protocol, transport, proxy_args)
|
0
sbapp/pmqtt/py.typed
Normal file
0
sbapp/pmqtt/py.typed
Normal file
223
sbapp/pmqtt/reasoncodes.py
Normal file
223
sbapp/pmqtt/reasoncodes.py
Normal file
@ -0,0 +1,223 @@
|
||||
# *******************************************************************
|
||||
# Copyright (c) 2017, 2019 IBM Corp.
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
# http://www.eclipse.org/legal/epl-v20.html
|
||||
# and the Eclipse Distribution License is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# Contributors:
|
||||
# Ian Craggs - initial implementation and/or documentation
|
||||
# *******************************************************************
|
||||
|
||||
import functools
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
from .packettypes import PacketTypes
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class ReasonCode:
|
||||
"""MQTT version 5.0 reason codes class.
|
||||
|
||||
See ReasonCode.names for a list of possible numeric values along with their
|
||||
names and the packets to which they apply.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, packetType: int, aName: str ="Success", identifier: int =-1):
|
||||
"""
|
||||
packetType: the type of the packet, such as PacketTypes.CONNECT that
|
||||
this reason code will be used with. Some reason codes have different
|
||||
names for the same identifier when used a different packet type.
|
||||
|
||||
aName: the String name of the reason code to be created. Ignored
|
||||
if the identifier is set.
|
||||
|
||||
identifier: an integer value of the reason code to be created.
|
||||
|
||||
"""
|
||||
|
||||
self.packetType = packetType
|
||||
self.names = {
|
||||
0: {"Success": [PacketTypes.CONNACK, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.PUBREL, PacketTypes.PUBCOMP,
|
||||
PacketTypes.UNSUBACK, PacketTypes.AUTH],
|
||||
"Normal disconnection": [PacketTypes.DISCONNECT],
|
||||
"Granted QoS 0": [PacketTypes.SUBACK]},
|
||||
1: {"Granted QoS 1": [PacketTypes.SUBACK]},
|
||||
2: {"Granted QoS 2": [PacketTypes.SUBACK]},
|
||||
4: {"Disconnect with will message": [PacketTypes.DISCONNECT]},
|
||||
16: {"No matching subscribers":
|
||||
[PacketTypes.PUBACK, PacketTypes.PUBREC]},
|
||||
17: {"No subscription found": [PacketTypes.UNSUBACK]},
|
||||
24: {"Continue authentication": [PacketTypes.AUTH]},
|
||||
25: {"Re-authenticate": [PacketTypes.AUTH]},
|
||||
128: {"Unspecified error": [PacketTypes.CONNACK, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK,
|
||||
PacketTypes.DISCONNECT], },
|
||||
129: {"Malformed packet":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
130: {"Protocol error":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
131: {"Implementation specific error": [PacketTypes.CONNACK,
|
||||
PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.SUBACK,
|
||||
PacketTypes.UNSUBACK, PacketTypes.DISCONNECT], },
|
||||
132: {"Unsupported protocol version": [PacketTypes.CONNACK]},
|
||||
133: {"Client identifier not valid": [PacketTypes.CONNACK]},
|
||||
134: {"Bad user name or password": [PacketTypes.CONNACK]},
|
||||
135: {"Not authorized": [PacketTypes.CONNACK, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.UNSUBACK,
|
||||
PacketTypes.DISCONNECT], },
|
||||
136: {"Server unavailable": [PacketTypes.CONNACK]},
|
||||
137: {"Server busy": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
138: {"Banned": [PacketTypes.CONNACK]},
|
||||
139: {"Server shutting down": [PacketTypes.DISCONNECT]},
|
||||
140: {"Bad authentication method":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
141: {"Keep alive timeout": [PacketTypes.DISCONNECT]},
|
||||
142: {"Session taken over": [PacketTypes.DISCONNECT]},
|
||||
143: {"Topic filter invalid":
|
||||
[PacketTypes.SUBACK, PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]},
|
||||
144: {"Topic name invalid":
|
||||
[PacketTypes.CONNACK, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.DISCONNECT]},
|
||||
145: {"Packet identifier in use":
|
||||
[PacketTypes.PUBACK, PacketTypes.PUBREC,
|
||||
PacketTypes.SUBACK, PacketTypes.UNSUBACK]},
|
||||
146: {"Packet identifier not found":
|
||||
[PacketTypes.PUBREL, PacketTypes.PUBCOMP]},
|
||||
147: {"Receive maximum exceeded": [PacketTypes.DISCONNECT]},
|
||||
148: {"Topic alias invalid": [PacketTypes.DISCONNECT]},
|
||||
149: {"Packet too large": [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
150: {"Message rate too high": [PacketTypes.DISCONNECT]},
|
||||
151: {"Quota exceeded": [PacketTypes.CONNACK, PacketTypes.PUBACK,
|
||||
PacketTypes.PUBREC, PacketTypes.SUBACK, PacketTypes.DISCONNECT], },
|
||||
152: {"Administrative action": [PacketTypes.DISCONNECT]},
|
||||
153: {"Payload format invalid":
|
||||
[PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.DISCONNECT]},
|
||||
154: {"Retain not supported":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
155: {"QoS not supported":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
156: {"Use another server":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
157: {"Server moved":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
158: {"Shared subscription not supported":
|
||||
[PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
|
||||
159: {"Connection rate exceeded":
|
||||
[PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
|
||||
160: {"Maximum connect time":
|
||||
[PacketTypes.DISCONNECT]},
|
||||
161: {"Subscription identifiers not supported":
|
||||
[PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
|
||||
162: {"Wildcard subscription not supported":
|
||||
[PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
|
||||
}
|
||||
if identifier == -1:
|
||||
if packetType == PacketTypes.DISCONNECT and aName == "Success":
|
||||
aName = "Normal disconnection"
|
||||
self.set(aName)
|
||||
else:
|
||||
self.value = identifier
|
||||
self.getName() # check it's good
|
||||
|
||||
def __getName__(self, packetType, identifier):
|
||||
"""
|
||||
Get the reason code string name for a specific identifier.
|
||||
The name can vary by packet type for the same identifier, which
|
||||
is why the packet type is also required.
|
||||
|
||||
Used when displaying the reason code.
|
||||
"""
|
||||
if identifier not in self.names:
|
||||
raise KeyError(identifier)
|
||||
names = self.names[identifier]
|
||||
namelist = [name for name in names.keys() if packetType in names[name]]
|
||||
if len(namelist) != 1:
|
||||
raise ValueError(f"Expected exactly one name, found {namelist!r}")
|
||||
return namelist[0]
|
||||
|
||||
def getId(self, name):
|
||||
"""
|
||||
Get the numeric id corresponding to a reason code name.
|
||||
|
||||
Used when setting the reason code for a packetType
|
||||
check that only valid codes for the packet are set.
|
||||
"""
|
||||
for code in self.names.keys():
|
||||
if name in self.names[code].keys():
|
||||
if self.packetType in self.names[code][name]:
|
||||
return code
|
||||
raise KeyError(f"Reason code name not found: {name}")
|
||||
|
||||
def set(self, name):
|
||||
self.value = self.getId(name)
|
||||
|
||||
def unpack(self, buffer):
|
||||
c = buffer[0]
|
||||
name = self.__getName__(self.packetType, c)
|
||||
self.value = self.getId(name)
|
||||
return 1
|
||||
|
||||
def getName(self):
|
||||
"""Returns the reason code name corresponding to the numeric value which is set.
|
||||
"""
|
||||
return self.__getName__(self.packetType, self.value)
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, int):
|
||||
return self.value == other
|
||||
if isinstance(other, str):
|
||||
return other == str(self)
|
||||
if isinstance(other, ReasonCode):
|
||||
return self.value == other.value
|
||||
return False
|
||||
|
||||
def __lt__(self, other):
|
||||
if isinstance(other, int):
|
||||
return self.value < other
|
||||
if isinstance(other, ReasonCode):
|
||||
return self.value < other.value
|
||||
return NotImplemented
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
packet_name = PacketTypes.Names[self.packetType]
|
||||
except IndexError:
|
||||
packet_name = "Unknown"
|
||||
|
||||
return f"ReasonCode({packet_name}, {self.getName()!r})"
|
||||
|
||||
def __str__(self):
|
||||
return self.getName()
|
||||
|
||||
def json(self):
|
||||
return self.getName()
|
||||
|
||||
def pack(self):
|
||||
return bytearray([self.value])
|
||||
|
||||
@property
|
||||
def is_failure(self) -> bool:
|
||||
return self.value >= 0x80
|
||||
|
||||
|
||||
class _CompatibilityIsInstance(type):
|
||||
def __instancecheck__(self, other: Any) -> bool:
|
||||
return isinstance(other, ReasonCode)
|
||||
|
||||
|
||||
class ReasonCodes(ReasonCode, metaclass=_CompatibilityIsInstance):
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("ReasonCodes is deprecated, use ReasonCode (singular) instead",
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
super().__init__(*args, **kwargs)
|
281
sbapp/pmqtt/subscribe.py
Normal file
281
sbapp/pmqtt/subscribe.py
Normal file
@ -0,0 +1,281 @@
|
||||
# Copyright (c) 2016 Roger Light <roger@atchoo.org>
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
# http://www.eclipse.org/legal/epl-v20.html
|
||||
# and the Eclipse Distribution License is available at
|
||||
# http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
#
|
||||
# Contributors:
|
||||
# Roger Light - initial API and implementation
|
||||
|
||||
"""
|
||||
This module provides some helper functions to allow straightforward subscribing
|
||||
to topics and retrieving messages. The two functions are simple(), which
|
||||
returns one or messages matching a set of topics, and callback() which allows
|
||||
you to pass a callback for processing of messages.
|
||||
"""
|
||||
|
||||
from .. import mqtt
|
||||
from . import client as paho
|
||||
|
||||
|
||||
def _on_connect(client, userdata, flags, reason_code, properties):
|
||||
"""Internal callback"""
|
||||
if reason_code != 0:
|
||||
raise mqtt.MQTTException(paho.connack_string(reason_code))
|
||||
|
||||
if isinstance(userdata['topics'], list):
|
||||
for topic in userdata['topics']:
|
||||
client.subscribe(topic, userdata['qos'])
|
||||
else:
|
||||
client.subscribe(userdata['topics'], userdata['qos'])
|
||||
|
||||
|
||||
def _on_message_callback(client, userdata, message):
|
||||
"""Internal callback"""
|
||||
userdata['callback'](client, userdata['userdata'], message)
|
||||
|
||||
|
||||
def _on_message_simple(client, userdata, message):
|
||||
"""Internal callback"""
|
||||
|
||||
if userdata['msg_count'] == 0:
|
||||
return
|
||||
|
||||
# Don't process stale retained messages if 'retained' was false
|
||||
if message.retain and not userdata['retained']:
|
||||
return
|
||||
|
||||
userdata['msg_count'] = userdata['msg_count'] - 1
|
||||
|
||||
if userdata['messages'] is None and userdata['msg_count'] == 0:
|
||||
userdata['messages'] = message
|
||||
client.disconnect()
|
||||
return
|
||||
|
||||
userdata['messages'].append(message)
|
||||
if userdata['msg_count'] == 0:
|
||||
client.disconnect()
|
||||
|
||||
|
||||
def callback(callback, topics, qos=0, userdata=None, hostname="localhost",
|
||||
port=1883, client_id="", keepalive=60, will=None, auth=None,
|
||||
tls=None, protocol=paho.MQTTv311, transport="tcp",
|
||||
clean_session=True, proxy_args=None):
|
||||
"""Subscribe to a list of topics and process them in a callback function.
|
||||
|
||||
This function creates an MQTT client, connects to a broker and subscribes
|
||||
to a list of topics. Incoming messages are processed by the user provided
|
||||
callback. This is a blocking function and will never return.
|
||||
|
||||
:param callback: function with the same signature as `on_message` for
|
||||
processing the messages received.
|
||||
|
||||
:param topics: either a string containing a single topic to subscribe to, or a
|
||||
list of topics to subscribe to.
|
||||
|
||||
:param int qos: the qos to use when subscribing. This is applied to all topics.
|
||||
|
||||
:param userdata: passed to the callback
|
||||
|
||||
:param str hostname: the address of the broker to connect to.
|
||||
Defaults to localhost.
|
||||
|
||||
:param int port: the port to connect to the broker on. Defaults to 1883.
|
||||
|
||||
:param str client_id: the MQTT client id to use. If "" or None, the Paho library will
|
||||
generate a client id automatically.
|
||||
|
||||
:param int keepalive: the keepalive timeout value for the client. Defaults to 60
|
||||
seconds.
|
||||
|
||||
:param will: a dict containing will parameters for the client: will = {'topic':
|
||||
"<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
|
||||
Topic is required, all other parameters are optional and will
|
||||
default to None, 0 and False respectively.
|
||||
|
||||
Defaults to None, which indicates no will should be used.
|
||||
|
||||
:param auth: a dict containing authentication parameters for the client:
|
||||
auth = {'username':"<username>", 'password':"<password>"}
|
||||
Username is required, password is optional and will default to None
|
||||
if not provided.
|
||||
Defaults to None, which indicates no authentication is to be used.
|
||||
|
||||
:param tls: a dict containing TLS configuration parameters for the client:
|
||||
dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
|
||||
'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
|
||||
'ciphers':"<ciphers">, 'insecure':"<bool>"}
|
||||
ca_certs is required, all other parameters are optional and will
|
||||
default to None if not provided, which results in the client using
|
||||
the default behaviour - see the paho.mqtt.client documentation.
|
||||
Alternatively, tls input can be an SSLContext object, which will be
|
||||
processed using the tls_set_context method.
|
||||
Defaults to None, which indicates that TLS should not be used.
|
||||
|
||||
:param str transport: set to "tcp" to use the default setting of transport which is
|
||||
raw TCP. Set to "websockets" to use WebSockets as the transport.
|
||||
|
||||
:param clean_session: a boolean that determines the client type. If True,
|
||||
the broker will remove all information about this client
|
||||
when it disconnects. If False, the client is a persistent
|
||||
client and subscription information and queued messages
|
||||
will be retained when the client disconnects.
|
||||
Defaults to True.
|
||||
|
||||
:param proxy_args: a dictionary that will be given to the client.
|
||||
"""
|
||||
|
||||
if qos < 0 or qos > 2:
|
||||
raise ValueError('qos must be in the range 0-2')
|
||||
|
||||
callback_userdata = {
|
||||
'callback':callback,
|
||||
'topics':topics,
|
||||
'qos':qos,
|
||||
'userdata':userdata}
|
||||
|
||||
client = paho.Client(
|
||||
paho.CallbackAPIVersion.VERSION2,
|
||||
client_id=client_id,
|
||||
userdata=callback_userdata,
|
||||
protocol=protocol,
|
||||
transport=transport,
|
||||
clean_session=clean_session,
|
||||
)
|
||||
client.enable_logger()
|
||||
|
||||
client.on_message = _on_message_callback
|
||||
client.on_connect = _on_connect
|
||||
|
||||
if proxy_args is not None:
|
||||
client.proxy_set(**proxy_args)
|
||||
|
||||
if auth:
|
||||
username = auth.get('username')
|
||||
if username:
|
||||
password = auth.get('password')
|
||||
client.username_pw_set(username, password)
|
||||
else:
|
||||
raise KeyError("The 'username' key was not found, this is "
|
||||
"required for auth")
|
||||
|
||||
if will is not None:
|
||||
client.will_set(**will)
|
||||
|
||||
if tls is not None:
|
||||
if isinstance(tls, dict):
|
||||
insecure = tls.pop('insecure', False)
|
||||
client.tls_set(**tls)
|
||||
if insecure:
|
||||
# Must be set *after* the `client.tls_set()` call since it sets
|
||||
# up the SSL context that `client.tls_insecure_set` alters.
|
||||
client.tls_insecure_set(insecure)
|
||||
else:
|
||||
# Assume input is SSLContext object
|
||||
client.tls_set_context(tls)
|
||||
|
||||
client.connect(hostname, port, keepalive)
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
def simple(topics, qos=0, msg_count=1, retained=True, hostname="localhost",
|
||||
port=1883, client_id="", keepalive=60, will=None, auth=None,
|
||||
tls=None, protocol=paho.MQTTv311, transport="tcp",
|
||||
clean_session=True, proxy_args=None):
|
||||
"""Subscribe to a list of topics and return msg_count messages.
|
||||
|
||||
This function creates an MQTT client, connects to a broker and subscribes
|
||||
to a list of topics. Once "msg_count" messages have been received, it
|
||||
disconnects cleanly from the broker and returns the messages.
|
||||
|
||||
:param topics: either a string containing a single topic to subscribe to, or a
|
||||
list of topics to subscribe to.
|
||||
|
||||
:param int qos: the qos to use when subscribing. This is applied to all topics.
|
||||
|
||||
:param int msg_count: the number of messages to retrieve from the broker.
|
||||
if msg_count == 1 then a single MQTTMessage will be returned.
|
||||
if msg_count > 1 then a list of MQTTMessages will be returned.
|
||||
|
||||
:param bool retained: If set to True, retained messages will be processed the same as
|
||||
non-retained messages. If set to False, retained messages will
|
||||
be ignored. This means that with retained=False and msg_count=1,
|
||||
the function will return the first message received that does
|
||||
not have the retained flag set.
|
||||
|
||||
:param str hostname: the address of the broker to connect to.
|
||||
Defaults to localhost.
|
||||
|
||||
:param int port: the port to connect to the broker on. Defaults to 1883.
|
||||
|
||||
:param str client_id: the MQTT client id to use. If "" or None, the Paho library will
|
||||
generate a client id automatically.
|
||||
|
||||
:param int keepalive: the keepalive timeout value for the client. Defaults to 60
|
||||
seconds.
|
||||
|
||||
:param will: a dict containing will parameters for the client: will = {'topic':
|
||||
"<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
|
||||
Topic is required, all other parameters are optional and will
|
||||
default to None, 0 and False respectively.
|
||||
Defaults to None, which indicates no will should be used.
|
||||
|
||||
:param auth: a dict containing authentication parameters for the client:
|
||||
auth = {'username':"<username>", 'password':"<password>"}
|
||||
Username is required, password is optional and will default to None
|
||||
if not provided.
|
||||
Defaults to None, which indicates no authentication is to be used.
|
||||
|
||||
:param tls: a dict containing TLS configuration parameters for the client:
|
||||
dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
|
||||
'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
|
||||
'ciphers':"<ciphers">, 'insecure':"<bool>"}
|
||||
ca_certs is required, all other parameters are optional and will
|
||||
default to None if not provided, which results in the client using
|
||||
the default behaviour - see the paho.mqtt.client documentation.
|
||||
Alternatively, tls input can be an SSLContext object, which will be
|
||||
processed using the tls_set_context method.
|
||||
Defaults to None, which indicates that TLS should not be used.
|
||||
|
||||
:param protocol: the MQTT protocol version to use. Defaults to MQTTv311.
|
||||
|
||||
:param transport: set to "tcp" to use the default setting of transport which is
|
||||
raw TCP. Set to "websockets" to use WebSockets as the transport.
|
||||
|
||||
:param clean_session: a boolean that determines the client type. If True,
|
||||
the broker will remove all information about this client
|
||||
when it disconnects. If False, the client is a persistent
|
||||
client and subscription information and queued messages
|
||||
will be retained when the client disconnects.
|
||||
Defaults to True. If protocol is MQTTv50, clean_session
|
||||
is ignored.
|
||||
|
||||
:param proxy_args: a dictionary that will be given to the client.
|
||||
"""
|
||||
|
||||
if msg_count < 1:
|
||||
raise ValueError('msg_count must be > 0')
|
||||
|
||||
# Set ourselves up to return a single message if msg_count == 1, or a list
|
||||
# if > 1.
|
||||
if msg_count == 1:
|
||||
messages = None
|
||||
else:
|
||||
messages = []
|
||||
|
||||
# Ignore clean_session if protocol is MQTTv50, otherwise Client will raise
|
||||
if protocol == paho.MQTTv5:
|
||||
clean_session = None
|
||||
|
||||
userdata = {'retained':retained, 'msg_count':msg_count, 'messages':messages}
|
||||
|
||||
callback(_on_message_simple, topics, qos, userdata, hostname, port,
|
||||
client_id, keepalive, will, auth, tls, protocol, transport,
|
||||
clean_session, proxy_args)
|
||||
|
||||
return userdata['messages']
|
113
sbapp/pmqtt/subscribeoptions.py
Normal file
113
sbapp/pmqtt/subscribeoptions.py
Normal file
@ -0,0 +1,113 @@
|
||||
"""
|
||||
*******************************************************************
|
||||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
http://www.eclipse.org/legal/epl-v20.html
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
Contributors:
|
||||
Ian Craggs - initial implementation and/or documentation
|
||||
*******************************************************************
|
||||
"""
|
||||
|
||||
|
||||
|
||||
class MQTTException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SubscribeOptions:
|
||||
"""The MQTT v5.0 subscribe options class.
|
||||
|
||||
The options are:
|
||||
qos: As in MQTT v3.1.1.
|
||||
noLocal: True or False. If set to True, the subscriber will not receive its own publications.
|
||||
retainAsPublished: True or False. If set to True, the retain flag on received publications will be as set
|
||||
by the publisher.
|
||||
retainHandling: RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB or RETAIN_DO_NOT_SEND
|
||||
Controls when the broker should send retained messages:
|
||||
- RETAIN_SEND_ON_SUBSCRIBE: on any successful subscribe request
|
||||
- RETAIN_SEND_IF_NEW_SUB: only if the subscribe request is new
|
||||
- RETAIN_DO_NOT_SEND: never send retained messages
|
||||
"""
|
||||
|
||||
# retain handling options
|
||||
RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB, RETAIN_DO_NOT_SEND = range(
|
||||
0, 3)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
qos: int = 0,
|
||||
noLocal: bool = False,
|
||||
retainAsPublished: bool = False,
|
||||
retainHandling: int = RETAIN_SEND_ON_SUBSCRIBE,
|
||||
):
|
||||
"""
|
||||
qos: 0, 1 or 2. 0 is the default.
|
||||
noLocal: True or False. False is the default and corresponds to MQTT v3.1.1 behavior.
|
||||
retainAsPublished: True or False. False is the default and corresponds to MQTT v3.1.1 behavior.
|
||||
retainHandling: RETAIN_SEND_ON_SUBSCRIBE, RETAIN_SEND_IF_NEW_SUB or RETAIN_DO_NOT_SEND
|
||||
RETAIN_SEND_ON_SUBSCRIBE is the default and corresponds to MQTT v3.1.1 behavior.
|
||||
"""
|
||||
object.__setattr__(self, "names",
|
||||
["QoS", "noLocal", "retainAsPublished", "retainHandling"])
|
||||
self.QoS = qos # bits 0,1
|
||||
self.noLocal = noLocal # bit 2
|
||||
self.retainAsPublished = retainAsPublished # bit 3
|
||||
self.retainHandling = retainHandling # bits 4 and 5: 0, 1 or 2
|
||||
if self.retainHandling not in (0, 1, 2):
|
||||
raise AssertionError(f"Retain handling should be 0, 1 or 2, not {self.retainHandling}")
|
||||
if self.QoS not in (0, 1, 2):
|
||||
raise AssertionError(f"QoS should be 0, 1 or 2, not {self.QoS}")
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name not in self.names:
|
||||
raise MQTTException(
|
||||
f"{name} Attribute name must be one of {self.names}")
|
||||
object.__setattr__(self, name, value)
|
||||
|
||||
def pack(self):
|
||||
if self.retainHandling not in (0, 1, 2):
|
||||
raise AssertionError(f"Retain handling should be 0, 1 or 2, not {self.retainHandling}")
|
||||
if self.QoS not in (0, 1, 2):
|
||||
raise AssertionError(f"QoS should be 0, 1 or 2, not {self.QoS}")
|
||||
noLocal = 1 if self.noLocal else 0
|
||||
retainAsPublished = 1 if self.retainAsPublished else 0
|
||||
data = [(self.retainHandling << 4) | (retainAsPublished << 3) |
|
||||
(noLocal << 2) | self.QoS]
|
||||
return bytes(data)
|
||||
|
||||
def unpack(self, buffer):
|
||||
b0 = buffer[0]
|
||||
self.retainHandling = ((b0 >> 4) & 0x03)
|
||||
self.retainAsPublished = True if ((b0 >> 3) & 0x01) == 1 else False
|
||||
self.noLocal = True if ((b0 >> 2) & 0x01) == 1 else False
|
||||
self.QoS = (b0 & 0x03)
|
||||
if self.retainHandling not in (0, 1, 2):
|
||||
raise AssertionError(f"Retain handling should be 0, 1 or 2, not {self.retainHandling}")
|
||||
if self.QoS not in (0, 1, 2):
|
||||
raise AssertionError(f"QoS should be 0, 1 or 2, not {self.QoS}")
|
||||
return 1
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
def __str__(self):
|
||||
return "{QoS="+str(self.QoS)+", noLocal="+str(self.noLocal) +\
|
||||
", retainAsPublished="+str(self.retainAsPublished) +\
|
||||
", retainHandling="+str(self.retainHandling)+"}"
|
||||
|
||||
def json(self):
|
||||
data = {
|
||||
"QoS": self.QoS,
|
||||
"noLocal": self.noLocal,
|
||||
"retainAsPublished": self.retainAsPublished,
|
||||
"retainHandling": self.retainHandling,
|
||||
}
|
||||
return data
|
33
sbapp/share/flasher.html
Normal file
33
sbapp/share/flasher.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/water.css">
|
||||
<link rel="shortcut icon" type="image/x-icon" href="gfx/icon.png">
|
||||
<meta charset="utf-8"/>
|
||||
<title>Sideband Repository</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<span class="logo">RNode Flasher</span>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="flasher.html">RNode Flasher</a> | <a href="guides.html">Guides</a></span></center></p><hr>
|
||||
<br/>Sideband includes a copy of the web-based RNode Flasher developed by <a href="https://github.com/liamcottle/rnode-flasher">Liam Cottle</a>. You can use this flasher to install and provision the RNode firmware on any compatible boards.<br/>
|
||||
<br/>
|
||||
<b>Please note!</b> Your browser must support Web-USB for this to work.<br/>
|
||||
<br/>
|
||||
To use the flasher, you will need firmware packages for the boards you want use. You can obtain these in different ways:
|
||||
<ul>
|
||||
<li>Sideband can automatically download the latest release of these, and include them directly in this repository.
|
||||
<ul>
|
||||
<li>To do so, go to the <b>Repository</b> menu item, and select <b>Update Contents</b>.</li>
|
||||
<li>After that, they will be available on the <a href="pkgs.html">Software</a> page of this repository.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>You can download them manually from <a href="https://github.com/markqvist/RNode_Firmware/releases/latest">the latest release page on GitHub</a>.</li>
|
||||
<li>You can compile them yourself from the RNode Firmware source code package <a href="pkgs.html">included in this repository</a>.</li>
|
||||
</ul>
|
||||
<br/>
|
||||
<center><a href="/mirrors/rnode-flasher/index.html"><button type="button" id="task-replicate">Launch Web Flasher</button></a></center>
|
||||
<br/>
|
||||
<hr>
|
||||
<p><center></p>
|
||||
</body></html>
|
@ -9,7 +9,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<span class="logo">Guides</span>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="guides.html">Guides</a></span></center></p><hr>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="flasher.html">RNode Flasher</a> | <a href="guides.html">Guides</a></span></center></p><hr><br/>
|
||||
Welcome to the <b>Guide Section</b>!<br/><br/>From here, you can browse or download various included manuals, documentation, references and guides.
|
||||
|
||||
<ul>
|
||||
@ -19,6 +19,7 @@ Welcome to the <b>Guide Section</b>!<br/><br/>From here, you can browse or downl
|
||||
<li><a href="./mirrors/Reticulum_Manual.epub">Download the Reticulum Manual in EPUB format</a></li>
|
||||
<li><a href="./mirrors/reticulum.network/index.html">Browse a local copy of the Reticulum website</a></li>
|
||||
</ul>
|
||||
<br/>
|
||||
<hr>
|
||||
<p><center></p>
|
||||
</body></html>
|
@ -10,7 +10,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<span class="logo">Sideband Repo</span>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="guides.html">Guides</a></span></center></p><hr><h2>Hello!</h2>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="flasher.html">RNode Flasher</a> | <a href="guides.html">Guides</a></span></center></p><hr><h2>Hello!</h2>
|
||||
<table style="margin-bottom: 1.5em;">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -9,10 +9,10 @@
|
||||
</head>
|
||||
<body>
|
||||
<span class="logo">Software</span>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="guides.html">Guides</a></span></center></p><hr>
|
||||
<p><center><span class="menu"><a href="index.html">Start</a> | <a href="pkgs.html">Software</a> | <a href="flasher.html">RNode Flasher</a> | <a href="guides.html">Guides</a></span></center></p><hr><br/>
|
||||
Welcome to the <b>Software Library</b>!<br/><br/>From here, you can download installable Python Wheel packages of Reticulum and various other auxillary programs and utilities.
|
||||
<ul id="filelist">
|
||||
</ul>
|
||||
</ul><br/>
|
||||
<hr>
|
||||
<p><center></p>
|
||||
</body></html>
|
||||
|
106
sbapp/sideband/certgen.py
Normal file
106
sbapp/sideband/certgen.py
Normal file
@ -0,0 +1,106 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2024 Mark Qvist / unsigned.io.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
KEY_PASSPHRASE = None
|
||||
LOADED_KEY = None
|
||||
|
||||
import os
|
||||
import RNS
|
||||
import datetime
|
||||
from cryptography import x509
|
||||
from cryptography.x509.oid import NameOID
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||
|
||||
from cryptography import __version__ as cryptography_version_str
|
||||
try:
|
||||
cryptography_major_version = int(cryptography_version_str.split(".")[0])
|
||||
except:
|
||||
RNS.log(f"Could not determine PyCA/cryptography version: {e}", RNS.LOG_ERROR)
|
||||
RNS.log(f"Assuming recent version with automatic backend selection", RNS.LOG_ERROR)
|
||||
|
||||
def get_key(key_path, force_reload=False):
|
||||
KEY_PATH = key_path
|
||||
key = None
|
||||
if LOADED_KEY != None and not force_reload:
|
||||
return LOADED_KEY
|
||||
elif os.path.isfile(KEY_PATH):
|
||||
with open(KEY_PATH, "rb") as f:
|
||||
if cryptography_major_version > 3:
|
||||
key = load_pem_private_key(f.read(), KEY_PASSPHRASE)
|
||||
else:
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
key = load_pem_private_key(f.read(), KEY_PASSPHRASE, backend=default_backend())
|
||||
else:
|
||||
if cryptography_major_version > 3:
|
||||
key = ec.generate_private_key(curve=ec.SECP256R1())
|
||||
else:
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
key = ec.generate_private_key(curve=ec.SECP256R1(), backend=default_backend())
|
||||
|
||||
if KEY_PASSPHRASE == None:
|
||||
key_encryption = serialization.NoEncryption()
|
||||
else:
|
||||
key_encryption = serialization.BestAvailableEncryption(KEY_PASSPHRASE)
|
||||
|
||||
with open(KEY_PATH, "wb") as f:
|
||||
f.write(key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.PKCS8,
|
||||
encryption_algorithm=key_encryption))
|
||||
|
||||
return key
|
||||
|
||||
def gen_cert(cert_path, key):
|
||||
CERT_PATH = cert_path
|
||||
cert_attrs = [x509.NameAttribute(NameOID.COUNTRY_NAME, "NA"),
|
||||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "None"),
|
||||
x509.NameAttribute(NameOID.LOCALITY_NAME, "Earth"),
|
||||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Sideband"),
|
||||
x509.NameAttribute(NameOID.COMMON_NAME, "Sideband Repository")]
|
||||
|
||||
issuer = x509.Name(cert_attrs)
|
||||
subject = issuer
|
||||
|
||||
cb = x509.CertificateBuilder()
|
||||
cb = cb.subject_name(subject)
|
||||
cb = cb.issuer_name(issuer)
|
||||
cb = cb.public_key(key.public_key())
|
||||
cb = cb.serial_number(x509.random_serial_number())
|
||||
cb = cb.not_valid_before(datetime.datetime.now(datetime.timezone.utc)+datetime.timedelta(days=-14))
|
||||
cb = cb.not_valid_after(datetime.datetime.now(datetime.timezone.utc)+datetime.timedelta(days=3652))
|
||||
cb = cb.add_extension(x509.SubjectAlternativeName([x509.DNSName("localhost")]), critical=False)
|
||||
|
||||
if cryptography_major_version > 3:
|
||||
cert = cb.sign(key, hashes.SHA256())
|
||||
else:
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
cert = cb.sign(key, hashes.SHA256(), backend=default_backend())
|
||||
|
||||
with open(CERT_PATH, "wb") as f:
|
||||
f.write(cert.public_bytes(serialization.Encoding.PEM))
|
||||
|
||||
def ensure_certificate(key_path, cert_path):
|
||||
gen_cert(cert_path, get_key(key_path))
|
||||
return cert_path
|
File diff suppressed because it is too large
Load Diff
132
sbapp/sideband/mqtt.py
Normal file
132
sbapp/sideband/mqtt.py
Normal file
@ -0,0 +1,132 @@
|
||||
import RNS
|
||||
import time
|
||||
import threading
|
||||
from collections import deque
|
||||
from .sense import Telemeter, Commands
|
||||
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
import pmqtt.client as mqtt
|
||||
else:
|
||||
from sbapp.pmqtt import client as mqtt
|
||||
|
||||
class MQTT():
|
||||
QUEUE_MAXLEN = 65536
|
||||
SCHEDULER_SLEEP = 1
|
||||
|
||||
def __init__(self):
|
||||
self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||
self.host = None
|
||||
self.port = None
|
||||
self.run = False
|
||||
self.is_connected = False
|
||||
self.queue_lock = threading.Lock()
|
||||
self.waiting_msgs = deque(maxlen=MQTT.QUEUE_MAXLEN)
|
||||
self.waiting_telemetry = set()
|
||||
self.client.on_connect_fail = self.connect_failed
|
||||
self.client.on_disconnect = self.disconnected
|
||||
self.start()
|
||||
|
||||
def start(self):
|
||||
self.run = True
|
||||
threading.Thread(target=self.jobs, daemon=True).start()
|
||||
RNS.log("Started MQTT scheduler", RNS.LOG_DEBUG)
|
||||
|
||||
def stop(self):
|
||||
RNS.log("Stopping MQTT scheduler", RNS.LOG_DEBUG)
|
||||
self.run = False
|
||||
|
||||
def jobs(self):
|
||||
while self.run:
|
||||
try:
|
||||
if len(self.waiting_msgs) > 0:
|
||||
RNS.log(f"Processing {len(self.waiting_msgs)} MQTT messages", RNS.LOG_DEBUG)
|
||||
if self.process_queue():
|
||||
RNS.log("All MQTT messages processed", RNS.LOG_DEBUG)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"An error occurred while running MQTT scheduler jobs: {e}", RNS.LOG_ERROR)
|
||||
RNS.trace_exception(e)
|
||||
|
||||
time.sleep(MQTT.SCHEDULER_SLEEP)
|
||||
|
||||
try: self.disconnect()
|
||||
except Exception as e: RNS.log(f"An error occurred while disconnecting MQTT server: {e}", RNS.LOG_ERROR)
|
||||
|
||||
RNS.log("Stopped MQTT scheduler", RNS.LOG_DEBUG)
|
||||
|
||||
def connect_failed(self, client, userdata):
|
||||
RNS.log(f"Connection to MQTT server failed", RNS.LOG_DEBUG)
|
||||
self.is_connected = False
|
||||
|
||||
def disconnected(self, client, userdata, disconnect_flags, reason_code, properties):
|
||||
RNS.log(f"Disconnected from MQTT server, reason code: {reason_code}", RNS.LOG_EXTREME)
|
||||
self.is_connected = False
|
||||
|
||||
def set_server(self, host, port):
|
||||
try:
|
||||
port = int(port)
|
||||
except:
|
||||
port = None
|
||||
|
||||
self.host = host
|
||||
self.port = port or 1883
|
||||
|
||||
def set_auth(self, username, password):
|
||||
self.client.username_pw_set(username, password)
|
||||
|
||||
def connect(self):
|
||||
RNS.log(f"Connecting MQTT server {self.host}:{self.port}", RNS.LOG_DEBUG) # TODO: Remove debug
|
||||
cs = self.client.connect(self.host, self.port)
|
||||
self.client.loop_start()
|
||||
|
||||
def disconnect(self):
|
||||
RNS.log("Disconnecting from MQTT server", RNS.LOG_EXTREME) # TODO: Remove debug
|
||||
self.client.disconnect()
|
||||
self.client.loop_stop()
|
||||
self.is_connected = False
|
||||
|
||||
def post_message(self, topic, data):
|
||||
mqtt_msg = self.client.publish(topic, data, qos=1)
|
||||
self.waiting_telemetry.add(mqtt_msg)
|
||||
|
||||
def process_queue(self):
|
||||
with self.queue_lock:
|
||||
try:
|
||||
self.connect()
|
||||
except Exception as e:
|
||||
RNS.log(f"An error occurred while connecting to MQTT server: {e}", RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
try:
|
||||
while len(self.waiting_msgs) > 0:
|
||||
topic, data = self.waiting_msgs.pop()
|
||||
self.post_message(topic, data)
|
||||
except Exception as e:
|
||||
RNS.log(f"An error occurred while publishing MQTT messages: {e}", RNS.LOG_ERROR)
|
||||
RNS.trace_exception(e)
|
||||
|
||||
try:
|
||||
for msg in self.waiting_telemetry:
|
||||
msg.wait_for_publish()
|
||||
self.waiting_telemetry.clear()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"An error occurred while publishing MQTT messages: {e}", RNS.LOG_ERROR)
|
||||
RNS.trace_exception(e)
|
||||
|
||||
self.disconnect()
|
||||
return True
|
||||
|
||||
def handle(self, context_dest, telemetry):
|
||||
remote_telemeter = Telemeter.from_packed(telemetry)
|
||||
read_telemetry = remote_telemeter.read_all()
|
||||
telemetry_timestamp = read_telemetry["time"]["utc"]
|
||||
root_path = f"lxmf/telemetry/{RNS.hexrep(context_dest, delimit=False)}"
|
||||
for sensor in remote_telemeter.sensors:
|
||||
s = remote_telemeter.sensors[sensor]
|
||||
topics = s.render_mqtt()
|
||||
if topics != None:
|
||||
for topic in topics:
|
||||
topic_path = f"{root_path}/{topic}"
|
||||
data = topics[topic]
|
||||
self.waiting_msgs.append((topic_path, data))
|
File diff suppressed because it is too large
Load Diff
171
sbapp/sideband/voice.py
Normal file
171
sbapp/sideband/voice.py
Normal file
@ -0,0 +1,171 @@
|
||||
import RNS
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from LXST._version import __version__
|
||||
from LXST.Primitives.Telephony import Telephone
|
||||
from RNS.vendor.configobj import ConfigObj
|
||||
|
||||
class ReticulumTelephone():
|
||||
STATE_AVAILABLE = 0x00
|
||||
STATE_CONNECTING = 0x01
|
||||
STATE_RINGING = 0x02
|
||||
STATE_IN_CALL = 0x03
|
||||
|
||||
HW_SLEEP_TIMEOUT = 15
|
||||
HW_STATE_IDLE = 0x00
|
||||
HW_STATE_DIAL = 0x01
|
||||
HW_STATE_SLEEP = 0xFF
|
||||
|
||||
RING_TIME = 30
|
||||
WAIT_TIME = 60
|
||||
PATH_TIME = 10
|
||||
|
||||
def __init__(self, identity, owner = None, service = False, speaker=None, microphone=None, ringer=None):
|
||||
self.identity = identity
|
||||
self.service = service
|
||||
self.owner = owner
|
||||
self.config = None
|
||||
self.should_run = False
|
||||
self.telephone = None
|
||||
self.state = self.STATE_AVAILABLE
|
||||
self.hw_state = self.HW_STATE_IDLE
|
||||
self.hw_last_event = time.time()
|
||||
self.hw_input = ""
|
||||
self.direction = None
|
||||
self.last_input = None
|
||||
self.first_run = False
|
||||
self.ringtone_path = None
|
||||
self.speaker_device = speaker
|
||||
self.microphone_device = microphone
|
||||
self.ringer_device = ringer
|
||||
self.phonebook = {}
|
||||
self.aliases = {}
|
||||
self.names = {}
|
||||
|
||||
self.telephone = Telephone(self.identity, ring_time=self.RING_TIME, wait_time=self.WAIT_TIME)
|
||||
self.telephone.set_ringing_callback(self.ringing)
|
||||
self.telephone.set_established_callback(self.call_established)
|
||||
self.telephone.set_ended_callback(self.call_ended)
|
||||
self.telephone.set_speaker(self.speaker_device)
|
||||
self.telephone.set_microphone(self.microphone_device)
|
||||
self.telephone.set_ringer(self.ringer_device)
|
||||
self.telephone.set_allowed(self.__is_allowed)
|
||||
RNS.log(f"{self} initialised", RNS.LOG_DEBUG)
|
||||
|
||||
def set_ringtone(self, ringtone_path):
|
||||
if os.path.isfile(ringtone_path):
|
||||
self.ringtone_path = ringtone_path
|
||||
self.telephone.set_ringtone(self.ringtone_path)
|
||||
|
||||
def set_speaker(self, device):
|
||||
self.speaker_device = device
|
||||
self.telephone.set_speaker(self.speaker_device)
|
||||
|
||||
def set_microphone(self, device):
|
||||
self.microphone_device = device
|
||||
self.telephone.set_microphone(self.microphone_device)
|
||||
|
||||
def set_ringer(self, device):
|
||||
self.ringer_device = device
|
||||
self.telephone.set_ringer(self.ringer_device)
|
||||
|
||||
def announce(self, attached_interface=None):
|
||||
self.telephone.announce(attached_interface=attached_interface)
|
||||
|
||||
@property
|
||||
def is_available(self):
|
||||
return self.state == self.STATE_AVAILABLE
|
||||
|
||||
@property
|
||||
def is_in_call(self):
|
||||
return self.state == self.STATE_IN_CALL
|
||||
|
||||
@property
|
||||
def is_ringing(self):
|
||||
return self.state == self.STATE_RINGING
|
||||
|
||||
@property
|
||||
def call_is_connecting(self):
|
||||
return self.state == self.STATE_CONNECTING
|
||||
|
||||
@property
|
||||
def hw_is_idle(self):
|
||||
return self.hw_state == self.HW_STATE_IDLE
|
||||
|
||||
@property
|
||||
def hw_is_dialing(self):
|
||||
return self.hw_state == self.HW_STATE_DIAL
|
||||
|
||||
def start(self):
|
||||
if not self.should_run:
|
||||
self.should_run = True
|
||||
self.run()
|
||||
|
||||
def stop(self):
|
||||
self.should_run = False
|
||||
self.telephone.teardown()
|
||||
self.telephone = None
|
||||
|
||||
def hangup(self): self.telephone.hangup()
|
||||
def answer(self): self.telephone.answer(self.caller)
|
||||
def set_busy(self, busy): self.telephone.set_busy(busy)
|
||||
|
||||
def dial(self, identity_hash):
|
||||
self.last_dialled_identity_hash = identity_hash
|
||||
destination_hash = RNS.Destination.hash_from_name_and_identity("lxst.telephony", identity_hash)
|
||||
if RNS.Transport.has_path(destination_hash):
|
||||
call_hops = RNS.Transport.hops_to(destination_hash)
|
||||
cs = "" if call_hops == 1 else "s"
|
||||
RNS.log(f"Connecting call over {call_hops} hop{cs}...", RNS.LOG_DEBUG)
|
||||
identity = RNS.Identity.recall(destination_hash)
|
||||
self.call(identity)
|
||||
else:
|
||||
return "no_path"
|
||||
|
||||
def redial(self, args=None):
|
||||
if self.last_dialled_identity_hash: self.dial(self.last_dialled_identity_hash)
|
||||
|
||||
def call(self, remote_identity):
|
||||
RNS.log(f"Calling {RNS.prettyhexrep(remote_identity.hash)}...", RNS.LOG_DEBUG)
|
||||
self.state = self.STATE_CONNECTING
|
||||
self.caller = remote_identity
|
||||
self.direction = "to"
|
||||
self.telephone.call(self.caller)
|
||||
|
||||
def ringing(self, remote_identity):
|
||||
if self.hw_state == self.HW_STATE_SLEEP: self.hw_state = self.HW_STATE_IDLE
|
||||
self.state = self.STATE_RINGING
|
||||
self.caller = remote_identity
|
||||
self.direction = "from" if self.direction == None else "to"
|
||||
RNS.log(f"Incoming call from {RNS.prettyhexrep(self.caller.hash)}", RNS.LOG_DEBUG)
|
||||
if self.owner:
|
||||
self.owner.incoming_call(remote_identity)
|
||||
|
||||
def call_ended(self, remote_identity):
|
||||
if self.is_in_call or self.is_ringing or self.call_is_connecting:
|
||||
if self.is_in_call: RNS.log(f"Call with {RNS.prettyhexrep(self.caller.hash)} ended\n", RNS.LOG_DEBUG)
|
||||
if self.is_ringing: RNS.log(f"Call {self.direction} {RNS.prettyhexrep(self.caller.hash)} was not answered\n", RNS.LOG_DEBUG)
|
||||
if self.call_is_connecting: RNS.log(f"Call to {RNS.prettyhexrep(self.caller.hash)} could not be connected\n", RNS.LOG_DEBUG)
|
||||
self.direction = None
|
||||
self.state = self.STATE_AVAILABLE
|
||||
|
||||
def call_established(self, remote_identity):
|
||||
if self.call_is_connecting or self.is_ringing:
|
||||
self.state = self.STATE_IN_CALL
|
||||
RNS.log(f"Call established with {RNS.prettyhexrep(self.caller.hash)}", RNS.LOG_DEBUG)
|
||||
|
||||
def __is_allowed(self, identity_hash):
|
||||
if self.owner.config["voice_trusted_only"]:
|
||||
return self.owner.voice_is_trusted(identity_hash)
|
||||
else: return True
|
||||
|
||||
def __spin(self, until=None, msg=None, timeout=None):
|
||||
if msg: RNS.log(msg, RNS.LOG_DEBUG)
|
||||
if timeout != None: timeout = time.time()+timeout
|
||||
while (timeout == None or time.time()<timeout) and not until(): time.sleep(0.1)
|
||||
if timeout != None and time.time() > timeout:
|
||||
return False
|
||||
else:
|
||||
return True
|
@ -18,9 +18,9 @@ from kivy.lang.builder import Builder
|
||||
|
||||
from kivy.utils import escape_markup
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
from ui.helpers import multilingual_markup
|
||||
from ui.helpers import multilingual_markup, sig_icon_for_q
|
||||
else:
|
||||
from .helpers import multilingual_markup
|
||||
from .helpers import multilingual_markup, sig_icon_for_q
|
||||
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
from ui.helpers import ts_format
|
||||
@ -92,6 +92,25 @@ class Announces():
|
||||
a_name = announce["name"]
|
||||
a_cost = announce["cost"]
|
||||
dest_type = announce["type"]
|
||||
a_rssi = None
|
||||
a_snr = None
|
||||
a_q = None
|
||||
|
||||
link_extras_str = ""
|
||||
link_extras_full = ""
|
||||
if "extras" in announce and announce["extras"] != None:
|
||||
extras = announce["extras"]
|
||||
if "link_stats" in extras:
|
||||
link_stats = extras["link_stats"]
|
||||
if "rssi" in link_stats and "snr" in link_stats and "q" in link_stats:
|
||||
a_rssi = link_stats["rssi"]
|
||||
a_snr = link_stats["snr"]
|
||||
a_q = link_stats["q"]
|
||||
if a_rssi != None and a_snr != None and a_q != None:
|
||||
link_extras_str = f" ([b]RSSI[/b] {a_rssi} [b]SNR[/b] {a_snr})"
|
||||
link_extras_full = f"\n[b]Link Quality[/b] {a_q}%[/b]\n[b]RSSI[/b] {a_rssi}\n[b]SNR[/b] {a_snr}"
|
||||
|
||||
sig_icon = multilingual_markup(sig_icon_for_q(a_q).encode("utf-8")).decode("utf-8")
|
||||
|
||||
if not context_dest in self.added_item_dests:
|
||||
if self.app.sideband.is_trusted(context_dest):
|
||||
@ -99,16 +118,16 @@ class Announces():
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
|
||||
def gen_info(ts, dest, name, cost, dtype):
|
||||
def gen_info(ts, dest, name, cost, dtype, link_extras):
|
||||
name = multilingual_markup(escape_markup(str(name)).encode("utf-8")).decode("utf-8")
|
||||
cost = str(cost)
|
||||
def x(sender):
|
||||
yes_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
|
||||
if dtype == "lxmf.delivery":
|
||||
ad_text = "[size=22dp]LXMF Peer[/size]\n\n[b]Received[/b] "+ts+"\n[b]Address[/b] "+RNS.prettyhexrep(dest)+"\n[b]Name[/b] "+name+"\n[b]Stamp Cost[/b] "+cost
|
||||
ad_text = "[size=22dp]LXMF Peer[/size]\n\n[b]Received[/b] "+ts+"\n[b]Address[/b] "+RNS.prettyhexrep(dest)+"\n[b]Name[/b] "+name+"\n[b]Stamp Cost[/b] "+cost+link_extras
|
||||
|
||||
if dtype == "lxmf.propagation":
|
||||
ad_text = "[size=22dp]LXMF Propagation Node[/size]\n\n[b]Received[/b] "+ts+"\n[b]Address[/b] "+RNS.prettyhexrep(dest)
|
||||
ad_text = "[size=22dp]LXMF Propagation Node[/size]\n\n[b]Received[/b] "+ts+"\n[b]Address[/b] "+RNS.prettyhexrep(dest)+link_extras
|
||||
|
||||
dialog = MDDialog(
|
||||
text=ad_text,
|
||||
@ -123,7 +142,8 @@ class Announces():
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
time_string = time.strftime(ts_format, time.localtime(ts))
|
||||
time_string = sig_icon + " " + time.strftime(ts_format, time.localtime(ts)) + link_extras_str
|
||||
time_string_plain = time.strftime(ts_format, time.localtime(ts))
|
||||
|
||||
if dest_type == "lxmf.delivery":
|
||||
disp_name = multilingual_markup(escape_markup(str(self.app.sideband.peer_display_name(context_dest))).encode("utf-8")).decode("utf-8")
|
||||
@ -137,7 +157,7 @@ class Announces():
|
||||
disp_name = "Unknown Announce"
|
||||
iconl = IconLeftWidget(icon="progress-question")
|
||||
|
||||
item = TwoLineAvatarIconListItem(text=time_string, secondary_text=disp_name, on_release=gen_info(time_string, context_dest, a_name, a_cost, dest_type))
|
||||
item = TwoLineAvatarIconListItem(text=time_string, secondary_text=disp_name, on_release=gen_info(time_string_plain, context_dest, a_name, a_cost, dest_type, link_extras_full))
|
||||
item.add_widget(iconl)
|
||||
item.sb_uid = context_dest
|
||||
item.ts = ts
|
||||
|
@ -6,6 +6,7 @@ from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivymd.uix.list import MDList, IconLeftWidget, IconRightWidget, OneLineAvatarIconListItem
|
||||
from kivymd.uix.menu import MDDropdownMenu
|
||||
from kivymd.toast import toast
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.clock import Clock
|
||||
@ -53,6 +54,7 @@ class Conversations():
|
||||
self.app.root.ids.screen_manager.add_widget(self.screen)
|
||||
|
||||
self.conversation_dropdown = None
|
||||
self.voice_dropdown = None
|
||||
self.delete_dialog = None
|
||||
self.clear_dialog = None
|
||||
self.clear_telemetry_dialog = None
|
||||
@ -91,6 +93,7 @@ class Conversations():
|
||||
self.app.sideband.setstate("wants.viewupdate.conversations", False)
|
||||
|
||||
def trust_icon(self, conv):
|
||||
conv_type = conv["type"]
|
||||
context_dest = conv["dest"]
|
||||
unread = conv["unread"]
|
||||
appearance = self.app.sideband.peer_appearance(context_dest, conv=conv)
|
||||
@ -106,25 +109,28 @@ class Conversations():
|
||||
trust_icon = appearance[0] or da[0];
|
||||
|
||||
else:
|
||||
if self.app.sideband.requests_allowed_from(context_dest):
|
||||
if unread:
|
||||
if is_trusted:
|
||||
trust_icon = "email-seal"
|
||||
else:
|
||||
trust_icon = "email"
|
||||
else:
|
||||
trust_icon = "account-lock-open"
|
||||
if conv_type == self.app.sideband.CONV_VOICE:
|
||||
trust_icon = "phone"
|
||||
else:
|
||||
if is_trusted:
|
||||
if self.app.sideband.requests_allowed_from(context_dest):
|
||||
if unread:
|
||||
trust_icon = "email-seal"
|
||||
if is_trusted:
|
||||
trust_icon = "email-seal"
|
||||
else:
|
||||
trust_icon = "email"
|
||||
else:
|
||||
trust_icon = "account-check"
|
||||
trust_icon = "account-lock-open"
|
||||
else:
|
||||
if unread:
|
||||
trust_icon = "email"
|
||||
if is_trusted:
|
||||
if unread:
|
||||
trust_icon = "email-seal"
|
||||
else:
|
||||
trust_icon = "account-check"
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
if unread:
|
||||
trust_icon = "email"
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
|
||||
return trust_icon
|
||||
|
||||
@ -133,6 +139,7 @@ class Conversations():
|
||||
unread = conv["unread"]
|
||||
last_activity = conv["last_activity"]
|
||||
trusted = conv["trust"] == 1
|
||||
appearance_from_all = self.app.sideband.config["display_style_from_all"]
|
||||
appearance = self.app.sideband.peer_appearance(context_dest, conv=conv)
|
||||
is_object = self.app.sideband.is_object(context_dest, conv_data=conv)
|
||||
da = self.app.sideband.DEFAULT_APPEARANCE
|
||||
@ -141,7 +148,7 @@ class Conversations():
|
||||
conv_icon = self.trust_icon(conv)
|
||||
fg = None; bg = None; ti_color = None
|
||||
|
||||
if trusted and self.app.sideband.config["display_style_in_contact_list"] and appearance != None and appearance != da:
|
||||
if (trusted or appearance_from_all) and self.app.sideband.config["display_style_in_contact_list"] and appearance != None and appearance != da:
|
||||
fg = appearance[1] or da[1]; bg = appearance[2] or da[2]
|
||||
ti_color = "Custom"
|
||||
else:
|
||||
@ -165,6 +172,7 @@ class Conversations():
|
||||
|
||||
iconl._default_icon_pad = dp(ic_p)
|
||||
iconl.icon_size = dp(ic_s)
|
||||
iconl.conv_type = conv["type"]
|
||||
|
||||
return iconl
|
||||
|
||||
@ -186,6 +194,7 @@ class Conversations():
|
||||
|
||||
for conv in self.context_dests:
|
||||
context_dest = conv["dest"]
|
||||
conv_type = conv["type"]
|
||||
unread = conv["unread"]
|
||||
last_activity = conv["last_activity"]
|
||||
|
||||
@ -202,6 +211,7 @@ class Conversations():
|
||||
item.sb_uid = context_dest
|
||||
item.sb_unread = unread
|
||||
iconl.sb_uid = context_dest
|
||||
item.conv_type = conv_type
|
||||
|
||||
def gen_edit(item):
|
||||
def x():
|
||||
@ -282,7 +292,7 @@ class Conversations():
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
dialog.open()
|
||||
RNS.log("Generated edit dialog in "+str(RNS.prettytime(time.time()-t_s)), RNS.LOG_DEBUG)
|
||||
|
||||
@ -311,7 +321,7 @@ class Conversations():
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
|
||||
item.dmenu.dismiss()
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
self.clear_dialog.open()
|
||||
return x
|
||||
|
||||
@ -335,7 +345,7 @@ class Conversations():
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
|
||||
item.dmenu.dismiss()
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
self.clear_telemetry_dialog.open()
|
||||
return x
|
||||
|
||||
@ -361,27 +371,61 @@ class Conversations():
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
|
||||
item.dmenu.dismiss()
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
self.delete_dialog.open()
|
||||
return x
|
||||
|
||||
# def gen_move_to(item):
|
||||
# def x():
|
||||
# item.dmenu.dismiss()
|
||||
# self.app.sideband.conversation_set_object(self.conversation_dropdown.context_dest, not self.app.sideband.is_object(self.conversation_dropdown.context_dest))
|
||||
# self.app.conversations_view.update()
|
||||
# return x
|
||||
|
||||
def gen_copy_addr(item):
|
||||
def x():
|
||||
Clipboard.copy(RNS.hexrep(self.conversation_dropdown.context_dest, delimit=False))
|
||||
item.dmenu.dismiss()
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
return x
|
||||
|
||||
def gen_call(item):
|
||||
def x():
|
||||
identity = RNS.Identity.recall(self.conversation_dropdown.context_dest)
|
||||
if identity: self.app.dial_action(identity.hash)
|
||||
else: toast("Can't call, identity unknown")
|
||||
self.voice_dropdown.dismiss(); self.conversation_dropdown.dismiss()
|
||||
return x
|
||||
|
||||
item.iconr = IconRightWidget(icon="dots-vertical");
|
||||
|
||||
if self.voice_dropdown == None:
|
||||
dmi_h = 40
|
||||
dmv_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Edit",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_edit(item)
|
||||
},
|
||||
{
|
||||
"text": "Copy Identity Hash",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_copy_addr(item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_del(item)
|
||||
}
|
||||
]
|
||||
|
||||
self.voice_dropdown = MDDropdownMenu(
|
||||
caller=item.iconr,
|
||||
items=dmv_items,
|
||||
position="auto",
|
||||
width=dp(256),
|
||||
elevation=0,
|
||||
radius=dp(3),
|
||||
)
|
||||
self.voice_dropdown.effect_cls = ScrollEffect
|
||||
self.voice_dropdown.md_bg_color = self.app.color_hover
|
||||
|
||||
if self.conversation_dropdown == None:
|
||||
obj_str = "conversations" if is_object else "objects"
|
||||
dmi_h = 40
|
||||
dm_items = [
|
||||
{
|
||||
@ -390,18 +434,18 @@ class Conversations():
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_edit(item)
|
||||
},
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Call",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_call(item)
|
||||
},
|
||||
{
|
||||
"text": "Copy Address",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_copy_addr(item)
|
||||
},
|
||||
# {
|
||||
# "text": "Move to objects",
|
||||
# "viewclass": "OneLineListItem",
|
||||
# "height": dp(dmi_h),
|
||||
# "on_release": gen_move_to(item)
|
||||
# },
|
||||
{
|
||||
"text": "Clear Messages",
|
||||
"viewclass": "OneLineListItem",
|
||||
@ -433,11 +477,15 @@ class Conversations():
|
||||
self.conversation_dropdown.effect_cls = ScrollEffect
|
||||
self.conversation_dropdown.md_bg_color = self.app.color_hover
|
||||
|
||||
item.dmenu = self.conversation_dropdown
|
||||
if conv_type == self.app.sideband.CONV_VOICE:
|
||||
item.dmenu = self.voice_dropdown
|
||||
else:
|
||||
item.dmenu = self.conversation_dropdown
|
||||
|
||||
def callback_factory(ref, dest):
|
||||
def x(sender):
|
||||
self.conversation_dropdown.context_dest = dest
|
||||
self.voice_dropdown.context_dest = dest
|
||||
ref.dmenu.caller = ref.iconr
|
||||
ref.dmenu.open()
|
||||
return x
|
||||
@ -447,6 +495,7 @@ class Conversations():
|
||||
item.add_widget(item.iconr)
|
||||
|
||||
item.trusted = self.app.sideband.is_trusted(context_dest, conv_data=existing_conv)
|
||||
item.conv_type = conv_type
|
||||
|
||||
self.added_item_dests.append(context_dest)
|
||||
self.list.add_widget(item)
|
||||
@ -518,14 +567,14 @@ Builder.load_string("""
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(250)
|
||||
height: dp(260)
|
||||
|
||||
MDTextField:
|
||||
id: n_address_field
|
||||
max_text_length: 32
|
||||
hint_text: "Address"
|
||||
helper_text: "Error, check your input"
|
||||
helper_text_mode: "on_error"
|
||||
helper_text: ""
|
||||
helper_text_mode: "on_focus"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
@ -539,7 +588,7 @@ Builder.load_string("""
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(8),dp(24)]
|
||||
height: dp(48)
|
||||
height: dp(24)
|
||||
MDLabel:
|
||||
id: "trusted_switch_label"
|
||||
text: "Trusted"
|
||||
@ -550,6 +599,21 @@ Builder.load_string("""
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(8),dp(24)]
|
||||
height: dp(24)
|
||||
MDLabel:
|
||||
id: "trusted_switch_label"
|
||||
text: "Voice Only"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: n_voice_only
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
<ConvSettings>
|
||||
orientation: "vertical"
|
||||
spacing: "16dp"
|
||||
@ -652,6 +716,10 @@ Builder.load_string("""
|
||||
padding: [0, 0, 0, dp(16)]
|
||||
height: self.minimum_height+dp(24)
|
||||
|
||||
MDLabel:
|
||||
id: node_info
|
||||
text: "Unknown propagation node"
|
||||
|
||||
MDProgressBar:
|
||||
id: sync_progress
|
||||
type: "determinate"
|
||||
@ -659,7 +727,6 @@ Builder.load_string("""
|
||||
|
||||
MDLabel:
|
||||
id: sync_status
|
||||
hint_text: "Name"
|
||||
text: "Initiating sync..."
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ from kivy.uix.screenmanager import ScreenManager, Screen
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivymd.uix.list import OneLineIconListItem, MDList, IconLeftWidget, IconRightWidget
|
||||
from kivy.properties import StringProperty
|
||||
import re
|
||||
|
||||
ts_format = "%Y-%m-%d %H:%M:%S"
|
||||
file_ts_format = "%Y_%m_%d_%H_%M_%S"
|
||||
@ -19,11 +20,27 @@ color_delivered = "Blue"
|
||||
color_paper = "Indigo"
|
||||
color_propagated = "Indigo"
|
||||
color_failed = "Red"
|
||||
color_cancelled = "Red"
|
||||
color_unknown = "Gray"
|
||||
intensity_msgs_dark = "800"
|
||||
intensity_msgs_light = "500"
|
||||
intensity_play_dark = "600"
|
||||
intensity_play_light = "300"
|
||||
intensity_cancelled = "900"
|
||||
|
||||
|
||||
intensity_msgs_dark_alt = "800"
|
||||
intensity_msgs_light_alt = "400"
|
||||
intensity_delivered_alt_dark = "800"
|
||||
color_received_alt = "BlueGray"
|
||||
color_received_alt_light = "BlueGray"
|
||||
color_delivered_alt = "Indigo"
|
||||
color_propagated_alt = "DeepPurple"
|
||||
color_paper_alt = "DeepPurple"
|
||||
color_playing_alt = "Amber"
|
||||
color_failed_alt = "Red"
|
||||
color_unknown_alt = "Gray"
|
||||
color_cancelled_alt = "Red"
|
||||
|
||||
class ContentNavigationDrawer(Screen):
|
||||
pass
|
||||
@ -45,13 +62,12 @@ def strip_emojis(str_input):
|
||||
return output
|
||||
|
||||
def multilingual_markup(data):
|
||||
# TODO: Remove
|
||||
# import time
|
||||
# ts = time.time()
|
||||
|
||||
do = ""
|
||||
rfont = "default"
|
||||
ds = data.decode("utf-8")
|
||||
di = 0
|
||||
persistent_regions = [(m.start(), m.end()) for m in re.finditer("(?s)\[font=(?:nf|term)\].*?\[/font\]", ds)]
|
||||
|
||||
for cp in ds:
|
||||
match = False
|
||||
switch = False
|
||||
@ -63,6 +79,10 @@ def multilingual_markup(data):
|
||||
switch = True
|
||||
rfont = "emoji"
|
||||
|
||||
in_persistent = False
|
||||
if any(x[0] < di and x[1] > di for x in persistent_regions):
|
||||
in_persistent = True
|
||||
|
||||
if not match:
|
||||
for range_start in codepoint_map:
|
||||
range_end = codepoint_map[range_start][0]
|
||||
@ -71,8 +91,9 @@ def multilingual_markup(data):
|
||||
if range_end >= ord(cp) >= range_start:
|
||||
match = True
|
||||
if rfont != mapped_font:
|
||||
rfont = mapped_font
|
||||
switch = True
|
||||
if not in_persistent:
|
||||
rfont = mapped_font
|
||||
switch = True
|
||||
break
|
||||
|
||||
if (not match) and rfont != "default":
|
||||
@ -86,15 +107,32 @@ def multilingual_markup(data):
|
||||
do += "[font="+str(rfont)+"]"
|
||||
|
||||
do += cp
|
||||
di += 1
|
||||
|
||||
if rfont != "default":
|
||||
do += "[/font]"
|
||||
|
||||
# TODO: Remove
|
||||
# print(do+"\n\n"+str(time.time()-ts))
|
||||
|
||||
return do.encode("utf-8")
|
||||
|
||||
def sig_icon_for_q(q):
|
||||
if q == None:
|
||||
return ""
|
||||
elif q > 90:
|
||||
return ""
|
||||
elif q > 70:
|
||||
return ""
|
||||
elif q > 50:
|
||||
return ""
|
||||
elif q > 20:
|
||||
return ""
|
||||
elif q > 5:
|
||||
return ""
|
||||
else:
|
||||
return ""
|
||||
|
||||
persistent_fonts = ["nf", "term"]
|
||||
nf_mapped = "nf"
|
||||
|
||||
codepoint_map = {
|
||||
0x0590: [0x05ff, "hebrew"],
|
||||
0x2e3a: [0x2e3b, "chinese"],
|
||||
@ -128,6 +166,29 @@ codepoint_map = {
|
||||
0xac00: [0xd7af, "korean"],
|
||||
0xd7b0: [0xd7ff, "korean"],
|
||||
0x0900: [0x097f, "combined"], # Devanagari
|
||||
0xe5fa: [0xe6b7, nf_mapped], # Seti-UI + Custom
|
||||
0xe700: [0xe8ef, nf_mapped], # Devicons
|
||||
0xed00: [0xf2ff, nf_mapped], # Font Awesome
|
||||
0xe200: [0xe2a9, nf_mapped], # Font Awesome Extension
|
||||
0xf0001: [0xf1af0, nf_mapped], # Material Design Icons
|
||||
0xe300: [0xe3e3, nf_mapped], # Weather
|
||||
0xf400: [0xf533, nf_mapped], # Octicons
|
||||
0x2665: [0x2665, nf_mapped], # Octicons
|
||||
0x26a1: [0x26a1, nf_mapped], # Octicons
|
||||
0xe0a0: [0xe0a2, nf_mapped], # Powerline Symbols
|
||||
0xe0b0: [0xe0b3, nf_mapped], # Powerline Symbols
|
||||
0xe0a3: [0xe0a3, nf_mapped], # Powerline Extra Symbols
|
||||
0xe0b4: [0xe0c8, nf_mapped], # Powerline Extra Symbols
|
||||
0xe0ca: [0xe0ca, nf_mapped], # Powerline Extra Symbols
|
||||
0xe0cc: [0xe0d7, nf_mapped], # Powerline Extra Symbols
|
||||
0x23fb: [0x23fe, nf_mapped], # IEC Power Symbols
|
||||
0x2b58: [0x2b58, nf_mapped], # IEC Power Symbols
|
||||
0xf300: [0xf381, nf_mapped], # Font logos
|
||||
0xe000: [0xe00a, nf_mapped], # Pomicons
|
||||
0xea60: [0xec1e, nf_mapped], # Codicons
|
||||
0x276c: [0x2771, nf_mapped], # Heavy Angle Brackets
|
||||
0x2500: [0x259f, nf_mapped], # Box Drawing
|
||||
0xee00: [0xee0b, nf_mapped], # Progress
|
||||
}
|
||||
|
||||
emoji_lookup = [
|
||||
|
@ -80,6 +80,15 @@ MDNavigationLayout:
|
||||
on_release: root.ids.screen_manager.app.map_action(self)
|
||||
|
||||
|
||||
# OneLineIconListItem:
|
||||
# text: "Overview"
|
||||
# on_release: root.ids.screen_manager.app.overview_action(self)
|
||||
|
||||
# IconLeftWidget:
|
||||
# icon: "view-dashboard-outline"
|
||||
# on_release: root.ids.screen_manager.app.overview_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Announce Stream"
|
||||
on_release: root.ids.screen_manager.app.announces_action(self)
|
||||
@ -87,6 +96,16 @@ MDNavigationLayout:
|
||||
IconLeftWidget:
|
||||
icon: "account-voice"
|
||||
on_release: root.ids.screen_manager.app.announces_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Voice"
|
||||
on_release: root.ids.screen_manager.app.voice_action(self)
|
||||
# _no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "phone-in-talk"
|
||||
on_release: root.ids.screen_manager.app.voice_action(self)
|
||||
|
||||
|
||||
# OneLineIconListItem:
|
||||
@ -107,6 +126,15 @@ MDNavigationLayout:
|
||||
on_release: root.ids.screen_manager.app.telemetry_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Utilities"
|
||||
on_release: root.ids.screen_manager.app.utilities_action(self)
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "tools"
|
||||
on_release: root.ids.screen_manager.app.utilities_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Preferences"
|
||||
on_release: root.ids.screen_manager.app.settings_action(self)
|
||||
@ -1260,6 +1288,28 @@ MDScreen:
|
||||
"""
|
||||
|
||||
layout_settings_screen = """
|
||||
<UIScaling>
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height+dp(0)
|
||||
|
||||
MDLabel:
|
||||
id: scaling_info
|
||||
markup: True
|
||||
text: "You can scale the entire Sideband UI by specifying a scaling factor in the field below. After setting it, restart sideband for the scaling to take effect.\\n\\nSet to 0.0 to disable scaling adjustments.\\n\\n[b]Please note![/b] On some devices, the default scaling factor will be higher than 1.0, and setting a smaller value will result in miniscule UI elements."
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
MDTextField:
|
||||
id: scaling_factor
|
||||
hint_text: "Scaling Factor"
|
||||
helper_text: "From 0.3 to 5.0"
|
||||
helper_text_mode: "on_focus"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDScreen:
|
||||
name: "settings_screen"
|
||||
|
||||
@ -1399,11 +1449,21 @@ MDScreen:
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: appearance_ui_scaling
|
||||
icon: "relative-scale"
|
||||
text: "Configure UI Scaling"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.app.configure_ui_scaling_action(self)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
padding: [0,dp(14),dp(24),dp(0)]
|
||||
height: dp(62)
|
||||
|
||||
MDLabel:
|
||||
text: "Notifications"
|
||||
@ -1444,6 +1504,21 @@ MDScreen:
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Classic message colors"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_classic_message_colors
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
@ -1518,7 +1593,7 @@ MDScreen:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Announce Automatically"
|
||||
text: "Announce automatically"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1533,7 +1608,7 @@ MDScreen:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Try propagation on direct delivery failure"
|
||||
text: "Try propagation automatically"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1574,6 +1649,38 @@ MDScreen:
|
||||
disabled: False
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Only render markup from trusted"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_trusted_markup_only
|
||||
pos_hint: {"center_y": 0.3}
|
||||
disabled: False
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Compose messages in markdown"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_compose_in_markdown
|
||||
pos_hint: {"center_y": 0.3}
|
||||
disabled: False
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
@ -1693,7 +1800,7 @@ MDScreen:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Use high-quality voice for PTT"
|
||||
text: "High-quality codec for LXMF PTT"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
@ -1709,14 +1816,30 @@ MDScreen:
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Use Home Node as Broadcast Repeater"
|
||||
text: "Enable voice calls"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_home_node_as_broadcast_repeater
|
||||
id: settings_voice_enabled
|
||||
pos_hint: {"center_y": 0.3}
|
||||
disabled: False
|
||||
active: False
|
||||
disabled: True
|
||||
|
||||
# MDBoxLayout:
|
||||
# orientation: "horizontal"
|
||||
# size_hint_y: None
|
||||
# padding: [0,0,dp(24),dp(0)]
|
||||
# height: dp(48)
|
||||
|
||||
# MDLabel:
|
||||
# text: "Use Home Node as Broadcast Repeater"
|
||||
# font_style: "H6"
|
||||
|
||||
# MDSwitch:
|
||||
# id: settings_home_node_as_broadcast_repeater
|
||||
# pos_hint: {"center_y": 0.3}
|
||||
# active: False
|
||||
# disabled: True
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
|
@ -34,12 +34,14 @@ if RNS.vendor.platformutils.get_platform() == "android":
|
||||
import plyer
|
||||
from sideband.sense import Telemeter, Commands
|
||||
from ui.helpers import ts_format, file_ts_format, mdc
|
||||
from ui.helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light
|
||||
from ui.helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light, color_cancelled, intensity_cancelled
|
||||
from ui.helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark, color_cancelled_alt
|
||||
else:
|
||||
import sbapp.plyer as plyer
|
||||
from sbapp.sideband.sense import Telemeter, Commands
|
||||
from .helpers import ts_format, file_ts_format, mdc
|
||||
from .helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light
|
||||
from .helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light, color_cancelled, intensity_cancelled
|
||||
from .helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark, color_cancelled_alt
|
||||
|
||||
if RNS.vendor.platformutils.is_darwin():
|
||||
from PIL import Image as PilImage
|
||||
@ -108,8 +110,6 @@ class Messages():
|
||||
msg = self.app.sideband.message(lxm_hash)
|
||||
if msg:
|
||||
close_button = MDRectangleFlatButton(text="Close", font_size=dp(18))
|
||||
# d_items = [ ]
|
||||
# d_items.append(DialogItem(IconLeftWidget(icon="postage-stamp"), text="[size="+str(ss)+"]Stamp[/size]"))
|
||||
|
||||
d_text = ""
|
||||
|
||||
@ -203,6 +203,25 @@ class Messages():
|
||||
self.ids.message_text.input_type = "text"
|
||||
self.ids.message_text.keyboard_suggestions = True
|
||||
|
||||
if not self.app.sideband.config["classic_message_colors"]:
|
||||
c_delivered = color_delivered_alt
|
||||
c_received = color_received_alt
|
||||
c_propagated = color_propagated_alt
|
||||
c_playing = color_playing_alt
|
||||
c_paper = color_paper_alt
|
||||
c_unknown = color_unknown_alt
|
||||
c_failed = color_failed_alt
|
||||
c_cancelled = color_cancelled_alt
|
||||
else:
|
||||
c_delivered = color_delivered
|
||||
c_received = color_received
|
||||
c_propagated = color_propagated
|
||||
c_playing = color_playing
|
||||
c_paper = color_paper
|
||||
c_unknown = color_unknown
|
||||
c_failed = color_failed
|
||||
c_cancelled = color_cancelled
|
||||
|
||||
for new_message in self.app.sideband.list_messages(self.context_dest, after=self.latest_message_timestamp,limit=limit):
|
||||
self.new_messages.append(new_message)
|
||||
|
||||
@ -241,12 +260,24 @@ class Messages():
|
||||
if (len(self.added_item_hashes) < self.db_message_count) and not self.load_more_button in self.list.children:
|
||||
self.list.add_widget(self.load_more_button, len(self.list.children))
|
||||
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark
|
||||
intensity_play = intensity_play_dark
|
||||
if self.app.sideband.config["classic_message_colors"]:
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark
|
||||
intensity_play = intensity_play_dark
|
||||
intensity_delivered = intensity_msgs
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light
|
||||
intensity_play = intensity_play_light
|
||||
intensity_delivered = intensity_msgs
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light
|
||||
intensity_play = intensity_play_light
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark_alt
|
||||
intensity_play = intensity_play_dark
|
||||
intensity_delivered = intensity_delivered_alt_dark
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light_alt
|
||||
intensity_play = intensity_play_light
|
||||
intensity_delivered = intensity_msgs
|
||||
|
||||
for w in self.widgets:
|
||||
m = w.m
|
||||
@ -270,8 +301,19 @@ class Messages():
|
||||
delivery_syms += " 📦"
|
||||
delivery_syms = multilingual_markup(delivery_syms.encode("utf-8")).decode("utf-8")
|
||||
|
||||
if msg["state"] > LXMF.LXMessage.SENT:
|
||||
if hasattr(w, "dmenu"):
|
||||
if hasattr(w.dmenu, "items"):
|
||||
remove_item = None
|
||||
for item in w.dmenu.items:
|
||||
if item["text"] == "Cancel message":
|
||||
remove_item = item
|
||||
break
|
||||
if remove_item != None:
|
||||
w.dmenu.items.remove(remove_item)
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.OUTBOUND or msg["state"] == LXMF.LXMessage.SENDING or msg["state"] == LXMF.LXMessage.SENT:
|
||||
w.md_bg_color = msg_color = mdc(color_unknown, intensity_msgs)
|
||||
w.md_bg_color = msg_color = mdc(c_unknown, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
prgstr = ""
|
||||
@ -303,9 +345,15 @@ class Messages():
|
||||
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||
m["state"] = msg["state"]
|
||||
|
||||
att_heading_str = ""
|
||||
if hasattr(w, "has_attachment") and w.has_attachment:
|
||||
att_heading_str = "\n[b]Attachments[/b] "
|
||||
for attachment in w.attachments_field:
|
||||
att_heading_str += str(attachment[0])+", "
|
||||
att_heading_str = att_heading_str[:-2]
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.DELIVERED:
|
||||
w.md_bg_color = msg_color = mdc(color_delivered, intensity_msgs)
|
||||
w.md_bg_color = msg_color = mdc(c_delivered, intensity_delivered)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
@ -317,7 +365,7 @@ class Messages():
|
||||
m["state"] = msg["state"]
|
||||
|
||||
if msg["method"] == LXMF.LXMessage.PAPER:
|
||||
w.md_bg_color = msg_color = mdc(color_paper, intensity_msgs)
|
||||
w.md_bg_color = msg_color = mdc(c_paper, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
@ -326,7 +374,7 @@ class Messages():
|
||||
m["state"] = msg["state"]
|
||||
|
||||
if msg["method"] == LXMF.LXMessage.PROPAGATED and msg["state"] == LXMF.LXMessage.SENT:
|
||||
w.md_bg_color = msg_color = mdc(color_propagated, intensity_msgs)
|
||||
w.md_bg_color = msg_color = mdc(c_propagated, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
@ -338,7 +386,7 @@ class Messages():
|
||||
m["state"] = msg["state"]
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.FAILED:
|
||||
w.md_bg_color = msg_color = mdc(color_failed, intensity_msgs)
|
||||
w.md_bg_color = msg_color = mdc(c_failed, intensity_cancelled)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
@ -350,6 +398,34 @@ class Messages():
|
||||
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||
w.dmenu.items.append(w.dmenu.retry_item)
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.CANCELLED:
|
||||
w.md_bg_color = msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Cancelled"
|
||||
m["state"] = msg["state"]
|
||||
if w.has_audio:
|
||||
alstr = RNS.prettysize(w.audio_size)
|
||||
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||
w.dmenu.items.append(w.dmenu.retry_item)
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.REJECTED:
|
||||
w.md_bg_color = msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Rejected"
|
||||
m["state"] = msg["state"]
|
||||
if w.has_audio:
|
||||
alstr = RNS.prettysize(w.audio_size)
|
||||
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||
w.dmenu.items.append(w.dmenu.retry_item)
|
||||
|
||||
w.heading += att_heading_str
|
||||
|
||||
|
||||
def hide_widget(self, wid, dohide=True):
|
||||
if hasattr(wid, 'saved_attrs'):
|
||||
@ -361,14 +437,51 @@ class Messages():
|
||||
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = 0, None, 0, True
|
||||
|
||||
def update_widget(self):
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark
|
||||
intensity_play = intensity_play_dark
|
||||
mt_color = [1.0, 1.0, 1.0, 0.8]
|
||||
|
||||
if self.app.sideband.config["classic_message_colors"]:
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark
|
||||
intensity_play = intensity_play_dark
|
||||
intensity_delivered = intensity_msgs
|
||||
mt_color = [1.0, 1.0, 1.0, 0.8]
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light
|
||||
intensity_play = intensity_play_light
|
||||
intensity_delivered = intensity_msgs
|
||||
mt_color = [1.0, 1.0, 1.0, 0.95]
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light
|
||||
intensity_play = intensity_play_light
|
||||
mt_color = [1.0, 1.0, 1.0, 0.95]
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
intensity_msgs = intensity_msgs_dark_alt
|
||||
intensity_play = intensity_play_dark
|
||||
intensity_delivered = intensity_delivered_alt_dark
|
||||
mt_color = [1.0, 1.0, 1.0, 0.8]
|
||||
else:
|
||||
intensity_msgs = intensity_msgs_light_alt
|
||||
intensity_play = intensity_play_light
|
||||
intensity_delivered = intensity_msgs
|
||||
mt_color = [1.0, 1.0, 1.0, 0.95]
|
||||
|
||||
if not self.app.sideband.config["classic_message_colors"]:
|
||||
if self.app.sideband.config["dark_ui"]:
|
||||
c_received = color_received_alt
|
||||
else:
|
||||
c_received = color_received_alt_light
|
||||
c_delivered = color_delivered_alt
|
||||
c_propagated = color_propagated_alt
|
||||
c_playing = color_playing_alt
|
||||
c_paper = color_paper_alt
|
||||
c_unknown = color_unknown_alt
|
||||
c_failed = color_failed_alt
|
||||
c_cancelled = color_cancelled_alt
|
||||
else:
|
||||
c_delivered = color_delivered
|
||||
c_received = color_received
|
||||
c_propagated = color_propagated
|
||||
c_playing = color_playing
|
||||
c_paper = color_paper
|
||||
c_unknown = color_unknown
|
||||
c_failed = color_failed
|
||||
c_cancelled = color_cancelled
|
||||
|
||||
self.ids.message_text.font_name = self.app.input_font
|
||||
|
||||
@ -377,13 +490,27 @@ class Messages():
|
||||
|
||||
for m in self.new_messages:
|
||||
if not m["hash"] in self.added_item_hashes:
|
||||
renderer = None
|
||||
message_source = m["content"]
|
||||
if "lxm" in m and m["lxm"] and m["lxm"].fields != None and LXMF.FIELD_RENDERER in m["lxm"].fields:
|
||||
renderer = m["lxm"].fields[LXMF.FIELD_RENDERER]
|
||||
|
||||
try:
|
||||
if not self.is_trusted:
|
||||
if self.app.sideband.config["trusted_markup_only"] and not self.is_trusted:
|
||||
message_input = str( escape_markup(m["content"].decode("utf-8")) ).encode("utf-8")
|
||||
else:
|
||||
message_input = m["content"]
|
||||
if renderer == LXMF.RENDERER_MARKDOWN:
|
||||
message_input = self.app.md_to_bbcode(message_input.decode("utf-8")).encode("utf-8")
|
||||
message_input = self.app.process_bb_markup(message_input.decode("utf-8")).encode("utf-8")
|
||||
elif renderer == LXMF.RENDERER_BBCODE:
|
||||
message_input = self.app.process_bb_markup(message_input.decode("utf-8")).encode("utf-8")
|
||||
else:
|
||||
message_input = str(escape_markup(m["content"].decode("utf-8"))).encode("utf-8")
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"Message content could not be decoded: {e}", RNS.LOG_DEBUG)
|
||||
RNS.trace_exception(e)
|
||||
message_input = b""
|
||||
|
||||
if message_input.strip() == b"":
|
||||
@ -524,37 +651,42 @@ class Messages():
|
||||
|
||||
if m["source"] == self.app.sideband.lxmf_destination.hash:
|
||||
if m["state"] == LXMF.LXMessage.DELIVERED:
|
||||
msg_color = mdc(color_delivered, intensity_msgs)
|
||||
msg_color = mdc(c_delivered, intensity_delivered)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+delivery_syms+"\n[b]State[/b] Delivered"
|
||||
|
||||
elif m["method"] == LXMF.LXMessage.PROPAGATED and m["state"] == LXMF.LXMessage.SENT:
|
||||
msg_color = mdc(color_propagated, intensity_msgs)
|
||||
msg_color = mdc(c_propagated, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+delivery_syms+"\n[b]State[/b] On Propagation Net"
|
||||
|
||||
elif m["method"] == LXMF.LXMessage.PAPER:
|
||||
msg_color = mdc(color_paper, intensity_msgs)
|
||||
msg_color = mdc(c_paper, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Created[/b] "+txstr+"\n[b]State[/b] Paper Message"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.FAILED:
|
||||
msg_color = mdc(color_failed, intensity_msgs)
|
||||
msg_color = mdc(c_failed, intensity_cancelled)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.CANCELLED:
|
||||
msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Cancelled"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.REJECTED:
|
||||
msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Rejected"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.OUTBOUND or m["state"] == LXMF.LXMessage.SENDING:
|
||||
msg_color = mdc(color_unknown, intensity_msgs)
|
||||
msg_color = mdc(c_unknown, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Sending "
|
||||
|
||||
else:
|
||||
msg_color = mdc(color_unknown, intensity_msgs)
|
||||
msg_color = mdc(c_unknown, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Unknown"
|
||||
|
||||
else:
|
||||
msg_color = mdc(color_received, intensity_msgs)
|
||||
msg_color = mdc(c_received, intensity_msgs)
|
||||
heading_str = titlestr
|
||||
if phy_stats_str != "" and self.app.sideband.config["advanced_stats"]:
|
||||
heading_str += phy_stats_str+"\n"
|
||||
# TODO: Remove
|
||||
# if stamp_valid:
|
||||
# txstr += f" [b]Stamp[/b] value is {stamp_value} "
|
||||
|
||||
heading_str += "[b]Sent[/b] "+txstr+delivery_syms
|
||||
heading_str += "\n[b]Received[/b] "+rxstr
|
||||
@ -592,19 +724,29 @@ class Messages():
|
||||
|
||||
if has_attachment:
|
||||
item.attachments_field = attachments_field
|
||||
item.has_attachment = True
|
||||
else:
|
||||
item.has_attachment = False
|
||||
|
||||
if has_audio:
|
||||
def play_audio(sender):
|
||||
self.app.play_audio_field(sender.audio_field)
|
||||
stored_color = sender.md_bg_color
|
||||
if sender.lsource == self.app.sideband.lxmf_destination.hash:
|
||||
sender.md_bg_color = mdc(color_delivered, intensity_play)
|
||||
else:
|
||||
sender.md_bg_color = mdc(color_received, intensity_play)
|
||||
touch_event = None; block_play = False
|
||||
if sender and hasattr(sender, "last_touch"): touch_event = sender.last_touch
|
||||
if touch_event and hasattr(touch_event, "dpos"):
|
||||
delta = abs(touch_event.dpos[0]) + abs(touch_event.dpos[1])
|
||||
if delta >= 2.0: block_play = True
|
||||
|
||||
def cb(dt):
|
||||
sender.md_bg_color = stored_color
|
||||
Clock.schedule_once(cb, 0.25)
|
||||
if not block_play:
|
||||
self.app.play_audio_field(sender.audio_field)
|
||||
stored_color = sender.md_bg_color
|
||||
if sender.lsource == self.app.sideband.lxmf_destination.hash:
|
||||
sender.md_bg_color = mdc(c_delivered, intensity_play)
|
||||
else:
|
||||
sender.md_bg_color = mdc(c_received, intensity_play)
|
||||
|
||||
def cb(dt):
|
||||
sender.md_bg_color = stored_color
|
||||
Clock.schedule_once(cb, 0.25)
|
||||
|
||||
item.has_audio = True
|
||||
item.audio_size = len(audio_field[1])
|
||||
@ -653,6 +795,19 @@ class Messages():
|
||||
item.ids.content_text.owner = item
|
||||
item.ids.content_text.bind(texture_size=check_textures)
|
||||
|
||||
def cbf(w):
|
||||
def x(dt):
|
||||
if w.texture_size[0] == 0 and w.texture_size[1] == 0:
|
||||
w.markup = False
|
||||
escaped_content = escape_markup(w.text)
|
||||
def deferred(dt):
|
||||
w.text = "[i]This message could not be rendered correctly, likely due to an error in its markup. Falling back to plain-text rendering.[/i]\n\n"+escaped_content
|
||||
w.markup = True
|
||||
Clock.schedule_once(deferred, 0.1)
|
||||
return x
|
||||
|
||||
Clock.schedule_once(cbf(item.ids.content_text), 0.25)
|
||||
|
||||
if not RNS.vendor.platformutils.is_android():
|
||||
item.radius = dp(5)
|
||||
|
||||
@ -719,6 +874,13 @@ class Messages():
|
||||
|
||||
return x
|
||||
|
||||
def gen_cancel(mhash, item):
|
||||
def x():
|
||||
self.app.sideband.cancel_message(mhash)
|
||||
item.dmenu.dismiss()
|
||||
|
||||
return x
|
||||
|
||||
def gen_save_image(item):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
def x():
|
||||
@ -1001,7 +1163,7 @@ class Messages():
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy message text",
|
||||
"height": dp(40),
|
||||
"on_release": gen_copy(message_input.decode("utf-8"), item)
|
||||
"on_release": gen_copy(message_source.decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
@ -1035,7 +1197,7 @@ class Messages():
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy message text",
|
||||
"height": dp(40),
|
||||
"on_release": gen_copy(message_input.decode("utf-8"), item)
|
||||
"on_release": gen_copy(message_source.decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
@ -1053,7 +1215,7 @@ class Messages():
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy",
|
||||
"height": dp(40),
|
||||
"on_release": gen_copy(message_input.decode("utf-8"), item)
|
||||
"on_release": gen_copy(message_source.decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
@ -1070,7 +1232,7 @@ class Messages():
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy",
|
||||
"height": dp(40),
|
||||
"on_release": gen_copy(message_input.decode("utf-8"), item)
|
||||
"on_release": gen_copy(message_source.decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
@ -1093,7 +1255,7 @@ class Messages():
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy",
|
||||
"height": dp(40),
|
||||
"on_release": gen_copy(message_input.decode("utf-8"), item)
|
||||
"on_release": gen_copy(message_source.decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
@ -1118,6 +1280,14 @@ class Messages():
|
||||
"on_release": gen_save_attachment(item)
|
||||
}
|
||||
dm_items.append(extra_item)
|
||||
if m["source"] == self.app.sideband.lxmf_destination.hash and m["state"] <= LXMF.LXMessage.SENT:
|
||||
extra_item = {
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Cancel message",
|
||||
"height": dp(40),
|
||||
"on_release": gen_cancel(m["hash"], item)
|
||||
}
|
||||
dm_items.append(extra_item)
|
||||
|
||||
item.dmenu = MDDropdownMenu(
|
||||
caller=item.ids.msg_submenu,
|
||||
|
@ -148,6 +148,15 @@ class ObjectDetails():
|
||||
else:
|
||||
self.from_objects = False
|
||||
|
||||
if self.viewing_self:
|
||||
self.screen.ids.track_button.disabled = True
|
||||
else:
|
||||
self.screen.ids.track_button.disabled = False
|
||||
if self.app.sideband.is_tracking(source_dest):
|
||||
self.screen.ids.track_button.text = "Stop Live Tracking"
|
||||
else:
|
||||
self.screen.ids.track_button.text = "Start Live Tracking"
|
||||
|
||||
self.coords = None
|
||||
self.telemetry_list.data = []
|
||||
pds = multilingual_markup(escape_markup(str(self.app.sideband.peer_display_name(source_dest))).encode("utf-8")).decode("utf-8")
|
||||
@ -218,6 +227,15 @@ class ObjectDetails():
|
||||
self.clear_widget()
|
||||
self.update()
|
||||
|
||||
def live_tracking(self, sender):
|
||||
if not self.viewing_self:
|
||||
if not self.app.sideband.is_tracking(self.object_hash):
|
||||
self.app.sideband.start_tracking(self.object_hash, interval=59, duration=7*24*60*60)
|
||||
self.screen.ids.track_button.text = "Stop Live Tracking"
|
||||
else:
|
||||
self.app.sideband.stop_tracking(self.object_hash)
|
||||
self.screen.ids.track_button.text = "Start Live Tracking"
|
||||
|
||||
def send_update(self):
|
||||
if not self.viewing_self:
|
||||
result = self.app.sideband.send_latest_telemetry(to_addr=self.object_hash)
|
||||
@ -643,10 +661,9 @@ class RVDetails(MDRecycleView):
|
||||
alt_str = RNS.prettydistance(alt)
|
||||
formatted_values = f"Coordinates [b]{fcoords}[/b], altitude [b]{alt_str}[/b]"
|
||||
if speed != None:
|
||||
if speed > 0.02:
|
||||
if speed > 0.1:
|
||||
speed_formatted_values = f"Speed [b]{speed} Km/h[/b], heading [b]{heading}°[/b]"
|
||||
else:
|
||||
# speed_formatted_values = f"Speed [b]0 Km/h[/b]"
|
||||
speed_formatted_values = f"Object is [b]stationary[/b]"
|
||||
else:
|
||||
speed_formatted_values = None
|
||||
@ -750,6 +767,16 @@ class RVDetails(MDRecycleView):
|
||||
threading.Thread(target=lj, daemon=True).start()
|
||||
|
||||
release_function = select
|
||||
|
||||
elif name == "Reticulum Transport":
|
||||
te = "enabled" if s["values"]["transport_enabled"] else "disabled"
|
||||
formatted_values = f"Reticulum Transport [b]{te}[/b]"
|
||||
|
||||
elif name == "LXMF Propagation":
|
||||
tp = str(s["values"]["total_peers"])
|
||||
ap = str(s["values"]["active_peers"])
|
||||
formatted_values = f"Peered with [b]{tp}[/b] LXMF Propagation Nodes, [b]{ap}[/b] available"
|
||||
|
||||
else:
|
||||
formatted_values = f"{name}"
|
||||
for vn in s["values"]:
|
||||
@ -795,17 +822,23 @@ class RVDetails(MDRecycleView):
|
||||
if nhi and nhi != "None":
|
||||
self.entries.append({"icon": "routes", "text": f"Current path on [b]{nhi}[/b]", "on_release": pass_job})
|
||||
|
||||
try:
|
||||
ler = self.delegate.app.sideband.get_destination_establishment_rate(self.delegate.object_hash)
|
||||
if ler:
|
||||
lers = RNS.prettyspeed(ler, "b")
|
||||
self.entries.append({"icon": "lock-check-outline", "text": f"Direct link established, LER is [b]{lers}[/b]", "on_release": pass_job})
|
||||
except Exception as e:
|
||||
RNS.trace_exception(e)
|
||||
|
||||
if nh != RNS.Transport.PATHFINDER_M:
|
||||
hs = "hop" if nh == 1 else "hops"
|
||||
self.entries.append({"icon": "atom-variant", "text": f"Network distance is [b]{nh} {hs}[/b]", "on_release": pass_job})
|
||||
|
||||
try:
|
||||
ler = self.delegate.app.sideband.get_destination_establishment_rate(self.delegate.object_hash)
|
||||
mtu = self.delegate.app.sideband.get_destination_mtu(self.delegate.object_hash) or RNS.Reticulum.MTU
|
||||
edr = self.delegate.app.sideband.get_destination_edr(self.delegate.object_hash)
|
||||
if ler:
|
||||
lers = RNS.prettyspeed(ler, "b")
|
||||
mtus = RNS.prettysize(mtu)
|
||||
edrs = f"{RNS.prettyspeed(edr)}" if edr != None else ""
|
||||
self.entries.append({"icon": "lock-check-outline", "text": f"Link established, LER is [b]{lers}[/b], MTU is [b]{mtus}[/b]", "on_release": pass_job})
|
||||
if edr: self.entries.append({"icon": "approximately-equal", "text": f"Expected data rate is [b]{edrs}[/b]", "on_release": pass_job})
|
||||
except Exception as e:
|
||||
RNS.trace_exception(e)
|
||||
|
||||
except Exception as e:
|
||||
RNS.trace_exception(e)
|
||||
|
||||
@ -972,22 +1005,22 @@ MDScreen:
|
||||
on_release: root.delegate.request_update()
|
||||
disabled: False
|
||||
|
||||
# MDBoxLayout:
|
||||
# orientation: "horizontal"
|
||||
# spacing: dp(16)
|
||||
# size_hint_y: None
|
||||
# height: self.minimum_height
|
||||
# padding: [dp(24), dp(16), dp(24), dp(24)]
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
spacing: dp(16)
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(24), dp(0), dp(24), dp(24)]
|
||||
|
||||
# MDRectangleFlatIconButton:
|
||||
# id: delete_button
|
||||
# icon: "trash-can-outline"
|
||||
# text: "Delete All Telemetry"
|
||||
# padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
# icon_size: dp(24)
|
||||
# font_size: dp(16)
|
||||
# size_hint: [1.0, None]
|
||||
# on_release: root.delegate.copy_telemetry(self)
|
||||
# disabled: False
|
||||
MDRectangleFlatIconButton:
|
||||
id: track_button
|
||||
icon: "crosshairs-gps"
|
||||
text: "Start Live Tracking"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.live_tracking(self)
|
||||
disabled: False
|
||||
|
||||
"""
|
@ -44,6 +44,30 @@ class Telemetry():
|
||||
else:
|
||||
self.screen.ids.telemetry_collector.text = RNS.hexrep(self.app.sideband.config["telemetry_collector"], delimit=False)
|
||||
|
||||
self.screen.ids.telemetry_mqtt_host.bind(focus=self.telemetry_save)
|
||||
if self.app.sideband.config["telemetry_mqtt_host"] == None:
|
||||
self.screen.ids.telemetry_mqtt_host.text = ""
|
||||
else:
|
||||
self.screen.ids.telemetry_mqtt_host.text = self.app.sideband.config["telemetry_mqtt_host"]
|
||||
|
||||
self.screen.ids.telemetry_mqtt_port.bind(focus=self.telemetry_save)
|
||||
if self.app.sideband.config["telemetry_mqtt_port"] == None:
|
||||
self.screen.ids.telemetry_mqtt_port.text = ""
|
||||
else:
|
||||
self.screen.ids.telemetry_mqtt_port.text = self.app.sideband.config["telemetry_mqtt_port"]
|
||||
|
||||
self.screen.ids.telemetry_mqtt_user.bind(focus=self.telemetry_save)
|
||||
if self.app.sideband.config["telemetry_mqtt_user"] == None:
|
||||
self.screen.ids.telemetry_mqtt_user.text = ""
|
||||
else:
|
||||
self.screen.ids.telemetry_mqtt_user.text = self.app.sideband.config["telemetry_mqtt_user"]
|
||||
|
||||
self.screen.ids.telemetry_mqtt_pass.bind(focus=self.telemetry_save)
|
||||
if self.app.sideband.config["telemetry_mqtt_pass"] == None:
|
||||
self.screen.ids.telemetry_mqtt_pass.text = ""
|
||||
else:
|
||||
self.screen.ids.telemetry_mqtt_pass.text = self.app.sideband.config["telemetry_mqtt_pass"]
|
||||
|
||||
self.screen.ids.telemetry_icon_preview.icon_color = self.app.sideband.config["telemetry_fg"]
|
||||
self.screen.ids.telemetry_icon_preview.md_bg_color = self.app.sideband.config["telemetry_bg"]
|
||||
self.screen.ids.telemetry_icon_preview.icon = self.app.sideband.config["telemetry_icon"]
|
||||
@ -83,6 +107,9 @@ class Telemetry():
|
||||
|
||||
self.screen.ids.telemetry_allow_requests_from_anyone.active = self.app.sideband.config["telemetry_allow_requests_from_anyone"]
|
||||
self.screen.ids.telemetry_allow_requests_from_anyone.bind(active=self.telemetry_save)
|
||||
|
||||
self.screen.ids.telemetry_to_mqtt.active = self.app.sideband.config["telemetry_to_mqtt"]
|
||||
self.screen.ids.telemetry_to_mqtt.bind(active=self.telemetry_save)
|
||||
|
||||
|
||||
self.screen.ids.telemetry_scrollview.effect_cls = ScrollEffect
|
||||
@ -259,6 +286,11 @@ class Telemetry():
|
||||
self.app.sideband.config["telemetry_allow_requests_from_trusted"] = self.screen.ids.telemetry_allow_requests_from_trusted.active
|
||||
self.app.sideband.config["telemetry_allow_requests_from_anyone"] = self.screen.ids.telemetry_allow_requests_from_anyone.active
|
||||
self.app.sideband.config["telemetry_collector_enabled"] = self.screen.ids.telemetry_collector_enabled.active
|
||||
self.app.sideband.config["telemetry_to_mqtt"] = self.screen.ids.telemetry_to_mqtt.active
|
||||
self.app.sideband.config["telemetry_mqtt_host"] = self.screen.ids.telemetry_mqtt_host.text
|
||||
self.app.sideband.config["telemetry_mqtt_port"] = self.screen.ids.telemetry_mqtt_port.text
|
||||
self.app.sideband.config["telemetry_mqtt_user"] = self.screen.ids.telemetry_mqtt_user.text
|
||||
self.app.sideband.config["telemetry_mqtt_pass"] = self.screen.ids.telemetry_mqtt_pass.text
|
||||
|
||||
self.app.sideband.save_configuration()
|
||||
if run_telemetry_update:
|
||||
@ -366,6 +398,8 @@ class Telemetry():
|
||||
self.sensors_screen.ids.telemetry_s_accelerometer.bind(active=self.sensors_save)
|
||||
self.sensors_screen.ids.telemetry_s_proximity.active = self.app.sideband.config["telemetry_s_proximity"]
|
||||
self.sensors_screen.ids.telemetry_s_proximity.bind(active=self.sensors_save)
|
||||
self.sensors_screen.ids.telemetry_s_rns_transport.active = self.app.sideband.config["telemetry_s_rns_transport"]
|
||||
self.sensors_screen.ids.telemetry_s_rns_transport.bind(active=self.sensors_save)
|
||||
self.sensors_screen.ids.telemetry_s_information.active = self.app.sideband.config["telemetry_s_information"]
|
||||
self.sensors_screen.ids.telemetry_s_information.bind(active=self.sensors_save)
|
||||
self.sensors_screen.ids.telemetry_s_information_text.text = str(self.app.sideband.config["telemetry_s_information_text"])
|
||||
@ -434,6 +468,7 @@ class Telemetry():
|
||||
self.app.sideband.config["telemetry_s_angular_velocity"] = self.sensors_screen.ids.telemetry_s_gyroscope.active
|
||||
self.app.sideband.config["telemetry_s_acceleration"] = self.sensors_screen.ids.telemetry_s_accelerometer.active
|
||||
self.app.sideband.config["telemetry_s_proximity"] = self.sensors_screen.ids.telemetry_s_proximity.active
|
||||
self.app.sideband.config["telemetry_s_rns_transport"] = self.sensors_screen.ids.telemetry_s_rns_transport.active
|
||||
|
||||
if self.app.sideband.config["telemetry_s_information"] != self.sensors_screen.ids.telemetry_s_information.active:
|
||||
run_telemetry_update = True
|
||||
@ -880,6 +915,90 @@ MDScreen:
|
||||
on_release: root.delegate.telemetry_bg_color(self)
|
||||
disabled: False
|
||||
|
||||
MDLabel:
|
||||
text: "MQTT Configuration"
|
||||
font_style: "H6"
|
||||
|
||||
MDLabel:
|
||||
id: telemetry_info6
|
||||
markup: True
|
||||
text: "\\nFor integration with other systems, you can configure Sideband to send all known telemetry data to an MQTT server in real-time as it is received or generated.\\n"
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Send telemetry to MQTT"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_to_mqtt
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
padding: [dp(0),dp(0),dp(0),dp(0)]
|
||||
#height: dp(232)
|
||||
height: self.minimum_height
|
||||
|
||||
MDTextField:
|
||||
id: telemetry_mqtt_host
|
||||
hint_text: "Server Hostname"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
padding: [dp(0),dp(0),dp(0),dp(0)]
|
||||
#height: dp(232)
|
||||
height: self.minimum_height
|
||||
|
||||
MDTextField:
|
||||
id: telemetry_mqtt_port
|
||||
hint_text: "Server Port"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
padding: [dp(0),dp(0),dp(0),dp(0)]
|
||||
#height: dp(232)
|
||||
height: self.minimum_height
|
||||
|
||||
MDTextField:
|
||||
id: telemetry_mqtt_user
|
||||
hint_text: "Username"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
padding: [dp(0),dp(0),dp(0),dp(60)]
|
||||
#height: dp(232)
|
||||
height: self.minimum_height
|
||||
|
||||
MDTextField:
|
||||
id: telemetry_mqtt_pass
|
||||
password: True
|
||||
hint_text: "Password"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDLabel:
|
||||
text: "Advanced Configuration"
|
||||
font_style: "H6"
|
||||
@ -1211,6 +1330,21 @@ MDScreen:
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Reticulum Transport Stats"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_s_rns_transport
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
|
470
sbapp/ui/utilities.py
Normal file
470
sbapp/ui/utilities.py
Normal file
@ -0,0 +1,470 @@
|
||||
import time
|
||||
import RNS
|
||||
|
||||
from typing import Union
|
||||
from kivy.metrics import dp,sp
|
||||
from kivy.lang.builder import Builder
|
||||
from kivy.core.clipboard import Clipboard
|
||||
from kivy.utils import escape_markup
|
||||
from kivymd.uix.recycleview import MDRecycleView
|
||||
from kivymd.uix.list import OneLineIconListItem
|
||||
from kivymd.uix.pickers import MDColorPicker
|
||||
from kivymd.uix.button import MDRectangleFlatButton
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
from kivymd.icon_definitions import md_icons
|
||||
from kivymd.toast import toast
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivy.effects.scroll import ScrollEffect
|
||||
from kivy.clock import Clock
|
||||
from sideband.sense import Telemeter
|
||||
import threading
|
||||
from datetime import datetime
|
||||
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
from ui.helpers import ts_format
|
||||
from android.permissions import request_permissions, check_permission
|
||||
else:
|
||||
from .helpers import ts_format
|
||||
|
||||
class Utilities():
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.screen = None
|
||||
self.rnstatus_screen = None
|
||||
self.rnstatus_instance = None
|
||||
self.logviewer_screen = None
|
||||
|
||||
if not self.app.root.ids.screen_manager.has_screen("utilities_screen"):
|
||||
self.screen = Builder.load_string(layout_utilities_screen)
|
||||
self.screen.app = self.app
|
||||
self.screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.screen)
|
||||
|
||||
self.screen.ids.utilities_scrollview.effect_cls = ScrollEffect
|
||||
info = "This section contains various utilities and diagnostics tools, "
|
||||
info += "that can be helpful while using Sideband and Reticulum."
|
||||
|
||||
if self.app.theme_cls.theme_style == "Dark":
|
||||
info = "[color=#"+self.app.dark_theme_text_color+"]"+info+"[/color]"
|
||||
|
||||
self.screen.ids.utilities_info.text = info
|
||||
|
||||
|
||||
### RNode Flasher
|
||||
######################################
|
||||
|
||||
def flasher_action(self, sender=None):
|
||||
yes_button = MDRectangleFlatButton(text="Launch",font_size=dp(18), theme_text_color="Custom", line_color=self.app.color_accept, text_color=self.app.color_accept)
|
||||
no_button = MDRectangleFlatButton(text="Back",font_size=dp(18))
|
||||
dialog = MDDialog(
|
||||
title="RNode Flasher",
|
||||
text="You can use the included web-based RNode flasher, by starting Sideband's built-in repository server, and accessing the RNode Flasher page.",
|
||||
buttons=[ no_button, yes_button ],
|
||||
# elevation=0,
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
self.app.wants_flasher_launch = True
|
||||
self.app.sideband.start_webshare()
|
||||
def cb(dt):
|
||||
self.app.repository_action()
|
||||
Clock.schedule_once(cb, 0.6)
|
||||
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
dialog.open()
|
||||
|
||||
|
||||
### rnstatus screen
|
||||
######################################
|
||||
|
||||
def rnstatus_action(self, sender=None):
|
||||
if not self.app.root.ids.screen_manager.has_screen("rnstatus_screen"):
|
||||
self.rnstatus_screen = Builder.load_string(layout_rnstatus_screen)
|
||||
self.rnstatus_screen.app = self.app
|
||||
self.rnstatus_screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.rnstatus_screen)
|
||||
|
||||
self.app.root.ids.screen_manager.transition.direction = "left"
|
||||
self.app.root.ids.screen_manager.current = "rnstatus_screen"
|
||||
self.app.sideband.setstate("app.displaying", self.app.root.ids.screen_manager.current)
|
||||
|
||||
self.update_rnstatus()
|
||||
|
||||
def update_rnstatus(self, sender=None):
|
||||
threading.Thread(target=self.update_rnstatus_job, daemon=True).start()
|
||||
|
||||
def update_rnstatus_job(self, sender=None):
|
||||
if self.rnstatus_instance == None:
|
||||
import RNS.Utilities.rnstatus as rnstatus
|
||||
self.rnstatus_instance = rnstatus
|
||||
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
output = "None"
|
||||
with io.StringIO() as buffer, redirect_stdout(buffer):
|
||||
with RNS.logging_lock:
|
||||
self.rnstatus_instance.main(rns_instance=RNS.Reticulum.get_instance())
|
||||
output = buffer.getvalue()
|
||||
|
||||
def cb(dt):
|
||||
self.rnstatus_screen.ids.rnstatus_output.text = f"[font=RobotoMono-Regular][size={int(dp(12))}]{output}[/size][/font]"
|
||||
Clock.schedule_once(cb, 0.2)
|
||||
|
||||
if self.app.root.ids.screen_manager.current == "rnstatus_screen":
|
||||
Clock.schedule_once(self.update_rnstatus, 1)
|
||||
|
||||
### Advanced Configuration screen
|
||||
######################################
|
||||
|
||||
def advanced_action(self, sender=None):
|
||||
if not self.app.root.ids.screen_manager.has_screen("advanced_screen"):
|
||||
self.advanced_screen = Builder.load_string(layout_advanced_screen)
|
||||
self.advanced_screen.app = self.app
|
||||
self.advanced_screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.advanced_screen)
|
||||
|
||||
self.app.root.ids.screen_manager.transition.direction = "left"
|
||||
self.app.root.ids.screen_manager.current = "advanced_screen"
|
||||
self.app.sideband.setstate("app.displaying", self.app.root.ids.screen_manager.current)
|
||||
|
||||
self.update_advanced()
|
||||
|
||||
def update_advanced(self, sender=None):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
ct = self.app.sideband.config["config_template"]
|
||||
if ct == None:
|
||||
ct = self.app.sideband.default_config_template
|
||||
self.advanced_screen.ids.config_template.text = f"[font=RobotoMono-Regular][size={int(dp(12))}]{ct}[/size][/font]"
|
||||
else:
|
||||
self.advanced_screen.ids.config_template.text = f"[font=RobotoMono-Regular][size={int(dp(12))}]On this platform, Reticulum configuration is managed by the system. You can change the configuration by editing the file located at:\n\n{self.app.sideband.reticulum.configpath}[/size][/font]"
|
||||
|
||||
def reset_config(self, sender=None):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.app.sideband.config["config_template"] = None
|
||||
self.app.sideband.save_configuration()
|
||||
self.update_advanced()
|
||||
|
||||
def copy_config(self, sender=None):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
if self.app.sideband.config["config_template"]:
|
||||
Clipboard.copy(self.app.sideband.config["config_template"])
|
||||
else:
|
||||
Clipboard.copy(self.app.sideband.default_config_template)
|
||||
|
||||
def paste_config(self, sender=None):
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
self.app.sideband.config_template = Clipboard.paste()
|
||||
self.app.sideband.config["config_template"] = self.app.sideband.config_template
|
||||
self.app.sideband.save_configuration()
|
||||
self.update_advanced()
|
||||
|
||||
### Log viewer screen
|
||||
######################################
|
||||
|
||||
def logviewer_action(self, sender=None):
|
||||
if not self.app.root.ids.screen_manager.has_screen("logviewer_screen"):
|
||||
self.logviewer_screen = Builder.load_string(layout_logviewer_screen)
|
||||
self.logviewer_screen.app = self.app
|
||||
self.logviewer_screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.logviewer_screen)
|
||||
|
||||
self.app.root.ids.screen_manager.transition.direction = "left"
|
||||
self.app.root.ids.screen_manager.current = "logviewer_screen"
|
||||
self.app.sideband.setstate("app.displaying", self.app.root.ids.screen_manager.current)
|
||||
|
||||
self.update_logviewer()
|
||||
|
||||
def update_logviewer(self, sender=None):
|
||||
threading.Thread(target=self.update_logviewer_job, daemon=True).start()
|
||||
|
||||
def update_logviewer_job(self, sender=None):
|
||||
try:
|
||||
output = self.app.sideband.get_log()
|
||||
except Exception as e:
|
||||
output = f"An error occurred while retrieving log entries:\n{e}"
|
||||
|
||||
self.logviewer_screen.log_contents = output
|
||||
def cb(dt):
|
||||
self.logviewer_screen.ids.logviewer_output.text = f"[font=RobotoMono-Regular][size={int(dp(12))}]{output}[/size][/font]"
|
||||
Clock.schedule_once(cb, 0.2)
|
||||
|
||||
if self.app.root.ids.screen_manager.current == "logviewer_screen":
|
||||
Clock.schedule_once(self.update_logviewer, 1)
|
||||
|
||||
def logviewer_copy(self, sender=None):
|
||||
Clipboard.copy(self.logviewer_screen.log_contents)
|
||||
if True or RNS.vendor.platformutils.is_android():
|
||||
toast("Log copied to clipboard")
|
||||
|
||||
|
||||
layout_utilities_screen = """
|
||||
MDScreen:
|
||||
name: "utilities_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
title: "Utilities"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['close', lambda x: root.app.close_any_action(self)],
|
||||
]
|
||||
|
||||
ScrollView:
|
||||
id: utilities_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(28), dp(32), dp(28), dp(16)]
|
||||
|
||||
# MDLabel:
|
||||
# text: "Utilities & Tools"
|
||||
# font_style: "H6"
|
||||
|
||||
MDLabel:
|
||||
id: utilities_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(35), dp(0), dp(35)]
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: rnstatus_button
|
||||
icon: "wifi-check"
|
||||
text: "Reticulum Status"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.rnstatus_action(self)
|
||||
disabled: False
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: logview_button
|
||||
icon: "list-box-outline"
|
||||
text: "Log Viewer"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.logviewer_action(self)
|
||||
disabled: False
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: flasher_button
|
||||
icon: "radio-handheld"
|
||||
text: "RNode Flasher"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.flasher_action(self)
|
||||
disabled: False
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: advanced_button
|
||||
icon: "network-pos"
|
||||
text: "Advanced RNS Configuration"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.advanced_action(self)
|
||||
disabled: False
|
||||
|
||||
"""
|
||||
|
||||
layout_rnstatus_screen = """
|
||||
MDScreen:
|
||||
name: "rnstatus_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
id: top_bar
|
||||
title: "Reticulum Status"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
# ['refresh', lambda x: root.delegate.update_rnstatus()],
|
||||
['close', lambda x: root.app.close_sub_utilities_action(self)],
|
||||
]
|
||||
|
||||
MDScrollView:
|
||||
id: rnstatus_scrollview
|
||||
size_hint_x: 1
|
||||
size_hint_y: None
|
||||
size: [root.width, root.height-root.ids.top_bar.height]
|
||||
do_scroll_x: False
|
||||
do_scroll_y: True
|
||||
|
||||
MDGridLayout:
|
||||
cols: 1
|
||||
padding: [dp(28), dp(14), dp(28), dp(28)]
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
MDLabel:
|
||||
id: rnstatus_output
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
"""
|
||||
|
||||
layout_logviewer_screen = """
|
||||
MDScreen:
|
||||
name: "logviewer_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
id: top_bar
|
||||
title: "Log Viewer"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['content-copy', lambda x: root.delegate.logviewer_copy()],
|
||||
['close', lambda x: root.app.close_sub_utilities_action(self)],
|
||||
]
|
||||
|
||||
MDScrollView:
|
||||
id: logviewer_scrollview
|
||||
size_hint_x: 1
|
||||
size_hint_y: None
|
||||
size: [root.width, root.height-root.ids.top_bar.height]
|
||||
do_scroll_x: False
|
||||
do_scroll_y: True
|
||||
|
||||
MDGridLayout:
|
||||
cols: 1
|
||||
padding: [dp(28), dp(14), dp(28), dp(28)]
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
MDLabel:
|
||||
id: logviewer_output
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
"""
|
||||
|
||||
layout_advanced_screen = """
|
||||
MDScreen:
|
||||
name: "advanced_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
id: top_bar
|
||||
title: "RNS Configuration"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
# ['refresh', lambda x: root.delegate.update_rnstatus()],
|
||||
['close', lambda x: root.app.close_sub_utilities_action(self)],
|
||||
]
|
||||
|
||||
MDScrollView:
|
||||
id: advanced_scrollview
|
||||
size_hint_x: 1
|
||||
size_hint_y: None
|
||||
size: [root.width, root.height-root.ids.top_bar.height]
|
||||
do_scroll_x: False
|
||||
do_scroll_y: True
|
||||
|
||||
MDGridLayout:
|
||||
cols: 1
|
||||
padding: [dp(28), dp(14), dp(28), dp(28)]
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(14), dp(0), dp(24)]
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: conf_copy_button
|
||||
icon: "content-copy"
|
||||
text: "Copy Configuration"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.copy_config(self)
|
||||
disabled: False
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: conf_paste_button
|
||||
icon: "download"
|
||||
text: "Paste Configuration"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.paste_config(self)
|
||||
disabled: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(0), dp(0), dp(24)]
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: conf_reset_button
|
||||
icon: "cog-counterclockwise"
|
||||
text: "Reset Configuration"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.reset_config(self)
|
||||
disabled: False
|
||||
|
||||
MDLabel:
|
||||
id: config_template
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
"""
|
481
sbapp/ui/voice.py
Normal file
481
sbapp/ui/voice.py
Normal file
@ -0,0 +1,481 @@
|
||||
import time
|
||||
import RNS
|
||||
|
||||
from typing import Union
|
||||
from kivy.metrics import dp,sp
|
||||
from kivy.lang.builder import Builder
|
||||
from kivy.core.clipboard import Clipboard
|
||||
from kivy.utils import escape_markup
|
||||
from kivymd.uix.recycleview import MDRecycleView
|
||||
from kivymd.uix.list import OneLineIconListItem
|
||||
from kivymd.uix.pickers import MDColorPicker
|
||||
from kivymd.uix.button import MDRectangleFlatButton
|
||||
from kivymd.uix.button import MDRectangleFlatIconButton
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
from kivymd.icon_definitions import md_icons
|
||||
from kivymd.toast import toast
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivy.effects.scroll import ScrollEffect
|
||||
from kivy.clock import Clock
|
||||
from sideband.sense import Telemeter
|
||||
import threading
|
||||
from datetime import datetime
|
||||
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
from ui.helpers import ts_format
|
||||
from android.permissions import request_permissions, check_permission
|
||||
else:
|
||||
from .helpers import ts_format
|
||||
|
||||
class Voice():
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.screen = None
|
||||
self.settings_screen = None
|
||||
self.dial_target = None
|
||||
self.ui_updater = None
|
||||
self.path_requesting = None
|
||||
self.output_devices = []
|
||||
self.input_devices = []
|
||||
self.listed_output_devices = []
|
||||
self.listed_input_devices = []
|
||||
self.listed_ringer_devices = []
|
||||
|
||||
if not self.app.root.ids.screen_manager.has_screen("voice_screen"):
|
||||
self.screen = Builder.load_string(layout_voice_screen)
|
||||
self.screen.app = self.app
|
||||
self.screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.screen)
|
||||
|
||||
self.screen.ids.voice_scrollview.effect_cls = ScrollEffect
|
||||
|
||||
def update_call_status(self, dt=None):
|
||||
if self.app.root.ids.screen_manager.current == "voice_screen":
|
||||
if self.ui_updater == None: self.ui_updater = Clock.schedule_interval(self.update_call_status, 0.5)
|
||||
else:
|
||||
if self.ui_updater:
|
||||
self.ui_updater.cancel()
|
||||
self.ui_updater = None
|
||||
|
||||
db = self.screen.ids.dial_button
|
||||
ih = self.screen.ids.identity_hash
|
||||
if self.app.sideband.voice_running:
|
||||
telephone = self.app.sideband.telephone
|
||||
if self.path_requesting:
|
||||
db.disabled = True
|
||||
ih.disabled = True
|
||||
|
||||
else:
|
||||
if telephone.is_available:
|
||||
ih.disabled = False
|
||||
self.target_input_action(ih)
|
||||
else:
|
||||
ih.disabled = True
|
||||
|
||||
if telephone.is_in_call or telephone.call_is_connecting:
|
||||
ih.disabled = True
|
||||
db.disabled = False
|
||||
db.text = "Hang up"
|
||||
db.icon = "phone-hangup"
|
||||
|
||||
elif telephone.is_ringing:
|
||||
ih.disabled = True
|
||||
db.disabled = False
|
||||
db.text = "Answer"
|
||||
db.icon = "phone-ring"
|
||||
if telephone.caller: ih.text = RNS.hexrep(telephone.caller.hash, delimit=False)
|
||||
|
||||
else:
|
||||
db.disabled = True; db.text = "Voice calls disabled"
|
||||
ih.disabled = True
|
||||
|
||||
def target_valid(self):
|
||||
if self.app.sideband.voice_running:
|
||||
db = self.screen.ids.dial_button
|
||||
db.disabled = False; db.text = "Call"
|
||||
db.icon = "phone-outgoing"
|
||||
|
||||
def target_invalid(self):
|
||||
if self.app.sideband.voice_running:
|
||||
db = self.screen.ids.dial_button
|
||||
db.disabled = True; db.text = "Call"
|
||||
db.icon = "phone-outgoing"
|
||||
|
||||
def target_input_action(self, sender):
|
||||
if sender:
|
||||
target_hash = sender.text
|
||||
if len(target_hash) == RNS.Reticulum.TRUNCATED_HASHLENGTH//8*2:
|
||||
try:
|
||||
identity_hash = bytes.fromhex(target_hash)
|
||||
self.dial_target = identity_hash
|
||||
self.target_valid()
|
||||
|
||||
except Exception as e: self.target_invalid()
|
||||
else: self.target_invalid()
|
||||
|
||||
def request_path(self, destination_hash):
|
||||
if not self.path_requesting:
|
||||
self.app.sideband.telephone.set_busy(True)
|
||||
toast("Requesting path...")
|
||||
self.screen.ids.dial_button.disabled = True
|
||||
self.path_requesting = destination_hash
|
||||
RNS.Transport.request_path(destination_hash)
|
||||
threading.Thread(target=self._path_wait_job, daemon=True).start()
|
||||
|
||||
else:
|
||||
toast("Waiting for path request answer...")
|
||||
|
||||
def _path_wait_job(self):
|
||||
timeout = time.time()+self.app.sideband.telephone.PATH_TIME
|
||||
while not RNS.Transport.has_path(self.path_requesting) and time.time() < timeout:
|
||||
time.sleep(0.25)
|
||||
|
||||
self.app.sideband.telephone.set_busy(False)
|
||||
if RNS.Transport.has_path(self.path_requesting):
|
||||
RNS.log(f"Calling {RNS.prettyhexrep(self.dial_target)}...", RNS.LOG_DEBUG)
|
||||
self.app.sideband.telephone.dial(self.dial_target)
|
||||
Clock.schedule_once(self.update_call_status, 0.1)
|
||||
|
||||
else:
|
||||
Clock.schedule_once(self._path_request_failed, 0.05)
|
||||
Clock.schedule_once(self.update_call_status, 0.1)
|
||||
|
||||
self.path_requesting = None
|
||||
self.update_call_status()
|
||||
|
||||
def _path_request_failed(self, dt):
|
||||
toast("Path request timed out")
|
||||
|
||||
def dial_action(self, sender=None):
|
||||
if self.app.sideband.voice_running:
|
||||
if self.app.sideband.telephone.is_available:
|
||||
|
||||
destination_hash = RNS.Destination.hash_from_name_and_identity("lxst.telephony", self.dial_target)
|
||||
if not RNS.Transport.has_path(destination_hash):
|
||||
self.request_path(destination_hash)
|
||||
|
||||
else:
|
||||
RNS.log(f"Calling {RNS.prettyhexrep(self.dial_target)}...", RNS.LOG_DEBUG)
|
||||
self.app.sideband.telephone.dial(self.dial_target)
|
||||
self.update_call_status()
|
||||
|
||||
elif self.app.sideband.telephone.is_in_call or self.app.sideband.telephone.call_is_connecting:
|
||||
RNS.log(f"Hanging up", RNS.LOG_DEBUG)
|
||||
self.app.sideband.telephone.hangup()
|
||||
self.update_call_status()
|
||||
|
||||
elif self.app.sideband.telephone.is_ringing:
|
||||
RNS.log(f"Answering", RNS.LOG_DEBUG)
|
||||
self.app.sideband.telephone.answer()
|
||||
self.update_call_status()
|
||||
|
||||
|
||||
### settings screen
|
||||
######################################
|
||||
|
||||
def settings_action(self, sender=None):
|
||||
if not self.app.root.ids.screen_manager.has_screen("voice_settings_screen"):
|
||||
self.voice_settings_screen = Builder.load_string(layout_voice_settings_screen)
|
||||
self.voice_settings_screen.app = self.app
|
||||
self.voice_settings_screen.delegate = self
|
||||
self.app.root.ids.screen_manager.add_widget(self.voice_settings_screen)
|
||||
|
||||
self.app.root.ids.screen_manager.transition.direction = "left"
|
||||
self.app.root.ids.screen_manager.current = "voice_settings_screen"
|
||||
self.voice_settings_screen.ids.voice_settings_scrollview.effect_cls = ScrollEffect
|
||||
self.app.sideband.setstate("app.displaying", self.app.root.ids.screen_manager.current)
|
||||
|
||||
self.update_settings_screen()
|
||||
|
||||
def update_devices(self):
|
||||
import LXST
|
||||
self.output_devices = []; self.input_devices = []
|
||||
for device in LXST.Sources.Backend().soundcard.all_speakers(): self.output_devices.append(device.name)
|
||||
for device in LXST.Sinks.Backend().soundcard.all_microphones(): self.input_devices.append(device.name)
|
||||
if self.app.sideband.config["voice_output"] != None:
|
||||
if not self.app.sideband.config["voice_output"] in self.output_devices: self.output_devices.append(self.app.sideband.config["voice_output"])
|
||||
if self.app.sideband.config["voice_input"] != None:
|
||||
if not self.app.sideband.config["voice_input"] in self.input_devices: self.input_devices.append(self.app.sideband.config["voice_input"])
|
||||
if self.app.sideband.config["voice_ringer"] != None:
|
||||
if not self.app.sideband.config["voice_ringer"] in self.output_devices: self.output_devices.append(self.app.sideband.config["voice_ringer"])
|
||||
|
||||
def update_settings_screen(self, sender=None):
|
||||
self.voice_settings_screen.ids.voice_trusted_only.active = self.app.sideband.config["voice_trusted_only"]
|
||||
self.voice_settings_screen.ids.voice_trusted_only.bind(active=self.settings_save_action)
|
||||
|
||||
bp = 6; ml = 45; fs = 16; ics = 14
|
||||
self.update_devices()
|
||||
|
||||
# Output devices
|
||||
if not "system_default" in self.listed_output_devices:
|
||||
default_output_button = MDRectangleFlatIconButton(text="System Default", font_size=dp(fs), icon_size=dp(ics), on_release=self.output_device_action)
|
||||
default_output_button.device = None; default_output_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_output"] == None: default_output_button.icon = "check"
|
||||
self.voice_settings_screen.ids.output_devices.add_widget(default_output_button)
|
||||
self.listed_output_devices.append("system_default")
|
||||
|
||||
for device in self.output_devices:
|
||||
if not device in self.listed_output_devices:
|
||||
label = device if len(device) < ml else device[:ml-3]+"..."
|
||||
device_button = MDRectangleFlatIconButton(text=label, font_size=dp(fs), icon_size=dp(ics), on_release=self.output_device_action)
|
||||
device_button.padding = [dp(bp), dp(bp), dp(bp), dp(bp)]; device_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_output"] == device: device_button.icon = "check"
|
||||
device_button.device = device
|
||||
self.voice_settings_screen.ids.output_devices.add_widget(device_button)
|
||||
self.listed_output_devices.append(device)
|
||||
|
||||
# Input devices
|
||||
if not "system_default" in self.listed_input_devices:
|
||||
default_input_button = MDRectangleFlatIconButton(text="System Default", font_size=dp(fs), icon_size=dp(ics), on_release=self.input_device_action)
|
||||
default_input_button.device = None; default_input_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_output"] == None: default_input_button.icon = "check"
|
||||
self.voice_settings_screen.ids.input_devices.add_widget(default_input_button)
|
||||
self.listed_input_devices.append("system_default")
|
||||
|
||||
for device in self.input_devices:
|
||||
if not device in self.listed_input_devices:
|
||||
label = device if len(device) < ml else device[:ml-3]+"..."
|
||||
device_button = MDRectangleFlatIconButton(text=label, font_size=dp(fs), icon_size=dp(ics), on_release=self.input_device_action)
|
||||
device_button.padding = [dp(bp), dp(bp), dp(bp), dp(bp)]; device_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_input"] == device: device_button.icon = "check"
|
||||
device_button.device = device
|
||||
self.voice_settings_screen.ids.input_devices.add_widget(device_button)
|
||||
self.listed_input_devices.append(device)
|
||||
|
||||
# Ringer devices
|
||||
if not "system_default" in self.listed_ringer_devices:
|
||||
default_ringer_button = MDRectangleFlatIconButton(text="System Default", font_size=dp(fs), icon_size=dp(ics), on_release=self.ringer_device_action)
|
||||
default_ringer_button.device = None; default_ringer_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_ringer"] == None: default_ringer_button.icon = "check"
|
||||
self.voice_settings_screen.ids.ringer_devices.add_widget(default_ringer_button)
|
||||
self.listed_ringer_devices.append("system_default")
|
||||
|
||||
for device in self.output_devices:
|
||||
if not device in self.listed_ringer_devices:
|
||||
label = device if len(device) < ml else device[:ml-3]+"..."
|
||||
device_button = MDRectangleFlatIconButton(text=label, font_size=dp(fs), icon_size=dp(ics), on_release=self.ringer_device_action)
|
||||
device_button.padding = [dp(bp), dp(bp), dp(bp), dp(bp)]; device_button.size_hint = [1.0, None]
|
||||
if self.app.sideband.config["voice_ringer"] == device: device_button.icon = "check"
|
||||
device_button.device = device
|
||||
self.voice_settings_screen.ids.ringer_devices.add_widget(device_button)
|
||||
self.listed_ringer_devices.append(device)
|
||||
|
||||
def settings_save_action(self, sender=None, event=None):
|
||||
self.app.sideband.config["voice_trusted_only"] = self.voice_settings_screen.ids.voice_trusted_only.active
|
||||
self.app.sideband.save_configuration()
|
||||
|
||||
def output_device_action(self, sender=None):
|
||||
self.app.sideband.config["voice_output"] = sender.device
|
||||
self.app.sideband.save_configuration()
|
||||
for w in self.voice_settings_screen.ids.output_devices.children: w.icon = ""
|
||||
sender.icon = "check"
|
||||
if self.app.sideband.telephone:
|
||||
self.app.sideband.telephone.set_speaker(self.app.sideband.config["voice_output"])
|
||||
|
||||
def input_device_action(self, sender=None):
|
||||
self.app.sideband.config["voice_input"] = sender.device
|
||||
self.app.sideband.save_configuration()
|
||||
for w in self.voice_settings_screen.ids.input_devices.children: w.icon = ""
|
||||
sender.icon = "check"
|
||||
if self.app.sideband.telephone:
|
||||
self.app.sideband.telephone.set_microphone(self.app.sideband.config["voice_input"])
|
||||
|
||||
def ringer_device_action(self, sender=None):
|
||||
self.app.sideband.config["voice_ringer"] = sender.device
|
||||
self.app.sideband.save_configuration()
|
||||
for w in self.voice_settings_screen.ids.ringer_devices.children: w.icon = ""
|
||||
sender.icon = "check"
|
||||
if self.app.sideband.telephone:
|
||||
self.app.sideband.telephone.set_ringer(self.app.sideband.config["voice_ringer"])
|
||||
|
||||
|
||||
layout_voice_screen = """
|
||||
MDScreen:
|
||||
name: "voice_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
title: "Voice"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['wrench-cog', lambda x: root.delegate.settings_action(self)],
|
||||
['close', lambda x: root.app.close_any_action(self)],
|
||||
]
|
||||
|
||||
ScrollView:
|
||||
id: voice_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(28), dp(32), dp(28), dp(16)]
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(12), dp(0), dp(0)]
|
||||
|
||||
MDTextField:
|
||||
id: identity_hash
|
||||
hint_text: "Identity hash"
|
||||
mode: "rectangle"
|
||||
# size_hint: [1.0, None]
|
||||
pos_hint: {"center_x": .5}
|
||||
max_text_length: 32
|
||||
on_text: root.delegate.target_input_action(self)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(35), dp(0), dp(35)]
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: dial_button
|
||||
icon: "phone-outgoing"
|
||||
text: "Call"
|
||||
padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
icon_size: dp(24)
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.delegate.dial_action(self)
|
||||
disabled: True
|
||||
"""
|
||||
|
||||
layout_voice_settings_screen = """
|
||||
MDScreen:
|
||||
name: "voice_settings_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
id: top_bar
|
||||
title: "Voice Configuration"
|
||||
anchor_title: "left"
|
||||
elevation: 0
|
||||
left_action_items:
|
||||
[['menu', lambda x: root.app.nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['close', lambda x: root.app.close_sub_voice_action(self)],
|
||||
]
|
||||
|
||||
MDScrollView:
|
||||
id: voice_settings_scrollview
|
||||
size_hint_x: 1
|
||||
size_hint_y: None
|
||||
size: [root.width, root.height-root.ids.top_bar.height]
|
||||
do_scroll_x: False
|
||||
do_scroll_y: True
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(28), dp(48), dp(28), dp(16)]
|
||||
|
||||
MDLabel:
|
||||
text: "Call Handling"
|
||||
font_style: "H6"
|
||||
height: self.texture_size[1]
|
||||
padding: [dp(0), dp(0), dp(0), dp(12)]
|
||||
|
||||
MDLabel:
|
||||
id: voice_settings_info
|
||||
markup: True
|
||||
text: "You can block calls from all other callers than contacts marked as trusted, by enabling the following option."
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
padding: [dp(0), dp(16), dp(0), dp(16)]
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
padding: [0,0,dp(24),0]
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Block non-trusted callers"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: voice_trusted_only
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDLabel:
|
||||
text: "Audio Devices"
|
||||
font_style: "H6"
|
||||
padding: [dp(0), dp(96), dp(0), dp(12)]
|
||||
|
||||
MDLabel:
|
||||
id: voice_settings_info
|
||||
markup: True
|
||||
text: "You can configure which audio devices Sideband will use for voice calls, by selecting either the system default device, or specific audio devices available."
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
padding: [dp(0), dp(64), dp(0), dp(32)]
|
||||
|
||||
MDLabel:
|
||||
text: "[b]Output[/b]"
|
||||
font_size: dp(18)
|
||||
markup: True
|
||||
|
||||
MDBoxLayout:
|
||||
id: output_devices
|
||||
orientation: "vertical"
|
||||
spacing: "12dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(24), dp(0), dp(48)]
|
||||
|
||||
# MDRectangleFlatIconButton:
|
||||
# id: output_default_button
|
||||
# text: "System Default"
|
||||
# padding: [dp(0), dp(14), dp(0), dp(14)]
|
||||
# icon_size: dp(24)
|
||||
# font_size: dp(16)
|
||||
# size_hint: [1.0, None]
|
||||
# on_release: root.delegate.output_device_action(self)
|
||||
# disabled: False
|
||||
|
||||
MDLabel:
|
||||
text: "[b]Input[/b]"
|
||||
font_size: dp(18)
|
||||
markup: True
|
||||
|
||||
MDBoxLayout:
|
||||
id: input_devices
|
||||
orientation: "vertical"
|
||||
spacing: "12dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(24), dp(0), dp(48)]
|
||||
|
||||
MDLabel:
|
||||
text: "[b]Ringer[/b]"
|
||||
font_size: dp(18)
|
||||
markup: True
|
||||
|
||||
MDBoxLayout:
|
||||
id: ringer_devices
|
||||
orientation: "vertical"
|
||||
spacing: "12dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: [dp(0), dp(24), dp(0), dp(48)]
|
||||
|
||||
"""
|
28
setup.py
28
setup.py
@ -47,6 +47,20 @@ def glob_paths(pattern):
|
||||
|
||||
return out_files
|
||||
|
||||
def glob_share():
|
||||
out_files = []
|
||||
src_path = os.path.join(os.path.dirname(__file__), "sbapp/share")
|
||||
print(src_path)
|
||||
|
||||
for root, dirs, files in os.walk(src_path):
|
||||
for file in files:
|
||||
filepath = os.path.join(str(Path(*Path(root).parts[1:])), file)
|
||||
|
||||
if not "mirrors/unsigned.io" in str(filepath):
|
||||
out_files.append(filepath.split(f"sbapp{os.sep}")[1])
|
||||
|
||||
return out_files
|
||||
|
||||
packages = setuptools.find_packages(
|
||||
exclude=[
|
||||
"sbapp.plyer.platforms.android",
|
||||
@ -63,6 +77,7 @@ package_data = {
|
||||
"kivymd/images/*",
|
||||
"kivymd/*",
|
||||
"mapview/icons/*",
|
||||
*glob_share(),
|
||||
*glob_paths(".kv")
|
||||
]
|
||||
}
|
||||
@ -99,8 +114,8 @@ setuptools.setup(
|
||||
]
|
||||
},
|
||||
install_requires=[
|
||||
"rns>=0.8.4",
|
||||
"lxmf>=0.5.7",
|
||||
"rns>=0.9.4",
|
||||
"lxmf>=0.6.3",
|
||||
"kivy>=2.3.0",
|
||||
"pillow>=10.2.0",
|
||||
"qrcode",
|
||||
@ -108,11 +123,14 @@ setuptools.setup(
|
||||
"ffpyplayer",
|
||||
"sh",
|
||||
"numpy<=1.26.4",
|
||||
"pycodec2;platform_system!='Windows'",
|
||||
"lxst>=0.2.7",
|
||||
"mistune>=3.0.2",
|
||||
"beautifulsoup4",
|
||||
"pycodec2;sys.platform!='Windows' and sys.platform!='win32' and sys.platform!='darwin'",
|
||||
"pyaudio;sys.platform=='linux'",
|
||||
"pyobjus;sys.platform=='darwin'",
|
||||
"pyogg;sys.platform=='darwin'",
|
||||
"pyogg;platform_system=='Windows'",
|
||||
"pyogg;sys.platform=='Windows' and sys.platform!='win32'",
|
||||
"audioop-lts>=0.2.1;python_version>='3.13'"
|
||||
],
|
||||
python_requires='>=3.7',
|
||||
)
|
||||
|
69
sideband.spec
Normal file
69
sideband.spec
Normal file
@ -0,0 +1,69 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
from kivy_deps import sdl2, glew
|
||||
|
||||
a = Analysis(
|
||||
['main.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
hiddenimports=["mistune", "bs4"],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
def extra_datas(mydir):
|
||||
def rec_glob(p, files):
|
||||
import os
|
||||
import glob
|
||||
for d in glob.glob(p):
|
||||
if os.path.isfile(d):
|
||||
files.append(d)
|
||||
rec_glob("%s/*" % d, files)
|
||||
files = []
|
||||
rec_glob("%s/*" % mydir, files)
|
||||
extra_datas = []
|
||||
for f in files:
|
||||
extra_datas.append((f, f, 'DATA'))
|
||||
|
||||
return extra_datas
|
||||
|
||||
a.datas += extra_datas('sbapp')
|
||||
a.datas += extra_datas('RNS')
|
||||
a.datas += extra_datas('LXMF')
|
||||
a.datas += extra_datas('LXST')
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
[],
|
||||
exclude_binaries=True,
|
||||
name='Sideband',
|
||||
icon="sbapp\\assets\\icon.png",
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
console=False,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
|
||||
coll = COLLECT(
|
||||
exe,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
name='main',
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user