aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/p2p-media-loader/segment-url-builder.ts
diff options
context:
space:
mode:
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.ts20
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 @@
1import { basename } from 'path'
2import { Segment } from 'p2p-media-loader-core' 1import { Segment } from 'p2p-media-loader-core'
2import { RedundancyUrlManager } from './redundancy-url-manager'
3 3
4function segmentUrlBuilderFactory (baseUrls: string[]) { 4function 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[]) {
20export { 12export {
21 segmentUrlBuilderFactory 13 segmentUrlBuilderFactory
22} 14}
23
24// ---------------------------------------------------------------------------
25
26function getRandomInt (max: number) {
27 return Math.floor(Math.random() * Math.floor(max))
28}