// Inter Instance Panel // Purpose: Renders remote rover servers discovered through the inter-instance directory. // Scope: Owns external server metadata presentation while reusing RoverQueuesPanel for rover/queue rows. import { useMemo } from 'react'; import './styles.css'; import { useSessionSelector } from '../../context/SessionContext.jsx'; import CardFrame from '../CardFrame/index.jsx'; import RoverQueuesPanel from '../RoverQueuesPanel/index.jsx'; import { openExternalRover } from '../../lib/interInstanceTransfer.js'; import { isFeatureEnabled } from '../../lib/features.js'; import { useSettingsNamespace } from '../../settings/index.js'; function classNames(...values) { return values.filter(Boolean).join(' '); } function useRemoteInstances() { return useSessionSelector((state) => state.session?.interInstances?.instances ?? []); } function useInterInstanceEnabled() { return useSessionSelector((state) => isFeatureEnabled(state, 'interInstance')); } function featureEntries(features = {}) { return Object.entries(features || {}) .filter(([, enabled]) => Boolean(enabled)) .map(([name]) => name); } function getRemoteAvailability(remote) { const mode = remote?.instance?.mode || 'unknown'; if (!remote?.online) return { blocked: true, label: 'Offline', overlay: 'This server is offline', tone: 'red' }; if (mode === 'lockdown') return { blocked: true, label: 'Lockdown', overlay: 'This server is currently in lockdown mode', tone: 'red' }; if (mode === 'admin') return { blocked: true, label: 'Admin only', overlay: 'This server is currently admin locked', tone: 'red' }; if (mode === 'turns') return { blocked: false, label: 'Turns mode (open)', tone: 'emerald' }; if (mode === 'open') return { blocked: false, label: 'Open mode', tone: 'emerald' }; return { blocked: false, label: mode, tone: 'slate' }; } function statusClass(tone) { switch (tone) { case 'emerald': return 'bg-emerald-700/70 text-emerald-50 ring-1 ring-emerald-300/50'; case 'sky': return 'bg-sky-700/70 text-sky-50 ring-1 ring-sky-300/50'; case 'amber': return 'bg-amber-600/80 text-amber-50 ring-1 ring-amber-200/60'; case 'red': return 'bg-red-700/80 text-red-50 ring-1 ring-red-300/60'; default: return 'bg-slate-700/80 text-slate-50 ring-1 ring-slate-400/40'; } } function InstanceStatus({ remote }) { const availability = getRemoteAvailability(remote); return (
{availability.label}
); } function InstanceLatency({ remote }) { if (remote?.latencyMs == null) return null; return {remote.latencyMs}ms; } function InstancePanel({ remote, children = null }) { const instance = remote?.instance || {}; const features = featureEntries(instance.features); const color = instance.color || '#64748b'; const online = Boolean(remote?.online); const { value: pageSettings } = useSettingsNamespace('page', { interInstanceTransferSettings: true }); const includeSettings = pageSettings?.interInstanceTransferSettings !== false; return ( } bodyClassName="space-y-0.5 p-0.5 text-sm" >
{/* The status is the main operational signal for a remote instance, so it stays beside the human-facing description where users naturally scan the server summary. Latency is intentionally moved to the title bar as quiet metadata because it is useful detail, not the primary decision. */}
{online && instance.description ?

{instance.description}

: null}
{online && features.length ? (
{features.map((feature) => ( {feature} ))}
) : null}
{online ? children : null} ); } function RemoteMediaStrip({ remote }) { const roomCameras = Array.isArray(remote.roomCameras) ? remote.roomCameras.filter((camera) => camera.snapshotUrl) : []; if (!roomCameras.length) return null; return (
{roomCameras.map((camera) => (
{camera.name
))}
); } export function ExternalInstancesCompact({ onBrowse = null }) { const enabled = useInterInstanceEnabled(); const instances = useRemoteInstances(); const visible = useMemo(() => instances.filter((remote) => remote?.online || remote?.url), [instances]); if (!enabled) return null; if (!visible.length) return null; const browseAction = onBrowse ? ( ) : null; return ( /* External instances are intentionally always mounted. Besides removing an unnecessary disclosure click, this preserves the live queue rows while the local Rover Queues card can provide one continuous scroll surface for both its local and external rows. Scrolling belongs to that owning panel, so this nested section deliberately keeps its natural content height. */ {/* One containing card gives the remote-server collection a clear boundary below the local rover rows. Individual remote queue cards stay intact inside it because they still own each server's title and operational status, while this outer title bar owns the collection-wide browser. */} {visible.map((remote) => remote.online ? ( ) : ( ), )} ); } export function InterInstancePopup({ onClose }) { return (
); } function InterInstanceCards({ instances, centered = false, singleColumn = false }) { return (
{instances.map((remote) => (
{/* The large browser should read as one card per external server: the server metadata, room snapshots, and the exact existing rover queues panel are grouped together here. RoverQueuesPanel keeps its own CardFrame and default title, so this component only controls where that already-existing panel is placed. */} <>
))}
); } export function InterInstanceBrowserFrame({ onClose = null, hideWhenEmpty = false, className = '', bodyClassName = 'p-0.5', centered = false, scaledOverlay = false, singleColumn = false, }) { const enabled = useInterInstanceEnabled(); const instances = useRemoteInstances(); if (!enabled) return null; if (!instances.length && hideWhenEmpty) return null; const actions = onClose ? ( ) : null; /* This frame is shared by the popup and the admin/lockdown overlay. Keeping the wrapper here means those surfaces get the same external-instance card without placing it inside the login card or duplicating layout behavior. */ return ( {instances.length ? ( ) : (

No external instances discovered.

)}
); } export default function InterInstancePanel({ compact = false, centered = false }) { const enabled = useInterInstanceEnabled(); const instances = useRemoteInstances(); if (!enabled) return null; if (compact) return ; if (!instances.length) { return (

No external instances discovered.

); } return ; }