Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix invalid state change notif of remote live

Chocobozzz1e121c989820
diff --git a/packages/tests/src/api/live/live-socket-messages.ts b/packages/tests/src/api/live/live-socket-messages.ts
index 80bae154c5..dbf1f6a6f9 100644
--- a/packages/tests/src/api/live/live-socket-messages.ts
+++ b/packages/tests/src/api/live/live-socket-messages.ts
@@ -86,9 +86,13 @@ describe('Test live socket messages', function () {
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
+ // Ensure remote server doesn't send multiple times the state change event to viewers
+ await servers[0].videos.update({ id: liveVideoUUID, attributes: { name: 'my new live name' } })
+ await waitJobs(servers)
+
for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
- expect(stateChanges).to.have.length.at.least(1)
- expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED)
+ expect(stateChanges).to.have.lengthOf(1)
+ expect(stateChanges[0]).to.equal(VideoState.PUBLISHED)
}
await stopFfmpeg(ffmpegCommand)
diff --git a/server/core/lib/activitypub/videos/updater.ts b/server/core/lib/activitypub/videos/updater.ts
index f9c5b40402..d40ddab311 100644
--- a/server/core/lib/activitypub/videos/updater.ts
+++ b/server/core/lib/activitypub/videos/updater.ts
@@ -53,6 +53,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
this.checkChannelUpdateOrThrow(channelActor)
+ const oldState = this.video.state
const videoUpdated = await this.updateVideo(channelActor.VideoChannel, undefined, overrideTo)
if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel)
@@ -95,7 +96,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
Notifier.Instance.notifyOnNewVideoIfNeeded(videoUpdated)
}
- if (videoUpdated.isLive) {
+ if (videoUpdated.isLive && oldState !== videoUpdated.state) {
PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated)
}
diff --git a/server/core/lib/schedulers/update-videos-scheduler.ts b/server/core/lib/schedulers/update-videos-scheduler.ts
index 6e3dcdcb68..50ecb019cf 100644
--- a/server/core/lib/schedulers/update-videos-scheduler.ts
+++ b/server/core/lib/schedulers/update-videos-scheduler.ts
@@ -48,7 +48,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
private async updateAVideo (schedule: MScheduleVideoUpdate) {
let oldPrivacy: VideoPrivacyType
- let isNewVideo: boolean
+ let isNewVideoForFederation: boolean
let published = false
const video = await sequelizeTypescript.transaction(async t => {
@@ -58,7 +58,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
logger.info('Executing scheduled video update on %s.', video.uuid)
if (schedule.privacy) {
- isNewVideo = video.isNewVideoForFederation(schedule.privacy)
+ isNewVideoForFederation = video.isNewVideoForFederation(schedule.privacy)
oldPrivacy = video.privacy
setVideoPrivacy(video, schedule.privacy)
@@ -78,7 +78,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
return { video, published: false }
}
- await addVideoJobsAfterUpdate({ video, oldPrivacy, isNewVideo, nameChanged: false })
+ await addVideoJobsAfterUpdate({ video, oldPrivacy, isNewVideoForFederation, nameChanged: false })
return { video, published }
}