mirror of https://github.com/Chocobozzz/PeerTube
Try to optimize sha segments fetching
parent
210856a7be
commit
25b7c84724
|
@ -771,6 +771,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
: null,
|
: null,
|
||||||
embedUrl: video.embedUrl,
|
embedUrl: video.embedUrl,
|
||||||
|
|
||||||
|
isLive: video.isLive,
|
||||||
|
|
||||||
language: this.localeId,
|
language: this.localeId,
|
||||||
|
|
||||||
userWatching: user && user.videosHistoryEnabled === true ? {
|
userWatching: user && user.videosHistoryEnabled === true ? {
|
||||||
|
|
|
@ -6,11 +6,14 @@ type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string
|
||||||
|
|
||||||
const maxRetries = 3
|
const maxRetries = 3
|
||||||
|
|
||||||
function segmentValidatorFactory (segmentsSha256Url: string) {
|
function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) {
|
||||||
let segmentsJSON = fetchSha256Segments(segmentsSha256Url)
|
let segmentsJSON = fetchSha256Segments(segmentsSha256Url)
|
||||||
const regex = /bytes=(\d+)-(\d+)/
|
const regex = /bytes=(\d+)-(\d+)/
|
||||||
|
|
||||||
return async function segmentValidator (segment: Segment, retry = 1) {
|
return async function segmentValidator (segment: Segment, retry = 1) {
|
||||||
|
// Wait for hash generation from the server
|
||||||
|
if (isLive) await wait(1000)
|
||||||
|
|
||||||
const filename = basename(segment.url)
|
const filename = basename(segment.url)
|
||||||
|
|
||||||
const segmentValue = (await segmentsJSON)[filename]
|
const segmentValue = (await segmentsJSON)[filename]
|
||||||
|
@ -20,10 +23,10 @@ function segmentValidatorFactory (segmentsSha256Url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!segmentValue) {
|
if (!segmentValue) {
|
||||||
await wait(1000)
|
|
||||||
|
|
||||||
console.log('Refetching sha segments for %s.', filename)
|
console.log('Refetching sha segments for %s.', filename)
|
||||||
|
|
||||||
|
await wait(1000)
|
||||||
|
|
||||||
segmentsJSON = fetchSha256Segments(segmentsSha256Url)
|
segmentsJSON = fetchSha256Segments(segmentsSha256Url)
|
||||||
await segmentValidator(segment, retry + 1)
|
await segmentValidator(segment, retry + 1)
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,8 @@ export interface CommonOptions extends CustomizationOptions {
|
||||||
videoViewUrl: string
|
videoViewUrl: string
|
||||||
embedUrl: string
|
embedUrl: string
|
||||||
|
|
||||||
|
isLive: boolean
|
||||||
|
|
||||||
language?: string
|
language?: string
|
||||||
|
|
||||||
videoCaptions: VideoJSCaption[]
|
videoCaptions: VideoJSCaption[]
|
||||||
|
@ -323,7 +325,7 @@ export class PeertubePlayerManager {
|
||||||
const p2pMediaLoaderConfig = {
|
const p2pMediaLoaderConfig = {
|
||||||
loader: {
|
loader: {
|
||||||
trackerAnnounce,
|
trackerAnnounce,
|
||||||
segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
|
segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
|
||||||
rtcConfig: getRtcConfig(),
|
rtcConfig: getRtcConfig(),
|
||||||
requiredSegmentsPriority: 1,
|
requiredSegmentsPriority: 1,
|
||||||
segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
|
segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
|
||||||
|
|
|
@ -532,6 +532,8 @@ export class PeerTubeEmbed {
|
||||||
inactivityTimeout: 2500,
|
inactivityTimeout: 2500,
|
||||||
videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
|
videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
|
||||||
|
|
||||||
|
isLive: videoInfo.isLive,
|
||||||
|
|
||||||
playerElement: this.playerElement,
|
playerElement: this.playerElement,
|
||||||
onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
|
onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue