Skip to content

Commit

Permalink
feat: public function for updating VHS options (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
wseymour15 authored and Dzianis Dashkevich committed Nov 30, 2023
1 parent bfe0161 commit da37185
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,15 @@ class VhsHandler extends Component {
this.on(this.tech_, 'play', this.play);
}

setOptions_() {
/**
* Set VHS options based on options from configuration, as well as partial
* options to be passed at a later time.
*
* @param {Object} options A partial chunk of config options
*/
setOptions_(options = {}) {
this.options_ = merge(this.options_, options);

// defaults
this.options_.withCredentials = this.options_.withCredentials || false;
this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
Expand Down Expand Up @@ -754,6 +762,10 @@ class VhsHandler extends Component {
this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
}
// alias for public method to set options
setOptions(options = {}) {
this.setOptions_(options);
}
/**
* called when player.src gets called, handle a new source
*
Expand Down
23 changes: 23 additions & 0 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,29 @@ QUnit.test('VhsHandler is referenced by player.tech().vhs', function(assert) {
);
});

QUnit.test.only('options are updated when setOptions is called', function(assert) {
this.player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
this.clock.tick(1);

const vhs = this.player.tech().vhs;

assert.equal(this.env.log.warn.calls, 1, 'warning logged');
assert.equal(
this.env.log.warn.args[0][0],
'Using the tech directly can be dangerous. I hope you know what you\'re doing.\n' +
'See https://github.com/videojs/video.js/issues/2617 for more info.\n',
'logged warning'
);
assert.equal(vhs.options_.withCredentials, false);

vhs.setOptions({ withCredentials: true });

assert.equal(vhs.options_.withCredentials, true, 'options are updated');
});

QUnit.test('starts playing if autoplay is specified', function(assert) {
this.player.autoplay(true);
this.player.src({
Expand Down

0 comments on commit da37185

Please sign in to comment.