]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-vod-transcoding.component.ts
Fix updating transcoding profiles
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-vod-transcoding.component.ts
1
2 import { SelectOptionsItem } from 'src/types/select-options-item.model'
3 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
4 import { FormGroup } from '@angular/forms'
5 import { ServerConfig } from '@shared/models'
6 import { ConfigService } from '../shared/config.service'
7 import { 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 })
14 export class EditVODTranscodingComponent implements OnInit, OnChanges {
15 @Input() form: FormGroup
16 @Input() formErrors: any
17 @Input() serverConfig: ServerConfig
18
19 transcodingThreadOptions: SelectOptionsItem[] = []
20 transcodingProfiles: SelectOptionsItem[] = []
21 resolutions: ResolutionOption[] = []
22
23 constructor (
24 private configService: ConfigService,
25 private editConfigurationService: EditConfigurationService
26 ) { }
27
28 ngOnInit () {
29 this.transcodingThreadOptions = this.configService.transcodingThreadOptions
30 this.resolutions = this.editConfigurationService.getVODResolutions()
31
32 this.checkTranscodingFields()
33 }
34
35 ngOnChanges (changes: SimpleChanges) {
36 if (changes['serverConfig']) {
37 this.transcodingProfiles = this.buildAvailableTranscodingProfile()
38 }
39 }
40
41 buildAvailableTranscodingProfile () {
42 const profiles = this.serverConfig.transcoding.availableProfiles
43
44 return profiles.map(p => {
45 const description = p === 'default'
46 ? $localize`x264, targeting maximum device compatibility`
47 : ''
48
49 return { id: p, label: p, description }
50 })
51 }
52
53 getResolutionKey (resolution: string) {
54 return 'transcoding.resolutions.' + resolution
55 }
56
57 isTranscodingEnabled () {
58 return this.editConfigurationService.isTranscodingEnabled(this.form)
59 }
60
61 getTranscodingDisabledClass () {
62 return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() }
63 }
64
65 getTotalTranscodingThreads () {
66 return this.editConfigurationService.getTotalTranscodingThreads(this.form)
67 }
68
69 private checkTranscodingFields () {
70 const hlsControl = this.form.get('transcoding.hls.enabled')
71 const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
72
73 webtorrentControl.valueChanges
74 .subscribe(newValue => {
75 if (newValue === false && !hlsControl.disabled) {
76 hlsControl.disable()
77 }
78
79 if (newValue === true && !hlsControl.enabled) {
80 hlsControl.enable()
81 }
82 })
83
84 hlsControl.valueChanges
85 .subscribe(newValue => {
86 if (newValue === false && !webtorrentControl.disabled) {
87 webtorrentControl.disable()
88 }
89
90 if (newValue === true && !webtorrentControl.enabled) {
91 webtorrentControl.enable()
92 }
93 })
94 }
95 }