]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/constants.ts
Increase live delay
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
index ebbdba262957cde3249afa51296ae8f3b8e0ce6e..083351d6184ce59811cb0c86fff578470bb3c7c6 100644 (file)
@@ -1,29 +1,30 @@
-import { join } from 'path'
+import { randomInt } from '../../shared/core-utils/miscs/miscs'
+import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
 import { randomBytes } from 'crypto'
-import { ActivityPubActorType } from '../../shared/models/activitypub'
-import { FollowState } from '../../shared/models/actors'
+import { invert } from 'lodash'
+import { join } from 'path'
 import {
   AbuseState,
+  JobType,
   VideoImportState,
   VideoPrivacy,
-  VideoTranscodingFPS,
-  JobType,
   VideoRateType,
   VideoResolution,
-  VideoState
+  VideoState,
+  VideoTranscodingFPS
 } from '../../shared/models'
-// Do not use barrels, remain constants as independent as possible
-import { isTestInstance, sanitizeHost, sanitizeUrl, root } from '../helpers/core-utils'
+import { ActivityPubActorType } from '../../shared/models/activitypub'
+import { FollowState } from '../../shared/models/actors'
 import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
-import { invert } from 'lodash'
-import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
 import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
 import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
+// Do not use barrels, remain constants as independent as possible
+import { isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
 import { CONFIG, registerConfigChangedHandler } from './config'
 
 // ---------------------------------------------------------------------------
 
-const LAST_MIGRATION_VERSION = 525
+const LAST_MIGRATION_VERSION = 550
 
 // ---------------------------------------------------------------------------
 
@@ -50,7 +51,8 @@ const WEBSERVER = {
   SCHEME: '',
   WS: '',
   HOSTNAME: '',
-  PORT: 0
+  PORT: 0,
+  RTMP_URL: ''
 }
 
 // Sortable columns per schema
@@ -61,7 +63,10 @@ const SORTABLE_COLUMNS = {
   JOBS: [ 'createdAt' ],
   VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
   VIDEO_IMPORTS: [ 'createdAt' ],
+
   VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ],
+  VIDEO_COMMENTS: [ 'createdAt' ],
+
   VIDEO_RATES: [ 'createdAt' ],
   BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
   FOLLOWERS: [ 'createdAt', 'state', 'score' ],
@@ -138,7 +143,8 @@ const JOB_ATTEMPTS: { [id in JobType]: number } = {
   'email': 5,
   'videos-views': 1,
   'activitypub-refresher': 1,
-  'video-redundancy': 1
+  'video-redundancy': 1,
+  'video-live-ending': 1
 }
 const JOB_CONCURRENCY: { [id in JobType]: number } = {
   'activitypub-http-broadcast': 1,
@@ -151,7 +157,8 @@ const JOB_CONCURRENCY: { [id in JobType]: number } = {
   'email': 5,
   'videos-views': 1,
   'activitypub-refresher': 1,
-  'video-redundancy': 1
+  'video-redundancy': 1,
+  'video-live-ending': 10
 }
 const JOB_TTL: { [id in JobType]: number } = {
   'activitypub-http-broadcast': 60000 * 10, // 10 minutes
@@ -164,11 +171,12 @@ const JOB_TTL: { [id in JobType]: number } = {
   'email': 60000 * 10, // 10 minutes
   'videos-views': undefined, // Unlimited
   'activitypub-refresher': 60000 * 10, // 10 minutes
-  'video-redundancy': 1000 * 3600 * 3 // 3 hours
+  'video-redundancy': 1000 * 3600 * 3, // 3 hours
+  'video-live-ending': 1000 * 60 * 10 // 10 minutes
 }
 const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
   'videos-views': {
-    cron: '1 * * * *' // At 1 minute past the hour
+    cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
   }
 }
 
@@ -264,7 +272,7 @@ const CONSTRAINTS_FIELDS = {
     VIEWS: { min: 0 },
     LIKES: { min: 0 },
     DISLIKES: { min: 0 },
-    FILE_SIZE: { min: 10 },
+    FILE_SIZE: { min: -1 },
     URL: { min: 3, max: 2000 } // Length
   },
   VIDEO_PLAYLISTS: {
@@ -312,7 +320,11 @@ const CONSTRAINTS_FIELDS = {
   }
 }
 
-let VIDEO_VIEW_LIFETIME = 60000 * 60 // 1 hour
+const VIEW_LIFETIME = {
+  VIDEO: 60000 * 60, // 1 hour
+  LIVE: 60000 * 5 // 5 minutes
+}
+
 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
 
 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
@@ -370,39 +382,41 @@ const VIDEO_LICENCES = {
 
 const VIDEO_LANGUAGES: { [id: string]: string } = {}
 
-const VIDEO_PRIVACIES = {
+const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
   [VideoPrivacy.PUBLIC]: 'Public',
   [VideoPrivacy.UNLISTED]: 'Unlisted',
   [VideoPrivacy.PRIVATE]: 'Private',
   [VideoPrivacy.INTERNAL]: 'Internal'
 }
 
-const VIDEO_STATES = {
+const VIDEO_STATES: { [ id in VideoState ]: string } = {
   [VideoState.PUBLISHED]: 'Published',
   [VideoState.TO_TRANSCODE]: 'To transcode',
-  [VideoState.TO_IMPORT]: 'To import'
+  [VideoState.TO_IMPORT]: 'To import',
+  [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
+  [VideoState.LIVE_ENDED]: 'Livestream ended'
 }
 
-const VIDEO_IMPORT_STATES = {
+const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
   [VideoImportState.FAILED]: 'Failed',
   [VideoImportState.PENDING]: 'Pending',
   [VideoImportState.SUCCESS]: 'Success',
   [VideoImportState.REJECTED]: 'Rejected'
 }
 
-const ABUSE_STATES = {
+const ABUSE_STATES: { [ id in AbuseState ]: string } = {
   [AbuseState.PENDING]: 'Pending',
   [AbuseState.REJECTED]: 'Rejected',
   [AbuseState.ACCEPTED]: 'Accepted'
 }
 
-const VIDEO_PLAYLIST_PRIVACIES = {
+const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
   [VideoPlaylistPrivacy.PUBLIC]: 'Public',
   [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
   [VideoPlaylistPrivacy.PRIVATE]: 'Private'
 }
 
-const VIDEO_PLAYLIST_TYPES = {
+const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
   [VideoPlaylistType.REGULAR]: 'Regular',
   [VideoPlaylistType.WATCH_LATER]: 'Watch later'
 }
@@ -417,7 +431,9 @@ const MIMETYPES = {
       'audio/x-ms-wma': '.wma',
       'audio/wav': '.wav',
       'audio/x-flac': '.flac',
-      'audio/flac': '.flac'
+      'audio/flac': '.flac',
+      '‎audio/aac': '.aac',
+      'audio/ac3': '.ac3'
     },
     EXT_MIMETYPE: null as { [ id: string ]: string }
   },
@@ -500,6 +516,10 @@ const HTTP_SIGNATURE = {
   HEADER_NAME: 'signature',
   ALGORITHM: 'rsa-sha256',
   HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
+  REQUIRED_HEADERS: {
+    ALL: [ '(request-target)', 'host', 'date' ],
+    POST: [ '(request-target)', 'host', 'date', 'digest' ]
+  },
   CLOCK_SKEW_SECONDS: 1800
 }
 
@@ -543,8 +563,8 @@ const STATIC_DOWNLOAD_PATHS = {
 }
 const LAZY_STATIC_PATHS = {
   AVATARS: '/lazy-static/avatars/',
-  PREVIEWS: '/static/previews/',
-  VIDEO_CAPTIONS: '/static/video-captions/'
+  PREVIEWS: '/lazy-static/previews/',
+  VIDEO_CAPTIONS: '/lazy-static/video-captions/'
 }
 
 // Cache control
@@ -598,9 +618,25 @@ const LRU_CACHE = {
 const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
 
+const VIDEO_LIVE = {
+  EXTENSION: '.ts',
+  CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
+  SEGMENT_TIME_SECONDS: 4, // 4 seconds
+  SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
+  EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 5,
+  RTMP: {
+    CHUNK_SIZE: 60000,
+    GOP_CACHE: true,
+    PING: 60,
+    PING_TIMEOUT: 30,
+    BASE_PATH: 'live'
+  }
+}
+
 const MEMOIZE_TTL = {
   OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
-  INFO_HASH_EXISTS: 1000 * 3600 * 12 // 12 hours
+  INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
+  LIVE_ABLE_TO_UPLOAD: 1000 * 60 // 1 minute
 }
 
 const MEMOIZE_LENGTH = {
@@ -620,7 +656,8 @@ const REDUNDANCY = {
 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
 
 const ASSETS_PATH = {
-  DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg')
+  DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
+  DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
 }
 
 // ---------------------------------------------------------------------------
@@ -648,7 +685,7 @@ const TRACKER_RATE_LIMITS = {
   INTERVAL: 60000 * 5, // 5 minutes
   ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
   ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
-  BLOCK_IP_LIFETIME: 60000 * 10 // 10 minutes
+  BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
 }
 
 const P2P_MEDIA_LOADER_PEER_VERSION = 2
@@ -702,16 +739,22 @@ if (isTestInstance() === true) {
 
   REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
 
-  VIDEO_VIEW_LIFETIME = 1000 // 1 second
+  VIEW_LIFETIME.VIDEO = 1000 // 1 second
+  VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second
   CONTACT_FORM_LIFETIME = 1000 // 1 second
 
   JOB_ATTEMPTS['email'] = 1
 
   FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
   MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
+  MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
   OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
 
   PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
+
+  VIDEO_LIVE.CLEANUP_DELAY = 5000
+  VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
+  VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
 }
 
 updateWebserverUrls()
@@ -735,6 +778,7 @@ const FILES_CONTENT_HASH = {
 export {
   WEBSERVER,
   API_VERSION,
+  VIDEO_LIVE,
   PEERTUBE_VERSION,
   LAZY_STATIC_PATHS,
   SEARCH_INDEX,
@@ -809,7 +853,7 @@ export {
   JOB_COMPLETED_LIFETIME,
   HTTP_SIGNATURE,
   VIDEO_IMPORT_STATES,
-  VIDEO_VIEW_LIFETIME,
+  VIEW_LIFETIME,
   CONTACT_FORM_LIFETIME,
   VIDEO_PLAYLIST_PRIVACIES,
   PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
@@ -841,7 +885,7 @@ function buildVideoMimetypeExt () {
         'video/x-matroska': '.mkv',
 
         // Developed by Apple
-        'video/quicktime': '.mov', // often used as output format by editing software
+        'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
         'video/x-m4v': '.m4v',
         'video/m4v': '.m4v',
 
@@ -856,8 +900,8 @@ function buildVideoMimetypeExt () {
 
         // Developed by 3GPP
         // common video formats for cell phones
-        'video/3gpp': '.3gp',
-        'video/3gpp2': '.3g2',
+        'video/3gpp': [ '.3gp', '.3gpp' ],
+        'video/3gpp2': [ '.3g2', '.3gpp2' ],
 
         // Developed by FFmpeg/Mplayer
         'application/x-nut': '.nut',
@@ -870,7 +914,8 @@ function buildVideoMimetypeExt () {
         // Old formats reliant on MPEG-1/MPEG-2
         'video/mpv': '.mpv',
         'video/mpeg2': '.m2v',
-        'video/mpeg': '.mpeg',
+        'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
+        'video/dvd': '.vob',
 
         // Could be anything
         'application/octet-stream': null,
@@ -889,10 +934,13 @@ function buildVideoMimetypeExt () {
 function updateWebserverUrls () {
   WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
   WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
-  WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
   WEBSERVER.WS = CONFIG.WEBSERVER.WS
+
+  WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
   WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
   WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
+
+  WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
 }
 
 function updateWebserverConfig () {
@@ -953,7 +1001,9 @@ function buildLanguages () {
     jsl: true, // Japanese sign language
     sfs: true, // South African sign language
     swl: true, // Swedish sign language
-    rsl: true, // Russian sign language: true
+    rsl: true, // Russian sign language
+
+    kab: true, // Kabyle
 
     epo: true, // Esperanto
     tlh: true, // Klingon