1
0
Fork 0
peertube/client/src/app/+admin/config/edit-custom-config/edit-vod-transcoding.compon...

114 lines
3.6 KiB
TypeScript
Raw Normal View History

2021-02-10 10:06:32 +00:00
import { SelectOptionsItem } from 'src/types/select-options-item.model'
2021-04-08 12:41:15 +00:00
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
2021-02-10 10:06:32 +00:00
import { FormGroup } from '@angular/forms'
2021-06-04 11:31:41 +00:00
import { HTMLServerConfig } from '@shared/models'
2021-02-10 10:06:32 +00:00
import { ConfigService } from '../shared/config.service'
import { EditConfigurationService, ResolutionOption } from './edit-configuration.service'
@Component({
selector: 'my-edit-vod-transcoding',
templateUrl: './edit-vod-transcoding.component.html',
styleUrls: [ './edit-custom-config.component.scss' ]
})
2021-04-08 12:41:15 +00:00
export class EditVODTranscodingComponent implements OnInit, OnChanges {
2021-02-10 10:06:32 +00:00
@Input() form: FormGroup
@Input() formErrors: any
2021-06-04 11:31:41 +00:00
@Input() serverConfig: HTMLServerConfig
2021-02-10 10:06:32 +00:00
transcodingThreadOptions: SelectOptionsItem[] = []
2021-04-08 12:41:15 +00:00
transcodingProfiles: SelectOptionsItem[] = []
2021-02-10 10:06:32 +00:00
resolutions: ResolutionOption[] = []
additionalVideoExtensions = ''
2021-02-10 10:06:32 +00:00
constructor (
private configService: ConfigService,
private editConfigurationService: EditConfigurationService
) { }
ngOnInit () {
this.transcodingThreadOptions = this.configService.transcodingThreadOptions
this.resolutions = this.editConfigurationService.getVODResolutions()
this.checkTranscodingFields()
}
2021-04-08 12:41:15 +00:00
ngOnChanges (changes: SimpleChanges) {
if (changes['serverConfig']) {
this.transcodingProfiles = this.buildAvailableTranscodingProfile()
this.additionalVideoExtensions = this.serverConfig.video.file.extensions.join(' ')
2021-04-08 12:41:15 +00:00
}
}
buildAvailableTranscodingProfile () {
2021-02-10 10:06:32 +00:00
const profiles = this.serverConfig.transcoding.availableProfiles
2021-02-10 10:27:36 +00:00
return profiles.map(p => {
const description = p === 'default'
? $localize`x264, targeting maximum device compatibility`
: ''
return { id: p, label: p, description }
})
2021-02-10 10:06:32 +00:00
}
getResolutionKey (resolution: string) {
return 'transcoding.resolutions.' + resolution
}
isTranscodingEnabled () {
return this.editConfigurationService.isTranscodingEnabled(this.form)
}
2021-02-10 10:27:36 +00:00
getTranscodingDisabledClass () {
return { 'disabled-checkbox-extra': !this.isTranscodingEnabled() }
}
2021-02-10 10:06:32 +00:00
getTotalTranscodingThreads () {
return this.editConfigurationService.getTotalTranscodingThreads(this.form)
}
private checkTranscodingFields () {
2022-02-11 09:51:33 +00:00
const transcodingControl = this.form.get('transcoding.enabled')
2022-03-22 15:58:49 +00:00
const videoStudioControl = this.form.get('videoStudio.enabled')
2021-02-10 10:06:32 +00:00
const hlsControl = this.form.get('transcoding.hls.enabled')
const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
webtorrentControl.valueChanges
.subscribe(newValue => {
if (newValue === false && !hlsControl.disabled) {
hlsControl.disable()
}
if (newValue === true && !hlsControl.enabled) {
hlsControl.enable()
}
})
hlsControl.valueChanges
.subscribe(newValue => {
if (newValue === false && !webtorrentControl.disabled) {
webtorrentControl.disable()
}
if (newValue === true && !webtorrentControl.enabled) {
webtorrentControl.enable()
}
})
2022-02-11 09:51:33 +00:00
transcodingControl.valueChanges
.subscribe(newValue => {
if (newValue === false) {
2022-03-22 15:58:49 +00:00
videoStudioControl.setValue(false)
2022-02-11 09:51:33 +00:00
}
})
2022-07-28 07:45:15 +00:00
transcodingControl.updateValueAndValidity()
webtorrentControl.updateValueAndValidity()
videoStudioControl.updateValueAndValidity()
hlsControl.updateValueAndValidity()
2021-02-10 10:06:32 +00:00
}
}