13 } from 'sequelize-typescript'
14 import { CONFIG } from '@server/initializers/config'
15 import { WEBSERVER } from '@server/initializers/constants'
16 import { MVideoLive, MVideoLiveVideoWithSetting } from '@server/types/models'
17 import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models'
18 import { AttributesOnly } from '@shared/typescript-utils'
19 import { VideoModel } from './video'
20 import { VideoBlacklistModel } from './video-blacklist'
21 import { VideoLiveReplaySettingModel } from './video-live-replay-setting'
23 @DefaultScope(() => ({
30 model: VideoBlacklistModel,
36 model: VideoLiveReplaySettingModel,
42 tableName: 'videoLive',
45 fields: [ 'videoId' ],
49 fields: [ 'replaySettingId' ],
54 export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>>> {
57 @Column(DataType.STRING)
66 permanentLive: boolean
70 latencyMode: LiveVideoLatencyMode
78 @ForeignKey(() => VideoModel)
82 @BelongsTo(() => VideoModel, {
90 @ForeignKey(() => VideoLiveReplaySettingModel)
92 replaySettingId: number
94 @BelongsTo(() => VideoLiveReplaySettingModel, {
100 ReplaySetting: VideoLiveReplaySettingModel
103 static deleteReplaySetting (instance: VideoLiveModel) {
104 return VideoLiveReplaySettingModel.destroy({
106 id: instance.replaySettingId
111 static loadByStreamKey (streamKey: string) {
118 model: VideoModel.unscoped(),
121 state: VideoState.WAITING_FOR_LIVE
125 model: VideoBlacklistModel.unscoped(),
131 model: VideoLiveReplaySettingModel.unscoped(),
137 return VideoLiveModel.findOne<MVideoLiveVideoWithSetting>(query)
140 static loadByVideoId (videoId: number) {
147 return VideoLiveModel.findOne<MVideoLive>(query)
150 toFormattedJSON (canSeePrivateInformation: boolean): LiveVideo {
151 let privateInformation: Pick<LiveVideo, 'rtmpUrl' | 'rtmpsUrl' | 'streamKey'> | {} = {}
153 // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
154 // We also display these private information only to the live owne/moderators
155 if (this.streamKey && canSeePrivateInformation === true) {
156 privateInformation = {
157 streamKey: this.streamKey,
159 rtmpUrl: CONFIG.LIVE.RTMP.ENABLED
163 rtmpsUrl: CONFIG.LIVE.RTMPS.ENABLED
164 ? WEBSERVER.RTMPS_URL
169 const replaySettings = this.replaySettingId
170 ? this.ReplaySetting.toFormattedJSON()
174 ...privateInformation,
176 permanentLive: this.permanentLive,
177 saveReplay: this.saveReplay,
179 latencyMode: this.latencyMode