mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
guh
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user