Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

3.3 KB
Raw Blame
import type { CopyKey } from "../../ui/copy";
import type { GlyphName } from "../../ui/icons";
import type { HintKind } from "../../ui/visual-kinds";

// The same metric keeps its icon and explanation in detail cells and headings.
export const METRIC_PRESENTATION = {
  "stats.resolution": { icon: "expand", hint: "hint-metric-resolution" },
  "stats.resolutionRange": { icon: "expand", hint: "hint-metric-resolution" },
  "stats.fps": { icon: "frames", hint: "hint-metric-fps" },
  "stats.fpsRange": { icon: "frames", hint: "hint-metric-fps" },
  "stats.bitrate": { icon: "gauge", hint: "hint-metric-bitrate" },
  "stats.totalBitrate": { icon: "gauge", hint: "hint-metric-bitrate", description: "stats.totalBitrateHint" },
  "stats.loss": { icon: "packetLoss", hint: "hint-metric-loss" },
  "stats.avgLoss": { icon: "packetLoss", hint: "hint-metric-loss", description: "stats.avgLossHint" },
  "stats.rtt": { icon: "clock", hint: "hint-metric-rtt", description: "stats.rttHint" },
  "stats.avgRtt": { icon: "clock", hint: "hint-metric-rtt", description: "stats.avgRttHint" },
  "stats.avgJitter": { icon: "jitter", hint: "hint-metric-jitter" },
  "stats.codec": { icon: "puzzle", hint: "hint-codec" },
  "voice.details.codec": { icon: "puzzle", hint: "hint-codec" },
  "stats.outgoing": { icon: "gauge", hint: "hint-metric-outgoing" },
  "stats.qualityState": { icon: "sliders", hint: "hint-metric-quality", wrap: true },
  "stats.capture": { icon: "share", hint: "hint-metric-capture", wrap: true },
  "stats.inputFps": { icon: "frames", hint: "hint-metric-input-fps", description: "stats.inputFpsHint" },
  "stats.encoder": { icon: "cpu", hint: "hint-metric-encoder", wrap: true },
  "stats.encodeMs": { icon: "clock", hint: "hint-metric-encode-time" },
  "stats.jitter": { icon: "jitter", hint: "hint-metric-jitter" },
  "stats.dropped": { icon: "frameDrop", hint: "hint-metric-dropped", description: "stats.droppedHint" },
  "stats.decodeMs": { icon: "clock", hint: "hint-metric-decode-time" },
  "stats.freezeCount": { icon: "pause", hint: "hint-metric-freezes" },
  "stats.freezeDuration": { icon: "clock", hint: "hint-metric-freeze-time" },
  "stats.audio": { icon: "speaker", hint: "hint-metric-audio-bitrate" },
  "stats.group.sourceAudio": { icon: "speaker", hint: "hint-source-audio" },
  "stats.audioLoss": { icon: "packetLoss", hint: "hint-metric-audio-loss" },
  "stats.audioJitter": { icon: "jitter", hint: "hint-metric-audio-jitter" },
  "stats.playoutDelta": { icon: "clock", hint: "hint-metric-playout" },
  "stats.videoBuffer": { icon: "clock", hint: "hint-metric-video-buffer" },
  "stats.audioBuffer": { icon: "clock", hint: "hint-metric-audio-buffer" },
  "stats.audioConcealedRate": { icon: "audioRepair", hint: "hint-metric-concealment-rate" },
  "stats.audioConcealed": { icon: "audioRepair", hint: "hint-metric-concealments" },
} satisfies Partial<Record<CopyKey, { icon: GlyphName; hint: HintKind; description?: CopyKey; wrap?: boolean }>>;

export type MetricLabel = keyof typeof METRIC_PRESENTATION;

export function metricHintText(label: MetricLabel, t: (key: CopyKey) => string, value?: string): string {
  const presentation = METRIC_PRESENTATION[label];
  const heading = value === undefined ? t(label) : `${t(label)} · ${value}`;
  return "description" in presentation ? `${heading}\n${t(presentation.description)}` : heading;
}