tunapanda/h5p-standalone

How do you detect if h5p package is successfully completed?

Opened this issue · 3 comments

How can you detect if programmatically if the H5P package is completed?

There seems to be a "ajax.setFinishedUrl" option for a URL but is there a way to detect the completion as a callback function instead?

You can listen for xAPI events that contain a result property or a verb property with completed or answered. See official documentation, for instance: https://h5p.org/node/3391

Hmm so I've tried it with a sample H5P package and the package doesn't report a result or verb property.

However, if I set the ajax.setFinishedUrl, it does POST the result to a URL at the right time with form post of something like:

contentId: 10c2ie7uy
score: 5
maxScore: 5
opened: 1701146845
finished: 1701146936

Is there any option for something like "setFinishedCallback" which is just a callback function that passes the completion object?

For example:

setFinishedCallback : function(results) { 
 //Let me process the completion however I want, not necessarily to do an Ajax post.
console.log(results); 
}

Is this something that could be added?

Not sure what the "H5P sample package" is, but I am pretty sure that all H5P content types that report some result via xAPI have both, a verb and a results property, which can be tracked (https://github.com/tunapanda/h5p-standalone#listening-to-xapi-events) and evaluated. The core of H5P does the same and calls the AJAX endpoint that you can define in H5P Standalone (see postUserStatistics and ajax.setFinishedURL. You will need to implement that endpoint, as H5P Standalone does not implement one itself. If you're only interested in the 'completed' state and not the whole xAPI information, that's an option.

Apart from that: I am neither affiliated with the H5P Standalone team nor H5P Group, so I cannot answer what could/will be added to either H5P Standalone or H5P core.