From c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 17 Sep 2020 09:20:52 +0200 Subject: Live streaming implementation first step --- server/models/video/video-file.ts | 4 +- server/models/video/video-format-utils.ts | 2 + server/models/video/video-live.ts | 74 +++++++++++++++++++++++++ server/models/video/video-streaming-playlist.ts | 4 +- server/models/video/video.ts | 5 ++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 server/models/video/video-live.ts (limited to 'server/models') diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index f95022383..6a321917c 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -123,8 +123,8 @@ export class VideoFileModel extends Model { @Column extname: string - @AllowNull(false) - @Is('VideoFileInfohash', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash')) + @AllowNull(true) + @Is('VideoFileInfohash', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash', true)) @Column infoHash: string diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index ad512fc7f..0dbd92a43 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -77,6 +77,8 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor publishedAt: video.publishedAt, originallyPublishedAt: video.originallyPublishedAt, + isLive: video.isLive, + account: video.VideoChannel.Account.toFormattedSummaryJSON(), channel: video.VideoChannel.toFormattedSummaryJSON(), diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts new file mode 100644 index 000000000..6929b9688 --- /dev/null +++ b/server/models/video/video-live.ts @@ -0,0 +1,74 @@ +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { WEBSERVER } from '@server/initializers/constants' +import { MVideoLive, MVideoLiveVideo } from '@server/types/models' +import { VideoLive } from '@shared/models/videos/video-live.model' +import { VideoModel } from './video' + +@DefaultScope(() => ({ + include: [ + { + model: VideoModel, + required: true + } + ] +})) +@Table({ + tableName: 'videoLive', + indexes: [ + { + fields: [ 'videoId' ], + unique: true + } + ] +}) +export class VideoLiveModel extends Model { + + @AllowNull(false) + @Column(DataType.STRING) + streamKey: string + + @CreatedAt + createdAt: Date + + @UpdatedAt + updatedAt: Date + + @ForeignKey(() => VideoModel) + @Column + videoId: number + + @BelongsTo(() => VideoModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'cascade' + }) + Video: VideoModel + + static loadByStreamKey (streamKey: string) { + const query = { + where: { + streamKey + } + } + + return VideoLiveModel.findOne(query) + } + + static loadByVideoId (videoId: number) { + const query = { + where: { + videoId + } + } + + return VideoLiveModel.findOne(query) + } + + toFormattedJSON (): VideoLive { + return { + rtmpUrl: WEBSERVER.RTMP_URL, + streamKey: this.streamKey + } + } +} diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 021b9b063..b8dc7c450 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -173,7 +173,9 @@ export class VideoStreamingPlaylistModel extends Model { @Column remote: boolean + @AllowNull(false) + @Default(false) + @Column + isLive: boolean + @AllowNull(false) @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) -- cgit v1.2.3