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'
10 selector: 'my-edit-vod-transcoding',
11 templateUrl: './edit-vod-transcoding.component.html',
12 styleUrls: [ './edit-custom-config.component.scss' ]
14 export class EditVODTranscodingComponent implements OnInit, OnChanges {
15 @Input() form: FormGroup
16 @Input() formErrors: any
17 @Input() serverConfig: ServerConfig
19 transcodingThreadOptions: SelectOptionsItem[] = []
20 transcodingProfiles: SelectOptionsItem[] = []
21 resolutions: ResolutionOption[] = []
24 private configService: ConfigService,
25 private editConfigurationService: EditConfigurationService
29 this.transcodingThreadOptions = this.configService.transcodingThreadOptions
30 this.resolutions = this.editConfigurationService.getVODResolutions()
32 this.checkTranscodingFields()
35 ngOnChanges (changes: SimpleChanges) {
36 if (changes['serverConfig']) {
37 this.transcodingProfiles = this.buildAvailableTranscodingProfile()
41 buildAvailableTranscodingProfile () {
42 const profiles = this.serverConfig.transcoding.availableProfiles
44 return profiles.map(p => {
45 const description = p === 'default'
46 ? $localize`x264, targeting maximum device compatibility`
49 return { id: p, label: p, description }
53 getResolutionKey (resolution: string) {
54 return 'transcoding.resolutions.' + resolution
57 isTranscodingEnabled () {
58 return this.editConfigurationService.isTranscodingEnabled(this.form)
61 getTranscodingDisabledClass () {
62 return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() }
65 getTotalTranscodingThreads () {
66 return this.editConfigurationService.getTotalTranscodingThreads(this.form)
69 private checkTranscodingFields () {
70 const hlsControl = this.form.get('transcoding.hls.enabled')
71 const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
73 webtorrentControl.valueChanges
74 .subscribe(newValue => {
75 if (newValue === false && !hlsControl.disabled) {
79 if (newValue === true && !hlsControl.enabled) {
84 hlsControl.valueChanges
85 .subscribe(newValue => {
86 if (newValue === false && !webtorrentControl.disabled) {
87 webtorrentControl.disable()
90 if (newValue === true && !webtorrentControl.enabled) {
91 webtorrentControl.enable()