]>
Commit | Line | Data |
---|---|---|
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 { HTMLServerConfig } 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: HTMLServerConfig | |
18 | ||
19 | transcodingThreadOptions: SelectOptionsItem[] = [] | |
20 | transcodingProfiles: SelectOptionsItem[] = [] | |
21 | resolutions: ResolutionOption[] = [] | |
22 | ||
23 | additionalVideoExtensions = '' | |
24 | ||
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 | ||
37 | ngOnChanges (changes: SimpleChanges) { | |
38 | if (changes['serverConfig']) { | |
39 | this.transcodingProfiles = this.buildAvailableTranscodingProfile() | |
40 | ||
41 | this.additionalVideoExtensions = this.serverConfig.video.file.extensions.join(' ') | |
42 | } | |
43 | } | |
44 | ||
45 | buildAvailableTranscodingProfile () { | |
46 | const profiles = this.serverConfig.transcoding.availableProfiles | |
47 | ||
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 | }) | |
55 | } | |
56 | ||
57 | getResolutionKey (resolution: string) { | |
58 | return 'transcoding.resolutions.' + resolution | |
59 | } | |
60 | ||
61 | isTranscodingEnabled () { | |
62 | return this.editConfigurationService.isTranscodingEnabled(this.form) | |
63 | } | |
64 | ||
65 | isStudioEnabled () { | |
66 | return this.editConfigurationService.isStudioEnabled(this.form) | |
67 | } | |
68 | ||
69 | getTranscodingDisabledClass () { | |
70 | return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() } | |
71 | } | |
72 | ||
73 | getStudioDisabledClass () { | |
74 | return { 'disabled-checkbox-extra': !this.isStudioEnabled() } | |
75 | } | |
76 | ||
77 | getTotalTranscodingThreads () { | |
78 | return this.editConfigurationService.getTotalTranscodingThreads(this.form) | |
79 | } | |
80 | ||
81 | private checkTranscodingFields () { | |
82 | const transcodingControl = this.form.get('transcoding.enabled') | |
83 | const videoStudioControl = this.form.get('videoStudio.enabled') | |
84 | const hlsControl = this.form.get('transcoding.hls.enabled') | |
85 | const webtorrentControl = this.form.get('transcoding.webtorrent.enabled') | |
86 | ||
87 | webtorrentControl.valueChanges | |
88 | .subscribe(newValue => { | |
89 | if (newValue === false && !hlsControl.disabled) { | |
90 | hlsControl.disable() | |
91 | } | |
92 | ||
93 | if (newValue === true && !hlsControl.enabled) { | |
94 | hlsControl.enable() | |
95 | } | |
96 | }) | |
97 | ||
98 | hlsControl.valueChanges | |
99 | .subscribe(newValue => { | |
100 | if (newValue === false && !webtorrentControl.disabled) { | |
101 | webtorrentControl.disable() | |
102 | } | |
103 | ||
104 | if (newValue === true && !webtorrentControl.enabled) { | |
105 | webtorrentControl.enable() | |
106 | } | |
107 | }) | |
108 | ||
109 | transcodingControl.valueChanges | |
110 | .subscribe(newValue => { | |
111 | if (newValue === false) { | |
112 | videoStudioControl.setValue(false) | |
113 | } | |
114 | }) | |
115 | ||
116 | transcodingControl.updateValueAndValidity() | |
117 | webtorrentControl.updateValueAndValidity() | |
118 | videoStudioControl.updateValueAndValidity() | |
119 | hlsControl.updateValueAndValidity() | |
120 | } | |
121 | } |