]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add.component.ts
Live streaming implementation first step
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 import { AuthService, AuthUser, CanComponentDeactivate, ServerService } from '@app/core'
3 import { ServerConfig } from '@shared/models'
4 import { VideoEditType } from './shared/video-edit.type'
5 import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
6 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
7 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
8 import { VideoUploadComponent } from './video-add-components/video-upload.component'
9
10 @Component({
11 selector: 'my-videos-add',
12 templateUrl: './video-add.component.html',
13 styleUrls: [ './video-add.component.scss' ]
14 })
15 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
16 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
17 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
18 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
19 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
20
21 user: AuthUser = null
22
23 secondStepType: VideoEditType
24 videoName: string
25 serverConfig: ServerConfig
26
27 constructor (
28 private auth: AuthService,
29 private serverService: ServerService
30 ) {}
31
32 get userInformationLoaded () {
33 return this.auth.userInformationLoaded
34 }
35
36 ngOnInit () {
37 this.user = this.auth.getUser()
38
39 this.serverConfig = this.serverService.getTmpConfig()
40
41 this.serverService.getConfig()
42 .subscribe(config => this.serverConfig = config)
43
44 this.user = this.auth.getUser()
45 }
46
47 onFirstStepDone (type: VideoEditType, videoName: string) {
48 this.secondStepType = type
49 this.videoName = videoName
50 }
51
52 onError () {
53 this.videoName = undefined
54 this.secondStepType = undefined
55 }
56
57 @HostListener('window:beforeunload', [ '$event' ])
58 onUnload (event: any) {
59 const { text, canDeactivate } = this.canDeactivate()
60
61 if (canDeactivate) return
62
63 event.returnValue = text
64 return text
65 }
66
67 canDeactivate (): { canDeactivate: boolean, text?: string} {
68 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
69 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
70 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
71
72 return { canDeactivate: true }
73 }
74
75 isVideoImportHttpEnabled () {
76 return this.serverConfig.import.videos.http.enabled
77 }
78
79 isVideoImportTorrentEnabled () {
80 return this.serverConfig.import.videos.torrent.enabled
81 }
82
83 isVideoLiveEnabled () {
84 return this.serverConfig.live.enabled
85 }
86
87 isInSecondStep () {
88 return !!this.secondStepType
89 }
90
91 isRootUser () {
92 return this.user.username === 'root'
93 }
94 }