-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from 15 commits
3e79b0c
c4b4b9d
65e6956
a177bb4
0282ff7
0c4f4ea
be3e78f
47b75b7
1e5e163
3eb1204
1e32fa0
51e3054
1a1cdfe
9121f62
484767d
7facc56
29f8db7
6794d7a
3fcdd5f
4d5cf0f
f45592f
cd9bd83
50f9cf8
0a8cf79
c7ea59e
0f82a4f
8556f06
878ad3c
49654b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'); | ||
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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OrenMe |
||
config.playback.options.adapters.forceRedirectExternalStreams = shouldUseExternalStreamRedirect(); | ||
} | ||
config.playback.options.adapters.redirectExternalStreamsCallback = getDirectManfiestUri; | ||
} | ||
|
||
export {configureExternalStreamRedirect} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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