]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.component.ts
Don't log "The play() request was interrupted..."
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
CommitLineData
fd45e8f4 1import { Component, OnInit } from '@angular/core'
00b5556c 2import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
989e526a 3import { GuardsCheckStart, NavigationEnd, Router } from '@angular/router'
901637bb 4import { AuthService, RedirectService, ServerService } from '@app/core'
989e526a 5import { is18nPath } from '../../../shared/models/i18n'
bbe0f064 6import { ScreenService } from '@app/shared/misc/screen.service'
e2a2d6c8 7
dc8bc31b 8@Component({
3154f382
C
9 selector: 'my-app',
10 templateUrl: './app.component.html',
11 styleUrls: [ './app.component.scss' ]
dc8bc31b 12})
e2a2d6c8 13export class AppComponent implements OnInit {
7ddd02c9 14 notificationOptions = {
35bf0c83 15 timeOut: 5000,
7ddd02c9
C
16 lastOnBottom: true,
17 clickToClose: true,
18 maxLength: 0,
19 maxStack: 7,
20 showProgressBar: false,
21 pauseOnHover: false,
22 preventDuplicates: false,
23 preventLastDuplicates: 'visible',
24 rtl: false
df98563e 25 }
7ddd02c9 26
df98563e 27 isMenuDisplayed = true
67167390 28
00b5556c
C
29 customCSS: SafeHtml
30
df98563e 31 constructor (
3154f382 32 private router: Router,
e2a2d6c8 33 private authService: AuthService,
00b5556c 34 private serverService: ServerService,
901637bb 35 private domSanitizer: DomSanitizer,
bbe0f064
C
36 private redirectService: RedirectService,
37 private screenService: ScreenService
989e526a 38 ) { }
a99593ed 39
915c5bbe
C
40 get serverVersion () {
41 return this.serverService.getConfig().serverVersion
42 }
43
36f9424f
C
44 get instanceName () {
45 return this.serverService.getConfig().instance.name
46 }
47
29f9b562
C
48 get defaultRoute () {
49 return RedirectService.DEFAULT_ROUTE
50 }
51
df98563e 52 ngOnInit () {
b3eeb529 53 document.getElementById('incompatible-browser').className += ' browser-ok'
73e09f27 54
b851dabf
C
55 this.router.events.subscribe(e => {
56 if (e instanceof NavigationEnd) {
57 const pathname = window.location.pathname
989e526a 58 if (!pathname || pathname === '/' || is18nPath(pathname)) {
7cf26f43 59 this.redirectService.redirectToHomepage(true)
b851dabf
C
60 }
61 }
62 })
901637bb 63
d592e0a9
C
64 this.authService.loadClientCredentials()
65
d414207f 66 if (this.isUserLoggedIn()) {
e2a2d6c8 67 // The service will automatically redirect to the login page if the token is not valid anymore
bcd9f81e 68 this.authService.refreshUserInformation()
e2a2d6c8 69 }
6e07c3de 70
db7af09b
C
71 // Load custom data from server
72 this.serverService.loadConfig()
73 this.serverService.loadVideoCategories()
74 this.serverService.loadVideoLanguages()
75 this.serverService.loadVideoLicences()
fd45e8f4 76 this.serverService.loadVideoPrivacies()
3eeeb87f
C
77
78 // Do not display menu on small screens
bbe0f064 79 if (this.screenService.isInSmallView()) {
df98563e 80 this.isMenuDisplayed = false
3eeeb87f 81 }
c8cf5952
C
82
83 this.router.events.subscribe(
84 e => {
85 // User clicked on a link in the menu, change the page
bbe0f064 86 if (e instanceof GuardsCheckStart && this.screenService.isInSmallView()) {
c8cf5952
C
87 this.isMenuDisplayed = false
88 }
89 }
90 )
00b5556c
C
91
92 this.serverService.configLoaded
93 .subscribe(() => {
94 const config = this.serverService.getConfig()
95
c263f3b4 96 // We test customCSS if the admin removed the css
00b5556c
C
97 if (this.customCSS || config.instance.customizations.css) {
98 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
99 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
100 }
101
102 if (config.instance.customizations.javascript) {
103 try {
104 // tslint:disable:no-eval
105 eval(config.instance.customizations.javascript)
106 } catch (err) {
107 console.error('Cannot eval custom JavaScript.', err)
108 }
109 }
110 })
e2a2d6c8
C
111 }
112
d414207f
C
113 isUserLoggedIn () {
114 return this.authService.isLoggedIn()
115 }
116
df98563e 117 toggleMenu () {
a01f107b 118 window.scrollTo(0, 0)
df98563e 119 this.isMenuDisplayed = !this.isMenuDisplayed
67167390 120 }
dc8bc31b 121}