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

Uncaught TypeError: H5P.isEmpty is not a function #157

Open
skills-up opened this issue Aug 9, 2024 · 1 comment
Open

Uncaught TypeError: H5P.isEmpty is not a function #157

skills-up opened this issue Aug 9, 2024 · 1 comment

Comments

@skills-up
Copy link

Getting the following error when trying to load the interactive video using this library:
Uncaught TypeError: H5P.isEmpty is not a function

This happens when I'm trying to save the current user state. Interactive Video library has the following definition for getCurrentState function:

    Z.prototype.getCurrentState = function () {
      var t = this;
      if (t.video && t.video.play) {
        var e = {
          progress: t.currentTime,
          maxTimeReached: this.maxTimeReached ||
          null,
          answers: [],
          interactionsProgress: t.interactions.slice().sort(
            (
              function (t, e) {
                return t.getDuration().from - e.getDuration().from
              }
            )
          ).map((function (t) {
            return t.getProgress()
          }))
        };
        if (void 0 !== t.interactions) for (var o = 0; o < t.interactions.length; o++) e.answers[o] = t.interactions[o].getCurrentState();
        if (
          !H5P.isEmpty(e.answers) ||
          parseInt(e.progress) !== (t.params.override.startVideoAt || 0)
        ) return e
      }
    }

Since we are unable to get the current state due to missing isEmpty function, so the user state cannot be saved for interactive videos.

@himanshu-ntml
Copy link

You can add below function to your code and it should fix.

H5P.isEmpty = value => {
  if (!value && value !== 0 && value !== false) {
    return true; // undefined, null, NaN and empty strings.
  }
  else if (Array.isArray(value)) {
    for (let i = 0; i < value.length; i++) {
      if (!H5P.isEmpty(value[i])) {
        return false; // Array contains a non-empty value
      }
    }
    return true; // Empty array
  }
  else if (typeof value === 'object') {
    for (let prop in value) {
      if (value.hasOwnProperty(prop) && !H5P.isEmpty(value[prop])) {
        return false; // Object contains a non-empty value
      }
    }
    return true; // Empty object
  }
  return false;
};

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

No branches or pull requests

2 participants