1 import { catchError, switchMap, tap } from 'rxjs/operators'
2 import { EventEmitter, OnInit } from '@angular/core'
3 import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
4 import { populateAsyncUserVideoChannels } from '@app/helpers'
5 import { FormReactive } from '@app/shared/shared-forms'
6 import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
7 import { LoadingBarService } from '@ngx-loading-bar/core'
8 import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
10 export abstract class VideoSend extends FormReactive implements OnInit {
11 userVideoChannels: { id: number, label: string, support: string }[] = []
12 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
13 videoCaptions: VideoCaptionEdit[] = []
15 firstStepPrivacyId = 0
16 firstStepChannelId = 0
18 abstract firstStepDone: EventEmitter<string>
19 abstract firstStepError: EventEmitter<void>
20 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
22 protected loadingBar: LoadingBarService
23 protected notifier: Notifier
24 protected authService: AuthService
25 protected serverService: ServerService
26 protected videoService: VideoService
27 protected videoCaptionService: VideoCaptionService
28 protected serverConfig: ServerConfig
30 abstract canDeactivate (): CanComponentDeactivateResult
35 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
36 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
38 this.serverConfig = this.serverService.getTmpConfig()
39 this.serverService.getConfig()
40 .subscribe(config => this.serverConfig = config)
42 this.serverService.getVideoPrivacies()
45 this.videoPrivacies = privacies
47 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
54 return this.form.valid
57 protected updateVideoAndCaptions (video: VideoEdit) {
58 this.loadingBar.start()
60 return this.videoService.updateVideo(video)
62 // Then update captions
63 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
64 tap(() => this.loadingBar.complete()),
66 this.loadingBar.complete()