-
Notifications
You must be signed in to change notification settings - Fork 795
[ABR] Store bandwidth and throughput values in local storage and use them o… #1142
[ABR] Store bandwidth and throughput values in local storage and use them o… #1142
Conversation
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? |
…and useBandwidthFromLocalStorage 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
We should add the usage tracking event for when localstorage values have been used |
There was a problem hiding this 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.
src/videojs-contrib-hls.js
Outdated
// broadband internet | ||
// 0.5 MB/s | ||
if (typeof this.options_.bandwidth !== 'number') { | ||
this.options_.bandwidth = 4194304; |
There was a problem hiding this comment.
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.
test/videojs-contrib-hls.test.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
test/videojs-contrib-hls.test.js
Outdated
}); | ||
|
||
assert.equal(this.player.tech_.hls.bandwidth, | ||
4194304, |
There was a problem hiding this comment.
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.
src/videojs-contrib-hls.js
Outdated
// 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 = |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good call
test/videojs-contrib-hls.test.js
Outdated
@@ -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 = { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Let's open this against VHS |
@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? |
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. 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 |
Closing in favor of videojs/http-streaming#275 |
…n startup
Description
#1113
Requirements Checklist