/video signaling proxy and a global public server http path config item

This commit is contained in:
legop3
2026-09-14 19:49:37 -04:00
parent e7d7f2a270
commit 43274e7371
32 changed files with 364 additions and 145 deletions
@@ -33,7 +33,7 @@ function createReplayCommand({
getActiveDrivers,
getNickname,
rovers,
discordConfig,
config,
}) {
const sourceResolver = createReplaySourceResolver({
rovers,
@@ -137,8 +137,8 @@ function createReplayCommand({
if (progressMessage?.edit) {
await progressMessage.edit({ content: sanitizeMentions(buildStatusMessage(job, 'ready')), allowedMentions: DEFAULT_ALLOWED_MENTIONS });
}
const siteUrl = String(discordConfig?.siteUrl || '').replace(/\/$/, '');
const publicUrl = siteUrl ? `${siteUrl}${media.url}` : media.url;
const publicBaseUrl = String(config?.publicUrl || '').replace(/\/$/, '');
const publicUrl = publicBaseUrl ? `${publicBaseUrl}${media.url}` : media.url;
await progressMessage.reply({ content: `Replay hosted by the rover server: ${publicUrl}`, allowedMentions: DEFAULT_ALLOWED_MENTIONS });
return;
} catch (fallbackError) {
@@ -3,12 +3,12 @@
// Scope: Builds a concise time embed for common zones and server local zone.
const { EmbedBuilder } = require('discord.js');
function createTimeStatusCommand({ config, discordConfig }) {
function createTimeStatusCommand({ config }) {
function buildEmbed({ title, description, color, includeSiteUrl = true }) {
const embed = new EmbedBuilder().setTitle(title || 'Update').setColor(color || 0x2196f3);
const siteUrl = includeSiteUrl && discordConfig.siteUrl ? String(discordConfig.siteUrl) : '';
if (description) embed.setDescription(siteUrl ? `${description}\n\n${siteUrl}` : description);
else if (siteUrl) embed.setDescription(siteUrl);
const publicUrl = includeSiteUrl && config.publicUrl ? String(config.publicUrl) : '';
if (description) embed.setDescription(publicUrl ? `${description}\n\n${publicUrl}` : description);
else if (publicUrl) embed.setDescription(publicUrl);
embed.setTimestamp(new Date());
return embed;
}
@@ -12,7 +12,6 @@ module.exports = {
enabled: false,
token: '',
guildId: '123456789012345678',
siteUrl: 'https://rover.example.com',
channels: {
general: '123456789012345678',
announcements: '123456789012345678',
@@ -31,7 +30,6 @@ module.exports = {
enabled: boolean({ description: 'Logs the Discord bot in and immediately enables commands, chat bridges, replay delivery, and configured announcements.' }),
token: string({ title: 'Bot token', description: 'Discord bot token used to log in. The saved value is never returned to the browser.', examples: ['DISCORD_BOT_TOKEN'], writeOnly: true, maxLength: 10000 }),
guildId: string({ title: 'Guild id', description: 'Reserved Discord server identifier. The current bot runtime does not restrict commands or events using this value.', examples: ['123456789012345678'], maxLength: 100 }),
siteUrl: string({ title: 'Public site URL', description: 'Public base URL appended to announcement embeds and server-hosted replay links.', examples: ['https://rover.example.com'], maxLength: 2048 }),
channels: strictObject({
general: string({ description: 'Channel ID used by the button-box stalker-role and everyone-ping rewards.', examples: ['123456789012345678'], maxLength: 100 }),
announcements: string({ description: 'Channel ID used for public-mode openings, objective changes, and all-rovers-unlocked announcements.', examples: ['123456789012345678'], maxLength: 100 }),
@@ -55,7 +53,7 @@ module.exports = {
}),
}, {
title: 'Discord',
description: 'Optional Discord bot credentials, public URL, and notification routing.',
required: ['enabled', 'token', 'guildId', 'siteUrl', 'channels', 'roles'],
description: 'Optional Discord bot credentials and notification routing; public links use the top-level public URL.',
required: ['enabled', 'token', 'guildId', 'channels', 'roles'],
}),
};
@@ -206,8 +206,8 @@ registerPreferredDeliveryProvider({
}
},
async completeFallback({ context, media }) {
const siteUrl = String(discordConfig.siteUrl || '').replace(/\/$/, '');
const publicUrl = siteUrl ? `${siteUrl}${media.url}` : media.url;
const publicBaseUrl = String(config.publicUrl || '').replace(/\/$/, '');
const publicUrl = publicBaseUrl ? `${publicBaseUrl}${media.url}` : media.url;
if (context?.progressMessage?.reply) {
await context.progressMessage.reply({
content: `Replay hosted by the rover server: ${publicUrl}`,
@@ -434,7 +434,7 @@ function applySharedConfigSection(section, value) {
}
registerConfigurationHandler('discord', applyDiscordConfig);
['commands', 'timezone', 'fleetReports'].forEach((section) => {
['commands', 'publicUrl', 'timezone', 'fleetReports'].forEach((section) => {
registerConfigurationHandler(section, (value) => applySharedConfigSection(section, value));
});
@@ -5,15 +5,15 @@ const { EmbedBuilder, AttachmentBuilder } = require('discord.js');
const { buildBatteryStatusEmbed, buildBatteryCaption } = require('../batteryEmbeds');
function createBusEventHandler(deps) {
const { logger, discordConfig, roverManager, rovers, schedulePresenceRotation, formatDuration, sendToChannel } = deps;
const { logger, config, discordConfig, roverManager, rovers, schedulePresenceRotation, formatDuration, sendToChannel } = deps;
const ADMIN_ALERT_EVENT_TYPES = new Set(['rover.online', 'rover.offline', 'rover.dockGuard', 'rover.helpNeeded', 'rover.helpCleared', 'battery.warn', 'battery.urgent', 'battery.docked', 'battery.undocked', 'battery.charging.start', 'battery.charging.stop', 'battery.locked', 'battery.unlocked']);
let skippedFirstModeAnnouncement = false;
function buildEmbed({ title, description, color, includeSiteUrl = true }) {
const embed = new EmbedBuilder().setTitle(title || 'Update').setColor(color || 0x2196f3);
const siteUrl = includeSiteUrl && discordConfig.siteUrl ? String(discordConfig.siteUrl) : '';
if (description) embed.setDescription(siteUrl ? `${description}\n\n${siteUrl}` : description);
else if (siteUrl) embed.setDescription(siteUrl);
const publicUrl = includeSiteUrl && config.publicUrl ? String(config.publicUrl) : '';
if (description) embed.setDescription(publicUrl ? `${description}\n\n${publicUrl}` : description);
else if (publicUrl) embed.setDescription(publicUrl);
embed.setTimestamp(new Date());
return embed;
}
@@ -14,6 +14,7 @@ const WATCHED_EVENT_TYPES = new Set([
function createUserAnnouncements(deps) {
const {
discordConfig,
config,
getMode,
rovers,
roverManager,
@@ -27,7 +28,7 @@ function createUserAnnouncements(deps) {
// send/render time so announcements do not retain stale channel or site data.
const getAnnouncementChannelId = () => discordConfig?.channels?.announcements || null;
const getAnnouncementRoleId = () => discordConfig?.roles?.announcementPing || null;
const getSiteUrl = () => (discordConfig?.siteUrl ? String(discordConfig.siteUrl) : '');
const getPublicUrl = () => (config?.publicUrl ? String(config.publicUrl) : '');
let previousSnapshot = buildSnapshot();
let skippedFirstModeChange = false;
@@ -127,11 +128,11 @@ function createUserAnnouncements(deps) {
});
}
const siteUrl = getSiteUrl();
if (siteUrl) {
const publicUrl = getPublicUrl();
if (publicUrl) {
embed.addFields({
name: 'Join',
value: siteUrl,
value: publicUrl,
inline: false,
});
}