diff --git a/README.md b/README.md index f51927c..b761865 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,7 @@ This fork includes an option to use the [CeraUI](https://github.com/CERALIVE/Cer ## Moblink support -> [!WARNING] -> I will likely remove the integration of moblink in one of the next releases, since [datagutt/moblink-rust](https://github.com/datagutt/moblink-rust) implemented a service that makes the integration mostly obsolete. I would recommend disabling the moblink relay in this fork (setup.json) and installing the service instead: [Install moblink serivce](https://github.com/datagutt/moblink-rust#use-on-belabox). - -This fork integrates [datagutt/moblink-rust](https://github.com/datagutt/moblink-rust) in the relay mode, meaning it allows Moblin apps in the network of the encoder (BELABOX) to use the network interfaces of the BELABOX including modems as Moblink relays for SRTLA from Moblin. It does not yet support using Moblinks or Moblin apps to be used as SRTLA relays for the BELABOX! - -The implementation defaults to the password `1234` and uses auto-discovery to connect to "Moblin Streamers" in the network. You can change the password in the `setup.json` via SSH. As of now (2025-03-30) there is no UI for Moblink in this belaUI fork, nor CeraUI. +This fork previously integrated [datagutt/moblink-rust](https://github.com/datagutt/moblink-rust). This integration has been removed in favor of installing the new moblink service directly: [Install moblink on your BELABOX](https://github.com/datagutt/moblink-rust#use-on-belabox). ## Install the fork on your BELABOX @@ -94,11 +89,6 @@ pair: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on `echo "ssh-..." >> /root/.ssh/authorized_keys`). - Install rsync (`sudo apt install rsync`) - Install an editor (e.g. `sudo apt install nano`) -- Edit the `/opt/belaUI/setup.json` and add the following line to your existing setup to enable the moblink relay: - ```json - "moblink_relay_enabled": true - ``` - Make sure to add commas to the end of the lines before and after the new line, if necessary. ### Set up on host (currently tested on macOS) diff --git a/deploy-to-local.sh b/deploy-to-local.sh index e906d66..7daf1cc 100755 --- a/deploy-to-local.sh +++ b/deploy-to-local.sh @@ -70,22 +70,6 @@ rsync -rltvz --delete --chown=root:root \ --exclude setup.json \ "${DIST_PATH}/" "$RSYNC_TARGET" -# Install jq if its not installed -ssh "$SSH_TARGET" "jq --version 2>/dev/null || apt-get update && apt-get install -y jq" - -# Add moblink_relay_enabled: true to setup.json -echo "Enabling Moblink Relay. You can disable it in $BELAUI_PATH/setup.json" -ssh "$SSH_TARGET" "cp $BELAUI_PATH/setup.json $BELAUI_PATH/setup.json.tmp" - -# Enable moblink relay and set path to moblink-rust-relay -ssh "$SSH_TARGET" "cd $BELAUI_PATH; jq '.moblink_relay_enabled = true | .moblink_relay_bin = \"/opt/moblink-rust-relay/target/release/moblink-rust-relay\"' setup.json.tmp | sudo tee setup.json > /dev/null" -ssh "$SSH_TARGET" "rm $BELAUI_PATH/setup.json.tmp" - -# Install moblink-rust-relay -ssh "$SSH_TARGET" "cd $BELAUI_PATH; bash ./install-moblink-rust-relay.sh" - -echo "Moblink relay installed successfully." - # shellcheck disable=SC2029 ssh "$SSH_TARGET" "cd $BELAUI_PATH; bash ./override-belaui.sh" diff --git a/install.sh b/install.sh index cdd84c3..5b8685b 100644 --- a/install.sh +++ b/install.sh @@ -12,17 +12,16 @@ TEMP_DIR="$HOME/.tmp/belaui" TARGET_DIR="/opt/belaUI" # Check if dependencies are installed -JQ_INSTALLED=$(jq --version 2>/dev/null) || false RSYNC_INSTALLED=$(rsync --version 2>/dev/null) || false # stop on error set -e -if [ -z "$JQ_INSTALLED" ] || [ -z "$RSYNC_INSTALLED" ]; then +if [ -z "$RSYNC_INSTALLED" ]; then echo "Installing missing dependencies" sudo apt-get update - sudo apt-get install -y rsync jq + sudo apt-get install -y rsync fi # Clone the repository branch into a temporary directory @@ -58,20 +57,6 @@ rm -rf "$TEMP_DIR" # Set ownership to root:root and preserve permissions sudo chown -R root:root $TARGET_DIR -# Add moblink_relay_enabled: true to setup.json -echo "Enabling Moblink Relay. You can disable it in $TARGET_DIR/setup.json" -sudo cp $TARGET_DIR/setup.json $TARGET_DIR/setup.json.tmp - -# Enable moblink relay and set path to moblink-rust-relay -sudo jq '.moblink_relay_enabled = true | .moblink_relay_bin = "/opt/moblink-rust-relay/target/release/moblink-rust-relay"' $TARGET_DIR/setup.json.tmp | sudo tee $TARGET_DIR/setup.json > /dev/null -sudo rm $TARGET_DIR/setup.json.tmp - -# Install moblink-rust-relay -cd $TARGET_DIR || exit -sudo bash ./install-moblink-rust-relay.sh - -echo "Moblink relay installed successfully." - # Run the override script cd $TARGET_DIR || exit sudo bash ./override-belaui.sh diff --git a/server/belaUI.ts b/server/belaUI.ts index 4e1e2e0..5a0a55e 100644 --- a/server/belaUI.ts +++ b/server/belaUI.ts @@ -24,7 +24,6 @@ import { initRTMPIngestStats } from "./modules/ingest/rtmp.ts"; import { initSRTIngest } from "./modules/ingest/srt.ts"; import { updateModems } from "./modules/modems/modem-update-loop.ts"; import { UPDATE_GW_INT, updateGwWrapper } from "./modules/network/gateways.ts"; -import { initMoblinkRelays } from "./modules/network/moblink-relay.ts"; import { initNetworkInterfaceMonitoring } from "./modules/network/network-interfaces.ts"; import { initRemote } from "./modules/remote/remote.ts"; import { setup } from "./modules/setup.ts"; @@ -75,8 +74,6 @@ if (setup.apt_update_enabled) { initNetworkInterfaceMonitoring(); -initMoblinkRelays(); - // check for Cam Links on USB2 at startup checkCamlinkUsb2(); @@ -96,6 +93,5 @@ process.on("SIGUSR2", function udevDeviceUpdate() { // make sure we didn't inherit orphan processes killall(["belacoder"]); killall(["srtla_send"]); -killall(["moblink-rust-relay"]); initHttpServer(); diff --git a/server/modules/network/moblink-relay.ts b/server/modules/network/moblink-relay.ts deleted file mode 100644 index 59968ed..0000000 --- a/server/modules/network/moblink-relay.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { type ChildProcessByStdio, spawn } from "node:child_process"; -import type { Readable } from "node:stream"; - -import { checkExecPath, checkExecPathSafe } from "../../helpers/exec.ts"; -import { logger } from "../../helpers/logger.ts"; -import { stableUuidFromString } from "../../helpers/uuid.ts"; -import { setup } from "../setup.ts"; -import { - getNetworkInterfaces, - onNetworkInterfacesChange, -} from "./network-interfaces.ts"; - -const enabled = setup.moblink_relay_enabled; - -const RELAY_COOLDOWN = 3_000; -const INTERFACES_UPDATE_RATE = 10_000; - -export const moblinkRelayExec = - setup.moblink_relay_bin ?? - "/opt/moblink-rust-relay/target/release/moblink-rust-relay"; - -type RelayProcess = ChildProcessByStdio & { - restartTimer?: ReturnType; -}; - -const relayProcesses = new Map(); - -type RelayOptions = { - name: string; - bindIpAddressDestination: string; - streamerPassword?: string; -}; - -type RelayInterface = { - name: string; - ip: string; -}; - -const defaultStreamerPassword = setup.moblink_relay_streamer_password || "1234"; - -async function spawnRelay(relayOptions: RelayOptions) { - const { - name, - bindIpAddressDestination, - streamerPassword = defaultStreamerPassword, - } = relayOptions; - - checkExecPath(moblinkRelayExec); - - const id = await stableUuidFromString(`belabox-${name}`); - logger.info( - `Starting Moblink relay ${name} [${id}] on ${bindIpAddressDestination}`, - ); - - const process = spawn( - moblinkRelayExec, - [ - "--name", - name, - "--id", - id, - "--password", - streamerPassword, - "--bind-address", - bindIpAddressDestination, - "--log-level", - "error", - ], - { - stdio: ["inherit", "inherit", "pipe"], - }, - ) as RelayProcess; - - relayProcesses.set(bindIpAddressDestination, process); - - process.stderr.on("data", (data) => { - const dataStr = data.toString("utf8"); - logger.info(`Moblink relay ${name}: ${dataStr}`); - }); - - process.on("exit", (code) => { - logger.warn(`Moblink relay ${name} exited with code ${code}`); - - process.restartTimer = setTimeout(() => { - relayProcesses.delete(bindIpAddressDestination); - spawnRelay(relayOptions); - }, RELAY_COOLDOWN); - }); -} - -function stopRelay(relayId: string) { - const process = relayProcesses.get(relayId); - if (!process) return true; - - if (process.restartTimer) { - clearTimeout(process.restartTimer); - } - - process.removeAllListeners("exit"); - process.on("exit", () => { - relayProcesses.delete(relayId); - }); - - if (process.exitCode === null && process.signalCode === null) { - process.kill("SIGTERM"); - return false; - } - - relayProcesses.delete(relayId); - return true; -} - -export function initMoblinkRelays() { - if (!enabled) return; - - if (!checkExecPathSafe(moblinkRelayExec)) { - logger.error("Moblink relay binary not found, disabling Moblink relay"); - return; - } - - setInterval(updateMoblinkRelayInterfaces, INTERFACES_UPDATE_RATE); - onNetworkInterfacesChange(updateMoblinkRelayInterfaces); -} - -function findDestinationInterfaces() { - const networkInterfaces = getNetworkInterfaces(); - - const destinationInterfaces = new Set(); - - for (const interfaceName in networkInterfaces) { - const networkInterface = networkInterfaces[interfaceName]; - if (!networkInterface) continue; - - if ( - networkInterface.enabled && - networkInterface.error === 0 && - networkInterface.ip - ) { - destinationInterfaces.add({ - name: interfaceName, - ip: networkInterface.ip, - }); - } - } - return destinationInterfaces; -} - -export function updateMoblinkRelayInterfaces() { - if (!enabled) return; - - const oldIds = new Set(relayProcesses.keys()); - const newIds = new Set(); - - const destinationInterfaces = findDestinationInterfaces(); - - for (const destinationInterface of destinationInterfaces) { - newIds.add(destinationInterface.ip); - - if (!oldIds.has(destinationInterface.ip)) { - spawnRelay({ - name: destinationInterface.name, - bindIpAddressDestination: destinationInterface.ip, - }); - } - } - - // Stop relays for interfaces that are no longer enabled - for (const oldId of oldIds) { - if (!newIds.has(oldId)) { - stopRelay(oldId); - } - } -} diff --git a/server/modules/wifi/wifi-interfaces.ts b/server/modules/wifi/wifi-interfaces.ts index e719582..651f437 100644 --- a/server/modules/wifi/wifi-interfaces.ts +++ b/server/modules/wifi/wifi-interfaces.ts @@ -18,7 +18,6 @@ import { logger } from "../../helpers/logger.ts"; import { getms } from "../../helpers/time.ts"; -import { updateMoblinkRelayInterfaces } from "../network/moblink-relay.ts"; import { NETIF_ERR_HOTSPOT, getNetworkInterfaces, @@ -236,8 +235,6 @@ export async function wifiUpdateDevices() { } logger.debug("Wifi interfaces", wifiInterfacesByMacAddress); - updateMoblinkRelayInterfaces(); - /* If some wifi adapters were marked unavailable, recheck periodically This might happen when the system has just booted up and the adapter typically becomes available within 30 seconds. diff --git a/setup.json b/setup.json index bda5e81..9cf74fe 100644 --- a/setup.json +++ b/setup.json @@ -7,8 +7,5 @@ "mmcli_binary": "./mocks/mmcli", "killall_binary": "./mocks/killall", "bitrate_file": "/tmp/belacoder_br", - "ips_file": "/tmp/srtla_ips", - "moblink_relay_enabled": true, - "moblink_relay_bin": "/opt/moblink-rust-relay/target/release/moblink-rust-relay", - "moblink_relay_streamer_password": "1234" + "ips_file": "/tmp/srtla_ips" }