diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-02 15:43:44 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | af4ae64f6faf38f8179f2e07d3cd4ad60006be92 (patch) | |
tree | a2d39ddc138d49619f03f11e003c2302f824286c /server/lib | |
parent | 77e9f859c6ad75ba179dec74e5410cc651eaa49b (diff) | |
download | PeerTube-af4ae64f6faf38f8179f2e07d3cd4ad60006be92.tar.gz PeerTube-af4ae64f6faf38f8179f2e07d3cd4ad60006be92.tar.zst PeerTube-af4ae64f6faf38f8179f2e07d3cd4ad60006be92.zip |
Begin live tests
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/videos.ts | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index ab23ff507..ea1e6a38f 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { VideoLiveModel } from '@server/models/video/video-live' | ||
1 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
2 | import { maxBy, minBy } from 'lodash' | 3 | import { maxBy, minBy } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 4 | import * as magnetUtil from 'magnet-uri' |
@@ -84,7 +85,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid | |||
84 | // Check this is not a blacklisted video, or unfederated blacklisted video | 85 | // Check this is not a blacklisted video, or unfederated blacklisted video |
85 | (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) && | 86 | (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) && |
86 | // Check the video is public/unlisted and published | 87 | // Check the video is public/unlisted and published |
87 | video.hasPrivacyForFederation() && video.state === VideoState.PUBLISHED | 88 | video.hasPrivacyForFederation() && (video.state === VideoState.PUBLISHED || video.state === VideoState.WAITING_FOR_LIVE) |
88 | ) { | 89 | ) { |
89 | // Fetch more attributes that we will need to serialize in AP object | 90 | // Fetch more attributes that we will need to serialize in AP object |
90 | if (isArray(video.VideoCaptions) === false) { | 91 | if (isArray(video.VideoCaptions) === false) { |
@@ -424,6 +425,27 @@ async function updateVideoFromAP (options: { | |||
424 | await Promise.all(videoCaptionsPromises) | 425 | await Promise.all(videoCaptionsPromises) |
425 | } | 426 | } |
426 | 427 | ||
428 | { | ||
429 | // Create or update existing live | ||
430 | if (video.isLive) { | ||
431 | const [ videoLive ] = await VideoLiveModel.upsert({ | ||
432 | saveReplay: videoObject.liveSaveReplay, | ||
433 | videoId: video.id | ||
434 | }, { transaction: t, returning: true }) | ||
435 | |||
436 | videoUpdated.VideoLive = videoLive | ||
437 | } else { // Delete existing live if it exists | ||
438 | await VideoLiveModel.destroy({ | ||
439 | where: { | ||
440 | videoId: video.id | ||
441 | }, | ||
442 | transaction: t | ||
443 | }) | ||
444 | |||
445 | videoUpdated.VideoLive = null | ||
446 | } | ||
447 | } | ||
448 | |||
427 | return videoUpdated | 449 | return videoUpdated |
428 | }) | 450 | }) |
429 | 451 | ||
@@ -436,7 +458,7 @@ async function updateVideoFromAP (options: { | |||
436 | }) | 458 | }) |
437 | 459 | ||
438 | if (wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoUpdated) // Notify our users? | 460 | if (wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoUpdated) // Notify our users? |
439 | if (videoUpdated.isLive) PeerTubeSocket.Instance.sendVideoLiveNewState(video) | 461 | if (videoUpdated.isLive) PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated) |
440 | 462 | ||
441 | logger.info('Remote video with uuid %s updated', videoObject.uuid) | 463 | logger.info('Remote video with uuid %s updated', videoObject.uuid) |
442 | 464 | ||
@@ -606,6 +628,16 @@ async function createVideo (videoObject: VideoObject, channel: MChannelAccountLi | |||
606 | 628 | ||
607 | videoCreated.VideoFiles = videoFiles | 629 | videoCreated.VideoFiles = videoFiles |
608 | 630 | ||
631 | if (videoCreated.isLive) { | ||
632 | const videoLive = new VideoLiveModel({ | ||
633 | streamKey: null, | ||
634 | saveReplay: videoObject.liveSaveReplay, | ||
635 | videoId: videoCreated.id | ||
636 | }) | ||
637 | |||
638 | videoCreated.VideoLive = await videoLive.save({ transaction: t }) | ||
639 | } | ||
640 | |||
609 | const autoBlacklisted = await autoBlacklistVideoIfNeeded({ | 641 | const autoBlacklisted = await autoBlacklistVideoIfNeeded({ |
610 | video: videoCreated, | 642 | video: videoCreated, |
611 | user: undefined, | 643 | user: undefined, |