Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Public function for updating VHS options #1446

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -756,6 +764,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
Loading