diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-23 10:19:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-23 10:28:21 +0200 |
commit | da3324177025b15ca23d84dd4249e3c7ba95053c (patch) | |
tree | d83265f1e24e27eb6162f09299ec54728cd3d139 /client/src/assets/player/p2p-media-loader/segment-url-builder.ts | |
parent | 20ec03846ddb40d8aeaa87fc92b8bd7994c3ecf7 (diff) | |
download | PeerTube-da3324177025b15ca23d84dd4249e3c7ba95053c.tar.gz PeerTube-da3324177025b15ca23d84dd4249e3c7ba95053c.tar.zst PeerTube-da3324177025b15ca23d84dd4249e3c7ba95053c.zip |
Improve HLS redundancy
Diffstat (limited to 'client/src/assets/player/p2p-media-loader/segment-url-builder.ts')
-rw-r--r-- | client/src/assets/player/p2p-media-loader/segment-url-builder.ts | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts index fb990a19d..039777cea 100644 --- a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts +++ b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts | |||
@@ -1,17 +1,9 @@ | |||
1 | import { basename } from 'path' | ||
2 | import { Segment } from 'p2p-media-loader-core' | 1 | import { Segment } from 'p2p-media-loader-core' |
2 | import { RedundancyUrlManager } from './redundancy-url-manager' | ||
3 | 3 | ||
4 | function segmentUrlBuilderFactory (baseUrls: string[]) { | 4 | function segmentUrlBuilderFactory (redundancyUrlManager: RedundancyUrlManager) { |
5 | return function segmentBuilder (segment: Segment) { | 5 | return function segmentBuilder (segment: Segment) { |
6 | const max = baseUrls.length + 1 | 6 | return redundancyUrlManager.buildUrl(segment.url) |
7 | const i = getRandomInt(max) | ||
8 | |||
9 | if (i === max - 1) return segment.url | ||
10 | |||
11 | const newBaseUrl = baseUrls[i] | ||
12 | const middlePart = newBaseUrl.endsWith('/') ? '' : '/' | ||
13 | |||
14 | return newBaseUrl + middlePart + basename(segment.url) | ||
15 | } | 7 | } |
16 | } | 8 | } |
17 | 9 | ||
@@ -20,9 +12,3 @@ function segmentUrlBuilderFactory (baseUrls: string[]) { | |||
20 | export { | 12 | export { |
21 | segmentUrlBuilderFactory | 13 | segmentUrlBuilderFactory |
22 | } | 14 | } |
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | function getRandomInt (max: number) { | ||
27 | return Math.floor(Math.random() * Math.floor(max)) | ||
28 | } | ||