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

fix: stopLoad() after destroy() becomes no-op, startLoad() after destroy() throws nicer error message. #3710

Merged
merged 2 commits into from Apr 7, 2021

Conversation

jwalton
Copy link
Contributor

@jwalton jwalton commented Apr 1, 2021

This PR will make error messages nicer when you call stopLoad() or startLoad() after calling destroy.

Why is this Pull Request needed?

This is a super minor fix. I was getting the very unhelpful error: TypeError: Cannot read property 'forEach' of null. It turns out I was calling stopLoad() after calling destroy(), and was running into:

this.networkControllers.forEach(...

but this.networkControllers had been set to null in the destroy() function.

So this change:

  • Makes it so networkControllers is defined as an array or undefined.
  • Handles the case where you call stopLoad() when networkControllers is undefined (this is a no-op now).
  • Throws a slightly more user friendly "Cannot call startLoad() on destroyed instance of hls" when you call startLoad() after calling destroy().

Are there any points in the code the reviewer needs to double check?

No

Resolves issues:

None.

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

src/hls.ts Outdated
@@ -284,8 +284,7 @@ export default class Hls implements HlsEventEmitter {
this.url = null;
if (this.networkControllers) {
this.networkControllers.forEach((component) => component.destroy());
// @ts-ignore
this.networkControllers = null;
this.networkControllers = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if we just did this?

Suggested change
this.networkControllers = undefined;
this.networkControllers.length = 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a much simpler fix. :) I made the same change to coreComponents below, too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

jwalton added a commit to jwalton/hls.js that referenced this pull request Apr 6, 2021
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.

None yet

2 participants