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