mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add ability to configure stun servers
This commit is contained in:
parent
34957c5a18
commit
70ee15d3aa
@ -696,6 +696,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
|||||||
authorizationHeader: () => this.authService.getRequestHeaderValue(),
|
authorizationHeader: () => this.authService.getRequestHeaderValue(),
|
||||||
|
|
||||||
serverUrl: environment.originServerUrl || window.location.origin,
|
serverUrl: environment.originServerUrl || window.location.origin,
|
||||||
|
stunServers: this.serverConfig.webrtc.stunServers,
|
||||||
|
|
||||||
errorNotifier: (message: string) => this.notifier.error(message),
|
errorNotifier: (message: string) => this.notifier.error(message),
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ export class PeerTubePlayer {
|
|||||||
|
|
||||||
private async loadP2PMediaLoader () {
|
private async loadP2PMediaLoader () {
|
||||||
const hlsOptionsBuilder = new HLSOptionsBuilder({
|
const hlsOptionsBuilder = new HLSOptionsBuilder({
|
||||||
...pick(this.options, [ 'pluginsManager', 'serverUrl', 'authorizationHeader' ]),
|
...pick(this.options, [ 'pluginsManager', 'serverUrl', 'authorizationHeader', 'stunServers' ]),
|
||||||
...pick(this.currentLoadOptions, [
|
...pick(this.currentLoadOptions, [
|
||||||
'videoPassword',
|
'videoPassword',
|
||||||
'requiresUserAuth',
|
'requiresUserAuth',
|
||||||
|
@ -15,16 +15,9 @@ export function bytes (value: number) {
|
|||||||
return [ calc, format.type ]
|
return [ calc, format.type ]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRtcConfig () {
|
export function getRtcConfig (stunServers: string[]) {
|
||||||
return {
|
return {
|
||||||
iceServers: [
|
iceServers: stunServers.map(s => ({ urls: s }))
|
||||||
{
|
|
||||||
urls: 'stun:stun.stunprotocol.org'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
urls: 'stun:stun.framasoft.org'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,12 @@ import { getRtcConfig, isSameOrigin } from '../common'
|
|||||||
import { RedundancyUrlManager } from '../p2p-media-loader/redundancy-url-manager'
|
import { RedundancyUrlManager } from '../p2p-media-loader/redundancy-url-manager'
|
||||||
import { segmentUrlBuilderFactory } from '../p2p-media-loader/segment-url-builder'
|
import { segmentUrlBuilderFactory } from '../p2p-media-loader/segment-url-builder'
|
||||||
import { SegmentValidator } from '../p2p-media-loader/segment-validator'
|
import { SegmentValidator } from '../p2p-media-loader/segment-validator'
|
||||||
|
import debug from 'debug'
|
||||||
|
|
||||||
|
const debugLogger = debug('peertube:player:hls')
|
||||||
|
|
||||||
type ConstructorOptions =
|
type ConstructorOptions =
|
||||||
Pick<PeerTubePlayerContructorOptions, 'pluginsManager' | 'serverUrl' | 'authorizationHeader'> &
|
Pick<PeerTubePlayerContructorOptions, 'pluginsManager' | 'serverUrl' | 'authorizationHeader' | 'stunServers'> &
|
||||||
Pick<PeerTubePlayerLoadOptions, 'videoPassword' | 'requiresUserAuth' | 'videoFileToken' | 'requiresPassword' |
|
Pick<PeerTubePlayerLoadOptions, 'videoPassword' | 'requiresUserAuth' | 'videoFileToken' | 'requiresPassword' |
|
||||||
'isLive' | 'liveOptions' | 'p2pEnabled' | 'hls'>
|
'isLive' | 'liveOptions' | 'p2pEnabled' | 'hls'>
|
||||||
|
|
||||||
@ -86,6 +89,8 @@ export class HLSOptionsBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugLogger('Creating HLS player options', { hlsjs, p2pMediaLoader, loaderOptions: p2pMediaLoaderConfig })
|
||||||
|
|
||||||
return { p2pMediaLoader, hlsjs }
|
return { p2pMediaLoader, hlsjs }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +121,7 @@ export class HLSOptionsBuilder {
|
|||||||
return {
|
return {
|
||||||
loader: {
|
loader: {
|
||||||
trackerAnnounce,
|
trackerAnnounce,
|
||||||
rtcConfig: getRtcConfig(),
|
rtcConfig: getRtcConfig(this.options.stunServers),
|
||||||
|
|
||||||
simultaneousHttpDownloads: 1,
|
simultaneousHttpDownloads: 1,
|
||||||
httpFailedSegmentTimeout: 1000,
|
httpFailedSegmentTimeout: 1000,
|
||||||
|
@ -41,6 +41,8 @@ export type PeerTubePlayerContructorOptions = {
|
|||||||
|
|
||||||
pluginsManager: PluginsManager
|
pluginsManager: PluginsManager
|
||||||
|
|
||||||
|
stunServers: string[]
|
||||||
|
|
||||||
autoPlayerRatio?: {
|
autoPlayerRatio?: {
|
||||||
cssRatioVariable: string
|
cssRatioVariable: string
|
||||||
cssPlayerPortraitModeVariable: string
|
cssPlayerPortraitModeVariable: string
|
||||||
|
@ -206,6 +206,7 @@ export class PlayerOptionsBuilder {
|
|||||||
theaterButton: false,
|
theaterButton: false,
|
||||||
|
|
||||||
serverUrl: getBackendUrl(),
|
serverUrl: getBackendUrl(),
|
||||||
|
stunServers: serverConfig.webrtc.stunServers,
|
||||||
language: navigator.language,
|
language: navigator.language,
|
||||||
|
|
||||||
pluginsManager: this.peertubePlugin.getPluginsManager(),
|
pluginsManager: this.peertubePlugin.getPluginsManager(),
|
||||||
|
@ -514,6 +514,12 @@ stats:
|
|||||||
total_admins:
|
total_admins:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
webrtc:
|
||||||
|
# 1 or 2 STUN servers are sufficient
|
||||||
|
stun_servers:
|
||||||
|
- 'stun:stunserver2024.stunprotocol.org'
|
||||||
|
- 'stun:stun.framasoft.org'
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
previews:
|
previews:
|
||||||
size: 500 # Max number of previews you want to cache
|
size: 500 # Max number of previews you want to cache
|
||||||
|
@ -512,6 +512,12 @@ stats:
|
|||||||
total_admins:
|
total_admins:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
webrtc:
|
||||||
|
# 1 or 2 STUN servers are sufficient
|
||||||
|
stun_servers:
|
||||||
|
- 'stun:stunserver2024.stunprotocol.org'
|
||||||
|
- 'stun:stun.framasoft.org'
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# From this point, almost all following keys can be overridden by the web interface
|
# From this point, almost all following keys can be overridden by the web interface
|
||||||
|
@ -354,6 +354,10 @@ export interface ServerConfig {
|
|||||||
enabled: boolean
|
enabled: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webrtc: {
|
||||||
|
stunServers: string[]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HTMLServerConfig = Omit<ServerConfig, 'signup'>
|
export type HTMLServerConfig = Omit<ServerConfig, 'signup'>
|
||||||
|
@ -444,6 +444,11 @@ describe('Test config', function () {
|
|||||||
|
|
||||||
expect(data.views.videos.watchingInterval.anonymous).to.equal(5000)
|
expect(data.views.videos.watchingInterval.anonymous).to.equal(5000)
|
||||||
expect(data.views.videos.watchingInterval.users).to.equal(5000)
|
expect(data.views.videos.watchingInterval.users).to.equal(5000)
|
||||||
|
|
||||||
|
expect(data.webrtc.stunServers).to.have.members([
|
||||||
|
'stun:stunserver2024.stunprotocol.org',
|
||||||
|
'stun:stun.framasoft.org'
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have a correct config on a server with registration enabled', async function () {
|
it('Should have a correct config on a server with registration enabled', async function () {
|
||||||
|
@ -396,6 +396,9 @@ const CONFIG = {
|
|||||||
ENABLED: config.get<boolean>('stats.total_admins.enabled')
|
ENABLED: config.get<boolean>('stats.total_admins.enabled')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
WEBRTC: {
|
||||||
|
STUN_SERVERS: config.get<string[]>('webrtc.stun_servers')
|
||||||
|
},
|
||||||
ADMIN: {
|
ADMIN: {
|
||||||
get EMAIL () { return config.get<string>('admin.email') }
|
get EMAIL () { return config.get<string>('admin.email') }
|
||||||
},
|
},
|
||||||
|
@ -37,7 +37,7 @@ class Redis {
|
|||||||
const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
|
const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
|
||||||
logger.info(`Connecting to Redis in "${redisMode}" mode...`, lTags())
|
logger.info(`Connecting to Redis in "${redisMode}" mode...`, lTags())
|
||||||
|
|
||||||
this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }))
|
this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }, true))
|
||||||
this.client.on('error', err => logger.error('Redis failed to connect', { err, ...lTags() }))
|
this.client.on('error', err => logger.error('Redis failed to connect', { err, ...lTags() }))
|
||||||
this.client.on('connect', () => {
|
this.client.on('connect', () => {
|
||||||
logger.info('Connected to redis.', lTags())
|
logger.info('Connected to redis.', lTags())
|
||||||
@ -59,15 +59,17 @@ class Redis {
|
|||||||
this.prefix = 'redis-' + WEBSERVER.HOST + '-'
|
this.prefix = 'redis-' + WEBSERVER.HOST + '-'
|
||||||
}
|
}
|
||||||
|
|
||||||
static getRedisClientOptions (name?: string, options: RedisOptions = {}): RedisOptions {
|
static getRedisClientOptions (name?: string, options: RedisOptions = {}, logOptions = false): RedisOptions {
|
||||||
const connectionName = [ 'PeerTube', name ].join('')
|
const connectionName = [ 'PeerTube', name ].join('')
|
||||||
const connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
|
const connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
|
||||||
|
|
||||||
if (CONFIG.REDIS.SENTINEL.ENABLED) {
|
if (CONFIG.REDIS.SENTINEL.ENABLED) {
|
||||||
logger.info(
|
if (logOptions) {
|
||||||
`Using sentinel redis options`,
|
logger.info(
|
||||||
{ sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
|
`Using sentinel redis options`,
|
||||||
)
|
{ sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectionName,
|
connectionName,
|
||||||
@ -80,10 +82,12 @@ class Redis {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
if (logOptions) {
|
||||||
`Using standalone redis options`,
|
logger.info(
|
||||||
{ db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
|
`Using standalone redis options`,
|
||||||
)
|
{ db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectionName,
|
connectionName,
|
||||||
|
@ -320,6 +320,10 @@ class ServerConfigManager {
|
|||||||
|
|
||||||
storyboards: {
|
storyboards: {
|
||||||
enabled: CONFIG.STORYBOARDS.ENABLED
|
enabled: CONFIG.STORYBOARDS.ENABLED
|
||||||
|
},
|
||||||
|
|
||||||
|
webrtc: {
|
||||||
|
stunServers: CONFIG.WEBRTC.STUN_SERVERS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user