From 7f19d2428eb0208ea8222a8c25d48ba199e839d5 Mon Sep 17 00:00:00 2001 From: Zach Buttram Date: Thu, 6 Dec 2018 11:04:33 -0800 Subject: [PATCH 1/4] add ability to pass player sources to support multiple qualities --- src/helpers/get-player-opts.js | 3 +++ src/player-prop-types.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/helpers/get-player-opts.js b/src/helpers/get-player-opts.js index 2c834bca..37018d07 100644 --- a/src/helpers/get-player-opts.js +++ b/src/helpers/get-player-opts.js @@ -9,6 +9,7 @@ function getPlayerOpts(opts) { isMuted, licenseKey, playlist, + sources, } = opts; const hasAdvertising = !!generatePrerollUrl; @@ -23,6 +24,8 @@ function getPlayerOpts(opts) { playerOpts.playlist = playlist; } else if (file) { playerOpts.file = file; + } else if (sources) { + playerOpts.sources = sources; } if (aspectRatio && aspectRatio !== 'inherit') { diff --git a/src/player-prop-types.js b/src/player-prop-types.js index de82be6f..98f27d25 100644 --- a/src/player-prop-types.js +++ b/src/player-prop-types.js @@ -5,6 +5,14 @@ const propTypes = { className: PropTypes.string, customProps: PropTypes.object, file: PropTypes.string, + sources: PropTypes.arrayOf( + PropTypes.shape({ + file: PropTypes.string, + label: PropTypes.string, + default: PropTypes.bool, + type: PropTypes.string, + }), + ), generatePrerollUrl: PropTypes.func, image: PropTypes.string, isAutoPlay: PropTypes.bool, From 6aa4b7f8e81ae239655223fe38c55f829d71963e Mon Sep 17 00:00:00 2001 From: Zach Buttram Date: Tue, 7 May 2019 14:21:10 -0700 Subject: [PATCH 2/4] add sCU check for sources prop --- src/react-jw-player.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/react-jw-player.jsx b/src/react-jw-player.jsx index 8d95aa99..a55cd244 100644 --- a/src/react-jw-player.jsx +++ b/src/react-jw-player.jsx @@ -62,8 +62,9 @@ class ReactJWPlayer extends Component { shouldComponentUpdate(nextProps) { const hasFileChanged = this.props.file !== nextProps.file; const hasPlaylistChanged = !isEqual(this.props.playlist, nextProps.playlist); + const hasSourcesChanged = !isEqual(this.props.sources, nextProps.sources); - return hasFileChanged || hasPlaylistChanged; + return hasFileChanged || hasPlaylistChanged || hasSourcesChanged; } componentDidUpdate() { if (window.jwplayer && window.jwplayer(this.videoRef)) { From 1d3bf2a7f8dd00448549ac19cbaa37618a73fb56 Mon Sep 17 00:00:00 2001 From: Zach Buttram Date: Tue, 7 May 2019 14:25:51 -0700 Subject: [PATCH 3/4] add test for passing sources prop through getPlayerOpts --- test/get-player-opts.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/get-player-opts.test.js b/test/get-player-opts.test.js index 995287ab..b1d09734 100644 --- a/test/get-player-opts.test.js +++ b/test/get-player-opts.test.js @@ -118,6 +118,19 @@ test('getPlayerOpts() with both only a file', (t) => { t.end(); }); +test('getPlayerOpts() with sources', (t) => { + const mockSources = [ + { file: 'mock file hd', label: 'HD' }, + { file: 'mock file sd', label: 'SD' }, + ]; + + const actual = getPlayerOpts({ sources: mockSources }); + + t.equal(actual.sources, mockSources, 'it sets the sources properly'); + + t.end(); +}); + test('getPlayerOpts() with image', (t) => { const mockImage = 'mock image'; From e18afdbf13e5e6370dbecc7fa679f26e8b97a049 Mon Sep 17 00:00:00 2001 From: Zach Buttram Date: Tue, 7 May 2019 14:27:58 -0700 Subject: [PATCH 4/4] add test for sCU with sources changing --- test/react-jw-player.test.jsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/react-jw-player.test.jsx b/test/react-jw-player.test.jsx index b9bfb72c..59449733 100644 --- a/test/react-jw-player.test.jsx +++ b/test/react-jw-player.test.jsx @@ -118,3 +118,30 @@ test('ReactJWPlayer().shouldComponentUpdate() with file change', (t) => { t.end(); }); + +test('ReactJWPlayer().shouldComponentUpdate() with sources change', (t) => { + const propsOne = { + sources: [ + { file: 'mock file hd 1', label: 'HD' }, + { file: 'mock file sd 1', label: 'SD' }, + ], + }; + + const propsTwo = { + sources: [ + { file: 'mock file hd 2', label: 'HD' }, + { file: 'mock file sd 2', label: 'SD' }, + ], + }; + + const shouldComponentUpdate = new ReactJWPlayer({}).shouldComponentUpdate.bind({ + props: propsOne, + }); + + t.ok( + shouldComponentUpdate(propsTwo), + 'it returns true when the file prop changes', + ); + + t.end(); +});