diff --git a/README.md b/README.md index 51c289d6..de7df9ca 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ The script must be executed via `sudo` from the user that owns the repo. It will Publishing rovers lives on a trusted network, so the shipped config (tracked at `server/mediamtx/mediamtx.yml`) skips HTTP auth for SRT ingest and whitelists any path that matches `rover-*`. The installer overwrites `/etc/mediamtx/mediamtx.yml` every time you run it—if you need to tweak ports or add TURN servers, edit the template in the repo and rerun `install_server.sh` so every box stays in sync automatically. -Once finished, update `server/config.yaml` with your admin passwords and `media.whepBaseUrl` (`http://192.168.0.86:8889/whep`). Restart `multirover.service` whenever you edit the config. To pull updates later, just `git pull`, re-run `npm install --production` inside `server/`, and restart the service—no need to rerun the installer. +Once finished, update `server/config.yaml` with your admin passwords and `media.whepBaseUrl` (`http://192.168.0.86:8889/whep`). The UI appends the rover ID to whatever you provide; if you prefer a different layout, include `{roverId}` or `{id}` in the URL (for example `http://192.168.0.86:8889/{id}/whep`). Restart `multirover.service` whenever you edit the config. To pull updates later, just `git pull`, re-run `npm install --production` inside `server/`, and restart the service—no need to rerun the installer. ### Video handshake + diagnostics diff --git a/server/config.example.yaml b/server/config.example.yaml index 816e5c32..aac281d7 100644 --- a/server/config.example.yaml +++ b/server/config.example.yaml @@ -8,4 +8,8 @@ admins: discord_id: "0987654321" lockdown: true media: + # Base URL for mediaMTX WHEP publishes. Append the rover ID automatically, or embed {roverId}/{id}. + # Examples: + # http://192.168.0.86:8889/whep -> becomes http://192.168.0.86:8889/whep/ + # http://192.168.0.86:8889/{id}/whep -> becomes http://192.168.0.86:8889/Freaky/whep whepBaseUrl: "http://192.168.0.86:8889/whep" diff --git a/server/src/services/videoSocketService.js b/server/src/services/videoSocketService.js index f76912d5..e94b6c78 100644 --- a/server/src/services/videoSocketService.js +++ b/server/src/services/videoSocketService.js @@ -9,6 +9,21 @@ const { loadConfig } = require('../helpers/configLoader'); const config = loadConfig(); const mediaConfig = config.media || {}; +function buildWhepUrl(roverId) { + const base = mediaConfig.whepBaseUrl; + if (!base) { + return ''; + } + const encodedId = encodeURIComponent(roverId); + if (base.includes('{roverId}')) { + return base.replace(/\{roverId\}/g, encodedId); + } + if (base.includes('{id}')) { + return base.replace(/\{id\}/g, encodedId); + } + return `${base.replace(/\/$/, '')}/${encodedId}`; +} + function canView(socket, roverId) { const mode = getMode(); if (mode === MODES.LOCKDOWN && !isLockdownAdmin(socket)) { @@ -27,9 +42,6 @@ function canView(socket, roverId) { io.on('connection', (socket) => { socket.on('video:request', ({ roverId } = {}, cb = () => {}) => { try { - if (!mediaConfig.whepBaseUrl) { - throw new Error('Server video base URL missing'); - } if (!roverId) { throw new Error('roverId required'); } @@ -39,8 +51,11 @@ io.on('connection', (socket) => { if (!canView(socket, roverId)) { throw new Error('Not authorized for video'); } + const url = buildWhepUrl(roverId); + if (!url) { + throw new Error('Server video base URL missing'); + } const sessionId = videoSessions.createSession(socket, roverId); - const url = `${mediaConfig.whepBaseUrl.replace(/\/$/, '')}/${roverId}`; cb({ url, token: sessionId }); } catch (err) { logger.warn('video request failed: %s', err.message);