Skip to content

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

Live dvr (#7396)

djblu2003dk-tech4d54ea4587c3
diff --git a/client/src/app/+admin/config/pages/admin-config-advanced.component.html b/client/src/app/+admin/config/pages/admin-config-advanced.component.html
index 489e6e43ae..c10632abf6 100644
--- a/client/src/app/+admin/config/pages/admin-config-advanced.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-advanced.component.html
@@ -1,4 +1,4 @@
-<my-admin-save-bar i18n-title title="Advanced configuration" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar i18n-title title="Advanced configuration" (save)="save()" [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
diff --git a/client/src/app/+admin/config/pages/admin-config-customization.component.html b/client/src/app/+admin/config/pages/admin-config-customization.component.html
index 1eb4d46aaf..c3bf719511 100644
--- a/client/src/app/+admin/config/pages/admin-config-customization.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-customization.component.html
@@ -1,4 +1,4 @@
-<my-admin-save-bar i18n-title title="Platform customization" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar i18n-title title="Platform customization" (save)="save()" [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
<div class="pt-two-cols">
@@ -91,10 +91,10 @@
}
@if (field.type === 'color') {
- <my-peertube-color-picker
- [inputId]="field.inputId"
- [formControlName]="field.name"
- [formError]="formErrors.theme.customization[field.name]"
+ <my-peertube-color-picker
+ [inputId]="field.inputId"
+ [formControlName]="field.name"
+ [formError]="formErrors.theme.customization[field.name]"
/>
} @else if (field.type === 'radius') {
<my-select-custom-value
diff --git a/client/src/app/+admin/config/pages/admin-config-general.component.html b/client/src/app/+admin/config/pages/admin-config-general.component.html
index 1f5ea5ddae..711e85d77d 100644
--- a/client/src/app/+admin/config/pages/admin-config-general.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-general.component.html
@@ -1,4 +1,4 @@
-<my-admin-save-bar i18n-title title="General configuration" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar i18n-title title="General configuration" (save)="save()" [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
<div class="pt-two-cols">
diff --git a/client/src/app/+admin/config/pages/admin-config-homepage.component.html b/client/src/app/+admin/config/pages/admin-config-homepage.component.html
index 8d93d6e7df..efca7ea6f3 100644
--- a/client/src/app/+admin/config/pages/admin-config-homepage.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-homepage.component.html
@@ -1,4 +1,4 @@
-<my-admin-save-bar i18n-title title="Edit your homepage" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar i18n-title title="Edit your homepage" (save)="save()" [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"></my-admin-save-bar>
<form class="homepage pt-two-cols" [formGroup]="form" id="admin-config-form">
<div class="title-col">
diff --git a/client/src/app/+admin/config/pages/admin-config-information.component.html b/client/src/app/+admin/config/pages/admin-config-information.component.html
index 9876ae014a..e5d27ca1ea 100644
--- a/client/src/app/+admin/config/pages/admin-config-information.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-information.component.html
@@ -1,4 +1,7 @@
-<my-admin-save-bar i18n-title title="Platform information" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar
+ i18n-title title="Platform information" (save)="save()"
+ [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"
+></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
diff --git a/client/src/app/+admin/config/pages/admin-config-information.component.ts b/client/src/app/+admin/config/pages/admin-config-information.component.ts
index d92b75fd59..0528ac3d8a 100644
--- a/client/src/app/+admin/config/pages/admin-config-information.component.ts
+++ b/client/src/app/+admin/config/pages/admin-config-information.component.ts
@@ -20,7 +20,7 @@ import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.serv
import { SelectOptionsComponent } from '@app/shared/shared-forms/select/select-options.component'
import { SelectRadioComponent } from '@app/shared/shared-forms/select/select-radio.component'
import { getCompleteLocale, I18N_LOCALES } from '@peertube/peertube-core-utils'
-import { ActorImage, CustomConfig, NSFWPolicyType, ConstantLabel } from '@peertube/peertube-models'
+import { ActorImage, ConstantLabel, CustomConfig, NSFWPolicyType } from '@peertube/peertube-models'
import merge from 'lodash-es/merge'
import { Subscription } from 'rxjs'
import { SelectOptionsItem } from 'src/types/select-options-item.model'
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 d31a6757d6..3645ad823d 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
@@ -1,4 +1,8 @@
-<my-admin-save-bar i18n-title title="Live configuration" (save)="save()" [form]="form" [formErrors]="formErrors" [inconsistentOptions]="checkTranscodingConsistentOptions()"></my-admin-save-bar>
+<my-admin-save-bar
+ i18n-title title="Live configuration" (save)="save()"
+ [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"
+ [inconsistentOptions]="checkTranscodingConsistentOptions()"
+></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
@@ -36,6 +40,29 @@
</my-peertube-checkbox>
</div>
+ <div formGroupName="dvr" class="form-group" [ngClass]="getDisabledLiveClass()">
+ <my-peertube-checkbox
+ inputName="liveAllowDVR" formControlName="enabled"
+ i18n-labelText labelText="Allow your users to enable DVR (pause/rewind live)"
+ >
+
+ <ng-container ngProjectAs="extra">
+ <div class="form-group" [ngClass]="getDisabledLiveDVRClass()">
+ <label i18n for="liveDvrMaxWindow">Allow video streamers to set the DVR window up to</label>
+
+ <div class="number-with-unit">
+ <input type="number" id="liveDvrMaxWindow" formControlName="maxWindow" />
+ <span i18n>{form.value.live.dvr.maxWindow, plural, =1 {minute} other {minutes}}</span>
+ </div>
+
+ @if (formErrors.live.dvr.maxWindow) {
+ <div class="form-error" role="alert">{{ formErrors.live.dvr.maxWindow }}</div>
+ }
+ </div>
+ </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 086169cc7c..129bcf2d71 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
@@ -1,9 +1,10 @@
import { CommonModule } from '@angular/common'
-import { Component, OnInit, OnDestroy, inject } from '@angular/core'
+import { Component, OnDestroy, OnInit, inject } from '@angular/core'
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ActivatedRoute, RouterLink } from '@angular/router'
import { CanComponentDeactivate, ServerService } from '@app/core'
import {
+ MAX_DVR_WINDOW_MINUTES_VALIDATOR,
MAX_INSTANCE_LIVES_VALIDATOR,
MAX_LIVE_DURATION_VALIDATOR,
MAX_USER_LIVES_VALIDATOR,
@@ -18,14 +19,14 @@ import {
} from '@app/shared/form-validators/form-validator.model'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { CustomConfig } from '@peertube/peertube-models'
+import { Subscription } from 'rxjs'
import { SelectOptionsItem } from 'src/types/select-options-item.model'
+import { AdminConfigService, FormResolutions, ResolutionOption } from '../../../shared/shared-admin/admin-config.service'
import { PeertubeCheckboxComponent } from '../../../shared/shared-forms/peertube-checkbox.component'
import { SelectCustomValueComponent } from '../../../shared/shared-forms/select/select-custom-value.component'
import { SelectOptionsComponent } from '../../../shared/shared-forms/select/select-options.component'
import { PeerTubeTemplateDirective } from '../../../shared/shared-main/common/peertube-template.directive'
-import { AdminConfigService, FormResolutions, ResolutionOption } from '../../../shared/shared-admin/admin-config.service'
import { AdminSaveBarComponent } from '../shared/admin-save-bar.component'
-import { Subscription } from 'rxjs'
type Form = {
live: FormGroup<{
@@ -55,6 +56,11 @@ type Form = {
threads: FormControl<number>
profile: FormControl<string>
}>
+
+ dvr: FormGroup<{
+ enabled: FormControl<boolean>
+ maxWindow: FormControl<number>
+ }>
}>
}
@@ -118,7 +124,7 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
.subscribe(customConfig => {
this.customConfig = customConfig
- this.form.patchValue(this.customConfig)
+ this.form.patchValue(this.buildFormValue(this.customConfig))
})
}
@@ -151,11 +157,16 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
fps: {
max: TRANSCODING_MAX_FPS_VALIDATOR
}
+ },
+
+ dvr: {
+ enabled: null,
+ maxWindow: MAX_DVR_WINDOW_MINUTES_VALIDATOR
}
}
}
- const defaultValues: FormDefaultTyped<Form> = this.customConfig
+ const defaultValues: FormDefaultTyped<Form> = this.buildFormValue(this.customConfig)
const {
form,
@@ -184,6 +195,10 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
return this.form.value.live.enabled === true
}
+ isDvrEnabled () {
+ return this.form.value.live.dvr.enabled === true
+ }
+
isRemoteRunnerLiveEnabled () {
return this.form.value.live.transcoding.remoteRunners.enabled === true
}
@@ -192,6 +207,10 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
return { 'disabled-checkbox-extra': !this.isLiveEnabled() }
}
+ getDisabledLiveDVRClass () {
+ return { 'disabled-checkbox-extra': !this.isLiveEnabled() || !this.isDvrEnabled() }
+ }
+
getDisabledLiveTranscodingClass () {
return { 'disabled-checkbox-extra': !this.isLiveEnabled() || !this.isLiveTranscodingEnabled() }
}
@@ -217,10 +236,22 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
}
save () {
+ const value = {
+ live: {
+ ...this.form.value.live,
+
+ dvr: {
+ maxWindow: this.form.value.live.dvr.enabled && this.form.value.live.dvr.maxWindow
+ ? this.form.value.live.dvr.maxWindow * 60
+ : 0
+ }
+ }
+ }
+
this.adminConfigService.saveAndUpdateCurrent({
currentConfig: this.customConfig,
form: this.form,
- formConfig: this.form.value,
+ formConfig: value,
success: $localize`Live configuration updated.`
})
}
@@ -234,4 +265,17 @@ export class AdminConfigLiveComponent implements OnInit, OnDestroy, CanComponent
}
})
}
+
+ private buildFormValue (customConfig: CustomConfig): FormDefaultTyped<Form> {
+ return {
+ live: {
+ ...customConfig.live,
+
+ dvr: {
+ enabled: customConfig.live.dvr.maxWindow > 0,
+ maxWindow: Math.round(customConfig.live.dvr.maxWindow / 60)
+ }
+ }
+ }
+ }
}
diff --git a/client/src/app/+admin/config/pages/admin-config-logo.component.html b/client/src/app/+admin/config/pages/admin-config-logo.component.html
index 52a11d28f6..9c2dbe8a7e 100644
--- a/client/src/app/+admin/config/pages/admin-config-logo.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-logo.component.html
@@ -1,4 +1,4 @@
-<my-admin-save-bar i18n-title title="Upload logos" (save)="save()" [form]="form" [formErrors]="formErrors"></my-admin-save-bar>
+<my-admin-save-bar i18n-title title="Upload logos" (save)="save()" [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
<div class="pt-two-cols mt-4">
diff --git a/client/src/app/+admin/config/pages/admin-config-vod.component.html b/client/src/app/+admin/config/pages/admin-config-vod.component.html
index f6407c4ea9..db79d5990b 100644
--- a/client/src/app/+admin/config/pages/admin-config-vod.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-vod.component.html
@@ -1,4 +1,7 @@
-<my-admin-save-bar i18n-title title="VOD configuration" (save)="save()" [form]="form" [formErrors]="formErrors" [inconsistentOptions]="checkTranscodingConsistentOptions()"></my-admin-save-bar>
+<my-admin-save-bar
+ i18n-title title="VOD configuration" (save)="save()"
+ [form]="form" [formErrors]="formErrors" [validationMessages]="validationMessages"
+ [inconsistentOptions]="checkTranscodingConsistentOptions()"></my-admin-save-bar>
<form [formGroup]="form" id="admin-config-form">
diff --git a/client/src/app/+admin/config/shared/admin-save-bar.component.ts b/client/src/app/+admin/config/shared/admin-save-bar.component.ts
index bd2d075edf..3012136c9b 100644
--- a/client/src/app/+admin/config/shared/admin-save-bar.component.ts
+++ b/client/src/app/+admin/config/shared/admin-save-bar.component.ts
@@ -3,7 +3,7 @@ import { FormGroup } from '@angular/forms'
import { RouterModule } from '@angular/router'
import { ScreenService, ServerService } from '@app/core'
import { HeaderService } from '@app/header/header.service'
-import { FormReactiveErrors, FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
+import { FormReactiveErrors, FormReactiveMessages, FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { PeertubeModalService } from '@app/shared/shared-main/peertube-modal/peertube-modal.service'
import { ButtonComponent } from '../../../shared/shared-main/buttons/button.component'
import { AlertComponent } from '../../../shared/shared-main/common/alert.component'
@@ -28,6 +28,7 @@ export class AdminSaveBarComponent implements OnInit, OnDestroy {
readonly title = input.required<string>()
readonly form = input.required<FormGroup>()
readonly formErrors = input.required<FormReactiveErrors>()
+ readonly validationMessages = input.required<FormReactiveMessages>()
readonly inconsistentOptions = input<string>()
readonly save = output()
@@ -66,6 +67,8 @@ export class AdminSaveBarComponent implements OnInit, OnDestroy {
onSave (event: Event) {
this.displayFormErrors = false
+ this.formReactiveService.forceCheck(this.form(), this.formErrors(), this.validationMessages())
+
if (this.form().valid) {
this.save.emit()
return
diff --git a/client/src/app/+video-watch/video-watch.component.ts b/client/src/app/+video-watch/video-watch.component.ts
index fe1ad4d5fb..e39a21197c 100644
--- a/client/src/app/+video-watch/video-watch.component.ts
+++ b/client/src/app/+video-watch/video-watch.component.ts
@@ -838,7 +838,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
: undefined
const liveOptions = video.isLive
- ? { latencyMode: liveVideo.latencyMode }
+ ? { latencyMode: liveVideo.latencyMode, dvrEnabled: liveVideo.dvrWindow > 0 }
: undefined
return {
@@ -928,7 +928,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
webVideo: {
videoFiles: video.files
}
- }
+ } satisfies PeerTubePlayerLoadOptions
}
private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) {
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 d605fd5536..3d68c7d2d2 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
@@ -93,6 +93,7 @@ export class VideoGoLiveComponent implements OnInit, AfterViewInit, CanComponent
support: this.userChannels().find(c => c.id === this.firstStepChannelId).support ?? '',
permanentLive: this.firstStepPermanentLive,
latencyMode: LiveVideoLatencyMode.DEFAULT,
+ dvrWindow: serverConfig.live.dvr.maxWindow,
saveReplay: this.isReplayAllowed(),
replaySettings: { privacy: this.highestPrivacy() },
schedules: [],
diff --git a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
index 89a32965b1..8490812887 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
@@ -27,11 +27,11 @@ import {
VideoUpdate
} from '@peertube/peertube-models'
import { logger } from '@root-helpers/logger'
+import { splitAndGetNotEmpty } from '@root-helpers/string'
import debug from 'debug'
import { Jsonify, SharedUnionFieldsDeep } from 'type-fest'
import { VideoCaptionWithPathEdit } from './video-caption-edit.model'
import { VideoChaptersEdit } from './video-chapters-edit.model'
-import { splitAndGetNotEmpty } from '@root-helpers/string'
const debugLogger = debug('peertube:video-manage:video-edit')
@@ -52,9 +52,14 @@ type CommonUpdateForm =
nsfwFlagSex?: boolean
}
-type LiveUpdateForm = Omit<LiveVideoUpdate, 'replaySettings' | 'schedules'> & {
+type LiveUpdateForm = Omit<LiveVideoUpdate, 'replaySettings' | 'schedules' | 'dvrWindow'> & {
replayPrivacy?: VideoPrivacyType
+
+ dvrEnabled?: boolean
+ dvrWindowMinutes?: number
+
liveStreamKey?: string
+
schedules?: {
startAt?: Date
}[]
@@ -90,7 +95,12 @@ type CreateFromImportOptions = LoadFromPublishOptions & Pick<VideoImportCreate,
type CreateFromLiveOptions =
& CreateFromUploadOptions
- & Required<Pick<LiveVideoCreate, 'permanentLive' | 'latencyMode' | 'saveReplay' | 'replaySettings' | 'schedules'>>
+ & Required<
+ Pick<
+ LiveVideoCreate,
+ 'permanentLive' | 'latencyMode' | 'dvrWindow' | 'saveReplay' | 'replaySettings' | 'schedules'
+ >
+ >
type UpdateFromAPIOptions = {
video?: Pick<
@@ -278,6 +288,8 @@ export class VideoEdit {
latencyMode: options.latencyMode,
permanentLive: options.permanentLive,
+ dvrWindow: options.dvrWindow,
+
saveReplay: options.saveReplay,
replaySettings: options.replaySettings
@@ -478,6 +490,7 @@ export class VideoEdit {
return {
permanentLive: live.permanentLive,
latencyMode: live.latencyMode,
+ dvrWindow: live.dvrWindow,
saveReplay: live.saveReplay,
replaySettings: live.replaySettings
@@ -711,6 +724,14 @@ export class VideoEdit {
if (values.latencyMode !== undefined) this.live.latencyMode = values.latencyMode
if (values.saveReplay !== undefined) this.live.saveReplay = values.saveReplay
+ if (values.dvrWindowMinutes !== undefined) {
+ this.live.dvrWindow = this.dvrWindowMinutesToSeconds(values.dvrWindowMinutes)
+ }
+
+ if (values.dvrEnabled !== undefined && values.dvrEnabled === false) {
+ this.live.dvrWindow = 0
+ }
+
if (values.replayPrivacy !== undefined) {
this.live.replaySettings = values.replayPrivacy
? { privacy: values.replayPrivacy }
@@ -735,6 +756,10 @@ export class VideoEdit {
liveStreamKey: this.metadata.live.streamKey,
permanentLive: this.live.permanentLive,
latencyMode: this.live.latencyMode,
+
+ dvrEnabled: this.live.dvrWindow > 0,
+ dvrWindowMinutes: this.dvrWindowToMinutes(this.live.dvrWindow),
+
saveReplay: this.live.saveReplay,
replayPrivacy: this.live.replaySettings
@@ -755,7 +780,7 @@ export class VideoEdit {
? this.live.replaySettings
: undefined,
latencyMode: this.live.latencyMode,
-
+ dvrWindow: this.live.dvrWindow,
schedules: this.live.schedules
}
}
@@ -766,6 +791,7 @@ export class VideoEdit {
permanentLive: this.live.permanentLive,
latencyMode: this.live.latencyMode,
+ dvrWindow: this.live.dvrWindow,
saveReplay: this.live.saveReplay,
replaySettings: this.live.replaySettings,
schedules: this.live.schedules
@@ -1133,6 +1159,14 @@ export class VideoEdit {
}
}
+ private dvrWindowToMinutes (seconds: number) {
+ return Math.round(seconds / 60)
+ }
+
+ private dvrWindowMinutesToSeconds (minutes: number) {
+ return minutes * 60
+ }
+
// ---------------------------------------------------------------------------
areSameObjects<T, U> (a: Jsonify<T>, b: Jsonify<U>) {
diff --git a/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.html b/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.html
index dbfcb4e903..04345ecc54 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.html
+++ b/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.html
@@ -86,6 +86,37 @@
</div>
</div>
+ @if (isDvrEnabledByInstance()) {
+ <div class="form-group">
+ <my-peertube-checkbox inputName="liveVideoDvrEnabled" formControlName="dvrEnabled">
+ <ng-template ptTemplate="label">
+ <ng-container i18n>Enable DVR</ng-container>
+ </ng-template>
+
+ <ng-container ngProjectAs="description">
+ <span i18n>Allows viewers to pause, rewind, and jump back to live during the stream</span>
+ </ng-container>
+ </my-peertube-checkbox>
+ </div>
+
+ @if (form.value.dvrEnabled === true) {
+ <div class="form-group ms-4">
+ <label i18n for="liveDvrWindowMinutes">DVR window</label>
+ <div class="form-group-description" i18n>Maximum is {{ getMaxDvrWindowMinutes() }} minutes</div>
+
+ <div class="number-with-unit">
+ <input type="number" id="liveDvrWindowMinutes" formControlName="dvrWindowMinutes" class="pt-input-text" />
+ <span i18n>{form.value.dvrWindowMinutes, plural, =1 {minute} other {minutes}}</span>
+ </div>
+
+
+ @if (formErrors.dvrWindowMinutes) {
+ <div class="form-error" role="alert">{{ formErrors.dvrWindowMinutes }}</div>
+ }
+ </div>
+ }
+ }
+
@if (isSaveReplayAllowed()) {
<div class="form-group">
<my-peertube-checkbox inputName="liveVideoSaveReplay" formControlName="saveReplay">
diff --git a/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.ts b/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.ts
index 78cba54bae..30127bbd23 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/live-settings/video-live-settings.component.ts
@@ -1,21 +1,22 @@
import { CommonModule } from '@angular/common'
import { Component, OnDestroy, OnInit, inject } from '@angular/core'
-import { FormArray, FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'
+import { FormArray, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'
import { ServerService } from '@app/core'
import { BuildFormArgument } from '@app/shared/form-validators/form-validator.model'
-import { FormReactiveErrors, FormReactiveService, FormReactiveMessages } from '@app/shared/shared-forms/form-reactive.service'
+import { FormReactiveErrors, FormReactiveMessages, FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { VideoService } from '@app/shared/shared-main/video/video.service'
import {
+ ConstantLabel,
HTMLServerConfig,
LiveVideoLatencyMode,
LiveVideoLatencyModeType,
- ConstantLabel,
VideoPrivacy,
VideoPrivacyType,
VideoState
} from '@peertube/peertube-models'
import debug from 'debug'
+import { DatePickerModule } from 'primeng/datepicker'
import { Subscription } from 'rxjs'
import { SelectOptionsItem } from 'src/types/select-options-item.model'
import { InputTextComponent } from '../../../shared/shared-forms/input-text.component'
@@ -24,12 +25,11 @@ import { SelectOptionsComponent } from '../../../shared/shared-forms/select/sele
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { PeerTubeTemplateDirective } from '../../../shared/shared-main/common/peertube-template.directive'
import { TimeDurationFormatterPipe } from '../../../shared/shared-main/date/time-duration-formatter.pipe'
+import { I18nPrimengCalendarService } from '../common/i18n-primeng-calendar.service'
import { VideoEdit } from '../common/video-edit.model'
import { VideoManageController } from '../video-manage-controller.service'
import { LiveDocumentationLinkComponent } from './live-documentation-link.component'
import { LiveStreamInformationComponent } from './live-stream-information.component'
-import { I18nPrimengCalendarService } from '../common/i18n-primeng-calendar.service'
-import { DatePickerModule } from 'primeng/datepicker'
const debugLogger = debug('peertube:video-manage')
@@ -37,6 +37,10 @@ type Form = {
liveStreamKey: FormControl<string>
permanentLive: FormControl<boolean>
latencyMode: FormControl<LiveVideoLatencyModeType>
+
+ dvrEnabled: FormControl<boolean>
+ dvrWindowMinutes: FormControl<number>
+
saveReplay: FormControl<boolean>
replayPrivacy: FormControl<VideoPrivacyType>
@@ -141,6 +145,15 @@ export class VideoLiveSettingsComponent implements OnInit, OnDestroy {
liveStreamKey: null,
permanentLive: null,
latencyMode: null,
+ dvrEnabled: null,
+ dvrWindowMinutes: {
+ VALIDATORS: [], // Validators are set on-demand
+ MESSAGES: {
+ required: $localize`DVR window is required.`,
+ min: $localize`DVR window must be at least 1 minute.`,
+ max: $localize`DVR window exceeds the maximum.`
+ }
+ },
saveReplay: null,
replayPrivacy: null
}
@@ -178,6 +191,26 @@ export class VideoLiveSettingsComponent implements OnInit, OnDestroy {
this.updatedSub = this.manageController.getUpdatedObs().subscribe(() => {
this.form.patchValue(this.videoEdit.toLiveFormPatch())
})
+
+ this.form.controls.dvrEnabled.valueChanges.subscribe(dvrEnabled => {
+ const dvrWindowMinutes = this.form.controls.dvrWindowMinutes
+
+ if (dvrEnabled) {
+ dvrWindowMinutes.setValidators([
+ Validators.required,
+ Validators.min(1),
+ Validators.max(this.getMaxDvrWindowMinutes())
+ ])
+
+ if (!dvrWindowMinutes.value) {
+ dvrWindowMinutes.setValue(this.getMaxDvrWindowMinutes())
+ }
+ } else {
+ dvrWindowMinutes.clearValidators()
+ }
+
+ dvrWindowMinutes.updateValueAndValidity()
+ })
}
isSaveReplayAllowed () {
@@ -220,6 +253,14 @@ export class VideoLiveSettingsComponent implements OnInit, OnDestroy {
return this.serverConfig.live.maxDuration / 1000
}
+ getMaxDvrWindowMinutes () {
+ return Math.round(this.serverConfig.live.dvr.maxWindow / 60)
+ }
+
+ isDvrEnabledByInstance () {
+ return this.serverConfig.live.dvr.maxWindow > 0
+ }
+
getInstanceName () {
return this.serverConfig.instance.name
}
diff --git a/client/src/app/shared/form-validators/custom-config-validators.ts b/client/src/app/shared/form-validators/custom-config-validators.ts
index f1d277e893..51525a54f0 100644
--- a/client/src/app/shared/form-validators/custom-config-validators.ts
+++ b/client/src/app/shared/form-validators/custom-config-validators.ts
@@ -128,3 +128,10 @@ export const EXPORT_MAX_USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
min: $localize`Max user video video quota must be greater or equal to 1.`
}
}
+
+export const MAX_DVR_WINDOW_MINUTES_VALIDATOR: BuildFormValidator = {
+ VALIDATORS: [ Validators.min(1) ],
+ MESSAGES: {
+ min: $localize`DVR window must be greater or equal to 1 minute.`
+ }
+}
diff --git a/client/src/app/shared/shared-share-modal/video-share.component.ts b/client/src/app/shared/shared-share-modal/video-share.component.ts
index 91fdd34e22..684f40a39e 100644
--- a/client/src/app/shared/shared-share-modal/video-share.component.ts
+++ b/client/src/app/shared/shared-share-modal/video-share.component.ts
@@ -58,10 +58,12 @@ export class VideoShareComponent {
// Embed options
embedP2P: this.server.getHTMLConfig().defaults.p2p.embed.enabled,
+ embedPiP: true,
onlyEmbedUrl: false,
title: true,
warningTitle: true,
controlBar: true,
+ contextMenu: true,
peertubeLink: true,
responsive: false,
diff --git a/client/src/standalone/player/src/peertube-player.ts b/client/src/standalone/player/src/peertube-player.ts
index ab96f69493..0ea3209a0b 100644
--- a/client/src/standalone/player/src/peertube-player.ts
+++ b/client/src/standalone/player/src/peertube-player.ts
@@ -72,10 +72,6 @@ if (PlayProgressBar.prototype.options_.children.includes('timeTooltip') !== true
PlayProgressBar.prototype.options_.children.push('timeTooltip')
}
-// FIXME: https://github.com/videojs/video.js/pull/8988#issuecomment-3402464579
-const seekBar = videojs.getComponent('SeekBar') as any
-seekBar.prototype.pendingSeekTime = seekBar.prototype.getCurrentTime_
-
export { videojs }
export class PeerTubePlayer {
@@ -307,7 +303,10 @@ export class PeerTubePlayer {
})
if (this.options.enableHotkeys === true) {
- this.player.peerTubeHotkeysPlugin({ isLive: this.currentLoadOptions.isLive })
+ this.player.peerTubeHotkeysPlugin({
+ isLive: this.currentLoadOptions.isLive,
+ liveDvrEnabled: this.currentLoadOptions.liveOptions?.dvrEnabled === true
+ })
}
if (this.currentLoadOptions.playlist) {
@@ -421,7 +420,10 @@ export class PeerTubePlayer {
stopTime: () => this.currentLoadOptions.stopTime,
videoCaptions: () => this.currentLoadOptions.videoCaptions,
+
isLive: () => this.currentLoadOptions.isLive,
+ liveDvrEnabled: () => this.currentLoadOptions.liveOptions?.dvrEnabled === true,
+
videoUUID: () => this.currentLoadOptions.videoUUID,
subtitle: () => this.currentLoadOptions.subtitle,
diff --git a/client/src/standalone/player/src/sass/shared/control-bar.scss b/client/src/standalone/player/src/sass/shared/control-bar.scss
index dd0ab076aa..030ef845f5 100644
--- a/client/src/standalone/player/src/sass/shared/control-bar.scss
+++ b/client/src/standalone/player/src/sass/shared/control-bar.scss
@@ -312,6 +312,11 @@ $chapter-marker-size: 9px;
--peertube-link-max-width: 200px;
}
+// Override video.js style
+.vjs-peertube-skin.vjs-live.vjs-live-dvr .vjs-control-bar .vjs-progress-control {
+ display: flex;
+}
+
// ---------------------------------------------------------------------------
// PeerTube Galaxy (original) Theme
// ---------------------------------------------------------------------------
@@ -605,7 +610,7 @@ $chapter-marker-size: 9px;
}
}
- &.vjs-live {
+ &.vjs-live:not(.vjs-live-dvr) {
// Take the available space for the control bar
.vjs-progress-control {
display: flex;
@@ -664,7 +669,7 @@ $chapter-marker-size: 9px;
max-width: 100px;
}
- &.vjs-live {
+ &.vjs-live:not(.vjs-live-dvr) {
.vjs-duration {
display: none !important;
}
@@ -693,7 +698,7 @@ $chapter-marker-size: 9px;
@include margin-left(0);
}
- &.vjs-live {
+ &.vjs-live:not(.vjs-live-dvr) {
.vjs-current-time {
display: none !important;
}
diff --git a/client/src/standalone/player/src/sass/shared/peertube-skin.scss b/client/src/standalone/player/src/sass/shared/peertube-skin.scss
index 1ab0389c23..88a0ff0bdc 100644
--- a/client/src/standalone/player/src/sass/shared/peertube-skin.scss
+++ b/client/src/standalone/player/src/sass/shared/peertube-skin.scss
@@ -120,6 +120,12 @@ body {
}
}
+ &.vjs-audio-poster-mode {
+ .vjs-poster {
+ cursor: default;
+ }
+ }
+
// Theater mode is enabled
&.vjs-theater-enabled {
.vjs-theater-control {
diff --git a/client/src/standalone/player/src/shared/hotkeys/peertube-hotkeys-plugin.ts b/client/src/standalone/player/src/shared/hotkeys/peertube-hotkeys-plugin.ts
index 3d91efcb64..d15249edf4 100644
--- a/client/src/standalone/player/src/shared/hotkeys/peertube-hotkeys-plugin.ts
+++ b/client/src/standalone/player/src/shared/hotkeys/peertube-hotkeys-plugin.ts
@@ -7,6 +7,7 @@ const Plugin = videojs.getPlugin('plugin') as typeof VideojsPlugin
export type HotkeysOptions = {
isLive: boolean
+ liveDvrEnabled?: boolean
}
class PeerTubeHotkeysPlugin extends Plugin {
@@ -18,11 +19,13 @@ class PeerTubeHotkeysPlugin extends Plugin {
declare private readonly handlers: KeyHandler[]
declare private readonly isLive: boolean
+ declare private readonly liveDvrEnabled: boolean
constructor (player: VideojsPlayer, options: HotkeysOptions) {
super(player)
this.isLive = options.isLive
+ this.liveDvrEnabled = options.liveDvrEnabled === true
this.handlers = this.buildHandlers()
@@ -154,7 +157,7 @@ class PeerTubeHotkeysPlugin extends Plugin {
}
]
- if (this.isLive) return handlers
+ if (this.isLive && this.liveDvrEnabled !== true) return handlers
return handlers.concat(this.buildVODHandlers())
}
@@ -165,7 +168,7 @@ class PeerTubeHotkeysPlugin extends Plugin {
{
accept: e => this.isNaked(e, 'ArrowLeft') || this.isNaked(e, 'MediaRewind'),
cb: e => {
- if (this.isLive) return
+ if (!this.canSeek()) return
e.preventDefault()
@@ -178,7 +181,7 @@ class PeerTubeHotkeysPlugin extends Plugin {
{
accept: e => this.isNaked(e, 'ArrowRight') || this.isNaked(e, 'MediaForward'),
cb: e => {
- if (this.isLive) return
+ if (!this.canSeek()) return
e.preventDefault()
@@ -193,7 +196,7 @@ class PeerTubeHotkeysPlugin extends Plugin {
handlers.push({
accept: e => this.isNakedOrShift(e, i + ''),
cb: e => {
- if (this.isLive) return
+ if (!this.canSeek()) return
e.preventDefault()
@@ -252,6 +255,10 @@ class PeerTubeHotkeysPlugin extends Plugin {
return key.toUpperCase()
}
+
+ private canSeek () {
+ return this.isLive !== true || this.liveDvrEnabled === true
+ }
}
videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin)
diff --git a/client/src/standalone/player/src/shared/p2p-media-loader/hls-plugin.ts b/client/src/standalone/player/src/shared/p2p-media-loader/hls-plugin.ts
index c85a8d8676..1b398ee04d 100644
--- a/client/src/standalone/player/src/shared/p2p-media-loader/hls-plugin.ts
+++ b/client/src/standalone/player/src/shared/p2p-media-loader/hls-plugin.ts
@@ -122,7 +122,9 @@ export class Html5Hlsjs {
private _duration: number = null
private metadata: ManifestParsedData = null
+
private isLive: boolean = null
+ private liveDvrEnabled = false
private dvrDuration: number = null
private edgeMargin: number = null
@@ -189,17 +191,22 @@ export class Html5Hlsjs {
seekable () {
if (this.hls.media) {
if (!this.isLive) {
- return this.vjs.createTimeRanges(0, this.hls.media.duration)
+ return this.vjs.time.createTimeRanges(0, this.hls.media.duration)
}
+ // if (this.liveDvrEnabled && !isNaN(this.dvrDuration)) {
+ // const endTime = Math.max(0, Math.round(this.dvrDuration - this.edgeMargin))
+ // return this.vjs.time.createTimeRanges(0, endTime)
+ // }
+
// Video.js doesn't seem to like floating point timeranges
const startTime = Math.round(this.hls.media.duration - this.dvrDuration)
const endTime = Math.round(this.hls.media.duration - this.edgeMargin)
- return this.vjs.createTimeRanges(startTime, endTime)
+ return this.vjs.time.createTimeRanges(startTime, endTime)
}
- return this.vjs.createTimeRanges()
+ return this.vjs.time.createTimeRanges(0, undefined)
}
dispose () {
@@ -397,6 +404,8 @@ export class Html5Hlsjs {
this.buildBaseConfig()
+ this.liveDvrEnabled = this.hlsjsConfig?.liveDvrEnabled === true
+
if ([ '', 'auto' ].includes(this.videoElement.preload) && !this.videoElement.autoplay && this.hlsjsConfig.autoStartLoad === undefined) {
this.hlsjsConfig.autoStartLoad = false
}
@@ -436,7 +445,9 @@ export class Html5Hlsjs {
this.isLive = data.details.live
this.dvrDuration = data.details.totalduration
- this._duration = this.isLive ? Infinity : data.details.totalduration
+ this._duration = this.isLive
+ ? Infinity
+ : data.details.totalduration
// Increase network error recovery for lives since they can be broken (server restart, stream interruption etc)
if (this.isLive) this.maxNetworkErrorRecovery = 30
diff --git a/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts b/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
index 03bfe91bef..b563987d50 100644
--- a/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
+++ b/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
@@ -586,15 +586,22 @@ class PeerTubePlugin extends Plugin {
private updateControlBar () {
debugLogger('Updating control bar')
+ if (this.options.isLive() && this.options.liveDvrEnabled()) {
+ this.player.addClass('vjs-live-dvr')
+ } else {
+ this.player.removeClass('vjs-live-dvr')
+ }
+
if (this.options.isLive()) {
this.getPlaybackRateButton().hide()
-
- this.player.controlBar.getChild('progressControl').hide()
+ this.player.controlBar.getChild('peerTubeLiveDisplay').show()
this.player.controlBar.getChild('currentTimeDisplay').hide()
this.player.controlBar.getChild('timeDivider').hide()
this.player.controlBar.getChild('durationDisplay').hide()
- this.player.controlBar.getChild('peerTubeLiveDisplay').show()
+ if (!this.options.liveDvrEnabled()) {
+ this.player.controlBar.getChild('progressControl').hide()
+ }
} else {
this.getPlaybackRateButton().show()
diff --git a/client/src/standalone/player/src/shared/player-options-builder/hls-options-builder.ts b/client/src/standalone/player/src/shared/player-options-builder/hls-options-builder.ts
index d7ca4cc57f..28876e8029 100644
--- a/client/src/standalone/player/src/shared/player-options-builder/hls-options-builder.ts
+++ b/client/src/standalone/player/src/shared/player-options-builder/hls-options-builder.ts
@@ -254,22 +254,16 @@ export class HLSOptionsBuilder {
private getHLSLiveOptions () {
const latencyMode = this.options.liveOptions.latencyMode
+ const liveSyncDurationCountMap = {
+ [LiveVideoLatencyMode.SMALL_LATENCY]: 2,
+ [LiveVideoLatencyMode.DEFAULT]: 2,
+ [LiveVideoLatencyMode.HIGH_LATENCY]: 10
+ }
- switch (latencyMode) {
- case LiveVideoLatencyMode.SMALL_LATENCY:
- return {
- liveSyncDurationCount: 2
- }
-
- case LiveVideoLatencyMode.HIGH_LATENCY:
- return {
- liveSyncDurationCount: 10
- }
+ return {
+ liveDvrEnabled: this.options.liveOptions.dvrEnabled,
- default:
- return {
- liveSyncDurationCount: 5
- }
+ liveSyncDurationCount: liveSyncDurationCountMap[latencyMode] ?? liveSyncDurationCountMap[LiveVideoLatencyMode.DEFAULT]
}
}
diff --git a/client/src/standalone/player/src/types/peertube-player-options.ts b/client/src/standalone/player/src/types/peertube-player-options.ts
index c02168e50b..1299174238 100644
--- a/client/src/standalone/player/src/types/peertube-player-options.ts
+++ b/client/src/standalone/player/src/types/peertube-player-options.ts
@@ -70,6 +70,8 @@ export type PeerTubePlayerLoadOptions = {
liveOptions?: {
latencyMode: LiveVideoLatencyModeType
+
+ dvrEnabled: boolean
}
videoCaptions: VideoJSCaption[]
diff --git a/client/src/standalone/player/src/types/peertube-videojs-typings.ts b/client/src/standalone/player/src/types/peertube-videojs-typings.ts
index 02aa92ce3d..77ba064e4d 100644
--- a/client/src/standalone/player/src/types/peertube-videojs-typings.ts
+++ b/client/src/standalone/player/src/types/peertube-videojs-typings.ts
@@ -108,6 +108,7 @@ export type PeerTubePluginOptions = {
videoCaptions: () => VideoJSCaption[]
isLive: () => boolean
+ liveDvrEnabled: () => boolean
videoUUID: () => string
subtitle: () => string
@@ -197,7 +198,7 @@ export type HLSLoaderClass = {
getEngine(): HlsJsP2PEngine
}
-export type HLSPluginOptions = Partial<HlsConfig & { cueHandler: any, p2pMediaLoaderOptions: CoreConfig }>
+export type HLSPluginOptions = Partial<HlsConfig & { cueHandler: any, p2pMediaLoaderOptions: CoreConfig, liveDvrEnabled?: boolean }>
export type P2PMediaLoaderPluginOptions = {
redundancyUrlManager: RedundancyUrlManager | null
diff --git a/client/src/standalone/videos/shared/player-options-builder.ts b/client/src/standalone/videos/shared/player-options-builder.ts
index 8f7130e908..0b8abd9266 100644
--- a/client/src/standalone/videos/shared/player-options-builder.ts
+++ b/client/src/standalone/videos/shared/player-options-builder.ts
@@ -354,7 +354,8 @@ export class PlayerOptionsBuilder {
return {
isLive: true,
liveOptions: {
- latencyMode: live.latencyMode
+ latencyMode: live.latencyMode,
+ dvrEnabled: live.dvrWindow > 0
}
}
}
diff --git a/config/default.yaml b/config/default.yaml
index 0477bbf6df..2764077180 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -708,6 +708,10 @@ live:
# /!\ transcoding.enabled (and not live.transcoding.enabled) has to be true to create a replay
allow_replay: true
+ # Allows viewers to rewind live streams
+ dvr:
+ max_window: '1 hour' # Set 0 to disable DVR
+
# Allow your users to change latency settings (small latency/default/high latency)
# Small latency live streams cannot use P2P
# High latency live streams can increase P2P ratio
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 8f731763f9..d987285326 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -718,6 +718,10 @@ live:
# /!\ transcoding.enabled (and not live.transcoding.enabled) has to be true to create a replay
allow_replay: true
+ # Allows viewers to rewind live streams
+ dvr:
+ max_window: '1 hour' # Set 0 to disable DVR
+
# Allow your users to change latency settings (small latency/default/high latency)
# Small latency live streams cannot use P2P
# High latency live streams can increase P2P ratio
diff --git a/config/test.yaml b/config/test.yaml
index 5836255aed..925cb4dd7a 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -35,7 +35,7 @@ smtp:
from_address: '[email protected]'
username: null
password: null
-
+
log:
level: 'debug'
rotation:
diff --git a/packages/core-utils/src/common/url.ts b/packages/core-utils/src/common/url.ts
index a7e77cc6da..fe3fc2881b 100644
--- a/packages/core-utils/src/common/url.ts
+++ b/packages/core-utils/src/common/url.ts
@@ -101,7 +101,6 @@ function decorateVideoLink (options: {
peertubeLink?: boolean
p2p?: boolean
-
api?: boolean
version?: number
@@ -133,7 +132,6 @@ function decorateVideoLink (options: {
if (options.peertubeLink === false) params.set('peertubeLink', '0')
if (options.p2p !== undefined) params.set('p2p', options.p2p ? '1' : '0')
-
if (options.api !== undefined) params.set('api', options.api ? '1' : '0')
if (options.version !== undefined) params.set('v', options.version + '')
diff --git a/packages/models/src/activitypub/objects/video-object.ts b/packages/models/src/activitypub/objects/video-object.ts
index bcd3b33e27..70803b4f3f 100644
--- a/packages/models/src/activitypub/objects/video-object.ts
+++ b/packages/models/src/activitypub/objects/video-object.ts
@@ -31,6 +31,7 @@ export interface VideoObject {
liveSaveReplay: boolean
permanentLive: boolean
latencyMode: LiveVideoLatencyModeType
+ dvrWindow: string
commentsPolicy: VideoCommentPolicyType
canReply: 'as:Public' | 'https://www.w3.org/ns/activitystreams#Public'
diff --git a/packages/models/src/import-export/peertube-export-format/video-export.model.ts b/packages/models/src/import-export/peertube-export-format/video-export.model.ts
index 6f2fcd4027..55c854eb3e 100644
--- a/packages/models/src/import-export/peertube-export-format/video-export.model.ts
+++ b/packages/models/src/import-export/peertube-export-format/video-export.model.ts
@@ -38,6 +38,7 @@ export interface VideoExportJSON {
saveReplay: boolean
permanentLive: boolean
latencyMode: LiveVideoLatencyModeType
+ dvrWindow?: number
streamKey: string
replaySettings?: {
diff --git a/packages/models/src/server/custom-config.model.ts b/packages/models/src/server/custom-config.model.ts
index 975e0f1533..e366770c8b 100644
--- a/packages/models/src/server/custom-config.model.ts
+++ b/packages/models/src/server/custom-config.model.ts
@@ -213,6 +213,11 @@ export interface CustomConfig {
max: number
}
}
+
+ dvr: {
+ // In seconds, 0 means no DVR
+ maxWindow: number
+ }
}
videoStudio: {
diff --git a/packages/models/src/server/server-config.model.ts b/packages/models/src/server/server-config.model.ts
index c24d7520d4..871863008f 100644
--- a/packages/models/src/server/server-config.model.ts
+++ b/packages/models/src/server/server-config.model.ts
@@ -245,6 +245,12 @@ export interface ServerConfig {
enabled: boolean
allowReplay: boolean
+
+ dvr: {
+ // Seconds
+ maxWindow: number
+ }
+
latencySetting: {
enabled: boolean
}
diff --git a/packages/models/src/videos/live/live-video-create.model.ts b/packages/models/src/videos/live/live-video-create.model.ts
index ad9fee1c29..7b51d229b7 100644
--- a/packages/models/src/videos/live/live-video-create.model.ts
+++ b/packages/models/src/videos/live/live-video-create.model.ts
@@ -6,6 +6,7 @@ import { LiveVideoScheduleEdit } from './live-video-schedule.model.js'
export interface LiveVideoCreate extends VideoCreate {
permanentLive?: boolean
latencyMode?: LiveVideoLatencyModeType
+ dvrWindow?: number
saveReplay?: boolean
replaySettings?: { privacy: VideoPrivacyType }
diff --git a/packages/models/src/videos/live/live-video-update.model.ts b/packages/models/src/videos/live/live-video-update.model.ts
index 960b55283c..5e8b70a020 100644
--- a/packages/models/src/videos/live/live-video-update.model.ts
+++ b/packages/models/src/videos/live/live-video-update.model.ts
@@ -8,5 +8,7 @@ export interface LiveVideoUpdate {
replaySettings?: { privacy: VideoPrivacyType }
latencyMode?: LiveVideoLatencyModeType
+ dvrWindow?: number
+
schedules?: LiveVideoScheduleEdit[]
}
diff --git a/packages/models/src/videos/live/live-video.model.ts b/packages/models/src/videos/live/live-video.model.ts
index 68148e237c..49a1ba7abc 100644
--- a/packages/models/src/videos/live/live-video.model.ts
+++ b/packages/models/src/videos/live/live-video.model.ts
@@ -14,5 +14,8 @@ export interface LiveVideo {
permanentLive: boolean
latencyMode: LiveVideoLatencyModeType
+ // DVR is enabled if dvrWindowMs is > 0
+ dvrWindow: number
+
schedules: LiveVideoScheduleEdit[]
}
diff --git a/packages/server-commands/src/server/config-command.ts b/packages/server-commands/src/server/config-command.ts
index e0117b251e..3a0e344c25 100644
--- a/packages/server-commands/src/server/config-command.ts
+++ b/packages/server-commands/src/server/config-command.ts
@@ -230,8 +230,9 @@ export class ConfigCommand extends AbstractCommand {
transcoding?: boolean
maxDuration?: number
alwaysTranscodeOriginalResolution?: boolean
+ dvrMaxWindow?: number
} = {}) {
- const { allowReplay, transcoding, maxDuration, resolutions = 'min', alwaysTranscodeOriginalResolution } = options
+ const { allowReplay, transcoding, maxDuration, resolutions = 'min', alwaysTranscodeOriginalResolution, dvrMaxWindow } = options
return this.updateExistingConfig({
newConfig: {
@@ -247,6 +248,9 @@ export class ConfigCommand extends AbstractCommand {
resolutions: Array.isArray(resolutions)
? ConfigCommand.getCustomConfigResolutions(resolutions)
: ConfigCommand.getConfigResolutions(resolutions === 'max')
+ },
+ dvr: {
+ maxWindow: dvrMaxWindow
}
}
}
diff --git a/packages/tests/src/api/check-params/live.ts b/packages/tests/src/api/check-params/live.ts
index 38eee58ea0..2fff19e853 100644
--- a/packages/tests/src/api/check-params/live.ts
+++ b/packages/tests/src/api/check-params/live.ts
@@ -36,6 +36,7 @@ describe('Test video lives API validator', function () {
let video: VideoCreateResult
let videoIdNotLive: number
let command: LiveCommand
+ const dvrMaxWindow = 50
// ---------------------------------------------------------------
@@ -56,7 +57,10 @@ describe('Test video lives API validator', function () {
},
maxInstanceLives: 20,
maxUserLives: 20,
- allowReplay: true
+ allowReplay: true,
+ dvr: {
+ maxWindow: dvrMaxWindow
+ }
}
}
})
@@ -98,6 +102,7 @@ describe('Test video lives API validator', function () {
replaySettings: undefined,
permanentLive: true,
latencyMode: LiveVideoLatencyMode.DEFAULT,
+ dvrWindow: Math.max(1, Math.floor(dvrMaxWindow / 2)),
schedules: [
{
startAt: new Date(Date.now() + 1000 * 60 * 60) // 1 hour later
@@ -279,6 +284,60 @@ describe('Test video lives API validator', function () {
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
+ it('Should fail with a bad dvrWindow', async function () {
+ const toTests = [ -1, 0.5, dvrMaxWindow + 1 ]
+
+ for (const dvrWindow of toTests) {
+ const fields = { ...baseCorrectParams, dvrWindow }
+
+ await makePostBodyRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ fields,
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ }
+ })
+
+ it('Should fail with dvr window set but the server does not allow it', async function () {
+ await server.config.updateExistingConfig({
+ newConfig: {
+ live: {
+ dvr: {
+ maxWindow: 0
+ }
+ }
+ }
+ })
+
+ await makePostBodyRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ fields: { ...baseCorrectParams, dvrWindow: 1 },
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+
+ await makePostBodyRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ fields: { ...baseCorrectParams, dvrWindow: 0 },
+ expectedStatus: HttpStatusCode.OK_200
+ })
+
+ await server.config.updateExistingConfig({
+ newConfig: {
+ live: {
+ dvr: {
+ maxWindow: dvrMaxWindow
+ }
+ }
+ }
+ })
+ })
+
it('Should fail with an invalid schedules', async function () {
const toTests = [ 'toto', 42, [ 'toto' ], { toto: 'toto' }, { startAt: 'toto' } ]
@@ -528,6 +587,51 @@ describe('Test video lives API validator', function () {
await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
+ it('Should fail with bad dvrWindow', async function () {
+ const toTests = [ -1, 0.5, dvrMaxWindow + 1 ]
+
+ for (const dvrWindow of toTests) {
+ await command.update({
+ videoId: video.id,
+ fields: { dvrWindow },
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ }
+ })
+
+ it('Should fail with dvr window set but the server does not allow it', async function () {
+ await server.config.updateExistingConfig({
+ newConfig: {
+ live: {
+ dvr: {
+ maxWindow: 0
+ }
+ }
+ }
+ })
+
+ await command.update({
+ videoId: video.id,
+ fields: { dvrWindow: 1 },
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+
+ await command.update({
+ videoId: video.id,
+ fields: { dvrWindow: 0 }
+ })
+
+ await server.config.updateExistingConfig({
+ newConfig: {
+ live: {
+ dvr: {
+ maxWindow: dvrMaxWindow
+ }
+ }
+ }
+ })
+ })
+
it('Should fail with a bad privacy for replay settings', async function () {
const fields = { saveReplay: true, replaySettings: { privacy: 999 as any } }
diff --git a/packages/tests/src/api/live/live.ts b/packages/tests/src/api/live/live.ts
index 01d7926361..ca4455195c 100644
--- a/packages/tests/src/api/live/live.ts
+++ b/packages/tests/src/api/live/live.ts
@@ -60,6 +60,9 @@ describe('Test live', function () {
},
transcoding: {
enabled: false
+ },
+ dvr: {
+ maxWindow: 36
}
}
}
@@ -71,6 +74,53 @@ describe('Test live', function () {
commands = servers.map(s => s.live)
})
+ describe('Live DVR settings', function () {
+ let liveVideoUUID: string
+
+ it('Should create a live with custom DVR settings', async function () {
+ const live = await commands[0].create({
+ fields: {
+ name: 'live dvr settings',
+ channelId: servers[0].store.channel.id,
+ privacy: VideoPrivacy.PUBLIC,
+ permanentLive: true,
+ dvrWindow: 13
+ }
+ })
+ liveVideoUUID = live.uuid
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const live = await server.live.get({ videoId: liveVideoUUID })
+
+ expect(live.dvrWindow).to.equal(13)
+ }
+ })
+
+ it('Should update DVR settings on the live', async function () {
+ await commands[0].update({
+ videoId: liveVideoUUID,
+ fields: {
+ dvrWindow: 10
+ }
+ })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const live = await server.live.get({ videoId: liveVideoUUID })
+
+ expect(live.dvrWindow).to.equal(10)
+ }
+ })
+
+ it('Should delete the DVR test live', async function () {
+ await servers[0].videos.remove({ id: liveVideoUUID })
+ await waitJobs(servers)
+ })
+ })
+
describe('Live creation, update and delete', function () {
let liveVideoUUID: string
@@ -146,6 +196,7 @@ describe('Test live', function () {
expect(live.saveReplay).to.be.true
expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY)
+ expect(live.dvrWindow).to.equal(36)
}
})
diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts
index f5c626187b..8a6d3d2c84 100644
--- a/packages/tests/src/api/server/config.ts
+++ b/packages/tests/src/api/server/config.ts
@@ -114,6 +114,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
expect(data.live.transcoding.resolutions['2160p']).to.be.false
expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.true
expect(data.live.transcoding.fps.max).to.equal(60)
+ expect(data.live.dvr.maxWindow).to.equal(3600)
expect(data.videoStudio.enabled).to.be.false
expect(data.videoStudio.remoteRunners.enabled).to.be.false
@@ -339,6 +340,9 @@ function buildNewCustomConfig (server: PeerTubeServer): CustomConfig {
fps: {
max: 144
}
+ },
+ dvr: {
+ maxWindow: 0
}
},
videoStudio: {
diff --git a/packages/tests/src/api/users/user-export.ts b/packages/tests/src/api/users/user-export.ts
index 8083694864..4058420aa5 100644
--- a/packages/tests/src/api/users/user-export.ts
+++ b/packages/tests/src/api/users/user-export.ts
@@ -578,6 +578,7 @@ function runTest (withObjectStorage: boolean) {
expect(liveVideo.live.saveReplay).to.be.true
expect(liveVideo.live.permanentLive).to.be.true
expect(liveVideo.live.streamKey).to.exist
+ expect(liveVideo.live.dvrWindow).to.equal(15)
expect(liveVideo.live.replaySettings.privacy).to.equal(VideoPrivacy.PUBLIC)
expect(liveVideo.live.schedules).to.have.lengthOf(1)
expect(liveVideo.live.schedules[0].startAt).to.exist
diff --git a/packages/tests/src/api/users/user-import.ts b/packages/tests/src/api/users/user-import.ts
index ab558a1abe..014f39628a 100644
--- a/packages/tests/src/api/users/user-import.ts
+++ b/packages/tests/src/api/users/user-import.ts
@@ -515,6 +515,7 @@ function runTest (withObjectStorage: boolean) {
expect(video.isLive).to.be.true
expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY)
+ expect(live.dvrWindow).to.equal(15)
expect(live.saveReplay).to.be.true
expect(live.permanentLive).to.be.true
expect(live.streamKey).to.exist
diff --git a/packages/tests/src/api/videos/video-transcription.ts b/packages/tests/src/api/videos/video-transcription.ts
index 0364a65a8d..6dbf13595e 100644
--- a/packages/tests/src/api/videos/video-transcription.ts
+++ b/packages/tests/src/api/videos/video-transcription.ts
@@ -199,7 +199,7 @@ describe('Test video transcription', function () {
})
it('Should run transcription after a video edition', async function () {
- this.timeout(120000)
+ this.timeout(240000)
await servers[0].config.enableMinimumTranscoding()
await servers[0].config.enableStudio()
@@ -253,7 +253,7 @@ describe('Test video transcription', function () {
})
it('Should run transcription after a video replacement', async function () {
- this.timeout(120000)
+ this.timeout(240000)
await servers[0].config.enableFileUpdate()
@@ -271,7 +271,7 @@ describe('Test video transcription', function () {
})
it('Should not run transcription after video replacement if the subtitle has not been auto generated', async function () {
- this.timeout(120000)
+ this.timeout(240000)
const uuid = await uploadForTranscription(servers[0], { language: 'en' })
await waitJobs(servers)
diff --git a/packages/tests/src/shared/import-export.ts b/packages/tests/src/shared/import-export.ts
index 9f053226ef..82e007cd89 100644
--- a/packages/tests/src/shared/import-export.ts
+++ b/packages/tests/src/shared/import-export.ts
@@ -342,6 +342,7 @@ export async function prepareImportExportTests (options: {
channelId: noahSecondChannelId,
name: 'noah live video',
privacy: VideoPrivacy.PASSWORD_PROTECTED,
+ dvrWindow: 15,
schedules: [
{ startAt: new Date(Date.now() + 1000 * 60 * 60).toISOString() }
]
diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts
index e2c3605fc9..f1f654a585 100644
--- a/server/core/controllers/api/config.ts
+++ b/server/core/controllers/api/config.ts
@@ -472,6 +472,9 @@ function customConfig (): CustomConfig {
fps: {
max: CONFIG.LIVE.TRANSCODING.FPS.MAX
}
+ },
+ dvr: {
+ maxWindow: CONFIG.LIVE.DVR.MAX_WINDOW
}
},
videoStudio: {
diff --git a/server/core/controllers/api/videos/live.ts b/server/core/controllers/api/videos/live.ts
index ea3883ca71..f0a0162890 100644
--- a/server/core/controllers/api/videos/live.ts
+++ b/server/core/controllers/api/videos/live.ts
@@ -98,10 +98,11 @@ export {
async function getLiveVideo (req: express.Request, res: express.Response) {
const videoLive = res.locals.videoLive
+ const video = res.locals.videoWithRights
- const canSeePrivateLiveInformation = await checkCanManageVideo({
+ const canSeePrivateInformation = await checkCanManageVideo({
user: res.locals.oauth?.token.User,
- video: res.locals.videoWithRights,
+ video,
right: UserRight.GET_ANY_LIVE,
req,
res: null,
@@ -109,7 +110,7 @@ async function getLiveVideo (req: express.Request, res: express.Response) {
checkIsOwner: false
})
- return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation))
+ return res.json(videoLive.toFormattedJSON({ isLocal: video.isLocal(), canSeePrivateInformation }))
}
function getLiveReplaySession (req: express.Request, res: express.Response) {
@@ -145,6 +146,7 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive
if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode
+ if (exists(body.dvrWindow)) videoLive.dvrWindow = body.dvrWindow
if (body.schedules !== undefined) {
await VideoLiveScheduleModel.deleteAllOfLiveId(videoLive.id, t)
@@ -205,7 +207,14 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
fromDescription: false,
finalFallback: undefined
},
- liveAttributes: pick(videoInfo, [ 'saveReplay', 'permanentLive', 'latencyMode', 'replaySettings', 'schedules' ]),
+ liveAttributes: pick(videoInfo, [
+ 'saveReplay',
+ 'permanentLive',
+ 'latencyMode',
+ 'dvrWindow',
+ 'replaySettings',
+ 'schedules'
+ ]),
videoAttributeResultHook: 'filter:api.video.live.video-attribute.result',
lTags,
videoAttributes: {
diff --git a/server/core/helpers/activity-pub-utils.ts b/server/core/helpers/activity-pub-utils.ts
index 572ad78eaf..def0c6f198 100644
--- a/server/core/helpers/activity-pub-utils.ts
+++ b/server/core/helpers/activity-pub-utils.ts
@@ -97,6 +97,10 @@ const contextStore: { [id in ContextType]: (string | { [id: string]: string })[]
'@type': 'sc:Number',
'@id': 'pt:latencyMode'
},
+ dvrWindow: {
+ '@type': 'sc:Duration',
+ '@id': 'pt:dvrWindow'
+ },
Infohash: 'pt:Infohash',
diff --git a/server/core/helpers/custom-validators/activitypub/videos.ts b/server/core/helpers/custom-validators/activitypub/videos.ts
index 8c865a4e0f..a088409bfc 100644
--- a/server/core/helpers/custom-validators/activitypub/videos.ts
+++ b/server/core/helpers/custom-validators/activitypub/videos.ts
@@ -15,7 +15,7 @@ import validator from 'validator'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
import { peertubeTruncate } from '../../core-utils.js'
import { exists, isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc.js'
-import { isLiveLatencyModeValid } from '../video-lives.js'
+import { isLiveDvrWindowValid, isLiveLatencyModeValid } from '../video-lives.js'
import {
isVideoCommentsPolicyValid,
isVideoDescriptionValid,
@@ -26,6 +26,7 @@ import {
isVideoViewsValid
} from '../videos.js'
import { isActivityPubUrlValid, isActivityPubVideoDurationValid, isBaseActivityValid, setValidAttributedTo } from './misc.js'
+import { getDurationFromActivityStream } from '@server/lib/activitypub/activity.js'
export function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) {
return isBaseActivityValid(activity, 'Update') &&
@@ -71,7 +72,10 @@ export function sanitizeAndCheckVideoTorrentObject (video: VideoObject) {
if (!isVideoNameValid(video.name)) return fail('name')
if (!isActivityPubVideoDurationValid(video.duration)) return fail('duration format')
- if (!isVideoDurationValid(video.duration.replace(/[^0-9]+/g, ''))) return fail('duration')
+ if (!isVideoDurationValid('' + getDurationFromActivityStream(video.duration))) return fail('duration')
+
+ if (!isActivityPubVideoDurationValid(video.dvrWindow)) video.dvrWindow = 'PT0S'
+ if (!isLiveDvrWindowValid('' + getDurationFromActivityStream(video.dvrWindow), Infinity)) video.dvrWindow = 'PT0S'
if (!isUUIDValid(video.uuid)) return fail('uuid')
diff --git a/server/core/helpers/custom-validators/video-lives.ts b/server/core/helpers/custom-validators/video-lives.ts
index 8c5fde0e0e..4f9131d856 100644
--- a/server/core/helpers/custom-validators/video-lives.ts
+++ b/server/core/helpers/custom-validators/video-lives.ts
@@ -1,5 +1,6 @@
import { LiveVideoLatencyMode } from '@peertube/peertube-models'
-import { isDateValid } from './misc.js'
+import validator from 'validator'
+import { exists, isDateValid } from './misc.js'
export function isLiveLatencyModeValid (value: any) {
return [ LiveVideoLatencyMode.DEFAULT, LiveVideoLatencyMode.SMALL_LATENCY, LiveVideoLatencyMode.HIGH_LATENCY ].includes(value)
@@ -16,3 +17,7 @@ export function areLiveSchedulesValid (schedules: any[]) {
return schedules.every(schedule => isLiveScheduleValid(schedule))
}
+
+export function isLiveDvrWindowValid (value: unknown, maxDvrWindow: number) {
+ return exists(value) && validator.default.isInt('' + value, { min: 0, max: maxDvrWindow })
+}
diff --git a/server/core/initializers/checker-before-init.ts b/server/core/initializers/checker-before-init.ts
index edae92211e..54e338e106 100644
--- a/server/core/initializers/checker-before-init.ts
+++ b/server/core/initializers/checker-before-init.ts
@@ -259,6 +259,7 @@ export function checkMissedConfig () {
'live.transcoding.always_transcode_original_resolution',
'live.transcoding.fps.max',
'live.transcoding.remote_runners.enabled',
+ 'live.dvr.max_window',
'storyboards.enabled',
'webrtc.stun_servers',
'nsfw_flags_settings.enabled',
diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts
index 5c45a9f27c..d05ef19ba3 100644
--- a/server/core/initializers/config.ts
+++ b/server/core/initializers/config.ts
@@ -718,6 +718,15 @@ const CONFIG = {
return config.get<boolean>('live.allow_replay')
},
+ DVR: {
+ get MAX_WINDOW () { // In seconds
+ const value = config.get<string>('live.dvr.max_window')
+ if (typeof value === 'number') return value
+
+ return Math.round(parseDurationToMs(value) / 1000)
+ }
+ },
+
LATENCY_SETTING: {
get ENABLED () {
return config.get<boolean>('live.latency_setting.enabled')
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index c2a70bbad6..c6d13957b4 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -60,7 +60,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'
// ---------------------------------------------------------------------------
-export const LAST_MIGRATION_VERSION = 1005
+export const LAST_MIGRATION_VERSION = 1010
// ---------------------------------------------------------------------------
diff --git a/server/core/initializers/migrations/1010-live-dvr.ts b/server/core/initializers/migrations/1010-live-dvr.ts
new file mode 100644
index 0000000000..fafa58ba8e
--- /dev/null
+++ b/server/core/initializers/migrations/1010-live-dvr.ts
@@ -0,0 +1,32 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<void> {
+ const { transaction } = utils
+
+ {
+ await utils.queryInterface.addColumn('videoLive', 'dvrWindow', {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ defaultValue: 0
+ }, { transaction })
+
+ await utils.queryInterface.changeColumn('videoLive', 'dvrWindow', {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ defaultValue: null
+ }, { transaction })
+ }
+}
+
+function down () {
+ throw new Error('Not implemented.')
+}
+
+export {
+ down,
+ up
+}
diff --git a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts
index 992175d4a8..72937382a3 100644
--- a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts
+++ b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts
@@ -200,6 +200,7 @@ export function getLiveAttributesFromObject (video: MVideoId, videoObject: Video
saveReplay: videoObject.liveSaveReplay,
permanentLive: videoObject.permanentLive,
latencyMode: videoObject.latencyMode,
+ dvrWindow: getDurationFromActivityStream(videoObject.dvrWindow),
videoId: video.id
}
}
diff --git a/server/core/lib/auth/oauth-model.ts b/server/core/lib/auth/oauth-model.ts
index 1202d31616..bf411df3f1 100644
--- a/server/core/lib/auth/oauth-model.ts
+++ b/server/core/lib/auth/oauth-model.ts
@@ -185,8 +185,11 @@ async function revokeToken (
TokensCache.Instance.clearCacheByToken(token.accessToken)
- token.destroy()
- .catch(err => logger.error('Cannot destroy token when revoking token.', { err }))
+ try {
+ await token.destroy()
+ } catch (err) {
+ logger.error('Cannot destroy token when revoking token.', { err })
+ }
return { success: true, redirectUrl }
}
diff --git a/server/core/lib/live/live-utils.ts b/server/core/lib/live/live-utils.ts
index 4abde18204..86c2948114 100644
--- a/server/core/lib/live/live-utils.ts
+++ b/server/core/lib/live/live-utils.ts
@@ -1,6 +1,7 @@
import { wait } from '@peertube/peertube-core-utils'
import { FileStorage, LiveVideoLatencyMode, LiveVideoLatencyModeType, VideoState } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
+import { CONFIG } from '@server/initializers/config.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models/index.js'
import { pathExists, remove } from 'fs-extra/esm'
@@ -60,6 +61,22 @@ export function getLiveSegmentTime (latencyMode: LiveVideoLatencyModeType) {
return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY
}
+export function getLiveSegmentListSize (options: {
+ latencyMode: LiveVideoLatencyModeType
+ dvrWindow: number
+}) {
+ const { latencyMode, dvrWindow } = options
+
+ if (dvrWindow === 0) return VIDEO_LIVE.SEGMENTS_LIST_SIZE
+
+ const segmentDuration = getLiveSegmentTime(latencyMode)
+ const maxDvrWindow = CONFIG.LIVE.DVR.MAX_WINDOW
+
+ const sanitizedWindow = Math.min(dvrWindow, maxDvrWindow)
+
+ return Math.ceil(sanitizedWindow / segmentDuration)
+}
+
// ---------------------------------------------------------------------------
// Private
// ---------------------------------------------------------------------------
diff --git a/server/core/lib/live/shared/muxing-session.ts b/server/core/lib/live/shared/muxing-session.ts
index 5dea64b83b..c2e5798e45 100644
--- a/server/core/lib/live/shared/muxing-session.ts
+++ b/server/core/lib/live/shared/muxing-session.ts
@@ -33,7 +33,7 @@ import {
import { isUserQuotaValid } from '../../user.js'
import { LiveQuotaStore } from '../live-quota-store.js'
import { LiveSegmentShaStore } from '../live-segment-sha-store.js'
-import { buildConcatenatedName, getLiveSegmentTime } from '../live-utils.js'
+import { buildConcatenatedName, getLiveSegmentListSize, getLiveSegmentTime } from '../live-utils.js'
import { AbstractTranscodingWrapper, FFmpegTranscodingWrapper, RemoteTranscodingWrapper } from './transcoding-wrapper/index.js'
interface MuxingSessionEvents {
@@ -542,7 +542,10 @@ class MuxingSession extends EventEmitter implements MuxingSession {
hasVideo: this.hasVideo,
probe: this.probe,
- segmentListSize: VIDEO_LIVE.SEGMENTS_LIST_SIZE,
+ segmentListSize: getLiveSegmentListSize({
+ latencyMode: this.videoLive.latencyMode,
+ dvrWindow: this.videoLive.dvrWindow
+ }),
segmentDuration: getLiveSegmentTime(this.videoLive.latencyMode),
outDirectory: this.outDirectory
diff --git a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
index 0a5feb027a..b432153e2a 100644
--- a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
+++ b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
@@ -2,7 +2,6 @@ import { FFmpegLive } from '@peertube/peertube-ffmpeg'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/index.js'
import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
-import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles.js'
import { FfmpegCommand } from 'fluent-ffmpeg'
import { getLiveSegmentTime } from '../../live-utils.js'
@@ -43,7 +42,7 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
masterPlaylistName: this.streamingPlaylist.playlistFilename,
- segmentListSize: VIDEO_LIVE.SEGMENTS_LIST_SIZE,
+ segmentListSize: this.segmentListSize,
segmentDuration: getLiveSegmentTime(this.videoLive.latencyMode)
})
diff --git a/server/core/lib/local-video-creator.ts b/server/core/lib/local-video-creator.ts
index 89b41e4151..c367483965 100644
--- a/server/core/lib/local-video-creator.ts
+++ b/server/core/lib/local-video-creator.ts
@@ -49,9 +49,19 @@ type VideoAttributes = Omit<VideoCreate, 'channelId'> & {
embedPrivacyPolicy?: VideoEmbedPrivacyPolicyType
}
-type LiveAttributes = Pick<LiveVideoCreate, 'permanentLive' | 'latencyMode' | 'saveReplay' | 'replaySettings' | 'schedules'> & {
- streamKey?: string
-}
+type LiveAttributes =
+ & Pick<
+ LiveVideoCreate,
+ | 'permanentLive'
+ | 'latencyMode'
+ | 'dvrWindow'
+ | 'saveReplay'
+ | 'replaySettings'
+ | 'schedules'
+ >
+ & {
+ streamKey?: string
+ }
export type ThumbnailOption = {
path: string
@@ -199,6 +209,7 @@ export class LocalVideoCreator {
saveReplay: this.liveAttributes.saveReplay || false,
permanentLive: this.liveAttributes.permanentLive || false,
latencyMode: this.liveAttributes.latencyMode || LiveVideoLatencyMode.DEFAULT,
+ dvrWindow: this.liveAttributes.dvrWindow ?? CONFIG.LIVE.DVR.MAX_WINDOW,
streamKey: this.liveAttributes.streamKey || buildUUID()
})
diff --git a/server/core/lib/server-config-manager.ts b/server/core/lib/server-config-manager.ts
index 583cacbf27..5019920c0d 100644
--- a/server/core/lib/server-config-manager.ts
+++ b/server/core/lib/server-config-manager.ts
@@ -223,6 +223,9 @@ class ServerConfigManager {
enabled: CONFIG.LIVE.ENABLED,
allowReplay: CONFIG.LIVE.ALLOW_REPLAY,
+ dvr: {
+ maxWindow: CONFIG.LIVE.DVR.MAX_WINDOW
+ },
latencySetting: {
enabled: CONFIG.LIVE.LATENCY_SETTING.ENABLED
},
diff --git a/server/core/lib/user-import-export/exporters/videos-exporter.ts b/server/core/lib/user-import-export/exporters/videos-exporter.ts
index 02d387e5b1..6347ceeef5 100644
--- a/server/core/lib/user-import-export/exporters/videos-exporter.ts
+++ b/server/core/lib/user-import-export/exporters/videos-exporter.ts
@@ -221,6 +221,7 @@ export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {
saveReplay: live.saveReplay,
permanentLive: live.permanentLive,
latencyMode: live.latencyMode,
+ dvrWindow: live.dvrWindow,
streamKey: live.streamKey,
replaySettings: live.ReplaySetting
diff --git a/server/core/lib/user-import-export/importers/videos-importer.ts b/server/core/lib/user-import-export/importers/videos-importer.ts
index 28ad570a97..a522b23c9c 100644
--- a/server/core/lib/user-import-export/importers/videos-importer.ts
+++ b/server/core/lib/user-import-export/importers/videos-importer.ts
@@ -8,7 +8,7 @@ import { isVideoCaptionLanguageValid } from '@server/helpers/custom-validators/v
import { isVideoChannelUsernameValid } from '@server/helpers/custom-validators/video-channels.js'
import { isVideoChapterTimecodeValid, isVideoChapterTitleValid } from '@server/helpers/custom-validators/video-chapters.js'
import { areVideoEmbedPrivacyDomainsValid, isVideoEmbedPrivacyPolicyValid } from '@server/helpers/custom-validators/video-embed-privacy.js'
-import { isLiveLatencyModeValid, isLiveScheduleValid } from '@server/helpers/custom-validators/video-lives.js'
+import { isLiveDvrWindowValid, isLiveLatencyModeValid, isLiveScheduleValid } from '@server/helpers/custom-validators/video-lives.js'
import {
isPasswordValid,
isVideoCategoryValid,
@@ -125,6 +125,10 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
if (!isBooleanValid(o.live.saveReplay)) o.live.saveReplay = false
if (o.live.saveReplay && !isVideoReplayPrivacyValid(o.live.replaySettings.privacy)) return undefined
+ if (!isLiveDvrWindowValid(o.live.dvrWindow, CONFIG.LIVE.DVR.MAX_WINDOW)) {
+ o.live.dvrWindow = CONFIG.LIVE.DVR.MAX_WINDOW
+ }
+
if (!o.live.latencyMode || !isLiveLatencyModeValid(o.live.latencyMode)) o.live.latencyMode = LiveVideoLatencyMode.DEFAULT
if (!o.live.streamKey) o.live.streamKey = buildUUID()
diff --git a/server/core/middlewares/validators/config.ts b/server/core/middlewares/validators/config.ts
index 66afc75725..4ceddfb241 100644
--- a/server/core/middlewares/validators/config.ts
+++ b/server/core/middlewares/validators/config.ts
@@ -132,6 +132,7 @@ export const customConfigUpdateValidator = [
body('live.transcoding.alwaysTranscodeOriginalResolution').isBoolean(),
body('live.transcoding.fps.max').custom(isIntOrNull),
body('live.transcoding.remoteRunners.enabled').isBoolean(),
+ body('live.dvr.maxWindow').custom(isIntOrNull),
body('search.remoteUri.users').isBoolean(),
body('search.remoteUri.anonymous').isBoolean(),
diff --git a/server/core/middlewares/validators/videos/video-live.ts b/server/core/middlewares/validators/videos/video-live.ts
index 09883a10e9..4b7418d4ec 100644
--- a/server/core/middlewares/validators/videos/video-live.ts
+++ b/server/core/middlewares/validators/videos/video-live.ts
@@ -7,7 +7,7 @@ import {
UserRight,
VideoState
} from '@peertube/peertube-models'
-import { areLiveSchedulesValid, isLiveLatencyModeValid } from '@server/helpers/custom-validators/video-lives.js'
+import { areLiveSchedulesValid, isLiveDvrWindowValid, isLiveLatencyModeValid } from '@server/helpers/custom-validators/video-lives.js'
import { getVideoWithAttributes } from '@server/helpers/video.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import { VideoLoadType } from '@server/lib/model-loaders/video.js'
@@ -76,6 +76,12 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
.customSanitizer(toIntOrNull)
.custom(isLiveLatencyModeValid),
+ body('dvrWindow')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(v => isLiveDvrWindowValid(v, CONFIG.LIVE.DVR.MAX_WINDOW))
+ .withMessage('Should have a valid dvrWindow integer'),
+
body('videoPasswords')
.optional()
.isArray()
@@ -96,7 +102,7 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Live is not enabled on this instance',
+ message: req.t('Live is not enabled on this instance'),
type: ServerErrorCode.LIVE_NOT_ENABLED
})
}
@@ -108,7 +114,7 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Saving live replay is not enabled on this instance',
+ message: req.t('Saving live replay is not enabled on this instance'),
type: ServerErrorCode.LIVE_NOT_ALLOWING_REPLAY
})
}
@@ -118,10 +124,15 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Custom latency mode is not allowed by this instance'
+ message: req.t('Custom latency mode is not allowed by this instance')
})
}
+ if (checkLiveDVRConsistency({ req, res, body }) !== true) {
+ cleanUpReqFiles(req)
+ return
+ }
+
if (!await doesChannelIdExist({ id: body.channelId, req, res, checkCanManage: true, checkIsLocal: true, checkIsOwner: false })) {
return cleanUpReqFiles(req)
}
@@ -134,7 +145,7 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Cannot create this live because the max instance lives limit is reached.',
+ message: req.t('Cannot create this live because the max instance lives limit is reached.'),
type: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED
})
}
@@ -150,7 +161,7 @@ export const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Cannot create this live because the max user lives limit is reached.',
+ message: req.t('Cannot create this live because the max user lives limit is reached.'),
type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED
})
}
@@ -178,6 +189,12 @@ export const videoLiveUpdateValidator = [
.customSanitizer(toIntOrNull)
.custom(isLiveLatencyModeValid),
+ body('dvrWindow')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(v => isLiveDvrWindowValid(v, CONFIG.LIVE.DVR.MAX_WINDOW))
+ .withMessage('Should have a valid dvrWindow integer'),
+
body('schedules')
.optional()
.custom(areLiveSchedulesValid).withMessage('Should have a valid schedules array'),
@@ -190,21 +207,22 @@ export const videoLiveUpdateValidator = [
if (hasValidSaveReplay(body) !== true) {
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Saving live replay is not allowed by this instance'
+ message: req.t('Saving live replay is not allowed by this instance')
})
}
if (hasValidLatencyMode(body) !== true) {
return res.fail({
status: HttpStatusCode.FORBIDDEN_403,
- message: 'Custom latency mode is not allowed by this instance'
+ message: req.t('Custom latency mode is not allowed by this instance')
})
}
- if (!checkLiveSettingsReplayConsistency({ res, body })) return
+ if (!checkLiveSettingsReplayConsistency({ req, res, body })) return
+ if (!checkLiveDVRConsistency({ req, res, body })) return
if (res.locals.videoFull.state !== VideoState.WAITING_FOR_LIVE) {
- return res.fail({ message: 'Cannot update a live that has already started' })
+ return res.fail({ message: req.t('Cannot update a live that has already started') })
}
// Check the user can manage the live
@@ -312,17 +330,18 @@ function hasValidLatencyMode (body: LiveVideoUpdate | LiveVideoCreate) {
}
function checkLiveSettingsReplayConsistency (options: {
+ req: express.Request
res: express.Response
body: LiveVideoUpdate
}) {
- const { res, body } = options
+ const { req, res, body } = options
// We now save replays of this live, so replay settings are mandatory
if (res.locals.videoLive.saveReplay !== true && body.saveReplay === true) {
if (!exists(body.replaySettings)) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
- message: 'Replay settings are missing now the live replay is saved'
+ message: req.t('Replay settings are missing now the live replay is saved')
})
return false
}
@@ -330,7 +349,7 @@ function checkLiveSettingsReplayConsistency (options: {
if (!exists(body.replaySettings.privacy)) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
- message: 'Privacy replay setting is missing now the live replay is saved'
+ message: req.t('Privacy replay setting is missing now the live replay is saved')
})
return false
}
@@ -341,7 +360,7 @@ function checkLiveSettingsReplayConsistency (options: {
if (exists(body.replaySettings)) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
- message: 'Cannot save replay settings since live replay is not enabled'
+ message: req.t('Cannot save replay settings since live replay is not enabled')
})
return false
}
@@ -349,3 +368,22 @@ function checkLiveSettingsReplayConsistency (options: {
return true
}
+
+function checkLiveDVRConsistency (options: {
+ req: express.Request
+ res: express.Response
+ body: LiveVideoUpdate
+}) {
+ const { req, res, body } = options
+
+ if (exists(body.dvrWindow) && body.dvrWindow > 0 && !CONFIG.LIVE.DVR.MAX_WINDOW) {
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: req.t('DVR is not enabled on this instance')
+ })
+
+ return false
+ }
+
+ return true
+}
diff --git a/server/core/models/video/formatter/video-activity-pub-format.ts b/server/core/models/video/formatter/video-activity-pub-format.ts
index 680bbff302..d9d90b89be 100644
--- a/server/core/models/video/formatter/video-activity-pub-format.ts
+++ b/server/core/models/video/formatter/video-activity-pub-format.ts
@@ -160,7 +160,8 @@ function buildLiveAPAttributes (video: MVideoAP) {
isLiveBroadcast: false,
liveSaveReplay: null,
permanentLive: null,
- latencyMode: null
+ latencyMode: null,
+ dvrWindow: null
}
}
@@ -168,7 +169,8 @@ function buildLiveAPAttributes (video: MVideoAP) {
isLiveBroadcast: true,
liveSaveReplay: video.VideoLive.saveReplay,
permanentLive: video.VideoLive.permanentLive,
- latencyMode: video.VideoLive.latencyMode
+ latencyMode: video.VideoLive.latencyMode,
+ dvrWindow: getActivityStreamDuration(video.VideoLive.dvrWindow)
}
}
diff --git a/server/core/models/video/sql/video/shared/video-model-builder.ts b/server/core/models/video/sql/video/shared/video-model-builder.ts
index fa7db45783..a306e51139 100644
--- a/server/core/models/video/sql/video/shared/video-model-builder.ts
+++ b/server/core/models/video/sql/video/shared/video-model-builder.ts
@@ -451,6 +451,7 @@ export class VideoModelBuilder {
if (!id || this.liveDone.has(id)) return
const attributes = this.grab(row, this.tables.getLiveAttributes(), 'VideoLive')
+
videoModel.VideoLive = new VideoLiveModel(attributes, this.buildOpts)
this.liveDone.add(id)
diff --git a/server/core/models/video/sql/video/shared/video-table-attributes.ts b/server/core/models/video/sql/video/shared/video-table-attributes.ts
index a04de8ee57..8551c4397b 100644
--- a/server/core/models/video/sql/video/shared/video-table-attributes.ts
+++ b/server/core/models/video/sql/video/shared/video-table-attributes.ts
@@ -158,6 +158,7 @@ export class VideoTableAttributes {
'streamKey',
'saveReplay',
'permanentLive',
+ 'dvrWindow',
'latencyMode',
'videoId',
'replaySettingId',
diff --git a/server/core/models/video/video-live.ts b/server/core/models/video/video-live.ts
index 309db8cdb0..47cdefe43f 100644
--- a/server/core/models/video/video-live.ts
+++ b/server/core/models/video/video-live.ts
@@ -55,6 +55,11 @@ export class VideoLiveModel extends SequelizeModel<VideoLiveModel> {
@Column
declare latencyMode: LiveVideoLatencyModeType
+ // 0 if DVR is disabled, otherwise the DVR window in seconds
+ @AllowNull(false)
+ @Column
+ declare dvrWindow: number
+
@CreatedAt
declare createdAt: Date
@@ -163,12 +168,15 @@ export class VideoLiveModel extends SequelizeModel<VideoLiveModel> {
return VideoLiveModel.findOne<MVideoLiveVideoWithSettingSchedules>(query)
}
- toFormattedJSON (this: MVideoLiveWithSettingSchedules, canSeePrivateInformation: boolean): LiveVideo {
+ toFormattedJSON (this: MVideoLiveWithSettingSchedules, options: {
+ canSeePrivateInformation: boolean
+ isLocal: boolean
+ }): LiveVideo {
let privateInformation: Pick<LiveVideo, 'rtmpUrl' | 'rtmpsUrl' | 'streamKey'> | {} = {}
// If we don't have a stream key, it means this is a remote live so we don't specify the rtmp URL
// We also display these private information only to the live owne/moderators
- if (this.streamKey && canSeePrivateInformation === true) {
+ if (this.streamKey && options.canSeePrivateInformation === true) {
privateInformation = {
streamKey: this.streamKey,
@@ -193,6 +201,9 @@ export class VideoLiveModel extends SequelizeModel<VideoLiveModel> {
saveReplay: this.saveReplay,
replaySettings,
latencyMode: this.latencyMode,
+ dvrWindow: options.isLocal
+ ? Math.min(this.dvrWindow, CONFIG.LIVE.DVR.MAX_WINDOW)
+ : this.dvrWindow,
schedules: (this.LiveSchedules || []).map(schedule => schedule.toFormattedJSON())
}
}