2 import { Component, EventEmitter, OnInit, Output } from '@angular/core'
3 import { Router } from '@angular/router'
4 import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@app/core'
5 import { scrollToTop } from '@app/helpers'
6 import { FormValidatorService } from '@app/shared/shared-forms'
7 import { VideoCaptionService, VideoEdit, VideoService, VideoLiveService } from '@app/shared/shared-main'
8 import { LoadingBarService } from '@ngx-loading-bar/core'
9 import { VideoCreate, VideoLive, VideoPrivacy } from '@shared/models'
10 import { VideoSend } from './video-send'
13 selector: 'my-video-go-live',
14 templateUrl: './video-go-live.component.html',
16 '../shared/video-edit.component.scss',
20 export class VideoGoLiveComponent extends VideoSend implements OnInit, CanComponentDeactivate {
21 @Output() firstStepDone = new EventEmitter<string>()
22 @Output() firstStepError = new EventEmitter<void>()
24 isInUpdateForm = false
31 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
34 protected formValidatorService: FormValidatorService,
35 protected loadingBar: LoadingBarService,
36 protected notifier: Notifier,
37 protected authService: AuthService,
38 protected serverService: ServerService,
39 protected videoService: VideoService,
40 protected videoCaptionService: VideoCaptionService,
41 private videoLiveService: VideoLiveService,
42 private router: Router
52 return { canDeactivate: true }
56 const video: VideoCreate = {
58 privacy: VideoPrivacy.PRIVATE,
59 nsfw: this.serverConfig.instance.isNSFW,
60 waitTranscoding: true,
61 commentsEnabled: true,
62 downloadEnabled: true,
63 channelId: this.firstStepChannelId
66 this.firstStepDone.emit(name)
68 // Go live in private mode, but correctly fill the update form with the first user choice
69 const toPatch = Object.assign({}, video, { privacy: this.firstStepPrivacyId })
70 this.form.patchValue(toPatch)
72 this.videoLiveService.goLive(video).subscribe(
74 this.videoId = res.video.id
75 this.videoUUID = res.video.uuid
76 this.isInUpdateForm = true
82 this.firstStepError.emit()
83 this.notifier.error(err.message)
89 if (this.checkForm() === false) {
93 const video = new VideoEdit()
94 video.patch(this.form.value)
95 video.id = this.videoId
96 video.uuid = this.videoUUID
99 this.updateVideoAndCaptions(video)
102 this.notifier.success($localize`Live published.`)
104 this.router.navigate([ '/videos/watch', video.uuid ])
108 this.error = err.message
116 private fetchVideoLive () {
117 this.videoLiveService.getVideoLive(this.videoId)
120 this.videoLive = videoLive
124 this.firstStepError.emit()
125 this.notifier.error(err.message)