]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-live.ts
Add live notification tests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-live.ts
index 6929b96886cd48270c4c1aee80a4d393e2b140e5..f3bff74ea93a24f2f025d0b8b9d9399fd790558b 100644 (file)
@@ -1,14 +1,21 @@
 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
 import { WEBSERVER } from '@server/initializers/constants'
 import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
-import { VideoLive } from '@shared/models/videos/video-live.model'
+import { LiveVideo, VideoState } from '@shared/models'
 import { VideoModel } from './video'
+import { VideoBlacklistModel } from './video-blacklist'
 
 @DefaultScope(() => ({
   include: [
     {
       model: VideoModel,
-      required: true
+      required: true,
+      include: [
+        {
+          model: VideoBlacklistModel,
+          required: false
+        }
+      ]
     }
   ]
 }))
@@ -23,10 +30,14 @@ import { VideoModel } from './video'
 })
 export class VideoLiveModel extends Model<VideoLiveModel> {
 
-  @AllowNull(false)
+  @AllowNull(true)
   @Column(DataType.STRING)
   streamKey: string
 
+  @AllowNull(false)
+  @Column
+  saveReplay: boolean
+
   @CreatedAt
   createdAt: Date
 
@@ -49,7 +60,22 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
     const query = {
       where: {
         streamKey
-      }
+      },
+      include: [
+        {
+          model: VideoModel.unscoped(),
+          required: true,
+          where: {
+            state: VideoState.WAITING_FOR_LIVE
+          },
+          include: [
+            {
+              model: VideoBlacklistModel.unscoped(),
+              required: false
+            }
+          ]
+        }
+      ]
     }
 
     return VideoLiveModel.findOne<MVideoLiveVideo>(query)
@@ -65,10 +91,15 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
     return VideoLiveModel.findOne<MVideoLive>(query)
   }
 
-  toFormattedJSON (): VideoLive {
+  toFormattedJSON (): LiveVideo {
     return {
-      rtmpUrl: WEBSERVER.RTMP_URL,
-      streamKey: this.streamKey
+      // 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,
+
+      streamKey: this.streamKey,
+      saveReplay: this.saveReplay
     }
   }
 }