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(FEC-7815): Support playManifest redirects for external streams #85

Merged
merged 29 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3e79b0c
configuring jsonp
odedhutzler Jan 31, 2018
c4b4b9d
add hls configuration support
odedhutzler Feb 1, 2018
65e6956
Unifing the adapters redirect config.
odedhutzler Feb 6, 2018
a177bb4
change config key name
odedhutzler Feb 6, 2018
0282ff7
Merge branch 'master' of https://github.com/kaltura/kaltura-player-js…
odedhutzler Feb 8, 2018
0c4f4ea
merge
odedhutzler Feb 8, 2018
be3e78f
removed unneccery files
odedhutzler Feb 8, 2018
47b75b7
changing the browser sniffing
odedhutzler Feb 8, 2018
1e5e163
move to setup defaults
OrenMe Feb 28, 2018
3eb1204
code cleanup
OrenMe Feb 28, 2018
1e32fa0
protect against access to null/undefined
OrenMe Feb 28, 2018
51e3054
code cleanup
OrenMe Feb 28, 2018
1a1cdfe
Merge branch 'master' into FEC-7815
OrenMe Feb 28, 2018
9121f62
remove test page
OrenMe Feb 28, 2018
484767d
more concise config name
OrenMe Feb 28, 2018
7facc56
renmae file
OrenMe Feb 28, 2018
29f8db7
fix condition check
OrenMe Feb 28, 2018
6794d7a
move config location
OrenMe Feb 28, 2018
3fcdd5f
Merge branch 'master' into FEC-7815
OrenMe Feb 28, 2018
4d5cf0f
Update external-stream-redirect-helper.js
Mar 1, 2018
f45592f
Code cleanup
Mar 4, 2018
cd9bd83
Merge branch 'FEC-7815' of https://github.com/kaltura/kaltura-player-…
Mar 4, 2018
50f9cf8
Update external-stream-redirect-helper.js
Mar 4, 2018
0a8cf79
Merge branch 'master' into FEC-7815
Mar 5, 2018
c7ea59e
Merge branch 'master' of https://github.com/kaltura/kaltura-player-js…
Mar 6, 2018
0f82a4f
Fix flow
Mar 6, 2018
8556f06
Update config names
Mar 6, 2018
878ad3c
Update setup-helpers.js
Mar 6, 2018
49654b2
Update external-stream-redirect-helper.js
Mar 6, 2018
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
53 changes: 53 additions & 0 deletions src/common/utils/jsonp-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// @flow
import {Env} from 'playkit-js'

/**
* jsonp callback function, returns the direct manifest uri
* @param {Object} data - the json object that returns from the server
* @param {string} uri - original request uri
* @returns {string} returns the direct uri
*/
function getDirectManfiestUri(data: Object, uri: string): string {
const getHostName = uri => {
const parser = document.createElement('a');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser? looks like an element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's purpose is to parse the url

parser.href = uri;
return parser.hostname
};
// if the json contains one url, it means it is a redirect url. if it contains few urls, it means its the flavours
//so we should use the original url.
const uriHost = getHostName(uri);
const hasOneFlavor = data && data.flavors && (data.flavors.length === 1);
const flavorUriHost = hasOneFlavor && getHostName(data.flavors[0].url);
if (hasOneFlavor && (uriHost !== flavorUriHost)) {
return data.flavors[0].url;
} else {
return uri;
}
}

/**
* returns if we should use our jsonp http plugin
* @returns {boolean} should use external stream requests redirect on manifests
*/
function shouldUseExternalStreamRedirect(): boolean {
const affectedBrowsers = ['IE', 'Edge'];
const affectedVendors = ['panasonic'];
return (affectedBrowsers.includes(Env.browser.name) ||
(Env.device.vendor && affectedVendors.includes(Env.device.vendor)));
}

/**
* add jsonp configuration to the general config
* @param {Object} config - configuration relevant to jsonp
* @returns {void}
*/
function configureExternalStreamRedirect(config: Object): void {
config.playback.options = config.playback.options || {};
let adapters = config.playback.options.adapters = config.playback.options.adapters || {};
if (typeof adapters.forceRedirectExternalStreams !== "boolean") {
Copy link
Contributor

@dan-ziv dan-ziv Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrenMe
We should discuss those configuration names and placement.
I think it should be forceRedirectToExternalStreams and under sources config (it related directly to sources).
Adapters is internal and technical name that we've given to the MSEs but not should be exposed as external configuration.

config.playback.options.adapters.forceRedirectExternalStreams = shouldUseExternalStreamRedirect();
}
config.playback.options.adapters.redirectExternalStreamsCallback = getDirectManfiestUri;
}

export {configureExternalStreamRedirect}
2 changes: 2 additions & 0 deletions src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import StorageManager from '../storage/storage-manager'
import {setLogLevel as _setLogLevel, LogLevel} from './logger'
import type {LogLevelObject} from './logger'
import {DEFAULT_THUMBS_SLICES, DEFAULT_THUMBS_WIDTH, getThumbSlicesUrl} from './thumbs'
import {configureExternalStreamRedirect} from "./jsonp-helper";

const CONTAINER_CLASS_NAME: string = 'kaltura-player-container';
const KALTURA_PLAYER_DEBUG_QS: string = 'debugKalturaPlayer';
Expand Down Expand Up @@ -251,6 +252,7 @@ function getDefaultOptions(options: PartialKalturaPlayerOptionsObject): KalturaP
checkNativeHlsSupport(defaultOptions.player);
checkNativeTextTracksSupport(defaultOptions.player);
setDefaultAnalyticsPlugin(defaultOptions.player);
configureExternalStreamRedirect(defaultOptions.player);
return defaultOptions;
}

Expand Down