1 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { CONFIG } from '@server/initializers/config'
3 import { WEBSERVER } from '@server/initializers/constants'
4 import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
5 import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models'
6 import { AttributesOnly } from '@shared/typescript-utils'
7 import { VideoModel } from './video'
8 import { VideoBlacklistModel } from './video-blacklist'
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
49 latencyMode: LiveVideoLatencyMode
57 @ForeignKey(() => VideoModel)
61 @BelongsTo(() => VideoModel, {
69 static loadByStreamKey (streamKey: string) {
76 model: VideoModel.unscoped(),
79 state: VideoState.WAITING_FOR_LIVE
83 model: VideoBlacklistModel.unscoped(),
91 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
94 static loadByVideoId (videoId: number) {
101 return VideoLiveModel.findOne<MVideoLive>(query)
104 toFormattedJSON (canSeePrivateInformation: boolean): LiveVideo {
105 let privateInformation: Pick<LiveVideo, 'rtmpUrl' | 'rtmpsUrl' | 'streamKey'> | {} = {}
107 // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
108 // We also display these private information only to the live owne/moderators
109 if (this.streamKey && canSeePrivateInformation === true) {
110 privateInformation = {
111 streamKey: this.streamKey,
113 rtmpUrl: CONFIG.LIVE.RTMP.ENABLED
117 rtmpsUrl: CONFIG.LIVE.RTMPS.ENABLED
118 ? WEBSERVER.RTMPS_URL
124 ...privateInformation,
126 permanentLive: this.permanentLive,
127 saveReplay: this.saveReplay,
128 latencyMode: this.latencyMode