StreamOverlayPage.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. import { useEffect, useMemo } from 'react';
  2. import { useParams, useSearchParams } from 'react-router-dom';
  3. import { useQuery, useQueryClient } from '@tanstack/react-query';
  4. import { useTranslation } from 'react-i18next';
  5. import { Layers, Clock, Timer, Printer, Flame, Square, Box } from 'lucide-react';
  6. import { useOverlayLogo } from '../hooks/useOverlayLogo';
  7. import { overlayGradient, overlayProgressTextStyle } from '../utils/overlayBranding';
  8. import { OverlayFrame } from '../components/OverlayFrame';
  9. import { OVERLAY_DIMENSIONS, type OverlayLayout } from '../utils/overlayLayout';
  10. import './StreamOverlayPage.css';
  11. import { UpdatedStreamOverlay } from '../components/UpdatedStreamOverlay';
  12. import { api, ApiError, withStreamToken } from '../api/client';
  13. import { formatDuration, formatETA, type TimeFormat } from '../utils/date';
  14. import { mapModelCode } from '../utils/printerModel';
  15. import { useOverlayCameraRecovery } from '../hooks/useOverlayCameraRecovery';
  16. type TFunction = (key: string, options?: Record<string, unknown>) => string;
  17. type OverlaySize = 'small' | 'medium' | 'large';
  18. interface OverlayConfig {
  19. layout: OverlayLayout | null;
  20. size: OverlaySize;
  21. updatedArtwork: boolean;
  22. backgroundTransparency: number;
  23. fps: number;
  24. showCamera: boolean;
  25. showProgress: boolean;
  26. showLayers: boolean;
  27. showEta: boolean;
  28. showFilename: boolean;
  29. showStatus: boolean;
  30. showPrinter: boolean;
  31. showModel: boolean;
  32. showNozzle: boolean;
  33. showBed: boolean;
  34. showChamber: boolean;
  35. }
  36. function formatPrintName(name: string | null, gcodeFile: string | null | undefined, t: (key: string, fallback: string, opts?: Record<string, unknown>) => string): string {
  37. if (!name) return '';
  38. if (!gcodeFile) return name;
  39. const match = gcodeFile.match(/plate_(\d+)\.gcode/);
  40. if (match && parseInt(match[1], 10) > 1) {
  41. return `${name} — ${t('printers.plateNumber', 'Plate {{number}}', { number: match[1] })}`;
  42. }
  43. return name;
  44. }
  45. function parseConfig(params: URLSearchParams): OverlayConfig {
  46. // The default set is deliberately unchanged by #1422: temperatures are opt-in,
  47. // so every overlay URL already pasted into an OBS scene keeps looking the same
  48. // after upgrading.
  49. const show = params.get('show')?.split(',') || ['progress', 'layers', 'eta', 'filename', 'status'];
  50. // Parse FPS (default 15, max 30, min 1)
  51. const fpsParam = parseInt(params.get('fps') || '15', 10);
  52. const fps = Math.min(Math.max(isNaN(fpsParam) ? 15 : fpsParam, 1), 30);
  53. // Parse camera toggle (default true, set camera=false to hide)
  54. const cameraParam = params.get('camera');
  55. const showCamera = cameraParam !== 'false' && cameraParam !== '0';
  56. const transparencyParam = Number(params.get('backgroundTransparency'));
  57. const backgroundTransparency = Number.isFinite(transparencyParam)
  58. ? Math.min(100, Math.max(0, transparencyParam))
  59. : 0;
  60. const layout = params.get('layout');
  61. return {
  62. layout: layout === 'portrait' || layout === 'landscape' ? layout : null,
  63. backgroundTransparency,
  64. size: (params.get('size') as OverlaySize) || 'medium',
  65. fps,
  66. updatedArtwork: params.get('artwork') === '2',
  67. showCamera,
  68. showProgress: show.includes('progress'),
  69. showLayers: show.includes('layers'),
  70. showEta: show.includes('eta'),
  71. showFilename: show.includes('filename'),
  72. showStatus: show.includes('status'),
  73. showPrinter: show.includes('printer'),
  74. showModel: show.includes('model'),
  75. showNozzle: show.includes('nozzle'),
  76. showBed: show.includes('bed'),
  77. showChamber: show.includes('chamber'),
  78. };
  79. }
  80. // Accepts the minimal shape shared by PrinterStatus (logged-in path) and the
  81. // token-authed OverlayStatus (kiosk path) — both carry state + stg_cur_name.
  82. function getStatusText(status: { state: string | null; stg_cur_name?: string | null }, t: TFunction): string {
  83. if (status.stg_cur_name) return status.stg_cur_name;
  84. switch (status.state) {
  85. case 'RUNNING': return t('streamOverlay.status.printing');
  86. case 'PAUSE': return t('streamOverlay.status.paused');
  87. case 'FINISH': return t('streamOverlay.status.finished');
  88. case 'FAILED': return t('streamOverlay.status.failed');
  89. case 'IDLE': return t('streamOverlay.status.idle');
  90. default: return status.state || t('streamOverlay.status.unknown');
  91. }
  92. }
  93. // Reads one reading out of either status shape. The kiosk feed types
  94. // temperatures as Record<string, number>; the logged-in PrinterStatus types it
  95. // as a named object that also carries `*_heating` booleans. Narrowing here lets
  96. // one render path serve both without casting.
  97. function readTemp(temps: Record<string, unknown>, key: string): number | null {
  98. const value = temps[key];
  99. return typeof value === 'number' ? value : null;
  100. }
  101. interface TempReadingProps {
  102. icon: React.ReactNode;
  103. label: string;
  104. current: number;
  105. target: number | null;
  106. sizes: ReturnType<typeof getSizeClasses>;
  107. }
  108. // One "Nozzle 220°C" reading. The target is appended only while it is set and
  109. // still differs from the current value, so a hotend that has reached
  110. // temperature reads "220°C" for the rest of the print instead of the noisier
  111. // "220 / 220°C".
  112. function TempReading({ icon, label, current, target, sizes }: TempReadingProps) {
  113. const heating = target != null && target > 0 && Math.round(target) !== Math.round(current);
  114. return (
  115. <div className={`flex items-center ${sizes.gap} text-white/70`}>
  116. {icon}
  117. <span className={`classic-overlay__text ${sizes.text}`}>
  118. <span className="mr-1">{label}</span>
  119. <span className="text-white">{Math.round(current)}°C</span>
  120. {heating && (
  121. <>
  122. <span className="mx-1">/</span>
  123. <span>{Math.round(target)}°C</span>
  124. </>
  125. )}
  126. </span>
  127. </div>
  128. );
  129. }
  130. function getSizeClasses(size: OverlaySize) {
  131. switch (size) {
  132. case 'small':
  133. return {
  134. container: 'p-3',
  135. text: 'text-sm',
  136. textLarge: 'text-lg',
  137. progressHeight: 'h-2',
  138. icon: 'w-3 h-3',
  139. gap: 'gap-2',
  140. logoHeight: 'h-12',
  141. };
  142. case 'large':
  143. return {
  144. container: 'p-6',
  145. text: 'text-xl',
  146. textLarge: 'text-3xl',
  147. progressHeight: 'h-4',
  148. icon: 'w-6 h-6',
  149. gap: 'gap-4',
  150. logoHeight: 'h-24',
  151. };
  152. case 'medium':
  153. default:
  154. return {
  155. container: 'p-4',
  156. text: 'text-base',
  157. textLarge: 'text-xl',
  158. progressHeight: 'h-3',
  159. icon: 'w-4 h-4',
  160. gap: 'gap-3',
  161. logoHeight: 'h-16',
  162. };
  163. }
  164. }
  165. export function StreamOverlayPage() {
  166. const { printerId } = useParams<{ printerId: string }>();
  167. const [searchParams] = useSearchParams();
  168. const { t } = useTranslation();
  169. const queryClient = useQueryClient();
  170. const id = parseInt(printerId || '0', 10);
  171. const config = useMemo(() => parseConfig(searchParams), [searchParams]);
  172. const sizes = getSizeClasses(config.size);
  173. // Kiosk mode (#2613): OBS and other embeds have no login session, so they
  174. // pass an `overlay`-scoped token in the URL. When present, every data call
  175. // (status + camera stream) is authenticated by that token instead of a JWT.
  176. const token = searchParams.get('token');
  177. const kiosk = token != null && token !== '';
  178. const logo = useOverlayLogo(searchParams.get('logo') === '1', token);
  179. const progressBackground = overlayGradient(searchParams.get('progressFrom'), searchParams.get('progressTo'));
  180. const progressTextStyle = overlayProgressTextStyle(progressBackground);
  181. const customLogo = logo ? (
  182. <img
  183. src={logo}
  184. alt={t('streamOverlay.branding.logo')}
  185. className="mb-2 object-contain"
  186. style={{
  187. maxHeight: config.layout ? OVERLAY_DIMENSIONS[config.layout].height * 0.14 : '14vh',
  188. maxWidth: config.layout ? OVERLAY_DIMENSIONS[config.layout].width * 0.2 : '20vw',
  189. }}
  190. />
  191. ) : null;
  192. // Kiosk path: one token-authenticated call for name + live status + the one
  193. // setting the overlay reads. No JWT, so this is the only feed available.
  194. const { data: overlay } = useQuery({
  195. queryKey: ['overlayStatus', id, token],
  196. queryFn: () => api.getOverlayStatus(id, token ?? undefined),
  197. enabled: id > 0 && kiosk,
  198. refetchInterval: 2000,
  199. });
  200. // Logged-in path: the ordinary JWT-authenticated queries, unchanged. Disabled
  201. // in kiosk mode so an unauthenticated OBS browser never fires a doomed 401.
  202. const { data: printerData } = useQuery({
  203. queryKey: ['printer', id],
  204. queryFn: () => api.getPrinter(id),
  205. enabled: id > 0 && !kiosk,
  206. });
  207. const { data: statusData } = useQuery({
  208. queryKey: ['printerStatus', id],
  209. queryFn: () => api.getPrinterStatus(id),
  210. enabled: id > 0 && !kiosk,
  211. refetchInterval: 2000,
  212. });
  213. const { data: settings } = useQuery({
  214. queryKey: ['settings'],
  215. queryFn: api.getSettings,
  216. enabled: !kiosk,
  217. });
  218. // Normalize the two sources into the shape the render below reads. Memoized
  219. // because the title effect depends on `printer` — a fresh object literal each
  220. // render would re-run it (and reset document.title) on every poll tick.
  221. const printer = useMemo(
  222. () =>
  223. kiosk
  224. ? overlay && { name: overlay.name, model: overlay.model, camera_rotation: overlay.camera_rotation }
  225. : printerData,
  226. [kiosk, overlay, printerData],
  227. );
  228. const printerIdentity = [
  229. config.showPrinter ? printer?.name : null,
  230. config.showModel ? mapModelCode(printer?.model ?? null) : null,
  231. ].filter(Boolean).join(' · ');
  232. const status = kiosk ? overlay : statusData;
  233. const { imageKey, handleStreamError } = useOverlayCameraRecovery(id > 0 && config.showCamera && status != null);
  234. const timeFormat: TimeFormat = (kiosk ? overlay?.time_format : settings?.time_format) || 'system';
  235. // WebSocket for real-time updates (JWT-authenticated; skipped in kiosk mode,
  236. // where the token can't mint a ws-token — the 2s poll above is the feed).
  237. useEffect(() => {
  238. if (!id || kiosk) return;
  239. let ws: WebSocket | null = null;
  240. let cancelled = false;
  241. // GHSA-r2qv follow-up: mint a ws-token before connecting. Uses
  242. // api.getWebSocketToken so the JWT Authorization header rides along
  243. // (raw fetch+credentials:'include' would miss it — Bambuddy uses
  244. // Bearer tokens, not cookies, for JWT auth). Auth-disabled deployments
  245. // succeed even without a token.
  246. (async () => {
  247. let wsToken: string | undefined;
  248. try {
  249. const resp = await api.getWebSocketToken();
  250. wsToken = resp.token;
  251. } catch (err) {
  252. // A 401 (JWT expired) / 403 (no WEBSOCKET_CONNECT permission) is an
  253. // auth decision — a tokenless socket would just be closed 4401, so
  254. // skip opening one and let the REST polling fallback keep the overlay
  255. // fresh. There's no reconnect loop on this page, so this is purely
  256. // avoiding one doomed socket per mount. A network/5xx error is not
  257. // auth: fall through and try anyway (auth-disabled deployments land
  258. // here with no token and connect fine).
  259. const status = err instanceof ApiError ? err.status : 0;
  260. if (status === 401 || status === 403) return;
  261. }
  262. if (cancelled) return;
  263. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  264. const tokenParam = wsToken ? `?token=${encodeURIComponent(wsToken)}` : '';
  265. const wsUrl = `${protocol}//${window.location.host}/api/v1/ws${tokenParam}`;
  266. ws = new WebSocket(wsUrl);
  267. ws.onmessage = (event) => {
  268. try {
  269. const data = JSON.parse(event.data);
  270. if (data.type === 'printer_status' && data.printer_id === id) {
  271. queryClient.setQueryData(['printerStatus', id], data.status);
  272. }
  273. } catch {
  274. // Ignore parse errors
  275. }
  276. };
  277. ws.onerror = () => {
  278. // WebSocket error - polling will continue as fallback
  279. };
  280. })();
  281. return () => {
  282. cancelled = true;
  283. if (ws) ws.close();
  284. };
  285. }, [id, kiosk, queryClient]);
  286. // Update document title
  287. useEffect(() => {
  288. document.title = printer ? `${printer.name} - ${t('streamOverlay.title')}` : t('streamOverlay.title');
  289. return () => {
  290. document.title = 'Bambuddy';
  291. };
  292. }, [printer, t]);
  293. if (!id) {
  294. return (
  295. <div className="min-h-screen bg-black flex items-center justify-center">
  296. <p className="text-white">{t('streamOverlay.invalidPrinterId')}</p>
  297. </div>
  298. );
  299. }
  300. if (!status) {
  301. return (
  302. <div className="min-h-screen bg-black flex items-center justify-center">
  303. <p className="text-gray-400">{t('common.loading')}</p>
  304. </div>
  305. );
  306. }
  307. const isPrinting = status.connected && (status.state === 'RUNNING' || status.state === 'PAUSE');
  308. const progress = status.progress || 0;
  309. // Temperature readings the URL asked for, in a fixed order, skipping any the
  310. // printer doesn't report. Labels reuse printers.heaterHistory.* so the naming
  311. // matches the heater chart rather than inventing a second vocabulary.
  312. const temps: Record<string, unknown> = status.temperatures ?? {};
  313. const tempReadings: {
  314. key: string;
  315. icon: React.ReactNode;
  316. label: string;
  317. current: number;
  318. target: number | null;
  319. }[] = [];
  320. if (config.showNozzle) {
  321. const nozzle = readTemp(temps, 'nozzle');
  322. const nozzle2 = readTemp(temps, 'nozzle_2');
  323. if (nozzle != null) {
  324. tempReadings.push({
  325. key: 'nozzle',
  326. icon: <Flame className={`classic-overlay__icon ${sizes.icon}`} />,
  327. label: t('printers.heaterHistory.nozzle', 'Nozzle'),
  328. current: nozzle,
  329. target: readTemp(temps, 'nozzle_target'),
  330. });
  331. }
  332. if (nozzle2 != null) {
  333. tempReadings.push({
  334. key: 'nozzle_2',
  335. icon: <Flame className={`classic-overlay__icon ${sizes.icon}`} />,
  336. label: t('printers.heaterHistory.nozzle2', 'Nozzle 2'),
  337. current: nozzle2,
  338. target: readTemp(temps, 'nozzle_2_target'),
  339. });
  340. }
  341. }
  342. if (config.showBed) {
  343. const bed = readTemp(temps, 'bed');
  344. if (bed != null) {
  345. tempReadings.push({
  346. key: 'bed',
  347. icon: <Square className={`classic-overlay__icon ${sizes.icon}`} />,
  348. label: t('printers.heaterHistory.bed', 'Bed'),
  349. current: bed,
  350. target: readTemp(temps, 'bed_target'),
  351. });
  352. }
  353. }
  354. if (config.showChamber) {
  355. const chamber = readTemp(temps, 'chamber');
  356. if (chamber != null) {
  357. tempReadings.push({
  358. key: 'chamber',
  359. icon: <Box className={`classic-overlay__icon ${sizes.icon}`} />,
  360. label: t('printers.heaterHistory.chamber', 'Chamber'),
  361. current: chamber,
  362. target: readTemp(temps, 'chamber_target'),
  363. });
  364. }
  365. }
  366. // Append the kiosk token directly rather than leaning on withStreamToken's
  367. // module cache — the cache is populated by an effect and would miss the first
  368. // render (a 401 flash before the retry). The logged-in path keeps the cache.
  369. const camPath = `/api/v1/printers/${id}/camera/stream?fps=${config.fps}&t=${imageKey}`;
  370. const streamUrl = kiosk && token
  371. ? `${camPath}&token=${encodeURIComponent(token)}`
  372. : withStreamToken(camPath);
  373. if (config.updatedArtwork) {
  374. const active = status.connected && isPrinting;
  375. const remainingTime = status.remaining_time;
  376. const hasRemaining = active && config.showEta && remainingTime != null && remainingTime > 0;
  377. const artwork = <UpdatedStreamOverlay
  378. layout={config.layout ?? undefined}
  379. backgroundTransparency={config.backgroundTransparency}
  380. customLogo={customLogo}
  381. progressBackground={progressBackground}
  382. size={config.size}
  383. camera={config.showCamera ? { url: streamUrl, rotation: printer?.camera_rotation ?? 0, onError: handleStreamError } : null}
  384. name={config.showPrinter ? printer?.name ?? null : null}
  385. model={config.showModel ? mapModelCode(printer?.model ?? null) || null : null}
  386. filename={config.showFilename && status.current_print ? formatPrintName(status.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i, ''), status.gcode_file, t) : null}
  387. status={config.showStatus ? (status.connected ? getStatusText(status, t) : t('streamOverlay.printerOffline')) : null}
  388. state={status.connected ? status.state : null}
  389. progress={active && config.showProgress ? Math.min(100, Math.max(0, Number.isFinite(progress) ? progress : 0)) : null}
  390. layers={active && config.showLayers && status.layer_num != null && status.total_layers != null && status.total_layers > 0 ? `${status.layer_num} / ${status.total_layers}` : null}
  391. remaining={hasRemaining ? formatDuration(remainingTime * 60) : null}
  392. eta={hasRemaining ? formatETA(remainingTime, timeFormat, t) : null}
  393. temperatures={status.connected ? tempReadings : []}
  394. />;
  395. return config.layout ? <OverlayFrame layout={config.layout}>{artwork}</OverlayFrame> : artwork;
  396. }
  397. const dimensions = config.layout ? OVERLAY_DIMENSIONS[config.layout] : null;
  398. const rotation = printer?.camera_rotation ?? 0;
  399. const sideways = Math.abs(rotation % 180) === 90;
  400. const artwork = (
  401. <div className="classic-overlay min-h-screen bg-black relative overflow-hidden" data-layout={config.layout ?? undefined} data-size={config.size}>
  402. {/* Camera feed - fullscreen background (optional) */}
  403. {config.showCamera && (
  404. <img
  405. key={imageKey}
  406. src={streamUrl}
  407. alt={t('streamOverlay.cameraStream')}
  408. className="absolute inset-0 w-full h-full object-contain"
  409. style={dimensions ? {
  410. left: '50%', top: '50%', maxWidth: 'none',
  411. width: sideways ? dimensions.height : dimensions.width,
  412. height: sideways ? dimensions.width : dimensions.height,
  413. transform: `translate(-50%, -50%) rotate(${rotation}deg)`,
  414. } : rotation ? { transform: `rotate(${rotation}deg)` } : undefined}
  415. onError={handleStreamError}
  416. />
  417. )}
  418. {/* Channel branding above the Bambuddy mark. */}
  419. <div className="absolute top-4 right-4 z-10 flex flex-col items-end">
  420. {customLogo}
  421. <a
  422. href="https://github.com/maziggy/bambuddy"
  423. target="_blank"
  424. rel="noopener noreferrer"
  425. >
  426. <img
  427. src="/img/bambuddy_logo_dark_transparent.png"
  428. alt="Bambuddy"
  429. className={`classic-overlay__logo ${sizes.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`}
  430. />
  431. </a>
  432. </div>
  433. {/* Status overlay - bottom */}
  434. <div className="absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent">
  435. <div className={`classic-overlay__panel ${sizes.container}`}>
  436. {/* Printer name and model can each be selected independently. */}
  437. {printerIdentity && (
  438. <div className={`flex items-center ${sizes.gap} mb-2`}>
  439. <Printer className={`classic-overlay__icon ${sizes.icon} shrink-0 text-white/70`} />
  440. <span className={`classic-overlay__text ${sizes.text} min-w-0 truncate text-white font-medium`}>{printerIdentity}</span>
  441. </div>
  442. )}
  443. {/* Filename */}
  444. {config.showFilename && status.current_print && (
  445. <div className={`classic-overlay__filename ${sizes.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`}>
  446. {formatPrintName(status.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i, ''), status.gcode_file, t)}
  447. </div>
  448. )}
  449. {/* Status text */}
  450. {config.showStatus && (
  451. <div className={`classic-overlay__text ${sizes.text} text-white/70 mb-2`}>
  452. {!status.connected ? t('streamOverlay.printerOffline') : getStatusText(status, t)}
  453. </div>
  454. )}
  455. {/* Progress bar */}
  456. {config.showProgress && isPrinting && (
  457. <div className="mb-3">
  458. <div className={`flex items-center justify-between mb-1 classic-overlay__text ${sizes.text}`}>
  459. <span className="text-white/70" style={progressTextStyle}>{t('streamOverlay.progress')}</span>
  460. <span className="text-white font-bold" style={progressTextStyle}>{Math.round(progress)}%</span>
  461. </div>
  462. <div className={`w-full bg-white/20 rounded-full ${sizes.progressHeight}`}>
  463. <div
  464. className={`bg-bambu-green ${sizes.progressHeight} rounded-full transition-all duration-500`}
  465. style={{ width: `${progress}%`, background: progressBackground }}
  466. />
  467. </div>
  468. </div>
  469. )}
  470. {/* Stats row */}
  471. {isPrinting && (config.showLayers || config.showEta) && (
  472. <div className={`flex items-center ${sizes.gap} flex-wrap`}>
  473. {/* Layers */}
  474. {config.showLayers && status.layer_num != null && status.total_layers != null && status.total_layers > 0 && (
  475. <div className={`flex items-center ${sizes.gap} text-white/70`}>
  476. <Layers className={`classic-overlay__icon ${sizes.icon}`} />
  477. <span className={`classic-overlay__text ${sizes.text}`}>
  478. <span className="text-white">{status.layer_num}</span>
  479. <span className="mx-1">/</span>
  480. <span>{status.total_layers}</span>
  481. </span>
  482. </div>
  483. )}
  484. {/* Remaining time */}
  485. {config.showEta && status.remaining_time != null && status.remaining_time > 0 && (
  486. <>
  487. <div className={`flex items-center ${sizes.gap} text-white/70`}>
  488. <Timer className={`classic-overlay__icon ${sizes.icon}`} />
  489. <span className={`classic-overlay__text ${sizes.text} text-white`}>
  490. {formatDuration(status.remaining_time * 60)}
  491. </span>
  492. </div>
  493. <div className={`flex items-center ${sizes.gap} text-white/70`}>
  494. <Clock className={`classic-overlay__icon ${sizes.icon}`} />
  495. <span className={`classic-overlay__text ${sizes.text} text-white`}>
  496. {t('streamOverlay.eta')} {formatETA(status.remaining_time, timeFormat, t)}
  497. </span>
  498. </div>
  499. </>
  500. )}
  501. </div>
  502. )}
  503. {/* Temperatures (#1422). Rendered whether or not a print is running —
  504. a preheating or cooling printer is exactly when these are worth
  505. watching. Each reading appears only when the printer reports it,
  506. so a single-nozzle machine shows one nozzle and a model without a
  507. chamber sensor shows no chamber row even if `chamber` is in
  508. ?show= (the backend omits the reading entirely for those). */}
  509. {tempReadings.length > 0 && status.connected && (
  510. <div className={`flex items-center ${sizes.gap} flex-wrap mt-2`}>
  511. {tempReadings.map((reading) => (
  512. <TempReading
  513. key={reading.key}
  514. icon={reading.icon}
  515. label={reading.label}
  516. current={reading.current}
  517. target={reading.target}
  518. sizes={sizes}
  519. />
  520. ))}
  521. </div>
  522. )}
  523. </div>
  524. </div>
  525. </div>
  526. );
  527. return config.layout ? <OverlayFrame layout={config.layout}>{artwork}</OverlayFrame> : artwork;
  528. }