]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 function 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
13 function getStoredP2PEnabled (): boolean {
14 const value = getLocalStorage('webtorrent_enabled')
15 if (value !== null && value !== undefined) return value === 'true'
16
17 // By default webtorrent is enabled
18 return true
19 }
20
21 function getStoredMute () {
22 const value = getLocalStorage('mute')
23 if (value !== null && value !== undefined) return value === 'true'
24
25 return undefined
26 }
27
28 function getStoredTheater () {
29 const value = getLocalStorage('theater-enabled')
30 if (value !== null && value !== undefined) return value === 'true'
31
32 return false
33 }
34
35 function saveVolumeInStore (value: number) {
36 return setLocalStorage('volume', value.toString())
37 }
38
39 function saveMuteInStore (value: boolean) {
40 return setLocalStorage('mute', value.toString())
41 }
42
43 function saveTheaterInStore (enabled: boolean) {
44 return setLocalStorage('theater-enabled', enabled.toString())
45 }
46
47 function saveAverageBandwidth (value: number) {
48 return setLocalStorage('average-bandwidth', value.toString())
49 }
50
51 function 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
63 function saveLastSubtitle (language: string) {
64 return setLocalStorage('last-subtitle', language)
65 }
66
67 function getStoredLastSubtitle () {
68 return getLocalStorage('last-subtitle')
69 }
70
71 // ---------------------------------------------------------------------------
72
73 export {
74 getStoredVolume,
75 getStoredP2PEnabled,
76 getStoredMute,
77 getStoredTheater,
78 saveVolumeInStore,
79 saveMuteInStore,
80 saveTheaterInStore,
81 saveAverageBandwidth,
82 getAverageBandwidthInStore,
83 saveLastSubtitle,
84 getStoredLastSubtitle
85 }
86
87 // ---------------------------------------------------------------------------
88
89 const KEY_PREFIX = 'peertube-videojs-'
90
91 function getLocalStorage (key: string) {
92 try {
93 return localStorage.getItem(KEY_PREFIX + key)
94 } catch {
95 return undefined
96 }
97 }
98
99 function setLocalStorage (key: string, value: string) {
100 try {
101 localStorage.setItem(KEY_PREFIX + key, value)
102 } catch { /* empty */
103 }
104 }