Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

[ABR] Store bandwidth and throughput values in local storage and use them o… #1142

Closed

Conversation

gesinger
Copy link
Contributor

@gesinger gesinger commented Jun 1, 2017

…n startup

Description

#1113

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
  • Reviewed by Two Core Contributors

@mjneil mjneil changed the title Store bandwidth and throughput values in local storage and use them o… [ABR] Store bandwidth and throughput values in local storage and use them o… Jun 2, 2017
@mjneil
Copy link
Contributor

mjneil commented Jun 5, 2017

Didn't we want to turn on the storing of local storage but leave the using of it off for now?

Also do you think this would be a good thing to allow turning off and on through the player options?

README.md Outdated
@@ -306,6 +308,19 @@ When the `bandwidth` property is set (bits per second), it will be used in
the calculation for initial playlist selection, before more bandwidth
information is seen by the player.

##### storeBandwidthInLocalStorage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this option needed? Any reason to not just have storage always enabled, and allow the setting of whether its actually used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since local storage is limited in size (before access to more space must be granted by the site visitor), it is possible that a user of videojs-contrib-hls doesn't want the project using some of the space if they've carefully accounted for the amount allotted to them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't useBandwidthFromLocalStorage do both?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only storing 2 ints though, so I don't think it will be a big issue. Either way, I agree with @forbesjo , we should just use one flag to turn off both storing and using. I know previously we've discussed turning on the storing but not the using, but I don't think that matters much, especially since we are wanting to go the usage event route

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍 . Will change to just one.

@mjneil
Copy link
Contributor

mjneil commented Jun 13, 2017

We should add the usage tracking event for when localstorage values have been used

Copy link
Contributor

@OshinKaramian OshinKaramian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor suggestions.

// broadband internet
// 0.5 MB/s
if (typeof this.options_.bandwidth !== 'number') {
this.options_.bandwidth = 4194304;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to put this magic number into a const somewhere.

@@ -2687,6 +2689,108 @@ QUnit.test('populates quality levels list when available', function(assert) {
assert.ok(this.player.tech_.hls.qualityLevels_, 'added quality levels from video with source');
});

QUnit.test('stores bandwidth and throughput in localStorage', function(assert) {
const origHlsOptions = videojs.options.hls;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big test... it might make sense (if possible) to break it down into a few smaller tests. Tiny tests make debugging and finding issues a little bit easier.

});

assert.equal(this.player.tech_.hls.bandwidth,
4194304,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you export the const you might be able to reference it here.

// broadband internet (0.5 MB/s) or mobile (0.0625 MB/s)
if (typeof this.options_.bandwidth !== 'number') {
if (this.options_.useBandwidthFromLocalStorage && window.localStorage) {
let storedBandwidth =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is there any reason this can't be a const?

}

// if bandwidth was not set by options or pulled from local storage, start playlist
// selection at a reasonable bandwidth
if (typeof this.options_.bandwidth !== 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's semantically equivalent, but I'm wondering why you didn't include this as an else in the clause above. i.e. if use local storage, grab it, otherwise set the bandwidth from a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that the user did not specify a bandwidth value and set useBandwidthFromLocalStorage to true, but there was nothing in local storage, leaving bandwidth undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good call

@@ -2932,6 +2934,108 @@ QUnit.test('populates quality levels list when available', function(assert) {
assert.ok(this.player.tech_.hls.qualityLevels_, 'added quality levels from video with source');
});

QUnit.test('stores bandwidth and throughput in localStorage when option is true',
function(assert) {
videojs.options.hls = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be a test that sets it in the player directly?

* Type: `boolean`
* can be used as an initialization option

If true, `bandwidth` and `throughput` values are stored in and retrieved from local
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add explanation of default behavior

@forbesjo
Copy link
Contributor

forbesjo commented Aug 6, 2018

Let's open this against VHS

@forbesjo
Copy link
Contributor

@gkatsev what are your thoughts on plugins using local storage? Should there be a common API provided by video.js or should the plugins do this directly?

@gkatsev
Copy link
Member

gkatsev commented Aug 10, 2018

I think we shouldn't store things in local storage by default but have an option to enable it. This is because of the EU cookie laws where users have to be informed if things are stored locally. While local storage isn't specifically called out, it's best to play it safe. In Video.js, we have an option to persist caption settings for the user but it is disabled by default.
Then, when a site that has the cookie notification uses Video.js, they could enable the option to persist this information.

With ABR, we'd have two things that are stored in local storage, optionally, I don't think it quite warrants a combined API, but we should keep our eyes out, maybe we'll want to combine both of these into a common videojs api and a common allowPersistence option that enables or disabled all persistence via that new API.

@gesinger
Copy link
Contributor Author

Closing in favor of videojs/http-streaming#275

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants