@soffits/dsh-media-hub 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/locale/zh.json CHANGED
@@ -109,6 +109,7 @@
109
109
  "rooms.heading": "正在进行的房间",
110
110
  "room.tab.episodes": "选集",
111
111
  "room.tab.about": "简介",
112
+ "room.tab.comments": "评论",
112
113
  "room.nextSeason": "下一季:{title}",
113
114
  "room.state.playing": "播放中",
114
115
  "room.state.paused": "已暂停",
@@ -231,6 +232,32 @@
231
232
  "quality.auto": "自动",
232
233
  "quality.audio": "仅音频",
233
234
  "quality.height": "{n}p",
235
+ "quality.fromNext": "从下一集起生效,房间里每个人都一样。",
236
+ "quality.changing": "正在切换…",
237
+ "danmaku.label": "弹幕",
238
+ "danmaku.count": "弹幕 {n}",
239
+ "danmaku.opacity": "不透明度",
240
+ "danmaku.area": "显示区域",
241
+ "danmaku.area.quarter": "1/4 屏",
242
+ "danmaku.area.half": "半屏",
243
+ "danmaku.area.full": "全屏",
244
+ "danmaku.size": "字号",
245
+ "danmaku.size.small": "小",
246
+ "danmaku.size.medium": "标准",
247
+ "danmaku.size.large": "大",
248
+ "player.settings": "播放设置",
249
+ "player.full": "全屏",
250
+ "player.exitFull": "退出全屏",
251
+ "comments.loading": "正在加载评论…",
252
+ "comments.none": "还没有评论。",
253
+ "comments.more": "更多评论",
254
+ "comments.someone": "某位观众",
255
+ "comments.rating": "评分 {score}",
256
+ "comments.likes": "{n} 赞",
257
+ "comments.replies.one": "{n} 条回复",
258
+ "comments.replies.other": "{n} 条回复",
259
+ "comments.total.one": "站内共 {n} 条评论",
260
+ "comments.total.other": "站内共 {n} 条评论",
234
261
  "error.blocked": "网站拒绝了这次请求,可能屏蔽了媒体中心所用的网络,稍后再试。",
235
262
  "error.sign_in": "这个视频需要登录账号才能看,请让管理媒体中心的人添加一个。",
236
263
  "error.not_found": "这个地址没有可播放的内容,检查一下链接。",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soffits/dsh-media-hub",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A media hub for DeepSeek Harness: search shows, novels, ebooks and papers across sources, watch together in sync, and download books in the format you want onto your own shelf.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -75,6 +75,7 @@
75
75
  "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.1",
76
76
  "@deepseek-ai/schemastery": "^3.19.0",
77
77
  "@soffits/dsh-ui-kit": "0.2.0",
78
+ "danmaku": "^2.0.10",
78
79
  "esbuild": "^0.28.2",
79
80
  "hls.js": "^1.7.4",
80
81
  "https-proxy-agent": "^9.1.0",
@@ -0,0 +1,55 @@
1
+ /**
2
+ * A room's Comments tab: what people wrote about the work on its site, read
3
+ * only, newest copy first from the hub (src/remarks.js), with more pages on
4
+ * request.
5
+ */
6
+ import { formatCount } from './format.js'
7
+ import { React, api, day, fill, h, plural } from './ui.js'
8
+
9
+ function Comment({ t, item }) {
10
+ return h('li', { className: 'vsync-comment' },
11
+ h('div', { className: 'vsync-commentHead' },
12
+ h('strong', { className: 'vsync-commentName' }, item.name || t('comments.someone')),
13
+ item.rating !== null && h('span', { className: 'vsync-commentRating' }, fill(t('comments.rating'), { score: item.rating })),
14
+ item.created && h('span', { className: 'vsync-commentDate' }, day(t, Date.parse(item.created)))),
15
+ h('p', { className: 'vsync-commentText' }, item.text),
16
+ (item.likes > 0 || item.replies > 0) && h('div', { className: 'vsync-commentStats' },
17
+ item.likes > 0 && h('span', null, fill(t('comments.likes'), { n: formatCount(item.likes, t.language) })),
18
+ item.replies > 0 && h('span', null, plural(t, 'comments.replies', item.replies))))
19
+ }
20
+
21
+ export function Comments({ t, roomId }) {
22
+ const [pages, setPages] = React.useState(null)
23
+ const [error, setError] = React.useState(null)
24
+ const [busy, setBusy] = React.useState(false)
25
+ const path = `rooms/${encodeURIComponent(roomId)}/comments`
26
+
27
+ React.useEffect(() => {
28
+ let live = true
29
+ api(path).then((answer) => {
30
+ if (!live) return
31
+ if (answer.error) setError(answer.error)
32
+ else setPages([answer])
33
+ })
34
+ return () => { live = false }
35
+ }, [path])
36
+
37
+ if (error !== null) return h('p', { className: 'vsync-commentNote' }, error)
38
+ if (pages === null) return h('p', { className: 'vsync-commentNote', role: 'status' }, t('comments.loading'))
39
+ const items = pages.flatMap(page => page.items)
40
+ const next = pages[pages.length - 1].next
41
+ const more = async () => {
42
+ setBusy(true)
43
+ const answer = await api(`${path}?cursor=${encodeURIComponent(next)}`)
44
+ setBusy(false)
45
+ if (answer.error) return setError(answer.error)
46
+ const seen = new Set(items.map(item => item.id))
47
+ return setPages([...pages, { ...answer, items: answer.items.filter(item => !seen.has(item.id)) }])
48
+ }
49
+ return h('div', { className: 'vsync-comments' },
50
+ pages[0].total > 0 && h('p', { className: 'vsync-commentNote' }, plural(t, 'comments.total', pages[0].total)),
51
+ items.length === 0
52
+ ? h('p', { className: 'vsync-commentNote' }, t('comments.none'))
53
+ : h('ul', { className: 'vsync-commentList' }, items.map(item => h(Comment, { key: item.id, t, item }))),
54
+ next && h('button', { type: 'button', className: 'vsync-btn', disabled: busy, onClick: more }, busy ? t('comments.loading') : t('comments.more')))
55
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Danmaku over the picture: the comments people posted at a moment of an
3
+ * episode fly across it in time with the <video> playing, through Danmaku
4
+ * (weizhenye/Danmaku, its DOM engine, served by the host as danmaku.mjs).
5
+ * How they show (on or off, how opaque, how much of the picture they may
6
+ * cover, how large) is each viewer's own choice, kept in this browser.
7
+ */
8
+ import { React, h } from './ui.js'
9
+
10
+ const SETTINGS_KEY = 'media-hub.danmaku'
11
+ /** Seconds a comment takes to cross the picture, whatever its width (the official apps use about this). */
12
+ const CROSS_SECONDS = 8
13
+ export const AREAS = Object.freeze([0.25, 0.5, 1])
14
+ export const SIZES = Object.freeze(['small', 'medium', 'large'])
15
+ export const OPACITIES = Object.freeze([0.25, 0.5, 0.75, 1])
16
+ const DEFAULTS = Object.freeze({ on: true, opacity: 0.75, area: 0.5, size: 'medium' })
17
+
18
+ function loadSettings() {
19
+ try {
20
+ const saved = JSON.parse(localStorage.getItem(SETTINGS_KEY) ?? '{}')
21
+ return {
22
+ on: typeof saved.on === 'boolean' ? saved.on : DEFAULTS.on,
23
+ opacity: OPACITIES.includes(saved.opacity) ? saved.opacity : DEFAULTS.opacity,
24
+ area: AREAS.includes(saved.area) ? saved.area : DEFAULTS.area,
25
+ size: SIZES.includes(saved.size) ? saved.size : DEFAULTS.size,
26
+ }
27
+ } catch {
28
+ return { ...DEFAULTS }
29
+ }
30
+ }
31
+
32
+ /** This viewer's danmaku settings and a way to change some of them. */
33
+ export function useDanmakuSettings() {
34
+ const [settings, setSettings] = React.useState(loadSettings)
35
+ const change = React.useCallback((patch) => {
36
+ setSettings((current) => {
37
+ const next = { ...current, ...patch }
38
+ try {
39
+ localStorage.setItem(SETTINGS_KEY, JSON.stringify(next))
40
+ } catch { /* private mode: the choice lasts for this page */ }
41
+ return next
42
+ })
43
+ }, [])
44
+ return [settings, change]
45
+ }
46
+
47
+ /**
48
+ * The layer over the stage. `media` is the <video> in front (the player swaps
49
+ * elements between episodes), `items` the episode's danmaku `[{ time, text }]`.
50
+ */
51
+ export function DanmakuLayer({ media, items, settings }) {
52
+ const box = React.useRef(null)
53
+ React.useEffect(() => {
54
+ const container = box.current
55
+ if (container === null || media === null || items.length === 0) return undefined
56
+ let engine = null
57
+ let gone = false
58
+ const fit = () => {
59
+ if (engine === null) return
60
+ engine.resize()
61
+ engine.speed = Math.max(60, container.offsetWidth / CROSS_SECONDS)
62
+ }
63
+ const watcher = new ResizeObserver(fit)
64
+ import(new URL('./danmaku.mjs', import.meta.url).href).then(({ default: Danmaku }) => {
65
+ if (gone) return
66
+ engine = new Danmaku({ container, media, engine: 'dom', comments: items.map(item => ({ text: item.text, time: item.time, mode: 'rtl' })) })
67
+ fit()
68
+ watcher.observe(container)
69
+ })
70
+ return () => {
71
+ gone = true
72
+ watcher.disconnect()
73
+ engine?.destroy()
74
+ }
75
+ }, [media, items])
76
+ return h('div', {
77
+ ref: box,
78
+ className: 'vsync-danmaku',
79
+ 'aria-hidden': 'true',
80
+ 'data-size': settings.size,
81
+ style: { opacity: settings.opacity, height: `${settings.area * 100}%` },
82
+ })
83
+ }
package/web/page.js CHANGED
@@ -117,16 +117,18 @@ export function Page({ t, initialRoom }) {
117
117
  // The plugin announces every change of what the page shows (src/changes.js); the page re-reads then, and once when the stream (re)connects. No timer.
118
118
  const [shelf, setShelf] = React.useState(0)
119
119
  const [discover, setDiscover] = React.useState(0)
120
+ const [shows, setShows] = React.useState(0)
120
121
  const stream = K.useEventStream('api/media-hub/events', (message) => {
121
122
  if (message.what?.includes('shelf')) setShelf(count => count + 1)
122
123
  if (message.what?.includes('discover')) setDiscover(count => count + 1)
124
+ if (message.what?.includes('library')) setShows(count => count + 1)
123
125
  if (message.what?.some(kind => kind === 'library' || kind === 'rooms')) load()
124
126
  })
125
127
  React.useEffect(() => { if (stream === 'live') { load(); setShelf(count => count + 1) } }, [stream, load])
126
128
  React.useEffect(() => { load() }, [load])
127
129
 
128
130
  const known = React.useMemo(() => ({ library, rooms, reload: load }), [library, rooms, load])
129
- const changes = React.useMemo(() => ({ shelf, discover }), [shelf, discover])
131
+ const changes = React.useMemo(() => ({ shelf, discover, shows }), [shelf, discover, shows])
130
132
  return h(Changes.Provider, { value: changes }, h(Known.Provider, { value: known }, h(React.Fragment, null,
131
133
  roomId === null
132
134
  ? h(Home, { t, nav, go, onOpen: setRoomId, rooms, library, load })
package/web/panel.css CHANGED
@@ -49,7 +49,8 @@
49
49
  .vsync-member[data-wait=loading]:before{background:var(--dsw-alias-state-warning-primary,#d29922)}
50
50
  .vsync-status{flex:none;color:var(--dsw-alias-label-tertiary);font-size:12px}
51
51
  .vsync-body{flex:1;min-height:0;display:flex}
52
- .vsync-stageWrap{position:relative;flex:1;min-width:0;display:flex;background:#000}
52
+ .vsync-player{flex:1;min-width:0;display:flex;flex-direction:column;background:#000}
53
+ .vsync-stageWrap{position:relative;flex:1;min-width:0;min-height:0;display:flex;background:#000}
53
54
  .vsync-stage{flex:1;min-width:0;display:flex}
54
55
  .vsync-media{flex:1;width:100%;height:100%;border:0;display:block;background:#000;object-fit:contain}
55
56
  .vsync-overlay{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:rgba(255,255,255,.72);font-size:13px;pointer-events:none}
@@ -86,7 +87,7 @@
86
87
  .vsync-episode[aria-current=true] .vsync-episodeNo{color:inherit}
87
88
  .vsync-episodeTitle{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
88
89
  .vsync-episodeState{flex:none;color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400}
89
- @media (width<=900px){.vsync-body{flex-direction:column}.vsync-stageWrap{flex:none;aspect-ratio:16/9}.vsync-episodes{width:auto;flex:1;border-left:0;border-top:.5px solid var(--dsw-alias-border-l4)}.vsync-members .vsync-memberName{display:none}}
90
+ @media (width<=900px){.vsync-body{flex-direction:column}.vsync-player{flex:none}.vsync-stageWrap{flex:none;aspect-ratio:16/9}.vsync-episodes{width:auto;flex:1;border-left:0;border-top:.5px solid var(--dsw-alias-border-l4)}.vsync-members .vsync-memberName{display:none}}
90
91
  /* Search */
91
92
  .vsync-search{position:relative;display:flex;gap:8px;align-items:center;margin-bottom:10px}
92
93
  .vsync-searchIcon{position:absolute;left:12px;top:10px;width:16px;height:16px;color:var(--dsw-alias-label-tertiary);pointer-events:none}
@@ -366,3 +367,29 @@
366
367
  .vsync-pointsOffer{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);z-index:40;display:flex;align-items:center;gap:12px;max-width:min(560px,calc(100% - 32px));padding:10px 12px 10px 16px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base));box-shadow:var(--dsw-shadow-lv3)}
367
368
  .vsync-pointsText{flex:1;min-width:0;font-size:13px;line-height:19px;color:var(--dsw-alias-label-primary)}
368
369
  @media (width<=767px){.vsync-pointsOffer{flex-wrap:wrap;bottom:12px}.vsync-pointsOffer>.vsync-actions{margin-left:auto}}
370
+ /* Player bar, danmaku, full screen */
371
+ .vsync-playerBar{flex:none;display:flex;align-items:center;gap:8px;padding:6px 12px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);border-bottom:.5px solid var(--dsw-alias-border-l4)}
372
+ .vsync-grow{flex:1}
373
+ .vsync-danmakuToggle[aria-checked=true]{color:var(--dsw-alias-state-business-primary);box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsw-alias-state-business-primary)}
374
+ .vsync-danmakuToggle[aria-checked=false]{color:var(--dsw-alias-label-tertiary)}
375
+ .vsync-popover{position:absolute;right:0;bottom:calc(100% + 6px);z-index:30;box-sizing:border-box;width:min(320px,calc(100vw - 24px));display:flex;flex-direction:column;gap:14px;padding:14px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-base));color:var(--dsw-alias-label-primary);box-shadow:var(--dsw-shadow-lv3)}
376
+ .vsync-setting{display:flex;flex-direction:column;gap:6px}
377
+ .vsync-settingLabel{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}
378
+ .vsync-settingChoices{display:flex;flex-wrap:wrap;gap:6px}
379
+ .vsync-settingNote{margin:6px 0 0;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
380
+ .vsync-danmaku{position:absolute;top:0;left:0;right:0;z-index:1;overflow:hidden;pointer-events:none;color:#fff;font-size:20px;font-weight:600;line-height:1.3;text-shadow:0 0 2px rgba(0,0,0,.9),0 1px 2px rgba(0,0,0,.6)}
381
+ .vsync-danmaku[data-size=small]{font-size:15px}
382
+ .vsync-danmaku[data-size=large]{font-size:26px}
383
+ @media (width<=640px){.vsync-danmaku{font-size:15px}.vsync-danmaku[data-size=small]{font-size:12px}.vsync-danmaku[data-size=large]{font-size:19px}}
384
+ .vsync-player:fullscreen,.vsync-player[data-covering=true]{width:100%;height:100%}
385
+ .vsync-player[data-covering=true]{position:fixed;inset:0;z-index:1000;height:100dvh}
386
+ .vsync-player:fullscreen .vsync-stageWrap,.vsync-player[data-covering=true] .vsync-stageWrap{flex:1;aspect-ratio:auto}
387
+ .vsync-player:fullscreen .vsync-playerBar,.vsync-player[data-covering=true] .vsync-playerBar{background:#000;color:#fff;border-bottom:0;padding-bottom:max(6px,env(safe-area-inset-bottom))}
388
+ /* Comments */
389
+ .vsync-comments{flex:1;min-height:0;overflow:auto;display:flex;flex-direction:column;align-items:flex-start;gap:10px;padding:8px 16px 16px}
390
+ .vsync-commentNote{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
391
+ .vsync-commentList{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:16px;align-self:stretch}
392
+ .vsync-commentHead{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 8px;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
393
+ .vsync-commentName{color:var(--dsw-alias-label-secondary);font-weight:500}
394
+ .vsync-commentText{margin:4px 0 0;color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px;white-space:pre-wrap;overflow-wrap:anywhere}
395
+ .vsync-commentStats{display:flex;gap:12px;margin-top:4px;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The row under the picture, as phone players have it: danmaku on or off,
3
+ * how they show and the show's quality behind one settings button, and full
4
+ * screen with the danmaku kept on top.
5
+ */
6
+ import { AREAS, OPACITIES, SIZES } from './danmaku-layer.js'
7
+ import { Icon, Popover, React, fill, h, qualityLabel } from './ui.js'
8
+
9
+ /** One choice among a few, as chips. */
10
+ function Choice({ label, options, value, onChange }) {
11
+ return h('div', { className: 'vsync-setting' },
12
+ h('span', { className: 'vsync-settingLabel' }, label),
13
+ h('div', { className: 'vsync-settingChoices', role: 'group', 'aria-label': label }, options.map(option => h('button', {
14
+ key: option.value,
15
+ type: 'button',
16
+ className: 'vsync-chip',
17
+ 'aria-pressed': String(option.value === value),
18
+ onClick: () => onChange(option.value),
19
+ }, option.label))))
20
+ }
21
+
22
+ const percent = value => `${Math.round(value * 100)}%`
23
+ /** The words for AREAS, in its order. */
24
+ const AREA_WORDS = Object.freeze(['quarter', 'half', 'full'])
25
+
26
+ /**
27
+ * @param {object} props
28
+ * @param {{ on: boolean, opacity: number, area: number, size: string }} props.settings - this viewer's danmaku settings
29
+ * @param {(patch: object) => void} props.onSettings
30
+ * @param {boolean} props.danmaku - whether the show's source has danmaku
31
+ * @param {number | null} props.count - how many the episode has, once known
32
+ * @param {{ value: string, choices: string[], onChange: (quality: string) => void, busy: boolean } | null} props.quality
33
+ * @param {boolean} props.full - whether the player fills the screen
34
+ * @param {() => void} props.onFull
35
+ */
36
+ export function PlayerBar({ t, settings, onSettings, danmaku, count, quality, full, onFull }) {
37
+ const danmakuSettings = danmaku && settings.on && [
38
+ h(Choice, { key: 'opacity', label: t('danmaku.opacity'), value: settings.opacity, onChange: opacity => onSettings({ opacity }), options: OPACITIES.map(value => ({ value, label: percent(value) })) }),
39
+ h(Choice, { key: 'area', label: t('danmaku.area'), value: settings.area, onChange: area => onSettings({ area }), options: AREAS.map((value, n) => ({ value, label: t(`danmaku.area.${AREA_WORDS[n]}`) })) }),
40
+ h(Choice, { key: 'size', label: t('danmaku.size'), value: settings.size, onChange: size => onSettings({ size }), options: SIZES.map(value => ({ value, label: t(`danmaku.size.${value}`) })) }),
41
+ ]
42
+ const qualityChoice = quality !== null && h('div', { key: 'quality', className: 'vsync-settingGroup' },
43
+ h(Choice, { label: t('quality.label'), value: quality.value, onChange: quality.onChange, options: quality.choices.map(value => ({ value, label: qualityLabel(t, value) })) }),
44
+ h('p', { className: 'vsync-settingNote' }, quality.busy ? t('quality.changing') : t('quality.fromNext')))
45
+ const hasSettings = Boolean(danmakuSettings) || Boolean(qualityChoice)
46
+ return h('div', { className: 'vsync-playerBar' },
47
+ danmaku && h('button', {
48
+ type: 'button',
49
+ className: 'vsync-btn vsync-danmakuToggle',
50
+ role: 'switch',
51
+ 'aria-checked': String(settings.on),
52
+ onClick: () => onSettings({ on: !settings.on }),
53
+ }, h(Icon.Danmaku), settings.on && count !== null ? fill(t('danmaku.count'), { n: count }) : t('danmaku.label')),
54
+ h('span', { className: 'vsync-grow' }),
55
+ hasSettings && h(Popover, { label: t('player.settings'), icon: h(Icon.Settings) }, danmakuSettings, qualityChoice),
56
+ h('button', { type: 'button', className: 'vsync-icon', 'aria-label': t(full ? 'player.exitFull' : 'player.full'), title: t(full ? 'player.exitFull' : 'player.full'), 'aria-pressed': String(full), onClick: onFull }, h(full ? Icon.Shrink : Icon.Expand)))
57
+ }
package/web/player.js CHANGED
@@ -698,6 +698,8 @@ export function joinRoom({ base, roomId, name, language = '', trackLabel = label
698
698
 
699
699
  return {
700
700
  clientId,
701
+ /** The <video> in front, which danmaku follow (the player swaps elements between episodes); null before one plays. */
702
+ get media() { return player?.element ?? null },
701
703
  /** Switch the room to an episode. */
702
704
  select(index) {
703
705
  op({ op: 'select', index })
@@ -9,13 +9,11 @@ import { Cover, WorkDetails, glance, infoOf } from './details.js'
9
9
  import { FollowButton } from './follow.js'
10
10
  import { hasEpisodes, resumeLabel } from './format.js'
11
11
  import { useKnownWork } from './known.js'
12
- import { Confirm, EPISODE_BYTES, Icon, React, Spinner, asPersonPaying, bytes, chatAbout, clock, displayName, fill, h } from './ui.js'
12
+ import { Confirm, EPISODE_BYTES, Icon, React, Spinner, asPersonPaying, bytes, chatAbout, clock, displayName, fill, h, qualityLabel } from './ui.js'
13
13
 
14
14
  /** Episodes fetched ahead of the one being watched; the Host's `cacheAhead` default, for the size hint. */
15
15
  const WINDOW_EPISODES = 6
16
16
 
17
- /** The words for a quality a source offers: auto, audio, or a height. */
18
- const qualityLabel = (t, quality) => (/^\d+$/.test(quality) ? fill(t('quality.height'), { n: quality }) : t(`quality.${quality}`))
19
17
 
20
18
  /** How the episodes are fetched, for a source that offers a choice (Link); its first choice (auto) is the default. */
21
19
  function QualityPicker({ t, qualities, value, onChange }) {
package/web/room-view.js CHANGED
@@ -4,9 +4,12 @@
4
4
  */
5
5
  import { About, nextSeason } from './about-view.js'
6
6
  import { AvatarStack } from './avatars.js'
7
+ import { Comments } from './comments-view.js'
8
+ import { DanmakuLayer, useDanmakuSettings } from './danmaku-layer.js'
7
9
  import { Cover } from './details.js'
8
10
  import { useKnownWork } from './known.js'
9
- import { Confirm, Icon, ProgressBar, React, api, asPersonPaying, base, captionText, clock, copyText, displayName, fill, h, post, progressFraction, progressText, roomLink, watchMark } from './ui.js'
11
+ import { PlayerBar } from './player-bar.js'
12
+ import { Changes, Confirm, Icon, ProgressBar, React, api, asPersonPaying, base, captionText, clock, copyText, displayName, fill, h, post, progressFraction, progressText, roomLink, watchMark } from './ui.js'
10
13
 
11
14
  const TOAST_MS = 4000
12
15
  /** A wait shorter than this (a seek into what is already loaded) shows nothing. */
@@ -43,8 +46,38 @@ function WaitPanel({ t, view, item, onSkip, onContinue }) {
43
46
  view.wait.canSkip && others.length > 0 && view.wait.held && h('button', { type: 'button', className: 'vsync-btn', onClick: onSkip }, fill(t('room.startWithout'), { names })))
44
47
  }
45
48
 
49
+ /** No danmaku yet: the same empty list each time, so the layer is not rebuilt. */
50
+ const NO_DANMAKU = Object.freeze([])
51
+
52
+ /**
53
+ * The player filling the screen with the danmaku and the bar on top: the browser's full screen for the player's box
54
+ * where it has one, else (iPhone, which only lets a bare <video> go full screen) the box covering the page.
55
+ */
56
+ function useFullScreen(box) {
57
+ const [covering, setCovering] = React.useState(false)
58
+ const [native, setNative] = React.useState(false)
59
+ React.useEffect(() => {
60
+ const changed = () => setNative(document.fullscreenElement === box.current && box.current !== null)
61
+ document.addEventListener('fullscreenchange', changed)
62
+ return () => document.removeEventListener('fullscreenchange', changed)
63
+ }, [])
64
+ const toggle = () => {
65
+ if (native) return void document.exitFullscreen()
66
+ if (covering) return setCovering(false)
67
+ if (typeof box.current?.requestFullscreen === 'function' && document.fullscreenEnabled) return void box.current.requestFullscreen().catch(() => setCovering(true))
68
+ return setCovering(true)
69
+ }
70
+ return { full: native || covering, covering, toggle }
71
+ }
72
+
46
73
  export function RoomView({ t, roomId, onLeave, onOpen }) {
47
74
  const stage = React.useRef(null)
75
+ const playerBox = React.useRef(null)
76
+ const { shows } = React.useContext(Changes)
77
+ const [danmakuSettings, setDanmakuSettings] = useDanmakuSettings()
78
+ const [danmaku, setDanmaku] = React.useState({ index: null, items: NO_DANMAKU })
79
+ const [qualityBusy, setQualityBusy] = React.useState(false)
80
+ const screen = useFullScreen(playerBox)
48
81
  const session = React.useRef(null)
49
82
  const [view, setView] = React.useState({ connection: 'connecting', room: null, members: [], needsGesture: false })
50
83
  const [toasts, setToasts] = React.useState([])
@@ -84,14 +117,34 @@ export function RoomView({ t, roomId, onLeave, onOpen }) {
84
117
  }
85
118
  }, [roomId])
86
119
 
120
+ // The show's notes change (another viewer picked a quality, the work was read again): read them again.
87
121
  React.useEffect(() => {
88
122
  let live = true
89
123
  api(`rooms/${encodeURIComponent(roomId)}/work`).then((answer) => { if (live && answer.work) setAbout(answer) })
90
124
  return () => { live = false }
91
- }, [roomId])
125
+ }, [roomId, shows])
92
126
 
93
127
  const room = view.room
94
128
  const item = room?.items[room.index]
129
+ const index = room?.index ?? null
130
+ const wantsDanmaku = about?.danmaku === true && danmakuSettings.on
131
+ React.useEffect(() => {
132
+ if (!wantsDanmaku || index === null) return undefined
133
+ let live = true
134
+ setDanmaku({ index, items: NO_DANMAKU })
135
+ api(`rooms/${encodeURIComponent(roomId)}/danmaku/${index}`).then((answer) => {
136
+ if (live && Array.isArray(answer.items)) setDanmaku({ index, items: answer.items })
137
+ })
138
+ return () => { live = false }
139
+ }, [roomId, index, wantsDanmaku])
140
+ const choices = about?.work?.qualities ?? []
141
+ const pickQuality = async (quality) => {
142
+ setQualityBusy(true)
143
+ const answer = await post(`rooms/${encodeURIComponent(roomId)}/quality`, { quality })
144
+ setQualityBusy(false)
145
+ if (answer.error) toast(answer.error)
146
+ else setAbout(current => ({ ...current, quality: answer.quality }))
147
+ }
95
148
  const copy = async () => {
96
149
  if (await copyText(roomLink(roomId), t('room.copy'))) {
97
150
  setCopied(true)
@@ -111,6 +164,8 @@ export function RoomView({ t, roomId, onLeave, onOpen }) {
111
164
  onLeave()
112
165
  }
113
166
 
167
+ const tabs = [room && room.items.length > 1 && 'episodes', about && 'about', about?.comments && 'comments'].filter(Boolean)
168
+ const shownSide = tabs.includes(side) ? side : tabs[0]
114
169
  const season = about ? nextSeason(about.work) : null
115
170
  const seasonKnown = useKnownWork(about?.source, season?.id)
116
171
  const watchSeason = async () => {
@@ -150,40 +205,52 @@ export function RoomView({ t, roomId, onLeave, onOpen }) {
150
205
  room?.together && h('button', { type: 'button', className: 'vsync-icon', 'aria-label': copied ? t('room.copied') : t('room.copy'), title: copied ? t('room.copied') : t('room.copy'), onClick: copy }, h(Icon.Link)),
151
206
  h('button', { type: 'button', className: 'vsync-icon', 'aria-label': t('room.close'), title: t('room.close'), onClick: () => setClosing(true) }, h(Icon.Close)))),
152
207
  h('div', { className: 'vsync-body' },
153
- h('div', { className: 'vsync-stageWrap' },
154
- h('div', { className: 'vsync-stage', ref: stage }),
155
- overlay && h('div', { className: 'vsync-overlay' }, overlay),
156
- h('div', { className: 'vsync-toasts', role: 'status', 'aria-live': 'polite' }, toasts.map(item => h('span', { key: item.id, className: 'vsync-toast' }, item.text)))),
157
- room && (room.items.length > 1 || about) && h('aside', { className: 'vsync-episodes', 'aria-label': t('room.episodes') },
158
- about && room.items.length > 1 && h('div', { className: 'vsync-sideTabs', role: 'tablist' },
159
- ['episodes', 'about'].map(tab => h('button', { key: tab, type: 'button', role: 'tab', className: 'vsync-chip', 'aria-selected': String(side === tab), onClick: () => setSide(tab) }, t(`room.tab.${tab}`)))),
160
- (side === 'about' || room.items.length === 1) && about
161
- ? h(About, { t, work: about.work, source: about.source, workId: about.id })
162
- : h(React.Fragment, null,
163
- !about && h('h2', null, t('room.episodes')),
164
- h('ol', { className: 'vsync-episodeList' }, room.items.map((episode, index) => {
165
- const mark = watchMark(t, episode.watch, index === room.index)
166
- const title = episode.title ?? fill(t('room.episodeN'), { n: index + 1 })
167
- return h('li', { key: index },
168
- h('button', {
169
- type: 'button',
170
- className: 'vsync-episode',
171
- 'aria-current': String(index === room.index),
172
- 'data-watch': mark.state,
173
- 'data-cached': String(episode.cached),
174
- title: episode.cached ? undefined : t('room.notCached'),
175
- disabled: episode.status === 'failed' && episode.cached,
176
- onClick: () => session.current?.select(index),
177
- },
178
- h('span', { className: 'vsync-episodeNo' }, index + 1),
179
- h('span', { className: 'vsync-episodeMain' },
180
- h('span', { className: 'vsync-episodeTitle' }, title),
181
- mark.bar),
182
- episode.status === 'preparing'
183
- ? h('span', { className: 'vsync-episodeState' }, progressFraction(episode.progress) === null ? '…' : `${Math.floor(progressFraction(episode.progress) * 100)}%`)
184
- : mark.note))
185
- })),
186
- season && h('div', { className: 'vsync-nextSeason', 'data-last': String(room.index === room.items.length - 1) },
187
- h('span', { className: 'vsync-nextSeasonText' }, fill(t('room.nextSeason'), { title: season.title })),
188
- h('button', { type: 'button', className: 'vsync-btn vsync-primary', disabled: seasonBusy, onClick: watchSeason }, seasonBusy ? t('search.opening') : seasonKnown.room !== null ? t('search.joinRoom') : seasonKnown.show !== null ? t(seasonKnown.show.resume ? 'search.continue' : 'search.open') : t('search.watch')))))))
208
+ h('div', { className: 'vsync-player', ref: playerBox, 'data-covering': String(screen.covering) },
209
+ h('div', { className: 'vsync-stageWrap' },
210
+ h('div', { className: 'vsync-stage', ref: stage }),
211
+ wantsDanmaku && danmaku.index === index && h(DanmakuLayer, { media: session.current?.media ?? null, items: danmaku.items, settings: danmakuSettings }),
212
+ overlay && h('div', { className: 'vsync-overlay' }, overlay),
213
+ h('div', { className: 'vsync-toasts', role: 'status', 'aria-live': 'polite' }, toasts.map(item => h('span', { key: item.id, className: 'vsync-toast' }, item.text)))),
214
+ room && h(PlayerBar, {
215
+ t,
216
+ settings: danmakuSettings,
217
+ onSettings: setDanmakuSettings,
218
+ danmaku: about?.danmaku === true,
219
+ count: danmaku.index === index && danmaku.items !== NO_DANMAKU ? danmaku.items.length : null,
220
+ quality: choices.length > 1 ? { value: choices.includes(about.quality) ? about.quality : choices[0], choices, onChange: pickQuality, busy: qualityBusy } : null,
221
+ full: screen.full,
222
+ onFull: screen.toggle,
223
+ })),
224
+ tabs.length > 0 && h('aside', { className: 'vsync-episodes', 'aria-label': t('room.episodes') },
225
+ tabs.length > 1 && h('div', { className: 'vsync-sideTabs', role: 'tablist' },
226
+ tabs.map(tab => h('button', { key: tab, type: 'button', role: 'tab', className: 'vsync-chip', 'aria-selected': String(shownSide === tab), onClick: () => setSide(tab) }, t(`room.tab.${tab}`)))),
227
+ shownSide === 'about' && h(About, { t, work: about.work, source: about.source, workId: about.id }),
228
+ shownSide === 'comments' && h(Comments, { t, roomId }),
229
+ shownSide === 'episodes' && h(React.Fragment, null,
230
+ !about && h('h2', null, t('room.episodes')),
231
+ h('ol', { className: 'vsync-episodeList' }, room.items.map((episode, index) => {
232
+ const mark = watchMark(t, episode.watch, index === room.index)
233
+ const title = episode.title ?? fill(t('room.episodeN'), { n: index + 1 })
234
+ return h('li', { key: index },
235
+ h('button', {
236
+ type: 'button',
237
+ className: 'vsync-episode',
238
+ 'aria-current': String(index === room.index),
239
+ 'data-watch': mark.state,
240
+ 'data-cached': String(episode.cached),
241
+ title: episode.cached ? undefined : t('room.notCached'),
242
+ disabled: episode.status === 'failed' && episode.cached,
243
+ onClick: () => session.current?.select(index),
244
+ },
245
+ h('span', { className: 'vsync-episodeNo' }, index + 1),
246
+ h('span', { className: 'vsync-episodeMain' },
247
+ h('span', { className: 'vsync-episodeTitle' }, title),
248
+ mark.bar),
249
+ episode.status === 'preparing'
250
+ ? h('span', { className: 'vsync-episodeState' }, progressFraction(episode.progress) === null ? '…' : `${Math.floor(progressFraction(episode.progress) * 100)}%`)
251
+ : mark.note))
252
+ })),
253
+ season && h('div', { className: 'vsync-nextSeason', 'data-last': String(room.index === room.items.length - 1) },
254
+ h('span', { className: 'vsync-nextSeasonText' }, fill(t('room.nextSeason'), { title: season.title })),
255
+ h('button', { type: 'button', className: 'vsync-btn vsync-primary', disabled: seasonBusy, onClick: watchSeason }, seasonBusy ? t('search.opening') : seasonKnown.room !== null ? t('search.joinRoom') : seasonKnown.show !== null ? t(seasonKnown.show.resume ? 'search.continue' : 'search.open') : t('search.watch')))))))
189
256
  }
package/web/ui.js CHANGED
@@ -239,6 +239,10 @@ export const Icon = {
239
239
  Download: ({ size = 16 }) => svg(size, h('path', { d: 'M8 2.5v8M4.75 7.5 8 10.75l3.25-3.25M3 13.5h10', ...stroke })),
240
240
  Book: ({ size = 16 }) => svg(size, h('path', { d: 'M3 3.5A1.5 1.5 0 0 1 4.5 2H13v10H4.5A1.5 1.5 0 0 0 3 13.5Zm0 10A1.5 1.5 0 0 0 4.5 15H13v-3', ...stroke })),
241
241
  Check: ({ size = 16 }) => svg(size, h('path', { d: 'M3.5 8.5 6.5 11.5 12.5 4.5', ...stroke })),
242
+ Danmaku: ({ size = 16 }) => svg(size, h('rect', { x: 1.75, y: 3, width: 12.5, height: 10, rx: 2, ...stroke }), h('path', { d: 'M4.5 6.5h4M7 9.5h4.5', ...stroke })),
243
+ Settings: ({ size = 16 }) => svg(size, h('path', { d: 'M2.5 4.5h6M11.5 4.5h2M2.5 11.5h2M7.5 11.5h6', ...stroke }), h('circle', { cx: 10, cy: 4.5, r: 1.5, ...stroke }), h('circle', { cx: 6, cy: 11.5, r: 1.5, ...stroke })),
244
+ Expand: ({ size = 16 }) => svg(size, h('path', { d: 'M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10', ...stroke })),
245
+ Shrink: ({ size = 16 }) => svg(size, h('path', { d: 'M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5', ...stroke })),
242
246
  Chevron: ({ size = 16, open = false }) => svg(size, h('path', { d: open ? 'M4 6l4 4 4-4' : 'M6 4l4 4-4 4', ...stroke })),
243
247
  }
244
248
 
@@ -288,17 +292,12 @@ export function Confirm({ t, question, confirmLabel, onConfirm, onCancel, danger
288
292
  }, confirmLabel))
289
293
  }
290
294
 
291
- /**
292
- * A button with a small menu of actions; closes on outside click or Escape.
293
- * Without children it is the "more" icon; with children, a quiet text button.
294
- */
295
- export function Menu({ label, items, children, title }) {
296
- const [open, setOpen] = React.useState(false)
297
- const root = React.useRef(null)
295
+ /** Close something open on a press outside `root` or on Escape. */
296
+ function useDismiss(open, close, root) {
298
297
  React.useEffect(() => {
299
298
  if (!open) return undefined
300
- const away = (event) => { if (!root.current?.contains(event.target)) setOpen(false) }
301
- const key = (event) => { if (event.key === 'Escape') setOpen(false) }
299
+ const away = (event) => { if (!root.current?.contains(event.target)) close() }
300
+ const key = (event) => { if (event.key === 'Escape') close() }
302
301
  document.addEventListener('pointerdown', away)
303
302
  document.addEventListener('keydown', key)
304
303
  return () => {
@@ -306,6 +305,16 @@ export function Menu({ label, items, children, title }) {
306
305
  document.removeEventListener('keydown', key)
307
306
  }
308
307
  }, [open])
308
+ }
309
+
310
+ /**
311
+ * A button with a small menu of actions; closes on outside click or Escape.
312
+ * Without children it is the "more" icon; with children, a quiet text button.
313
+ */
314
+ export function Menu({ label, items, children, title }) {
315
+ const [open, setOpen] = React.useState(false)
316
+ const root = React.useRef(null)
317
+ useDismiss(open, () => setOpen(false), root)
309
318
  return h('span', { className: 'vsync-menuWrap', ref: root },
310
319
  h('button', { type: 'button', className: children ? 'vsync-metaButton' : 'vsync-icon', 'aria-label': label, title: title ?? label, 'aria-haspopup': 'menu', 'aria-expanded': String(open), onClick: () => setOpen(!open) }, children ?? h(Icon.More)),
311
320
  open && h('div', { className: 'vsync-menu', role: 'menu' }, items.filter(Boolean).map(item => h('button', {
@@ -319,3 +328,16 @@ export function Menu({ label, items, children, title }) {
319
328
  },
320
329
  }, item.label))))
321
330
  }
331
+
332
+ /** An icon button that opens a small panel of settings above it; closes on outside click or Escape. */
333
+ export function Popover({ label, icon, children }) {
334
+ const [open, setOpen] = React.useState(false)
335
+ const root = React.useRef(null)
336
+ useDismiss(open, () => setOpen(false), root)
337
+ return h('span', { className: 'vsync-menuWrap', ref: root },
338
+ h('button', { type: 'button', className: 'vsync-icon', 'aria-label': label, title: label, 'aria-haspopup': 'dialog', 'aria-expanded': String(open), onClick: () => setOpen(!open) }, icon),
339
+ open && h('div', { className: 'vsync-popover', role: 'dialog', 'aria-label': label }, children))
340
+ }
341
+
342
+ /** The words for a quality a source offers (src/quality.js): auto, audio, or a height. */
343
+ export const qualityLabel = (t, quality) => (/^\d+$/.test(quality) ? fill(t('quality.height'), { n: quality }) : t(`quality.${quality}`))