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

Add xAPI Events to gain deeper insights into the learners' behaviors #311

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "h5p-interactive-video",
"version": "1.25.0",
"version": "1.27.0",
"description": "Put texts, tasks and other medias on top of your video.",
"private": true,
"scripts": {
Expand Down
40 changes: 39 additions & 1 deletion src/scripts/interactive-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function InteractiveVideo(params, id, contentData) {
// set start time
// if previousState.progress exists, update time to that, else use startAt defined in params or 0
self.currentTime = Math.floor((self.previousState?.progress !== undefined && self.previousState?.progress !== null) ? self.previousState.progress : (params.override?.startVideoAt || 0));
self.lastxAPITime = Math.floor((self.previousState?.progress !== undefined && self.previousState?.progress !== null) ? self.previousState.progress : (params.override?.startVideoAt || 0));

this.maxTimeReached = (self.previousState && self.previousState.maxTimeReached) ?
self.previousState.maxTimeReached :
Expand Down Expand Up @@ -255,6 +256,23 @@ function InteractiveVideo(params, id, contentData) {
self.resize();
});

// Add H5P xAPI Verbs
if(H5P.jQuery.inArray("viewed", H5P.XAPIEvent.allowedXAPIVerbs) === -1)
{
H5P.XAPIEvent.allowedXAPIVerbs.push("viewed")
}

if(H5P.jQuery.inArray("play", H5P.XAPIEvent.allowedXAPIVerbs) === -1)
{
H5P.XAPIEvent.allowedXAPIVerbs.push("play")
}

if(H5P.jQuery.inArray("pause", H5P.XAPIEvent.allowedXAPIVerbs) === -1)
{
H5P.XAPIEvent.allowedXAPIVerbs.push("pause")
}


// In the editor, no captions will be shown
const textTracks = this.editor ? [] :
(self.options.video.textTracks && self.options.video.textTracks.videoTrack ? self.options.video.textTracks.videoTrack : []);
Expand Down Expand Up @@ -389,6 +407,10 @@ function InteractiveVideo(params, id, contentData) {
self.trigger('resize');
}, 400);
}
let statement = self.createXAPIEventTemplate('play');
let extensions = statement.getVerifiedStatementValue(["object","definition","extensions"]);
extensions = Object.assign(extensions,{ videoTime : self.video.getCurrentTime() });
self.trigger(statement);
}

self.currentState = H5P.Video.PLAYING;
Expand Down Expand Up @@ -420,6 +442,11 @@ function InteractiveVideo(params, id, contentData) {
self.controls.$play.focus();
}

let statement = self.createXAPIEventTemplate('pause');
let extensions = statement.getVerifiedStatementValue(["object","definition","extensions"]);
extensions = Object.assign(extensions,{ videoTime : self.video.getCurrentTime() });
self.trigger(statement);

self.timeUpdate(self.video.getCurrentTime());
break;

Expand Down Expand Up @@ -3163,7 +3190,17 @@ InteractiveVideo.prototype.toggleFullScreen = function () {
InteractiveVideo.prototype.timeUpdate = function (time, skipNextTimeUpdate) {
var self = this;

// keep track of current time in IV
if(Math.abs(self.lastxAPITime - time) > 1)
{
self.lastxAPITime = time;

let statement = self.createXAPIEventTemplate('viewed');
let extensions = statement.getVerifiedStatementValue(["object","definition","extensions"]);
extensions = Object.assign(extensions,{ videoTime : self.video.getCurrentTime() });
self.trigger(statement);
}

// keep track of current time in IV
self.currentTime = time;

// Scroll slider
Expand All @@ -3187,6 +3224,7 @@ InteractiveVideo.prototype.timeUpdate = function (time, skipNextTimeUpdate) {
self.timeUpdate(self.video.getCurrentTime());
}
}, 40); // 25 fps

};

/**
Expand Down