]>
Commit | Line | Data |
---|---|---|
f3aaa9a9 C |
1 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript |
2 | ||
c5911fd3 | 3 | import { environment } from '../../../environments/environment' |
15a7387d C |
4 | import { AuthService } from '../../core/auth' |
5 | ||
f3aaa9a9 C |
6 | function getParameterByName (name: string, url: string) { |
7 | if (!url) url = window.location.href | |
8 | name = name.replace(/[\[\]]/g, '\\$&') | |
9 | ||
10 | const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)') | |
11 | const results = regex.exec(url) | |
12 | ||
13 | if (!results) return null | |
14 | if (!results[2]) return '' | |
15 | ||
16 | return decodeURIComponent(results[2].replace(/\+/g, ' ')) | |
17 | } | |
18 | ||
cd83ea1b C |
19 | function viewportHeight () { |
20 | return Math.max(document.documentElement.clientHeight, window.innerHeight || 0) | |
21 | } | |
22 | ||
15a7387d C |
23 | function populateAsyncUserVideoChannels (authService: AuthService, channel: any[]) { |
24 | return new Promise(res => { | |
25 | authService.userInformationLoaded | |
26 | .subscribe( | |
27 | () => { | |
28 | const user = authService.getUser() | |
29 | if (!user) return | |
30 | ||
31 | const videoChannels = user.videoChannels | |
32 | if (Array.isArray(videoChannels) === false) return | |
33 | ||
34 | videoChannels.forEach(c => channel.push({ id: c.id, label: c.name })) | |
35 | ||
36 | return res() | |
37 | } | |
38 | ) | |
39 | }) | |
40 | } | |
41 | ||
c5911fd3 C |
42 | function getAbsoluteAPIUrl () { |
43 | let absoluteAPIUrl = environment.apiUrl | |
44 | if (!absoluteAPIUrl) { | |
45 | // The API is on the same domain | |
46 | absoluteAPIUrl = window.location.origin | |
47 | } | |
48 | ||
49 | return absoluteAPIUrl | |
50 | } | |
51 | ||
f3aaa9a9 | 52 | export { |
cd83ea1b | 53 | viewportHeight, |
15a7387d | 54 | getParameterByName, |
c5911fd3 C |
55 | populateAsyncUserVideoChannels, |
56 | getAbsoluteAPIUrl | |
f3aaa9a9 | 57 | } |