Skip to content

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

Add configurable default for live replay save option (#7414)

Moby Mikes 💻150962ffcfec
diff --git a/client/src/app/+admin/config/pages/admin-config-live.component.html b/client/src/app/+admin/config/pages/admin-config-live.component.html
index 3645ad823d..3b60167cda 100644
--- a/client/src/app/+admin/config/pages/admin-config-live.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-live.component.html
@@ -63,6 +63,17 @@
</my-peertube-checkbox>
</div>
+ <div class="form-group" [ngClass]="getDisabledLiveClass()">
+ <my-peertube-checkbox
+ inputName="liveSaveReplay" [formControl]="defaultsLiveSaveReplayControl"
+ i18n-labelText labelText="Automatically publish a replay by default"
+ >
+ <ng-container ngProjectAs="description" i18n>
+ Default value for the "automatically publish a replay when your live ends" checkbox when creating a new live
+ </ng-container>
+ </my-peertube-checkbox>
+ </div>
+
<div class="form-group" formGroupName="latencySetting" [ngClass]="getDisabledLiveClass()">
<my-peertube-checkbox
inputName="liveLatencySettingEnabled" formControlName="enabled"
diff --git a/client/src/app/+admin/config/pages/admin-config-live.component.ts b/client/src/app/+admin/config/pages/admin-config-live.component.ts
index 129bcf2d71..ac12799a52 100644
--- a/client/src/app/+admin/config/pages/admin-config-live.component.ts
+++ b/client/src/app/+admin/config/pages/admin-config-live.component.ts
@@ -62,6 +62,12 @@ type Form = {
maxWindow: FormControl<number>
}>
}>
+
+ defaults: FormGroup<{
+ live: FormGroup<{
+ saveReplay: FormControl<boolean>
+ }>
+ }>
}
@Component({
@@ -163,6 +169,12 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
enabled: null,
maxWindow: MAX_DVR_WINDOW_MINUTES_VALIDATOR
}
+ },
+
+ defaults: {
+ live: {
+ saveReplay: null
+ }
}
}
@@ -191,6 +203,10 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
return this.server.getHTMLConfig().live.rtmp.port
}
+ get defaultsLiveSaveReplayControl () {
+ return this.form.controls.defaults.controls.live.controls.saveReplay
+ }
+
isLiveEnabled () {
return this.form.value.live.enabled === true
}
@@ -237,6 +253,8 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
save () {
const value = {
+ ...this.form.value,
+
live: {
...this.form.value.live,
@@ -268,6 +286,8 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
private buildFormValue (customConfig: CustomConfig): FormDefaultTyped<Form> {
return {
+ ...customConfig,
+
live: {
...customConfig.live,
diff --git a/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts b/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
index 3d68c7d2d2..0cd04b1965 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
@@ -94,7 +94,7 @@ export class VideoGoLiveComponent implements OnInit, AfterViewInit, CanComponent
permanentLive: this.firstStepPermanentLive,
latencyMode: LiveVideoLatencyMode.DEFAULT,
dvrWindow: serverConfig.live.dvr.maxWindow,
- saveReplay: this.isReplayAllowed(),
+ saveReplay: this.isReplayAllowed() && serverConfig.defaults.live.saveReplay,
replaySettings: { privacy: this.highestPrivacy() },
schedules: [],
user: this.authService.getUser()
diff --git a/config/default.yaml b/config/default.yaml
index 2764077180..e4a13f5721 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -1219,6 +1219,12 @@ defaults:
# No licence by default
licence: null
+ live:
+ # Default value for "automatically publish a replay when your live ends" checkbox
+ # when creating a new live video
+ # If live.allow_replay is false, this setting has no effect
+ save_replay: false
+
p2p:
# Enable P2P by default in PeerTube client
# Can be enabled/disabled by anonymous users and logged in users
diff --git a/config/production.yaml.example b/config/production.yaml.example
index d987285326..3152449f16 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -1229,6 +1229,12 @@ defaults:
# No licence by default
licence: null
+ live:
+ # Default value for "automatically publish a replay when your live ends" checkbox
+ # when creating a new live video
+ # If live.allow_replay is false, this setting has no effect
+ save_replay: false
+
p2p:
# Enable P2P by default in PeerTube client
# Can be enabled/disabled by anonymous users and logged in users
diff --git a/config/test.yaml b/config/test.yaml
index 925cb4dd7a..633ae97c09 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -177,3 +177,7 @@ video_transcription:
user:
password_constraints:
min_length: 6
+
+defaults:
+ live:
+ save_replay: false
diff --git a/packages/models/src/server/custom-config.model.ts b/packages/models/src/server/custom-config.model.ts
index e366770c8b..aa23d2947b 100644
--- a/packages/models/src/server/custom-config.model.ts
+++ b/packages/models/src/server/custom-config.model.ts
@@ -349,6 +349,10 @@ export interface CustomConfig {
licence: number
}
+ live: {
+ saveReplay: boolean
+ }
+
p2p: {
webapp: {
enabled: boolean
diff --git a/packages/models/src/server/server-config.model.ts b/packages/models/src/server/server-config.model.ts
index 871863008f..f3a4f92f63 100644
--- a/packages/models/src/server/server-config.model.ts
+++ b/packages/models/src/server/server-config.model.ts
@@ -99,6 +99,10 @@ export interface ServerConfig {
licence: number
}
+ live: {
+ saveReplay: boolean
+ }
+
p2p: {
webapp: {
enabled: boolean
diff --git a/packages/tests/src/api/server/config-defaults.ts b/packages/tests/src/api/server/config-defaults.ts
index c93173530b..fd39705458 100644
--- a/packages/tests/src/api/server/config-defaults.ts
+++ b/packages/tests/src/api/server/config-defaults.ts
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { expect } from 'chai'
import { VideoCommentPolicy, VideoDetails, VideoPrivacy } from '@peertube/peertube-models'
import {
cleanupTests,
@@ -10,6 +9,7 @@ import {
setDefaultVideoChannel
} from '@peertube/peertube-server-commands'
import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
+import { expect } from 'chai'
describe('Test config defaults', function () {
let server: PeerTubeServer
@@ -27,19 +27,21 @@ describe('Test config defaults', function () {
describe('Default publish values', function () {
before(async function () {
- const overrideConfig = {
- defaults: {
- publish: {
- comments_policy: 2,
- download_enabled: false,
- privacy: VideoPrivacy.INTERNAL,
- licence: 4
+ await server.config.updateExistingConfig({
+ newConfig: {
+ defaults: {
+ publish: {
+ commentsPolicy: 2,
+ downloadEnabled: false,
+ privacy: VideoPrivacy.INTERNAL,
+ licence: 4
+ },
+ live: {
+ saveReplay: true
+ }
}
}
- }
-
- await server.kill()
- await server.run(overrideConfig)
+ })
})
const attributes = {
@@ -110,12 +112,16 @@ describe('Test config defaults', function () {
const { id } = await server.live.create({
fields: {
...attributes,
+
channelId
}
})
const video = await server.videos.get({ id })
checkVideo(video)
+
+ const live = await server.live.get({ videoId: id })
+ expect(live.saveReplay).to.be.true
})
})
diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts
index 8a6d3d2c84..d99c82c921 100644
--- a/packages/tests/src/api/server/config.ts
+++ b/packages/tests/src/api/server/config.ts
@@ -154,6 +154,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
expect(data.defaults.publish.downloadEnabled).to.be.true
expect(data.defaults.publish.licence).to.be.null
expect(data.defaults.publish.privacy).to.equal(VideoPrivacy.PUBLIC)
+ expect(data.defaults.live.saveReplay).to.be.false
expect(data.defaults.p2p.embed.enabled).to.be.true
expect(data.defaults.p2p.webapp.enabled).to.be.true
expect(data.defaults.player.theme).to.equal('lucide')
@@ -453,6 +454,9 @@ function buildNewCustomConfig (server: PeerTubeServer): CustomConfig {
licence: 2,
privacy: VideoPrivacy.INTERNAL
},
+ live: {
+ saveReplay: true
+ },
p2p: {
embed: {
enabled: false
diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts
index f1f654a585..fdc1c8a4a3 100644
--- a/server/core/controllers/api/config.ts
+++ b/server/core/controllers/api/config.ts
@@ -586,6 +586,9 @@ function customConfig (): CustomConfig {
privacy: CONFIG.DEFAULTS.PUBLISH.PRIVACY,
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
},
+ live: {
+ saveReplay: CONFIG.DEFAULTS.LIVE.SAVE_REPLAY
+ },
p2p: {
webapp: {
enabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED
diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts
index d05ef19ba3..49fecd9c1c 100644
--- a/server/core/initializers/config.ts
+++ b/server/core/initializers/config.ts
@@ -213,6 +213,11 @@ const CONFIG = {
return config.get<number>('defaults.publish.licence')
}
},
+ LIVE: {
+ get SAVE_REPLAY () {
+ return config.get<boolean>('defaults.live.save_replay')
+ }
+ },
P2P: {
WEBAPP: {
get ENABLED () {
diff --git a/server/core/lib/local-video-creator.ts b/server/core/lib/local-video-creator.ts
index c367483965..be10776e26 100644
--- a/server/core/lib/local-video-creator.ts
+++ b/server/core/lib/local-video-creator.ts
@@ -206,7 +206,7 @@ export class LocalVideoCreator {
if (this.videoAttributes.isLive) {
const videoLive = new VideoLiveModel({
- saveReplay: this.liveAttributes.saveReplay || false,
+ saveReplay: this.liveAttributes.saveReplay || CONFIG.DEFAULTS.LIVE.SAVE_REPLAY,
permanentLive: this.liveAttributes.permanentLive || false,
latencyMode: this.liveAttributes.latencyMode || LiveVideoLatencyMode.DEFAULT,
dvrWindow: this.liveAttributes.dvrWindow ?? CONFIG.LIVE.DVR.MAX_WINDOW,
diff --git a/server/core/lib/server-config-manager.ts b/server/core/lib/server-config-manager.ts
index 5019920c0d..b95977123a 100644
--- a/server/core/lib/server-config-manager.ts
+++ b/server/core/lib/server-config-manager.ts
@@ -107,6 +107,9 @@ class ServerConfigManager {
privacy: CONFIG.DEFAULTS.PUBLISH.PRIVACY,
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
},
+ live: {
+ saveReplay: CONFIG.DEFAULTS.LIVE.SAVE_REPLAY
+ },
p2p: {
webapp: {
enabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED
diff --git a/server/core/middlewares/validators/config.ts b/server/core/middlewares/validators/config.ts
index 4ceddfb241..fbb05530ea 100644
--- a/server/core/middlewares/validators/config.ts
+++ b/server/core/middlewares/validators/config.ts
@@ -116,6 +116,7 @@ export const customConfigUpdateValidator = [
body('live.enabled').isBoolean(),
body('live.allowReplay').isBoolean(),
+ body('defaults.live.saveReplay').isBoolean(),
body('live.maxDuration').isInt(),
body('live.maxInstanceLives').custom(isIntOrNull),
body('live.maxUserLives').custom(isIntOrNull),