Merge pull request #3 from MertUyanik/codex/fix-linting-errors-in-project
Fix lint issues and improve type safety
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import React, { createContext, useContext, useRef, useState, useCallback } from 'react'
|
import React, { createContext, useContext, useRef, useState, useCallback } from 'react'
|
||||||
import type { PlayerContextValue, VideoState, UIState, PlayerSettings, AudioTrack } from '../types'
|
import type { PlayerContextValue, VideoState, UIState, PlayerSettings, AudioTrack } from '../types'
|
||||||
|
|
||||||
|
type SelectedQuality = PlayerSettings['quality']
|
||||||
|
type SelectedSubtitle = PlayerSettings['subtitle']
|
||||||
|
|
||||||
interface PlayerContextType extends PlayerContextValue {
|
interface PlayerContextType extends PlayerContextValue {
|
||||||
setVideoState: React.Dispatch<React.SetStateAction<VideoState>>
|
setVideoState: React.Dispatch<React.SetStateAction<VideoState>>
|
||||||
setUIState: React.Dispatch<React.SetStateAction<UIState>>
|
setUIState: React.Dispatch<React.SetStateAction<UIState>>
|
||||||
@@ -8,6 +11,7 @@ interface PlayerContextType extends PlayerContextValue {
|
|||||||
|
|
||||||
const PlayerContext = createContext<PlayerContextType | null>(null)
|
const PlayerContext = createContext<PlayerContextType | null>(null)
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export const usePlayerContext = () => {
|
export const usePlayerContext = () => {
|
||||||
const context = useContext(PlayerContext)
|
const context = useContext(PlayerContext)
|
||||||
if (!context) {
|
if (!context) {
|
||||||
@@ -143,11 +147,11 @@ export const PlayerProvider: React.FC<PlayerProviderProps> = ({
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
const setQuality = useCallback((quality: typeof settings.quality) => {
|
const setQuality = useCallback((quality: SelectedQuality) => {
|
||||||
setSettings((prev) => ({ ...prev, quality }))
|
setSettings((prev) => ({ ...prev, quality }))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const setSubtitle = useCallback((subtitle: typeof settings.subtitle) => {
|
const setSubtitle = useCallback((subtitle: SelectedSubtitle) => {
|
||||||
setSettings((prev) => ({ ...prev, subtitle }))
|
setSettings((prev) => ({ ...prev, subtitle }))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
@@ -92,11 +92,12 @@ export const useKeyboardShortcuts = (enabled: boolean = true) => {
|
|||||||
case '6':
|
case '6':
|
||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9': {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const percent = parseInt(e.key) / 10
|
const percent = parseInt(e.key, 10) / 10
|
||||||
seek(videoState.duration * percent)
|
seek(videoState.duration * percent)
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|||||||
+5
-3
@@ -1,3 +1,5 @@
|
|||||||
|
import type { CSSProperties, RefObject } from 'react'
|
||||||
|
|
||||||
export interface SubtitleTrack {
|
export interface SubtitleTrack {
|
||||||
src: string
|
src: string
|
||||||
lang: string
|
lang: string
|
||||||
@@ -39,7 +41,7 @@ export interface VideoPlayerProps {
|
|||||||
keyboardShortcuts?: boolean
|
keyboardShortcuts?: boolean
|
||||||
pictureInPicture?: boolean
|
pictureInPicture?: boolean
|
||||||
className?: string
|
className?: string
|
||||||
style?: React.CSSProperties
|
style?: CSSProperties
|
||||||
onPlay?: () => void
|
onPlay?: () => void
|
||||||
onPause?: () => void
|
onPause?: () => void
|
||||||
onEnded?: () => void
|
onEnded?: () => void
|
||||||
@@ -85,8 +87,8 @@ export interface PlayerContextValue {
|
|||||||
videoState: VideoState
|
videoState: VideoState
|
||||||
uiState: UIState
|
uiState: UIState
|
||||||
settings: PlayerSettings
|
settings: PlayerSettings
|
||||||
videoRef: React.RefObject<HTMLVideoElement>
|
videoRef: RefObject<HTMLVideoElement>
|
||||||
containerRef: React.RefObject<HTMLDivElement>
|
containerRef: RefObject<HTMLDivElement>
|
||||||
|
|
||||||
// Video controls
|
// Video controls
|
||||||
play: () => void
|
play: () => void
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export const loadHls = async (): Promise<any> => {
|
|||||||
const Hls = await loadHlsFromCDN()
|
const Hls = await loadHlsFromCDN()
|
||||||
return Hls
|
return Hls
|
||||||
} catch (cdnError) {
|
} catch (cdnError) {
|
||||||
console.error('❌ [HLS Loader] Failed to load hls.js from both npm and CDN')
|
console.error('❌ [HLS Loader] Failed to load hls.js from both npm and CDN', cdnError)
|
||||||
throw new Error('Unable to load HLS.js library. HLS streaming is not available.')
|
throw new Error('Unable to load HLS.js library. HLS streaming is not available.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user