Skip to content

Commit

Permalink
docs: add instructions on how to listen for xAPI events
Browse files Browse the repository at this point in the history
  • Loading branch information
mimidotuser committed Jun 4, 2021
1 parent a253a44 commit e89bf15
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The player can be set up either by directly calling the already built scripts an
frameJs: '/assets/frame.bundle.js',
frameCss: '/assets/styles/h5p.css',
}
const h5p = new H5PStandalone.H5P(el, options);
new H5PStandalone.H5P(el, options);

```
A detailed description of the H5P player arguments are provided under the [advance section](https://github.com/tunapanda/h5p-standalone#advanced-usage)
Expand Down Expand Up @@ -70,7 +70,7 @@ const options = {
frameCss: '/assets/styles/h5p.css',
};

const h5p = new H5P(el, h5pLocation);
new H5P(el, h5pLocation);
```
A detailed description of the H5P player arguments are provided under the [advance section](https://github.com/tunapanda/h5p-standalone#advanced-usage)
## Advanced Usage
Expand Down Expand Up @@ -161,6 +161,53 @@ player1.then(() => {
// do stuff
}));
```

## Listening to xAPI events
To listen for [xAPI events](https://h5p.org/documentation/api/H5P.XAPIEvent.html) emmitted by the player, you must wait for the player to finish loading and initializing the required content libraries. You can find more info about xAPI events here https://h5p.org/documentation/x-api
1) Using `then()` method
```js
import { H5P } from 'h5p-standalone';

const el = document.getElementById("h5p-container");
const options = {
h5pJsonPath: "/h5p-folder",
frameJs: "/assets/frame.bundle.js",
frameCss: "/assets/styles/h5p.css",
};

new H5PStandalone.H5P(el, options).then(function () {
H5P.externalDispatcher.on("xAPI", (event) => {
//do something useful with the event
console.log("xAPI event: ", event);
});
});

```
2) Using `async` function
```js
import { H5P } from 'h5p-standalone';

async function myAwesomePlayer() {
const el = document.getElementById("h5p-container");
const options = {
h5pJsonPath: "/h5p-folder",
frameJs: "/assets/frame.bundle.js",
frameCss: "/assets/styles/h5p.css",
};

await new H5P(el, options);

H5P.externalDispatcher.on("xAPI", (event) => {
//do something useful with the event
console.log("xAPI event: ", event);
});
}

//don't forget to call the function
myAwesomePlayer();

```

### Extracting H5P
1. Rename the H5P file extension from `.h5p` file to `.zip`
2. Extract the renamed file contents into your workspace `h5p-folder` folder
Expand Down

0 comments on commit e89bf15

Please sign in to comment.