@therealtinhtute/baroiplayer 1.2.1 → 2.0.0-beta.1
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/README.md +90 -71
- package/dist/components/icons/index.d.ts +36 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts +13 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts +4 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts +30 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-video.d.ts +16 -0
- package/dist/components/variants/gradient/gradient-video.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +750 -5640
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +3 -0
- package/package.json +110 -114
- package/src/components/variants/gradient/gradient-audio.tsx +47 -0
- package/src/components/variants/gradient/gradient-controls.tsx +254 -0
- package/src/components/variants/gradient/gradient-glyphs.test.tsx +69 -0
- package/src/components/variants/gradient/gradient-glyphs.tsx +129 -0
- package/src/components/variants/gradient/gradient-skin.css +211 -0
- package/src/components/variants/gradient/gradient-video.tsx +70 -0
- package/src/index.ts +5 -198
- package/src/test/accessibility-utils.ts +0 -59
- package/dist/context/media.js +0 -1
- package/dist/context/media.mjs +0 -3
- package/dist/context/store.js +0 -1
- package/dist/context/store.mjs +0 -3
- package/dist/context-Bzd5QCKM.cjs +0 -7
- package/dist/context-Bzd5QCKM.cjs.map +0 -1
- package/dist/context-DD_SH4tT.js +0 -1053
- package/dist/context-DD_SH4tT.js.map +0 -1
- package/dist/core-events-BRnLMB7s.cjs +0 -2
- package/dist/core-events-BRnLMB7s.cjs.map +0 -1
- package/dist/core-events-v_mKdj5p.js +0 -417
- package/dist/core-events-v_mKdj5p.js.map +0 -1
- package/dist/core-plugins-CMBv-yVh.cjs +0 -2
- package/dist/core-plugins-CMBv-yVh.cjs.map +0 -1
- package/dist/core-plugins-CqCxLkbd.js +0 -754
- package/dist/core-plugins-CqCxLkbd.js.map +0 -1
- package/dist/core.js +0 -15
- package/dist/core.js.map +0 -1
- package/dist/core.mjs +0 -960
- package/dist/core.mjs.map +0 -1
- package/dist/enhanced-components-BwjBqSA1.js +0 -2858
- package/dist/enhanced-components-BwjBqSA1.js.map +0 -1
- package/dist/enhanced-components-C-ka-XLp.cjs +0 -2
- package/dist/enhanced-components-C-ka-XLp.cjs.map +0 -1
- package/dist/hooks-B-IIWPJr.js +0 -1842
- package/dist/hooks-B-IIWPJr.js.map +0 -1
- package/dist/hooks-DcHzmBwA.cjs +0 -4
- package/dist/hooks-DcHzmBwA.cjs.map +0 -1
- package/dist/minimal-components-BYsMQde5.js +0 -1610
- package/dist/minimal-components-BYsMQde5.js.map +0 -1
- package/dist/minimal-components-CsxQbDp7.cjs +0 -2
- package/dist/minimal-components-CsxQbDp7.cjs.map +0 -1
- package/dist/minimal-components.css +0 -1
- package/dist/mona-loading.gif +0 -0
- package/dist/performance-monitor-DCSijLJg.js +0 -312
- package/dist/performance-monitor-DCSijLJg.js.map +0 -1
- package/dist/performance-monitor-wNFKmqMr.cjs +0 -2
- package/dist/performance-monitor-wNFKmqMr.cjs.map +0 -1
- package/dist/rolldown-runtime-BmowowmI.js +0 -14
- package/dist/rolldown-runtime-mLOUI7ql.cjs +0 -1
- package/dist/utils-D2gQ7c2R.js +0 -64
- package/dist/utils-D2gQ7c2R.js.map +0 -1
- package/dist/utils-DJaAwiZ9.cjs +0 -2
- package/dist/utils-DJaAwiZ9.cjs.map +0 -1
- package/dist/utils.js +0 -1
- package/dist/utils.mjs +0 -3
- package/src/adapters/videojs-adapter.tsx +0 -470
- package/src/assets/mona-loading.gif +0 -0
- package/src/components/AnimateLoading.tsx +0 -111
- package/src/components/LoadingState.tsx +0 -239
- package/src/components/__tests__/media-player-accessibility.test.tsx +0 -510
- package/src/components/__tests__/media-player-react19.test.tsx +0 -457
- package/src/components/accessibility/keyboard-help-overlay.tsx +0 -207
- package/src/components/audio-player.tsx +0 -85
- package/src/components/basic/index.ts +0 -37
- package/src/components/enhanced/advanced-features.tsx +0 -311
- package/src/components/enhanced/debug-panel.tsx +0 -448
- package/src/components/enhanced/enhanced-controls.tsx +0 -597
- package/src/components/enhanced/enhanced-media-player.tsx +0 -566
- package/src/components/enhanced/error-handling.tsx +0 -338
- package/src/components/enhanced/index.ts +0 -39
- package/src/components/enhanced/media-player-enhanced.tsx +0 -383
- package/src/components/examples/basic-video-player.tsx +0 -50
- package/src/components/examples/custom-controls-example.tsx +0 -63
- package/src/components/examples/enhanced-controls-example.tsx +0 -100
- package/src/components/examples/enhanced-media-player-example.tsx +0 -302
- package/src/components/examples/loading-states-demo.tsx +0 -141
- package/src/components/examples/react-19-demo.tsx +0 -349
- package/src/components/examples/volume-orientation-demo.tsx +0 -105
- package/src/components/icon-demo.tsx +0 -196
- package/src/components/legacy.tsx +0 -87
- package/src/components/media-metadata-display.tsx +0 -99
- package/src/components/media-player-audio.tsx +0 -39
- package/src/components/media-player-controls.tsx +0 -223
- package/src/components/media-player-error.tsx +0 -163
- package/src/components/media-player-fullscreen.tsx +0 -109
- package/src/components/media-player-hls.tsx +0 -111
- package/src/components/media-player-loading.tsx +0 -76
- package/src/components/media-player-play.tsx +0 -75
- package/src/components/media-player-root.tsx +0 -338
- package/src/components/media-player-seek.tsx +0 -168
- package/src/components/media-player-time.tsx +0 -99
- package/src/components/media-player-tooltip.tsx +0 -58
- package/src/components/media-player-video.tsx +0 -54
- package/src/components/media-player-volume.tsx +0 -155
- package/src/components/media-player.tsx +0 -292
- package/src/components/media-suspense.tsx +0 -344
- package/src/components/player-settings-form.tsx +0 -158
- package/src/components/react-player-wrapper.tsx +0 -651
- package/src/components/simple-video-player.tsx +0 -62
- package/src/components/ui/blur-poster.tsx +0 -96
- package/src/components/ui/empty-state.tsx +0 -91
- package/src/components/ui/enhanced-seek-bar.tsx +0 -254
- package/src/components/ui/error-state.tsx +0 -124
- package/src/components/ui/fullscreen-button.tsx +0 -81
- package/src/components/ui/loading-skeleton.tsx +0 -107
- package/src/components/ui/media-resource-preloader.tsx +0 -458
- package/src/components/ui/offline-message.tsx +0 -98
- package/src/components/ui/play-button.tsx +0 -99
- package/src/components/ui/seek-bar.tsx +0 -191
- package/src/components/ui/time-display.tsx +0 -61
- package/src/components/ui/volume-control.tsx +0 -190
- package/src/components/unified/base-media-player.tsx +0 -252
- package/src/components/unified/media-player.tsx +0 -75
- package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +0 -587
- package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +0 -573
- package/src/components/variants/minimal/MinimalControls.tsx +0 -124
- package/src/components/variants/minimal/MinimalLoading.tsx +0 -28
- package/src/components/variants/minimal/MinimalMediaPlayer.tsx +0 -318
- package/src/components/variants/minimal/MinimalOverlay.tsx +0 -58
- package/src/components/variants/minimal/MinimalPlayButton.tsx +0 -56
- package/src/components/variants/minimal/MinimalSeekBar.tsx +0 -140
- package/src/components/variants/minimal/MinimalVolumeControl.tsx +0 -75
- package/src/components/variants/minimal/SimpleMinimalPlayer.tsx +0 -206
- package/src/components/variants/minimal/components/CenterPlayButton.tsx +0 -22
- package/src/components/variants/minimal/components/ControlBar.tsx +0 -142
- package/src/components/variants/minimal/components/EnhancedSettingsMenu.tsx +0 -412
- package/src/components/variants/minimal/components/PlaybackControls.tsx +0 -46
- package/src/components/variants/minimal/components/RightControls.tsx +0 -164
- package/src/components/variants/minimal/components/SeekBar.tsx +0 -127
- package/src/components/variants/minimal/components/SettingsDropdown.tsx +0 -68
- package/src/components/variants/minimal/components/SubtitleDisplay.tsx +0 -21
- package/src/components/variants/minimal/components/TimeDisplay.tsx +0 -15
- package/src/components/variants/minimal/components/VideoElement.tsx +0 -35
- package/src/components/variants/minimal/components/VolumeControl.tsx +0 -220
- package/src/components/variants/minimal/index.ts +0 -23
- package/src/components/video-player.tsx +0 -100
- package/src/context/__tests__/media-store.test.ts +0 -509
- package/src/context/error-handling.ts +0 -398
- package/src/context/media-context.tsx +0 -254
- package/src/context/media-provider.tsx +0 -264
- package/src/context/media-store.ts +0 -387
- package/src/context/persistence.ts +0 -462
- package/src/core/events/event-system.ts +0 -448
- package/src/core/events/hooks.ts +0 -325
- package/src/core/events/index.ts +0 -22
- package/src/core/events/middleware.ts +0 -286
- package/src/core/index.ts +0 -22
- package/src/core/optimization/bundle-optimizer.tsx +0 -312
- package/src/core/performance/cicd.ts +0 -98
- package/src/core/performance/index.ts +0 -38
- package/src/core/performance/media-loading-optimizer.ts +0 -545
- package/src/core/performance/performance-budgets.ts +0 -437
- package/src/core/performance/performance-monitor.tsx +0 -488
- package/src/core/performance/performance-testing.ts +0 -461
- package/src/core/plugins/__tests__/registry.test.ts +0 -595
- package/src/core/plugins/base-plugin.ts +0 -225
- package/src/core/plugins/enhanced-plugin-system.ts +0 -435
- package/src/core/plugins/examples/analytics-plugin.ts +0 -241
- package/src/core/plugins/index.ts +0 -39
- package/src/core/plugins/registry.ts +0 -546
- package/src/core/plugins/types.ts +0 -169
- package/src/core/plugins/utils.ts +0 -317
- package/src/core/progressive-loading.tsx +0 -331
- package/src/core/providers/enhanced-hls-provider.ts +0 -307
- package/src/core/providers/lazy-provider.tsx +0 -14
- package/src/core/providers/service-provider.tsx +0 -164
- package/src/core/utils.tsx +0 -34
- package/src/features/media-session/media-session-manager.ts +0 -411
- package/src/features/picture-in-picture/pip-manager.ts +0 -428
- package/src/features/playlist/playlist-manager.ts +0 -626
- package/src/features/subtitles/subtitle-manager.ts +0 -435
- package/src/features/subtitles/subtitle-parser.ts +0 -284
- package/src/features/thumbnails/thumbnail-generator.ts +0 -528
- package/src/hooks/__tests__/currentTime-fix.test.ts +0 -149
- package/src/hooks/__tests__/use-media-player.test.ts +0 -712
- package/src/hooks/__tests__/use-media-state.test.tsx +0 -316
- package/src/hooks/accessibility/index.ts +0 -27
- package/src/hooks/accessibility/use-accessibility-preferences.ts +0 -190
- package/src/hooks/accessibility/use-focus-management.ts +0 -183
- package/src/hooks/accessibility/use-keyboard-shortcuts.ts +0 -152
- package/src/hooks/accessibility/use-screen-reader.ts +0 -212
- package/src/hooks/core/index.ts +0 -47
- package/src/hooks/legacy.ts +0 -21
- package/src/hooks/use-buffer-health.ts +0 -218
- package/src/hooks/use-enhanced-media-player.ts +0 -575
- package/src/hooks/use-focus-trap.tsx +0 -162
- package/src/hooks/use-intelligent-preloading.ts +0 -387
- package/src/hooks/use-keyboard-controls.ts +0 -115
- package/src/hooks/use-keyboard-shortcuts.ts +0 -255
- package/src/hooks/use-media-actions.ts +0 -184
- package/src/hooks/use-media-metadata.ts +0 -91
- package/src/hooks/use-media-optimistic.ts +0 -264
- package/src/hooks/use-media-player.ts +0 -343
- package/src/hooks/use-media-state.ts +0 -194
- package/src/hooks/use-memory-optimization.ts +0 -360
- package/src/hooks/use-network-status.ts +0 -124
- package/src/hooks/use-optimistic-controls.ts +0 -95
- package/src/hooks/use-optimized-media.ts +0 -283
- package/src/hooks/use-smart-preload.ts +0 -229
- package/src/hooks/use-touch-gestures.ts +0 -461
- package/src/hooks/useEnhancedSubtitles.ts +0 -258
- package/src/hooks/useKeyboardShortcuts.ts +0 -106
- package/src/hooks/useMediaControls.ts +0 -52
- package/src/hooks/useScreenshot.ts +0 -77
- package/src/hooks/useSubtitles.ts +0 -91
- package/src/hooks/useVideoPlayer.ts +0 -278
- package/src/icons/components/FullscreenIcon.tsx +0 -36
- package/src/icons/components/SettingsIcon.tsx +0 -37
- package/src/icons/components/animated/LoadingIcon.tsx +0 -27
- package/src/icons/components/animated/PlayPauseIcon.tsx +0 -42
- package/src/icons/components/media/PauseIcon.tsx +0 -38
- package/src/icons/components/media/PlayIcon.tsx +0 -37
- package/src/icons/components/volume/VolumeIcon.tsx +0 -38
- package/src/icons/components/volume/VolumeOffIcon.tsx +0 -38
- package/src/icons/index.ts +0 -56
- package/src/icons/provider.tsx +0 -58
- package/src/icons/types.ts +0 -60
- package/src/index-enhanced.ts +0 -35
- package/src/index-legacy.ts +0 -324
- package/src/index.css +0 -102
- package/src/lib/__tests__/async-utils.test.ts +0 -291
- package/src/lib/async-utils.ts +0 -194
- package/src/lib/deprecation.ts +0 -51
- package/src/lib/format-time.ts +0 -37
- package/src/lib/index.ts +0 -4
- package/src/lib/utils.ts +0 -6
- package/src/styles/globals.css +0 -462
- package/src/styles/minimal-player.css +0 -621
- package/src/styles/pixel-art.css +0 -41
- package/src/styles/videojs.css +0 -100
- package/src/types/assets.d.ts +0 -29
- package/src/types/events.ts +0 -47
- package/src/types/formats.ts +0 -79
- package/src/types/index.ts +0 -203
- package/src/types/videojs-plugins.d.ts +0 -14
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from "react"
|
|
2
|
-
|
|
3
|
-
export interface KeyboardShortcut {
|
|
4
|
-
key: string
|
|
5
|
-
ctrlKey?: boolean
|
|
6
|
-
altKey?: boolean
|
|
7
|
-
shiftKey?: boolean
|
|
8
|
-
action: () => void
|
|
9
|
-
description: string
|
|
10
|
-
preventDefault?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface UseKeyboardShortcutsOptions {
|
|
14
|
-
shortcuts: KeyboardShortcut[]
|
|
15
|
-
enabled?: boolean
|
|
16
|
-
target?: HTMLElement | null
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function useKeyboardShortcuts({
|
|
20
|
-
shortcuts,
|
|
21
|
-
enabled = true,
|
|
22
|
-
target
|
|
23
|
-
}: UseKeyboardShortcutsOptions) {
|
|
24
|
-
const shortcutsRef = useRef(shortcuts)
|
|
25
|
-
shortcutsRef.current = shortcuts
|
|
26
|
-
|
|
27
|
-
const handleKeyDown = useCallback(
|
|
28
|
-
(event: KeyboardEvent) => {
|
|
29
|
-
if (!enabled) return
|
|
30
|
-
|
|
31
|
-
// Don't trigger shortcuts when user is typing in inputs
|
|
32
|
-
if (
|
|
33
|
-
event.target instanceof HTMLInputElement ||
|
|
34
|
-
event.target instanceof HTMLTextAreaElement ||
|
|
35
|
-
(event.target as HTMLElement)?.contentEditable === "true"
|
|
36
|
-
) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const shortcut = shortcutsRef.current.find(
|
|
41
|
-
(s) =>
|
|
42
|
-
s.key.toLowerCase() === event.key.toLowerCase() &&
|
|
43
|
-
!!s.ctrlKey === event.ctrlKey &&
|
|
44
|
-
!!s.altKey === event.altKey &&
|
|
45
|
-
!!s.shiftKey === event.shiftKey
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
if (shortcut) {
|
|
49
|
-
if (shortcut.preventDefault !== false) {
|
|
50
|
-
event.preventDefault()
|
|
51
|
-
}
|
|
52
|
-
shortcut.action()
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
[enabled]
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
const element = target || document
|
|
60
|
-
element.addEventListener("keydown", handleKeyDown as EventListener)
|
|
61
|
-
|
|
62
|
-
return () => {
|
|
63
|
-
element.removeEventListener("keydown", handleKeyDown as EventListener)
|
|
64
|
-
}
|
|
65
|
-
}, [handleKeyDown, target])
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
shortcuts: shortcuts.map((s) => ({
|
|
69
|
-
key: s.key,
|
|
70
|
-
description: s.description,
|
|
71
|
-
modifiers: {
|
|
72
|
-
ctrl: s.ctrlKey,
|
|
73
|
-
alt: s.altKey,
|
|
74
|
-
shift: s.shiftKey
|
|
75
|
-
}
|
|
76
|
-
}))
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Pre-defined media player shortcuts
|
|
81
|
-
export const createMediaKeyboardShortcuts = (controls: {
|
|
82
|
-
play: () => void
|
|
83
|
-
pause: () => void
|
|
84
|
-
togglePlayPause: () => void
|
|
85
|
-
seekForward: (seconds?: number) => void
|
|
86
|
-
seekBackward: (seconds?: number) => void
|
|
87
|
-
volumeUp: () => void
|
|
88
|
-
volumeDown: () => void
|
|
89
|
-
toggleMute: () => void
|
|
90
|
-
toggleFullscreen: () => void
|
|
91
|
-
showHelp?: () => void
|
|
92
|
-
}): KeyboardShortcut[] => [
|
|
93
|
-
{
|
|
94
|
-
key: " ",
|
|
95
|
-
action: controls.togglePlayPause,
|
|
96
|
-
description: "Play/Pause"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
key: "k",
|
|
100
|
-
action: controls.togglePlayPause,
|
|
101
|
-
description: "Play/Pause (K)"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
key: "ArrowLeft",
|
|
105
|
-
action: () => controls.seekBackward(10),
|
|
106
|
-
description: "Seek backward 10 seconds"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
key: "ArrowRight",
|
|
110
|
-
action: () => controls.seekForward(10),
|
|
111
|
-
description: "Seek forward 10 seconds"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
key: "j",
|
|
115
|
-
action: () => controls.seekBackward(10),
|
|
116
|
-
description: "Seek backward 10 seconds (J)"
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
key: "l",
|
|
120
|
-
action: () => controls.seekForward(10),
|
|
121
|
-
description: "Seek forward 10 seconds (L)"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
key: "ArrowUp",
|
|
125
|
-
action: controls.volumeUp,
|
|
126
|
-
description: "Volume up"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
key: "ArrowDown",
|
|
130
|
-
action: controls.volumeDown,
|
|
131
|
-
description: "Volume down"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
key: "m",
|
|
135
|
-
action: controls.toggleMute,
|
|
136
|
-
description: "Toggle mute"
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
key: "f",
|
|
140
|
-
action: controls.toggleFullscreen,
|
|
141
|
-
description: "Toggle fullscreen"
|
|
142
|
-
},
|
|
143
|
-
...(controls.showHelp
|
|
144
|
-
? [
|
|
145
|
-
{
|
|
146
|
-
key: "?",
|
|
147
|
-
action: controls.showHelp,
|
|
148
|
-
description: "Show keyboard shortcuts help"
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
: [])
|
|
152
|
-
]
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from "react"
|
|
2
|
-
|
|
3
|
-
export type AnnouncementPriority = "assertive" | "polite" | "off"
|
|
4
|
-
|
|
5
|
-
export interface UseScreenReaderOptions {
|
|
6
|
-
defaultPriority?: AnnouncementPriority
|
|
7
|
-
debounceMs?: number
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function useScreenReader({
|
|
11
|
-
defaultPriority = "polite",
|
|
12
|
-
debounceMs = 100
|
|
13
|
-
}: UseScreenReaderOptions = {}) {
|
|
14
|
-
const liveRegionRef = useRef<HTMLDivElement | null>(null)
|
|
15
|
-
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined)
|
|
16
|
-
|
|
17
|
-
// Create or get the live region for announcements
|
|
18
|
-
const getLiveRegion = useCallback((priority: AnnouncementPriority) => {
|
|
19
|
-
if (!liveRegionRef.current) {
|
|
20
|
-
const liveRegion = document.createElement("div")
|
|
21
|
-
liveRegion.setAttribute("aria-live", priority)
|
|
22
|
-
liveRegion.setAttribute("aria-atomic", "true")
|
|
23
|
-
liveRegion.setAttribute("class", "sr-only")
|
|
24
|
-
liveRegion.style.cssText = `
|
|
25
|
-
position: absolute !important;
|
|
26
|
-
width: 1px !important;
|
|
27
|
-
height: 1px !important;
|
|
28
|
-
padding: 0 !important;
|
|
29
|
-
margin: -1px !important;
|
|
30
|
-
overflow: hidden !important;
|
|
31
|
-
clip: rect(0, 0, 0, 0) !important;
|
|
32
|
-
white-space: nowrap !important;
|
|
33
|
-
border: 0 !important;
|
|
34
|
-
`
|
|
35
|
-
document.body.appendChild(liveRegion)
|
|
36
|
-
liveRegionRef.current = liveRegion
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Update priority if needed
|
|
40
|
-
if (liveRegionRef.current.getAttribute("aria-live") !== priority) {
|
|
41
|
-
liveRegionRef.current.setAttribute("aria-live", priority)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return liveRegionRef.current
|
|
45
|
-
}, [])
|
|
46
|
-
|
|
47
|
-
// Announce a message to screen readers
|
|
48
|
-
const announce = useCallback(
|
|
49
|
-
(message: string, priority: AnnouncementPriority = defaultPriority) => {
|
|
50
|
-
if (!message.trim() || priority === "off") return
|
|
51
|
-
|
|
52
|
-
// Clear existing timeout
|
|
53
|
-
if (timeoutRef.current) {
|
|
54
|
-
clearTimeout(timeoutRef.current)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Debounce announcements
|
|
58
|
-
timeoutRef.current = setTimeout(() => {
|
|
59
|
-
const liveRegion = getLiveRegion(priority)
|
|
60
|
-
|
|
61
|
-
// Clear and then set the message to ensure it's announced
|
|
62
|
-
liveRegion.textContent = ""
|
|
63
|
-
|
|
64
|
-
// Use requestAnimationFrame to ensure the clear happens first
|
|
65
|
-
requestAnimationFrame(() => {
|
|
66
|
-
liveRegion.textContent = message
|
|
67
|
-
})
|
|
68
|
-
}, debounceMs)
|
|
69
|
-
},
|
|
70
|
-
[defaultPriority, debounceMs, getLiveRegion]
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
// Cleanup on unmount
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
return () => {
|
|
76
|
-
if (timeoutRef.current) {
|
|
77
|
-
clearTimeout(timeoutRef.current)
|
|
78
|
-
}
|
|
79
|
-
if (liveRegionRef.current) {
|
|
80
|
-
document.body.removeChild(liveRegionRef.current)
|
|
81
|
-
liveRegionRef.current = null
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, [])
|
|
85
|
-
|
|
86
|
-
return { announce }
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Hook specifically for media player screen reader announcements
|
|
90
|
-
export function useMediaScreenReader() {
|
|
91
|
-
const { announce } = useScreenReader({ defaultPriority: "polite" })
|
|
92
|
-
|
|
93
|
-
// Announce playback state changes
|
|
94
|
-
const announcePlaybackState = useCallback(
|
|
95
|
-
(isPlaying: boolean) => {
|
|
96
|
-
announce(isPlaying ? "Playing" : "Paused", "assertive")
|
|
97
|
-
},
|
|
98
|
-
[announce]
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
// Announce volume changes
|
|
102
|
-
const announceVolume = useCallback(
|
|
103
|
-
(volume: number, isMuted: boolean) => {
|
|
104
|
-
if (isMuted) {
|
|
105
|
-
announce("Muted", "assertive")
|
|
106
|
-
} else {
|
|
107
|
-
const volumePercent = Math.round(volume * 100)
|
|
108
|
-
announce(`Volume ${volumePercent}%`, "polite")
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
[announce]
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
// Announce time position changes
|
|
115
|
-
const announceTime = useCallback(
|
|
116
|
-
(currentTime: number, duration: number) => {
|
|
117
|
-
const formatTime = (seconds: number) => {
|
|
118
|
-
const hours = Math.floor(seconds / 3600)
|
|
119
|
-
const minutes = Math.floor((seconds % 3600) / 60)
|
|
120
|
-
const secs = Math.floor(seconds % 60)
|
|
121
|
-
|
|
122
|
-
if (hours > 0) {
|
|
123
|
-
return `${hours}:${minutes.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`
|
|
124
|
-
}
|
|
125
|
-
return `${minutes}:${secs.toString().padStart(2, "0")}`
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const current = formatTime(currentTime)
|
|
129
|
-
const total = formatTime(duration)
|
|
130
|
-
announce(`${current} of ${total}`, "polite")
|
|
131
|
-
},
|
|
132
|
-
[announce]
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
// Announce fullscreen state changes
|
|
136
|
-
const announceFullscreen = useCallback(
|
|
137
|
-
(isFullscreen: boolean) => {
|
|
138
|
-
announce(isFullscreen ? "Entered fullscreen" : "Exited fullscreen", "assertive")
|
|
139
|
-
},
|
|
140
|
-
[announce]
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
// Announce subtitle state changes
|
|
144
|
-
const announceSubtitles = useCallback(
|
|
145
|
-
(enabled: boolean, language?: string) => {
|
|
146
|
-
if (enabled) {
|
|
147
|
-
announce(language ? `Subtitles enabled in ${language}` : "Subtitles enabled", "assertive")
|
|
148
|
-
} else {
|
|
149
|
-
announce("Subtitles disabled", "assertive")
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
[announce]
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
// Announce playback speed changes
|
|
156
|
-
const announcePlaybackSpeed = useCallback(
|
|
157
|
-
(speed: number) => {
|
|
158
|
-
if (speed === 1) {
|
|
159
|
-
announce("Normal playback speed", "assertive")
|
|
160
|
-
} else {
|
|
161
|
-
announce(`Playback speed ${speed}x`, "assertive")
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
[announce]
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
// Announce quality changes
|
|
168
|
-
const announceQuality = useCallback(
|
|
169
|
-
(quality: string) => {
|
|
170
|
-
announce(`Quality changed to ${quality}`, "polite")
|
|
171
|
-
},
|
|
172
|
-
[announce]
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
// Announce loading state
|
|
176
|
-
const announceLoading = useCallback(
|
|
177
|
-
(isLoading: boolean) => {
|
|
178
|
-
announce(isLoading ? "Loading..." : "Loading complete", "polite")
|
|
179
|
-
},
|
|
180
|
-
[announce]
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
// Announce errors
|
|
184
|
-
const announceError = useCallback(
|
|
185
|
-
(error: string) => {
|
|
186
|
-
announce(`Error: ${error}`, "assertive")
|
|
187
|
-
},
|
|
188
|
-
[announce]
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
// Announce buffering state
|
|
192
|
-
const announceBuffering = useCallback(
|
|
193
|
-
(isBuffering: boolean) => {
|
|
194
|
-
announce(isBuffering ? "Buffering..." : "Buffering complete", "polite")
|
|
195
|
-
},
|
|
196
|
-
[announce]
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
announce,
|
|
201
|
-
announcePlaybackState,
|
|
202
|
-
announceVolume,
|
|
203
|
-
announceTime,
|
|
204
|
-
announceFullscreen,
|
|
205
|
-
announceSubtitles,
|
|
206
|
-
announcePlaybackSpeed,
|
|
207
|
-
announceQuality,
|
|
208
|
-
announceLoading,
|
|
209
|
-
announceError,
|
|
210
|
-
announceBuffering
|
|
211
|
-
}
|
|
212
|
-
}
|
package/src/hooks/core/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// Core Media Player Hooks
|
|
2
|
-
export { useKeyboardControls } from "../use-keyboard-controls"
|
|
3
|
-
export { useMediaPlayer } from "../use-media-player"
|
|
4
|
-
|
|
5
|
-
// Media State Hooks
|
|
6
|
-
export {
|
|
7
|
-
useAdaptiveMediaState,
|
|
8
|
-
useEnhancedMediaState,
|
|
9
|
-
useMediaState
|
|
10
|
-
} from "../use-media-state"
|
|
11
|
-
|
|
12
|
-
// React 19 Advanced Hooks
|
|
13
|
-
export {
|
|
14
|
-
useMediaActions,
|
|
15
|
-
useMediaActionState
|
|
16
|
-
} from "../use-media-actions"
|
|
17
|
-
export type { MediaActionPayloads } from "../use-media-actions"
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
useMediaOptimistic,
|
|
21
|
-
useMediaStateComparison,
|
|
22
|
-
useOptimisticUpdates
|
|
23
|
-
} from "../use-media-optimistic"
|
|
24
|
-
|
|
25
|
-
// Mobile-First Touch Gestures
|
|
26
|
-
export {
|
|
27
|
-
useMediaGestures,
|
|
28
|
-
useTouchGestures
|
|
29
|
-
} from "../use-touch-gestures"
|
|
30
|
-
export type {
|
|
31
|
-
GestureConfig,
|
|
32
|
-
GestureEvent,
|
|
33
|
-
GestureType
|
|
34
|
-
} from "../use-touch-gestures"
|
|
35
|
-
|
|
36
|
-
// Refactored Hooks (React 19 optimized)
|
|
37
|
-
export { useVideoPlayer } from "../useVideoPlayer"
|
|
38
|
-
export { useSubtitles } from "../useSubtitles"
|
|
39
|
-
export { useEnhancedSubtitles } from "../useEnhancedSubtitles"
|
|
40
|
-
export type { SubtitleTrack, UseEnhancedSubtitlesOptions } from "../useEnhancedSubtitles"
|
|
41
|
-
export { useMediaControls } from "../useMediaControls"
|
|
42
|
-
export { useScreenshot } from "../useScreenshot"
|
|
43
|
-
export type { VideoState, VideoControls } from "../useVideoPlayer"
|
|
44
|
-
|
|
45
|
-
// Specialized hooks
|
|
46
|
-
export { useMediaMetadata } from "../use-media-metadata"
|
|
47
|
-
export { useOptimisticMediaState } from "../use-optimistic-controls"
|
package/src/hooks/legacy.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy Hooks (Deprecated)
|
|
3
|
-
* These hooks are wrapped with deprecation warnings
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { showDeprecationWarning } from "../lib/deprecation"
|
|
7
|
-
|
|
8
|
-
// Import current hooks
|
|
9
|
-
import { useMediaPlayer } from "./use-media-player"
|
|
10
|
-
import { useSubtitles } from "./useSubtitles"
|
|
11
|
-
|
|
12
|
-
// Legacy hook wrappers with deprecation warnings
|
|
13
|
-
export function useVideoPlayer(props: any) {
|
|
14
|
-
showDeprecationWarning("useVideoPlayer", "useMediaPlayer (the primary media player hook)")
|
|
15
|
-
return useMediaPlayer(props)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function useEnhancedSubtitles(props: any) {
|
|
19
|
-
showDeprecationWarning("useEnhancedSubtitles", "useSubtitles (the current subtitle hook)")
|
|
20
|
-
return useSubtitles(props)
|
|
21
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "react"
|
|
2
|
-
|
|
3
|
-
export interface BufferHealthMetrics {
|
|
4
|
-
bufferedDuration: number
|
|
5
|
-
bufferedPercent: number
|
|
6
|
-
playheadDistance: number
|
|
7
|
-
stallCount: number
|
|
8
|
-
isStalled: boolean
|
|
9
|
-
lastStallDuration: number | null
|
|
10
|
-
bitrate: number | null
|
|
11
|
-
droppedFrames: number
|
|
12
|
-
audioLevel: number | null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface UseBufferHealthOptions {
|
|
16
|
-
minBufferDuration?: number
|
|
17
|
-
maxStallDuration?: number
|
|
18
|
-
stallThreshold?: number
|
|
19
|
-
onStall?: (duration: number) => void
|
|
20
|
-
onRecover?: () => void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const DEFAULT_OPTIONS: UseBufferHealthOptions = {
|
|
24
|
-
minBufferDuration: 5,
|
|
25
|
-
maxStallDuration: 3000,
|
|
26
|
-
stallThreshold: 1000,
|
|
27
|
-
onStall: undefined,
|
|
28
|
-
onRecover: undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function useBufferHealth(
|
|
32
|
-
videoRef: React.RefObject<HTMLVideoElement | HTMLAudioElement>,
|
|
33
|
-
options: UseBufferHealthOptions = {}
|
|
34
|
-
): BufferHealthMetrics {
|
|
35
|
-
const opts = { ...DEFAULT_OPTIONS, ...options }
|
|
36
|
-
const [metrics, setMetrics] = useState<BufferHealthMetrics>({
|
|
37
|
-
bufferedDuration: 0,
|
|
38
|
-
bufferedPercent: 0,
|
|
39
|
-
playheadDistance: 0,
|
|
40
|
-
stallCount: 0,
|
|
41
|
-
isStalled: false,
|
|
42
|
-
lastStallDuration: null,
|
|
43
|
-
bitrate: null,
|
|
44
|
-
droppedFrames: 0,
|
|
45
|
-
audioLevel: null
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const stallStartRef = useRef<number | null>(null)
|
|
49
|
-
const lastPlayheadRef = useRef<number>(0)
|
|
50
|
-
const lastTimeRef = useRef<number>(0)
|
|
51
|
-
|
|
52
|
-
const calculateMetrics = useCallback(() => {
|
|
53
|
-
const video = videoRef.current
|
|
54
|
-
if (!video) return
|
|
55
|
-
|
|
56
|
-
const currentTime = video.currentTime
|
|
57
|
-
const duration = video.duration || 1
|
|
58
|
-
const buffered = video.buffered
|
|
59
|
-
|
|
60
|
-
let bufferedDuration = 0
|
|
61
|
-
if (buffered.length > 0) {
|
|
62
|
-
for (let i = 0; i < buffered.length; i++) {
|
|
63
|
-
const start = buffered.start(i)
|
|
64
|
-
const end = buffered.end(i)
|
|
65
|
-
if (start <= currentTime && end >= currentTime) {
|
|
66
|
-
bufferedDuration = end - currentTime
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const bufferedPercent = (bufferedDuration / duration) * 100
|
|
73
|
-
const playheadDistance = 0
|
|
74
|
-
|
|
75
|
-
const now = Date.now()
|
|
76
|
-
const timeDelta = now - lastTimeRef.current
|
|
77
|
-
const playheadDelta = Math.abs(currentTime - lastPlayheadRef.current)
|
|
78
|
-
|
|
79
|
-
let isStalled = false
|
|
80
|
-
let stallDuration: number | null = null
|
|
81
|
-
let stallCount = metrics.stallCount
|
|
82
|
-
|
|
83
|
-
if (video.paused || video.ended) {
|
|
84
|
-
if (stallStartRef.current !== null) {
|
|
85
|
-
stallDuration = Date.now() - stallStartRef.current
|
|
86
|
-
if (stallDuration > (opts.stallThreshold || 1000)) {
|
|
87
|
-
isStalled = true
|
|
88
|
-
stallCount++
|
|
89
|
-
opts.onStall?.(stallDuration)
|
|
90
|
-
}
|
|
91
|
-
stallStartRef.current = null
|
|
92
|
-
}
|
|
93
|
-
} else if (timeDelta > 500 && playheadDelta < 0.1) {
|
|
94
|
-
if (stallStartRef.current === null) {
|
|
95
|
-
stallStartRef.current = now
|
|
96
|
-
}
|
|
97
|
-
isStalled = true
|
|
98
|
-
} else if (playheadDelta > 0.1 && stallStartRef.current !== null) {
|
|
99
|
-
stallDuration = Date.now() - stallStartRef.current
|
|
100
|
-
stallStartRef.current = null
|
|
101
|
-
if (stallDuration > (opts.stallThreshold || 1000)) {
|
|
102
|
-
stallCount++
|
|
103
|
-
opts.onStall?.(stallDuration)
|
|
104
|
-
}
|
|
105
|
-
opts.onRecover?.()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let droppedFrames = 0
|
|
109
|
-
let bitrate: number | null = null
|
|
110
|
-
let audioLevel: number | null = null
|
|
111
|
-
|
|
112
|
-
if ("getVideoPlaybackQuality" in video) {
|
|
113
|
-
const quality = (video as any).getVideoPlaybackQuality()
|
|
114
|
-
droppedFrames = quality?.droppedVideoFrames || 0
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if ("getBitrateInfo" in video) {
|
|
118
|
-
const info = (video as any).getBitrateInfo()
|
|
119
|
-
bitrate = info?.bitrate || null
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if ("audioTracks" in video) {
|
|
123
|
-
const tracks = (video as any).audioTracks
|
|
124
|
-
if (tracks && tracks.length > 0) {
|
|
125
|
-
audioLevel = tracks[0]?.volume || null
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
lastPlayheadRef.current = currentTime
|
|
130
|
-
lastTimeRef.current = now
|
|
131
|
-
|
|
132
|
-
setMetrics({
|
|
133
|
-
bufferedDuration,
|
|
134
|
-
bufferedPercent,
|
|
135
|
-
playheadDistance,
|
|
136
|
-
stallCount,
|
|
137
|
-
isStalled,
|
|
138
|
-
lastStallDuration: stallDuration,
|
|
139
|
-
bitrate,
|
|
140
|
-
droppedFrames,
|
|
141
|
-
audioLevel
|
|
142
|
-
})
|
|
143
|
-
}, [videoRef, opts, metrics.stallCount, opts.onStall, opts.onRecover, opts.stallThreshold])
|
|
144
|
-
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
const video = videoRef.current
|
|
147
|
-
if (!video) return
|
|
148
|
-
|
|
149
|
-
const interval = setInterval(calculateMetrics, 250)
|
|
150
|
-
|
|
151
|
-
const handleWaiting = () => {
|
|
152
|
-
stallStartRef.current = Date.now()
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const handlePlaying = () => {
|
|
156
|
-
if (stallStartRef.current !== null) {
|
|
157
|
-
const stallDuration = Date.now() - stallStartRef.current
|
|
158
|
-
if (stallDuration > (opts.stallThreshold || 1000)) {
|
|
159
|
-
setMetrics((prev) => ({
|
|
160
|
-
...prev,
|
|
161
|
-
stallCount: prev.stallCount + 1,
|
|
162
|
-
isStalled: false,
|
|
163
|
-
lastStallDuration: stallDuration
|
|
164
|
-
}))
|
|
165
|
-
opts.onStall?.(stallDuration)
|
|
166
|
-
}
|
|
167
|
-
stallStartRef.current = null
|
|
168
|
-
}
|
|
169
|
-
opts.onRecover?.()
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
video.addEventListener("waiting", handleWaiting)
|
|
173
|
-
video.addEventListener("playing", handlePlaying)
|
|
174
|
-
|
|
175
|
-
return () => {
|
|
176
|
-
clearInterval(interval)
|
|
177
|
-
video.removeEventListener("waiting", handleWaiting)
|
|
178
|
-
video.removeEventListener("playing", handlePlaying)
|
|
179
|
-
}
|
|
180
|
-
}, [videoRef, calculateMetrics, opts.stallThreshold, opts.onStall, opts.onRecover])
|
|
181
|
-
|
|
182
|
-
return metrics
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function useAdaptiveBuffering(
|
|
186
|
-
videoRef: React.RefObject<HTMLVideoElement | HTMLAudioElement>,
|
|
187
|
-
options?: UseBufferHealthOptions
|
|
188
|
-
) {
|
|
189
|
-
const metrics = useBufferHealth(videoRef, options)
|
|
190
|
-
|
|
191
|
-
const getRecommendedBufferSize = useCallback(() => {
|
|
192
|
-
if (metrics.isStalled) {
|
|
193
|
-
return 30
|
|
194
|
-
}
|
|
195
|
-
if (metrics.stallCount > 3) {
|
|
196
|
-
return 20
|
|
197
|
-
}
|
|
198
|
-
if (metrics.bufferedPercent < 5) {
|
|
199
|
-
return 15
|
|
200
|
-
}
|
|
201
|
-
return 10
|
|
202
|
-
}, [metrics.isStalled, metrics.stallCount, metrics.bufferedPercent])
|
|
203
|
-
|
|
204
|
-
const shouldIncreaseBuffer = useCallback(() => {
|
|
205
|
-
return metrics.stallCount > 0 && metrics.bufferedPercent < 10
|
|
206
|
-
}, [metrics.stallCount, metrics.bufferedPercent])
|
|
207
|
-
|
|
208
|
-
const shouldReduceQuality = useCallback(() => {
|
|
209
|
-
return metrics.isStalled || metrics.stallCount > 5
|
|
210
|
-
}, [metrics.isStalled, metrics.stallCount])
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
...metrics,
|
|
214
|
-
recommendedBufferSize: getRecommendedBufferSize(),
|
|
215
|
-
shouldIncreaseBuffer: shouldIncreaseBuffer(),
|
|
216
|
-
shouldReduceQuality: shouldReduceQuality()
|
|
217
|
-
}
|
|
218
|
-
}
|