* feat(api): GET /v1/live-rates 录制中房间的每秒写盘速率瘦端点
/v1/streamers 每次查全表、拼齐全部字段,10 s 一次的节奏不适合调快;码率曲线需要 1 s 粒度,
新加一个只读内存的瘦端点:扫一遍 worker,对每个 Working 的房间读一次阶段一 RateMeter 的窗口均值,
返回 [{id, bytes_per_sec, ts}]。与 /v1/streamers 的 live_bytes_per_sec 同源同值;不新增采样任务、
服务端不存历史、Cache-Control: no-store;注册在 router() 内,--auth 时同一道登录校验。
Part of #1708
* feat(ui): 实时码率数据层与 uPlot 折线组件
- app/lib/use-live-rates.ts:页面内唯一的一份采样源。有订阅者时每秒拉一次 /v1/live-rates,
全部卸载 / 标签页隐藏即停;历史放模块级环形缓冲(每房间最近 3 分钟),组件卸载不清,
切走再切回曲线还在;帧里没有的房间补 null 成断口。useSyncExternalStore 订阅,无新帧不重渲染。
- app/ui/RateChart.tsx:uPlot 折线,full(带时间轴 / Y 轴,单位按窗口最大值自动选 KB/s / MB/s,
Y 从 0 起)与 sparkline(无坐标轴,hover 读数)两种形态;实例在 effect 里建 / 销毁,渲染期不碰 ref,
StrictMode 双次 effect 不留多余 canvas;配色每次绘制时读 Semi CSS 变量,深浅色切换不重建。
无采样 / 未录制只显示「—」占位,不画空图。
- app/ui/LiveRateChart.tsx:next/dynamic 懒加载入口 + 当前 / 峰值 / 均值统计条;
uPlot 与其 CSS 打进独立 chunk(约 23 KB gzip),首屏不含。
- 新依赖 uplot ^1.6.32(本 PR 唯一新依赖)。
Part of #1708
* feat(ui): 三处接入码率折线——弹层可折叠折线、卡片与监视器 sparkline
- 卡片弹层底部新增「写盘速率 · 最近 3 分钟」可折叠区(默认展开,折叠态记 localStorage
biliup.preview.rateChart):标题行带当前 / 峰值 / 均值,展开时才轮询与加载 uPlot。
- 控制台 / 直播管理页录制中卡片:名称行下一条 60 s sparkline(28 px,hover 显示时刻与数值)。
- 历史记录页「实时监视」:工具栏新增「码率图」开关(默认关,记 biliup.monitor.rateChart),
开启后每路小窗下方一条 60 s sparkline;所有小窗共用同一次每秒请求。
Part of #1708
* style(api): live_rates 测试按 rustfmt 换行
* fix(ui): sparkline 的 hover 读数浮在折线上方,不再被容器裁掉
* docs(readme): 功能列表补充直播预览(封面 / 播放器 / 弹幕 / 码率曲线)
#1708 三个阶段至此完整,在 README 的功能列表里加一条说明。
Closes #1708
* feat(api): GET /v1/ws/live-rates 用 WebSocket 每秒推送码率帧
review 1(ForgQi):复用现有的 WebSocket 机制推送而不是每秒轮询。WebSocket 不占浏览器对同一主机
HTTP/1.1 的六个并发连接(监视器 4 路视频 + 1 条弹幕 SSE 已用掉五个,这正是当初不用 SSE 的原因),
与日志页 /v1/ws/logs 同款:Origin 与 Host 同源校验、进程内连接数上限(16)、Ping 回 Pong、Close 即止。
连上立刻发一帧,之后每秒一帧,形状与 GET /v1/live-rates 相同;HTTP 版保留给 WebSocket 连不上时回退与 curl 核对。
两个路由都在 router() 内,--auth 下同一道登录校验。单测用手写的最小 WebSocket 客户端走完握手 + 两帧,不引新依赖。
* feat(ui): 码率数据改走 WebSocket;卡片 sparkline 加开关并叠在封面上
review 1(ForgQi):
- use-live-rates.ts 首选一条 WebSocket /v1/ws/live-rates(服务端每秒推一帧,所有图表共用),
一帧都没收到就断开(反代没放行 upgrade、401)时回退到每秒 GET /v1/live-rates 轮询;中途断开退避重连,
标签页隐藏时断开、可见时重连;快照新增 transport: 'ws' | 'poll'。
- 控制台「进行中」区块头与直播管理页工具栏新增「码率图」开关(默认关,记 localStorage biliup.cards.rateChart,
两页共用);开启后录制中卡片的 sparkline 叠在封面底部(深色渐变垫底、读数条在图区内;点击仍冒泡到封面打开预览),
封面没有 / 加载失败时退到名称行下方。
* test(api): 码率 WebSocket 连接上限测试改用独立信号量
CI 上与同一二进制里并发跑的 WebSocket 推送测试争用进程级信号量(后者占着一个许可),
上限测试拿不满 16 个而失败;改为像 ws.rs 的日志连接测试那样传入独立的 Semaphore。
192 lines
3.6 KiB
SCSS
192 lines
3.6 KiB
SCSS
/* 直播预览:卡片弹层播放区 + 监视器小窗共用 */
|
|
|
|
.player {
|
|
position: relative;
|
|
width: 100%;
|
|
aspect-ratio: 16 / 9;
|
|
background: #000;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.player > div {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
}
|
|
|
|
/* 连接中 / 重连中 / 出错时盖在画面上的说明层 */
|
|
.overlay {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 12px;
|
|
padding: 16px;
|
|
text-align: center;
|
|
color: rgba(255, 255, 255, 0.88);
|
|
background: rgba(0, 0, 0, 0.55);
|
|
pointer-events: none;
|
|
}
|
|
.overlay :global(.semi-button) {
|
|
pointer-events: auto;
|
|
}
|
|
.player[data-phase='connecting'] .overlay,
|
|
.player[data-phase='reconnecting'] .overlay {
|
|
background: rgba(0, 0, 0, 0.35);
|
|
}
|
|
|
|
/* 出错 / 断开时垫在说明后面的封面 */
|
|
.overlayCover {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
opacity: 0.35;
|
|
z-index: -1;
|
|
}
|
|
.overlay {
|
|
isolation: isolate;
|
|
}
|
|
|
|
.overlayText {
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
max-width: 90%;
|
|
word-break: break-word;
|
|
}
|
|
|
|
/* ===== 弹层 ===== */
|
|
.modal :global(.semi-modal-header) {
|
|
margin-bottom: 0;
|
|
padding-bottom: 12px;
|
|
}
|
|
|
|
.modalTitle {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
min-width: 0;
|
|
/* 右侧留出关闭按钮的位置 */
|
|
padding-right: 28px;
|
|
}
|
|
|
|
.modalName {
|
|
font-size: 15px;
|
|
font-weight: 650;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
min-width: 0;
|
|
}
|
|
|
|
/* 取流方式角标:左上角,不挡播放器控制栏 */
|
|
.badge {
|
|
position: absolute;
|
|
top: 8px;
|
|
left: 8px;
|
|
/* Artplayer 内部各层 z-index 到 90+,角标要压在它们之上 */
|
|
z-index: 120;
|
|
max-width: calc(100% - 16px);
|
|
padding: 2px 8px;
|
|
border-radius: 999px;
|
|
font-size: 12px;
|
|
line-height: 18px;
|
|
color: #fff;
|
|
background: rgba(0, 0, 0, 0.55);
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
pointer-events: auto;
|
|
}
|
|
.badge[data-tone='direct'] {
|
|
background: rgba(22, 163, 74, 0.75);
|
|
}
|
|
.badge[data-tone='fallback'] {
|
|
background: rgba(217, 119, 6, 0.8);
|
|
}
|
|
.badge[data-compact] {
|
|
top: 4px;
|
|
left: 4px;
|
|
font-size: 11px;
|
|
line-height: 16px;
|
|
padding: 1px 6px;
|
|
}
|
|
|
|
.danmakuSwitch {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
margin-left: auto;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.modalFoot {
|
|
padding: 10px 24px 14px;
|
|
}
|
|
|
|
/* ===== 弹层底部:写盘速率折线(可折叠) ===== */
|
|
.rateSection {
|
|
border-top: 1px solid var(--semi-color-border);
|
|
}
|
|
.rateHead {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
width: 100%;
|
|
padding: 8px 24px;
|
|
border: 0;
|
|
background: transparent;
|
|
color: var(--semi-color-text-1);
|
|
font: inherit;
|
|
font-size: 12.5px;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
}
|
|
.rateHead:hover {
|
|
background: var(--semi-color-fill-0);
|
|
}
|
|
.rateHead:focus-visible {
|
|
outline: 2px solid var(--semi-color-primary);
|
|
outline-offset: -2px;
|
|
}
|
|
.rateTitle {
|
|
font-weight: 600;
|
|
white-space: nowrap;
|
|
margin-right: auto;
|
|
}
|
|
.rateChevron {
|
|
flex-shrink: 0;
|
|
color: var(--semi-color-text-2);
|
|
transition: transform 0.15s ease;
|
|
}
|
|
.rateSection[data-open='false'] .rateChevron {
|
|
transform: rotate(-90deg);
|
|
}
|
|
.rateBody {
|
|
padding: 4px 24px 8px;
|
|
}
|
|
@media (max-width: 600px) {
|
|
.rateHead {
|
|
flex-wrap: wrap;
|
|
padding: 8px 16px;
|
|
}
|
|
.rateBody {
|
|
padding: 4px 12px 8px;
|
|
}
|
|
}
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.rateChevron {
|
|
transition: none;
|
|
}
|
|
}
|
|
|
|
/* disabled 的按钮不响应鼠标,包一层让 Tooltip 仍能弹出 */
|
|
.disabledWrap {
|
|
display: inline-flex;
|
|
}
|
|
.disabledWrap :global(.semi-button) {
|
|
pointer-events: none;
|
|
}
|