]>
Commit | Line | Data |
---|---|---|
c6c0fa6c | 1 | |
b5b68755 | 2 | import { forkJoin } from 'rxjs' |
d4a8e7a6 | 3 | import { AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core' |
c6c0fa6c | 4 | import { Router } from '@angular/router' |
2e257e36 | 5 | import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core' |
c6c0fa6c C |
6 | import { scrollToTop } from '@app/helpers' |
7 | import { FormValidatorService } from '@app/shared/shared-forms' | |
d4a8e7a6 | 8 | import { Video, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' |
f8c00564 | 9 | import { LiveVideoService } from '@app/shared/shared-video-live' |
c6c0fa6c | 10 | import { LoadingBarService } from '@ngx-loading-bar/core' |
1378c0d3 | 11 | import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' |
c6c0fa6c C |
12 | import { VideoSend } from './video-send' |
13 | ||
14 | @Component({ | |
15 | selector: 'my-video-go-live', | |
16 | templateUrl: './video-go-live.component.html', | |
17 | styleUrls: [ | |
18 | '../shared/video-edit.component.scss', | |
19 | './video-send.scss' | |
20 | ] | |
21 | }) | |
2e257e36 | 22 | export class VideoGoLiveComponent extends VideoSend implements OnInit, AfterViewInit, CanComponentDeactivate { |
c6c0fa6c C |
23 | @Output() firstStepDone = new EventEmitter<string>() |
24 | @Output() firstStepError = new EventEmitter<void>() | |
25 | ||
26 | isInUpdateForm = false | |
27 | ||
a5cf76af | 28 | liveVideo: LiveVideo |
2e80d256 | 29 | |
c6c0fa6c C |
30 | videoId: number |
31 | videoUUID: string | |
2e80d256 C |
32 | videoShortUUID: string |
33 | ||
c6c0fa6c C |
34 | error: string |
35 | ||
c6c0fa6c C |
36 | constructor ( |
37 | protected formValidatorService: FormValidatorService, | |
38 | protected loadingBar: LoadingBarService, | |
39 | protected notifier: Notifier, | |
40 | protected authService: AuthService, | |
41 | protected serverService: ServerService, | |
42 | protected videoService: VideoService, | |
43 | protected videoCaptionService: VideoCaptionService, | |
a5cf76af | 44 | private liveVideoService: LiveVideoService, |
2e257e36 C |
45 | private router: Router, |
46 | private hooks: HooksService | |
9df52d66 | 47 | ) { |
c6c0fa6c C |
48 | super() |
49 | } | |
50 | ||
51 | ngOnInit () { | |
52 | super.ngOnInit() | |
53 | } | |
54 | ||
2e257e36 C |
55 | ngAfterViewInit () { |
56 | this.hooks.runAction('action:go-live.init', 'video-edit') | |
57 | } | |
58 | ||
c6c0fa6c C |
59 | canDeactivate () { |
60 | return { canDeactivate: true } | |
61 | } | |
62 | ||
63 | goLive () { | |
d487a997 C |
64 | const name = 'Live' |
65 | ||
b5b68755 | 66 | const video: LiveVideoCreate = { |
d487a997 | 67 | name, |
a3f45a2a | 68 | privacy: this.highestPrivacy, |
c6c0fa6c C |
69 | nsfw: this.serverConfig.instance.isNSFW, |
70 | waitTranscoding: true, | |
71 | commentsEnabled: true, | |
72 | downloadEnabled: true, | |
3eb7ee65 C |
73 | permanentLive: false, |
74 | saveReplay: false, | |
c6c0fa6c C |
75 | channelId: this.firstStepChannelId |
76 | } | |
77 | ||
c6c0fa6c C |
78 | // Go live in private mode, but correctly fill the update form with the first user choice |
79 | const toPatch = Object.assign({}, video, { privacy: this.firstStepPrivacyId }) | |
80 | this.form.patchValue(toPatch) | |
81 | ||
1378c0d3 C |
82 | this.liveVideoService.goLive(video) |
83 | .subscribe({ | |
84 | next: res => { | |
85 | this.videoId = res.video.id | |
86 | this.videoUUID = res.video.uuid | |
2e80d256 | 87 | this.videoShortUUID = res.video.shortUUID |
1378c0d3 | 88 | this.isInUpdateForm = true |
c6c0fa6c | 89 | |
1378c0d3 | 90 | this.firstStepDone.emit(name) |
f8c00564 | 91 | |
1378c0d3 C |
92 | this.fetchVideoLive() |
93 | }, | |
94 | ||
95 | error: err => { | |
96 | this.firstStepError.emit() | |
c6c0fa6c | 97 | |
1378c0d3 | 98 | let message = err.message |
a056ca48 | 99 | |
1378c0d3 | 100 | const error = err.body as PeerTubeProblemDocument |
a056ca48 | 101 | |
1378c0d3 C |
102 | if (error?.code === ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED) { |
103 | message = $localize`Cannot create live because this instance have too many created lives` | |
104 | } else if (error?.code === ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED) { | |
105 | message = $localize`Cannot create live because you created too many lives` | |
106 | } | |
e030bfb5 | 107 | |
1378c0d3 | 108 | this.notifier.error(message) |
a056ca48 | 109 | } |
1378c0d3 | 110 | }) |
c6c0fa6c C |
111 | } |
112 | ||
113 | updateSecondStep () { | |
114 | if (this.checkForm() === false) { | |
115 | return | |
116 | } | |
117 | ||
118 | const video = new VideoEdit() | |
119 | video.patch(this.form.value) | |
120 | video.id = this.videoId | |
121 | video.uuid = this.videoUUID | |
2e80d256 | 122 | video.shortUUID = this.videoShortUUID |
c6c0fa6c | 123 | |
b5b68755 | 124 | const liveVideoUpdate: LiveVideoUpdate = { |
bb4ba6d9 C |
125 | saveReplay: this.form.value.saveReplay, |
126 | permanentLive: this.form.value.permanentLive | |
b5b68755 C |
127 | } |
128 | ||
c6c0fa6c | 129 | // Update the video |
b5b68755 C |
130 | forkJoin([ |
131 | this.updateVideoAndCaptions(video), | |
c6c0fa6c | 132 | |
b5b68755 | 133 | this.liveVideoService.updateLive(this.videoId, liveVideoUpdate) |
1378c0d3 C |
134 | ]).subscribe({ |
135 | next: () => { | |
b5b68755 C |
136 | this.notifier.success($localize`Live published.`) |
137 | ||
d4a8e7a6 | 138 | this.router.navigateByUrl(Video.buildWatchUrl(video)) |
b5b68755 | 139 | }, |
c6c0fa6c | 140 | |
1378c0d3 | 141 | error: err => { |
b5b68755 C |
142 | this.error = err.message |
143 | scrollToTop() | |
144 | console.error(err) | |
145 | } | |
1378c0d3 | 146 | }) |
b5b68755 | 147 | } |
c6c0fa6c | 148 | |
b5b68755 C |
149 | getMaxLiveDuration () { |
150 | return this.serverConfig.live.maxDuration / 1000 | |
c6c0fa6c C |
151 | } |
152 | ||
ddb62a85 C |
153 | isWaitTranscodingEnabled () { |
154 | return this.form.value['saveReplay'] === true | |
155 | } | |
156 | ||
c6c0fa6c | 157 | private fetchVideoLive () { |
a5cf76af | 158 | this.liveVideoService.getVideoLive(this.videoId) |
1378c0d3 C |
159 | .subscribe({ |
160 | next: liveVideo => { | |
a5cf76af | 161 | this.liveVideo = liveVideo |
c6c0fa6c C |
162 | }, |
163 | ||
1378c0d3 | 164 | error: err => { |
c6c0fa6c C |
165 | this.firstStepError.emit() |
166 | this.notifier.error(err.message) | |
167 | } | |
1378c0d3 | 168 | }) |
c6c0fa6c C |
169 | } |
170 | } |