From 3e67f6728eca8f0c509a2acaa8992d25c0f4a51c Mon Sep 17 00:00:00 2001 From: egdev6 <18334564+egdev6@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:04:19 +0100 Subject: [PATCH] feat(chat): preview the chat in the real sources from the panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Widgets › Chat gets «Simular mensajes en Meld»: every real chat source (default, variants, custom overlay slots) plays the panel preview's sample messages for 120 s, then restores its real messages. Ephemeral server state (src/chat-preview.mjs) broadcast as the chatPreview event, also on connect; nothing is written to the chat, history or metrics. POST/GET /api/chat/preview and MCP vista_previa_chat. --- README.md | 4 +- app/src/lib/live.ts | 1 + app/src/lib/types.ts | 3 ++ app/src/panel/views/ChatWidget.tsx | 34 ++++++++++++- docs/estado.md | 1 + public/widgets/chat.html | 22 ++++++-- src/chat-preview.mjs | 27 ++++++++++ src/events.mjs | 2 +- src/mcp.mjs | 1 + src/routes/chat.mjs | 12 ++++- src/server.mjs | 6 ++- test/chat-preview-browser.test.mjs | 68 +++++++++++++++++++++++++ test/chat-preview.test.mjs | 80 ++++++++++++++++++++++++++++++ test/groups.json | 12 +++-- test/routes-chat.test.mjs | 1 + 15 files changed, 259 insertions(+), 15 deletions(-) create mode 100644 src/chat-preview.mjs create mode 100644 test/chat-preview-browser.test.mjs create mode 100644 test/chat-preview.test.mjs diff --git a/README.md b/README.md index e1e84df..23e0092 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,8 @@ In the panel, the «Fuentes del programa de emisión» page lists all of them wi | Thank-yous | `http://127.0.0.1:4500/widget/thanks` | 900×200 | | Interview | `http://127.0.0.1:4500/widget/interview` | 1920×1080 | +**Preview in your broadcast program:** in **Widgets › Chat**, «Simular mensajes en Meld» makes every real chat source (the default chat, its variants and custom overlay slots) play the same sample messages as the panel preview for 2 minutes, then return to the real chat. A source loaded during the simulation joins it. Nothing is added to the chat, the history or the metrics. API: `POST /api/chat/preview` with `{ "on": true }` (optional `"seconds"`, 1–600) or `{ "on": false }`; `GET /api/chat/preview` returns `{ on, until }`. MCP: `vista_previa_chat`. + **Interview.** Fullscreen layer for the active, approved item of the active interview (see `docs/entrevista-formato.md`): the question on a card at the bottom over its image, local video, YouTube player (starting at the saved minute) or social post card, with the source shown on every item that has media. Without an active item the layer is empty. In **Widgets › Se manejan en directo › Entrevista**, create or import interviews, edit and reorder rounds and questions, and press **Guardar** to save the draft. The detail header selects or stops the active interview and controls the live layer; the dock can also stop it without deleting it. `POST /api/interviews/stop` does the same and is safe to repeat. **Capa** has its URL and demo preview. Private notes never appear on the layer. Try it with `?demo`. **Offline thank-yous.** This layer rotates one pending offline follower at a time and can finish with YouTube's anonymous count. In Widgets › Agradecimientos, choose platforms, all time / since the last archived stream / a number of days, the maximum names and rotation interval. Unknown follow dates remain included; with no archived stream, the last-stream window has no cutoff. Nothing pending leaves the layer transparent. Individual and confirmed bulk thank-you actions apply immediately; bulk affects only the names and anonymous records selected for the saved widget settings, not other pending followers. @@ -541,7 +543,7 @@ Claude Desktop (`claude_desktop_config.json`): | Giveaway | `estado_sorteo`, `abrir_sorteo`, `cerrar_sorteo`, `sortear`, `anadir_participante`, `quitar_participante`, `reiniciar_sorteo` | | Interactives | `estado_interactivos`, `configurar_interactivos` | | Files | `listar_archivos`, `importar_archivo` (from a path on your PC), `borrar_archivo` | -| Chat | `leer_chat`, `escribir_chat` (Twitch, YouTube or both), `simular_chat`, `unir_chat`, `youtube_conectar_cuenta`, `youtube_desconectar_cuenta` | +| Chat | `leer_chat`, `escribir_chat` (Twitch, YouTube or both), `simular_chat`, `vista_previa_chat`, `unir_chat`, `youtube_conectar_cuenta`, `youtube_desconectar_cuenta` | | Widgets | `ver_widgets`, `editar_widget`, `editar_variante_chat`, `crear_objetivo`, `editar_objetivo`, `borrar_objetivo`, `crear_barra`, `editar_barra`, `borrar_barra`, `sumar_objetivo`, `fijar_objetivo`, `sumar_barra`, `fijar_barra`, `lanzar_creditos`, `parar_creditos` | | Custom overlays | `listar_overlays`, `ver_overlay`, `crear_overlay`, `editar_overlay`, `borrar_overlay`, `probar_overlay`, `css_overlay_tema` | | Stream | `resumen_directo`, `metricas_directo`, `nuevo_directo`, `renombrar_directo`, `listar_directos`, `eventos_directo` | diff --git a/app/src/lib/live.ts b/app/src/lib/live.ts index a60b9c2..faf7dc9 100644 --- a/app/src/lib/live.ts +++ b/app/src/lib/live.ts @@ -330,6 +330,7 @@ class Live { for (const r of this.inflightRemoved) r.ids.add(id); this.update(s => ({ widgets: { ...s.widgets, chat: (s.widgets?.chat || []).filter(m => m.id !== id) } })); }); + on('chatPreview', () => {}); // views listen with live.on('chatPreview') on('chatResult', () => {}); // only partial failures arrive; the panel shows them as a toast on('chatClear', ({ login }) => { for (const r of this.inflightRemoved) r.logins.add(login || null); diff --git a/app/src/lib/types.ts b/app/src/lib/types.ts index 0fde3f3..5a89333 100644 --- a/app/src/lib/types.ts +++ b/app/src/lib/types.ts @@ -179,6 +179,8 @@ export interface AnonymousFollowers { at: string | null; count: number; thanked: export interface FollowerSelection { entries: FollowerEntry[]; anonymous: AnonymousFollowers[] } export interface FollowersList extends FollowerSelection { shown: FollowerSelection } export interface ThanksSnapshot { names: { name: string; platform: Platform }[]; anonymous: number } +/** Chat preview in the real sources (GET/POST /api/chat/preview, SSE chatPreview). */ +export interface ChatPreviewState { on: boolean; until: string | null } export interface WidgetsConfig { goals?: GoalConfig[]; chat?: WidgetSection; @@ -523,6 +525,7 @@ export interface LiveEvents { chat: ChatMessage; chatDelete: { id: string }; chatResult: ChatResult; + chatPreview: ChatPreviewState; chatClear: { login: string }; timeline: Timeline; prompter: PrompterState; diff --git a/app/src/panel/views/ChatWidget.tsx b/app/src/panel/views/ChatWidget.tsx index 1d1f568..a7e82f6 100644 --- a/app/src/panel/views/ChatWidget.tsx +++ b/app/src/panel/views/ChatWidget.tsx @@ -8,7 +8,7 @@ import { horizontalCssWarnings } from '../../lib/chat-css'; import { live, useLive } from '../../lib/live'; import { ManualDraft } from '../../lib/manual-draft'; import { patchWidgets } from '../../lib/patch'; -import type { ChatVariant, WidgetSection } from '../../lib/types'; +import type { ChatPreviewState, ChatVariant, WidgetSection } from '../../lib/types'; import { BrowserSource, codeTab, confirmDelete, Panel, Stage, Switch, toast, WidgetLayout } from '../../lib/ui'; const ROUTE = '/api/widgets/chat/variants'; @@ -210,7 +210,7 @@ export function ChatWidget({ info, anims }: { info: Info; anims: Options }) { return Widgets › {info.title}} title={info.title} desc={info.desc} back="#/widgets" wide foot={}> } - preview={Datos de ejemplo} src={preview} w={dimensions.w} h={dimensions.h} />}> + preview={<>Datos de ejemplo} src={preview} w={dimensions.w} h={dimensions.h} />}>