aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-live.ts')
-rw-r--r--server/models/video/video-live.ts74
1 files changed, 74 insertions, 0 deletions
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 @@
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 { VideoLive } from '@shared/models/videos/video-live.model'
5import { VideoModel } from './video'
6
7@DefaultScope(() => ({
8 include: [
9 {
10 model: VideoModel,
11 required: true
12 }
13 ]
14}))
15@Table({
16 tableName: 'videoLive',
17 indexes: [
18 {
19 fields: [ 'videoId' ],
20 unique: true
21 }
22 ]
23})
24export class VideoLiveModel extends Model<VideoLiveModel> {
25
26 @AllowNull(false)
27 @Column(DataType.STRING)
28 streamKey: string
29
30 @CreatedAt
31 createdAt: Date
32
33 @UpdatedAt
34 updatedAt: Date
35
36 @ForeignKey(() => VideoModel)
37 @Column
38 videoId: number
39
40 @BelongsTo(() => VideoModel, {
41 foreignKey: {
42 allowNull: false
43 },
44 onDelete: 'cascade'
45 })
46 Video: VideoModel
47
48 static loadByStreamKey (streamKey: string) {
49 const query = {
50 where: {
51 streamKey
52 }
53 }
54
55 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
56 }
57
58 static loadByVideoId (videoId: number) {
59 const query = {
60 where: {
61 videoId
62 }
63 }
64
65 return VideoLiveModel.findOne<MVideoLive>(query)
66 }
67
68 toFormattedJSON (): VideoLive {
69 return {
70 rtmpUrl: WEBSERVER.RTMP_URL,
71 streamKey: this.streamKey
72 }
73 }
74}