Skip to content

Commit

Permalink
chore: reverted ProxyBasenames
Browse files Browse the repository at this point in the history
  • Loading branch information
zapfire88 committed Feb 20, 2024
1 parent fc0fb87 commit e357fde
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 69 deletions.
34 changes: 6 additions & 28 deletions src/manifests/utils/dashManifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,11 @@ export default function (): DASHManifestTools {
const proxy = proxyPathBuilder(
mediaUrl.match(/^http/) ? mediaUrl : baseUrl + mediaUrl,
urlQuery,
// 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$_$Time$'
hasTime
? {
base: 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$',
time: true,
representationId: true,
bandwidth: true
}
: {
base: 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$',
number: true,
representationId: true,
bandwidth: true
}
// ? 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$'
// : `proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$`
? 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$'
: 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$'
);
segmentTemplate.$.media = proxy.url;
segmentTemplate.$.media = proxy;
// Initialization attr.
const initUrl = segmentTemplate.$.initialization;
if (!initUrl.match(/^http/)) {
Expand Down Expand Up @@ -164,19 +151,10 @@ export default function (): DASHManifestTools {
mediaUrl,
urlQuery,
hasTime
? {
base: 'proxy-segment/segment_$Time$.mp4',
time: true
}
: {
base: 'proxy-segment/segment_$Number$.mp4',
number: true
}
// ? 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$'
// : `proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$`
// 'proxy-segment/segment_$Number$.mp4'
? 'proxy-segment/segment_$Time$.mp4'
: 'proxy-segment/segment_$Number$.mp4'
);
segmentTemplate.$.media = proxy.url;
segmentTemplate.$.media = proxy;
// Initialization attr.
const masterDashUrl = originalUrlQuery.get('url');
const initUrl = segmentTemplate.$.initialization;
Expand Down
26 changes: 14 additions & 12 deletions src/manifests/utils/hlsManifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ export default function (): HLSManifestTools {
if (stateKey) {
urlQuery.set('state', stateKey);
}
const proxy = proxyPathBuilder(currentUri, urlQuery, {
base: 'proxy-media.m3u8'
});
streamItem.set('uri', proxy.url);
const proxy = proxyPathBuilder(
currentUri,
urlQuery,
'proxy-media.m3u8'
);
streamItem.set('uri', proxy);
return streamItem;
});

Expand All @@ -119,10 +121,12 @@ export default function (): HLSManifestTools {
if (stateKey) {
urlQuery.set('state', stateKey);
}
const proxy = proxyPathBuilder(currentUri, urlQuery, {
base: 'proxy-media.m3u8'
});
mediaItem.set('uri', proxy.url);
const proxy = proxyPathBuilder(
currentUri,
urlQuery,
'proxy-media.m3u8'
);
mediaItem.set('uri', proxy);
return mediaItem;
});

Expand Down Expand Up @@ -162,11 +166,9 @@ export default function (): HLSManifestTools {
const proxy = proxyPathBuilder(
item.get('uri'),
new URLSearchParams(params),
{
base: '../../segments/proxy-segment'
}
'../../segments/proxy-segment'
);
item.set('uri', proxy.url);
item.set('uri', proxy);
}
return m3u.toString();
}
Expand Down
40 changes: 24 additions & 16 deletions src/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ describe('shared.utils', () => {
);

// Act
const actual = proxyPathBuilder(itemUri, urlSearchParams, {
base: 'proxy-media.m3u8'
});
const actual = proxyPathBuilder(
itemUri,
urlSearchParams,
'proxy-media.m3u8'
);
const expected = `proxy-media.m3u8?url=${encodeURIComponent(
'https://mock.stream.origin.se/hls/vods/asset41/video-variants/variant_3.m3u8'
)}&delay=${encodeURIComponent('[{i:3,ms:200}]')}`;

// Assert
expect(actual.url).toEqual(expected);
expect(actual).toEqual(expected);
});

it('should return correct format with value in all parameters, when source url is already an absolut url', () => {
Expand All @@ -30,15 +32,17 @@ describe('shared.utils', () => {
);

// Act
const actual = proxyPathBuilder(itemUri, urlSearchParams, {
base: 'proxy-media.m3u8'
});
const actual = proxyPathBuilder(
itemUri,
urlSearchParams,
'proxy-media.m3u8'
);
const expected = `proxy-media.m3u8?url=${encodeURIComponent(
'https://different.origin.se/hls/variant_3.m3u8'
)}&delay=${encodeURIComponent('[{i:3,ms:200}]')}`;

// Assert
expect(actual.url).toEqual(expected);
expect(actual).toEqual(expected);
});

it("should return correct format with value in all parameters, when source url string has '../'", () => {
Expand All @@ -49,15 +53,17 @@ describe('shared.utils', () => {
);

// Act
const actual = proxyPathBuilder(itemUri, urlSearchParams, {
base: 'proxy-media.m3u8'
});
const actual = proxyPathBuilder(
itemUri,
urlSearchParams,
'proxy-media.m3u8'
);
const expected = `proxy-media.m3u8?url=${encodeURIComponent(
'https://mock.stream.origin.se/hls/pathB/path3/variant_3.m3u8'
)}&delay=${encodeURIComponent('[{i:3,ms:200}]')}`;

// Assert
expect(actual.url).toEqual(expected);
expect(actual).toEqual(expected);
});

it('should handle empty parameters', () => {
Expand All @@ -66,13 +72,15 @@ describe('shared.utils', () => {
const urlSearchParams = null;

// Act
const actual = proxyPathBuilder(itemUri, urlSearchParams, {
base: 'proxy-media.m3u8'
});
const actual = proxyPathBuilder(
itemUri,
urlSearchParams,
'proxy-media.m3u8'
);
const expected = '';

// Assert
expect(actual.url).toEqual(expected);
expect(actual).toEqual(expected);
});
});
});
23 changes: 10 additions & 13 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,13 @@ export function refineALBEventQuery(
return queryStringParameters;
}

type ProxyBasenames = {
base: string;
url?: string;
number?: boolean;
numberWidth?: boolean;
time?: boolean;
representationId?: boolean;
bandwidth?: boolean;
};
type ProxyBasenames =
| 'proxy-media.m3u8'
| '../../segments/proxy-segment'
| 'proxy-segment/segment_$Number$.mp4'
| 'proxy-segment/segment_$Time$.mp4'
| 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$'
| 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$';

/**
* Adjust paths based on directory navigation
Expand Down Expand Up @@ -223,9 +221,9 @@ export function proxyPathBuilder(
itemUri: string,
urlSearchParams: URLSearchParams,
proxy: ProxyBasenames
): ProxyBasenames {
): string {
if (!urlSearchParams) {
return { base: '', url: '' };
return '';
}
const allQueries = new URLSearchParams(urlSearchParams);
let sourceItemURL = '';
Expand All @@ -242,8 +240,7 @@ export function proxyPathBuilder(
allQueries.set('url', sourceItemURL);
}
const allQueriesString = allQueries.toString();
proxy.url = `${proxy.base}${allQueriesString ? `?${allQueriesString}` : ''}`;
return proxy;
return `${proxy}${allQueriesString ? `?${allQueriesString}` : ''}`;
}

export function segmentUrlParamString(
Expand Down

0 comments on commit e357fde

Please sign in to comment.