aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-18 09:46:58 +0200
committerChocobozzz <me@florianbigard.com>2018-06-18 10:26:19 +0200
commit7b3a99d51716e404bdea0cef8d1f994aab0e8aac (patch)
treef1a07e610a1db0afd9d08083a148381ae1eaf0cf /client/src/assets/player/utils.ts
parentf5a2dc48eb80ab7842cec1da7269b5d153208689 (diff)
downloadPeerTube-7b3a99d51716e404bdea0cef8d1f994aab0e8aac.tar.gz
PeerTube-7b3a99d51716e404bdea0cef8d1f994aab0e8aac.tar.zst
PeerTube-7b3a99d51716e404bdea0cef8d1f994aab0e8aac.zip
Move player local storage functions in their own file
Diffstat (limited to 'client/src/assets/player/utils.ts')
-rw-r--r--client/src/assets/player/utils.ts83
1 files changed, 2 insertions, 81 deletions
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts
index 18a6b4dfa..c27e630e5 100644
--- a/client/src/assets/player/utils.ts
+++ b/client/src/assets/player/utils.ts
@@ -1,4 +1,3 @@
1import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
2import { VideoFile } from '../../../../shared/models/videos' 1import { VideoFile } from '../../../../shared/models/videos'
3 2
4function toTitleCase (str: string) { 3function toTitleCase (str: string) {
@@ -20,60 +19,6 @@ function bytes (value) {
20 return [ calc, format.type ] 19 return [ calc, format.type ]
21} 20}
22 21
23function getStoredVolume () {
24 const value = getLocalStorage('volume')
25 if (value !== null && value !== undefined) {
26 const valueNumber = parseFloat(value)
27 if (isNaN(valueNumber)) return undefined
28
29 return valueNumber
30 }
31
32 return undefined
33}
34
35function getStoredMute () {
36 const value = getLocalStorage('mute')
37 if (value !== null && value !== undefined) return value === 'true'
38
39 return undefined
40}
41
42function getAverageBandwidth () {
43 const value = getLocalStorage('average-bandwidth')
44 if (value !== null && value !== undefined) {
45 const valueNumber = parseInt(value, 10)
46 if (isNaN(valueNumber)) return undefined
47
48 return valueNumber
49 }
50
51 return undefined
52}
53
54function getStoredTheater () {
55 const value = getLocalStorage('theater-enabled')
56 if (value !== null && value !== undefined) return value === 'true'
57
58 return undefined
59}
60
61function saveVolumeInStore (value: number) {
62 return setLocalStorage('volume', value.toString())
63}
64
65function saveMuteInStore (value: boolean) {
66 return setLocalStorage('mute', value.toString())
67}
68
69function saveTheaterInStore (enabled: boolean) {
70 return setLocalStorage('theater-enabled', enabled.toString())
71}
72
73function saveAverageBandwidth (value: number) {
74 return setLocalStorage('average-bandwidth', value.toString())
75}
76
77function isMobile () { 22function isMobile () {
78 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) 23 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
79} 24}
@@ -132,39 +77,15 @@ function videoFileMinByResolution (files: VideoFile[]) {
132 return min 77 return min
133} 78}
134 79
80// ---------------------------------------------------------------------------
81
135export { 82export {
136 toTitleCase, 83 toTitleCase,
137 buildVideoLink, 84 buildVideoLink,
138 getStoredVolume,
139 saveVolumeInStore,
140 saveAverageBandwidth,
141 getAverageBandwidth,
142 saveMuteInStore,
143 buildVideoEmbed, 85 buildVideoEmbed,
144 getStoredMute,
145 videoFileMaxByResolution, 86 videoFileMaxByResolution,
146 videoFileMinByResolution, 87 videoFileMinByResolution,
147 copyToClipboard, 88 copyToClipboard,
148 getStoredTheater,
149 saveTheaterInStore,
150 isMobile, 89 isMobile,
151 bytes 90 bytes
152} 91}
153
154// ---------------------------------------------------------------------------
155
156const KEY_PREFIX = 'peertube-videojs-'
157
158function getLocalStorage (key: string) {
159 try {
160 return localStorage.getItem(KEY_PREFIX + key)
161 } catch {
162 return undefined
163 }
164}
165
166function setLocalStorage (key: string, value: string) {
167 try {
168 localStorage.setItem(KEY_PREFIX + key, value)
169 } catch { /* empty */ }
170}