aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-09-17 09:20:52 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commitc6c0fa6cd8fe8f752463d8982c3dbcd448739c4e (patch)
tree79304b0152b0a38d33b26e65d4acdad0da4032a7 /client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
parent110d463fece85e87a26aca48a6048ae0017a27b3 (diff)
downloadPeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.tar.gz
PeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.tar.zst
PeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.zip
Live streaming implementation first step
Diffstat (limited to 'client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts')
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts129
1 files changed, 129 insertions, 0 deletions
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
new file mode 100644
index 000000000..64fd4c4d4
--- /dev/null
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
@@ -0,0 +1,129 @@
1
2import { Component, EventEmitter, OnInit, Output } from '@angular/core'
3import { Router } from '@angular/router'
4import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@app/core'
5import { scrollToTop } from '@app/helpers'
6import { FormValidatorService } from '@app/shared/shared-forms'
7import { VideoCaptionService, VideoEdit, VideoService, VideoLiveService } from '@app/shared/shared-main'
8import { LoadingBarService } from '@ngx-loading-bar/core'
9import { VideoCreate, VideoLive, VideoPrivacy } from '@shared/models'
10import { VideoSend } from './video-send'
11
12@Component({
13 selector: 'my-video-go-live',
14 templateUrl: './video-go-live.component.html',
15 styleUrls: [
16 '../shared/video-edit.component.scss',
17 './video-send.scss'
18 ]
19})
20export class VideoGoLiveComponent extends VideoSend implements OnInit, CanComponentDeactivate {
21 @Output() firstStepDone = new EventEmitter<string>()
22 @Output() firstStepError = new EventEmitter<void>()
23
24 isInUpdateForm = false
25
26 videoLive: VideoLive
27 videoId: number
28 videoUUID: string
29 error: string
30
31 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
32
33 constructor (
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
43 ) {
44 super()
45 }
46
47 ngOnInit () {
48 super.ngOnInit()
49 }
50
51 canDeactivate () {
52 return { canDeactivate: true }
53 }
54
55 goLive () {
56 const video: VideoCreate = {
57 name: 'Live',
58 privacy: VideoPrivacy.PRIVATE,
59 nsfw: this.serverConfig.instance.isNSFW,
60 waitTranscoding: true,
61 commentsEnabled: true,
62 downloadEnabled: true,
63 channelId: this.firstStepChannelId
64 }
65
66 this.firstStepDone.emit(name)
67
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)
71
72 this.videoLiveService.goLive(video).subscribe(
73 res => {
74 this.videoId = res.video.id
75 this.videoUUID = res.video.uuid
76 this.isInUpdateForm = true
77
78 this.fetchVideoLive()
79 },
80
81 err => {
82 this.firstStepError.emit()
83 this.notifier.error(err.message)
84 }
85 )
86 }
87
88 updateSecondStep () {
89 if (this.checkForm() === false) {
90 return
91 }
92
93 const video = new VideoEdit()
94 video.patch(this.form.value)
95 video.id = this.videoId
96 video.uuid = this.videoUUID
97
98 // Update the video
99 this.updateVideoAndCaptions(video)
100 .subscribe(
101 () => {
102 this.notifier.success($localize`Live published.`)
103
104 this.router.navigate([ '/videos/watch', video.uuid ])
105 },
106
107 err => {
108 this.error = err.message
109 scrollToTop()
110 console.error(err)
111 }
112 )
113
114 }
115
116 private fetchVideoLive () {
117 this.videoLiveService.getVideoLive(this.videoId)
118 .subscribe(
119 videoLive => {
120 this.videoLive = videoLive
121 },
122
123 err => {
124 this.firstStepError.emit()
125 this.notifier.error(err.message)
126 }
127 )
128 }
129}