aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-09-25 10:04:21 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commita5cf76afa378aae81af2a9b0ce548e5d2582f832 (patch)
tree58da320232bee7c9656774c5d6811e82bbf6c696 /server/models/video
parentde6310b2fcbb8a6b79c546b23dfa1920724faaa7 (diff)
downloadPeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.tar.gz
PeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.tar.zst
PeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.zip
Add watch messages if live has not started
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-live.ts30
-rw-r--r--server/models/video/video-streaming-playlist.ts11
-rw-r--r--server/models/video/video.ts8
3 files changed, 45 insertions, 4 deletions
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 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { WEBSERVER } from '@server/initializers/constants' 2import { WEBSERVER } from '@server/initializers/constants'
3import { MVideoLive, MVideoLiveVideo } from '@server/types/models' 3import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
4import { VideoLive } from '@shared/models/videos/video-live.model' 4import { LiveVideo, VideoState } from '@shared/models'
5import { VideoModel } from './video' 5import { VideoModel } from './video'
6import { VideoBlacklistModel } from './video-blacklist'
6 7
7@DefaultScope(() => ({ 8@DefaultScope(() => ({
8 include: [ 9 include: [
9 { 10 {
10 model: VideoModel, 11 model: VideoModel,
11 required: true 12 required: true,
13 include: [
14 {
15 model: VideoBlacklistModel,
16 required: false
17 }
18 ]
12 } 19 }
13 ] 20 ]
14})) 21}))
@@ -49,7 +56,22 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
49 const query = { 56 const query = {
50 where: { 57 where: {
51 streamKey 58 streamKey
52 } 59 },
60 include: [
61 {
62 model: VideoModel.unscoped(),
63 required: true,
64 where: {
65 state: VideoState.WAITING_FOR_LIVE
66 },
67 include: [
68 {
69 model: VideoBlacklistModel.unscoped(),
70 required: false
71 }
72 ]
73 }
74 ]
53 } 75 }
54 76
55 return VideoLiveModel.findOne<MVideoLiveVideo>(query) 77 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
@@ -65,7 +87,7 @@ export class VideoLiveModel extends Model<VideoLiveModel> {
65 return VideoLiveModel.findOne<MVideoLive>(query) 87 return VideoLiveModel.findOne<MVideoLive>(query)
66 } 88 }
67 89
68 toFormattedJSON (): VideoLive { 90 toFormattedJSON (): LiveVideo {
69 return { 91 return {
70 rtmpUrl: WEBSERVER.RTMP_URL, 92 rtmpUrl: WEBSERVER.RTMP_URL,
71 streamKey: this.streamKey 93 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<VideoStreamingPlaylistMod
153 return VideoStreamingPlaylistModel.findByPk(id, options) 153 return VideoStreamingPlaylistModel.findByPk(id, options)
154 } 154 }
155 155
156 static loadHLSPlaylistByVideo (videoId: number) {
157 const options = {
158 where: {
159 type: VideoStreamingPlaylistType.HLS,
160 videoId
161 }
162 }
163
164 return VideoStreamingPlaylistModel.findOne(options)
165 }
166
156 static getHlsPlaylistFilename (resolution: number) { 167 static getHlsPlaylistFilename (resolution: number) {
157 return resolution + '.m3u8' 168 return resolution + '.m3u8'
158 } 169 }
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index a3e3b6cfe..8493ab802 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -127,6 +127,7 @@ import { VideoShareModel } from './video-share'
127import { VideoStreamingPlaylistModel } from './video-streaming-playlist' 127import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
128import { VideoTagModel } from './video-tag' 128import { VideoTagModel } from './video-tag'
129import { VideoViewModel } from './video-view' 129import { VideoViewModel } from './video-view'
130import { LiveManager } from '@server/lib/live-manager'
130 131
131export enum ScopeNames { 132export enum ScopeNames {
132 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', 133 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
@@ -800,6 +801,13 @@ export class VideoModel extends Model<VideoModel> {
800 } 801 }
801 802
802 @BeforeDestroy 803 @BeforeDestroy
804 static stopLiveIfNeeded (instance: VideoModel) {
805 if (!instance.isLive) return
806
807 return LiveManager.Instance.stopSessionOf(instance.id)
808 }
809
810 @BeforeDestroy
803 static invalidateCache (instance: VideoModel) { 811 static invalidateCache (instance: VideoModel) {
804 ModelCache.Instance.invalidateCache('video', instance.id) 812 ModelCache.Instance.invalidateCache('video', instance.id)
805 } 813 }