diff --git a/client/src/app/core/users/user-local-storage.service.ts b/client/src/app/core/users/user-local-storage.service.ts index 431a57343..43da94213 100644 --- a/client/src/app/core/users/user-local-storage.service.ts +++ b/client/src/app/core/users/user-local-storage.service.ts @@ -107,6 +107,7 @@ export class UserLocalStorageService { const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy const defaultP2PEnabled = htmlConfig.defaults.p2p.webapp.enabled + const defaultAutoPlay = htmlConfig.defaults.player.autoPlay return { nsfwPolicy: this.localStorageService.getItem(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy, @@ -114,7 +115,7 @@ export class UserLocalStorageService { theme: this.localStorageService.getItem(UserLocalStorageKeys.THEME) || 'instance-default', videoLanguages, - autoPlayVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO), true), + autoPlayVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO), defaultAutoPlay), autoPlayNextVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_NEXT_VIDEO), false), autoPlayNextVideoPlaylist: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST), true) } diff --git a/config/default.yaml b/config/default.yaml index c54c0e5d2..8d5f3ad7b 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -150,6 +150,10 @@ defaults: embed: enabled: true + player: + # By default, playback starts automatically when opening a video + auto_play: true + # From the project root directory storage: tmp: 'storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing... diff --git a/config/production.yaml.example b/config/production.yaml.example index 4275c8ff1..bcd7a6dc2 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -148,6 +148,10 @@ defaults: embed: enabled: true + player: + # By default, playback starts automatically when opening a video + auto_play: true + # From the project root directory storage: tmp: '/var/www/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing... diff --git a/packages/models/src/server/server-config.model.ts b/packages/models/src/server/server-config.model.ts index 379bc5e25..3060d711f 100644 --- a/packages/models/src/server/server-config.model.ts +++ b/packages/models/src/server/server-config.model.ts @@ -74,6 +74,10 @@ export interface ServerConfig { enabled: boolean } } + + player: { + autoPlay: boolean + } } webadmin: { diff --git a/packages/tests/src/api/server/config-defaults.ts b/packages/tests/src/api/server/config-defaults.ts index 42b517ba2..419a7a11f 100644 --- a/packages/tests/src/api/server/config-defaults.ts +++ b/packages/tests/src/api/server/config-defaults.ts @@ -212,7 +212,50 @@ describe('Test config defaults', function () { }) }) + describe('Default player value', function () { + + before(async function () { + const overrideConfig = { + defaults: { + player: { + auto_play: false + } + }, + signup: { + limit: 15 + } + } + + await server.kill() + await server.run(overrideConfig) + }) + + it('Should have appropriate autoplay config', async function () { + const config = await server.config.getConfig() + + expect(config.defaults.player.autoPlay).to.be.false + }) + + it('Should create a user with this default setting', async function () { + await server.users.create({ username: 'user_autoplay_1' }) + const userToken = await server.login.getAccessToken('user_autoplay_1') + + const { autoPlayVideo } = await server.users.getMyInfo({ token: userToken }) + expect(autoPlayVideo).to.be.false + }) + + it('Should register a user with this default setting', async function () { + await server.registrations.register({ username: 'user_autoplay_2' }) + + const userToken = await server.login.getAccessToken('user_autoplay_2') + + const { autoPlayVideo } = await server.users.getMyInfo({ token: userToken }) + expect(autoPlayVideo).to.be.false + }) + }) + describe('Default user attributes', function () { + it('Should create a user and register a user with the default config', async function () { await server.config.updateExistingConfig({ newConfig: { diff --git a/server/core/initializers/checker-before-init.ts b/server/core/initializers/checker-before-init.ts index 36cdb4ec1..bbc58aa11 100644 --- a/server/core/initializers/checker-before-init.ts +++ b/server/core/initializers/checker-before-init.ts @@ -50,6 +50,7 @@ function checkMissedConfig () { 'auto_blacklist.videos.of_users.enabled', 'trending.videos.interval_days', 'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth', 'defaults.publish.download_enabled', 'defaults.publish.comments_policy', 'defaults.publish.privacy', 'defaults.publish.licence', + 'defaults.player.auto_play', 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', 'instance.server_country', 'instance.support.text', 'instance.social.external_link', 'instance.social.mastodon_link', diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts index cf9b91c09..72fad9373 100644 --- a/server/core/initializers/config.ts +++ b/server/core/initializers/config.ts @@ -104,6 +104,9 @@ const CONFIG = { EMBED: { ENABLED: config.get('defaults.p2p.embed.enabled') } + }, + PLAYER: { + get AUTO_PLAY () { return config.get('defaults.player.auto_play') } } }, diff --git a/server/core/lib/server-config-manager.ts b/server/core/lib/server-config-manager.ts index 71f5f7351..5dd99b55a 100644 --- a/server/core/lib/server-config-manager.ts +++ b/server/core/lib/server-config-manager.ts @@ -87,6 +87,9 @@ class ServerConfigManager { embed: { enabled: CONFIG.DEFAULTS.P2P.EMBED.ENABLED } + }, + player: { + autoPlay: CONFIG.DEFAULTS.PLAYER.AUTO_PLAY } }, diff --git a/server/core/lib/user.ts b/server/core/lib/user.ts index 39ec281a6..2121302db 100644 --- a/server/core/lib/user.ts +++ b/server/core/lib/user.ts @@ -65,7 +65,7 @@ function buildUser (options: { p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, videosHistoryEnabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED, - autoPlayVideo: true, + autoPlayVideo: CONFIG.DEFAULTS.PLAYER.AUTO_PLAY, role, emailVerified,