]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-live.ts
Add ability to save replay of permanent lives
[github/Chocobozzz/PeerTube.git] / server / models / video / video-live.ts
index 875ba9b31a61c73279128c3eba3187ecaeaacb8c..96c0bf7f770d1ce40f262b03d31de12387afdbbe 100644 (file)
@@ -1,7 +1,9 @@
 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
+import { CONFIG } from '@server/initializers/config'
 import { WEBSERVER } from '@server/initializers/constants'
 import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
-import { LiveVideo, VideoState } from '@shared/models'
+import { LiveVideo, LiveVideoLatencyMode, VideoPrivacy, VideoState } from '@shared/models'
+import { AttributesOnly } from '@shared/typescript-utils'
 import { VideoModel } from './video'
 import { VideoBlacklistModel } from './video-blacklist'
 
@@ -28,7 +30,7 @@ import { VideoBlacklistModel } from './video-blacklist'
     }
   ]
 })
-export class VideoLiveModel extends Model<VideoLiveModel> {
+export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>>> {
 
   @AllowNull(true)
   @Column(DataType.STRING)
@@ -42,6 +44,10 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
   @Column
   permanentLive: boolean
 
+  @AllowNull(false)
+  @Column
+  latencyMode: LiveVideoLatencyMode
+
   @CreatedAt
   createdAt: Date
 
@@ -96,15 +102,23 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
   }
 
   toFormattedJSON (): LiveVideo {
+    let rtmpUrl: string = null
+    let rtmpsUrl: string = null
+
+    // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
+    if (this.streamKey) {
+      if (CONFIG.LIVE.RTMP.ENABLED) rtmpUrl = WEBSERVER.RTMP_URL
+      if (CONFIG.LIVE.RTMPS.ENABLED) rtmpsUrl = WEBSERVER.RTMPS_URL
+    }
+
     return {
-      // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
-      rtmpUrl: this.streamKey
-        ? WEBSERVER.RTMP_URL
-        : null,
+      rtmpUrl,
+      rtmpsUrl,
 
       streamKey: this.streamKey,
       permanentLive: this.permanentLive,
-      saveReplay: this.saveReplay
+      saveReplay: this.saveReplay,
+      latencyMode: this.latencyMode
     }
   }
 }