Skip to content

Commit

Permalink
fix(FEC-10968): OTT doesn't have default external-stream-redirect-hel…
Browse files Browse the repository at this point in the history
…per (#416)

getting the default `sources.options.redirectExternalStreamsHandler` from common (as before #370)

Solves FEC-10968
  • Loading branch information
yairans authored Feb 18, 2021
1 parent 3106997 commit f13a81d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 16 deletions.
27 changes: 26 additions & 1 deletion src/common/utils/external-stream-redirect-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import {Utils} from '@playkit-js/playkit-js';

/**
* JSONP handler function, returns the direct manifest uri.
Expand Down Expand Up @@ -35,4 +36,28 @@ function getDirectManifestUri(data: Object, uri: string): string {
}
return uri;
}
export {getDirectManifestUri};

/**
* Get the redirect external stream handler.
* @public
* @param {KPOptionsObject} playerOptions - The player config.
* @param {KPOptionsObject} mediaOptions - The media config.
* @returns {void}
*/
function getRedirectExternalStreamsHandler(playerOptions: KPOptionsObject, mediaOptions: KPOptionsObject = {}): Object {
const configObj = {};
const playerRedirectExternalStreamsHandler = Utils.Object.getPropertyPath(playerOptions, 'sources.options.redirectExternalStreamsHandler');
const mediaRedirectExternalStreamsHandler = Utils.Object.getPropertyPath(mediaOptions, 'sources.options.redirectExternalStreamsHandler');
if (typeof playerRedirectExternalStreamsHandler !== 'function' && typeof mediaRedirectExternalStreamsHandler !== 'function') {
Utils.Object.mergeDeep(configObj, {
sources: {
options: {
redirectExternalStreamsHandler: getDirectManifestUri
}
}
});
}
return configObj;
}

export {getRedirectExternalStreamsHandler};
7 changes: 5 additions & 2 deletions src/ott/player-defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import {Utils} from '@playkit-js/playkit-js';
import {getRedirectExternalStreamsHandler} from '../common/utils/external-stream-redirect-helper';

/**
* Sets the default analytics plugin for the ott player.
Expand Down Expand Up @@ -31,8 +32,10 @@ export function setDefaultAnalyticsPlugin(options: KPOptionsObject): void {
/**
* get the default config for forcing external stream redirect.
* @public
* @param {KPOptionsObject} playerOptions - The player config.
* @param {KPOptionsObject} mediaOptions - The media config.
* @returns {Object} - config object
*/
export function getDefaultRedirectOptions(): Object {
return {};
export function getDefaultRedirectOptions(playerOptions: KPOptionsObject, mediaOptions: KPOptionsObject = {}): Object {
return Utils.Object.mergeDeep({}, getRedirectExternalStreamsHandler(playerOptions, mediaOptions));
}
15 changes: 2 additions & 13 deletions src/ovp/player-defaults.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import {Env, Utils, MediaType} from '@playkit-js/playkit-js';
import {getDirectManifestUri} from '../common/utils/external-stream-redirect-helper';
import {getRedirectExternalStreamsHandler} from '../common/utils/external-stream-redirect-helper';

/**
* Sets the default analytics plugin for the ovp player.
Expand Down Expand Up @@ -41,16 +41,5 @@ export function getDefaultRedirectOptions(playerOptions: KPOptionsObject, mediaO
});
}
}
const playerRedirectExternalStreamsHandler = Utils.Object.getPropertyPath(playerOptions, 'sources.options.redirectExternalStreamsHandler');
const mediaRedirectExternalStreamsHandler = Utils.Object.getPropertyPath(mediaOptions, 'sources.options.redirectExternalStreamsHandler');
if (typeof playerRedirectExternalStreamsHandler !== 'function' && typeof mediaRedirectExternalStreamsHandler !== 'function') {
Utils.Object.mergeDeep(configObj, {
sources: {
options: {
redirectExternalStreamsHandler: getDirectManifestUri
}
}
});
}
return configObj;
return Utils.Object.mergeDeep(configObj, getRedirectExternalStreamsHandler(playerOptions, mediaOptions));
}
33 changes: 33 additions & 0 deletions test/src/ott/player-defaults.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {getDefaultRedirectOptions} from './../../../src/ott/player-defaults';

describe('redirectExternalStreamsHandler', function () {
it('should return the default', function () {
const defaultConfig = getDefaultRedirectOptions({});
(typeof defaultConfig.sources.options.redirectExternalStreamsHandler === 'function').should.be.true;
});

it('should return void if already configured on player config', function () {
const defaultConfig = getDefaultRedirectOptions({
sources: {
options: {
redirectExternalStreamsHandler: () => {}
}
}
});
(defaultConfig.sources === undefined).should.be.true;
});

it('should return void if already configured on media config', function () {
const defaultConfig = getDefaultRedirectOptions(
{},
{
sources: {
options: {
redirectExternalStreamsHandler: () => {}
}
}
}
);
(defaultConfig.sources === undefined).should.be.true;
});
});

0 comments on commit f13a81d

Please sign in to comment.