From a5cf76afa378aae81af2a9b0ce548e5d2582f832 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 Sep 2020 10:04:21 +0200 Subject: Add watch messages if live has not started --- server/models/video/video-live.ts | 30 +++++++++++++++++++++---- server/models/video/video-streaming-playlist.ts | 11 +++++++++ server/models/video/video.ts | 8 +++++++ 3 files changed, 45 insertions(+), 4 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index 6929b9688..8608bc84c 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts @@ -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 + } + ] } ] })) @@ -49,7 +56,22 @@ export class VideoLiveModel extends Model { 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(query) @@ -65,7 +87,7 @@ export class VideoLiveModel extends Model { return VideoLiveModel.findOne(query) } - toFormattedJSON (): VideoLive { + toFormattedJSON (): LiveVideo { return { rtmpUrl: WEBSERVER.RTMP_URL, streamKey: this.streamKey diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index b8dc7c450..73bd89844 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -153,6 +153,17 @@ export class VideoStreamingPlaylistModel extends Model { return undefined } + @BeforeDestroy + static stopLiveIfNeeded (instance: VideoModel) { + if (!instance.isLive) return + + return LiveManager.Instance.stopSessionOf(instance.id) + } + @BeforeDestroy static invalidateCache (instance: VideoModel) { ModelCache.Instance.invalidateCache('video', instance.id) -- cgit v1.2.3