This commit is contained in:
legop3
2025-11-14 22:39:51 -05:00
parent 835850e686
commit 6cfdde30ea
3 changed files with 24 additions and 5 deletions
+4
View File
@@ -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/<roverId>
# 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"
+19 -4
View File
@@ -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);