1 import { Transaction } from 'sequelize'
14 } from 'sequelize-typescript'
15 import { CONFIG } from '@server/initializers/config'
16 import { WEBSERVER } from '@server/initializers/constants'
17 import { MVideoLive, MVideoLiveVideoWithSetting } from '@server/types/models'
18 import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models'
19 import { AttributesOnly } from '@shared/typescript-utils'
20 import { VideoModel } from './video'
21 import { VideoBlacklistModel } from './video-blacklist'
22 import { VideoLiveReplaySettingModel } from './video-live-replay-setting'
24 @DefaultScope(() => ({
31 model: VideoBlacklistModel,
37 model: VideoLiveReplaySettingModel,
43 tableName: 'videoLive',
46 fields: [ 'videoId' ],
50 fields: [ 'replaySettingId' ],
55 export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>>> {
58 @Column(DataType.STRING)
67 permanentLive: boolean
71 latencyMode: LiveVideoLatencyMode
79 @ForeignKey(() => VideoModel)
83 @BelongsTo(() => VideoModel, {
91 @ForeignKey(() => VideoLiveReplaySettingModel)
93 replaySettingId: number
95 @BelongsTo(() => VideoLiveReplaySettingModel, {
101 ReplaySetting: VideoLiveReplaySettingModel
104 static deleteReplaySetting (instance: VideoLiveModel, options: { transaction: Transaction }) {
105 return VideoLiveReplaySettingModel.destroy({
107 id: instance.replaySettingId
109 transaction: options.transaction
113 static loadByStreamKey (streamKey: string) {
120 model: VideoModel.unscoped(),
123 state: VideoState.WAITING_FOR_LIVE
127 model: VideoBlacklistModel.unscoped(),
133 model: VideoLiveReplaySettingModel.unscoped(),
139 return VideoLiveModel.findOne<MVideoLiveVideoWithSetting>(query)
142 static loadByVideoId (videoId: number) {
149 return VideoLiveModel.findOne<MVideoLive>(query)
152 toFormattedJSON (canSeePrivateInformation: boolean): LiveVideo {
153 let privateInformation: Pick<LiveVideo, 'rtmpUrl' | 'rtmpsUrl' | 'streamKey'> | {} = {}
155 // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
156 // We also display these private information only to the live owne/moderators
157 if (this.streamKey && canSeePrivateInformation === true) {
158 privateInformation = {
159 streamKey: this.streamKey,
161 rtmpUrl: CONFIG.LIVE.RTMP.ENABLED
162 ? WEBSERVER.RTMP_BASE_LIVE_URL
165 rtmpsUrl: CONFIG.LIVE.RTMPS.ENABLED
166 ? WEBSERVER.RTMPS_BASE_LIVE_URL
171 const replaySettings = this.replaySettingId
172 ? this.ReplaySetting.toFormattedJSON()
176 ...privateInformation,
178 permanentLive: this.permanentLive,
179 saveReplay: this.saveReplay,
181 latencyMode: this.latencyMode