]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
Add ability to save live replay
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-go-live.component.ts
index 64fd4c4d4e145184c6e1317731ea045c04132dbc..9868c37d2bb12616400d89505862d11d58cd5b9c 100644 (file)
@@ -1,12 +1,13 @@
 
+import { forkJoin } from 'rxjs'
 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'
-import { VideoCaptionService, VideoEdit, VideoService, VideoLiveService } from '@app/shared/shared-main'
+import { LiveVideoService, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
-import { VideoCreate, VideoLive, VideoPrivacy } from '@shared/models'
+import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
 import { VideoSend } from './video-send'
 
 @Component({
@@ -23,7 +24,7 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
 
   isInUpdateForm = false
 
-  videoLive: VideoLive
+  liveVideo: LiveVideo
   videoId: number
   videoUUID: string
   error: string
@@ -38,7 +39,7 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
     protected serverService: ServerService,
     protected videoService: VideoService,
     protected videoCaptionService: VideoCaptionService,
-    private videoLiveService: VideoLiveService,
+    private liveVideoService: LiveVideoService,
     private router: Router
     ) {
     super()
@@ -53,7 +54,7 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
   }
 
   goLive () {
-    const video: VideoCreate = {
+    const video: LiveVideoCreate = {
       name: 'Live',
       privacy: VideoPrivacy.PRIVATE,
       nsfw: this.serverConfig.instance.isNSFW,
@@ -69,7 +70,7 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
     const toPatch = Object.assign({}, video, { privacy: this.firstStepPrivacyId })
     this.form.patchValue(toPatch)
 
-    this.videoLiveService.goLive(video).subscribe(
+    this.liveVideoService.goLive(video).subscribe(
       res => {
         this.videoId = res.video.id
         this.videoUUID = res.video.uuid
@@ -95,29 +96,39 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
     video.id = this.videoId
     video.uuid = this.videoUUID
 
+    const liveVideoUpdate: LiveVideoUpdate = {
+      saveReplay: this.form.value.saveReplay
+    }
+
     // Update the video
-    this.updateVideoAndCaptions(video)
-        .subscribe(
-          () => {
-            this.notifier.success($localize`Live published.`)
+    forkJoin([
+      this.updateVideoAndCaptions(video),
 
-            this.router.navigate([ '/videos/watch', video.uuid ])
-          },
+      this.liveVideoService.updateLive(this.videoId, liveVideoUpdate)
+    ]).subscribe(
+      () => {
+        this.notifier.success($localize`Live published.`)
+
+        this.router.navigate(['/videos/watch', video.uuid])
+      },
 
-          err => {
-            this.error = err.message
-            scrollToTop()
-            console.error(err)
-          }
-        )
+      err => {
+        this.error = err.message
+        scrollToTop()
+        console.error(err)
+      }
+    )
+  }
 
+  getMaxLiveDuration () {
+    return this.serverConfig.live.maxDuration / 1000
   }
 
   private fetchVideoLive () {
-    this.videoLiveService.getVideoLive(this.videoId)
+    this.liveVideoService.getVideoLive(this.videoId)
       .subscribe(
-        videoLive => {
-          this.videoLive = videoLive
+        liveVideo => {
+          this.liveVideo = liveVideo
         },
 
         err => {