1 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { WEBSERVER } from '@server/initializers/constants'
3 import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
4 import { AttributesOnly } from '@shared/core-utils'
5 import { LiveVideo, VideoState } from '@shared/models'
6 import { VideoModel } from './video'
7 import { VideoBlacklistModel } from './video-blacklist'
8 import { CONFIG } from '@server/initializers/config'
10 @DefaultScope(() => ({
17 model: VideoBlacklistModel,
25 tableName: 'videoLive',
28 fields: [ 'videoId' ],
33 export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>>> {
36 @Column(DataType.STRING)
45 permanentLive: boolean
53 @ForeignKey(() => VideoModel)
57 @BelongsTo(() => VideoModel, {
65 static loadByStreamKey (streamKey: string) {
72 model: VideoModel.unscoped(),
75 state: VideoState.WAITING_FOR_LIVE
79 model: VideoBlacklistModel.unscoped(),
87 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
90 static loadByVideoId (videoId: number) {
97 return VideoLiveModel.findOne<MVideoLive>(query)
100 toFormattedJSON (): LiveVideo {
101 let rtmpUrl: string = null
102 let rtmpsUrl: string = null
104 // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
105 if (this.streamKey) {
106 if (CONFIG.LIVE.RTMP.ENABLED) rtmpUrl = WEBSERVER.RTMP_URL
107 if (CONFIG.LIVE.RTMPS.ENABLED) rtmpsUrl = WEBSERVER.RTMPS_URL
114 streamKey: this.streamKey,
115 permanentLive: this.permanentLive,
116 saveReplay: this.saveReplay