diff options
author | Wicklow <123956049+wickloww@users.noreply.github.com> | 2023-03-31 07:12:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 09:12:21 +0200 |
commit | 05a60d85997c108d39bcfb14f1ffd4c74f8b1e93 (patch) | |
tree | 5041a95ef945620a17f25ba934064b41f6bb00b7 /server/lib/live | |
parent | ebd61437c1ec92bea9772924c7051cb00d71f778 (diff) | |
download | PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.gz PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.zst PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.zip |
Feature/Add replay privacy (#5692)
* Add replay settings feature
* Fix replay settings behaviour
* Fix tests
* Fix tests
* Fix tests
* Update openapi doc and fix tests
* Add tests and fix code
* Models correction
* Add migration and update controller and middleware
* Add check params tests
* Fix video live middleware
* Updated code based on review comments
Diffstat (limited to 'server/lib/live')
-rw-r--r-- | server/lib/live/live-manager.ts | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 1d5b8bf14..05274955d 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -19,7 +19,7 @@ import { VideoModel } from '@server/models/video/video' | |||
19 | import { VideoLiveModel } from '@server/models/video/video-live' | 19 | import { VideoLiveModel } from '@server/models/video/video-live' |
20 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' | 20 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' |
21 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | 21 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' |
22 | import { MVideo, MVideoLiveSession, MVideoLiveVideo } from '@server/types/models' | 22 | import { MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models' |
23 | import { pick, wait } from '@shared/core-utils' | 23 | import { pick, wait } from '@shared/core-utils' |
24 | import { LiveVideoError, VideoState } from '@shared/models' | 24 | import { LiveVideoError, VideoState } from '@shared/models' |
25 | import { federateVideoIfNeeded } from '../activitypub/videos' | 25 | import { federateVideoIfNeeded } from '../activitypub/videos' |
@@ -30,6 +30,8 @@ import { Hooks } from '../plugins/hooks' | |||
30 | import { LiveQuotaStore } from './live-quota-store' | 30 | import { LiveQuotaStore } from './live-quota-store' |
31 | import { cleanupAndDestroyPermanentLive } from './live-utils' | 31 | import { cleanupAndDestroyPermanentLive } from './live-utils' |
32 | import { MuxingSession } from './shared' | 32 | import { MuxingSession } from './shared' |
33 | import { sequelizeTypescript } from '@server/initializers/database' | ||
34 | import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting' | ||
33 | 35 | ||
34 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') | 36 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') |
35 | const context = require('node-media-server/src/node_core_ctx') | 37 | const context = require('node-media-server/src/node_core_ctx') |
@@ -270,7 +272,7 @@ class LiveManager { | |||
270 | 272 | ||
271 | private async runMuxingSession (options: { | 273 | private async runMuxingSession (options: { |
272 | sessionId: string | 274 | sessionId: string |
273 | videoLive: MVideoLiveVideo | 275 | videoLive: MVideoLiveVideoWithSetting |
274 | 276 | ||
275 | inputUrl: string | 277 | inputUrl: string |
276 | fps: number | 278 | fps: number |
@@ -470,15 +472,26 @@ class LiveManager { | |||
470 | return resolutionsEnabled | 472 | return resolutionsEnabled |
471 | } | 473 | } |
472 | 474 | ||
473 | private saveStartingSession (videoLive: MVideoLiveVideo) { | 475 | private async saveStartingSession (videoLive: MVideoLiveVideoWithSetting) { |
474 | const liveSession = new VideoLiveSessionModel({ | 476 | const replaySettings = videoLive.saveReplay |
475 | startDate: new Date(), | 477 | ? new VideoLiveReplaySettingModel({ |
476 | liveVideoId: videoLive.videoId, | 478 | privacy: videoLive.ReplaySetting.privacy |
477 | saveReplay: videoLive.saveReplay, | 479 | }) |
478 | endingProcessed: false | 480 | : null |
479 | }) | ||
480 | 481 | ||
481 | return liveSession.save() | 482 | return sequelizeTypescript.transaction(async t => { |
483 | if (videoLive.saveReplay) { | ||
484 | await replaySettings.save({ transaction: t }) | ||
485 | } | ||
486 | |||
487 | return VideoLiveSessionModel.create({ | ||
488 | startDate: new Date(), | ||
489 | liveVideoId: videoLive.videoId, | ||
490 | saveReplay: videoLive.saveReplay, | ||
491 | replaySettingId: videoLive.saveReplay ? replaySettings.id : null, | ||
492 | endingProcessed: false | ||
493 | }, { transaction: t }) | ||
494 | }) | ||
482 | } | 495 | } |
483 | 496 | ||
484 | private async saveEndingSession (videoId: number, error: LiveVideoError | null) { | 497 | private async saveEndingSession (videoId: number, error: LiveVideoError | null) { |