You can manage user progress (saving and loading state) manually by providing the contentUserData option during initialization and implementing your own storage logic.
To restore state, pass an array containing an object with dataType: 'state' and the previousState (as a JSON string) to the contentUserData option.
To save state, access the current state via window.H5PIntegration.contents["cid-${contentId}"].contentUserData and implement your own persistence logic. It is recommended to call your save function periodically using a setInterval synchronized with the saveFreq option.
function retrieveSavedContentState(contentId){
// 👉 your implementation that returns the state for this content (and of course for this user)
}
function saveContentState(contentId){
const currentState = window.H5PIntegration.contents[`cid-${contentId}`].contentUserData;
//👉 you can call your logic to save this state somewhere
}
const CONTENT_ID = 'some-content-unique-id-xxxxx';
const previousStateJSON = await retrieveSavedContentState(CONTENT_ID)
const options = {
id: CONTENT_ID,
h5pJsonPath: '/content/course-presentation-one',
frameJs: '/dist/frame.bundle.js',
frameCss: '/dist/styles/h5p.css',
saveFreq: 100, // required
contentUserData: [
{
dataType: 'state',
previousState: previousStateJSON, // should be a json string
}
]
}
await new H5PStandalone(el, options);
// Call save function periodically based on saveFreq (converted to ms)
setInterval(()=>saveContentState(CONTENT_ID), options.saveFreq * 1000);