Skip to content

Commit

Permalink
Update: Do not prefetch for mp4 and mp3 viewers (#536)
Browse files Browse the repository at this point in the history
Prefetching for these viewers can lead to more problems than it's worth,
because for a single view the same token is used later when you seek
with a range-request (making it more likely for token-expiration issues
to occur).
  • Loading branch information
bhh1988 authored Dec 11, 2017
1 parent 85215b5 commit f5e487f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 76 deletions.
14 changes: 0 additions & 14 deletions src/lib/viewers/media/MP3Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ class MP3Viewer extends MediaBaseViewer {
this.mediaEl.setAttribute('preload', 'auto');
}

/**
* Prefetches assets for a mp3.
*
* @param {boolean} [options.content] - Whether or not to prefetch rep content
* @return {void}
*/
prefetch({ content = true }) {
const { representation } = this.options;
if (content && this.isRepresentationReady(representation)) {
const template = representation.content.url_template;
document.createElement('audio').src = this.createContentUrlWithAuthParams(template);
}
}

/**
* Loads the controls
*
Expand Down
14 changes: 0 additions & 14 deletions src/lib/viewers/media/MP4Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ class MP4Viewer extends VideoBaseViewer {
// mp4 specific class
this.wrapperEl.classList.add(CSS_CLASS_MP4);
}

/**
* Prefetches assets for a video.
*
* @param {boolean} [options.content] - Whether or not to prefetch rep content
* @return {void}
*/
prefetch({ content = true }) {
const { representation } = this.options;
if (content && this.isRepresentationReady(representation)) {
const template = representation.content.url_template;
document.createElement('video').src = this.createContentUrlWithAuthParams(template);
}
}
}

export default MP4Viewer;
24 changes: 0 additions & 24 deletions src/lib/viewers/media/__tests__/MP3Viewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ describe('lib/viewers/media/MP3Viewer', () => {
});
});

describe('prefetch()', () => {
beforeEach(() => {
mp3.options.representation = {
content: {
url_template: 'sometemplate'
}
};
});

it('should prefetch content if content is true and representation is ready', () => {
sandbox.stub(mp3, 'isRepresentationReady').returns(true);
sandbox.stub(mp3, 'createContentUrlWithAuthParams').returns('someContentUrl');
mp3.prefetch({ content: true });
expect(mp3.createContentUrlWithAuthParams).to.be.calledWith('sometemplate');
});

it('should not prefetch content if content is true but representation is not ready', () => {
sandbox.stub(mp3, 'isRepresentationReady').returns(false);
sandbox.stub(mp3, 'createContentUrlWithAuthParams');
mp3.prefetch({ content: true });
expect(mp3.createContentUrlWithAuthParams).to.not.be.called;
});
});

describe('loadUI()', () => {
const loadUIFunc = MediaBaseViewer.prototype.loadUI;

Expand Down
24 changes: 0 additions & 24 deletions src/lib/viewers/media/__tests__/MP4Viewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,4 @@ describe('lib/viewers/media/MP4Viewer', () => {
expect(mp4.wrapperEl).to.have.class('bp-media-mp4');
});
});

describe('prefetch()', () => {
beforeEach(() => {
mp4.options.representation = {
content: {
url_template: 'sometemplate'
}
};
});

it('should prefetch content if content is true and representation is ready', () => {
sandbox.stub(mp4, 'isRepresentationReady').returns(true);
sandbox.stub(mp4, 'createContentUrlWithAuthParams').returns('someContentUrl');
mp4.prefetch({ content: true });
expect(mp4.createContentUrlWithAuthParams).to.be.calledWith('sometemplate');
});

it('should not prefetch content if content is true but representation is not ready', () => {
sandbox.stub(mp4, 'isRepresentationReady').returns(false);
sandbox.stub(mp4, 'createContentUrlWithAuthParams');
mp4.prefetch({ content: true });
expect(mp4.createContentUrlWithAuthParams).to.not.be.called;
});
});
});

0 comments on commit f5e487f

Please sign in to comment.