diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-17 09:20:52 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e (patch) | |
tree | 79304b0152b0a38d33b26e65d4acdad0da4032a7 /server/models/video/video-live.ts | |
parent | 110d463fece85e87a26aca48a6048ae0017a27b3 (diff) | |
download | PeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.tar.gz PeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.tar.zst PeerTube-c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e.zip |
Live streaming implementation first step
Diffstat (limited to 'server/models/video/video-live.ts')
-rw-r--r-- | server/models/video/video-live.ts | 74 |
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 @@ | |||
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' | ||
4 | import { VideoLive } from '@shared/models/videos/video-live.model' | ||
5 | import { 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 | }) | ||
24 | export 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 | } | ||