2020-09-17 07:20:52 +00:00
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
import { forkJoin } from 'rxjs'
|
2020-09-17 07:20:52 +00:00
|
|
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core'
|
|
|
|
import { Router } from '@angular/router'
|
|
|
|
import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@app/core'
|
|
|
|
import { scrollToTop } from '@app/helpers'
|
|
|
|
import { FormValidatorService } from '@app/shared/shared-forms'
|
2020-11-05 09:56:23 +00:00
|
|
|
import { VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
|
|
|
|
import { LiveVideoService } from '@app/shared/shared-video-live'
|
2020-09-17 07:20:52 +00:00
|
|
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
2020-10-28 14:24:40 +00:00
|
|
|
import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, ServerErrorCode, VideoPrivacy } from '@shared/models'
|
2020-09-17 07:20:52 +00:00
|
|
|
import { VideoSend } from './video-send'
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-go-live',
|
|
|
|
templateUrl: './video-go-live.component.html',
|
|
|
|
styleUrls: [
|
|
|
|
'../shared/video-edit.component.scss',
|
|
|
|
'./video-send.scss'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
export class VideoGoLiveComponent extends VideoSend implements OnInit, CanComponentDeactivate {
|
|
|
|
@Output() firstStepDone = new EventEmitter<string>()
|
|
|
|
@Output() firstStepError = new EventEmitter<void>()
|
|
|
|
|
|
|
|
isInUpdateForm = false
|
|
|
|
|
2020-09-25 08:04:21 +00:00
|
|
|
liveVideo: LiveVideo
|
2020-09-17 07:20:52 +00:00
|
|
|
videoId: number
|
|
|
|
videoUUID: string
|
|
|
|
error: string
|
|
|
|
|
|
|
|
protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
protected formValidatorService: FormValidatorService,
|
|
|
|
protected loadingBar: LoadingBarService,
|
|
|
|
protected notifier: Notifier,
|
|
|
|
protected authService: AuthService,
|
|
|
|
protected serverService: ServerService,
|
|
|
|
protected videoService: VideoService,
|
|
|
|
protected videoCaptionService: VideoCaptionService,
|
2020-09-25 08:04:21 +00:00
|
|
|
private liveVideoService: LiveVideoService,
|
2020-09-17 07:20:52 +00:00
|
|
|
private router: Router
|
|
|
|
) {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
super.ngOnInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
canDeactivate () {
|
|
|
|
return { canDeactivate: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
goLive () {
|
2021-01-19 10:49:50 +00:00
|
|
|
const name = 'Live'
|
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
const video: LiveVideoCreate = {
|
2021-01-19 10:49:50 +00:00
|
|
|
name,
|
2020-09-17 07:20:52 +00:00
|
|
|
privacy: VideoPrivacy.PRIVATE,
|
|
|
|
nsfw: this.serverConfig.instance.isNSFW,
|
|
|
|
waitTranscoding: true,
|
|
|
|
commentsEnabled: true,
|
|
|
|
downloadEnabled: true,
|
|
|
|
channelId: this.firstStepChannelId
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go live in private mode, but correctly fill the update form with the first user choice
|
|
|
|
const toPatch = Object.assign({}, video, { privacy: this.firstStepPrivacyId })
|
|
|
|
this.form.patchValue(toPatch)
|
|
|
|
|
2020-09-25 08:04:21 +00:00
|
|
|
this.liveVideoService.goLive(video).subscribe(
|
2020-09-17 07:20:52 +00:00
|
|
|
res => {
|
|
|
|
this.videoId = res.video.id
|
|
|
|
this.videoUUID = res.video.uuid
|
|
|
|
this.isInUpdateForm = true
|
|
|
|
|
2020-11-05 09:56:23 +00:00
|
|
|
this.firstStepDone.emit(name)
|
|
|
|
|
2020-09-17 07:20:52 +00:00
|
|
|
this.fetchVideoLive()
|
|
|
|
},
|
|
|
|
|
|
|
|
err => {
|
|
|
|
this.firstStepError.emit()
|
2020-10-28 14:24:40 +00:00
|
|
|
|
|
|
|
let message = err.message
|
|
|
|
|
|
|
|
if (err.body?.code === ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED) {
|
|
|
|
message = $localize`Cannot create live because this instance have too many created lives`
|
|
|
|
} else if (err.body?.code) {
|
|
|
|
message = $localize`Cannot create live because you created too many lives`
|
|
|
|
}
|
|
|
|
|
|
|
|
this.notifier.error(message)
|
2020-09-17 07:20:52 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSecondStep () {
|
|
|
|
if (this.checkForm() === false) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const video = new VideoEdit()
|
|
|
|
video.patch(this.form.value)
|
|
|
|
video.id = this.videoId
|
|
|
|
video.uuid = this.videoUUID
|
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
const liveVideoUpdate: LiveVideoUpdate = {
|
2020-12-03 13:10:54 +00:00
|
|
|
saveReplay: this.form.value.saveReplay,
|
|
|
|
permanentLive: this.form.value.permanentLive
|
2020-10-26 15:44:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 07:20:52 +00:00
|
|
|
// Update the video
|
2020-10-26 15:44:23 +00:00
|
|
|
forkJoin([
|
|
|
|
this.updateVideoAndCaptions(video),
|
2020-09-17 07:20:52 +00:00
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
this.liveVideoService.updateLive(this.videoId, liveVideoUpdate)
|
|
|
|
]).subscribe(
|
|
|
|
() => {
|
|
|
|
this.notifier.success($localize`Live published.`)
|
|
|
|
|
|
|
|
this.router.navigate(['/videos/watch', video.uuid])
|
|
|
|
},
|
2020-09-17 07:20:52 +00:00
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
err => {
|
|
|
|
this.error = err.message
|
|
|
|
scrollToTop()
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2020-09-17 07:20:52 +00:00
|
|
|
|
2020-10-26 15:44:23 +00:00
|
|
|
getMaxLiveDuration () {
|
|
|
|
return this.serverConfig.live.maxDuration / 1000
|
2020-09-17 07:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fetchVideoLive () {
|
2020-09-25 08:04:21 +00:00
|
|
|
this.liveVideoService.getVideoLive(this.videoId)
|
2020-09-17 07:20:52 +00:00
|
|
|
.subscribe(
|
2020-09-25 08:04:21 +00:00
|
|
|
liveVideo => {
|
|
|
|
this.liveVideo = liveVideo
|
2020-09-17 07:20:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
err => {
|
|
|
|
this.firstStepError.emit()
|
|
|
|
this.notifier.error(err.message)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|