Skip to content

Commit

Permalink
fix(FEC-8026): external OTT VOD/Live media doesn't works on IE 11 (#204)
Browse files Browse the repository at this point in the history
Set default value to false.
Update docs.
Reduce timeout in JSONP util.
  • Loading branch information
Dan Ziv authored Mar 14, 2018
1 parent 771e915 commit fd8bbd6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
18 changes: 14 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var config = {
hls: [],
dash: [],
progressive: [],
options: {}
options: {
forceRedirectExternalStreams: false
}
},
plugins: {},
metadata: {},
Expand Down Expand Up @@ -117,7 +119,8 @@ var config = {
>>```js
>>{
>> forceRedirectExternalStreams: boolean,
>> redirectExternalStreamsHandler: ?Function
>> redirectExternalStreamsHandler: ?Function,
>> redirectExternalStreamsTimeout: ?number
>>}
>>```
>##### Default:
Expand All @@ -126,7 +129,9 @@ var config = {
> hls: [],
> dash: [],
> progressive: [],
> options: {}
> options: {
> forceRedirectExternalStreams: false
> }
>}
>```
>##### Description: Defines related sources configurations.
Expand Down Expand Up @@ -192,13 +197,18 @@ var config = {
>>##
>>>### config.sources.options.forceRedirectExternalStreams
>>>##### Type: `boolean`
>>>##### Default: `-`
>>>##### Default: `false`
>>>##### Description: Whether to force a source redirect for an external streams.
>>>##
>>>### config.sources.options.redirectExternalStreamsHandler
>>>##### Type: `Function`
>>>##### Default: `-`
>>>##### Description: The handler function which redirects the stream.
>>>##
>>>### config.sources.options.redirectExternalStreamsTimeout
>>>##### Type: `number`
>>>##### Default: `-`
>>>##### Description: The timeout for the redirect operation.
##
>### config.plugins
>##### Type: `PKPluginsObject`
Expand Down
3 changes: 2 additions & 1 deletion flow-typed/types/media-source-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
declare type PKMediaSourceOptionsObject = {
forceRedirectExternalStreams: boolean,
redirectExternalStreamsCallback: ?Function
redirectExternalStreamsHandler: ?Function,
redirectExternalStreamsTimeout: ?number
};
4 changes: 3 additions & 1 deletion src/player-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"hls": [],
"dash": [],
"progressive": [],
"options": {}
"options": {
"forceRedirectExternalStreams": false
}
},
"plugins": {},
"metadata": {},
Expand Down
18 changes: 8 additions & 10 deletions src/utils/jsonp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import Error from '../error/error'

const JSONP_TIMEOUT: number = 15000;
const JSONP_TIMEOUT: number = 5000;
const CALLBACK_PREFIX: string = 'jsonpcallback';
const JSONP_FORMAT_STRING: string = 'responseFormat=jsonp&callback=';

Expand All @@ -14,30 +14,28 @@ const JSONP_FORMAT_STRING: string = 'responseFormat=jsonp&callback=';
*/
function jsonp(url: string, callback: Function, options: Object): Promise<*> {
options = options || {};

const timeout = options.timeout ? options.timeout : JSONP_TIMEOUT;
const noop = () => {
};
const script = document.createElement("script");
const callbackId = CALLBACK_PREFIX + Math.round(Date.now() + Math.random() * 1000001);
let scriptUri = url;
let timer;
const callbackId = CALLBACK_PREFIX + Math.round(Date.now() + Math.random() * 1000001);

/**
* function to clean the DOM from the script tag and from the function
* @returns {void}
*/
const _cleanup = function (): void {
const _cleanup = () => {
if (script && script.parentNode) {
script.parentNode.removeChild(script);
}
window[callbackId] = noop;
window[callbackId] = () => {
};
if (timer) {
clearTimeout(timer);
}
};

return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
if (timeout) {
timer = setTimeout(function () {
_cleanup();
Expand All @@ -55,8 +53,8 @@ function jsonp(url: string, callback: Function, options: Object): Promise<*> {
* @param {Object} data - the data we get from the server, in response to the request
* @returns {void}
*/
window[callbackId] = function (data: Object): void {
let callbackResult = callback(data, url);
window[callbackId] = (data: Object) => {
const callbackResult = callback(data, url);
_cleanup();
resolve(callbackResult);
};
Expand Down

0 comments on commit fd8bbd6

Please sign in to comment.