Skip to content

Commit

Permalink
Fix: Set watermark-cache params for dash segments (#422)
Browse files Browse the repository at this point in the history
In theory, if a content-url-template is given with watermark-cache
(cache-busting) params from the server, all dash requests should carry
those cache-busting params. They did not however, because the
content-url-template is only used to construct the URL of the manifest -
the segment URLs are constructed by shaka-player itself, based on the
manifest url, but ignores all query-params on the manifest. This is why
we have a requestFilter function, but watermark-cache busting parameters
weren't taken into account. This commit adds a watermark cache-busting
parameter to every segment request, if the file is watermarked.
  • Loading branch information
bhh1988 authored Oct 3, 2017
1 parent 14322b8 commit ec68fd1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import autobind from 'autobind-decorator';
import VideoBaseViewer from './VideoBaseViewer';
import fullscreen from '../../Fullscreen';
import { get } from '../../util';
import { appendQueryParams, get } from '../../util';
import { getRepresentation } from '../../file';
import { MEDIA_STATIC_ASSETS_VERSION } from '../../constants';
import './Dash.scss';
Expand Down Expand Up @@ -78,6 +78,7 @@ class DashViewer extends VideoBaseViewer {
load() {
this.setup();
this.mediaUrl = this.options.representation.content.url_template;
this.watermarkCacheBust = Date.now();
this.mediaEl.addEventListener('loadeddata', this.loadeddataHandler);

return Promise.all([this.loadAssets(this.getJSAssets()), this.getRepStatus().getPromise()])
Expand Down Expand Up @@ -164,7 +165,13 @@ class DashViewer extends VideoBaseViewer {
requestFilter(type, request) {
const asset = type === shaka.net.NetworkingEngine.RequestType.MANIFEST ? MANIFEST : undefined;
/* eslint-disable no-param-reassign */
request.uris = request.uris.map((uri) => this.createContentUrlWithAuthParams(uri, asset));
request.uris = request.uris.map((uri) => {
let newUri = this.createContentUrlWithAuthParams(uri, asset);
if (asset !== MANIFEST && this.options.file.watermark_info.is_watermarked) {
newUri = appendQueryParams(newUri, { 'watermark-cache': this.watermarkCacheBust });
}
return newUri;
});
/* eslint-enable no-param-reassign */
}

Expand Down
37 changes: 37 additions & 0 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,47 @@ describe('lib/viewers/media/DashViewer', () => {
it('should append representation URLs with tokens', () => {
stubs.createUrl = sandbox.stub(dash, 'createContentUrlWithAuthParams').returns('auth_url');
stubs.req = { uris: ['uri'] };
dash.options = {
file: {
watermark_info: {
is_watermarked: false
},
representations: {
entries: [
{ representation: 'dash' },
]
}
}
}

dash.requestFilter('', stubs.req);

expect(stubs.createUrl).to.be.calledOnce;
expect(stubs.req.uris).to.deep.equal(['auth_url']);
});

it('should append watermark cache-busting query params if file is watermarked', () => {
stubs.createUrl = sandbox.stub(dash, 'createContentUrlWithAuthParams').returns('www.authed.com/?foo=bar');
stubs.req = { uris: ['uri'] };
dash.watermarkCacheBust = '123'
dash.options = {
file: {
watermark_info: {
is_watermarked: true
},
representations: {
entries: [
{ representation: 'dash' },
]
}
}
}

dash.requestFilter('', stubs.req);

expect(stubs.createUrl).to.be.calledOnce;
expect(stubs.req.uris).to.deep.equal(['www.authed.com/?foo=bar&watermark-cache=123']);
});
});

describe('getActiveTrack()', () => {
Expand Down

0 comments on commit ec68fd1

Please sign in to comment.