]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts
Fix wait transcoding checkbox display
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-go-live.component.ts
index 0a9efc693818acecd6ad1b808b3d51cbed220452..8780ca5678e641095fa4e5f6668fc59606877b79 100644 (file)
@@ -1,12 +1,14 @@
 
+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 { LiveVideoService, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
+import { VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
+import { LiveVideoService } from '@app/shared/shared-video-live'
 import { LoadingBarService } from '@ngx-loading-bar/core'
-import { LiveVideo, VideoCreate, VideoPrivacy } from '@shared/models'
+import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, ServerErrorCode, VideoPrivacy } from '@shared/models'
 import { VideoSend } from './video-send'
 
 @Component({
@@ -53,8 +55,10 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
   }
 
   goLive () {
-    const video: VideoCreate = {
-      name: 'Live',
+    const name = 'Live'
+
+    const video: LiveVideoCreate = {
+      name,
       privacy: VideoPrivacy.PRIVATE,
       nsfw: this.serverConfig.instance.isNSFW,
       waitTranscoding: true,
@@ -63,8 +67,6 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
       channelId: this.firstStepChannelId
     }
 
-    this.firstStepDone.emit(name)
-
     // 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)
@@ -75,12 +77,23 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
         this.videoUUID = res.video.uuid
         this.isInUpdateForm = true
 
+        this.firstStepDone.emit(name)
+
         this.fetchVideoLive()
       },
 
       err => {
         this.firstStepError.emit()
-        this.notifier.error(err.message)
+
+        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)
       }
     )
   }
@@ -95,22 +108,37 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, CanCompon
     video.id = this.videoId
     video.uuid = this.videoUUID
 
+    const liveVideoUpdate: LiveVideoUpdate = {
+      saveReplay: this.form.value.saveReplay,
+      permanentLive: this.form.value.permanentLive
+    }
+
     // 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.`)
 
-          err => {
-            this.error = err.message
-            scrollToTop()
-            console.error(err)
-          }
-        )
+        this.router.navigate(['/videos/watch', video.uuid])
+      },
+
+      err => {
+        this.error = err.message
+        scrollToTop()
+        console.error(err)
+      }
+    )
+  }
+
+  getMaxLiveDuration () {
+    return this.serverConfig.live.maxDuration / 1000
+  }
 
+  isWaitTranscodingEnabled () {
+    return this.form.value['saveReplay'] === true
   }
 
   private fetchVideoLive () {