diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:15:59 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:15:59 +0100 |
commit | 210856a7be4631540791bad027fb3ef0f7a51f14 (patch) | |
tree | db187b29a37fb1cfba1c7f97efb8a145b1f1a149 /client | |
parent | 52a350a15c34aa13bffaeedeb39de37cb0534fde (diff) | |
download | PeerTube-210856a7be4631540791bad027fb3ef0f7a51f14.tar.gz PeerTube-210856a7be4631540791bad027fb3ef0f7a51f14.tar.zst PeerTube-210856a7be4631540791bad027fb3ef0f7a51f14.zip |
Try to fix live segments check
Diffstat (limited to 'client')
3 files changed, 26 insertions, 8 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index de1cf46b1..d442df0e3 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | |||
@@ -95,7 +95,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A | |||
95 | ] | 95 | ] |
96 | 96 | ||
97 | this.liveMaxDurationOptions = [ | 97 | this.liveMaxDurationOptions = [ |
98 | { value: 0, label: $localize`No limit` }, | 98 | { value: null, label: $localize`No limit` }, |
99 | { value: 1000 * 3600, label: $localize`1 hour` }, | 99 | { value: 1000 * 3600, label: $localize`1 hour` }, |
100 | { value: 1000 * 3600 * 3, label: $localize`3 hours` }, | 100 | { value: 1000 * 3600 * 3, label: $localize`3 hours` }, |
101 | { value: 1000 * 3600 * 5, label: $localize`5 hours` }, | 101 | { value: 1000 * 3600 * 5, label: $localize`5 hours` }, |
@@ -328,7 +328,13 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A | |||
328 | } | 328 | } |
329 | 329 | ||
330 | async formValidated () { | 330 | async formValidated () { |
331 | this.configService.updateCustomConfig(this.form.getRawValue()) | 331 | const value: CustomConfig = this.form.getRawValue() |
332 | |||
333 | // Transform "null" to null | ||
334 | const maxDuration = value.live.maxDuration as any | ||
335 | if (maxDuration === 'null') value.live.maxDuration = null | ||
336 | |||
337 | this.configService.updateCustomConfig(value) | ||
332 | .subscribe( | 338 | .subscribe( |
333 | res => { | 339 | res => { |
334 | this.customConfig = res | 340 | this.customConfig = res |
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index fa6e6df1d..9add35184 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts | |||
@@ -1,27 +1,32 @@ | |||
1 | import { wait } from '@root-helpers/utils' | ||
1 | import { Segment } from 'p2p-media-loader-core' | 2 | import { Segment } from 'p2p-media-loader-core' |
2 | import { basename } from 'path' | 3 | import { basename } from 'path' |
3 | 4 | ||
4 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } | 5 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } |
5 | 6 | ||
7 | const maxRetries = 3 | ||
8 | |||
6 | function segmentValidatorFactory (segmentsSha256Url: string) { | 9 | function segmentValidatorFactory (segmentsSha256Url: string) { |
7 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 10 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
8 | const regex = /bytes=(\d+)-(\d+)/ | 11 | const regex = /bytes=(\d+)-(\d+)/ |
9 | 12 | ||
10 | return async function segmentValidator (segment: Segment, canRefetchSegmentHashes = true) { | 13 | return async function segmentValidator (segment: Segment, retry = 1) { |
11 | const filename = basename(segment.url) | 14 | const filename = basename(segment.url) |
12 | 15 | ||
13 | const segmentValue = (await segmentsJSON)[filename] | 16 | const segmentValue = (await segmentsJSON)[filename] |
14 | 17 | ||
15 | if (!segmentValue && !canRefetchSegmentHashes) { | 18 | if (!segmentValue && retry > maxRetries) { |
16 | throw new Error(`Unknown segment name ${filename} in segment validator`) | 19 | throw new Error(`Unknown segment name ${filename} in segment validator`) |
17 | } | 20 | } |
18 | 21 | ||
19 | if (!segmentValue) { | 22 | if (!segmentValue) { |
20 | console.log('Refetching sha segments.') | 23 | await wait(1000) |
24 | |||
25 | console.log('Refetching sha segments for %s.', filename) | ||
21 | 26 | ||
22 | // Refetch | ||
23 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 27 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
24 | segmentValidator(segment, false) | 28 | await segmentValidator(segment, retry + 1) |
29 | |||
25 | return | 30 | return |
26 | } | 31 | } |
27 | 32 | ||
diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts index 6df151ad9..de4e08bf5 100644 --- a/client/src/root-helpers/utils.ts +++ b/client/src/root-helpers/utils.ts | |||
@@ -44,7 +44,14 @@ function importModule (path: string) { | |||
44 | }) | 44 | }) |
45 | } | 45 | } |
46 | 46 | ||
47 | function wait (ms: number) { | ||
48 | return new Promise(res => { | ||
49 | setTimeout(() => res(), ms) | ||
50 | }) | ||
51 | } | ||
52 | |||
47 | export { | 53 | export { |
48 | importModule, | 54 | importModule, |
49 | objectToUrlEncoded | 55 | objectToUrlEncoded, |
56 | wait | ||
50 | } | 57 | } |