Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#45): resolve redirect before handing over to engine #46

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Channel Engine v4.3.11 including the following bugfixes and features:
- Option to protect session health endpoint with a key
- Fix timeOffset - Once enabled, Forever
- Fix missing Newlines in Dummy Webvtt Response
- Fix performance bottlenecks when running in High Availability mode with Redis.
- Fix performance bottlenecks when running in High Availability mode with Redis.
- Fix disable eventstream by default
- Fix HA & Demux - Audio Increment Not Respecting Position Diff-Threshold
- Fix Subtitle Track Playhead is dependant Of Video Track
Expand All @@ -28,7 +28,7 @@ New Features:

### Version 1.8.1

Verify URLs that must be HLS URLs
Verify URLs that must be HLS URLs

### Version 1.8.2

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/plugin_loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
getDefaultChannelAudioProfile,
getDefaultChannelVideoProfile,
getDefaultChannelSubtitleProfile,
getVodUrlWithPreroll
getVodUrlWithPreroll,
resolveRedirect
} from './utils';

class LoopAssetManager implements IAssetManager {
Expand All @@ -30,6 +31,7 @@ class LoopAssetManager implements IAssetManager {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getNextVod(vodRequest: VodRequest): Promise<VodResponse> {
let hlsUrl = this.vodToLoop.toString();
hlsUrl = await resolveRedirect(this.vodToLoop.toString());
if (this.prerollVod) {
hlsUrl = getVodUrlWithPreroll(
this.vodToLoop.toString(),
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/plugin_playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
getDefaultChannelAudioProfile,
getDefaultChannelSubtitleProfile,
getDefaultChannelVideoProfile,
getVodUrlWithPreroll
getVodUrlWithPreroll,
resolveRedirect
} from './utils';

interface PlaylistUrl {
Expand Down Expand Up @@ -92,7 +93,9 @@ class PlaylistAssetManager implements IAssetManager {
await this._updatePlaylist(vodRequest.playlistId);
}
if (playlist.position !== -1) {
let hlsUrl = playlist.hlsUrls[playlist.position].toString();
let hlsUrl = await resolveRedirect(
playlist.hlsUrls[playlist.position].toString()
);
if (this.prerollVod) {
hlsUrl = getVodUrlWithPreroll(
playlist.hlsUrls[playlist.position].toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/plugin_webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('webhook plugin', () => {
expect(fetchMock.mock.calls[0][0]).toEqual(
'http://localhost:8002/nextVod?channelId=test'
);
expect(fetchMock.mock.calls[1][0]).toEqual(
expect(fetchMock.mock.calls[2][0]).toEqual(
'http://localhost:8002/nextVod?channelId=test'
);
});
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/plugin_webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
getDefaultChannelAudioProfile,
getDefaultChannelVideoProfile,
getDefaultChannelSubtitleProfile,
getVodUrlWithPreroll
getVodUrlWithPreroll,
resolveRedirect
} from './utils';

export interface WebHookNextVodResponse {
Expand Down Expand Up @@ -52,7 +53,7 @@ class WebHookAssetManager implements IAssetManager {
});
if (response.ok) {
const payload: WebHookNextVodResponse = await response.json();
let hlsUrl = payload.hlsUrl;
let hlsUrl = await resolveRedirect(payload.hlsUrl);
if (payload.prerollUrl && payload.prerollDurationMs) {
hlsUrl = getVodUrlWithPreroll(
hlsUrl,
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,12 @@ export function getVodUrlWithPreroll(
}
return url;
}

export async function resolveRedirect(url: string) {
const response = await fetch(url);
if (response.redirected) {
console.log('Redirect: ' + response.url);
return response.url || url;
}
return url;
}