]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/peertube-player-local-storage.ts
Translated using Weblate (Dutch)
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-player-local-storage.ts
CommitLineData
7b3a99d5
C
1function getStoredVolume () {
2 const value = getLocalStorage('volume')
3 if (value !== null && value !== undefined) {
4 const valueNumber = parseFloat(value)
5 if (isNaN(valueNumber)) return undefined
6
7 return valueNumber
8 }
9
10 return undefined
11}
12
43c66a91 13function getStoredP2PEnabled (): boolean {
ed638e53
RK
14 const value = getLocalStorage('webtorrent_enabled')
15 if (value !== null && value !== undefined) return value === 'true'
64cc5e85 16
e280dd06
C
17 // By default webtorrent is enabled
18 return true
64cc5e85
RK
19}
20
7b3a99d5
C
21function getStoredMute () {
22 const value = getLocalStorage('mute')
23 if (value !== null && value !== undefined) return value === 'true'
24
25 return undefined
26}
27
28function getStoredTheater () {
29 const value = getLocalStorage('theater-enabled')
30 if (value !== null && value !== undefined) return value === 'true'
31
011e1e6b 32 return false
7b3a99d5
C
33}
34
35function saveVolumeInStore (value: number) {
36 return setLocalStorage('volume', value.toString())
37}
38
39function saveMuteInStore (value: boolean) {
40 return setLocalStorage('mute', value.toString())
41}
42
43function saveTheaterInStore (enabled: boolean) {
44 return setLocalStorage('theater-enabled', enabled.toString())
45}
46
47function saveAverageBandwidth (value: number) {
48 return setLocalStorage('average-bandwidth', value.toString())
49}
50
51function getAverageBandwidthInStore () {
52 const value = getLocalStorage('average-bandwidth')
53 if (value !== null && value !== undefined) {
54 const valueNumber = parseInt(value, 10)
55 if (isNaN(valueNumber)) return undefined
56
57 return valueNumber
58 }
59
60 return undefined
61}
62
3b019808
C
63function saveLastSubtitle (language: string) {
64 return setLocalStorage('last-subtitle', language)
65}
66
67function getStoredLastSubtitle () {
68 return getLocalStorage('last-subtitle')
69}
70
7b3a99d5
C
71// ---------------------------------------------------------------------------
72
73export {
74 getStoredVolume,
43c66a91 75 getStoredP2PEnabled,
7b3a99d5
C
76 getStoredMute,
77 getStoredTheater,
78 saveVolumeInStore,
79 saveMuteInStore,
80 saveTheaterInStore,
81 saveAverageBandwidth,
3b019808
C
82 getAverageBandwidthInStore,
83 saveLastSubtitle,
84 getStoredLastSubtitle
7b3a99d5
C
85}
86
87// ---------------------------------------------------------------------------
88
89const KEY_PREFIX = 'peertube-videojs-'
90
91function getLocalStorage (key: string) {
92 try {
93 return localStorage.getItem(KEY_PREFIX + key)
94 } catch {
95 return undefined
96 }
97}
98
99function setLocalStorage (key: string, value: string) {
100 try {
101 localStorage.setItem(KEY_PREFIX + key, value)
102 } catch { /* empty */
103 }
104}