Files
piik/src/client/pages/TooltipPreviewPage.tsx
T
AAA 1b9f5bd2a2 feat: add room interactions and media sharing improvements
## Problem and outcome / 问题与结果

This phase adds lightweight room interaction without making media depend on chat,
and adds Windows source-audio exclusion and optional SFU-only hosting at their
existing owners. It also corrects confirmed encoder/capture ownership and native
color-conversion defects. Host microphone commentary remains on the shared media
path; room voice and 4K are outside this phase.

## Release notes

### 中文

这是一次功能更新:Piik 加入了文字聊天与表情互动,并完善了 Windows 声音采集、画面颜色和自部署选项。

#### 新功能

- **边看边聊。** 在可移动、可缩放的聊天窗口中发送消息,或开启弹幕。停止分享后,房间中的朋友仍可继续聊天。
- **表情互动。** 点击沙发上的人物,给自己发表情,或把番茄等表情送给朋友;各端按同一事件显示动画。
- **排除应用声音。** Windows App 分享整个屏幕时,可排除一个应用及其子进程的声音,适合同时使用语音软件。所选应用退出后,来源声音停止,避免恢复为未过滤的系统声音。
- **可选的纯 SFU 模式。** 自部署管理员可让共享画面和声音统一通过媒体服务器转发。默认仍为优先 P2P;App 公网邀请保持纯 P2P。
- **Windows HDR 转 SDR。** 原生采集与缩略图自动将 HDR 来源转换为 SDR,沿用现有观看链路。

#### 修复与改进

- 修复原生颜色转换的范围与矩阵处理,避免已复现的暗部丢失、高光裁切和颜色偏差。
- 修复共享编码器切换时使用过期需求或过期帧信息的问题,保护正在观看的画面;修复换源后旧采集事件可能影响新来源的问题。
- 统一新控件、浮窗与来源选择文案,补充中英文使用说明。

#### 使用与升级

聊天与表情需要新版站点页面和 Server;声音排除需要新版页面与支持此能力的 Windows App。聊天只保留本页最近收到的消息,刷新后清空,不补发历史,且不提供端到端加密。

HDR 转换输出为 SDR,不代表端到端 HDR 或多声道支持。既有房主麦克风与立体声能力保留。

### English

This feature update brings text chat and reactions to Piik, alongside improvements to Windows audio capture, picture colors and self-hosting options.

#### New features

- **Chat while watching.** Send messages in a movable, resizable window, or enable on-screen chat. Friends can keep chatting after the host stops sharing.
- **Reactions.** Select a person on the sofa to react above yourself or send a tomato and other reactions to a friend. Participants animate the same shared event.
- **Exclude application audio.** When sharing a whole screen with Windows App, exclude one application and its child processes, useful when using a separate voice app. Source audio stops if the selected app exits, preventing a return to unfiltered system sound.
- **Optional SFU-only hosting.** Site operators can require shared video and audio to pass through the media server. P2P-first remains the default; App Public invite remains P2P-only.
- **Windows HDR-to-SDR conversion.** Native capture and source thumbnails automatically convert HDR sources to SDR for the existing viewing path.

#### Fixes and improvements

- Correct native color-conversion ranges and matrices, addressing reproduced crushed shadows, clipped highlights and color shifts.
- Correct stale demand and frame evidence during shared-encoder handoffs to protect the current picture. Prevent events from a replaced capture from affecting its successor.
- Align new controls, floating panels and source-picker copy, with updated Chinese and English guides.

#### Using this update

Chat and reactions require updated site pages and Server. Audio exclusion requires updated pages and a Windows App that supports the capability. Chat retains only recent messages received by the current page, clears on refresh and does not replay history. It is not end-to-end encrypted.

HDR conversion produces SDR; it does not add end-to-end HDR or surround sound. Existing host microphone commentary and stereo support remain available.

## Verification / 验证

- Web type checks, 78 test files / 1275 tests and production build: PASS.
- Go core tests, formatting/vet and target builds: PASS; Darwin cgo remains platform-limited on this Windows runner.
- Native build/check/color probes and synthetic HDR-to-SDR H.264/VP8 browser reception: PASS.
- Access/privacy gate, Native H.264 SFU-only media gate and local Auto/H.264 Host gate: PASS.
- Three real production pages: chat/reactions, stop/resume, idle-room join, host departure/return, offline draft recovery and invitation revocation: PASS.
- Synthetic parent/child process-audio exclusion and target lifetime: PASS; no raw audio retained.
- Windows candidate archive extraction and packaged Local startup/shutdown: PASS.
- Documentation and website build: PASS.
- [Candidate CI](https://github.com/TNTcraftHIM/Piik/actions/runs/36873766646) at
  `f26cd208d03bc0dcbe353f8cac217f993216b0a3`: Go core and race checks, Web tests,
  Server/container checks and Windows/macOS/Linux App packaging all PASS.
  Publication was skipped as intended.

The owner accepted the UI/model and bounded local walkthrough for phase closure.
Physical HDR/mixed displays, mobile keyboard,
real voice applications across output devices and macOS/Linux capture remain
unverified. Existing field reports without matched evidence are not claimed
resolved. The owner authorized v1.7.0 publication on 2026-10-02. The final
documentation-only commit records that authorization; product code matches
the verified candidate above.

## Impact / 影响

Authorized version: **v1.7.0**, matching the local release planner. Current wire
contracts remain Browser/server 23, Native control 9 and capture 7. Optional
capabilities gate new functionality; existing room/media authority remains owned
by the existing services. No new ports, message persistence, room voice or
automatic room creation on page visit. Updated README, guides, standards,
research evidence and TODO stay with the candidate phase.
2026-10-02 01:36:45 +08:00

147 lines
9.4 KiB
TypeScript

import { useState } from "react";
import { AppHeader } from "../components/living/Header";
import { Tooltip } from "../components/living/Tooltip";
import { ControlsPreview } from "./ControlsPreview";
import { WelcomeLine, WelcomeCipher } from "../components/living/WelcomeLine";
import { locales } from "../locales";
import { HINT_KINDS, HintComic, isHintKind, type HintKind } from "../components/living/hints";
import { Comic, type ComicKind } from "../components/living/Comic";
import { COMIC_KINDS, getComicPresentation, type ComicTone, type ComicMotion } from "../components/living/comic-presentation";
import { useCopy, type CopyKey } from "../ui/copy";
import { replaySvgAnimations } from "../ui/animation";
import { MetricCells } from "../components/living/Metrics";
import { EMPTY_METRICS } from "../types";
const EXAMPLES: { label: string; kind: HintKind | ComicKind; tone: ComicTone; motion: ComicMotion; text: CopyKey }[] = [
{ label: "说明 / Neutral", kind: "hint-volume", tone: "off", motion: "demo", text: "playback.volume" },
{ label: "成功 / Success", kind: "hint-copy-code", tone: "live", motion: "still", text: "common.copied" },
{ label: "受限 / Limited", kind: "hint-nat-unavailable", tone: "warn", motion: "still", text: "host.advanced.route.natPredictionUnavailable" },
{ label: "App incompatible", kind: "warning", tone: "warn", motion: "still", text: "native.incompatible" },
{ label: "Fullscreen waiting", kind: "hint-fullscreen-unavailable", tone: "warn", motion: "still", text: "playback.fullscreenWaiting" },
{ label: "Fullscreen failed", kind: "hint-fullscreen-unavailable", tone: "bad", motion: "still", text: "playback.fullscreenFailed" },
{ label: "失败 / Failed", kind: "warning", tone: "bad", motion: "still", text: "common.copyFailed" },
{ label: "连接中 / Connecting", kind: "signal-connecting", tone: "busy", motion: "progress", text: "state.signal.connecting" },
{ label: "恢复中 / Recovering", kind: "recovering", tone: "warn", motion: "progress", text: "state.peer.reconnecting" },
];
function PreviewCard({ kind, tone, motion, label, text }: {
kind: ComicKind | HintKind; tone?: ComicTone; motion?: ComicMotion; label?: string; text?: string;
}) {
const defaults = getComicPresentation(kind);
const replay = (card: HTMLElement) => {
const scene = card.querySelector(".lr-tooltip-preview-art > svg");
if (scene) replaySvgAnimations(scene);
};
return <section id={label ? undefined : kind} className="lr-tooltip-preview-card"
onPointerEnter={(event) => { if (event.pointerType !== "touch") replay(event.currentTarget); }}
onPointerDown={(event) => { if (event.pointerType === "touch") replay(event.currentTarget); }}
onFocusCapture={(event) => replay(event.currentTarget)}>
<header>
<code>{label ?? kind}</code>
<span className="lr-tooltip-preview-actions">
{text ? <Tooltip toggleOnClick kind={kind} tone={tone} motion={motion} text={text} place="below">
<button type="button" aria-label={`Text ${label ?? kind}`} className="lr-tooltip-preview-trigger">Aa</button>
</Tooltip> : null}
<Tooltip toggleOnClick kind={kind} tone={tone} motion={motion} place="below">
<button type="button" aria-label={`Preview ${label ?? kind}`} className="lr-tooltip-preview-trigger">✦</button>
</Tooltip>
</span>
</header>
<div className="lr-tooltip-preview-art">
{isHintKind(kind) ? <HintComic kind={kind} size={320} tone={tone} motion={motion} />
: <Comic kind={kind} size={320} theme="paper" tone={tone} motion={motion} />}
</div>
<small>{tone ?? defaults.tone} · {motion ?? defaults.motion}</small>
</section>;
}
export function TooltipPreviewPage() {
const { t, lang } = useCopy();
const en = lang === "en";
const [reducedMotion, setReducedMotion] = useState(false);
return (
<div className="lr-app" data-comic-reduced-motion={reducedMotion || undefined}>
<AppHeader />
<main className="lr-room lr-tooltip-preview">
<header className="lr-tooltip-preview-head">
<h1>{en ? "Piik · UI catalogue" : "Piik · UI 控件大全"}</h1>
<p>{en ? "Actual components, sample data. Comics loop while displayed. Use the corner buttons to open the same tooltip on hover, focus or tap." : "正式组件,示例数据。漫画在展示期间循环;悬停、聚焦或点击角上的按钮,可查看实际提示。"}</p>
<label><input type="checkbox" checked={reducedMotion} onChange={event => setReducedMotion(event.target.checked)} />
{en ? "Reduced motion" : "减少动态效果"}</label>
</header>
<nav className="cp-nav" aria-label={en ? "Preview sections" : "预览目录"}>
<a href="#button-preview">{en ? "Buttons" : "按钮"}</a><a href="#option-preview">{en ? "Options" : "选择与开关"}</a>
<a href="#input-preview">{en ? "Inputs" : "输入与房间号"}</a><a href="#feedback-preview">{en ? "Feedback" : "反馈"}</a>
<a href="#people-preview">{en ? "People & connections" : "人物、沙发与连接图"}</a><a href="#source-preview">{en ? "Source picker" : "画面选择"}</a>
<a href="#playback-preview">{en ? "Playback" : "播放栏"}</a><a href="#comic-preview">{en ? "Tooltips & comics" : "提示与漫画"}</a>
<a href="#launcher-preview">{en ? "App launcher" : "模式选择"}</a>
<a href="#interaction-preview">{en ? "Chat & reactions" : "聊天与互动"}</a>
<a href="#hint-admission-code">{en ? "Room entry" : "房间准入"}</a>
<a href="#metrics-preview">{en ? "Metrics" : "连接数据"}</a>
<a href="#welcome-preview">{en ? "Opening lines" : "开场白"}</a>
<a href="/__status-preview">{en ? "Status gallery" : "完整状态预览"}</a>
</nav>
<ControlsPreview />
<MetricPreview />
<WelcomeLine still={reducedMotion} />
<details id="welcome-preview" className="lr-welcome-catalog" open>
<summary>{locales[lang].playful.welcome.length} {en ? "opening lines" : "句开场白"}</summary>
<p>{en ? "A line appears immediately, then changes every eight seconds while visible. Each language has its own pool. Pure visual mode uses that entry's pictograms and pixel lettering; switching modes keeps the same entry." : "短句立即出现,可见时每 8 秒换一条。各语言独立维护词库;纯视觉模式显示当前语句对应的图形与像素暗号,切换模式仍是同一句。"}</p>
<ol>{locales[lang].playful.welcome.map(({ text, symbols }) => <li key={text}><span>{text}</span><WelcomeCipher symbols={symbols} /></li>)}</ol>
</details>
<h2 id="comic-preview">语义规则 / Semantic grammar</h2>
<p>{en ? "Aa pairs the scene with a caption; ✦ shows the pure-visual version." : "Aa 查看图示与文字说明,✦ 查看纯视觉版本。"}</p>
<div className="lr-tooltip-preview-grid">
{EXAMPLES.map((example) => <PreviewCard key={example.label} {...example} text={t(example.text)} />)}
</div>
<h2>操作说明 / Controls</h2>
<div className="lr-tooltip-preview-grid">
{HINT_KINDS.map((kind) => <PreviewCard key={kind} kind={kind} />)}
</div>
<h2>状态说明 / States</h2>
<div className="lr-tooltip-preview-grid">
{COMIC_KINDS.map((kind) => <PreviewCard key={kind} kind={kind} />)}
</div>
</main>
</div>
);
}
function MetricPreview() {
const { t, lang } = useCopy();
const en = lang === "en";
const [reason, setReason] = useState("other");
const [sendExpanded, setSendExpanded] = useState(true);
const [receiveExpanded, setReceiveExpanded] = useState(true);
const metrics = {
...EMPTY_METRICS,
resolution: "1920x1080", framesPerSecond: 59.8, bitrateKbps: 7200,
packetLossPercent: .2, rttMs: 24, codec: "video/H264",
availableOutgoingKbps: 12000, qualityLimitationReason: reason,
captureWidth: 2560, captureHeight: 1440, captureFramesPerSecond: 60,
mediaSourceFramesPerSecond: 60, encoderImplementation: "Sample encoder",
powerEfficientEncoder: true, intervalEncodeMs: 2.4,
jitterMs: 1.2, intervalFramesDropped: 2, intervalDecodeMs: 1.4,
intervalFreezeCount: 1, intervalFreezeDurationMs: 120,
audioBitrateKbps: 96, audioPacketLossPercent: .1, audioJitterMs: .8,
audioVideoPlayoutDeltaMs: 3, videoJitterBufferDelayMs: 12,
audioJitterBufferDelayMs: 15, audioConcealedSamplesPercent: .2,
intervalAudioConcealmentEvents: 1,
};
return <section id="metrics-preview" className="cp-section">
<h2>{en ? "Connection metrics" : "连接数据"}</h2>
<p>{en ? "Sample observations in the actual detail cells. Sender limits do not describe the receiver's playback."
: "用正式详情控件展示示例观测。发送端的限制不代表观众的播放状态。"}</p>
<label>{t("stats.qualityState")} <select value={reason} onChange={event => setReason(event.target.value)}>
{(["none", "bandwidth", "cpu", "other", "unclassified"] as const).map(value => <option key={value} value={value}>
{t(value === "none" ? "stats.quality.normal" : `stats.quality.${value}`)}
</option>)}
</select></label>
<h3>{en ? "Sending" : "发送"}</h3>
<MetricCells metrics={metrics} direction="send" expanded={sendExpanded} onToggle={setSendExpanded} />
<h3>{en ? "Receiving" : "接收"}</h3>
<MetricCells metrics={metrics} direction="receive" expanded={receiveExpanded} onToggle={setReceiveExpanded} />
</section>;
}