From af4ae64f6faf38f8179f2e07d3cd4ad60006be92 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 2 Nov 2020 15:43:44 +0100 Subject: Begin live tests --- server/lib/activitypub/videos.ts | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'server/lib') 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 @@ +import { VideoLiveModel } from '@server/models/video/video-live' import * as Bluebird from 'bluebird' import { maxBy, minBy } from 'lodash' import * as magnetUtil from 'magnet-uri' @@ -84,7 +85,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid // Check this is not a blacklisted video, or unfederated blacklisted video (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) && // Check the video is public/unlisted and published - video.hasPrivacyForFederation() && video.state === VideoState.PUBLISHED + video.hasPrivacyForFederation() && (video.state === VideoState.PUBLISHED || video.state === VideoState.WAITING_FOR_LIVE) ) { // Fetch more attributes that we will need to serialize in AP object if (isArray(video.VideoCaptions) === false) { @@ -424,6 +425,27 @@ async function updateVideoFromAP (options: { await Promise.all(videoCaptionsPromises) } + { + // Create or update existing live + if (video.isLive) { + const [ videoLive ] = await VideoLiveModel.upsert({ + saveReplay: videoObject.liveSaveReplay, + videoId: video.id + }, { transaction: t, returning: true }) + + videoUpdated.VideoLive = videoLive + } else { // Delete existing live if it exists + await VideoLiveModel.destroy({ + where: { + videoId: video.id + }, + transaction: t + }) + + videoUpdated.VideoLive = null + } + } + return videoUpdated }) @@ -436,7 +458,7 @@ async function updateVideoFromAP (options: { }) if (wasPrivateVideo || wasUnlistedVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoUpdated) // Notify our users? - if (videoUpdated.isLive) PeerTubeSocket.Instance.sendVideoLiveNewState(video) + if (videoUpdated.isLive) PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated) logger.info('Remote video with uuid %s updated', videoObject.uuid) @@ -606,6 +628,16 @@ async function createVideo (videoObject: VideoObject, channel: MChannelAccountLi videoCreated.VideoFiles = videoFiles + if (videoCreated.isLive) { + const videoLive = new VideoLiveModel({ + streamKey: null, + saveReplay: videoObject.liveSaveReplay, + videoId: videoCreated.id + }) + + videoCreated.VideoLive = await videoLive.save({ transaction: t }) + } + const autoBlacklisted = await autoBlacklistVideoIfNeeded({ video: videoCreated, user: undefined, -- cgit v1.2.3