From f5e487f48dd2a5371703e5bb8a2d7d61c40766d4 Mon Sep 17 00:00:00 2001 From: bhh1988 Date: Mon, 11 Dec 2017 14:20:11 -0800 Subject: [PATCH] Update: Do not prefetch for mp4 and mp3 viewers (#536) 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). --- src/lib/viewers/media/MP3Viewer.js | 14 ----------- src/lib/viewers/media/MP4Viewer.js | 14 ----------- .../viewers/media/__tests__/MP3Viewer-test.js | 24 ------------------- .../viewers/media/__tests__/MP4Viewer-test.js | 24 ------------------- 4 files changed, 76 deletions(-) diff --git a/src/lib/viewers/media/MP3Viewer.js b/src/lib/viewers/media/MP3Viewer.js index 8925bc2f9..c45235b9a 100644 --- a/src/lib/viewers/media/MP3Viewer.js +++ b/src/lib/viewers/media/MP3Viewer.js @@ -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 * diff --git a/src/lib/viewers/media/MP4Viewer.js b/src/lib/viewers/media/MP4Viewer.js index 41cb60467..557504843 100644 --- a/src/lib/viewers/media/MP4Viewer.js +++ b/src/lib/viewers/media/MP4Viewer.js @@ -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; diff --git a/src/lib/viewers/media/__tests__/MP3Viewer-test.js b/src/lib/viewers/media/__tests__/MP3Viewer-test.js index cd3bef809..9eb0c93cd 100644 --- a/src/lib/viewers/media/__tests__/MP3Viewer-test.js +++ b/src/lib/viewers/media/__tests__/MP3Viewer-test.js @@ -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; diff --git a/src/lib/viewers/media/__tests__/MP4Viewer-test.js b/src/lib/viewers/media/__tests__/MP4Viewer-test.js index 58497007e..0995e57d5 100644 --- a/src/lib/viewers/media/__tests__/MP4Viewer-test.js +++ b/src/lib/viewers/media/__tests__/MP4Viewer-test.js @@ -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; - }); - }); });