Skip to content

Allow video skip with Accept-Ranges closes #457 #462#466

Merged
timbl merged 2 commits into
nodeSolidServer:masterfrom
melvincarvalho:mc_video_skip
Dec 6, 2016
Merged

Allow video skip with Accept-Ranges closes #457 #462#466
timbl merged 2 commits into
nodeSolidServer:masterfrom
melvincarvalho:mc_video_skip

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

This PR allows video to be skipped using byte ranges.

It also refactors ldp.get to use options rather than positional variables in order to provide more flexibility.

Separation of concerns between ldp.js and handers/get.js is maintained

Comment thread lib/handlers/allow.js
? res.locals.path
: req.path
ldp.exists(req.hostname, reqPath, (err, stat) => {
ldp.exists(req.hostname, reqPath, (err, ret) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does ret stand for?

@melvincarvalho

Copy link
Copy Markdown
Contributor Author

@dmitrizagidulin ret == return value as an object

Reason is that get has to pass back a number of items, such as the range, the stream, etc.

Changing it into an object gives more flexibility.

@timbl

timbl commented Dec 5, 2016

Copy link
Copy Markdown
Contributor

Looks sensible to me

@timbl timbl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggest another review with someone who knows the code better.

@timbl timbl merged commit 67a07be into nodeSolidServer:master Dec 6, 2016
@timbl

timbl commented Dec 6, 2016

Copy link
Copy Markdown
Contributor

Ok, I have run it on a test machine , seems to work nicely! Video can be skipped backward amd forward and started at any point.
Merged in.
Thank you @melvincarvalho !

@nicola nicola left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Variables shouldn't be declared in a block scope, also, these changes need testing, why did this got merged?

Comment thread lib/handlers/allow.js
ldp.exists(req.hostname, reqPath, (err, stat) => {
ldp.exists(req.hostname, reqPath, (err, ret) => {
if (ret) {
var stat = ret.stream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait this doesn't sound right

Comment thread lib/handlers/get.js
var contentType = ret.contentType
var container = ret.container
var contentRange = ret.contentRange
var chunksize = ret.chunksize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you create variables inside a block scope?

Comment thread lib/handlers/post.js
}

if (ret) {
var stats = ret.stream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

Comment thread lib/identity-provider.js
return callback(notexists)
}
if (ret) {
var stream = ret.stream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

Comment thread lib/ldp.js
var start = parseInt(partialstart, 10)
var end = partialend ? parseInt(partialend, 10) : total - 1
var chunksize = (end - start) + 1
var contentRange = 'bytes ' + start + '-' + end + '/' + total

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

Comment thread lib/ldp.js

get (host, reqPath, baseUri, includeBody, contentType, callback) {
get (options, callback) {
if (options) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if no options are passed?

@melvincarvalho

Copy link
Copy Markdown
Contributor Author

Hi @nicola thanks for the review!

I asked about how to do this on gitter and in the issues since September. Since I didnt get any feedback I tried to make a patch based on my understanding of the code and what I have learnt in nodejs.

I'd be happy to refactor based on best practice recommendations.

Regarding variables in block scope, is that against our coding standards? My normal coding principle is to declare variables close to where they are used. As I understand it they are hoisted to the top of the function in JS. I could do it another way.

If no options are passed it is the same as sending in undefined in the positional parameters, I think?

Re: var stat = ret.stream not sounding right, I agree! But that's how the code was, overloading a positional parameter for multiple purpose. With my change it is now easier to refactor.

Advice welcome!

@nicola

nicola commented Dec 6, 2016

Copy link
Copy Markdown
Contributor

Hey @melvincarvalho of course your PR is super welcome, it really great to make a PR instead of just discussing changes! (and you even gave a test passing working PR, which is amazing!)

However, I am not sure it was ready to merge yet. The only parts that I don't find ready are the declarations of variables in a scope, they should be declared in the same scope as the others, which are mainly all the changes that I am pointing out.

Let me know if that makes sense or we can find some time to do it together

@melvincarvalho

Copy link
Copy Markdown
Contributor Author

@nicola thanks again for the kind feedback! :)

What I understand of JavaScript is that there is not block scoped variables with the keyword var. New block scoped variables will come in with the keyword let. So as far as the languages cares, whether the var is in the block, or at the top of the closures makes no difference. If you prefer it at the top of the closure, I'll be happy to make that change.

When returning from get with byte ranges, there are more parameters that must be passed back to the calling function such as the chunksize and the accept range. This was more difficult to return as positional parameters in a callback, so I turned it into an object.

There is some inconsistency as sometimes the callback returns the stat, and sometimes the stream, and different calling functions use it differently. That's why the names look a bit strange, but that could be improved with a refactor. However, this was the original logic of the current code.

We can discuss this further here or in gitter, if that suits you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants