X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-live.ts;h=ca11186410158ef0fdd6a262f3dae893476252ed;hb=26818a73ba0d7fd53ca69eba0c8e525f3670b5a8;hp=014491d50011f532de056c2e79e022d1276ce33c;hpb=16c016e8b1d5ca46343d3363f9a49e24c5d7c944;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index 014491d50..ca1118641 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts @@ -1,10 +1,25 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { Transaction } from 'sequelize' +import { + AllowNull, + BeforeDestroy, + BelongsTo, + Column, + CreatedAt, + DataType, + DefaultScope, + ForeignKey, + Model, + Table, + UpdatedAt +} from 'sequelize-typescript' +import { CONFIG } from '@server/initializers/config' import { WEBSERVER } from '@server/initializers/constants' -import { MVideoLive, MVideoLiveVideo } from '@server/types/models' -import { AttributesOnly } from '@shared/core-utils' -import { LiveVideo, VideoState } from '@shared/models' +import { MVideoLive, MVideoLiveVideoWithSetting } from '@server/types/models' +import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models' +import { AttributesOnly } from '@shared/typescript-utils' import { VideoModel } from './video' import { VideoBlacklistModel } from './video-blacklist' +import { VideoLiveReplaySettingModel } from './video-live-replay-setting' @DefaultScope(() => ({ include: [ @@ -17,6 +32,10 @@ import { VideoBlacklistModel } from './video-blacklist' required: false } ] + }, + { + model: VideoLiveReplaySettingModel, + required: false } ] })) @@ -26,6 +45,10 @@ import { VideoBlacklistModel } from './video-blacklist' { fields: [ 'videoId' ], unique: true + }, + { + fields: [ 'replaySettingId' ], + unique: true } ] }) @@ -43,6 +66,10 @@ export class VideoLiveModel extends Model @Column permanentLive: boolean + @AllowNull(false) + @Column + latencyMode: LiveVideoLatencyMode + @CreatedAt createdAt: Date @@ -61,6 +88,28 @@ export class VideoLiveModel extends Model }) Video: VideoModel + @ForeignKey(() => VideoLiveReplaySettingModel) + @Column + replaySettingId: number + + @BelongsTo(() => VideoLiveReplaySettingModel, { + foreignKey: { + allowNull: true + }, + onDelete: 'set null' + }) + ReplaySetting: VideoLiveReplaySettingModel + + @BeforeDestroy + static deleteReplaySetting (instance: VideoLiveModel, options: { transaction: Transaction }) { + return VideoLiveReplaySettingModel.destroy({ + where: { + id: instance.replaySettingId + }, + transaction: options.transaction + }) + } + static loadByStreamKey (streamKey: string) { const query = { where: { @@ -79,11 +128,15 @@ export class VideoLiveModel extends Model required: false } ] + }, + { + model: VideoLiveReplaySettingModel.unscoped(), + required: false } ] } - return VideoLiveModel.findOne(query) + return VideoLiveModel.findOne(query) } static loadByVideoId (videoId: number) { @@ -96,16 +149,36 @@ export class VideoLiveModel extends Model return VideoLiveModel.findOne(query) } - toFormattedJSON (): LiveVideo { + toFormattedJSON (canSeePrivateInformation: boolean): LiveVideo { + let privateInformation: Pick | {} = {} + + // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL + // We also display these private information only to the live owne/moderators + if (this.streamKey && canSeePrivateInformation === true) { + privateInformation = { + streamKey: this.streamKey, + + rtmpUrl: CONFIG.LIVE.RTMP.ENABLED + ? WEBSERVER.RTMP_BASE_LIVE_URL + : null, + + rtmpsUrl: CONFIG.LIVE.RTMPS.ENABLED + ? WEBSERVER.RTMPS_BASE_LIVE_URL + : null + } + } + + const replaySettings = this.replaySettingId + ? this.ReplaySetting.toFormattedJSON() + : undefined + return { - // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL - rtmpUrl: this.streamKey - ? WEBSERVER.RTMP_URL - : null, + ...privateInformation, - streamKey: this.streamKey, permanentLive: this.permanentLive, - saveReplay: this.saveReplay + saveReplay: this.saveReplay, + replaySettings, + latencyMode: this.latencyMode } } }