SPB Git

Repository Public

Live.tsx 6.3 KB 152 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Vision8 * File             : web/src/pages/Live.tsx9 * Module           : pages10 * Repository       : https://git.spboucher.ai/maclustr-vision11 * Project Website  : https://camera.spboucher.ai12 * Created          : 2026-11-3013 * Last Modified    : 2026-11-3014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { useEffect, useMemo, useState } from 'react';43import { isTyping } from '../App';44import { LiveTile } from '../components/LiveTile';45import { useApp } from '../ctx';46import { IconCinema, IconPatrol, IconStats } from '../icons';47import { hevcSupported } from '../live';48import { setPrefs, usePrefs } from '../prefs';4950const LAYOUTS = [51  { n: 0, label: 'AUTO' },52  { n: 1, label: '1' },53  { n: 2, label: '2' },54  { n: 3, label: '3' },55  { n: 4, label: '4' },56  { n: 9, label: 'FOCUS' },57];5859/** Mur de moniteurs : mosaïque ou disposition « focus », ronde automatique, mode cinéma. */60export function LivePage() {61  const { cameras, navigate, toast } = useApp();62  const prefs = usePrefs();63  const hevc = useMemo(() => hevcSupported(), []);64  const [focus, setFocus] = useState(0);65  const [patrol, setPatrol] = useState(false);66  const online = cameras.filter((c) => c.status.reachable).length;67  const rec = cameras.filter((c) => c.status.recConfirmed).length;68  const cols = prefs.layout;69  const open = (id: string) => navigate(`/camera/${encodeURIComponent(id)}`);7071  // ronde : alterne la caméra mise en avant72  useEffect(() => {73    if (!patrol || cameras.length < 2) return;74    const t = window.setInterval(() => !document.hidden && setFocus((f) => (f + 1) % cameras.length), Math.max(4, prefs.patrolSeconds) * 1000);75    return () => clearInterval(t);76  }, [patrol, cameras.length, prefs.patrolSeconds]);7778  useEffect(() => {79    const on = (e: KeyboardEvent) => {80      if (isTyping(e) || e.metaKey || e.ctrlKey || e.altKey) return;81      const k = e.key.toLowerCase();82      if (k === 'c') document.body.classList.toggle('cinema');83      else if (k === 'i') setPrefs({ stats: !prefs.stats });84      else if (k === 'r') togglePatrol();85    };86    window.addEventListener('keydown', on);87    return () => window.removeEventListener('keydown', on);88  });89  useEffect(() => () => document.body.classList.remove('cinema'), []);9091  function togglePatrol() {92    if (cameras.length < 2) return toast('La ronde demande au moins deux caméras.');93    setPatrol((p) => {94      if (!p) setPrefs({ layout: 9 });95      toast(!p ? `Ronde : une caméra toutes les ${prefs.patrolSeconds} s` : 'Ronde arrêtée');96      return !p;97    });98  }99100  const focusProfile: 'main' | 'sub' = prefs.quality === 'sub' || !hevc ? 'sub' : 'main';101  const f = cameras[Math.min(focus, Math.max(0, cameras.length - 1))];102  return (103    <>104      <div className="page-head">105        <h1>106          Direct107          <span className="sub mono">108            {cameras.length ? `${online}/${cameras.length} EN LIGNE · ${rec} REC` : 'CHARGEMENT…'}109          </span>110        </h1>111        <button className={`btn icon ${prefs.stats ? 'on' : ''}`} onClick={() => setPrefs({ stats: !prefs.stats })} aria-pressed={prefs.stats} aria-label="Statistiques techniques" title="Statistiques techniques (I)">112          <IconStats />113        </button>114        <button className={`btn icon ${patrol ? 'on' : ''}`} onClick={togglePatrol} aria-pressed={patrol} aria-label="Ronde automatique" title="Ronde automatique (R)">115          <IconPatrol />116        </button>117        <button className="btn icon" onClick={() => (document.body.classList.add('cinema'), toast('Mode cinéma — Échap ou C pour revenir'))} aria-label="Mode cinéma" title="Mode cinéma (C)">118          <IconCinema />119        </button>120        <div className="seg" role="group" aria-label="Disposition">121          {LAYOUTS.map((l) => (122            <button key={l.n} aria-pressed={cols === l.n} onClick={() => (setPrefs({ layout: l.n }), l.n !== 9 && setPatrol(false))}>123              {l.label}124            </button>125          ))}126        </div>127      </div>128      {cameras.length === 0 ? (129        <div className="card empty">Aucune caméra à afficher pour l’instant.</div>130      ) : cols === 9 && f ? (131        <div className="focus-wall">132          <LiveTile key={`f-${f.id}`} cam={f} index={cameras.indexOf(f)} profile={focusProfile} zoomable className="focus-main" onFullscreen={() => open(f.id)} />133          <div className="strip">134            {cameras.map((c, i) =>135              c.id === f.id ? null : <LiveTile key={c.id} cam={c} index={i} profile="sub" small onOpen={() => (setFocus(i), setPatrol(false))} />,136            )}137          </div>138        </div>139      ) : (140        <div className={`mosaic ${cols === 0 ? `auto ${cameras.length > 4 ? 'many' : ''}` : `c${cols}`}`}>141          {cameras.map((c, i) => (142            <LiveTile key={c.id} cam={c} index={i} profile="sub" small={cols >= 3} onOpen={() => open(c.id)} />143          ))}144        </div>145      )}146      <button className="sr-only" onClick={() => document.body.classList.remove('cinema')}>147        Quitter le mode cinéma148      </button>149    </>150  );151}152
Files main
Menu

Theme