X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-live.ts;h=ca11186410158ef0fdd6a262f3dae893476252ed;hb=f89189907bbdff6c4bc6d3460ed9ef4c49515f17;hp=a1dd80d3c74bfe0d9cb6e5ce12f221ed2ad707e7;hpb=fb7194043d0486ce0a6a40b2ffbdf32878c33a6f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index a1dd80d3c..ca1118641 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts @@ -1,9 +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 { 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: [ @@ -16,6 +32,10 @@ import { VideoBlacklistModel } from './video-blacklist' required: false } ] + }, + { + model: VideoLiveReplaySettingModel, + required: false } ] })) @@ -25,10 +45,14 @@ import { VideoBlacklistModel } from './video-blacklist' { fields: [ 'videoId' ], unique: true + }, + { + fields: [ 'replaySettingId' ], + unique: true } ] }) -export class VideoLiveModel extends Model { +export class VideoLiveModel extends Model>> { @AllowNull(true) @Column(DataType.STRING) @@ -36,11 +60,15 @@ export class VideoLiveModel extends Model { @AllowNull(false) @Column - perpetualLive: boolean + saveReplay: boolean @AllowNull(false) @Column - saveReplay: boolean + permanentLive: boolean + + @AllowNull(false) + @Column + latencyMode: LiveVideoLatencyMode @CreatedAt createdAt: Date @@ -60,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: { @@ -78,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) { @@ -95,10 +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 { - rtmpUrl: WEBSERVER.RTMP_URL, - streamKey: this.streamKey + ...privateInformation, + + permanentLive: this.permanentLive, + saveReplay: this.saveReplay, + replaySettings, + latencyMode: this.latencyMode } } }