Skip to content

Commit

Permalink
fix: player prefs part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhooks committed Oct 28, 2024
1 parent 854bbb3 commit 5daf7e2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/hooks/mux/use-player-prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cookies from '@/utils/cookies'

const PLAY_PREFS_KEY = 'muxplayer-react-prefs'

export const defaultSubtitlePreference = {
export const defaultSubtitlePreference: Subtitle = {
id: null,
kind: null,
label: null,
Expand Down Expand Up @@ -54,14 +54,14 @@ const defaultPlayerPreferences: PlayerPrefs = {
activeSidebarTab: 0,
}

export const getPlayerPrefs = () => {
export const getPlayerPrefs = (): PlayerPrefs => {
if (typeof window === 'undefined') {
return defaultPlayerPreferences
}
const cookiePrefs =
cookies.get(PLAY_PREFS_KEY) ||
cookies.set(PLAY_PREFS_KEY, defaultPlayerPreferences)
return cookiePrefs || defaultPlayerPreferences
return cookiePrefs ?? defaultPlayerPreferences
}

export const savePlayerPrefs = (options: any) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ export const setPreferredTextTrack = (
if (muxPlayerRef.current) {
let player = muxPlayerRef.current
let preferredTextTrack = player.textTracks?.getTrackById(
getPlayerPrefs().subtitle.id,
getPlayerPrefs()?.subtitle.id ?? '',
)
if (preferredTextTrack && getPlayerPrefs().subtitle.mode === 'showing') {
preferredTextTrack.mode = 'showing'
Expand Down

0 comments on commit 5daf7e2

Please sign in to comment.