chemoish / videojs-fairplay

Video.js source handler for supporting Fairplay streaming.
MIT License
23 stars 10 forks source link

Set player error on request failures #15

Closed kimurakenshi closed 7 years ago

kimurakenshi commented 7 years ago

Summary

Hi @chemoish, currently We are using this package in our project and it is being really awesome so far. While debugging a concurrency restriction we have in the backend I was trying to add a custom error message in our player to handle that scenario and noticed that for some http responses that come from our backend the error is not being set in the player:

this.player_.error({
  code: 0,
  message: errorMessage,
});

By looking at your code I think I found the problem so this PR is an attempt to fix it. When we

const request = new XMLHttpRequest(); 

and then

    request.addEventListener('error', this.onCertificateError, false);

the only errors that error listen to are network errors and cross-origin errors, when I http response comes from the backend load handler will be called instead and the request is considered successful. So, in order to catch all the errors that comes from the backend we have to check the satus code of the request and when is not 200 execute the error logic that will end up setting a custom error in the player instance.

Also I found a dependency error while trying to npm run build for babel-core so I added that package to devDependencies in a different commit. That change is totally unrelated to this PR so let me know if you want to remove that commit from this PR.

Feedback is more than welcome!

Thank you.

chemoish commented 7 years ago

@kimurakenshi Thanks for your gracious help!