2 import { forkJoin } from 'rxjs'
3 import { Component, EventEmitter, OnInit, Output } from '@angular/core'
4 import { Router } from '@angular/router'
5 import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@app/core'
6 import { scrollToTop } from '@app/helpers'
7 import { FormValidatorService } from '@app/shared/shared-forms'
8 import { LiveVideoService, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
9 import { LoadingBarService } from '@ngx-loading-bar/core'
10 import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
11 import { VideoSend } from './video-send'
14 selector: 'my-video-go-live',
15 templateUrl: './video-go-live.component.html',
17 '../shared/video-edit.component.scss',
21 export class VideoGoLiveComponent extends VideoSend implements OnInit, CanComponentDeactivate {
22 @Output() firstStepDone = new EventEmitter<string>()
23 @Output() firstStepError = new EventEmitter<void>()
25 isInUpdateForm = false
32 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
35 protected formValidatorService: FormValidatorService,
36 protected loadingBar: LoadingBarService,
37 protected notifier: Notifier,
38 protected authService: AuthService,
39 protected serverService: ServerService,
40 protected videoService: VideoService,
41 protected videoCaptionService: VideoCaptionService,
42 private liveVideoService: LiveVideoService,
43 private router: Router
53 return { canDeactivate: true }
57 const video: LiveVideoCreate = {
59 privacy: VideoPrivacy.PRIVATE,
60 nsfw: this.serverConfig.instance.isNSFW,
61 waitTranscoding: true,
62 commentsEnabled: true,
63 downloadEnabled: true,
64 channelId: this.firstStepChannelId
67 this.firstStepDone.emit(name)
69 // Go live in private mode, but correctly fill the update form with the first user choice
70 const toPatch = Object.assign({}, video, { privacy: this.firstStepPrivacyId })
71 this.form.patchValue(toPatch)
73 this.liveVideoService.goLive(video).subscribe(
75 this.videoId = res.video.id
76 this.videoUUID = res.video.uuid
77 this.isInUpdateForm = true
83 this.firstStepError.emit()
84 this.notifier.error(err.message)
90 if (this.checkForm() === false) {
94 const video = new VideoEdit()
95 video.patch(this.form.value)
96 video.id = this.videoId
97 video.uuid = this.videoUUID
99 const liveVideoUpdate: LiveVideoUpdate = {
100 saveReplay: this.form.value.saveReplay
105 this.updateVideoAndCaptions(video),
107 this.liveVideoService.updateLive(this.videoId, liveVideoUpdate)
110 this.notifier.success($localize`Live published.`)
112 this.router.navigate(['/videos/watch', video.uuid])
116 this.error = err.message
123 getMaxLiveDuration () {
124 return this.serverConfig.live.maxDuration / 1000
127 private fetchVideoLive () {
128 this.liveVideoService.getVideoLive(this.videoId)
131 this.liveVideo = liveVideo
135 this.firstStepError.emit()
136 this.notifier.error(err.message)