mirror of https://github.com/Chocobozzz/PeerTube
Add ability to configure stun servers
parent
34957c5a18
commit
70ee15d3aa
|
@ -696,6 +696,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
|||
authorizationHeader: () => this.authService.getRequestHeaderValue(),
|
||||
|
||||
serverUrl: environment.originServerUrl || window.location.origin,
|
||||
stunServers: this.serverConfig.webrtc.stunServers,
|
||||
|
||||
errorNotifier: (message: string) => this.notifier.error(message),
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ export class PeerTubePlayer {
|
|||
|
||||
private async loadP2PMediaLoader () {
|
||||
const hlsOptionsBuilder = new HLSOptionsBuilder({
|
||||
...pick(this.options, [ 'pluginsManager', 'serverUrl', 'authorizationHeader' ]),
|
||||
...pick(this.options, [ 'pluginsManager', 'serverUrl', 'authorizationHeader', 'stunServers' ]),
|
||||
...pick(this.currentLoadOptions, [
|
||||
'videoPassword',
|
||||
'requiresUserAuth',
|
||||
|
|
|
@ -15,16 +15,9 @@ export function bytes (value: number) {
|
|||
return [ calc, format.type ]
|
||||
}
|
||||
|
||||
export function getRtcConfig () {
|
||||
export function getRtcConfig (stunServers: string[]) {
|
||||
return {
|
||||
iceServers: [
|
||||
{
|
||||
urls: 'stun:stun.stunprotocol.org'
|
||||
},
|
||||
{
|
||||
urls: 'stun:stun.framasoft.org'
|
||||
}
|
||||
]
|
||||
iceServers: stunServers.map(s => ({ urls: s }))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,12 @@ import { getRtcConfig, isSameOrigin } from '../common'
|
|||
import { RedundancyUrlManager } from '../p2p-media-loader/redundancy-url-manager'
|
||||
import { segmentUrlBuilderFactory } from '../p2p-media-loader/segment-url-builder'
|
||||
import { SegmentValidator } from '../p2p-media-loader/segment-validator'
|
||||
import debug from 'debug'
|
||||
|
||||
const debugLogger = debug('peertube:player:hls')
|
||||
|
||||
type ConstructorOptions =
|
||||
Pick<PeerTubePlayerContructorOptions, 'pluginsManager' | 'serverUrl' | 'authorizationHeader'> &
|
||||
Pick<PeerTubePlayerContructorOptions, 'pluginsManager' | 'serverUrl' | 'authorizationHeader' | 'stunServers'> &
|
||||
Pick<PeerTubePlayerLoadOptions, 'videoPassword' | 'requiresUserAuth' | 'videoFileToken' | 'requiresPassword' |
|
||||
'isLive' | 'liveOptions' | 'p2pEnabled' | 'hls'>
|
||||
|
||||
|
@ -86,6 +89,8 @@ export class HLSOptionsBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
debugLogger('Creating HLS player options', { hlsjs, p2pMediaLoader, loaderOptions: p2pMediaLoaderConfig })
|
||||
|
||||
return { p2pMediaLoader, hlsjs }
|
||||
}
|
||||
|
||||
|
@ -116,7 +121,7 @@ export class HLSOptionsBuilder {
|
|||
return {
|
||||
loader: {
|
||||
trackerAnnounce,
|
||||
rtcConfig: getRtcConfig(),
|
||||
rtcConfig: getRtcConfig(this.options.stunServers),
|
||||
|
||||
simultaneousHttpDownloads: 1,
|
||||
httpFailedSegmentTimeout: 1000,
|
||||
|
|
|
@ -41,6 +41,8 @@ export type PeerTubePlayerContructorOptions = {
|
|||
|
||||
pluginsManager: PluginsManager
|
||||
|
||||
stunServers: string[]
|
||||
|
||||
autoPlayerRatio?: {
|
||||
cssRatioVariable: string
|
||||
cssPlayerPortraitModeVariable: string
|
||||
|
|
|
@ -206,6 +206,7 @@ export class PlayerOptionsBuilder {
|
|||
theaterButton: false,
|
||||
|
||||
serverUrl: getBackendUrl(),
|
||||
stunServers: serverConfig.webrtc.stunServers,
|
||||
language: navigator.language,
|
||||
|
||||
pluginsManager: this.peertubePlugin.getPluginsManager(),
|
||||
|
|
|
@ -514,6 +514,12 @@ stats:
|
|||
total_admins:
|
||||
enabled: true
|
||||
|
||||
webrtc:
|
||||
# 1 or 2 STUN servers are sufficient
|
||||
stun_servers:
|
||||
- 'stun:stunserver2024.stunprotocol.org'
|
||||
- 'stun:stun.framasoft.org'
|
||||
|
||||
cache:
|
||||
previews:
|
||||
size: 500 # Max number of previews you want to cache
|
||||
|
|
|
@ -512,6 +512,12 @@ stats:
|
|||
total_admins:
|
||||
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
|
||||
|
|
|
@ -354,6 +354,10 @@ export interface ServerConfig {
|
|||
enabled: boolean
|
||||
}
|
||||
}
|
||||
|
||||
webrtc: {
|
||||
stunServers: string[]
|
||||
}
|
||||
}
|
||||
|
||||
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.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 () {
|
||||
|
|
|
@ -396,6 +396,9 @@ const CONFIG = {
|
|||
ENABLED: config.get<boolean>('stats.total_admins.enabled')
|
||||
}
|
||||
},
|
||||
WEBRTC: {
|
||||
STUN_SERVERS: config.get<string[]>('webrtc.stun_servers')
|
||||
},
|
||||
ADMIN: {
|
||||
get EMAIL () { return config.get<string>('admin.email') }
|
||||
},
|
||||
|
|
|
@ -37,7 +37,7 @@ class Redis {
|
|||
const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
|
||||
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('connect', () => {
|
||||
logger.info('Connected to redis.', lTags())
|
||||
|
@ -59,15 +59,17 @@ class Redis {
|
|||
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 connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
|
||||
|
||||
if (CONFIG.REDIS.SENTINEL.ENABLED) {
|
||||
logger.info(
|
||||
`Using sentinel redis options`,
|
||||
{ sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
|
||||
)
|
||||
if (logOptions) {
|
||||
logger.info(
|
||||
`Using sentinel redis options`,
|
||||
{ sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
connectionName,
|
||||
|
@ -80,10 +82,12 @@ class Redis {
|
|||
}
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`Using standalone redis options`,
|
||||
{ db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
|
||||
)
|
||||
if (logOptions) {
|
||||
logger.info(
|
||||
`Using standalone redis options`,
|
||||
{ db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
connectionName,
|
||||
|
|
|
@ -320,6 +320,10 @@ class ServerConfigManager {
|
|||
|
||||
storyboards: {
|
||||
enabled: CONFIG.STORYBOARDS.ENABLED
|
||||
},
|
||||
|
||||
webrtc: {
|
||||
stunServers: CONFIG.WEBRTC.STUN_SERVERS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue