Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/add-xapi-video-verbs' into add…
Browse files Browse the repository at this point in the history
…-xapi-video-verbs
  • Loading branch information
otacke committed Mar 18, 2018
2 parents d0bc373 + 2224edd commit 83c472a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions scripts/x-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ H5P.VideoXAPI = (function ($) {
var volumeChangedAt = 0;
var sessionID = H5P.createUUID();
var currentTime = 0;
var xAPIBase;
var xAPIObject = null;

/**
* Generate common xAPI statement elements (Video Profile).
Expand Down Expand Up @@ -401,26 +401,28 @@ H5P.VideoXAPI = (function ($) {
* @returns {Object} 'Object' portion of JSON xAPI statement
*/
var getXAPIObject = function () {
if (xAPIBase !== undefined) {
return xAPIBase;
if (xAPIObject !== null) {
return xAPIObject;
}

var event = new H5P.XAPIEvent();
event.setObject(videoInstance);

var xAPIObject = event.data.statement.object;

// Add definition type (required by xAPI Video Profile).
// @see https://liveaspankaj.gitbooks.io/xapi-video-profile/content/statement_data_model.html#241-definition
xAPIObject.definition.type = 'https://w3id.org/xapi/video/activity-type/video';

// Add definition description (if video has a description).
if (videoInstance.contentId && H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + videoInstance.contentId].jsonContent) {
var videoData = JSON.parse(H5PIntegration.contents['cid-' + videoInstance.contentId].jsonContent);
if (videoData && videoData.interactiveVideo && videoData.interactiveVideo.video && videoData.interactiveVideo.video.startScreenOptions && videoData.interactiveVideo.video.startScreenOptions.shortStartDescription) {
xAPIObject.definition.description = {
'en-US': videoData.interactiveVideo.video.startScreenOptions.shortStartDescription
};
if (videoInstance && videoInstance.contentId && H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + videoInstance.contentId]) {
event.setObject(videoInstance);
xAPIObject = event.data.statement.object;

// Add definition type (required by xAPI Video Profile).
// @see https://liveaspankaj.gitbooks.io/xapi-video-profile/content/statement_data_model.html#241-definition
xAPIObject.definition.type = 'https://w3id.org/xapi/video/activity-type/video';

// Add definition description (if video has a description).
if (H5PIntegration.contents['cid-' + videoInstance.contentId].jsonContent) {
var videoData = JSON.parse(H5PIntegration.contents['cid-' + videoInstance.contentId].jsonContent);
if (videoData && videoData.interactiveVideo && videoData.interactiveVideo.video && videoData.interactiveVideo.video.startScreenOptions && videoData.interactiveVideo.video.startScreenOptions.shortStartDescription) {
xAPIObject.definition.description = {
'en-US': videoData.interactiveVideo.video.startScreenOptions.shortStartDescription
};
}
}
}
xAPIBase = xAPIObject;
Expand Down

0 comments on commit 83c472a

Please sign in to comment.