]>
Commit | Line | Data |
---|---|---|
5f46d28c C |
1 | |
2 | import { SelectOptionsItem } from 'src/types/select-options-item.model' | |
b06f1ead | 3 | import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' |
5f46d28c | 4 | import { FormGroup } from '@angular/forms' |
2989628b | 5 | import { HTMLServerConfig } from '@shared/models' |
5f46d28c C |
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 | }) | |
b06f1ead | 14 | export 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 C |
48 | return profiles.map(p => { |
49 | const description = p === 'default' | |
50 | ? $localize`x264, targeting maximum device compatibility` | |
51 | : '' | |
52 | ||
53 | return { id: p, label: p, description } | |
54 | }) | |
5f46d28c C |
55 | } |
56 | ||
57 | getResolutionKey (resolution: string) { | |
58 | return 'transcoding.resolutions.' + resolution | |
59 | } | |
60 | ||
61 | isTranscodingEnabled () { | |
62 | return this.editConfigurationService.isTranscodingEnabled(this.form) | |
63 | } | |
64 | ||
70e33515 C |
65 | getTranscodingDisabledClass () { |
66 | return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() } | |
67 | } | |
68 | ||
5f46d28c C |
69 | getTotalTranscodingThreads () { |
70 | return this.editConfigurationService.getTotalTranscodingThreads(this.form) | |
71 | } | |
72 | ||
73 | private checkTranscodingFields () { | |
c729caf6 | 74 | const transcodingControl = this.form.get('transcoding.enabled') |
92e66e04 | 75 | const videoStudioControl = this.form.get('videoStudio.enabled') |
5f46d28c C |
76 | const hlsControl = this.form.get('transcoding.hls.enabled') |
77 | const webtorrentControl = this.form.get('transcoding.webtorrent.enabled') | |
78 | ||
79 | webtorrentControl.valueChanges | |
80 | .subscribe(newValue => { | |
81 | if (newValue === false && !hlsControl.disabled) { | |
82 | hlsControl.disable() | |
83 | } | |
84 | ||
85 | if (newValue === true && !hlsControl.enabled) { | |
86 | hlsControl.enable() | |
87 | } | |
88 | }) | |
89 | ||
90 | hlsControl.valueChanges | |
91 | .subscribe(newValue => { | |
92 | if (newValue === false && !webtorrentControl.disabled) { | |
93 | webtorrentControl.disable() | |
94 | } | |
95 | ||
96 | if (newValue === true && !webtorrentControl.enabled) { | |
97 | webtorrentControl.enable() | |
98 | } | |
99 | }) | |
c729caf6 C |
100 | |
101 | transcodingControl.valueChanges | |
102 | .subscribe(newValue => { | |
103 | if (newValue === false) { | |
92e66e04 | 104 | videoStudioControl.setValue(false) |
c729caf6 C |
105 | } |
106 | }) | |
5f46d28c C |
107 | } |
108 | } |