]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-vod-transcoding.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-vod-transcoding.component.ts
CommitLineData
5f46d28c
C
1
2import { SelectOptionsItem } from 'src/types/select-options-item.model'
b06f1ead 3import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
5f46d28c 4import { FormGroup } from '@angular/forms'
2989628b 5import { HTMLServerConfig } from '@shared/models'
5f46d28c
C
6import { ConfigService } from '../shared/config.service'
7import { EditConfigurationService, ResolutionOption } from './edit-configuration.service'
8
9@Component({
10 selector: 'my-edit-vod-transcoding',
11 templateUrl: './edit-vod-transcoding.component.html',
12 styleUrls: [ './edit-custom-config.component.scss' ]
13})
b06f1ead 14export class EditVODTranscodingComponent implements OnInit, OnChanges {
5f46d28c
C
15 @Input() form: FormGroup
16 @Input() formErrors: any
2989628b 17 @Input() serverConfig: HTMLServerConfig
5f46d28c
C
18
19 transcodingThreadOptions: SelectOptionsItem[] = []
b06f1ead 20 transcodingProfiles: SelectOptionsItem[] = []
5f46d28c
C
21 resolutions: ResolutionOption[] = []
22
0c12054a
C
23 additionalVideoExtensions = ''
24
5f46d28c
C
25 constructor (
26 private configService: ConfigService,
27 private editConfigurationService: EditConfigurationService
28 ) { }
29
30 ngOnInit () {
31 this.transcodingThreadOptions = this.configService.transcodingThreadOptions
32 this.resolutions = this.editConfigurationService.getVODResolutions()
33
34 this.checkTranscodingFields()
35 }
36
b06f1ead
C
37 ngOnChanges (changes: SimpleChanges) {
38 if (changes['serverConfig']) {
39 this.transcodingProfiles = this.buildAvailableTranscodingProfile()
0c12054a
C
40
41 this.additionalVideoExtensions = this.serverConfig.video.file.extensions.join(' ')
b06f1ead
C
42 }
43 }
44
45 buildAvailableTranscodingProfile () {
5f46d28c
C
46 const profiles = this.serverConfig.transcoding.availableProfiles
47
70e33515 48 return profiles.map(p => {
b99ee1b1
C
49 if (p === 'default') {
50 return { id: p, label: $localize`Default`, description: $localize`x264, targeting maximum device compatibility` }
51 }
70e33515 52
b99ee1b1 53 return { id: p, label: p }
70e33515 54 })
5f46d28c
C
55 }
56
57 getResolutionKey (resolution: string) {
58 return 'transcoding.resolutions.' + resolution
59 }
60
01283e20
C
61 isRemoteRunnerVODEnabled () {
62 return this.editConfigurationService.isRemoteRunnerVODEnabled(this.form)
63 }
64
5f46d28c
C
65 isTranscodingEnabled () {
66 return this.editConfigurationService.isTranscodingEnabled(this.form)
67 }
68
5e47f6ab
C
69 isStudioEnabled () {
70 return this.editConfigurationService.isStudioEnabled(this.form)
71 }
72
70e33515
C
73 getTranscodingDisabledClass () {
74 return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() }
75 }
76
01283e20
C
77 getLocalTranscodingDisabledClass () {
78 return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() || this.isRemoteRunnerVODEnabled() }
79 }
80
5e47f6ab
C
81 getStudioDisabledClass () {
82 return { 'disabled-checkbox-extra': !this.isStudioEnabled() }
83 }
84
5f46d28c
C
85 getTotalTranscodingThreads () {
86 return this.editConfigurationService.getTotalTranscodingThreads(this.form)
87 }
88
89 private checkTranscodingFields () {
c729caf6 90 const transcodingControl = this.form.get('transcoding.enabled')
92e66e04 91 const videoStudioControl = this.form.get('videoStudio.enabled')
5f46d28c
C
92 const hlsControl = this.form.get('transcoding.hls.enabled')
93 const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
94
95 webtorrentControl.valueChanges
96 .subscribe(newValue => {
97 if (newValue === false && !hlsControl.disabled) {
98 hlsControl.disable()
99 }
100
101 if (newValue === true && !hlsControl.enabled) {
102 hlsControl.enable()
103 }
104 })
105
106 hlsControl.valueChanges
107 .subscribe(newValue => {
108 if (newValue === false && !webtorrentControl.disabled) {
109 webtorrentControl.disable()
110 }
111
112 if (newValue === true && !webtorrentControl.enabled) {
113 webtorrentControl.enable()
114 }
115 })
c729caf6
C
116
117 transcodingControl.valueChanges
118 .subscribe(newValue => {
119 if (newValue === false) {
92e66e04 120 videoStudioControl.setValue(false)
c729caf6
C
121 }
122 })
8224e13d
C
123
124 transcodingControl.updateValueAndValidity()
125 webtorrentControl.updateValueAndValidity()
126 videoStudioControl.updateValueAndValidity()
127 hlsControl.updateValueAndValidity()
5f46d28c
C
128 }
129}