]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/models/video/video-live.ts
Translated using Weblate (French)
[github/Chocobozzz/PeerTube.git] / server / models / video / video-live.ts
... / ...
CommitLineData
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { WEBSERVER } from '@server/initializers/constants'
3import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
4import { LiveVideo, VideoState } from '@shared/models'
5import { VideoModel } from './video'
6import { VideoBlacklistModel } from './video-blacklist'
7
8@DefaultScope(() => ({
9 include: [
10 {
11 model: VideoModel,
12 required: true,
13 include: [
14 {
15 model: VideoBlacklistModel,
16 required: false
17 }
18 ]
19 }
20 ]
21}))
22@Table({
23 tableName: 'videoLive',
24 indexes: [
25 {
26 fields: [ 'videoId' ],
27 unique: true
28 }
29 ]
30})
31export class VideoLiveModel extends Model {
32
33 @AllowNull(true)
34 @Column(DataType.STRING)
35 streamKey: string
36
37 @AllowNull(false)
38 @Column
39 saveReplay: boolean
40
41 @AllowNull(false)
42 @Column
43 permanentLive: boolean
44
45 @CreatedAt
46 createdAt: Date
47
48 @UpdatedAt
49 updatedAt: Date
50
51 @ForeignKey(() => VideoModel)
52 @Column
53 videoId: number
54
55 @BelongsTo(() => VideoModel, {
56 foreignKey: {
57 allowNull: false
58 },
59 onDelete: 'cascade'
60 })
61 Video: VideoModel
62
63 static loadByStreamKey (streamKey: string) {
64 const query = {
65 where: {
66 streamKey
67 },
68 include: [
69 {
70 model: VideoModel.unscoped(),
71 required: true,
72 where: {
73 state: VideoState.WAITING_FOR_LIVE
74 },
75 include: [
76 {
77 model: VideoBlacklistModel.unscoped(),
78 required: false
79 }
80 ]
81 }
82 ]
83 }
84
85 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
86 }
87
88 static loadByVideoId (videoId: number) {
89 const query = {
90 where: {
91 videoId
92 }
93 }
94
95 return VideoLiveModel.findOne<MVideoLive>(query)
96 }
97
98 toFormattedJSON (): LiveVideo {
99 return {
100 // If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
101 rtmpUrl: this.streamKey
102 ? WEBSERVER.RTMP_URL
103 : null,
104
105 streamKey: this.streamKey,
106 permanentLive: this.permanentLive,
107 saveReplay: this.saveReplay
108 }
109 }
110}