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

feat(FEC-10656): set forceRedirectExternalStreams as true by default on IE11 and Chromecast #370

Merged
merged 10 commits into from
Nov 25, 2020
25 changes: 1 addition & 24 deletions src/common/utils/external-stream-redirect-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
import {Utils} from '@playkit-js/playkit-js';

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

/**
* Add external stream redirect configuration to the general config.
* @private
* @param {KPOptionsObject} options - kaltura player options.
* @returns {void}
*/
function configureExternalStreamRedirect(options: KPOptionsObject): void {
let sourceOptions = Utils.Object.getPropertyPath(options, 'sources.options');
if (!sourceOptions) {
Utils.Object.mergeDeep(options, {
sources: {
options: {}
}
});
sourceOptions = options.sources && options.sources.options;
}
if (sourceOptions && typeof sourceOptions.redirectExternalStreamsHandler !== 'function') {
sourceOptions.redirectExternalStreamsHandler = getDirectManifestUri;
}
}

export {configureExternalStreamRedirect};
export {getDirectManifestUri};
2 changes: 0 additions & 2 deletions src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '@playkit-js/playkit-js';
import {ValidationErrorType} from './validation-error';
import StorageManager from '../storage/storage-manager';
import {configureExternalStreamRedirect} from './external-stream-redirect-helper';
import {RemotePlayerManager} from '../cast/remote-player-manager';
import {RemoteControl} from '../cast/remote-control';
import {KalturaPlayer} from '../../kaltura-player';
Expand Down Expand Up @@ -299,7 +298,6 @@ function getDefaultOptions(options: PartialKPOptionsObject): KPOptionsObject {
configureIMADefaultOptions(defaultOptions);
configureDAIDefaultOptions(defaultOptions);
configureBumperDefaultOptions(defaultOptions);
configureExternalStreamRedirect(defaultOptions);
maybeSetFullScreenConfig(defaultOptions);
maybeSetCapabilitiesForIos(defaultOptions);
return defaultOptions;
Expand Down
2 changes: 2 additions & 0 deletions src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {RemoteSession} from './common/cast/remote-session';
import {ControllerProvider, AdsController} from './common/controllers';
import {BasePlugin} from './common/plugins';
import {PluginManager} from './common/plugins';
import {getDefaultRedirectOptions} from 'player-defaults';
import {
Error,
EventManager,
Expand Down Expand Up @@ -106,6 +107,7 @@ class KalturaPlayer extends FakeEventTarget {
}
mediaConfig.sources = Utils.Object.mergeDeep(mediaConfig.sources, mediaOptions);
}
this.configure(getDefaultRedirectOptions(this.config, mediaConfig));
this.setMedia(mediaConfig);
},
e =>
Expand Down
9 changes: 9 additions & 0 deletions src/ott/player-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ export function setDefaultAnalyticsPlugin(options: KPOptionsObject): void {
});
}
}

/**
* get the default config for forcing external stream redirect.
* @public
* @returns {Object} - config object
*/
export function getDefaultRedirectOptions(): Object {
return {};
}
39 changes: 38 additions & 1 deletion src/ovp/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 {Env, Utils, MediaType} from '@playkit-js/playkit-js';
import {getDirectManifestUri} from '../common/utils/external-stream-redirect-helper';

/**
* Sets the default analytics plugin for the ovp player.
Expand All @@ -17,3 +18,39 @@ 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(playerOptions: KPOptionsObject, mediaOptions: KPOptionsObject = {}): Object {
const configObj = {};
if (mediaOptions.sources && mediaOptions.sources.type === MediaType.LIVE && (Env.browser.name === 'IE' || Env.device.model === 'Chromecast')) {
const playerForceRedirectExternalStreams = Utils.Object.getPropertyPath(playerOptions, 'sources.options.forceRedirectExternalStreams');
const mediaForceRedirectExternalStreams = Utils.Object.getPropertyPath(mediaOptions, 'sources.options.forceRedirectExternalStreams');
if (typeof playerForceRedirectExternalStreams !== 'boolean' && typeof mediaForceRedirectExternalStreams !== 'boolean') {
Utils.Object.mergeDeep(configObj, {
sources: {
options: {
forceRedirectExternalStreams: true
}
}
});
}
}
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;
}
84 changes: 84 additions & 0 deletions test/src/ovp/player-defaults.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {getDefaultRedirectOptions} from './../../../src/ovp/player-defaults';
import {Env, MediaType} from '@playkit-js/playkit-js';

describe('getDefaultRedirectOptions', function () {
let sandbox;
beforeEach(function () {
sandbox = sinon.createSandbox();
});

afterEach(function () {
sandbox.restore();
});
describe('forceRedirectExternalStreams', function () {
it('should return void for vod on ie11', function () {
sandbox.stub(Env, 'browser').get(() => ({name: 'IE'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.VOD}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return void for vod on chromecast', function () {
sandbox.stub(Env, 'device').get(() => ({model: 'Chromecast'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.VOD}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return void for live chrome', function () {
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.LIVE}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return true for live on ie11', function () {
sandbox.stub(Env, 'browser').get(() => ({name: 'IE'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.LIVE}});
defaultConfig.sources.options.forceRedirectExternalStreams.should.be.true;
});

it('should return true for live on chromecast', function () {
sandbox.stub(Env, 'device').get(() => ({model: 'Chromecast'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.LIVE}});
defaultConfig.sources.options.forceRedirectExternalStreams.should.be.true;
});

it('should return void for live on ie11 if already configured on player config', function () {
sandbox.stub(Env, 'browser').get(() => ({name: 'IE'}));
const defaultConfig = getDefaultRedirectOptions({sources: {options: {forceRedirectExternalStreams: false}}}, {sources: {type: MediaType.LIVE}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return void for live on ie11 if already configured on media config', function () {
sandbox.stub(Env, 'browser').get(() => ({name: 'IE'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.LIVE, options: {forceRedirectExternalStreams: false}}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return void for live on chromecast if already configured on player config', function () {
sandbox.stub(Env, 'device').get(() => ({model: 'Chromecast'}));
const defaultConfig = getDefaultRedirectOptions({sources: {options: {forceRedirectExternalStreams: false}}}, {sources: {type: MediaType.LIVE}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});

it('should return void for live on chromecast if already configured on media config', function () {
sandbox.stub(Env, 'device').get(() => ({model: 'Chromecast'}));
const defaultConfig = getDefaultRedirectOptions({}, {sources: {type: MediaType.LIVE, options: {forceRedirectExternalStreams: false}}});
(defaultConfig.sources.options.forceRedirectExternalStreams === undefined).should.be.true;
});
});

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;
});
});
});