Skip to content

Commit

Permalink
feat(FEC-8553): add ability to force redirect kaltura playManifest ur…
Browse files Browse the repository at this point in the history
…ls (#64)


Use kaltura JSONP service to allow getting the redirected playManifest URL directly.
This is to avoid issues with UA that consider CORS 302 responses as unsecured(IE11)
  • Loading branch information
OrenMe authored Nov 7, 2018
1 parent a6929c5 commit 5d9cc5c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function(config) {
client: {
mocha: {
reporter: 'html',
timeout: 5000
timeout: 10000
}
}
};
Expand Down
46 changes: 39 additions & 7 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,20 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
* @static
*/
static createAdapter(videoElement: HTMLVideoElement, source: PKMediaSourceObject, config: Object): IMediaSourceAdapter {
let dashConfig = {};
let adapterConfig = {};
if (Utils.Object.hasPropertyPath(config, 'playback.options.html5.dash')) {
dashConfig = config.playback.options.html5.dash;
adapterConfig.shakaConfig = config.playback.options.html5.dash;
}
if (Utils.Object.hasPropertyPath(config, 'playback.useNativeTextTrack')) {
dashConfig.textTrackVisibile = Utils.Object.getPropertyPath(config, 'playback.useNativeTextTrack');
adapterConfig.textTrackVisibile = Utils.Object.getPropertyPath(config, 'playback.useNativeTextTrack');
}
return new this(videoElement, source, dashConfig);
if (Utils.Object.hasPropertyPath(config, 'sources.options')) {
const options = config.sources.options;
adapterConfig.forceRedirectExternalStreams = options.forceRedirectExternalStreams;
adapterConfig.redirectExternalStreamsHandler = options.redirectExternalStreamsHandler;
adapterConfig.redirectExternalStreamsTimeout = options.redirectExternalStreamsTimeout;
}
return new this(videoElement, source, adapterConfig);
}

/**
Expand Down Expand Up @@ -260,10 +266,34 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
shaka.polyfill.installAll();
this._shaka = new shaka.Player(this._videoElement);
this._maybeSetDrmConfig();
this._shaka.configure(this._config);
this._shaka.configure(this._config.shakaConfig);
this._addBindings();
}

/**
* get the redirected URL
* @param {string} url - The url to check for redirection
* @returns {Promise<string>} - the resolved url
* @private
*/
_maybeGetRedirectedUrl(url: string): Promise<string> {
const shouldRedirect = this._config.forceRedirectExternalStreams;
const timeout = this._config.redirectExternalStreamsTimeout;
const callback = this._config.redirectExternalStreamsHandler;
return new Promise(resolve => {
if (!shouldRedirect) {
return resolve(url);
}
Utils.Http.jsonp(url, callback, {
timeout: timeout
})
.then(uri => {
resolve(uri);
})
.catch(() => resolve(url));
});
}

/**
* Configure drm for shaka player.
* @private
Expand Down Expand Up @@ -316,8 +346,10 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
if (this._sourceObj && this._sourceObj.url) {
this._trigger(EventType.ABR_MODE_CHANGED, {mode: this.isAdaptiveBitrateEnabled() ? 'auto' : 'manual'});
const shakaStartTime = startTime && startTime > -1 ? startTime : undefined;
this._shaka
.load(this._sourceObj.url, shakaStartTime)
this._maybeGetRedirectedUrl(this._sourceObj.url)
.then(url => {
return this._shaka.load(url, shakaStartTime);
})
.then(() => {
let data = {tracks: this._getParsedTracks()};
DashAdapter._logger.debug('The source has been loaded successfully');
Expand Down
9 changes: 6 additions & 3 deletions src/default-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"streaming": {
"ignoreTextStreamFailures": true
}
"shakaConfig": {
"streaming": {
"ignoreTextStreamFailures": true
}
},
"forceRedirectExternalStreams": false
}

0 comments on commit 5d9cc5c

Please sign in to comment.