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